*/
#include "http.h"
-#include "http_private.h"
\ No newline at end of file
+#include "http_private.h"
+
+struct curl_slist* _get_header_list(http_transaction_h http_transaction)
+{
+ __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+ __http_header_h *header = transaction->header;
+
+ gchar* header_str = NULL;
+ GHashTableIter iter;
+ gpointer key = NULL;
+ gpointer value = NULL;
+ gint size = 0;
+
+ size = g_hash_table_size(header->hash_table);
+ DBG("Header table Size: %d\n", size);
+
+ g_hash_table_iter_init(&iter, header->hash_table);
+
+ while(g_hash_table_iter_next (&iter, &key, &value)) {
+ header_str = (gchar *)malloc(sizeof(gchar) * (strlen(key) + 1 + 1 + strlen(value) + 1) );
+ sprintf(header_str, "%s: %s", (gchar*)key, (gchar*)value);
+ DBG("Header Field: %s\n", header_str);
+ header->header_list = curl_slist_append(header->header_list, header_str);
+ free(header_str);
+ }
+
+ return header->header_list;
+}
+
+API int http_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");
+ _retvm_if(field_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(field_name) is NULL\n");
+ _retvm_if(field_value == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(field_value) is NULL\n");
+
+ __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+ __http_header_h *header = transaction->header;
+
+ 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);
+
+ return HTTP_ERROR_NONE;
+}
+
+API int http_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");
+ _retvm_if(field_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(field_name) is NULL\n");
+
+ __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;
+}
+
+API int http_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");
+ _retvm_if(field_name == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(field_name) is NULL\n");
+ _retvm_if(field_value == NULL, HTTP_ERROR_INVALID_PARAMETER,
+ "parameter(field_value) is NULL\n");
+
+ __http_transaction_h *transaction = (__http_transaction_h *)http_transaction;
+ __http_header_h *header = transaction->header;
+
+ *field_value = g_hash_table_lookup(header->hash_table, field_name);
+
+ return HTTP_ERROR_NONE;
+}
CURLMcode ret = CURLM_OK;
gchar *proxy_addr = NULL;
+ struct curl_slist* header_list = NULL;
transaction->easy_handle = curl_easy_init();
if (transaction->interface_name)
curl_easy_setopt(transaction->easy_handle, CURLOPT_INTERFACE, transaction->interface_name);
+ header_list = _get_header_list(transaction);
+ if (header_list)
+ curl_easy_setopt(transaction->easy_handle, CURLOPT_HTTPHEADER, header_list);
+
if (request->encoding)
curl_easy_setopt(transaction->easy_handle, CURLOPT_ENCODING, request->encoding);
transaction->request->body = NULL;
transaction->request->http_version = HTTP_VERSION_1_1;
+ transaction->header->header_list = NULL;
+ transaction->header->hash_table = NULL;
+
transaction->thread = NULL;
*http_transaction = (http_transaction_h)transaction;
free(request);
}
free(response);
- free(header);
+
+ if (header) {
+ if (header->header_list != NULL) {
+ curl_slist_free_all(header->header_list);
+ header->header_list = NULL;
+ }
+
+ if (header->hash_table != NULL) {
+ g_hash_table_destroy(header->hash_table);
+ header->hash_table = NULL;
+ }
+
+ free(header);
+ }
free(transaction);
transaction = NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+int add_http_header(http_transaction_h transaction_handle)
+{
+ 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;
+}
+
+int remove_http_header(http_transaction_h transaction_handle)
+{
+ 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;
+}
+
http_transaction_h create_http_request(http_session_h session_handle, gchar* host_url, http_transaction_header_cb header_cb, http_transaction_body_cb body_cb, http_transaction_write_cb write_cb,
http_transaction_completed_cb completed_cb, http_transaction_aborted_cb aborted_cb)
{
(http_transaction_aborted_cb)aborted_cb, &transaction_handle);
http_request_set_uri(transaction_handle, host_url);
+ add_http_header(transaction_handle);
return transaction_handle;
}
http_transaction_h transaction_handle1 = NULL;
http_transaction_h transaction_handle2 = NULL;
-
DBG("########################## main:Enter#########################################\n");
mainloop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(mainloop);
+ remove_http_header(transaction_handle1);
+ remove_http_header(transaction_handle2);
+
http_transaction_close(transaction_handle1);
transaction_handle1 = NULL;
http_transaction_close(transaction_handle2);