From 4ef2f9e39c8d7c9dc605fb062a50d8a73b52c02a Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 11 Oct 2005 08:05:04 +0000 Subject: [PATCH] - add http_support() for probing features that depend on external libraries - fix PHP4 DSP --- http.c | 26 ++++++++++++++++++------- http.dsp | 12 ++++++++++-- http_api.c | 43 ++++++++++++++++++++++++++++++++++++++++++ http_functions.c | 36 +++++++++++++++++++++++++++++++++++ http_request_api.c | 9 +++++++++ http_util_object.c | 5 +++++ package.xml | 31 ++++++++++++++++++++++++++---- package2.xml | 1 + php_http.h | 1 + php_http_api.h | 13 +++++++++++++ php_http_request_api.h | 6 +++++- php_http_util_object.h | 1 + 12 files changed, 170 insertions(+), 14 deletions(-) diff --git a/http.c b/http.c index 060d55b..8930b67 100644 --- a/http.c +++ b/http.c @@ -61,6 +61,9 @@ #ifdef HTTP_HAVE_MHASH # include #endif +#ifdef HTTP_HAVE_ZLIB +# include +#endif #include @@ -122,6 +125,7 @@ zend_function_entry http_functions[] = { PHP_FE(http_compress, NULL) PHP_FE(http_uncompress, NULL) #endif + PHP_FE(http_support, NULL) EMPTY_FUNCTION_ENTRY }; @@ -273,13 +277,10 @@ PHP_MINIT_FUNCTION(http) REGISTER_INI_ENTRIES(); - if (SUCCESS != http_headers_global_init()) { - return FAILURE; - } - if (SUCCESS != http_cache_global_init()) { - return FAILURE; - } - if (SUCCESS != http_request_method_global_init()) { + if ( (SUCCESS != http_support_global_init()) || + (SUCCESS != http_headers_global_init()) || + (SUCCESS != http_cache_global_init()) || + (SUCCESS != http_request_method_global_init())) { return FAILURE; } #ifdef HTTP_HAVE_CURL @@ -357,6 +358,17 @@ PHP_MINFO_FUNCTION(http) #else php_info_print_table_row(2, "cURL HTTP Requests", "disabled"); #endif +#ifdef HTTP_HAVE_ZLIB + { + char my_zlib_version[64] = {0}; + + strlcat(my_zlib_version, "zlib/", 63); + strlcat(my_zlib_version, zlibVersion(), 63); + php_info_print_table_row(2, "zlib GZIP Encodings", my_zlib_version); + } +#else + php_info_print_table_row(2, "zlib GZIP Encodings", "disabled"); +#endif #ifdef HTTP_HAVE_MHASH { char mhash_info[32]; diff --git a/http.dsp b/http.dsp index 00bf67a..e752a92 100644 --- a/http.dsp +++ b/http.dsp @@ -54,7 +54,7 @@ BSC32=bscmake.exe # 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" +# ADD LINK32 libmhash.lib 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" @@ -81,7 +81,7 @@ BSC32=bscmake.exe # 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" +# ADD LINK32 libmhash.lib 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 @@ -102,6 +102,10 @@ SOURCE=.\http_api.c # End Source File # Begin Source File +SOURCE=.\http_encoding_api.c +# End Source File +# Begin Source File + SOURCE=.\http_request_api.c # End Source File # Begin Source File @@ -158,6 +162,10 @@ SOURCE=.\php_http_api.h # End Source File # Begin Source File +SOURCE=.\php_http_encoding_api.h +# End Source File +# Begin Source File + SOURCE=.\php_http_request_api.h # End Source File # Begin Source File diff --git a/http_api.c b/http_api.c index 39736ef..a613b3f 100644 --- a/http_api.c +++ b/http_api.c @@ -28,6 +28,7 @@ #include "php_http_std_defs.h" #include "php_http_api.h" #include "php_http_headers_api.h" +#include "php_http_request_api.h" #include "php_http_send_api.h" #ifdef ZEND_ENGINE_2 @@ -46,6 +47,48 @@ ZEND_EXTERN_MODULE_GLOBALS(http); +static zend_bool http_support_ssl; + +STATUS _http_support_global_init(INIT_FUNC_ARGS) +{ + http_support_ssl = http_request_supports_ssl(); + + HTTP_LONG_CONSTANT("HTTP_SUPPORT", HTTP_SUPPORT); + HTTP_LONG_CONSTANT("HTTP_SUPPORT_REQUESTS", HTTP_SUPPORT_REQUESTS); + HTTP_LONG_CONSTANT("HTTP_SUPPORT_MIMEMAGIC", HTTP_SUPPORT_MIMEMAGIC); + HTTP_LONG_CONSTANT("HTTP_SUPPORT_ENCODINGS", HTTP_SUPPORT_ENCODINGS); + HTTP_LONG_CONSTANT("HTTP_SUPPORT_MHASHETAGS", HTTP_SUPPORT_MHASHETAGS); + HTTP_LONG_CONSTANT("HTTP_SUPPORT_SSLREQUESTS", HTTP_SUPPORT_SSLREQUESTS); + + return SUCCESS; +} + +PHP_HTTP_API long _http_support(long feature) +{ + long support = HTTP_SUPPORT; + +#ifdef HTTP_HAVE_CURL + support |= HTTP_SUPPORT_REQUESTS; + if (http_support_ssl) { + support |= HTTP_SUPPORT_SSLREQUESTS; + } +#endif +#ifdef HTTP_HAVE_MHASH + support |= HTTP_SUPPORT_MHASHETAGS; +#endif +#ifdef HTTP_HAVE_MAGIC + support |= HTTP_SUPPORT_MIMEMAGIC; +#endif +#ifdef HTTP_HAVE_ZLIB + support |= HTTP_SUPPORT_ENCODINGS; +#endif + + if (feature) { + return (feature == (support & feature)); + } + return support; +} + /* 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) { diff --git a/http_functions.c b/http_functions.c index 88aefb4..d9cefaf 100644 --- a/http_functions.c +++ b/http_functions.c @@ -1590,6 +1590,42 @@ PHP_FUNCTION(http_uncompress) #endif /* HTTP_HAVE_ZLIB */ /* }}} */ +/* {{{ proto int http_support([int feature = 0]) + * + * Check for feature that require external libraries. + * + * Accpepts an optional in parameter specifying which feature to probe for. + * If the parameter is 0 or omitted, the return value contains a bitmask of + * all supported featuers that depend on external libraries. + * + * Available features to probe for are: + * - HTTP_SUPPORT: always set + * - HTTP_SUPPORT_REQUESTS: whether ext/http was linked against libcurl, + * and HTTP requests can be issued + * - HTTP_SUPPORT_SSLREQUESTS: whether libcurl was linked against openssl, + * and SSL requests can be issued + * - HTTP_SUPPORT_ENCOGINS: whether ext/http was linked against zlib, + * and compressed HTTP responses can be decoded + * - HTTP_SUPPORTS_MHASHETAGS: whether ext/http was linked against libhmash, + * and ETags can be generated with the available mhash algorithms + * - HTTP_SUPPORTS_MAGICMIME: whether ext/http was linked against libmagic, + * and the HttpResponse::guessContentType() method is usable + * + * Returns int, whether requested feature is supported, or a bitmask with + * all supported features. + */ +PHP_FUNCTION(http_support) +{ + long feature = 0; + + RETVAL_LONG(0L); + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &feature)) { + RETVAL_LONG(http_support(feature)); + } +} +/* }}} */ + PHP_FUNCTION(http_test) { } diff --git a/http_request_api.c b/http_request_api.c index 2e31181..56373d7 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -970,6 +970,15 @@ static inline void _http_curl_defaults(CURL *ch) #endif /* HTTP_HAVE_CURL */ +zend_bool _http_request_supports_ssl(void) +{ +#ifdef HTTP_NEED_SSL + return (zend_bool) 1; +#else + return (zend_bool) 0; +#endif +} + /* * Local variables: * tab-width: 4 diff --git a/http_util_object.c b/http_util_object.c index 8fab46b..5829c19 100644 --- a/http_util_object.c +++ b/http_util_object.c @@ -108,6 +108,10 @@ HTTP_BEGIN_ARGS(uncompress, 1) HTTP_ARG_VAL(encoded, 0) HTTP_END_ARGS; +HTTP_BEGIN_ARGS(support, 0) + HTTP_ARG_VAL(feature, 0) +HTTP_END_ARGS; + zend_class_entry *http_util_object_ce; zend_function_entry http_util_object_fe[] = { HTTP_UTIL_ALIAS(date, http_date) @@ -126,6 +130,7 @@ zend_function_entry http_util_object_fe[] = { HTTP_UTIL_ALIAS(inflate, http_inflate) HTTP_UTIL_ALIAS(compress, http_compress) HTTP_UTIL_ALIAS(uncompress, http_uncompress) + HTTP_UTIL_ALIAS(support, http_support) EMPTY_FUNCTION_ENTRY }; diff --git a/package.xml b/package.xml index 04ab3b7..199f91d 100644 --- a/package.xml +++ b/package.xml @@ -24,12 +24,21 @@ 0.15.0 - 2005-10-05 + 2005-10-11 PHP License beta - * Updated documentation -* Renamed http_absolute_uri() to http_build_uri() (complements with http_build_query()) -* Changed the signature of the negotiator to fill the second parameter with the results array + + Updated documentation (a lot) ++ Added optional third parameter to HttpRequest::__construct() accepting an array with options ++ Added compression functions gzencode/gzdecode, deflate/inflate, compress/uncompress ++ Added http_support() for probing features that depend on external libraries + +- Renamed http_absolute_uri() to http_build_uri() (complements with http_build_query()) +- Changed the signature of the negotiator to fill the second parameter with the results array + +* Fixed several ETag issues +* Fixed HttpRequestPools detach() and attach() methods when the iterator is active +* Fixed parsing messages with Content-Range headers +* Fixed parsing messages with another Transfer-Encoding header value than chunked @@ -70,6 +79,15 @@ + + + + + + + + + @@ -78,6 +96,8 @@ + + @@ -88,6 +108,7 @@ + @@ -115,6 +136,7 @@ + @@ -138,6 +160,7 @@ + diff --git a/package2.xml b/package2.xml index b168efd..8fa84b5 100644 --- a/package2.xml +++ b/package2.xml @@ -42,6 +42,7 @@ + Updated documentation (a lot) + Added optional third parameter to HttpRequest::__construct() accepting an array with options + Added compression functions gzencode/gzdecode, deflate/inflate, compress/uncompress ++ Added http_support() for probing features that depend on external libraries - Renamed http_absolute_uri() to http_build_uri() (complements with http_build_query()) - Changed the signature of the negotiator to fill the second parameter with the results array diff --git a/php_http.h b/php_http.h index 223a4f6..e59d0c2 100644 --- a/php_http.h +++ b/php_http.h @@ -140,6 +140,7 @@ PHP_FUNCTION(http_inflate); PHP_FUNCTION(http_compress); PHP_FUNCTION(http_uncompress); #endif +PHP_FUNCTION(http_support); PHP_MINIT_FUNCTION(http); PHP_MSHUTDOWN_FUNCTION(http); diff --git a/php_http_api.h b/php_http_api.h index c84331a..99153df 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -21,6 +21,19 @@ #include "php_http_std_defs.h" #include "php_http_send_api.h" +#define HTTP_SUPPORT 0x01L +#define HTTP_SUPPORT_REQUESTS 0x02L +#define HTTP_SUPPORT_MIMEMAGIC 0x04L +#define HTTP_SUPPORT_ENCODINGS 0x08L +#define HTTP_SUPPORT_MHASHETAGS 0x10L +#define HTTP_SUPPORT_SSLREQUESTS 0x20L + +#define http_support_global_init() _http_support_global_init(INIT_FUNC_ARGS_PASSTHRU) +extern STATUS _http_support_global_init(INIT_FUNC_ARGS); + +#define http_support(f) _http_support(f) +PHP_HTTP_API long _http_support(long feature); + #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); diff --git a/php_http_request_api.h b/php_http_request_api.h index 3ff2769..5b4dc16 100644 --- a/php_http_request_api.h +++ b/php_http_request_api.h @@ -17,6 +17,11 @@ #ifndef PHP_HTTP_REQUEST_API_H #define PHP_HTTP_REQUEST_API_H + +#define http_request_supports_ssl() _http_request_supports_ssl() +extern zend_bool _http_request_supports_ssl(void); + + #ifdef HTTP_HAVE_CURL #include "php_http_std_defs.h" @@ -27,7 +32,6 @@ #ifdef PHP_WIN32 # include #endif - #include #define http_request_global_init() _http_request_global_init(INIT_FUNC_ARGS_PASSTHRU) diff --git a/php_http_util_object.h b/php_http_util_object.h index ba711b8..414cc8e 100644 --- a/php_http_util_object.h +++ b/php_http_util_object.h @@ -40,6 +40,7 @@ PHP_METHOD(HttpUtil, deflate); PHP_METHOD(HttpUtil, inflate); PHP_METHOD(HttpUtil, compress); PHP_METHOD(HttpUtil, uncompress); +PHP_METHOD(HttpUtil, support); #endif #endif -- 2.30.2