From efe964ace6948e0496cd15fde717c6ef17b2d782 Mon Sep 17 00:00:00 2001 From: SVN Migration Date: Tue, 27 Sep 2005 16:01:38 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'RELEASE_0_14_0'. --- CREDITS | 3 - EXPERIMENTAL | 0 KnownIssues.txt | 13 - Makefile.frag | 22 - config.m4 | 168 --- config.w32 | 56 - docs/examples/Bandwidth_Throttling.php | 9 - docs/examples/Cached_Responses.php | 8 - docs/examples/GET_Queries.php | 23 - docs/examples/KISS_XMLRPC_Client.php | 43 - docs/examples/Multipart_Posts.php | 26 - docs/examples/Parallel_Requests.php | 22 - docs/examples/Parallel_Requests_.php | 32 - docs/examples/Simple_Feed_Aggregator.php | 115 -- docs/examples/extract.php | 12 - docs/examples/tutorial.txt | 342 ----- docs/functions.html | 525 ------- docs/http.ini | 30 - funcsummary.php | 117 -- http.c | 450 ------ http.dsp | 209 --- http_api.c | 424 ------ http_cache_api.c | 274 ---- http_date_api.c | 348 ----- http_exception_object.c | 116 -- http_functions.c | 1248 ---------------- http_headers_api.c | 486 ------- http_info_api.c | 150 -- http_message_api.c | 513 ------- http_message_object.c | 929 ------------ http_methods.c | 30 - http_request_api.c | 986 ------------- http_request_method_api.c | 230 --- http_request_object.c | 1688 ---------------------- http_request_pool_api.c | 316 ---- http_requestpool_object.c | 412 ------ http_response_object.c | 1071 -------------- http_send_api.c | 449 ------ http_url_api.c | 384 ----- http_util_object.c | 115 -- missing.c | 73 - missing.h | 47 - package2.xml | 225 --- php_http.h | 152 -- php_http_api.h | 143 -- php_http_cache_api.h | 220 --- php_http_date_api.h | 39 - php_http_exception_object.h | 45 - php_http_headers_api.h | 70 - php_http_info_api.h | 71 - php_http_message_api.h | 100 -- php_http_message_object.h | 101 -- php_http_request_api.h | 134 -- php_http_request_method_api.h | 88 -- php_http_request_object.h | 124 -- php_http_request_pool_api.h | 79 - php_http_requestpool_object.h | 75 - php_http_response_object.h | 78 - php_http_send_api.h | 81 -- php_http_std_defs.h | 413 ------ php_http_url_api.h | 55 - php_http_util_object.h | 49 - phpstr/phpstr.c | 256 ---- phpstr/phpstr.h | 168 --- rebuild | 32 - tests/HttpMessage_001.phpt | 52 - tests/HttpRequestPool_001.phpt | 37 - tests/HttpRequest_001.phpt | 52 - tests/HttpRequest_002.phpt | 80 - tests/HttpRequest_003.phpt | 20 - tests/HttpResponse_001.phpt | 25 - tests/HttpResponse_002.phpt | 25 - tests/INI_001.phpt | 24 - tests/abs_uri_001.phpt | 17 - tests/abs_uri_002.phpt | 19 - tests/allowed_methods_001.phpt | 20 - tests/allowed_methods_001_logging.phpt | 18 - tests/bug_34191.phpt | Bin 397 -> 0 bytes tests/chunked_decode_001.phpt | 25 - tests/chunked_decode_002.phpt | 25 - tests/data.txt | 10 - tests/date_001.phpt | 17 - tests/date_002.phpt | 22 - tests/get_request_data_001.phpt | 36 - tests/negotiation_001.phpt | 38 - tests/parse_headers_001.phpt | 43 - tests/parse_message_001.phpt | 14 - tests/redirect_001.phpt | 23 - tests/redirect_001_logging.phpt | 18 - tests/redirect_002.phpt | 25 - tests/redirect_002_logging.phpt | 18 - tests/redirect_003.phpt | 23 - tests/redirect_003_logging.phpt | 18 - tests/send_data_001.phpt | 22 - tests/send_data_002.phpt | 22 - tests/send_data_003.phpt | 22 - tests/send_data_004.phpt | 21 - tests/send_data_005.phpt | 17 - tests/send_data_006.phpt | 37 - tests/send_data_007.phpt | 22 - tests/send_data_007_logging.phpt | 18 - tests/send_data_008.phpt | 19 - tests/send_data_009.phpt | 21 - tests/send_file_001.phpt | 27 - tests/send_file_002.phpt | 21 - tests/send_file_003.phpt | 21 - tests/send_file_004.phpt | 21 - tests/send_file_005.phpt | 37 - tests/send_file_006.phpt | 29 - tests/send_file_007.phpt | 17 - tests/skip.inc | 10 - 111 files changed, 16460 deletions(-) delete mode 100644 CREDITS delete mode 100644 EXPERIMENTAL delete mode 100644 KnownIssues.txt delete mode 100644 Makefile.frag delete mode 100644 config.m4 delete mode 100644 config.w32 delete mode 100644 docs/examples/Bandwidth_Throttling.php delete mode 100644 docs/examples/Cached_Responses.php delete mode 100644 docs/examples/GET_Queries.php delete mode 100644 docs/examples/KISS_XMLRPC_Client.php delete mode 100644 docs/examples/Multipart_Posts.php delete mode 100644 docs/examples/Parallel_Requests.php delete mode 100644 docs/examples/Parallel_Requests_.php delete mode 100644 docs/examples/Simple_Feed_Aggregator.php delete mode 100644 docs/examples/extract.php delete mode 100644 docs/examples/tutorial.txt delete mode 100644 docs/functions.html delete mode 100644 docs/http.ini delete mode 100644 funcsummary.php delete mode 100644 http.c delete mode 100644 http.dsp delete mode 100644 http_api.c delete mode 100644 http_cache_api.c delete mode 100644 http_date_api.c delete mode 100644 http_exception_object.c delete mode 100644 http_functions.c delete mode 100644 http_headers_api.c delete mode 100644 http_info_api.c delete mode 100644 http_message_api.c delete mode 100644 http_message_object.c delete mode 100644 http_methods.c delete mode 100644 http_request_api.c delete mode 100644 http_request_method_api.c delete mode 100644 http_request_object.c delete mode 100644 http_request_pool_api.c delete mode 100644 http_requestpool_object.c delete mode 100644 http_response_object.c delete mode 100644 http_send_api.c delete mode 100644 http_url_api.c delete mode 100644 http_util_object.c delete mode 100644 missing.c delete mode 100644 missing.h delete mode 100644 package2.xml delete mode 100644 php_http.h delete mode 100644 php_http_api.h delete mode 100644 php_http_cache_api.h delete mode 100644 php_http_date_api.h delete mode 100644 php_http_exception_object.h delete mode 100644 php_http_headers_api.h delete mode 100644 php_http_info_api.h delete mode 100644 php_http_message_api.h delete mode 100644 php_http_message_object.h delete mode 100644 php_http_request_api.h delete mode 100644 php_http_request_method_api.h delete mode 100644 php_http_request_object.h delete mode 100644 php_http_request_pool_api.h delete mode 100644 php_http_requestpool_object.h delete mode 100644 php_http_response_object.h delete mode 100644 php_http_send_api.h delete mode 100644 php_http_std_defs.h delete mode 100644 php_http_url_api.h delete mode 100644 php_http_util_object.h delete mode 100644 phpstr/phpstr.c delete mode 100644 phpstr/phpstr.h delete mode 100755 rebuild delete mode 100644 tests/HttpMessage_001.phpt delete mode 100644 tests/HttpRequestPool_001.phpt delete mode 100644 tests/HttpRequest_001.phpt delete mode 100644 tests/HttpRequest_002.phpt delete mode 100644 tests/HttpRequest_003.phpt delete mode 100644 tests/HttpResponse_001.phpt delete mode 100644 tests/HttpResponse_002.phpt delete mode 100644 tests/INI_001.phpt delete mode 100644 tests/abs_uri_001.phpt delete mode 100644 tests/abs_uri_002.phpt delete mode 100644 tests/allowed_methods_001.phpt delete mode 100644 tests/allowed_methods_001_logging.phpt delete mode 100644 tests/bug_34191.phpt delete mode 100644 tests/chunked_decode_001.phpt delete mode 100644 tests/chunked_decode_002.phpt delete mode 100644 tests/data.txt delete mode 100644 tests/date_001.phpt delete mode 100644 tests/date_002.phpt delete mode 100644 tests/get_request_data_001.phpt delete mode 100644 tests/negotiation_001.phpt delete mode 100644 tests/parse_headers_001.phpt delete mode 100644 tests/parse_message_001.phpt delete mode 100644 tests/redirect_001.phpt delete mode 100644 tests/redirect_001_logging.phpt delete mode 100644 tests/redirect_002.phpt delete mode 100644 tests/redirect_002_logging.phpt delete mode 100644 tests/redirect_003.phpt delete mode 100644 tests/redirect_003_logging.phpt delete mode 100644 tests/send_data_001.phpt delete mode 100644 tests/send_data_002.phpt delete mode 100644 tests/send_data_003.phpt delete mode 100644 tests/send_data_004.phpt delete mode 100644 tests/send_data_005.phpt delete mode 100644 tests/send_data_006.phpt delete mode 100644 tests/send_data_007.phpt delete mode 100644 tests/send_data_007_logging.phpt delete mode 100644 tests/send_data_008.phpt delete mode 100644 tests/send_data_009.phpt delete mode 100644 tests/send_file_001.phpt delete mode 100644 tests/send_file_002.phpt delete mode 100644 tests/send_file_003.phpt delete mode 100644 tests/send_file_004.phpt delete mode 100644 tests/send_file_005.phpt delete mode 100644 tests/send_file_006.phpt delete mode 100644 tests/send_file_007.phpt delete mode 100644 tests/skip.inc diff --git a/CREDITS b/CREDITS deleted file mode 100644 index 1b486cb..0000000 --- a/CREDITS +++ /dev/null @@ -1,3 +0,0 @@ -HTTP -Michael Wallner, Sara Golemon, Daniel Stenberg (libcurl) - diff --git a/EXPERIMENTAL b/EXPERIMENTAL deleted file mode 100644 index e69de29..0000000 diff --git a/KnownIssues.txt b/KnownIssues.txt deleted file mode 100644 index 2bbc05f..0000000 --- a/KnownIssues.txt +++ /dev/null @@ -1,13 +0,0 @@ -Known Issues -============ -$Id$ - -HttpResponse class is only available for PHP >= 5.1 - -Not all places where files are handled check for open_basedir and/or safe_mode. - - -Internals: - - the request bodies created in http_request_pool_attach() are not - destroyed in http_request_pool_detach(); may be a memory problem - in long running scripts diff --git a/Makefile.frag b/Makefile.frag deleted file mode 100644 index 65547b8..0000000 --- a/Makefile.frag +++ /dev/null @@ -1,22 +0,0 @@ -phpincludedir=$(prefix)/include/php - -install-http-headers: - @echo "Installing HTTP headers: $(INSTALL_ROOT)$(phpincludedir)/ext/http/" - @$(mkinstalldirs) $(INSTALL_ROOT)$(phpincludedir)/ext/http - @for f in $(HTTP_HEADER_FILES); do \ - if test -f "$(top_srcdir)/$$f"; then \ - $(INSTALL_DATA) $(top_srcdir)/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/http; \ - elif test -f "$(top_builddir)/$$f"; then \ - $(INSTALL_DATA) $(top_builddir)/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/http; \ - elif test -f "$(top_srcdir)/ext/http/$$f"; then \ - $(INSTALL_DATA) $(top_srcdir)/ext/http/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/http; \ - elif test -f "$(top_builddir)/ext/http/$$f"; then \ - $(INSTALL_DATA) $(top_builddir)/ext/http/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/http; \ - else \ - echo "WTF? $f $$f"; \ - fi \ - done; - -# mini hack -install: $(all_targets) $(install_targets) install-http-headers - diff --git a/config.m4 b/config.m4 deleted file mode 100644 index ec5b519..0000000 --- a/config.m4 +++ /dev/null @@ -1,168 +0,0 @@ -dnl config.m4 for pecl/http -dnl $Id$ - -PHP_ARG_ENABLE([http], [whether to enable extended HTTP support], -[ --enable-http Enable extended HTTP support]) -PHP_ARG_WITH([http-curl-requests], [whether to enable cURL HTTP requests], -[ --with-http-curl-requests[=CURLDIR] - With cURL HTTP request support]) -PHP_ARG_WITH([http-mhash-etags], [whether to enable mhash ETag generator], -[ --with-http-mhash-etags[=MHASHDIR] - With mhash ETag generator support]) -PHP_ARG_WITH([http-magic-mime], [whether to enable response content type guessing], -[ --with-http-magic-mime[=MAGICDIR] - With magic mime response content type guessing]) - -if test "$PHP_HTTP" != "no"; then - -dnl ------- -dnl NETDB.H -dnl ------- - AC_MSG_CHECKING(for netdb.h) - if test -r /usr/include/netdb.h -o -r /usr/local/include/netdb.h; then - AC_DEFINE(HAVE_NETDB_H, 1, [Have netdb.h]) - AC_MSG_RESULT(found in default path) - else - AC_MSG_RESULT(not found in default path) - fi - -dnl ---- -dnl CURL -dnl ---- - if test "$PHP_HTTP_CURL_REQUESTS" != "no"; then - - AC_MSG_CHECKING([for curl/curl.h]) - CURL_DIR= - for i in "$PHP_HTTP_CURL_REQUESTS" /usr/local /usr /opt; do - if test -r "$i/include/curl/curl.h"; then - CURL_DIR=$i - break - fi - done - if test -z "$CURL_DIR"; then - AC_MSG_RESULT([not found]) - AC_MSG_ERROR([could not find curl/curl.h]) - else - AC_MSG_RESULT([found in $CURL_DIR]) - fi - - AC_MSG_CHECKING([for curl-config]) - CURL_CONFIG= - for i in "$CURL_DIR/bin/curl-config" "$CURL_DIR/curl-config" `which curl-config`; do - if test -x "$i"; then - CURL_CONFIG=$i - break - fi - done - if test -z "$CURL_CONFIG"; then - AC_MSG_RESULT([not found]) - AC_MSG_ERROR([could not find curl-config]) - else - AC_MSG_RESULT([found: $CURL_CONFIG]) - fi - - CURL_SSL=`$CURL_CONFIG --features | $EGREP SSL` - if test "$CURL_SSL" == "SSL"; then - AC_DEFINE([HTTP_HAVE_SSL], [1], [ ]) - fi - AC_CHECK_HEADERS([openssl/crypto.h]) - - CURL_LIBS=`$CURL_CONFIG --libs` - - PHP_ADD_INCLUDE($CURL_DIR/include) - PHP_ADD_LIBRARY_WITH_PATH(curl, $CURL_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD) - PHP_EVAL_LIBLINE($CURL_LIBS, HTTP_SHARED_LIBADD) - AC_DEFINE([HTTP_HAVE_CURL], [1], [Have cURL support]) - - PHP_CHECK_LIBRARY(curl, curl_multi_strerror, - [AC_DEFINE([HAVE_CURL_MULTI_STRERROR], [1], [ ])], [ ], - [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR] - ) - PHP_CHECK_LIBRARY(curl, curl_easy_strerror, - [AC_DEFINE([HAVE_CURL_EASY_STRERROR], [1], [ ])], [ ], - [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR] - ) - PHP_CHECK_LIBRARY(curl, curl_easy_reset, - [AC_DEFINE([HAVE_CURL_EASY_RESET], [1], [ ])], [ ], - [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR] - ) - fi - -dnl ---- -dnl MHASH -dnl ---- - if test "$PHP_HTTP_MHASH_ETAGS" != "no"; then - - AC_MSG_CHECKING([for mhash.h]) - MHASH_DIR= - for i in "$PHP_HTTP_MHASH_ETAGS" /usr/local /usr /opt; do - if test -f "$i/include/mhash.h"; then - MHASH_DIR=$i - break - fi - done - if test -z "$MHASH_DIR"; then - AC_MSG_RESULT([not found]) - AC_MSG_ERROR([could not find mhash.h]) - else - AC_MSG_RESULT([found in $MHASH_DIR]) - fi - - PHP_ADD_INCLUDE($MHASH_DIR/include) - PHP_ADD_LIBRARY_WITH_PATH(mhash, $MHASH_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD) - AC_DEFINE([HTTP_HAVE_MHASH], [1], [Have mhash support]) - fi - -dnl ---- -dnl MAGIC -dnl ---- - if test "$PHP_HTTP_MAGIC_MIME" != "no"; then - - AC_MSG_CHECKING([for magic.h]) - MAGIC_DIR= - for i in "$PHP_HTTP_MAGIC_MIME" /usr/local /usr /opt; do - if test -f "$i/include/magic.h"; then - MAGIC_DIR=$i - break - fi - done - if test -z "$MAGIC_DIR"; then - AC_MSG_RESULT([not found]) - AC_MSG_ERROR([could not find magic.h]) - else - AC_MSG_RESULT([found in $MAGIC_DIR]) - fi - - PHP_ADD_INCLUDE($MAGIC_DIR/include) - PHP_ADD_LIBRARY_WITH_PATH(magic, $MAGIC_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD) - AC_DEFINE([HTTP_HAVE_MAGIC], [1], [Have magic mime support]) - fi - -dnl ---- -dnl DONE -dnl ---- - PHP_HTTP_SOURCES="missing.c http.c http_functions.c phpstr/phpstr.c \ - http_util_object.c http_message_object.c http_request_object.c http_request_pool_api.c \ - http_response_object.c http_exception_object.c http_requestpool_object.c \ - http_api.c http_cache_api.c http_request_api.c http_date_api.c \ - http_headers_api.c http_message_api.c http_send_api.c http_url_api.c \ - http_info_api.c http_request_method_api.c" - PHP_NEW_EXTENSION([http], $PHP_HTTP_SOURCES, [$ext_shared]) - PHP_ADD_BUILD_DIR($ext_builddir/phpstr, 1) - PHP_SUBST([HTTP_SHARED_LIBADD]) - - HTTP_HEADER_FILES="php_http_std_defs.h php_http.h php_http_api.h php_http_cache_api.h \ - php_http_date_api.h php_http_headers_api.h php_http_info_api.h php_http_message_api.h \ - php_http_request_api.h php_http_request_method_api.h php_http_send_api.h php_http_url_api.h" - PHP_SUBST([HTTP_HEADER_FILES]) - - ifdef([PHP_INSTALL_HEADERS], - [ - PHP_INSTALL_HEADERS(ext/http, $HTTP_HEADER_FILES) - PHP_INSTALL_HEADERS(ext/http/phpstr, [phpstr/phpstr.h]) - ], [ - PHP_ADD_MAKEFILE_FRAGMENT - ]) - - AC_DEFINE([HAVE_HTTP], [1], [Have extended HTTP support]) -fi diff --git a/config.w32 b/config.w32 deleted file mode 100644 index 23a2dd1..0000000 --- a/config.w32 +++ /dev/null @@ -1,56 +0,0 @@ -// config.w32 for pecl/http -// $Id$ - -ARG_ENABLE("http", "whether to enable extended HTTP support", "no"); - -if (PHP_HTTP != "no") { - - EXTENSION("http", - "missing.c http.c http_functions.c http_exception_object.c "+ - "http_util_object.c http_message_object.c http_requestpool_object.c "+ - "http_request_object.c http_response_object.c "+ - "http_api.c http_cache_api.c http_request_pool_api.c "+ - "http_request_api.c http_date_api.c http_headers_api.c "+ - "http_message_api.c http_send_api.c http_url_api.c "+ - "http_info_api.c http_request_method_api.c", - null, - "/I\"" + configure_module_dirname + "/phpstr\""); - ADD_SOURCES(configure_module_dirname + "/phpstr", "phpstr.c", "http"); - AC_DEFINE("HAVE_HTTP", 1, "Have extended HTTP support"); - - MHASH_LIB = PHP_DEBUG != "no" ? "libmhash-staticd.lib":"libmhash-static.lib"; - if (CHECK_HEADER_ADD_INCLUDE('mhash.h', 'CFLAGS_HTTP') && - (CHECK_LIB(MHASH_LIB, 'http', PHP_HTTP) || - CHECK_LIB('libmhash.lib', 'http', PHP_HTTP))) { - AC_DEFINE('HTTP_HAVE_MHASH', 1 , "Have mhash library"); - } else { - WARNING("mhash etag generator not enabled; libraries and headers not found"); - } - - CURL_LIB = PHP_DEBUG != "no" ? "libcurld.lib":"libcurl.lib"; - if (CHECK_HEADER_ADD_INCLUDE("curl/curl.h", "CFLAGS_HTTP") && - CHECK_HEADER_ADD_INCLUDE("openssl/crypto.h", "CFLAGS_HTTP") && - CHECK_LIB(CURL_LIB, "http", PHP_HTTP) && - CHECK_LIB("ssleay32.lib", "http", PHP_HTTP) && - CHECK_LIB("libeay32.lib", "http", PHP_HTTP) && - CHECK_LIB("zlib.lib", "http", PHP_HTTP) && - CHECK_LIB("winmm.lib", "http", PHP_HTTP)) { - AC_DEFINE("HTTP_HAVE_CURL", 1, "Have CURL library"); - AC_DEFINE("HTTP_HAVE_SSL", 1, "Have SSL"); - AC_DEFINE("HAVE_CURL_MULTI_STRERROR", 1, ""); - AC_DEFINE("HAVE_CURL_EASY_STRERROR", 1, ""); - AC_DEFINE("HAVE_CURL_EASY_RESET", 1, ""); - AC_DEFINE("CURL_STATICLIB", 1, ""); - } else { - WARNING("curl convenience functions not enabled; libraries and headers not found"); - } - - MAGIC_LIB = PHP_DEBUG != "no" ? "libmagic-staticd.lib":"libmagic-static.lib"; - if (CHECK_HEADER_ADD_INCLUDE("magic.h", "CFLAGS_HTTP") && - CHECK_LIB(MAGIC_LIB, "http", PHP_HTTP)) { - AC_DEFINE("HTTP_HAVE_MAGIC", 1, "Have magic library"); - AC_DEFINE("USE_MAGIC_STATIC", "", ""); - } else { - WARNING("content type guessing not enabled; libraries and headers not found"); - } -} diff --git a/docs/examples/Bandwidth_Throttling.php b/docs/examples/Bandwidth_Throttling.php deleted file mode 100644 index 981272c..0000000 --- a/docs/examples/Bandwidth_Throttling.php +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/docs/examples/Cached_Responses.php b/docs/examples/Cached_Responses.php deleted file mode 100644 index 8ac2bcf..0000000 --- a/docs/examples/Cached_Responses.php +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/docs/examples/GET_Queries.php b/docs/examples/GET_Queries.php deleted file mode 100644 index cb21cb6..0000000 --- a/docs/examples/GET_Queries.php +++ /dev/null @@ -1,23 +0,0 @@ -setOptions( - array( 'cookiestore' => '../cookies/google.txt', - ) -); - -$r->setQueryData( - array( 'q' => '+"pecl_http" -msg -cvs -list', - 'hl' => 'de' - ) -); - -// HttpRequest::send() returns an HttpMessage object -// of type HttpMessage::RESPONSE or throws an exception -try { - print $r->send()->getBody(); -} catch (HttpException $e) { - print $e; -} -?> diff --git a/docs/examples/KISS_XMLRPC_Client.php b/docs/examples/KISS_XMLRPC_Client.php deleted file mode 100644 index b9e955b..0000000 --- a/docs/examples/KISS_XMLRPC_Client.php +++ /dev/null @@ -1,43 +0,0 @@ -namespace = $namespace; - $this->request = new HttpRequest($url, HTTP_METH_POST); - $this->request->setContentType('text/xml'); - } - - public function setOptions($options = array()) - { - return $this->request->setOptions($options); - } - - public function addOptions($options) - { - return $this->request->addOptions($options); - } - - public function __call($method, $params) - { - if ($this->namespace) { - $method = $this->namespace .'.'. $method; - } - $this->request->setPostData(xmlrpc_encode_request($method, $params)); - $response = $this->request->send(); - if ($response->getResponseCode() != 200) { - throw new Exception($response->getBody(), $response->getResponseCode()); - } - return xmlrpc_decode($response->getBody(), 'utf-8'); - } - - public function getHistory() - { - return $this->request->getHistory(); - } -} - -?> diff --git a/docs/examples/Multipart_Posts.php b/docs/examples/Multipart_Posts.php deleted file mode 100644 index 2656b31..0000000 --- a/docs/examples/Multipart_Posts.php +++ /dev/null @@ -1,26 +0,0 @@ -setOptions( - array( 'cookies' => array('MyCookie' => 'has a value'), - 'redirect' => true, - ) -); - -// common form data -$r->setPostFields( - array( 'name' => 'Mike', - 'mail' => 'mike@php.net', - ) -); -// add the file to post (form name, file name, file type) -$r->addPostFile('image', 'profile.jpg', 'image/jpeg'); - -try { - print $r->send()->getBody(); -} catch (HttpException $e) { - print $e; -} -?> diff --git a/docs/examples/Parallel_Requests.php b/docs/examples/Parallel_Requests.php deleted file mode 100644 index d9b05f0..0000000 --- a/docs/examples/Parallel_Requests.php +++ /dev/null @@ -1,22 +0,0 @@ -attach(new HttpRequest('http://pear.php.net', HTTP_METH_HEAD)); - $p->attach(new HttpRequest('http://pecl.php.net', HTTP_METH_HEAD)); -} catch (HttpException $e) { - print $e; - exit; -} - -try { - $p->send(); - // HttpRequestPool implements an iterator over attached HttpRequest objects - foreach ($p as $r) { - echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n"; - } -} catch (HttpException $e) { - print $e; -} -?> diff --git a/docs/examples/Parallel_Requests_.php b/docs/examples/Parallel_Requests_.php deleted file mode 100644 index 8798c30..0000000 --- a/docs/examples/Parallel_Requests_.php +++ /dev/null @@ -1,32 +0,0 @@ -socketPerform(); $i++) { - $i % 10 or print "."; - if (!$this->socketSelect()) { - throw new HttpException("Socket error!"); - } - } - print "\nDone!\n"; - } -} - -try { - foreach (new Pool as $r) { - echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n"; - } -} catch (HttpException $ex) { - print $e; -} -?> diff --git a/docs/examples/Simple_Feed_Aggregator.php b/docs/examples/Simple_Feed_Aggregator.php deleted file mode 100644 index c28e838..0000000 --- a/docs/examples/Simple_Feed_Aggregator.php +++ /dev/null @@ -1,115 +0,0 @@ -setDirectory($directory); - } - - public function setDirectory($directory) - { - $this->directory = $directory; - foreach (glob($this->directory .'/*.xml') as $feed) { - $this->feeds[basename($feed, '.xml')] = filemtime($feed); - } - } - - public function url2name($url) - { - return preg_replace('/[^\w\.-]+/', '_', $url); - } - - public function hasFeed($url) - { - return isset($this->feeds[$this->url2name($url)]); - } - - public function addFeed($url) - { - $r = $this->setupRequest($url); - $r->send(); - $this->handleResponse($r); - } - - public function addFeeds($urls) - { - $pool = new HttpRequestPool; - foreach ($urls as $url) { - $pool->attach($r = $this->setupRequest($url)); - } - $pool->send(); - - foreach ($pool as $request) { - $this->handleResponse($request); - } - } - - public function getFeed($url) - { - $this->addFeed($url); - return $this->loadFeed($this->url2name($url)); - } - - public function getFeeds($urls) - { - $feeds = array(); - $this->addFeeds($urls); - foreach ($urls as $url) { - $feeds[] = $this->loadFeed($this->url2name($url)); - } - return $feeds; - } - - protected function saveFeed($file, $contents) - { - if (file_put_contents($this->directory .'/'. $file .'.xml', $contents)) { - $this->feeds[$file] = time(); - } else { - throw new Exception("Could not save feed contents to $file.xml"); - } - } - - protected function loadFeed($file) - { - if (isset($this->feeds[$file])) { - if ($data = file_get_contents($this->directory .'/'. $file .'.xml')) { - return $data; - } else { - throw new Exception("Could not load feed contents from $file.xml"); - } - } else { - throw new Exception("Unknown feed/file $file.xml"); - } - } - - protected function setupRequest($url) - { - $r = new HttpRequest($url); - $r->setOptions(array('redirect' => true)); - - $file = $this->url2name($url); - - if (isset($this->feeds[$file])) { - $r->setOptions(array('lastmodified' => $this->feeds[$file])); - } - - return $r; - } - - protected function handleResponse(HttpRequest $r) - { - if ($r->getResponseCode() != 304) { - if ($r->getResponseCode() != 200) { - throw new Exception("Unexpected response code ". $r->getResponseCode()); - } - if (!strlen($body = $r->getResponseBody())) { - throw new Exception("Received empty feed from ". $r->getUrl()); - } - $this->saveFeed($this->url2name($r->getUrl()), $body); - } - } -} -?> diff --git a/docs/examples/extract.php b/docs/examples/extract.php deleted file mode 100644 index 466c544..0000000 --- a/docs/examples/extract.php +++ /dev/null @@ -1,12 +0,0 @@ -)/s', file_get_contents($_SERVER['argv'][1]), $matches)) { - for ($i = 0; $i < count($matches[0]); $i++) { - file_put_contents(preg_replace('/\W/', '_', $matches[1][$i]).".php", $matches[2][$i]."\n"); - } -} - -?> diff --git a/docs/examples/tutorial.txt b/docs/examples/tutorial.txt deleted file mode 100644 index b29fa96..0000000 --- a/docs/examples/tutorial.txt +++ /dev/null @@ -1,342 +0,0 @@ - -A Beginners Tutorial --------------------- -$Revision$ - - -- GET Queries - - The HttpRequest class can be used to execute any HTTP request method. - The following example shows a simple GET request where a few query - parameters are supplied. Additionally potential cookies will be - read from and written to a file. - -setOptions( - array( 'cookiestore' => '../cookies/google.txt', - ) -); - -$r->setQueryData( - array( 'q' => '+"pecl_http" -msg -cvs -list', - 'hl' => 'de' - ) -); - -// HttpRequest::send() returns an HttpMessage object -// of type HttpMessage::RESPONSE or throws an exception -try { - print $r->send()->getBody(); -} catch (HttpException $e) { - print $e; -} -?> - -- Multipart Posts - - The following example shows an multipart POST request, with two form - fields and an image that's supposed to be uploaded to the server. - It's a bad habit as well as common practice to issue a redirect after - an received POST request, so we'll allow a redirect by enabling the - redirect option. - -setOptions( - array( 'cookies' => array('MyCookie' => 'has a value'), - 'redirect' => true, - ) -); - -// common form data -$r->setPostFields( - array( 'name' => 'Mike', - 'mail' => 'mike@php.net', - ) -); -// add the file to post (form name, file name, file type) -$r->addPostFile('image', 'profile.jpg', 'image/jpeg'); - -try { - print $r->send()->getBody(); -} catch (HttpException $e) { - print $e; -} -?> - -- Parallel Requests - - It's possible to execute several HttpRequests in parallel with the - HttpRequestPool class. HttpRequests to send, do not need to perform - the same request method, but can only be attached to one HttpRequestPool - at the same time. - -attach(new HttpRequest('http://pear.php.net', HTTP_METH_HEAD)); - $p->attach(new HttpRequest('http://pecl.php.net', HTTP_METH_HEAD)); -} catch (HttpException $e) { - print $e; - exit; -} - -try { - $p->send(); - // HttpRequestPool implements an iterator over attached HttpRequest objects - foreach ($p as $r) { - echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n"; - } -} catch (HttpException $e) { - print $e; -} -?> - -- Parallel Requests? - - You can use a more advanced approach by using the protected interface of - the HttpRequestPool class. This allows you to perform some other tasks - while the requests are executed. - -socketPerform(); $i++) { - $i % 10 or print "."; - if (!$this->socketSelect()) { - throw new HttpException("Socket error!"); - } - } - print "\nDone!\n"; - } -} - -try { - foreach (new Pool as $r) { - echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n"; - } -} catch (HttpException $ex) { - print $e; -} -?> - -- Cached Responses - - One of the main key features of HttpResponse is HTTP caching. HttpResponse - will calculate an ETag based on the http.etag_mode INI setting as well as - it will determine the last modification time of the sent entity. It uses - those two indicators to decide if the cache entry on the client side is - still valid and will emit an "304 Not Modified" response if applicable. - - - -- Bandwidth Throttling - - HttpResponse supports a basic throttling mechanism, which is enabled by - setting a throttle delay and a buffer size. PHP will sleep the specified - amount of seconds after each sent chunk of specified bytes. - - - -Exemplar Use Cases ------------------- - -- KISS XMLRPC Client - -namespace = $namespace; - $this->request = new HttpRequest($url, HTTP_METH_POST); - $this->request->setContentType('text/xml'); - } - - public function setOptions($options = array()) - { - return $this->request->setOptions($options); - } - - public function addOptions($options) - { - return $this->request->addOptions($options); - } - - public function __call($method, $params) - { - if ($this->namespace) { - $method = $this->namespace .'.'. $method; - } - $this->request->setPostData(xmlrpc_encode_request($method, $params)); - $response = $this->request->send(); - if ($response->getResponseCode() != 200) { - throw new Exception($response->getBody(), $response->getResponseCode()); - } - return xmlrpc_decode($response->getBody(), 'utf-8'); - } - - public function getHistory() - { - return $this->request->getHistory(); - } -} - -?> - -- Simple Feed Aggregator - -setDirectory($directory); - } - - public function setDirectory($directory) - { - $this->directory = $directory; - foreach (glob($this->directory .'/*.xml') as $feed) { - $this->feeds[basename($feed, '.xml')] = filemtime($feed); - } - } - - public function url2name($url) - { - return preg_replace('/[^\w\.-]+/', '_', $url); - } - - public function hasFeed($url) - { - return isset($this->feeds[$this->url2name($url)]); - } - - public function addFeed($url) - { - $r = $this->setupRequest($url); - $r->send(); - $this->handleResponse($r); - } - - public function addFeeds($urls) - { - $pool = new HttpRequestPool; - foreach ($urls as $url) { - $pool->attach($r = $this->setupRequest($url)); - } - $pool->send(); - - foreach ($pool as $request) { - $this->handleResponse($request); - } - } - - public function getFeed($url) - { - $this->addFeed($url); - return $this->loadFeed($this->url2name($url)); - } - - public function getFeeds($urls) - { - $feeds = array(); - $this->addFeeds($urls); - foreach ($urls as $url) { - $feeds[] = $this->loadFeed($this->url2name($url)); - } - return $feeds; - } - - protected function saveFeed($file, $contents) - { - if (file_put_contents($this->directory .'/'. $file .'.xml', $contents)) { - $this->feeds[$file] = time(); - } else { - throw new Exception("Could not save feed contents to $file.xml"); - } - } - - protected function loadFeed($file) - { - if (isset($this->feeds[$file])) { - if ($data = file_get_contents($this->directory .'/'. $file .'.xml')) { - return $data; - } else { - throw new Exception("Could not load feed contents from $file.xml"); - } - } else { - throw new Exception("Unknown feed/file $file.xml"); - } - } - - protected function setupRequest($url) - { - $r = new HttpRequest($url); - $r->setOptions(array('redirect' => true)); - - $file = $this->url2name($url); - - if (isset($this->feeds[$file])) { - $r->setOptions(array('lastmodified' => $this->feeds[$file])); - } - - return $r; - } - - protected function handleResponse(HttpRequest $r) - { - if ($r->getResponseCode() != 304) { - if ($r->getResponseCode() != 200) { - throw new Exception("Unexpected response code ". $r->getResponseCode()); - } - if (!strlen($body = $r->getResponseBody())) { - throw new Exception("Received empty feed from ". $r->getUrl()); - } - $this->saveFeed($this->url2name($r->getUrl()), $body); - } - } -} -?> - - diff --git a/docs/functions.html b/docs/functions.html deleted file mode 100644 index 16dd0a5..0000000 --- a/docs/functions.html +++ /dev/null @@ -1,525 +0,0 @@ - - - Function Summary of ext/http - - -

http_functions.c

-

string http_date([int timestamp])

-

This function returns a valid HTTP date regarding RFC 822/1123
-looking like: "Wed, 22 Dec 2004 11:34:47 GMT"

-

string http_absolute_uri(string url[, string proto[, string host[, int port]]])

-

This function returns an absolute URI constructed from url.
-If the url is already abolute but a different proto was supplied,
-only the proto part of the URI will be updated. If url has no
-path specified, the path of the current REQUEST_URI will be taken.
-The host will be taken either from the Host HTTP header of the client
-the SERVER_NAME or just localhost if prior are not available.
-
-Some examples:

 url = "page.php"                    => http://www.example.com/current/path/page.php
- url = "/page.php" => http://www.example.com/page.php
- url = "/page.php", proto = "https" => https://www.example.com/page.php
-

-

string http_negotiate_language(array supported[, string default = 'en-US'])

-

This function negotiates the clients preferred language based on its
-Accept-Language HTTP header. It returns the negotiated language or
-the default language if none match.
-
-The qualifier is recognized and languages without qualifier are rated highest.
-
-The supported parameter is expected to be an array having
-the supported languages as array values.
-
-Example:


-<?php
$langs 
= array(
        
'en-US',// default
        
'fr',
        
'fr-FR',
        
'de',
        
'de-DE',
        
'de-AT',
        
'de-CH',
);
include 
'./langs/'http_negotiate_language($langs) .'.php';
?>
-

-

-
-

-

string http_negotiate_charset(array supported[, string default = 'iso-8859-1'])

-

This function negotiates the clients preferred charset based on its
-Accept-Charset HTTP header. It returns the negotiated charset or
-the default charset if none match.
-
-The qualifier is recognized and charset without qualifier are rated highest.
-
-The supported parameter is expected to be an array having
-the supported charsets as array values.
-
-Example:


-<?php
$charsets 
= array(
        
'iso-8859-1'// default
        
'iso-8859-2',
        
'iso-8859-15',
        
'utf-8'
);
$pref http_negotiate_charset($charsets);
if (!
strcmp($pref'iso-8859-1')) {
        
iconv_set_encoding('internal_encoding''iso-8859-1');
        
iconv_set_encoding('output_encoding'$pref);
        
ob_start('ob_iconv_handler');
}
?>
-

-

-
-

-

bool http_send_status(int status)

-

Send HTTP status code.

-

bool http_send_last_modified([int timestamp])

-

This converts the given timestamp to a valid HTTP date and
-sends it as "Last-Modified" HTTP header. If timestamp is
-omitted, current time is sent.

-

bool http_send_content_type([string content_type = 'application/x-octetstream'])

-

Sets the content type.

-

bool http_send_content_disposition(string filename[, bool inline = false])

-

Set the Content Disposition. The Content-Disposition header is very useful
-if the data actually sent came from a file or something similar, that should
-be "saved" by the client/user (i.e. by browsers "Save as..." popup window).

-

bool http_match_modified([int timestamp[, for_range = false]])

-

Matches the given timestamp against the clients "If-Modified-Since" resp.
-"If-Unmodified-Since" HTTP headers.

-

bool http_match_etag(string etag[, for_range = false])

-

This matches the given ETag against the clients
-"If-Match" resp. "If-None-Match" HTTP headers.

-

bool http_cache_last_modified([int timestamp_or_expires]])

-

If timestamp_or_expires is greater than 0, it is handled as timestamp
-and will be sent as date of last modification. If it is 0 or omitted,
-the current time will be sent as Last-Modified date. If it's negative,
-it is handled as expiration time in seconds, which means that if the
-requested last modification date is not between the calculated timespan,
-the Last-Modified header is updated and the actual body will be sent.

-

bool http_cache_etag([string etag])

-

This function attempts to cache the HTTP body based on an ETag,
-either supplied or generated through calculation of the MD5
-checksum of the output (uses output buffering).
-
-If clients "If-None-Match" header matches the supplied/calculated
-ETag, the body is considered cached on the clients side and
-a "304 Not Modified" status code is issued.

-

string ob_etaghandler(string data, int mode)

-

For use with ob_start().

-

void http_throttle(double sec[, long bytes = 2097152])

-

Use with http_send() API.
-
-Example:


-<?php
// ~ 20 kbyte/s
# http_throttle(1, 20000);
# http_throttle(0.5, 10000);
# http_throttle(0.1, 2000);
http_send_file('document.pdf');
?>
-

-

-
-

-

void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])

-

Redirect to a given url.
-The supplied url will be expanded with http_absolute_uri(), the params array will
-be treated with http_build_query() and the session identification will be appended
-if session is true.
-
-Depending on permanent the redirection will be issued with a permanent
-("301 Moved Permanently") or a temporary ("302 Found") redirection
-status code.
-
-To be RFC compliant, "Redirecting to URI." will be displayed,
-if the client doesn't redirect immediatly.

-

bool http_send_data(string data)

-

Sends raw data with support for (multiple) range requests.

-

bool http_send_file(string file)

-

Sends a file with support for (multiple) range requests.

-

bool http_send_stream(resource stream)

-

Sends an already opened stream with support for (multiple) range requests.

-

string http_chunked_decode(string encoded)

-

This function decodes a string that was HTTP-chunked encoded.
-Returns false on failure.

-

object http_parse_message(string message)

-

Parses (a) http_message(s) into a simple recursive object structure:


-<?php
print_r
(http_parse_message(http_get(URL, array('redirect' => 3)));

stdClass object
(
    [
type] => 2
    
[httpVersion] => 1.1
    
[responseCode] => 200
    
[headers] => Array 
        (
            [
Content-Length] => 3
            
[Server] => Apache
        
)
    [
body]  => Hi!
    [
parentMessage] => stdClass object
    
(
        [
type] => 2
        
[httpVersion] => 1.1
        
[responseCode] => 302
        
[headers] => Array 
            (
                [
Content-Length] => 0
                
[Location] => ...
            )
        [
body]  => 
        [
parentMessage] => ...
    )
)
?>
-

-

-
-

-

array http_parse_headers(string header)

-

-

array http_get_request_headers(void)

-

Get a list of incoming HTTP headers.

-

string http_get_request_body(void)

-

Get the raw request body (e.g. POST or PUT data).

-

bool http_match_request_header(string header, string value[, bool match_case = false])

-

Match an incoming HTTP header.

-

string http_get(string url[, array options[, array &info]])

-

Performs an HTTP GET request on the supplied url.
-
-The second parameter is expected to be an associative
-array where the following keys will be recognized:

 - redirect:         int, whether and how many redirects to follow
- - unrestrictedauth: bool, whether to continue sending credentials on
- redirects to a different host
- - proxyhost: string, proxy host in "host[:port]" format
- - proxyport: int, use another proxy port as specified in proxyhost
- - proxyauth: string, proxy credentials in "user:pass" format
- - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
- - httpauth: string, http credentials in "user:pass" format
- - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
- - compress: bool, whether to allow gzip/deflate content encoding
- (defaults to true)
- - port: int, use another port as specified in the url
- - referer: string, the referer to sends
- - useragent: string, the user agent to send
- (defaults to PECL::HTTP/version (PHP/version)))
- - headers: array, list of custom headers as associative array
- like array("header" => "value")
- - cookies: array, list of cookies as associative array
- like array("cookie" => "value")
- - cookiestore: string, path to a file where cookies are/will be stored
- - resume: int, byte offset to start the download from;
- if the server supports ranges
- - maxfilesize: int, maximum file size that should be downloaded;
- has no effect, if the size of the requested entity is not known
- - lastmodified: int, timestamp for If-(Un)Modified-Since header
- - timeout: int, seconds the request may take
- - connecttimeout: int, seconds the connect may take
- - onprogress: mixed, progress callback

The optional third parameter will be filled with some additional information
-in form af an associative array, if supplied, like the following example:


-<?php
array (
    
'effective_url' => 'http://localhost',
    
'response_code' => 403,
    
'total_time' => 0.017,
    
'namelookup_time' => 0.013,
    
'connect_time' => 0.014,
    
'pretransfer_time' => 0.014,
    
'size_upload' => 0,
    
'size_download' => 202,
    
'speed_download' => 11882,
    
'speed_upload' => 0,
    
'header_size' => 145,
    
'request_size' => 62,
    
'ssl_verifyresult' => 0,
    
'filetime' => -1,
    
'content_length_download' => 202,
    
'content_length_upload' => 0,
    
'starttransfer_time' => 0.017,
    
'content_type' => 'text/html; charset=iso-8859-1',
    
'redirect_time' => 0,
    
'redirect_count' => 0,
    
'http_connectcode' => 0,
    
'httpauth_avail' => 0,
    
'proxyauth_avail' => 0,
)
?>
-

-

-
-

-

string http_head(string url[, array options[, array &info]])

-

Performs an HTTP HEAD request on the suppied url.
-Returns the HTTP response as string.
-See http_get() for a full list of available options.

-

string http_post_data(string url, string data[, array options[, array &info]])

-

Performs an HTTP POST request, posting data.
-Returns the HTTP response as string.
-See http_get() for a full list of available options.

-

string http_post_fields(string url, array data[, array files[, array options[, array &info]]])

-

Performs an HTTP POST request, posting www-form-urlencoded array data.
-Returns the HTTP response as string.
-See http_get() for a full list of available options.

-

string http_put_file(string url, string file[, array options[, array &info]])

-

Performs an HTTP PUT request, uploading file.
-Returns the HTTP response as string.
-See http_get() for a full list of available options.

-

string http_put_stream(string url, resource stream[, array options[, array &info]])

-

Performs an HTTP PUT request, uploading stream.
-Returns the HTTP response as string.
-See http_get() for a full list of available options.

-

long http_request_method_register(string method)

-

Register a custom request method.

-

bool http_request_method_unregister(mixed method)

-

Unregister a previously registered custom request method.

-

long http_request_method_exists(mixed method)

-

Check if a request method is registered (or available by default).

-

string http_request_method_name(long method)

-

Get the literal string representation of a standard or registered request method.

-

string http_build_query(mixed formdata [, string prefix[, string arg_separator]])

-

Generates a form-encoded query string from an associative array or object.

-
-

http_message_object.c

-

HttpMessage

-

void HttpMessage::__construct([string message])

-

Instantiate a new HttpMessage object.

-

static HttpMessage HttpMessage::fromString(string raw_message)

-

Create an HttpMessage object from a string.

-

string HttpMessage::getBody()

-

Get the body of the parsed Message.

-

array HttpMessage::getHeaders()

-

Get Message Headers.

-

void HttpMessage::setHeaders(array headers)

-

Sets new headers.

-

void HttpMessage::addHeaders(array headers[, bool append = false])

-

Add headers. If append is true, headers with the same name will be separated, else overwritten.

-

long HttpMessage::getType()

-

Get Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE)

-

void HttpMessage::setType(long type)

-

Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE)

-

long HttpMessage::getResponseCode()

-

Get the Response Code of the Message.

-

bool HttpMessage::setResponseCode(long code)

-

Set the response code of an HTTP Response Message.
-Returns false if the Message is not of type HTTP_MSG_RESPONSE,
-or if the response code is out of range (100-510).

-

string HttpMessage::getRequestMethod()

-

Get the Request Method of the Message.
-Returns false if the Message is not of type HTTP_MSG_REQUEST.

-

bool HttpMessage::setRequestMethod(string method)

-

Set the Request Method of the HTTP Message.
-Returns false if the Message is not of type HTTP_MSG_REQUEST.

-

string HttpMessage::getRequestUri()

-

Get the Request URI of the Message.

-

bool HttpMessage::setRequestUri(string URI)

-

Set the Request URI of the HTTP Message.
-Returns false if the Message is not of type HTTP_MSG_REQUEST,
-or if paramtere URI was empty.

-

string HttpMessage::getHttpVersion()

-

Get the HTTP Protocol Version of the Message.

-

bool HttpMessage::setHttpVersion(string version)

-

Set the HTTP Protocol version of the Message.
-Returns false if version is invalid (1.0 and 1.1).

-

HttpMessage HttpMessage::getParentMessage()

-

Get parent Message.

-

bool HttpMessage::send()

-

Send the Message according to its type as Response or Request.

-

string HttpMessage::toString([bool include_parent = true])

-

Get the string representation of the Message.

-
-

http_request_object.c

-

HttpRequest

-

void HttpRequest::__construct([string url[, long request_method = HTTP_GET]])

-

Instantiate a new HttpRequest object which can be used to issue HEAD, GET
-and POST (including posting files) HTTP requests.

-

void HttpRequest::__destruct()

-

Destroys the HttpRequest object.

-

bool HttpRequest::setOptions([array options])

-

Set the request options to use. See http_get() for a full list of available options.

-

array HttpRequest::getOptions()

-

Get currently set options.

-

bool HttpRequest::setSslOptions([array options])

-

Set SSL options.

-

bool HttpRequest::addSslOptions(array options)

-

Set additional SSL options.

-

array HttpRequest::getSslOtpions()

-

Get previously set SSL options.

-

bool HttpRequest::addHeaders(array headers)

-

Add request header name/value pairs.

-

bool HttpRequest::setHeaders([array headers])

-

Set request header name/value pairs.

-

array HttpRequest::getHeaders()

-

Get previously set request headers.

-

bool HttpRequest::setCookies([array cookies])

-

Set cookies.

-

bool HttpRequest::addCookies(array cookies)

-

Add cookies.

-

array HttpRequest::getCookies()

-

Get previously set cookies.

-

bool HttpRequest::setUrl(string url)

-

Set the request URL.

-

string HttpRequest::getUrl()

-

Get the previously set request URL.

-

bool HttpRequest::setMethod(long request_method)

-

Set the request methods; one of the HTTP_HEAD, HTTP_GET or
-HTTP_POST constants.

-

long HttpRequest::getMethod()

-

Get the previously set request method.

-

bool HttpRequest::setContentType(string content_type)

-

Set the content type the post request should have.
-Use this only if you know what you're doing.

-

string HttpRequest::getContentType()

-

Get the previously content type.

-

bool HttpRequest::setQueryData([mixed query_data])

-

Set the URL query parameters to use.
-Overwrites previously set query parameters.
-Affects any request types.

-

string HttpRequest::getQueryData()

-

Get the current query data in form of an urlencoded query string.

-

bool HttpRequest::addQueryData(array query_params)

-

Add parameters to the query parameter list.
-Affects any request type.

-

bool HttpRequest::addPostFields(array post_data)

-

Adds POST data entries.
-Affects only POST requests.

-

bool HttpRequest::setPostFields([array post_data])

-

Set the POST data entries.
-Overwrites previously set POST data.
-Affects only POST requests.

-

array HttpRequest::getPostFields()

-

Get previously set POST data.

-

bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])

-

Add a file to the POST request.
-Affects only POST requests.

-

bool HttpRequest::setPostFiles([array post_files])

-

Set files to post.
-Overwrites previously set post files.
-Affects only POST requests.

-

array HttpRequest::getPostFiles()

-

Get all previously added POST files.

-

bool HttpRequest::setPutFile([string file])

-

Set file to put.
-Affects only PUT requests.

-

string HttpRequest::getPutFile()

-

Get previously set put file.

-

array HttpRequest::getResponseData()

-

Get all response data after the request has been sent.

-

mixed HttpRequest::getResponseHeader([string name])

-

Get response header(s) after the request has been sent.

-

array HttpRequest::getResponseCookie([string name])

-

Get response cookie(s) after the request has been sent.

-

string HttpRequest::getResponseBody()

-

Get the response body after the request has been sent.

-

int HttpRequest::getResponseCode()

-

Get the response code after the request has been sent.

-

array HttpRequest::getResponseInfo([string name])

-

Get response info after the request has been sent.
-See http_get() for a full list of returned info.

-

HttpMessage HttpRequest::getResponseMessage()

-

Get the full response as HttpMessage object.

-

HttpMessage HttpRequest::getRequestMessage()

-

Get sent HTTP message.

-

HttpMessage HttpRequest::send()

-

Send the HTTP request.
-
-GET example:


-<?php
$r 
= new HttpRequest('http://example.com/feed.rss'HTTP_GET);
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
    
$r->send();
    if (
$r->getResponseCode() == 200) {
        
file_put_contents('local.rss'$r->getResponseBody());
   }
} catch (
HttpException $ex) {
    echo 
$ex;
}
?>
-

-

POST example:


-<?php
$r 
= new HttpRequest('http://example.com/form.php'HTTP_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike''pass' => 's3c|r3t'));
$r->addPostFile('image''profile.jpg''image/jpeg');
try {
    echo 
$r->send()->getBody();
} catch (
HttpException $ex) {
    echo 
$ex;
}
?>
-

-

-
-

-
-

http_requestpool_object.c

-

HttpRequestPool

-

void HttpRequestPool::__construct([HttpRequest request[, ...]])

-

Instantiate a new HttpRequestPool object. An HttpRequestPool is
-able to send several HttpRequests in parallel.
-
-Example:


-<?php
try {
    
$pool = new HttpRequestPool(
        new 
HttpRequest('http://www.google.com/'HTTP_HEAD),
        new 
HttpRequest('http://www.php.net/'HTTP_HEAD)
    );
    
$pool->send();
    foreach(
$pool as $request) {
        
printf("%s is %s (%d)\n",
            
$request->getUrl(),
            
$request->getResponseCode() ? 'alive' 'not alive',
            
$request->getResponseCode()
        );
    }
} catch (
HttpException $e) {
    echo 
$e;
}
?>
-

-

-
-

-

void HttpRequestPool::__destruct()

-

Clean up HttpRequestPool object.

-

void HttpRequestPool::reset()

-

Detach all attached HttpRequest objects.

-

bool HttpRequestPool::attach(HttpRequest request)

-

Attach an HttpRequest object to this HttpRequestPool.
-NOTE: set all options prior attaching!

-

bool HttpRequestPool::detach(HttpRequest request)

-

Detach an HttpRequest object from this HttpRequestPool.

-

bool HttpRequestPool::send()

-

Send all attached HttpRequest objects in parallel.

-

protected bool HttpRequestPool::socketSend()

-

Usage:


-<?php
    
while ($pool->socketPerform()) {
        
do_something_else();
        if (!
$pool->socketSelect()) {
            die(
'Socket error');
        }
    }
?>
-

-

-
-

-

protected bool HttpRequestPool::socketSelect()

-

See HttpRequestPool::socketPerform().

-

bool HttpRequestPool::valid()

-

Implements Iterator::valid().

-

HttpRequest HttpRequestPool::current()

-

Implements Iterator::current().

-

long HttpRequestPool::key()

-

Implements Iterator::key().

-

void HttpRequestPool::next()

-

Implements Iterator::next().

-

void HttpRequestPool::rewind()

-

Implements Iterator::rewind().

-
-

http_response_object.c

-

static bool HttpResponse::setHeader(string name, mixed value[, bool replace = true)

-

-

static mixed HttpResponse::getHeader([string name])

-

-

static bool HttpResponse::setCache(bool cache)

-

Whether it sould be attempted to cache the entitity.
-This will result in necessary caching headers and checks of clients
-"If-Modified-Since" and "If-None-Match" headers. If one of those headers
-matches a "304 Not Modified" status code will be issued.
-
-NOTE: If you're using sessions, be shure that you set session.cache_limiter
-to something more appropriate than "no-cache"!

-

static bool HttpResponse::getCache()

-

Get current caching setting.

-

static bool HttpResponse::setGzip(bool gzip)

-

Enable on-thy-fly gzipping of the sent entity.

-

static bool HttpResponse::getGzip()

-

Get current gzipping setting.

-

static bool HttpResponse::setCacheControl(string control[, long max_age = 0])

-

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.

-

static string HttpResponse::getCacheControl()

-

Get current Cache-Control header setting.

-

static bool HttpResponse::setContentType(string content_type)

-

Set the content-type of the sent entity.

-

static string HttpResponse::getContentType()

-

Get current Content-Type header setting.

-

static bool HttpResponse::setContentDisposition(string filename[, bool inline = false])

-

Set the Content-Disposition of the sent entity. This setting aims to suggest
-the receiveing user agent how to handle the sent entity; usually the client
-will show the user a "Save As..." popup.

-

static string HttpResponse::getContentDisposition()

-

Get current Content-Disposition setting.

-

static bool HttpResponse::setETag(string etag)

-

Set a custom ETag. Use this only if you know what you're doing.

-

static string HttpResponse::getETag()

-

Get calculated or previously set custom ETag.

-

static bool HttpResponse::setLastModified(long timestamp)

-

Set a custom Last-Modified date.

-

static HttpResponse::getLastModified()

-

Get calculated or previously set custom Last-Modified date.

-

static bool HttpResponse::setThrottleDelay(double seconds)

-

-

static double HttpResponse::getThrottleDelay()

-

-

static bool HttpResponse::setBufferSize(long bytes)

-

-

static long HttpResponse::getBufferSize()

-

-

static bool HttpResponse::setData(string data)

-

Set the data to be sent.

-

static string HttpResponse::getData()

-

Get the previously set data to be sent.

-

static bool HttpResponse::setStream(resource stream)

-

Set the resource to be sent.

-

static resource HttpResponse::getStream()

-

Get the previously set resource to be sent.

-

static bool HttpResponse::setFile(string file)

-

Set the file to be sent.

-

static string HttpResponse::getFile()

-

Get the previously set file to be sent.

-

static bool HttpResponse::send([bool clean_ob = true])

-

Finally send the entity.
-
-Example:


-<?php
HttpResponse
::setCache(true);
HttpResponse::setContentType('application/pdf');
HttpResponse::setContentDisposition("$user.pdf"false);
HttpResponse::setFile('sheet.pdf');
HttpResponse::send();
?>
-

-

-
-

-

static void HttpResponse::capture()

-

Capture script output.
-
-Example:


-<?php
HttpResponse
::setCache(true);
HttpResponse::capture();
// script follows
// note that you need to call
HttpResponse::send();
// at the end of the script unless 
// you use PHP-5.1 or greater
?>
-

-

-
-

-
-

Generated at: Fri, 26 Aug 2005 11:08:03 +0000

- - - diff --git a/docs/http.ini b/docs/http.ini deleted file mode 100644 index 73c909c..0000000 --- a/docs/http.ini +++ /dev/null @@ -1,30 +0,0 @@ -; example INI file for pecl/http -; $Id$ - -[http] -; enable if you want to transform all errors to exceptions (PHP >= 5 only) -http.only_exceptions = 0 - -; the hashing algorithm with wich ETags are generated -; you can use mhash constants if ext/mhash is enabled, or their -; literal representation if ext/http was linked against libmhash -;http.etag_mode = MHASH_TIGER ; same as 7 -http.etag_mode = HTTP_ETAG_MD5 - -; allowed request methods -; by default PHP ignores unkown request methods -; PHP will exit with a response status of 405 and an Allow header -; if it encounters a request method not contained in the specified list -;http.allowed_methods = "HEAD, GET, POST" - -; log file for positive cache hits -;http.cache_log = - -; log file for redirects -;http.redirect_log = - -; log file for requests with an unallowed request method -;http.allowed_methods_log = - -; composite log file (i.e. log all messages to this file) -;http.composite_log = diff --git a/funcsummary.php b/funcsummary.php deleted file mode 100644 index 0a4e858..0000000 --- a/funcsummary.php +++ /dev/null @@ -1,117 +0,0 @@ -%s\n", highlight_string($m[1], true)); -} -function mf($f, &$m) -{ - return preg_match_all( - '/\/\* *\{\{\{ *proto (.*?)(\n|$)(.*?)PHP_(?:FUNCTION|METHOD)\((.*?)\)/s', - file_get_contents($f), $m); -} -function ff($t) -{ - $t = preg_replace('/^ \* /m', '', trim($t, "*/ \n")); - $t = preg_replace_callback('/(\<\?php.*?\?\>)/s', 'hl', $t); - $t = nl2br(preg_replace('/\n *\* */', "\n", $t)); - $t = preg_replace('/(\
\n)+\(\
\n)+/', '

', $t);
-    $t = preg_replace('/(\
\n)+\<\/pre\>(\
\n)+/', '

', $t); - return sprintf('

%s

', ltrim($t, ' *')); -} -function e($s) -{ - $a = func_get_args(); - array_unshift($a, STDERR); - call_user_func_array('fprintf', $a); -} - -$preface = <<<_PREFACE - - - Function Summary of ext/%s - - - -_PREFACE; - -$footer = <<<_FOOTER -

Generated at: %s

- - - -_FOOTER; - -if ($_SERVER['argc'] < 2) { - die("Usage: {$_SERVER['argv'][0]} [ ...]\n"); -} - -printf($preface, basename(getcwd())); - -foreach (array_slice($_SERVER['argv'], 1) as $fp) { - foreach (glob($fp) as $f) { - - if (mf($f, $m)) { - e("\nAnalyzing %s\n", basename($f)); - printf("

%s

\n", basename($f)); - foreach ($m[1] as $i => $p) { - e("Documenting $p\n"); - if ($o = preg_match('/^(.*), (.*)$/', $m[4][$i], $n)) { - if ($n[2] == '__construct') { - printf("

%s

\n", $n[1], $n[1]); - } - } - printf("%s\n%s\n", - $o?3:2, $o?$n[1].'_'.$n[2]:$m[4][$i], $p, $o?3:2, ff($m[3][$i])); - } - print "
\n"; - } - } -} - -printf($footer, date('r')); -e("\nDone\n"); -?> - diff --git a/http.c b/http.c deleted file mode 100644 index 5d0491a..0000000 --- a/http.c +++ /dev/null @@ -1,450 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "SAPI.h" -#include "php_ini.h" -#include "ext/standard/info.h" - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_send_api.h" -#include "php_http_cache_api.h" -#include "php_http_request_method_api.h" -#ifdef HTTP_HAVE_CURL -# include "php_http_request_api.h" -#endif - -#ifdef ZEND_ENGINE_2 -# include "php_http_util_object.h" -# include "php_http_message_object.h" -# ifndef WONKY -# include "php_http_response_object.h" -# endif -# ifdef HTTP_HAVE_CURL -# include "php_http_request_object.h" -# include "php_http_requestpool_object.h" -# endif -# include "php_http_exception_object.h" -#endif - -#include "missing.h" -#include "phpstr/phpstr.h" - -#ifdef HTTP_HAVE_CURL -# ifdef PHP_WIN32 -# include -# endif -# include -#endif -#ifdef HTTP_HAVE_MHASH -# include -#endif - -#include - -ZEND_DECLARE_MODULE_GLOBALS(http); -HTTP_DECLARE_ARG_PASS_INFO(); - -#ifdef COMPILE_DL_HTTP -ZEND_GET_MODULE(http) -#endif - -/* {{{ http_functions[] */ -zend_function_entry http_functions[] = { - PHP_FE(http_test, NULL) - PHP_FE(http_date, NULL) - PHP_FE(http_absolute_uri, NULL) - PHP_FE(http_negotiate_language, NULL) - PHP_FE(http_negotiate_charset, NULL) - PHP_FE(http_redirect, NULL) - PHP_FE(http_throttle, NULL) - PHP_FE(http_send_status, NULL) - PHP_FE(http_send_last_modified, NULL) - PHP_FE(http_send_content_type, NULL) - PHP_FE(http_send_content_disposition, NULL) - PHP_FE(http_match_modified, NULL) - PHP_FE(http_match_etag, NULL) - PHP_FE(http_cache_last_modified, NULL) - PHP_FE(http_cache_etag, NULL) - PHP_FE(http_send_data, NULL) - PHP_FE(http_send_file, NULL) - PHP_FE(http_send_stream, NULL) - PHP_FE(http_chunked_decode, NULL) - PHP_FE(http_parse_message, NULL) - PHP_FE(http_parse_headers, NULL) - PHP_FE(http_get_request_headers, NULL) - PHP_FE(http_get_request_body, NULL) - PHP_FE(http_match_request_header, NULL) -#ifdef HTTP_HAVE_CURL - PHP_FE(http_get, http_arg_pass_ref_3) - PHP_FE(http_head, http_arg_pass_ref_3) - PHP_FE(http_post_data, http_arg_pass_ref_4) - PHP_FE(http_post_fields, http_arg_pass_ref_5) - PHP_FE(http_put_file, http_arg_pass_ref_4) - PHP_FE(http_put_stream, http_arg_pass_ref_4) -#endif - PHP_FE(http_request_method_register, NULL) - PHP_FE(http_request_method_unregister, NULL) - PHP_FE(http_request_method_exists, NULL) - PHP_FE(http_request_method_name, NULL) -#ifndef ZEND_ENGINE_2 - PHP_FE(http_build_query, NULL) -#endif - PHP_FE(ob_etaghandler, NULL) - - EMPTY_FUNCTION_ENTRY -}; -/* }}} */ - -/* {{{ http_module_entry */ -zend_module_entry http_module_entry = { -#if ZEND_MODULE_API_NO >= 20010901 - STANDARD_MODULE_HEADER, -#endif - "http", - http_functions, - PHP_MINIT(http), - PHP_MSHUTDOWN(http), - PHP_RINIT(http), - PHP_RSHUTDOWN(http), - PHP_MINFO(http), -#if ZEND_MODULE_API_NO >= 20010901 - HTTP_PEXT_VERSION, -#endif - STANDARD_MODULE_PROPERTIES -}; -/* }}} */ - -int http_module_number; - -/* {{{ http_globals */ -static void http_globals_init_once(zend_http_globals *G) -{ - memset(G, 0, sizeof(zend_http_globals)); -} - -static inline void http_globals_init(zend_http_globals *G) -{ - G->send.buffer_size = HTTP_SENDBUF_SIZE; - zend_hash_init(&G->request.methods.custom, 0, NULL, ZVAL_PTR_DTOR, 0); -#ifdef HTTP_HAVE_CURL - zend_llist_init(&G->request.copies.strings, sizeof(char *), http_request_data_free_string, 0); - zend_llist_init(&G->request.copies.slists, sizeof(struct curl_slist *), http_request_data_free_slist, 0); - zend_llist_init(&G->request.copies.contexts, sizeof(http_request_callback_ctx *), http_request_data_free_context, 0); - zend_llist_init(&G->request.copies.convs, sizeof(http_request_conv *), http_request_data_free_conv, 0); -#endif -} - -static inline void http_globals_free(zend_http_globals *G) -{ - STR_SET(G->send.content_type, NULL); - STR_SET(G->send.unquoted_etag, NULL); - zend_hash_destroy(&G->request.methods.custom); -#ifdef HTTP_HAVE_CURL - zend_llist_clean(&G->request.copies.strings); - zend_llist_clean(&G->request.copies.slists); - zend_llist_clean(&G->request.copies.contexts); - zend_llist_clean(&G->request.copies.convs); -#endif -} -/* }}} */ - -/* {{{ static inline void http_check_allowed_methods(char *, int) */ -#define http_check_allowed_methods(m, l) _http_check_allowed_methods((m), (l) TSRMLS_CC) -static inline void _http_check_allowed_methods(char *methods, int length TSRMLS_DC) -{ - if (length && SG(request_info).request_method) { - if (SUCCESS != http_check_method_ex(SG(request_info).request_method, methods)) { - char *header = emalloc(length + sizeof("Allow: ")); - sprintf(header, "Allow: %s", methods); - http_exit(405, header); - } - } -} -/* }}} */ - -/* {{{ PHP_INI */ -PHP_INI_MH(http_update_allowed_methods) -{ - http_check_allowed_methods(new_value, new_value_length); - return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); -} - -PHP_INI_DISP(http_etag_mode_displayer) -{ - long value; - - if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { - value = (ini_entry->orig_value) ? atoi(ini_entry->orig_value) : HTTP_ETAG_MD5; - } else if (ini_entry->value) { - value = (ini_entry->value[0]) ? atoi(ini_entry->value) : HTTP_ETAG_MD5; - } else { - value = HTTP_ETAG_MD5; - } - - switch (value) - { - case HTTP_ETAG_CRC32: - ZEND_WRITE("HTTP_ETAG_CRC32", lenof("HTTP_ETAG_CRC32")); - break; - - case HTTP_ETAG_SHA1: - ZEND_WRITE("HTTP_ETAG_SHA1", lenof("HTTP_ETAG_SHA1")); - break; - - case HTTP_ETAG_MD5: -#ifndef HTTP_HAVE_MHASH - default: -#endif - ZEND_WRITE("HTTP_ETAG_MD5", lenof("HTTP_ETAG_MD5")); - break; - -#ifdef HTTP_HAVE_MHASH - default: - { - const char *hash_name = mhash_get_hash_name_static(value); - - if (!hash_name) { - ZEND_WRITE("HTTP_ETAG_MD5", lenof("HTTP_ETAG_MD5")); - } else { - ZEND_WRITE("HTTP_ETAG_MHASH_", lenof("HTTP_ETAG_MHASH_")); - ZEND_WRITE(hash_name, strlen(hash_name)); - } - } - break; -#endif - } -} - -#ifndef ZEND_ENGINE_2 -# define OnUpdateLong OnUpdateInt -#endif - -PHP_INI_BEGIN() - HTTP_PHP_INI_ENTRY("http.allowed_methods", "", PHP_INI_ALL, http_update_allowed_methods, request.methods.allowed) - HTTP_PHP_INI_ENTRY("http.cache_log", "", PHP_INI_ALL, OnUpdateString, log.cache) - HTTP_PHP_INI_ENTRY("http.redirect_log", "", PHP_INI_ALL, OnUpdateString, log.redirect) - HTTP_PHP_INI_ENTRY("http.allowed_methods_log", "", PHP_INI_ALL, OnUpdateString, log.allowed_methods) - HTTP_PHP_INI_ENTRY("http.composite_log", "", PHP_INI_ALL, OnUpdateString, log.composite) -#ifdef ZEND_ENGINE_2 - HTTP_PHP_INI_ENTRY("http.only_exceptions", "0", PHP_INI_ALL, OnUpdateBool, only_exceptions) -#endif - HTTP_PHP_INI_ENTRY_EX("http.etag_mode", "-2", PHP_INI_ALL, OnUpdateLong, http_etag_mode_displayer, etag.mode) -PHP_INI_END() -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION */ -PHP_MINIT_FUNCTION(http) -{ - http_module_number = module_number; - - ZEND_INIT_MODULE_GLOBALS(http, http_globals_init_once, NULL) - - REGISTER_INI_ENTRIES(); - - if (SUCCESS != http_cache_global_init()) { - return FAILURE; - } - if (SUCCESS != http_request_method_global_init()) { - return FAILURE; - } -#ifdef HTTP_HAVE_CURL - if (SUCCESS != http_request_global_init()) { - return FAILURE; - } -#endif /* HTTP_HAVE_CURL */ - -#ifdef ZEND_ENGINE_2 - http_util_object_init(); - http_message_object_init(); -# ifndef WONKY - http_response_object_init(); -# endif -# ifdef HTTP_HAVE_CURL - http_request_object_init(); - http_requestpool_object_init(); -# endif /* HTTP_HAVE_CURL */ - http_exception_object_init(); -#endif /* ZEND_ENGINE_2 */ - - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MSHUTDOWN_FUNCTION */ -PHP_MSHUTDOWN_FUNCTION(http) -{ - UNREGISTER_INI_ENTRIES(); -#ifdef HTTP_HAVE_CURL - http_request_global_cleanup(); -#endif - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_RINIT_FUNCTION */ -PHP_RINIT_FUNCTION(http) -{ - char *m; - - if (m = INI_STR("http.allowed_methods")) { - http_check_allowed_methods(m, strlen(m)); - } - - http_globals_init(HTTP_GLOBALS); - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_RSHUTDOWN_FUNCTION */ -PHP_RSHUTDOWN_FUNCTION(http) -{ -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) - int i, c = zend_hash_num_elements(&HTTP_G(request).methods.custom); - - for (i = 0; i < c; ++i) { - http_request_method_unregister(HTTP_MAX_REQUEST_METHOD + i); - } -#endif - http_globals_free(HTTP_GLOBALS); - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MINFO_FUNCTION */ -PHP_MINFO_FUNCTION(http) -{ - php_info_print_table_start(); - { - php_info_print_table_row(2, "Extended HTTP support", "enabled"); - php_info_print_table_row(2, "Extension Version", HTTP_PEXT_VERSION); -#ifdef HTTP_HAVE_CURL - php_info_print_table_row(2, "cURL HTTP Requests", curl_version()); -#else - php_info_print_table_row(2, "cURL HTTP Requests", "disabled"); -#endif -#ifdef HTTP_HAVE_MHASH - { - char mhash_info[32]; - - snprintf(mhash_info, 32, "libmhash/%d", MHASH_API_VERSION); - php_info_print_table_row(2, "mhash ETag Generator", mhash_info); - } -#else - php_info_print_table_row(2, "mhash ETag Generator", "disabled"); -#endif -#if defined(HTTP_HAVE_MAGIC) && !defined(WONKY) - php_info_print_table_row(2, "magic MIME Guessing", "libmagic/unknown"); -#else - php_info_print_table_row(2, "magic MIME Guessing", "disabled"); -#endif - php_info_print_table_row(2, "Registered Classes", -#ifndef ZEND_ENGINE_2 - "none" -#else - "HttpUtil, " - "HttpMessage, " -# ifdef HTTP_HAVE_CURL - "HttpRequest, " - "HttpRequestPool, " -# endif -# ifndef WONKY - "HttpResponse" -# endif -#endif - ); - } - php_info_print_table_end(); - - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "Supported ETag Hash Algorithms"); - { - - php_info_print_table_row(2, "PHP", "CRC32, MD5, SHA1"); -#ifdef HTTP_HAVE_MHASH - { - phpstr *algos = phpstr_new(); - int i, c = mhash_count(); - - for (i = 0; i <= c; ++i) { - const char *hash = mhash_get_hash_name_static(i); - - if (hash) { - phpstr_appendf(algos, "%s, ", hash); - } - } - phpstr_fix(algos); - php_info_print_table_row(2, "MHASH", PHPSTR_VAL(algos)); - phpstr_free(&algos); - } -#else - php_info_print_table_row(2, "MHASH", "not available"); -#endif - } - php_info_print_table_end(); - - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "Request Methods"); - { - unsigned i; - zval **custom_method; - phpstr *known_request_methods = phpstr_new(); - phpstr *custom_request_methods = phpstr_new(); - - for (i = HTTP_NO_REQUEST_METHOD+1; i < HTTP_MAX_REQUEST_METHOD; ++i) { - phpstr_appendl(known_request_methods, http_request_method_name(i)); - phpstr_appends(known_request_methods, ", "); - } - FOREACH_HASH_VAL(&HTTP_G(request).methods.custom, custom_method) { - phpstr_append(custom_request_methods, Z_STRVAL_PP(custom_method), Z_STRLEN_PP(custom_method)); - phpstr_appends(custom_request_methods, ", "); - } - - phpstr_append(known_request_methods, PHPSTR_VAL(custom_request_methods), PHPSTR_LEN(custom_request_methods)); - phpstr_fix(known_request_methods); - phpstr_fix(custom_request_methods); - - php_info_print_table_row(2, "Known", PHPSTR_VAL(known_request_methods)); - php_info_print_table_row(2, "Custom", - PHPSTR_LEN(custom_request_methods) ? PHPSTR_VAL(custom_request_methods) : "none registered"); - php_info_print_table_row(2, "Allowed", strlen(HTTP_G(request).methods.allowed) ? HTTP_G(request).methods.allowed : "(ANY)"); - - phpstr_free(&known_request_methods); - phpstr_free(&custom_request_methods); - } - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http.dsp b/http.dsp deleted file mode 100644 index 00bf67a..0000000 --- a/http.dsp +++ /dev/null @@ -1,209 +0,0 @@ -# Microsoft Developer Studio Project File - Name="http" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=http - Win32 Release_TS -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "http.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "http.mak" CFG="http - Win32 Release_TS" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "http - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "http - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "http - Win32 Release_TS" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release_TS" -# PROP BASE Intermediate_Dir "Release_TS" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release_TS" -# PROP Intermediate_Dir "Release_TS" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# 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 -# 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 "_WINSOCKAPI_=" /FR /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x406 /d "NDEBUG" -# ADD RSC /l 0x406 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# 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 -# 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" - -!ELSEIF "$(CFG)" == "http - Win32 Debug_TS" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Debug_TS" -# PROP BASE Intermediate_Dir "Debug_TS" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Debug_TS" -# PROP Intermediate_Dir "Debug_TS" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# 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 -# 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 "_WINSOCKAPI_=" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x406 /d "NDEBUG" -# ADD RSC /l 0x406 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# 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 -# 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" - -!ENDIF - -# Begin Target - -# Name "http - Win32 Release_TS" -# Name "http - Win32 Debug_TS" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\http.c -# End Source File -# Begin Source File - -SOURCE=.\http_api.c -# End Source File -# Begin Source File - -SOURCE=.\http_request_api.c -# End Source File -# Begin Source File - -SOURCE=.\http_request_method_api.c -# End Source File -# Begin Source File - -SOURCE=.\http_functions.c -# End Source File -# Begin Source File - -SOURCE=.\http_cache_api.c -# End Source File -# Begin Source File - -SOURCE=.\http_date_api.c -# End Source File -# Begin Source File - -SOURCE=.\http_headers_api.c -# End Source File -# Begin Source File - -SOURCE=.\http_message_api.c -# End Source File -# Begin Source File - -SOURCE=.\http_send_api.c -# End Source File -# Begin Source File - -SOURCE=.\http_url_api.c -# End Source File -# Begin Source File - -SOURCE=.\http_info_api.c -# End Source File -# Begin Source File - -SOURCE=.\phpstr\phpstr.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\php_http.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_request_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_request_method_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_cache_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_date_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_message_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_send_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_headers_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_url_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_info_api.h -# End Source File -# Begin Source File - -SOURCE=.\php_http_std_defs.h -# End Source File -# Begin Source File - -SOURCE=.\phpstr\phpstr.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/http_api.c b/http_api.c deleted file mode 100644 index eebfeb2..0000000 --- a/http_api.c +++ /dev/null @@ -1,424 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "SAPI.h" -#include "ext/standard/url.h" - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_headers_api.h" -#include "php_http_send_api.h" - -#ifdef ZEND_ENGINE_2 -# include "zend_exceptions.h" -# include "php_http_exception_object.h" -#endif - -#include - -#ifdef HTTP_HAVE_MAGIC -# if defined(PHP_WIN32) && !defined(USE_MAGIC_DLL) && !defined(USE_MAGIC_STATIC) -# define USE_MAGIC_STATIC -# endif -# include -#endif - -ZEND_EXTERN_MODULE_GLOBALS(http); - -/* char *pretty_key(char *, size_t, zend_bool, zend_bool) */ -char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen) -{ - if (key && key_len) { - size_t i; - int wasalpha; - if (wasalpha = isalpha((int) key[0])) { - key[0] = (char) (uctitle ? toupper((int) key[0]) : tolower((int) key[0])); - } - for (i = 1; i < key_len; i++) { - if (isalpha((int) key[i])) { - key[i] = (char) (((!wasalpha) && uctitle) ? toupper((int) key[i]) : tolower((int) key[i])); - wasalpha = 1; - } else { - if (xhyphen && (key[i] == '_')) { - key[i] = '-'; - } - wasalpha = 0; - } - } - } - return key; -} -/* }}} */ - -/* {{{ */ -void _http_key_list_default_decoder(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC) -{ - *decoded = estrndup(encoded, encoded_len); - *decoded_len = (size_t) php_url_decode(*decoded, encoded_len); -} -/* }}} */ - -/* {{{ */ -STATUS _http_parse_key_list(const char *list, HashTable *items, char separator, http_key_list_decode_t decode, zend_bool first_entry_is_name_value_pair TSRMLS_DC) -{ - const char *key = list, *val = NULL; - int vallen = 0, keylen = 0, done = 0; - zval array; - - INIT_ZARR(array, items); - - if (!(val = strchr(list, '='))) { - return FAILURE; - } - -#define HTTP_KEYLIST_VAL(array, k, str, len) \ - { \ - char *decoded; \ - size_t decoded_len; \ - if (decode) { \ - decode(str, len, &decoded, &decoded_len TSRMLS_CC); \ - } else { \ - decoded_len = len; \ - decoded = estrndup(str, decoded_len); \ - } \ - add_assoc_stringl(array, k, decoded, decoded_len, 0); \ - } -#define HTTP_KEYLIST_FIXKEY() \ - { \ - while (isspace(*key)) ++key; \ - keylen = val - key; \ - while (isspace(key[keylen - 1])) --keylen; \ - } -#define HTTP_KEYLIST_FIXVAL() \ - { \ - ++val; \ - while (isspace(*val)) ++val; \ - vallen = key - val; \ - while (isspace(val[vallen - 1])) --vallen; \ - } - - HTTP_KEYLIST_FIXKEY(); - - if (first_entry_is_name_value_pair) { - HTTP_KEYLIST_VAL(&array, "name", key, keylen); - - /* just one name=value */ - if (!(key = strchr(val, separator))) { - key = val + strlen(val); - HTTP_KEYLIST_FIXVAL(); - HTTP_KEYLIST_VAL(&array, "value", val, vallen); - return SUCCESS; - } - /* additional info appended */ - else { - HTTP_KEYLIST_FIXVAL(); - HTTP_KEYLIST_VAL(&array, "value", val, vallen); - } - } - - do { - char *keydup = NULL; - - if (!(val = strchr(key, '='))) { - break; - } - - /* start at 0 if first_entry_is_name_value_pair==0 */ - if (zend_hash_num_elements(items)) { - ++key; - } - - HTTP_KEYLIST_FIXKEY(); - keydup = estrndup(key, keylen); - if (!(key = strchr(val, separator))) { - done = 1; - key = val + strlen(val); - } - HTTP_KEYLIST_FIXVAL(); - HTTP_KEYLIST_VAL(&array, keydup, val, vallen); - efree(keydup); - } while (!done); - - return SUCCESS; -} -/* }}} */ - -/* {{{ void http_error(long, long, char*) */ -void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...) -{ - va_list args; - - va_start(args, format); -#ifdef ZEND_ENGINE_2 - if ((type == E_THROW) || (PG(error_handling) == EH_THROW)) { - char *message; - - vspprintf(&message, 0, format, args); - zend_throw_exception(http_exception_get_for_code(code), message, code TSRMLS_CC); - } else -#endif - php_verror(NULL, "", type, format, args TSRMLS_CC); - va_end(args); -} -/* }}} */ - -/* {{{ void http_log(char *, char *, char *) */ -void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC) -{ - time_t now; - struct tm nowtm; - char datetime[128]; - - time(&now); - strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm)); - -#define HTTP_LOG_WRITE(file, type, msg) \ - if (file && strlen(file)) { \ - php_stream *log = php_stream_open_wrapper(file, "ab", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL); \ - \ - if (log) { \ - php_stream_printf(log TSRMLS_CC, "%s\t[%s]\t%s\t<%s>%s", datetime, type, msg, SG(request_info).request_uri, PHP_EOL); \ - php_stream_close(log); \ - } \ - \ - } - - HTTP_LOG_WRITE(file, ident, message); - HTTP_LOG_WRITE(HTTP_G(log).composite, ident, message); -} -/* }}} */ - -/* {{{ STATUS http_exit(int, char*, char*) */ -STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send_header TSRMLS_DC) -{ - if (status || send_header) { - if (SUCCESS != http_send_status_header(status, send_header ? header : NULL)) { - http_error_ex(HE_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, header ? header : ""); - STR_FREE(header); - STR_FREE(body); - return FAILURE; - } - } - - if (body) { - PHPWRITE(body, strlen(body)); - } - - switch (status) - { - case 301: http_log(HTTP_G(log).redirect, "301-REDIRECT", header); break; - case 302: http_log(HTTP_G(log).redirect, "302-REDIRECT", header); break; - case 304: http_log(HTTP_G(log).cache, "304-CACHE", header); break; - case 405: http_log(HTTP_G(log).allowed_methods, "405-ALLOWED", header); break; - default: http_log(NULL, header, body); break; - } - - STR_FREE(header); - STR_FREE(body); - - zend_bailout(); - /* fake */ - return SUCCESS; -} -/* }}} */ - -/* {{{ STATUS http_check_method(char *) */ -STATUS _http_check_method_ex(const char *method, const char *methods) -{ - const char *found; - - if ( (found = strstr(methods, method)) && - (found == method || !isalpha(found[-1])) && - (!isalpha(found[strlen(method) + 1]))) { - return SUCCESS; - } - return FAILURE; -} -/* }}} */ - -/* {{{ zval *http_get_server_var_ex(char *, size_t) */ -PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC) -{ - zval **hsv; - zval **var; - - if (SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &hsv)) { - return NULL; - } - if (SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_size, (void **) &var)) { - return NULL; - } - if (check && !(Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) { - return NULL; - } - return *var; -} -/* }}} */ - -/* {{{ STATUS http_get_request_body(char **, size_t *) */ -PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC) -{ - *length = 0; - *body = NULL; - - if (SG(request_info).raw_post_data) { - *length = SG(request_info).raw_post_data_length; - *body = (char *) (dup ? estrndup(SG(request_info).raw_post_data, *length) : SG(request_info).raw_post_data); - return SUCCESS; - } - return FAILURE; -} -/* }}} */ - -/* {{{ char *http_chunked_decode(char *, size_t, char **, size_t *) */ -PHP_HTTP_API const char *_http_chunked_decode(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC) -{ - const char *e_ptr; - char *d_ptr; - long rest; - - *decoded_len = 0; - *decoded = ecalloc(1, encoded_len); - d_ptr = *decoded; - e_ptr = encoded; - - while ((rest = encoded + encoded_len - e_ptr) > 0) { - long chunk_len = 0; - int EOL_len = 0, eol_mismatch = 0; - char *n_ptr; - - chunk_len = strtol(e_ptr, &n_ptr, 16); - - /* check if: - * - we could not read in chunk size - * - we got a negative chunk size - * - chunk size is greater then remaining size - * - chunk size is not followed by (CR)LF|NUL - */ - if ( (n_ptr == e_ptr) || (chunk_len < 0) || (chunk_len > rest) || - (*n_ptr && (eol_mismatch = (n_ptr != http_locate_eol(e_ptr, &EOL_len))))) { - /* don't fail on apperently not encoded data */ - if (e_ptr == encoded) { - memcpy(*decoded, encoded, encoded_len); - *decoded_len = encoded_len; - return encoded + encoded_len; - } else { - efree(*decoded); - if (eol_mismatch) { - if (EOL_len == 2) { - http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Invalid character (expected 0x0D 0x0A; got: 0x%X 0x%X)", *n_ptr, *(n_ptr + 1)); - } else { - http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Invalid character (expected 0x0A; got: 0x%X)", *n_ptr); - } - } else { - char *error = estrndup(n_ptr, strcspn(n_ptr, "\r\n ")); - http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Invalid chunk size: '%s' at pos %d", error, n_ptr - encoded); - efree(error); - } - return NULL; - } - } else { - e_ptr = n_ptr; - } - - /* reached the end */ - if (!chunk_len) { - break; - } - - memcpy(d_ptr, e_ptr += EOL_len, chunk_len); - d_ptr += chunk_len; - e_ptr += chunk_len + EOL_len; - *decoded_len += chunk_len; - } - - return e_ptr; -} -/* }}} */ - -/* {{{ char *http_guess_content_type(char *magic_file, long magic_mode, void *data, size_t size, http_send_mode mode) */ -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) -{ - char *ct = NULL; - -#ifdef HTTP_HAVE_MAGIC - /* magic_load() fails if MAGIC_MIME is set because it - cowardly adds .mime to the file name */ - struct magic_set *magic = magic_open(magicmode &~ MAGIC_MIME); - - if (!magic) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid magic mode: %ld", magicmode); - } else if (-1 == magic_load(magic, magicfile)) { - http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Failed to load magic database '%s' (%s)", magicfile, magic_error(magic)); - } else { - const char *ctype = NULL; - - magic_setflags(magic, magicmode); - - switch (data_mode) - { - case SEND_RSRC: - { - char *buffer; - size_t b_len; - - b_len = php_stream_copy_to_mem(data_ptr, &buffer, 65536, 0); - ctype = magic_buffer(magic, buffer, b_len); - efree(buffer); - } - break; - - case SEND_DATA: - ctype = magic_buffer(magic, data_ptr, data_len); - break; - - default: - ctype = magic_file(magic, data_ptr); - break; - } - - if (ctype) { - ct = estrdup(ctype); - } else { - http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Failed to guess Content-Type: %s", magic_error(magic)); - } - } - if (magic) { - magic_close(magic); - } -#else - http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available"); -#endif - - return ct; -} -/* }}} */ -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_cache_api.c b/http_cache_api.c deleted file mode 100644 index d03ee85..0000000 --- a/http_cache_api.c +++ /dev/null @@ -1,274 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "SAPI.h" -#include "php_streams.h" -#include "php_output.h" -#include "ext/standard/md5.h" -#include "ext/standard/sha1.h" - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_cache_api.h" -#include "php_http_send_api.h" -#include "php_http_date_api.h" - -#ifdef HTTP_HAVE_MHASH -# include -#endif - -ZEND_EXTERN_MODULE_GLOBALS(http); - -STATUS _http_cache_global_init(INIT_FUNC_ARGS) -{ - HTTP_LONG_CONSTANT("HTTP_ETAG_MD5", HTTP_ETAG_MD5); - HTTP_LONG_CONSTANT("HTTP_ETAG_SHA1", HTTP_ETAG_SHA1); - HTTP_LONG_CONSTANT("HTTP_ETAG_CRC32", HTTP_ETAG_CRC32); - -#ifdef HTTP_HAVE_MHASH - { - int l, i, c = mhash_count(); - - for (i = 0; i <= c; ++i) { - char const_name[256] = {0}; - const char *hash_name = mhash_get_hash_name_static(i); - - if (hash_name) { - l = snprintf(const_name, 255, "HTTP_ETAG_MHASH_%s", hash_name); - zend_register_long_constant(const_name, l + 1, i, CONST_CS|CONST_PERSISTENT, module_number TSRMLS_CC); - } - } - } -#endif - - return SUCCESS; -} - -/* {{{ char *http_etag(void *, size_t, http_send_mode) */ -PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC) -{ - php_stream_statbuf ssb; - char ssb_buf[128] = {0}; - size_t ssb_len; - void *ctx = http_etag_init(); - - switch (data_mode) - { - case SEND_DATA: - http_etag_update(ctx, data_ptr, data_len); - break; - - case SEND_RSRC: - { - if (php_stream_stat((php_stream *) data_ptr, &ssb)) { - efree(ctx); - return NULL; - } - ssb_len = snprintf(ssb_buf, 127, "%ld=%ld=%ld", ssb.sb.st_mtime, ssb.sb.st_ino, ssb.sb.st_size); - http_etag_update(ctx, ssb_buf, ssb_len); - } - break; - - default: - { - if (php_stream_stat_path((char *) data_ptr, &ssb)) { - efree(ctx); - return NULL; - } - ssb_len = snprintf(ssb_buf, 127, "%ld=%ld=%ld", ssb.sb.st_mtime, ssb.sb.st_ino, ssb.sb.st_size); - http_etag_update(ctx, ssb_buf, ssb_len); - } - break; - } - - return http_etag_finish(ctx); -} -/* }}} */ - -/* {{{ time_t http_last_modified(void *, http_send_mode) */ -PHP_HTTP_API time_t _http_last_modified(const void *data_ptr, http_send_mode data_mode TSRMLS_DC) -{ - php_stream_statbuf ssb; - - switch (data_mode) - { - case SEND_DATA: return time(NULL); - case SEND_RSRC: return php_stream_stat((php_stream *) data_ptr, &ssb) ? 0 : ssb.sb.st_mtime; - default: return php_stream_stat_path((char *) data_ptr, &ssb) ? 0 : ssb.sb.st_mtime; - } -} -/* }}} */ - -/* {{{ zend_bool http_match_last_modified(char *, time_t) */ -PHP_HTTP_API zend_bool _http_match_last_modified_ex(const char *entry, time_t t, zend_bool enforce_presence TSRMLS_DC) -{ - zend_bool retval; - zval *zmodified; - char *modified, *chr_ptr; - - HTTP_GSC(zmodified, entry, !enforce_presence); - - modified = estrndup(Z_STRVAL_P(zmodified), Z_STRLEN_P(zmodified)); - if (chr_ptr = strrchr(modified, ';')) { - chr_ptr = 0; - } - retval = (t <= http_parse_date(modified)); - efree(modified); - return retval; -} -/* }}} */ - -/* {{{ zend_bool http_match_etag(char *, char *) */ -PHP_HTTP_API zend_bool _http_match_etag_ex(const char *entry, const char *etag, zend_bool enforce_presence TSRMLS_DC) -{ - zval *zetag; - char *quoted_etag; - zend_bool result; - - HTTP_GSC(zetag, entry, !enforce_presence); - - if (NULL != strchr(Z_STRVAL_P(zetag), '*')) { - return 1; - } - - quoted_etag = (char *) emalloc(strlen(etag) + 3); - sprintf(quoted_etag, "\"%s\"", etag); - - if (!strchr(Z_STRVAL_P(zetag), ',')) { - result = !strcmp(Z_STRVAL_P(zetag), quoted_etag); - } else { - result = (NULL != strstr(Z_STRVAL_P(zetag), quoted_etag)); - } - efree(quoted_etag); - return result; -} -/* }}} */ - -/* {{{ STATUS http_cache_last_modified(time_t, time_t, char *, size_t) */ -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) -{ - char *sent_header = NULL; - - if (cc_len && (SUCCESS != http_send_cache_control(cache_control, cc_len))) { - return FAILURE; - } - - if (SUCCESS != http_send_last_modified_ex(send_modified, &sent_header)) { - return FAILURE; - } - - if (http_match_last_modified("HTTP_IF_MODIFIED_SINCE", last_modified)) { - http_exit_ex(304, sent_header, NULL, 0); - } else { - STR_FREE(sent_header); - } - - return SUCCESS; -} -/* }}} */ - -/* {{{ STATUS http_cache_etag(char *, size_t, char *, size_t) */ -PHP_HTTP_API STATUS _http_cache_etag(const char *etag, size_t etag_len, - const char *cache_control, size_t cc_len TSRMLS_DC) -{ - char *sent_header = NULL; - - if (cc_len && (SUCCESS != http_send_cache_control(cache_control, cc_len))) { - return FAILURE; - } - - if (etag_len) { - if (SUCCESS != http_send_etag_ex(etag, etag_len, &sent_header)) { - return FAILURE; - } - if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) { - http_exit_ex(304, sent_header, NULL, 0); - } else { - STR_FREE(sent_header); - } - return SUCCESS; - } - - /* if no etag is given and we didn't already start ob_etaghandler -- start it */ - if (HTTP_G(etag).started) { - return SUCCESS; - } - - if (HTTP_G(etag).started = (SUCCESS == php_start_ob_buffer_named("ob_etaghandler", HTTP_SENDBUF_SIZE, 1 TSRMLS_CC))) { - return SUCCESS; - } else { - return FAILURE; - } -} -/* }}} */ - -/* {{{ void http_ob_etaghandler(char *, uint, char **, uint *, int) */ -PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len, - char **handled_output, uint *handled_output_len, int mode TSRMLS_DC) -{ - if (mode & PHP_OUTPUT_HANDLER_START) { - if (HTTP_G(etag).started) { - http_error(HE_WARNING, HTTP_E_RUNTIME, "ob_etaghandler can only be used once"); - return; - } - HTTP_G(etag).started = 1; - HTTP_G(etag).ctx = http_etag_init(); - } - - http_etag_update(HTTP_G(etag).ctx, output, output_len); - - if (mode & PHP_OUTPUT_HANDLER_END) { - char *etag = http_etag_finish(HTTP_G(etag).ctx); - - /* just do that if desired */ - if (HTTP_G(etag).started) { - char *sent_header = NULL; - - http_send_cache_control(HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL)); - http_send_etag_ex(etag, strlen(etag), &sent_header); - - if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) { - efree(etag); - http_exit_ex(304, sent_header, NULL, 0); - } else { - STR_FREE(sent_header); - } - } - efree(etag); - } - - *handled_output_len = output_len; - *handled_output = estrndup(output, output_len); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ - diff --git a/http_date_api.c b/http_date_api.c deleted file mode 100644 index 37047b6..0000000 --- a/http_date_api.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "php_http.h" -#include "php_http_std_defs.h" - -#include - -static int check_day(char *day, size_t len); -static int check_month(char *month); -static int check_tzone(char *tzone); - -/* {{{ day/month names */ -static const char *days[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" -}; -static const char *wkdays[] = { - "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" -}; -static const char *weekdays[] = { - "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday", "Sunday" -}; -static const char *months[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Okt", "Nov", "Dec" -}; -enum assume_next { - DATE_MDAY, - DATE_YEAR, - DATE_TIME -}; -static const struct time_zone { - const char *name; - const int offset; -} time_zones[] = { - {"GMT", 0}, /* Greenwich Mean */ - {"UTC", 0}, /* Universal (Coordinated) */ - {"WET", 0}, /* Western European */ - {"BST", 0}, /* British Summer */ - {"WAT", 60}, /* West Africa */ - {"AST", 240}, /* Atlantic Standard */ - {"ADT", 240}, /* Atlantic Daylight */ - {"EST", 300}, /* Eastern Standard */ - {"EDT", 300}, /* Eastern Daylight */ - {"CST", 360}, /* Central Standard */ - {"CDT", 360}, /* Central Daylight */ - {"MST", 420}, /* Mountain Standard */ - {"MDT", 420}, /* Mountain Daylight */ - {"PST", 480}, /* Pacific Standard */ - {"PDT", 480}, /* Pacific Daylight */ - {"YST", 540}, /* Yukon Standard */ - {"YDT", 540}, /* Yukon Daylight */ - {"HST", 600}, /* Hawaii Standard */ - {"HDT", 600}, /* Hawaii Daylight */ - {"CAT", 600}, /* Central Alaska */ - {"AHST", 600}, /* Alaska-Hawaii Standard */ - {"NT", 660}, /* Nome */ - {"IDLW", 720}, /* International Date Line West */ - {"CET", -60}, /* Central European */ - {"MET", -60}, /* Middle European */ - {"MEWT", -60}, /* Middle European Winter */ - {"MEST", -120}, /* Middle European Summer */ - {"CEST", -120}, /* Central European Summer */ - {"MESZ", -60}, /* Middle European Summer */ - {"FWT", -60}, /* French Winter */ - {"FST", -60}, /* French Summer */ - {"EET", -120}, /* Eastern Europe, USSR Zone 1 */ - {"WAST", -420}, /* West Australian Standard */ - {"WADT", -420}, /* West Australian Daylight */ - {"CCT", -480}, /* China Coast, USSR Zone 7 */ - {"JST", -540}, /* Japan Standard, USSR Zone 8 */ - {"EAST", -600}, /* Eastern Australian Standard */ - {"EADT", -600}, /* Eastern Australian Daylight */ - {"GST", -600}, /* Guam Standard, USSR Zone 9 */ - {"NZT", -720}, /* New Zealand */ - {"NZST", -720}, /* New Zealand Standard */ - {"NZDT", -720}, /* New Zealand Daylight */ - {"IDLE", -720}, /* International Date Line East */ -}; -/* }}} */ - -/* {{{ Day/Month/TZ checks for http_parse_date() - Originally by libcurl, Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. */ -static int check_day(char *day, size_t len) -{ - int i; - const char * const *check = (len > 3) ? &weekdays[0] : &wkdays[0]; - for (i = 0; i < 7; i++) { - if (!strcmp(day, check[0])) { - return i; - } - check++; - } - return -1; -} - -static int check_month(char *month) -{ - int i; - const char * const *check = &months[0]; - for (i = 0; i < 12; i++) { - if (!strcmp(month, check[0])) { - return i; - } - check++; - } - return -1; -} - -/* return the time zone offset between GMT and the input one, in number - of seconds or -1 if the timezone wasn't found/legal */ - -static int check_tzone(char *tzone) -{ - unsigned i; - const struct time_zone *check = time_zones; - for (i = 0; i < sizeof(time_zones) / sizeof(time_zones[0]); i++) { - if (!strcmp(tzone, check->name)) { - return check->offset * 60; - } - check++; - } - return -1; -} -/* }}} */ - -/* {{{ char *http_date(time_t) */ -PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC) -{ - struct tm *gmtime, tmbuf; - - if (gmtime = php_gmtime_r(&t, &tmbuf)) { - char *date = ecalloc(1, 31); - snprintf(date, 30, - "%s, %02d %s %04d %02d:%02d:%02d GMT", - days[gmtime->tm_wday], gmtime->tm_mday, - months[gmtime->tm_mon], gmtime->tm_year + 1900, - gmtime->tm_hour, gmtime->tm_min, gmtime->tm_sec - ); - return date; - } - - return NULL; -} -/* }}} */ - -/* {{{ time_t http_parse_date(char *) - Originally by libcurl, Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. */ -PHP_HTTP_API time_t _http_parse_date(const char *date) -{ - time_t t = 0; - int tz_offset = -1, year = -1, month = -1, monthday = -1, weekday = -1, - hours = -1, minutes = -1, seconds = -1; - struct tm tm; - enum assume_next dignext = DATE_MDAY; - const char *indate = date; - - int part = 0; /* max 6 parts */ - - while (*date && (part < 6)) { - int found = 0; - - while (*date && !isalnum(*date)) { - date++; - } - - if (isalpha(*date)) { - /* a name coming up */ - char buf[32] = ""; - size_t len; - sscanf(date, "%31[A-Za-z]", buf); - len = strlen(buf); - - if (weekday == -1) { - weekday = check_day(buf, len); - if (weekday != -1) { - found = 1; - } - } - - if (!found && (month == -1)) { - month = check_month(buf); - if (month != -1) { - found = 1; - } - } - - if (!found && (tz_offset == -1)) { - /* this just must be a time zone string */ - tz_offset = check_tzone(buf); - if (tz_offset != -1) { - found = 1; - } - } - - if (!found) { - return -1; /* bad string */ - } - date += len; - } - else if (isdigit(*date)) { - /* a digit */ - int val; - char *end; - if ((seconds == -1) && - (3 == sscanf(date, "%02d:%02d:%02d", &hours, &minutes, &seconds))) { - /* time stamp! */ - date += 8; - found = 1; - } - else { - val = (int) strtol(date, &end, 10); - - if ((tz_offset == -1) && ((end - date) == 4) && (val < 1300) && - (indate < date) && ((date[-1] == '+' || date[-1] == '-'))) { - /* four digits and a value less than 1300 and it is preceeded with - a plus or minus. This is a time zone indication. */ - found = 1; - tz_offset = (val / 100 * 60 + val % 100) * 60; - - /* the + and - prefix indicates the local time compared to GMT, - this we need ther reversed math to get what we want */ - tz_offset = date[-1] == '+' ? -tz_offset : tz_offset; - } - - if (((end - date) == 8) && (year == -1) && (month == -1) && (monthday == -1)) { - /* 8 digits, no year, month or day yet. This is YYYYMMDD */ - found = 1; - year = val / 10000; - month = (val % 10000) / 100 - 1; /* month is 0 - 11 */ - monthday = val % 100; - } - - if (!found && (dignext == DATE_MDAY) && (monthday == -1)) { - if ((val > 0) && (val < 32)) { - monthday = val; - found = 1; - } - dignext = DATE_YEAR; - } - - if (!found && (dignext == DATE_YEAR) && (year == -1)) { - year = val; - found = 1; - if (year < 1900) { - year += year > 70 ? 1900 : 2000; - } - if(monthday == -1) { - dignext = DATE_MDAY; - } - } - - if (!found) { - return -1; - } - - date = end; - } - } - - part++; - } - - if (-1 == seconds) { - seconds = minutes = hours = 0; /* no time, make it zero */ - } - - if ((-1 == monthday) || (-1 == month) || (-1 == year)) { - /* lacks vital info, fail */ - return -1; - } - - if (sizeof(time_t) < 5) { - /* 32 bit time_t can only hold dates to the beginning of 2038 */ - if (year > 2037) { - return 0x7fffffff; - } - } - - tm.tm_sec = seconds; - tm.tm_min = minutes; - tm.tm_hour = hours; - tm.tm_mday = monthday; - tm.tm_mon = month; - tm.tm_year = year - 1900; - tm.tm_wday = 0; - tm.tm_yday = 0; - tm.tm_isdst = 0; - - t = mktime(&tm); - - /* time zone adjust */ - if (t != -1) { - struct tm *gmt, keeptime2; - long delta; - time_t t2; - - if(!(gmt = php_gmtime_r(&t, &keeptime2))) { - return -1; /* illegal date/time */ - } - - t2 = mktime(gmt); - - /* Add the time zone diff (between the given timezone and GMT) and the - diff between the local time zone and GMT. */ - delta = (tz_offset != -1 ? tz_offset : 0) + (t - t2); - - if((delta > 0) && (t + delta < t)) { - return -1; /* time_t overflow */ - } - - t += delta; - } - - return t; -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ - diff --git a/http_exception_object.c b/http_exception_object.c deleted file mode 100644 index a35eb0e..0000000 --- a/http_exception_object.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#ifdef ZEND_ENGINE_2 - -#include "zend_exceptions.h" - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_exception_object.h" - -#define HTTP_EX_DEF_CE http_exception_object_ce -zend_class_entry *http_exception_object_ce; -#define HTTP_EX_CE(name) http_ ##name## _exception_object_ce -zend_class_entry *HTTP_EX_CE(runtime); -zend_class_entry *HTTP_EX_CE(header); -zend_class_entry *HTTP_EX_CE(malformed_headers); -zend_class_entry *HTTP_EX_CE(request_method); -zend_class_entry *HTTP_EX_CE(message_type); -zend_class_entry *HTTP_EX_CE(invalid_param); -zend_class_entry *HTTP_EX_CE(encoding); -zend_class_entry *HTTP_EX_CE(request); -zend_class_entry *HTTP_EX_CE(request_pool); -zend_class_entry *HTTP_EX_CE(socket); -zend_class_entry *HTTP_EX_CE(response); -zend_class_entry *HTTP_EX_CE(url); - -void _http_exception_object_init(INIT_FUNC_ARGS) -{ - HTTP_REGISTER_EXCEPTION(HttpException, http_exception_object_ce, zend_exception_get_default()); - HTTP_REGISTER_EXCEPTION(HttpRuntimeException, HTTP_EX_CE(runtime), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpInvalidParamException, HTTP_EX_CE(invalid_param), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpHeaderException, HTTP_EX_CE(header), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpMalformedHeadersException, HTTP_EX_CE(malformed_headers), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpRequestMethodException, HTTP_EX_CE(request_method), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpMessageTypeException, HTTP_EX_CE(message_type), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpEncodingException, HTTP_EX_CE(encoding), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpRequestException, HTTP_EX_CE(request), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpRequestPoolException, HTTP_EX_CE(request_pool), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpSocketException, HTTP_EX_CE(socket), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpResponseException, HTTP_EX_CE(response), HTTP_EX_DEF_CE); - HTTP_REGISTER_EXCEPTION(HttpUrlException, HTTP_EX_CE(url), HTTP_EX_DEF_CE); - - HTTP_LONG_CONSTANT("HTTP_E_RUNTIME", HTTP_E_RUNTIME); - HTTP_LONG_CONSTANT("HTTP_E_INVALID_PARAM", HTTP_E_INVALID_PARAM); - HTTP_LONG_CONSTANT("HTTP_E_HEADER", HTTP_E_HEADER); - HTTP_LONG_CONSTANT("HTTP_E_MALFORMED_HEADERS", HTTP_E_MALFORMED_HEADERS); - HTTP_LONG_CONSTANT("HTTP_E_REQUEST_METHOD", HTTP_E_REQUEST_METHOD); - HTTP_LONG_CONSTANT("HTTP_E_MESSAGE_TYPE", HTTP_E_MESSAGE_TYPE); - HTTP_LONG_CONSTANT("HTTP_E_ENCODING", HTTP_E_ENCODING); - HTTP_LONG_CONSTANT("HTTP_E_REQUEST", HTTP_E_REQUEST); - HTTP_LONG_CONSTANT("HTTP_E_REQUEST_POOL", HTTP_E_REQUEST_POOL); - HTTP_LONG_CONSTANT("HTTP_E_SOCKET", HTTP_E_SOCKET); - HTTP_LONG_CONSTANT("HTTP_E_RESPONSE", HTTP_E_RESPONSE); - HTTP_LONG_CONSTANT("HTTP_E_URL", HTTP_E_URL); -} - -zend_class_entry *_http_exception_get_default() -{ - return http_exception_object_ce; -} - -zend_class_entry *_http_exception_get_for_code(long code) -{ - zend_class_entry *ex = http_exception_object_ce; - - switch (code) - { - case HTTP_E_RUNTIME: ex = HTTP_EX_CE(runtime); break; - case HTTP_E_INVALID_PARAM: ex = HTTP_EX_CE(invalid_param); break; - case HTTP_E_HEADER: ex = HTTP_EX_CE(header); break; - case HTTP_E_MALFORMED_HEADERS: ex = HTTP_EX_CE(malformed_headers); break; - case HTTP_E_REQUEST_METHOD: ex = HTTP_EX_CE(request_method); break; - case HTTP_E_MESSAGE_TYPE: ex = HTTP_EX_CE(message_type); break; - case HTTP_E_ENCODING: ex = HTTP_EX_CE(encoding); break; - case HTTP_E_REQUEST: ex = HTTP_EX_CE(request); break; - case HTTP_E_REQUEST_POOL: ex = HTTP_EX_CE(request_pool); break; - case HTTP_E_SOCKET: ex = HTTP_EX_CE(socket); break; - case HTTP_E_RESPONSE: ex = HTTP_EX_CE(response); break; - case HTTP_E_URL: ex = HTTP_EX_CE(url); break; - } - - return ex; -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_functions.c b/http_functions.c deleted file mode 100644 index 63a3423..0000000 --- a/http_functions.c +++ /dev/null @@ -1,1248 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "zend_operators.h" - -#include "SAPI.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "ext/standard/php_string.h" -#if defined(HAVE_PHP_SESSION) && !defined(COMPILE_DL_SESSION) -# include "ext/session/php_session.h" -#endif - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_request_api.h" -#include "php_http_cache_api.h" -#include "php_http_request_method_api.h" -#include "php_http_request_api.h" -#include "php_http_date_api.h" -#include "php_http_headers_api.h" -#include "php_http_message_api.h" -#include "php_http_send_api.h" -#include "php_http_url_api.h" - -#include "phpstr/phpstr.h" - -ZEND_EXTERN_MODULE_GLOBALS(http) - -/* {{{ proto string http_date([int timestamp]) - * - * This function returns a valid HTTP date regarding RFC 822/1123 - * looking like: "Wed, 22 Dec 2004 11:34:47 GMT" - * - */ -PHP_FUNCTION(http_date) -{ - long t = -1; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) { - RETURN_FALSE; - } - - if (t == -1) { - t = (long) time(NULL); - } - - RETURN_STRING(http_date(t), 0); -} -/* }}} */ - -/* {{{ proto string http_absolute_uri(string url[, string proto[, string host[, int port]]]) - * - * This function returns an absolute URI constructed from url. - * If the url is already abolute but a different proto was supplied, - * only the proto part of the URI will be updated. If url has no - * path specified, the path of the current REQUEST_URI will be taken. - * The host will be taken either from the Host HTTP header of the client - * the SERVER_NAME or just localhost if prior are not available. - * - * Some examples: - *
- *  url = "page.php"                    => http://www.example.com/current/path/page.php
- *  url = "/page.php"                   => http://www.example.com/page.php
- *  url = "/page.php", proto = "https"  => https://www.example.com/page.php
- * 
- * - */ -PHP_FUNCTION(http_absolute_uri) -{ - char *url = NULL, *proto = NULL, *host = NULL; - int url_len = 0, proto_len = 0, host_len = 0; - long port = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ssl", &url, &url_len, &proto, &proto_len, &host, &host_len, &port) != SUCCESS) { - RETURN_FALSE; - } - - RETURN_STRING(http_absolute_uri_ex(url, url_len, proto, proto_len, host, host_len, port), 0); -} -/* }}} */ - -#define HTTP_DO_NEGOTIATE(type, supported, as_array) \ -{ \ - HashTable *result; \ - if (result = http_negotiate_ ##type(supported)) { \ - if (as_array) { \ - Z_TYPE_P(return_value) = IS_ARRAY; \ - Z_ARRVAL_P(return_value) = result; \ - } else { \ - char *key; \ - uint key_len; \ - ulong idx; \ - \ - if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key, &key_len, &idx, 1, NULL)) { \ - RETVAL_STRINGL(key, key_len-1, 0); \ - } else { \ - RETVAL_NULL(); \ - } \ - zend_hash_destroy(result); \ - } \ - } else { \ - if (as_array) { \ - zval **value; \ - \ - array_init(return_value); \ - \ - FOREACH_VAL(supported, value) { \ - convert_to_string_ex(value); \ - add_assoc_double(return_value, Z_STRVAL_PP(value), 1.0); \ - } \ - } else { \ - zval **value; \ - \ - zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported)); \ - if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(supported), (void **) &value)) { \ - RETVAL_ZVAL(*value, 1, 0); \ - } else { \ - RETVAL_NULL(); \ - } \ - } \ - } \ -} - - -/* {{{ proto string http_negotiate_language(array supported[, bool return_quality_array = false]) - * - * This function negotiates the clients preferred language based on its - * Accept-Language HTTP header. It returns the negotiated language or - * the default language (i.e. first array entry) if none match. - * - * The qualifier is recognized and languages without qualifier are rated highest. - * - * The supported parameter is expected to be an array having - * the supported languages as array values. - * - * Example: - *
- * 
- * 
- * - */ -PHP_FUNCTION(http_negotiate_language) -{ - zval *supported; - zend_bool as_array = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &supported, &as_array) != SUCCESS) { - RETURN_FALSE; - } - - HTTP_DO_NEGOTIATE(language, supported, as_array); -} -/* }}} */ - -/* {{{ proto string http_negotiate_charset(array supported) - * - * This function negotiates the clients preferred charset based on its - * Accept-Charset HTTP header. It returns the negotiated charset or - * the default charset (i.e. first array entry) if none match. - * - * The qualifier is recognized and charset without qualifier are rated highest. - * - * The supported parameter is expected to be an array having - * the supported charsets as array values. - * - * Example: - *
- * 
- * 
- */ -PHP_FUNCTION(http_negotiate_charset) -{ - zval *supported; - zend_bool as_array = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &supported, &as_array) != SUCCESS) { - RETURN_FALSE; - } - - HTTP_DO_NEGOTIATE(charset, supported, as_array); -} -/* }}} */ - -/* {{{ proto bool http_send_status(int status) - * - * Send HTTP status code. - * - */ -PHP_FUNCTION(http_send_status) -{ - int status = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status) != SUCCESS) { - RETURN_FALSE; - } - if (status < 100 || status > 510) { - http_error_ex(HE_WARNING, HTTP_E_HEADER, "Invalid HTTP status code (100-510): %d", status); - RETURN_FALSE; - } - - RETURN_SUCCESS(http_send_status(status)); -} -/* }}} */ - -/* {{{ proto bool http_send_last_modified([int timestamp]) - * - * This converts the given timestamp to a valid HTTP date and - * sends it as "Last-Modified" HTTP header. If timestamp is - * omitted, current time is sent. - * - */ -PHP_FUNCTION(http_send_last_modified) -{ - long t = -1; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) { - RETURN_FALSE; - } - - if (t == -1) { - t = (long) time(NULL); - } - - RETURN_SUCCESS(http_send_last_modified(t)); -} -/* }}} */ - -/* {{{ proto bool http_send_content_type([string content_type = 'application/x-octetstream']) - * - * Sets the content type. - * - */ -PHP_FUNCTION(http_send_content_type) -{ - char *ct; - int ct_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ct, &ct_len) != SUCCESS) { - RETURN_FALSE; - } - - if (!ct_len) { - RETURN_SUCCESS(http_send_content_type("application/x-octetstream", lenof("application/x-octetstream"))); - } - RETURN_SUCCESS(http_send_content_type(ct, ct_len)); -} -/* }}} */ - -/* {{{ proto bool http_send_content_disposition(string filename[, bool inline = false]) - * - * Set the Content Disposition. The Content-Disposition header is very useful - * if the data actually sent came from a file or something similar, that should - * be "saved" by the client/user (i.e. by browsers "Save as..." popup window). - * - */ -PHP_FUNCTION(http_send_content_disposition) -{ - char *filename; - int f_len; - zend_bool send_inline = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &filename, &f_len, &send_inline) != SUCCESS) { - RETURN_FALSE; - } - RETURN_SUCCESS(http_send_content_disposition(filename, f_len, send_inline)); -} -/* }}} */ - -/* {{{ proto bool http_match_modified([int timestamp[, for_range = false]]) - * - * Matches the given timestamp against the clients "If-Modified-Since" resp. - * "If-Unmodified-Since" HTTP headers. - * - */ -PHP_FUNCTION(http_match_modified) -{ - long t = -1; - zend_bool for_range = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &t, &for_range) != SUCCESS) { - RETURN_FALSE; - } - - // current time if not supplied (senseless though) - if (t == -1) { - t = (long) time(NULL); - } - - if (for_range) { - RETURN_BOOL(http_match_last_modified("HTTP_IF_UNMODIFIED_SINCE", t)); - } - RETURN_BOOL(http_match_last_modified("HTTP_IF_MODIFIED_SINCE", t)); -} -/* }}} */ - -/* {{{ proto bool http_match_etag(string etag[, for_range = false]) - * - * This matches the given ETag against the clients - * "If-Match" resp. "If-None-Match" HTTP headers. - * - */ -PHP_FUNCTION(http_match_etag) -{ - int etag_len; - char *etag; - zend_bool for_range = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &etag, &etag_len, &for_range) != SUCCESS) { - RETURN_FALSE; - } - - if (for_range) { - RETURN_BOOL(http_match_etag("HTTP_IF_MATCH", etag)); - } - RETURN_BOOL(http_match_etag("HTTP_IF_NONE_MATCH", etag)); -} -/* }}} */ - -/* {{{ proto bool http_cache_last_modified([int timestamp_or_expires]]) - * - * If timestamp_or_expires is greater than 0, it is handled as timestamp - * and will be sent as date of last modification. If it is 0 or omitted, - * the current time will be sent as Last-Modified date. If it's negative, - * it is handled as expiration time in seconds, which means that if the - * requested last modification date is not between the calculated timespan, - * the Last-Modified header is updated and the actual body will be sent. - * - */ -PHP_FUNCTION(http_cache_last_modified) -{ - long last_modified = 0, send_modified = 0, t; - zval *zlm; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &last_modified) != SUCCESS) { - RETURN_FALSE; - } - - t = (long) time(NULL); - - /* 0 or omitted */ - if (!last_modified) { - /* does the client have? (att: caching "forever") */ - if (zlm = http_get_server_var("HTTP_IF_MODIFIED_SINCE")) { - last_modified = send_modified = http_parse_date(Z_STRVAL_P(zlm)); - /* send current time */ - } else { - send_modified = t; - } - /* negative value is supposed to be expiration time */ - } else if (last_modified < 0) { - last_modified += t; - send_modified = t; - /* send supplied time explicitly */ - } else { - send_modified = last_modified; - } - - RETURN_SUCCESS(http_cache_last_modified(last_modified, send_modified, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL))); -} -/* }}} */ - -/* {{{ proto bool http_cache_etag([string etag]) - * - * This function attempts to cache the HTTP body based on an ETag, - * either supplied or generated through calculation of the MD5 - * checksum of the output (uses output buffering). - * - * If clients "If-None-Match" header matches the supplied/calculated - * ETag, the body is considered cached on the clients side and - * a "304 Not Modified" status code is issued. - * - */ -PHP_FUNCTION(http_cache_etag) -{ - char *etag = NULL; - int etag_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &etag, &etag_len) != SUCCESS) { - RETURN_FALSE; - } - - RETURN_SUCCESS(http_cache_etag(etag, etag_len, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL))); -} -/* }}} */ - -/* {{{ proto string ob_etaghandler(string data, int mode) - * - * For use with ob_start(). - */ -PHP_FUNCTION(ob_etaghandler) -{ - char *data; - int data_len; - long mode; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) { - RETURN_FALSE; - } - - Z_TYPE_P(return_value) = IS_STRING; - http_ob_etaghandler(data, data_len, &Z_STRVAL_P(return_value), (uint *) &Z_STRLEN_P(return_value), mode); -} -/* }}} */ - -/* {{{ proto void http_throttle(double sec[, long bytes = 2097152]) - * - * Use with http_send() API. - * - * Example: - *
- * 
- * 
- */ -PHP_FUNCTION(http_throttle) -{ - long chunk_size; - double interval; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dl", &interval, &chunk_size)) { - return; - } - - HTTP_G(send).throttle_delay = interval; - HTTP_G(send).buffer_size = chunk_size; -} -/* }}} */ - -/* {{{ proto void http_redirect([string url[, array params[, bool session,[ bool permanent]]]]) - * - * Redirect to a given url. - * The supplied url will be expanded with http_absolute_uri(), the params array will - * be treated with http_build_query() and the session identification will be appended - * if session is true. - * - * Depending on permanent the redirection will be issued with a permanent - * ("301 Moved Permanently") or a temporary ("302 Found") redirection - * status code. - * - * To be RFC compliant, "Redirecting to URI." will be displayed, - * if the client doesn't redirect immediatly. - */ -PHP_FUNCTION(http_redirect) -{ - int url_len; - size_t query_len = 0; - zend_bool session = 0, permanent = 0, free_params = 0; - zval *params = NULL; - char *query = NULL, *url = NULL, *URI, *LOC, *RED = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bb", &url, &url_len, ¶ms, &session, &permanent) != SUCCESS) { - RETURN_FALSE; - } - - /* append session info */ - if (session) { - if (!params) { - free_params = 1; - MAKE_STD_ZVAL(params); - array_init(params); - } -#ifdef HAVE_PHP_SESSION -# ifdef COMPILE_DL_SESSION - if (SUCCESS == zend_get_module_started("session")) { - zval nm_retval, id_retval, func; - - INIT_PZVAL(&func); - INIT_PZVAL(&nm_retval); - INIT_PZVAL(&id_retval); - ZVAL_NULL(&nm_retval); - ZVAL_NULL(&id_retval); - - ZVAL_STRINGL(&func, "session_id", lenof("session_id"), 0); - call_user_function(EG(function_table), NULL, &func, &id_retval, 0, NULL TSRMLS_CC); - ZVAL_STRINGL(&func, "session_name", lenof("session_name"), 0); - call_user_function(EG(function_table), NULL, &func, &nm_retval, 0, NULL TSRMLS_CC); - - if ( Z_TYPE(nm_retval) == IS_STRING && Z_STRLEN(nm_retval) && - Z_TYPE(id_retval) == IS_STRING && Z_STRLEN(id_retval)) { - if (add_assoc_stringl_ex(params, Z_STRVAL(nm_retval), Z_STRLEN(nm_retval)+1, - Z_STRVAL(id_retval), Z_STRLEN(id_retval), 0) != SUCCESS) { - http_error(HE_WARNING, HTTP_E_RUNTIME, "Could not append session information"); - } - } - } -# else - if (PS(session_status) == php_session_active) { - if (add_assoc_string(params, PS(session_name), PS(id), 1) != SUCCESS) { - http_error(HE_WARNING, HTTP_E_RUNTIME, "Could not append session information"); - } - } -# endif -#endif - } - - /* treat params array with http_build_query() */ - if (params) { - if (SUCCESS != http_urlencode_hash_ex(Z_ARRVAL_P(params), 0, NULL, 0, &query, &query_len)) { - if (free_params) { - zval_dtor(params); - FREE_ZVAL(params); - } - if (query) { - efree(query); - } - RETURN_FALSE; - } - } - - URI = http_absolute_uri(url); - - if (query_len) { - spprintf(&LOC, 0, "Location: %s?%s", URI, query); - if (SG(request_info).request_method && strcmp(SG(request_info).request_method, "HEAD")) { - spprintf(&RED, 0, "Redirecting to %s?%s.\n", URI, query, URI, query); - } - } else { - spprintf(&LOC, 0, "Location: %s", URI); - if (SG(request_info).request_method && strcmp(SG(request_info).request_method, "HEAD")) { - spprintf(&RED, 0, "Redirecting to %s.\n", URI, URI); - } - } - - efree(URI); - if (query) { - efree(query); - } - if (free_params) { - zval_dtor(params); - FREE_ZVAL(params); - } - - RETURN_SUCCESS(http_exit_ex(permanent ? 301 : 302, LOC, RED, 1)); -} -/* }}} */ - -/* {{{ proto bool http_send_data(string data) - * - * Sends raw data with support for (multiple) range requests. - * - */ -PHP_FUNCTION(http_send_data) -{ - zval *zdata; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zdata) != SUCCESS) { - RETURN_FALSE; - } - - convert_to_string_ex(&zdata); - RETURN_SUCCESS(http_send_data(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata))); -} -/* }}} */ - -/* {{{ proto bool http_send_file(string file) - * - * Sends a file with support for (multiple) range requests. - * - */ -PHP_FUNCTION(http_send_file) -{ - char *file; - int flen = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &flen) != SUCCESS) { - RETURN_FALSE; - } - if (!flen) { - RETURN_FALSE; - } - - RETURN_SUCCESS(http_send_file(file)); -} -/* }}} */ - -/* {{{ proto bool http_send_stream(resource stream) - * - * Sends an already opened stream with support for (multiple) range requests. - * - */ -PHP_FUNCTION(http_send_stream) -{ - zval *zstream; - php_stream *file; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) != SUCCESS) { - RETURN_FALSE; - } - - php_stream_from_zval(file, &zstream); - RETURN_SUCCESS(http_send_stream(file)); -} -/* }}} */ - -/* {{{ proto string http_chunked_decode(string encoded) - * - * This function decodes a string that was HTTP-chunked encoded. - * Returns false on failure. - */ -PHP_FUNCTION(http_chunked_decode) -{ - char *encoded = NULL, *decoded = NULL; - size_t decoded_len = 0; - int encoded_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &encoded, &encoded_len) != SUCCESS) { - RETURN_FALSE; - } - - if (NULL != http_chunked_decode(encoded, encoded_len, &decoded, &decoded_len)) { - RETURN_STRINGL(decoded, (int) decoded_len, 0); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto object http_parse_message(string message) - * - * Parses (a) http_message(s) into a simple recursive object structure: - * - *
- *  3)));
- * 
- * stdClass object
- * (
- *     [type] => 2
- *     [httpVersion] => 1.1
- *     [responseCode] => 200
- *     [headers] => Array 
- *         (
- *             [Content-Length] => 3
- *             [Server] => Apache
- *         )
- *     [body]  => Hi!
- *     [parentMessage] => stdClass object
- *     (
- *         [type] => 2
- *         [httpVersion] => 1.1
- *         [responseCode] => 302
- *         [headers] => Array 
- *             (
- *                 [Content-Length] => 0
- *                 [Location] => ...
- *             )
- *         [body]  => 
- *         [parentMessage] => ...
- *     )
- * )
- * ?>
- * 
- */ -PHP_FUNCTION(http_parse_message) -{ - char *message; - int message_len; - http_message *msg = NULL; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &message, &message_len)) { - RETURN_NULL(); - } - - - if (msg = http_message_parse(message, message_len)) { - object_init(return_value); - http_message_tostruct_recursive(msg, return_value); - http_message_free(&msg); - } else { - RETURN_NULL(); - } -} -/* }}} */ - -/* {{{ proto array http_parse_headers(string header) - * - */ -PHP_FUNCTION(http_parse_headers) -{ - char *header; - int header_len; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len)) { - RETURN_FALSE; - } - - array_init(return_value); - if (SUCCESS != http_parse_headers(header, return_value)) { - zval_dtor(return_value); - RETURN_FALSE; - } -} -/* }}}*/ - -/* {{{ proto array http_get_request_headers(void) - * - * Get a list of incoming HTTP headers. - */ -PHP_FUNCTION(http_get_request_headers) -{ - NO_ARGS; - - array_init(return_value); - http_get_request_headers(return_value); -} -/* }}} */ - -/* {{{ proto string http_get_request_body(void) - * - * Get the raw request body (e.g. POST or PUT data). - */ -PHP_FUNCTION(http_get_request_body) -{ - char *body; - size_t length; - - NO_ARGS; - - if (SUCCESS == http_get_request_body(&body, &length)) { - RETURN_STRINGL(body, (int) length, 0); - } else { - RETURN_NULL(); - } -} -/* }}} */ - -/* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false]) - * - * Match an incoming HTTP header. - */ -PHP_FUNCTION(http_match_request_header) -{ - char *header, *value; - int header_len, value_len; - zend_bool match_case = 0; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &header, &header_len, &value, &value_len, &match_case)) { - RETURN_FALSE; - } - - RETURN_BOOL(http_match_request_header_ex(header, value, match_case)); -} -/* }}} */ - -/* {{{ HAVE_CURL */ -#ifdef HTTP_HAVE_CURL - -/* {{{ proto string http_get(string url[, array options[, array &info]]) - * - * Performs an HTTP GET request on the supplied url. - * - * The second parameter is expected to be an associative - * array where the following keys will be recognized: - *
- *  - redirect:         int, whether and how many redirects to follow
- *  - unrestrictedauth: bool, whether to continue sending credentials on
- *                      redirects to a different host
- *  - proxyhost:        string, proxy host in "host[:port]" format
- *  - proxyport:        int, use another proxy port as specified in proxyhost
- *  - proxyauth:        string, proxy credentials in "user:pass" format
- *  - proxyauthtype:    int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
- *  - httpauth:         string, http credentials in "user:pass" format
- *  - httpauthtype:     int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
- *  - compress:         bool, whether to allow gzip/deflate content encoding
- *                      (defaults to true)
- *  - port:             int, use another port as specified in the url
- *  - referer:          string, the referer to sends
- *  - useragent:        string, the user agent to send
- *                      (defaults to PECL::HTTP/version (PHP/version)))
- *  - headers:          array, list of custom headers as associative array
- *                      like array("header" => "value")
- *  - cookies:          array, list of cookies as associative array
- *                      like array("cookie" => "value")
- *  - cookiestore:      string, path to a file where cookies are/will be stored
- *  - resume:           int, byte offset to start the download from;
- *                      if the server supports ranges
- *  - maxfilesize:      int, maximum file size that should be downloaded;
- *                      has no effect, if the size of the requested entity is not known
- *  - lastmodified:     int, timestamp for If-(Un)Modified-Since header
- *  - timeout:          int, seconds the request may take
- *  - connecttimeout:   int, seconds the connect may take
- *  - onprogress:       mixed, progress callback
- * 
- * - * The optional third parameter will be filled with some additional information - * in form af an associative array, if supplied, like the following example: - *
- *  'http://localhost',
- *     'response_code' => 403,
- *     'total_time' => 0.017,
- *     'namelookup_time' => 0.013,
- *     'connect_time' => 0.014,
- *     'pretransfer_time' => 0.014,
- *     'size_upload' => 0,
- *     'size_download' => 202,
- *     'speed_download' => 11882,
- *     'speed_upload' => 0,
- *     'header_size' => 145,
- *     'request_size' => 62,
- *     'ssl_verifyresult' => 0,
- *     'filetime' => -1,
- *     'content_length_download' => 202,
- *     'content_length_upload' => 0,
- *     'starttransfer_time' => 0.017,
- *     'content_type' => 'text/html; charset=iso-8859-1',
- *     'redirect_time' => 0,
- *     'redirect_count' => 0,
- *     'http_connectcode' => 0,
- *     'httpauth_avail' => 0,
- *     'proxyauth_avail' => 0,
- * )
- * ?>
- * 
- */ -PHP_FUNCTION(http_get) -{ - zval *options = NULL, *info = NULL; - char *URL; - int URL_len; - phpstr response; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) { - RETURN_FALSE; - } - - if (info) { - zval_dtor(info); - array_init(info); - } - - phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0); - if (SUCCESS == http_get(URL, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) { - RETURN_PHPSTR_VAL(&response); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto string http_head(string url[, array options[, array &info]]) - * - * Performs an HTTP HEAD request on the suppied url. - * Returns the HTTP response as string. - * See http_get() for a full list of available options. - */ -PHP_FUNCTION(http_head) -{ - zval *options = NULL, *info = NULL; - char *URL; - int URL_len; - phpstr response; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) { - RETURN_FALSE; - } - - if (info) { - zval_dtor(info); - array_init(info); - } - - phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0); - if (SUCCESS == http_head(URL, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) { - RETURN_PHPSTR_VAL(&response); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto string http_post_data(string url, string data[, array options[, array &info]]) - * - * Performs an HTTP POST request, posting data. - * Returns the HTTP response as string. - * See http_get() for a full list of available options. - */ -PHP_FUNCTION(http_post_data) -{ - zval *options = NULL, *info = NULL; - char *URL, *postdata; - int postdata_len, URL_len; - phpstr response; - http_request_body body; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &postdata, &postdata_len, &options, &info) != SUCCESS) { - RETURN_FALSE; - } - - if (info) { - zval_dtor(info); - array_init(info); - } - - body.type = HTTP_REQUEST_BODY_CSTRING; - body.data = postdata; - body.size = postdata_len; - - phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0); - if (SUCCESS == http_post(URL, &body, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) { - RETVAL_PHPSTR_VAL(&response); - } else { - RETVAL_FALSE; - } -} -/* }}} */ - -/* {{{ proto string http_post_fields(string url, array data[, array files[, array options[, array &info]]]) - * - * Performs an HTTP POST request, posting www-form-urlencoded array data. - * Returns the HTTP response as string. - * See http_get() for a full list of available options. - */ -PHP_FUNCTION(http_post_fields) -{ - zval *options = NULL, *info = NULL, *fields, *files = NULL; - char *URL; - int URL_len; - phpstr response; - http_request_body body; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|aa/!z", &URL, &URL_len, &fields, &files, &options, &info) != SUCCESS) { - RETURN_FALSE; - } - - if (SUCCESS != http_request_body_fill(&body, Z_ARRVAL_P(fields), files ? Z_ARRVAL_P(files) : NULL)) { - RETURN_FALSE; - } - - if (info) { - zval_dtor(info); - array_init(info); - } - - phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0); - if (SUCCESS == http_post(URL, &body, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) { - RETVAL_PHPSTR_VAL(&response); - } else { - RETVAL_FALSE; - } - http_request_body_dtor(&body); -} -/* }}} */ - -/* {{{ proto string http_put_file(string url, string file[, array options[, array &info]]) - * - * Performs an HTTP PUT request, uploading file. - * Returns the HTTP response as string. - * See http_get() for a full list of available options. - */ -PHP_FUNCTION(http_put_file) -{ - char *URL, *file; - int URL_len, f_len; - zval *options = NULL, *info = NULL; - phpstr response; - php_stream *stream; - php_stream_statbuf ssb; - http_request_body body; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &file, &f_len, &options, &info)) { - RETURN_FALSE; - } - - if (!(stream = php_stream_open_wrapper(file, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL))) { - RETURN_FALSE; - } - if (php_stream_stat(stream, &ssb)) { - php_stream_close(stream); - RETURN_FALSE; - } - - if (info) { - zval_dtor(info); - array_init(info); - } - - body.type = HTTP_REQUEST_BODY_UPLOADFILE; - body.data = stream; - body.size = ssb.sb.st_size; - - phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0); - if (SUCCESS == http_put(URL, &body, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) { - RETVAL_PHPSTR_VAL(&response); - } else { - RETVAL_FALSE; - } - http_request_body_dtor(&body); -} -/* }}} */ - -/* {{{ proto string http_put_stream(string url, resource stream[, array options[, array &info]]) - * - * Performs an HTTP PUT request, uploading stream. - * Returns the HTTP response as string. - * See http_get() for a full list of available options. - */ -PHP_FUNCTION(http_put_stream) -{ - zval *resource, *options = NULL, *info = NULL; - char *URL; - int URL_len; - phpstr response; - php_stream *stream; - php_stream_statbuf ssb; - http_request_body body; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sr|a/!z", &URL, &URL_len, &resource, &options, &info)) { - RETURN_FALSE; - } - - php_stream_from_zval(stream, &resource); - if (php_stream_stat(stream, &ssb)) { - RETURN_FALSE; - } - - if (info) { - zval_dtor(info); - array_init(info); - } - - body.type = HTTP_REQUEST_BODY_UPLOADFILE; - body.data = stream; - body.size = ssb.sb.st_size; - - phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0); - if (SUCCESS == http_put(URL, &body, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) { - RETURN_PHPSTR_VAL(&response); - } else { - RETURN_NULL(); - } -} -/* }}} */ -#endif /* HTTP_HAVE_CURL */ -/* }}} HAVE_CURL */ - -/* {{{ proto long http_request_method_register(string method) - * - * Register a custom request method. - */ -PHP_FUNCTION(http_request_method_register) -{ - char *method; - int *method_len; - unsigned long existing; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) { - RETURN_FALSE; - } - if (existing = http_request_method_exists(1, 0, method)) { - RETURN_LONG((long) existing); - } - - RETVAL_LONG((long) http_request_method_register(method)); -} -/* }}} */ - -/* {{{ proto bool http_request_method_unregister(mixed method) - * - * Unregister a previously registered custom request method. - */ -PHP_FUNCTION(http_request_method_unregister) -{ - zval *method; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) { - RETURN_FALSE; - } - - switch (Z_TYPE_P(method)) - { - case IS_OBJECT: - convert_to_string(method); - case IS_STRING: - if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) { - convert_to_long(method); - } else { - unsigned long mn; - if (!(mn = http_request_method_exists(1, 0, Z_STRVAL_P(method)))) { - RETURN_FALSE; - } - zval_dtor(method); - ZVAL_LONG(method, (long)mn); - } - case IS_LONG: - RETURN_SUCCESS(http_request_method_unregister(Z_LVAL_P(method))); - default: - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto long http_request_method_exists(mixed method) - * - * Check if a request method is registered (or available by default). - */ -PHP_FUNCTION(http_request_method_exists) -{ - IF_RETVAL_USED { - zval *method; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) { - RETURN_FALSE; - } - - switch (Z_TYPE_P(method)) - { - case IS_OBJECT: - convert_to_string(method); - case IS_STRING: - if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) { - convert_to_long(method); - } else { - RETURN_LONG((long) http_request_method_exists(1, 0, Z_STRVAL_P(method))); - } - case IS_LONG: - RETURN_LONG((long) http_request_method_exists(0, Z_LVAL_P(method), NULL)); - default: - RETURN_FALSE; - } - } -} -/* }}} */ - -/* {{{ proto string http_request_method_name(long method) - * - * Get the literal string representation of a standard or registered request method. - */ -PHP_FUNCTION(http_request_method_name) -{ - IF_RETVAL_USED { - long method; - - if ((SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method)) || (method < 0)) { - RETURN_FALSE; - } - - RETURN_STRING(estrdup(http_request_method_name((unsigned long) method)), 0); - } -} -/* }}} */ - -/* {{{ Sara Golemons http_build_query() */ -#ifndef ZEND_ENGINE_2 - -/* {{{ proto string http_build_query(mixed formdata [, string prefix[, string arg_separator]]) - Generates a form-encoded query string from an associative array or object. */ -PHP_FUNCTION(http_build_query) -{ - zval *formdata; - char *prefix = NULL, *arg_sep = INI_STR("arg_separator.output"); - int prefix_len = 0, arg_sep_len = strlen(arg_sep); - phpstr *formstr; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) { - RETURN_FALSE; - } - - if (Z_TYPE_P(formdata) != IS_ARRAY && Z_TYPE_P(formdata) != IS_OBJECT) { - http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Parameter 1 expected to be Array or Object. Incorrect value given."); - RETURN_FALSE; - } - - if (!arg_sep_len) { - arg_sep = HTTP_URL_ARGSEP; - } - - formstr = phpstr_new(); - if (SUCCESS != http_urlencode_hash_implementation_ex(HASH_OF(formdata), formstr, arg_sep, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL))) { - phpstr_free(&formstr); - RETURN_FALSE; - } - - if (!formstr->used) { - phpstr_free(&formstr); - RETURN_NULL(); - } - - RETURN_PHPSTR_PTR(formstr); -} -/* }}} */ -#endif /* !ZEND_ENGINE_2 */ -/* }}} */ - -PHP_FUNCTION(http_test) -{ -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_headers_api.c b/http_headers_api.c deleted file mode 100644 index 63c46ab..0000000 --- a/http_headers_api.c +++ /dev/null @@ -1,486 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "ext/standard/php_string.h" -#include "ext/standard/url.h" - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_headers_api.h" -#include "php_http_info_api.h" - -#include - -ZEND_EXTERN_MODULE_GLOBALS(http); - -#ifndef HTTP_DBG_NEG -# define HTTP_DBG_NEG 0 -#endif - -/* {{{ static int http_sort_q(const void *, const void *) */ -static int http_sort_q(const void *a, const void *b TSRMLS_DC) -{ - Bucket *f, *s; - zval result, *first, *second; - - f = *((Bucket **) a); - s = *((Bucket **) b); - - first = *((zval **) f->pData); - second= *((zval **) s->pData); - - if (numeric_compare_function(&result, first, second TSRMLS_CC) != SUCCESS) { - return 0; - } - return (Z_LVAL(result) > 0 ? -1 : (Z_LVAL(result) < 0 ? 1 : 0)); -} -/* }}} */ - -/* {{{ char *http_negotiate_language_func */ -char *_http_negotiate_language_func(const char *test, double *quality, HashTable *supported TSRMLS_DC) -{ - zval **value; - const char *dash_test; - - FOREACH_HASH_VAL(supported, value) { -#if HTTP_DBG_NEG - fprintf(stderr, "strcasecmp('%s', '%s')\n", Z_STRVAL_PP(value), test); -#endif - if (!strcasecmp(Z_STRVAL_PP(value), test)) { - return Z_STRVAL_PP(value); - } - } - - /* no distinct match found, so try primaries */ - if (dash_test = strchr(test, '-')) { - FOREACH_HASH_VAL(supported, value) { - int len = dash_test - test; -#if HTTP_DBG_NEG - fprintf(stderr, "strncascmp('%s', '%s', %d)\n", Z_STRVAL_PP(value), test, len); -#endif - if ( (!strncasecmp(Z_STRVAL_PP(value), test, len)) && - ( (Z_STRVAL_PP(value)[len] == '\0') || - (Z_STRVAL_PP(value)[len] == '-'))) { - *quality /= 2; - return Z_STRVAL_PP(value); - } - } - } - - return NULL; -} -/* }}} */ - -/* {{{ char *http_negotiate_charset_func */ -char *_http_negotiate_charset_func(const char *test, double *quality, HashTable *supported TSRMLS_DC) -{ - zval **value; - - FOREACH_HASH_VAL(supported, value) { -#if HTTP_DBG_NEG - fprintf(stderr, "strcasecmp('%s', '%s')\n", Z_STRVAL_PP(value), test); -#endif - if (!strcasecmp(Z_STRVAL_PP(value), test)) { - return Z_STRVAL_PP(value); - } - } - - return NULL; -} -/* }}} */ - -/* {{{ HashTable *http_negotiate_q(const char *, HashTable *, negotiate_func_t) */ -PHP_HTTP_API HashTable *_http_negotiate_q(const char *header, HashTable *supported, negotiate_func_t neg TSRMLS_DC) -{ - zval *accept; - HashTable *result = NULL; - -#if HTTP_DBG_NEG - fprintf(stderr, "Reading header %s: ", header); -#endif - HTTP_GSC(accept, header, NULL); -#if HTTP_DBG_NEG - fprintf(stderr, "%s\n", Z_STRVAL_P(accept)); -#endif - - if (Z_STRLEN_P(accept)) { - zval ex_arr, ex_del; - - INIT_PZVAL(&ex_del); - INIT_PZVAL(&ex_arr); - ZVAL_STRINGL(&ex_del, ",", 1, 0); - array_init(&ex_arr); - - php_explode(&ex_del, accept, &ex_arr, -1); - - if (zend_hash_num_elements(Z_ARRVAL(ex_arr)) > 0) { - int i = 0; - zval **entry, array; - - INIT_PZVAL(&array); - array_init(&array); - - FOREACH_HASH_VAL(Z_ARRVAL(ex_arr), entry) { - double quality; - char *selected, *identifier; - const char *separator; - -#if HTTP_DBG_NEG - fprintf(stderr, "Checking %s\n", Z_STRVAL_PP(entry)); -#endif - - if (separator = strchr(Z_STRVAL_PP(entry), ';')) { - const char *ptr = separator; - - while (*++ptr && !isdigit(*ptr)); - - quality = atof(ptr); - identifier = estrndup(Z_STRVAL_PP(entry), separator - Z_STRVAL_PP(entry)); - } else { - quality = 1000.0 - i++; - identifier = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry)); - } - - if (selected = neg(identifier, &quality, supported TSRMLS_CC)) { - /* don't overwrite previously set with higher quality */ - if (!zend_hash_exists(Z_ARRVAL(array), selected, strlen(selected) + 1)) { - add_assoc_double(&array, selected, quality); - } - } - - efree(identifier); - } - - result = Z_ARRVAL(array); - zend_hash_sort(result, zend_qsort, http_sort_q, 0 TSRMLS_CC); - } - - zval_dtor(&ex_arr); - } - - return result; -} -/* }}} */ - -/* {{{ http_range_status http_get_request_ranges(HashTable *ranges, size_t) */ -PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, size_t length TSRMLS_DC) -{ - zval *zrange; - char *range, c; - long begin = -1, end = -1, *ptr; - - HTTP_GSC(zrange, "HTTP_RANGE", RANGE_NO); - range = Z_STRVAL_P(zrange); - - if (strncmp(range, "bytes=", sizeof("bytes=") - 1)) { - return RANGE_NO; - } - - ptr = &begin; - range += sizeof("bytes=") - 1; - - do { - switch (c = *(range++)) - { - case '0': - /* allow 000... - shall we? */ - if (*ptr != -10) { - *ptr *= 10; - } - break; - - case '1': case '2': case '3': - case '4': case '5': case '6': - case '7': case '8': case '9': - /* - * If the value of the pointer is already set (non-negative) - * then multiply its value by ten and add the current value, - * else initialise the pointers value with the current value - * -- - * This let us recognize empty fields when validating the - * ranges, i.e. a "-10" for begin and "12345" for the end - * was the following range request: "Range: bytes=0-12345"; - * While a "-1" for begin and "12345" for the end would - * have been: "Range: bytes=-12345". - */ - if (*ptr > 0) { - *ptr *= 10; - *ptr += c - '0'; - } else { - *ptr = c - '0'; - } - break; - - case '-': - ptr = &end; - break; - - case ' ': - /* IE - ignore for now */ - break; - - case 0: - case ',': - - if (length) { - /* validate ranges */ - switch (begin) - { - /* "0-12345" */ - case -10: - /* "0-" */ - if (end == -1) { - return RANGE_NO; - } - /* "0-0" or overflow */ - if (end == -10 || length <= (size_t) end) { - return RANGE_ERR; - } - begin = 0; - break; - - /* "-12345" */ - case -1: - /* "-", "-0" or overflow */ - if (end == -1 || end == -10 || length <= (size_t) end) { - return RANGE_ERR; - } - begin = length - end; - end = length - 1; - break; - - /* "12345-(xxx)" */ - default: - switch (end) - { - /* "12345-0" */ - case -10: - return RANGE_ERR; - break; - - /* "12345-" */ - case -1: - if (length <= (size_t) begin) { - return RANGE_ERR; - } - end = length - 1; - break; - - /* "12345-67890" */ - default: - if ( (length <= (size_t) begin) || - (length <= (size_t) end) || - (end < begin)) { - return RANGE_ERR; - } - break; - } - break; - } - } - { - zval *zentry; - MAKE_STD_ZVAL(zentry); - array_init(zentry); - add_index_long(zentry, 0, begin); - add_index_long(zentry, 1, end); - zend_hash_next_index_insert(ranges, &zentry, sizeof(zval *), NULL); - - begin = -1; - end = -1; - ptr = &begin; - } - break; - - default: - return RANGE_NO; - break; - } - } while (c != 0); - - return RANGE_OK; -} -/* }}} */ - -/* {{{ STATUS http_parse_headers(char *, HashTable *, zend_bool) */ -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) -{ - const char *colon = NULL, *line = NULL, *begin = header; - const char *body = http_locate_body(header); - size_t header_len; - zval array; - - INIT_ZARR(array, headers); - - if (body) { - header_len = body - header; - } else { - header_len = strlen(header) + 1; - } - line = header; - - while (header_len >= (size_t) (line - begin)) { - int value_len = 0; - /* note: valgrind may choke on that -- should be safe though */ - switch (*line++) - { - case ':': - if (!colon) { - colon = line - 1; - } - break; - - case 0: - --value_len; /* we don't have CR so value length is one char less */ - case '\n': - if ((!(*line - 1)) || ((*line != ' ') && (*line != '\t'))) { - http_info i; - - /* response/request line */ - if (SUCCESS == http_info_parse(header, &i)) { - callback_func(callback_data, &headers, &i TSRMLS_CC); - http_info_dtor(&i); - Z_ARRVAL(array) = headers; - } else - - /* "header: value" pair */ - if (colon) { - - /* skip empty key */ - if (header != colon) { - zval **previous = NULL; - char *value; - int keylen = colon - header; - char *key = estrndup(header, keylen); - - if (prettify) { - key = pretty_key(key, keylen, 1, 1); - } - - value_len += line - colon - 1; - - /* skip leading ws */ - while (isspace(*(++colon))) --value_len; - /* skip trailing ws */ - while (isspace(colon[value_len - 1])) --value_len; - - if (value_len > 0) { - value = estrndup(colon, value_len); - } else { - value = estrdup(""); - value_len = 0; - } - - /* if we already have got such a header make an array of those */ - if (SUCCESS == zend_hash_find(headers, key, keylen + 1, (void **) &previous)) { - /* convert to array */ - if (Z_TYPE_PP(previous) != IS_ARRAY) { - convert_to_array(*previous); - } - add_next_index_stringl(*previous, value, value_len, 0); - } else { - add_assoc_stringl(&array, key, value, value_len, 0); - } - efree(key); - } - } - colon = NULL; - value_len = 0; - header += line - header; - } - break; - } - } - return SUCCESS; -} -/* }}} */ - -/* {{{ void http_get_request_headers_ex(HashTable *, zend_bool) */ -PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool prettify TSRMLS_DC) -{ - char *key = NULL; - ulong idx = 0; - zval array, **hsv; - - Z_ARRVAL(array) = headers; - - if (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &hsv)) { - FOREACH_KEY(*hsv, key, idx) { - if (key && !strncmp(key, "HTTP_", 5)) { - zval **header; - - key += 5; - if (prettify) { - key = pretty_key(key, strlen(key), 1, 1); - } - - zend_hash_get_current_data(Z_ARRVAL_PP(hsv), (void **) &header); - add_assoc_stringl(&array, key, Z_STRVAL_PP(header), Z_STRLEN_PP(header), 1); - key = NULL; - } - } - } -} -/* }}} */ - -/* {{{ zend_bool http_match_request_header(char *, char *) */ -PHP_HTTP_API zend_bool _http_match_request_header_ex(const char *header, const char *value, zend_bool match_case TSRMLS_DC) -{ - char *name, *key = NULL; - ulong idx; - zend_bool result = 0; - HashTable headers; - - name = pretty_key(estrdup(header), strlen(header), 1, 1); - zend_hash_init(&headers, 0, NULL, ZVAL_PTR_DTOR, 0); - http_get_request_headers_ex(&headers, 1); - - FOREACH_HASH_KEY(&headers, key, idx) { - if (key && (!strcmp(key, name))) { - zval **data; - - if (SUCCESS == zend_hash_get_current_data(&headers, (void **) &data)) { - result = (match_case ? strcmp(Z_STRVAL_PP(data), value) : strcasecmp(Z_STRVAL_PP(data), value)) ? 0 : 1; - } - break; - } - } - - zend_hash_destroy(&headers); - efree(name); - - return result; -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_info_api.c b/http_info_api.c deleted file mode 100644 index 0e9b648..0000000 --- a/http_info_api.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "php_http.h" -#include "php_http_api.h" -#include "php_http_std_defs.h" -#include "php_http_info_api.h" - -#include - -ZEND_EXTERN_MODULE_GLOBALS(http); - -PHP_HTTP_API void _http_info_default_callback(void **nothing, HashTable **headers, http_info *info TSRMLS_DC) -{ - zval array; - - INIT_ZARR(array, *headers); - - switch (info->type) - { - case IS_HTTP_REQUEST: - add_assoc_string(&array, "Request Method", HTTP_INFO(info).request.method, 1); - add_assoc_string(&array, "Request Uri", HTTP_INFO(info).request.URI, 1); - break; - - case IS_HTTP_RESPONSE: - add_assoc_long(&array, "Response Code", (long) HTTP_INFO(info).response.code); - add_assoc_string(&array, "Response Status", HTTP_INFO(info).response.status, 1); - break; - } -} - -PHP_HTTP_API void _http_info_dtor(http_info *info) -{ - http_info_t *i = (http_info_t *) info; - - switch (info->type) - { - case IS_HTTP_REQUEST: - STR_SET(i->request.method, NULL); - STR_SET(i->request.URI, NULL); - break; - - case IS_HTTP_RESPONSE: - STR_SET(i->response.status, NULL); - break; - - default: - break; - } -} - -PHP_HTTP_API STATUS _http_info_parse_ex(const char *pre_header, http_info *info, zend_bool silent TSRMLS_DC) -{ - const char *end, *http; - - /* sane parameter */ - if ((!pre_header) || (!*pre_header)) { - if (!silent) { - http_error(HE_WARNING, HTTP_E_MALFORMED_HEADERS, "Empty pre-header HTTP info"); - } - return FAILURE; - } - - /* where's the end of the line */ - if (!(end = http_locate_eol(pre_header, NULL))) { - end = pre_header + strlen(pre_header); - } - - /* there must be HTTP/1.x in the line - * and nothing than SPACE or NUL after HTTP/1.x - */ - if ( (!(http = strstr(pre_header, "HTTP/1."))) || - (!(http < end)) || - (!isdigit(http[lenof("HTTP/1.")])) || - (http[lenof("HTTP/1.1")] && (!isspace(http[lenof("HTTP/1.1")])))) { - if (!silent) { - http_error(HE_WARNING, HTTP_E_MALFORMED_HEADERS, "Invalid or missing HTTP/1.x protocol identification"); - } - return FAILURE; - } - -#if 0 - { - char *line = estrndup(pre_header, end - pre_header); - fprintf(stderr, "http_parse_info('%s')\n", line); - efree(line); - } -#endif - - info->http.version = atof(http + lenof("HTTP/")); - - /* is response */ - if (pre_header == http) { - char *status = NULL; - const char *code = http + sizeof("HTTP/1.1"); - - info->type = IS_HTTP_RESPONSE; - HTTP_INFO(info).response.code = (code && (end > code)) ? strtol(code, &status, 10) : 0; - HTTP_INFO(info).response.status = (status && (end > ++status)) ? estrndup(status, end - status) : ecalloc(1,1); - - return SUCCESS; - } - - /* is request */ - else { - const char *url = strchr(pre_header, ' '); - - info->type = IS_HTTP_REQUEST; - if (url && http > url) { - HTTP_INFO(info).request.method = estrndup(pre_header, url - pre_header); - HTTP_INFO(info).request.URI = estrndup(url + 1, http - url - 2); - } else { - HTTP_INFO(info).request.method = ecalloc(1,1); - HTTP_INFO(info).request.URI = ecalloc(1,1); - } - - return SUCCESS; - } -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_message_api.c b/http_message_api.c deleted file mode 100644 index 36b3098..0000000 --- a/http_message_api.c +++ /dev/null @@ -1,513 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_message_api.h" -#include "php_http_headers_api.h" -#include "php_http_send_api.h" -#include "php_http_request_api.h" -#include "php_http_url_api.h" - -#include "phpstr/phpstr.h" - -ZEND_EXTERN_MODULE_GLOBALS(http); - -#define http_message_info_callback _http_message_info_callback -static void _http_message_info_callback(http_message **message, HashTable **headers, http_info *info TSRMLS_DC) -{ - http_message *old = *message; - - /* advance message */ - if (old->type || zend_hash_num_elements(&old->hdrs) || PHPSTR_LEN(old)) { - (*message) = http_message_new(); - (*message)->parent = old; - (*headers) = &((*message)->hdrs); - } - - (*message)->http.version = info->http.version; - - switch (info->type) - { - case IS_HTTP_REQUEST: - (*message)->type = HTTP_MSG_REQUEST; - HTTP_INFO(*message).request.URI = estrdup(HTTP_INFO(info).request.URI); - HTTP_INFO(*message).request.method = estrdup(HTTP_INFO(info).request.method); - break; - - case IS_HTTP_RESPONSE: - (*message)->type = HTTP_MSG_RESPONSE; - HTTP_INFO(*message).response.code = HTTP_INFO(info).response.code; - HTTP_INFO(*message).response.status = estrdup(HTTP_INFO(info).response.status); - break; - } -} - -#define http_message_init_type _http_message_init_type -static inline void _http_message_init_type(http_message *message, http_message_type type) -{ - message->http.version = .0; - - switch (message->type = type) - { - case HTTP_MSG_RESPONSE: - message->http.info.response.code = 0; - message->http.info.response.status = NULL; - break; - - case HTTP_MSG_REQUEST: - message->http.info.request.method = NULL; - message->http.info.request.URI = NULL; - break; - - case HTTP_MSG_NONE: - default: - break; - } -} - -PHP_HTTP_API http_message *_http_message_init_ex(http_message *message, http_message_type type) -{ - if (!message) { - message = ecalloc(1, sizeof(http_message)); - } - - http_message_init_type(message, type); - message->parent = NULL; - phpstr_init(&message->body); - zend_hash_init(&message->hdrs, 0, NULL, ZVAL_PTR_DTOR, 0); - - return message; -} - - -PHP_HTTP_API void _http_message_set_type(http_message *message, http_message_type type) -{ - /* just act if different */ - if (type != message->type) { - - /* free request info */ - switch (message->type) - { - case HTTP_MSG_REQUEST: - STR_FREE(message->http.info.request.method); - STR_FREE(message->http.info.request.URI); - break; - - case HTTP_MSG_RESPONSE: - STR_FREE(message->http.info.response.status); - break; - - default: - break; - } - - /* init */ - http_message_init_type(message, type); - } -} - -PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t message_length TSRMLS_DC) -{ - const char *body = NULL; - zend_bool free_msg = msg ? 0 : 1; - - if ((!message) || (message_length < HTTP_MSG_MIN_SIZE)) { - return NULL; - } - - msg = http_message_init(msg); - - if (SUCCESS != http_parse_headers_cb(message, &msg->hdrs, 1, (http_info_callback) http_message_info_callback, (void **) &msg)) { - if (free_msg) { - http_message_free(&msg); - } - return NULL; - } - - /* header parsing stops at (CR)LF (CR)LF */ - if (body = http_locate_body(message)) { - zval *c; - const char *continue_at = NULL; - - /* message has chunked transfer encoding */ - if (c = http_message_header(msg, "Transfer-Encoding")) { - if (!strcasecmp("chunked", Z_STRVAL_P(c))) { - char *decoded; - size_t decoded_len; - - /* decode and replace Transfer-Encoding with Content-Length header */ - if (continue_at = http_chunked_decode(body, message + message_length - body, &decoded, &decoded_len)) { - phpstr_from_string_ex(PHPSTR(msg), decoded, decoded_len); - efree(decoded); - { - zval *len; - char *tmp; - - spprintf(&tmp, 0, "%lu", (ulong) decoded_len); - MAKE_STD_ZVAL(len); - ZVAL_STRING(len, tmp, 0); - - zend_hash_del(&msg->hdrs, "Transfer-Encoding", sizeof("Transfer-Encoding")); - zend_hash_add(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &len, sizeof(zval *), NULL); - } - } - } - } else - - /* message has content-length header */ - if (c = http_message_header(msg, "Content-Length")) { - long len = atol(Z_STRVAL_P(c)); - phpstr_from_string_ex(PHPSTR(msg), body, len); - continue_at = body + len; - } else - - /* message has content-range header */ - if (c = http_message_header(msg, "Content-Range")) { - ulong start = 0, end = 0; - - sscanf(Z_STRVAL_P(c), "bytes=%lu-%lu", &start, &end); - if (end > start) { - phpstr_from_string_ex(PHPSTR(msg), body, (size_t) (end - start)); - continue_at = body + (end - start); - } - } else - - /* no headers that indicate content length */ - if (HTTP_MSG_TYPE(RESPONSE, msg)) { - phpstr_from_string_ex(PHPSTR(msg), body, message + message_length - body); - } else { - continue_at = body; - } - - /* check for following messages */ - if (continue_at) { - while (isspace(*continue_at)) ++continue_at; - if (continue_at < (message + message_length)) { - http_message *next = NULL, *most = NULL; - - /* set current message to parent of most parent following messages and return deepest */ - if (most = next = http_message_parse(continue_at, message + message_length - continue_at)) { - while (most->parent) most = most->parent; - most->parent = msg; - msg = next; - } - } - } - } - - return msg; -} - -PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length) -{ - phpstr str; - char *key, *data; - ulong idx; - zval **header; - - phpstr_init_ex(&str, 4096, 0); - - switch (msg->type) - { - case HTTP_MSG_REQUEST: - phpstr_appendf(&str, "%s %s HTTP/%1.1f" HTTP_CRLF, - msg->http.info.request.method, - msg->http.info.request.URI, - msg->http.version); - break; - - case HTTP_MSG_RESPONSE: - phpstr_appendf(&str, "HTTP/%1.1f %d%s%s" HTTP_CRLF, - msg->http.version, - msg->http.info.response.code, - *msg->http.info.response.status ? " ":"", - msg->http.info.response.status); - break; - - case HTTP_MSG_NONE: - default: - break; - } - - FOREACH_HASH_KEYVAL(&msg->hdrs, key, idx, header) { - if (key) { - zval **single_header; - - switch (Z_TYPE_PP(header)) - { - case IS_STRING: - phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key, Z_STRVAL_PP(header)); - break; - - case IS_ARRAY: - FOREACH_VAL(*header, single_header) { - phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key, Z_STRVAL_PP(single_header)); - } - break; - } - - key = NULL; - } - } - - if (PHPSTR_LEN(msg)) { - phpstr_appends(&str, HTTP_CRLF); - phpstr_append(&str, PHPSTR_VAL(msg), PHPSTR_LEN(msg)); - phpstr_appends(&str, HTTP_CRLF); - } - - data = phpstr_data(&str, string, length); - if (!string) { - efree(data); - } - - phpstr_dtor(&str); -} - -PHP_HTTP_API void _http_message_serialize(http_message *message, char **string, size_t *length) -{ - char *buf; - size_t len; - phpstr str; - - phpstr_init(&str); - - do { - http_message_tostring(message, &buf, &len); - phpstr_prepend(&str, buf, len); - efree(buf); - } while (message = message->parent); - - buf = phpstr_data(&str, string, length); - if (!string) { - efree(buf); - } - - phpstr_dtor(&str); -} - -PHP_HTTP_API void _http_message_tostruct_recursive(http_message *msg, zval *obj TSRMLS_DC) -{ - zval strct; - zval *headers; - - INIT_ZARR(strct, HASH_OF(obj)); - - add_assoc_long(&strct, "type", msg->type); - add_assoc_double(&strct, "httpVersion", msg->http.version); - switch (msg->type) - { - case HTTP_MSG_RESPONSE: - add_assoc_long(&strct, "responseCode", msg->http.info.response.code); - add_assoc_string(&strct, "responseStatus", msg->http.info.response.status, 1); - break; - - case HTTP_MSG_REQUEST: - add_assoc_string(&strct, "requestMethod", msg->http.info.request.method, 1); - add_assoc_string(&strct, "requestUri", msg->http.info.request.URI, 1); - break; - } - - MAKE_STD_ZVAL(headers); - array_init(headers); - zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - add_assoc_zval(&strct, "headers", headers); - - add_assoc_stringl(&strct, "body", PHPSTR_VAL(msg), PHPSTR_LEN(msg), 1); - - if (msg->parent) { - zval *parent; - - MAKE_STD_ZVAL(parent); - if (Z_TYPE_P(obj) == IS_ARRAY) { - array_init(parent); - } else { - object_init(parent); - } - add_assoc_zval(&strct, "parentMessage", parent); - http_message_tostruct_recursive(msg->parent, parent); - zval_ptr_dtor(&parent); - } else { - add_assoc_null(&strct, "parentMessage"); - } -} - -PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC) -{ - STATUS rs = FAILURE; - - switch (message->type) - { - case HTTP_MSG_RESPONSE: - { - char *key; - ulong idx; - zval **val; - - FOREACH_HASH_KEYVAL(&message->hdrs, key, idx, val) { - if (key) { - if (Z_TYPE_PP(val) == IS_ARRAY) { - zend_bool first = 1; - zval **data; - - FOREACH_VAL(*val, data) { - http_send_header_ex(key, strlen(key), Z_STRVAL_PP(data), Z_STRLEN_PP(data), first, NULL); - first = 0; - } - } else { - http_send_header_ex(key, strlen(key), Z_STRVAL_PP(val), Z_STRLEN_PP(val), 1, NULL); - } - key = NULL; - } - } - rs = SUCCESS == http_send_status(message->http.info.response.code) && - SUCCESS == http_send_data(PHPSTR_VAL(message), PHPSTR_LEN(message)) ? - SUCCESS : FAILURE; - } - break; - - case HTTP_MSG_REQUEST: - { -#ifdef HTTP_HAVE_CURL - char *uri = NULL; - zval **zhost, options, headers; - - INIT_PZVAL(&options); - INIT_PZVAL(&headers); - array_init(&options); - array_init(&headers); - zend_hash_copy(Z_ARRVAL(headers), &message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - add_assoc_zval(&options, "headers", &headers); - - /* check host header */ - if (SUCCESS == zend_hash_find(&message->hdrs, "Host", sizeof("Host"), (void **) &zhost)) { - char *colon = NULL, *host = NULL; - size_t host_len = 0; - int port = 0; - - /* check for port */ - if (colon = strchr(Z_STRVAL_PP(zhost), ':')) { - port = atoi(colon + 1); - host = estrndup(Z_STRVAL_PP(zhost), host_len = (Z_STRVAL_PP(zhost) - colon - 1)); - } else { - host = estrndup(Z_STRVAL_PP(zhost), host_len = Z_STRLEN_PP(zhost)); - } - uri = http_absolute_uri_ex( - message->http.info.request.URI, strlen(message->http.info.request.URI), - NULL, 0, host, host_len, port); - efree(host); - } else { - uri = http_absolute_uri(message->http.info.request.URI); - } - - if (!strcasecmp("POST", message->http.info.request.method)) { - http_request_body body = {HTTP_REQUEST_BODY_CSTRING, PHPSTR_VAL(message), PHPSTR_LEN(message)}; - rs = http_post(uri, &body, Z_ARRVAL(options), NULL, NULL); - } else - if (!strcasecmp("GET", message->http.info.request.method)) { - rs = http_get(uri, Z_ARRVAL(options), NULL, NULL); - } else - if (!strcasecmp("HEAD", message->http.info.request.method)) { - rs = http_head(uri, Z_ARRVAL(options), NULL, NULL); - } else { - http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, - "Cannot send HttpMessage. Request method %s not supported", - message->http.info.request.method); - } - - efree(uri); -#else - http_error(HE_WARNING, HTTP_E_RUNTIME, "HTTP requests not supported - ext/http was not linked against libcurl."); -#endif - } - break; - - case HTTP_MSG_NONE: - default: - http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is neither of type HTTP_MSG_REQUEST nor HTTP_MSG_RESPONSE"); - break; - } - - return rs; -} - -PHP_HTTP_API http_message *_http_message_dup(http_message *msg TSRMLS_DC) -{ - /* - * TODO: unroll - */ - http_message *new; - char *serialized_data; - size_t serialized_length; - - http_message_serialize(msg, &serialized_data, &serialized_length); - new = http_message_parse(serialized_data, serialized_length); - efree(serialized_data); - return new; -} - -PHP_HTTP_API void _http_message_dtor(http_message *message) -{ - if (message) { - zend_hash_destroy(&message->hdrs); - phpstr_dtor(PHPSTR(message)); - - switch (message->type) - { - case HTTP_MSG_REQUEST: - STR_SET(message->http.info.request.method, NULL); - STR_SET(message->http.info.request.URI, NULL); - break; - - case HTTP_MSG_RESPONSE: - STR_SET(message->http.info.response.status, NULL); - break; - - default: - break; - } - } -} - -PHP_HTTP_API void _http_message_free(http_message **message) -{ - if (*message) { - if ((*message)->parent) { - http_message_free(&(*message)->parent); - } - http_message_dtor(*message); - efree(*message); - *message = NULL; - } -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_message_object.c b/http_message_object.c deleted file mode 100644 index 058f963..0000000 --- a/http_message_object.c +++ /dev/null @@ -1,929 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#ifdef ZEND_ENGINE_2 - -#include "php_http.h" -#include "php_http_api.h" -#include "php_http_std_defs.h" -#include "php_http_message_object.h" -#include "php_http_exception_object.h" - -#include "phpstr/phpstr.h" -#include "missing.h" - -ZEND_EXTERN_MODULE_GLOBALS(http); - -#define HTTP_BEGIN_ARGS(method, ret_ref, req_args) HTTP_BEGIN_ARGS_EX(HttpMessage, method, ret_ref, req_args) -#define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpMessage, method, ret_ref) -#define HTTP_MESSAGE_ME(method, visibility) PHP_ME(HttpMessage, method, HTTP_ARGS(HttpMessage, method), visibility) - -HTTP_BEGIN_ARGS(__construct, 0, 0) - HTTP_ARG_VAL(message, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(fromString, 1, 1) - HTTP_ARG_VAL(message, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getBody, 0); -HTTP_BEGIN_ARGS(setBody, 0, 1) - HTTP_ARG_VAL(body, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getHeaders, 0); -HTTP_BEGIN_ARGS(setHeaders, 0, 1) - HTTP_ARG_VAL(headers, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(addHeaders, 0, 1) - HTTP_ARG_VAL(headers, 0) - HTTP_ARG_VAL(append, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getType, 0); -HTTP_BEGIN_ARGS(setType, 0, 1) - HTTP_ARG_VAL(type, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getResponseCode, 0); -HTTP_BEGIN_ARGS(setResponseCode, 0, 1) - HTTP_ARG_VAL(response_code, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getRequestMethod, 0); -HTTP_BEGIN_ARGS(setRequestMethod, 0, 1) - HTTP_ARG_VAL(request_method, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getRequestUri, 0); -HTTP_BEGIN_ARGS(setRequestUri, 0, 1) - HTTP_ARG_VAL(uri, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getHttpVersion, 0); -HTTP_BEGIN_ARGS(setHttpVersion, 0, 1) - HTTP_ARG_VAL(http_version, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getParentMessage, 1); -HTTP_EMPTY_ARGS(send, 0); -HTTP_BEGIN_ARGS(toString, 0, 0) - HTTP_ARG_VAL(include_parent, 0) -HTTP_END_ARGS; - -#define http_message_object_declare_default_properties() _http_message_object_declare_default_properties(TSRMLS_C) -static inline void _http_message_object_declare_default_properties(TSRMLS_D); -#define http_message_object_read_prop _http_message_object_read_prop -static zval *_http_message_object_read_prop(zval *object, zval *member, int type TSRMLS_DC); -#define http_message_object_write_prop _http_message_object_write_prop -static void _http_message_object_write_prop(zval *object, zval *member, zval *value TSRMLS_DC); -#define http_message_object_get_props _http_message_object_get_props -static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC); -#define http_message_object_clone_obj _http_message_object_clone_obj -static inline zend_object_value _http_message_object_clone_obj(zval *object TSRMLS_DC); - -zend_class_entry *http_message_object_ce; -zend_function_entry http_message_object_fe[] = { - HTTP_MESSAGE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - HTTP_MESSAGE_ME(getBody, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(setBody, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(getHeaders, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(setHeaders, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(addHeaders, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(getType, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(setType, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(getResponseCode, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(setResponseCode, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(getRequestMethod, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(setRequestMethod, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(getRequestUri, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(setRequestUri, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(getHttpVersion, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(setHttpVersion, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(getParentMessage, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(send, ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(toString, ZEND_ACC_PUBLIC) - - ZEND_MALIAS(HttpMessage, __toString, toString, HTTP_ARGS(HttpMessage, toString), ZEND_ACC_PUBLIC) - - HTTP_MESSAGE_ME(fromString, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - - EMPTY_FUNCTION_ENTRY -}; -static zend_object_handlers http_message_object_handlers; - -void _http_message_object_init(INIT_FUNC_ARGS) -{ - HTTP_REGISTER_CLASS_EX(HttpMessage, http_message_object, NULL, 0); - - HTTP_LONG_CONSTANT("HTTP_MSG_NONE", HTTP_MSG_NONE); - HTTP_LONG_CONSTANT("HTTP_MSG_REQUEST", HTTP_MSG_REQUEST); - HTTP_LONG_CONSTANT("HTTP_MSG_RESPONSE", HTTP_MSG_RESPONSE); - - http_message_object_handlers.clone_obj = http_message_object_clone_obj; - http_message_object_handlers.read_property = http_message_object_read_prop; - http_message_object_handlers.write_property = http_message_object_write_prop; - http_message_object_handlers.get_properties = http_message_object_get_props; - http_message_object_handlers.get_property_ptr_ptr = NULL; -} - -zend_object_value _http_message_object_new(zend_class_entry *ce TSRMLS_DC) -{ - return http_message_object_new_ex(ce, NULL); -} - -zend_object_value _http_message_object_new_ex(zend_class_entry *ce, http_message *msg TSRMLS_DC) -{ - zend_object_value ov; - http_message_object *o; - - o = ecalloc(1, sizeof(http_message_object)); - o->zo.ce = ce; - - if (msg) { - o->message = msg; - if (msg->parent) { - o->parent = http_message_object_from_msg(msg->parent); - } - } - - ALLOC_HASHTABLE(OBJ_PROP(o)); - zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); - - ov.handle = putObject(http_message_object, o); - ov.handlers = &http_message_object_handlers; - - return ov; -} - -zend_object_value _http_message_object_clone(zval *this_ptr TSRMLS_DC) -{ - return http_message_object_clone_obj(this_ptr TSRMLS_CC); -} - -static inline void _http_message_object_declare_default_properties(TSRMLS_D) -{ - zend_class_entry *ce = http_message_object_ce; - -#ifndef WONKY - DCL_CONST(long, "TYPE_NONE", HTTP_MSG_NONE); - DCL_CONST(long, "TYPE_REQUEST", HTTP_MSG_REQUEST); - DCL_CONST(long, "TYPE_RESPONSE", HTTP_MSG_RESPONSE); -#endif - - DCL_PROP(PROTECTED, long, type, HTTP_MSG_NONE); - DCL_PROP(PROTECTED, string, body, ""); - DCL_PROP(PROTECTED, string, requestMethod, ""); - DCL_PROP(PROTECTED, string, requestUri, ""); - DCL_PROP(PROTECTED, long, responseCode, 0); - DCL_PROP_N(PROTECTED, httpVersion); - DCL_PROP_N(PROTECTED, headers); - DCL_PROP_N(PROTECTED, parentMessage); -} - -void _http_message_object_free(zend_object *object TSRMLS_DC) -{ - http_message_object *o = (http_message_object *) object; - - if (OBJ_PROP(o)) { - zend_hash_destroy(OBJ_PROP(o)); - FREE_HASHTABLE(OBJ_PROP(o)); - } - if (o->message) { - http_message_dtor(o->message); - efree(o->message); - } - efree(o); -} - -static inline zend_object_value _http_message_object_clone_obj(zval *this_ptr TSRMLS_DC) -{ - getObject(http_message_object, obj); - return http_message_object_from_msg(http_message_dup(obj->message)); -} - -static zval *_http_message_object_read_prop(zval *object, zval *member, int type TSRMLS_DC) -{ - getObjectEx(http_message_object, obj, object); - http_message *msg = obj->message; - zval *return_value; -#ifdef WONKY - zend_hash_value h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member)+1); -#else - zend_property_info *pinfo = zend_get_property_info(obj->zo.ce, member, 1 TSRMLS_CC); - - if (!pinfo || ACC_PROP_PUBLIC(pinfo->flags)) { - return zend_get_std_object_handlers()->read_property(object, member, type TSRMLS_CC); - } -#endif - - return_value = &EG(uninitialized_zval); - return_value->refcount = 0; - return_value->is_ref = 0; - -#ifdef WONKY - switch (h) -#else - switch (pinfo->h) -#endif - { - case HTTP_MSG_PROPHASH_TYPE: - RETVAL_LONG(msg->type); - break; - - case HTTP_MSG_PROPHASH_HTTP_VERSION: - RETVAL_DOUBLE(msg->http.version); - break; - - case HTTP_MSG_PROPHASH_BODY: - phpstr_fix(PHPSTR(msg)); - RETVAL_PHPSTR(PHPSTR(msg), 0, 1); - break; - - case HTTP_MSG_PROPHASH_HEADERS: - /* This is needed for situations like - * $this->headers['foo'] = 'bar'; - */ - if (type == BP_VAR_W) { - return_value->refcount = 1; - return_value->is_ref = 1; - Z_TYPE_P(return_value) = IS_ARRAY; - Z_ARRVAL_P(return_value) = &msg->hdrs; - } else { - array_init(return_value); - zend_hash_copy(Z_ARRVAL_P(return_value), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - } - break; - - case HTTP_MSG_PROPHASH_PARENT_MESSAGE: - if (msg->parent) { - RETVAL_OBJVAL(obj->parent); - } else { - RETVAL_NULL(); - } - break; - - case HTTP_MSG_PROPHASH_REQUEST_METHOD: - if (HTTP_MSG_TYPE(REQUEST, msg) && msg->http.info.request.method) { - RETVAL_STRING(msg->http.info.request.method, 1); - } else { - RETVAL_NULL(); - } - break; - - case HTTP_MSG_PROPHASH_REQUEST_URI: - if (HTTP_MSG_TYPE(REQUEST, msg) && msg->http.info.request.URI) { - RETVAL_STRING(msg->http.info.request.URI, 1); - } else { - RETVAL_NULL(); - } - break; - - case HTTP_MSG_PROPHASH_RESPONSE_CODE: - if (HTTP_MSG_TYPE(RESPONSE, msg)) { - RETVAL_LONG(msg->http.info.response.code); - } else { - RETVAL_NULL(); - } - break; - - case HTTP_MSG_PROPHASH_RESPONSE_STATUS: - if (HTTP_MSG_TYPE(RESPONSE, msg) && msg->http.info.response.status) { - RETVAL_STRING(msg->http.info.response.status, 1); - } else { - RETVAL_NULL(); - } - break; - - default: -#ifdef WONKY - return zend_get_std_object_handlers()->read_property(object, member, type TSRMLS_CC); -#else - RETVAL_NULL(); -#endif - break; - } - - return return_value; -} - -static void _http_message_object_write_prop(zval *object, zval *member, zval *value TSRMLS_DC) -{ - getObjectEx(http_message_object, obj, object); - http_message *msg = obj->message; -#ifdef WONKY - zend_hash_value h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1); -#else - zend_property_info *pinfo = zend_get_property_info(obj->zo.ce, member, 1 TSRMLS_CC); - - if (!pinfo || ACC_PROP_PUBLIC(pinfo->flags)) { - zend_get_std_object_handlers()->write_property(object, member, value TSRMLS_CC); - return; - } -#endif - -#ifdef WONKY - switch (h) -#else - switch (pinfo->h) -#endif - { - case HTTP_MSG_PROPHASH_TYPE: - convert_to_long_ex(&value); - http_message_set_type(msg, Z_LVAL_P(value)); - break; - - case HTTP_MSG_PROPHASH_HTTP_VERSION: - convert_to_double_ex(&value); - msg->http.version = Z_DVAL_P(value); - break; - - case HTTP_MSG_PROPHASH_BODY: - convert_to_string_ex(&value); - phpstr_dtor(PHPSTR(msg)); - phpstr_from_string_ex(PHPSTR(msg), Z_STRVAL_P(value), Z_STRLEN_P(value)); - break; - - case HTTP_MSG_PROPHASH_HEADERS: - convert_to_array_ex(&value); - zend_hash_clean(&msg->hdrs); - zend_hash_copy(&msg->hdrs, Z_ARRVAL_P(value), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - break; - - case HTTP_MSG_PROPHASH_PARENT_MESSAGE: - if (msg->parent) { - zval tmp; - tmp.value.obj = obj->parent; - zend_objects_store_del_ref(&tmp TSRMLS_CC); - } - zend_objects_store_add_ref(value TSRMLS_CC); - obj->parent = value->value.obj; - break; - - case HTTP_MSG_PROPHASH_REQUEST_METHOD: - if (HTTP_MSG_TYPE(REQUEST, msg)) { - convert_to_string_ex(&value); - STR_SET(msg->http.info.request.method, estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value))); - } - break; - - case HTTP_MSG_PROPHASH_REQUEST_URI: - if (HTTP_MSG_TYPE(REQUEST, msg)) { - convert_to_string_ex(&value); - STR_SET(msg->http.info.request.URI, estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value))); - } - break; - - case HTTP_MSG_PROPHASH_RESPONSE_CODE: - if (HTTP_MSG_TYPE(RESPONSE, msg)) { - convert_to_long_ex(&value); - msg->http.info.response.code = Z_LVAL_P(value); - } - break; - - case HTTP_MSG_PROPHASH_RESPONSE_STATUS: - if (HTTP_MSG_TYPE(RESPONSE, msg)) { - convert_to_string_ex(&value); - STR_SET(msg->http.info.response.status, estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value))); - } - break; - - default: -#ifdef WONKY - zend_get_std_object_handlers()->write_property(object, member, value TSRMLS_CC); -#endif - break; - } -} - -static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC) -{ - zval *headers; - getObjectEx(http_message_object, obj, object); - http_message *msg = obj->message; - HashTable *props = OBJ_PROP(obj); - zval array; - - INIT_ZARR(array, props); - -#define ASSOC_PROP(array, ptype, name, val) \ - { \ - char *m_prop_name; \ - int m_prop_len; \ - zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 0); \ - add_assoc_ ##ptype## _ex(&array, m_prop_name, sizeof(name)+4, val); \ - efree(m_prop_name); \ - } -#define ASSOC_STRING(array, name, val) ASSOC_STRINGL(array, name, val, strlen(val)) -#define ASSOC_STRINGL(array, name, val, len) \ - { \ - char *m_prop_name; \ - int m_prop_len; \ - zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 0); \ - add_assoc_stringl_ex(&array, m_prop_name, sizeof(name)+4, val, len, 1); \ - efree(m_prop_name); \ - } - - ASSOC_PROP(array, long, "type", msg->type); - ASSOC_PROP(array, double, "httpVersion", msg->http.version); - - switch (msg->type) - { - case HTTP_MSG_REQUEST: - ASSOC_PROP(array, long, "responseCode", 0); - ASSOC_STRINGL(array, "responseStatus", "", 0); - ASSOC_STRING(array, "requestMethod", msg->http.info.request.method); - ASSOC_STRING(array, "requestUri", msg->http.info.request.URI); - break; - - case HTTP_MSG_RESPONSE: - ASSOC_PROP(array, long, "responseCode", msg->http.info.response.code); - ASSOC_STRING(array, "responseStatus", msg->http.info.response.status); - ASSOC_STRINGL(array, "requestMethod", "", 0); - ASSOC_STRINGL(array, "requestUri", "", 0); - break; - - case HTTP_MSG_NONE: - default: - ASSOC_PROP(array, long, "responseCode", 0); - ASSOC_STRINGL(array, "responseStatus", "", 0); - ASSOC_STRINGL(array, "requestMethod", "", 0); - ASSOC_STRINGL(array, "requestUri", "", 0); - break; - } - - MAKE_STD_ZVAL(headers); - array_init(headers); - zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - ASSOC_PROP(array, zval, "headers", headers); - ASSOC_STRINGL(array, "body", PHPSTR_VAL(msg), PHPSTR_LEN(msg)); - - return OBJ_PROP(obj); -} - -/* ### USERLAND ### */ - -/* {{{ proto void HttpMessage::__construct([string message]) - * - * Instantiate a new HttpMessage object. - */ -PHP_METHOD(HttpMessage, __construct) -{ - char *message = NULL; - int length = 0; - getObject(http_message_object, obj); - - SET_EH_THROW_HTTP(); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &message, &length) && message && length) { - if (obj->message = http_message_parse(message, length)) { - if (obj->message->parent) { - obj->parent = http_message_object_from_msg(obj->message->parent); - } - } - } else if (!obj->message) { - obj->message = http_message_new(); - } - SET_EH_NORMAL(); -} -/* }}} */ - -/* {{{ proto static HttpMessage HttpMessage::fromString(string raw_message) - * - * Create an HttpMessage object from a string. - */ -PHP_METHOD(HttpMessage, fromString) -{ - char *string = NULL; - int length = 0; - http_message *msg = NULL; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &string, &length)) { - RETURN_NULL(); - } - - if (!(msg = http_message_parse(string, length))) { - RETURN_NULL(); - } - - Z_TYPE_P(return_value) = IS_OBJECT; - return_value->value.obj = http_message_object_from_msg(msg); -} -/* }}} */ - -/* {{{ proto string HttpMessage::getBody() - * - * Get the body of the parsed Message. - */ -PHP_METHOD(HttpMessage, getBody) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_message_object, obj); - RETURN_PHPSTR(&obj->message->body, PHPSTR_FREE_NOT, 1); - } -} -/* }}} */ - -/* {{{ proto void HttpMessage::setBody(string body) - * - * Set the body of the HttpMessage. - * NOTE: Don't forget to update any headers accordingly. - */ -PHP_METHOD(HttpMessage, setBody) -{ - char *body; - int len; - getObject(http_message_object, obj); - - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &body, &len)) { - phpstr_dtor(PHPSTR(obj->message)); - phpstr_from_string_ex(PHPSTR(obj->message), body, len); - } -} -/* }}} */ - -/* {{{ proto array HttpMessage::getHeaders() - * - * Get Message Headers. - */ -PHP_METHOD(HttpMessage, getHeaders) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval headers; - getObject(http_message_object, obj); - - INIT_ZARR(headers, &obj->message->hdrs); - array_init(return_value); - array_copy(&headers, return_value); - } -} -/* }}} */ - -/* {{{ proto void HttpMessage::setHeaders(array headers) - * - * Sets new headers. - */ -PHP_METHOD(HttpMessage, setHeaders) -{ - zval *new_headers, old_headers; - getObject(http_message_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &new_headers)) { - return; - } - - zend_hash_clean(&obj->message->hdrs); - INIT_ZARR(old_headers, &obj->message->hdrs); - array_copy(new_headers, &old_headers); -} -/* }}} */ - -/* {{{ proto void HttpMessage::addHeaders(array headers[, bool append = false]) - * - * Add headers. If append is true, headers with the same name will be separated, else overwritten. - */ -PHP_METHOD(HttpMessage, addHeaders) -{ - zval old_headers, *new_headers; - zend_bool append = 0; - getObject(http_message_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &new_headers, &append)) { - return; - } - - INIT_ZARR(old_headers, &obj->message->hdrs); - if (append) { - array_append(new_headers, &old_headers); - } else { - array_merge(new_headers, &old_headers); - } -} -/* }}} */ - -/* {{{ proto long HttpMessage::getType() - * - * Get Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) - */ -PHP_METHOD(HttpMessage, getType) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_message_object, obj); - RETURN_LONG(obj->message->type); - } -} -/* }}} */ - -/* {{{ proto void HttpMessage::setType(long type) - * - * Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) - */ -PHP_METHOD(HttpMessage, setType) -{ - long type; - getObject(http_message_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type)) { - return; - } - http_message_set_type(obj->message, type); -} -/* }}} */ - -/* {{{ proto long HttpMessage::getResponseCode() - * - * Get the Response Code of the Message. - */ -PHP_METHOD(HttpMessage, getResponseCode) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_message_object, obj); - - if (!HTTP_MSG_TYPE(RESPONSE, obj->message)) { - http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_RESPONSE"); - RETURN_NULL(); - } - - RETURN_LONG(obj->message->http.info.response.code); - } -} -/* }}} */ - -/* {{{ proto bool HttpMessage::setResponseCode(long code) - * - * Set the response code of an HTTP Response Message. - * Returns false if the Message is not of type HTTP_MSG_RESPONSE, - * or if the response code is out of range (100-510). - */ -PHP_METHOD(HttpMessage, setResponseCode) -{ - long code; - getObject(http_message_object, obj); - - if (!HTTP_MSG_TYPE(RESPONSE, obj->message)) { - http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_RESPONSE"); - RETURN_FALSE; - } - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) { - RETURN_FALSE; - } - if (code < 100 || code > 510) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid response code (100-510): %ld", code); - RETURN_FALSE; - } - - obj->message->http.info.response.code = code; - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string HttpMessage::getRequestMethod() - * - * Get the Request Method of the Message. - * Returns false if the Message is not of type HTTP_MSG_REQUEST. - */ -PHP_METHOD(HttpMessage, getRequestMethod) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_message_object, obj); - - if (!HTTP_MSG_TYPE(REQUEST, obj->message)) { - http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); - RETURN_NULL(); - } - - RETURN_STRING(obj->message->http.info.request.method, 1); - } -} -/* }}} */ - -/* {{{ proto bool HttpMessage::setRequestMethod(string method) - * - * Set the Request Method of the HTTP Message. - * Returns false if the Message is not of type HTTP_MSG_REQUEST. - */ -PHP_METHOD(HttpMessage, setRequestMethod) -{ - char *method; - int method_len; - getObject(http_message_object, obj); - - if (!HTTP_MSG_TYPE(REQUEST, obj->message)) { - http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); - RETURN_FALSE; - } - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) { - RETURN_FALSE; - } - if (method_len < 1) { - http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestMethod to an empty string"); - RETURN_FALSE; - } - if (SUCCESS != http_check_method(method)) { - http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unkown request method: %s", method); - RETURN_FALSE; - } - - STR_SET(obj->message->http.info.request.method, estrndup(method, method_len)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string HttpMessage::getRequestUri() - * - * Get the Request URI of the Message. - */ -PHP_METHOD(HttpMessage, getRequestUri) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_message_object, obj); - - if (!HTTP_MSG_TYPE(REQUEST, obj->message)) { - http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); - RETURN_NULL(); - } - - RETURN_STRING(obj->message->http.info.request.URI, 1); - } -} -/* }}} */ - -/* {{{ proto bool HttpMessage::setRequestUri(string URI) - * - * Set the Request URI of the HTTP Message. - * Returns false if the Message is not of type HTTP_MSG_REQUEST, - * or if paramtere URI was empty. - */ -PHP_METHOD(HttpMessage, setRequestUri) -{ - char *URI; - int URIlen; - getObject(http_message_object, obj); - - if (!HTTP_MSG_TYPE(REQUEST, obj->message)) { - http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); - RETURN_FALSE; - } - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URI, &URIlen)) { - RETURN_FALSE; - } - if (URIlen < 1) { - http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestUri to an empty string"); - RETURN_FALSE; - } - - STR_SET(obj->message->http.info.request.URI, estrndup(URI, URIlen)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string HttpMessage::getHttpVersion() - * - * Get the HTTP Protocol Version of the Message. - */ -PHP_METHOD(HttpMessage, getHttpVersion) -{ - NO_ARGS; - - IF_RETVAL_USED { - char ver[4] = {0}; - getObject(http_message_object, obj); - - sprintf(ver, "%1.1lf", obj->message->http.version); - RETURN_STRINGL(ver, 3, 1); - } -} -/* }}} */ - -/* {{{ proto bool HttpMessage::setHttpVersion(string version) - * - * Set the HTTP Protocol version of the Message. - * Returns false if version is invalid (1.0 and 1.1). - */ -PHP_METHOD(HttpMessage, setHttpVersion) -{ - char v[4]; - zval *zv; - getObject(http_message_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &zv)) { - return; - } - - convert_to_double(zv); - sprintf(v, "%1.1lf", Z_DVAL_P(zv)); - if (strcmp(v, "1.0") && strcmp(v, "1.1")) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid HTTP protocol version (1.0 or 1.1): %s", v); - RETURN_FALSE; - } - - obj->message->http.version = Z_DVAL_P(zv); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto HttpMessage HttpMessage::getParentMessage() - * - * Get parent Message. - */ -PHP_METHOD(HttpMessage, getParentMessage) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_message_object, obj); - - if (obj->message->parent) { - RETVAL_OBJVAL(obj->parent); - } else { - RETVAL_NULL(); - } - } -} -/* }}} */ - -/* {{{ proto bool HttpMessage::send() - * - * Send the Message according to its type as Response or Request. - */ -PHP_METHOD(HttpMessage, send) -{ - getObject(http_message_object, obj); - - NO_ARGS; - - RETURN_SUCCESS(http_message_send(obj->message)); -} -/* }}} */ - -/* {{{ proto string HttpMessage::toString([bool include_parent = false]) - * - * Get the string representation of the Message. - */ -PHP_METHOD(HttpMessage, toString) -{ - IF_RETVAL_USED { - char *string; - size_t length; - zend_bool include_parent = 0; - getObject(http_message_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &include_parent)) { - RETURN_FALSE; - } - - if (include_parent) { - http_message_serialize(obj->message, &string, &length); - } else { - http_message_tostring(obj->message, &string, &length); - } - RETURN_STRINGL(string, length, 0); - } -} -/* }}} */ - -#endif /* ZEND_ENGINE_2 */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_methods.c b/http_methods.c deleted file mode 100644 index 2ebf3e6..0000000 --- a/http_methods.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* - * Contents have been split up into http_*_object.c - */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_request_api.c b/http_request_api.c deleted file mode 100644 index d9b1a21..0000000 --- a/http_request_api.c +++ /dev/null @@ -1,986 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#ifdef HTTP_HAVE_CURL - -#if defined(ZTS) && defined(HTTP_HAVE_SSL) -# if !defined(HAVE_OPENSSL_CRYPTO_H) -# error "libcurl was compiled with OpenSSL support, but we have no openssl/crypto.h" -# else -# define HTTP_NEED_SSL -# include -# endif -#endif - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_request_api.h" -#include "php_http_request_method_api.h" -#include "php_http_url_api.h" -#ifdef ZEND_ENGINE_2 -# include "php_http_request_object.h" -#endif - -#include "phpstr/phpstr.h" - -#ifdef PHP_WIN32 -# include -#endif - -#include - -ZEND_EXTERN_MODULE_GLOBALS(http); - -#ifdef HTTP_NEED_SSL -static inline zend_bool http_ssl_init(void); -static inline void http_ssl_cleanup(void); -#endif - -STATUS _http_request_global_init(INIT_FUNC_ARGS) -{ - if (CURLE_OK != curl_global_init(CURL_GLOBAL_ALL)) { - return FAILURE; - } - -#ifdef HTTP_NEED_SSL - http_ssl_init(); -#endif - -#if LIBCURL_VERSION_NUM >= 0x070a05 - HTTP_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC); - HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST); - HTTP_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM); - HTTP_LONG_CONSTANT("HTTP_AUTH_ANY", CURLAUTH_ANY); -#endif /* LIBCURL_VERSION_NUM */ - - return SUCCESS; -} - -void _http_request_global_cleanup(TSRMLS_D) -{ - curl_global_cleanup(); -#ifdef HTTP_NEED_SSL - http_ssl_cleanup(); -#endif -} - -#ifndef HAVE_CURL_EASY_STRERROR -# define curl_easy_strerror(code) HTTP_G(request).error -#endif - -#define HTTP_CURL_INFO(I) HTTP_CURL_INFO_EX(I, I) -#define HTTP_CURL_INFO_EX(I, X) \ - switch (CURLINFO_ ##I & ~CURLINFO_MASK) \ - { \ - case CURLINFO_STRING: \ - { \ - char *c; \ - if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &c)) { \ - add_assoc_string(&array, pretty_key(http_request_data_copy(COPY_STRING, #X), sizeof(#X)-1, 0, 0), c ? c : "", 1); \ - } \ - } \ - break; \ -\ - case CURLINFO_DOUBLE: \ - { \ - double d; \ - if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &d)) { \ - add_assoc_double(&array, pretty_key(http_request_data_copy(COPY_STRING, #X), sizeof(#X)-1, 0, 0), d); \ - } \ - } \ - break; \ -\ - case CURLINFO_LONG: \ - { \ - long l; \ - if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_ ##I, &l)) { \ - add_assoc_long(&array, pretty_key(http_request_data_copy(COPY_STRING, #X), sizeof(#X)-1, 0, 0), l); \ - } \ - } \ - break; \ - } - -#define HTTP_CURL_OPT(OPTION, p) curl_easy_setopt(ch, CURLOPT_##OPTION, (p)) -#define HTTP_CURL_OPT_STRING(keyname) HTTP_CURL_OPT_STRING_EX(keyname, keyname) -#define HTTP_CURL_OPT_SSL_STRING(keyname) HTTP_CURL_OPT_STRING_EX(keyname, SSL##keyname) -#define HTTP_CURL_OPT_SSL_STRING_(keyname) HTTP_CURL_OPT_STRING_EX(keyname, SSL_##keyname) -#define HTTP_CURL_OPT_STRING_EX(keyname, optname) \ - if (!strcasecmp(key, #keyname)) { \ - convert_to_string_ex(param); \ - HTTP_CURL_OPT(optname, http_request_data_copy(COPY_STRING, Z_STRVAL_PP(param))); \ - key = NULL; \ - continue; \ - } -#define HTTP_CURL_OPT_LONG(keyname) HTTP_OPT_SSL_LONG_EX(keyname, keyname) -#define HTTP_CURL_OPT_SSL_LONG(keyname) HTTP_CURL_OPT_LONG_EX(keyname, SSL##keyname) -#define HTTP_CURL_OPT_SSL_LONG_(keyname) HTTP_CURL_OPT_LONG_EX(keyname, SSL_##keyname) -#define HTTP_CURL_OPT_LONG_EX(keyname, optname) \ - if (!strcasecmp(key, #keyname)) { \ - convert_to_long_ex(param); \ - HTTP_CURL_OPT(optname, Z_LVAL_PP(param)); \ - key = NULL; \ - continue; \ - } - -#define http_curl_getopt(o, k, t) _http_curl_getopt_ex((o), (k), sizeof(k), (t) TSRMLS_CC) -#define http_curl_getopt_ex(o, k, l, t) _http_curl_getopt_ex((o), (k), (l), (t) TSRMLS_CC) -static inline zval *_http_curl_getopt_ex(HashTable *options, char *key, size_t keylen, int type TSRMLS_DC); -#define http_curl_defaults(ch) _http_curl_defaults((ch)) -static inline void _http_curl_defaults(CURL *ch); -static size_t http_curl_read_callback(void *, size_t, size_t, void *); -static int http_curl_progress_callback(void *, double, double, double, double); -static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *); -static int http_curl_dummy_callback(char *data, size_t n, size_t l, void *s) { return n*l; } - -/* {{{ http_request_callback_ctx http_request_callback_data(void *) */ -http_request_callback_ctx *_http_request_callback_data_ex(void *data, zend_bool cpy TSRMLS_DC) -{ - http_request_callback_ctx *ctx = emalloc(sizeof(http_request_callback_ctx)); - - TSRMLS_SET_CTX(ctx->tsrm_ctx); - ctx->data = data; - - if (cpy) { - return http_request_data_copy(COPY_CONTEXT, ctx); - } else { - return ctx; - } -} -/* }}} */ - -/* {{{ void *http_request_data_copy(int, void *) */ -void *_http_request_data_copy(int type, void *data TSRMLS_DC) -{ - switch (type) - { - case COPY_STRING: - { - char *new_str = estrdup(data); - zend_llist_add_element(&HTTP_G(request).copies.strings, &new_str); - return new_str; - } - - case COPY_SLIST: - { - zend_llist_add_element(&HTTP_G(request).copies.slists, &data); - return data; - } - - case COPY_CONTEXT: - { - zend_llist_add_element(&HTTP_G(request).copies.contexts, &data); - return data; - } - - case COPY_CONV: - { - zend_llist_add_element(&HTTP_G(request).copies.convs, &data); - return data; - } - - default: - { - return data; - } - } -} -/* }}} */ - -/* {{{ void http_request_data_free_string(char **) */ -void _http_request_data_free_string(void *string) -{ - efree(*((char **)string)); -} -/* }}} */ - -/* {{{ void http_request_data_free_slist(struct curl_slist **) */ -void _http_request_data_free_slist(void *list) -{ - curl_slist_free_all(*((struct curl_slist **) list)); -} -/* }}} */ - -/* {{{ _http_request_data_free_context(http_request_callback_ctx **) */ -void _http_request_data_free_context(void *context) -{ - efree(*((http_request_callback_ctx **) context)); -} -/* }}} */ - -/* {{{ _http_request_data_free_conv(http_request_conv **) */ -void _http_request_data_free_conv(void *conv) -{ - efree(*((http_request_conv **) conv)); -} -/* }}} */ - -/* {{{ http_request_body *http_request_body_new() */ -PHP_HTTP_API http_request_body *_http_request_body_new(TSRMLS_D) -{ - http_request_body *body = ecalloc(1, sizeof(http_request_body)); - return body; -} -/* }}} */ - -/* {{{ STATUS http_request_body_fill(http_request_body *body, HashTable *, HashTable *) */ -PHP_HTTP_API STATUS _http_request_body_fill(http_request_body *body, HashTable *fields, HashTable *files TSRMLS_DC) -{ - if (files && (zend_hash_num_elements(files) > 0)) { - char *key = NULL; - ulong idx; - zval **data; - struct curl_httppost *http_post_data[2] = {NULL, NULL}; - - /* normal data */ - FOREACH_HASH_KEYVAL(fields, key, idx, data) { - CURLcode err; - if (key) { - convert_to_string_ex(data); - err = curl_formadd(&http_post_data[0], &http_post_data[1], - CURLFORM_COPYNAME, key, - CURLFORM_COPYCONTENTS, Z_STRVAL_PP(data), - CURLFORM_CONTENTSLENGTH, (long) Z_STRLEN_PP(data), - CURLFORM_END - ); - if (CURLE_OK != err) { - http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err)); - curl_formfree(http_post_data[0]); - return FAILURE; - } - - /* reset */ - key = NULL; - } - } - - /* file data */ - FOREACH_HASH_VAL(files, data) { - zval **file, **type, **name; - - if ( SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "name", sizeof("name"), (void **) &name) || - SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "type", sizeof("type"), (void **) &type) || - SUCCESS != zend_hash_find(Z_ARRVAL_PP(data), "file", sizeof("file"), (void **) &file)) { - http_error(HE_NOTICE, HTTP_E_INVALID_PARAM, "Post file array entry misses either 'name', 'type' or 'file' entry"); - } else { - CURLcode err = curl_formadd(&http_post_data[0], &http_post_data[1], - CURLFORM_COPYNAME, Z_STRVAL_PP(name), - CURLFORM_FILE, Z_STRVAL_PP(file), - CURLFORM_CONTENTTYPE, Z_STRVAL_PP(type), - CURLFORM_END - ); - if (CURLE_OK != err) { - http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post files: %s", curl_easy_strerror(err)); - curl_formfree(http_post_data[0]); - return FAILURE; - } - } - } - - body->type = HTTP_REQUEST_BODY_CURLPOST; - body->data = http_post_data[0]; - body->size = 0; - - } else { - char *encoded; - size_t encoded_len; - - if (SUCCESS != http_urlencode_hash_ex(fields, 1, NULL, 0, &encoded, &encoded_len)) { - http_error(HE_WARNING, HTTP_E_ENCODING, "Could not encode post data"); - return FAILURE; - } - - body->type = HTTP_REQUEST_BODY_CSTRING; - body->data = encoded; - body->size = encoded_len; - } - - return SUCCESS; -} -/* }}} */ - -/* {{{ void http_request_body_dtor(http_request_body *) */ -PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC) -{ - if (body) { - switch (body->type) - { - case HTTP_REQUEST_BODY_CSTRING: - if (body->data) { - efree(body->data); - } - break; - - case HTTP_REQUEST_BODY_CURLPOST: - curl_formfree(body->data); - break; - - case HTTP_REQUEST_BODY_UPLOADFILE: - php_stream_close(body->data); - break; - } - } -} -/* }}} */ - -/* {{{ void http_request_body_free(http_request_body *) */ -PHP_HTTP_API void _http_request_body_free(http_request_body *body TSRMLS_DC) -{ - if (body) { - http_request_body_dtor(body); - efree(body); - } -} -/* }}} */ - -/* {{{ STATUS http_request_init(CURL *, http_request_method, char *, http_request_body *, HashTable *) */ -PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, char *url, http_request_body *body, HashTable *options TSRMLS_DC) -{ - zval *zoption; - zend_bool range_req = 0; - - /* reset CURL handle */ -#ifdef HAVE_CURL_EASY_RESET - curl_easy_reset(ch); -#endif - http_curl_defaults(ch); - - /* set options */ - if (url) { - HTTP_CURL_OPT(URL, http_request_data_copy(COPY_STRING, url)); - } - - HTTP_CURL_OPT(HEADER, 0); - HTTP_CURL_OPT(FILETIME, 1); - HTTP_CURL_OPT(AUTOREFERER, 1); - HTTP_CURL_OPT(READFUNCTION, http_curl_read_callback); - /* we'll get all data through the debug function */ - HTTP_CURL_OPT(WRITEFUNCTION, http_curl_dummy_callback); - HTTP_CURL_OPT(HEADERFUNCTION, NULL); - - HTTP_CURL_OPT(VERBOSE, 1); - HTTP_CURL_OPT(DEBUGFUNCTION, http_curl_raw_callback); - -#if defined(ZTS) && (LIBCURL_VERSION_NUM >= 0x070a00) - HTTP_CURL_OPT(NOSIGNAL, 1); -#endif -#if LIBCURL_VERSION_NUM < 0x070c00 - HTTP_CURL_OPT(ERRORBUFFER, HTTP_G(request).error); -#endif - - /* progress callback */ - if (zoption = http_curl_getopt(options, "onprogress", 0)) { - HTTP_CURL_OPT(NOPROGRESS, 0); - HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback); - HTTP_CURL_OPT(PROGRESSDATA, http_request_callback_data(zoption)); - } - - /* proxy */ - if (zoption = http_curl_getopt(options, "proxyhost", IS_STRING)) { - HTTP_CURL_OPT(PROXY, http_request_data_copy(COPY_STRING, Z_STRVAL_P(zoption))); - /* port */ - if (zoption = http_curl_getopt(options, "proxyport", IS_LONG)) { - HTTP_CURL_OPT(PROXYPORT, Z_LVAL_P(zoption)); - } - /* user:pass */ - if (zoption = http_curl_getopt(options, "proxyauth", IS_STRING)) { - HTTP_CURL_OPT(PROXYUSERPWD, http_request_data_copy(COPY_STRING, Z_STRVAL_P(zoption))); - } -#if LIBCURL_VERSION_NUM >= 0x070a07 - /* auth method */ - if (zoption = http_curl_getopt(options, "proxyauthtype", IS_LONG)) { - HTTP_CURL_OPT(PROXYAUTH, Z_LVAL_P(zoption)); - } -#endif - } - - /* outgoing interface */ - if (zoption = http_curl_getopt(options, "interface", IS_STRING)) { - HTTP_CURL_OPT(INTERFACE, http_request_data_copy(COPY_STRING, Z_STRVAL_P(zoption))); - } - - /* another port */ - if (zoption = http_curl_getopt(options, "port", IS_LONG)) { - HTTP_CURL_OPT(PORT, Z_LVAL_P(zoption)); - } - - /* auth */ - if (zoption = http_curl_getopt(options, "httpauth", IS_STRING)) { - HTTP_CURL_OPT(USERPWD, http_request_data_copy(COPY_STRING, Z_STRVAL_P(zoption))); - } -#if LIBCURL_VERSION_NUM >= 0x070a06 - if (zoption = http_curl_getopt(options, "httpauthtype", IS_LONG)) { - HTTP_CURL_OPT(HTTPAUTH, Z_LVAL_P(zoption)); - } -#endif - - /* compress, empty string enables deflate and gzip */ - if ((zoption = http_curl_getopt(options, "compress", IS_BOOL)) && Z_LVAL_P(zoption)) { - HTTP_CURL_OPT(ENCODING, ""); - } - - /* redirects, defaults to 0 */ - if (zoption = http_curl_getopt(options, "redirect", IS_LONG)) { - HTTP_CURL_OPT(FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1 : 0); - HTTP_CURL_OPT(MAXREDIRS, Z_LVAL_P(zoption)); - if (zoption = http_curl_getopt(options, "unrestrictedauth", IS_BOOL)) { - HTTP_CURL_OPT(UNRESTRICTED_AUTH, Z_LVAL_P(zoption)); - } - } - - /* referer */ - if (zoption = http_curl_getopt(options, "referer", IS_STRING)) { - HTTP_CURL_OPT(REFERER, http_request_data_copy(COPY_STRING, Z_STRVAL_P(zoption))); - } - - /* useragent, default "PECL::HTTP/version (PHP/version)" */ - if (zoption = http_curl_getopt(options, "useragent", IS_STRING)) { - HTTP_CURL_OPT(USERAGENT, http_request_data_copy(COPY_STRING, Z_STRVAL_P(zoption))); - } - - /* additional headers, array('name' => 'value') */ - if (zoption = http_curl_getopt(options, "headers", IS_ARRAY)) { - char *header_key; - ulong header_idx; - struct curl_slist *headers = NULL; - - FOREACH_KEY(zoption, header_key, header_idx) { - if (header_key) { - zval **header_val; - if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &header_val)) { - char header[1024] = {0}; - snprintf(header, 1023, "%s: %s", header_key, Z_STRVAL_PP(header_val)); - headers = curl_slist_append(headers, http_request_data_copy(COPY_STRING, header)); - } - - /* reset */ - header_key = NULL; - } - } - - if (headers) { - HTTP_CURL_OPT(HTTPHEADER, http_request_data_copy(COPY_SLIST, headers)); - } - } - - /* cookies, array('name' => 'value') */ - if (zoption = http_curl_getopt(options, "cookies", IS_ARRAY)) { - char *cookie_key = NULL; - ulong cookie_idx = 0; - phpstr *qstr = phpstr_new(); - - FOREACH_KEY(zoption, cookie_key, cookie_idx) { - if (cookie_key) { - zval **cookie_val; - if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void **) &cookie_val)) { - phpstr_appendf(qstr, "%s=%s; ", cookie_key, Z_STRVAL_PP(cookie_val)); - } - - /* reset */ - cookie_key = NULL; - } - } - - if (qstr->used) { - phpstr_fix(qstr); - HTTP_CURL_OPT(COOKIE, http_request_data_copy(COPY_STRING, qstr->data)); - } - phpstr_free(&qstr); - } - - /* session cookies */ - if (zoption = http_curl_getopt(options, "cookiesession", IS_BOOL)) { - if (Z_LVAL_P(zoption)) { - /* accept cookies for this session */ - HTTP_CURL_OPT(COOKIEFILE, ""); - } else { - /* reset session cookies */ - HTTP_CURL_OPT(COOKIESESSION, 1); - } - } - - /* cookiestore, read initial cookies from that file and store cookies back into that file */ - if ((zoption = http_curl_getopt(options, "cookiestore", IS_STRING)) && Z_STRLEN_P(zoption)) { - HTTP_CURL_OPT(COOKIEFILE, http_request_data_copy(COPY_STRING, Z_STRVAL_P(zoption))); - HTTP_CURL_OPT(COOKIEJAR, http_request_data_copy(COPY_STRING, Z_STRVAL_P(zoption))); - } - - /* resume */ - if ((zoption = http_curl_getopt(options, "resume", IS_LONG)) && (Z_LVAL_P(zoption) != 0)) { - range_req = 1; - HTTP_CURL_OPT(RESUME_FROM, Z_LVAL_P(zoption)); - } - - /* maxfilesize */ - if (zoption = http_curl_getopt(options, "maxfilesize", IS_LONG)) { - HTTP_CURL_OPT(MAXFILESIZE, Z_LVAL_P(zoption)); - } - - /* lastmodified */ - if (zoption = http_curl_getopt(options, "lastmodified", IS_LONG)) { - HTTP_CURL_OPT(TIMECONDITION, range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE); - HTTP_CURL_OPT(TIMEVALUE, Z_LVAL_P(zoption)); - } - - /* timeout, defaults to 0 */ - if (zoption = http_curl_getopt(options, "timeout", IS_LONG)) { - HTTP_CURL_OPT(TIMEOUT, Z_LVAL_P(zoption)); - } - - /* connecttimeout, defaults to 3 */ - if (zoption = http_curl_getopt(options, "connecttimeout", IS_LONG)) { - HTTP_CURL_OPT(CONNECTTIMEOUT, Z_LVAL_P(zoption)); - } - - /* ssl */ - if (zoption = http_curl_getopt(options, "ssl", IS_ARRAY)) { - ulong idx; - char *key = NULL; - zval **param; - - FOREACH_KEYVAL(zoption, key, idx, param) { - if (key) { - HTTP_CURL_OPT_SSL_STRING(CERT); -#if LIBCURL_VERSION_NUM >= 0x070903 - HTTP_CURL_OPT_SSL_STRING(CERTTYPE); -#endif - HTTP_CURL_OPT_SSL_STRING(CERTPASSWD); - - HTTP_CURL_OPT_SSL_STRING(KEY); - HTTP_CURL_OPT_SSL_STRING(KEYTYPE); - HTTP_CURL_OPT_SSL_STRING(KEYPASSWD); - - HTTP_CURL_OPT_SSL_STRING(ENGINE); - HTTP_CURL_OPT_SSL_LONG(VERSION); - - HTTP_CURL_OPT_SSL_LONG_(VERIFYPEER); - HTTP_CURL_OPT_SSL_LONG_(VERIFYHOST); - HTTP_CURL_OPT_SSL_STRING_(CIPHER_LIST); - - - HTTP_CURL_OPT_STRING(CAINFO); -#if LIBCURL_VERSION_NUM >= 0x070908 - HTTP_CURL_OPT_STRING(CAPATH); -#endif - HTTP_CURL_OPT_STRING(RANDOM_FILE); - HTTP_CURL_OPT_STRING(EGDSOCKET); - - /* reset key */ - key = NULL; - } - } - } - - /* request method */ - switch (meth) - { - case HTTP_GET: - curl_easy_setopt(ch, CURLOPT_HTTPGET, 1); - break; - - case HTTP_HEAD: - curl_easy_setopt(ch, CURLOPT_NOBODY, 1); - break; - - case HTTP_POST: - curl_easy_setopt(ch, CURLOPT_POST, 1); - break; - - case HTTP_PUT: - curl_easy_setopt(ch, CURLOPT_UPLOAD, 1); - break; - - default: - if (http_request_method_exists(0, meth, NULL)) { - curl_easy_setopt(ch, CURLOPT_CUSTOMREQUEST, http_request_method_name(meth)); - } else { - http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unsupported request method: %d", meth); - return FAILURE; - } - break; - } - - /* attach request body */ - if (body && (meth != HTTP_GET) && (meth != HTTP_HEAD)) { - switch (body->type) - { - case HTTP_REQUEST_BODY_CSTRING: - curl_easy_setopt(ch, CURLOPT_POSTFIELDS, body->data); - curl_easy_setopt(ch, CURLOPT_POSTFIELDSIZE, body->size); - break; - - case HTTP_REQUEST_BODY_CURLPOST: - curl_easy_setopt(ch, CURLOPT_HTTPPOST, (struct curl_httppost *) body->data); - break; - - case HTTP_REQUEST_BODY_UPLOADFILE: - curl_easy_setopt(ch, CURLOPT_READDATA, http_request_callback_data(body)); - curl_easy_setopt(ch, CURLOPT_INFILESIZE, body->size); - break; - - default: - /* shouldn't ever happen */ - http_error_ex(HE_ERROR, 0, "Unknown request body type: %d", body->type); - return FAILURE; - break; - } - } - - return SUCCESS; -} -/* }}} */ - -/* {{{ void http_request_conv(CURL *, phpstr *, phpstr *) */ -void _http_request_conv(CURL *ch, phpstr* response, phpstr *request TSRMLS_DC) -{ - http_request_conv *conv = emalloc(sizeof(http_request_conv)); - conv->response = response; - conv->request = request; - conv->last_info = -1; - HTTP_CURL_OPT(DEBUGDATA, http_request_callback_data(http_request_data_copy(COPY_CONV, conv))); -} -/* }}} */ - -/* {{{ STATUS http_request_exec(CURL *, HashTable *) */ -PHP_HTTP_API STATUS _http_request_exec(CURL *ch, HashTable *info, phpstr *response, phpstr *request TSRMLS_DC) -{ - CURLcode result; - - http_request_conv(ch, response, request); - - /* perform request */ - if (CURLE_OK != (result = curl_easy_perform(ch))) { - http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not perform request: %s", curl_easy_strerror(result)); - return FAILURE; - } else { - /* get curl info */ - if (info) { - http_request_info(ch, info); - } - return SUCCESS; - } -} -/* }}} */ - -/* {{{ void http_request_info(CURL *, HashTable *) */ -PHP_HTTP_API void _http_request_info(CURL *ch, HashTable *info TSRMLS_DC) -{ - zval array; - INIT_ZARR(array, info); - - HTTP_CURL_INFO(EFFECTIVE_URL); -#if LIBCURL_VERSION_NUM >= 0x070a07 - HTTP_CURL_INFO(RESPONSE_CODE); -#else - HTTP_CURL_INFO_EX(HTTP_CODE, RESPONSE_CODE); -#endif - HTTP_CURL_INFO(HTTP_CONNECTCODE); -#if LIBCURL_VERSION_NUM >= 0x070500 - HTTP_CURL_INFO(FILETIME); -#endif - HTTP_CURL_INFO(TOTAL_TIME); - HTTP_CURL_INFO(NAMELOOKUP_TIME); - HTTP_CURL_INFO(CONNECT_TIME); - HTTP_CURL_INFO(PRETRANSFER_TIME); - HTTP_CURL_INFO(STARTTRANSFER_TIME); -#if LIBCURL_VERSION_NUM >= 0x070907 - HTTP_CURL_INFO(REDIRECT_TIME); - HTTP_CURL_INFO(REDIRECT_COUNT); -#endif - HTTP_CURL_INFO(SIZE_UPLOAD); - HTTP_CURL_INFO(SIZE_DOWNLOAD); - HTTP_CURL_INFO(SPEED_DOWNLOAD); - HTTP_CURL_INFO(SPEED_UPLOAD); - HTTP_CURL_INFO(HEADER_SIZE); - HTTP_CURL_INFO(REQUEST_SIZE); - HTTP_CURL_INFO(SSL_VERIFYRESULT); -#if LIBCURL_VERSION_NUM >= 0x070c03 - /*HTTP_CURL_INFO(SSL_ENGINES); todo: CURLINFO_SLIST */ -#endif - HTTP_CURL_INFO(CONTENT_LENGTH_DOWNLOAD); - HTTP_CURL_INFO(CONTENT_LENGTH_UPLOAD); - HTTP_CURL_INFO(CONTENT_TYPE); -#if LIBCURL_VERSION_NUM >= 0x070a03 - /*HTTP_CURL_INFO(PRIVATE);*/ -#endif -#if LIBCURL_VERSION_NUM >= 0x070a08 - HTTP_CURL_INFO(HTTPAUTH_AVAIL); - HTTP_CURL_INFO(PROXYAUTH_AVAIL); -#endif -#if LIBCURL_VERSION_NUM >= 0x070c02 - /*HTTP_CURL_INFO(OS_ERRNO);*/ -#endif -#if LIBCURL_VERSION_NUM >= 0x070c03 - HTTP_CURL_INFO(NUM_CONNECTS); -#endif -} -/* }}} */ - -/* {{{ STATUS http_request_ex(CURL *, http_request_method, char *, http_request_body, HashTable, HashTable, phpstr *) */ -PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, char *url, http_request_body *body, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC) -{ - STATUS status; - zend_bool clean_curl; - - if ((clean_curl = (!ch))) { - if (!(ch = curl_easy_init())) { - http_error(HE_WARNING, HTTP_E_REQUEST, "Could not initialize curl."); - return FAILURE; - } - } - - status = ((SUCCESS == http_request_init(ch, meth, url, body, options)) && - (SUCCESS == http_request_exec(ch, info, response, NULL))) ? SUCCESS : FAILURE; - - if (clean_curl) { - curl_easy_cleanup(ch); - } - return status; -} -/* }}} */ - -/* {{{ static size_t http_curl_read_callback(void *, size_t, size_t, void *) */ -static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *s) -{ - HTTP_REQUEST_CALLBACK_DATA(s, http_request_body *, body); - - if (body->type != HTTP_REQUEST_BODY_UPLOADFILE) { - return 0; - } - return php_stream_read((php_stream *) body->data, data, len * n); -} -/* }}} */ - -/* {{{ static int http_curl_progress_callback(void *, double, double, double, double) */ -static int http_curl_progress_callback(void *data, double dltotal, double dlnow, double ultotal, double ulnow) -{ - zval *params_pass[4], params_local[4], retval; - HTTP_REQUEST_CALLBACK_DATA(data, zval *, func); - - params_pass[0] = ¶ms_local[0]; - params_pass[1] = ¶ms_local[1]; - params_pass[2] = ¶ms_local[2]; - params_pass[3] = ¶ms_local[3]; - - INIT_PZVAL(params_pass[0]); - INIT_PZVAL(params_pass[1]); - INIT_PZVAL(params_pass[2]); - INIT_PZVAL(params_pass[3]); - ZVAL_DOUBLE(params_pass[0], dltotal); - ZVAL_DOUBLE(params_pass[1], dlnow); - ZVAL_DOUBLE(params_pass[2], ultotal); - ZVAL_DOUBLE(params_pass[3], ulnow); - - return call_user_function(EG(function_table), NULL, func, &retval, 4, params_pass TSRMLS_CC); -} -/* }}} */ - -/* {{{ static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *) */ -static int http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, size_t length, void *ctx) -{ - HTTP_REQUEST_CALLBACK_DATA(ctx, http_request_conv *, conv); - -#if 0 - fprintf(stderr, "DEBUG: %s\n", data); -#endif - - switch (type) - { - case CURLINFO_DATA_IN: - if (conv->response && conv->last_info == CURLINFO_HEADER_IN) { - phpstr_appends(conv->response, HTTP_CRLF); - } - case CURLINFO_HEADER_IN: - if (conv->response) { - phpstr_append(conv->response, data, length); - } - break; - case CURLINFO_DATA_OUT: - if (conv->request && conv->last_info == CURLINFO_HEADER_OUT) { - phpstr_appends(conv->request, HTTP_CRLF); - } - case CURLINFO_HEADER_OUT: - if (conv->request) { - phpstr_append(conv->request, data, length); - } - break; - } - - if (type) { - conv->last_info = type; - } - return 0; -} -/* }}} */ - -/* {{{ static inline zval *http_curl_getopt(HashTable *, char *, size_t, int) */ -static inline zval *_http_curl_getopt_ex(HashTable *options, char *key, size_t keylen, int type TSRMLS_DC) -{ - zval **zoption; - - if (!options || (SUCCESS != zend_hash_find(options, key, keylen, (void **) &zoption))) { - return NULL; - } - - if (Z_TYPE_PP(zoption) != type) { - switch (type) - { - case IS_BOOL: convert_to_boolean_ex(zoption); break; - case IS_LONG: convert_to_long_ex(zoption); break; - case IS_DOUBLE: convert_to_double_ex(zoption); break; - case IS_STRING: convert_to_string_ex(zoption); break; - case IS_ARRAY: convert_to_array_ex(zoption); break; - case IS_OBJECT: convert_to_object_ex(zoption); break; - default: - break; - } - } - - return *zoption; -} -/* }}} */ - -#ifdef HTTP_NEED_SSL - -static MUTEX_T *http_ssl_mutex = NULL; - -static void http_ssl_lock(int mode, int n, const char * file, int line) -{ - if (mode & CRYPTO_LOCK) { - tsrm_mutex_lock(http_ssl_mutex[n]); - } else { - tsrm_mutex_unlock(http_ssl_mutex[n]); - } -} - -static unsigned long http_ssl_id(void) -{ - return (unsigned long) tsrm_thread_id(); -} - -static inline zend_bool http_ssl_init(void) -{ - curl_version_info_data *cvid = curl_version_info(CURLVERSION_NOW); - - if (cvid && (cvid->features & CURL_VERSION_SSL)) { - int i, c = CRYPTO_num_locks(); - - http_ssl_mutex = malloc(c * sizeof(MUTEX_T)); - - for (i = 0; i < c; ++i) { - http_ssl_mutex[i] = tsrm_mutex_alloc(); - } - - CRYPTO_set_id_callback(http_ssl_id); - CRYPTO_set_locking_callback(http_ssl_lock); - - return 1; - } - - return 0; -} - -static inline void http_ssl_cleanup(void) -{ - if (http_ssl_mutex) { - int i, c = CRYPTO_num_locks(); - - CRYPTO_set_id_callback(NULL); - CRYPTO_set_locking_callback(NULL); - - for (i = 0; i < c; ++i) { - tsrm_mutex_free(http_ssl_mutex[i]); - } - - free(http_ssl_mutex); - http_ssl_mutex = NULL; - } -} -#endif /* HTTP_NEED_SSL */ - -static inline void _http_curl_defaults(CURL *ch) -{ - HTTP_CURL_OPT(URL, NULL); - HTTP_CURL_OPT(NOPROGRESS, 1); - HTTP_CURL_OPT(PROXY, NULL); - HTTP_CURL_OPT(PROXYPORT, 0); - HTTP_CURL_OPT(PROXYUSERPWD, NULL); -#if LIBCURL_VERSION_NUM >= 0x070a07 - HTTP_CURL_OPT(PROXYAUTH, 0); -#endif - HTTP_CURL_OPT(INTERFACE, NULL); - HTTP_CURL_OPT(PORT, 0); - HTTP_CURL_OPT(USERPWD, NULL); -#if LIBCURL_VERSION_NUM >= 0x070a06 - HTTP_CURL_OPT(HTTPAUTH, 0); -#endif - HTTP_CURL_OPT(ENCODING, 0); - HTTP_CURL_OPT(FOLLOWLOCATION, 0); - HTTP_CURL_OPT(UNRESTRICTED_AUTH, 0); - HTTP_CURL_OPT(REFERER, NULL); - HTTP_CURL_OPT(USERAGENT, "PECL::HTTP/" HTTP_PEXT_VERSION " (PHP/" PHP_VERSION ")"); - HTTP_CURL_OPT(HTTPHEADER, NULL); - HTTP_CURL_OPT(COOKIE, NULL); - HTTP_CURL_OPT(COOKIEFILE, NULL); - HTTP_CURL_OPT(COOKIEJAR, NULL); - HTTP_CURL_OPT(RESUME_FROM, 0); - HTTP_CURL_OPT(MAXFILESIZE, 0); - HTTP_CURL_OPT(TIMEVALUE, 0); - HTTP_CURL_OPT(TIMEOUT, 0); - HTTP_CURL_OPT(CONNECTTIMEOUT, 3); - HTTP_CURL_OPT(SSLCERT, NULL); -#if LIBCURL_VERSION_NUM >= 0x070903 - HTTP_CURL_OPT(SSLCERTTYPE, NULL); -#endif - HTTP_CURL_OPT(SSLCERTPASSWD, NULL); - HTTP_CURL_OPT(SSLKEY, NULL); - HTTP_CURL_OPT(SSLKEYTYPE, NULL); - HTTP_CURL_OPT(SSLKEYPASSWD, NULL); - HTTP_CURL_OPT(SSLENGINE, NULL); - HTTP_CURL_OPT(SSLVERSION, 0); - HTTP_CURL_OPT(SSL_VERIFYPEER, 0); - HTTP_CURL_OPT(SSL_VERIFYHOST, 0); - HTTP_CURL_OPT(SSL_CIPHER_LIST, NULL); - HTTP_CURL_OPT(CAINFO, NULL); -#if LIBCURL_VERSION_NUM >= 0x070908 - HTTP_CURL_OPT(CAPATH, NULL); -#endif - HTTP_CURL_OPT(RANDOM_FILE, NULL); - HTTP_CURL_OPT(EGDSOCKET, NULL); - HTTP_CURL_OPT(POSTFIELDS, NULL); - HTTP_CURL_OPT(POSTFIELDSIZE, 0); - HTTP_CURL_OPT(HTTPPOST, NULL); - HTTP_CURL_OPT(READDATA, NULL); - HTTP_CURL_OPT(INFILESIZE, 0); -} - -#endif /* HTTP_HAVE_CURL */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_request_method_api.c b/http_request_method_api.c deleted file mode 100644 index 8c18129..0000000 --- a/http_request_method_api.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_request_method_api.h" -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) -# include "php_http_request_object.h" -#endif - -#include "phpstr/phpstr.h" - -ZEND_EXTERN_MODULE_GLOBALS(http); - -/* {{{ char *http_request_methods[] */ -static const char *const http_request_methods[] = { - "UNKOWN", - /* HTTP/1.1 */ - "GET", - "HEAD", - "POST", - "PUT", - "DELETE", - "OPTIONS", - "TRACE", - "CONNECT", - /* WebDAV - RFC 2518 */ - "PROPFIND", - "PROPPATCH", - "MKCOL", - "COPY", - "MOVE", - "LOCK", - "UNLOCK", - /* WebDAV Versioning - RFC 3253 */ - "VERSION-CONTROL", - "REPORT", - "CHECKOUT", - "CHECKIN", - "UNCHECKOUT", - "MKWORKSPACE", - "UPDATE", - "LABEL", - "MERGE", - "BASELINE-CONTROL", - "MKACTIVITY", - /* WebDAV Access Control - RFC 3744 */ - "ACL", - NULL -}; -/* }}} */ - -STATUS _http_request_method_global_init(INIT_FUNC_ARGS) -{ - /* HTTP/1.1 */ - HTTP_LONG_CONSTANT("HTTP_METH_GET", HTTP_GET); - HTTP_LONG_CONSTANT("HTTP_METH_HEAD", HTTP_HEAD); - HTTP_LONG_CONSTANT("HTTP_METH_POST", HTTP_POST); - HTTP_LONG_CONSTANT("HTTP_METH_PUT", HTTP_PUT); - HTTP_LONG_CONSTANT("HTTP_METH_DELETE", HTTP_DELETE); - HTTP_LONG_CONSTANT("HTTP_METH_OPTIONS", HTTP_OPTIONS); - HTTP_LONG_CONSTANT("HTTP_METH_TRACE", HTTP_TRACE); - HTTP_LONG_CONSTANT("HTTP_METH_CONNECT", HTTP_CONNECT); - /* WebDAV - RFC 2518 */ - HTTP_LONG_CONSTANT("HTTP_METH_PROPFIND", HTTP_PROPFIND); - HTTP_LONG_CONSTANT("HTTP_METH_PROPPATCH", HTTP_PROPPATCH); - HTTP_LONG_CONSTANT("HTTP_METH_MKCOL", HTTP_MKCOL); - HTTP_LONG_CONSTANT("HTTP_METH_COPY", HTTP_COPY); - HTTP_LONG_CONSTANT("HTTP_METH_MOVE", HTTP_MOVE); - HTTP_LONG_CONSTANT("HTTP_METH_LOCK", HTTP_LOCK); - HTTP_LONG_CONSTANT("HTTP_METH_UNLOCK", HTTP_UNLOCK); - /* WebDAV Versioning - RFC 3253 */ - HTTP_LONG_CONSTANT("HTTP_METH_VERSION_CONTROL", HTTP_VERSION_CONTROL); - HTTP_LONG_CONSTANT("HTTP_METH_REPORT", HTTP_REPORT); - HTTP_LONG_CONSTANT("HTTP_METH_CHECKOUT", HTTP_CHECKOUT); - HTTP_LONG_CONSTANT("HTTP_METH_CHECKIN", HTTP_CHECKIN); - HTTP_LONG_CONSTANT("HTTP_METH_UNCHECKOUT", HTTP_UNCHECKOUT); - HTTP_LONG_CONSTANT("HTTP_METH_MKWORKSPACE", HTTP_MKWORKSPACE); - HTTP_LONG_CONSTANT("HTTP_METH_UPDATE", HTTP_UPDATE); - HTTP_LONG_CONSTANT("HTTP_METH_LABEL", HTTP_LABEL); - HTTP_LONG_CONSTANT("HTTP_METH_MERGE", HTTP_MERGE); - HTTP_LONG_CONSTANT("HTTP_METH_BASELINE_CONTROL", HTTP_BASELINE_CONTROL); - HTTP_LONG_CONSTANT("HTTP_METH_MKACTIVITY", HTTP_MKACTIVITY); - /* WebDAV Access Control - RFC 3744 */ - HTTP_LONG_CONSTANT("HTTP_METH_ACL", HTTP_ACL); - - return SUCCESS; -} - -/* {{{ char *http_request_method_name(http_request_method) */ -PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC) -{ - zval **meth; - - if (HTTP_STD_REQUEST_METHOD(m)) { - return http_request_methods[m]; - } - - if (SUCCESS == zend_hash_index_find(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(m), (void **) &meth)) { - return Z_STRVAL_PP(meth); - } - - return http_request_methods[0]; -} -/* }}} */ - -/* {{{ unsigned long http_request_method_exists(zend_bool, unsigned long, char *) */ -PHP_HTTP_API unsigned long _http_request_method_exists(zend_bool by_name, unsigned long id, const char *name TSRMLS_DC) -{ - if (by_name) { - unsigned i; - - for (i = HTTP_NO_REQUEST_METHOD + 1; i < HTTP_MAX_REQUEST_METHOD; ++i) { - if (!strcmp(name, http_request_methods[i])) { - return i; - } - } - { - zval **data; - char *key; - ulong idx; - - FOREACH_HASH_KEYVAL(&HTTP_G(request).methods.custom, key, idx, data) { - if (!strcmp(name, Z_STRVAL_PP(data))) { - return idx + HTTP_MAX_REQUEST_METHOD; - } - } - } - return 0; - } else { - return HTTP_STD_REQUEST_METHOD(id) || zend_hash_index_exists(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(id)) ? id : 0; - } -} -/* }}} */ - -/* {{{ unsigned long http_request_method_register(char *) */ -PHP_HTTP_API unsigned long _http_request_method_register(const char *method_name TSRMLS_DC) -{ - zval array; - char *http_method, *method; - int i, method_len = strlen(method_name); - unsigned long meth_num = HTTP_G(request).methods.custom.nNextFreeElement + HTTP_MAX_REQUEST_METHOD; - - method = emalloc(method_len + 1); - for (i = 0; i < method_len; ++i) { - method[i] = toupper(method_name[i]); - } - method[method_len] = '\0'; - - INIT_ZARR(array, &HTTP_G(request).methods.custom); - add_next_index_stringl(&array, method, method_len, 0); - - method_len = spprintf(&http_method, 0, "HTTP_METH_%s", method); - zend_register_long_constant(http_method, method_len + 1, meth_num, CONST_CS, http_module_number TSRMLS_CC); - efree(http_method); - -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY) - method_len = spprintf(&http_method, 0, "METH_%s", method); - zend_declare_class_constant_long(http_request_object_ce, http_method, method_len, meth_num TSRMLS_CC); - efree(http_method); -#endif - - return meth_num; -} -/* }}} */ - -/* {{{ STATUS http_request_method_unregister(usngigned long) */ -PHP_HTTP_API STATUS _http_request_method_unregister(unsigned long method TSRMLS_DC) -{ - zval **zmethod; - char *http_method; - int method_len; - - if (SUCCESS != zend_hash_index_find(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(method), (void **) &zmethod)) { - http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Request method with id %lu does not exist", method); - return FAILURE; - } - -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY) - method_len = spprintf(&http_method, 0, "METH_%s", Z_STRVAL_PP(zmethod)); - if ((SUCCESS != zend_hash_del(&http_request_object_ce->constants_table, http_method, method_len + 1))) { - http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: HttpRequest::%s", http_method); - efree(http_method); - return FAILURE; - } - efree(http_method); -#endif - - method_len = spprintf(&http_method, 0, "HTTP_METH_%s", Z_STRVAL_PP(zmethod)); - if ( (SUCCESS != zend_hash_index_del(&HTTP_G(request).methods.custom, HTTP_CUSTOM_REQUEST_METHOD(method))) - || (SUCCESS != zend_hash_del(EG(zend_constants), http_method, method_len + 1))) { - http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: %s", http_method); - efree(http_method); - return FAILURE; - } - efree(http_method); - - return SUCCESS; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_request_object.c b/http_request_object.c deleted file mode 100644 index 9c5e902..0000000 --- a/http_request_object.c +++ /dev/null @@ -1,1688 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) - -#include "php_http_std_defs.h" -#include "php_http_request_object.h" -#include "php_http_request_api.h" -#include "php_http_request_pool_api.h" -#include "php_http.h" -#include "php_http_api.h" -#include "php_http_url_api.h" -#include "php_http_message_api.h" -#include "php_http_message_object.h" -#include "php_http_exception_object.h" - -#include "missing.h" - -#ifdef PHP_WIN32 -# include -#endif -#include - -ZEND_EXTERN_MODULE_GLOBALS(http); - -#define HTTP_BEGIN_ARGS(method, ret_ref, req_args) HTTP_BEGIN_ARGS_EX(HttpRequest, method, ret_ref, req_args) -#define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpRequest, method, ret_ref) -#define HTTP_REQUEST_ME(method, visibility) PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility) -#define HTTP_REQUEST_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method)) - -HTTP_EMPTY_ARGS(__destruct, 0); -HTTP_BEGIN_ARGS(__construct, 0, 0) - HTTP_ARG_VAL(url, 0) - HTTP_ARG_VAL(method, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getOptions, 0); -HTTP_BEGIN_ARGS(setOptions, 0, 0) - HTTP_ARG_VAL(options, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getSslOptions, 0); -HTTP_BEGIN_ARGS(setSslOptions, 0, 0) - HTTP_ARG_VAL(ssl_options, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getHeaders, 0); -HTTP_BEGIN_ARGS(setHeaders, 0, 0) - HTTP_ARG_VAL(headers, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(addHeaders, 0, 1) - HTTP_ARG_VAL(headers, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getCookies, 0); -HTTP_BEGIN_ARGS(setCookies, 0, 0) - HTTP_ARG_VAL(cookies, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(addCookies, 0, 1) - HTTP_ARG_VAL(cookies, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getUrl, 0); -HTTP_BEGIN_ARGS(setUrl, 0, 1) - HTTP_ARG_VAL(url, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getMethod, 0); -HTTP_BEGIN_ARGS(setMethod, 0, 1) - HTTP_ARG_VAL(request_method, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getContentType, 0); -HTTP_BEGIN_ARGS(setContentType, 0, 1) - HTTP_ARG_VAL(content_type, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getQueryData, 0); -HTTP_BEGIN_ARGS(setQueryData, 0, 0) - HTTP_ARG_VAL(query_data, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(addQueryData, 0, 1) - HTTP_ARG_VAL(query_data, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getPostFields, 0); -HTTP_BEGIN_ARGS(setPostFields, 0, 0) - HTTP_ARG_VAL(post_fields, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(addPostFields, 0, 1) - HTTP_ARG_VAL(post_fields, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getPostFiles, 0); -HTTP_BEGIN_ARGS(setPostFiles, 0, 0) - HTTP_ARG_VAL(post_files, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(addPostFile, 0, 2) - HTTP_ARG_VAL(formname, 0) - HTTP_ARG_VAL(filename, 0) - HTTP_ARG_VAL(content_type, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getRawPostData, 0); -HTTP_BEGIN_ARGS(setRawPostData, 0, 0) - HTTP_ARG_VAL(raw_post_data, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(addRawPostData, 0, 1) - HTTP_ARG_VAL(raw_post_data, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getPutFile, 0); -HTTP_BEGIN_ARGS(setPutFile, 0, 0) - HTTP_ARG_VAL(filename, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getResponseData, 0); -HTTP_BEGIN_ARGS(getResponseHeader, 0, 0) - HTTP_ARG_VAL(name, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(getResponseCookie, 0, 0) - HTTP_ARG_VAL(name, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getResponseBody, 0); -HTTP_EMPTY_ARGS(getResponseCode, 0); -HTTP_BEGIN_ARGS(getResponseInfo, 0, 0) - HTTP_ARG_VAL(name, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getResponseMessage, 1); -HTTP_EMPTY_ARGS(getRequestMessage, 1); -HTTP_EMPTY_ARGS(getHistory, 1); -HTTP_EMPTY_ARGS(send, 1); - -HTTP_BEGIN_ARGS(get, 0, 1) - HTTP_ARG_VAL(url, 0) - HTTP_ARG_VAL(options, 0) - HTTP_ARG_VAL(info, 1) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(head, 0, 1) - HTTP_ARG_VAL(url, 0) - HTTP_ARG_VAL(options, 0) - HTTP_ARG_VAL(info, 1) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(postData, 0, 2) - HTTP_ARG_VAL(url, 0) - HTTP_ARG_VAL(data, 0) - HTTP_ARG_VAL(options, 0) - HTTP_ARG_VAL(info, 1) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(postFields, 0, 2) - HTTP_ARG_VAL(url, 0) - HTTP_ARG_VAL(data, 0) - HTTP_ARG_VAL(options, 0) - HTTP_ARG_VAL(info, 1) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(putFile, 0, 2) - HTTP_ARG_VAL(url, 0) - HTTP_ARG_VAL(file, 0) - HTTP_ARG_VAL(options, 0) - HTTP_ARG_VAL(info, 1) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(putStream, 0, 2) - HTTP_ARG_VAL(url, 0) - HTTP_ARG_VAL(stream, 0) - HTTP_ARG_VAL(options, 0) - HTTP_ARG_VAL(info, 1) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(methodRegister, 0, 1) - HTTP_ARG_VAL(method_name, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(methodUnregister, 0, 1) - HTTP_ARG_VAL(method, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(methodName, 0, 1) - HTTP_ARG_VAL(method_id, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(methodExists, 0, 1) - HTTP_ARG_VAL(method, 0) -HTTP_END_ARGS; - -#define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C) -static inline void _http_request_object_declare_default_properties(TSRMLS_D); - -zend_class_entry *http_request_object_ce; -zend_function_entry http_request_object_fe[] = { - HTTP_REQUEST_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - HTTP_REQUEST_ME(__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) - - HTTP_REQUEST_ME(setOptions, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getOptions, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(setSslOptions, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getSslOptions, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(addHeaders, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getHeaders, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(setHeaders, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(addCookies, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getCookies, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(setCookies, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(setMethod, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getMethod, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(setUrl, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getUrl, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(setContentType, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getContentType, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(setQueryData, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getQueryData, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(addQueryData, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(setPostFields, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getPostFields, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(addPostFields, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(setRawPostData, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getRawPostData, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(addRawPostData, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(setPostFiles, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(addPostFile, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getPostFiles, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(setPutFile, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getPutFile, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(send, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ME(getResponseData, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getResponseHeader, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getResponseCookie, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getResponseCode, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getResponseBody, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getResponseInfo, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getResponseMessage, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getRequestMessage, ZEND_ACC_PUBLIC) - HTTP_REQUEST_ME(getHistory, ZEND_ACC_PUBLIC) - - HTTP_REQUEST_ALIAS(get, http_get) - HTTP_REQUEST_ALIAS(head, http_head) - HTTP_REQUEST_ALIAS(postData, http_post_data) - HTTP_REQUEST_ALIAS(postFields, http_post_fields) - HTTP_REQUEST_ALIAS(putFile, http_put_file) - HTTP_REQUEST_ALIAS(putStream, http_put_stream) - - HTTP_REQUEST_ALIAS(methodRegister, http_request_method_register) - HTTP_REQUEST_ALIAS(methodUnregister, http_request_method_unregister) - HTTP_REQUEST_ALIAS(methodName, http_request_method_name) - HTTP_REQUEST_ALIAS(methodExists, http_request_method_exists) - - EMPTY_FUNCTION_ENTRY -}; -static zend_object_handlers http_request_object_handlers; - -void _http_request_object_init(INIT_FUNC_ARGS) -{ - HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0); -} - -zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value ov; - http_request_object *o; - - o = ecalloc(1, sizeof(http_request_object)); - o->zo.ce = ce; - o->ch = curl_easy_init(); - - phpstr_init(&o->history); - phpstr_init(&o->request); - phpstr_init_ex(&o->response, HTTP_CURLBUF_SIZE, 0); - - ALLOC_HASHTABLE(OBJ_PROP(o)); - zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - - ov.handle = putObject(http_request_object, o); - ov.handlers = &http_request_object_handlers; - - return ov; -} - -static inline void _http_request_object_declare_default_properties(TSRMLS_D) -{ - zend_class_entry *ce = http_request_object_ce; - - DCL_PROP_N(PROTECTED, options); - DCL_PROP_N(PROTECTED, responseInfo); - DCL_PROP_N(PROTECTED, responseData); - DCL_PROP_N(PROTECTED, responseCode); - DCL_PROP_N(PROTECTED, responseMessage); - DCL_PROP_N(PROTECTED, postFields); - DCL_PROP_N(PROTECTED, postFiles); - - DCL_PROP(PROTECTED, long, method, HTTP_GET); - - DCL_PROP(PROTECTED, string, url, ""); - DCL_PROP(PROTECTED, string, contentType, ""); - DCL_PROP(PROTECTED, string, rawPostData, ""); - DCL_PROP(PROTECTED, string, queryData, ""); - DCL_PROP(PROTECTED, string, putFile, ""); - - DCL_PROP(PUBLIC, bool, recordHistory, 1); - -#ifndef WONKY - /* - * Request Method Constants - */ - /* HTTP/1.1 */ - DCL_CONST(long, "METH_GET", HTTP_GET); - DCL_CONST(long, "METH_HEAD", HTTP_HEAD); - DCL_CONST(long, "METH_POST", HTTP_POST); - DCL_CONST(long, "METH_PUT", HTTP_PUT); - DCL_CONST(long, "METH_DELETE", HTTP_DELETE); - DCL_CONST(long, "METH_OPTIONS", HTTP_OPTIONS); - DCL_CONST(long, "METH_TRACE", HTTP_TRACE); - DCL_CONST(long, "METH_CONNECT", HTTP_CONNECT); - /* WebDAV - RFC 2518 */ - DCL_CONST(long, "METH_PROPFIND", HTTP_PROPFIND); - DCL_CONST(long, "METH_PROPPATCH", HTTP_PROPPATCH); - DCL_CONST(long, "METH_MKCOL", HTTP_MKCOL); - DCL_CONST(long, "METH_COPY", HTTP_COPY); - DCL_CONST(long, "METH_MOVE", HTTP_MOVE); - DCL_CONST(long, "METH_LOCK", HTTP_LOCK); - DCL_CONST(long, "METH_UNLOCK", HTTP_UNLOCK); - /* WebDAV Versioning - RFC 3253 */ - DCL_CONST(long, "METH_VERSION_CONTROL", HTTP_VERSION_CONTROL); - DCL_CONST(long, "METH_REPORT", HTTP_REPORT); - DCL_CONST(long, "METH_CHECKOUT", HTTP_CHECKOUT); - DCL_CONST(long, "METH_CHECKIN", HTTP_CHECKIN); - DCL_CONST(long, "METH_UNCHECKOUT", HTTP_UNCHECKOUT); - DCL_CONST(long, "METH_MKWORKSPACE", HTTP_MKWORKSPACE); - DCL_CONST(long, "METH_UPDATE", HTTP_UPDATE); - DCL_CONST(long, "METH_LABEL", HTTP_LABEL); - DCL_CONST(long, "METH_MERGE", HTTP_MERGE); - DCL_CONST(long, "METH_BASELINE_CONTROL", HTTP_BASELINE_CONTROL); - DCL_CONST(long, "METH_MKACTIVITY", HTTP_MKACTIVITY); - /* WebDAV Access Control - RFC 3744 */ - DCL_CONST(long, "METH_ACL", HTTP_ACL); - - /* - * Auth Constants - */ -# if LIBCURL_VERSION_NUM >= 0x070a05 - DCL_CONST(long, "AUTH_BASIC", CURLAUTH_BASIC); - DCL_CONST(long, "AUTH_DIGEST", CURLAUTH_DIGEST); - DCL_CONST(long, "AUTH_NTLM", CURLAUTH_NTLM); - DCL_CONST(long, "AUTH_ANY", CURLAUTH_ANY); -# endif /* LIBCURL_VERSION_NUM */ -#endif /* WONKY */ -} - -void _http_request_object_free(zend_object *object TSRMLS_DC) -{ - http_request_object *o = (http_request_object *) object; - - if (OBJ_PROP(o)) { - zend_hash_destroy(OBJ_PROP(o)); - FREE_HASHTABLE(OBJ_PROP(o)); - } - if (o->ch) { - /* avoid nasty segfaults with already cleaned up callbacks */ - curl_easy_setopt(o->ch, CURLOPT_NOPROGRESS, 1); - curl_easy_setopt(o->ch, CURLOPT_PROGRESSFUNCTION, NULL); - curl_easy_setopt(o->ch, CURLOPT_VERBOSE, 0); - curl_easy_setopt(o->ch, CURLOPT_DEBUGFUNCTION, NULL); - curl_easy_cleanup(o->ch); - } - phpstr_dtor(&o->response); - phpstr_dtor(&o->request); - phpstr_dtor(&o->history); - efree(o); -} - -STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr, http_request_body *body TSRMLS_DC) -{ - zval *meth, *URL; - char *request_uri; - STATUS status = SUCCESS; - - if (!body) { - return FAILURE; - } - if ((!obj->ch) && (!(obj->ch = curl_easy_init()))) { - http_error(HE_WARNING, HTTP_E_REQUEST, "Could not initilaize curl"); - return FAILURE; - } - - URL = convert_to_type_ex(IS_STRING, GET_PROP(obj, url)); - // HTTP_URI_MAXLEN+1 long char * - if (!(request_uri = http_absolute_uri_ex(Z_STRVAL_P(URL), Z_STRLEN_P(URL), NULL, 0, NULL, 0, 0))) { - return FAILURE; - } - - meth = convert_to_type_ex(IS_LONG, GET_PROP(obj, method)); - switch (Z_LVAL_P(meth)) - { - case HTTP_GET: - case HTTP_HEAD: - body->type = -1; - body = NULL; - break; - - case HTTP_PUT: - { - php_stream_statbuf ssb; - php_stream *stream = php_stream_open_wrapper(Z_STRVAL_P(GET_PROP(obj, putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL); - - if (stream && !php_stream_stat(stream, &ssb)) { - body->type = HTTP_REQUEST_BODY_UPLOADFILE; - body->data = stream; - body->size = ssb.sb.st_size; - } else { - status = FAILURE; - } - } - break; - - case HTTP_POST: - default: - { - /* check for raw post data */ - zval *raw_data = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData)); - - if (Z_STRLEN_P(raw_data)) { - zval *ctype = convert_to_type_ex(IS_STRING, GET_PROP(obj, contentType)); - - if (Z_STRLEN_P(ctype)) { - zval **headers, *opts = GET_PROP(obj, options); - - convert_to_array(opts); - - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) { - zval **ct_header; - - convert_to_array(*headers); - /* only override if not already set */ - if (SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void **) &ct_header)) { - add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1); - } - } else { - zval *headers; - - MAKE_STD_ZVAL(headers); - array_init(headers); - add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1); - add_assoc_zval(opts, "headers", headers); - } - } - - body->type = HTTP_REQUEST_BODY_CSTRING; - body->data = estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data)); - body->size = Z_STRLEN_P(raw_data); - } else { - status = http_request_body_fill(body, Z_ARRVAL_P(GET_PROP(obj, postFields)), Z_ARRVAL_P(GET_PROP(obj, postFiles))); - } - } - break; - } - - if (status == SUCCESS) { - zval *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData)); - - if (Z_STRLEN_P(qdata) && (strlen(request_uri) < HTTP_URI_MAXLEN)) { - if (!strchr(request_uri, '?')) { - strcat(request_uri, "?"); - } else { - strcat(request_uri, "&"); - } - strncat(request_uri, Z_STRVAL_P(qdata), HTTP_URI_MAXLEN - strlen(request_uri)); - } - - status = http_request_init(obj->ch, Z_LVAL_P(meth), request_uri, body, Z_ARRVAL_P(GET_PROP(obj, options))); - } - efree(request_uri); - - /* clean previous response */ - phpstr_dtor(&obj->response); - /* clean previous request */ - phpstr_dtor(&obj->request); - - return status; -} - -STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this_ptr TSRMLS_DC) -{ - http_message *msg; - - phpstr_fix(&obj->request); - phpstr_fix(&obj->response); - - msg = http_message_parse(PHPSTR_VAL(&obj->response), PHPSTR_LEN(&obj->response)); - - if (!msg) { - return FAILURE; - } else { - char *body; - size_t body_len; - zval *headers, *message, - *resp = convert_to_type(IS_ARRAY, GET_PROP(obj, responseData)), - *info = convert_to_type(IS_ARRAY, GET_PROP(obj, responseInfo)); - - if (zval_is_true(GET_PROP(obj, recordHistory))) { - /* we need to act like a zipper, as we'll receive - * the requests and the responses in separate chains - * for redirects - */ - http_message *response = msg, *request = http_message_parse(PHPSTR_VAL(&obj->request), PHPSTR_LEN(&obj->request)); - http_message *free_msg = request; - - do { - char *message; - size_t msglen; - - http_message_tostring(response, &message, &msglen); - phpstr_append(&obj->history, message, msglen); - efree(message); - - http_message_tostring(request, &message, &msglen); - phpstr_append(&obj->history, message, msglen); - efree(message); - - } while ((response = response->parent) && (request = request->parent)); - - http_message_free(&free_msg); - phpstr_fix(&obj->history); - } - - UPD_PROP(obj, long, responseCode, msg->http.info.response.code); - - MAKE_STD_ZVAL(headers) - array_init(headers); - - zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - phpstr_data(PHPSTR(msg), &body, &body_len); - - add_assoc_zval(resp, "headers", headers); - add_assoc_stringl(resp, "body", body, body_len, 0); - - MAKE_STD_ZVAL(message); - ZVAL_OBJVAL(message, http_message_object_from_msg(msg)); - SET_PROP(obj, responseMessage, message); - zval_ptr_dtor(&message); - - http_request_info(obj->ch, Z_ARRVAL_P(info)); - SET_PROP(obj, responseInfo, info); - - return SUCCESS; - } -} - -#define http_request_object_set_options_subr(key, ow) \ - _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow)) -static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len, int overwrite) -{ - zval *opts, **options, *new_options = NULL; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &new_options)) { - RETURN_FALSE; - } - - opts = convert_to_type(IS_ARRAY, GET_PROP(obj, options)); - - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options)) { - convert_to_array(*options); - if (overwrite) { - zend_hash_clean(Z_ARRVAL_PP(options)); - } - if (new_options && zend_hash_num_elements(Z_ARRVAL_P(new_options))) { - if (overwrite) { - array_copy(new_options, *options); - } else { - array_merge(new_options, *options); - } - } - } else if (new_options && zend_hash_num_elements(Z_ARRVAL_P(new_options))) { - zval_add_ref(&new_options); - add_assoc_zval(opts, key, new_options); - } - - RETURN_TRUE; -} - -#define http_request_object_get_options_subr(key) \ - _http_request_get_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key)) -static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *opts, **options; - getObject(http_request_object, obj); - - opts = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, options)); - - array_init(return_value); - - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options)) { - convert_to_array(*options); - array_copy(*options, return_value); - } - } -} - - -/* ### USERLAND ### */ - -/* {{{ proto void HttpRequest::__construct([string url[, long request_method = HTTP_GET]]) - * - * Instantiate a new HttpRequest object which can be used to issue HEAD, GET - * and POST (including posting files) HTTP requests. - */ -PHP_METHOD(HttpRequest, __construct) -{ - char *URL = NULL; - int URL_len; - long meth = -1; - getObject(http_request_object, obj); - - SET_EH_THROW_HTTP(); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &URL, &URL_len, &meth)) { - INIT_PARR(obj, options); - INIT_PARR(obj, responseInfo); - INIT_PARR(obj, responseData); - INIT_PARR(obj, postFields); - INIT_PARR(obj, postFiles); - - if (URL) { - UPD_STRL(obj, url, URL, URL_len); - } - if (meth > -1) { - UPD_PROP(obj, long, method, meth); - } - } - SET_EH_NORMAL(); -} -/* }}} */ - -/* {{{ proto void HttpRequest::__destruct() - * - * Destroys the HttpRequest object. - */ -PHP_METHOD(HttpRequest, __destruct) -{ - getObject(http_request_object, obj); - - NO_ARGS; - - FREE_PARR(obj, options); - FREE_PARR(obj, responseInfo); - FREE_PARR(obj, responseData); - FREE_PARR(obj, postFields); - FREE_PARR(obj, postFiles); -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setOptions([array options]) - * - * Set the request options to use. See http_get() for a full list of available options. - */ -PHP_METHOD(HttpRequest, setOptions) -{ - char *key = NULL; - ulong idx = 0; - zval *opts = NULL, *old_opts, **opt; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &opts)) { - RETURN_FALSE; - } - - old_opts = convert_to_type(IS_ARRAY, GET_PROP(obj, options)); - - if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) { - zend_hash_clean(Z_ARRVAL_P(old_opts)); - RETURN_TRUE; - } - - /* some options need extra attention -- thus cannot use array_merge() directly */ - FOREACH_KEYVAL(opts, key, idx, opt) { - if (key) { - if (!strcmp(key, "headers")) { - zval **headers; - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(old_opts), "headers", sizeof("headers"), (void **) &headers)) { - convert_to_array(*opt); - convert_to_array(*headers); - array_merge(*opt, *headers); - continue; - } - } else if (!strcmp(key, "cookies")) { - zval **cookies; - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(old_opts), "cookies", sizeof("cookies"), (void **) &cookies)) { - convert_to_array(*opt); - convert_to_array(*cookies); - array_merge(*opt, *cookies); - continue; - } - } else if (!strcmp(key, "ssl")) { - zval **ssl; - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(old_opts), "ssl", sizeof("ssl"), (void **) &ssl)) { - convert_to_array(*opt); - convert_to_array(*ssl); - array_merge(*opt, *ssl); - continue; - } - } else if ((!strcasecmp(key, "url")) || (!strcasecmp(key, "uri"))) { - if (Z_TYPE_PP(opt) != IS_STRING) { - convert_to_string_ex(opt); - } - UPD_STRL(obj, url, Z_STRVAL_PP(opt), Z_STRLEN_PP(opt)); - continue; - } else if (!strcmp(key, "method")) { - if (Z_TYPE_PP(opt) != IS_LONG) { - convert_to_long_ex(opt); - } - UPD_PROP(obj, long, method, Z_LVAL_PP(opt)); - continue; - } - - zval_add_ref(opt); - add_assoc_zval(old_opts, key, *opt); - - /* reset */ - key = NULL; - } - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto array HttpRequest::getOptions() - * - * Get currently set options. - */ -PHP_METHOD(HttpRequest, getOptions) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *opts; - getObject(http_request_object, obj); - - opts = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, options)); - array_init(return_value); - array_copy(opts, return_value); - } -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setSslOptions([array options]) - * - * Set SSL options. - */ -PHP_METHOD(HttpRequest, setSslOptions) -{ - http_request_object_set_options_subr("ssl", 1); -} -/* }}} */ - -/* {{{ proto bool HttpRequest::addSslOptions(array options) - * - * Set additional SSL options. - */ -PHP_METHOD(HttpRequest, addSslOptions) -{ - http_request_object_set_options_subr("ssl", 0); -} -/* }}} */ - -/* {{{ proto array HttpRequest::getSslOtpions() - * - * Get previously set SSL options. - */ -PHP_METHOD(HttpRequest, getSslOptions) -{ - http_request_object_get_options_subr("ssl"); -} -/* }}} */ - -/* {{{ proto bool HttpRequest::addHeaders(array headers) - * - * Add request header name/value pairs. - */ -PHP_METHOD(HttpRequest, addHeaders) -{ - http_request_object_set_options_subr("headers", 0); -} - -/* {{{ proto bool HttpRequest::setHeaders([array headers]) - * - * Set request header name/value pairs. - */ -PHP_METHOD(HttpRequest, setHeaders) -{ - http_request_object_set_options_subr("headers", 1); -} -/* }}} */ - -/* {{{ proto array HttpRequest::getHeaders() - * - * Get previously set request headers. - */ -PHP_METHOD(HttpRequest, getHeaders) -{ - http_request_object_get_options_subr("headers"); -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setCookies([array cookies]) - * - * Set cookies. - */ -PHP_METHOD(HttpRequest, setCookies) -{ - http_request_object_set_options_subr("cookies", 1); -} -/* }}} */ - -/* {{{ proto bool HttpRequest::addCookies(array cookies) - * - * Add cookies. - */ -PHP_METHOD(HttpRequest, addCookies) -{ - http_request_object_set_options_subr("cookies", 0); -} -/* }}} */ - -/* {{{ proto array HttpRequest::getCookies() - * - * Get previously set cookies. - */ -PHP_METHOD(HttpRequest, getCookies) -{ - http_request_object_get_options_subr("cookies"); -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setUrl(string url) - * - * Set the request URL. - */ -PHP_METHOD(HttpRequest, setUrl) -{ - char *URL = NULL; - int URL_len; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URL, &URL_len)) { - RETURN_FALSE; - } - - UPD_STRL(obj, url, URL, URL_len); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string HttpRequest::getUrl() - * - * Get the previously set request URL. - */ -PHP_METHOD(HttpRequest, getUrl) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *URL = GET_PROP(obj, url); - - RETURN_ZVAL(URL, 1, 0); - } -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setMethod(long request_method) - * - * Set the request methods; one of the HTTP_HEAD, HTTP_GET or - * HTTP_POST constants. - */ -PHP_METHOD(HttpRequest, setMethod) -{ - long meth; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &meth)) { - RETURN_FALSE; - } - - UPD_PROP(obj, long, method, meth); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto long HttpRequest::getMethod() - * - * Get the previously set request method. - */ -PHP_METHOD(HttpRequest, getMethod) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *meth = GET_PROP(obj, method); - - RETURN_ZVAL(meth, 1, 0); - } -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setContentType(string content_type) - * - * Set the content type the post request should have. - * Use this only if you know what you're doing. - */ -PHP_METHOD(HttpRequest, setContentType) -{ - char *ctype; - int ct_len; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ct_len)) { - RETURN_FALSE; - } - - if (!strchr(ctype, '/')) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content-Type '%s' doesn't seem to contain a primary and a secondary part", ctype); - RETURN_FALSE; - } - - UPD_STRL(obj, contentType, ctype, ct_len); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string HttpRequest::getContentType() - * - * Get the previously content type. - */ -PHP_METHOD(HttpRequest, getContentType) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *ctype = GET_PROP(obj, contentType); - - RETURN_ZVAL(ctype, 1, 0); - } -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setQueryData([mixed query_data]) - * - * Set the URL query parameters to use. - * Overwrites previously set query parameters. - * Affects any request types. - */ -PHP_METHOD(HttpRequest, setQueryData) -{ - zval *qdata = NULL; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata)) { - RETURN_FALSE; - } - - if ((!qdata) || Z_TYPE_P(qdata) == IS_NULL) { - UPD_STRL(obj, queryData, "", 0); - } else if ((Z_TYPE_P(qdata) == IS_ARRAY) || (Z_TYPE_P(qdata) == IS_OBJECT)) { - char *query_data = NULL; - - if (SUCCESS != http_urlencode_hash(HASH_OF(qdata), &query_data)) { - RETURN_FALSE; - } - - UPD_PROP(obj, string, queryData, query_data); - efree(query_data); - } else { - convert_to_string_ex(&qdata); - UPD_STRL(obj, queryData, Z_STRVAL_P(qdata), Z_STRLEN_P(qdata)); - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string HttpRequest::getQueryData() - * - * Get the current query data in form of an urlencoded query string. - */ -PHP_METHOD(HttpRequest, getQueryData) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData)); - - RETURN_ZVAL(qdata, 1, 0); - } -} -/* }}} */ - -/* {{{ proto bool HttpRequest::addQueryData(array query_params) - * - * Add parameters to the query parameter list. - * Affects any request type. - */ -PHP_METHOD(HttpRequest, addQueryData) -{ - zval *qdata, *old_qdata; - char *query_data = NULL; - size_t query_data_len = 0; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &qdata)) { - RETURN_FALSE; - } - - old_qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData)); - - 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)) { - RETURN_FALSE; - } - - UPD_STRL(obj, queryData, query_data, query_data_len); - efree(query_data); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool HttpRequest::addPostFields(array post_data) - * - * Adds POST data entries. - * Affects only POST requests. - */ -PHP_METHOD(HttpRequest, addPostFields) -{ - zval *post, *post_data; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &post_data)) { - RETURN_FALSE; - } - - post = convert_to_type(IS_ARRAY, GET_PROP(obj, postFields)); - array_merge(post_data, post); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setPostFields([array post_data]) - * - * Set the POST data entries. - * Overwrites previously set POST data. - * Affects only POST requests. - */ -PHP_METHOD(HttpRequest, setPostFields) -{ - zval *post, *post_data = NULL; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!", &post_data)) { - RETURN_FALSE; - } - - post = convert_to_type(IS_ARRAY, GET_PROP(obj, postFields)); - zend_hash_clean(Z_ARRVAL_P(post)); - - if (post_data && zend_hash_num_elements(Z_ARRVAL_P(post_data))) { - array_copy(post_data, post); - } - - RETURN_TRUE; -} -/* }}}*/ - -/* {{{ proto array HttpRequest::getPostFields() - * - * Get previously set POST data. - */ -PHP_METHOD(HttpRequest, getPostFields) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *post_data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFields)); - - array_init(return_value); - array_copy(post_data, return_value); - } -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setRawPostData([string raw_post_data]) - * - * Set raw post data to send. Don't forget to specify a content type. - * Affects only POST requests. - */ -PHP_METHOD(HttpRequest, setRawPostData) -{ - char *raw_data = NULL; - int data_len = 0; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &raw_data, &data_len)) { - RETURN_FALSE; - } - - if (!raw_data) { - raw_data = ""; - } - - UPD_STRL(obj, rawPostData, raw_data, data_len); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool HttpRequest::addRawPostData(string raw_post_data) - * - * Add raw post data. - * Affects only POST requests. - */ -PHP_METHOD(HttpRequest, addRawPostData) -{ - char *raw_data, *new_data; - int data_len; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &raw_data, &data_len)) { - RETURN_FALSE; - } - - if (data_len) { - zval *zdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData)); - - new_data = emalloc(Z_STRLEN_P(zdata) + data_len + 1); - new_data[Z_STRLEN_P(zdata) + data_len] = '\0'; - - if (Z_STRLEN_P(zdata)) { - memcpy(new_data, Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)); - } - - memcpy(new_data + Z_STRLEN_P(zdata), raw_data, data_len); - UPD_STRL(obj, rawPostData, new_data, Z_STRLEN_P(zdata) + data_len); - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string HttpRequest::getRawPostData() - * - * Get previously set raw post data. - */ -PHP_METHOD(HttpRequest, getRawPostData) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *raw_data = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData)); - - RETURN_ZVAL(raw_data, 1, 0); - } -} -/* }}} */ - -/* {{{ proto bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"]) - * - * Add a file to the POST request. - * Affects only POST requests. - */ -PHP_METHOD(HttpRequest, addPostFile) -{ - zval *files, *entry; - char *name, *file, *type = NULL; - int name_len, file_len, type_len = 0; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &name, &name_len, &file, &file_len, &type, &type_len)) { - RETURN_FALSE; - } - - if (type_len) { - if (!strchr(type, '/')) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content-Type '%s' doesn't seem to contain a primary and a secondary part", type); - RETURN_FALSE; - } - } else { - type = "application/x-octetstream"; - type_len = sizeof("application/x-octetstream") - 1; - } - - MAKE_STD_ZVAL(entry); - array_init(entry); - - add_assoc_stringl(entry, "name", name, name_len, 1); - add_assoc_stringl(entry, "type", type, type_len, 1); - add_assoc_stringl(entry, "file", file, file_len, 1); - - files = convert_to_type(IS_ARRAY, GET_PROP(obj, postFiles)); - add_next_index_zval(files, entry); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setPostFiles([array post_files]) - * - * Set files to post. - * Overwrites previously set post files. - * Affects only POST requests. - */ -PHP_METHOD(HttpRequest, setPostFiles) -{ - zval *files, *pFiles; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &files)) { - RETURN_FALSE; - } - - pFiles = convert_to_type(IS_ARRAY, GET_PROP(obj, postFiles)); - zend_hash_clean(Z_ARRVAL_P(pFiles)); - - if (files && zend_hash_num_elements(Z_ARRVAL_P(files))) { - array_copy(files, pFiles); - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto array HttpRequest::getPostFiles() - * - * Get all previously added POST files. - */ -PHP_METHOD(HttpRequest, getPostFiles) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *files = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFiles)); - - array_init(return_value); - array_copy(files, return_value); - } -} -/* }}} */ - -/* {{{ proto bool HttpRequest::setPutFile([string file]) - * - * Set file to put. - * Affects only PUT requests. - */ -PHP_METHOD(HttpRequest, setPutFile) -{ - char *file = ""; - int file_len = 0; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &file, &file_len)) { - RETURN_FALSE; - } - - UPD_STRL(obj, putFile, file, file_len); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string HttpRequest::getPutFile() - * - * Get previously set put file. - */ -PHP_METHOD(HttpRequest, getPutFile) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *putfile = convert_to_type_ex(IS_STRING, GET_PROP(obj, putFile)); - - RETURN_ZVAL(putfile, 1, 0); - } -} -/* }}} */ - -/* {{{ proto array HttpRequest::getResponseData() - * - * Get all response data after the request has been sent. - */ -PHP_METHOD(HttpRequest, getResponseData) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData)); - - array_init(return_value); - array_copy(data, return_value); - } -} -/* }}} */ - -/* {{{ proto mixed HttpRequest::getResponseHeader([string name]) - * - * Get response header(s) after the request has been sent. - */ -PHP_METHOD(HttpRequest, getResponseHeader) -{ - IF_RETVAL_USED { - zval *data, **headers, **header; - char *header_name = NULL; - int header_len = 0; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &header_name, &header_len)) { - RETURN_FALSE; - } - - data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData)); - if (SUCCESS != zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) { - RETURN_FALSE; - } - convert_to_array_ex(headers); - if (!header_len || !header_name) { - array_init(return_value); - array_copy(*headers, return_value); - } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void **) &header)) { - RETURN_ZVAL(*header, 1, 0); - } else { - RETURN_FALSE; - } - } -} -/* }}} */ - -/* {{{ proto array HttpRequest::getResponseCookie([string name]) - * - * Get response cookie(s) after the request has been sent. - */ -PHP_METHOD(HttpRequest, getResponseCookie) -{ - IF_RETVAL_USED { - zval *data, **headers; - char *cookie_name = NULL; - int cookie_len = 0; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &cookie_name, &cookie_len)) { - RETURN_FALSE; - } - - array_init(return_value); - - data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData)); - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) { - ulong idx = 0; - char *key = NULL; - zval **header = NULL; - - convert_to_array_ex(headers); - FOREACH_HASH_KEYVAL(Z_ARRVAL_PP(headers), key, idx, header) { - if (key && !strcasecmp(key, "Set-Cookie")) { - /* several cookies? */ - if (Z_TYPE_PP(header) == IS_ARRAY) { - zval **cookie; - - FOREACH_HASH_VAL(Z_ARRVAL_PP(header), cookie) { - zval *cookie_hash; - MAKE_STD_ZVAL(cookie_hash); - array_init(cookie_hash); - - if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(cookie), Z_ARRVAL_P(cookie_hash))) { - if (!cookie_len) { - add_next_index_zval(return_value, cookie_hash); - } else { - zval **name; - - if ( (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) && - (!strcmp(Z_STRVAL_PP(name), cookie_name))) { - add_next_index_zval(return_value, cookie_hash); - return; /* <<< FOUND >>> */ - } else { - zval_dtor(cookie_hash); - efree(cookie_hash); - } - } - } else { - zval_dtor(cookie_hash); - efree(cookie_hash); - } - } - } else { - zval *cookie_hash; - - MAKE_STD_ZVAL(cookie_hash); - array_init(cookie_hash); - convert_to_string_ex(header); - - if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(header), Z_ARRVAL_P(cookie_hash))) { - if (!cookie_len) { - add_next_index_zval(return_value, cookie_hash); - } else { - zval **name; - - if ( (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) && - (!strcmp(Z_STRVAL_PP(name), cookie_name))) { - add_next_index_zval(return_value, cookie_hash); - } else { - zval_dtor(cookie_hash); - efree(cookie_hash); - } - } - } else { - zval_dtor(cookie_hash); - efree(cookie_hash); - } - } - break; - } - /* reset key */ - key = NULL; - } - } - } -} -/* }}} */ - -/* {{{ proto string HttpRequest::getResponseBody() - * - * Get the response body after the request has been sent. - */ -PHP_METHOD(HttpRequest, getResponseBody) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval **body; - getObject(http_request_object, obj); - zval *data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData)); - - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void **) &body)) { - convert_to_string_ex(body); - RETURN_ZVAL(*body, 1, 0); - } else { - RETURN_FALSE; - } - } -} -/* }}} */ - -/* {{{ proto int HttpRequest::getResponseCode() - * - * Get the response code after the request has been sent. - */ -PHP_METHOD(HttpRequest, getResponseCode) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *code = convert_to_type_ex(IS_LONG, GET_PROP(obj, responseCode)); - - RETURN_ZVAL(code, 1, 0); - } -} -/* }}} */ - -/* {{{ proto array HttpRequest::getResponseInfo([string name]) - * - * Get response info after the request has been sent. - * See http_get() for a full list of returned info. - */ -PHP_METHOD(HttpRequest, getResponseInfo) -{ - IF_RETVAL_USED { - zval *info, **infop; - char *info_name = NULL; - int info_len = 0; - getObject(http_request_object, obj); - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) { - RETURN_FALSE; - } - - info = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseInfo)); - - if (info_len && info_name) { - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void **) &infop)) { - RETURN_ZVAL(*infop, 1, 0); - } else { - http_error_ex(HE_NOTICE, HTTP_E_INVALID_PARAM, "Could not find response info named %s", info_name); - RETURN_FALSE; - } - } else { - array_init(return_value); - array_copy(info, return_value); - } - } -} -/* }}}*/ - -/* {{{ proto HttpMessage HttpRequest::getResponseMessage() - * - * Get the full response as HttpMessage object. - */ -PHP_METHOD(HttpRequest, getResponseMessage) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *message; - getObject(http_request_object, obj); - - SET_EH_THROW_HTTP(); - message = GET_PROP(obj, responseMessage); - if (Z_TYPE_P(message) == IS_OBJECT) { - RETVAL_OBJECT(message); - } else { - RETVAL_NULL(); - } - SET_EH_NORMAL(); - } -} -/* }}} */ - -/* {{{ proto HttpMessage HttpRequest::getRequestMessage() - * - * Get sent HTTP message. - */ -PHP_METHOD(HttpRequest, getRequestMessage) -{ - NO_ARGS; - - IF_RETVAL_USED { - http_message *msg; - getObject(http_request_object, obj); - - SET_EH_THROW_HTTP(); - if (msg = http_message_parse(PHPSTR_VAL(&obj->request), PHPSTR_LEN(&obj->request))) { - RETVAL_OBJVAL(http_message_object_from_msg(msg)); - } - SET_EH_NORMAL(); - } -} -/* }}} */ - -PHP_METHOD(HttpRequest, getHistory) -{ - NO_ARGS; - - IF_RETVAL_USED { - http_message *msg; - getObject(http_request_object, obj); - - SET_EH_THROW_HTTP(); - if (msg = http_message_parse(PHPSTR_VAL(&obj->history), PHPSTR_LEN(&obj->history))) { - RETVAL_OBJVAL(http_message_object_from_msg(msg)); - } - SET_EH_NORMAL(); - } -} - -/* {{{ proto HttpMessage HttpRequest::send() - * - * Send the HTTP request. - * - * GET example: - *
- * setOptions(array('lastmodified' => filemtime('local.rss')));
- * $r->addQueryData(array('category' => 3));
- * try {
- *     $r->send();
- *     if ($r->getResponseCode() == 200) {
- *         file_put_contents('local.rss', $r->getResponseBody());
- *    }
- * } catch (HttpException $ex) {
- *     echo $ex;
- * }
- * ?>
- * 
- * - * POST example: - *
- * setOptions(array('cookies' => array('lang' => 'de')));
- * $r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
- * $r->addPostFile('image', 'profile.jpg', 'image/jpeg');
- * try {
- *     echo $r->send()->getBody();
- * } catch (HttpException $ex) {
- *     echo $ex;
- * }
- * ?>
- * 
- */ -PHP_METHOD(HttpRequest, send) -{ - http_request_body body = {0, NULL, 0}; - getObject(http_request_object, obj); - - NO_ARGS; - - SET_EH_THROW_HTTP(); - - if (obj->pool) { - http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot perform HttpRequest::send() while attached to an HttpRequestPool"); - SET_EH_NORMAL(); - RETURN_FALSE; - } - - RETVAL_NULL(); - - if ( (SUCCESS == http_request_object_requesthandler(obj, getThis(), &body)) && - (SUCCESS == http_request_exec(obj->ch, NULL, &obj->response, &obj->request)) && - (SUCCESS == http_request_object_responsehandler(obj, getThis()))) { - RETVAL_OBJECT(GET_PROP(obj, responseMessage)); - } - http_request_body_dtor(&body); - - SET_EH_NORMAL(); -} -/* }}} */ - -#endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_request_pool_api.c b/http_request_pool_api.c deleted file mode 100644 index 76bd181..0000000 --- a/http_request_pool_api.c +++ /dev/null @@ -1,316 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_request_api.h" -#include "php_http_request_pool_api.h" -#include "php_http_request_object.h" -#include "php_http_requestpool_object.h" - -#ifndef HTTP_DEBUG_REQPOOLS -# define HTTP_DEBUG_REQPOOLS 0 -#endif - -ZEND_EXTERN_MODULE_GLOBALS(http); - -#ifndef HAVE_CURL_MULTI_STRERROR -# define curl_multi_strerror(dummy) "unknown error" -#endif - -static void http_request_pool_freebody(http_request_callback_ctx **body); -static int http_request_pool_compare_handles(void *h1, void *h2); - -/* {{{ http_request_pool *http_request_pool_init(http_request_pool *) */ -PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool TSRMLS_DC) -{ - zend_bool free_pool; -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Initializing request pool %p\n", pool); -#endif - if ((free_pool = (!pool))) { - pool = emalloc(sizeof(http_request_pool)); - pool->ch = NULL; - } - - if (!pool->ch) { - if (!(pool->ch = curl_multi_init())) { - http_error(HE_WARNING, HTTP_E_REQUEST, "Could not initialize curl"); - if (free_pool) { - efree(pool); - } - return NULL; - } - } - - pool->unfinished = 0; - zend_llist_init(&pool->handles, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0); - zend_llist_init(&pool->bodies, sizeof(http_request_callback_ctx *), (llist_dtor_func_t) http_request_pool_freebody, 0); -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Initialized request pool %p\n", pool); -#endif - return pool; -} -/* }}} */ - -/* {{{ STATUS http_request_pool_attach(http_request_pool *, zval *) */ -PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *request TSRMLS_DC) -{ - getObjectEx(http_request_object, req, request); -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Attaching HttpRequest(#%d) %p to pool %p\n", Z_OBJ_HANDLE_P(request), req, pool); -#endif - if (req->pool) { - 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"); - } else { - http_request_callback_ctx *body = http_request_callback_data_ex(http_request_body_new(), 0); - - if (SUCCESS != http_request_pool_requesthandler(request, body->data)) { - http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not initialize HttpRequest object for attaching to the HttpRequestPool"); - } else { - CURLMcode code = curl_multi_add_handle(pool->ch, req->ch); - - if ((CURLM_OK != code) && (CURLM_CALL_MULTI_PERFORM != code)) { - http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not attach HttpRequest object to the HttpRequestPool: %s", curl_multi_strerror(code)); - } else { - req->pool = pool; - - zend_llist_add_element(&pool->handles, &request); - zend_llist_add_element(&pool->bodies, &body); - - zval_add_ref(&request); - zend_objects_store_add_ref(request TSRMLS_CC); - -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "> %d HttpRequests attached to pool %p\n", zend_llist_count(&pool->handles), pool); -#endif - return SUCCESS; - } - } - efree(body->data); - efree(body); - } - return FAILURE; -} -/* }}} */ - -/* {{{ STATUS http_request_pool_detach(http_request_pool *, zval *) */ -PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *request TSRMLS_DC) -{ - getObjectEx(http_request_object, req, request); -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Detaching HttpRequest(#%d) %p from pool %p\n", Z_OBJ_HANDLE_P(request), req, pool); -#endif - if (!req->pool) { - /* not attached to any pool */ -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "HttpRequest object(#%d) %p is not attached to any HttpRequestPool\n", Z_OBJ_HANDLE_P(request), req); -#endif - } else if (req->pool != pool) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is not attached to this HttpRequestPool", Z_OBJ_HANDLE_P(request)); - } else { - CURLMcode code; - - req->pool = NULL; - zend_llist_del_element(&pool->handles, request, http_request_pool_compare_handles); -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "> %d HttpRequests remaining in pool %p\n", zend_llist_count(&pool->handles), pool); -#endif - if (CURLM_OK != (code = curl_multi_remove_handle(pool->ch, req->ch))) { - http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not detach HttpRequest object from the HttpRequestPool: %s", curl_multi_strerror(code)); - } else { - return SUCCESS; - } - } - return FAILURE; -} -/* }}} */ - -/* {{{ void http_request_pool_detach_all(http_request_pool *) */ -PHP_HTTP_API void _http_request_pool_detach_all(http_request_pool *pool TSRMLS_DC) -{ - int count = zend_llist_count(&pool->handles); -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Detaching %d requests from pool %p\n", count, pool); -#endif - /* - * we cannot apply a function to the llist which actually detaches - * the curl handle *and* removes the llist element -- - * so let's get our hands dirty - */ - if (count) { - int i = 0; - zend_llist_position pos; - zval **handle, **handles = emalloc(count * sizeof(zval *)); - - for (handle = zend_llist_get_first_ex(&pool->handles, &pos); handle; handle = zend_llist_get_next_ex(&pool->handles, &pos)) { - handles[i++] = *handle; - } - /* should never happen */ - if (i != count) { - zend_error(E_ERROR, "number of fetched request handles do not match overall count"); - count = i; - } - for (i = 0; i < count; ++i) { - http_request_pool_detach(pool, handles[i]); - } - efree(handles); - } -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Destroying %d request bodies of pool %p\n", zend_llist_count(&pool->bodies), pool); -#endif - /* free created bodies too */ - zend_llist_clean(&pool->bodies); -} - -/* {{{ STATUS http_request_pool_send(http_request_pool *) */ -PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool TSRMLS_DC) -{ -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Attempt to send %d requests of pool %p\n", zend_llist_count(&pool->handles), pool); -#endif - while (http_request_pool_perform(pool)) { - if (SUCCESS != http_request_pool_select(pool)) { -#ifdef PHP_WIN32 - http_error(HE_WARNING, HTTP_E_SOCKET, WSAGetLastError()); -#else - http_error(HE_WARNING, HTTP_E_SOCKET, strerror(errno)); -#endif - return FAILURE; - } - } -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Finished sending %d HttpRequests of pool %p (still unfinished: %d)\n", zend_llist_count(&pool->handles), pool, pool->unfinished); - { - int remaining = 0; - CURLMsg *msg; - /* - * FIXXME: populate --somehow - */ - do { - if (msg = curl_multi_info_read(pool->ch, &remaining)) - fprintf(stderr, "CURL: %s (%d)\n", curl_easy_strerror(msg->data.result), msg->data.result); - } while (remaining); - } -#endif - zend_llist_apply(&pool->handles, (llist_apply_func_t) http_request_pool_responsehandler TSRMLS_CC); - return SUCCESS; -} -/* }}} */ - -/* {{{ void http_request_pool_dtor(http_request_pool *) */ -PHP_HTTP_API void _http_request_pool_dtor(http_request_pool *pool TSRMLS_DC) -{ -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Destructing request pool %p\n", pool); -#endif - pool->unfinished = 0; - zend_llist_clean(&pool->handles); - zend_llist_clean(&pool->bodies); - curl_multi_cleanup(pool->ch); -} -/* }}} */ - -/* {{{ STATUS http_request_pool_select(http_request_pool *) */ -PHP_HTTP_API STATUS _http_request_pool_select(http_request_pool *pool) -{ - int MAX; - fd_set R, W, E; - struct timeval timeout = {1, 0}; - - FD_ZERO(&R); - FD_ZERO(&W); - FD_ZERO(&E); - - curl_multi_fdset(pool->ch, &R, &W, &E, &MAX); - return (-1 != select(MAX + 1, &R, &W, &E, &timeout)) ? SUCCESS : FAILURE; -} -/* }}} */ - -/* {{{ int http_request_pool_perform(http_request_pool *) */ -PHP_HTTP_API int _http_request_pool_perform(http_request_pool *pool) -{ - while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(pool->ch, &pool->unfinished)); - return pool->unfinished; -} -/* }}} */ - -/* {{{ STATUS http_request_pool_requesthandler(zval *, http_request_body *) */ -STATUS _http_request_pool_requesthandler(zval *request, http_request_body *body TSRMLS_DC) -{ - getObjectEx(http_request_object, req, request); - if (SUCCESS == http_request_object_requesthandler(req, request, body)) { - http_request_conv(req->ch, &req->response, &req->request); - return SUCCESS; - } - return FAILURE; -} -/* }}} */ - -/* {{{ void http_request_pool_responsehandler(zval **) */ -void _http_request_pool_responsehandler(zval **req TSRMLS_DC) -{ - getObjectEx(http_request_object, obj, *req); -#if HTTP_DEBUG_REQPOOLS - fprintf(stderr, "Fetching data from HttpRequest(#%d) %p of pool %p\n", Z_OBJ_HANDLE_PP(req), obj, obj->pool); -#endif - http_request_object_responsehandler(obj, *req); -} -/* }}} */ - -/*#*/ - -/* {{{ static void http_request_pool_freebody(http_request_ctx **) */ -static void http_request_pool_freebody(http_request_callback_ctx **body) -{ - HTTP_REQUEST_CALLBACK_DATA(*body, http_request_body *, b); - http_request_body_free(b); - efree(*body); -} -/* }}} */ - -/* {{{ static int http_request_pool_compare_handles(void *, void *) */ -static int http_request_pool_compare_handles(void *h1, void *h2) -{ - int match = (Z_OBJ_HANDLE_PP((zval **) h1) == Z_OBJ_HANDLE_P((zval *) h2)); -#if HTTP_DEBUG_REQPOOLS - /* if(match) fprintf(stderr, "OK\n"); */ -#endif - return match; -} -/* }}} */ - -#endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_requestpool_object.c b/http_requestpool_object.c deleted file mode 100644 index f312b7f..0000000 --- a/http_requestpool_object.c +++ /dev/null @@ -1,412 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) - -#include "php_http_std_defs.h" -#include "php_http_requestpool_object.h" -#include "php_http_request_pool_api.h" -#include "php_http_request_object.h" -#include "php_http_exception_object.h" - -#include "zend_interfaces.h" - -#ifdef PHP_WIN32 -# include -#endif -#include - -#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpRequestPool, method, 0, req_args) -#define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpRequestPool, method, ret_ref) -#define HTTP_REQPOOL_ME(method, visibility) PHP_ME(HttpRequestPool, method, HTTP_ARGS(HttpRequestPool, method), visibility) - -HTTP_BEGIN_ARGS_AR(HttpRequestPool, __construct, 0, 0) - HTTP_ARG_OBJ(HttpRequest, request0, 0) - HTTP_ARG_OBJ(HttpRequest, request1, 0) - HTTP_ARG_OBJ(HttpRequest, requestN, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(__destruct, 0); -HTTP_EMPTY_ARGS(reset, 0); - -HTTP_BEGIN_ARGS(attach, 1) - HTTP_ARG_OBJ(HttpRequest, request, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(detach, 1) - HTTP_ARG_OBJ(HttpRequest, request, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(send, 0); -HTTP_EMPTY_ARGS(socketPerform, 0); -HTTP_EMPTY_ARGS(socketSelect, 0); - -HTTP_EMPTY_ARGS(valid, 0); -HTTP_EMPTY_ARGS(current, 1); -HTTP_EMPTY_ARGS(key, 0); -HTTP_EMPTY_ARGS(next, 0); -HTTP_EMPTY_ARGS(rewind, 0); - -#define http_requestpool_object_declare_default_properties() _http_requestpool_object_declare_default_properties(TSRMLS_C) -static inline void _http_requestpool_object_declare_default_properties(TSRMLS_D); - -zend_class_entry *http_requestpool_object_ce; -zend_function_entry http_requestpool_object_fe[] = { - HTTP_REQPOOL_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - HTTP_REQPOOL_ME(__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) - HTTP_REQPOOL_ME(attach, ZEND_ACC_PUBLIC) - HTTP_REQPOOL_ME(detach, ZEND_ACC_PUBLIC) - HTTP_REQPOOL_ME(send, ZEND_ACC_PUBLIC) - HTTP_REQPOOL_ME(reset, ZEND_ACC_PUBLIC) - - HTTP_REQPOOL_ME(socketPerform, ZEND_ACC_PROTECTED) - HTTP_REQPOOL_ME(socketSelect, ZEND_ACC_PROTECTED) - - /* implements Interator */ - HTTP_REQPOOL_ME(valid, ZEND_ACC_PUBLIC) - HTTP_REQPOOL_ME(current, ZEND_ACC_PUBLIC) - HTTP_REQPOOL_ME(key, ZEND_ACC_PUBLIC) - HTTP_REQPOOL_ME(next, ZEND_ACC_PUBLIC) - HTTP_REQPOOL_ME(rewind, ZEND_ACC_PUBLIC) - - EMPTY_FUNCTION_ENTRY -}; -static zend_object_handlers http_requestpool_object_handlers; - -void _http_requestpool_object_init(INIT_FUNC_ARGS) -{ - HTTP_REGISTER_CLASS_EX(HttpRequestPool, http_requestpool_object, NULL, 0); - zend_class_implements(http_requestpool_object_ce TSRMLS_CC, 1, zend_ce_iterator); -} - -zend_object_value _http_requestpool_object_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value ov; - http_requestpool_object *o; - - o = ecalloc(1, sizeof(http_requestpool_object)); - o->zo.ce = ce; - - http_request_pool_init(&o->pool); - - ALLOC_HASHTABLE(OBJ_PROP(o)); - zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - - ov.handle = putObject(http_requestpool_object, o); - ov.handlers = &http_requestpool_object_handlers; - - return ov; -} - -static inline void _http_requestpool_object_declare_default_properties(TSRMLS_D) -{ - zend_class_entry *ce = http_requestpool_object_ce; - - DCL_PROP_N(PROTECTED, pool); -} - -void _http_requestpool_object_free(zend_object *object TSRMLS_DC) -{ - http_requestpool_object *o = (http_requestpool_object *) object; - - if (OBJ_PROP(o)) { - zend_hash_destroy(OBJ_PROP(o)); - FREE_HASHTABLE(OBJ_PROP(o)); - } - http_request_pool_dtor(&o->pool); - efree(o); -} - -/* ### USERLAND ### */ - -/* {{{ proto void HttpRequestPool::__construct([HttpRequest request[, ...]]) - * - * Instantiate a new HttpRequestPool object. An HttpRequestPool is - * able to send several HttpRequests in parallel. - * - * Example: - *
- * send();
- *     foreach($pool as $request) {
- *         printf("%s is %s (%d)\n",
- *             $request->getUrl(),
- *             $request->getResponseCode() ? 'alive' : 'not alive',
- *             $request->getResponseCode()
- *         );
- *     }
- * } catch (HttpException $e) {
- *     echo $e;
- * }
- * ?>
- * 
- */ -PHP_METHOD(HttpRequestPool, __construct) -{ - int argc = ZEND_NUM_ARGS(); - zval ***argv = safe_emalloc(argc, sizeof(zval *), 0); - getObject(http_requestpool_object, obj); - - if (SUCCESS == zend_get_parameters_array_ex(argc, argv)) { - int i; - - for (i = 0; i < argc; ++i) { - if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), http_request_object_ce TSRMLS_CC)) { - http_request_pool_attach(&obj->pool, *(argv[i])); - } - } - } - efree(argv); -} -/* }}} */ - -/* {{{ proto void HttpRequestPool::__destruct() - * - * Clean up HttpRequestPool object. - */ -PHP_METHOD(HttpRequestPool, __destruct) -{ - getObject(http_requestpool_object, obj); - - NO_ARGS; - - http_request_pool_detach_all(&obj->pool); -} -/* }}} */ - -/* {{{ proto void HttpRequestPool::reset() - * - * Detach all attached HttpRequest objects. - */ -PHP_METHOD(HttpRequestPool, reset) -{ - getObject(http_requestpool_object, obj); - - NO_ARGS; - - http_request_pool_detach_all(&obj->pool); -} - -/* {{{ proto bool HttpRequestPool::attach(HttpRequest request) - * - * Attach an HttpRequest object to this HttpRequestPool. - * NOTE: set all options prior attaching! - */ -PHP_METHOD(HttpRequestPool, attach) -{ - zval *request; - STATUS status = FAILURE; - getObject(http_requestpool_object, obj); - - SET_EH_THROW_HTTP(); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, http_request_object_ce)) { - status = http_request_pool_attach(&obj->pool, request); - } - SET_EH_NORMAL(); - RETURN_SUCCESS(status); -} -/* }}} */ - -/* {{{ proto bool HttpRequestPool::detach(HttpRequest request) - * - * Detach an HttpRequest object from this HttpRequestPool. - */ -PHP_METHOD(HttpRequestPool, detach) -{ - zval *request; - STATUS status = FAILURE; - getObject(http_requestpool_object, obj); - - SET_EH_THROW_HTTP(); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, http_request_object_ce)) { - status = http_request_pool_detach(&obj->pool, request); - } - SET_EH_NORMAL(); - RETURN_SUCCESS(status); -} -/* }}} */ - -/* {{{ proto bool HttpRequestPool::send() - * - * Send all attached HttpRequest objects in parallel. - */ -PHP_METHOD(HttpRequestPool, send) -{ - STATUS status; - getObject(http_requestpool_object, obj); - - NO_ARGS; - - SET_EH_THROW_HTTP(); - status = http_request_pool_send(&obj->pool); - SET_EH_NORMAL(); - - RETURN_SUCCESS(status); -} -/* }}} */ - -/* {{{ proto protected bool HttpRequestPool::socketSend() - * - * Usage: - *
- * socketPerform()) {
- *         do_something_else();
- *         if (!$pool->socketSelect()) {
- *             die('Socket error');
- *         }
- *     }
- * ?>
- * 
- */ -PHP_METHOD(HttpRequestPool, socketPerform) -{ - getObject(http_requestpool_object, obj); - - NO_ARGS; - - if (0 < http_request_pool_perform(&obj->pool)) { - RETURN_TRUE; - } else { - zend_llist_apply(&obj->pool.handles, (llist_apply_func_t) http_request_pool_responsehandler TSRMLS_CC); - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto protected bool HttpRequestPool::socketSelect() - * - * See HttpRequestPool::socketPerform(). - */ -PHP_METHOD(HttpRequestPool, socketSelect) -{ - getObject(http_requestpool_object, obj); - - NO_ARGS; - - RETURN_SUCCESS(http_request_pool_select(&obj->pool)); -} -/* }}} */ - -/* implements Iterator */ - -/* {{{ proto bool HttpRequestPool::valid() - * - * Implements Iterator::valid(). - */ -PHP_METHOD(HttpRequestPool, valid) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_requestpool_object, obj); - RETURN_BOOL(obj->iterator.pos < zend_llist_count(&obj->pool.handles)); - } -} -/* }}} */ - -/* {{{ proto HttpRequest HttpRequestPool::current() - * - * Implements Iterator::current(). - */ -PHP_METHOD(HttpRequestPool, current) -{ - NO_ARGS; - - IF_RETVAL_USED { - long pos = 0; - zval **current = NULL; - zend_llist_position lpos; - getObject(http_requestpool_object, obj); - - if (obj->iterator.pos < zend_llist_count(&obj->pool.handles)) { - for ( current = zend_llist_get_first_ex(&obj->pool.handles, &lpos); - current && obj->iterator.pos != pos++; - current = zend_llist_get_next_ex(&obj->pool.handles, &lpos)); - if (current) { - RETURN_OBJECT(*current); - } - } - RETURN_NULL(); - } -} -/* }}} */ - -/* {{{ proto long HttpRequestPool::key() - * - * Implements Iterator::key(). - */ -PHP_METHOD(HttpRequestPool, key) -{ - NO_ARGS; - - IF_RETVAL_USED { - getObject(http_requestpool_object, obj); - RETURN_LONG(obj->iterator.pos); - } -} -/* }}} */ - -/* {{{ proto void HttpRequestPool::next() - * - * Implements Iterator::next(). - */ -PHP_METHOD(HttpRequestPool, next) -{ - NO_ARGS { - getObject(http_requestpool_object, obj); - ++(obj->iterator.pos); - } -} -/* }}} */ - -/* {{{ proto void HttpRequestPool::rewind() - * - * Implements Iterator::rewind(). - */ -PHP_METHOD(HttpRequestPool, rewind) -{ - NO_ARGS { - getObject(http_requestpool_object, obj); - obj->iterator.pos = 0; - } -} -/* }}} */ - -#endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_response_object.c b/http_response_object.c deleted file mode 100644 index 93c8f0c..0000000 --- a/http_response_object.c +++ /dev/null @@ -1,1071 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "missing.h" - -/* broken static properties in PHP 5.0 */ -#if defined(ZEND_ENGINE_2) && !defined(WONKY) - -#include "SAPI.h" -#include "php_ini.h" - -#include "php_http.h" -#include "php_http_api.h" -#include "php_http_std_defs.h" -#include "php_http_response_object.h" -#include "php_http_exception_object.h" -#include "php_http_send_api.h" -#include "php_http_cache_api.h" -#include "php_http_headers_api.h" - -#ifdef HTTP_HAVE_MHASH -# include -#endif -#ifdef HTTP_HAVE_MAGIC -# include -#endif - -ZEND_EXTERN_MODULE_GLOBALS(http); - -#define GET_STATIC_PROP(n) *GET_STATIC_PROP_EX(http_response_object_ce, n) -#define UPD_STATIC_PROP(t, n, v) UPD_STATIC_PROP_EX(http_response_object_ce, t, n, v) -#define SET_STATIC_PROP(n, v) SET_STATIC_PROP_EX(http_response_object_ce, n, v) -#define UPD_STATIC_STRL(n, v, l) UPD_STATIC_STRL_EX(http_response_object_ce, n, v, l) - -#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpResponse, method, 0, req_args) -#define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpResponse, method, ret_ref) -#define HTTP_RESPONSE_ME(method, visibility) PHP_ME(HttpResponse, method, HTTP_ARGS(HttpResponse, method), visibility|ZEND_ACC_STATIC) -#define HTTP_RESPONSE_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpResponse, method)) - -HTTP_BEGIN_ARGS(setHeader, 2) - HTTP_ARG_VAL(name, 0) - HTTP_ARG_VAL(value, 0) - HTTP_ARG_VAL(replace, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(getHeader, 0) - HTTP_ARG_VAL(name, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getETag, 0); -HTTP_BEGIN_ARGS(setETag, 1) - HTTP_ARG_VAL(etag, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getLastModified, 0); -HTTP_BEGIN_ARGS(setLastModified, 1) - HTTP_ARG_VAL(timestamp, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getCache, 0); -HTTP_BEGIN_ARGS(setCache, 1) - HTTP_ARG_VAL(cache, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getGzip, 0); -HTTP_BEGIN_ARGS(setGzip, 1) - HTTP_ARG_VAL(gzip, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getCacheControl, 0); -HTTP_BEGIN_ARGS(setCacheControl, 1) - HTTP_ARG_VAL(cache_control, 0) - HTTP_ARG_VAL(max_age, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getContentType, 0); -HTTP_BEGIN_ARGS(setContentType, 1) - HTTP_ARG_VAL(content_type, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(guessContentType, 1) - HTTP_ARG_VAL(magic_file, 0) - HTTP_ARG_VAL(magic_mode, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getContentDisposition, 0); -HTTP_BEGIN_ARGS(setContentDisposition, 1) - HTTP_ARG_VAL(filename, 0) - HTTP_ARG_VAL(send_inline, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getThrottleDelay, 0); -HTTP_BEGIN_ARGS(setThrottleDelay, 1) - HTTP_ARG_VAL(seconds, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getBufferSize, 0); -HTTP_BEGIN_ARGS(setBufferSize, 1) - HTTP_ARG_VAL(bytes, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getData, 0); -HTTP_BEGIN_ARGS(setData, 1) - HTTP_ARG_VAL(data, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getStream, 0); -HTTP_BEGIN_ARGS(setStream, 1) - HTTP_ARG_VAL(stream, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getFile, 0); -HTTP_BEGIN_ARGS(setFile, 1) - HTTP_ARG_VAL(filepath, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(send, 0) - HTTP_ARG_VAL(clean_ob, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(capture, 0); - -HTTP_BEGIN_ARGS(redirect, 0) - HTTP_ARG_VAL(url, 0) - HTTP_ARG_VAL(params, 0) - HTTP_ARG_VAL(session, 0) - HTTP_ARG_VAL(permanent, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(status, 1) - HTTP_ARG_VAL(code, 0) -HTTP_END_ARGS; - -HTTP_EMPTY_ARGS(getRequestHeaders, 0); -HTTP_EMPTY_ARGS(getRequestBody, 0); - -#define http_response_object_declare_default_properties() _http_response_object_declare_default_properties(TSRMLS_C) -static inline void _http_response_object_declare_default_properties(TSRMLS_D); -#define http_grab_response_headers _http_grab_response_headers -static void _http_grab_response_headers(void *data, void *arg TSRMLS_DC); - -zend_class_entry *http_response_object_ce; -zend_function_entry http_response_object_fe[] = { - - HTTP_RESPONSE_ME(setHeader, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getHeader, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setETag, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getETag, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setLastModified, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getLastModified, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setContentDisposition, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getContentDisposition, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setContentType, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getContentType, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(guessContentType, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setCache, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getCache, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setCacheControl, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getCacheControl, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setGzip, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getGzip, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setThrottleDelay, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getThrottleDelay, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setBufferSize, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getBufferSize, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setData, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getData, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setFile, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getFile, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(setStream, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(getStream, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ME(send, ZEND_ACC_PUBLIC) - HTTP_RESPONSE_ME(capture, ZEND_ACC_PUBLIC) - - HTTP_RESPONSE_ALIAS(redirect, http_redirect) - HTTP_RESPONSE_ALIAS(status, http_send_status) - HTTP_RESPONSE_ALIAS(getRequestHeaders, http_get_request_headers) - HTTP_RESPONSE_ALIAS(getRequestBody, http_get_request_body) - - EMPTY_FUNCTION_ENTRY -}; - -void _http_response_object_init(INIT_FUNC_ARGS) -{ - HTTP_REGISTER_CLASS(HttpResponse, http_response_object, NULL, 0); - http_response_object_declare_default_properties(); -} - -static inline void _http_response_object_declare_default_properties(TSRMLS_D) -{ - zend_class_entry *ce = http_response_object_ce; - - DCL_STATIC_PROP(PRIVATE, bool, sent, 0); - DCL_STATIC_PROP(PRIVATE, bool, catch, 0); - DCL_STATIC_PROP(PRIVATE, long, mode, -1); - DCL_STATIC_PROP(PRIVATE, long, stream, 0); - DCL_STATIC_PROP_N(PRIVATE, file); - DCL_STATIC_PROP_N(PRIVATE, data); - DCL_STATIC_PROP(PROTECTED, bool, cache, 0); - DCL_STATIC_PROP(PROTECTED, bool, gzip, 0); - DCL_STATIC_PROP_N(PROTECTED, eTag); - DCL_STATIC_PROP(PROTECTED, long, lastModified, 0); - DCL_STATIC_PROP_N(PROTECTED, cacheControl); - DCL_STATIC_PROP_N(PROTECTED, contentType); - DCL_STATIC_PROP_N(PROTECTED, contentDisposition); - DCL_STATIC_PROP(PROTECTED, long, bufferSize, HTTP_SENDBUF_SIZE); - DCL_STATIC_PROP(PROTECTED, double, throttleDelay, 0.0); - -#ifndef WONKY - DCL_CONST(long, "ETAG_MD5", HTTP_ETAG_MD5); - DCL_CONST(long, "ETAG_SHA1", HTTP_ETAG_SHA1); - DCL_CONST(long, "ETAG_CRC32", HTTP_ETAG_CRC32); - -# ifdef HTTP_HAVE_MHASH - { - int l, i, c = mhash_count(); - - for (i = 0; i <= c; ++i) { - char const_name[256] = {0}; - const char *hash_name = mhash_get_hash_name_static(i); - - if (hash_name) { - l = snprintf(const_name, 255, "ETAG_MHASH_%s", hash_name); - zend_declare_class_constant_long(ce, const_name, l, i TSRMLS_CC); - } - } - } -# endif /* HTTP_HAVE_MHASH */ -#endif /* WONKY */ -} - -static void _http_grab_response_headers(void *data, void *arg TSRMLS_DC) -{ - phpstr_appendl(PHPSTR(arg), ((sapi_header_struct *)data)->header); - phpstr_appends(PHPSTR(arg), HTTP_CRLF); -} - -/* ### USERLAND ### */ - -/* {{{ proto static bool HttpResponse::setHeader(string name, mixed value[, bool replace = true) - */ -PHP_METHOD(HttpResponse, setHeader) -{ - zend_bool replace = 1; - char *name; - int name_len = 0; - zval *value = NULL; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/!|b", &name, &name_len, &value, &replace)) { - RETURN_FALSE; - } - if (SG(headers_sent)) { - http_error(HE_WARNING, HTTP_E_HEADER, "Cannot add another header when headers have already been sent"); - RETURN_FALSE; - } - if (!name_len) { - http_error(HE_WARNING, HTTP_E_HEADER, "Cannot send anonymous headers"); - RETURN_FALSE; - } - - /* delete header if value == null */ - if (!value || Z_TYPE_P(value) == IS_NULL) { - RETURN_SUCCESS(http_send_header_ex(name, name_len, "", 0, replace, NULL)); - } - /* send multiple header if replace is false and value is an array */ - if (!replace && Z_TYPE_P(value) == IS_ARRAY) { - zval **data; - - FOREACH_VAL(value, data) { - convert_to_string_ex(data); - if (SUCCESS != http_send_header_ex(name, name_len, Z_STRVAL_PP(data), Z_STRLEN_PP(data), 0, NULL)) { - RETURN_FALSE; - } - } - RETURN_TRUE; - } - /* send standard header */ - if (Z_TYPE_P(value) != IS_STRING) { - convert_to_string_ex(&value); - } - RETURN_SUCCESS(http_send_header_ex(name, name_len, Z_STRVAL_P(value), Z_STRLEN_P(value), replace, NULL)); -} -/* }}} */ - -/* {{{ proto static mixed HttpResponse::getHeader([string name]) - */ -PHP_METHOD(HttpResponse, getHeader) -{ - char *name = NULL; - int name_len = 0; - phpstr headers; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len)) { - RETURN_FALSE; - } - - phpstr_init(&headers); - zend_llist_apply_with_argument(&SG(sapi_headers).headers, http_grab_response_headers, &headers TSRMLS_CC); - phpstr_fix(&headers); - - if (name && name_len) { - zval **header; - HashTable headers_ht; - - zend_hash_init(&headers_ht, sizeof(zval *), NULL, ZVAL_PTR_DTOR, 0); - if ( (SUCCESS == http_parse_headers_ex(PHPSTR_VAL(&headers), &headers_ht, 1)) && - (SUCCESS == zend_hash_find(&headers_ht, name, name_len + 1, (void **) &header))) { - RETVAL_ZVAL(*header, 1, 0); - } else { - RETVAL_NULL(); - } - zend_hash_destroy(&headers_ht); - } else { - array_init(return_value); - http_parse_headers_ex(PHPSTR_VAL(&headers), Z_ARRVAL_P(return_value), 1); - } - - phpstr_dtor(&headers); -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setCache(bool cache) - * - * Whether it sould be attempted to cache the entitity. - * This will result in necessary caching headers and checks of clients - * "If-Modified-Since" and "If-None-Match" headers. If one of those headers - * matches a "304 Not Modified" status code will be issued. - * - * NOTE: If you're using sessions, be shure that you set session.cache_limiter - * to something more appropriate than "no-cache"! - */ -PHP_METHOD(HttpResponse, setCache) -{ - zend_bool do_cache = 0; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_cache)) { - RETURN_FALSE; - } - - RETURN_SUCCESS(UPD_STATIC_PROP(bool, cache, do_cache)); -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::getCache() - * - * Get current caching setting. - */ -PHP_METHOD(HttpResponse, getCache) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *cache = convert_to_type_ex(IS_BOOL, GET_STATIC_PROP(cache)); - - RETURN_ZVAL(cache, 1, 0); - } -} -/* }}}*/ - -/* {{{ proto static bool HttpResponse::setGzip(bool gzip) - * - * Enable on-thy-fly gzipping of the sent entity. - */ -PHP_METHOD(HttpResponse, setGzip) -{ - zend_bool do_gzip = 0; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_gzip)) { - RETURN_FALSE; - } - - RETURN_SUCCESS(UPD_STATIC_PROP(bool, gzip, do_gzip)); -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::getGzip() - * - * Get current gzipping setting. - */ -PHP_METHOD(HttpResponse, getGzip) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *gzip = convert_to_type_ex(IS_BOOL, GET_STATIC_PROP(gzip)); - - RETURN_ZVAL(gzip, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setCacheControl(string control[, long max_age = 0]) - * - * 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. - */ -PHP_METHOD(HttpResponse, setCacheControl) -{ - char *ccontrol, *cctl; - int cc_len; - long max_age = 0; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &ccontrol, &cc_len, &max_age)) { - RETURN_FALSE; - } - - if (strcmp(ccontrol, "public") && strcmp(ccontrol, "private") && strcmp(ccontrol, "no-cache")) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Cache-Control '%s' doesn't match public, private or no-cache", ccontrol); - RETURN_FALSE; - } else { - size_t cctl_len = spprintf(&cctl, 0, "%s, must-revalidate, max_age=%ld", ccontrol, max_age); - RETVAL_SUCCESS(UPD_STATIC_STRL(cacheControl, cctl, cctl_len)); - efree(cctl); - } -} -/* }}} */ - -/* {{{ proto static string HttpResponse::getCacheControl() - * - * Get current Cache-Control header setting. - */ -PHP_METHOD(HttpResponse, getCacheControl) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *ccontrol = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(cacheControl)); - - RETURN_ZVAL(ccontrol, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setContentType(string content_type) - * - * Set the content-type of the sent entity. - */ -PHP_METHOD(HttpResponse, setContentType) -{ - char *ctype; - int ctype_len; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ctype_len)) { - RETURN_FALSE; - } - - if (!strchr(ctype, '/')) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content type '%s' doesn't seem to contain a primary and a secondary part", ctype); - RETURN_FALSE; - } - - RETURN_SUCCESS(UPD_STATIC_STRL(contentType, ctype, ctype_len)); -} -/* }}} */ - -/* {{{ proto static string HttpResponse::getContentType() - * - * Get current Content-Type header setting. - */ -PHP_METHOD(HttpResponse, getContentType) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *ctype = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentType)); - - RETURN_ZVAL(ctype, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static string HttpResponse::guessContentType(string magic_file[, long magic_mode = MAGIC_MIME]) - * - * Attempts to guess the content type of supplied payload through libmagic. - */ -PHP_METHOD(HttpResponse, guessContentType) -{ - char *magic_file, *ct = NULL; - int magic_file_len; - long magic_mode = 0; - - RETVAL_NULL(); - -#ifdef HTTP_HAVE_MAGIC - magic_mode = MAGIC_MIME; - - SET_EH_THROW_HTTP(); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &magic_file, &magic_file_len, &magic_mode)) { - switch (Z_LVAL_P(GET_STATIC_PROP(mode))) { - case SEND_DATA: - { - zval *data = GET_STATIC_PROP(data); - ct = http_guess_content_type(magic_file, magic_mode, Z_STRVAL_P(data), Z_STRLEN_P(data), SEND_DATA); - } - break; - - case SEND_RSRC: - { - php_stream *s; - zval *z = GET_STATIC_PROP(stream); - z->type = IS_RESOURCE; - php_stream_from_zval(s, &z); - ct = http_guess_content_type(magic_file, magic_mode, s, 0, SEND_RSRC); - } - break; - - default: - ct = http_guess_content_type(magic_file, magic_mode, Z_STRVAL_P(GET_STATIC_PROP(file)), 0, -1); - break; - } - if (ct) { - UPD_STATIC_PROP(string, contentType, ct); - RETVAL_STRING(ct, 0); - } - } - SET_EH_NORMAL(); -#else - http_error(HE_THROW, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available"); -#endif -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setContentDisposition(string filename[, bool inline = false]) - * - * Set the Content-Disposition of the sent entity. This setting aims to suggest - * the receiveing user agent how to handle the sent entity; usually the client - * will show the user a "Save As..." popup. - */ -PHP_METHOD(HttpResponse, setContentDisposition) -{ - char *file, *cd; - int file_len; - size_t cd_len; - zend_bool send_inline = 0; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &file, &file_len, &send_inline)) { - RETURN_FALSE; - } - - cd_len = spprintf(&cd, 0, "%s; filename=\"%s\"", send_inline ? "inline" : "attachment", file); - RETVAL_SUCCESS(UPD_STATIC_STRL(contentDisposition, cd, cd_len)); - efree(cd); -} -/* }}} */ - -/* {{{ proto static string HttpResponse::getContentDisposition() - * - * Get current Content-Disposition setting. - */ -PHP_METHOD(HttpResponse, getContentDisposition) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *cd = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentDisposition)); - - RETURN_ZVAL(cd, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setETag(string etag) - * - * Set a custom ETag. Use this only if you know what you're doing. - */ -PHP_METHOD(HttpResponse, setETag) -{ - char *etag; - int etag_len; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &etag, &etag_len)) { - RETURN_FALSE; - } - - RETURN_SUCCESS(UPD_STATIC_STRL(eTag, etag, etag_len)); -} -/* }}} */ - -/* {{{ proto static string HttpResponse::getETag() - * - * Get calculated or previously set custom ETag. - */ -PHP_METHOD(HttpResponse, getETag) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *etag = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)); - - RETURN_ZVAL(etag, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setLastModified(long timestamp) - * - * Set a custom Last-Modified date. - */ -PHP_METHOD(HttpResponse, setLastModified) -{ - long lm; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &lm)) { - RETURN_FALSE; - } - - RETURN_SUCCESS(UPD_STATIC_PROP(long, lastModified, lm)); -} -/* }}} */ - -/* {{{ proto static HttpResponse::getLastModified() - * - * Get calculated or previously set custom Last-Modified date. - */ -PHP_METHOD(HttpResponse, getLastModified) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *lm = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified)); - - RETURN_ZVAL(lm, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setThrottleDelay(double seconds) - * - */ -PHP_METHOD(HttpResponse, setThrottleDelay) -{ - double seconds; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &seconds)) { - RETURN_FALSE; - } - RETURN_SUCCESS(UPD_STATIC_PROP(double, throttleDelay, seconds)); -} -/* }}} */ - -/* {{{ proto static double HttpResponse::getThrottleDelay() - * - */ -PHP_METHOD(HttpResponse, getThrottleDelay) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *delay = convert_to_type_ex(IS_DOUBLE, GET_STATIC_PROP(throttleDelay)); - - RETURN_ZVAL(delay, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setBufferSize(long bytes) - * - */ -PHP_METHOD(HttpResponse, setBufferSize) -{ - long bytes; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &bytes)) { - RETURN_FALSE; - } - RETURN_SUCCESS(UPD_STATIC_PROP(long, bufferSize, bytes)); -} -/* }}} */ - -/* {{{ proto static long HttpResponse::getBufferSize() - * - */ -PHP_METHOD(HttpResponse, getBufferSize) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *size = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(bufferSize)); - - RETURN_ZVAL(size, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setData(string data) - * - * Set the data to be sent. - */ -PHP_METHOD(HttpResponse, setData) -{ - zval *the_data; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &the_data)) { - RETURN_FALSE; - } - if (Z_TYPE_P(the_data) != IS_STRING) { - convert_to_string_ex(&the_data); - } - - if ( (SUCCESS != SET_STATIC_PROP(data, the_data)) || - (SUCCESS != UPD_STATIC_PROP(long, mode, SEND_DATA))) { - RETURN_FALSE; - } - - if (!(Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified))) > 0)) { - UPD_STATIC_PROP(long, lastModified, http_last_modified(the_data, SEND_DATA)); - } - if (!Z_STRLEN_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)))) { - char *etag = http_etag(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), SEND_DATA); - if (etag) { - UPD_STATIC_PROP(string, eTag, etag); - efree(etag); - } - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto static string HttpResponse::getData() - * - * Get the previously set data to be sent. - */ -PHP_METHOD(HttpResponse, getData) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *the_data = GET_STATIC_PROP(data); - - RETURN_ZVAL(the_data, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setStream(resource stream) - * - * Set the resource to be sent. - */ -PHP_METHOD(HttpResponse, setStream) -{ - zval *the_stream; - php_stream *the_real_stream; - php_stream_statbuf ssb; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &the_stream)) { - RETURN_FALSE; - } - - php_stream_from_zval(the_real_stream, &the_stream); - if (php_stream_stat(the_real_stream, &ssb)) { - RETURN_FALSE; - } - - if ( (SUCCESS != UPD_STATIC_PROP(long, stream, Z_LVAL_P(the_stream))) || - (SUCCESS != UPD_STATIC_PROP(long, mode, SEND_RSRC))) { - RETURN_FALSE; - } - zend_list_addref(Z_LVAL_P(the_stream)); - - if (!(Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified))) > 0)) { - UPD_STATIC_PROP(long, lastModified, http_last_modified(the_real_stream, SEND_RSRC)); - } - if (!Z_STRLEN_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)))) { - char *etag = http_etag(the_real_stream, 0, SEND_RSRC); - if (etag) { - UPD_STATIC_PROP(string, eTag, etag); - efree(etag); - } - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto static resource HttpResponse::getStream() - * - * Get the previously set resource to be sent. - */ -PHP_METHOD(HttpResponse, getStream) -{ - NO_ARGS; - - IF_RETVAL_USED { - RETURN_RESOURCE(Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(stream)))); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::setFile(string file) - * - * Set the file to be sent. - */ -PHP_METHOD(HttpResponse, setFile) -{ - char *the_file; - int file_len; - php_stream_statbuf ssb; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &the_file, &file_len)) { - RETURN_FALSE; - } - - if (php_stream_stat_path(the_file, &ssb)) { - RETURN_FALSE; - } - - if ( (SUCCESS != UPD_STATIC_STRL(file, the_file, file_len)) || - (SUCCESS != UPD_STATIC_PROP(long, mode, -1))) { - RETURN_FALSE; - } - - if (!(Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified))) > 0)) { - UPD_STATIC_PROP(long, lastModified, http_last_modified(the_file, -1)); - } - if (!Z_STRLEN_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)))) { - char *etag = http_etag(the_file, 0, -1); - if (etag) { - UPD_STATIC_PROP(string, eTag, etag); - efree(etag); - } - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto static string HttpResponse::getFile() - * - * Get the previously set file to be sent. - */ -PHP_METHOD(HttpResponse, getFile) -{ - NO_ARGS; - - IF_RETVAL_USED { - zval *the_file = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(file)); - - RETURN_ZVAL(the_file, 1, 0); - } -} -/* }}} */ - -/* {{{ proto static bool HttpResponse::send([bool clean_ob = true]) - * - * Finally send the entity. - * - * Example: - *
- * 
- * 
- */ -PHP_METHOD(HttpResponse, send) -{ - zval *sent; - zend_bool clean_ob = 1; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean_ob)) { - RETURN_FALSE; - } - if (SG(headers_sent)) { - http_error(HE_WARNING, HTTP_E_RESPONSE, "Cannot send HttpResponse, headers have already been sent"); - RETURN_FALSE; - } - - sent = GET_STATIC_PROP(sent); - if (zval_is_true(sent)) { - http_error(HE_WARNING, HTTP_E_RESPONSE, "Cannot send HttpResponse, response has already been sent"); - RETURN_FALSE; - } else { - Z_LVAL_P(sent) = 1; - } - - /* capture mode */ - if (zval_is_true(GET_STATIC_PROP(catch))) { - zval *the_data; - - MAKE_STD_ZVAL(the_data); - php_ob_get_buffer(the_data TSRMLS_CC); - SET_STATIC_PROP(data, the_data); - ZVAL_LONG(GET_STATIC_PROP(mode), SEND_DATA); - - if (!Z_STRLEN_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)))) { - char *etag = http_etag(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), SEND_DATA); - if (etag) { - UPD_STATIC_PROP(string, eTag, etag); - efree(etag); - } - } - zval_ptr_dtor(&the_data); - - clean_ob = 1; - } - - if (clean_ob) { - /* interrupt on-the-fly etag generation */ - HTTP_G(etag).started = 0; - /* discard previous output buffers */ - php_end_ob_buffers(0 TSRMLS_CC); - } - - /* gzip */ - if (zval_is_true(GET_STATIC_PROP(gzip))) { - php_start_ob_buffer_named("ob_gzhandler", 0, 0 TSRMLS_CC); - } else { - php_start_ob_buffer(NULL, 0, 0 TSRMLS_CC); - } - - /* caching */ - if (zval_is_true(GET_STATIC_PROP(cache))) { - zval *cctl, *etag, *lmod; - - etag = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)); - lmod = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified)); - cctl = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(cacheControl)); - - http_cache_etag(Z_STRVAL_P(etag), Z_STRLEN_P(etag), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl)); - http_cache_last_modified(Z_LVAL_P(lmod), Z_LVAL_P(lmod) ? Z_LVAL_P(lmod) : time(NULL), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl)); - } - - /* content type */ - { - zval *ctype = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentType)); - if (Z_STRLEN_P(ctype)) { - http_send_content_type(Z_STRVAL_P(ctype), Z_STRLEN_P(ctype)); - } else { - char *ctypes = INI_STR("default_mimetype"); - size_t ctlen = ctypes ? strlen(ctypes) : 0; - - if (ctlen) { - http_send_content_type(ctypes, ctlen); - } else { - http_send_content_type("application/x-octetstream", lenof("application/x-octetstream")); - } - } - } - - /* content disposition */ - { - zval *cd = GET_STATIC_PROP(contentDisposition); - if (Z_STRLEN_P(cd)) { - http_send_header_ex("Content-Disposition", lenof("Content-Disposition"), Z_STRVAL_P(cd), Z_STRLEN_P(cd), 1, NULL); - } - } - - /* throttling */ - { - HTTP_G(send).buffer_size = Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(bufferSize))); - HTTP_G(send).throttle_delay = Z_DVAL_P(convert_to_type_ex(IS_DOUBLE, GET_STATIC_PROP(throttleDelay))); - } - - /* send */ - { - switch (Z_LVAL_P(GET_STATIC_PROP(mode))) - { - case SEND_DATA: - { - zval *zdata = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(data)); - RETURN_SUCCESS(http_send_data_ex(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata), 1)); - } - - case SEND_RSRC: - { - php_stream *the_real_stream; - zval *the_stream = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(stream)); - the_stream->type = IS_RESOURCE; - php_stream_from_zval(the_real_stream, &the_stream); - RETURN_SUCCESS(http_send_stream_ex(the_real_stream, 0, 1)); - } - - default: - { - RETURN_SUCCESS(http_send_file_ex(Z_STRVAL_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(file))), 1)); - } - } - } -} -/* }}} */ - -/* {{{ proto static void HttpResponse::capture() - * - * Capture script output. - * - * Example: - *
- * 
- * 
- */ -PHP_METHOD(HttpResponse, capture) -{ - NO_ARGS; - - UPD_STATIC_PROP(long, catch, 1); - - php_end_ob_buffers(0 TSRMLS_CC); - php_start_ob_buffer(NULL, 0, 0 TSRMLS_CC); - - /* register shutdown function */ - { - zval func, retval, arg, *argp[1]; - - INIT_PZVAL(&arg); - INIT_PZVAL(&func); - INIT_PZVAL(&retval); - ZVAL_STRINGL(&func, "register_shutdown_function", lenof("register_shutdown_function"), 0); - - array_init(&arg); - add_next_index_stringl(&arg, "HttpResponse", lenof("HttpResponse"), 1); - add_next_index_stringl(&arg, "send", lenof("send"), 1); - argp[0] = &arg; - call_user_function(EG(function_table), NULL, &func, &retval, 1, argp TSRMLS_CC); - zval_dtor(&arg); - } -} -/* }}} */ - -#endif /* ZEND_ENGINE_2 && !WONKY */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_send_api.c b/http_send_api.c deleted file mode 100644 index 3f6f2a6..0000000 --- a/http_send_api.c +++ /dev/null @@ -1,449 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "SAPI.h" -#include "php_streams.h" -#include "ext/standard/php_lcg.h" - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_date_api.h" -#include "php_http_send_api.h" -#include "php_http_headers_api.h" -#include "php_http_date_api.h" -#include "php_http_cache_api.h" - -ZEND_EXTERN_MODULE_GLOBALS(http); - -#define http_flush() _http_flush(TSRMLS_C) -/* {{{ static inline void http_flush() */ -static inline void _http_flush(TSRMLS_D) -{ - php_end_ob_buffer(1, 1 TSRMLS_CC); - sapi_flush(TSRMLS_C); -} -/* }}} */ - -#define http_sleep() _http_sleep(TSRMLS_C) -/* {{{ static inline void http_sleep() */ -static inline void _http_sleep(TSRMLS_D) -{ -#define HTTP_MSEC(s) (s * 1000) -#define HTTP_USEC(s) (HTTP_MSEC(s) * 1000) -#define HTTP_NSEC(s) (HTTP_USEC(s) * 1000) -#define HTTP_NANOSEC (1000 * 1000 * 1000) -#define HTTP_DIFFSEC (0.001) - - if (HTTP_G(send).throttle_delay >= HTTP_DIFFSEC) { -#if defined(PHP_WIN32) - Sleep((DWORD) HTTP_MSEC(HTTP_G(send).throttle_delay)); -#elif defined(HAVE_USLEEP) - usleep(HTTP_USEC(HTTP_G(send).throttle_delay)); -#elif defined(HAVE_NANOSLEEP) - struct timespec req, rem; - - req.tv_sec = (time_t) HTTP_G(send).throttle_delay; - req.tv_nsec = HTTP_NSEC(HTTP_G(send).throttle_delay) % HTTP_NANOSEC; - - while (nanosleep(&req, &rem) && (errno == EINTR) && (HTTP_NSEC(rem.tv_sec) + rem.tv_nsec) > HTTP_NSEC(HTTP_DIFFSEC))) { - req.tv_sec = rem.tv_sec; - req.tv_nsec = rem.tv_nsec; - } -#endif - } -} -/* }}} */ - -#define HTTP_CHUNK_AVAIL(len) ((len -= HTTP_G(send).buffer_size) >= 0) -#define HTTP_CHUNK_WRITE(data, l, dofree, dosleep) \ - { \ - long size = (long) l; \ - \ - if ((1 > size) || (size - PHPWRITE(data, size))) { \ - if (dofree) { \ - efree(data); \ - } \ - return FAILURE; \ - } \ - \ - http_flush(); \ - if (dosleep) { \ - http_sleep(); \ - } \ - } - -#define http_send_chunk(d, b, e, m) _http_send_chunk((d), (b), (e), (m) TSRMLS_CC) -/* {{{ static STATUS http_send_chunk(const void *, size_t, size_t, http_send_mode) */ -static STATUS _http_send_chunk(const void *data, size_t begin, size_t end, http_send_mode mode TSRMLS_DC) -{ - long len = end - begin; - - switch (mode) - { - case SEND_RSRC: - { - char *buf; - php_stream *s = (php_stream *) data; - - if (php_stream_seek(s, begin, SEEK_SET)) { - return FAILURE; - } - - buf = emalloc(HTTP_G(send).buffer_size); - - while (HTTP_CHUNK_AVAIL(len)) { - HTTP_CHUNK_WRITE(buf, php_stream_read(s, buf, HTTP_G(send).buffer_size), 1, 1); - } - - /* read & write left over */ - if (len) { - HTTP_CHUNK_WRITE(buf, php_stream_read(s, buf, HTTP_G(send).buffer_size + len), 1, 0); - } - - efree(buf); - return SUCCESS; - } - - case SEND_DATA: - { - char *s = (char *) data + begin; - - while (HTTP_CHUNK_AVAIL(len)) { - HTTP_CHUNK_WRITE(s, HTTP_G(send).buffer_size, 0, 1); - s += HTTP_G(send).buffer_size; - } - - /* write left over */ - if (len) { - HTTP_CHUNK_WRITE(s, HTTP_G(send).buffer_size + len, 0, 0); - } - - return SUCCESS; - } - - default: - return FAILURE; - break; - } -} -/* }}} */ - -/* {{{ STATUS http_send_header(char *, char *, zend_bool) */ -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) -{ - STATUS ret; - size_t header_len = sizeof(": ") + name_len + value_len + 1; - char *header = emalloc(header_len + 1); - - header[header_len] = '\0'; - snprintf(header, header_len, "%s: %s", name, value); - ret = http_send_header_string_ex(header, replace); - efree(header); - return ret; -} -/* }}} */ - -/* {{{ STATUS http_send_status_header(int, char *) */ -PHP_HTTP_API STATUS _http_send_status_header_ex(int status, const char *header, zend_bool replace TSRMLS_DC) -{ - STATUS ret; - sapi_header_line h = {(char *) header, header ? strlen(header) : 0, status}; - if (SUCCESS != (ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, &h TSRMLS_CC))) { - http_error_ex(HE_WARNING, HTTP_E_HEADER, "Could not send header: %s (%d)", header, status); - } - return ret; -} -/* }}} */ - -/* {{{ STATUS http_send_last_modified(int) */ -PHP_HTTP_API STATUS _http_send_last_modified_ex(time_t t, char **sent_header TSRMLS_DC) -{ - STATUS ret; - char *date = http_date(t); - - if (!date) { - return FAILURE; - } - - ret = http_send_header_ex("Last-Modified", lenof("Last-Modifed"), date, strlen(date), 1, sent_header); - efree(date); - - /* remember */ - HTTP_G(send).last_modified = t; - - return ret; -} -/* }}} */ - -/* {{{ STATUS http_send_etag(char *, size_t) */ -PHP_HTTP_API STATUS _http_send_etag_ex(const char *etag, size_t etag_len, char **sent_header TSRMLS_DC) -{ - STATUS status; - char *etag_header; - - if (!etag_len){ - http_error_ex(HE_WARNING, HTTP_E_HEADER, "Attempt to send empty ETag (previous: %s)\n", HTTP_G(send).unquoted_etag); - return FAILURE; - } - - /* remember */ - STR_FREE(HTTP_G(send).unquoted_etag); - HTTP_G(send).unquoted_etag = estrdup(etag); - - etag_header = ecalloc(1, sizeof("ETag: \"\"") + etag_len); - sprintf(etag_header, "ETag: \"%s\"", etag); - status = http_send_header_string(etag_header); - - if (sent_header) { - *sent_header = etag_header; - } else { - efree(etag_header); - } - - return status; -} -/* }}} */ - -/* {{{ STATUS http_send_content_type(char *, size_t) */ -PHP_HTTP_API STATUS _http_send_content_type(const char *content_type, size_t ct_len TSRMLS_DC) -{ - if (!strchr(content_type, '/')) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content-Type '%s' doesn't seem to consist of a primary and a secondary part", content_type); - return FAILURE; - } - - /* remember for multiple ranges */ - STR_FREE(HTTP_G(send).content_type); - HTTP_G(send).content_type = estrndup(content_type, ct_len); - - return http_send_header_ex("Content-Type", lenof("Content-Type"), content_type, ct_len, 1, NULL); -} -/* }}} */ - -/* {{{ STATUS http_send_content_disposition(char *, size_t, zend_bool) */ -PHP_HTTP_API STATUS _http_send_content_disposition(const char *filename, size_t f_len, zend_bool send_inline TSRMLS_DC) -{ - STATUS status; - char *cd_header; - - if (send_inline) { - cd_header = ecalloc(1, sizeof("Content-Disposition: inline; filename=\"\"") + f_len); - sprintf(cd_header, "Content-Disposition: inline; filename=\"%s\"", filename); - } else { - cd_header = ecalloc(1, sizeof("Content-Disposition: attachment; filename=\"\"") + f_len); - sprintf(cd_header, "Content-Disposition: attachment; filename=\"%s\"", filename); - } - - status = http_send_header_string(cd_header); - efree(cd_header); - return status; -} -/* }}} */ - -/* {{{ STATUS http_send_ranges(HashTable *, void *, size_t, http_send_mode) */ -PHP_HTTP_API STATUS _http_send_ranges(HashTable *ranges, const void *data, size_t size, http_send_mode mode TSRMLS_DC) -{ - zval **zbegin, **zend, **zrange; - - /* single range */ - if (zend_hash_num_elements(ranges) == 1) { - char range_header[256] = {0}; - - if (SUCCESS != zend_hash_index_find(ranges, 0, (void **) &zrange) || - SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 0, (void **) &zbegin) || - SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 1, (void **) &zend)) { - http_send_status(500); - return FAILURE; - } - - /* Send HTTP 206 Partial Content */ - http_send_status(206); - - /* send content range header */ - snprintf(range_header, 255, "Content-Range: bytes %ld-%ld/%lu", Z_LVAL_PP(zbegin), Z_LVAL_PP(zend), (ulong) size); - http_send_header_string(range_header); - - /* send requested chunk */ - return http_send_chunk(data, Z_LVAL_PP(zbegin), Z_LVAL_PP(zend) + 1, mode); - } - - /* multi range */ - else { - size_t preface_len; - char bound[23] = {0}, preface[1024] = {0}, - multi_header[68] = "Content-Type: multipart/byteranges; boundary="; - - /* Send HTTP 206 Partial Content */ - http_send_status(206); - - /* send multipart/byteranges header */ - snprintf(bound, 22, "--%lu%0.9f", (ulong) time(NULL), php_combined_lcg(TSRMLS_C)); - strncat(multi_header, bound + 2, 21); - http_send_header_string(multi_header); - - /* send each requested chunk */ - FOREACH_HASH_VAL(ranges, zrange) { - if (SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 0, (void **) &zbegin) || - SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 1, (void **) &zend)) { - break; - } - - preface_len = snprintf(preface, 1023, - HTTP_CRLF "%s" - HTTP_CRLF "Content-Type: %s" - HTTP_CRLF "Content-Range: bytes %ld-%ld/%lu" - HTTP_CRLF - HTTP_CRLF, - - bound, - HTTP_G(send).content_type ? HTTP_G(send).content_type : "application/x-octetstream", - Z_LVAL_PP(zbegin), - Z_LVAL_PP(zend), - (ulong) size - ); - - PHPWRITE(preface, preface_len); - http_send_chunk(data, Z_LVAL_PP(zbegin), Z_LVAL_PP(zend) + 1, mode); - } - - /* write boundary once more */ - PHPWRITE(HTTP_CRLF, lenof(HTTP_CRLF)); - PHPWRITE(bound, strlen(bound)); - PHPWRITE("--", lenof("--")); - - return SUCCESS; - } -} -/* }}} */ - -/* {{{ STATUS http_send(void *, size_t, http_send_mode) */ -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) -{ - HashTable ranges; - http_range_status range_status; - int cache_etag = 0; - - if (!data_ptr) { - return FAILURE; - } - if (!data_size) { - return SUCCESS; - } - - /* stop on-the-fly etag generation */ - if (cache_etag = HTTP_G(etag).started) { - /* interrupt ob_etaghandler */ - HTTP_G(etag).started = 0; - } - - /* enable partial dl and resume */ - http_send_header_string("Accept-Ranges: bytes"); - - zend_hash_init(&ranges, 0, NULL, ZVAL_PTR_DTOR, 0); - range_status = http_get_request_ranges(&ranges, data_size); - - if (range_status == RANGE_ERR) { - zend_hash_destroy(&ranges); - http_send_status(416); - return FAILURE; - } - - /* Range Request - only send ranges if entity hasn't changed */ - if ( range_status == RANGE_OK && - http_match_etag_ex("HTTP_IF_MATCH", HTTP_G(send).unquoted_etag, 0) && - http_match_last_modified_ex("HTTP_IF_UNMODIFIED_SINCE", HTTP_G(send).last_modified, 0) && - http_match_last_modified_ex("HTTP_UNLESS_MODIFIED_SINCE", HTTP_G(send).last_modified, 0)) { - STATUS result = http_send_ranges(&ranges, data_ptr, data_size, data_mode); - zend_hash_destroy(&ranges); - return result; - } - - zend_hash_destroy(&ranges); - - /* send 304 Not Modified if etag matches - DON'T return on ETag generation failure */ - if (!no_cache && cache_etag) { - char *etag = NULL; - - if (!(etag = http_etag(data_ptr, data_size, data_mode))) { - http_error(HE_NOTICE, HTTP_E_RUNTIME, "Failed to generate ETag for data source"); - } else { - char *sent_header = NULL; - - http_send_etag_ex(etag, 32, &sent_header); - if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) { - return http_exit_ex(304, sent_header, NULL, 0); - } else { - STR_FREE(sent_header); - } - efree(etag); - } - } - - /* send 304 Not Modified if last modified matches */ - if (!no_cache && http_match_last_modified("HTTP_IF_MODIFIED_SINCE", HTTP_G(send).last_modified)) { - char *sent_header = NULL; - http_send_last_modified_ex(HTTP_G(send).last_modified, &sent_header); - return http_exit_ex(304, sent_header, NULL, 0); - } - - /* emit a content-length header */ - if (!php_ob_handler_used("ob_gzhandler" TSRMLS_CC)) { - char *cl; - spprintf(&cl, 0, "Content-Length: %lu", (unsigned long) data_size); - http_send_header_string(cl); - efree(cl); - } - /* send full entity */ - return http_send_chunk(data_ptr, 0, data_size, data_mode); -} -/* }}} */ - -/* {{{ STATUS http_send_stream(php_stream *) */ -PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *file, zend_bool close_stream, zend_bool no_cache TSRMLS_DC) -{ - STATUS status; - php_stream_statbuf ssb; - - if ((!file) || php_stream_stat(file, &ssb)) { - return FAILURE; - } - - status = http_send_ex(file, ssb.sb.st_size, SEND_RSRC, no_cache); - - if (close_stream) { - php_stream_close(file); - } - - return status; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ - diff --git a/http_url_api.c b/http_url_api.c deleted file mode 100644 index ccee5b3..0000000 --- a/http_url_api.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#include "SAPI.h" -#include "zend_ini.h" -#include "php_output.h" -#include "ext/standard/url.h" - -#include "php_http.h" -#include "php_http_api.h" -#include "php_http_url_api.h" -#include "php_http_std_defs.h" - -#include "phpstr/phpstr.h" - -#ifdef PHP_WIN32 -# include -#elif defined(HAVE_NETDB_H) -# include -#endif - -ZEND_EXTERN_MODULE_GLOBALS(http); - -/* {{{ char *http_absolute_url(char *) */ -PHP_HTTP_API char *_http_absolute_url_ex( - const char *url, size_t url_len, - const char *proto, size_t proto_len, - const char *host, size_t host_len, - unsigned port TSRMLS_DC) -{ -#if defined(PHP_WIN32) || defined(HAVE_NETDB_H) - struct servent *se; -#endif - php_url *purl = NULL, furl; - size_t full_len = 0; - zval *zhost = NULL; - char *scheme = NULL, *uri, *URL; - - if ((!url || !url_len) && ( - (!(url = SG(request_info).request_uri)) || - (!(url_len = strlen(SG(request_info).request_uri))))) { - http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot build an absolute URI if supplied URL and REQUEST_URI is empty"); - return NULL; - } - - URL = ecalloc(1, HTTP_URI_MAXLEN + 1); - uri = estrndup(url, url_len); - if (!(purl = php_url_parse(uri))) { - http_error_ex(HE_WARNING, HTTP_E_URL, "Could not parse supplied URL: %s", url); - return NULL; - } - - furl.user = purl->user; - furl.pass = purl->pass; - furl.path = purl->path; - furl.query = purl->query; - furl.fragment = purl->fragment; - - if (proto && proto_len) { - furl.scheme = scheme = estrdup(proto); - } else if (purl->scheme) { - furl.scheme = purl->scheme; -#if defined(PHP_WIN32) || defined(HAVE_NETDB_H) - } else if (port && (se = getservbyport(port, "tcp"))) { - furl.scheme = (scheme = estrdup(se->s_name)); -#endif - } else { - furl.scheme = "http"; - } - - if (port) { - furl.port = port; - } else if (purl->port) { - furl.port = purl->port; - } else if (strncmp(furl.scheme, "http", 4)) { -#if defined(PHP_WIN32) || defined(HAVE_NETDB_H) - if (se = getservbyname(furl.scheme, "tcp")) { - furl.port = se->s_port; - } -#endif - } else { - furl.port = (furl.scheme[4] == 's') ? 443 : 80; - } - - if (host) { - furl.host = (char *) host; - } else if (purl->host) { - furl.host = purl->host; - } else if ( (zhost = http_get_server_var("HTTP_HOST")) || - (zhost = http_get_server_var("SERVER_NAME"))) { - furl.host = Z_STRVAL_P(zhost); - } else { - furl.host = "localhost"; - } - -#define HTTP_URI_STRLCATS(URL, full_len, add_string) HTTP_URI_STRLCAT(URL, full_len, add_string, sizeof(add_string)-1) -#define HTTP_URI_STRLCATL(URL, full_len, add_string) HTTP_URI_STRLCAT(URL, full_len, add_string, strlen(add_string)) -#define HTTP_URI_STRLCAT(URL, full_len, add_string, add_len) \ - if ((full_len += add_len) > HTTP_URI_MAXLEN) { \ - http_error_ex(HE_NOTICE, HTTP_E_URL, \ - "Absolute URI would have exceeded max URI length (%d bytes) - " \ - "tried to add %d bytes ('%s')", \ - HTTP_URI_MAXLEN, add_len, add_string); \ - if (scheme) { \ - efree(scheme); \ - } \ - php_url_free(purl); \ - efree(uri); \ - return URL; \ - } else { \ - strcat(URL, add_string); \ - } - - HTTP_URI_STRLCATL(URL, full_len, furl.scheme); - HTTP_URI_STRLCATS(URL, full_len, "://"); - - if (furl.user) { - HTTP_URI_STRLCATL(URL, full_len, furl.user); - if (furl.pass) { - HTTP_URI_STRLCATS(URL, full_len, ":"); - HTTP_URI_STRLCATL(URL, full_len, furl.pass); - } - HTTP_URI_STRLCATS(URL, full_len, "@"); - } - - HTTP_URI_STRLCATL(URL, full_len, furl.host); - - if ( (!strcmp(furl.scheme, "http") && (furl.port != 80)) || - (!strcmp(furl.scheme, "https") && (furl.port != 443))) { - char port_string[8] = {0}; - snprintf(port_string, 7, ":%u", furl.port); - HTTP_URI_STRLCATL(URL, full_len, port_string); - } - - if (furl.path) { - if (furl.path[0] != '/') { - HTTP_URI_STRLCATS(URL, full_len, "/"); - } - HTTP_URI_STRLCATL(URL, full_len, furl.path); - } else { - HTTP_URI_STRLCATS(URL, full_len, "/"); - } - - if (furl.query) { - HTTP_URI_STRLCATS(URL, full_len, "?"); - HTTP_URI_STRLCATL(URL, full_len, furl.query); - } - - if (furl.fragment) { - HTTP_URI_STRLCATS(URL, full_len, "#"); - HTTP_URI_STRLCATL(URL, full_len, furl.fragment); - } - - if (scheme) { - efree(scheme); - } - php_url_free(purl); - efree(uri); - - return URL; -} -/* }}} */ - -/* {{{ STATUS http_urlencode_hash_ex(HashTable *, zend_bool, char *, size_t, char **, size_t *) */ -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) -{ - char *arg_sep; - phpstr *qstr = phpstr_new(); - - if (override_argsep || !strlen(arg_sep = INI_STR("arg_separator.output"))) { - arg_sep = HTTP_URL_ARGSEP; - } - - if (pre_encoded_len && pre_encoded_data) { - phpstr_append(qstr, pre_encoded_data, pre_encoded_len); - } - - if (SUCCESS != http_urlencode_hash_implementation(hash, qstr, arg_sep)) { - phpstr_free(&qstr); - return FAILURE; - } - - phpstr_data(qstr, encoded_data, encoded_len); - phpstr_free(&qstr); - - return SUCCESS; -} -/* }}} */ - -/* {{{ http_urlencode_hash_implementation - Original Author: Sara Golemon */ -PHP_HTTP_API STATUS _http_urlencode_hash_implementation_ex( - HashTable *ht, phpstr *formstr, char *arg_sep, - const char *num_prefix, int num_prefix_len, - const char *key_prefix, int key_prefix_len, - const char *key_suffix, int key_suffix_len, - zval *type TSRMLS_DC) -{ - char *key = NULL, *ekey, *newprefix, *p; - int arg_sep_len, ekey_len, key_type, newprefix_len; - uint key_len; - ulong idx; - zval **zdata = NULL, *copyzval; - - if (!ht || !formstr) { - http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid parameters"); - return FAILURE; - } - - if (ht->nApplyCount > 0) { - /* Prevent recursion */ - return SUCCESS; - } - - if (!arg_sep || !strlen(arg_sep)) { - arg_sep = HTTP_URL_ARGSEP; - } - arg_sep_len = strlen(arg_sep); - - for (zend_hash_internal_pointer_reset(ht); - (key_type = zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, NULL)) != HASH_KEY_NON_EXISTANT; - zend_hash_move_forward(ht) - ) { - if (key_type == HASH_KEY_IS_STRING && key_len && key[key_len-1] == '\0') { - /* We don't want that trailing NULL */ - key_len -= 1; - } - -#ifdef ZEND_ENGINE_2 - /* handling for private & protected object properties */ - if (key && *key == '\0' && type != NULL) { - char *tmp; - - zend_object *zobj = zend_objects_get_address(type TSRMLS_CC); - if (zend_check_property_access(zobj, key TSRMLS_CC) != SUCCESS) { - /* private or protected property access outside of the class */ - continue; - } - zend_unmangle_property_name(key, &tmp, &key); - key_len = strlen(key); - } -#endif - - if (zend_hash_get_current_data_ex(ht, (void **)&zdata, NULL) == FAILURE || !zdata || !(*zdata)) { - http_error(HE_WARNING, HTTP_E_ENCODING, "Error traversing form data array."); - return FAILURE; - } - if (Z_TYPE_PP(zdata) == IS_ARRAY || Z_TYPE_PP(zdata) == IS_OBJECT) { - if (key_type == HASH_KEY_IS_STRING) { - ekey = php_url_encode(key, key_len, &ekey_len); - newprefix_len = key_suffix_len + ekey_len + key_prefix_len + 1; - newprefix = emalloc(newprefix_len + 1); - p = newprefix; - - if (key_prefix) { - memcpy(p, key_prefix, key_prefix_len); - p += key_prefix_len; - } - - memcpy(p, ekey, ekey_len); - p += ekey_len; - efree(ekey); - - if (key_suffix) { - memcpy(p, key_suffix, key_suffix_len); - p += key_suffix_len; - } - - *(p++) = '['; - *p = '\0'; - } else { - /* Is an integer key */ - ekey_len = spprintf(&ekey, 12, "%ld", idx); - newprefix_len = key_prefix_len + num_prefix_len + ekey_len + key_suffix_len + 1; - newprefix = emalloc(newprefix_len + 1); - p = newprefix; - - if (key_prefix) { - memcpy(p, key_prefix, key_prefix_len); - p += key_prefix_len; - } - - memcpy(p, num_prefix, num_prefix_len); - p += num_prefix_len; - - memcpy(p, ekey, ekey_len); - p += ekey_len; - efree(ekey); - - if (key_suffix) { - memcpy(p, key_suffix, key_suffix_len); - p += key_suffix_len; - } - *(p++) = '['; - *p = '\0'; - } - ht->nApplyCount++; - http_urlencode_hash_implementation_ex(HASH_OF(*zdata), formstr, arg_sep, - NULL, 0, newprefix, newprefix_len, "]", 1, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL)); - ht->nApplyCount--; - efree(newprefix); - } else if (Z_TYPE_PP(zdata) == IS_NULL || Z_TYPE_PP(zdata) == IS_RESOURCE) { - /* Skip these types */ - continue; - } else { - if (formstr->used) { - phpstr_append(formstr, arg_sep, arg_sep_len); - } - /* Simple key=value */ - phpstr_append(formstr, key_prefix, key_prefix_len); - if (key_type == HASH_KEY_IS_STRING) { - ekey = php_url_encode(key, key_len, &ekey_len); - phpstr_append(formstr, ekey, ekey_len); - efree(ekey); - } else { - /* Numeric key */ - if (num_prefix) { - phpstr_append(formstr, num_prefix, num_prefix_len); - } - ekey_len = spprintf(&ekey, 12, "%ld", idx); - phpstr_append(formstr, ekey, ekey_len); - efree(ekey); - } - phpstr_append(formstr, key_suffix, key_suffix_len); - phpstr_appends(formstr, "="); - switch (Z_TYPE_PP(zdata)) { - case IS_STRING: - ekey = php_url_encode(Z_STRVAL_PP(zdata), Z_STRLEN_PP(zdata), &ekey_len); - break; - case IS_LONG: - case IS_BOOL: - ekey_len = spprintf(&ekey, 12, "%ld", Z_LVAL_PP(zdata)); - break; - case IS_DOUBLE: - ekey_len = spprintf(&ekey, 48, "%.*G", (int) EG(precision), Z_DVAL_PP(zdata)); - break; - default: - /* fall back on convert to string */ - MAKE_STD_ZVAL(copyzval); - *copyzval = **zdata; - zval_copy_ctor(copyzval); - convert_to_string_ex(©zval); - ekey = php_url_encode(Z_STRVAL_P(copyzval), Z_STRLEN_P(copyzval), &ekey_len); - zval_ptr_dtor(©zval); - } - phpstr_append(formstr, ekey, ekey_len); - efree(ekey); - } - } - - return SUCCESS; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/http_util_object.c b/http_util_object.c deleted file mode 100644 index 1feabad..0000000 --- a/http_util_object.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include "php.h" - -#ifdef ZEND_ENGINE_2 - -#include "php_http.h" -#include "php_http_std_defs.h" -#include "php_http_util_object.h" - -#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpUtil, method, 0, req_args) -#define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpUtil, method, ret_ref) - -#define HTTP_UTIL_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpUtil, method)) - -HTTP_BEGIN_ARGS(date, 0) - HTTP_ARG_VAL(timestamp, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(absoluteUri, 1) - HTTP_ARG_VAL(url, 0) - HTTP_ARG_VAL(proto, 0) - HTTP_ARG_VAL(host, 0) - HTTP_ARG_VAL(port, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(negotiateLanguage, 1) - HTTP_ARG_VAL(supported, 0) - HTTP_ARG_VAL(default, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(negotiateCharset, 1) - HTTP_ARG_VAL(supported, 0) - HTTP_ARG_VAL(default, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(matchModified, 1) - HTTP_ARG_VAL(last_modified, 0) - HTTP_ARG_VAL(for_range, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(matchEtag, 1) - HTTP_ARG_VAL(plain_etag, 0) - HTTP_ARG_VAL(for_range, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(matchRequestHeader, 2) - HTTP_ARG_VAL(header_name, 0) - HTTP_ARG_VAL(header_value, 0) - HTTP_ARG_VAL(case_sensitive, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(chunkedDecode, 1) - HTTP_ARG_VAL(encoded_string, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(parseMessage, 1) - HTTP_ARG_VAL(message_string, 0) -HTTP_END_ARGS; - -HTTP_BEGIN_ARGS(parseHeaders, 1) - HTTP_ARG_VAL(headers_string, 0) -HTTP_END_ARGS; - -zend_class_entry *http_util_object_ce; -zend_function_entry http_util_object_fe[] = { - HTTP_UTIL_ALIAS(date, http_date) - HTTP_UTIL_ALIAS(absoluteUri, http_absolute_uri) - HTTP_UTIL_ALIAS(negotiateLanguage, http_negotiate_language) - HTTP_UTIL_ALIAS(negotiateCharset, http_negotiate_charset) - HTTP_UTIL_ALIAS(matchModified, http_match_modified) - HTTP_UTIL_ALIAS(matchEtag, http_match_etag) - HTTP_UTIL_ALIAS(matchRequestHeader, http_match_request_header) - HTTP_UTIL_ALIAS(chunkedDecode, http_chunked_decode) - HTTP_UTIL_ALIAS(parseMessage, http_parse_message) - HTTP_UTIL_ALIAS(parseHeaders, http_parse_headers) - - EMPTY_FUNCTION_ENTRY -}; - -void _http_util_object_init(INIT_FUNC_ARGS) -{ - HTTP_REGISTER_CLASS(HttpUtil, http_util_object, NULL, 0); -} - -#endif /* ZEND_ENGINE_2 */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/missing.c b/missing.c deleted file mode 100644 index 584a75c..0000000 --- a/missing.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "missing.h" - -#ifdef WONKY -int zend_declare_property_double(zend_class_entry *ce, char *name, int name_length, double value, int access_type TSRMLS_DC) -{ - zval *property = pemalloc(sizeof(zval), ce->type & ZEND_INTERNAL_CLASS); - INIT_PZVAL(property); - ZVAL_DOUBLE(property, value); - return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC); -} - -void zend_update_property_double(zend_class_entry *scope, zval *object, char *name, int name_length, double value TSRMLS_DC) -{ - zval *tmp = ecalloc(1, sizeof(zval)); - ZVAL_DOUBLE(tmp, value); - zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC); -} - -int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC) -{ - zval *property = pemalloc(sizeof(zval), ce->type & ZEND_INTERNAL_CLASS); - INIT_PZVAL(property); - ZVAL_BOOL(property, value); - return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC); -} - -void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC) -{ - zval *tmp = ecalloc(1, sizeof(zval)); - ZVAL_BOOL(tmp, value); - zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC); -} - -void zend_update_property_stringl(zend_class_entry *scope, zval *object, char *name, int name_length, char *value, int value_len TSRMLS_DC) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->is_ref = 0; - tmp->refcount = 0; - ZVAL_STRINGL(tmp, value, value_len, 1); - zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/missing.h b/missing.h deleted file mode 100644 index e76b078..0000000 --- a/missing.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_MISSING -#define PHP_HTTP_MISSING - -#include "php_version.h" - -#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION == 0) -# define WONKY -#endif - -#ifdef WONKY -extern int zend_declare_property_double(zend_class_entry *ce, char *name, int name_length, double value, int access_type TSRMLS_DC); -extern void zend_update_property_double(zend_class_entry *scope, zval *object, char *name, int name_length, double value TSRMLS_DC); - -extern int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC); -extern void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC); - -extern void zend_update_property_stringl(zend_class_entry *scope, zval *object, char *name, int name_length, char *value, int value_len TSRMLS_DC); -#endif - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/package2.xml b/package2.xml deleted file mode 100644 index e46d871..0000000 --- a/package2.xml +++ /dev/null @@ -1,225 +0,0 @@ - - - pecl_http - pecl.php.net - Extended HTTP Support - - - Michael Wallner - mike - mike@php.net - yes - - 2005-00-00 - - 0.14.0 - 0.14.0 - - - beta - beta - - PHP License - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4.3 - 6.0.0 - 6.0.0 - - - 1.4.1 - - - - - session - - - - http - - - - - - - - - - - - - - - - - - - - diff --git a/php_http.h b/php_http.h deleted file mode 100644 index db41f35..0000000 --- a/php_http.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_EXT_HTTP_H -#define PHP_EXT_HTTP_H - -#define HTTP_PEXT_VERSION "0.14.0" - -/* make compile on Win32 */ -#ifdef HTTP_HAVE_CURL -# ifdef PHP_WIN32 -# include -# endif -# include -#endif - -#include "phpstr/phpstr.h" - -extern zend_module_entry http_module_entry; -#define phpext_http_ptr &http_module_entry - -extern int http_module_number; - -ZEND_BEGIN_MODULE_GLOBALS(http) - -#ifdef ZEND_ENGINE_2 - zend_bool only_exceptions; -#endif - struct _http_globals_etag { - long mode; - void *ctx; - zend_bool started; - } etag; - - struct _http_globals_log { - char *cache; - char *redirect; - char *allowed_methods; - char *composite; - } log; - - struct _http_globals_send { - double throttle_delay; - size_t buffer_size; - char *content_type; - char *unquoted_etag; - time_t last_modified; - } send; - - struct _http_globals_request { - struct _http_globals_request_methods { - char *allowed; - HashTable custom; - } methods; - -#ifdef HTTP_HAVE_CURL - struct _http_globals_request_copies { - zend_llist strings; - zend_llist slists; - zend_llist contexts; - zend_llist convs; - } copies; -# ifndef HAVE_CURL_EASY_STRERROR - char error[CURL_ERROR_SIZE + 1]; -# endif -#endif /* HTTP_HAVE_CURL */ - } request; - -ZEND_END_MODULE_GLOBALS(http) - -#ifdef ZTS -# include "TSRM.h" -# define HTTP_G(v) TSRMG(http_globals_id, zend_http_globals *, v) -# define HTTP_GLOBALS ((zend_http_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(http_globals_id)]) -#else -# define HTTP_G(v) (http_globals.v) -# define HTTP_GLOBALS (&http_globals) -#endif -#define getGlobals(G) zend_http_globals *G = HTTP_GLOBALS; - -PHP_FUNCTION(http_test); -PHP_FUNCTION(http_date); -PHP_FUNCTION(http_absolute_uri); -PHP_FUNCTION(http_negotiate_language); -PHP_FUNCTION(http_negotiate_charset); -PHP_FUNCTION(http_redirect); -PHP_FUNCTION(http_throttle); -PHP_FUNCTION(http_send_status); -PHP_FUNCTION(http_send_last_modified); -PHP_FUNCTION(http_send_content_type); -PHP_FUNCTION(http_send_content_disposition); -PHP_FUNCTION(http_match_modified); -PHP_FUNCTION(http_match_etag); -PHP_FUNCTION(http_cache_last_modified); -PHP_FUNCTION(http_cache_etag); -PHP_FUNCTION(http_send_data); -PHP_FUNCTION(http_send_file); -PHP_FUNCTION(http_send_stream); -PHP_FUNCTION(http_chunked_decode); -PHP_FUNCTION(http_parse_message); -PHP_FUNCTION(http_parse_headers); -PHP_FUNCTION(http_get_request_headers); -PHP_FUNCTION(http_get_request_body); -PHP_FUNCTION(http_match_request_header); -#ifdef HTTP_HAVE_CURL -PHP_FUNCTION(http_get); -PHP_FUNCTION(http_head); -PHP_FUNCTION(http_post_data); -PHP_FUNCTION(http_post_fields); -PHP_FUNCTION(http_put_file); -PHP_FUNCTION(http_put_stream); -#endif /* HTTP_HAVE_CURL */ -PHP_FUNCTION(http_request_method_register); -PHP_FUNCTION(http_request_method_unregister); -PHP_FUNCTION(http_request_method_exists); -PHP_FUNCTION(http_request_method_name); -#ifndef ZEND_ENGINE_2 -PHP_FUNCTION(http_build_query); -#endif /* ZEND_ENGINE_2 */ -PHP_FUNCTION(ob_etaghandler); - -PHP_MINIT_FUNCTION(http); -PHP_MSHUTDOWN_FUNCTION(http); -PHP_RINIT_FUNCTION(http); -PHP_RSHUTDOWN_FUNCTION(http); -PHP_MINFO_FUNCTION(http); - -#endif /* PHP_HTTP_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_api.h b/php_http_api.h deleted file mode 100644 index 826f6cd..0000000 --- a/php_http_api.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_API_H -#define PHP_HTTP_API_H - -#include "php_http_std_defs.h" -#include "php_http_send_api.h" - -#define pretty_key(key, key_len, uctitle, xhyphen) _http_pretty_key(key, key_len, uctitle, xhyphen) -extern char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen); - -typedef void (*http_key_list_decode_t)(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC); -#define http_key_list_default_decoder _http_key_list_default_decoder -extern void _http_key_list_default_decoder(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC); - -#define http_parse_cookie(l, i) _http_parse_key_list((l), (i), ';', http_key_list_default_decoder, 1 TSRMLS_CC) -#define http_parse_key_list(l, i, s, d, f) _http_parse_key_list((l), (i), (s), (d), (f) TSRMLS_CC) -extern STATUS _http_parse_key_list(const char *list, HashTable *items, char separator, http_key_list_decode_t decode, zend_bool first_entry_is_name_value_pair TSRMLS_DC); - -#define http_error(type, code, string) _http_error_ex(type, code, "%s", string) -#define http_error_ex _http_error_ex -extern void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...); - -#define http_log(f, i, m) _http_log_ex((f), (i), (m) TSRMLS_CC) -extern void http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC); - -#define http_exit(s, h) http_exit_ex((s), (h), NULL, 1) -#define http_exit_ex(s, h, b, e) _http_exit_ex((s), (h), (b), (e) TSRMLS_CC) -extern STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send_header TSRMLS_DC); - -#define http_check_method(m) http_check_method_ex((m), HTTP_KNOWN_METHODS) -#define http_check_method_ex(m, a) _http_check_method_ex((m), (a)) -extern STATUS _http_check_method_ex(const char *method, const char *methods); - -#define HTTP_GSC(var, name, ret) HTTP_GSP(var, name, return ret) -#define HTTP_GSP(var, name, ret) \ - if (!(var = _http_get_server_var_ex(name, strlen(name)+1, 1 TSRMLS_CC))) { \ - ret; \ - } -#define http_got_server_var(v) (NULL != _http_get_server_var_ex((v), sizeof(v), 1 TSRMLS_CC)) -#define http_get_server_var(v) http_get_server_var_ex((v), sizeof(v)) -#define http_get_server_var_ex(v, s) _http_get_server_var_ex((v), (s), 0 TSRMLS_CC) -PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC); - -#define http_get_request_body(b, l) _http_get_request_body_ex((b), (l), 1 TSRMLS_CC) -#define http_get_Request_body_ex(b, l, d) _http_get_request_body_ex((b), (l), (d) TSRMLS_CC) -PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC); - -#define http_chunked_decode(e, el, d, dl) _http_chunked_decode((e), (el), (d), (dl) TSRMLS_CC) -PHP_HTTP_API const char *_http_chunked_decode(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC); - -#define http_guess_content_type(mf, mm, d, l, m) _http_guess_content_type((mf), (mm), (d), (l), (m) TSRMLS_CC) -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); - - -#define http_locate_body _http_locate_body -static inline const char *_http_locate_body(const char *message) -{ - const char *cr = strstr(message, "\r\n\r\n"); - const char *lf = strstr(message, "\n\n"); - - if (lf && cr) { - return MIN(lf + 2, cr + 4); - } else if (lf || cr) { - return MAX(lf + 2, cr + 4); - } else { - return NULL; - } -} - -#define http_locate_eol _http_locate_eol -static inline const char *_http_locate_eol(const char *line, int *eol_len) -{ - const char *eol = strpbrk(line, "\r\n"); - - if (eol_len) { - *eol_len = eol ? ((eol[0] == '\r' && eol[1] == '\n') ? 2 : 1) : 0; - } - return eol; -} - -#define convert_to_type(t, z) _convert_to_type((t), (z)) -static inline zval *_convert_to_type(int type, zval *z) -{ - if (Z_TYPE_P(z) != type) { - switch (type) - { - case IS_NULL: convert_to_null(z); break; - case IS_BOOL: convert_to_boolean(z); break; - case IS_LONG: convert_to_long(z); break; - case IS_DOUBLE: convert_to_array(z); break; - case IS_STRING: convert_to_string(z); break; - case IS_ARRAY: convert_to_array(z); break; - case IS_OBJECT: convert_to_object(z); break; - } - } - return z; -} -#define convert_to_type_ex(t, z) _convert_to_type_ex((t), (z)) -static inline zval *_convert_to_type_ex(int type, zval *z) -{ - if (Z_TYPE_P(z) != type) { - switch (type) - { - case IS_NULL: convert_to_null_ex(&z); break; - case IS_BOOL: convert_to_boolean_ex(&z); break; - case IS_LONG: convert_to_long_ex(&z); break; - case IS_DOUBLE: convert_to_array_ex(&z); break; - case IS_STRING: convert_to_string_ex(&z); break; - case IS_ARRAY: convert_to_array_ex(&z); break; - case IS_OBJECT: convert_to_object_ex(&z); break; - } - } - return z; -} - - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_cache_api.h b/php_http_cache_api.h deleted file mode 100644 index 14ae720..0000000 --- a/php_http_cache_api.h +++ /dev/null @@ -1,220 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_CACHE_API_H -#define PHP_HTTP_CACHE_API_H - -#include "zend_ini.h" - -#include "ext/standard/md5.h" -#include "ext/standard/sha1.h" -#include "ext/standard/crc32.h" - -#include "php_http_std_defs.h" -#include "php_http.h" -#include "php_http_api.h" -#include "php_http_send_api.h" - -#ifdef HTTP_HAVE_MHASH -# include -#endif - -ZEND_EXTERN_MODULE_GLOBALS(http); - -#define http_cache_global_init() _http_cache_global_init(INIT_FUNC_ARGS_PASSTHRU) -extern STATUS _http_cache_global_init(INIT_FUNC_ARGS); - -typedef enum { - HTTP_ETAG_CRC32 = -3, - HTTP_ETAG_MD5 = -2, - HTTP_ETAG_SHA1 = -1, -} http_etag_mode; - -#ifdef HTTP_HAVE_MHASH -static void *http_etag_alloc_mhash_digest(size_t size) -{ - return emalloc(size); -} -#endif - -#define http_etag_digest(d, l) _http_etag_digest((d), (l) TSRMLS_CC) -static inline char *_http_etag_digest(const unsigned char *digest, int len TSRMLS_DC) -{ - int i; - char *hex = emalloc(len * 2 + 1); - char *ptr = hex; - - /* optimize this -- - look at apache's make_etag */ - for (i = 0; i < len; ++i) { - sprintf(ptr, "%02x", digest[i]); - ptr += 2; - } - *ptr = '\0'; - - return hex; -} - -#define http_etag_init() _http_etag_init(TSRMLS_C) -static inline void *_http_etag_init(TSRMLS_D) -{ - void *ctx = NULL; - long mode = INI_INT("http.etag_mode"); - - switch (mode) - { - case HTTP_ETAG_CRC32: - ctx = emalloc(sizeof(unsigned int)); - memset(ctx, 1, sizeof(unsigned int)); - break; - - case HTTP_ETAG_SHA1: - PHP_SHA1Init(ctx = emalloc(sizeof(PHP_SHA1_CTX))); - break; - - case HTTP_ETAG_MD5: -#ifndef HTTP_HAVE_MHASH - default: -#endif - PHP_MD5Init(ctx = emalloc(sizeof(PHP_MD5_CTX))); - break; - -#ifdef HTTP_HAVE_MHASH - default: - if ((mode < 0) || ((ulong)mode > mhash_count()) || (!(ctx = mhash_init(mode)))) { - http_error_ex(HE_ERROR, HTTP_E_RUNTIME, "Invalid ETag mode: %ld", mode); - } - break; -#endif - } - - return ctx; -} - -#define http_etag_finish(c) _http_etag_finish((c) TSRMLS_CC) -static inline char *_http_etag_finish(void *ctx TSRMLS_DC) -{ - char *etag = NULL; - unsigned char digest[20]; - long mode = INI_INT("http.etag_mode"); - - switch (mode) - { - case HTTP_ETAG_CRC32: - *((unsigned int *) ctx) = ~*((unsigned int *) ctx); - etag = http_etag_digest((const unsigned char *) ctx, sizeof(unsigned int)); - efree(ctx); - break; - - case HTTP_ETAG_SHA1: - PHP_SHA1Final(digest, ctx); - etag = http_etag_digest(digest, 20); - efree(ctx); - break; - - case HTTP_ETAG_MD5: -#ifndef HTTP_HAVE_MHASH - default: -#endif - PHP_MD5Final(digest, ctx); - etag = http_etag_digest(digest, 16); - efree(ctx); - break; - -#ifdef HTTP_HAVE_MHASH - default: - { - unsigned char *mhash_digest = mhash_end_m(ctx, http_etag_alloc_mhash_digest); - etag = http_etag_digest(mhash_digest, mhash_get_block_size(mode)); - efree(mhash_digest); - } - break; -#endif - } - - return etag; -} - -#define http_etag_update(c, d, l) _http_etag_update((c), (d), (l) TSRMLS_CC) -static inline void _http_etag_update(void *ctx, const char *data_ptr, size_t data_len TSRMLS_DC) -{ - switch (INI_INT("http.etag_mode")) - { - case HTTP_ETAG_CRC32: - { - unsigned int i, c = *((unsigned int *) ctx); - - for (i = 0; i < data_len; ++i) { - c = CRC32(c, data_ptr[i]); - } - *((unsigned int *)ctx) = c; - } - break; - - case HTTP_ETAG_SHA1: - PHP_SHA1Update(ctx, (const unsigned char *) data_ptr, data_len); - break; - - case HTTP_ETAG_MD5: -#ifndef HTTP_HAVE_MHASH - default: -#endif - PHP_MD5Update(ctx, (const unsigned char *) data_ptr, data_len); - break; - -#ifdef HTTP_HAVE_MHASH - default: - mhash(ctx, data_ptr, data_len); - break; -#endif - } -} - -#define http_etag(p, l, m) _http_etag((p), (l), (m) TSRMLS_CC) -PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC); - -#define http_last_modified(p, m) _http_last_modified((p), (m) TSRMLS_CC) -PHP_HTTP_API time_t _http_last_modified(const void *data_ptr, http_send_mode data_mode TSRMLS_DC); - -#define http_match_last_modified(entry, modified) _http_match_last_modified_ex((entry), (modified), 1 TSRMLS_CC) -#define http_match_last_modified_ex(entry, modified, ep) _http_match_last_modified_ex((entry), (modified), (ep) TSRMLS_CC) -PHP_HTTP_API zend_bool _http_match_last_modified_ex(const char *entry, time_t t, zend_bool enforce_presence TSRMLS_DC); - -#define http_match_etag(entry, etag) _http_match_etag_ex((entry), (etag), 1 TSRMLS_CC) -#define http_match_etag_ex(entry, etag, ep) _http_match_etag_ex((entry), (etag), (ep) TSRMLS_CC) -PHP_HTTP_API zend_bool _http_match_etag_ex(const char *entry, const char *etag, zend_bool enforce_presence TSRMLS_DC); - -#define http_cache_last_modified(l, s, cc, ccl) _http_cache_last_modified((l), (s), (cc), (ccl) TSRMLS_CC) -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); - -#define http_cache_etag(e, el, cc, ccl) _http_cache_etag((e), (el), (cc), (ccl) TSRMLS_CC) -PHP_HTTP_API STATUS _http_cache_etag(const char *etag, size_t etag_len, const char *cache_control, size_t cc_len TSRMLS_DC); - -#define http_ob_etaghandler(o, l, ho, hl, m) _http_ob_etaghandler((o), (l), (ho), (hl), (m) TSRMLS_CC) -PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_date_api.h b/php_http_date_api.h deleted file mode 100644 index ee93458..0000000 --- a/php_http_date_api.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_DATE_API_H -#define PHP_HTTP_DATE_API_H - -#include "php_http_std_defs.h" - -#define http_date(t) _http_date((t) TSRMLS_CC) -PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC); - -#define http_parse_date(d) _http_parse_date((d)) -PHP_HTTP_API time_t _http_parse_date(const char *date); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_exception_object.h b/php_http_exception_object.h deleted file mode 100644 index f309035..0000000 --- a/php_http_exception_object.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_EXCEPTION_OBJECT_H -#define PHP_HTTP_EXCEPTION_OBJECT_H -#ifdef ZEND_ENGINE_2 - -extern zend_class_entry *http_exception_object_ce; -extern zend_function_entry http_exception_object_fe[]; - -#define http_exception_object_init() _http_exception_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_exception_object_init(INIT_FUNC_ARGS); - -#define http_exception_get_default _http_exception_get_default -extern zend_class_entry *_http_exception_get_default(); - -#define http_exception_get_for_code(c) _http_exception_get_for_code(c) -extern zend_class_entry *_http_exception_get_for_code(long code); - -#endif -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_headers_api.h b/php_http_headers_api.h deleted file mode 100644 index 329d650..0000000 --- a/php_http_headers_api.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_HEADERS_API_H -#define PHP_HTTP_HEADERS_API_H - -#include "php_http_std_defs.h" -#include "php_http_info_api.h" - -typedef enum { - RANGE_OK, - RANGE_NO, - RANGE_ERR -} http_range_status; - -#define http_parse_headers(h, a) _http_parse_headers_ex((h), Z_ARRVAL_P(a), 1, http_info_default_callback, NULL TSRMLS_CC) -#define http_parse_headers_ex(h, ht, p) _http_parse_headers_ex((h), (ht), (p), http_info_default_callback, NULL TSRMLS_CC) -#define http_parse_headers_cb(h, ht, p, f, d) _http_parse_headers_ex((h), (ht), (p), (f), (d) TSRMLS_CC) -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); - -#define http_get_request_headers(h) _http_get_request_headers_ex(Z_ARRVAL_P(h), 1 TSRMLS_CC) -#define http_get_request_headers_ex(h, p) _http_get_request_headers_ex((h), (p) TSRMLS_CC) -PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool prettify TSRMLS_DC); - -typedef char *(*negotiate_func_t)(const char *test, double *quality, HashTable *supported TSRMLS_DC); - -#define http_negotiate_language_func _http_negotiate_language_func -extern char *_http_negotiate_language_func(const char *test, double *quality, HashTable *supported TSRMLS_DC); -#define http_negotiate_charset_func _http_negotiate_charset_func -extern char *_http_negotiate_charset_func(const char *test, double *quality, HashTable *supported TSRMLS_DC); - -#define http_negotiate_language(zsupported) http_negotiate_language_ex(Z_ARRVAL_P(zsupported)) -#define http_negotiate_language_ex(supported) http_negotiate_q("HTTP_ACCEPT_LANGUAGE", (supported), http_negotiate_language_func) -#define http_negotiate_charset(zsupported) http_negotiate_charset_ex(Z_ARRVAL_P(zsupported)) -#define http_negotiate_charset_ex(supported) http_negotiate_q("HTTP_ACCEPT_CHARSET", (supported), http_negotiate_charset_func) -#define http_negotiate_q(e, s, n) _http_negotiate_q((e), (s), (n) TSRMLS_CC) -PHP_HTTP_API HashTable *_http_negotiate_q(const char *header, HashTable *supported, negotiate_func_t neg TSRMLS_DC); - -#define http_get_request_ranges(r, l) _http_get_request_ranges((r), (l) TSRMLS_CC) -PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, size_t length TSRMLS_DC); - -#define http_match_request_header(h, v) http_match_request_header_ex((h), (v), 0) -#define http_match_request_header_ex(h, v, c) _http_match_request_header_ex((h), (v), (c) TSRMLS_CC) -PHP_HTTP_API zend_bool _http_match_request_header_ex(const char *header, const char *value, zend_bool match_case TSRMLS_DC); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_info_api.h b/php_http_info_api.h deleted file mode 100644 index 9dd64c8..0000000 --- a/php_http_info_api.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_INFO_API_H -#define PHP_HTTP_INFO_API_H - -#define IS_HTTP_REQUEST 1 -#define IS_HTTP_RESPONSE 2 - -#define HTTP_INFO(ptr) (ptr)->http.info - -typedef struct { - char *method; - char *URI; -} http_request_info; - -typedef struct { - int code; - char *status; -} http_response_info; - -typedef union { - http_request_info request; - http_response_info response; -} http_info_t; - -struct http_info { - http_info_t info; - double version; -}; - -typedef struct { - struct http_info http; - int type; -} http_info; - -typedef void (*http_info_callback)(void **callback_data, HashTable **headers, http_info *info TSRMLS_DC); - -#define http_info_default_callback _http_info_default_callback -PHP_HTTP_API void _http_info_default_callback(void **nothing, HashTable **headers, http_info *info TSRMLS_DC); -#define http_info_dtor _http_info_dtor -PHP_HTTP_API void _http_info_dtor(http_info *info); -#define http_info_parse(p, i) _http_info_parse_ex((p), (i), 1 TSRMLS_CC) -#define http_info_parse_ex(p, i, s) _http_info_parse_ex((p), (i), (s) TSRMLS_CC) -PHP_HTTP_API STATUS _http_info_parse_ex(const char *pre_header, http_info *info , zend_bool silent TSRMLS_DC); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_message_api.h b/php_http_message_api.h deleted file mode 100644 index 9ba6081..0000000 --- a/php_http_message_api.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_MESSAGE_API_H -#define PHP_HTTP_MESSAGE_API_H - -#include "php_http_info_api.h" -#include "phpstr/phpstr.h" - -typedef enum { - HTTP_MSG_NONE = 0, - HTTP_MSG_REQUEST = IS_HTTP_REQUEST, - HTTP_MSG_RESPONSE = IS_HTTP_RESPONSE, -} http_message_type; - -typedef struct _http_message http_message; - -struct _http_message { - phpstr body; - HashTable hdrs; - http_message_type type; - struct http_info http; - http_message *parent; -}; - -/* required minimum length of an HTTP message "HTTP/1.1" */ -#define HTTP_MSG_MIN_SIZE 8 - -/* shorthand for type checks */ -#define HTTP_MSG_TYPE(TYPE, msg) ((msg) && ((msg)->type == HTTP_MSG_ ##TYPE)) - -#define http_message_new() _http_message_init_ex(NULL, 0) -#define http_message_init(m) _http_message_init_ex((m), 0) -#define http_message_init_ex(m, t) _http_message_init_ex((m), (t)) -PHP_HTTP_API http_message *_http_message_init_ex(http_message *m, http_message_type t); - -#define http_message_set_type(m, t) _http_message_set_type((m), (t)) -PHP_HTTP_API void _http_message_set_type(http_message *m, http_message_type t); - -#define http_message_header(m, h) _http_message_header_ex((m), (h), sizeof(h)) -#define http_message_header_ex _http_message_header_ex -static inline zval *_http_message_header_ex(http_message *msg, char *key_str, size_t key_len) -{ - zval **header; - if (SUCCESS == zend_hash_find(&msg->hdrs, key_str, key_len, (void **) &header)) { - return *header; - } - return NULL; -} - -#define http_message_parse(m, l) http_message_parse_ex(NULL, (m), (l)) -#define http_message_parse_ex(h, m, l) _http_message_parse_ex((h), (m), (l) TSRMLS_CC) -PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t length TSRMLS_DC); - -#define http_message_tostring(m, s, l) _http_message_tostring((m), (s), (l)) -PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length); - -#define http_message_serialize(m, s, l) _http_message_serialize((m), (s), (l)) -PHP_HTTP_API void _http_message_serialize(http_message *message, char **string, size_t *length); - -#define http_message_tostruct_recursive(m, s) _http_message_tostruct_recursive((m), (s) TSRMLS_CC) -PHP_HTTP_API void _http_message_tostruct_recursive(http_message *msg, zval *strct TSRMLS_DC); - -#define http_message_send(m) _http_message_send((m) TSRMLS_CC) -PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC); - -#define http_message_dup(m) _http_message_dup((m) TSRMLS_CC) -PHP_HTTP_API http_message *_http_message_dup(http_message *msg TSRMLS_DC); - -#define http_message_dtor(m) _http_message_dtor((m)) -PHP_HTTP_API void _http_message_dtor(http_message *message); - -#define http_message_free(m) _http_message_free((m)) -PHP_HTTP_API void _http_message_free(http_message **message); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_message_object.h b/php_http_message_object.h deleted file mode 100644 index 1e95c74..0000000 --- a/php_http_message_object.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_MESSAGE_OBJECT_H -#define PHP_HTTP_MESSAGE_OBJECT_H -#ifdef ZEND_ENGINE_2 - -#include "php_http_message_api.h" - -typedef struct { - zend_object zo; - http_message *message; - zend_object_value parent; -} http_message_object; - -extern zend_class_entry *http_message_object_ce; -extern zend_function_entry http_message_object_fe[]; - -#define http_message_object_init() _http_message_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_message_object_init(INIT_FUNC_ARGS); -#define http_message_object_new _http_message_object_new -extern zend_object_value _http_message_object_new(zend_class_entry *ce TSRMLS_DC); -#define http_message_object_new_ex(ce, msg) _http_message_object_new_ex(ce, msg TSRMLS_CC) -#define http_message_object_from_msg(msg) _http_message_object_new_ex(http_message_object_ce, msg TSRMLS_CC) -extern zend_object_value _http_message_object_new_ex(zend_class_entry *ce, http_message *msg TSRMLS_DC); -#define http_message_object_clone(zobj) _http_message_object_clone(zobj TSRMLS_CC) -extern zend_object_value _http_message_object_clone(zval *object TSRMLS_DC); -#define http_message_object_free _http_message_object_free -extern void _http_message_object_free(zend_object *object TSRMLS_DC); - -#define HTTP_MSG_PROPHASH_TYPE 276192743LU -#define HTTP_MSG_PROPHASH_HTTP_VERSION 1138628683LU -#define HTTP_MSG_PROPHASH_BODY 254474387LU -#define HTTP_MSG_PROPHASH_HEADERS 3199929089LU -#define HTTP_MSG_PROPHASH_PARENT_MESSAGE 2105714836LU -#define HTTP_MSG_PROPHASH_REQUEST_METHOD 1669022159LU -#define HTTP_MSG_PROPHASH_REQUEST_URI 3208695486LU -#define HTTP_MSG_PROPHASH_RESPONSE_STATUS 3857097400LU -#define HTTP_MSG_PROPHASH_RESPONSE_CODE 1305615119LU - -#define HTTP_MSG_CHECK_OBJ(obj, dofail) \ - if (!(obj)->message) { \ - http_error(E_WARNING, HTTP_E_MSG, "HttpMessage is empty"); \ - dofail; \ - } -#define HTTP_MSG_CHECK_STD() HTTP_MSG_CHECK_OBJ(obj, RETURN_FALSE) - -#define HTTP_MSG_INIT_OBJ(obj) \ - if (!(obj)->message) { \ - (obj)->message = http_message_new(); \ - } -#define HTTP_MSG_INIT_STD() HTTP_MSG_INIT_OBJ(obj) - -PHP_METHOD(HttpMessage, __construct); -PHP_METHOD(HttpMessage, getBody); -PHP_METHOD(HttpMessage, setBody); -PHP_METHOD(HttpMessage, getHeaders); -PHP_METHOD(HttpMessage, setHeaders); -PHP_METHOD(HttpMessage, addHeaders); -PHP_METHOD(HttpMessage, getType); -PHP_METHOD(HttpMessage, setType); -PHP_METHOD(HttpMessage, getResponseCode); -PHP_METHOD(HttpMessage, setResponseCode); -PHP_METHOD(HttpMessage, getRequestMethod); -PHP_METHOD(HttpMessage, setRequestMethod); -PHP_METHOD(HttpMessage, getRequestUri); -PHP_METHOD(HttpMessage, setRequestUri); -PHP_METHOD(HttpMessage, getHttpVersion); -PHP_METHOD(HttpMessage, setHttpVersion); -PHP_METHOD(HttpMessage, getParentMessage); -PHP_METHOD(HttpMessage, send); -PHP_METHOD(HttpMessage, toString); - -PHP_METHOD(HttpMessage, fromString); - -#endif -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_request_api.h b/php_http_request_api.h deleted file mode 100644 index 3ff2769..0000000 --- a/php_http_request_api.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_REQUEST_API_H -#define PHP_HTTP_REQUEST_API_H -#ifdef HTTP_HAVE_CURL - -#include "php_http_std_defs.h" -#include "php_http_request_method_api.h" - -#include "phpstr/phpstr.h" - -#ifdef PHP_WIN32 -# include -#endif - -#include - -#define http_request_global_init() _http_request_global_init(INIT_FUNC_ARGS_PASSTHRU) -extern STATUS _http_request_global_init(INIT_FUNC_ARGS); -#define http_request_global_cleanup() _http_request_global_cleanup(TSRMLS_C) -extern void _http_request_global_cleanup(TSRMLS_D); - -#define HTTP_REQUEST_BODY_CSTRING 1 -#define HTTP_REQUEST_BODY_CURLPOST 2 -#define HTTP_REQUEST_BODY_UPLOADFILE 3 -typedef struct { - int type; - void *data; - size_t size; -} http_request_body; - -typedef struct { - void ***tsrm_ctx; - void *data; -} http_request_callback_ctx; - -typedef struct { - phpstr *response; - phpstr *request; - curl_infotype last_info; -} http_request_conv; - -#define HTTP_REQUEST_CALLBACK_DATA(from, type, var) \ - http_request_callback_ctx *__CTX = (http_request_callback_ctx *) (from); \ - TSRMLS_FETCH_FROM_CTX(__CTX->tsrm_ctx); \ - type (var) = (type) (__CTX->data) - -#define http_request_callback_data(data) _http_request_callback_data_ex((data), 1 TSRMLS_CC) -#define http_request_callback_data_ex(data, copy) _http_request_callback_data_ex((data), (copy) TSRMLS_CC) -extern http_request_callback_ctx *_http_request_callback_data_ex(void *data, zend_bool cpy TSRMLS_DC); - - -#define COPY_STRING 1 -#define COPY_SLIST 2 -#define COPY_CONTEXT 3 -#define COPY_CONV 4 -#define http_request_data_copy(type, data) _http_request_data_copy((type), (data) TSRMLS_CC) -extern void *_http_request_data_copy(int type, void *data TSRMLS_DC); -#define http_request_data_free_string _http_request_data_free_string -extern void _http_request_data_free_string(void *string); -#define http_request_data_free_slist _http_request_data_free_slist -extern void _http_request_data_free_slist(void *list); -#define http_request_data_free_context _http_request_data_free_context -extern void _http_request_data_free_context(void *context); -#define http_request_data_free_conv _http_request_data_free_conv -extern void _http_request_data_free_conv(void *conv); - -#define http_request_conv(ch, rs, rq) _http_request_conv((ch), (rs), (rq) TSRMLS_CC) -extern void _http_request_conv(CURL *ch, phpstr* response, phpstr *request TSRMLS_DC); - -#define http_request_body_new() _http_request_body_new(TSRMLS_C) -PHP_HTTP_API http_request_body *_http_request_body_new(TSRMLS_D); - -#define http_request_body_fill(b, fields, files) _http_request_body_fill((b), (fields), (files) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_body_fill(http_request_body *body, HashTable *fields, HashTable *files TSRMLS_DC); - -#define http_request_body_dtor(b) _http_request_body_dtor((b) TSRMLS_CC) -PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC); - -#define http_request_body_free(b) _http_request_body_free((b) TSRMLS_CC) -PHP_HTTP_API void _http_request_body_free(http_request_body *body TSRMLS_DC); - -#define http_request_init(ch, meth, url, body, options) _http_request_init((ch), (meth), (url), (body), (options) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_init(CURL *ch, http_request_method meth, char *url, http_request_body *body, HashTable *options TSRMLS_DC); - -#define http_request_exec(ch, i, response, request) _http_request_exec((ch), (i), (response), (request) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_exec(CURL *ch, HashTable *info, phpstr *response, phpstr *request TSRMLS_DC); - -#define http_request_info(ch, i) _http_request_info((ch), (i) TSRMLS_CC) -PHP_HTTP_API void _http_request_info(CURL *ch, HashTable *info TSRMLS_DC); - -#define http_request(meth, url, body, opt, info, resp) _http_request_ex(NULL, (meth), (url), (body), (opt), (info), (resp) TSRMLS_CC) -#define http_request_ex(ch, meth, url, body, opt, info, resp) _http_request_ex((ch), (meth), (url), (body), (opt), (info), (resp) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, char *URL, http_request_body *body, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC); - -#define http_get(u, o, i, r) _http_request_ex(NULL, HTTP_GET, (u), NULL, (o), (i), (r) TSRMLS_CC) -#define http_get_ex(c, u, o, i, r) _http_request_ex((c), HTTP_GET, (u), NULL, (o), (i), (r) TSRMLS_CC) - -#define http_head(u, o, i, r) _http_request_ex(NULL, HTTP_HEAD, (u), NULL, (o), (i), (r) TSRMLS_CC) -#define http_head_ex(c, u, o, i, r) _http_request_ex((c), HTTP_HEAD, (u), NULL, (o), (i), (r) TSRMLS_CC) - -#define http_post(u, b, o, i, r) _http_request_ex(NULL, HTTP_POST, (u), (b), (o), (i), (r) TSRMLS_CC) -#define http_post_ex(c, u, b, o, i, r) _http_request_ex((c), HTTP_POST, (u), (b), (o), (i), (r) TSRMLS_CC) - -#define http_put(u, b, o, i, r) _http_request_ex(NULL, HTTP_PUT, (u), (b), (o), (i), (r) TSRMLS_CC) -#define http_put_ex(c, u, b, o, i, r) _http_request_ex((c), HTTP_PUT, (u), (b), (o), (i), (r) TSRMLS_CC) - -#endif -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_request_method_api.h b/php_http_request_method_api.h deleted file mode 100644 index 362b5dc..0000000 --- a/php_http_request_method_api.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_REQUEST_METHOD_API_H -#define PHP_HTTP_REQUEST_METHOD_API_H - -#include "php_http_std_defs.h" -#include "phpstr/phpstr.h" - -typedef enum { - HTTP_NO_REQUEST_METHOD = 0, - /* HTTP/1.1 */ - HTTP_GET = 1, - HTTP_HEAD = 2, - HTTP_POST = 3, - HTTP_PUT = 4, - HTTP_DELETE = 5, - HTTP_OPTIONS = 6, - HTTP_TRACE = 7, - HTTP_CONNECT = 8, - /* WebDAV - RFC 2518 */ - HTTP_PROPFIND = 9, - HTTP_PROPPATCH = 10, - HTTP_MKCOL = 11, - HTTP_COPY = 12, - HTTP_MOVE = 13, - HTTP_LOCK = 14, - HTTP_UNLOCK = 15, - /* WebDAV Versioning - RFC 3253 */ - HTTP_VERSION_CONTROL = 16, - HTTP_REPORT = 17, - HTTP_CHECKOUT = 18, - HTTP_CHECKIN = 19, - HTTP_UNCHECKOUT = 20, - HTTP_MKWORKSPACE = 21, - HTTP_UPDATE = 22, - HTTP_LABEL = 23, - HTTP_MERGE = 24, - HTTP_BASELINE_CONTROL = 25, - HTTP_MKACTIVITY = 26, - /* WebDAV Access Control - RFC 3744 */ - HTTP_ACL = 27, - HTTP_MAX_REQUEST_METHOD = 28 -} http_request_method; - -#define http_request_method_global_init() _http_request_method_global_init(INIT_FUNC_ARGS_PASSTHRU) -STATUS _http_request_method_global_init(INIT_FUNC_ARGS); - -#define HTTP_STD_REQUEST_METHOD(m) ((m > HTTP_NO_REQUEST_METHOD) && (m < HTTP_MAX_REQUEST_METHOD)) -#define HTTP_CUSTOM_REQUEST_METHOD(m) (m - HTTP_MAX_REQUEST_METHOD) - -#define http_request_method_name(m) _http_request_method_name((m) TSRMLS_CC) -PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC); - -#define http_request_method_exists(u, l, c) _http_request_method_exists((u), (l), (c) TSRMLS_CC) -PHP_HTTP_API unsigned long _http_request_method_exists(zend_bool by_name, unsigned long id, const char *name TSRMLS_DC); - -#define http_request_method_register(m) _http_request_method_register((m) TSRMLS_CC) -PHP_HTTP_API unsigned long _http_request_method_register(const char *method TSRMLS_DC); - -#define http_request_method_unregister(mn) _http_request_method_unregister((mn) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_method_unregister(unsigned long method TSRMLS_DC); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_request_object.h b/php_http_request_object.h deleted file mode 100644 index 6be6718..0000000 --- a/php_http_request_object.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_REQUEST_OBJECT_H -#define PHP_HTTP_REQUEST_OBJECT_H -#ifdef HTTP_HAVE_CURL -#ifdef ZEND_ENGINE_2 - -#ifdef PHP_WIN32 -# include -#endif - -#include - -#include "php_http_request_api.h" -#include "php_http_request_pool_api.h" -#include "phpstr/phpstr.h" - -typedef struct { - zend_object zo; - CURL *ch; - http_request_pool *pool; - phpstr response; - phpstr request; - phpstr history; -} http_request_object; - -extern zend_class_entry *http_request_object_ce; -extern zend_function_entry http_request_object_fe[]; - -#define http_request_object_init() _http_request_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_request_object_init(INIT_FUNC_ARGS); -#define http_request_object_new _http_request_object_new -extern zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC); -#define http_request_object_free _http_request_object_free -extern void _http_request_object_free(zend_object *object TSRMLS_DC); - -#define http_request_object_requesthandler(req, this, body) _http_request_object_requesthandler((req), (this), (body) TSRMLS_CC) -extern STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr, http_request_body *body TSRMLS_DC); -#define http_request_object_responsehandler(req, this) _http_request_object_responsehandler((req), (this) TSRMLS_CC) -extern STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this_ptr TSRMLS_DC); - -PHP_METHOD(HttpRequest, __construct); -PHP_METHOD(HttpRequest, __destruct); -PHP_METHOD(HttpRequest, setOptions); -PHP_METHOD(HttpRequest, getOptions); -PHP_METHOD(HttpRequest, setSslOptions); -PHP_METHOD(HttpRequest, getSslOptions); -PHP_METHOD(HttpRequest, addHeaders); -PHP_METHOD(HttpRequest, getHeaders); -PHP_METHOD(HttpRequest, setHeaders); -PHP_METHOD(HttpRequest, addCookies); -PHP_METHOD(HttpRequest, getCookies); -PHP_METHOD(HttpRequest, setCookies); -PHP_METHOD(HttpRequest, setMethod); -PHP_METHOD(HttpRequest, getMethod); -PHP_METHOD(HttpRequest, setUrl); -PHP_METHOD(HttpRequest, getUrl); -PHP_METHOD(HttpRequest, setContentType); -PHP_METHOD(HttpRequest, getContentType); -PHP_METHOD(HttpRequest, setQueryData); -PHP_METHOD(HttpRequest, getQueryData); -PHP_METHOD(HttpRequest, addQueryData); -PHP_METHOD(HttpRequest, setPostFields); -PHP_METHOD(HttpRequest, getPostFields); -PHP_METHOD(HttpRequest, addPostFields); -PHP_METHOD(HttpRequest, getRawPostData); -PHP_METHOD(HttpRequest, setRawPostData); -PHP_METHOD(HttpRequest, addRawPostData); -PHP_METHOD(HttpRequest, addPostFile); -PHP_METHOD(HttpRequest, setPostFiles); -PHP_METHOD(HttpRequest, getPostFiles); -PHP_METHOD(HttpRequest, setPutFile); -PHP_METHOD(HttpRequest, getPutFile); -PHP_METHOD(HttpRequest, send); -PHP_METHOD(HttpRequest, getResponseData); -PHP_METHOD(HttpRequest, getResponseHeader); -PHP_METHOD(HttpRequest, getResponseCookie); -PHP_METHOD(HttpRequest, getResponseCode); -PHP_METHOD(HttpRequest, getResponseBody); -PHP_METHOD(HttpRequest, getResponseInfo); -PHP_METHOD(HttpRequest, getResponseMessage); -PHP_METHOD(HttpRequest, getRequestMessage); -PHP_METHOD(HttpRequest, getHistory); - -PHP_METHOD(HttpRequest, get); -PHP_METHOD(HttpRequest, head); -PHP_METHOD(HttpRequest, postData); -PHP_METHOD(HttpRequest, postFields); -PHP_METHOD(HttpRequest, putFile); -PHP_METHOD(HttpRequest, putStream); - -PHP_METHOD(HttpRequest, methodRegister); -PHP_METHOD(HttpRequest, methodUnregister); -PHP_METHOD(HttpRequest, methodName); -PHP_METHOD(HttpRequest, methodExists); - -#endif -#endif -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_request_pool_api.h b/php_http_request_pool_api.h deleted file mode 100644 index 9f87005..0000000 --- a/php_http_request_pool_api.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_REQUEST_POOL_API_H -#define PHP_HTTP_REQUEST_POOL_API_H -#ifdef HTTP_HAVE_CURL - -#include "php_http_std_defs.h" -#include "php_http_request_api.h" -#include "phpstr/phpstr.h" - -#ifdef PHP_WIN32 -# include -#endif - -#include - -typedef struct { - CURLM *ch; - zend_llist handles; - zend_llist bodies; - int unfinished; -} http_request_pool; - -#define http_request_pool_responsehandler _http_request_pool_responsehandler -extern void _http_request_pool_responsehandler(zval **req TSRMLS_DC); -#define http_request_pool_requesthandler(r, b) _http_request_pool_requesthandler((r), (b) TSRMLS_CC) -extern STATUS _http_request_pool_requesthandler(zval *request, http_request_body *body TSRMLS_DC); - -#define http_request_pool_init(p) _http_request_pool_init((p) TSRMLS_CC) -PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool TSRMLS_DC); - -#define http_request_pool_attach(p, r) _http_request_pool_attach((p), (r) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *request TSRMLS_DC); - -#define http_request_pool_detach(p, r) _http_request_pool_detach((p), (r) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *request TSRMLS_DC); - -#define http_request_pool_detach_all(p) _http_request_pool_detach_all((p) TSRMLS_CC) -PHP_HTTP_API void _http_request_pool_detach_all(http_request_pool *pool TSRMLS_DC); - -#define http_request_pool_send(p) _http_request_pool_send((p) TSRMLS_CC) -PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool TSRMLS_DC); - -#define http_request_pool_select _http_request_pool_select -PHP_HTTP_API STATUS _http_request_pool_select(http_request_pool *pool); - -#define http_request_pool_perform _http_request_pool_perform -PHP_HTTP_API int _http_request_pool_perform(http_request_pool *pool); - -#define http_request_pool_dtor(p) _http_request_pool_dtor((p) TSRMLS_CC) -PHP_HTTP_API void _http_request_pool_dtor(http_request_pool *pool TSRMLS_DC); - -#endif -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_requestpool_object.h b/php_http_requestpool_object.h deleted file mode 100644 index 24c40e0..0000000 --- a/php_http_requestpool_object.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_REQUESTPOOL_OBJECT_H -#define PHP_HTTP_REQUESTPOOL_OBJECT_H -#ifdef HTTP_HAVE_CURL -#ifdef ZEND_ENGINE_2 - -#ifdef PHP_WIN32 -# include -#endif - -#include - -#include "php_http_request_pool_api.h" - -typedef struct { - zend_object zo; - http_request_pool pool; - struct { - long pos; - } iterator; -} http_requestpool_object; - -extern zend_class_entry *http_requestpool_object_ce; -extern zend_function_entry http_requestpool_object_fe[]; - -#define http_requestpool_object_init() _http_requestpool_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_requestpool_object_init(INIT_FUNC_ARGS); -#define http_requestpool_object_new _http_requestpool_object_new -extern zend_object_value _http_requestpool_object_new(zend_class_entry *ce TSRMLS_DC); -#define http_requestpool_object_free _http_requestpool_object_free -extern void _http_requestpool_object_free(zend_object *object TSRMLS_DC); - -PHP_METHOD(HttpRequestPool, __construct); -PHP_METHOD(HttpRequestPool, __destruct); -PHP_METHOD(HttpRequestPool, attach); -PHP_METHOD(HttpRequestPool, detach); -PHP_METHOD(HttpRequestPool, send); -PHP_METHOD(HttpRequestPool, reset); -PHP_METHOD(HttpRequestPool, socketPerform); -PHP_METHOD(HttpRequestPool, socketSelect); -PHP_METHOD(HttpRequestPool, valid); -PHP_METHOD(HttpRequestPool, current); -PHP_METHOD(HttpRequestPool, key); -PHP_METHOD(HttpRequestPool, next); -PHP_METHOD(HttpRequestPool, rewind); - -#endif -#endif -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_response_object.h b/php_http_response_object.h deleted file mode 100644 index 60a5be0..0000000 --- a/php_http_response_object.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_RESPONSE_OBJECT_H -#define PHP_HTTP_RESPONSE_OBJECT_H -#ifdef ZEND_ENGINE_2 - -#include "missing.h" - -#ifndef WONKY - -extern zend_class_entry *http_response_object_ce; -extern zend_function_entry http_response_object_fe[]; - -#define http_response_object_init() _http_response_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_response_object_init(INIT_FUNC_ARGS); - -PHP_METHOD(HttpResponse, setHeader); -PHP_METHOD(HttpResponse, getHeader); -PHP_METHOD(HttpResponse, setETag); -PHP_METHOD(HttpResponse, getETag); -PHP_METHOD(HttpResponse, setLastModified); -PHP_METHOD(HttpResponse, getLastModified); -PHP_METHOD(HttpResponse, setContentDisposition); -PHP_METHOD(HttpResponse, getContentDisposition); -PHP_METHOD(HttpResponse, setContentType); -PHP_METHOD(HttpResponse, getContentType); -PHP_METHOD(HttpResponse, guessContentType); -PHP_METHOD(HttpResponse, setCache); -PHP_METHOD(HttpResponse, getCache); -PHP_METHOD(HttpResponse, setCacheControl); -PHP_METHOD(HttpResponse, getCacheControl); -PHP_METHOD(HttpResponse, setGzip); -PHP_METHOD(HttpResponse, getGzip); -PHP_METHOD(HttpResponse, setThrottleDelay); -PHP_METHOD(HttpResponse, getThrottleDelay); -PHP_METHOD(HttpResponse, setBufferSize); -PHP_METHOD(HttpResponse, getBufferSize); -PHP_METHOD(HttpResponse, setData); -PHP_METHOD(HttpResponse, getData); -PHP_METHOD(HttpResponse, setFile); -PHP_METHOD(HttpResponse, getFile); -PHP_METHOD(HttpResponse, setStream); -PHP_METHOD(HttpResponse, getStream); -PHP_METHOD(HttpResponse, send); -PHP_METHOD(HttpResponse, capture); -PHP_METHOD(HttpResponse, redirect); -PHP_METHOD(HttpResponse, status); -PHP_METHOD(HttpResponse, getRequestHeaders); -PHP_METHOD(HttpResponse, getRequestBody); - -#endif -#endif -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_send_api.h b/php_http_send_api.h deleted file mode 100644 index 8845afd..0000000 --- a/php_http_send_api.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_SEND_API_H -#define PHP_HTTP_SEND_API_H - -#include "SAPI.h" -#include "php_streams.h" -#include "php_http_std_defs.h" - -typedef enum { - SEND_DATA, - SEND_RSRC -} http_send_mode; - -#define http_send_status(s) sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (s) TSRMLS_CC) -#define http_send_header(n, v, r) _http_send_header_ex((n), strlen(n), (v), strlen(v), (r) TSRMLS_CC) -#define http_send_header_ex(n, nl, v, vl, r, s) _http_send_header_ex((n), (nl), (v), (vl), (r), (s) TSRMLS_CC) -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); -#define http_send_header_string(h) _http_send_status_header_ex(0, (h), 1 TSRMLS_CC) -#define http_send_header_string_ex(h, r) _http_send_status_header_ex(0, (h), (r) TSRMLS_CC) -#define http_send_status_header(s, h) _http_send_status_header_ex((s), (h), 1 TSRMLS_CC) -#define http_send_status_header_ex(s, h, r) _http_send_status_header_ex((s), (h), (r) TSRMLS_CC) -PHP_HTTP_API STATUS _http_send_status_header_ex(int status, const char *header, zend_bool replace TSRMLS_DC); - -#define http_send_last_modified(t) _http_send_last_modified_ex((t), NULL TSRMLS_CC) -#define http_send_last_modified_ex(t, s) _http_send_last_modified_ex((t), (s) TSRMLS_CC) -PHP_HTTP_API STATUS _http_send_last_modified_ex(time_t t, char **sent_header TSRMLS_DC); - -#define http_send_etag(e, l) _http_send_etag_ex((e), (l), NULL TSRMLS_CC) -#define http_send_etag_ex(e, l, s) _http_send_etag_ex((e), (l), (s) TSRMLS_CC) -PHP_HTTP_API STATUS _http_send_etag_ex(const char *etag, size_t etag_len, char **sent_header TSRMLS_DC); - -#define http_send_cache_control(cc, cl) http_send_header_ex("Cache-Control", lenof("Cache-Control"), (cc), (cl), 1, NULL) - -#define http_send_content_type(c, l) _http_send_content_type((c), (l) TSRMLS_CC) -PHP_HTTP_API STATUS _http_send_content_type(const char *content_type, size_t ct_len TSRMLS_DC); - -#define http_send_content_disposition(f, l, i) _http_send_content_disposition((f), (l), (i) TSRMLS_CC) -PHP_HTTP_API STATUS _http_send_content_disposition(const char *filename, size_t f_len, zend_bool send_inline TSRMLS_DC); - -#define http_send_ranges(r, d, s, m) _http_send_ranges((r), (d), (s), (m) TSRMLS_CC) -PHP_HTTP_API STATUS _http_send_ranges(HashTable *ranges, const void *data, size_t size, http_send_mode mode TSRMLS_DC); - -#define http_send_data(d, l) http_send((d), (l), SEND_DATA) -#define http_send_data_ex(d, l, nc) http_send_ex((d), (l), SEND_DATA, (nc)) -#define http_send(d, s, m) _http_send_ex((d), (s), (m), 0 TSRMLS_CC) -#define http_send_ex(d, s, m, nc) _http_send_ex((d), (s), (m), (nc) TSRMLS_CC) -PHP_HTTP_API STATUS _http_send_ex(const void *data, size_t data_size, http_send_mode mode, zend_bool no_cache TSRMLS_DC); - -#define http_send_file(f) http_send_stream_ex(php_stream_open_wrapper(f, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL), 1, 0) -#define http_send_file_ex(f, nc) http_send_stream_ex(php_stream_open_wrapper(f, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL), 1, (nc)) -#define http_send_stream(s) http_send_stream_ex((s), 0, 0) -#define http_send_stream_ex(s, c, nc) _http_send_stream_ex((s), (c), (nc) TSRMLS_CC) -PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *s, zend_bool close_stream, zend_bool no_cache TSRMLS_DC); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_std_defs.h b/php_http_std_defs.h deleted file mode 100644 index ce42260..0000000 --- a/php_http_std_defs.h +++ /dev/null @@ -1,413 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_STD_DEFS_H -#define PHP_HTTP_STD_DEFS_H - -#if defined(PHP_WIN32) -# if defined(HTTP_EXPORTS) -# define PHP_HTTP_API __declspec(dllexport) -# elif defined(COMPILE_DL_HTTP) -# define PHP_HTTP_API __declspec(dllimport) -# else -# define PHP_HTTP_API -# endif -#else -# define PHP_HTTP_API -#endif - -/* make functions that return SUCCESS|FAILURE more obvious */ -typedef int STATUS; - -/* lenof() */ -#define lenof(S) (sizeof(S) - 1) - -#ifndef MIN -# define MIN(a,b) (ab?a:b) -#endif - -/* STR_SET() */ -#ifndef STR_SET -# define STR_SET(STR, SET) \ - { \ - STR_FREE(STR); \ - STR = SET; \ - } -#endif - -#define INIT_ZARR(zv, ht) \ - { \ - INIT_PZVAL(&(zv)); \ - Z_TYPE(zv) = IS_ARRAY; \ - Z_ARRVAL(zv) = (ht); \ - } - -/* return bool (v == SUCCESS) */ -#define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v)) -#define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v)) -/* return object(values) */ -#define RETVAL_OBJECT(o) \ - RETVAL_OBJVAL((o)->value.obj) -#define RETURN_OBJECT(o) \ - RETVAL_OBJECT(o); \ - return -#define RETVAL_OBJVAL(ov) \ - ZVAL_OBJVAL(return_value, ov) -#define RETURN_OBJVAL(ov) \ - RETVAL_OBJVAL(ov); \ - return -#define ZVAL_OBJVAL(zv, ov) \ - (zv)->is_ref = 1; \ - (zv)->type = IS_OBJECT; \ - (zv)->value.obj = (ov); \ - if (Z_OBJ_HT_P(zv)->add_ref) { \ - Z_OBJ_HT_P(zv)->add_ref((zv) TSRMLS_CC); \ - } - -/* function accepts no args */ -#define NO_ARGS \ - if (ZEND_NUM_ARGS()) { \ - zend_error(E_NOTICE, "Wrong parameter count for %s()", get_active_function_name(TSRMLS_C)); \ - } - -/* check if return value is used */ -#define IF_RETVAL_USED \ - if (!return_value_used) { \ - return; \ - } else - -/* CR LF */ -#define HTTP_CRLF "\r\n" - -/* default cache control */ -#define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0" - -/* max URL length */ -#define HTTP_URL_MAXLEN 2048 -#define HTTP_URI_MAXLEN HTTP_URL_MAXLEN - -/* def URL arg separator */ -#define HTTP_URL_ARGSEP "&" -#define HTTP_URI_ARGSEP HTTP_URL_ARGSEP - -/* send buffer size */ -#define HTTP_SENDBUF_SIZE 2097152 - -/* CURL buffer size */ -#define HTTP_CURLBUF_SIZE 16384 - -/* known methods */ -#define HTTP_KNOWN_METHODS \ - /* HTTP 1.1 */ \ - "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, " \ - /* WebDAV - RFC 2518 */ \ - "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, " \ - /* WebDAV Versioning - RFC 3253 */ \ - "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, " \ - "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, " \ - /* WebDAV Access Control - RFC 3744 */ \ - "ACL, " \ - /* END */ - - -#define HTTP_PHP_INI_ENTRY(entry, default, scope, updater, global) \ - STD_PHP_INI_ENTRY(entry, default, scope, updater, global, zend_http_globals, http_globals) -#define HTTP_PHP_INI_ENTRY_EX(entry, default, scope, updater, displayer, global) \ - STD_PHP_INI_ENTRY_EX(entry, default, scope, updater, global, zend_http_globals, http_globals, displayer) - -/* {{{ arrays */ -#define FOREACH_VAL(array, val) FOREACH_HASH_VAL(Z_ARRVAL_P(array), val) -#define FOREACH_HASH_VAL(hash, val) \ - for ( zend_hash_internal_pointer_reset(hash); \ - zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \ - zend_hash_move_forward(hash)) - -#define FOREACH_KEY(array, strkey, numkey) FOREACH_HASH_KEY(Z_ARRVAL_P(array), strkey, numkey) -#define FOREACH_HASH_KEY(hash, strkey, numkey) \ - for ( zend_hash_internal_pointer_reset(hash); \ - zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT; \ - zend_hash_move_forward(hash)) \ - -#define FOREACH_KEYVAL(array, strkey, numkey, val) FOREACH_HASH_KEYVAL(Z_ARRVAL_P(array), strkey, numkey, val) -#define FOREACH_HASH_KEYVAL(hash, strkey, numkey, val) \ - for ( zend_hash_internal_pointer_reset(hash); \ - zend_hash_get_current_key(hash, &strkey, &numkey, 0) != HASH_KEY_NON_EXISTANT && \ - zend_hash_get_current_data(hash, (void **) &val) == SUCCESS; \ - zend_hash_move_forward(hash)) \ - -#define array_copy(src, dst) zend_hash_copy(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)) -#define array_merge(src, dst) zend_hash_merge(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 1) -#define array_append(src, dst) \ - { \ - ulong idx; \ - uint klen; \ - char *key = NULL; \ - zval **data; \ - \ - for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(src)); \ - zend_hash_get_current_key_ex(Z_ARRVAL_P(src), &key, &klen, &idx, 0, NULL) != HASH_KEY_NON_EXISTANT && \ - zend_hash_get_current_data(Z_ARRVAL_P(src), (void **) &data) == SUCCESS; \ - zend_hash_move_forward(Z_ARRVAL_P(src))) \ - { \ - if (key) { \ - zval **tmp; \ - \ - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(dst), key, klen, (void **) &tmp)) { \ - if (Z_TYPE_PP(tmp) != IS_ARRAY) { \ - convert_to_array_ex(tmp); \ - } \ - add_next_index_zval(*tmp, *data); \ - } else { \ - add_assoc_zval(dst, key, *data); \ - } \ - zval_add_ref(data); \ - key = NULL; \ - } \ - } \ - } -/* }}} */ - -#define HTTP_LONG_CONSTANT(name, const) REGISTER_LONG_CONSTANT(name, const, CONST_CS | CONST_PERSISTENT) - -/* {{{ objects & properties */ -#ifdef ZEND_ENGINE_2 - -# define HTTP_STATIC_ME_ALIAS(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - -# define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \ - { \ - zend_class_entry ce; \ - INIT_CLASS_ENTRY(ce, #classname, name## _fe); \ - ce.create_object = name## _new; \ - name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \ - name## _ce->ce_flags |= flags; \ - memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \ - zend_hash_init(& name## _ce->constants_table, 0, NULL, ZVAL_INTERNAL_PTR_DTOR, 1); \ - name## _declare_default_properties(); \ - } - -# define HTTP_REGISTER_CLASS(classname, name, parent, flags) \ - { \ - zend_class_entry ce; \ - INIT_CLASS_ENTRY(ce, #classname, name## _fe); \ - ce.create_object = NULL; \ - name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \ - name## _ce->ce_flags |= flags; \ - } - -# define HTTP_REGISTER_EXCEPTION(classname, cename, parent) \ - { \ - zend_class_entry ce; \ - INIT_CLASS_ENTRY(ce, #classname, NULL); \ - ce.create_object = NULL; \ - cename = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \ - } - -# define getObject(t, o) getObjectEx(t, o, getThis()) -# define getObjectEx(t, o, v) t * o = ((t *) zend_object_store_get_object(v TSRMLS_CC)) -# 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); -# define OBJ_PROP(o) (o)->zo.properties - -# define DCL_STATIC_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC) -# define DCL_STATIC_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC) -# define DCL_STATIC_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a | ZEND_ACC_STATIC) TSRMLS_CC) -# define GET_STATIC_PROP_EX(ce, n) zend_std_get_static_property(ce, (#n), sizeof(#n)-1, 0 TSRMLS_CC) -# define UPD_STATIC_PROP_EX(ce, t, n, v) zend_update_static_property_ ##t(ce, #n, sizeof(#n)-1, (v) TSRMLS_CC) -# define UPD_STATIC_STRL_EX(ce, n, v, l) zend_update_static_property_stringl(ce, #n, sizeof(#n)-1, (v), (l) TSRMLS_CC) -# define SET_STATIC_PROP_EX(ce, n, v) zend_update_static_property(ce, #n, sizeof(#n)-1, v TSRMLS_CC) - -# define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC) -# define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC) -# define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a) TSRMLS_CC) -# define UPD_PROP(o, t, n, v) UPD_PROP_EX(o, getThis(), t, n, v) -# define UPD_PROP_EX(o, this, t, n, v) zend_update_property_ ##t(o->zo.ce, this, (#n), sizeof(#n)-1, (v) TSRMLS_CC) -# define UPD_STRL(o, n, v, l) zend_update_property_stringl(o->zo.ce, getThis(), (#n), sizeof(#n)-1, (v), (l) TSRMLS_CC) -# define SET_PROP(o, n, z) SET_PROP_EX(o, getThis(), n, z) -# define SET_PROP_EX(o, this, n, z) zend_update_property(o->zo.ce, this, (#n), sizeof(#n)-1, (z) TSRMLS_CC) -# define GET_PROP(o, n) GET_PROP_EX(o, getThis(), n) -# define GET_PROP_EX(o, this, n) zend_read_property(o->zo.ce, this, (#n), sizeof(#n)-1, 0 TSRMLS_CC) - -# define DCL_CONST(t, n, v) zend_declare_class_constant_ ##t(ce, (n), sizeof(n)-1, (v) TSRMLS_CC) - -# define ACC_PROP_PRIVATE(ce, flags) ((flags & ZEND_ACC_PRIVATE) && (EG(scope) && ce == EG(scope)) -# define ACC_PROP_PROTECTED(ce, flags) ((flags & ZEND_ACC_PROTECTED) && (zend_check_protected(ce, EG(scope)))) -# define ACC_PROP_PUBLIC(flags) (flags & ZEND_ACC_PUBLIC) -# define ACC_PROP(ce, flags) (ACC_PROP_PUBLIC(flags) || ACC_PROP_PRIVATE(ce, flags) || ACC_PROP_PROTECTED(ce, flags)) - -# define INIT_PARR(o, n) \ - { \ - zval *__tmp; \ - MAKE_STD_ZVAL(__tmp); \ - array_init(__tmp); \ - SET_PROP(o, n, __tmp); \ - } - -# define FREE_PARR(o, p) \ - { \ - zval *__tmp = GET_PROP(o, p); \ - if (__tmp) { \ - zval_ptr_dtor(&__tmp); \ - } \ - } - -# define SET_EH_THROW() SET_EH_THROW_EX(zend_exception_get_default()) -# define SET_EH_THROW_HTTP() SET_EH_THROW_EX(http_exception_get_default()) -# define SET_EH_THROW_EX(ex) php_set_error_handling(EH_THROW, ex TSRMLS_CC) -# define SET_EH_NORMAL() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC) - -#endif /* ZEND_ENGINE_2 */ -/* }}} */ - -#ifndef E_THROW -# define E_THROW 0 -#endif -#ifdef ZEND_ENGINE_2 -# define HE_THROW E_THROW TSRMLS_CC -# define HE_NOTICE (HTTP_G(only_exceptions) ? E_THROW : E_NOTICE) TSRMLS_CC -# define HE_WARNING (HTTP_G(only_exceptions) ? E_THROW : E_WARNING) TSRMLS_CC -# define HE_ERROR (HTTP_G(only_exceptions) ? E_THROW : E_ERROR) TSRMLS_CC -#else -# define HE_THROW E_WARNING TSRMLS_CC -# define HE_NOTICE E_NOTICE TSRMLS_CC -# define HE_WARNING E_WARNING TSRMLS_CC -# define HE_ERROR E_ERROR TSRMLS_CC -#endif - -#define HTTP_E_RUNTIME 1L -#define HTTP_E_INVALID_PARAM 2L -#define HTTP_E_HEADER 3L -#define HTTP_E_MALFORMED_HEADERS 4L -#define HTTP_E_REQUEST_METHOD 5L -#define HTTP_E_MESSAGE_TYPE 6L -#define HTTP_E_ENCODING 7L -#define HTTP_E_REQUEST 8L -#define HTTP_E_REQUEST_POOL 9L -#define HTTP_E_SOCKET 10L -#define HTTP_E_RESPONSE 11L -#define HTTP_E_URL 12L - -#ifdef ZEND_ENGINE_2 -# define HTTP_BEGIN_ARGS_EX(class, method, ret_ref, req_args) static ZEND_BEGIN_ARG_INFO_EX(args_for_ ##class## _ ##method , 0, ret_ref, req_args) -# define HTTP_BEGIN_ARGS_AR(class, method, ret_ref, req_args) static ZEND_BEGIN_ARG_INFO_EX(args_for_ ##class## _ ##method , 1, ret_ref, req_args) -# define HTTP_END_ARGS } -# define HTTP_EMPTY_ARGS_EX(class, method, ret_ref) HTTP_BEGIN_ARGS_EX(class, method, ret_ref, 0) HTTP_END_ARGS -# define HTTP_ARGS(class, method) args_for_ ##class## _ ##method -# define HTTP_ARG_VAL(name, pass_ref) ZEND_ARG_INFO(pass_ref, name) -# define HTTP_ARG_OBJ(class, name, allow_null) ZEND_ARG_OBJ_INFO(0, name, class, allow_null) -#endif - -#ifdef ZEND_ENGINE_2 -# define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL, 0, 0} -#else -# define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL} -#endif - -#ifdef HTTP_HAVE_CURL -# ifdef ZEND_ENGINE_2 -# define HTTP_DECLARE_ARG_PASS_INFO() \ - static \ - ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_3, 0) \ - ZEND_ARG_PASS_INFO(0) \ - ZEND_ARG_PASS_INFO(0) \ - ZEND_ARG_PASS_INFO(1) \ - ZEND_END_ARG_INFO(); \ - \ - static \ - ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_4, 0) \ - ZEND_ARG_PASS_INFO(0) \ - ZEND_ARG_PASS_INFO(0) \ - ZEND_ARG_PASS_INFO(0) \ - ZEND_ARG_PASS_INFO(1) \ - ZEND_END_ARG_INFO(); \ - \ - static \ - ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_5, 0) \ - ZEND_ARG_PASS_INFO(0) \ - ZEND_ARG_PASS_INFO(0) \ - ZEND_ARG_PASS_INFO(0) \ - ZEND_ARG_PASS_INFO(0) \ - ZEND_ARG_PASS_INFO(1) \ - ZEND_END_ARG_INFO(); - -# else -# define HTTP_DECLARE_ARG_PASS_INFO() \ - static unsigned char http_arg_pass_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \ - static unsigned char http_arg_pass_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \ - static unsigned char http_arg_pass_ref_5[] = {5, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; -# endif /* ZEND_ENGINE_2 */ -#else -# define HTTP_DECLARE_ARG_PASS_INFO() -#endif /* HTTP_HAVE_CURL */ - - -#ifndef TSRMLS_FETCH_FROM_CTX -# ifdef ZTS -# define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx -# else -# define TSRMLS_FETCH_FROM_CTX(ctx) -# endif -#endif - -#ifndef TSRMLS_SET_CTX -# ifdef ZTS -# define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_ls -# else -# define TSRMLS_SET_CTX(ctx) -# endif -#endif - -#ifndef ZVAL_ZVAL -#define ZVAL_ZVAL(z, zv, copy, dtor) { \ - int is_ref, refcount; \ - is_ref = (z)->is_ref; \ - refcount = (z)->refcount; \ - *(z) = *(zv); \ - if (copy) { \ - zval_copy_ctor(z); \ - } \ - if (dtor) { \ - if (!copy) { \ - ZVAL_NULL(zv); \ - } \ - zval_ptr_dtor(&zv); \ - } \ - (z)->is_ref = is_ref; \ - (z)->refcount = refcount; \ - } -#endif -#ifndef RETVAL_ZVAL -#define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor) -#endif -#ifndef RETURN_ZVAL -#define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; } -#endif - - -#endif /* PHP_HTTP_STD_DEFS_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_url_api.h b/php_http_url_api.h deleted file mode 100644 index 878afff..0000000 --- a/php_http_url_api.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_URL_API_H -#define PHP_HTTP_URL_API_H - -#include "php_http_std_defs.h" - -#define http_absolute_uri(url) http_absolute_url(url) -#define http_absolute_uri_ex(url, url_len, proto, proto_len, host, host_len, port) _http_absolute_url_ex((url), (url_len), (proto), (proto_len), (host), (host_len), (port) TSRMLS_CC) -#define http_absolute_url(url) http_absolute_url_ex((url), strlen(url), NULL, 0, NULL, 0, 0) -#define http_absolute_url_ex(url, url_len, proto, proto_len, host, host_len, port) _http_absolute_url_ex((url), (url_len), (proto), (proto_len), (host), (host_len), (port) TSRMLS_CC) -PHP_HTTP_API char *_http_absolute_url_ex(const char *url, size_t url_len, const char *proto, size_t proto_len, const char *host, size_t host_len, unsigned port TSRMLS_DC); - -#define http_urlencode_hash(h, q) _http_urlencode_hash_ex((h), 1, NULL, 0, (q), NULL TSRMLS_CC) -#define http_urlencode_hash_ex(h, o, p, pl, q, ql) _http_urlencode_hash_ex((h), (o), (p), (pl), (q), (ql) TSRMLS_CC) -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); - -#define http_urlencode_hash_implementation(ht, formstr, argsep) \ - http_urlencode_hash_implementation_ex((ht), (formstr), (argsep), NULL, 0, NULL, 0, NULL, 0, NULL) -#define http_urlencode_hash_implementation_ex(ht, formstr, argsep, np, npl, kp, kpl, ks, ksl, type) \ - _http_urlencode_hash_implementation_ex((ht), (formstr), (argsep), (np), (npl), (kp), (kpl), (ks), (ksl), (type) TSRMLS_CC) -PHP_HTTP_API STATUS _http_urlencode_hash_implementation_ex( - HashTable *ht, phpstr *formstr, char *arg_sep, - const char *num_prefix, int num_prefix_len, - const char *key_prefix, int key_prefix_len, - const char *key_suffix, int key_suffix_len, - zval *type TSRMLS_DC); - - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/php_http_util_object.h b/php_http_util_object.h deleted file mode 100644 index d50850e..0000000 --- a/php_http_util_object.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HTTP_UTIL_OBJECT_H -#define PHP_HTTP_UTIL_OBJECT_H -#ifdef ZEND_ENGINE_2 - -extern zend_class_entry *http_util_object_ce; -extern zend_function_entry http_util_object_fe[]; - -#define http_util_object_init() _http_util_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_util_object_init(INIT_FUNC_ARGS); - -PHP_METHOD(HttpUtil, date); -PHP_METHOD(HttpUtil, absoluteUri); -PHP_METHOD(HttpUtil, negotiateLanguage); -PHP_METHOD(HttpUtil, negotiateCharset); -PHP_METHOD(HttpUtil, matchModified); -PHP_METHOD(HttpUtil, matchEtag); -PHP_METHOD(HttpUtil, chunkedDecode); -PHP_METHOD(HttpUtil, parseHeaders); -PHP_METHOD(HttpUtil, parseMessage); - -#endif -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ - diff --git a/phpstr/phpstr.c b/phpstr/phpstr.c deleted file mode 100644 index 70673a9..0000000 --- a/phpstr/phpstr.c +++ /dev/null @@ -1,256 +0,0 @@ - -/* $Id$ */ - -#include "php.h" -#include "phpstr.h" - -PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, zend_bool pre_alloc) -{ - if (!buf) { - buf = emalloc(sizeof(phpstr)); - } - - buf->size = chunk_size > 0 ? chunk_size : PHPSTR_DEFAULT_SIZE; - buf->data = pre_alloc ? emalloc(buf->size) : NULL; - buf->free = pre_alloc ? buf->size : 0; - buf->used = 0; - - return buf; -} - -PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, const char *string, size_t length) -{ - buf = phpstr_init(buf); - phpstr_append(buf, string, length); - return buf; -} - -PHPSTR_API void phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size) -{ - if (buf->free < len) { - size_t size = override_size ? override_size : buf->size; - while ((size + buf->free) < len) { - size *= 2; - } - if (buf->data) { - buf->data = erealloc(buf->data, buf->used + buf->free + size); - } else { - buf->data = emalloc(size); - } - buf->free += size; - } -} - -PHPSTR_API size_t phpstr_append(phpstr *buf, const char *append, size_t append_len) -{ - phpstr_resize(buf, append_len); - memcpy(buf->data + buf->used, append, append_len); - buf->used += append_len; - buf->free -= append_len; - return append_len; -} - -PHPSTR_API size_t phpstr_appendf(phpstr *buf, const char *format, ...) -{ - va_list argv; - char *append; - size_t append_len; - - va_start(argv, format); - append_len = vspprintf(&append, 0, format, argv); - va_end(argv); - - phpstr_append(buf, append, append_len); - efree(append); - - return append_len; -} - -PHPSTR_API size_t phpstr_insert(phpstr *buf, const char *insert, size_t insert_len, size_t offset) -{ - phpstr_resize(buf, insert_len); - memmove(buf->data + offset + insert_len, buf->data + offset, insert_len); - memcpy(buf->data + offset, insert, insert_len); - buf->used += insert_len; - buf->free -= insert_len; - return insert_len; -} - -PHPSTR_API size_t phpstr_insertf(phpstr *buf, size_t offset, const char *format, ...) -{ - va_list argv; - char *insert; - size_t insert_len; - - va_start(argv, format); - insert_len = vspprintf(&insert, 0, format, argv); - va_end(argv); - - phpstr_insert(buf, insert, insert_len, offset); - efree(insert); - - return insert_len; -} - -PHPSTR_API size_t phpstr_prepend(phpstr *buf, const char *prepend, size_t prepend_len) -{ - phpstr_resize(buf, prepend_len); - memmove(buf->data + prepend_len, buf->data, buf->used); - memcpy(buf->data, prepend, prepend_len); - buf->used += prepend_len; - buf->free -= prepend_len; - return prepend_len; -} - -PHPSTR_API size_t phpstr_prependf(phpstr *buf, const char *format, ...) -{ - va_list argv; - char *prepend; - size_t prepend_len; - - va_start(argv, format); - prepend_len = vspprintf(&prepend, 0, format, argv); - va_end(argv); - - phpstr_prepend(buf, prepend, prepend_len); - efree(prepend); - - return prepend_len; -} - -PHPSTR_API char *phpstr_data(const phpstr *buf, char **into, size_t *len) -{ - char *copy = ecalloc(1, buf->used + 1); - memcpy(copy, buf->data, buf->used); - if (into) { - *into = copy; - } - if (len) { - *len = buf->used; - } - return copy; -} - -PHPSTR_API phpstr *phpstr_dup(const phpstr *buf) -{ - phpstr *dup = phpstr_clone(buf); - phpstr_append(dup, buf->data, buf->used); - return dup; -} - -PHPSTR_API size_t phpstr_cut(phpstr *buf, size_t offset, size_t length) -{ - if (offset >= buf->used) { - return 0; - } - if (offset + length > buf->used) { - length = buf->used - offset; - } - memmove(buf->data + offset, buf->data + offset + length, buf->used - length); - buf->used -= length; - buf->free += length; - return length; -} - -PHPSTR_API phpstr *phpstr_sub(const phpstr *buf, size_t offset, size_t length) -{ - if (offset >= buf->used) { - return NULL; - } else { - size_t need = (length + offset) > buf->used ? (buf->used - offset) : (length - offset); - phpstr *sub = phpstr_init_ex(NULL, need, 1); - phpstr_append(sub, buf->data + offset, need); - sub->size = buf->size; - return sub; - } -} - -PHPSTR_API phpstr *phpstr_right(const phpstr *buf, size_t length) -{ - if (length < buf->used) { - return phpstr_sub(buf, buf->used - length, length); - } else { - return phpstr_sub(buf, 0, buf->used); - } -} - - -PHPSTR_API phpstr *phpstr_merge_va(phpstr *buf, unsigned argc, va_list argv) -{ - unsigned i = 0; - buf = phpstr_init(buf); - - while (argc > i++) { - phpstr_free_t f = va_arg(argv, phpstr_free_t); - phpstr *current = va_arg(argv, phpstr *); - phpstr_append(buf, current->data, current->used); - FREE_PHPSTR(f, current); - } - - return buf; -} - -PHPSTR_API phpstr *phpstr_merge_ex(phpstr *buf, unsigned argc, ...) -{ - va_list argv; - phpstr *ret; - - va_start(argv, argc); - ret = phpstr_merge_va(buf, argc, argv); - va_end(argv); - return ret; -} - -PHPSTR_API phpstr *phpstr_merge(unsigned argc, ...) -{ - va_list argv; - phpstr *ret; - - va_start(argv, argc); - ret = phpstr_merge_va(NULL, argc, argv); - va_end(argv); - return ret; -} - -PHPSTR_API void phpstr_fix(phpstr *buf) -{ - phpstr_resize_ex(buf, 1, 1); - buf->data[buf->used] = '\0'; -} - -PHPSTR_API int phpstr_cmp(phpstr *left, phpstr *right) -{ - if (left->used > right->used) { - return -1; - } else if (right->used > left->used) { - return 1; - } else { - return memcmp(left->data, right->data, left->used); - } -} - -PHPSTR_API void phpstr_dtor(phpstr *buf) -{ - STR_SET(buf->data, NULL); - buf->used = 0; - buf->free = 0; -} - -PHPSTR_API void phpstr_free(phpstr **buf) -{ - if (*buf) { - phpstr_dtor(*buf); - efree(*buf); - *buf = NULL; - } -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ - diff --git a/phpstr/phpstr.h b/phpstr/phpstr.h deleted file mode 100644 index 5b2ee56..0000000 --- a/phpstr/phpstr.h +++ /dev/null @@ -1,168 +0,0 @@ - -/* $Id$ */ - -#ifndef _PHPSTR_H_ -#define _PHPSTR_H_ - -#include "php.h" - -#ifndef PHPSTR_DEFAULT_SIZE -# define PHPSTR_DEFAULT_SIZE 256 -#endif - -#ifndef STR_SET -# define STR_SET(STR, SET) \ - { \ - STR_FREE(STR); \ - STR = SET; \ - } -#endif - -#if defined(PHP_WIN32) -# if defined(PHPSTR_EXPORTS) -# define PHPSTR_API __declspec(dllexport) -# elif defined(COMPILE_DL_PHPSTR) -# define PHPSTR_API __declspec(dllimport) -# else -# define PHPSTR_API -# endif -#else -# define PHPSTR_API -#endif - -#define PHPSTR(p) ((phpstr *) (p)) -#define PHPSTR_VAL(p) (PHPSTR(p))->data -#define PHPSTR_LEN(p) (PHPSTR(p))->used - -#define FREE_PHPSTR_PTR(STR) efree(STR) -#define FREE_PHPSTR_VAL(STR) phpstr_dtor(STR) -#define FREE_PHPSTR_ALL(STR) phpstr_free(&(STR)) -#define FREE_PHPSTR(free, STR) \ - switch (free) \ - { \ - case PHPSTR_FREE_NOT: break; \ - case PHPSTR_FREE_PTR: efree(STR); break; \ - case PHPSTR_FREE_VAL: phpstr_dtor(STR); break; \ - case PHPSTR_FREE_ALL: \ - { \ - phpstr *PTR = (STR); \ - phpstr_free(&PTR); \ - } \ - break; \ - default: break; \ - } - -#define RETURN_PHPSTR_PTR(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_PTR, 0) -#define RETURN_PHPSTR_VAL(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_NOT, 0) -#define RETVAL_PHPSTR_PTR(STR) RETVAL_PHPSTR((STR), PHPSTR_FREE_PTR, 0) -#define RETVAL_PHPSTR_VAL(STR) RETVAL_PHPSTR((STR), PHPSTR_FREE_NOT, 0) -/* RETURN_PHPSTR(buf, PHPSTR_FREE_PTR, 0) */ -#define RETURN_PHPSTR(STR, free, dup) \ - RETVAL_PHPSTR((STR), (free), (dup)); \ - return; - -#define RETVAL_PHPSTR(STR, free, dup) \ - phpstr_fix(STR); \ - RETVAL_STRINGL((STR)->data, (STR)->used, (dup)); \ - FREE_PHPSTR((free), (STR)); - -typedef struct { - size_t size; - char *data; - size_t used; - size_t free; -} phpstr; - -typedef enum { - PHPSTR_FREE_NOT = 0, - PHPSTR_FREE_PTR, /* efree() */ - PHPSTR_FREE_VAL, /* phpstr_dtor() */ - PHPSTR_FREE_ALL /* phpstr_free() */ -} phpstr_free_t; - -#define PHPSTR_ALL_FREE(STR) PHPSTR_FREE_ALL,(STR) -#define PHPSTR_PTR_FREE(STR) PHPSTR_FREE_PTR,(STR) -#define PHPSTR_VAL_FREE(STR) PHPSTR_FREE_VAL,(STR) -#define PHPSTR_NOT_FREE(STR) PHPSTR_FREE_NOT,(STR) - -/* create a new phpstr */ -#define phpstr_new() phpstr_init(NULL) -#define phpstr_init(b) phpstr_init_ex(b, 0, 0) -#define phpstr_clone(phpstr_pointer) phpstr_init_ex(NULL, (phpstr_pointer)->size, 0) -PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, zend_bool pre_alloc); - -/* create a phpstr from a zval or c-string */ -#define phpstr_from_zval(z) phpstr_from_string(Z_STRVAL(z), Z_STRLEN(z)) -#define phpstr_from_zval_ex(b, z) phpstr_from_string_ex(b, Z_STRVAL(z), Z_STRLEN(z)) -#define phpstr_from_string(s, l) phpstr_from_string_ex(NULL, (s), (l)) -PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, const char *string, size_t length); - -/* usually only called from within the internal functions */ -#define phpstr_resize(b, s) phpstr_resize_ex((b), (s), 0) -PHPSTR_API void phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size); - -/* append data to the phpstr */ -#define phpstr_appends(b, a) phpstr_append((b), (a), sizeof(a)-1) -#define phpstr_appendl(b, a) phpstr_append((b), (a), strlen(a)) -PHPSTR_API size_t phpstr_append(phpstr *buf, const char *append, size_t append_len); -PHPSTR_API size_t phpstr_appendf(phpstr *buf, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); - -/* insert data at a specific position of the phpstr */ -#define phpstr_inserts(b, i, o) phpstr_insert((b), (i), sizeof(i)-1, (o)) -#define phpstr_insertl(b, i, o) phpstr_insert((b), (i), strlen(i), (o)) -PHPSTR_API size_t phpstr_insert(phpstr *buf, const char *insert, size_t insert_len, size_t offset); -PHPSTR_API size_t phpstr_insertf(phpstr *buf, size_t offset, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); - -/* prepend data */ -#define phpstr_prepends(b, p) phpstr_prepend((b), (p), sizeof(p)-1) -#define phpstr_prependl(b, p) phpstr_prepend((b), (p), strlen(p)) -PHPSTR_API size_t phpstr_prepend(phpstr *buf, const char *prepend, size_t prepend_len); -PHPSTR_API size_t phpstr_prependf(phpstr *buf, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); - -/* get a zero-terminated string */ -PHPSTR_API char *phpstr_data(const phpstr *buf, char **into, size_t *len); - -/* get a part of the phpstr */ -#define phpstr_mid(b, o, l) phpstr_sub((b), (o), (l)) -#define phpstr_left(b, l) phpstr_sub((b), 0, (l)) -PHPSTR_API phpstr *phpstr_right(const phpstr *buf, size_t length); -PHPSTR_API phpstr *phpstr_sub(const phpstr *buf, size_t offset, size_t len); - -/* remove a substring */ -PHPSTR_API size_t phpstr_cut(phpstr *buf, size_t offset, size_t length); - -/* get a complete phpstr duplicate */ -PHPSTR_API phpstr *phpstr_dup(const phpstr *buf); - -/* merge several phpstr objects - use like: - - phpstr *final = phpstr_merge(3, - PHPSTR_NOT_FREE(&keep), - PHPSTR_ALL_FREE(middle_ptr), - PHPSTR_VAL_FREE(&local); -*/ -PHPSTR_API phpstr *phpstr_merge(unsigned argc, ...); -PHPSTR_API phpstr *phpstr_merge_ex(phpstr *buf, unsigned argc, ...); -PHPSTR_API phpstr *phpstr_merge_va(phpstr *buf, unsigned argc, va_list argv); - -/* sets a trailing NUL byte */ -PHPSTR_API void phpstr_fix(phpstr *buf); - -/* free a phpstr objects contents */ -PHPSTR_API void phpstr_dtor(phpstr *buf); - -/* free a phpstr object completely */ -PHPSTR_API void phpstr_free(phpstr **buf); - -#endif - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/rebuild b/rebuild deleted file mode 100755 index 2506a9b..0000000 --- a/rebuild +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -rm -f warnings - -echo -n "executing phpize... " -phpize 2>&1 >/dev/null -if test $? -ne 0 ; then - echo "FAILED!" - exit 1 -fi -echo "DONE" - -echo -n "configuring... " -CFLAGS="-W -Wchar-subscripts -Wformat=2 -Wno-format-y2k -Wimplicit -Wmissing-braces -Wunused-variable -Wbad-function-cast -Wpointer-arith -Wsign-compare -Winline" \ - ./configure $@ >/dev/null -if test $? -ne 0 ; then - echo "FAILED!" - exit 1 -fi -echo "DONE" - -echo -n "building... " -make clean install 2>warnings >/dev/null -if test $? -ne 0 ; then - echo "FAILED!" -else - echo "DONE" -fi - -if test -s warnings; then - cat warnings -fi - diff --git a/tests/HttpMessage_001.phpt b/tests/HttpMessage_001.phpt deleted file mode 100644 index 00e0e4b..0000000 --- a/tests/HttpMessage_001.phpt +++ /dev/null @@ -1,52 +0,0 @@ ---TEST-- -HttpMessage ---SKIPIF-- - ---FILE-- -getBody()); -var_dump($m->toString(true)); -var_dump(HttpMessage::fromString($m->toString(true))->toString(true)); -?> ---EXPECTF-- -%sTEST -string(1) "X" -string(134) "HTTP/1.1 301 -Location: /anywhere -HTTP/1.1 302 -Location: /somwhere -HTTP/1.1 206 -Content-Range: bytes=2-3 -Content-Length: 1 - -X -" -string(134) "HTTP/1.1 301 -Location: /anywhere -HTTP/1.1 302 -Location: /somwhere -HTTP/1.1 206 -Content-Range: bytes=2-3 -Content-Length: 1 - -X -" - diff --git a/tests/HttpRequestPool_001.phpt b/tests/HttpRequestPool_001.phpt deleted file mode 100644 index d8bff6e..0000000 --- a/tests/HttpRequestPool_001.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -HttpRequestPool ---SKIPIF-- - ---FILE-- -addPostFields(array('a'=>1,'b'=>2)) ; -$pool->send(); -foreach ($pool as $req) { - echo $req->getUrl(), '=', - $req->getResponseCode(), ':', - $req->getResponseMessage()->getResponseCode(), "\n"; -} -echo "Done\n"; -?> ---EXPECTF-- -%sTEST -http://www.php.net/=200:200 -http://pear.php.net/=200:200 -http://pecl.php.net/=200:200 -http://dev.iworks.at/.print_request.php=200:200 -Done diff --git a/tests/HttpRequest_001.phpt b/tests/HttpRequest_001.phpt deleted file mode 100644 index 27cd1a0..0000000 --- a/tests/HttpRequest_001.phpt +++ /dev/null @@ -1,52 +0,0 @@ ---TEST-- -HttpRequest options ---SKIPIF-- - ---FILE-- -setOptions(array('redirect'=>11, 'headers'=>array('X-Foo'=>'Bar'))); -$r2->setOptions(array('redirect'=>99, 'headers'=>array('X-Bar'=>'Foo'))); -$o1 = $r1->getOptions(); -$o2 = $r2->getOptions(); -$r1->setOptions($o2); -$r2->setOptions($o1); -print_r(array($o1, $o2)); -var_dump(serialize($r1->getOptions()) === serialize($r2->getOptions())); -$r1 = null; -$r2 = null; -?> ---EXPECTF-- -%sTEST -Array -( - [0] => Array - ( - [redirect] => 11 - [headers] => Array - ( - [X-Foo] => Bar - [X-Bar] => Foo - ) - - ) - - [1] => Array - ( - [redirect] => 99 - [headers] => Array - ( - [X-Bar] => Foo - [X-Foo] => Bar - ) - - ) - -) -bool(false) diff --git a/tests/HttpRequest_002.phpt b/tests/HttpRequest_002.phpt deleted file mode 100644 index 76e12a3..0000000 --- a/tests/HttpRequest_002.phpt +++ /dev/null @@ -1,80 +0,0 @@ ---TEST-- -HttpRequest GET/POST ---SKIPIF-- - ---FILE-- -send(); -print_r($r->getResponseInfo()); - -$r = new HttpRequest('http://dev.iworks.at/.print_request.php', HTTP_METH_POST); -$r->addCookies(array('MyCookie' => 'foobar')); -$r->addQueryData(array('gq'=>'foobar','gi'=>10)); -$r->addPostFields(array('pq'=>'foobar','pi'=>10)); -$r->addPostFile('upload', dirname(__FILE__).'/data.txt', 'text/plain'); -$r->send(); -echo $r->getResponseBody(); -var_dump($r->getResponseMessage()->getResponseCode()); - -echo "Done"; -?> ---EXPECTF-- -%sTEST -Array -( - [effective_url] => http://www.google.com/ - [response_code] => %d - [http_connectcode] => %d - [filetime] => %s - [total_time] => %f - [namelookup_time] => %f - [connect_time] => %f - [pretransfer_time] => %f - [starttransfer_time] => %f - [redirect_time] => %f - [redirect_count] => %f - [size_upload] => %f - [size_download] => %d - [speed_download] => %d - [speed_upload] => %d - [header_size] => %d - [request_size] => %d - [ssl_verifyresult] => %d - [content_length_download] => %d - [content_length_upload] => %d - [content_type] => %s - [httpauth_avail] => %d - [proxyauth_avail] => %s -) -Array -( - [gq] => foobar - [gi] => 10 - [pq] => foobar - [pi] => 10 - [MyCookie] => foobar -) -Array -( - [upload] => Array - ( - [name] => data.txt - [type] => text/plain - [tmp_name] => %s - [error] => 0 - [size] => 1010 - ) - -) - -int(200) -Done diff --git a/tests/HttpRequest_003.phpt b/tests/HttpRequest_003.phpt deleted file mode 100644 index 32b134c..0000000 --- a/tests/HttpRequest_003.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -HttpRequest SSL ---SKIPIF-- - ---FILE-- -send(); -var_dump($r->getResponseBody()); -?> ---EXPECTF-- -%sTEST -string(10) "1234567890" - diff --git a/tests/HttpResponse_001.phpt b/tests/HttpResponse_001.phpt deleted file mode 100644 index 78b03e4..0000000 --- a/tests/HttpResponse_001.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -HttpResponse - send data with caching headers ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -X-Powered-By: PHP/%s -ETag: "3858f62230ac3c915f300c664312c63f" -Cache-Control: public, must-revalidate, max_age=3600 -Last-Modified: %s, %d %s 20%d %d:%d:%d GMT -Content-Type: %s -Accept-Ranges: bytes -Content-Length: 6 - -foobar \ No newline at end of file diff --git a/tests/HttpResponse_002.phpt b/tests/HttpResponse_002.phpt deleted file mode 100644 index 1c69a7f..0000000 --- a/tests/HttpResponse_002.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -HttpResponse - send gzipped file ---SKIPIF-- - ---ENV-- -HTTP_ACCEPT_ENCODING=gzip ---FILE-- - ---EXPECTF-- -X-Powered-By: PHP/%s -Content-Type: %s -Accept-Ranges: bytes -Content-Encoding: gzip -Vary: Accept-Encoding - -%s diff --git a/tests/INI_001.phpt b/tests/INI_001.phpt deleted file mode 100644 index 9210aad..0000000 --- a/tests/INI_001.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -INI entries ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -%sTEST -string(9) "cache.log" -string(15) "POST, HEAD, GET" -string(1) "1" -Done - diff --git a/tests/abs_uri_001.phpt b/tests/abs_uri_001.phpt deleted file mode 100644 index e76191e..0000000 --- a/tests/abs_uri_001.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -http_absolute_uri() with relative paths ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -%sTEST -http://localhost/page -http://localhost/with/some/path/ - diff --git a/tests/abs_uri_002.phpt b/tests/abs_uri_002.phpt deleted file mode 100644 index 47f796b..0000000 --- a/tests/abs_uri_002.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -http_absolute_uri() with proto ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -%sTEST -https://localhost/sec -ftp://localhost/pub -http://localhost/ - diff --git a/tests/allowed_methods_001.phpt b/tests/allowed_methods_001.phpt deleted file mode 100644 index f0b7d9c..0000000 --- a/tests/allowed_methods_001.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -allowed methods ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -Status: 405 -Content-type: %s -X-Powered-By: PHP/%s -Allow: POST - diff --git a/tests/allowed_methods_001_logging.phpt b/tests/allowed_methods_001_logging.phpt deleted file mode 100644 index a9355aa..0000000 --- a/tests/allowed_methods_001_logging.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -logging allowed methods ---SKIPIF-- -include 'skip.inc'; -checkcgi(); ---ENV-- -HTTP_HOST=example.com ---FILE-- - ---EXPECTF-- -%sTEST -%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d [405-ALLOWED] Allow: POST <%s> -Done diff --git a/tests/bug_34191.phpt b/tests/bug_34191.phpt deleted file mode 100644 index 65c2b89a7d7658dbf585a198960e4a8316336345..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 397 zcmY*U%TB^T6eZ%qOfui#1Y=qk1Hs3_`XE>bs2XfwLRgp(7_Myt&P>`tg@r%hkN7Vx z{0u(>+bW88b#BD**Q3@9#=7V<1*C ziF7$d)(J);1TlGp*gh&(_f}X0k^Kwc+1S=%8jY-ss-0)rtli6mTb%oYy6ZBZ4_Mp1 zz4Y46vtSXWW|TI(8@A@&GDdeG(Ml%ZI0=|$x@YH}|3_k|%`Are0T7`grF*6BWa-bm z?=zR@$@)8=7;V3974j-xy?=aer0sH9EWE+~%jOq4j&vIU diff --git a/tests/chunked_decode_001.phpt b/tests/chunked_decode_001.phpt deleted file mode 100644 index 2575704..0000000 --- a/tests/chunked_decode_001.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -http_chunked_decode() "\r\n" ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -%sTEST -string(12) "abra -cadabra" - diff --git a/tests/chunked_decode_002.phpt b/tests/chunked_decode_002.phpt deleted file mode 100644 index 8221ee8..0000000 --- a/tests/chunked_decode_002.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -http_chunked_decode() "\n" ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -%sTEST -string(12) "abra -cadabra" - diff --git a/tests/data.txt b/tests/data.txt deleted file mode 100644 index 2426113..0000000 --- a/tests/data.txt +++ /dev/null @@ -1,10 +0,0 @@ -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 diff --git a/tests/date_001.phpt b/tests/date_001.phpt deleted file mode 100644 index 7964be7..0000000 --- a/tests/date_001.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -http_date() with timestamp ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -%sTEST -Thu, 01 Jan 1970 00:00:01 GMT -Fri, 13 Feb 2009 23:31:30 GMT - diff --git a/tests/date_002.phpt b/tests/date_002.phpt deleted file mode 100644 index 522d0e2..0000000 --- a/tests/date_002.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -http_date() without timestamp ---SKIPIF-- - ---INI-- -date.timezone=GMT ---FILE-- - 1); -echo "$t\n$d\nDone\n"; -?> ---EXPECTF-- -%sTEST -bool(true) -%d -%s, %d %s %d %d:%d:%d GMT -Done diff --git a/tests/get_request_data_001.phpt b/tests/get_request_data_001.phpt deleted file mode 100644 index 4d15265..0000000 --- a/tests/get_request_data_001.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -get request data ---SKIPIF-- - ---ENV-- -HTTP_ACCEPT_CHARSET=iso-8859-1, * -HTTP_ACCEPT_ENCODING=none -HTTP_USER_AGENT=Mozilla/5.0 -HTTP_HOST=localhost ---POST-- -a=b&c=d ---FILE-- - -===DONE=== ---EXPECTF-- -%sTEST -Array -( - [Accept-Charset] => iso-8859-1, * - [Accept-Encoding] => none - [Host] => localhost - [User-Agent] => Mozilla/5.0 -) -OK -===DONE=== diff --git a/tests/negotiation_001.phpt b/tests/negotiation_001.phpt deleted file mode 100644 index 88e6ec4..0000000 --- a/tests/negotiation_001.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -negotiation ---SKIPIF-- - ---ENV-- -HTTP_ACCEPT_LANGUAGE=de-AT,de-DE;q=0.8,en-GB;q=0.3,en-US;q=0.2 -HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7 ---FILE-- - 500 - [en] => 0.15 -) -string(10) "iso-8859-1" -Array -( - [iso-8859-1] => 1000 - [utf-8] => 0.7 -) -Done diff --git a/tests/parse_headers_001.phpt b/tests/parse_headers_001.phpt deleted file mode 100644 index 1e095f2..0000000 --- a/tests/parse_headers_001.phpt +++ /dev/null @@ -1,43 +0,0 @@ ---TEST-- -http_parse_headers() ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -%sTEST -Array -( - [Host] => Array - ( - [0] => localhost - [1] => ambigious - ) - - [Nospace] => here - [Muchspace] => there - [Empty] => - [Empty2] => - [Folded] => one - two - three -) - diff --git a/tests/parse_message_001.phpt b/tests/parse_message_001.phpt deleted file mode 100644 index 4d36b46..0000000 --- a/tests/parse_message_001.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -http_parse_message() ---SKIPIF-- -include 'skip.inc'; -checkurl('www.google.com'); ---FILE-- -body; -echo "Done\n"; ---EXPECTF-- -%sTEST -%sThe document has moved%s -Done diff --git a/tests/redirect_001.phpt b/tests/redirect_001.phpt deleted file mode 100644 index d4e7bbd..0000000 --- a/tests/redirect_001.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -http_redirect() with params ---SKIPIF-- - ---ENV-- -HTTP_HOST=localhost ---FILE-- - 1, 'b' => 2)); -?> ---EXPECTF-- -Status: 302 -Content-type: text/html -X-Powered-By: PHP/%s -Location: http://localhost/redirect?a=1&b=2 - -Redirecting to http://localhost/redirect?a=1&b=2. - diff --git a/tests/redirect_001_logging.phpt b/tests/redirect_001_logging.phpt deleted file mode 100644 index 5237c1c..0000000 --- a/tests/redirect_001_logging.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -logging redirects ---SKIPIF-- -include 'skip.inc'; -checkcgi(); ---ENV-- -HTTP_HOST=example.com ---FILE-- - ---EXPECTF-- -%sTEST -%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d [302-REDIRECT] Location: http%s <%s> -Done diff --git a/tests/redirect_002.phpt b/tests/redirect_002.phpt deleted file mode 100644 index d43e9ad..0000000 --- a/tests/redirect_002.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -http_redirect() with session ---SKIPIF-- - ---ENV-- -HTTP_HOST=localhost ---FILE-- - 1), true); -?> ---EXPECTF-- -Status: 302 -Content-type: text/html -X-Powered-By: PHP/%s -Set-Cookie: PHPSESSID=%s; path=/ -Expires: %s -Cache-Control: %s -Pragma: %s -Location: http://localhost/redirect?a=1&PHPSESSID=%s diff --git a/tests/redirect_002_logging.phpt b/tests/redirect_002_logging.phpt deleted file mode 100644 index 5237c1c..0000000 --- a/tests/redirect_002_logging.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -logging redirects ---SKIPIF-- -include 'skip.inc'; -checkcgi(); ---ENV-- -HTTP_HOST=example.com ---FILE-- - ---EXPECTF-- -%sTEST -%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d [302-REDIRECT] Location: http%s <%s> -Done diff --git a/tests/redirect_003.phpt b/tests/redirect_003.phpt deleted file mode 100644 index ba9b83b..0000000 --- a/tests/redirect_003.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -http_redirect() permanent ---SKIPIF-- - ---ENV-- -HTTP_HOST=localhost ---FILE-- - ---EXPECTF-- -Status: 301 -Content-type: text/html -X-Powered-By: PHP/%s -Location: http://localhost/redirect - -Redirecting to http://localhost/redirect. - diff --git a/tests/redirect_003_logging.phpt b/tests/redirect_003_logging.phpt deleted file mode 100644 index 2296e63..0000000 --- a/tests/redirect_003_logging.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -logging redirects ---SKIPIF-- -include 'skip.inc'; -checkcgi(); ---ENV-- -HTTP_HOST=example.com ---FILE-- - ---EXPECTF-- -%sTEST -%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d [301-REDIRECT] Location: http%s <%s> -Done diff --git a/tests/send_data_001.phpt b/tests/send_data_001.phpt deleted file mode 100644 index ce8bcc0..0000000 --- a/tests/send_data_001.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -http_send_data() NIL-NUM range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=-5 ---FILE-- - ---EXPECTF-- -Status: 206 -X-Powered-By: PHP/%s -Content-Type: text/plain -Accept-Ranges: bytes -Content-Range: bytes 5995-5999/6000 - -23abc \ No newline at end of file diff --git a/tests/send_data_002.phpt b/tests/send_data_002.phpt deleted file mode 100644 index 91ffd08..0000000 --- a/tests/send_data_002.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -http_send_data() NUM-NUM range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=5-6 ---FILE-- - ---EXPECTF-- -Status: 206 -X-Powered-By: PHP/%s -Content-Type: text/plain -Accept-Ranges: bytes -Content-Range: bytes 5-6/6000 - -c1 \ No newline at end of file diff --git a/tests/send_data_003.phpt b/tests/send_data_003.phpt deleted file mode 100644 index be7d70b..0000000 --- a/tests/send_data_003.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -http_send_data() NUM-NIL range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=5981- ---FILE-- - ---EXPECTF-- -Status: 206 -X-Powered-By: PHP/%s -Content-Type: text/plain -Accept-Ranges: bytes -Content-Range: bytes 5981-5999/6000 - -c123abc123abc123abc \ No newline at end of file diff --git a/tests/send_data_004.phpt b/tests/send_data_004.phpt deleted file mode 100644 index 6237a42..0000000 --- a/tests/send_data_004.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -http_send_data() syntactically invalid range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=123,-wtf ? ---FILE-- - ---EXPECTF-- -X-Powered-By: PHP/%s -Content-Type: text/plain -Accept-Ranges: bytes -Content-Length: 6000 - -123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc \ No newline at end of file diff --git a/tests/send_data_005.phpt b/tests/send_data_005.phpt deleted file mode 100644 index 2cbb717..0000000 --- a/tests/send_data_005.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -http_send_data() oversized range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=5990-6000 ---FILE-- - ---EXPECTF-- -Status: 416 -%s \ No newline at end of file diff --git a/tests/send_data_006.phpt b/tests/send_data_006.phpt deleted file mode 100644 index 43d7a93..0000000 --- a/tests/send_data_006.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -http_send_data() multiple ranges ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=0-3, 4-5,9-11 ---FILE-- - ---EXPECTF-- -Status: 206 -X-Powered-By: PHP/%s -Accept-Ranges: bytes -Content-Type: multipart/byteranges; boundary=%d.%d - - ---%d.%d -Content-Type: text/plain -Content-Range: bytes 0-3/6000 - -123a ---%d.%d -Content-Type: text/plain -Content-Range: bytes 4-5/6000 - -bc ---%d.%d -Content-Type: text/plain -Content-Range: bytes 9-11/6000 - -abc ---%d.%d-- diff --git a/tests/send_data_007.phpt b/tests/send_data_007.phpt deleted file mode 100644 index f6d6058..0000000 --- a/tests/send_data_007.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -http_send_data() etag caching ---SKIPIF-- - ---ENV-- -HTTP_IF_NONE_MATCH="0bee89b07a248e27c83fc3d5951213c1" ---FILE-- - ---EXPECTF-- -Status: 304 -Content-type: text/html -X-Powered-By: PHP/%s -Cache-Control: private, must-revalidate, max-age=0 -%s diff --git a/tests/send_data_007_logging.phpt b/tests/send_data_007_logging.phpt deleted file mode 100644 index 4395fca..0000000 --- a/tests/send_data_007_logging.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -logging caching ---SKIPIF-- -include 'skip.inc'; -checkcgi(); ---ENV-- -HTTP_HOST=example.com ---FILE-- - ---EXPECTF-- -%sTEST -%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d [304-CACHE] ETag: "%s" <%s> -Done diff --git a/tests/send_data_008.phpt b/tests/send_data_008.phpt deleted file mode 100644 index eb2a9e0..0000000 --- a/tests/send_data_008.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -http_send_data() HTTP_SENDBUF_SIZE long string ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -Content-type: text/html -X-Powered-By: PHP/%s -Accept-Ranges: bytes -Content-Length: 20 - -00000000000000000000 \ No newline at end of file diff --git a/tests/send_data_009.phpt b/tests/send_data_009.phpt deleted file mode 100644 index 8fb1868..0000000 --- a/tests/send_data_009.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -http_send_data() last modified caching ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -Content-type: text/html -X-Powered-By: PHP/%s -Cache-Control: private, must-revalidate, max-age=0 -Last-Modified: %s, %d %s %d %d:%d:%d GMT -Accept-Ranges: bytes -Content-Length: 4 - -abc diff --git a/tests/send_file_001.phpt b/tests/send_file_001.phpt deleted file mode 100644 index c4b2af5..0000000 --- a/tests/send_file_001.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -http_send_file() ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -Content-type: text/html -X-Powered-By: PHP/%s -Accept-Ranges: bytes -Content-Length: 1010 - -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 diff --git a/tests/send_file_002.phpt b/tests/send_file_002.phpt deleted file mode 100644 index e949157..0000000 --- a/tests/send_file_002.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -http_send_file() NUM-NUM range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=5-9 ---FILE-- - ---EXPECTF-- -Status: 206 -Content-type: text/html -X-Powered-By: PHP/%s -Accept-Ranges: bytes -Content-Range: bytes 5-9/1010 - -56789 \ No newline at end of file diff --git a/tests/send_file_003.phpt b/tests/send_file_003.phpt deleted file mode 100644 index 7aa8b49..0000000 --- a/tests/send_file_003.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -http_send_file() NIL-NUM range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=-9 ---FILE-- - ---EXPECTF-- -Status: 206 -Content-type: text/html -X-Powered-By: PHP/%s -Accept-Ranges: bytes -Content-Range: bytes 1001-1009/1010 - -23456789 diff --git a/tests/send_file_004.phpt b/tests/send_file_004.phpt deleted file mode 100644 index 034c1f9..0000000 --- a/tests/send_file_004.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -http_send_file() NUM-NIL range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=1000- ---FILE-- - ---EXPECTF-- -Status: 206 -Content-type: text/html -X-Powered-By: PHP/%s -Accept-Ranges: bytes -Content-Range: bytes 1000-1009/1010 - -123456789 diff --git a/tests/send_file_005.phpt b/tests/send_file_005.phpt deleted file mode 100644 index d6705ea..0000000 --- a/tests/send_file_005.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -http_send_file() multiple ranges ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=0-3, 4-5,9-11 ---FILE-- - ---EXPECTF-- -Status: 206 -X-Powered-By: PHP/%s -Accept-Ranges: bytes -Content-Type: multipart/byteranges; boundary=%d.%d - - ---%d.%d -Content-Type: text/plain -Content-Range: bytes 0-3/1010 - -0123 ---%d.%d -Content-Type: text/plain -Content-Range: bytes 4-5/1010 - -45 ---%d.%d -Content-Type: text/plain -Content-Range: bytes 9-11/1010 - -901 ---%d.%d-- diff --git a/tests/send_file_006.phpt b/tests/send_file_006.phpt deleted file mode 100644 index 10f170a..0000000 --- a/tests/send_file_006.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -http_send_file() syntactically invalid range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=xxx ---FILE-- - ---EXPECTF-- -Content-type: text/html -X-Powered-By: PHP/%s -Accept-Ranges: bytes -Content-Length: 1010 - -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 -0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 diff --git a/tests/send_file_007.phpt b/tests/send_file_007.phpt deleted file mode 100644 index a337546..0000000 --- a/tests/send_file_007.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -http_send_file() oversized range ---SKIPIF-- - ---ENV-- -HTTP_RANGE=bytes=-1111 ---FILE-- - ---EXPECTF-- -Status: 416 -Content-type: text/html -X-Powered-By: PHP/%s diff --git a/tests/skip.inc b/tests/skip.inc deleted file mode 100644 index f273c91..0000000 --- a/tests/skip.inc +++ /dev/null @@ -1,10 +0,0 @@ - round((double) PHP_VERSION,1), "need PHP v$ver"); } -function checkurl($url) { skipif(!@fsockopen($url, 80), "$url not responsive"); } -function checkcls($cls) { skipif(!class_exists($cls), "need class $cls"); } -checkext('http'); -?> -- 2.30.2