fixes for windows and 5.3 compatibility
[m6w6/ext-http] / php_http_encoding.c
index ce47fcdff87cf30a5a15dd7482a679ba61519ae6..c84c30981277d7f478a83e2330da97a88dfb555b 100644 (file)
@@ -129,9 +129,7 @@ static inline int php_http_inflate_rounds(z_stream *Z, int flush, char **buf, si
                        fprintf(stderr, "\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
 #endif
                        status = inflate(Z, flush);
-                       
-                       buffer.used += buffer.free - Z->avail_out;
-                       buffer.free = Z->avail_out;
+                       php_http_buffer_account(&buffer, buffer.free - Z->avail_out);
 #if 0
                        fprintf(stderr, "%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
 #endif
@@ -203,7 +201,7 @@ retry_raw_inflate:
        status = inflateInit2(&Z, wbits);
        if (Z_OK == status) {
                Z.next_in = (Bytef *) data;
-               Z.avail_in = data_len;
+               Z.avail_in = data_len + 1; /* include the terminating NULL, see #61287 */
                
                switch (status = php_http_inflate_rounds(&Z, Z_NO_FLUSH, decoded, decoded_len)) {
                        case Z_STREAM_END:
@@ -931,8 +929,14 @@ PHP_HTTP_EMPTY_ARGS(flush);
 PHP_HTTP_EMPTY_ARGS(done);
 PHP_HTTP_EMPTY_ARGS(finish);
 
-zend_class_entry *php_http_encoding_stream_class_entry;
-zend_function_entry php_http_encoding_stream_method_entry[] = {
+static zend_class_entry *php_http_encoding_stream_class_entry;
+
+zend_class_entry *php_http_encoding_stream_get_class_entry(void)
+{
+       return php_http_encoding_stream_class_entry;
+}
+
+static zend_function_entry php_http_encoding_stream_method_entry[] = {
        PHP_HTTP_ENCSTREAM_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        PHP_HTTP_ENCSTREAM_ME(update, ZEND_ACC_PUBLIC)
        PHP_HTTP_ENCSTREAM_ME(flush, ZEND_ACC_PUBLIC)
@@ -955,7 +959,11 @@ zend_object_value php_http_encoding_stream_object_new_ex(zend_class_entry *ce, p
 
        o = ecalloc(1, sizeof(*o));
        zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
+#if PHP_VERSION_ID < 50339
+       zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*));
+#else
        object_properties_init((zend_object *) o, ce);
+#endif
 
        if (ptr) {
                *ptr = o;
@@ -995,21 +1003,21 @@ void php_http_encoding_stream_object_free(void *object TSRMLS_DC)
 
 PHP_METHOD(HttpEncodingStream, __construct)
 {
-       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                long flags = 0;
 
                if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags)) {
-                       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+                       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                                php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
                                if (!obj->stream) {
                                        php_http_encoding_stream_ops_t *ops = NULL;
 
-                                       if (instanceof_function(obj->zo.ce, php_http_deflate_stream_class_entry TSRMLS_CC)) {
+                                       if (instanceof_function(obj->zo.ce, php_http_deflate_stream_get_class_entry() TSRMLS_CC)) {
                                                ops = &php_http_encoding_deflate_ops;
-                                       } else if (instanceof_function(obj->zo.ce, php_http_inflate_stream_class_entry TSRMLS_CC)) {
+                                       } else if (instanceof_function(obj->zo.ce, php_http_inflate_stream_get_class_entry() TSRMLS_CC)) {
                                                ops = &php_http_encoding_inflate_ops;
-                                       } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_class_entry TSRMLS_CC)) {
+                                       } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_get_class_entry() TSRMLS_CC)) {
                                                ops = &php_http_encoding_dechunk_ops;
                                        }
 
@@ -1112,8 +1120,14 @@ PHP_HTTP_BEGIN_ARGS(encode, 1)
        PHP_HTTP_ARG_VAL(flags, 0)
 PHP_HTTP_END_ARGS;
 
-zend_class_entry *php_http_deflate_stream_class_entry;
-zend_function_entry php_http_deflate_stream_method_entry[] = {
+static zend_class_entry *php_http_deflate_stream_class_entry;
+
+zend_class_entry *php_http_deflate_stream_get_class_entry(void)
+{
+       return php_http_deflate_stream_class_entry;
+}
+
+static zend_function_entry php_http_deflate_stream_method_entry[] = {
        PHP_HTTP_DEFLATE_ME(encode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
 
        EMPTY_FUNCTION_ENTRY
@@ -1146,8 +1160,14 @@ PHP_HTTP_BEGIN_ARGS(decode, 1)
        PHP_HTTP_ARG_VAL(data, 0)
 PHP_HTTP_END_ARGS;
 
-zend_class_entry *php_http_inflate_stream_class_entry;
-zend_function_entry php_http_inflate_stream_method_entry[] = {
+static zend_class_entry *php_http_inflate_stream_class_entry;
+
+zend_class_entry *php_http_inflate_stream_get_class_entry(void)
+{
+       return php_http_inflate_stream_class_entry;
+}
+
+static zend_function_entry php_http_inflate_stream_method_entry[] = {
        PHP_HTTP_INFLATE_ME(decode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
 
        EMPTY_FUNCTION_ENTRY
@@ -1180,8 +1200,14 @@ PHP_HTTP_BEGIN_ARGS(decode, 1)
        PHP_HTTP_ARG_VAL(decoded_len, 1)
 PHP_HTTP_END_ARGS;
 
-zend_class_entry *php_http_dechunk_stream_class_entry;
-zend_function_entry php_http_dechunk_stream_method_entry[] = {
+static zend_class_entry *php_http_dechunk_stream_class_entry;
+
+zend_class_entry *php_http_dechunk_stream_get_class_entry(void)
+{
+       return php_http_dechunk_stream_class_entry;
+}
+
+static zend_function_entry php_http_dechunk_stream_method_entry[] = {
        PHP_HTTP_DECHUNK_ME(decode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
 
        EMPTY_FUNCTION_ENTRY
@@ -1211,7 +1237,7 @@ PHP_METHOD(HttpDechunkStream, decode)
 
 PHP_MINIT_FUNCTION(http_encoding)
 {
-       PHP_HTTP_REGISTER_CLASS(http\\Encoding, Stream, http_encoding_stream, php_http_object_class_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
+       PHP_HTTP_REGISTER_CLASS(http\\Encoding, Stream, http_encoding_stream, php_http_object_get_class_entry(), ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
        php_http_encoding_stream_class_entry->create_object = php_http_encoding_stream_object_new;
        memcpy(&php_http_encoding_stream_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        php_http_encoding_stream_object_handlers.clone_obj = php_http_encoding_stream_object_clone;