- update docs
[m6w6/ext-http] / http_message_object.c
index 00fb3cededac04f81a91de025fd5d834018fc66e..7af330dcfa91851b1393e44848cc884c6ddabcdf 100644 (file)
@@ -18,6 +18,7 @@
 
 #ifdef ZEND_ENGINE_2
 
+#include "zend_interfaces.h"
 #include "ext/standard/url.h"
 
 #include "php_http_api.h"
@@ -32,7 +33,6 @@
 #include "php_http_request_object.h"
 
 #ifndef WONKY
-#      include "zend_interfaces.h"
 #      ifdef HAVE_SPL
 /* SPL doesn't install its headers */
 extern PHPAPI zend_class_entry *spl_ce_Countable;
@@ -76,6 +76,11 @@ HTTP_BEGIN_ARGS(setResponseCode, 0, 1)
        HTTP_ARG_VAL(response_code, 0)
 HTTP_END_ARGS;
 
+HTTP_EMPTY_ARGS(getResponseStatus, 0);
+HTTP_BEGIN_ARGS(setResponseStatus, 0, 1)
+       HTTP_ARG_VAL(response_status, 0)
+HTTP_END_ARGS;
+
 HTTP_EMPTY_ARGS(getRequestMethod, 0);
 HTTP_BEGIN_ARGS(setRequestMethod, 0, 1)
        HTTP_ARG_VAL(request_method, 0)
