- add http_support() for probing features that depend on external libraries
authorMichael Wallner <mike@php.net>
Tue, 11 Oct 2005 08:05:04 +0000 (08:05 +0000)
committerMichael Wallner <mike@php.net>
Tue, 11 Oct 2005 08:05:04 +0000 (08:05 +0000)
- fix PHP4 DSP

12 files changed:
http.c
http.dsp
http_api.c
http_functions.c
http_request_api.c
http_util_object.c
package.xml
package2.xml
php_http.h
php_http_api.h
php_http_request_api.h
php_http_util_object.h

diff --git a/http.c b/http.c
index 060d55b96524c9535713bc3ce4f515ae903b7c0a..8930b67939e65efbdc47ae7331d92131a24c8425 100644 (file)
--- a/http.c
+++ b/http.c
@@ -61,6 +61,9 @@
 #ifdef HTTP_HAVE_MHASH
 #      include <mhash.h>
 #endif
+#ifdef HTTP_HAVE_ZLIB
+#      include <zlib.h>
+#endif
 
 #include <ctype.h>
 
@@ -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];
index 00bf67ab1cf34991e59d2a747d01f7bdd0a35d16..e752a927d4f89edb60721b0cea3e8571d6df0db7 100644 (file)
--- a/http.dsp
+++ b/http.dsp
@@ -54,7 +54,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo\r
 LINK32=link.exe\r
 # 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\r
-# 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"\r
+# 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"\r
 \r
 !ELSEIF  "$(CFG)" == "http - Win32 Debug_TS"\r
 \r
@@ -81,7 +81,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo\r
 LINK32=link.exe\r
 # 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\r
-# 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"\r
+# 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"\r
 \r
 !ENDIF \r
 \r
@@ -102,6 +102,10 @@ SOURCE=.\http_api.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\http_encoding_api.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\http_request_api.c\r
 # End Source File\r
 # Begin Source File\r
@@ -158,6 +162,10 @@ SOURCE=.\php_http_api.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\php_http_encoding_api.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\php_http_request_api.h\r
 # End Source File\r
 # Begin Source File\r
index 39736ef70b17cfc307c3281d514393800c6ec39f..a613b3f0dc9899b9b8fd52c577e5091a2b1c1937 100644 (file)
@@ -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
 
 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)
 {
index 88aefb47ae33ec54521a645c3f08d27c467a65ab..d9cefaf87b9cf2e61550d625bfb007d12c414079 100644 (file)
@@ -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)
 {
 }
index 2e3118114f9e282944613788493e41012d634346..56373d7d68e3d2d67637e8fc247e32824597d53f 100644 (file)
@@ -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
index 8fab46bb8e07b4f3ab69e165b612f6c47131054c..5829c194d539e0c56061bc8ddae35163f2daa67a 100644 (file)
@@ -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
 };
index 04ab3b7019d5072eb9d114208c93a57a8480a1a9..199f91d54cdc90c4b313e897bd5b691c6de0bbfd 100644 (file)
   </maintainers>
  <release>
   <version>0.15.0</version>
-  <date>2005-10-05</date>
+  <date>2005-10-11</date>
   <license>PHP License</license>
   <state>beta</state>
-  <notes>* 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
+  <notes>+ 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
   </notes>
   <deps>
    <dep type="php" rel="ge" version="4.3"/>
     <file role="test" name="data.txt"/>
     <file role="test" name="date_001.phpt"/>
     <file role="test" name="date_002.phpt"/>
+    <file role="test" name="etag_mode_001.phpt"/>
+    <file role="test" name="etag_mode_002.phpt"/>
+    <file role="test" name="etag_mode_003.phpt"/>
+    <file role="test" name="etag_mode_004.phpt"/>
+    <file role="test" name="etag_mode_011.phpt"/>
+    <file role="test" name="etag_mode_012.phpt"/>
+    <file role="test" name="etag_mode_013.phpt"/>
+    <file role="test" name="etag_mode_014.phpt"/>
+    <file role="test" name="etag_mode_crc.phpt"/>
     <file role="test" name="get_request_data_001.phpt"/>
     <file role="test" name="HttpMessage_001.phpt"/>
     <file role="test" name="HttpRequestPool_001.phpt"/>
@@ -78,6 +96,8 @@
     <file role="test" name="HttpRequest_003.phpt"/>
     <file role="test" name="HttpResponse_001.phpt"/>
     <file role="test" name="HttpResponse_002.phpt"/>
+    <file role="test" name="HttpResponse_003.phpt"/>
+    <file role="test" name="HttpResponse_004.phpt"/>
     <file role="test" name="INI_001.phpt"/>
     <file role="test" name="log.inc"/>
     <file role="test" name="parse_headers_001.phpt"/>
     <file role="test" name="redirect_002_logging.phpt"/>
     <file role="test" name="redirect_003.phpt"/>
     <file role="test" name="redirect_003_logging.phpt"/>
+    <file role="test" name="request_gzip.phpt"/>
     <file role="test" name="send_data_001.phpt"/>
     <file role="test" name="send_data_002.phpt"/>
     <file role="test" name="send_data_003.phpt"/>
    <file role="src" name="http_api.c"/>
    <file role="src" name="http_cache_api.c"/>
    <file role="src" name="http_date_api.c"/>
+   <file role="src" name="http_encoding_api.c"/>
    <file role="src" name="http_exception_object.c"/>
    <file role="src" name="http_functions.c"/>
    <file role="src" name="http_headers_api.c"/>
    <file role="src" name="php_http_api.h"/>
    <file role="src" name="php_http_cache_api.h"/>
    <file role="src" name="php_http_date_api.h"/>
+   <file role="src" name="php_http_encoding_api.h"/>
    <file role="src" name="php_http_exception_object.h"/>
    <file role="src" name="php_http_headers_api.h"/>
    <file role="src" name="php_http_info_api.h"/>
index b168efde4e9cf9ecf470a3e39706a755a57b8732..8fa84b52d992464a1fd5eb8ac9e0c3ccbcf0505a 100644 (file)
@@ -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
index 223a4f63dbab25bd6f59450f95ac465c3ff3186c..e59d0c241e72d42b3a3d63dbe4463ca49f527688 100644 (file)
@@ -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);
index c84331a2379361dfad6150c6c625aa97107cb8a3..99153df81b9ae0c991206b71c24f613cbce6b77d 100644 (file)
 #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);
 
index 3ff2769a9db82413c91d59663f598fd0a07d7904..5b4dc16edb69046be5c456368bc94e38c7f64363 100644 (file)
 
 #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 <winsock2.h>
 #endif
-
 #include <curl/curl.h>
 
 #define http_request_global_init() _http_request_global_init(INIT_FUNC_ARGS_PASSTHRU)
index ba711b8cb52583a6bbf1c9d3a8ef85ee8c066e87..414cc8ee67b681396674a36755d9c63c814fafee 100644 (file)
@@ -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