- add HttpMessage::guessContentType()
authorMichael Wallner <mike@php.net>
Thu, 8 Jun 2006 22:07:39 +0000 (22:07 +0000)
committerMichael Wallner <mike@php.net>
Thu, 8 Jun 2006 22:07:39 +0000 (22:07 +0000)
- release 1.0.0

docs/functions.html
http_message_object.c
http_send_api.c
http_util_object.c
package.xml
package2.xml
php_http_message_object.h
tests/HttpRequest_010.phpt

index 25b14cc58520389e19bc74f074de10c25d7fde1b..b939e06fb1ae8d59b054f759c52e395bea90f429 100644 (file)
@@ -576,6 +576,13 @@ HttpMessage::TYPE_REQUEST or supplied URL was empty.</p>
 <p>Set the HTTP Protocol version of the Message.</p>
 <p>Expects a string parameter containing the HTTP protocol version.</p>
 <p>Returns TRUE on success, or FALSE if supplied version is out of range (1.0/1.1).</p>
+<h3 id="HttpMessage_guessContentType">string HttpMessage::guessContentType(string magic_file[, int magic_mode = MAGIC_MIME])</h3>
+<p>Attempts to guess the content type of supplied payload through libmagic.</p>
+<p>Expects a string parameter specifying the magic.mime database to use.<br />
+Additionally accepts an optional int parameter, being flags for libmagic.</p>
+<p>Returns the guessed content type on success, or FALSE on failure.</p>
+<p>Throws HttpRuntimeException, HttpInvalidParamException <br />
+if http.only_exceptions is TRUE.</p>
 <h3 id="HttpMessage_getParentMessage">HttpMessage HttpMessage::getParentMessage()</h3>
 <p>Get parent Message.</p>
 <p>Returns the parent HttpMessage on success, or NULL if there's none.</p>
@@ -1289,6 +1296,7 @@ http.cache_log is set.</p>
 <li><a href="#HttpMessage_setRequestUrl">HttpMessage::setRequestUrl()</a></li>
 <li><a href="#HttpMessage_getHttpVersion">HttpMessage::getHttpVersion()</a></li>
 <li><a href="#HttpMessage_setHttpVersion">HttpMessage::setHttpVersion()</a></li>
+<li><a href="#HttpMessage_guessContentType">HttpMessage::guessContentType()</a></li>
 <li><a href="#HttpMessage_getParentMessage">HttpMessage::getParentMessage()</a></li>
 <li><a href="#HttpMessage_send">HttpMessage::send()</a></li>
 <li><a href="#HttpMessage_toString">HttpMessage::toString()</a></li>
@@ -1434,7 +1442,7 @@ http.cache_log is set.</p>
 </li>
 </ul>
 </div>
-    <p><b>Generated at: Sun, 28 May 2006 17:55:39 +0200</b></p>
+    <p><b>Generated at: Thu, 08 Jun 2006 23:59:56 +0200</b></p>
 </body>
 </html>
 
index 3d736cdaaafa4d19d8b151bb17abe84d32fca23b..56b1a1e9c9566514b091a6aaf6fb619f7d27b439 100644 (file)
@@ -14,6 +14,7 @@
 
 #define HTTP_WANT_SAPI
 #define HTTP_WANT_CURL
+#define HTTP_WANT_MAGIC
 #include "php_http.h"
 
 #ifdef ZEND_ENGINE_2
