* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int http_transaction_set_progress_callbacks(http_transaction_h http_transaction, http_transaction_upload_progress_cb upload_progress_cb,
+int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_upload_progress_cb upload_progress_cb,
http_transaction_download_progress_cb download_progress_cb);
/**
int http_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding);
/**
+ * @internal
+ * @brief Sets the request message body.
+ * @since_tizen 3.0
+ * @privlevel platform
+ * @privilege http://tizen.org/privilege/http.admin
+ * @details Sets the request message body.
+ * @param[in] http_transaction The http transaction handle
+ * @param[in] body message body data
+ * @return 0 on success, otherwise negative error value
+ * @retval #HTTP_ERROR_NONE Successful
+ * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int http_request_write_body(http_transaction_h http_transaction, const char *body);
+
+/**
* @}
*/
return HTTP_ERROR_NONE;
}
+
+API int http_request_write_body(http_transaction_h http_transaction, const char *body)
+{
+ _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(http_transaction) is NULL\n");
+ _retvm_if(body == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(body) is NULL\n");
+
+ __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+ __http_request_h *request = transaction->request;
+
+ request->tot_size += strlen(body);
+
+ g_queue_push_tail(request->body_queue, (gpointer)body);
+
+ return HTTP_ERROR_NONE;
+}
+
+int _get_request_body_size(http_transaction_h http_transaction, int *body_size)
+{
+ _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(http_transaction) is NULL\n");
+ _retvm_if(body_size == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(body_size) is NULL\n");
+
+ __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+ __http_request_h *request = transaction->request;
+
+ *body_size = request->tot_size;
+
+ return HTTP_ERROR_NONE;
+}
+
+int _read_request_body(http_transaction_h http_transaction, char **body)
+{
+ _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(http_transaction) is NULL\n");
+ _retvm_if(body == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(body) is NULL\n");
+
+ __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+ __http_request_h *request = transaction->request;
+
+ int len = 0;
+ int index = 0;
+ int body_size = 0;
+ int curr_len = 0;
+ size_t new_len = 0;
+ gchar* ptr = NULL;
+
+ *body = malloc(curr_len + 1);
+ if (*body == NULL) {
+ DBG("malloc() failed\n");
+ return HTTP_ERROR_OPERATION_FAILED;
+ }
+
+ len = g_queue_get_length(request->body_queue);
+
+ for (index = 0; index < len; index++) {
+
+ ptr = (gchar*)g_queue_pop_head(request->body_queue);
+ body_size = strlen(ptr);
+
+ new_len = curr_len + body_size;
+ *body = realloc(*body, new_len + 1);
+ if (*body == NULL) {
+ DBG("realloc() failed\n");
+ return HTTP_ERROR_OPERATION_FAILED;
+ }
+
+ memcpy(*body + curr_len, ptr, body_size);
+
+ body[new_len] = '\0';
+ curr_len = new_len;
+ }
+
+ return HTTP_ERROR_NONE;
+}
return written;
}
+size_t __handle_write_cb(char *ptr, size_t size, size_t nmemb, gpointer user_data)
+{
+ __http_transaction_h *transaction = (__http_transaction_h *)user_data;
+ __http_request_h *request = transaction->request;
+ size_t recommended_size = size * nmemb;
+ size_t body_size = 0;
+
+ transaction->write_cb(recommended_size);
+
+ ptr = (gchar*)g_queue_pop_head(request->body_queue);
+ if (ptr == NULL) {
+ DBG("Sent the last chunk.\n");
+ return 0;
+ }
+ body_size = strlen(ptr);
+
+ return body_size;
+}
+
size_t __http_debug_received(CURL* easy_handle, curl_infotype type, char* byte, size_t size, void *user_data)
{
char log_buffer[_HTTP_DEFAULT_HEADER_SIZE];
CURLMcode ret = CURLM_OK;
gchar *proxy_addr = NULL;
struct curl_slist* header_list = NULL;
+ gchar *field_value = NULL;
+ gboolean write_event = FALSE;
+ gint body_size = 0;
+ gint content_len = 0;
transaction->easy_handle = curl_easy_init();
curl_easy_setopt(transaction->easy_handle, CURLOPT_WRITEFUNCTION, __handle_body_cb);
curl_easy_setopt(transaction->easy_handle, CURLOPT_WRITEDATA, transaction);
+ http_header_get_field_value(transaction, "Content-Length", &field_value);
+ if (field_value) {
+ content_len = atoi(field_value);
+
+ if (content_len > 0) {
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)(content_len));
+ DBG("Set the Content-Length(%d).", content_len);
+ }
+ else if (content_len == 0) {
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)(content_len));
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_COPYPOSTFIELDS, NULL);
+ DBG("Set the Content-Length(%d).", content_len);
+ }
+ } else {
+ DBG("The Content-Length is not set.\n");
+ }
+
+ _get_request_body_size(transaction, &body_size);
+
+ if (transaction->write_event) {
+ if (content_len >= 0 && content_len <= body_size) {
+ write_event = FALSE;
+ }
+ else {
+ write_event = TRUE;
+ }
+ DBG("The write_event is %d.\n", write_event);
+ }
+
+ if (!write_event) {
+ gchar *body = NULL;
+
+ _read_request_body(transaction, &body);
+
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_COPYPOSTFIELDS, body);
+ free(body);
+ }
+
+ if (write_event) {
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_POST, 1);
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_READFUNCTION, __handle_write_cb);
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_READDATA, transaction);
+ }
+
curl_easy_setopt(transaction->easy_handle, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(transaction->easy_handle, CURLOPT_DEBUGFUNCTION, __http_debug_received);
curl_easy_setopt(transaction->easy_handle, CURLOPT_ERRORBUFFER, transaction->error);
transaction->request->method = _get_http_method(method);
transaction->request->encoding = NULL;
- transaction->request->body = NULL;
transaction->request->http_version = HTTP_VERSION_1_1;
+ transaction->request->body_queue = g_queue_new();
+
transaction->header->header_list = NULL;
transaction->header->hash_table = NULL;
request->encoding = NULL;
}
- if (request->body != NULL) {
- free(request->body);
- request->body = NULL;
+ if (request->body_queue != NULL) {
+ g_queue_free(request->body_queue);
}
free(request);
return HTTP_ERROR_NONE;
}
-API int http_transaction_set_progress_callbacks(http_transaction_h http_transaction, http_transaction_upload_progress_cb upload_progress_cb,
+API int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_upload_progress_cb upload_progress_cb,
http_transaction_download_progress_cb download_progress_cb)
{
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
return HTTP_ERROR_NONE;
}
+
+API int http_transaction_set_ready_to_write(http_transaction_h http_transaction, bool read_to_write)
+{
+ _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(http_transaction) is NULL\n");
+
+ __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+
+ transaction->write_event = read_to_write;
+
+ return HTTP_ERROR_NONE;
+}