#define LOG_TAG "CAPI_NETWORK_HTTP"
+#include <limits.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
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"
typedef struct {
CURL *easy_handle;
- int session_id;
- int transaction_id;
gchar *interface_name;
int timeout;
int write_event;
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
#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;
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);
}
}
}
-//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)
{
}
//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);
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;
}
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) {
}
//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");
_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;
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);
}
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) {
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) {
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;
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) {
*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