- add http_put_data() and HttpRequest::(set|get|add)PutData()
authorMichael Wallner <mike@php.net>
Fri, 24 Feb 2006 20:31:53 +0000 (20:31 +0000)
committerMichael Wallner <mike@php.net>
Fri, 24 Feb 2006 20:31:53 +0000 (20:31 +0000)
- fix HttpRequest::addRawPostData()
- properly initialize request body in http_(post|put)_*()

docs/functions.html
http.c
http_functions.c
http_request_api.c
http_request_body_api.c
http_request_object.c
package2.xml
php_http.h
php_http_request_body_api.h
php_http_request_object.h

index 02b48406b0cbcfd56f95dc0ab6bb3dd104e4d8f7..148840804190bed8a03cf26a4e58d0f17ba34391 100644 (file)
@@ -386,7 +386,12 @@ See http_get() for a full list of available options.</p>
 <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>
@@ -777,6 +782,22 @@ If the parameter is empty or omitted the put file will be unset.</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 />
@@ -1171,6 +1192,8 @@ http.cache_log is set.</p>
 </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>
@@ -1295,6 +1318,9 @@ http.cache_log is set.</p>
 <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>
@@ -1369,7 +1395,7 @@ http.cache_log is set.</p>
 </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>
 
diff --git a/http.c b/http.c
index 75ca08854053cb51c9671f3e59697eaa05ef32f9..2f2011fad9ed22d32e0d86bcc234e20356e020d2 100644 (file)
--- a/http.c
+++ b/http.c
@@ -102,6 +102,7 @@ zend_function_entry http_functions[] = {
        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
index 8ce961fdac10ccdf666076eb2ad5bd7cda2db923..8f9130042def69c1a234e5e3f2a46d6970ae271c 100644 (file)
@@ -1517,12 +1517,8 @@ PHP_FUNCTION(http_put_file)
 
        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) {
@@ -1530,8 +1526,6 @@ PHP_FUNCTION(http_put_file)
                }
                RETVAL_RESPONSE_OR_BODY(request);
        }
-       http_request_body_dtor(&body);
-       request.body = NULL;
        http_request_dtor(&request);
 }
 /* }}} */
@@ -1544,7 +1538,7 @@ PHP_FUNCTION(http_put_file)
  * 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)
 {
@@ -1572,12 +1566,49 @@ 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) {
@@ -1585,7 +1616,6 @@ PHP_FUNCTION(http_put_stream)
                }
                RETVAL_RESPONSE_OR_BODY(request);
        }
-       request.body = NULL;
        http_request_dtor(&request);
 }
 /* }}} */
index e34b866330acc551cb4dccc08b36eef94f40616a..8e8fa9ca08e2b00a1c106585f2e612a41925fae8 100644 (file)
@@ -827,15 +827,17 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
                                /* 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);
@@ -910,11 +912,28 @@ static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *ct
 {
        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;
 }
 /* }}} */
 
@@ -953,12 +972,24 @@ static curlioerr http_curl_ioctl_callback(CURL *ch, curliocmd cmd, void *ctx)
        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;
 }
 /* }}} */
 
index 14a235d397f662ef9e9d6e057079500270bffc1e..dd76edb47053b18d52b03499464f72f08059b43b 100644 (file)
@@ -30,6 +30,7 @@ PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *bo
        
        body->type = type;
        body->free = free;
+       body->priv = 0;
        body->data = data;
        body->size = size;
        
index 3bf2f9871c0556d5be618989d3de579929e4846d..87bfb65ce5a1187126f7c706d7bd945cac90f5c5 100644 (file)
@@ -130,6 +130,15 @@ HTTP_BEGIN_ARGS(setPutFile, 0)
        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)
@@ -261,6 +270,10 @@ zend_function_entry http_request_object_fe[] = {
        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)
@@ -366,6 +379,7 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D)
        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);
 
@@ -432,6 +446,35 @@ void _http_request_object_free(zend_object *object TSRMLS_DC)
        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;
@@ -449,13 +492,21 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
 
                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;
@@ -467,34 +518,9 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                        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;
@@ -1292,13 +1318,15 @@ PHP_METHOD(HttpRequest, addRawPostData)
        }
        
        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;
@@ -1458,6 +1486,88 @@ PHP_METHOD(HttpRequest, getPutFile)
 }
 /* }}} */
 
+/* {{{ 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.
index fe0878e4811de4fab732e3132d5691a7f09d2042..df982fc7da06a990db9be5214e3060b7b6677afa 100644 (file)
@@ -37,8 +37,8 @@ HttpResponse
  </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>
@@ -46,8 +46,10 @@ HttpResponse
  </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="/">
index beddf2ac59c6afb9d6cb899b6ea356e18f95a5b4..f8f3e966f311e4421d607f6029a9f03fb0b75b1a 100644 (file)
@@ -15,7 +15,7 @@
 #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"
@@ -178,6 +178,7 @@ PHP_FUNCTION(http_get);
 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 */
index 5786d6c3b109666ffc1d8d3293013fdc31030848..346544dfc193fac9857e0d7f52a36ed4aa572126 100644 (file)
@@ -22,8 +22,9 @@
 #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;
index 4d2ab24f51fbe0108049669d708fd18cd3232952..00c2eb03caf346845f52fd5585d3ae919f8f09ee 100644 (file)
@@ -76,6 +76,9 @@ PHP_METHOD(HttpRequest, setPostFiles);
 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);