5 #include <sys/socket.h>
12 #include <download_private.h>
13 #include <download-provider-interface.h>
15 /////////////////////// APIs /////////////////////////////////
17 int download_create(int *download_id)
20 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
21 if (download_id == NULL)
22 return DOWNLOAD_ERROR_INVALID_PARAMETER;
23 return dp_interface_create(download_id);
26 int download_destroy(int download_id)
29 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
30 return dp_interface_destroy(download_id);
33 int download_start(int download_id)
36 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
37 return dp_interface_start(download_id);
40 int download_pause(int download_id)
43 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
44 return dp_interface_pause(download_id);
47 int download_cancel(int download_id)
50 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
51 return dp_interface_cancel(download_id);
55 int download_set_url(int download_id, const char *url)
58 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
60 return DOWNLOAD_ERROR_INVALID_PARAMETER;
61 return dp_interface_set_url(download_id, url);
65 int download_get_url(int download_id, char **url)
68 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
70 return DOWNLOAD_ERROR_INVALID_PARAMETER;
71 return dp_interface_get_url(download_id, url);
74 int download_set_network_type(int download_id,
75 download_network_type_e net_type)
78 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
79 if (net_type == DOWNLOAD_NETWORK_DATA_NETWORK)
80 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
81 else if (net_type == DOWNLOAD_NETWORK_WIFI)
82 CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
83 else if (net_type == DOWNLOAD_NETWORK_WIFI_DIRECT)
84 CHECK_FEATURE_SUPPORTED(WIFI_DIRECT_FEATURE);
85 else if (net_type == DOWNLOAD_NETWORK_ALL)
86 CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, WIFI_DIRECT_FEATURE);
88 return dp_interface_set_network_type(download_id, (int)net_type);
91 int download_get_network_type(int download_id,
92 download_network_type_e *net_type)
95 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
97 if (net_type == NULL) {
98 TRACE_ERROR("Parameter NULL Check");
99 return DOWNLOAD_ERROR_INVALID_PARAMETER;
101 int network_type = DOWNLOAD_ADAPTOR_NETWORK_ALL;
102 int ret = dp_interface_get_network_type(download_id, &network_type);
103 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
104 *net_type = network_type;
108 int download_set_network_bonding(int download_id, bool enable)
111 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
112 return dp_interface_set_network_bonding(download_id, (int)enable);
115 int download_get_network_bonding(int download_id, bool *enable)
119 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
120 if (enable == NULL) {
121 TRACE_ERROR("Parameter NULL Check");
122 return DOWNLOAD_ERROR_INVALID_PARAMETER;
124 int ret = dp_interface_get_network_bonding(download_id, &is_set);
125 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
126 *enable = (bool)is_set;
130 int download_set_destination(int download_id, const char *path)
133 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
135 return DOWNLOAD_ERROR_INVALID_PARAMETER;
136 return dp_interface_set_destination(download_id, path);
140 int download_get_destination(int download_id, char **path)
143 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
145 return DOWNLOAD_ERROR_INVALID_PARAMETER;
146 return dp_interface_get_destination(download_id, path);
149 int download_set_file_name(int download_id, const char *file_name)
152 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
153 if (file_name == NULL)
154 return DOWNLOAD_ERROR_INVALID_PARAMETER;
155 return dp_interface_set_file_name(download_id, file_name);
158 int download_get_file_name(int download_id, char **file_name)
161 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
162 if (file_name == NULL)
163 return DOWNLOAD_ERROR_INVALID_PARAMETER;
164 return dp_interface_get_file_name(download_id, file_name);
167 int download_get_downloaded_file_path(int download_id, char **path)
170 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
172 return DOWNLOAD_ERROR_INVALID_PARAMETER;
173 return dp_interface_get_downloaded_file_path(download_id, path);
176 int download_add_http_header_field(int download_id, const char *field,
180 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
181 if (field == NULL || value == NULL)
182 return DOWNLOAD_ERROR_INVALID_PARAMETER;
184 dp_interface_add_http_header_field(download_id, field, value);
187 int download_get_http_header_field(int download_id,
188 const char *field, char **value)
191 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
192 if (field == NULL || value == NULL)
193 return DOWNLOAD_ERROR_INVALID_PARAMETER;
195 dp_interface_get_http_header_field(download_id, field, value);
198 int download_get_http_header_field_list(int download_id, char ***fields,
202 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
203 if (fields == NULL || length == NULL)
204 return DOWNLOAD_ERROR_INVALID_PARAMETER;
205 return dp_interface_get_http_header_field_list(download_id, fields,
209 int download_remove_http_header_field(int download_id,
213 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
215 return DOWNLOAD_ERROR_INVALID_PARAMETER;
216 return dp_interface_remove_http_header_field(download_id, field);
219 // download_state_changed_cb is different with dp_interface_state_changed_cb.
220 int download_set_state_changed_cb(int download_id,
221 download_state_changed_cb callback, void* user_data)
224 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
225 return dp_interface_set_state_changed_cb(download_id,
226 (dp_interface_state_changed_cb)callback, user_data);
229 int download_unset_state_changed_cb(int download_id)
232 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
233 return dp_interface_unset_state_changed_cb(download_id);
236 // download_progress_cb is same with dp_interface_progress_cb.
237 int download_set_progress_cb(int download_id,
238 download_progress_cb callback, void *user_data)
241 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
242 return dp_interface_set_progress_cb(download_id,
243 (dp_interface_progress_cb)callback, user_data);
246 int download_unset_progress_cb(int download_id)
249 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
250 return dp_interface_unset_progress_cb(download_id);
253 int download_get_state(int download_id, download_state_e *state)
257 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
259 TRACE_ERROR("Parameter NULL Check");
260 return DOWNLOAD_ERROR_INVALID_PARAMETER;
262 int ret = dp_interface_get_state(download_id, &statecode);
263 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
268 int download_get_temp_path(int download_id, char **temp_path)
271 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
272 if (temp_path == NULL)
273 return DOWNLOAD_ERROR_INVALID_PARAMETER;
274 return dp_interface_get_temp_path(download_id, temp_path);
277 int download_get_content_name(int download_id, char **content_name)
280 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
281 if (content_name == NULL)
282 return DOWNLOAD_ERROR_INVALID_PARAMETER;
283 return dp_interface_get_content_name(download_id, content_name);
286 int download_get_content_size(int download_id,
287 unsigned long long *content_size)
290 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
291 if (content_size == NULL)
292 return DOWNLOAD_ERROR_INVALID_PARAMETER;
293 return dp_interface_get_content_size(download_id, content_size);
296 int download_get_mime_type(int download_id, char **mime_type)
299 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
300 if (mime_type == NULL)
301 return DOWNLOAD_ERROR_INVALID_PARAMETER;
302 return dp_interface_get_mime_type(download_id, mime_type);
305 int download_set_auto_download(int download_id, bool enable)
308 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
309 return dp_interface_set_auto_download(download_id, (int)enable);
312 int download_get_auto_download(int download_id, bool *enable)
316 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
317 if (enable == NULL) {
318 TRACE_ERROR("Parameter NULL Check");
319 return DOWNLOAD_ERROR_INVALID_PARAMETER;
321 int ret = dp_interface_get_auto_download(download_id, &is_set);
322 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
323 *enable = (bool)is_set;
327 int download_get_error(int download_id, download_error_e *error)
331 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
333 TRACE_ERROR("Parameter NULL Check");
334 return DOWNLOAD_ERROR_INVALID_PARAMETER;
336 int ret = dp_interface_get_error(download_id, &errorcode);
337 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
342 int download_get_http_status(int download_id, int *http_status)
345 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
346 if (http_status == NULL)
347 return DOWNLOAD_ERROR_INVALID_PARAMETER;
348 return dp_interface_get_http_status(download_id, http_status);
351 int download_set_notification_app_control(int download_id, download_notification_app_control_type_e type, app_control_h handle)
354 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
356 return DOWNLOAD_ERROR_INVALID_PARAMETER;
357 return dp_interface_set_notification_service_handle(download_id, (int)type, handle);
360 int download_get_notification_app_control(int download_id, download_notification_app_control_type_e type, app_control_h *handle)
363 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
365 return DOWNLOAD_ERROR_INVALID_PARAMETER;
366 return dp_interface_get_notification_service_handle(download_id, (int)type, (void **)handle);
369 int download_set_notification_title(int download_id, const char *title)
372 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
374 return DOWNLOAD_ERROR_INVALID_PARAMETER;
375 return dp_interface_set_notification_title(download_id, title);
378 int download_get_notification_title(int download_id, char **title)
381 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
383 return DOWNLOAD_ERROR_INVALID_PARAMETER;
384 return dp_interface_get_notification_title(download_id, title);
387 int download_set_notification_description(int download_id, const char *description)
390 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
391 if (description == NULL)
392 return DOWNLOAD_ERROR_INVALID_PARAMETER;
393 return dp_interface_set_notification_description(download_id, description);
396 int download_get_notification_description(int download_id, char **description)
399 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
400 if (description == NULL)
401 return DOWNLOAD_ERROR_INVALID_PARAMETER;
402 return dp_interface_get_notification_description(download_id, description);
405 int download_set_notification_type(int download_id, download_notification_type_e type)
408 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
409 return dp_interface_set_notification_type(download_id, (int)type);
412 int download_get_notification_type(int download_id, download_notification_type_e *type)
416 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
418 TRACE_ERROR("Parameter NULL Check");
419 return DOWNLOAD_ERROR_INVALID_PARAMETER;
421 int ret = dp_interface_get_notification_type(download_id, ¬i_type);
422 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
423 *type = (download_notification_type_e)noti_type;
427 int download_get_etag(int download_id, char **etag)
430 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
432 return DOWNLOAD_ERROR_INVALID_PARAMETER;
433 return dp_interface_get_etag(download_id, etag);
436 int download_set_temp_file_path(int download_id, char *path)
439 CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
441 return DOWNLOAD_ERROR_INVALID_PARAMETER;
442 return dp_interface_set_temp_file_path(download_id, path);