/**
* @brief Initializes the Http module.
* @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_OPERATION_FAILED Operation failed
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
- * @retval #HTTP_ERROR_PERMISSION_DENIED Permission denied
* @see http_deinit()
*/
int http_init(void);
/**
* @brief Creates the Http session handle.
* @since_tizen 3.0
- * @remarks The @a http_session should be released using http_session_destroy().
+ * @remarks The @a http_session should be released using http_session_destroy(). \
+ * Opened transactions can't be submitted after destroing session handle.
* @param[in] mode The http session mode
* @param[out] http_session The http session handle
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_OUT_OF_MEMORY Out of memory
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
* @see http_session_destroy()
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
* @see http_session_create()
*/
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_OUT_OF_MEMORY Out of memory
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
* @see http_session_get_auto_redirection()
*/
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
* @see http_session_set_auto_redirection()
*/
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_session_get_active_transaction_count(http_session_h http_session, int *active_transaction_count);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_session_get_max_transaction_count(http_session_h http_session, int *transaction_count);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_OPERATION_fAILED Operation failed
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
/**
* @brief Submits the Http request.
* @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
* @param[in] http_transaction The http transaction handle
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
+ * @retval #HTTP_ERROR_PERMISSION_DENIED Permission denied
*/
int http_transaction_submit(http_transaction_h http_transaction);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
* @see http_transaction_create()
*/
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_received_header_cb(http_transaction_h http_transaction, http_transaction_header_cb header_cb, void* user_data);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_received_body_cb(http_transaction_h http_transaction, http_transaction_body_cb body_cb, void* user_data);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_uploaded_cb(http_transaction_h http_transaction, http_transaction_write_cb write_cb, void* user_data);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_completed_cb(http_transaction_h http_transaction, http_transaction_completed_cb completed_cb, void* user_data);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_aborted_cb(http_transaction_h http_http_transaction, http_transaction_aborted_cb aborted_cb, void* user_data);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_progress_cb progress_cb, void* user_data);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_timeout(http_transaction_h http_transaction, int timeout);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_get_timeout(http_transaction_h http_transaction, int *timeout);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_OPERATION_FAILED Operation failed
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_OPERATION_FAILED Operation failed
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_ready_to_write(http_transaction_h http_transaction, bool read_to_write);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_interface_name(http_transaction_h http_transaction, const char *interface_name);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_get_interface_name(http_transaction_h http_transaction, char **interface_name);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_set_server_certificate_verification(http_transaction_h http_transaction, bool verify);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_get_server_certificate_verification(http_transaction_h http_transaction, bool* verify);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_header_add_field(http_transaction_h http_transaction, const char *field_name, const char* field_value);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_set_method(http_transaction_h http_transaction, http_method_e method);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_get_method(http_transaction_h http_transaction, http_method_e *method);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_set_version(http_transaction_h http_transaction, http_version_e version);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_get_version(http_transaction_h http_transaction, http_version_e *version);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_set_uri(http_transaction_h http_transaction, const char *host_uri);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_get_uri(http_transaction_h http_transaction, char **host_uri);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_set_accept_encoding(http_transaction_h http_transaction, const char *encoding);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_set_cookie(http_transaction_h http_transaction, const char *cookie);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_get_cookie(http_transaction_h http_transaction, const char **cookie);
/**
- * @brief Sets the request message body.
+ * @brief Writes the request message body.
+ * @details This function writes the request message body in the internal queue. \n
+ * The written queue for request body is uploaded after invoking http_transaction_submit()
* @since_tizen 3.0
* @param[in] http_transaction The http transaction handle
* @param[in] body The message body data
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_request_write_body(http_transaction_h http_transaction, const char *body);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_response_get_status_code(http_transaction_h http_transaction, http_status_code_e *status_code);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_response_get_status_text(http_transaction_h http_transaction, char **status_text);
* @return 0 on success, otherwise negative error value
* @retval #HTTP_ERROR_NONE Successful
* @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation
* @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported
*/
int http_transaction_response_get_version(http_transaction_h http_transaction, http_version_e *version);
void print_curl_multi_errorCode(CURLMcode code);
+bool _http_is_init(void);
gchar* _get_http_method(http_method_e method);
http_method_e _get_method(gchar* method);
gchar* _get_proxy();
#define THREAD_ID pthread_self()
/* This array will store all of the mutexes available to OpenSSL. */
-static MUTEX_TYPE *mutex_buf= NULL;
+static MUTEX_TYPE *mutex_buf = NULL;
+static bool is_init = false;
+
+bool _http_is_init(void)
+{
+ return is_init;
+}
+
+static void __http_set_init(bool init)
+{
+ is_init = init;
+}
http_method_e _get_method(gchar* method)
{
- if (g_strcmp0(method, "GET") == 0) {
+ if (g_strcmp0(method, "GET") == 0)
return HTTP_METHOD_GET;
- } else if (g_strcmp0(method, "OPTIONS") == 0) {
+ else if (g_strcmp0(method, "OPTIONS") == 0)
return HTTP_METHOD_OPTIONS;
- } else if (g_strcmp0(method, "HEAD") == 0) {
+ else if (g_strcmp0(method, "HEAD") == 0)
return HTTP_METHOD_HEAD;
- } else if (g_strcmp0(method, "DELETE") == 0) {
+ else if (g_strcmp0(method, "DELETE") == 0)
return HTTP_METHOD_DELETE;
- } else if (g_strcmp0(method, "TRACE") == 0) {
+ else if (g_strcmp0(method, "TRACE") == 0)
return HTTP_METHOD_TRACE;
- } else if (g_strcmp0(method, "POST") == 0) {
+ else if (g_strcmp0(method, "POST") == 0)
return HTTP_METHOD_POST;
- } else if (g_strcmp0(method, "PUT") == 0) {
+ else if (g_strcmp0(method, "PUT") == 0)
return HTTP_METHOD_PUT;
- } else if (g_strcmp0(method, "CONNECT") == 0) {
+ else if (g_strcmp0(method, "CONNECT") == 0)
return HTTP_METHOD_CONNECT;
- }
return HTTP_METHOD_GET;
}
}
CATCH:
- if (connection_destroy(connection) < 0) {
+ if (connection_destroy(connection) < 0)
DBG("Fail to destroy network handle\n");
- }
return proxy_addr;
}
if (!mutex_buf)
return 0;
- for (index = 0; index < CRYPTO_num_locks(); index++) {
+ for (index = 0; index < CRYPTO_num_locks(); index++)
MUTEX_SETUP(mutex_buf[index]);
- }
+
CRYPTO_set_id_callback(id_function);
CRYPTO_set_locking_callback(locking_function);
CRYPTO_set_id_callback(NULL);
CRYPTO_set_locking_callback(NULL);
- for (index = 0; index < CRYPTO_num_locks(); index++) {
+ for (index = 0; index < CRYPTO_num_locks(); index++)
MUTEX_CLEANUP(mutex_buf[index]);
- }
free(mutex_buf);
mutex_buf = NULL;
API int http_init(void)
{
+ _retvm_if(_http_is_init(), HTTP_ERROR_INVALID_OPERATION,
+ "http is already initialized!!");
+
int ret = 0;
+ __http_set_init(true);
+
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
DBG("curl_global_init failed, so returning!\n");
return HTTP_ERROR_OPERATION_FAILED;
API int http_deinit(void)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http is already deinitialized!!");
+
int ret = 0;
+ __http_set_init(false);
+
ret = thread_cleanup();
if (!ret) {
DBG("ssl thread de-initialization failed!\n");
gpointer key = NULL;
gpointer value = NULL;
- if (!header->hash_table) {
+ if (!header->hash_table)
return NULL;
- }
g_hash_table_iter_init(&iter, header->hash_table);
API int http_transaction_header_add_field(http_transaction_h http_transaction, const char *field_name, const char* field_value)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(field_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
__http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
__http_header_h *header = transaction->header;
- if (!header->hash_table) {
+ if (!header->hash_table)
header->hash_table = g_hash_table_new(g_str_hash, g_str_equal);
- }
- g_hash_table_insert(header->hash_table, (char*)field_name, (char*)field_value);
+ g_hash_table_insert(header->hash_table, g_strdup(field_name), g_strdup(field_value));
return HTTP_ERROR_NONE;
}
API int http_transaction_header_remove_field(http_transaction_h http_transaction, const char *field_name)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(field_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
__http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
__http_header_h *header = transaction->header;
+ gpointer orig_key = NULL;
+ gpointer orig_value = NULL;
+ g_hash_table_lookup_extended(header->hash_table, field_name, &orig_key, &orig_value);
if (g_hash_table_remove(header->hash_table, field_name)) {
+ if (orig_key)
+ g_free(orig_key);
+
+ if (orig_value)
+ g_free(orig_value);
+
return HTTP_ERROR_NONE;
- }
- else {
+ } else {
ERR("field_name doesn't exist!!");
return HTTP_ERROR_INVALID_OPERATION;
}
API int http_transaction_header_get_field_value(http_transaction_h http_transaction, const char *field_name, char **field_value)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(field_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
__http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
__http_header_h *header = transaction->header;
+ const char *value;
if (header->hash_table == NULL) {
*field_value = NULL;
return HTTP_ERROR_INVALID_OPERATION;
}
- *field_value = g_hash_table_lookup(header->hash_table, field_name);
- if (*field_value == NULL) {
+ value = g_hash_table_lookup(header->hash_table, field_name);
+ if (value == NULL) {
ERR("filed_name doesn't exist!!");
return HTTP_ERROR_INVALID_OPERATION;
}
+ *field_value = g_strdup(value);
return HTTP_ERROR_NONE;
}
API int http_transaction_request_set_method(http_transaction_h http_transaction, http_method_e method)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
API int http_transaction_request_get_method(http_transaction_h http_transaction, http_method_e *method)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(method == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_request_set_version(http_transaction_h http_transaction, http_version_e version)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
API int http_transaction_request_get_version(http_transaction_h http_transaction, http_version_e *version)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(version == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_request_set_uri(http_transaction_h http_transaction, const char *host_uri)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(host_uri == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_request_get_uri(http_transaction_h http_transaction, char **host_uri)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(host_uri == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_request_set_accept_encoding(http_transaction_h http_transaction, const char *encoding)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(encoding == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_request_get_accept_encoding(http_transaction_h http_transaction, char **encoding)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(encoding == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_request_set_cookie(http_transaction_h http_transaction, const char *cookie)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(cookie == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_request_get_cookie(http_transaction_h http_transaction, const char **cookie)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(cookie == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_request_write_body(http_transaction_h http_transaction, const char *body)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(body == NULL, HTTP_ERROR_INVALID_PARAMETER,
__http_response_h*response = (__http_response_h *)transaction->response;
char status_code[HTTP_STATUS_CODE_SIZE] = {0, };
- //char reason_phrase[HTTP_REASON_PHRASE_SIZE] = {0, };
char* start = NULL;
char* end = NULL;
API int http_transaction_response_get_status_code(http_transaction_h http_transaction, http_status_code_e *status_code)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(status_code == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_response_get_status_text(http_transaction_h http_transaction, char **status_text)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(status_text == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_response_get_version(http_transaction_h http_transaction, http_version_e *version)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(version == NULL, HTTP_ERROR_INVALID_PARAMETER,
DBG("Completed -%s: result(%d)\n", url, curl_code);
switch (curl_code) {
- case CURLE_OK:
- if (transaction->completed_cb)
- transaction->completed_cb(transaction, transaction->completed_user_data);
- break;
- case CURLE_COULDNT_RESOLVE_HOST:
- if (transaction->aborted_cb)
- transaction->aborted_cb(transaction, HTTP_ERROR_COULDNT_RESOLVE_HOST, transaction->aborted_user_data);
- break;
- case CURLE_COULDNT_CONNECT:
- if (transaction->aborted_cb)
- transaction->aborted_cb(transaction, HTTP_ERROR_COULDNT_CONNECT, transaction->aborted_user_data);
- break;
- case CURLE_SSL_CONNECT_ERROR:
- if (transaction->aborted_cb)
- transaction->aborted_cb(transaction, HTTP_ERROR_SSL_CONNECT_ERROR, transaction->aborted_user_data);
- break;
- case CURLE_OPERATION_TIMEDOUT:
- if (transaction->aborted_cb)
- transaction->aborted_cb(transaction, HTTP_ERROR_OPERATION_TIMEDOUT, transaction->aborted_user_data);
- break;
- default:
- break;
+ case CURLE_OK:
+ if (transaction->completed_cb)
+ transaction->completed_cb(transaction, transaction->completed_user_data);
+ break;
+ case CURLE_COULDNT_RESOLVE_HOST:
+ if (transaction->aborted_cb)
+ transaction->aborted_cb(transaction, HTTP_ERROR_COULDNT_RESOLVE_HOST, transaction->aborted_user_data);
+ break;
+ case CURLE_COULDNT_CONNECT:
+ if (transaction->aborted_cb)
+ transaction->aborted_cb(transaction, HTTP_ERROR_COULDNT_CONNECT, transaction->aborted_user_data);
+ break;
+ case CURLE_SSL_CONNECT_ERROR:
+ if (transaction->aborted_cb)
+ transaction->aborted_cb(transaction, HTTP_ERROR_SSL_CONNECT_ERROR, transaction->aborted_user_data);
+ break;
+ case CURLE_OPERATION_TIMEDOUT:
+ if (transaction->aborted_cb)
+ transaction->aborted_cb(transaction, HTTP_ERROR_OPERATION_TIMEDOUT, transaction->aborted_user_data);
+ break;
+ default:
+ break;
}
curl_multi_remove_handle(session->multi_handle, curl_easy);
CURLMcode ret;
ret = curl_multi_socket_action(session->multi_handle, CURL_SOCKET_TIMEOUT, 0, &(session->still_running));
- if (ret == CURLM_OK) {
- //DBG("CURLM_OK - Called curl_multi_socket_action()\n");
- } else {
+ if (ret == CURLM_OK)
+ /* DBG("CURLM_OK - Called curl_multi_socket_action()\n"); */
+ else
print_curl_multi_errorCode(ret);
- }
_check_curl_multi_status(session);
CURLMcode ret = CURLM_OK;
ret = curl_multi_socket_action(session->multi_handle, fd, action, &running_handles);
- if (ret == CURLM_OK) {
- //DBG("CURLM_OK: Called curl_multi_socket_action(%d)\n", action);
- } else {
+ if (ret == CURLM_OK)
+ /* DBG("CURLM_OK: Called curl_multi_socket_action(%d)\n", action); */
+ else
print_curl_multi_errorCode(ret);
- }
_check_curl_multi_status(session);
fd = g_io_channel_unix_get_fd(channel);
- //CURL_CSELECT_IN : 1, CURL_CSELECT_OUT: 2
+ /* CURL_CSELECT_IN : 1, CURL_CSELECT_OUT: 2 */
action = (condition & G_IO_IN ? CURL_CSELECT_IN : 0) | (condition & G_IO_OUT ? CURL_CSELECT_OUT : 0);
ret = _handle_event(fd, action, user_data);
- if (ret) {
+ if (ret)
return TRUE;
- }
return FALSE;
}
/* Clean up the __http_socket_info_h structure */
static void _remove_socket_info(__http_socket_info_h *sock_info)
{
- if (!sock_info) {
+ if (!sock_info)
return;
- }
+
if (sock_info->event) {
g_source_remove(sock_info->event);
sock_info->event = 0;
API int http_session_create(http_session_mode_e mode, http_session_h *http_session)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_session) is NULL\n");
curl_multi_setopt(session->multi_handle, CURLMOPT_TIMERFUNCTION, __handle_timer_cb);
curl_multi_setopt(session->multi_handle, CURLMOPT_TIMERDATA, session);
- if (mode == HTTP_SESSION_MODE_PIPELINING) {
+ if (mode == HTTP_SESSION_MODE_PIPELINING)
curl_multi_setopt(session->multi_handle, CURLMOPT_PIPELINING, 1L);
- }
*http_session = (http_session_h)session;
API int http_session_destroy(http_session_h http_session)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_session) is NULL\n");
API int http_session_set_auto_redirection(http_session_h http_session, bool auto_redirection)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_session) is NULL\n");
API int http_session_get_auto_redirection(http_session_h http_session, bool *auto_redirect)
{
- _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
- "parameter(http_session) is NULL\n");
- _retvm_if(auto_redirect == NULL, HTTP_ERROR_INVALID_PARAMETER,
- "parameter(auto_redirect) is NULL\n");
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION, "http isn't initialized");
+ _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_session) is NULL\n");
+ _retvm_if(auto_redirect == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(auto_redirect) is NULL\n");
__http_session_h *session = (__http_session_h *)http_session;
API int http_session_get_active_transaction_count(http_session_h http_session, int *active_transaction_count)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_session) is NULL\n");
_retvm_if(active_transaction_count == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_session_get_max_transaction_count(http_session_h http_session, int *transaction_count)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_session) is NULL\n");
_retvm_if(transaction_count == NULL, HTTP_ERROR_INVALID_PARAMETER,
__http_session_h *session = (__http_session_h *)http_session;
- if (session->session_mode == HTTP_SESSION_MODE_NORMAL) {
+ if (session->session_mode == HTTP_SESSION_MODE_NORMAL)
*transaction_count = _MAX_HTTP_TRANSACTIONS_PER_SESSION_NORMAL;
- } else if (session->session_mode == HTTP_SESSION_MODE_PIPELINING) {
+ else if (session->session_mode == HTTP_SESSION_MODE_PIPELINING)
*transaction_count = _MAX_HTTP_TRANSACTIONS_PER_SESSION_PIPE;
- } else {
+ else
*transaction_count = -1;
- }
return HTTP_ERROR_NONE;
}
void _remove_transaction_from_list(http_transaction_h http_transaction)
{
transaction_list = g_slist_remove(transaction_list, http_transaction);
- //g_free(http_transaction);
}
void _remove_transaction_list(void)
if (request->cookie)
curl_easy_setopt(transaction->easy_handle, CURLOPT_COOKIE, request->cookie);
- //The connection timeout is 30s. (default)
+ /* The connection timeout is 30s. (default) */
curl_easy_setopt(transaction->easy_handle, CURLOPT_CONNECTTIMEOUT, _HTTP_DEFAULT_CONNECTION_TIMEOUT);
if (transaction->timeout > 0) {
curl_easy_setopt(transaction->easy_handle, CURLOPT_TIMEOUT, transaction->timeout);
} else if (transaction->timeout == 0) {
- //Set the transaction timeout. The timeout includes connection timeout.
+ /* Set the transaction timeout. The timeout includes connection timeout. */
curl_easy_setopt(transaction->easy_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);
curl_easy_setopt(transaction->easy_handle, CURLOPT_LOW_SPEED_TIME, 30L);
}
curl_easy_setopt(transaction->easy_handle, CURLOPT_WRITEFUNCTION, __handle_body_cb);
curl_easy_setopt(transaction->easy_handle, CURLOPT_WRITEDATA, transaction);
- http_transaction_header_get_field_value(transaction, "Content-Length", &field_value);
- if (field_value) {
+ if (http_transaction_header_get_field_value(transaction, "Content-Length", &field_value) == HTTP_ERROR_NONE) {
content_len = atoi(field_value);
-
if (content_len > 0) {
curl_easy_setopt(transaction->easy_handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)(content_len));
DBG("Set the Content-Length(%d).", content_len);
API int http_session_open_transaction(http_session_h http_session, http_method_e method, http_transaction_h *http_transaction)
{
- _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
- "parameter(http_session) is NULL\n");
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION, "http isn't initialized");
+ _retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_session) is NULL\n");
__http_transaction_h *transaction = NULL;
API int http_transaction_submit(http_transaction_h http_transaction)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL");
API int http_transaction_destroy(http_transaction_h http_transaction)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
API int http_transaction_pause(http_transaction_h http_transaction, http_pause_type_e pause_type)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(pause_type < HTTP_PAUSE_RECV || pause_type > HTTP_PAUSE_ALL, HTTP_ERROR_INVALID_PARAMETER,
- "Wrong pause state \n");
+ "Wrong pause state \n");
__http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
int ret = 0;
API int http_transaction_resume(http_transaction_h http_transaction)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
API int http_transaction_set_progress_cb(http_transaction_h http_transaction, http_transaction_progress_cb progress_cb, void* user_data)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(progress_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_set_received_header_cb(http_transaction_h http_transaction, http_transaction_header_cb header_cb, void* user_data)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(header_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_set_received_body_cb(http_transaction_h http_transaction, http_transaction_body_cb body_cb, void* user_data)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(body_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_set_uploaded_cb(http_transaction_h http_transaction, http_transaction_write_cb write_cb, void* user_data)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(write_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_set_completed_cb(http_transaction_h http_transaction, http_transaction_completed_cb completed_cb, void* user_data)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(completed_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_set_aborted_cb(http_transaction_h http_transaction, http_transaction_aborted_cb aborted_cb, void* user_data)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(aborted_cb == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_unset_progress_cb(http_transaction_h http_transaction)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
API int http_transaction_set_timeout(http_transaction_h http_transaction, int timeout)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
API int http_transaction_get_timeout(http_transaction_h http_transaction, int *timeout)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(timeout == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_set_interface_name(http_transaction_h http_transaction, const char *interface_name)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(interface_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_get_interface_name(http_transaction_h http_transaction, char **interface_name)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
_retvm_if(interface_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
API int http_transaction_set_ready_to_write(http_transaction_h http_transaction, bool read_to_write)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
API int http_transaction_get_server_certificate_verification(http_transaction_h http_transaction, bool* verify)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
API int http_transaction_set_server_certificate_verification(http_transaction_h http_transaction, bool verify)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_transaction) is NULL\n");
API int http_session_destroy_all_transactions(http_session_h http_session)
{
+ _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION,
+ "http isn't initialized");
_retvm_if(http_session == NULL, HTTP_ERROR_INVALID_PARAMETER,
"parameter(http_session) is NULL\n");
#include <stdio.h>
+#include <string.h>
#include <glib.h>
#include <gio/gio.h>
FILE* fp1 = NULL;
FILE* fp2 = NULL;
-/////////////////Callbacks////////////////////////////////////////////////////////////////////////////
+http_session_h session = NULL;
+
void __transaction_header_cb(http_transaction_h transaction, char *header, size_t header_len, void *user_data)
{
PRG("transaction_header_cb", transaction);
ret = http_transaction_request_get_uri(transaction, &uri);
ret = http_transaction_response_get_status_code(transaction, &status);
+ http_transaction_header_remove_field(transaction, "Content-Length");
DBG("%s - status(%d)\n", uri, status);
ret = http_transaction_destroy(transaction);
if (ret == HTTP_ERROR_NONE) DBG("Success to close transaction\n");
else DBG("Fail to close transaction\n");
}
-void __transaction_aborted_cb(http_transaction_h transaction, http_error_code_e error, void *user_data)
+void __transaction_aborted_cb(http_transaction_h transaction, int reason, void *user_data)
{
PRG("transaction_aborted_cb", transaction);
- DBG("aborted reason: %d\n", error);
+ DBG("aborted reason: %d\n", reason);
}
void _register_callbacks(http_transaction_h transaction)
else return 0;
}
+int test_http_session_create(void)
+{
+ int ret;
+ int session_mode;
+
+ printf("Select session mode(0: NORMAL 1: PIPELINING): ");
+ ret = scanf("%d", &session_mode);
+
+ ret = http_session_create(session_mode, &session);
+ if (ret != HTTP_ERROR_NONE) {
+ ERR("Fail to create session", ret);
+ return 0;
+ }
+ return 1;
+}
+
+int test_http_session_destroy(void)
+{
+ int ret = http_session_destroy(session);
+ if (ret != HTTP_ERROR_NONE) {
+ ERR("Fail to destroy session", ret);
+ return 0;
+ }
+
+ return 1;
+}
+
int test_simple_get(void)
{
char uri[1024];
int ret;
- http_session_h session = NULL;
http_transaction_h transaction = NULL;
http_method_e method;
printf("Input uri: ");
ret = scanf("%1023s", uri);
- ret = http_session_create(HTTP_SESSION_MODE_NORMAL, &session);
- if (ret != 0) {
- ERR("Fail to create session", ret);
- return 0;
- }
-
ret = http_session_open_transaction(session, HTTP_METHOD_GET, &transaction);
if (ret != 0) {
ERR("Fail to open transaction", ret);
int test_multiple_get(void)
{
int ret;
- http_session_h session = NULL;
http_transaction_h transaction[10];
- int count, session_mode;
+ int count;
int i;
printf("Input count of transactions(1~10): ");
ret = scanf("%d", &count);
- printf("Select session mode(0: NORMAL 1: PIPELINING): ");
- ret = scanf("%d", &session_mode);
-
- ret = http_session_create(session_mode, &session);
- if (ret != 0) {
- ERR("Fail to create session", ret);
- return 0;
- }
-
for (i = 0; i < count; i++) {
char uri[1024];
printf("Input uri for transaction[%d]: ", i + 1);
return 1;
}
+int test_simple_post(void)
+{
+ int ret;
+ http_transaction_h transaction;
+ const char* post_msg = "name=tizen&project=capi-network-curl";
+ char field_value[15];
+
+ ret = http_session_open_transaction(session, HTTP_METHOD_POST, &transaction);
+ if (ret != 0) {
+ ERR("Fail to open transaction", ret);
+ return 0;
+ }
+ ret = http_transaction_request_set_uri(transaction, "http://posttestserver.com/post.php");
+ if (ret != 0) {
+ ERR("Fail to set URI", ret);
+ return 0;
+ }
+ http_transaction_set_ready_to_write(transaction, TRUE);
+ http_transaction_request_write_body(transaction, post_msg);
+
+ sprintf(field_value, "%d", strlen(post_msg));
+ printf("[dbg] post size (%s)\n", field_value);
+ http_transaction_header_add_field(transaction, "Content-Length", field_value);
+
+ _register_callbacks(transaction);
+ http_transaction_submit(transaction);
+
+ return 1;
+}
+
gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
{
- int rv;
- char a[10];
-
- printf("Event received from stdin\n");
-
- rv = read(0, a, 10);
-
- if (rv <= 0 || a[0] == '0')
- exit(1);
-
- if (a[0] == '\n' || a[0] == '\r') {
- printf("\n\n Network Connection API Test App\n\n");
- printf("Options..\n");
- printf("1 - Initialize\n");
- printf("2 - Deinitialize\n");
- printf("3 - Simple GET\n");
- printf("4 - Multiple GET\n");
- printf("5 - \n");
- printf("6 - \n");
- printf("0 - Exit \n");
- printf("ENTER - Show options menu.......\n");
- }
-
- switch (a[0]) {
- case '1':
- rv = test_http_init();
- break;
- case '2':
- rv = test_http_deinit();
- break;
- case '3':
- rv = test_simple_get();
- break;
- case '4':
- rv = test_multiple_get();
- break;
- case '5':
- break;
- case '6':
- break;
- }
-
- if (rv == 1)
- printf("Operation succeeded!\n");
- else
- printf("Operation failed!\n");
-
- return true;
+ int rv;
+ char a[10];
+
+ printf("Event received from stdin\n");
+
+ rv = read(0, a, 10);
+
+ if (rv <= 0 || a[0] == '0')
+ exit(1);
+
+ if (a[0] == '\n' || a[0] == '\r') {
+ printf("\n\n Network Connection API Test App\n\n");
+ printf("Options..\n");
+ printf("1 - Initialize\n");
+ printf("2 - Deinitialize\n");
+ printf("3 - Create session\n");
+ printf("4 - Destroy session\n");
+ printf("5 - Simple GET\n");
+ printf("6 - Multiple GET\n");
+ printf("7 - Simple POST\n");
+ printf("8 - \n");
+ printf("0 - Exit \n");
+ printf("ENTER - Show options menu.......\n");
+ }
+
+ switch (a[0]) {
+ case '1':
+ rv = test_http_init();
+ break;
+ case '2':
+ rv = test_http_deinit();
+ break;
+ case '3':
+ rv = test_http_session_create();
+ break;
+ case '4':
+ rv = test_http_session_destroy();
+ break;
+ case '5':
+ rv = test_simple_get();
+ break;
+ case '6':
+ rv = test_multiple_get();
+ break;
+ case '7':
+ rv = test_simple_post();
+ break;
+ }
+
+ if (rv == 1)
+ printf("Operation succeeded!\n");
+ else
+ printf("Operation failed!\n");
+
+ return true;
}
int main(int argc, char **argv)
{
- GMainLoop *mainloop;
+ GMainLoop *mainloop;
#if !GLIB_CHECK_VERSION(2, 36, 0)
- g_type_init();
+ g_type_init();
#endif
- mainloop = g_main_loop_new(NULL, false);
+ mainloop = g_main_loop_new(NULL, false);
- GIOChannel *channel = g_io_channel_unix_new(0);
- g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
- printf("Test Thread created...\n");
- g_main_loop_run(mainloop);
+ GIOChannel *channel = g_io_channel_unix_new(0);
+ g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
+ printf("Test Thread created...\n");
+ g_main_loop_run(mainloop);
- return 0;
+ return 0;
}