<p>Expects the second parameter to be a resource referencing an already <br />
opened stream, from which the data to upload should be read.<br />
See http_get() for a full list of available options.</p>
-<p>Returns the HTTP response(s) as string on success. or FALSE on failure.</p>
+<p>Returns the HTTP response(s) as string on success, or FALSE on failure.</p>
+<h2 id="http_put_data">string http_put_data(string url, string data[, array options[, array &info]])</h2>
+<p>Performs an HTTP PUT request on the supplied url.</p>
+<p>Expects the second parameter to be a string containing the data to upload.<br />
+See http_get() for a full list of available options.</p>
+<p>Returns the HTTP response(s) as string on success, or FALSE on failure.</p>
<h2 id="http_request_method_register">int http_request_method_register(string method)</h2>
<p>Register a custom request method.</p>
<p>Expects a string parameter containing the request method name to register.</p>
<h3 id="HttpRequest_getPutFile">string HttpRequest::getPutFile()</h3>
<p>Get previously set put file.</p>
<p>Returns a string containing the path to the currently set put file.</p>
+<h3 id="HttpRequest_setPutData">bool HttpRequest::setPutData([string put_data])</h3>
+<p>Set PUT data to send, overwriting previously set PUT data.<br />
+Affects only PUT requests.<br />
+Only either PUT data or PUT file can be used for each request.<br />
+PUT data has higher precedence and will be used even if a PUT<br />
+file is set. </p>
+<p>Accepts a string as parameter containing the data to upload.</p>
+<p>Returns TRUE on success, or FALSE on failure.</p>
+<h3 id="HttpRequest_addPutData">bool HttpRequest::addPutData(string put_data)</h3>
+<p>Add PUT data, leaving previously set PUT data unchanged.<br />
+Affects only PUT requests.</p>
+<p>Expects a string as parameter containing the data to concatenate.</p>
+<p>Returns TRUE on success, or FALSE on failure.</p>
+<h3 id="HttpRequest_getPutData">string HttpRequest::getPutData()</h3>
+<p>Get previously set PUT data.</p>
+<p>Returns a string containing the currently set raw post data.</p>
<h3 id="HttpRequest_getResponseData">array HttpRequest::getResponseData()</h3>
<p>Get all response data after the request has been sent.</p>
<p>Returns an associative array with the key "headers" containing an associative<br />
</li>
<li><a href="#http_put_stream">http_put_stream</a>
</li>
+<li><a href="#http_put_data">http_put_data</a>
+</li>
<li><a href="#http_request_method_register">http_request_method_register</a>
</li>
<li><a href="#http_request_method_unregister">http_request_method_unregister</a>
<li><a href="#HttpRequest_getPostFiles">HttpRequest::getPostFiles()</a></li>
<li><a href="#HttpRequest_setPutFile">HttpRequest::setPutFile()</a></li>
<li><a href="#HttpRequest_getPutFile">HttpRequest::getPutFile()</a></li>
+<li><a href="#HttpRequest_setPutData">HttpRequest::setPutData()</a></li>
+<li><a href="#HttpRequest_addPutData">HttpRequest::addPutData()</a></li>
+<li><a href="#HttpRequest_getPutData">HttpRequest::getPutData()</a></li>
<li><a href="#HttpRequest_getResponseData">HttpRequest::getResponseData()</a></li>
<li><a href="#HttpRequest_getResponseHeader">HttpRequest::getResponseHeader()</a></li>
<li><a href="#HttpRequest_getResponseCookies">HttpRequest::getResponseCookies()</a></li>
</li>
</ul>
</div>
- <p><b>Generated at: Mon, 20 Feb 2006 17:41:32 +0100</b></p>
+ <p><b>Generated at: Fri, 24 Feb 2006 21:29:29 +0100</b></p>
</body>
</html>
PHP_FE(http_head, http_arg_pass_ref_3)
PHP_FE(http_post_data, http_arg_pass_ref_4)
PHP_FE(http_post_fields, http_arg_pass_ref_5)
+ PHP_FE(http_put_data, http_arg_pass_ref_4)
PHP_FE(http_put_file, http_arg_pass_ref_4)
PHP_FE(http_put_stream, http_arg_pass_ref_4)
#endif
RETVAL_FALSE;
- body.type = HTTP_REQUEST_BODY_UPLOADFILE;
- body.data = stream;
- body.size = ssb.sb.st_size;
-
http_request_init_ex(&request, NULL, HTTP_PUT, URL);
- request.body = &body;
+ request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
http_request_exec(&request);
if (info) {
}
RETVAL_RESPONSE_OR_BODY(request);
}
- http_request_body_dtor(&body);
- request.body = NULL;
http_request_dtor(&request);
}
/* }}} */
* opened stream, from which the data to upload should be read.
* See http_get() for a full list of available options.
*
- * Returns the HTTP response(s) as string on success. or FALSE on failure.
+ * Returns the HTTP response(s) as string on success, or FALSE on failure.
*/
PHP_FUNCTION(http_put_stream)
{
RETVAL_FALSE;
- body.type = HTTP_REQUEST_BODY_UPLOADFILE;
- body.data = stream;
- body.size = ssb.sb.st_size;
+ http_request_init_ex(&request, NULL, HTTP_PUT, URL);
+ request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 0);
+ if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
+ http_request_exec(&request);
+ if (info) {
+ http_request_info(&request, Z_ARRVAL_P(info));
+ }
+ RETVAL_RESPONSE_OR_BODY(request);
+ }
+ http_request_dtor(&request);
+}
+/* }}} */
- http_request_init_ex(&request, NULL, HTTP_POST, URL);
- request.body = &body;
+/* {{{ proto string http_put_data(string url, string data[, array options[, array &info]])
+ *
+ * Performs an HTTP PUT request on the supplied url.
+ *
+ * Expects the second parameter to be a string containing the data to upload.
+ * See http_get() for a full list of available options.
+ *
+ * Returns the HTTP response(s) as string on success, or FALSE on failure.
+ */
+PHP_FUNCTION(http_put_data)
+{
+ char *URL, *data;
+ int URL_len, data_len;
+ zval *options = NULL, *info = NULL;
+ http_request_body body;
+ http_request request;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &data, &data_len, &options, &info)) {
+ RETURN_FALSE;
+ }
+
+ if (info) {
+ zval_dtor(info);
+ array_init(info);
+ }
+
+ RETVAL_FALSE;
+
+ http_request_init_ex(&request, NULL, HTTP_PUT, URL);
+ request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, data, data_len, 0);
if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
http_request_exec(&request);
if (info) {
}
RETVAL_RESPONSE_OR_BODY(request);
}
- request.body = NULL;
http_request_dtor(&request);
}
/* }}} */
/* nothing */
break;
- case HTTP_REQUEST_BODY_CSTRING:
- HTTP_CURL_OPT(CURLOPT_POSTFIELDS, request->body->data);
- HTTP_CURL_OPT(CURLOPT_POSTFIELDSIZE, request->body->size);
- break;
-
case HTTP_REQUEST_BODY_CURLPOST:
HTTP_CURL_OPT(CURLOPT_HTTPPOST, (struct curl_httppost *) request->body->data);
break;
+ case HTTP_REQUEST_BODY_CSTRING:
+ if (request->meth != HTTP_PUT) {
+ HTTP_CURL_OPT(CURLOPT_POSTFIELDS, request->body->data);
+ HTTP_CURL_OPT(CURLOPT_POSTFIELDSIZE, request->body->size);
+ break;
+ }
+ /* fallthrough, PUT/UPLOAD _needs_ READDATA */
case HTTP_REQUEST_BODY_UPLOADFILE:
HTTP_CURL_OPT(CURLOPT_IOCTLDATA, request);
HTTP_CURL_OPT(CURLOPT_READDATA, request);
{
http_request *request = (http_request *) ctx;
TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
-
- if (request->body == NULL || request->body->type != HTTP_REQUEST_BODY_UPLOADFILE) {
- return 0;
+
+ if (request->body) {
+ switch (request->body->type)
+ {
+ case HTTP_REQUEST_BODY_CSTRING:
+ {
+ size_t out = MIN(len * n, request->body->size - request->body->priv);
+
+ if (out) {
+ memcpy(data, request->body->data + request->body->priv, out);
+ request->body->priv += out;
+ return out;
+ }
+ }
+ break;
+
+ case HTTP_REQUEST_BODY_UPLOADFILE:
+ return php_stream_read((php_stream *) request->body->data, data, len * n);
+ break;
+ }
}
- return php_stream_read((php_stream *) request->body->data, data, len * n);
+ return 0;
}
/* }}} */
if (cmd != CURLIOCMD_RESTARTREAD) {
return CURLIOE_UNKNOWNCMD;
}
- if ( request->body == NULL ||
- request->body->type != HTTP_REQUEST_BODY_UPLOADFILE ||
- SUCCESS != php_stream_rewind((php_stream *) request->body->data)) {
- return CURLIOE_FAILRESTART;
+
+ if (request->body) {
+ switch (request->body->type)
+ {
+ case HTTP_REQUEST_BODY_CSTRING:
+ request->body->priv = 0;
+ return CURLIOE_OK;
+ break;
+
+ case HTTP_REQUEST_BODY_UPLOADFILE:
+ if (SUCCESS == php_stream_rewind((php_stream *) request->body->data)) {
+ return CURLIOE_OK;
+ }
+ break;
+ }
}
- return CURLIOE_OK;
+
+ return CURLIOE_FAILRESTART;
}
/* }}} */
body->type = type;
body->free = free;
+ body->priv = 0;
body->data = data;
body->size = size;
HTTP_ARG_VAL(filename, 0)
HTTP_END_ARGS;
+HTTP_EMPTY_ARGS(getPutData);
+HTTP_BEGIN_ARGS(setPutData, 0)
+ HTTP_ARG_VAL(put_data, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(addPutData, 1)
+ HTTP_ARG_VAL(put_data, 0)
+HTTP_END_ARGS;
+
HTTP_EMPTY_ARGS(getResponseData);
HTTP_BEGIN_ARGS(getResponseHeader, 0)
HTTP_ARG_VAL(name, 0)
HTTP_REQUEST_ME(setPutFile, ZEND_ACC_PUBLIC)
HTTP_REQUEST_ME(getPutFile, ZEND_ACC_PUBLIC)
+ HTTP_REQUEST_ME(setPutData, ZEND_ACC_PUBLIC)
+ HTTP_REQUEST_ME(getPutData, ZEND_ACC_PUBLIC)
+ HTTP_REQUEST_ME(addPutData, ZEND_ACC_PUBLIC)
+
HTTP_REQUEST_ME(send, ZEND_ACC_PUBLIC)
HTTP_REQUEST_ME(getResponseData, ZEND_ACC_PUBLIC)
DCL_PROP(PRIVATE, string, rawPostData, "");
DCL_PROP(PRIVATE, string, queryData, "");
DCL_PROP(PRIVATE, string, putFile, "");
+ DCL_PROP(PRIVATE, string, putData, "");
DCL_PROP_N(PRIVATE, history);
DCL_PROP(PUBLIC, bool, recordHistory, 0);
efree(o);
}
+#define http_request_object_check_request_content_type(t) _http_request_object_check_request_content_type((t) TSRMLS_CC)
+static inline void _http_request_object_check_request_content_type(zval *this_ptr TSRMLS_DC)
+{
+ zval *ctype = GET_PROP(contentType);
+
+ if (Z_STRLEN_P(ctype)) {
+ zval **headers, *opts = GET_PROP(options);
+
+ if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) &&
+ (Z_TYPE_PP(headers) == IS_ARRAY)) {
+ zval **ct_header;
+
+ /* only override if not already set */
+ if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void **) &ct_header))) {
+ add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+ }
+ } else {
+ zval *headers;
+
+ MAKE_STD_ZVAL(headers);
+ array_init(headers);
+ add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, headers);
+ zval_ptr_dtor(&headers);
+ }
+ }
+}
+
STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr TSRMLS_DC)
{
STATUS status = SUCCESS;
case HTTP_PUT:
{
- php_stream_statbuf ssb;
- php_stream *stream = php_stream_open_wrapper_ex(Z_STRVAL_P(GET_PROP(putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT);
+ zval *put_data = GET_PROP(putData);
- if (stream && !php_stream_stat(stream, &ssb)) {
- obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
+ http_request_object_check_request_content_type(getThis());
+ if (Z_STRLEN_P(put_data)) {
+ obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_CSTRING,
+ estrndup(Z_STRVAL_P(put_data), Z_STRLEN_P(put_data)), Z_STRLEN_P(put_data), 1);
} else {
- status = FAILURE;
+ php_stream_statbuf ssb;
+ php_stream *stream = php_stream_open_wrapper_ex(Z_STRVAL_P(GET_PROP(putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT);
+
+ if (stream && !php_stream_stat(stream, &ssb)) {
+ obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
+ } else {
+ status = FAILURE;
+ }
}
}
break;
zval *raw_data = GET_PROP(rawPostData);
if (Z_STRLEN_P(raw_data)) {
- zval *ctype = GET_PROP(contentType);
-
- if (Z_STRLEN_P(ctype)) {
- zval **headers, *opts = GET_PROP(options);
-
- if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
- (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) &&
- (Z_TYPE_PP(headers) == IS_ARRAY)) {
- zval **ct_header;
-
- /* only override if not already set */
- if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void **) &ct_header))) {
- add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
- }
- } else {
- zval *headers;
-
- MAKE_STD_ZVAL(headers);
- array_init(headers);
- add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
- zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, headers);
- zval_ptr_dtor(&headers);
- }
- }
-
+ http_request_object_check_request_content_type(getThis());
obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_CSTRING,
estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data)), Z_STRLEN_P(raw_data), 1);
-
} else {
zval *zfields = GET_PROP(postFields), *zfiles = GET_PROP(postFiles);
HashTable *fields;
}
if (data_len) {
- zval *data = zval_copy(IS_STRING, GET_PROP(rawPostData));
+ zval *data = GET_PROP(rawPostData);
- Z_STRVAL_P(data) = erealloc(Z_STRVAL_P(data), (Z_STRLEN_P(data) += data_len) + 1);
- Z_STRVAL_P(data)[Z_STRLEN_P(data)] = '\0';
- memcpy(Z_STRVAL_P(data) + Z_STRLEN_P(data) - data_len, raw_data, data_len);
- SET_PROP(rawPostData, data);
- zval_free(&data);
+ if (Z_STRLEN_P(data)) {
+ Z_STRVAL_P(data) = erealloc(Z_STRVAL_P(data), (Z_STRLEN_P(data) += data_len) + 1);
+ Z_STRVAL_P(data)[Z_STRLEN_P(data)] = '\0';
+ memcpy(Z_STRVAL_P(data) + Z_STRLEN_P(data) - data_len, raw_data, data_len);
+ } else {
+ UPD_STRL(putData, raw_data, data_len);
+ }
}
RETURN_TRUE;
}
/* }}} */
+/* {{{ proto bool HttpRequest::setPutData([string put_data])
+ *
+ * Set PUT data to send, overwriting previously set PUT data.
+ * Affects only PUT requests.
+ * Only either PUT data or PUT file can be used for each request.
+ * PUT data has higher precedence and will be used even if a PUT
+ * file is set.
+ *
+ * Accepts a string as parameter containing the data to upload.
+ *
+ * Returns TRUE on success, or FALSE on failure.
+ */
+PHP_METHOD(HttpRequest, setPutData)
+{
+ char *put_data = NULL;
+ int data_len = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &put_data, &data_len)) {
+ RETURN_FALSE;
+ }
+
+ if (!put_data) {
+ put_data = "";
+ }
+
+ UPD_STRL(putData, put_data, data_len);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::addPutData(string put_data)
+ *
+ * Add PUT data, leaving previously set PUT data unchanged.
+ * Affects only PUT requests.
+ *
+ * Expects a string as parameter containing the data to concatenate.
+ *
+ * Returns TRUE on success, or FALSE on failure.
+ */
+PHP_METHOD(HttpRequest, addPutData)
+{
+ char *put_data;
+ int data_len;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &put_data, &data_len)) {
+ RETURN_FALSE;
+ }
+
+ if (data_len) {
+ char *new_data;
+ size_t new_data_len;
+ zval *data = GET_PROP(putData);
+
+ if (Z_STRLEN_P(data)) {
+ Z_STRVAL_P(data) = erealloc(Z_STRVAL_P(data), (Z_STRLEN_P(data) += data_len) + 1);
+ Z_STRVAL_P(data)[Z_STRLEN_P(data)] = '\0';
+ memcpy(Z_STRVAL_P(data) + Z_STRLEN_P(data) - data_len, put_data, data_len);
+ } else {
+ UPD_STRL(putData, put_data, data_len);
+ }
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpRequest::getPutData()
+ *
+ * Get previously set PUT data.
+ *
+ * Returns a string containing the currently set raw post data.
+ */
+PHP_METHOD(HttpRequest, getPutData)
+{
+ NO_ARGS;
+
+ IF_RETVAL_USED {
+ RETURN_PROP(putData);
+ }
+}
+/* }}} */
+
/* {{{ proto array HttpRequest::getResponseData()
*
* Get all response data after the request has been sent.
</lead>
<date>2006-00-00</date>
<version>
- <release>0.24.1</release>
- <api>0.24.0</api>
+ <release>0.25.0</release>
+ <api>0.25.0</api>
</version>
<stability>
<release>beta</release>
</stability>
<license>BSD, revised</license>
<notes><![CDATA[
-* Fixed bug #6861 - 5 digit ports get truncated
-* Fixed bug with non-functional HttpRequest::setContentType()
+* Fixed bug #6924 - Linking fails on Mac OSX
+* Fixed HttpRequest::addRawPostData().
+
++ Added feature request http_put_data() and HttpRequest::(set|get|add)PutData().
]]></notes>
<contents>
<dir name="/">
#ifndef PHP_EXT_HTTP_H
#define PHP_EXT_HTTP_H
-#define PHP_EXT_HTTP_VERSION "0.24.1"
+#define PHP_EXT_HTTP_VERSION "0.25.0dev"
#ifdef HAVE_CONFIG_H
# include "config.h"
PHP_FUNCTION(http_head);
PHP_FUNCTION(http_post_data);
PHP_FUNCTION(http_post_fields);
+PHP_FUNCTION(http_put_data);
PHP_FUNCTION(http_put_file);
PHP_FUNCTION(http_put_stream);
#endif /* HTTP_HAVE_CURL */
#define HTTP_REQUEST_BODY_CURLPOST 2
#define HTTP_REQUEST_BODY_UPLOADFILE 3
typedef struct {
- uint type:31;
+ uint type:3;
uint free:1;
+ uint priv:28;
void *data;
size_t size;
} http_request_body;
PHP_METHOD(HttpRequest, getPostFiles);
PHP_METHOD(HttpRequest, setPutFile);
PHP_METHOD(HttpRequest, getPutFile);
+PHP_METHOD(HttpRequest, getPutData);
+PHP_METHOD(HttpRequest, setPutData);
+PHP_METHOD(HttpRequest, addPutData);
PHP_METHOD(HttpRequest, send);
PHP_METHOD(HttpRequest, getResponseData);
PHP_METHOD(HttpRequest, getResponseHeader);