@@ -138,6 +143,8 @@ zend_function_entry http_message_object_fe[] = {
        HTTP_MESSAGE_ME(setType, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(getResponseCode, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(setResponseCode, ZEND_ACC_PUBLIC)
+       HTTP_MESSAGE_ME(getResponseStatus, ZEND_ACC_PUBLIC)
+       HTTP_MESSAGE_ME(setResponseStatus, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(getRequestMethod, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(setRequestMethod, ZEND_ACC_PUBLIC)
        HTTP_MESSAGE_ME(getRequestUrl, ZEND_ACC_PUBLIC)
@@ -253,6 +260,7 @@ static inline void _http_message_object_declare_default_properties(TSRMLS_D)
        DCL_PROP(PROTECTED, string, body, "");
        DCL_PROP(PROTECTED, string, requestMethod, "");
        DCL_PROP(PROTECTED, string, requestUrl, "");
+       DCL_PROP(PROTECTED, string, responseStatus, "");
        DCL_PROP(PROTECTED, long, responseCode, 0);
        DCL_PROP_N(PROTECTED, httpVersion);
        DCL_PROP_N(PROTECTED, headers);
@@ -337,7 +345,7 @@ static zval *_http_message_object_read_prop(zval *object, zval *member, int type
                case HTTP_MSG_PROPHASH_PARENT_MESSAGE:
                case HTTP_MSG_CHILD_PROPHASH_PARENT_MESSAGE:
                        if (msg->parent) {
-                               RETVAL_OBJVAL(obj->parent);
+                               RETVAL_OBJVAL(obj->parent, 1);
                        } else {
                                RETVAL_NULL();
                        }
@@ -604,8 +612,8 @@ PHP_METHOD(HttpMessage, __construct)
  *
  * Create an HttpMessage object from a string. Kind of a static constructor.
  * 
- * Expects a string parameter containing a sinlge or several consecutive
- * HTTP messages.  Accepts an optionsl string parameter specifying the class to use.
+ * Expects a string parameter containing a single or several consecutive
+ * HTTP messages.  Accepts an optional string parameter specifying the class to use.
  * 
  * Returns an HttpMessage object on success or NULL on failure.
  * 
@@ -632,7 +640,7 @@ PHP_METHOD(HttpMessage, fromString)
                                }
                        }
                        if (ce) {
-                               ZVAL_OBJVAL(return_value, http_message_object_new_ex(ce, msg, NULL));
+                               RETVAL_OBJVAL(http_message_object_new_ex(ce, msg, NULL), 0);
                        }
                }
        }
@@ -770,7 +778,7 @@ PHP_METHOD(HttpMessage, getType)
  *
  * Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE)
  * 
- * Exptects an int parameter, the HttpMessage::TYPE.
+ * Expects an int parameter, the HttpMessage::TYPE.
  */
 PHP_METHOD(HttpMessage, setType)
 {
@@ -832,6 +840,50 @@ PHP_METHOD(HttpMessage, setResponseCode)
 }
 /* }}} */
 
+/* {{{ proto string HttpMessage::getResponseStatus()
+ *
+ * Get the Response Status of the message (i.e. the string following the response code).
+ *
+ * Returns the HTTP response status string if the message is of type 
+ * HttpMessage::TYPE_RESPONSE, else FALSE.
+ */
+PHP_METHOD(HttpMessage, getResponseStatus)
+{
+       NO_ARGS;
+       
+       IF_RETVAL_USED {
+               getObject(http_message_object, obj);
+               HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
+               RETURN_STRING(obj->message->http.info.response.status, 1);
+       }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setResponseStatus(string status)
+ *
+ * Set the Response Status of the HTTP message (i.e. the string following the response code).
+ *
+ * Expects a string parameter containing the response status text.
+ *
+ * Returns TRUE on success or FALSE if the message is not of type
+ * HttpMessage::TYPE_RESPONSE.
+ */
+PHP_METHOD(HttpMessage, setResponseStatus)
+{
+       char *status;
+       int status_len;
+       getObject(http_message_object, obj);
+       
+       HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
+       
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len)) {
+               RETURN_FALSE;
+       }
+       STR_SET(obj->message->http.info.response.status, estrdup(status));
+       RETURN_TRUE;
+}
+/* }}} */
+
 /* {{{ proto string HttpMessage::getRequestMethod()
  *
  * Get the Request Method of the Message.
@@ -997,7 +1049,7 @@ PHP_METHOD(HttpMessage, getParentMessage)
                getObject(http_message_object, obj);
 
                if (obj->message->parent) {
-                       RETVAL_OBJVAL(obj->parent);
+                       RETVAL_OBJVAL(obj->parent, 1);
                } else {
                        RETVAL_NULL();
                }
@@ -1085,7 +1137,7 @@ PHP_METHOD(HttpMessage, toMessageTypeObject)
                                
                                memset(&hurl, 0, sizeof(php_url));
                                hurl.host = host ? Z_STRVAL_P(host) : NULL;
-                               http_build_url(purl, &hurl, NULL, &url, NULL);
+                               http_build_url(HTTP_URL_REPLACE, purl, &hurl, NULL, &url, NULL);
                                php_url_free(purl);
                                add_assoc_string(array, "url", url, 0);
                                
@@ -1260,7 +1312,7 @@ PHP_METHOD(HttpMessage, detach)
        zend_hash_copy(&msg->hdrs, &obj->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
        phpstr_append(&msg->body, PHPSTR_VAL(obj->message), PHPSTR_LEN(obj->message));
        
-       ZVAL_OBJVAL(return_value, http_message_object_new_ex(Z_OBJCE_P(getThis()), msg, NULL));
+       RETVAL_OBJVAL(http_message_object_new_ex(Z_OBJCE_P(getThis()), msg, NULL), 0);
 }
 /* }}} */
 
@@ -1361,8 +1413,7 @@ PHP_METHOD(HttpMessage, next)
                if (itr && itr->parent.handle) {
                        zval *old = obj->iterator;
                        MAKE_STD_ZVAL(obj->iterator);
-                       ZVAL_OBJVAL(obj->iterator, itr->parent);
-                       Z_OBJ_ADDREF_P(obj->iterator);
+                       ZVAL_OBJVAL(obj->iterator, itr->parent, 1);
                        zval_ptr_dtor(&old);
                } else {
                        zval_ptr_dtor(&obj->iterator);