]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Implemented means to set request payload buffer rather than an...
authorStephan Bosch <stephan@dovecot.fi>
Fri, 15 Apr 2016 21:59:24 +0000 (23:59 +0200)
committerStephan Bosch <stephan@rename-it.nl>
Wed, 20 Apr 2016 01:06:01 +0000 (03:06 +0200)
This is not purely a convenience function: there have been bugs caused by allocating a data input stream from a datastack buffer.
With this function, the buffer is copied to the request pool, so that it is durably allocated while the request exists.
This prevents futher mishaps. The server already has an equivalent function for its response object.

src/lib-http/http-client-request.c
src/lib-http/http-client.h

index ce1a00d45ac6e16e2649133c6e683ae60df824f6..cde2db97c64e2872e0068abfe7f77f1a9802fb0a 100644 (file)
@@ -356,6 +356,23 @@ void http_client_request_set_payload(struct http_client_request *req,
                req->payload_sync = TRUE;
 }
 
+void http_client_request_set_payload_data(struct http_client_request *req,
+                                    const unsigned char *data, size_t size)
+{
+       struct istream *input;
+       unsigned char *payload_data;
+
+       if (size == 0)
+               return;
+
+       payload_data = p_malloc(req->pool, size);
+       memcpy(payload_data, data, size);
+       input = i_stream_create_from_data(payload_data, size);
+
+       http_client_request_set_payload(req, input, FALSE);
+       i_stream_unref(&input);
+}
+
 void http_client_request_set_timeout_msecs(struct http_client_request *req,
        unsigned int msecs)
 {
index 9f59c58d04dbdd6651a42891d634580ba61573c0..ddc221e538ad4364b2c5aa62a05b91560962d416 100644 (file)
@@ -204,6 +204,8 @@ void http_client_request_set_date(struct http_client_request *req,
 
 void http_client_request_set_payload(struct http_client_request *req,
                                     struct istream *input, bool sync);
+void http_client_request_set_payload_data(struct http_client_request *req,
+                                    const unsigned char *data, size_t size);
 
 void http_client_request_set_timeout_msecs(struct http_client_request *req,
        unsigned int msecs);