PHP 7.4: ulong->unsigned long, uint->uint32_t
[m6w6/ext-http] / src / php_http_encoding.c
index ad4385369c62a7c95022e5b5fb26f75142672c13..3e57e2932e53233c99fa7fd408b724c4604a4f31 100644 (file)
@@ -36,7 +36,7 @@ const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, c
        *decoded = ecalloc(1, encoded_len + 1);
 
        while ((encoded + encoded_len - e_ptr) > 0) {
-               ulong chunk_len = 0, rest;
+               unsigned long chunk_len = 0, rest;
 
                chunk_len = strtoul(e_ptr, &n_ptr, 16);
 
@@ -164,7 +164,9 @@ ZEND_RESULT_CODE php_http_encoding_stream_reset(php_http_encoding_stream_t **s)
        if (EXPECTED((*s)->ops->dtor)) {
                (*s)->ops->dtor(*s);
        }
+
        if (EXPECTED(ss = (*s)->ops->init(*s))) {
+               ss->flags &= ~PHP_HTTP_ENCODING_STREAM_DIRTY;
                *s = ss;
                return SUCCESS;
        }
@@ -173,10 +175,15 @@ ZEND_RESULT_CODE php_http_encoding_stream_reset(php_http_encoding_stream_t **s)
 
 ZEND_RESULT_CODE php_http_encoding_stream_update(php_http_encoding_stream_t *s, const char *in_str, size_t in_len, char **out_str, size_t *out_len)
 {
-       if (UNEXPECTED(!s->ops->update)) {
-               return FAILURE;
+       ZEND_RESULT_CODE rc = FAILURE;
+
+       if (EXPECTED(s->ops->update)) {
+               rc = s->ops->update(s, in_str, in_len, out_str, out_len);
        }
-       return s->ops->update(s, in_str, in_len, out_str, out_len);
+
+       s->flags |= PHP_HTTP_ENCODING_STREAM_DIRTY;
+
+       return rc;
 }
 
 ZEND_RESULT_CODE php_http_encoding_stream_flush(php_http_encoding_stream_t *s, char **out_str, size_t *out_len)
@@ -192,7 +199,7 @@ ZEND_RESULT_CODE php_http_encoding_stream_flush(php_http_encoding_stream_t *s, c
 zend_bool php_http_encoding_stream_done(php_http_encoding_stream_t *s)
 {
        if (!s->ops->done) {
-               return 0;
+               return !(s->flags & PHP_HTTP_ENCODING_STREAM_DIRTY);
        }
        return s->ops->done(s);
 }
@@ -202,6 +209,9 @@ ZEND_RESULT_CODE php_http_encoding_stream_finish(php_http_encoding_stream_t *s,
        if (!s->ops->finish) {
                *out_str = NULL;
                *out_len = 0;
+
+               s->flags &= ~PHP_HTTP_ENCODING_STREAM_DIRTY;
+
                return SUCCESS;
        }
        return s->ops->finish(s, out_str, out_len);
@@ -227,7 +237,7 @@ void php_http_encoding_stream_free(php_http_encoding_stream_t **s)
 
 struct dechunk_ctx {
        php_http_buffer_t buffer;
-       ulong hexlen;
+       unsigned long hexlen;
        unsigned zeroed:1;
 };
 
@@ -472,6 +482,10 @@ zend_object *php_http_encoding_stream_object_clone(zval *object)
        php_http_encoding_stream_object_t *new_obj, *old_obj = PHP_HTTP_OBJ(NULL, object);
        php_http_encoding_stream_t *cpy = php_http_encoding_stream_copy(old_obj->stream, NULL);
 
+       if (!cpy) {
+               return NULL;
+       }
+
        new_obj = php_http_encoding_stream_object_new_ex(old_obj->zo.ce, cpy);
        zend_objects_clone_members(&new_obj->zo, &old_obj->zo);
 
@@ -514,7 +528,7 @@ static PHP_METHOD(HttpEncodingStream, __construct)
        obj = PHP_HTTP_OBJ(NULL, getThis());
 
        if (UNEXPECTED(obj->stream)) {
-               php_http_throw(bad_method_call, "http\\Encoding\\Stream cannot be initialized twice", NULL);
+               php_http_throw(bad_method_call, "http\\Encoding\\Stream cannot be initialized twice");
                return;
        }
 
@@ -524,10 +538,12 @@ static PHP_METHOD(HttpEncodingStream, __construct)
                ops = php_http_encoding_stream_get_inflate_ops();
        } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_class_entry)) {
                ops = &php_http_encoding_dechunk_ops;
+#if PHP_HTTP_HAVE_LIBBROTLI
        } else if (instanceof_function(obj->zo.ce, php_http_get_enbrotli_stream_class_entry())) {
                ops = php_http_encoding_stream_get_enbrotli_ops();
        } else if (instanceof_function(obj->zo.ce, php_http_get_debrotli_stream_class_entry())) {
                ops = php_http_encoding_stream_get_debrotli_ops();
+#endif
        } else {
                php_http_throw(runtime, "Unknown http\\Encoding\\Stream class '%s'", obj->zo.ce->name->val);
                return;
@@ -624,7 +640,7 @@ static PHP_METHOD(HttpEncodingStream, finish)
 }
 
 static zend_function_entry php_http_encoding_stream_methods[] = {
-       PHP_ME(HttpEncodingStream, __construct,  ai_HttpEncodingStream___construct,  ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+       PHP_ME(HttpEncodingStream, __construct,  ai_HttpEncodingStream___construct,  ZEND_ACC_PUBLIC)
        PHP_ME(HttpEncodingStream, update,       ai_HttpEncodingStream_update,       ZEND_ACC_PUBLIC)
        PHP_ME(HttpEncodingStream, flush,        ai_HttpEncodingStream_flush,        ZEND_ACC_PUBLIC)
        PHP_ME(HttpEncodingStream, done,         ai_HttpEncodingStream_done,         ZEND_ACC_PUBLIC)