+ if (code < 100 || code > 510) {
+ http_error_ex(E_WARNING, HTTP_E_PARAM, "Invalid response code (100-510): %ld", code);
+ RETURN_FALSE;
+ }
+
+ UPD_PROP(obj, long, responseCode, code);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getRequestMethod()
+ *
+ * Get the Request Method of the Message.
+ * Returns false if the Message is not of type HTTP_MSG_REQUEST.
+ */
+PHP_METHOD(HttpMessage, getRequestMethod)
+{
+ zval *method;
+ getObject(http_message_object, obj);
+
+ NO_ARGS;
+
+ if (obj->message->type != HTTP_MSG_REQUEST) {
+ http_error(E_NOTICE, HTTP_E_MSG, "HttpMessage is not of type HTTP_MSG_REQUEST");
+ RETURN_NULL();
+ }
+
+ method = GET_PROP(obj, requestMethod);
+ RETURN_STRINGL(Z_STRVAL_P(method), Z_STRLEN_P(method), 1);
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setRequestMethod(string method)
+ *
+ * Set the Request Method of the HTTP Message.
+ * Returns false if the Message is not of type HTTP_MSG_REQUEST.
+ */
+PHP_METHOD(HttpMessage, setRequestMethod)
+{
+ char *method;
+ int method_len;
+ getObject(http_message_object, obj);
+
+ if (obj->message->type != HTTP_MSG_REQUEST) {
+ http_error(E_WARNING, HTTP_E_MSG, "HttpMessage is not of type HTTP_MSG_REQUEST");
+ RETURN_FALSE;
+ }
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
+ RETURN_FALSE;
+ }
+ if (method_len < 1) {
+ http_error(E_WARNING, HTTP_E_PARAM, "Cannot set HttpMessage::requestMethod to an empty string");
+ RETURN_FALSE;
+ }
+
+ UPD_PROP(obj, string, requestMethod, method);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getRequestUri()
+ *
+ * Get the Request URI of the Message.
+ */
+PHP_METHOD(HttpMessage, getRequestUri)
+{
+ zval *uri;
+ getObject(http_message_object, obj);
+
+ NO_ARGS;
+
+ if (obj->message->type != HTTP_MSG_REQUEST) {
+ RETURN_NULL();
+ }
+
+ uri = GET_PROP(obj, requestUri);
+ RETURN_STRINGL(Z_STRVAL_P(uri), Z_STRLEN_P(uri), 1);
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setRequestUri(string URI)
+ *
+ * Set the Request URI of the HTTP Message.
+ * Returns false if the Message is not of type HTTP_MSG_REQUEST,
+ * or if paramtere URI was empty.
+ */
+PHP_METHOD(HttpMessage, setRequestUri)
+{
+ char *URI;
+ int URIlen;
+ getObject(http_message_object, obj);
+
+ if (obj->message->type != HTTP_MSG_REQUEST) {
+ http_error(E_WARNING, HTTP_E_MSG, "HttpMessage is not of type HTTP_MSG_REQUEST");
+ RETURN_FALSE;
+ }
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URI, &URIlen)) {
+ RETURN_FALSE;
+ }
+ if (URIlen < 1) {
+ http_error(E_WARNING, HTTP_E_PARAM, "Cannot set HttpMessage::requestUri to an empty string");
+ RETURN_FALSE;
+ }
+
+ UPD_PROP(obj, string, requestUri, URI);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getHttpVersion()
+ *
+ * Get the HTTP Protocol Version of the Message.
+ */
+PHP_METHOD(HttpMessage, getHttpVersion)
+{
+ zval *version;
+ char ver[4] = {0};
+ getObject(http_message_object, obj);
+
+ NO_ARGS;
+
+ version = GET_PROP(obj, httpVersion);
+
+ if (Z_TYPE_P(version) == IS_NULL) {
+ RETURN_NULL();
+ }
+
+ sprintf(ver, "1.1f", Z_DVAL_P(version));
+ RETURN_STRINGL(ver, 3, 1);
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setHttpVersion(string version)
+ *
+ * Set the HTTP Protocol version of the Message.
+ * Returns false if version is invalid (1.0 and 1.1).
+ */
+PHP_METHOD(HttpMessage, setHttpVersion)
+{
+ char v[4];
+ zval *zv, *version;
+ getObject(http_message_object, obj);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &zv)) {
+ return;
+ }
+
+ convert_to_double_ex(&zv);
+ sprintf(v, "%1.1f", Z_DVAL_P(zv));
+ if (strcmp(v, "1.0") && strcmp(v, "1.1")) {
+ http_error_ex(E_WARNING, HTTP_E_PARAM, "Invalid HTTP version (1.0 or 1.1): %s", v);
+ RETURN_FALSE;
+ }
+
+ SET_PROP(obj, httpVersion, zv);
+}
+/* }}} */
+
+/* {{{ proto HttpMessage HttpMessage::getNestedMessage()
+ *
+ * Get nested HTTP Message.
+ */
+PHP_METHOD(HttpMessage, getNestedMessage)
+{
+ zval *nested;
+ getObject(http_message_object, obj);
+
+ NO_ARGS;
+
+ nested = GET_PROP(obj, nestedMessage);
+ if (Z_TYPE_P(nested) == IS_OBJECT) {
+ Z_TYPE_P(return_value) = IS_OBJECT;
+ return_value->is_ref = 1;
+ return_value->value.obj = nested->value.obj;
+ zval_add_ref(&return_value);
+ } else {
+ RETVAL_NULL();
+ }
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::toString()
+ *
+ * Get the string representation of the Message.
+ */
+PHP_METHOD(HttpMessage, toString)
+{
+ char *string;
+ size_t length;
+ getObject(http_message_object, obj);
+
+ NO_ARGS;
+
+ http_message_tostring(obj->message, &string, &length);
+ RETURN_STRINGL(string, length, 0);
+}
+/* }}} */
+
+/* }}} */
+
+#ifdef HTTP_HAVE_CURL
+/* {{{ HttpRequest */
+
+/* {{{ proto void HttpRequest::__construct([string url[, long request_method = HTTP_GET]])
+ *
+ * Instantiate a new HttpRequest object which can be used to issue HEAD, GET
+ * and POST (including posting files) HTTP requests.
+ */
+PHP_METHOD(HttpRequest, __construct)
+{
+ char *URL = NULL;
+ int URL_len;
+ long meth = -1;
+ getObject(http_request_object, obj);
+
+ SET_EH_THROW_HTTP();
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &URL, &URL_len, &meth)) {
+ INIT_PARR(obj, options);
+ INIT_PARR(obj, responseInfo);
+ INIT_PARR(obj, responseData);
+ INIT_PARR(obj, postData);
+ INIT_PARR(obj, postFiles);
+
+ if (URL) {
+ UPD_PROP(obj, string, url, URL);
+ }
+ if (meth > -1) {
+ UPD_PROP(obj, long, method, meth);
+ }