- consistent usage of HTTP_G macro (only)
[m6w6/ext-http] / http_message_object.c
index 00a8007db26ed08a03041bb8c7a0585c554bce3c..d275004a3b7669cfa8820bfb6841243544c032f6 100644 (file)
@@ -39,81 +39,86 @@ extern PHPAPI zend_class_entry *spl_ce_Countable;
 #      endif
 #endif
 
-#define HTTP_BEGIN_ARGS(method, ret_ref, req_args)     HTTP_BEGIN_ARGS_EX(HttpMessage, method, ret_ref, req_args)
-#define HTTP_EMPTY_ARGS(method, ret_ref)                       HTTP_EMPTY_ARGS_EX(HttpMessage, method, ret_ref)
-#define HTTP_MESSAGE_ME(method, visibility)                    PHP_ME(HttpMessage, method, HTTP_ARGS(HttpMessage, method), visibility)
+#define HTTP_BEGIN_ARGS(method, req_args)      HTTP_BEGIN_ARGS_EX(HttpMessage, method, 0, req_args)
+#define HTTP_EMPTY_ARGS(method)                                HTTP_EMPTY_ARGS_EX(HttpMessage, method, 0)
+#define HTTP_MESSAGE_ME(method, visibility)    PHP_ME(HttpMessage, method, HTTP_ARGS(HttpMessage, method), visibility)
 
-HTTP_BEGIN_ARGS(__construct, 0, 0)
+HTTP_BEGIN_ARGS(__construct, 0)
        HTTP_ARG_VAL(message, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(fromString, 1, 1)
+HTTP_BEGIN_ARGS(fromString, 1)
        HTTP_ARG_VAL(message, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getBody, 0);
-HTTP_BEGIN_ARGS(setBody, 0, 1)
+HTTP_EMPTY_ARGS(getBody);
+HTTP_BEGIN_ARGS(setBody, 1)
        HTTP_ARG_VAL(body, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getHeaders, 0);
-HTTP_BEGIN_ARGS(setHeaders, 0, 1)
+HTTP_EMPTY_ARGS(getHeaders);
+HTTP_BEGIN_ARGS(setHeaders, 1)
        HTTP_ARG_VAL(headers, 0)
 HTTP_END_ARGS;
 
-HTTP_BEGIN_ARGS(addHeaders, 0, 1)
+HTTP_BEGIN_ARGS(addHeaders, 1)
        HTTP_ARG_VAL(headers, 0)
        HTTP_ARG_VAL(append, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getType, 0);
-HTTP_BEGIN_ARGS(setType, 0, 1)
+HTTP_EMPTY_ARGS(getType);
+HTTP_BEGIN_ARGS(setType, 1)
        HTTP_ARG_VAL(type, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getResponseCode, 0);
-HTTP_BEGIN_ARGS(setResponseCode, 0, 1)
+HTTP_EMPTY_ARGS(getResponseCode);
+HTTP_BEGIN_ARGS(setResponseCode, 1)
        HTTP_ARG_VAL(response_code, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getRequestMethod, 0);
-HTTP_BEGIN_ARGS(setRequestMethod, 0, 1)
+HTTP_EMPTY_ARGS(getResponseStatus);
+HTTP_BEGIN_ARGS(setResponseStatus, 1)
+       HTTP_ARG_VAL(response_status, 0)
+HTTP_END_ARGS;
+
+HTTP_EMPTY_ARGS(getRequestMethod);
+HTTP_BEGIN_ARGS(setRequestMethod, 1)
        HTTP_ARG_VAL(request_method, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getRequestUrl, 0);
-HTTP_BEGIN_ARGS(setRequestUrl, 0, 1)
+HTTP_EMPTY_ARGS(getRequestUrl);
+HTTP_BEGIN_ARGS(setRequestUrl, 1)
        HTTP_ARG_VAL(url, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getHttpVersion, 0);
-HTTP_BEGIN_ARGS(setHttpVersion, 0, 1)
+HTTP_EMPTY_ARGS(getHttpVersion);
+HTTP_BEGIN_ARGS(setHttpVersion, 1)
        HTTP_ARG_VAL(http_version, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(getParentMessage, 0);
-HTTP_EMPTY_ARGS(send, 0);
-HTTP_BEGIN_ARGS(toString, 0, 0)
+HTTP_EMPTY_ARGS(getParentMessage);
+HTTP_EMPTY_ARGS(send);
+HTTP_BEGIN_ARGS(toString, 0)
        HTTP_ARG_VAL(include_parent, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(toMessageTypeObject, 0);
+HTTP_EMPTY_ARGS(toMessageTypeObject);
 
-HTTP_EMPTY_ARGS(count, 0);
+HTTP_EMPTY_ARGS(count);
 
-HTTP_EMPTY_ARGS(serialize, 0);
-HTTP_BEGIN_ARGS(unserialize, 0, 1)
+HTTP_EMPTY_ARGS(serialize);
+HTTP_BEGIN_ARGS(unserialize, 1)
        HTTP_ARG_VAL(serialized, 0)
 HTTP_END_ARGS;
 
-HTTP_EMPTY_ARGS(rewind, 0);
-HTTP_EMPTY_ARGS(valid, 0);
-HTTP_EMPTY_ARGS(key, 0);
-HTTP_EMPTY_ARGS(current, 0);
-HTTP_EMPTY_ARGS(next, 0);
+HTTP_EMPTY_ARGS(rewind);
+HTTP_EMPTY_ARGS(valid);
+HTTP_EMPTY_ARGS(key);
+HTTP_EMPTY_ARGS(current);
+HTTP_EMPTY_ARGS(next);
 
-HTTP_EMPTY_ARGS(detach, 0);
-HTTP_BEGIN_ARGS(prepend, 0, 1)
+HTTP_EMPTY_ARGS(detach);
+HTTP_BEGIN_ARGS(prepend, 1)
        HTTP_ARG_OBJ(HttpMessage, message, 0)
 HTTP_END_ARGS;
 
@@ -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);
@@ -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.
  * 
@@ -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.