From 61f165688d2cc39424678829a145c8cbab51d1af Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 5 Sep 2005 15:12:46 +0000 Subject: [PATCH] - fix config.m4 (CURL_LIBS define was missing) - fix HAVE_LIBMHASH -> HTTP_HAVE_MHASH macro - check for curl_*_strerror() in the lib and assume they're there for windows - separate http_request_method_api (should be available even without libcurl) - use custom displayer for http.etag_mode INI entry - simplify phpinfo() output --- config.m4 | 12 ++- config.w32 | 8 +- http.c | 101 ++++++++++++++------ http.dsp | 8 ++ http_cache_api.c | 2 +- http_functions.c | 1 + http_request_api.c | 132 +-------------------------- http_request_method_api.c | 167 ++++++++++++++++++++++++++++++++++ http_request_pool_api.c | 4 + php_http.h | 5 +- php_http_cache_api.h | 16 ++-- php_http_request_api.h | 53 +---------- php_http_request_method_api.h | 85 +++++++++++++++++ php_http_std_defs.h | 2 + 14 files changed, 369 insertions(+), 227 deletions(-) create mode 100644 http_request_method_api.c create mode 100644 php_http_request_method_api.h diff --git a/config.m4 b/config.m4 index eb1c302..90e3a3d 100644 --- a/config.m4 +++ b/config.m4 @@ -58,15 +58,21 @@ dnl ---- AC_MSG_RESULT([found: $CURL_CONFIG]) fi + 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_CONFIG --libs`, 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] + ) fi dnl ---- @@ -91,7 +97,7 @@ dnl ---- PHP_ADD_INCLUDE($MHASH_DIR/include) PHP_ADD_LIBRARY_WITH_PATH(mhash, $MHASH_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD) - AC_DEFINE([HAVE_LIBMHASH], [1], [Have mhash support]) + AC_DEFINE([HTTP_HAVE_MHASH], [1], [Have mhash support]) fi dnl ---- @@ -102,7 +108,7 @@ dnl ---- 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_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]) diff --git a/config.w32 b/config.w32 index 1a73d74..80762b2 100644 --- a/config.w32 +++ b/config.w32 @@ -12,7 +12,7 @@ if (PHP_HTTP != "no") { "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_info_api.c http_request_method_api.c", null, "/I\"" + configure_module_dirname + "/phpstr\""); ADD_SOURCES(configure_module_dirname + "/phpstr", "phpstr.c", "http"); @@ -25,13 +25,15 @@ if (PHP_HTTP != "no") { WARNING("mhash etag generator not enabled; libraries and headers not found"); } - if (CHECK_LIB("libcurl.lib", "http", PHP_HTTP) && - CHECK_HEADER_ADD_INCLUDE("curl/easy.h", "CFLAGS_HTTP") && + if (CHECK_HEADER_ADD_INCLUDE("curl/curl.h", "CFLAGS_HTTP") && + CHECK_LIB("libcurl.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("HAVE_CURL_MULTI_STRERROR", 1, ""); + AC_DEFINE("HAVE_CURL_EASY_STRERROR", 1, "") } else { WARNING("curl convenience functions not enabled; libraries and headers not found"); } diff --git a/http.c b/http.c index dc8d7dd..627f5b7 100644 --- a/http.c +++ b/http.c @@ -30,6 +30,7 @@ #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 @@ -37,7 +38,9 @@ #ifdef ZEND_ENGINE_2 # include "php_http_util_object.h" # include "php_http_message_object.h" -# include "php_http_response_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" @@ -97,11 +100,11 @@ function_entry http_functions[] = { 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) -#endif #ifndef ZEND_ENGINE_2 PHP_FE(http_build_query, NULL) #endif @@ -184,6 +187,48 @@ PHP_INI_MH(http_update_allowed_methods) 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_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|MHASH_", lenof("HTTP_ETAG_MHASH|MHASH_")); + ZEND_WRITE(hash_name, strlen(hash_name)); + } + } + break; +#endif + } +} + #ifndef ZEND_ENGINE_2 # define OnUpdateLong OnUpdateInt #endif @@ -197,7 +242,7 @@ PHP_INI_BEGIN() #ifdef ZEND_ENGINE_2 HTTP_PHP_INI_ENTRY("http.only_exceptions", "0", PHP_INI_ALL, OnUpdateBool, only_exceptions) #endif - HTTP_PHP_INI_ENTRY("http.etag_mode", "-2", PHP_INI_ALL, OnUpdateLong, etag.mode) + HTTP_PHP_INI_ENTRY_EX("http.etag_mode", "-2", PHP_INI_ALL, OnUpdateLong, http_etag_mode_displayer, etag.mode) PHP_INI_END() /* }}} */ @@ -274,26 +319,12 @@ PHP_RSHUTDOWN_FUNCTION(http) /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(http) { -#ifdef ZEND_ENGINE_2 -# define HTTP_FUNC_AVAIL(CLASS) "procedural, object oriented (" CLASS ")" -#else -# define HTTP_FUNC_AVAIL(CLASS) "procedural" -#endif - #ifdef HTTP_HAVE_CURL # define HTTP_CURL_VERSION curl_version() -# ifdef ZEND_ENGINE_2 -# define HTTP_CURL_AVAIL(CLASS) "procedural, object oriented (" CLASS ")" -# else -# define HTTP_CURL_AVAIL(CLASS) "procedural" -# endif #else # define HTTP_CURL_VERSION "libcurl not available" -# define HTTP_CURL_AVAIL(CLASS) "libcurl not available" #endif -#include "php_http_request_api.h" - php_info_print_table_start(); { char full_version_string[1024] = {0}; @@ -301,10 +332,34 @@ PHP_MINFO_FUNCTION(http) php_info_print_table_row(2, "Extended HTTP support:", "enabled"); php_info_print_table_row(2, "Extension Version:", full_version_string); +#ifdef HTTP_HAVE_CURL + php_info_print_table_row(2, "cURL HTTP Requests:", "enabled"); +#else + php_info_print_table_row(2, "cURL HTTP Requests:", "disabled"); +#endif +#ifdef HTTP_HAVE_MHASH + php_info_print_table_row(2, "mhash ETag Generator:", "enabled"); +#else + php_info_print_table_row(2, "mhash ETag Generator:", "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(); -#ifdef HTTP_HAVE_CURL php_info_print_table_start(); { unsigned i; @@ -333,16 +388,6 @@ PHP_MINFO_FUNCTION(http) phpstr_free(&custom_request_methods); } php_info_print_table_end(); -#endif - - php_info_print_table_start(); - { - php_info_print_table_header(2, "Functionality", "Availability"); - php_info_print_table_row(2, "Miscellaneous Utilities:", HTTP_FUNC_AVAIL("HttpUtil, HttpMessage")); - php_info_print_table_row(2, "Extended HTTP Responses:", HTTP_FUNC_AVAIL("HttpResponse")); - php_info_print_table_row(2, "Extended HTTP Requests:", HTTP_CURL_AVAIL("HttpRequest, HttpRequestPool")); - } - php_info_print_table_end(); DISPLAY_INI_ENTRIES(); } diff --git a/http.dsp b/http.dsp index bf39787..00bf67a 100644 --- a/http.dsp +++ b/http.dsp @@ -106,6 +106,10 @@ 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 @@ -158,6 +162,10 @@ 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 diff --git a/http_cache_api.c b/http_cache_api.c index 6a86a80..9b2b8aa 100644 --- a/http_cache_api.c +++ b/http_cache_api.c @@ -33,7 +33,7 @@ #include "php_http_send_api.h" #include "php_http_date_api.h" -#ifdef HAVE_LIBMHASH +#ifdef HTTP_HAVE_MHASH # include #endif diff --git a/http_functions.c b/http_functions.c index 3e75ff4..617d223 100644 --- a/http_functions.c +++ b/http_functions.c @@ -33,6 +33,7 @@ #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" diff --git a/http_request_api.c b/http_request_api.c index 63eb983..3aba703 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -26,6 +26,7 @@ #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" @@ -41,7 +42,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http); -#if LIBCURL_VERSION_NUM < 0x070c00 +#ifndef HAVE_CURL_EASY_STRERROR # define curl_easy_strerror(code) HTTP_G(request).error #endif @@ -99,7 +100,6 @@ ZEND_EXTERN_MODULE_GLOBALS(http); continue; \ } -static const char *const http_request_methods[HTTP_MAX_REQUEST_METHOD + 1]; #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); @@ -739,134 +739,6 @@ PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, char *u } /* }}} */ -/* {{{ 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 TSRMLS_DC) -{ - zval array; - char *http_method; - unsigned long meth_num = HTTP_G(request).methods.custom.nNextFreeElement + HTTP_MAX_REQUEST_METHOD; - - Z_ARRVAL(array) = &HTTP_G(request).methods.custom; - add_next_index_string(&array, estrdup(method), 0); - - spprintf(&http_method, 0, "HTTP_%s", method); - zend_register_long_constant(http_method, strlen(http_method) + 1, meth_num, CONST_CS, http_module_number TSRMLS_CC); - efree(http_method); - - 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; - - 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; - } - - spprintf(&http_method, 0, "HTTP_%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, strlen(http_method) + 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; -} -/* }}} */ - - -/* {{{ 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 -}; -/* }}} */ - /* {{{ 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) { diff --git a/http_request_method_api.c b/http_request_method_api.c new file mode 100644 index 0000000..5a26927 --- /dev/null +++ b/http_request_method_api.c @@ -0,0 +1,167 @@ +/* + +----------------------------------------------------------------------+ + | 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" + +#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 +}; +/* }}} */ + +/* {{{ 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 TSRMLS_DC) +{ + zval array; + char *http_method; + unsigned long meth_num = HTTP_G(request).methods.custom.nNextFreeElement + HTTP_MAX_REQUEST_METHOD; + + Z_ARRVAL(array) = &HTTP_G(request).methods.custom; + add_next_index_string(&array, estrdup(method), 0); + + spprintf(&http_method, 0, "HTTP_%s", method); + zend_register_long_constant(http_method, strlen(http_method) + 1, meth_num, CONST_CS, http_module_number TSRMLS_CC); + efree(http_method); + + 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; + + 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; + } + + spprintf(&http_method, 0, "HTTP_%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, strlen(http_method) + 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_pool_api.c b/http_request_pool_api.c index 1775293..41352b5 100644 --- a/http_request_pool_api.c +++ b/http_request_pool_api.c @@ -36,6 +36,10 @@ 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_body **body); static int http_request_pool_compare_handles(void *h1, void *h2); diff --git a/php_http.h b/php_http.h index da2b04a..92da495 100644 --- a/php_http.h +++ b/php_http.h @@ -74,7 +74,7 @@ ZEND_BEGIN_MODULE_GLOBALS(http) zend_llist contexts; zend_llist convs; } copies; -# if LIBCURL_VERSION_NUM < 0x070c00 +# ifndef HAVE_CURL_EASY_STRERROR char error[CURL_ERROR_SIZE + 1]; # endif #endif /* HTTP_HAVE_CURL */ @@ -123,12 +123,11 @@ PHP_FUNCTION(http_post_data); PHP_FUNCTION(http_post_fields); PHP_FUNCTION(http_put_file); PHP_FUNCTION(http_put_stream); -/*PHP_FUNCTION(http_request)*/ +#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); -#endif /* HTTP_HAVE_CURL */ #ifndef ZEND_ENGINE_2 PHP_FUNCTION(http_build_query); #endif /* ZEND_ENGINE_2 */ diff --git a/php_http_cache_api.h b/php_http_cache_api.h index 3e882c9..4f067f5 100644 --- a/php_http_cache_api.h +++ b/php_http_cache_api.h @@ -28,7 +28,7 @@ #include "php_http_api.h" #include "php_http_send_api.h" -#ifdef HAVE_LIBMHASH +#ifdef HTTP_HAVE_MHASH # include #endif @@ -40,7 +40,7 @@ typedef enum { HTTP_ETAG_MHASH = 0, } http_etag_mode; -#ifdef HAVE_LIBMHASH +#ifdef HTTP_HAVE_MHASH static void *http_etag_alloc_mhash_digest(size_t size) { return emalloc(size); @@ -78,13 +78,13 @@ static inline void *_http_etag_init(TSRMLS_D) break; case HTTP_ETAG_MD5: -#ifndef HAVE_LIBMHASH +#ifndef HTTP_HAVE_MHASH default: #endif PHP_MD5Init(ctx = emalloc(sizeof(PHP_MD5_CTX))); break; -#ifdef HAVE_LIBMHASH +#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); @@ -112,7 +112,7 @@ static inline char *_http_etag_finish(void *ctx TSRMLS_DC) break; case HTTP_ETAG_MD5: -#ifndef HAVE_LIBMHASH +#ifndef HTTP_HAVE_MHASH default: #endif PHP_MD5Final(digest, ctx); @@ -120,7 +120,7 @@ static inline char *_http_etag_finish(void *ctx TSRMLS_DC) efree(ctx); break; -#ifdef HAVE_LIBMHASH +#ifdef HTTP_HAVE_MHASH default: { unsigned char *mhash_digest = mhash_end_m(ctx, http_etag_alloc_mhash_digest); @@ -144,13 +144,13 @@ static inline void _http_etag_update(void *ctx, const char *data_ptr, size_t dat break; case HTTP_ETAG_MD5: -#ifndef HAVE_LIBMHASH +#ifndef HTTP_HAVE_MHASH default: #endif PHP_MD5Update(ctx, (const unsigned char *) data_ptr, data_len); break; -#ifdef HAVE_LIBMHASH +#ifdef HTTP_HAVE_MHASH default: mhash(ctx, data_ptr, data_len); break; diff --git a/php_http_request_api.h b/php_http_request_api.h index 437fc90..202bb0b 100644 --- a/php_http_request_api.h +++ b/php_http_request_api.h @@ -20,6 +20,8 @@ #ifdef HTTP_HAVE_CURL #include "php_http_std_defs.h" +#include "php_http_request_method_api.h" + #include "phpstr/phpstr.h" #ifdef PHP_WIN32 @@ -28,45 +30,6 @@ #include -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_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_BODY_CSTRING 1 #define HTTP_REQUEST_BODY_CURLPOST 2 #define HTTP_REQUEST_BODY_UPLOADFILE 3 @@ -105,18 +68,6 @@ 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_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); - #define http_request_body_new() _http_request_body_new(TSRMLS_C) PHP_HTTP_API http_request_body *_http_request_body_new(TSRMLS_D); diff --git a/php_http_request_method_api.h b/php_http_request_method_api.h new file mode 100644 index 0000000..6958cbd --- /dev/null +++ b/php_http_request_method_api.h @@ -0,0 +1,85 @@ +/* + +----------------------------------------------------------------------+ + | 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_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_std_defs.h b/php_http_std_defs.h index 1d86564..cfb9cee 100644 --- a/php_http_std_defs.h +++ b/php_http_std_defs.h @@ -122,6 +122,8 @@ typedef int STATUS; #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) -- 2.30.2