Add checking code for initialize 47/65947/5
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 14 Apr 2016 07:04:04 +0000 (16:04 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Wed, 20 Apr 2016 09:04:17 +0000 (18:04 +0900)
Change-Id: I4e9cb86aed34cec256f837d5a1d8517019298605
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
include/http.h
include/http_private.h
src/http_common.c
src/http_header.c
src/http_request.c
src/http_response.c
src/http_session.c
src/http_transaction.c
test/http_test.c

index 987e32dab7098abc2fbb73d34fecba0b82bc0e0f..45632f00c130c018bb5752e70642ae8166202f11 100644 (file)
@@ -250,13 +250,10 @@ typedef void (*http_transaction_progress_cb)(http_transaction_h http_transaction
 /**
  * @brief Initializes the Http module.
  * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
  * @return 0 on success, otherwise negative error value
  * @retval  #HTTP_ERROR_NONE  Successful
  * @retval  #HTTP_ERROR_OPERATION_FAILED Operation failed
  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
- * @retval  #HTTP_ERROR_PERMISSION_DENIED Permission denied
  * @see                http_deinit()
  */
 int http_init(void);
@@ -284,12 +281,14 @@ 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().
+ * @remarks The @a http_session should be released using http_session_destroy(). \
+ *                     Opened transactions can't be submitted after destroing session handle.
  * @param[in]   mode            The http session mode
  * @param[out]  http_session   The http session handle
  * @return 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_OUT_OF_MEMORY  Out of memory
  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
  * @see        http_session_destroy()
@@ -303,6 +302,7 @@ int http_session_create(http_session_mode_e mode, http_session_h *http_session);
  * @return 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
  * @see     http_session_create()
  */
@@ -318,6 +318,7 @@ int http_session_destroy(http_session_h http_session);
  * @return 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_OUT_OF_MEMORY  Out of memory
  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
  */
@@ -331,6 +332,7 @@ int http_session_open_transaction(http_session_h http_session, http_method_e met
  * @return 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
  * @see                http_session_get_auto_redirection()
  */
@@ -344,6 +346,7 @@ int http_session_set_auto_redirection(http_session_h http_session, bool auto_red
  * @return 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
  * @see     http_session_set_auto_redirection()
  */
@@ -357,6 +360,7 @@ int http_session_get_auto_redirection(http_session_h http_session, bool *auto_re
  * @return 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_session_get_active_transaction_count(http_session_h http_session, int *active_transaction_count);
@@ -369,6 +373,7 @@ int http_session_get_active_transaction_count(http_session_h http_session, int *
  * @return 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_session_get_max_transaction_count(http_session_h http_session, int *transaction_count);
@@ -380,6 +385,7 @@ int http_session_get_max_transaction_count(http_session_h http_session, int *tra
  * @return 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_OPERATION_fAILED  Operation failed
  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
  */
@@ -396,12 +402,15 @@ int http_session_destroy_all_transactions(http_session_h http_session);
 /**
  * @brief Submits the Http request.
  * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
  * @param[in]  http_transaction  The http transaction handle
  * @return 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
+ * @retval  #HTTP_ERROR_PERMISSION_DENIED Permission denied
  */
 int http_transaction_submit(http_transaction_h http_transaction);
 
@@ -414,6 +423,7 @@ int http_transaction_submit(http_transaction_h http_transaction);
  * @return 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
  * @see                http_transaction_create()
  */
@@ -428,6 +438,7 @@ int http_transaction_destroy(http_transaction_h http_transaction);
  * @return 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_received_header_cb(http_transaction_h http_transaction, http_transaction_header_cb header_cb, void* user_data);
@@ -441,6 +452,7 @@ int http_transaction_set_received_header_cb(http_transaction_h http_transaction,
  * @return 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_received_body_cb(http_transaction_h http_transaction, http_transaction_body_cb body_cb, void* user_data);
@@ -454,6 +466,7 @@ int http_transaction_set_received_body_cb(http_transaction_h http_transaction, h
  * @return 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_uploaded_cb(http_transaction_h http_transaction, http_transaction_write_cb write_cb, void* user_data);
@@ -467,6 +480,7 @@ int http_transaction_set_uploaded_cb(http_transaction_h http_transaction, http_t
  * @return 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_completed_cb(http_transaction_h http_transaction, http_transaction_completed_cb completed_cb, void* user_data);
@@ -480,6 +494,7 @@ int http_transaction_set_completed_cb(http_transaction_h http_transaction, http_
  * @return 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_aborted_cb(http_transaction_h http_http_transaction, http_transaction_aborted_cb aborted_cb, void* user_data);
@@ -495,6 +510,7 @@ int http_transaction_set_aborted_cb(http_transaction_h http_http_transaction, ht
  * @return 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_progress_cb(http_transaction_h http_transaction, http_transaction_progress_cb progress_cb, void* user_data);
@@ -509,6 +525,7 @@ int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_t
  * @return 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_timeout(http_transaction_h http_transaction, int timeout);
@@ -521,6 +538,7 @@ int http_transaction_set_timeout(http_transaction_h http_transaction, int timeou
  * @return 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_timeout(http_transaction_h http_transaction, int *timeout);
@@ -532,6 +550,7 @@ int http_transaction_get_timeout(http_transaction_h http_transaction, int *timeo
  * @return 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_OPERATION_FAILED  Operation failed
  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
  */
@@ -545,6 +564,7 @@ int http_transaction_resume(http_transaction_h http_transaction);
  * @return 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_OPERATION_FAILED  Operation failed
  * @retval  #HTTP_ERROR_NOT_SUPPORTED  Not Supported
  */
@@ -558,6 +578,7 @@ int http_transaction_pause(http_transaction_h http_transaction, http_pause_type_
  * @return 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_ready_to_write(http_transaction_h http_transaction, bool read_to_write);
@@ -570,6 +591,7 @@ int http_transaction_set_ready_to_write(http_transaction_h http_transaction, boo
  * @return 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_interface_name(http_transaction_h http_transaction, const char *interface_name);
@@ -583,6 +605,7 @@ int http_transaction_set_interface_name(http_transaction_h http_transaction, con
  * @return 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_interface_name(http_transaction_h http_transaction, char **interface_name);
@@ -596,6 +619,7 @@ int http_transaction_get_interface_name(http_transaction_h http_transaction, cha
  * @return 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_server_certificate_verification(http_transaction_h http_transaction, bool verify);
@@ -608,6 +632,7 @@ int http_transaction_set_server_certificate_verification(http_transaction_h http
  * @return 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_server_certificate_verification(http_transaction_h http_transaction, bool* verify);
@@ -622,6 +647,7 @@ int http_transaction_get_server_certificate_verification(http_transaction_h http
  * @return 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_header_add_field(http_transaction_h http_transaction, const char *field_name, const char* field_value);
@@ -674,6 +700,7 @@ int http_transaction_header_get_field_value(http_transaction_h http_transaction,
  * @return 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_request_set_method(http_transaction_h http_transaction, http_method_e method);
@@ -686,6 +713,7 @@ int http_transaction_request_set_method(http_transaction_h http_transaction, htt
  * @return 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_request_get_method(http_transaction_h http_transaction, http_method_e *method);
@@ -699,6 +727,7 @@ int http_transaction_request_get_method(http_transaction_h http_transaction, htt
  * @return 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_request_set_version(http_transaction_h http_transaction, http_version_e version);
@@ -712,6 +741,7 @@ int http_transaction_request_set_version(http_transaction_h http_transaction, ht
  * @return 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_request_get_version(http_transaction_h http_transaction, http_version_e *version);
@@ -726,6 +756,7 @@ int http_transaction_request_get_version(http_transaction_h http_transaction, ht
  * @return 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_request_set_uri(http_transaction_h http_transaction, const char *host_uri);
@@ -739,6 +770,7 @@ int http_transaction_request_set_uri(http_transaction_h http_transaction, const
  * @return 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_request_get_uri(http_transaction_h http_transaction, char **host_uri);
@@ -753,6 +785,7 @@ int http_transaction_request_get_uri(http_transaction_h http_transaction, char *
  * @return 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_request_set_accept_encoding(http_transaction_h http_transaction, const char *encoding);
@@ -766,6 +799,7 @@ int http_transaction_request_set_accept_encoding(http_transaction_h http_transac
  * @return 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_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding);
@@ -779,6 +813,7 @@ int http_transaction_request_get_accept_encoding(http_transaction_h http_transac
  * @return 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_request_set_cookie(http_transaction_h http_transaction, const char *cookie);
@@ -792,18 +827,22 @@ int http_transaction_request_set_cookie(http_transaction_h http_transaction, con
  * @return 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_request_get_cookie(http_transaction_h http_transaction, const char **cookie);
 
 /**
- * @brief Sets the request message body.
+ * @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() 
  * @since_tizen 3.0
  * @param[in]  http_transaction The http transaction handle
  * @param[in]  body                    The message body data
  * @return 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_request_write_body(http_transaction_h http_transaction, const char *body);
@@ -825,6 +864,7 @@ int http_transaction_request_write_body(http_transaction_h http_transaction, con
  * @return 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_response_get_status_code(http_transaction_h http_transaction, http_status_code_e *status_code);
@@ -838,6 +878,7 @@ int http_transaction_response_get_status_code(http_transaction_h http_transactio
  * @return 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_response_get_status_text(http_transaction_h http_transaction, char **status_text);
@@ -850,6 +891,7 @@ int http_transaction_response_get_status_text(http_transaction_h http_transactio
  * @return 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_response_get_version(http_transaction_h http_transaction, http_version_e *version);
index c7bfc0e79c23d5b3ee6a0187aaf96ef6b5315c1e..f0e26fa1a473acb419add05feada5400103cbad7 100644 (file)
@@ -167,6 +167,7 @@ typedef struct {
 
 
 void print_curl_multi_errorCode(CURLMcode code);
+bool _http_is_init(void);
 gchar* _get_http_method(http_method_e method);
 http_method_e _get_method(gchar* method);
 gchar* _get_proxy();
index 66e3361d20d89e6c855bf13b007a216196e5dd82..d3634734f8ef14642e1970914e30b3481499c17c 100644 (file)
 #define THREAD_ID        pthread_self()
 
 /* This array will store all of the mutexes available to OpenSSL. */
-static MUTEX_TYPE *mutex_buf= NULL;
+static MUTEX_TYPE *mutex_buf = NULL;
+static bool is_init = false;
+
+bool _http_is_init(void)
+{
+       return is_init;
+}
+
+static void __http_set_init(bool init)
+{
+       is_init = init;
+}
 
 http_method_e _get_method(gchar* method)
 {
-       if (g_strcmp0(method, "GET") == 0) {
+       if (g_strcmp0(method, "GET") == 0)
                return HTTP_METHOD_GET;
-       } else if (g_strcmp0(method, "OPTIONS") == 0) {
+       else if (g_strcmp0(method, "OPTIONS") == 0)
                return HTTP_METHOD_OPTIONS;
-       } else if (g_strcmp0(method, "HEAD") == 0) {
+       else if (g_strcmp0(method, "HEAD") == 0)
                return HTTP_METHOD_HEAD;
-       } else if (g_strcmp0(method, "DELETE") == 0) {
+       else if (g_strcmp0(method, "DELETE") == 0)
                return HTTP_METHOD_DELETE;
-       } else if (g_strcmp0(method, "TRACE") == 0) {
+       else if (g_strcmp0(method, "TRACE") == 0)
                return HTTP_METHOD_TRACE;
-       } else if (g_strcmp0(method, "POST") == 0) {
+       else if (g_strcmp0(method, "POST") == 0)
                return HTTP_METHOD_POST;
-       } else if (g_strcmp0(method, "PUT") == 0) {
+       else if (g_strcmp0(method, "PUT") == 0)
                return HTTP_METHOD_PUT;
-       } else if (g_strcmp0(method, "CONNECT") == 0) {
+       else if (g_strcmp0(method, "CONNECT") == 0)
                return HTTP_METHOD_CONNECT;
-       }
 
        return HTTP_METHOD_GET;
 }
@@ -148,9 +158,8 @@ gchar* _get_proxy()
        }
 
 CATCH:
-       if (connection_destroy(connection) < 0) {
+       if (connection_destroy(connection) < 0)
                DBG("Fail to destroy network handle\n");
-       }
 
        return proxy_addr;
 }
@@ -176,9 +185,9 @@ int thread_setup(void)
        if (!mutex_buf)
                return 0;
 
-       for (index = 0;  index < CRYPTO_num_locks();  index++) {
+       for (index = 0;  index < CRYPTO_num_locks();  index++)
                MUTEX_SETUP(mutex_buf[index]);
-       }
+
        CRYPTO_set_id_callback(id_function);
        CRYPTO_set_locking_callback(locking_function);
 
@@ -195,9 +204,8 @@ int thread_cleanup(void)
        CRYPTO_set_id_callback(NULL);
        CRYPTO_set_locking_callback(NULL);
 
-       for (index = 0;  index < CRYPTO_num_locks();  index++) {
+       for (index = 0;  index < CRYPTO_num_locks();  index++)
                MUTEX_CLEANUP(mutex_buf[index]);
-       }
 
        free(mutex_buf);
        mutex_buf = NULL;
@@ -207,8 +215,13 @@ int thread_cleanup(void)
 
 API int http_init(void)
 {
+       _retvm_if(_http_is_init(), HTTP_ERROR_INVALID_OPERATION,
+                       "http is already initialized!!");
+
        int ret = 0;
 
+       __http_set_init(true);
+
        if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
                DBG("curl_global_init failed, so returning!\n");
                return HTTP_ERROR_OPERATION_FAILED;
@@ -225,8 +238,13 @@ API int http_init(void)
 
 API int http_deinit(void)
 {
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+                       "http is already deinitialized!!");
+
        int ret = 0;
 
+       __http_set_init(false);
+
        ret = thread_cleanup();
        if (!ret) {
                DBG("ssl thread de-initialization failed!\n");
index 182db5f4a39aee757b8bcd05b7f70ed09dc9c3f0..6fd5a79b3a4e0ac2653ad34b5f936dc0559a4642 100644 (file)
@@ -27,9 +27,8 @@ struct curl_slist* _get_header_list(http_transaction_h http_transaction)
        gpointer key = NULL;
        gpointer value = NULL;
 
-       if (!header->hash_table) {
+       if (!header->hash_table)
                return NULL;
-       }
 
        g_hash_table_iter_init(&iter, header->hash_table);
 
@@ -46,6 +45,8 @@ struct curl_slist* _get_header_list(http_transaction_h http_transaction)
 
 API int http_transaction_header_add_field(http_transaction_h http_transaction, const char *field_name, const char* field_value)
 {
+       _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");
        _retvm_if(field_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -56,17 +57,18 @@ API int http_transaction_header_add_field(http_transaction_h http_transaction, c
        __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
        __http_header_h *header = transaction->header;
 
-       if (!header->hash_table) {
+       if (!header->hash_table)
                header->hash_table = g_hash_table_new(g_str_hash, g_str_equal);
-       }
 
-       g_hash_table_insert(header->hash_table, (char*)field_name, (char*)field_value);
+       g_hash_table_insert(header->hash_table, g_strdup(field_name), g_strdup(field_value));
 
        return HTTP_ERROR_NONE;
 }
 
 API int http_transaction_header_remove_field(http_transaction_h http_transaction, const char *field_name)
 {
+       _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");
        _retvm_if(field_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -74,11 +76,19 @@ API int http_transaction_header_remove_field(http_transaction_h http_transaction
 
        __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
        __http_header_h *header = transaction->header;
+       gpointer orig_key = NULL;
+       gpointer orig_value = NULL;
 
+       g_hash_table_lookup_extended(header->hash_table, field_name, &orig_key, &orig_value);
        if (g_hash_table_remove(header->hash_table, field_name)) {
+               if (orig_key)
+                       g_free(orig_key);
+
+               if (orig_value)
+                       g_free(orig_value);
+
                return HTTP_ERROR_NONE;
-       }
-       else {
+       } else {
                ERR("field_name doesn't exist!!");
                return HTTP_ERROR_INVALID_OPERATION;
        }
@@ -86,6 +96,8 @@ API int http_transaction_header_remove_field(http_transaction_h http_transaction
 
 API int http_transaction_header_get_field_value(http_transaction_h http_transaction, const char *field_name, char **field_value)
 {
+       _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");
        _retvm_if(field_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -95,17 +107,19 @@ API int http_transaction_header_get_field_value(http_transaction_h http_transact
 
        __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
        __http_header_h *header = transaction->header;
+       const char *value;
 
        if (header->hash_table == NULL) {
                *field_value = NULL;
                return HTTP_ERROR_INVALID_OPERATION;
        }
 
-       *field_value = g_hash_table_lookup(header->hash_table, field_name);
-       if (*field_value == NULL) {
+       value = g_hash_table_lookup(header->hash_table, field_name);
+       if (value == NULL) {
                ERR("filed_name doesn't exist!!");
                return HTTP_ERROR_INVALID_OPERATION;
        }
+       *field_value = g_strdup(value);
 
        return HTTP_ERROR_NONE;
 }
index 9c837576f74511337b0177e818b1d2b2f6f64a84..4d04e07489bcb921f1757a464751f620e12cc619 100644 (file)
@@ -19,6 +19,8 @@
 
 API int http_transaction_request_set_method(http_transaction_h http_transaction, http_method_e method)
 {
+       _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");
 
@@ -37,6 +39,8 @@ API int http_transaction_request_set_method(http_transaction_h http_transaction,
 
 API int http_transaction_request_get_method(http_transaction_h http_transaction, http_method_e *method)
 {
+       _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");
        _retvm_if(method == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -52,6 +56,8 @@ API int http_transaction_request_get_method(http_transaction_h http_transaction,
 
 API int http_transaction_request_set_version(http_transaction_h http_transaction, http_version_e version)
 {
+       _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");
 
@@ -65,6 +71,8 @@ API int http_transaction_request_set_version(http_transaction_h http_transaction
 
 API int http_transaction_request_get_version(http_transaction_h http_transaction, http_version_e *version)
 {
+       _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");
        _retvm_if(version == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -80,6 +88,8 @@ API int http_transaction_request_get_version(http_transaction_h http_transaction
 
 API int http_transaction_request_set_uri(http_transaction_h http_transaction, const char *host_uri)
 {
+       _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");
        _retvm_if(host_uri == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -95,6 +105,8 @@ API int http_transaction_request_set_uri(http_transaction_h http_transaction, co
 
 API int http_transaction_request_get_uri(http_transaction_h http_transaction, char **host_uri)
 {
+       _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");
        _retvm_if(host_uri == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -115,6 +127,8 @@ API int http_transaction_request_get_uri(http_transaction_h http_transaction, ch
 
 API int http_transaction_request_set_accept_encoding(http_transaction_h http_transaction, const char *encoding)
 {
+       _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");
        _retvm_if(encoding == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -130,6 +144,8 @@ API int http_transaction_request_set_accept_encoding(http_transaction_h http_tra
 
 API int http_transaction_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding)
 {
+       _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");
        _retvm_if(encoding == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -149,6 +165,8 @@ API int http_transaction_request_get_accept_encoding(http_transaction_h http_tra
 
 API int http_transaction_request_set_cookie(http_transaction_h http_transaction, const char *cookie)
 {
+       _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");
        _retvm_if(cookie == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -164,6 +182,8 @@ API int http_transaction_request_set_cookie(http_transaction_h http_transaction,
 
 API int http_transaction_request_get_cookie(http_transaction_h http_transaction, const char **cookie)
 {
+       _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");
        _retvm_if(cookie == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -183,6 +203,8 @@ API int http_transaction_request_get_cookie(http_transaction_h http_transaction,
 
 API int http_transaction_request_write_body(http_transaction_h http_transaction, const char *body)
 {
+       _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");
        _retvm_if(body == NULL, HTTP_ERROR_INVALID_PARAMETER,
index 7b646799c85de132240ed746570f99b521eb4a92..03e955860c5c6153a4902168a93cad34fd3ad1c5 100644 (file)
@@ -39,7 +39,6 @@ void __parse_response_header(char *buffer, size_t written, gpointer user_data)
        __http_response_h*response = (__http_response_h *)transaction->response;
 
        char status_code[HTTP_STATUS_CODE_SIZE] = {0, };
-       //char reason_phrase[HTTP_REASON_PHRASE_SIZE] = {0, };
        char* start = NULL;
        char* end = NULL;
 
@@ -67,6 +66,8 @@ void __parse_response_header(char *buffer, size_t written, gpointer user_data)
 
 API int http_transaction_response_get_status_code(http_transaction_h http_transaction, http_status_code_e *status_code)
 {
+       _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");
        _retvm_if(status_code == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -82,6 +83,8 @@ API int http_transaction_response_get_status_code(http_transaction_h http_transa
 
 API int http_transaction_response_get_status_text(http_transaction_h http_transaction, char **status_text)
 {
+       _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");
        _retvm_if(status_text == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -97,6 +100,8 @@ API int http_transaction_response_get_status_text(http_transaction_h http_transa
 
 API int http_transaction_response_get_version(http_transaction_h http_transaction, http_version_e *version)
 {
+       _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");
        _retvm_if(version == NULL, HTTP_ERROR_INVALID_PARAMETER,
index 8255d5adc190183d22d30c4d4e2f0ab0554cc232..36780fe9482619f9389f32c797746d429008798d 100644 (file)
@@ -40,28 +40,28 @@ void _check_curl_multi_status(gpointer user_data)
                        DBG("Completed -%s: result(%d)\n", url, curl_code);
 
                        switch (curl_code) {
-                               case CURLE_OK:
-                                       if (transaction->completed_cb)
-                                               transaction->completed_cb(transaction, transaction->completed_user_data);
-                                       break;
-                               case CURLE_COULDNT_RESOLVE_HOST:
-                                       if (transaction->aborted_cb)
-                                               transaction->aborted_cb(transaction, HTTP_ERROR_COULDNT_RESOLVE_HOST, transaction->aborted_user_data);
-                                       break;
-                               case CURLE_COULDNT_CONNECT:
-                                       if (transaction->aborted_cb)
-                                               transaction->aborted_cb(transaction, HTTP_ERROR_COULDNT_CONNECT, transaction->aborted_user_data);
-                                       break;
-                               case CURLE_SSL_CONNECT_ERROR:
-                                       if (transaction->aborted_cb)
-                                               transaction->aborted_cb(transaction, HTTP_ERROR_SSL_CONNECT_ERROR, transaction->aborted_user_data);
-                                       break;
-                               case CURLE_OPERATION_TIMEDOUT:
-                                       if (transaction->aborted_cb)
-                                               transaction->aborted_cb(transaction, HTTP_ERROR_OPERATION_TIMEDOUT, transaction->aborted_user_data);
-                                       break;
-                               default:
-                                       break;
+                       case CURLE_OK:
+                               if (transaction->completed_cb)
+                                       transaction->completed_cb(transaction, transaction->completed_user_data);
+                               break;
+                       case CURLE_COULDNT_RESOLVE_HOST:
+                               if (transaction->aborted_cb)
+                                       transaction->aborted_cb(transaction, HTTP_ERROR_COULDNT_RESOLVE_HOST, transaction->aborted_user_data);
+                               break;
+                       case CURLE_COULDNT_CONNECT:
+                               if (transaction->aborted_cb)
+                                       transaction->aborted_cb(transaction, HTTP_ERROR_COULDNT_CONNECT, transaction->aborted_user_data);
+                               break;
+                       case CURLE_SSL_CONNECT_ERROR:
+                               if (transaction->aborted_cb)
+                                       transaction->aborted_cb(transaction, HTTP_ERROR_SSL_CONNECT_ERROR, transaction->aborted_user_data);
+                               break;
+                       case CURLE_OPERATION_TIMEDOUT:
+                               if (transaction->aborted_cb)
+                                       transaction->aborted_cb(transaction, HTTP_ERROR_OPERATION_TIMEDOUT, transaction->aborted_user_data);
+                               break;
+                       default:
+                               break;
                        }
 
                        curl_multi_remove_handle(session->multi_handle, curl_easy);
@@ -84,11 +84,10 @@ gboolean timer_expired_callback(gpointer user_data)
        CURLMcode ret;
 
        ret = curl_multi_socket_action(session->multi_handle, CURL_SOCKET_TIMEOUT, 0, &(session->still_running));
-       if (ret == CURLM_OK) {
-               //DBG("CURLM_OK - Called curl_multi_socket_action()\n");
-       } else {
+       if (ret == CURLM_OK)
+               /* DBG("CURLM_OK - Called curl_multi_socket_action()\n"); */
+       else
                print_curl_multi_errorCode(ret);
-       }
 
        _check_curl_multi_status(session);
 
@@ -104,11 +103,10 @@ gboolean _handle_event(int fd, int action, gpointer user_data)
        CURLMcode ret = CURLM_OK;
 
        ret = curl_multi_socket_action(session->multi_handle, fd, action, &running_handles);
-       if (ret == CURLM_OK) {
-               //DBG("CURLM_OK: Called curl_multi_socket_action(%d)\n", action);
-       } else {
+       if (ret == CURLM_OK)
+               /* DBG("CURLM_OK: Called curl_multi_socket_action(%d)\n", action); */
+       else
                print_curl_multi_errorCode(ret);
-       }
 
        _check_curl_multi_status(session);
 
@@ -133,13 +131,12 @@ gboolean __handle_socket_received_event_cb(GIOChannel *channel, GIOCondition con
 
        fd = g_io_channel_unix_get_fd(channel);
 
-       //CURL_CSELECT_IN : 1, CURL_CSELECT_OUT: 2
+       /* CURL_CSELECT_IN : 1, CURL_CSELECT_OUT: 2 */
        action = (condition & G_IO_IN ? CURL_CSELECT_IN : 0) | (condition & G_IO_OUT ? CURL_CSELECT_OUT : 0);
 
        ret = _handle_event(fd, action, user_data);
-       if (ret) {
+       if (ret)
                return TRUE;
-       }
 
        return FALSE;
 }
@@ -147,9 +144,9 @@ gboolean __handle_socket_received_event_cb(GIOChannel *channel, GIOCondition con
 /* Clean up the __http_socket_info_h structure */
 static void _remove_socket_info(__http_socket_info_h *sock_info)
 {
-       if (!sock_info) {
+       if (!sock_info)
                return;
-       }
+
        if (sock_info->event) {
                g_source_remove(sock_info->event);
                sock_info->event = 0;
@@ -226,6 +223,8 @@ int __handle_timer_cb(CURLM *curl_multi, long timeout_ms, void *user_data)
 
 API int http_session_create(http_session_mode_e mode, http_session_h *http_session)
 {
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+                       "http isn't initialized");
        _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
                        "parameter(http_session) is NULL\n");
 
@@ -248,9 +247,8 @@ API int http_session_create(http_session_mode_e mode, http_session_h *http_sessi
        curl_multi_setopt(session->multi_handle, CURLMOPT_TIMERFUNCTION, __handle_timer_cb);
        curl_multi_setopt(session->multi_handle, CURLMOPT_TIMERDATA, session);
 
-       if (mode == HTTP_SESSION_MODE_PIPELINING) {
+       if (mode == HTTP_SESSION_MODE_PIPELINING)
                curl_multi_setopt(session->multi_handle, CURLMOPT_PIPELINING, 1L);
-       }
 
        *http_session = (http_session_h)session;
 
@@ -259,6 +257,8 @@ API int http_session_create(http_session_mode_e mode, http_session_h *http_sessi
 
 API int http_session_destroy(http_session_h http_session)
 {
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+                       "http isn't initialized");
        _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
                        "parameter(http_session) is NULL\n");
 
@@ -280,6 +280,8 @@ API int http_session_destroy(http_session_h http_session)
 
 API int http_session_set_auto_redirection(http_session_h http_session, bool auto_redirection)
 {
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+                       "http isn't initialized");
        _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
                        "parameter(http_session) is NULL\n");
 
@@ -292,10 +294,9 @@ API int http_session_set_auto_redirection(http_session_h http_session, bool auto
 
 API int http_session_get_auto_redirection(http_session_h http_session, bool *auto_redirect)
 {
-       _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
-                       "parameter(http_session) is NULL\n");
-       _retvm_if(auto_redirect == NULL, HTTP_ERROR_INVALID_PARAMETER,
-                       "parameter(auto_redirect) is NULL\n");
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION, "http isn't initialized");
+       _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_session) is NULL\n");
+       _retvm_if(auto_redirect == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(auto_redirect) is NULL\n");
 
        __http_session_h *session = (__http_session_h *)http_session;
 
@@ -306,6 +307,8 @@ API int http_session_get_auto_redirection(http_session_h http_session, bool *aut
 
 API int http_session_get_active_transaction_count(http_session_h http_session, int *active_transaction_count)
 {
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+                       "http isn't initialized");
        _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
                        "parameter(http_session) is NULL\n");
        _retvm_if(active_transaction_count == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -320,6 +323,8 @@ API int http_session_get_active_transaction_count(http_session_h http_session, i
 
 API int http_session_get_max_transaction_count(http_session_h http_session, int *transaction_count)
 {
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+                       "http isn't initialized");
        _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
                        "parameter(http_session) is NULL\n");
        _retvm_if(transaction_count == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -327,13 +332,12 @@ API int http_session_get_max_transaction_count(http_session_h http_session, int
 
        __http_session_h *session = (__http_session_h *)http_session;
 
-       if (session->session_mode == HTTP_SESSION_MODE_NORMAL) {
+       if (session->session_mode == HTTP_SESSION_MODE_NORMAL)
                *transaction_count =  _MAX_HTTP_TRANSACTIONS_PER_SESSION_NORMAL;
-       } else if (session->session_mode == HTTP_SESSION_MODE_PIPELINING) {
+       else if (session->session_mode == HTTP_SESSION_MODE_PIPELINING)
                *transaction_count =  _MAX_HTTP_TRANSACTIONS_PER_SESSION_PIPE;
-       } else {
+       else
                *transaction_count =  -1;
-       }
 
        return HTTP_ERROR_NONE;
 }
index 3601a2eb8c0a2a4e444a2ab6cf71baa66dcfe945..a07f5af8f2be6567ea131493ebbf80fd67c99c99 100644 (file)
@@ -27,7 +27,6 @@ void _add_transaction_to_list(http_transaction_h http_transaction)
 void _remove_transaction_from_list(http_transaction_h http_transaction)
 {
        transaction_list = g_slist_remove(transaction_list, http_transaction);
-       //g_free(http_transaction);
 }
 
 void _remove_transaction_list(void)
@@ -166,13 +165,13 @@ int _transaction_submit(gpointer user_data)
        if (request->cookie)
                curl_easy_setopt(transaction->easy_handle, CURLOPT_COOKIE, request->cookie);
 
-       //The connection timeout is 30s. (default)
+       /* The connection timeout is 30s. (default) */
        curl_easy_setopt(transaction->easy_handle, CURLOPT_CONNECTTIMEOUT, _HTTP_DEFAULT_CONNECTION_TIMEOUT);
 
        if (transaction->timeout > 0) {
                curl_easy_setopt(transaction->easy_handle, CURLOPT_TIMEOUT, transaction->timeout);
        } else if (transaction->timeout == 0) {
-               //Set the transaction timeout. The timeout includes connection timeout.
+               /* Set the transaction timeout. The timeout includes connection timeout. */
                curl_easy_setopt(transaction->easy_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);
                curl_easy_setopt(transaction->easy_handle, CURLOPT_LOW_SPEED_TIME, 30L);
        }
@@ -205,10 +204,8 @@ int _transaction_submit(gpointer user_data)
        curl_easy_setopt(transaction->easy_handle, CURLOPT_WRITEFUNCTION, __handle_body_cb);
        curl_easy_setopt(transaction->easy_handle, CURLOPT_WRITEDATA, transaction);
 
-       http_transaction_header_get_field_value(transaction, "Content-Length", &field_value);
-       if (field_value) {
+       if (http_transaction_header_get_field_value(transaction, "Content-Length", &field_value) == HTTP_ERROR_NONE) {
                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);
@@ -285,8 +282,8 @@ void* thread_callback(void *user_data)
 
 API int http_session_open_transaction(http_session_h http_session, http_method_e method, http_transaction_h *http_transaction)
 {
-       _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
-                       "parameter(http_session) is NULL\n");
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION, "http isn't initialized");
+       _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_session) is NULL\n");
 
        __http_transaction_h *transaction = NULL;
 
@@ -353,6 +350,8 @@ API int http_session_open_transaction(http_session_h http_session, http_method_e
 
 API int http_transaction_submit(http_transaction_h http_transaction)
 {
+       _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");
 
@@ -367,6 +366,8 @@ API int http_transaction_submit(http_transaction_h http_transaction)
 
 API int http_transaction_destroy(http_transaction_h http_transaction)
 {
+       _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");
 
@@ -473,10 +474,12 @@ API int http_transaction_destroy(http_transaction_h http_transaction)
 
 API int http_transaction_pause(http_transaction_h http_transaction, http_pause_type_e pause_type)
 {
+       _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");
        _retvm_if(pause_type < HTTP_PAUSE_RECV || pause_type > HTTP_PAUSE_ALL, HTTP_ERROR_INVALID_PARAMETER,
-                               "Wrong pause state \n");
+                       "Wrong pause state \n");
 
        __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
        int ret = 0;
@@ -492,6 +495,8 @@ API int http_transaction_pause(http_transaction_h http_transaction, http_pause_t
 
 API int http_transaction_resume(http_transaction_h http_transaction)
 {
+       _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");
 
@@ -510,6 +515,8 @@ API int http_transaction_resume(http_transaction_h http_transaction)
 
 API int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_progress_cb progress_cb, void* user_data)
 {
+       _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");
        _retvm_if(progress_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -525,6 +532,8 @@ API int http_transaction_set_progress_cb(http_transaction_h http_transaction, ht
 
 API int http_transaction_set_received_header_cb(http_transaction_h http_transaction, http_transaction_header_cb header_cb, void* user_data)
 {
+       _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");
        _retvm_if(header_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -540,6 +549,8 @@ API int http_transaction_set_received_header_cb(http_transaction_h http_transact
 
 API int http_transaction_set_received_body_cb(http_transaction_h http_transaction, http_transaction_body_cb body_cb, void* user_data)
 {
+       _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");
        _retvm_if(body_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -555,6 +566,8 @@ API int http_transaction_set_received_body_cb(http_transaction_h http_transactio
 
 API int http_transaction_set_uploaded_cb(http_transaction_h http_transaction, http_transaction_write_cb write_cb, void* user_data)
 {
+       _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");
        _retvm_if(write_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -570,6 +583,8 @@ API int http_transaction_set_uploaded_cb(http_transaction_h http_transaction, ht
 
 API int http_transaction_set_completed_cb(http_transaction_h http_transaction, http_transaction_completed_cb completed_cb, void* user_data)
 {
+       _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");
        _retvm_if(completed_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -585,6 +600,8 @@ API int http_transaction_set_completed_cb(http_transaction_h http_transaction, h
 
 API int http_transaction_set_aborted_cb(http_transaction_h http_transaction, http_transaction_aborted_cb aborted_cb,  void* user_data)
 {
+       _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");
        _retvm_if(aborted_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -599,6 +616,8 @@ API int http_transaction_set_aborted_cb(http_transaction_h http_transaction, htt
 
 API int http_transaction_unset_progress_cb(http_transaction_h http_transaction)
 {
+       _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");
 
@@ -610,6 +629,8 @@ API int http_transaction_unset_progress_cb(http_transaction_h http_transaction)
 
 API int http_transaction_set_timeout(http_transaction_h http_transaction, int timeout)
 {
+       _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");
 
@@ -622,6 +643,8 @@ API int http_transaction_set_timeout(http_transaction_h http_transaction, int ti
 
 API int http_transaction_get_timeout(http_transaction_h http_transaction, int *timeout)
 {
+       _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");
        _retvm_if(timeout == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -636,6 +659,8 @@ API int http_transaction_get_timeout(http_transaction_h http_transaction, int *t
 
 API int http_transaction_set_interface_name(http_transaction_h http_transaction, const char *interface_name)
 {
+       _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");
        _retvm_if(interface_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -650,6 +675,8 @@ API int http_transaction_set_interface_name(http_transaction_h http_transaction,
 
 API int http_transaction_get_interface_name(http_transaction_h http_transaction, char **interface_name)
 {
+       _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");
        _retvm_if(interface_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
@@ -668,6 +695,8 @@ API int http_transaction_get_interface_name(http_transaction_h http_transaction,
 
 API int http_transaction_set_ready_to_write(http_transaction_h http_transaction, bool read_to_write)
 {
+       _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");
 
@@ -680,6 +709,8 @@ API int http_transaction_set_ready_to_write(http_transaction_h http_transaction,
 
 API int http_transaction_get_server_certificate_verification(http_transaction_h http_transaction, bool* verify)
 {
+       _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");
 
@@ -692,6 +723,8 @@ API int http_transaction_get_server_certificate_verification(http_transaction_h
 
 API int http_transaction_set_server_certificate_verification(http_transaction_h http_transaction, bool verify)
 {
+       _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");
 
@@ -704,6 +737,8 @@ API int http_transaction_set_server_certificate_verification(http_transaction_h
 
 API int http_session_destroy_all_transactions(http_session_h http_session)
 {
+       _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+                       "http isn't initialized");
        _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
                        "parameter(http_session) is NULL\n");
 
index 3fbf37c8e599d71ec979ea1a624039167f436573..8c370c7066871647306e14fa41e536b265cbe706 100644 (file)
@@ -16,6 +16,7 @@
 
 
 #include <stdio.h>
+#include <string.h>
 #include <glib.h>
 #include <gio/gio.h>
 
@@ -29,7 +30,8 @@
 FILE* fp1 = NULL;
 FILE* fp2 = NULL;
 
-/////////////////Callbacks////////////////////////////////////////////////////////////////////////////
+http_session_h session = NULL;
+
 void __transaction_header_cb(http_transaction_h transaction, char *header, size_t header_len, void *user_data)
 {
        PRG("transaction_header_cb", transaction);
@@ -59,16 +61,17 @@ void __transaction_completed_cb(http_transaction_h transaction, void *user_data)
        ret = http_transaction_request_get_uri(transaction, &uri);
        ret = http_transaction_response_get_status_code(transaction, &status);
 
+       http_transaction_header_remove_field(transaction, "Content-Length");
        DBG("%s - status(%d)\n", uri, status);
        ret = http_transaction_destroy(transaction);
        if (ret == HTTP_ERROR_NONE) DBG("Success to close transaction\n");
        else DBG("Fail to close transaction\n");
 }
 
-void __transaction_aborted_cb(http_transaction_h transaction, http_error_code_e error, void *user_data)
+void __transaction_aborted_cb(http_transaction_h transaction, int reason, void *user_data)
 {
        PRG("transaction_aborted_cb", transaction);
-       DBG("aborted reason: %d\n", error);
+       DBG("aborted reason: %d\n", reason);
 }
 
 void _register_callbacks(http_transaction_h transaction)
@@ -96,23 +99,43 @@ int test_http_deinit(void)
        else return 0;
 }
 
+int test_http_session_create(void)
+{
+       int ret;
+       int session_mode;
+
+       printf("Select session mode(0: NORMAL 1: PIPELINING): ");
+       ret = scanf("%d", &session_mode);
+
+       ret = http_session_create(session_mode, &session);
+       if (ret != HTTP_ERROR_NONE) {
+               ERR("Fail to create session", ret);
+               return 0;
+       }
+       return 1;
+}
+
+int test_http_session_destroy(void)
+{
+       int ret = http_session_destroy(session);
+       if (ret != HTTP_ERROR_NONE) {
+               ERR("Fail to destroy session", ret);
+               return 0;
+       }
+
+       return 1;
+}
+
 int test_simple_get(void)
 {
        char uri[1024];
        int ret;
-       http_session_h session = NULL;
        http_transaction_h transaction = NULL;
        http_method_e method;
 
        printf("Input uri: ");
        ret = scanf("%1023s", uri);
 
-       ret = http_session_create(HTTP_SESSION_MODE_NORMAL, &session);
-       if (ret != 0) {
-               ERR("Fail to create session", ret);
-               return 0;
-       }
-
        ret = http_session_open_transaction(session, HTTP_METHOD_GET, &transaction);
        if (ret != 0) {
                ERR("Fail to open transaction", ret);
@@ -140,23 +163,13 @@ int test_simple_get(void)
 int test_multiple_get(void)
 {
        int ret;
-       http_session_h session = NULL;
        http_transaction_h transaction[10];
-       int count, session_mode;
+       int count;
        int i;
 
        printf("Input count of transactions(1~10): ");
        ret = scanf("%d", &count);
 
-       printf("Select session mode(0: NORMAL 1: PIPELINING): ");
-       ret = scanf("%d", &session_mode);
-
-       ret = http_session_create(session_mode, &session);
-       if (ret != 0) {
-               ERR("Fail to create session", ret);
-               return 0;
-       }
-
        for (i = 0; i < count; i++) {
                char uri[1024];
                printf("Input uri for transaction[%d]: ", i + 1);
@@ -178,73 +191,110 @@ int test_multiple_get(void)
        return 1;
 }
 
+int test_simple_post(void)
+{
+       int ret;
+       http_transaction_h transaction;
+       const char* post_msg = "name=tizen&project=capi-network-curl";
+       char field_value[15];
+
+       ret = http_session_open_transaction(session, HTTP_METHOD_POST, &transaction);
+       if (ret != 0) {
+               ERR("Fail to open transaction", ret);
+               return 0;
+       }
+       ret = http_transaction_request_set_uri(transaction, "http://posttestserver.com/post.php");
+       if (ret != 0) {
+               ERR("Fail to set URI", ret);
+               return 0;
+       }
+       http_transaction_set_ready_to_write(transaction, TRUE);
+       http_transaction_request_write_body(transaction, post_msg);
+
+       sprintf(field_value, "%d", strlen(post_msg));
+       printf("[dbg] post size (%s)\n", field_value);
+       http_transaction_header_add_field(transaction, "Content-Length", field_value);
+
+       _register_callbacks(transaction);
+       http_transaction_submit(transaction);
+
+       return 1;
+}
+
 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
 {
-    int rv;
-    char a[10];
-
-    printf("Event received from stdin\n");
-
-    rv = read(0, a, 10);
-
-    if (rv <= 0 || a[0] == '0')
-        exit(1);
-
-    if (a[0] == '\n' || a[0] == '\r') {
-        printf("\n\n Network Connection API Test App\n\n");
-        printf("Options..\n");
-        printf("1       - Initialize\n");
-        printf("2       - Deinitialize\n");
-        printf("3       - Simple GET\n");
-        printf("4       - Multiple GET\n");
-        printf("5       - \n");
-        printf("6       - \n");
-        printf("0       - Exit \n");
-        printf("ENTER  - Show options menu.......\n");
-    }
-
-    switch (a[0]) {
-    case '1':
-        rv = test_http_init();
-        break;
-    case '2':
-       rv = test_http_deinit();
-        break;
-    case '3':
-       rv = test_simple_get();
-        break;
-    case '4':
-       rv = test_multiple_get();
-        break;
-    case '5':
-        break;
-    case '6':
-        break;
-    }
-
-    if (rv == 1)
-        printf("Operation succeeded!\n");
-    else
-        printf("Operation failed!\n");
-
-    return true;
+       int rv;
+       char a[10];
+
+       printf("Event received from stdin\n");
+
+       rv = read(0, a, 10);
+
+       if (rv <= 0 || a[0] == '0')
+               exit(1);
+
+       if (a[0] == '\n' || a[0] == '\r') {
+               printf("\n\n Network Connection API Test App\n\n");
+               printf("Options..\n");
+               printf("1       - Initialize\n");
+               printf("2       - Deinitialize\n");
+               printf("3       - Create session\n");
+               printf("4       - Destroy session\n");
+               printf("5       - Simple GET\n");
+               printf("6       - Multiple GET\n");
+               printf("7       - Simple POST\n");
+               printf("8       - \n");
+               printf("0       - Exit \n");
+               printf("ENTER  - Show options menu.......\n");
+       }
+
+       switch (a[0]) {
+       case '1':
+               rv = test_http_init();
+               break;
+       case '2':
+               rv = test_http_deinit();
+               break;
+       case '3':
+               rv = test_http_session_create();
+               break;
+       case '4':
+               rv = test_http_session_destroy();
+               break;
+       case '5':
+               rv = test_simple_get();
+               break;
+       case '6':
+               rv = test_multiple_get();
+               break;
+       case '7':
+               rv = test_simple_post();
+               break;
+       }
+
+       if (rv == 1)
+               printf("Operation succeeded!\n");
+       else
+               printf("Operation failed!\n");
+
+       return true;
 }
 
 int main(int argc, char **argv)
 {
-    GMainLoop *mainloop;
+       GMainLoop *mainloop;
 
 #if !GLIB_CHECK_VERSION(2, 36, 0)
-    g_type_init();
+       g_type_init();
 #endif
-    mainloop = g_main_loop_new(NULL, false);
+       mainloop = g_main_loop_new(NULL, false);
 
-    GIOChannel *channel = g_io_channel_unix_new(0);
-    g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
-    printf("Test Thread created...\n");
-    g_main_loop_run(mainloop);
+       GIOChannel *channel = g_io_channel_unix_new(0);
+       g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
+       printf("Test Thread created...\n");
+       g_main_loop_run(mainloop);
 
-    return 0;
+       return 0;
 }