Backport v4 updates
[m6w6/ext-http] / src / php_http_message.c
index f5e99a469029c01efff643952f851d33c4464e3a..2014aac8f4087a4cb587127fdba5e42f30a2cb38 100644 (file)
@@ -332,7 +332,7 @@ static void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
        char *tmp = NULL;
        size_t len = 0;
 
-       php_http_info_to_string((php_http_info_t *) msg, &tmp, &len, PHP_HTTP_CRLF TSRMLS_CC);
+       php_http_info_to_string((php_http_info_t *) msg, &tmp, &len, PHP_HTTP_CRLF);
        php_http_message_update_headers(msg);
 
        php_http_buffer_append(str, tmp, len);
@@ -648,15 +648,15 @@ static void php_http_message_object_prophandler_set_headers(php_http_message_obj
        }
 }
 static void php_http_message_object_prophandler_get_body(php_http_message_object_t *obj, zval *return_value) {
-       if (obj->body) {
-               zval tmp;
+       zval tmp;
 
-               ZVAL_COPY_VALUE(&tmp, return_value);
-               RETVAL_OBJECT(&obj->body->zo, 1);
-               zval_ptr_dtor(&tmp);
-       } else {
-               RETVAL_NULL();
+       if (!obj->body) {
+               RETURN_NULL();
        }
+
+       ZVAL_COPY_VALUE(&tmp, return_value);
+       RETVAL_OBJECT(&obj->body->zo, 1);
+       zval_ptr_dtor(&tmp);
 }
 static void php_http_message_object_prophandler_set_body(php_http_message_object_t *obj, zval *value) {
        php_http_message_object_set_body(obj, value);
@@ -689,6 +689,8 @@ static void php_http_message_object_prophandler_set_parent_message(php_http_mess
        do { \
                if (!obj->message) { \
                        obj->message = php_http_message_init(NULL, 0, NULL); \
+               } else if (!obj->body && php_http_message_body_size(obj->message->body)) { \
+                       php_http_message_object_init_body_object(obj); \
                } \
        } while(0)
 
@@ -895,6 +897,13 @@ void php_http_message_object_free(zend_object *object)
        zend_object_std_dtor(object);
 }
 
+#if PHP_VERSION_ID >= 70400
+static zval *php_http_message_object_get_prop_ptr(zval *object, zval *member, int type, void **cache_slot)
+{
+       return NULL;
+}
+#endif
+
 static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
 {
        zval *return_value;
@@ -951,7 +960,9 @@ static HashTable *php_http_message_object_get_debug_info(zval *object, int *is_t
        size_t ver_len, url_len = 0;
 
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
-       *is_temp = 0;
+       if (is_temp) {
+               *is_temp = 0;
+       }
 
 #define UPDATE_PROP(name_str, action_with_tmp) \
        do { \
@@ -1470,7 +1481,7 @@ static PHP_METHOD(HttpMessage, getResponseCode)
                PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                if (obj->message->type != PHP_HTTP_RESPONSE) {
-                       php_error_docref(NULL, E_WARNING, "http\\Message is not if type response");
+                       php_error_docref(NULL, E_WARNING, "http\\Message is not of type response");
                        RETURN_FALSE;
                }
 
@@ -2064,7 +2075,11 @@ PHP_MINIT_FUNCTION(http_message)
        php_http_message_object_handlers.read_property = php_http_message_object_read_prop;
        php_http_message_object_handlers.write_property = php_http_message_object_write_prop;
        php_http_message_object_handlers.get_debug_info = php_http_message_object_get_debug_info;
+#if PHP_VERSION_ID >= 70400
+       php_http_message_object_handlers.get_property_ptr_ptr = php_http_message_object_get_prop_ptr;
+#else
        php_http_message_object_handlers.get_property_ptr_ptr = NULL;
+#endif
        php_http_message_object_handlers.get_gc = php_http_message_object_get_gc;
 
        zend_class_implements(php_http_message_class_entry, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator);