Add new API for TCP Fast Open 67/177767/9 accepted/tizen/unified/20180515.163405 submit/tizen/20180515.003743
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 3 May 2018 10:58:56 +0000 (19:58 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Mon, 14 May 2018 08:27:20 +0000 (17:27 +0900)
Change-Id: Ic459a29d1fa1100ca598726aca8f555e8c4f69e3

include/http.h
include/http_private.h
packaging/capi-network-http.spec
src/http_transaction.c
test/http_test.c

index 618904f69884622abd6d065108e17488a662f882..931d6023c3fccb83f14425b5a03c7f6ae6593598 100644 (file)
 extern "C" {
 #endif
 
-
-#ifndef TIZEN_ERROR_HTTP
-#define TIZEN_ERROR_HTTP -0x03000000
-#endif
-
-
 /**
  * @file http.h
  */
@@ -215,6 +209,8 @@ typedef enum {
 /**
  * @brief Called when the HTTP header is received.
  * @since_tizen 3.0
+ * @remarks The @a header should be released using free(). \n
+ *          The @a header is available until @a http_transaction is released.
  * @param[in] http_transaction The HTTP transaction handle
  * @param[in] header The header information of HTTP Transaction
  * @param[in] header_len The length of the HTTP Transaction header
@@ -261,11 +257,11 @@ typedef void (*http_transaction_completed_cb)(http_transaction_h http_transactio
 /**
  * @brief Called when the HTTP transaction is aborted.
  * @details Following error codes can be delivered. \n
- *                 #HTTP_ERROR_OPERATION_FAILED, \n
- *                 #HTTP_ERROR_COULDNT_RESOLVE_HOST, \n
- *                 #HTTP_ERROR_COULDNT_CONNECT, \n
- *                 #HTTP_ERROR_OPERATION_TIMEDOUT, \n
- *                 #HTTP_ERROR_SSL_CONNECT_ERROR.
+ *          #HTTP_ERROR_OPERATION_FAILED, \n
+ *          #HTTP_ERROR_COULDNT_RESOLVE_HOST, \n
+ *          #HTTP_ERROR_COULDNT_CONNECT, \n
+ *          #HTTP_ERROR_OPERATION_TIMEDOUT, \n
+ *          #HTTP_ERROR_SSL_CONNECT_ERROR.
  * @since_tizen 3.0
  * @param[in] http_transaction The HTTP transaction handle
  * @param[in] error The error code about aborted reason
@@ -330,9 +326,9 @@ int http_deinit(void);
  * @brief Creates the HTTP session handle.
  * @since_tizen 3.0
  * @remarks The @a http_session should be released using http_session_destroy().
- *                     Opened transactions can't be submitted after destroying session handle.
+ *          Opened transactions can't be submitted after destroying session handle.
  * @param[in] mode The HTTP session mode
- * @param[out] http_session    The HTTP session handle
+ * @param[out] http_session The HTTP session handle
  * @return @c 0 on success,
  *         otherwise negative error value
  * @retval #HTTP_ERROR_NONE Successful
@@ -415,7 +411,7 @@ int http_session_get_auto_redirection(http_session_h http_session, bool *auto_re
  * @brief Gets the number of active transactions in the current session.
  * @since_tizen 3.0
  * @param[in] http_session The HTTP session handle
- * @param[out] active_transaction_count        The number of activated transactions
+ * @param[out] active_transaction_count The number of activated transactions
  * @return @c 0 on success,
  *         otherwise negative error value
  * @retval #HTTP_ERROR_NONE Successful
@@ -473,7 +469,7 @@ int http_session_destroy_all_transactions(http_session_h http_session);
  * @since_tizen 3.0
  * @privlevel public
  * @privilege %http://tizen.org/privilege/internet \n
- *                       %http://tizen.org/privilege/network.get
+ *            %http://tizen.org/privilege/network.get
  * @param[in] http_transaction The HTTP transaction handle
  * @return @c 0 on success,
  *         otherwise negative error value
@@ -489,8 +485,8 @@ int http_transaction_submit(http_transaction_h http_transaction);
 /**
  * @brief Closes the HTTP transaction handle.
  * @since_tizen 3.0
- * @remarks The @a transaction is released by http_transaction_destroy().
- *                     http_transaction should be set to NULL after using it.
+ * @remarks The @a http_transaction is released by http_transaction_destroy().
+ *          http_transaction should be set to NULL after using it.
  * @param[in] http_transaction The HTTP transaction handle
  * @return @c 0 on success,
  *         otherwise negative error value
@@ -506,8 +502,8 @@ int http_transaction_destroy(http_transaction_h http_transaction);
 /**
  * @brief Registers callback called when receives header.
  * @since_tizen 3.0
- * @param[in] http_transaction The HTTP transaction handle
- * @param[in] header_cb The callback function to be called
+ * @param[in] http_transaction        The HTTP transaction handle
+ * @param[in] header_cb The callback  function to be called
  * @param[in] user_data The user data passed to the callback function
  * @return @c 0 on success,
  *         otherwise negative error value
@@ -665,7 +661,7 @@ int http_transaction_pause(http_transaction_h http_transaction, http_pause_type_
 /**
  * @brief Cancels the transaction.
  * @details This function cancels the transaction.\n
- *                     The aborted callback is invoked after using it.
+ *          The aborted callback is invoked after using it.
  * @since_tizen 3.0
  * @param[in] http_transaction The HTTP transaction handle
  * @return @c 0 on success,
@@ -755,6 +751,34 @@ int http_transaction_set_server_certificate_verification(http_transaction_h http
 int http_transaction_get_server_certificate_verification(http_transaction_h http_transaction, bool* verify);
 
 
+/**
+ * @brief Sets the flag to allow TCP Fast Open.
+ * @since_tizen 5.0
+ * @param[in] http_transaction The HTTP transaction handle
+ * @param[in] enable The flag to enable TCP Fast Open
+ * @return @c 0 on success,
+ *         otherwise negative error value
+ * @retval #HTTP_ERROR_NONE Successful
+ * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
+ */
+int http_transaction_set_tcp_fastopen(http_transaction_h http_transaction, bool enable);
+
+/**
+ * @brief Gets the flag to allow TCP Fast Open.
+ * @since_tizen 5.0
+ * @param[in] http_transaction The HTTP transaction handle
+ * @param[out] enable The flag to enable TCP Fast Open
+ * @return @c 0 on success,
+ *         otherwise negative error value
+ * @retval #HTTP_ERROR_NONE Successful
+ * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
+ */
+int http_transaction_get_tcp_fastopen(http_transaction_h http_transaction, bool *enable);
+
 /**
  * @}
  */
@@ -992,7 +1016,7 @@ int http_transaction_request_get_cookie(http_transaction_h http_transaction, cha
 /**
  * @brief Writes the request message body.
  * @details This function writes the request message body in the internal queue. \n
- *                     The written queue for request body is uploaded after invoking http_transaction_submit().
+ *          The written queue for request body is uploaded after invoking http_transaction_submit().
  * @since_tizen 3.0
  * @param[in] http_transaction The HTTP transaction handle
  * @param[in] body The message body data
@@ -1019,6 +1043,7 @@ int http_transaction_request_write_body(http_transaction_h http_transaction, con
  * @retval #HTTP_ERROR_INVALID_PARAMETER  Invalid parameter
  * @retval #HTTP_ERROR_INVALID_OPERATION  Invalid operation
  * @retval #HTTP_ERROR_NOT_SUPPORTED  Not Supported
+ * @retval #HTTP_ERROR_PERMISSION_DENIED Permission denied
  */
 int http_transaction_request_set_upload_file(http_transaction_h http_transaction, const char *file_path);
 
index aa25e3499728d75cac27d79f783a151096da39fc..22651fc661af0b30206af639cd55986658a63b71 100644 (file)
@@ -153,6 +153,8 @@ typedef struct {
        bool upload_event;
        bool verify_peer;
        gchar *ca_path;
+       bool tcp_fastopen;
+
        gchar error[CURL_ERROR_SIZE];
        bool cancel;
 
index ecc64c04edefc10432b91b967ae20bd3b653c80f..d2fa6592f5303704aee68a32304a8932aee38fb0 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-http
 Summary:       Http Framework
-Version:       0.0.32
+Version:       0.0.33
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
index 396a21f6f1f152101e412906fe29fd918b3cfbae..41acb26368c7fdb928312c4897d5db977e27d621 100644 (file)
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <linux/version.h>
+
 #include "http.h"
 #include "http_private.h"
 
@@ -389,6 +391,9 @@ int _transaction_submit(gpointer user_data)
        }
        //LCOV_EXCL_STOP
 
+       if (transaction->tcp_fastopen)
+               curl_easy_setopt(transaction->easy_handle, CURLOPT_TCP_FASTOPEN, 1L);
+
        curl_easy_setopt(transaction->easy_handle, CURLOPT_HEADERFUNCTION, __handle_header_cb);
        curl_easy_setopt(transaction->easy_handle, CURLOPT_HEADERDATA, transaction);
 
@@ -529,6 +534,7 @@ API int http_session_open_transaction(http_session_h http_session, http_method_e
        transaction->upload_event = FALSE;
        transaction->verify_peer = TRUE;
        transaction->ca_path = g_strdup(HTTP_DEFAULT_CA_PATH);
+       transaction->tcp_fastopen = 0;
        transaction->error[0] = '\0';
        transaction->cancel = 0;
 
@@ -649,6 +655,7 @@ API int http_transaction_destroy(http_transaction_h http_transaction)
 
                transaction->timeout = 0;
                transaction->verify_peer = 0;
+               transaction->tcp_fastopen = 0;
 
                if (transaction->ca_path) {
                        free(transaction->ca_path);
@@ -1034,6 +1041,38 @@ API int http_transaction_set_server_certificate_verification(http_transaction_h
        return HTTP_ERROR_NONE;
 }
 
+API int http_transaction_get_tcp_fastopen(http_transaction_h http_transaction, bool *enable)
+{
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+                       "http isn't initialized");
+       _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
+                       "parameter(http_transaction) is NULL\n");
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0)
+       return HTTP_ERROR_NOT_SUPPORTED;
+#else
+       __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+       *enable = transaction->tcp_fastopen;
+       return HTTP_ERROR_NONE;
+#endif
+}
+
+API int http_transaction_set_tcp_fastopen(http_transaction_h http_transaction, bool enable)
+{
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+                       "http isn't initialized");
+       _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
+                       "parameter(http_transaction) is NULL\n");
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0)
+       return HTTP_ERROR_NOT_SUPPORTED;
+#else
+       __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+       transaction->tcp_fastopen = enable;
+       return HTTP_ERROR_NONE;
+#endif
+}
+
 //LCOV_EXCL_START
 API int http_transaction_set_http_auth_scheme(http_transaction_h http_transaction, http_auth_scheme_e auth_scheme)
 {
index 19ded4599aee74e14b4c601850001ad762d40b42..bb3ae2780501c124481d157040e593232e108148 100644 (file)
@@ -226,6 +226,7 @@ int test_simple_get(void)
        int ret;
        http_transaction_h transaction = NULL;
        http_method_e method;
+       int tfo = false;
 
        printf("Input uri: ");
        ret = scanf("%1023s", uri);
@@ -243,6 +244,15 @@ int test_simple_get(void)
                return 0;
        }
 
+       printf("TCP Fast Oepn(0: disable, 1: enable): ");
+       ret = scanf("%1d", &tfo);
+
+       ret = http_transaction_set_tcp_fastopen(transaction, tfo);
+       if (ret != 0) {
+               ERR("Fail to set tfo", ret);
+               return 0;
+       }
+
        _register_callbacks(transaction);
        ret = http_transaction_submit(transaction);
        if (ret != 0) {