+ case HTTP_MSG_RESPONSE:
+ Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, ""));
+ break;
+ default:
+ RETURN_NULL();
+ break;
+ }
+ Z_TYPE_P(return_value) = IS_STRING;
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setInfo(string http_info)
+ Set type and request or response info with a standard HTTP request or response line */
+PHP_METHOD(HttpMessage, setInfo)
+{
+ char *str;
+ int len;
+ http_info inf;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len) && SUCCESS == http_info_parse_ex(str, &inf, 0)) {
+ getObject(http_message_object, obj);
+
+ http_message_set_info(obj->message, &inf);
+ http_info_dtor(&inf);
+ RETURN_TRUE;
+ }
+ RETURN_FALSE;
+}
+/* }}} */
+
+/* {{{ proto int HttpMessage::getResponseCode()
+ Get the Response Code of the Message. */
+PHP_METHOD(HttpMessage, getResponseCode)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+ HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
+ RETURN_LONG(obj->message->http.info.response.code);
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setResponseCode(int code)
+ Set the response code of an HTTP Response Message. */
+PHP_METHOD(HttpMessage, setResponseCode)
+{
+ long code;
+ getObject(http_message_object, obj);
+
+ HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
+ RETURN_FALSE;
+ }
+ if (code < 100 || code > 599) {
+ http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid response code (100-599): %ld", code);
+ RETURN_FALSE;
+ }
+
+ obj->message->http.info.response.code = code;
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getResponseStatus()
+ Get the Response Status of the message (i.e. the string following the response code). */
+PHP_METHOD(HttpMessage, getResponseStatus)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+ HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
+ if (obj->message->http.info.response.status) {
+ RETURN_STRING(obj->message->http.info.response.status, 1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setResponseStatus(string status)
+ Set the Response Status of the HTTP message (i.e. the string following the response code). */
+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, estrndup(status, status_len));
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getRequestMethod()
+ Get the Request Method of the Message. */
+PHP_METHOD(HttpMessage, getRequestMethod)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
+ if (obj->message->http.info.request.method) {
+ RETURN_STRING(obj->message->http.info.request.method, 1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setRequestMethod(string method)
+ Set the Request Method of the HTTP Message. */
+PHP_METHOD(HttpMessage, setRequestMethod)
+{
+ char *method;
+ int method_len;
+ getObject(http_message_object, obj);
+
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
+ RETURN_FALSE;
+ }
+ if (method_len < 1) {
+ http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestMethod to an empty string");
+ RETURN_FALSE;
+ }
+ if (!http_request_method_exists(1, 0, method)) {
+ http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unknown request method: %s", method);
+ RETURN_FALSE;
+ }
+
+ STR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getRequestUrl()
+ Get the Request URL of the Message. */
+PHP_METHOD(HttpMessage, getRequestUrl)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
+ if (obj->message->http.info.request.url) {
+ RETURN_STRING(obj->message->http.info.request.url, 1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setRequestUrl(string url)
+ Set the Request URL of the HTTP Message. */
+PHP_METHOD(HttpMessage, setRequestUrl)
+{
+ char *URI;
+ int URIlen;
+ getObject(http_message_object, obj);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URI, &URIlen)) {
+ RETURN_FALSE;
+ }
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
+ if (URIlen < 1) {
+ http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestUrl to an empty string");
+ RETURN_FALSE;
+ }
+
+ STR_SET(obj->message->http.info.request.url, estrndup(URI, URIlen));
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getHttpVersion()
+ Get the HTTP Protocol Version of the Message. */
+PHP_METHOD(HttpMessage, getHttpVersion)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ char *version;
+ getObject(http_message_object, obj);
+
+ spprintf(&version, 0, "%1.1F", obj->message->http.version);
+ RETURN_STRING(version, 0);
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setHttpVersion(string version)
+ Set the HTTP Protocol version of the Message. */
+PHP_METHOD(HttpMessage, setHttpVersion)
+{
+ zval *zv;
+ char *version;
+ getObject(http_message_object, obj);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &zv)) {
+ return;
+ }
+
+ convert_to_double(zv);
+ spprintf(&version, 0, "%1.1F", Z_DVAL_P(zv));
+ if (strcmp(version, "1.0") && strcmp(version, "1.1")) {
+ efree(version);
+ http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid HTTP protocol version (1.0 or 1.1): %g", Z_DVAL_P(zv));
+ RETURN_FALSE;
+ }
+ efree(version);
+ obj->message->http.version = Z_DVAL_P(zv);
+ RETURN_TRUE;
+}
+/* }}} */