Remove deprecated curl APIs 26/304526/1 accepted/tizen_unified_riscv accepted/tizen/unified/20240122.175422 accepted/tizen/unified/riscv/20240125.032128
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 18 Jan 2024 11:22:27 +0000 (20:22 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 18 Jan 2024 11:22:32 +0000 (20:22 +0900)
- curl_formadd
- CURLOPT_PROGRESSFUNCTION

Change-Id: I9c07aec3ad8a5a81211a19683894692e7a0de2ac

include/http_private.h
src/http_request.c
src/http_transaction.c

index 22651fc661af0b30206af639cd55986658a63b71..aab154e26e093f3d9f801d3ead45445cd7bf7455 100644 (file)
@@ -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;
index 08393344515ceecd25451958a7cc51db18fd4afc..e2e4dd8ff3391156814997ca7c754a01124a2550 100644 (file)
@@ -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
index 0be290970086c47fa5b26d58d549c8612211ed18..ae780518ab2366d0214cc3ff61f10baa7fac5c36 100644 (file)
@@ -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) {