- fixed a gotcha in http_chunked_decode (-size_t is always > 0)
[m6w6/ext-http] / http_response_object.c
index f2c5e5730d13a262b5967385f5dc937b259640c1..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);
 
@@ -237,14 +240,16 @@ static inline void _http_response_object_declare_default_properties(TSRMLS_D)
        DCL_STATIC_PROP(PROTECTED, long, bufferSize, HTTP_SENDBUF_SIZE);
        DCL_STATIC_PROP(PROTECTED, double, throttleDelay, 0.0);
 
+#ifndef WONKY
        DCL_CONST(long, "ETAG_MD5", HTTP_ETAG_MD5);
        DCL_CONST(long, "ETAG_SHA1", HTTP_ETAG_SHA1);
+       DCL_CONST(long, "ETAG_CRC32", HTTP_ETAG_CRC32);
        
-#ifdef HTTP_HAVE_MHASH
+#      ifdef HTTP_HAVE_MHASH
        {
                int l, i, c = mhash_count();
                
-               for (i = 0; i < c; ++i) {
+               for (i = 0; i <= c; ++i) {
                        char const_name[256] = {0};
                        const char *hash_name = mhash_get_hash_name_static(i);
                        
@@ -254,7 +259,8 @@ static inline void _http_response_object_declare_default_properties(TSRMLS_D)
                        }
                }
        }
-#endif
+#      endif /* HTTP_HAVE_MHASH */
+#endif /* WONKY */
 }
 
 static void _http_grab_response_headers(void *data, void *arg TSRMLS_DC)
@@ -497,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.
  */
@@ -509,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))) {
@@ -539,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
 }
 /* }}} */
 
@@ -880,7 +892,7 @@ PHP_METHOD(HttpResponse, getFile)
  */
 PHP_METHOD(HttpResponse, send)
 {
-       zval *sent, *headers;
+       zval *sent;
        zend_bool clean_ob = 1;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean_ob)) {
@@ -1020,14 +1032,9 @@ PHP_METHOD(HttpResponse, send)
  */
 PHP_METHOD(HttpResponse, capture)
 {
-       zval do_catch;
-
        NO_ARGS;
 
-       INIT_PZVAL(&do_catch);
-       ZVAL_LONG(&do_catch, 1);
-
-       SET_STATIC_PROP(catch, &do_catch);
+       UPD_STATIC_PROP(long, catch, 1);
 
        php_end_ob_buffers(0 TSRMLS_CC);
        php_start_ob_buffer(NULL, 0, 0 TSRMLS_CC);