@@ -94,6 +95,11 @@ HTTP_BEGIN_ARGS(setHttpVersion, 1)
        HTTP_ARG_VAL(http_version, 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(getParentMessage);
 HTTP_EMPTY_ARGS(send);
 HTTP_BEGIN_ARGS(toString, 0)
@@ -149,6 +155,7 @@ zend_function_entry http_message_object_fe[] = {
        HTTP_MESSAGE_ME(setRequestUrl, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(getHttpVersion, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(setHttpVersion, ZEND_ACC_PUBLIC)
+       HTTP_MESSAGE_ME(guessContentType, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(getParentMessage, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(send, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(toString, ZEND_ACC_PUBLIC)
@@ -1126,6 +1133,41 @@ PHP_METHOD(HttpMessage, setHttpVersion)
 }
 /* }}} */
 
+/* {{{ proto string HttpMessage::guessContentType(string magic_file[, int magic_mode = MAGIC_MIME])
+ *
+ * Attempts to guess the content type of supplied payload through libmagic.
+ * 
+ * Expects a string parameter specifying the magic.mime database to use.
+ * Additionally accepts an optional int parameter, being flags for libmagic.
+ * 
+ * Returns the guessed content type on success, or FALSE on failure.
+ * 
+ * Throws HttpRuntimeException, HttpInvalidParamException 
+ * if http.only_exceptions is TRUE.
+ */
+PHP_METHOD(HttpMessage, guessContentType)
+{
+#ifdef HTTP_HAVE_MAGIC
+       char *magic_file, *ct = NULL;
+       int magic_file_len;
+       long magic_mode = MAGIC_MIME;
+       
+       RETVAL_FALSE;
+       SET_EH_THROW_HTTP();
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &magic_file, &magic_file_len, &magic_mode)) {
+               getObject(http_message_object, obj);
+               if ((ct = http_guess_content_type(magic_file, magic_mode, PHPSTR_VAL(&obj->message->body), PHPSTR_LEN(&obj->message->body), SEND_DATA))) {
+                       RETVAL_STRING(ct, 0);
+               }
+       }
+       SET_EH_NORMAL();
+#else
+       http_error(HE_THROW, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available");
+       RETURN_FALSE;
+#endif
+}
+/* }}} */
+
 /* {{{ proto HttpMessage HttpMessage::getParentMessage()
  *
  * Get parent Message.
index 88a27e1a7684cf83d6a82b422a76cf59fcd7e90c..587870f8a85fb170ec408dc5aedd30eab7b4b22e 100644 (file)
@@ -484,15 +484,13 @@ PHP_HTTP_API char *_http_guess_content_type(const char *magicfile, long magicmod
        char *ct = NULL;
 
 #ifdef HTTP_HAVE_MAGIC
-       struct magic_set *magic;
+       struct magic_set *magic = NULL;
        
        HTTP_CHECK_OPEN_BASEDIR(magicfile, return NULL);
        
-       /*      magic_load() fails if MAGIC_MIME is set because it 
-               cowardly adds .mime to the file name */
-       magic = magic_open(magicmode &~ MAGIC_MIME);
-       
-       if (!magic) {
+       if (!data_ptr) {
+               http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Supplied payload is empty");
+       } else if (!(magic = magic_open(magicmode &~ MAGIC_MIME))) {
                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));
index 2d46aa8c84ec81a427d3df1f45878f1b996762ac..ad75f7a51f56c5137e9bc6a8240ed0123930361e 100644 (file)
@@ -94,6 +94,7 @@ HTTP_BEGIN_ARGS(chunkedDecode, 1)
        HTTP_ARG_VAL(encoded_string, 0)
 HTTP_END_ARGS;
 
+#ifdef HTTP_HAVE_ZLIB
 HTTP_BEGIN_ARGS(deflate, 1)
        HTTP_ARG_VAL(plain, 0)
        HTTP_ARG_VAL(flags, 0)
@@ -102,6 +103,7 @@ HTTP_END_ARGS;
 HTTP_BEGIN_ARGS(inflate, 1)
        HTTP_ARG_VAL(encoded, 0)
 HTTP_END_ARGS;
+#endif
 
 HTTP_BEGIN_ARGS(support, 0)
        HTTP_ARG_VAL(feature, 0)
index 775bedca39943ad51868c9b1aaf25298d63eb769..45aa0d9f4868071c3c2264cebf2aa861ecb6a122 100644 (file)
@@ -23,19 +23,16 @@ support. Parallel requests are available for PHP 5 and greater.
   </maintainer>
   </maintainers>
  <release>
-  <version>1.0.0RC5</version>
-  <date>2006-05-28</date>
+  <version>1.0.0</version>
+  <date>2006-06-09</date>
   <license>BSD, revised</license>
-  <state>beta</state>
-  <notes>+ Added HttpRequest::enableCookies() and HttpRequest::resetCookies([bool session_only=FALSE])
-+ Added optional flags argument to http_parse_params()
-+ Added HTTP_PARAMS_ALLOW_COMMA, HTTP_PARAMS_ALLOW_FAILURE, HTTP_PARAMS_RAISE_ERROR constants
-* Fixed http_build_url(&quot;./path&quot;) if REQUEST_URI is empty
-* Fixed http_parse_params(&quot;foo;bar&quot;) returning &quot;foo&quot; and &quot;ar&quot;
-* Fixed return value of http_parse_params() Object{&quot;params&quot;=&gt;Array(&quot;value&quot;, Array(&quot;name&quot;=&gt;&quot;value&quot;), ...)}
-* Fixed HttpMessage::setRequestMethod() errenously issuing a warning about an unknown request method
-* Fixed bugs introduced by using the new REQUEST_TIME server variable
-! NOTE: Many INI settings have been renamed to comply with the internal structure
+  <state>stable</state>
+  <notes>+ Added --with[out]-http-shared-deps configure option (dependencies on shared extensions)
++ Added INI entries: http.log.not_found, http.send.not_found_404
++ Added HttpMessage::guessContentType()
+* Fixed build on Debian systems where access to Curl_* functions is prohibited
+* Fixed empty Cache-Control header if not customly set with HttpResponse
+* Reset Content-Disposition and Content-Type if file is not found by http_send_file() etc
   </notes>
   <deps>
    <dep type="php" rel="ge" version="4.3"/>
@@ -43,8 +40,9 @@ support. Parallel requests are available for PHP 5 and greater.
   </deps>
   <configureoptions>
    <configureoption name="with-http-curl-requests" default="yes" prompt="whether to enable cURL HTTP requests; specify libcurl directory"/>
-   <configureoption name="with-http-magic-mime" default="no" prompt="whether to enable response content type guessing; specify libmagic directory"/>
    <configureoption name="with-http-zlib-compression" default="yes" prompt="whether to enable support for gzencoded/deflated message bodies; specify zlib directory"/>
+   <configureoption name="with-http-magic-mime" default="no" prompt="whether to enable response content type guessing; specify libmagic directory"/>
+   <configureoption name="with-http-shared-deps" default="yes" prompt="whether to depend on extensions which have been built shared"/>
   </configureoptions>
   <filelist>
    <dir name="docs">
@@ -59,6 +57,7 @@ support. Parallel requests are available for PHP 5 and greater.
     <file role="php" install-as="pecl/http/FeedAggregator.php" name="FeedAggregator.php"/>
     <file role="php" install-as="pecl/http/PgLobStream.php" name="PgLobStream.php"/>
     <file role="php" install-as="pecl/http/XmlRpcClient.php" name="XmlRpcClient.php"/>
+    <file role="php" install-as="pecl/http/XmlRpcServer.php" name="XmlRpcServer.php"/>
    </dir> <!-- /lib -->
    <dir name="phpstr">
     <file role="src" name="phpstr.c"/>
@@ -131,6 +130,7 @@ support. Parallel requests are available for PHP 5 and greater.
     <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="HttpResponse_005.phpt"/>
     <file role="test" name="log.inc"/>
     <file role="test" name="match_request_header_001.phpt"/>
     <file role="test" name="negotiation_001.phpt"/>
@@ -196,6 +196,7 @@ support. Parallel requests are available for PHP 5 and greater.
    </dir> <!-- /tests -->
    <file role="src" name="config.m4"/>
    <file role="src" name="config.w32"/>
+   <file role="src" name="config9.m4"/>
    <file role="doc" name="CREDITS"/>
    <file role="doc" name="EXPERIMENTAL"/>
    <file role="src" name="http.c"/>
@@ -250,6 +251,7 @@ support. Parallel requests are available for PHP 5 and greater.
    <file role="src" name="php_http_requestpool_object.h"/>
    <file role="src" name="php_http_request_api.h"/>
    <file role="src" name="php_http_request_body_api.h"/>
+   <file role="src" name="php_http_request_int.h"/>
    <file role="src" name="php_http_request_method_api.h"/>
    <file role="src" name="php_http_request_object.h"/>
    <file role="src" name="php_http_request_pool_api.h"/>
index f3552fa85253b8dc4894c2a2b27aed56c31de11a..be45841ea0bc4c3769808c0c1ebe4d33c79289ab 100644 (file)
@@ -30,17 +30,18 @@ support. Parallel requests are available for PHP 5 and greater.
  </lead>
  <date>2006-00-00</date>
  <version>
-  <release>1.0.0dev</release>
+  <release>1.0.0</release>
   <api>1.0.0</api>
  </version>
  <stability>
-  <release>beta</release>
-  <api>beta</api>
+  <release>stable</release>
+  <api>stable</api>
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
 + Added --with[out]-http-shared-deps configure option (dependencies on shared extensions)
 + Added INI entries: http.log.not_found, http.send.not_found_404
++ Added HttpMessage::guessContentType()
 * Fixed build on Debian systems where access to Curl_* functions is prohibited
 * Fixed empty Cache-Control header if not customly set with HttpResponse
 * Reset Content-Disposition and Content-Type if file is not found by http_send_file() etc
@@ -131,6 +132,7 @@ support. Parallel requests are available for PHP 5 and greater.
     <file role="php" name="FeedAggregator.php"/>
     <file role="php" name="PgLobStream.php"/>
     <file role="php" name="XmlRpcClient.php"/>
+    <file role="php" name="XmlRpcServer.php"/>
    </dir>
    
    <dir name="tests">
@@ -314,6 +316,7 @@ support. Parallel requests are available for PHP 5 and greater.
    <install as="pecl/http/FeedAggregator.php" name="lib/FeedAggregator.php"/>
    <install as="pecl/http/PgLobStream.php" name="lib/PgLobStream.php"/>
    <install as="pecl/http/XmlRpcClient.php" name="lib/XmlRpcClient.php"/>
+   <install as="pecl/http/XmlRpcServer.php" name="lib/XmlRpcServer.php"/>
   </filelist>
  </extsrcrelease>
  <changelog />
index 1004ac6c8ac0479e0c5a49a1d3140ea96f6edb5e..38030ad3c002dba333ecf9b571e4284c0eabb373 100644 (file)
@@ -95,6 +95,7 @@ PHP_METHOD(HttpMessage, getRequestUrl);
 PHP_METHOD(HttpMessage, setRequestUrl);
 PHP_METHOD(HttpMessage, getHttpVersion);
 PHP_METHOD(HttpMessage, setHttpVersion);
+PHP_METHOD(HttpMessage, guessContentType);
 PHP_METHOD(HttpMessage, getParentMessage);
 PHP_METHOD(HttpMessage, send);
 PHP_METHOD(HttpMessage, toString);
index b8bcaa516975a03900d2b10441f944c51ced8907..4559be23205605bf103be7da20ad0d1001adbc95 100644 (file)
@@ -4,6 +4,7 @@ HttpRequest cookie API
 <?php
 include 'skip.inc';
 checkmin(5);
+checkcls("HttpRequest");
 ?>
 --FILE--
 <?php