- 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 25b14cc..b939e06 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 3d736cd..56b1a1e 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 88a27e1..587870f 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 2d46aa8..ad75f7a 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 775bedc..45aa0d9 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 f3552fa..be45841 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 1004ac6..38030ad 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 b8bcaa5..4559be2 100644 (file)
@@ -4,6 +4,7 @@ HttpRequest cookie API
 <?php
 include 'skip.inc';
 checkmin(5);
+checkcls("HttpRequest");
 ?>
 --FILE--
 <?php