merge with master
[platform/framework/web/download-provider.git] / agent / include / download-agent-plugin-libsoup.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _Download_Agent_Plugin_Libsoup_H
18 #define _Download_Agent_Plugin_Libsoup_H
19
20 #include <string.h>
21 #include <libsoup/soup.h>
22
23 #include "download-agent-http-queue.h"
24 #include "download-agent-pthread.h"
25 #include "download-agent-plugin-http-interface.h"
26
27 typedef struct  _pi_session_table_t {
28         da_bool_t is_using;
29         SoupSession *session;
30         SoupMessage *msg;
31         queue_t *queue;
32         pthread_mutex_t mutex;
33         pthread_cond_t cond;
34         da_bool_t is_paused;
35 } pi_session_table_t;
36
37 extern pi_session_table_t pi_session_table[];
38
39 #define MAX_SESSION_COUNT       DA_MAX_DOWNLOAD_REQ_AT_ONCE
40 #define MAX_TIMEOUT             60      // second
41
42 #define IS_VALID_SESSION_TABLE_ENTRY(ENTRY)             ((((ENTRY) < 0) || ((ENTRY) > MAX_SESSION_COUNT-1)) ? 0 : 1)
43
44
45 #define GET_SESSION_FROM_TABLE_ENTRY(ENTRY)     (pi_session_table[ENTRY].session)
46 #define GET_MSG_FROM_TABLE_ENTRY(ENTRY) (pi_session_table[ENTRY].msg)
47 #define GET_QUEUE_FROM_TABLE_ENTRY(ENTRY)               (pi_session_table[ENTRY].queue)
48
49
50 da_bool_t _pi_http_is_valid_input_for_tranx(const input_for_tranx_t *input_for_tranx);
51
52 void _pi_http_init_session_table_entry(const int in_session_table_entry);
53 void _pi_http_destroy_session_table_entry(const int in_session_table_entry);
54 int _pi_http_get_avaiable_session_table_entry(void);
55
56 da_bool_t _pi_http_register_queue_to_session_table(const int session_table_entry, const queue_t *in_queue);
57 da_bool_t _pi_http_register_session_to_session_table(const int in_session_table_entry, SoupSession *session);
58 da_bool_t _pi_http_register_msg_to_session_table(const int in_session_table_entry, SoupMessage *msg);
59
60 queue_t *_pi_http_get_queue_from_session_table_entry(const int in_session_table_entry);
61 int _pi_http_get_session_table_entry_from_message(SoupMessage *msg);
62
63 void _pi_http_store_read_data_to_queue(SoupMessage *msg, const char *body_data, int received_body_len);
64 void _pi_http_store_read_header_to_queue(SoupMessage *msg, const char *sniffedType);
65 void _pi_http_store_neterr_to_queue(SoupMessage *msg);
66
67
68 void _pi_http_finished_cb(SoupSession *session, SoupMessage *msg, gpointer data);
69 void _pi_http_restarted_cb(SoupMessage *msg, gpointer data);
70 void _pi_http_gotheaders_cb(SoupMessage *msg, gpointer data);
71 void _pi_http_contentsniffed_cb(SoupMessage *msg, const char *sniffedType, GHashTable *params, gpointer data);
72 void _pi_http_gotchunk_cb(SoupMessage *msg, SoupBuffer *chunk, gpointer data);
73
74
75 #endif