- add package.xml generated by $pecl pickle
[m6w6/ext-http] / http_response_object.c
index dfc2476a8819259df634f5b2dbad0577cf9c3cf2..93c8f0c82193ca56993cb02928a12f21c017b707 100644 (file)
@@ -41,6 +41,9 @@
 #ifdef HTTP_HAVE_MHASH
 #      include <mhash.h>
 #endif
+#ifdef HTTP_HAVE_MAGIC
+#      include <magic.h>
+#endif
 
 ZEND_EXTERN_MODULE_GLOBALS(http);
 
@@ -500,7 +503,7 @@ PHP_METHOD(HttpResponse, getContentType)
 }
 /* }}} */
 
-/* {{{ proto static string HttpResponse::guessContentType(string magic_file[, long magic_mode])
+/* {{{ proto static string HttpResponse::guessContentType(string magic_file[, long magic_mode = MAGIC_MIME])
  *
  * Attempts to guess the content type of supplied payload through libmagic.
  */
@@ -512,6 +515,9 @@ PHP_METHOD(HttpResponse, guessContentType)
        
        RETVAL_NULL();
        
+#ifdef HTTP_HAVE_MAGIC
+       magic_mode = MAGIC_MIME;
+       
        SET_EH_THROW_HTTP();
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &magic_file, &magic_file_len, &magic_mode)) {
                switch (Z_LVAL_P(GET_STATIC_PROP(mode))) {
@@ -542,6 +548,9 @@ PHP_METHOD(HttpResponse, guessContentType)
                }
        }
        SET_EH_NORMAL();
+#else
+       http_error(HE_THROW, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available");
+#endif
 }
 /* }}} */