From: Seonah Moon Date: Mon, 1 Aug 2016 07:19:40 +0000 (+0900) Subject: Fix some bugs X-Git-Tag: submit/tizen/20160805.043859^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe6f94c1b90dd97591ccdfc5cbda2b9ec3ad82e2;p=platform%2Fcore%2Fapi%2Fhttp.git Fix some bugs Change-Id: I94e90a7dbd42fdb0ac7db4060a84621d74f3d7f6 Signed-off-by: Seonah Moon --- diff --git a/include/http_private.h b/include/http_private.h index 4583da0..7bd4b94 100644 --- a/include/http_private.h +++ b/include/http_private.h @@ -19,6 +19,7 @@ #define LOG_TAG "CAPI_NETWORK_HTTP" +#include #include #include #include @@ -89,7 +90,6 @@ static const int _HTTP_DEFAULT_HEADER_SIZE = 1024; static const int _MAX_HTTP_TRANSACTIONS_PER_SESSION_NORMAL = 1; static const int _MAX_HTTP_TRANSACTIONS_PER_SESSION_PIPE = 5; - #define _HTTP_PROXY_AUTHENTICATE_HEADER_NAME "Proxy-Authenticate" #define _HTTP_WWW_AUTHENTICATE_HEADER_NAME "WWW-Authenticate" #define _HTTP_CONTENT_LENGTH_HEADER_NAME "Content-Length" @@ -142,8 +142,6 @@ typedef struct { typedef struct { CURL *easy_handle; - int session_id; - int transaction_id; gchar *interface_name; int timeout; int write_event; @@ -208,12 +206,12 @@ int _get_request_body_size(http_transaction_h http_transaction, int *body_size); int _read_request_body(http_transaction_h http_transaction, gchar **body); void __parse_response_header(gchar *buffer, size_t written, gpointer user_data); int _generate_session_id(void); -int _generate_transaction_id(void); void _add_transaction_to_list(http_transaction_h http_transaction); void _remove_transaction_from_list(http_transaction_h http_transaction); void _remove_transaction_list(void); curl_http_auth_scheme_e _get_http_curl_auth_scheme(http_auth_scheme_e auth_scheme); http_auth_scheme_e _get_http_auth_scheme(bool proxy_auth, curl_http_auth_scheme_e curl_auth_scheme); +int _set_authentication_info(http_transaction_h http_transaction); gchar* parse_values(const gchar* string, int from_index, int to_index); #ifdef __cplusplus diff --git a/packaging/capi-network-http.spec b/packaging/capi-network-http.spec index b288539..0cb39d2 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.11 +Version: 0.0.12 Release: 0 Group: System/Network License: Apache-2.0 diff --git a/src/http_session.c b/src/http_session.c index e4c95a3..0b37433 100644 --- a/src/http_session.c +++ b/src/http_session.c @@ -17,6 +17,8 @@ #include "http.h" #include "http_private.h" +static int generated_session_id = -1; + void _check_curl_multi_status(gpointer user_data) { __http_transaction_h *transaction = NULL; @@ -64,6 +66,7 @@ void _check_curl_multi_status(gpointer user_data) http_auth_scheme_e auth_scheme = _get_http_auth_scheme(proxy, http_auth); http_transaction_set_http_auth_scheme(transaction, auth_scheme); + _set_authentication_info(transaction); } transaction->completed_cb(transaction, transaction->completed_user_data); } @@ -96,14 +99,15 @@ void _check_curl_multi_status(gpointer user_data) } } -//LCOV_EXCL_START int _generate_session_id(void) { - int session_id = 0; + if (generated_session_id >= INT_MAX) + generated_session_id = 0; + else + generated_session_id++; - return session_id; + return generated_session_id; } -//LCOV_EXCL_STOP gboolean timer_expired_callback(gpointer user_data) { diff --git a/src/http_transaction.c b/src/http_transaction.c index 44e5b6b..6c462d3 100644 --- a/src/http_transaction.c +++ b/src/http_transaction.c @@ -37,13 +37,6 @@ void _remove_transaction_list(void) } //LCOV_EXCL_STOP -int _generate_transaction_id(void) -{ - int transaction_id = 0; - - return transaction_id; -} - curl_socket_t __handle_opensocket_cb(void *client_fd, curlsocktype purpose, struct curl_sockaddr *address) { int fd = socket(address->family, address->socktype, address->protocol); @@ -86,10 +79,12 @@ size_t __handle_body_cb(gchar *ptr, size_t size, size_t nmemb, gpointer user_dat if (!transaction->header_event) { transaction->header_event = TRUE; - transaction->header_cb(transaction, header->rsp_header, header->rsp_header_len, transaction->header_user_data); + if (transaction->header_cb) + transaction->header_cb(transaction, header->rsp_header, header->rsp_header_len, transaction->header_user_data); } - transaction->body_cb(transaction, ptr, size, nmemb, transaction->body_user_data); + if (transaction->body_cb) + transaction->body_cb(transaction, ptr, size, nmemb, transaction->body_user_data); return written; } @@ -102,7 +97,8 @@ size_t __handle_write_cb(gchar *ptr, size_t size, size_t nmemb, gpointer user_da size_t recommended_size = size * nmemb; size_t body_size = 0; - transaction->write_cb(transaction, recommended_size, transaction->write_user_data); + if (transaction->write_cb) + transaction->write_cb(transaction, recommended_size, transaction->write_user_data); ptr = (gchar*)g_queue_pop_head(request->body_queue); if (ptr == NULL) { @@ -160,7 +156,7 @@ int __progress_cb(void *user_data, double dltotal, double dlnow, double ultotal, } //LCOV_EXCL_START -int http_transaction_set_authentication_info(http_transaction_h http_transaction) +int _set_authentication_info(http_transaction_h http_transaction) { _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, "parameter(http_transaction) is NULL\n"); @@ -338,7 +334,7 @@ int _transaction_submit(gpointer user_data) _get_request_body_size(transaction, &body_size); if (transaction->write_event) { - if (content_len >= 0 && content_len <= body_size) + if (content_len > 0 && content_len <= body_size) write_event = FALSE; else write_event = TRUE; @@ -358,6 +354,7 @@ int _transaction_submit(gpointer user_data) if (write_event) { curl_easy_setopt(transaction->easy_handle, CURLOPT_POST, 1); + curl_easy_setopt(transaction->easy_handle, CURLOPT_POSTFIELDSIZE, body_size); curl_easy_setopt(transaction->easy_handle, CURLOPT_READFUNCTION, __handle_write_cb); curl_easy_setopt(transaction->easy_handle, CURLOPT_READDATA, transaction); } @@ -437,7 +434,6 @@ API int http_session_open_transaction(http_session_h http_session, http_method_e 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) { @@ -917,7 +913,7 @@ API int http_session_destroy_all_transactions(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) { + if (session->session_id == transaction->session->session_id) { _remove_transaction_from_list(list->data); ret = http_transaction_destroy((http_transaction_h) transaction); if (ret != HTTP_ERROR_NONE) { @@ -1046,11 +1042,13 @@ API int http_transaction_open_authentication(http_transaction_h http_transaction auth_transaction->ca_path = g_strdup(transaction->ca_path); auth_transaction->auth_required = transaction->auth_required; - auth_transaction->realm = NULL; auth_transaction->user_name = NULL; auth_transaction->password = NULL; auth_transaction->proxy_auth_type = FALSE; auth_transaction->auth_scheme = transaction->auth_scheme; + if (transaction->realm) + auth_transaction->realm = g_strdup(transaction->realm); + auth_transaction->write_event = FALSE; auth_transaction->header_cb = NULL; @@ -1067,7 +1065,6 @@ API int http_transaction_open_authentication(http_transaction_h http_transaction auth_transaction->session = transaction->session; auth_transaction->session->active_transaction_count = transaction->session->active_transaction_count; - auth_transaction->session_id = transaction->session_id; auth_transaction->request = (__http_request_h *)malloc(sizeof(__http_request_h)); if (auth_transaction->request == NULL) { @@ -1125,8 +1122,6 @@ API int http_transaction_open_authentication(http_transaction_h http_transaction *http_auth_transaction = (http_transaction_h)auth_transaction; _add_transaction_to_list(auth_transaction); - http_transaction_set_authentication_info((http_transaction_h)auth_transaction); - return HTTP_ERROR_NONE; } //LCOV_EXCL_STOP diff --git a/test/http_test.c b/test/http_test.c index ebf32d3..1f71de7 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -58,6 +58,7 @@ void __transaction_completed_cb(http_transaction_h transaction, void *user_data) http_status_code_e status = 0; int ret; char *uri = NULL; + char *realm = NULL; char id[16] = {0, }; char pw[16] = {0, }; @@ -72,6 +73,12 @@ void __transaction_completed_cb(http_transaction_h transaction, void *user_data) http_transaction_open_authentication(transaction, &http_auth_transaction); http_transaction_get_http_auth_scheme(http_auth_transaction, &auth_scheme); + ret = http_transaction_get_realm(http_auth_transaction, &realm); + if (ret != HTTP_ERROR_NONE) + DBG("Fail to get realm\n"); + else + DBG("realm (%s)", realm); + printf("User ID: "); ret = scanf("%15s", id); printf("Password: "); @@ -227,7 +234,7 @@ int test_simple_post(void) { int ret; http_transaction_h transaction; - const char* post_msg = "name=tizen&project=capi-network-curl"; + const char* post_msg = "name=tizen&project=capi-network-http"; char field_value[15]; ret = http_session_open_transaction(session, HTTP_METHOD_POST, &transaction);