merge with master
[platform/core/api/url-download.git] / src / download-wrapping.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <sys/socket.h>
6 #include <sys/un.h>
7 #include <fcntl.h>
8 #include <errno.h>
9 #include <unistd.h>
10
11 #include <dlog.h>
12 #include <download.h>
13 #include <download-provider-interface.h>
14
15 #define DEBUG_MSG
16 #ifdef DEBUG_MSG
17 #include <dlog.h>
18 #ifdef LOG_TAG
19 #undef LOG_TAG
20 #endif
21 #define LOG_TAG "TIZEN_N_URL_DOWNLOAD"
22 #define TRACE_ERROR(format, ARG...)  \
23 { \
24 LOGE(format, ##ARG); \
25 }
26 #define TRACE_STRERROR(format, ARG...)  \
27 { \
28 LOGE(format" [%s]", ##ARG, strerror(errno)); \
29 }
30 #define TRACE_INFO(format, ARG...)  \
31 { \
32 LOGI(format, ##ARG); \
33 }
34 #else
35 #define TRACE_DEBUG_MSG(format, ARG...) ;
36 #endif
37
38 /////////////////////// APIs /////////////////////////////////
39
40 int download_create(int *download_id)
41 {
42         TRACE_INFO("");
43         return dp_interface_create(download_id);
44 }
45
46 int download_destroy(int download_id)
47 {
48         TRACE_INFO("");
49         return dp_interface_destroy(download_id);
50 }
51
52 int download_start(int download_id)
53 {
54         TRACE_INFO("");
55         return dp_interface_start(download_id);
56 }
57
58 int download_pause(int download_id)
59 {
60         TRACE_INFO("");
61         return dp_interface_pause(download_id);
62 }
63
64 int download_cancel(int download_id)
65 {
66         TRACE_INFO("");
67         return dp_interface_cancel(download_id);
68 }
69
70
71 int download_set_url(int download_id, const char *url)
72 {
73         TRACE_INFO("");
74         return dp_interface_set_url(download_id, url);
75 }
76
77
78 int download_get_url(int download_id, char **url)
79 {
80         TRACE_INFO("");
81         return dp_interface_get_url(download_id, url);
82 }
83
84 int download_set_network_type(int download_id,
85                                                 download_network_type_e net_type)
86 {
87         TRACE_INFO("");
88         return dp_interface_set_network_type(download_id, (int)net_type);
89 }
90
91 int download_get_network_type(int download_id,
92                                                         download_network_type_e *net_type)
93 {
94         TRACE_INFO("");
95
96         int network_type = DOWNLOAD_ADAPTOR_NETWORK_ALL;
97         int ret = dp_interface_get_network_type(download_id, &network_type);
98         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
99                 *net_type = network_type;
100         return ret;
101 }
102
103 int download_set_destination(int download_id, const char *path)
104 {
105         TRACE_INFO("");
106         return dp_interface_set_destination(download_id, path);
107 }
108
109
110 int download_get_destination(int download_id, char **path)
111 {
112         TRACE_INFO("");
113         return dp_interface_get_destination(download_id, path);
114 }
115
116 int download_set_file_name(int download_id, const char *file_name)
117 {
118         TRACE_INFO("");
119         return dp_interface_set_file_name(download_id, file_name);
120 }
121
122 int download_get_file_name(int download_id, char **file_name)
123 {
124         TRACE_INFO("");
125         return dp_interface_get_file_name(download_id, file_name);
126 }
127
128 int download_set_ongoing_notification(int download_id, bool enable)
129 {
130         return download_set_notification(download_id, enable);
131 }
132
133 int download_set_notification(int download_id, bool enable)
134 {
135         TRACE_INFO("");
136         return dp_interface_set_notification(download_id, (int)enable);
137 }
138
139 int download_get_ongoing_notification(int download_id, bool *enable)
140 {
141         return download_get_notification(download_id, enable);
142 }
143
144 int download_get_notification(int download_id, bool *enable)
145 {
146         int is_set = 0;
147
148         TRACE_INFO("");
149         int ret = dp_interface_get_notification(download_id, &is_set);
150         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
151                 *enable = (bool)is_set;
152         return ret;
153 }
154
155 int download_get_downloaded_file_path(int download_id, char **path)
156 {
157         TRACE_INFO("");
158         return dp_interface_get_downloaded_file_path(download_id, path);
159 }
160
161 int download_add_notification_extra_param(
162                 int download_id, const char *key,
163                 const char **value, const unsigned int length)
164 {
165         TRACE_INFO("");
166         return dp_interface_add_noti_extra(download_id, key, value, length);
167 }
168
169 int download_remove_notification_extra_param(int download_id, const char *key)
170 {
171         TRACE_INFO("");
172         return dp_interface_remove_noti_extra_key(download_id, key);
173 }
174
175 int download_get_notification_extra_param(
176                 int download_id, const char *key,
177                 char ***values, unsigned int *length)
178 {
179         TRACE_INFO("");
180         return dp_interface_get_noti_extra_values(download_id, key, values, length);
181 }
182
183 int download_add_http_header_field(int download_id, const char *field,
184         const char *value)
185 {
186         TRACE_INFO("");
187         return
188                 dp_interface_add_http_header_field(download_id, field, value);
189 }
190
191 int download_get_http_header_field(int download_id,
192         const char *field, char **value)
193 {
194         TRACE_INFO("");
195         return
196                 dp_interface_get_http_header_field(download_id, field, value);
197 }
198
199 int download_remove_http_header_field(int download_id,
200         const char *field)
201 {
202         TRACE_INFO("");
203         return dp_interface_remove_http_header_field(download_id, field);
204 }
205
206 // download_state_changed_cb is different with dp_interface_state_changed_cb.
207 int download_set_state_changed_cb(int download_id,
208         download_state_changed_cb callback, void* user_data)
209 {
210         TRACE_INFO("");
211         return dp_interface_set_state_changed_cb(download_id,
212                 (dp_interface_state_changed_cb)callback, user_data);
213 }
214
215 int download_unset_state_changed_cb(int download_id)
216 {
217         TRACE_INFO("");
218         return dp_interface_unset_state_changed_cb(download_id);
219 }
220
221 // download_progress_cb is same with dp_interface_progress_cb.
222 int download_set_progress_cb(int download_id,
223         download_progress_cb callback, void *user_data)
224 {
225         TRACE_INFO("");
226         return dp_interface_set_progress_cb(download_id,
227                         (dp_interface_progress_cb)callback, user_data);
228 }
229
230 int download_unset_progress_cb(int download_id)
231 {
232         TRACE_INFO("");
233         return dp_interface_unset_progress_cb(download_id);
234 }
235
236 int download_get_state(int download_id, download_state_e *state)
237 {
238         int statecode = 0;
239
240         TRACE_INFO("");
241         int ret = dp_interface_get_state(download_id, &statecode);
242         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
243                 *state = statecode;
244         return ret;
245 }
246
247 int download_get_temp_path(int download_id, char **temp_path)
248 {
249         TRACE_INFO("");
250         return dp_interface_get_temp_path(download_id, temp_path);
251 }
252
253 int download_get_content_name(int download_id, char **content_name)
254 {
255         TRACE_INFO("");
256         return dp_interface_get_content_name(download_id, content_name);
257 }
258
259 int download_get_content_size(int download_id,
260         unsigned long long *content_size)
261 {
262         TRACE_INFO("");
263         return dp_interface_get_content_size(download_id, content_size);
264 }
265
266 int download_get_mime_type(int download_id, char **mime_type)
267 {
268         TRACE_INFO("");
269         return dp_interface_get_mime_type(download_id, mime_type);
270 }
271
272 int download_set_auto_download(int download_id, bool enable)
273 {
274         TRACE_INFO("");
275         return dp_interface_set_auto_download(download_id, (int)enable);
276 }
277
278 int download_get_auto_download(int download_id, bool *enable)
279 {
280         int is_set = 0;
281
282         TRACE_INFO("");
283         int ret = dp_interface_get_auto_download(download_id, &is_set);
284         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
285                 *enable = (bool)is_set;
286         return ret;
287 }
288
289 int download_get_error(int download_id, download_error_e *error)
290 {
291         int errorcode = 0;
292
293         TRACE_INFO("");
294         int ret = dp_interface_get_error(download_id, &errorcode);
295         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
296                 *error = errorcode;
297         return ret;
298 }
299
300 int download_get_http_status(int download_id, int *http_status)
301 {
302         TRACE_INFO("");
303         return dp_interface_get_http_status(download_id, http_status);
304 }
305