summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeonah Moon <seonah1.moon@samsung.com>2024-01-18 20:22:27 +0900
committerSeonah Moon <seonah1.moon@samsung.com>2024-01-18 20:22:32 +0900
commit2f3cf9964036fa8fa4030002ff21b706c8142960 (patch)
tree06392a92c8329be28523a1177feaf3ad83f4cbbd
parent6e52b90547ecde75c9b415aae75f7abd686331e8 (diff)
downloadhttp-2f3cf9964036fa8fa4030002ff21b706c8142960.tar.gz
http-2f3cf9964036fa8fa4030002ff21b706c8142960.tar.bz2
http-2f3cf9964036fa8fa4030002ff21b706c8142960.zip
- curl_formadd - CURLOPT_PROGRESSFUNCTION Change-Id: I9c07aec3ad8a5a81211a19683894692e7a0de2ac
-rw-r--r--include/http_private.h4
-rw-r--r--src/http_request.c41
-rw-r--r--src/http_transaction.c28
3 files changed, 37 insertions, 36 deletions
diff --git a/include/http_private.h b/include/http_private.h
index 22651fc..aab154e 100644
--- a/include/http_private.h
+++ b/include/http_private.h
@@ -121,8 +121,8 @@ typedef struct {
gchar *cookie;
GQueue* body_queue;
gint tot_size;
- struct curl_httppost *formpost;
- struct curl_httppost *lastptr;
+ curl_mime *multipart;
+ curl_mimepart *part;
gchar *upload_file;
FILE *fp;
curl_off_t upload_size;
diff --git a/src/http_request.c b/src/http_request.c
index 0839334..e2e4dd8 100644
--- a/src/http_request.c
+++ b/src/http_request.c
@@ -394,27 +394,26 @@ static void _add_multipart_data(http_transaction_h http_transaction,
const char *content_type, http_formdata_type_e type)
{
__http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+ CURL *handle = transaction->easy_handle;
+ _retm_if(handle == NULL, "parameter(handle) is NULL\n");
+
__http_request_h *request = transaction->request;
- CURLformoption option = CURLFORM_COPYCONTENTS;
-
- if (type == HTTP_MULTIPART_CONTENTS)
- option = CURLFORM_COPYCONTENTS;
- else if (type == HTTP_MULTIPART_FILE)
- option = CURLFORM_FILE;
-
- if (content_type) {
- curl_formadd(&(request->formpost),
- &(request->lastptr),
- CURLFORM_COPYNAME, part_name,
- option, value,
- CURLFORM_CONTENTTYPE, content_type,
- CURLFORM_END);
- } else {
- curl_formadd(&(request->formpost),
- &(request->lastptr),
- CURLFORM_COPYNAME, part_name,
- option, value,
- CURLFORM_END);
- }
+ _retm_if(request == NULL, "parameter(request) is NULL\n");
+
+ curl_mime *multipart = curl_mime_init(handle);
+ curl_mimepart *part = curl_mime_addpart(multipart);
+ curl_mime_name(part, part_name);
+
+ if (type == HTTP_MULTIPART_FILE)
+ curl_mime_filedata(part, value);
+ else
+ curl_mime_data(part, value, CURL_ZERO_TERMINATED);
+
+ if (content_type)
+ curl_mime_type(part, content_type);
+
+
+ request->multipart = multipart;
+ request->part = part;
}
//LCOV_EXCL_STOP
diff --git a/src/http_transaction.c b/src/http_transaction.c
index 0be2909..ae78051 100644
--- a/src/http_transaction.c
+++ b/src/http_transaction.c
@@ -185,7 +185,8 @@ size_t __http_debug_received(CURL *easy_handle, curl_infotype type, gchar *byte,
return 0;
}
-int __progress_cb(void *user_data, double dltotal, double dlnow, double ultotal, double ulnow)
+int __progress_cb(void *user_data,
+ curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
{
__http_transaction_h *transaction = (__http_transaction_h *)user_data;
@@ -424,12 +425,12 @@ int _transaction_submit(gpointer user_data)
if (transaction->write_event)
write_event = TRUE;
- DBG("The write_event[%d/%d] formpost[%d] upload_event[%d]\n",
+ DBG("The write_event[%d/%d] multipart[%d] upload_event[%d]\n",
transaction->write_event,
- write_event, (request->formpost) ? 1 : 0,
+ write_event, (request->multipart) ? 1 : 0,
transaction->upload_event);
- if ((_get_method(request->method) == HTTP_METHOD_POST) && !write_event && !request->formpost) {
+ if ((_get_method(request->method) == HTTP_METHOD_POST) && !write_event && !request->multipart) {
gchar *body = NULL;
ret = _read_request_body(transaction, &body);
@@ -451,8 +452,8 @@ int _transaction_submit(gpointer user_data)
}
/* Mulipart POST */
- if (request->formpost)
- curl_easy_setopt(transaction->easy_handle, CURLOPT_HTTPPOST, request->formpost);
+ if (request->multipart)
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_MIMEPOST, request->multipart);
/* Setup for PUT method */
if (transaction->upload_event) {
@@ -466,8 +467,8 @@ int _transaction_submit(gpointer user_data)
}
curl_easy_setopt(transaction->easy_handle, CURLOPT_NOPROGRESS, FALSE);
- curl_easy_setopt(transaction->easy_handle, CURLOPT_PROGRESSFUNCTION, __progress_cb);
- curl_easy_setopt(transaction->easy_handle, CURLOPT_PROGRESSDATA, transaction);
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_XFERINFOFUNCTION, __progress_cb);
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_XFERINFODATA, transaction);
curl_easy_setopt(transaction->easy_handle, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(transaction->easy_handle, CURLOPT_DEBUGFUNCTION, __http_debug_received);
@@ -588,8 +589,8 @@ API int http_session_open_transaction(http_session_h http_session, http_method_e
transaction->request->upload_size = 0;
transaction->request->upload_file = NULL;
transaction->request->fp = NULL;
- transaction->request->formpost = NULL;
- transaction->request->lastptr = NULL;
+ transaction->request->multipart = NULL;
+ transaction->request->part = NULL;
/* Response */
transaction->response->status_text = NULL;
@@ -728,9 +729,10 @@ API int http_transaction_destroy(http_transaction_h http_transaction)
if (request->body_queue != NULL)
g_queue_free(request->body_queue);
- if (request->formpost) {
- curl_formfree(request->formpost);
- request->formpost = NULL;
+ if (request->multipart) {
+ curl_mime_free(request->multipart);
+ request->multipart = NULL;
+ request->part = NULL;
}
if (request->upload_file != NULL) {