- module/includes cleanup
[m6w6/ext-http] / http_message_object.c
index c9505f6cb0f5a348bbc094eec378e09ad24f85b2..f741e65754ea7bdeebe2976d9c9861ff985444c9 100644 (file)
 #ifdef HAVE_CONFIG_H
 #      include "config.h"
 #endif
-#include "php.h"
+
+#include "php_http.h"
 
 #ifdef ZEND_ENGINE_2
 
-#include "php_http.h"
 #include "php_http_api.h"
-#include "php_http_std_defs.h"
+#include "php_http_message_api.h"
 #include "php_http_message_object.h"
 #include "php_http_exception_object.h"
 
-#include "phpstr/phpstr.h"
-#include "missing.h"
-
 #ifndef WONKY
 #      include "zend_interfaces.h"
-#endif
-#ifdef HAVE_SPL
-#      include "ext/spl/spl_array.h"
+#      if defined(HAVE_SPL)
+/* SPL doesn't install its headers */
+extern PHPAPI zend_class_entry *spl_ce_Countable;
+#      endif
 #endif
 
 ZEND_EXTERN_MODULE_GLOBALS(http);
@@ -158,10 +156,6 @@ PHP_MINIT_FUNCTION(http_message_object)
 #      else
        zend_class_implements(http_message_object_ce TSRMLS_CC, 1, zend_ce_serializable);
 #      endif
-#else
-#      ifdef HAVE_SPL
-       zend_class_implements(http_message_object_ce TSRMLS_CC, 1, spl_ce_Countable);
-#      endif
 #endif
 
        HTTP_LONG_CONSTANT("HTTP_MSG_NONE", HTTP_MSG_NONE);
@@ -364,6 +358,7 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va
 {
        getObjectEx(http_message_object, obj, object);
        http_message *msg = obj->message;
+       zval *cpy = NULL;
 #ifdef WONKY
        ulong h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1);
 #else
@@ -374,7 +369,12 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va
                return;
        }
 #endif
-
+       
+       ALLOC_ZVAL(cpy);
+       *cpy = *value;
+       zval_copy_ctor(cpy);
+       INIT_PZVAL(cpy);
+       
 #ifdef WONKY
        switch (h)
 #else
@@ -383,28 +383,28 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va
        {
                case HTTP_MSG_PROPHASH_TYPE:
                case HTTP_MSG_CHILD_PROPHASH_TYPE:
-                       convert_to_long_ex(&value);
-                       http_message_set_type(msg, Z_LVAL_P(value));
+                       convert_to_long(cpy);
+                       http_message_set_type(msg, Z_LVAL_P(cpy));
                break;
 
                case HTTP_MSG_PROPHASH_HTTP_VERSION:
                case HTTP_MSG_CHILD_PROPHASH_HTTP_VERSION:
-                       convert_to_double_ex(&value);
-                       msg->http.version = Z_DVAL_P(value);
+                       convert_to_double(cpy);
+                       msg->http.version = Z_DVAL_P(cpy);
                break;
 
                case HTTP_MSG_PROPHASH_BODY:
                case HTTP_MSG_CHILD_PROPHASH_BODY:
-                       convert_to_string_ex(&value);
+                       convert_to_string(cpy);
                        phpstr_dtor(PHPSTR(msg));
-                       phpstr_from_string_ex(PHPSTR(msg), Z_STRVAL_P(value), Z_STRLEN_P(value));
+                       phpstr_from_string_ex(PHPSTR(msg), Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
                break;
 
                case HTTP_MSG_PROPHASH_HEADERS:
                case HTTP_MSG_CHILD_PROPHASH_HEADERS:
-                       convert_to_array_ex(&value);
+                       convert_to_array(cpy);
                        zend_hash_clean(&msg->hdrs);
-                       zend_hash_copy(&msg->hdrs, Z_ARRVAL_P(value), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+                       zend_hash_copy(&msg->hdrs, Z_ARRVAL_P(cpy), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
                break;
 
                case HTTP_MSG_PROPHASH_PARENT_MESSAGE:
@@ -423,32 +423,32 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va
                case HTTP_MSG_PROPHASH_REQUEST_METHOD:
                case HTTP_MSG_CHILD_PROPHASH_REQUEST_METHOD:
                        if (HTTP_MSG_TYPE(REQUEST, msg)) {
-                               convert_to_string_ex(&value);
-                               STR_SET(msg->http.info.request.method, estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value)));
+                               convert_to_string(cpy);
+                               STR_SET(msg->http.info.request.method, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
                        }
                break;
 
                case HTTP_MSG_PROPHASH_REQUEST_URI:
                case HTTP_MSG_CHILD_PROPHASH_REQUEST_URI:
                        if (HTTP_MSG_TYPE(REQUEST, msg)) {
-                               convert_to_string_ex(&value);
-                               STR_SET(msg->http.info.request.URI, estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value)));
+                               convert_to_string(cpy);
+                               STR_SET(msg->http.info.request.URI, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
                        }
                break;
 
                case HTTP_MSG_PROPHASH_RESPONSE_CODE:
                case HTTP_MSG_CHILD_PROPHASH_RESPONSE_CODE:
                        if (HTTP_MSG_TYPE(RESPONSE, msg)) {
-                               convert_to_long_ex(&value);
-                               msg->http.info.response.code = Z_LVAL_P(value);
+                               convert_to_long(cpy);
+                               msg->http.info.response.code = Z_LVAL_P(cpy);
                        }
                break;
                
                case HTTP_MSG_PROPHASH_RESPONSE_STATUS:
                case HTTP_MSG_CHILD_PROPHASH_RESPONSE_STATUS:
                        if (HTTP_MSG_TYPE(RESPONSE, msg)) {
-                               convert_to_string_ex(&value);
-                               STR_SET(msg->http.info.response.status, estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value)));
+                               convert_to_string(cpy);
+                               STR_SET(msg->http.info.response.status, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
                        }
                break;
                
@@ -458,6 +458,7 @@ static void _http_message_object_write_prop(zval *object, zval *member, zval *va
 #endif
                break;
        }
+       zval_ptr_dtor(&cpy);
 }
 
 static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC)
@@ -550,7 +551,7 @@ PHP_METHOD(HttpMessage, __construct)
                http_message *msg = obj->message;
                
                http_message_dtor(msg);
-               if (obj->message = http_message_parse_ex(msg, message, length)) {
+               if ((obj->message = http_message_parse_ex(msg, message, length))) {
                        if (obj->message->parent) {
                                obj->parent = http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, NULL);
                        }
@@ -586,7 +587,7 @@ PHP_METHOD(HttpMessage, fromString)
        
        SET_EH_THROW_HTTP();
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &string, &length)) {
-               if (msg = http_message_parse(string, length)) {
+               if ((msg = http_message_parse(string, length))) {
                        ZVAL_OBJVAL(return_value, http_message_object_new_ex(http_message_object_ce, msg, NULL));
                }
        }