Initialize Tizen 3.0
[framework/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         if (net_type == NULL) {
97                 TRACE_ERROR("Parameter NULL Check");
98                 return DOWNLOAD_ERROR_INVALID_PARAMETER;
99         }
100         int network_type = DOWNLOAD_ADAPTOR_NETWORK_ALL;
101         int ret = dp_interface_get_network_type(download_id, &network_type);
102         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
103                 *net_type = network_type;
104         return ret;
105 }
106
107 int download_set_destination(int download_id, const char *path)
108 {
109         TRACE_INFO("");
110         return dp_interface_set_destination(download_id, path);
111 }
112
113
114 int download_get_destination(int download_id, char **path)
115 {
116         TRACE_INFO("");
117         return dp_interface_get_destination(download_id, path);
118 }
119
120 int download_set_file_name(int download_id, const char *file_name)
121 {
122         TRACE_INFO("");
123         return dp_interface_set_file_name(download_id, file_name);
124 }
125
126 int download_get_file_name(int download_id, char **file_name)
127 {
128         TRACE_INFO("");
129         return dp_interface_get_file_name(download_id, file_name);
130 }
131
132 int download_set_notification(int download_id, bool enable)
133 {
134         TRACE_INFO("");
135         return dp_interface_set_notification(download_id, (int)enable);
136 }
137
138 int download_get_notification(int download_id, bool *enable)
139 {
140         int is_set = 0;
141         TRACE_INFO("");
142         if (enable == NULL) {
143                 TRACE_ERROR("Parameter NULL Check");
144                 return DOWNLOAD_ERROR_INVALID_PARAMETER;
145         }
146         int ret = dp_interface_get_notification(download_id, &is_set);
147         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
148                 *enable = (bool)is_set;
149         return ret;
150 }
151
152 int download_get_downloaded_file_path(int download_id, char **path)
153 {
154         TRACE_INFO("");
155         return dp_interface_get_downloaded_file_path(download_id, path);
156 }
157
158 int download_add_notification_extra_param(
159                 int download_id, const char *key,
160                 const char **value, const unsigned int length)
161 {
162         TRACE_INFO("");
163         return dp_interface_add_noti_extra(download_id, key, value, length);
164 }
165
166 int download_remove_notification_extra_param(int download_id, const char *key)
167 {
168         TRACE_INFO("");
169         return dp_interface_remove_noti_extra_key(download_id, key);
170 }
171
172 int download_get_notification_extra_param(
173                 int download_id, const char *key,
174                 char ***values, unsigned int *length)
175 {
176         TRACE_INFO("");
177         return dp_interface_get_noti_extra_values(download_id, key, values, length);
178 }
179
180 int download_add_http_header_field(int download_id, const char *field,
181         const char *value)
182 {
183         TRACE_INFO("");
184         return
185                 dp_interface_add_http_header_field(download_id, field, value);
186 }
187
188 int download_get_http_header_field(int download_id,
189         const char *field, char **value)
190 {
191         TRACE_INFO("");
192         return
193                 dp_interface_get_http_header_field(download_id, field, value);
194 }
195
196 int download_get_http_header_field_list(int download_id, char ***fields,
197         int *length)
198 {
199         TRACE_INFO("");
200         return dp_interface_get_http_header_field_list(download_id, fields,
201                 length);
202 }
203
204 int download_remove_http_header_field(int download_id,
205         const char *field)
206 {
207         TRACE_INFO("");
208         return dp_interface_remove_http_header_field(download_id, field);
209 }
210
211 // download_state_changed_cb is different with dp_interface_state_changed_cb.
212 int download_set_state_changed_cb(int download_id,
213         download_state_changed_cb callback, void* user_data)
214 {
215         TRACE_INFO("");
216         return dp_interface_set_state_changed_cb(download_id,
217                 (dp_interface_state_changed_cb)callback, user_data);
218 }
219
220 int download_unset_state_changed_cb(int download_id)
221 {
222         TRACE_INFO("");
223         return dp_interface_unset_state_changed_cb(download_id);
224 }
225
226 // download_progress_cb is same with dp_interface_progress_cb.
227 int download_set_progress_cb(int download_id,
228         download_progress_cb callback, void *user_data)
229 {
230         TRACE_INFO("");
231         return dp_interface_set_progress_cb(download_id,
232                         (dp_interface_progress_cb)callback, user_data);
233 }
234
235 int download_unset_progress_cb(int download_id)
236 {
237         TRACE_INFO("");
238         return dp_interface_unset_progress_cb(download_id);
239 }
240
241 int download_get_state(int download_id, download_state_e *state)
242 {
243         int statecode = 0;
244         TRACE_INFO("");
245         if (state == NULL) {
246                 TRACE_ERROR("Parameter NULL Check");
247                 return DOWNLOAD_ERROR_INVALID_PARAMETER;
248         }
249         int ret = dp_interface_get_state(download_id, &statecode);
250         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
251                 *state = statecode;
252         return ret;
253 }
254
255 int download_get_temp_path(int download_id, char **temp_path)
256 {
257         TRACE_INFO("");
258         return dp_interface_get_temp_path(download_id, temp_path);
259 }
260
261 int download_get_content_name(int download_id, char **content_name)
262 {
263         TRACE_INFO("");
264         return dp_interface_get_content_name(download_id, content_name);
265 }
266
267 int download_get_content_size(int download_id,
268         unsigned long long *content_size)
269 {
270         TRACE_INFO("");
271         return dp_interface_get_content_size(download_id, content_size);
272 }
273
274 int download_get_mime_type(int download_id, char **mime_type)
275 {
276         TRACE_INFO("");
277         return dp_interface_get_mime_type(download_id, mime_type);
278 }
279
280 int download_set_auto_download(int download_id, bool enable)
281 {
282         TRACE_INFO("");
283         return dp_interface_set_auto_download(download_id, (int)enable);
284 }
285
286 int download_get_auto_download(int download_id, bool *enable)
287 {
288         int is_set = 0;
289         TRACE_INFO("");
290         if (enable == NULL) {
291                 TRACE_ERROR("Parameter NULL Check");
292                 return DOWNLOAD_ERROR_INVALID_PARAMETER;
293         }
294         int ret = dp_interface_get_auto_download(download_id, &is_set);
295         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
296                 *enable = (bool)is_set;
297         return ret;
298 }
299
300 int download_get_error(int download_id, download_error_e *error)
301 {
302         int errorcode = 0;
303         TRACE_INFO("");
304         if (error == NULL) {
305                 TRACE_ERROR("Parameter NULL Check");
306                 return DOWNLOAD_ERROR_INVALID_PARAMETER;
307         }
308         int ret = dp_interface_get_error(download_id, &errorcode);
309         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
310                 *error = errorcode;
311         return ret;
312 }
313
314 int download_get_http_status(int download_id, int *http_status)
315 {
316         TRACE_INFO("");
317         return dp_interface_get_http_status(download_id, http_status);
318 }
319
320 int download_set_notification_bundle(int download_id, download_notification_bundle_type_e type, bundle *b)
321 {
322         TRACE_INFO("");
323         return dp_interface_set_notification_bundle(download_id, (int)type, b);
324 }
325
326 int download_get_notification_bundle(int download_id, download_notification_bundle_type_e type, bundle **b)
327 {
328         TRACE_INFO("");
329         return dp_interface_get_notification_bundle(download_id, (int)type, b);
330 }
331
332 int download_set_notification_title(int download_id, const char *title)
333 {
334         TRACE_INFO("");
335         return dp_interface_set_notification_title(download_id, title);
336 }
337
338 int download_get_notification_title(int download_id, char **title)
339 {
340         TRACE_INFO("");
341         return dp_interface_get_notification_title(download_id, title);
342 }
343
344 int download_set_notification_description(int download_id, const char *description)
345 {
346         TRACE_INFO("");
347         return dp_interface_set_notification_description(download_id, description);
348 }
349
350 int download_get_notification_description(int download_id, char **description)
351 {
352         TRACE_INFO("");
353         return dp_interface_get_notification_description(download_id, description);
354 }
355
356 int download_set_notification_type(int download_id, download_notification_type_e type)
357 {
358         TRACE_INFO("");
359         return dp_interface_set_notification_type(download_id, (int)type);
360 }
361
362 int download_get_notification_type(int download_id, download_notification_type_e *type)
363 {
364         int noti_type = 0;
365         TRACE_INFO("");
366         if (type == NULL) {
367                 TRACE_ERROR("Parameter NULL Check");
368                 return DOWNLOAD_ERROR_INVALID_PARAMETER;
369         }
370         int ret = dp_interface_get_notification_type(download_id, &noti_type);
371         if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
372                 *type = (download_notification_type_e)noti_type;
373         return ret;
374 }
375