From: Seonah Moon Date: Fri, 18 Mar 2016 08:08:28 +0000 (+0900) Subject: Fix some APIs and test file X-Git-Tag: submit/tizen/20160511.063207~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=882ef5f6562c12de9abedbe792879b6ce840af70;p=platform%2Fcore%2Fapi%2Fhttp.git Fix some APIs and test file Change-Id: I5c52ce0d49f09f86e2548c90fe3eb9b1e32ebf68 Signed-off-by: Seonah Moon Signed-off-by: pradeep kumar B --- diff --git a/doc/http_doc.h b/doc/http_doc.h new file mode 100755 index 0000000..cf7f527 --- /dev/null +++ b/doc/http_doc.h @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __TIZEN_NETWORK_HTTP_DOC_H__ +#define __TIZEN_NETWORK_HTTP_DOC_H__ + +/** + * @ingroup CAPI_NETWORK_FRAMEWORK + * @defgroup CAPI_NETWORK_HTTP_MODULE HTTP + * @brief The HTTP API provieds functions for communication with server according to HTTP protocol. + * + * @section CAPI_NETWORK_HTTP_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_HTTP_MODULE Overview + * The HTTP API provieds functions for communication with server according to HTTP protocol. + * Using the HTTP APIs, you can implement features that allow the users of your application to: + * - Manage HTTP session + * - Manage HTTP transaction + * - Send/Recieve HTTP request/response + * + * @if WEARABLE + * @section CAPI_NETWORK_HTTP_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.internet \n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + * @ endif + * + */ + +/** + * @ingroup CAPI_NETWORK_HTTP_MODULE + * @defgroup CAPI_NETWORK_HTTP_SESSION_MODULE HTTP Session + * @brief The HTTP Session API provides functions for managing HTTP session. + * + * @section CAPI_NETWORK_HTTP_SESSION_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_HTTP_SESSION_MODULE_OVERVEW Overview + * The HTTP Session API provides functions for managing HTTP session. + * Using the HTTP Session, you can implement features that allow the users of your application to: + * - Create / Delete HTTP session + * - Get activated transaction count + * - Manage redirection + * + * @if WEARABLE + * @section CAPI_NETWORK_HTTP_SESSION_MODULE_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.internet \n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + * @ endif + * + */ + +/** + * @ingroup CAPI_NETWORK_HTTP_SESSION_MODULE + * @defgroup CAPI_NETWORK_HTTP_TRANSACTION_MODULE HTTP Transaction + * @brief The HTTP Transaction API provides functions for managing HTTP transactions. + * + * @section CAPI_NETWORK_HTTP_TRANSACTION_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_HTTP_TRANSACTION_MODULE_OVERVIEW Overview + * It allows managing HTTP transactions. + * Using the HTTP Transaction, you can implement features that allow the users of your application to: + * - Open/Close transactions + * - Pause/Resume transactions + * - Transfer HTTP request + * - Get/Set transaction options such as interface, verification and timeout + * + * @if WEARABLE + * @section CAPI_NETWORK_HTTP_TRANSACTION_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.internet \n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + * @ endif + * + */ + +/** + * @ingroup CAPI_NETWORK_HTTP_TRANSACTION_MODULE + * @defgroup CAPI_NETWORK_HTTP_REQUEST_MODULE HTTP Request + * @brief It manages HTTP request. + * + * @section CAPI_NETWORK_HTTP_REQUEST_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_HTTP_REQUEST_MODULE_OVERVIEW Overview + * It manages HTTP request message. + * - Set/Get uri, method + * - Make body for POST/PUT Method + * It supports other request options according to the HTTP protocol. + * + * @if WEARABLE + * @section CAPI_NETWORK_HTTP_REQUEST_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.internet\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + * @ endif + * + */ + +/** + * @ingroup CAPI_NETWORK_HTTP_TRANSACTION_MODULE + * @defgroup CAPI_NETWORK_HTTP_RESPONSE_MODULE HTTP Response + * @brief It manages HTTP response. + * + * @section CAPI_NETWORK_HTTP_RESPONSE_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_HTTP_RESPONSE_MODULE_OVERVIEW Overview + * It manages HTTP response message. + * - Get status code and reason phrase from response message + * + * @if WEARABLE + * @section CAPI_NETWORK_HTTP_RESPONSE_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.internet \n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + * @ endif + * + */ + +/** + * @ingroup CAPI_NETWORK_HTTP_TRANSACTION_MODULE + * @defgroup CAPI_NETWORK_HTTP_HEADER_MODULE HTTP Header + * @brief It manages custom header + * + * @section CAPI_NETWORK_HTTP_HEADER_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_HTTP_HEADER_MODULE_OVERVIEW Overview + * It manages custom header + * + * @if WEARABLE + * @section CAPI_NETWORK_HTTP_HEADER_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.internet \n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + * @ endif + * + */ + +#endif /* __TIZEN_NETWORK_HTTP_DOC_H__ */ diff --git a/include/http.h b/include/http.h index c339428..987e32d 100644 --- a/include/http.h +++ b/include/http.h @@ -24,20 +24,29 @@ extern "C" { #endif +#ifndef TIZEN_ERROR_HTTP +#define TIZEN_ERROR_HTTP -0x03000000 +#endif + /** * @file http.h */ /** - * @addtogroup CAPI_NETWORK_HTTP_MANAGER_MODULE + * @addtogroup CAPI_NETWORK_HTTP_MODULE * @{ */ /** - * @brief The Http handle. + * @brief The HTTP Session handle. * @since_tizen 3.0 */ typedef void * http_session_h; + +/** + * @brief The HTTP Transaction handle. + * @since_tizen 3.0 + */ typedef void * http_transaction_h; /** @@ -45,7 +54,11 @@ typedef void * http_transaction_h; */ /** - * @internal + * @addtogroup CAPI_NETWORK_HTTP_SESSION_MODULE + * @{ + */ + +/** * @brief Enumeration for the http session. * @since_tizen 3.0 */ @@ -55,12 +68,19 @@ typedef enum { } http_session_mode_e; /** - * @internal + * @} + */ + +/** +* @addtogroup CAPI_NETWORK_HTTP_MODULE +* @{ +*/ + +/** * @brief Enumeration for the http method. * @since_tizen 3.0 */ typedef enum { - HTTP_METHOD_NONE = 0x0, HTTP_METHOD_GET = 0x40, /**< The HTTP GET Method */ HTTP_METHOD_OPTIONS = 0x41, /**< The HTTP OPTIONS Method */ HTTP_METHOD_HEAD = 0x42, /**< The HTTP HEAD Method */ @@ -72,46 +92,43 @@ typedef enum { } http_method_e; /** - * @internal * @brief Enumeration for the http version. * @since_tizen 3.0 */ typedef enum { - HTTP_VERSION_1_0, /**< %Http version 1.0 */ - HTTP_VERSION_1_1 /**< %Http version 1.1 */ + HTTP_VERSION_1_0, /**< HTTP version 1.0 */ + HTTP_VERSION_1_1 /**< HTTP version 1.1 */ } http_version_e; /** - * @internal * @brief Enumeration for transfer pause state * @since_tizen 3.0 */ typedef enum { HTTP_PAUSE_RECV = 1 << 0, /**< Pause receiving data */ HTTP_PAUSE_SEND = 1 << 2, /**< Pause sending data */ - HTTP_PAUSE_ALL = HTTP_PAUSE_RECV | HTTP_PAUSE_SEND /**< %Pause both directions */ -} http_pause_state_e; + HTTP_PAUSE_ALL = HTTP_PAUSE_RECV | HTTP_PAUSE_SEND /**< Pause both directions */ +} http_pause_type_e; /** - * @internal * @brief Enumeration for the http error code. * @since_tizen 3.0 */ typedef enum { - HTTP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - HTTP_ERROR_NOT_PERMITTED = TIZEN_ERROR_NOT_PERMITTED, /**< Operation not permitted */ - HTTP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - HTTP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - HTTP_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Resource busy */ - HTTP_ERROR_NOT_ENABLED = 0x0501, /**< Not enabled */ - HTTP_ERROR_OPERATION_FAILED = 0x0502, /**< Operation failed */ - HTTP_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */ - HTTP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< API is not supported */ - HTTP_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + HTTP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + HTTP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + HTTP_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + HTTP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + HTTP_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */ + HTTP_ERROR_OPERATION_FAILED = TIZEN_ERROR_HTTP|0x01, /**< Operation failed */ + HTTP_ERROR_COULDNT_RESOLVE_HOST = TIZEN_ERROR_HTTP|0x06, /**< Couldn't resolve host */ + HTTP_ERROR_COULDNT_CONNECT = TIZEN_ERROR_HTTP|0x07, /**< Couldn't Connect to host */ + HTTP_ERROR_OPERATION_TIMEDOUT = TIZEN_ERROR_HTTP|0x28, /**< Timeout */ + HTTP_ERROR_SSL_CONNECT_ERROR = TIZEN_ERROR_HTTP|0x35, /**< SSL Error */ + HTTP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< API is not supported */ } http_error_code_e; /** - * @internal * @brief Enumeration for the http status code. * @since_tizen 3.0 */ @@ -160,695 +177,682 @@ typedef enum { } http_status_code_e; /** - * @internal * @brief Called when the http header is received. * @since_tizen 3.0 - * @details Called when the http header is received. - * @param[in] header header information of Http Transaction - * @param[in] header_len length of the Http Transaction header + * @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 + * @param[in] user_data The user data + * @see http_transaction_set_received_header_cb() */ -typedef void (*http_transaction_header_cb)(http_transaction_h transaction, char *header, size_t header_len, void *user_data); +typedef void (*http_transaction_header_cb)(http_transaction_h http_transaction, char *header, size_t header_len, void *user_data); /** - * @internal * @brief Called when the http response is received. * @since_tizen 3.0 - * @details Called when the http response is received. - * @param[in] body response information of Http Transaction - * @param[in] size Size in bytes of each element to be written - * @param[in] count Number of elements, each one with a size of size bytes + * @param[in] http_transaction The http transaction handle + * @param[in] body Response information of Http Transaction + * @param[in] size Size in bytes of each element to be written + * @param[in] count Number of elements, each one with a size of size bytes + * @param[in] user_data The user data + * @see http_transaction_set_received_body_cb() */ -typedef void (*http_transaction_body_cb)(http_transaction_h transaction, char *body, size_t size, size_t count, void *user_data); +typedef void (*http_transaction_body_cb)(http_transaction_h http_transaction, char *body, size_t size, size_t count, void *user_data); /** - * @internal * @brief Called when the http ready to write event is received. * @since_tizen 3.0 - * @details Called when the http ready to write event is received. - * @param[in] recommended_chunk_size recommended chunk length of the Http transaction + * @param[in] http_transaction The http transaction handle + * @param[in] recommended_chunk_size Recommended chunk length(bytes) of the Http transaction + * @param[in] user_data The user data + * @see http_transaction_set_uploaded_cb() */ -typedef void (*http_transaction_write_cb)(http_transaction_h transaction, int recommended_chunk_size, void *user_data); +typedef void (*http_transaction_write_cb)(http_transaction_h http_transaction, int recommended_chunk_size, void *user_data); /** - * @internal * @brief Called when the http transaction is completed. * @since_tizen 3.0 - * @details Called when the http transaction is completed. + * @param[in] http_transaction The http transaction handle + * @param[in] user_data The user data + * @see http_transaction_set_completed_cb() */ -typedef void (*http_transaction_completed_cb)(http_transaction_h transaction, void *user_data); +typedef void (*http_transaction_completed_cb)(http_transaction_h http_transaction, void *user_data); /** - * @internal * @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 * @since_tizen 3.0 - * @details Called when the http transaction is aborted. - * @param[in] reason aborted reason code - */ -typedef void (*http_transaction_aborted_cb)(http_transaction_h transaction, int reason, void *user_data); - -/** - * @internal - * @brief Called to notify when the content body of the request message is being uploaded. - * @since_tizen 3.0 - * @details Called to notify when the content body of the request message is being uploaded. - * @param[in] currentLength current length of the uploaded data (in bytes) - * @param[in] totalLength total length of the data (in bytes) to upload + * @param[in] http_transaction The http transaction handle + * @param[in] error The error code about aborted reason + * @param[in] user_data The user data + * @see http_transaction_set_aborted_cb() */ -typedef void (*http_transaction_upload_progress_cb)(long long currentLength, long long totalLength); +typedef void (*http_transaction_aborted_cb)(http_transaction_h http_transaction, http_error_code_e error, void *user_data); /** - * @internal - * @brief Called to notify when the content body of the response message is being downloaded. + * @brief Called to notify when the content body of the response message is being downloaded or uploaded. * @since_tizen 3.0 - * @details Called to notify when the content body of the response message is being downloaded. - * @param[in] currentLength current length of the downloaded data (in bytes) - * @param[in] totalLength total length of the data (in bytes) to download + * @param[in] http_transaction The http transaction handle + * @param[in] download_total The total length of the data (in bytes) to download + * @param[in] download_now The current length of the downloaded data (in bytes) + * @param[in] upload_total The total length of the data (in bytes) to upload + * @param[in] upload_now The current length of the uploaded data (in bytes) + * @param[in] user_data The user data + * @see http_transaction_set_progress_cb() */ -typedef void (*http_transaction_download_progress_cb)(long long currentLength, long long totalLength); +typedef void (*http_transaction_progress_cb)(http_transaction_h http_transaction, double download_total, double download_now, double upload_total, double upload_now, void *user_data); /** - * @internal - * @addtogroup CAPI_NETWORK_HTTP_MODULE - * @{ - */ - -/** - * @internal - * @brief Initialize the Http module. + * @brief Initializes the Http module. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Initialize the Http module. + * @privlevel public + * @privilege %http://tizen.org/privilege/internet * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful - * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @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(); +int http_init(void); /** - * @internal - * @brief Deinitialize the Http module. + * @brief Deinitializes the Http module. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Deinitialize the Http module. + * @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 + * @see http_init() */ -void http_deinit(); +int http_deinit(void); /** * @} */ /** - * @internal * @addtogroup CAPI_NETWORK_HTTP_SESSION_MODULE * @{ */ /** - * @internal - * @brief Create the Http Session. + * @brief Creates the Http session handle. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Create the Http Session. - * @param[out] http_session http session handle - * @param[in] mode http session mode + * @remarks The @a http_session should be released using http_session_destroy(). + * @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_OUT_OF_MEMORY Out of memory + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + * @see http_session_destroy() */ -int http_create_session(http_session_h *http_session, http_session_mode_e mode); +int http_session_create(http_session_mode_e mode, http_session_h *http_session); /** - * @internal - * @brief Delete the Http Session. + * @brief Destroys the Http session handle. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Delete the Http Session. - * @param[in] http_session http session handle + * @param[in] 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_NOT_SUPPORTED Not Supported + * @see http_session_create() */ -int http_delete_session(http_session_h http_session); +int http_session_destroy(http_session_h http_session); + +/** + * @brief Opens Http transaction from the Http Session. + * @since_tizen 3.0 + * @remarks The @a http_transaction should be released using http_transaction_destroy(). + * @param[in] http_session The http session handle + * @param[in] method The http request method + * @param[out] 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_OUT_OF_MEMORY Out of memory + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + */ +int http_session_open_transaction(http_session_h http_session, http_method_e method, http_transaction_h *http_transaction); /** - * @internal * @brief Sets the value to redirect the HTTP request automatically. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Sets the value to redirect the HTTP request automatically. - * @param[in] http_session http session handle - * @param[in] auto_redirect set value of auto redirect + * @param[in] http_session The http session handle + * @param[in] auto_redirection The value which determines whether allow redirection or not * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + * @see http_session_get_auto_redirection() */ -int http_session_set_auto_redirection(http_session_h http_session, bool enable); +int http_session_set_auto_redirection(http_session_h http_session, bool auto_redirection); /** - * @internal - * @brief Get the auto redirection for the HTTP request. + * @brief Gets the auto redirection for the HTTP request. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the auto redirection for the HTTP request. - * @param[in] http_session http session handle - * @param[out] auto_redirect get value of auto redirect + * @param[in] http_session The http session handle + * @param[out] auto_redirect The value of auto redirect * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + * @see http_session_set_auto_redirection() */ int http_session_get_auto_redirection(http_session_h http_session, bool *auto_redirect); /** - * @internal * @brief Gets the number of active transactions in the current session. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Gets the number of active transactions in the current session. - * @param[in] http_session http session handle - * @param[out] active_transaction_count active transaction count + * @param[in] http_session The http session handle + * @param[out] active_transaction_count The number of activated transactions * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ int http_session_get_active_transaction_count(http_session_h http_session, int *active_transaction_count); /** - * @internal * @brief Gets the maximum number of transactions for the current session. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Gets the maximum number of transactions for the current session. - * @param[in] http_session http session handle - * @param[out] transaction_count maximum transaction count + * @param[in] http_session The http session handle + * @param[out] transaction_count The maximum transaction count * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ int http_session_get_max_transaction_count(http_session_h http_session, int *transaction_count); + +/* + * @brief Destroys all transaction. + * @since_tizen 3.0 + * @param[in] 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_OPERATION_fAILED Operation failed + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + */ +int http_session_destroy_all_transactions(http_session_h http_session); /** * @} */ /** - * @internal * @addtogroup CAPI_NETWORK_HTTP_TRANSACTION_MODULE * @{ */ /** - * @internal - * @brief Open Http Transaction from the Http Session. + * @brief Submits the Http request. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Open Http Transaction from the Http Session. - * @param[in] http_session http session handle - * @param[in] method http method - * @param[in] transaction_header_callback Header callback - * @param[in] transaction_body_callback Body callback - * @param[in] transaction_write_callback write callback - * @param[in] transaction_completed_cb completed callback - * @param[in] transaction_aborted_cb aborted callback - * @param[out] http_transaction http transaction handle + * @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 */ -int http_open_transaction(http_session_h http_session, http_method_e method, http_transaction_h *http_transaction); +int http_transaction_submit(http_transaction_h http_transaction); /** - * @internal - * @brief Submit the Http request. + * @brief Closes the http transaction handle. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Submit the Http request. + * @remarks The @a transaction is released by http_transaction_destroy(). + * It should be used after finishing http trasaction. * @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_NOT_SUPPORTED Not Supported + * @see http_transaction_create() */ -int http_transaction_submit(http_transaction_h http_transaction); +int http_transaction_destroy(http_transaction_h http_transaction); -/** - * @internal - * @brief Close the Http Transaction. +/* + * @brief Registers callback called when receive header. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Close the Http Transaction. * @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 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_transaction_close(http_transaction_h http_transaction); - -int http_transaction_set_received_header_cb(http_transaction_h transaction, http_transaction_header_cb header_cb, void* user_data); - -int http_transaction_set_received_body_cb(http_transaction_h transaction, http_transaction_body_cb body_cb, void* user_data); +int http_transaction_set_received_header_cb(http_transaction_h http_transaction, http_transaction_header_cb header_cb, void* user_data); -int http_transaction_set_uploaded_cb(http_transaction_h transaction, http_transaction_write_cb write_cb, void* user_data); - -int http_transaction_set_completed_cb(http_transaction_h transaction, http_transaction_completed_cb completed_cb, void* user_data); - -int http_transaction_set_aborted_cb(http_transaction_h http_transaction, http_transaction_aborted_cb aborted_cb, void* user_data); - -int http_transaction_close_all(http_session_h session); +/* + * @brief Registers callback called when receive body. + * @since_tizen 3.0 + * @param[in] http_transaction The http transaction handle + * @param[in] body_cb The callback function to be called + * @param[in] user_data The user data passed to the callback function + * @return 0 on success, otherwise negative error value + * @retval #HTTP_ERROR_NONE Successful + * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @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); +/* + * @brief Registers callback called when write data. + * @since_tizen 3.0 + * @param[in] http_transaction The http transaction handle + * @param[in] write_cb The callback function to be called + * @param[in] user_data The user data passed to the callback function + * @return 0 on success, otherwise negative error value + * @retval #HTTP_ERROR_NONE Successful + * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @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); -/** - * @internal - * @brief Sets the progress callbacks. +/* + * @brief Registers callback called when transaction is completed. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Sets the progress callbacks. * @param[in] http_transaction The http transaction handle - * @param[in] upload_progress_cb upload callback - * @param[in] download_progress_cb download callback + * @param[in] completed_cb The callback function to be called + * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_upload_progress_cb upload_progress_cb, - http_transaction_download_progress_cb download_progress_cb); +int http_transaction_set_completed_cb(http_transaction_h http_transaction, http_transaction_completed_cb completed_cb, void* user_data); -/** - * @internal - * @brief Sets the timeout in seconds that is the timeout for waiting the transaction. @n - * A timeout value of zero means an infinite timeout. +/* + * @brief Registers callback called when transaction is aborted. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Sets the timeout in seconds that is the timeout for waiting the transaction. * @param[in] http_transaction The http transaction handle - * @param[in] timeout timeout in seconds + * @param[in] header_cb The callback function to be called + * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_transaction_set_timeout(http_transaction_h http_transaction, int timeout); +int http_transaction_set_aborted_cb(http_transaction_h http_http_transaction, http_transaction_aborted_cb aborted_cb, void* user_data); + /** - * @internal - * @brief Get the time out in seconds for the transaction. + * @brief Registers the progress callbacks. + * @details Registers callback that is called when data is uploaded/downloaded. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the time out in seconds for the transaction. * @param[in] http_transaction The http transaction handle - * @param[out] timeout timeout in seconds + * @param[in] progress_cb The callback function to be called + * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_transaction_get_timeout(http_transaction_h http_transaction, int *timeout); +int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_progress_cb progress_cb, void* user_data); /** - * @internal - * @brief Sets a user object to the instance of HTTP transaction. + * @brief Sets the timeout in seconds that is the timeout for waiting the transaction. + * @details Sets the timeout in seconds that is the timeout for waiting the transaction. \n + * A timeout value of zero means an infinite timeout. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Sets a user object to the instance of HTTP transaction. * @param[in] http_transaction The http transaction handle - * @param[in] user_object user object + * @param[in] timeout The timeout in seconds * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_transaction_set_user_object(http_transaction_h http_transaction, void *user_object); +int http_transaction_set_timeout(http_transaction_h http_transaction, int timeout); /** - * @internal - * @brief Gets a user object that is set to the instance of HTTP transaction. + * @brief Gets the time out in seconds for the transaction. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Gets a user object that is set to the instance of HTTP transaction. * @param[in] http_transaction The http transaction handle - * @param[out] user_object user object + * @param[out] timeout The timeout in seconds * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_transaction_get_user_object(http_transaction_h http_transaction, void **user_object); +int http_transaction_get_timeout(http_transaction_h http_transaction, int *timeout); /** - * @internal - * @brief Resumes the transaction after the http_transaction_cert_verifcation_required_cb event is invoked. + * @brief Resumes the transaction. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Resumes the transaction after the http_transaction_cert_verifcation_required_cb event is invoked. * @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_OPERATION_FAILED Operation failed + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ int http_transaction_resume(http_transaction_h http_transaction); /** - * @internal - * @brief Pauses the transaction after the http_transaction_cert_verifcation_required_cb event is invoked. + * @brief Pauses the transaction. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Pauses the transaction after the http_transaction_cert_verifcation_required_cb event is invoked. * @param[in] http_transaction The http transaction handle + * @param[in] pause_type The pause type of the connection * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_OPERATION_FAILED Operation failed + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_transaction_pause(http_transaction_h http_transaction, http_pause_state_e pause_state); +int http_transaction_pause(http_transaction_h http_transaction, http_pause_type_e pause_type); /** - * @internal * @brief Sets ready to write event for a transaction. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Sets ready to write event for a transaction. * @param[in] http_transaction The http transaction handle - * @param[out] read_to_write enable/disable ready to write + * @param[out] read_to_write Enable/disable ready to write * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ int http_transaction_set_ready_to_write(http_transaction_h http_transaction, bool read_to_write); /** - * @internal - * @brief Set the interface name. + * @brief Sets the interface name. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Set the interface name. * @param[in] http_transaction The http transaction handle - * @param[in] interface_name interface name + * @param[in] interface_name The interface name to use as outgoing network interface * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ int http_transaction_set_interface_name(http_transaction_h http_transaction, const char *interface_name); /** - * @internal - * @brief Get the interface name. + * @brief Gets the interface name. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the interface name. - * @param[in] http_transaction The http transaction handle - * @param[out] interface_name interface name + * @remarks The @a interface_name should be freed using free(). + * @param[in] http_transaction The http transaction handle + * @param[out] interface_name The interface name * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ int http_transaction_get_interface_name(http_transaction_h http_transaction, char **interface_name); /** - * @internal * @brief Sets the flag to verify a server certificate. + * @details The verify determines whether verifies the peer's certificate. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the interface name. * @param[in] http_transaction The http transaction handle - * @param[in] verify flag to verify a server certificate. + * @param[in] verify The flag to verify a server certificate; true means verifies; false means it doesn't. * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ int http_transaction_set_server_certificate_verification(http_transaction_h http_transaction, bool verify); /** - * @internal * @brief Gets the flag to verify a server certificate. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the interface name. * @param[in] http_transaction The http transaction handle - * @param[out] verify flag to verify a server certificate. + * @param[out] verify The flag to verify a server certificate; true means verifies; false means it doesn't. * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ int http_transaction_get_server_certificate_verification(http_transaction_h http_transaction, bool* verify); /** - * @internal - * @brief Adds a named field, which is a <@c fieldName, @c fieldValue> pair, to the current instance of Http Transaction. - * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin + * @brief Adds a named field to header. * @details Adds a named field, which is a <@c fieldName, @c fieldValue> pair, to the current instance of Http Transaction. + * @since_tizen 3.0 * @param[in] http_transaction The http transaction handle - * @param[in] field_name Http Header Field name - * @param[in] field_name Http Header Field value + * @param[in] field_name The http Header Field name + * @param[in] field_value The http Header Field value * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_header_add_field(http_transaction_h http_transaction, const char *field_name, const char* field_value); +int http_transaction_header_add_field(http_transaction_h http_transaction, const char *field_name, const char* field_value); /** - * @internal - * @brief Remove the named field, which is a <@c fieldName, @c fieldValue> pair, from the current instance of Http Transaction. - * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin + * @brief Removes the named field from header. * @details Remove the named field, which is a <@c fieldName, @c fieldValue> pair, from the current instance of Http Transaction. + * @since_tizen 3.0 * @param[in] http_transaction The http transaction handle - * @param[in] field_name Http Header Field name + * @param[in] field_name The http Header Field name * @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_header_remove_field(http_transaction_h http_transaction, const char *field_name); +int http_transaction_header_remove_field(http_transaction_h http_transaction, const char *field_name); /** - * @internal - * @brief Get the Http Header Field value. + * @brief Gets the Http Header Field value from custom header. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the Http Header Field value. + * @remarks The @a field_value should be freed using free(). * @param[in] http_transaction The http transaction handle - * @param[in] field_name Http Header Field name - * @param[out] field_value Http Header Field value + * @param[in] field_name The http Header Field name + * @param[out] field_value The http Header Field value * @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_header_get_field_value(http_transaction_h http_transaction, const char *field_name, char **field_value); +int http_transaction_header_get_field_value(http_transaction_h http_transaction, const char *field_name, char **field_value); /** * @} */ /** - * @internal * @addtogroup CAPI_NETWORK_HTTP_REQUEST_MODULE * @{ */ /** - * @internal * @brief Sets an HTTP method of the request header. + * @details Set an HTTP method such as GET, POST, PUT and etc. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Sets an HTTP method of the request header. + * @remarks The default method is GET. * @param[in] http_transaction The http transaction handle + * @param[in] method The http method * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_request_set_method(http_transaction_h http_transaction, http_method_e method); +int http_transaction_request_set_method(http_transaction_h http_transaction, http_method_e method); /** - * @internal - * @brief Get the Http method. + * @brief Gets the Http method from request header. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the Http method. * @param[in] http_transaction The http transaction handle - * @param[out] method method + * @param[out] method The http method * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_request_get_method(http_transaction_h http_transaction, http_method_e *method); +int http_transaction_request_get_method(http_transaction_h http_transaction, http_method_e *method); /** - * @internal * @brief Sets an HTTP version of the request header. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Sets an HTTP version of the request header. - * @param[in] http_transaction The http transaction handle + * @remarks The default version is HTTP 1.1. + * @param[in] http_transaction The http transaction handle + * @param[in] version The http version * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_request_set_version(http_transaction_h http_transaction, http_version_e version); +int http_transaction_request_set_version(http_transaction_h http_transaction, http_version_e version); /** - * @internal - * @brief Get the Http version. - * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin + * @brief Gets the Http version from request header. * @details Get the Http version. - * @param[in] http_transaction The http transaction handle - * @param[out] version version + * @since_tizen 3.0 + * @param[in] http_transaction The http transaction handle + * @param[out] version The http version * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_request_get_version(http_transaction_h http_transaction, http_version_e *version); +int http_transaction_request_get_version(http_transaction_h http_transaction, http_version_e *version); /** - * @internal * @brief Sets a URI of the request header. - * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin * @details Sets a URI of the request header. - * @param[in] http_transaction The http transaction handle + * @since_tizen 3.0 + * @remarks It should be used before http_transaction_submit(). + * @param[in] http_transaction The http transaction handle + * @param[in] host_uri The uri to use in the request * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_request_set_uri(http_transaction_h http_transaction, const char *host_uri); +int http_transaction_request_set_uri(http_transaction_h http_transaction, const char *host_uri); /** - * @internal - * @brief Get the uri. + * @brief Gets the uri. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the uri. - * @param[in] http_transaction The http transaction handle - * @param[out] host_uri host uri + * @remarks The @a host_uri should be freed using free(). + * @param[in] http_transaction The http transaction handle + * @param[out] host_uri The host uri * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_request_get_uri(http_transaction_h http_transaction, char **host_uri); +int http_transaction_request_get_uri(http_transaction_h http_transaction, char **host_uri); /** - * @internal * @brief Sets the Accept-Encoding header field of HttpRequest. + * @details The Accept-Encoding header enables automatic decompression of HTTP downloads. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Sets the Accept-Encoding header field of HttpRequest. - * @param[in] http_transaction The http transaction handle - * @param[in] encoding encoding + * @remarks If empty string is set, an Accept-Encoding header contains all supported built-in compressions. + * @param[in] http_transaction The http transaction handle + * @param[in] encoding The encoding algorithms (e.g. gizp, deflate) * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_request_set_accept_encoding(http_transaction_h http_transaction, const char *encoding); +int http_transaction_request_set_accept_encoding(http_transaction_h http_transaction, const char *encoding); /** - * @internal - * @brief Get the Accept-Encoding header field of HttpRequest. + * @brief Gets the Accept-Encoding header field of HttpRequest. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the Accept-Encoding header field of HttpRequest. - * @param[in] http_transaction The http transaction handle - * @param[out] encoding encoding + * @remarks The @a encoding should be freed using free(). + * @param[in] http_transaction The http transaction handle + * @param[out] encoding The encoding algorithms * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding); +int http_transaction_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding); + +/** + * @brief Sets a cookie in the HTTP request. + * @since_tizen 3.0 + * @remarks The format of string should be NME=CONTENTS (e.g. "name1=hello; name2=tizen;") + * @param[in] http_transaction The http transaction handle + * @param[in] cookie The cookie + * @return 0 on success, otherwise negative error value + * @retval #HTTP_ERROR_NONE Successful + * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + */ +int http_transaction_request_set_cookie(http_transaction_h http_transaction, const char *cookie); + +/** + * @brief Gets a cookie in the HTT request. + * @since_tizen 3.0 + * @remarks The @a cookie should be freed using free(). + * @param[in] http_transaction The http transaction handle + * @param[out] cookie The cookie + * @return 0 on success, otherwise negative error value + * @retval #HTTP_ERROR_NONE Successful + * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + */ +int http_transaction_request_get_cookie(http_transaction_h http_transaction, const char **cookie); /** - * @internal * @brief Sets the request message body. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Sets the request message body. - * @param[in] http_transaction The http transaction handle - * @param[in] body message body data + * @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_NOT_SUPPORTED Not Supported */ -int http_request_write_body(http_transaction_h http_transaction, const char *body); +int http_transaction_request_write_body(http_transaction_h http_transaction, const char *body); /** * @} */ /** - * @internal * @addtogroup CAPI_NETWORK_HTTP_RESPONSE_MODULE * @{ */ /** - * @internal - * @brief Get the Http status code from Http Response. + * @brief Gets the Http status code from Http Response. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the Http status code from Http Response. * @param[in] http_transaction The http transaction handle - * @param[out] status_code http status code + * @param[out] status_code The http status code * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_response_get_status_code(http_transaction_h http_transaction, http_status_code_e *status_code); +int http_transaction_response_get_status_code(http_transaction_h http_transaction, http_status_code_e *status_code); /** - * @internal - * @brief Get the Http status text from Http Response. + * @brief Gets the Http status text from Http Response. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the Http status text from Http Response. + * @remarks The @a status_text should be freed using free(). * @param[in] http_transaction The http transaction handle - * @param[out] status_text http status text + * @param[out] status_text The http status text * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_response_get_status_text(http_transaction_h http_transaction, char **status_text); +int http_transaction_response_get_status_text(http_transaction_h http_transaction, char **status_text); /** - * @internal - * @brief Get the Http version from Http Response. + * @brief Gets the Http version from Http Response. * @since_tizen 3.0 - * @privlevel platform - * @privilege http://tizen.org/privilege/http.admin - * @details Get the Http version from Http Response. * @param[in] http_transaction The http transaction handle - * @param[out] version version + * @param[out] version The http version * @return 0 on success, otherwise negative error value * @retval #HTTP_ERROR_NONE Successful * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported */ -int http_response_get_version(http_transaction_h http_transaction, http_version_e *version); +int http_transaction_response_get_version(http_transaction_h http_transaction, http_version_e *version); /** * @} diff --git a/include/http_private.h b/include/http_private.h index bbed38d..c7bfc0e 100644 --- a/include/http_private.h +++ b/include/http_private.h @@ -133,21 +133,19 @@ typedef struct { int socket_fd; /*Transaction Callbacks and User data*/ + http_transaction_progress_cb progress_cb; + void* progress_user_data; http_transaction_header_cb header_cb; - void *header_user_data; + void* header_user_data; http_transaction_body_cb body_cb; - void *body_user_data; + void* body_user_data; http_transaction_write_cb write_cb; - void *write_user_data; + void* write_user_data; http_transaction_completed_cb completed_cb; - void *completed_user_data; + void* completed_user_data; http_transaction_aborted_cb aborted_cb; void *aborted_user_data; - /*Progress Callbacks */ - http_transaction_upload_progress_cb upload_progress_cb; - http_transaction_download_progress_cb download_progress_cb; - __http_session_h *session; __http_request_h *request; __http_response_h *response; diff --git a/packaging/capi-network-http.spec b/packaging/capi-network-http.spec index af02a13..48c3477 100644 --- a/packaging/capi-network-http.spec +++ b/packaging/capi-network-http.spec @@ -1,6 +1,6 @@ Name: capi-network-http Summary: Http Framework -Version: 0.0.3 +Version: 0.0.4 Release: 0 Group: System/Network License: Apache-2.0 diff --git a/src/http_common.c b/src/http_common.c index 35d45fd..66e3361 100644 --- a/src/http_common.c +++ b/src/http_common.c @@ -19,6 +19,19 @@ #include "net_connection.h" +#include +#include + +#define MUTEX_TYPE pthread_mutex_t +#define MUTEX_SETUP(x) pthread_mutex_init(&(x), NULL) +#define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x)) +#define MUTEX_LOCK(x) pthread_mutex_lock(&(x)) +#define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x)) +#define THREAD_ID pthread_self() + +/* This array will store all of the mutexes available to OpenSSL. */ +static MUTEX_TYPE *mutex_buf= NULL; + http_method_e _get_method(gchar* method) { if (g_strcmp0(method, "GET") == 0) { @@ -39,7 +52,7 @@ http_method_e _get_method(gchar* method) return HTTP_METHOD_CONNECT; } - return HTTP_METHOD_NONE; + return HTTP_METHOD_GET; } gchar* _get_http_method(http_method_e method) @@ -47,10 +60,6 @@ gchar* _get_http_method(http_method_e method) gchar* http_method = NULL; switch (method) { - case HTTP_METHOD_GET: - http_method = g_strdup("GET"); - break; - case HTTP_METHOD_OPTIONS: http_method = g_strdup("OPTIONS"); break; @@ -78,10 +87,9 @@ gchar* _get_http_method(http_method_e method) case HTTP_METHOD_CONNECT: http_method = g_strdup("CONNECT"); break; - - case HTTP_METHOD_NONE: + case HTTP_METHOD_GET: default: - http_method = NULL; + http_method = g_strdup("GET"); break; } @@ -147,17 +155,85 @@ CATCH: return proxy_addr; } -API int http_init() +static void locking_function(int mode, int n, const char * file, int line) +{ + if (mode & CRYPTO_LOCK) + MUTEX_LOCK(mutex_buf[n]); + else + MUTEX_UNLOCK(mutex_buf[n]); +} + +static unsigned long id_function(void) +{ + return ((unsigned long)THREAD_ID); +} + +int thread_setup(void) +{ + int index = 0; + + mutex_buf = malloc(CRYPTO_num_locks() * sizeof(MUTEX_TYPE)); + if (!mutex_buf) + return 0; + + 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); + + return 1; +} + +int thread_cleanup(void) +{ + int index; + + if (!mutex_buf) + return 0; + + CRYPTO_set_id_callback(NULL); + CRYPTO_set_locking_callback(NULL); + + for (index = 0; index < CRYPTO_num_locks(); index++) { + MUTEX_CLEANUP(mutex_buf[index]); + } + + free(mutex_buf); + mutex_buf = NULL; + + return 1; +} + +API int http_init(void) { + int ret = 0; + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { DBG("curl_global_init failed, so returning!\n"); return HTTP_ERROR_OPERATION_FAILED; } + ret = thread_setup(); + if (!ret) { + DBG("ssl thread initialization failed!\n"); + return HTTP_ERROR_OPERATION_FAILED; + } + return HTTP_ERROR_NONE; } -API void http_deinit() +API int http_deinit(void) { + int ret = 0; + + ret = thread_cleanup(); + if (!ret) { + DBG("ssl thread de-initialization failed!\n"); + return HTTP_ERROR_OPERATION_FAILED; + } + curl_global_cleanup(); + + return HTTP_ERROR_NONE; } diff --git a/src/http_header.c b/src/http_header.c index 8bf7501..182db5f 100644 --- a/src/http_header.c +++ b/src/http_header.c @@ -44,7 +44,7 @@ struct curl_slist* _get_header_list(http_transaction_h http_transaction) return header->header_list; } -API int http_header_add_field(http_transaction_h http_transaction, const char *field_name, const char* field_value) +API int http_transaction_header_add_field(http_transaction_h http_transaction, const char *field_name, const char* field_value) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -65,7 +65,7 @@ API int http_header_add_field(http_transaction_h http_transaction, const char *f return HTTP_ERROR_NONE; } -API int http_header_remove_field(http_transaction_h http_transaction, const char *field_name) +API int http_transaction_header_remove_field(http_transaction_h http_transaction, const char *field_name) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -75,12 +75,16 @@ API int http_header_remove_field(http_transaction_h http_transaction, const char __http_transaction_h *transaction = (__http_transaction_h *)http_transaction; __http_header_h *header = transaction->header; - g_hash_table_remove(header->hash_table, field_name); - - return HTTP_ERROR_NONE; + if (g_hash_table_remove(header->hash_table, field_name)) { + return HTTP_ERROR_NONE; + } + else { + ERR("field_name doesn't exist!!"); + return HTTP_ERROR_INVALID_OPERATION; + } } -API int http_header_get_field_value(http_transaction_h http_transaction, const char *field_name, char **field_value) +API int http_transaction_header_get_field_value(http_transaction_h http_transaction, const char *field_name, char **field_value) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -98,6 +102,10 @@ API int http_header_get_field_value(http_transaction_h http_transaction, const c } *field_value = g_hash_table_lookup(header->hash_table, field_name); + if (*field_value == NULL) { + ERR("filed_name doesn't exist!!"); + return HTTP_ERROR_INVALID_OPERATION; + } return HTTP_ERROR_NONE; } diff --git a/src/http_request.c b/src/http_request.c index 673f931..9c83757 100644 --- a/src/http_request.c +++ b/src/http_request.c @@ -17,7 +17,7 @@ #include "http.h" #include "http_private.h" -API int http_request_set_method(http_transaction_h http_transaction, http_method_e method) +API int http_transaction_request_set_method(http_transaction_h http_transaction, http_method_e method) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -35,7 +35,7 @@ API int http_request_set_method(http_transaction_h http_transaction, http_method return HTTP_ERROR_NONE; } -API int http_request_get_method(http_transaction_h http_transaction, http_method_e *method) +API int http_transaction_request_get_method(http_transaction_h http_transaction, http_method_e *method) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -50,7 +50,7 @@ API int http_request_get_method(http_transaction_h http_transaction, http_method return HTTP_ERROR_NONE; } -API int http_request_set_version(http_transaction_h http_transaction, http_version_e version) +API int http_transaction_request_set_version(http_transaction_h http_transaction, http_version_e version) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -63,7 +63,7 @@ API int http_request_set_version(http_transaction_h http_transaction, http_versi return HTTP_ERROR_NONE; } -API int http_request_get_version(http_transaction_h http_transaction, http_version_e *version) +API int http_transaction_request_get_version(http_transaction_h http_transaction, http_version_e *version) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -78,7 +78,7 @@ API int http_request_get_version(http_transaction_h http_transaction, http_versi return HTTP_ERROR_NONE; } -API int http_request_set_uri(http_transaction_h http_transaction, const char *host_uri) +API int http_transaction_request_set_uri(http_transaction_h http_transaction, const char *host_uri) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -93,7 +93,7 @@ API int http_request_set_uri(http_transaction_h http_transaction, const char *ho return HTTP_ERROR_NONE; } -API int http_request_get_uri(http_transaction_h http_transaction, char **host_uri) +API int http_transaction_request_get_uri(http_transaction_h http_transaction, char **host_uri) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -113,7 +113,7 @@ API int http_request_get_uri(http_transaction_h http_transaction, char **host_ur return HTTP_ERROR_NONE; } -API int http_request_set_accept_encoding(http_transaction_h http_transaction, const char *encoding) +API int http_transaction_request_set_accept_encoding(http_transaction_h http_transaction, const char *encoding) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -128,7 +128,7 @@ API int http_request_set_accept_encoding(http_transaction_h http_transaction, co return HTTP_ERROR_NONE; } -API int http_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding) +API int http_transaction_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -147,7 +147,7 @@ API int http_request_get_accept_encoding(http_transaction_h http_transaction, ch return HTTP_ERROR_NONE; } -API int http_request_set_cookie(http_transaction_h http_transaction, const char* cookie) +API int http_transaction_request_set_cookie(http_transaction_h http_transaction, const char *cookie) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -162,7 +162,7 @@ API int http_request_set_cookie(http_transaction_h http_transaction, const char* return HTTP_ERROR_NONE; } -API int http_request_get_cookie(http_transaction_h http_transaction, const char** cookie) +API int http_transaction_request_get_cookie(http_transaction_h http_transaction, const char **cookie) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -181,7 +181,7 @@ API int http_request_get_cookie(http_transaction_h http_transaction, const char* return HTTP_ERROR_NONE; } -API int http_request_write_body(http_transaction_h http_transaction, const char *body) +API int http_transaction_request_write_body(http_transaction_h http_transaction, const char *body) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -239,7 +239,7 @@ int _read_request_body(http_transaction_h http_transaction, char **body) *body = malloc(curr_len + 1); if (*body == NULL) { DBG("malloc() failed\n"); - return HTTP_ERROR_OPERATION_FAILED; + return HTTP_ERROR_OUT_OF_MEMORY; } for (index = 0; index < len; index++) { @@ -251,7 +251,7 @@ int _read_request_body(http_transaction_h http_transaction, char **body) *body = realloc(*body, new_len + 1); if (*body == NULL) { DBG("realloc() failed\n"); - return HTTP_ERROR_OPERATION_FAILED; + return HTTP_ERROR_OUT_OF_MEMORY; } memcpy(*body + curr_len, ptr, body_size); diff --git a/src/http_response.c b/src/http_response.c index 3b27bd4..7b64679 100644 --- a/src/http_response.c +++ b/src/http_response.c @@ -19,7 +19,7 @@ #include "http.h" #include "http_private.h" -static int __convert_status_code(char* status_code) +static int __convert_status_code(char *status_code) { int i = 0; int converted_digit = 0; @@ -33,7 +33,7 @@ static int __convert_status_code(char* status_code) return converted_status_code; } -void __parse_response_header(char* buffer, size_t written, gpointer user_data) +void __parse_response_header(char *buffer, size_t written, gpointer user_data) { __http_transaction_h* transaction = (__http_transaction_h *)user_data; __http_response_h*response = (__http_response_h *)transaction->response; @@ -65,7 +65,7 @@ void __parse_response_header(char* buffer, size_t written, gpointer user_data) } } -API int http_response_get_status_code(http_transaction_h http_transaction, http_status_code_e* status_code) +API int http_transaction_response_get_status_code(http_transaction_h http_transaction, http_status_code_e *status_code) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -80,7 +80,7 @@ API int http_response_get_status_code(http_transaction_h http_transaction, http_ return HTTP_ERROR_NONE; } -API int http_response_get_status_text(http_transaction_h http_transaction, char** status_text) +API int http_transaction_response_get_status_text(http_transaction_h http_transaction, char **status_text) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -95,7 +95,7 @@ API int http_response_get_status_text(http_transaction_h http_transaction, char* return HTTP_ERROR_NONE; } -API int http_response_get_version(http_transaction_h http_transaction, http_version_e* version) +API int http_transaction_response_get_version(http_transaction_h http_transaction, http_version_e *version) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); diff --git a/src/http_session.c b/src/http_session.c index b092a3b..8255d5a 100644 --- a/src/http_session.c +++ b/src/http_session.c @@ -45,11 +45,20 @@ void _check_curl_multi_status(gpointer user_data) 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, (int)curl_code, transaction->aborted_user_data); + transaction->aborted_cb(transaction, HTTP_ERROR_OPERATION_TIMEDOUT, transaction->aborted_user_data); break; default: break; @@ -215,7 +224,7 @@ int __handle_timer_cb(CURLM *curl_multi, long timeout_ms, void *user_data) return 0; } -API int http_create_session(http_session_h *http_session, http_session_mode_e mode) +API int http_session_create(http_session_mode_e mode, http_session_h *http_session) { _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_session) is NULL\n"); @@ -223,6 +232,10 @@ API int http_create_session(http_session_h *http_session, http_session_mode_e mo __http_session_h *session = NULL; session = (__http_session_h *)malloc(sizeof(__http_session_h)); + if (session == NULL) { + ERR("Fail to allocate session memory!!"); + return HTTP_ERROR_OUT_OF_MEMORY; + } session->multi_handle = curl_multi_init(); session->session_id = _generate_session_id(); @@ -244,7 +257,7 @@ API int http_create_session(http_session_h *http_session, http_session_mode_e mo return HTTP_ERROR_NONE; } -API int http_delete_session(http_session_h http_session) +API int http_session_destroy(http_session_h http_session) { _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_session) is NULL\n"); @@ -265,14 +278,14 @@ API int http_delete_session(http_session_h http_session) return HTTP_ERROR_NONE; } -API int http_session_set_auto_redirection(http_session_h http_session, bool enable) +API int http_session_set_auto_redirection(http_session_h http_session, bool auto_redirection) { _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_session) is NULL\n"); __http_session_h *session = (__http_session_h *)http_session; - session->auto_redirect = enable; + session->auto_redirect = auto_redirection; return HTTP_ERROR_NONE; } diff --git a/src/http_transaction.c b/src/http_transaction.c index 18ec22c..3601a2e 100644 --- a/src/http_transaction.c +++ b/src/http_transaction.c @@ -161,7 +161,7 @@ int _transaction_submit(gpointer user_data) curl_easy_setopt(transaction->easy_handle, CURLOPT_HTTPHEADER, header_list); if (request->encoding) - curl_easy_setopt(transaction->easy_handle, CURLOPT_ENCODING, request->encoding); + curl_easy_setopt(transaction->easy_handle, CURLOPT_ACCEPT_ENCODING, request->encoding); if (request->cookie) curl_easy_setopt(transaction->easy_handle, CURLOPT_COOKIE, request->cookie); @@ -205,7 +205,7 @@ 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_header_get_field_value(transaction, "Content-Length", &field_value); + http_transaction_header_get_field_value(transaction, "Content-Length", &field_value); if (field_value) { content_len = atoi(field_value); @@ -283,16 +283,19 @@ void* thread_callback(void *user_data) return NULL; } -API int http_open_transaction(http_session_h http_session, http_method_e method, http_transaction_h *http_transaction) +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"); __http_transaction_h *transaction = NULL; - DBG("[Seonah] + "); - transaction = (__http_transaction_h *)malloc(sizeof(__http_transaction_h)); + if (transaction == NULL) { + ERR("Fail to allocate transaction memory!!"); + return HTTP_ERROR_OUT_OF_MEMORY; + } + transaction->easy_handle = NULL; transaction->interface_name = NULL; transaction->timeout = 0; @@ -305,17 +308,29 @@ API int http_open_transaction(http_session_h http_session, http_method_e method, transaction->write_cb = NULL; transaction->completed_cb = NULL; transaction->aborted_cb = NULL; - - transaction->upload_progress_cb = NULL; - transaction->download_progress_cb = NULL; + transaction->progress_cb = NULL; transaction->session = http_session; transaction->session->active_transaction_count++; transaction->session_id = 0; transaction->request = (__http_request_h *)malloc(sizeof(__http_request_h)); + if (transaction->request == NULL) { + ERR("Fail to allocate request memory!!"); + return HTTP_ERROR_OUT_OF_MEMORY; + } + transaction->response = (__http_response_h *)malloc(sizeof(__http_response_h)); + if (transaction->response == NULL) { + ERR("Fail to allocate response memory!!"); + return HTTP_ERROR_OUT_OF_MEMORY; + } + transaction->header = (__http_header_h *)malloc(sizeof(__http_header_h)); + if (transaction->header == NULL) { + ERR("Fail to allocate header memory!!"); + return HTTP_ERROR_OUT_OF_MEMORY; + } transaction->request->host_uri = NULL; transaction->request->method = _get_http_method(method); @@ -323,6 +338,7 @@ API int http_open_transaction(http_session_h http_session, http_method_e method, transaction->request->cookie = NULL; transaction->request->http_version = HTTP_VERSION_1_1; transaction->request->body_queue = g_queue_new(); + transaction->request->tot_size = 0; transaction->header->header_list = NULL; transaction->header->hash_table = NULL; @@ -332,23 +348,24 @@ API int http_open_transaction(http_session_h http_session, http_method_e method, *http_transaction = (http_transaction_h)transaction; _add_transaction_to_list(transaction); - DBG("[Seonah] - "); return HTTP_ERROR_NONE; } API int http_transaction_submit(http_transaction_h http_transaction) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, - "parameter(http_transaction) is NULL\n"); + "parameter(http_transaction) is NULL"); __http_transaction_h *transaction = (__http_transaction_h *)http_transaction; + _retvm_if(transaction->request->host_uri == NULL, HTTP_ERROR_INVALID_OPERATION, "URI isn't set!!"); + transaction->thread = g_thread_new("transaction_thread", thread_callback, transaction); return HTTP_ERROR_NONE; } -API int http_transaction_close(http_transaction_h http_transaction) +API int http_transaction_destroy(http_transaction_h http_transaction) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -369,7 +386,6 @@ API int http_transaction_close(http_transaction_h http_transaction) session->active_transaction_count--; if (transaction) { - if (transaction->easy_handle != NULL) { curl_easy_cleanup(transaction->easy_handle); transaction->easy_handle = NULL; @@ -394,9 +410,7 @@ API int http_transaction_close(http_transaction_h http_transaction) transaction->write_cb = NULL; transaction->completed_cb = NULL; transaction->aborted_cb = NULL; - - transaction->upload_progress_cb = NULL; - transaction->download_progress_cb = NULL; + transaction->progress_cb = NULL; if (request) { if (request->host_uri != NULL) { @@ -457,16 +471,21 @@ API int http_transaction_close(http_transaction_h http_transaction) return HTTP_ERROR_NONE; } -API int http_transaction_pause(http_transaction_h http_transaction, http_pause_state_e pause_state) +API int http_transaction_pause(http_transaction_h http_transaction, http_pause_type_e pause_type) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); - _retvm_if(pause_state < HTTP_PAUSE_RECV || pause_state > HTTP_PAUSE_ALL, HTTP_ERROR_INVALID_PARAMETER, + _retvm_if(pause_type < HTTP_PAUSE_RECV || pause_type > HTTP_PAUSE_ALL, HTTP_ERROR_INVALID_PARAMETER, "Wrong pause state \n"); __http_transaction_h *transaction = (__http_transaction_h *)http_transaction; + int ret = 0; - curl_easy_pause(transaction->easy_handle, pause_state); + ret = curl_easy_pause(transaction->easy_handle, pause_type); + if (ret != 0) { + ERR("Fail to pause!(%d)", ret); + return HTTP_ERROR_OPERATION_FAILED; + } return HTTP_ERROR_NONE; } @@ -477,27 +496,29 @@ API int http_transaction_resume(http_transaction_h http_transaction) "parameter(http_transaction) is NULL\n"); __http_transaction_h *transaction = (__http_transaction_h *)http_transaction; + int ret = 0; - curl_easy_pause(transaction->easy_handle, CURLPAUSE_CONT); + ret = curl_easy_pause(transaction->easy_handle, CURLPAUSE_CONT); + if (ret != 0) { + ERR("Fail to resume!(%d)", ret); + return HTTP_ERROR_OPERATION_FAILED; + } return HTTP_ERROR_NONE; } -API int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_upload_progress_cb upload_progress_cb, - http_transaction_download_progress_cb download_progress_cb) +API int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_progress_cb progress_cb, void* user_data) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); - _retvm_if(upload_progress_cb == NULL, HTTP_ERROR_INVALID_PARAMETER, - "parameter(upload_progress_cb) is NULL\n"); - _retvm_if(download_progress_cb == NULL, HTTP_ERROR_INVALID_PARAMETER, - "parameter(download_progress_cb) is NULL\n"); + _retvm_if(progress_cb == NULL, HTTP_ERROR_INVALID_PARAMETER, + "parameter(progress_cb) is NULL\n"); __http_transaction_h *transaction = (__http_transaction_h *)http_transaction; - transaction->upload_progress_cb = upload_progress_cb; - transaction->download_progress_cb = download_progress_cb; + transaction->progress_cb = progress_cb; + transaction->progress_user_data = user_data; return HTTP_ERROR_NONE; } @@ -562,17 +583,16 @@ API int http_transaction_set_completed_cb(http_transaction_h http_transaction, h return HTTP_ERROR_NONE; } -API int http_transaction_set_aborted_cb(http_transaction_h http_transaction, http_transaction_aborted_cb aborted_cb, void* user_data) +API int http_transaction_set_aborted_cb(http_transaction_h http_transaction, http_transaction_aborted_cb aborted_cb, void* user_data) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, - "parameter(http_transaction) is NULL\n"); + "parameter(http_transaction) is NULL\n"); _retvm_if(aborted_cb == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(aborted_cb) is NULL\n"); __http_transaction_h *transaction = (__http_transaction_h *)http_transaction; transaction->aborted_cb = aborted_cb; - transaction->aborted_user_data = user_data; return HTTP_ERROR_NONE; } @@ -583,9 +603,7 @@ API int http_transaction_unset_progress_cb(http_transaction_h http_transaction) "parameter(http_transaction) is NULL\n"); __http_transaction_h *transaction = (__http_transaction_h *)http_transaction; - - transaction->upload_progress_cb = NULL; - transaction->download_progress_cb = NULL; + transaction->progress_cb = NULL; return HTTP_ERROR_NONE; } @@ -684,22 +702,24 @@ API int http_transaction_set_server_certificate_verification(http_transaction_h return HTTP_ERROR_NONE; } -API int http_transaction_close_all(http_session_h http_session) +API int http_session_destroy_all_transactions(http_session_h http_session) { _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_session) is NULL\n"); + int ret = 0; GSList *list = NULL; __http_session_h *session = (__http_session_h *)http_session; for (list = transaction_list; list; list = list->next) { __http_transaction_h *transaction = (__http_transaction_h *)list->data; if (session->session_id == transaction->session_id) { - DBG("[Seonah]Close.. (%p)", list->data); _remove_transaction_from_list(list->data); - DBG("[Seonah]Close..1"); - http_transaction_close((http_transaction_h) transaction); - DBG("[Seonah]Close..11"); + ret = http_transaction_destroy((http_transaction_h) transaction); + if (ret != HTTP_ERROR_NONE) { + ERR("Fail to destroy transaction!!"); + return HTTP_ERROR_OPERATION_FAILED; + } } } diff --git a/test/http_test.c b/test/http_test.c index f3cf8de..3fbf37c 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -21,183 +21,231 @@ #include "http.h" -static GMainLoop *mainloop = NULL; - +#define ERR(x, y) printf("[ERR] %s(%d)\n", x, y) +#define PRG(x, y) printf("[PRG] %s(%p)\n", x, y) #define DBG printf +#define MAX_URI_LEN 1024 FILE* fp1 = NULL; FILE* fp2 = NULL; -http_session_h session_handle = NULL; -http_transaction_h transaction_handle1 = NULL; -http_transaction_h transaction_handle2 = NULL; -int count = 0; - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -int add_http_header(http_transaction_h transaction_handle) +/////////////////Callbacks//////////////////////////////////////////////////////////////////////////// +void __transaction_header_cb(http_transaction_h transaction, char *header, size_t header_len, void *user_data) { - http_header_add_field(transaction_handle, "Connection", "close"); - //http_header_add_field(transaction_handle, "Accept-Charset", "ISO-8859-1,UTF-8;q=0.7,*;q=0.7"); - //http_header_add_field(transaction_handle, "Cache-Control", "no-cache"); - //http_header_add_field(transaction_handle, "Accept-Language", "en-us;q=0.3"); - - return 0; + PRG("transaction_header_cb", transaction); } -int remove_http_header(http_transaction_h transaction_handle) +void __transaction_body_cb(http_transaction_h transaction, char *body, size_t size, size_t nmemb, void *user_data) { - http_header_remove_field(transaction_handle, "Connection"); - //http_header_remove_field(transaction_handle, "Accept-Charset"); - //http_header_remove_field(transaction_handle, "Cache-Control"); - //http_header_remove_field(transaction_handle, "Accept-Language"); - - return 0; + PRG("transaction_body_cb", transaction); + int written = size * nmemb; + DBG("Received: %d\n", written); } -void print_response_header(http_transaction_h transaction_handle) +void __transaction_write_cb(http_transaction_h transaction, int recommended_chunk_size, void *user_data) { - char* uri = NULL; - char* status_text = NULL; - http_status_code_e status_code; - http_version_e version; - - DBG("########################## Result #########################################\n"); - - http_request_get_uri(transaction_handle, &uri); - http_response_get_version(transaction_handle, &version); - http_response_get_status_code(transaction_handle, &status_code); - http_response_get_status_text(transaction_handle, &status_text); - - DBG("URI(%s) HTTP version (%d) Status Code (%d) Status message (%s)\n", uri, version, status_code, status_text); + PRG("transaction_write_cb", transaction); + DBG("recommended_chunk_size:%d\n", recommended_chunk_size); } -void close_transaction(http_transaction_h transaction_handle) +void __transaction_completed_cb(http_transaction_h transaction, void *user_data) { - remove_http_header(transaction_handle); - - http_transaction_close(transaction_handle); + PRG("transaction_completed_cb", transaction); - //transaction_handle = NULL; -} + http_status_code_e status = 0; + int ret; + char *uri = NULL; -void delete_session(http_session_h session) -{ - http_transaction_close_all(session_handle); + ret = http_transaction_request_get_uri(transaction, &uri); + ret = http_transaction_response_get_status_code(transaction, &status); - http_delete_session(session_handle); - session_handle = NULL; - http_deinit(); + 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"); } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////Callbacks//////////////////////////////////////////////////////////////////////////// -void transaction_header_cb(http_transaction_h transaction_handle, char *header, size_t header_len, void *user_data) +void __transaction_aborted_cb(http_transaction_h transaction, http_error_code_e error, void *user_data) { - DBG("########################## transaction_header_cb(%p)#########################################\n", transaction_handle); - + PRG("transaction_aborted_cb", transaction); + DBG("aborted reason: %d\n", error); } -void transaction_body_cb(http_transaction_h transaction_handle, char *body, size_t size, size_t nmemb, void *user_data) +void _register_callbacks(http_transaction_h transaction) { - DBG("########################## transaction_body_cb(%p)#########################################\n", transaction_handle); - int written = size * nmemb; - DBG("Received: %d\n", written); - //if (written) { - //fwrite(body, size, nmemb, fp1); - //} + http_transaction_set_received_header_cb(transaction, __transaction_header_cb, NULL); + http_transaction_set_received_body_cb(transaction, __transaction_body_cb, NULL); + http_transaction_set_uploaded_cb(transaction, __transaction_write_cb, NULL); + http_transaction_set_completed_cb(transaction, __transaction_completed_cb, NULL); + http_transaction_set_aborted_cb(transaction, __transaction_aborted_cb, NULL); } -void transaction_write_cb(http_transaction_h transaction_handle, int recommended_chunk_size, void *user_data) +int test_http_init(void) { - DBG("########################## transaction_write_cb(%p)#########################################\n", transaction_handle); - - DBG("recommended_chunk_size:%d\n", recommended_chunk_size); + int ret = http_init(); + if (ret == HTTP_ERROR_NONE) + return 1; + else return 0; } -void transaction_completed_cb(http_transaction_h transaction_handle, void *user_data) +int test_http_deinit(void) { - DBG("########################## transaction_completed_cb(%p)#########################################\n", transaction_handle); - - char *uri = NULL; - - http_request_get_uri(transaction_handle, &uri); - DBG("Completed uri: %s\n", uri); - print_response_header(transaction_handle); - count--; - - if (count == 0) - g_main_loop_quit((GMainLoop*)mainloop); + int ret = http_deinit(); + if (ret == HTTP_ERROR_NONE) + return 1; + else return 0; } -void transaction_aborted_cb(http_transaction_h transaction_handle, int reason, void *user_data) +int test_simple_get(void) { - DBG("########################## transaction_aborted_cb(%p)#########################################\n", transaction_handle); - - close_transaction(transaction_handle); - count--; - - if (count == 0) - g_main_loop_quit((GMainLoop*)mainloop); + 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); + return 0; + } + + http_transaction_request_get_method(transaction, &method); + ret = http_transaction_request_set_uri(transaction, uri); + if (ret != 0) { + ERR("Fail to set URI", ret); + return 0; + } + + _register_callbacks(transaction); + ret = http_transaction_submit(transaction); + + if (ret != 0) { + ERR("Fail to submit transaction", ret); + return 0; + } + + return 1; } -http_transaction_h create_http_request(http_session_h session_handle, gchar* host_url) +int test_multiple_get(void) { - http_transaction_h transaction_handle = NULL; - - //http_session_set_auto_redirection(session_handle, TRUE); - - http_open_transaction(session_handle, HTTP_METHOD_GET, &transaction_handle); - - http_request_set_uri(transaction_handle, host_url); - add_http_header(transaction_handle); - count++; - - return transaction_handle; + int ret; + http_session_h session = NULL; + http_transaction_h transaction[10]; + int count, session_mode; + 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); + ret = scanf("%1023s", uri); + ret = http_session_open_transaction(session, HTTP_METHOD_GET, &transaction[i]); + if (ret != 0) { + ERR("Fail to open transaction", ret); + return 0; + } + ret = http_transaction_request_set_uri(transaction[i], uri); + if (ret != 0) { + ERR("Fail to set URI", ret); + return 0; + } + _register_callbacks(transaction[i]); + http_transaction_submit(transaction[i]); + } + + return 1; } -int submit_http_request(http_transaction_h transaction_handle) +gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) { - http_transaction_submit(transaction_handle); - - return 0; + 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 main() +int main(int argc, char **argv) { - DBG("########################## main:Enter#########################################\n"); - - mainloop = g_main_loop_new(NULL, FALSE); - - http_init(); + GMainLoop *mainloop; - http_create_session(&session_handle, HTTP_SESSION_MODE_NORMAL); +#if !GLIB_CHECK_VERSION(2, 36, 0) + g_type_init(); +#endif + mainloop = g_main_loop_new(NULL, false); - transaction_handle1 = create_http_request(session_handle, "https://www.google.com"); - transaction_handle2 = create_http_request(session_handle, "http://www.naver.com"); + 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); - http_transaction_set_server_certificate_verification(transaction_handle1, 0); - http_transaction_set_received_header_cb(transaction_handle1, transaction_header_cb, NULL); - http_transaction_set_received_body_cb(transaction_handle1, transaction_body_cb, NULL); - http_transaction_set_uploaded_cb(transaction_handle1, transaction_write_cb, NULL); - http_transaction_set_completed_cb(transaction_handle1, transaction_completed_cb, NULL); - http_transaction_set_aborted_cb(transaction_handle1, transaction_aborted_cb, NULL); - - http_transaction_set_received_header_cb(transaction_handle2, transaction_header_cb, NULL); - http_transaction_set_received_body_cb(transaction_handle2, transaction_body_cb, NULL); - http_transaction_set_uploaded_cb(transaction_handle2, transaction_write_cb, NULL); - http_transaction_set_completed_cb(transaction_handle2, transaction_completed_cb, NULL); - http_transaction_set_aborted_cb(transaction_handle2, transaction_aborted_cb, NULL); - - DBG("transaction1(%p), transaction2(%p)\n", transaction_handle1, transaction_handle2); - submit_http_request(transaction_handle1); - submit_http_request(transaction_handle2); + return 0; +} - g_main_loop_run(mainloop); - http_transaction_close_all(session_handle); - delete_session(session_handle); - DBG("########################## main:Exit#########################################\n"); - return 0; -}