2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _DOWNLOAD_AGENT_INFO_H
18 #define _DOWNLOAD_AGENT_INFO_H
20 #include "download-agent-type.h"
21 #include "download-agent-interface.h"
22 #include "download-agent-pthread.h"
24 #include "curl/curl.h"
28 pthread_mutex_t mutex;
30 da_bool_t is_cancel_reqeusted;
34 HTTP_STATE_READY_TO_DOWNLOAD = 0,
35 HTTP_STATE_REDIRECTED = 1,
36 HTTP_STATE_DOWNLOAD_REQUESTED = 2,
37 HTTP_STATE_DOWNLOAD_STARTED = 3,
38 HTTP_STATE_DOWNLOADING = 4,
39 HTTP_STATE_DOWNLOAD_FINISH = 5,
40 HTTP_STATE_REQUEST_CANCEL = 6,
41 HTTP_STATE_REQUEST_PAUSE = 7,
42 HTTP_STATE_REQUEST_RESUME = 8,
43 HTTP_STATE_CANCELED = 9,
44 HTTP_STATE_FAILED = 10,
45 HTTP_STATE_PAUSED = 11,
46 HTTP_STATE_RESUMED = 12,
47 HTTP_STATE_ABORTED = 13,
48 HTTP_STATE_WAIT_FOR_NET_ERR = 14,
68 void *user_client_data;
72 HTTP_EVENT_GOT_HEADER = 0,
73 HTTP_EVENT_GOT_PACKET,
78 typedef struct _http_header_options_t http_header_options_t;
79 struct _http_header_options_t {
82 http_header_options_t *next;
85 typedef struct _http_header_t http_header_t;
86 typedef http_header_t *http_msg_iter_t;
87 struct _http_header_t {
90 http_header_options_t *options;
91 char *raw_value; // raw string including options
100 } http_msg_request_t;
106 } http_msg_response_t;
109 http_event_type_t type;
113 da_size_t received_len;
119 typedef void (*http_update_cb) (http_raw_data_t *data, void *user_param);
124 pthread_mutex_t mutex_state;
125 pthread_mutex_t mutex_http;
126 pthread_cond_t cond_http;
127 http_msg_request_t *http_msg_request;
128 http_msg_response_t *http_msg_response;
129 http_method_t http_method;
130 http_msg_t *http_msg;
132 char *content_type_from_header;
133 char *file_name_from_header;
134 da_size_t content_len_from_header;
135 char *etag_from_header;
136 int error_code; // for error value for http abort.
137 da_size_t total_size;
139 da_bool_t is_raf_mode_confirmed;
141 http_update_cb update_cb;
146 char *pure_file_name;
148 char *file_path; /* malloced in set_file_path_for_final_saving */
149 char *mime_type;// For drm converting
151 da_size_t buffer_len;
152 da_size_t file_size; /* http header's Content-Length has higher priority than DD's <size> */
153 da_size_t bytes_written_to_file; /* The file size to be written at actual file */
155 da_size_t file_size_of_temp_file; /* If the temporary file is existed, the file size of it */
157 da_bool_t is_updated; /* The flag for updating progress event only if the data is wrriten to file not buffer */
164 http_info_t *http_info;
165 file_info_t *file_info;
166 req_info_t *req_info;
168 da_bool_t is_cb_update;
172 extern da_info_t *da_info_list[DA_MAX_ID];
174 #define GET_STATE_MUTEX(INFO) (INFO->mutex_state)
175 #define GET_STATE(INFO) (INFO->state)
176 #define CHANGE_STATE(STATE, INFO) {\
177 DA_MUTEX_LOCK(&GET_STATE_MUTEX(INFO));\
178 GET_STATE(INFO) = STATE;\
179 DA_LOGV("Changed state[%d]", GET_STATE(INFO));\
180 DA_MUTEX_UNLOCK(&GET_STATE_MUTEX(INFO));\
183 da_ret_t init_openssl_locks(void);
184 da_ret_t deinit_openssl_locks(void);
185 da_ret_t get_available_da_id(int *available_id);
186 da_ret_t copy_user_input_data(da_info_t *da_info, const char *url,
187 req_data_t *ext_data, da_cb_t *da_cb_data);
188 da_bool_t is_valid_download_id(int id);
189 void destroy_da_info(int id);
190 void destroy_da_info_list(void);
191 da_ret_t get_da_info_with_da_id(int id, da_info_t **out_info);
192 da_ret_t init_http_msg_t(http_msg_t **http_msg);
193 void destroy_http_msg_t(http_msg_t *http_msg);
194 void reset_http_info(http_info_t *http_info);
195 void reset_http_info_for_resume(http_info_t *http_info);
196 void destroy_http_info(http_info_t *http_info);
197 void destroy_file_info(file_info_t *file_info);
199 #endif /* _DOWNLOAD_AGENT_INFO_H */