5 #include <sys/socket.h>
10 #include <system_info.h>
14 #include <download-provider-interface.h>
22 #define LOG_TAG "TIZEN_N_URL_DOWNLOAD"
23 #define TRACE_ERROR(format, ARG...) \
25 LOGE(format, ##ARG); \
27 #define TRACE_STRERROR(format, ARG...) \
29 LOGE(format" [%s]", ##ARG, strerror(errno)); \
31 #define TRACE_INFO(format, ARG...) \
33 LOGI(format, ##ARG); \
36 #define TRACE_DEBUG_MSG(format, ARG...) ;
39 #define TELEPHONY_FEATURE "tizen.org/feature/network.telephony"
40 #define WIFI_FEATURE "tizen.org/feature/network.wifi"
41 #define WIFI_DIRECT_FEATURE "tizen.org/feature/network.wifi.direct"
43 /////////////////////// APIs /////////////////////////////////
45 int download_create(int *download_id)
48 if (download_id == NULL)
49 return DOWNLOAD_ERROR_INVALID_PARAMETER;
50 return dp_interface_create(download_id);
53 int download_destroy(int download_id)
56 return dp_interface_destroy(download_id);
59 int download_start(int download_id)
62 return dp_interface_start(download_id);
65 int download_pause(int download_id)
68 return dp_interface_pause(download_id);
71 int download_cancel(int download_id)
74 return dp_interface_cancel(download_id);
78 int download_set_url(int download_id, const char *url)
82 return DOWNLOAD_ERROR_INVALID_PARAMETER;
83 return dp_interface_set_url(download_id, url);
87 int download_get_url(int download_id, char **url)
91 return DOWNLOAD_ERROR_INVALID_PARAMETER;
92 return dp_interface_get_url(download_id, url);
95 int download_set_network_type(int download_id,
96 download_network_type_e net_type)
100 bool bIsTelephonyFeatureSupported = 0;
101 bool bIsWifiFeatureSupported = 0;
102 bool bIsWifiDirectFeatureSupported = 0;
104 system_info_get_platform_bool (TELEPHONY_FEATURE, &bIsTelephonyFeatureSupported);
105 system_info_get_platform_bool (WIFI_FEATURE, &bIsWifiFeatureSupported);
106 system_info_get_platform_bool (WIFI_DIRECT_FEATURE, &bIsWifiDirectFeatureSupported);
109 case DOWNLOAD_NETWORK_DATA_NETWORK:
110 if (!bIsTelephonyFeatureSupported) {
111 return DOWNLOAD_ERROR_NOT_SUPPORTED;
114 case DOWNLOAD_NETWORK_WIFI:
115 if (!bIsWifiFeatureSupported) {
116 return DOWNLOAD_ERROR_NOT_SUPPORTED;
119 case DOWNLOAD_NETWORK_WIFI_DIRECT:
120 if (!bIsWifiDirectFeatureSupported) {
121 return DOWNLOAD_ERROR_NOT_SUPPORTED;
124 case DOWNLOAD_NETWORK_ALL:
125 if (!bIsTelephonyFeatureSupported && !bIsWifiFeatureSupported && !bIsWifiDirectFeatureSupported) {
126 return DOWNLOAD_ERROR_NOT_SUPPORTED;
131 return dp_interface_set_network_type(download_id, (int)net_type);
134 int download_get_network_type(int download_id,
135 download_network_type_e *net_type)
139 if (net_type == NULL) {
140 TRACE_ERROR("Parameter NULL Check");
141 return DOWNLOAD_ERROR_INVALID_PARAMETER;
143 int network_type = DOWNLOAD_ADAPTOR_NETWORK_ALL;
144 int ret = dp_interface_get_network_type(download_id, &network_type);
145 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
146 *net_type = network_type;
150 int download_set_network_bonding(int download_id, bool enable)
153 return dp_interface_set_network_bonding(download_id, (int)enable);
156 int download_get_network_bonding(int download_id, bool *enable)
160 if (enable == NULL) {
161 TRACE_ERROR("Parameter NULL Check");
162 return DOWNLOAD_ERROR_INVALID_PARAMETER;
164 int ret = dp_interface_get_network_bonding(download_id, &is_set);
165 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
166 *enable = (bool)is_set;
170 int download_set_destination(int download_id, const char *path)
174 return DOWNLOAD_ERROR_INVALID_PARAMETER;
175 return dp_interface_set_destination(download_id, path);
179 int download_get_destination(int download_id, char **path)
183 return DOWNLOAD_ERROR_INVALID_PARAMETER;
184 return dp_interface_get_destination(download_id, path);
187 int download_set_file_name(int download_id, const char *file_name)
190 if (file_name == NULL)
191 return DOWNLOAD_ERROR_INVALID_PARAMETER;
192 return dp_interface_set_file_name(download_id, file_name);
195 int download_get_file_name(int download_id, char **file_name)
198 if (file_name == NULL)
199 return DOWNLOAD_ERROR_INVALID_PARAMETER;
200 return dp_interface_get_file_name(download_id, file_name);
203 int download_get_downloaded_file_path(int download_id, char **path)
207 return DOWNLOAD_ERROR_INVALID_PARAMETER;
208 return dp_interface_get_downloaded_file_path(download_id, path);
211 int download_add_http_header_field(int download_id, const char *field,
215 if (field == NULL || value == NULL)
216 return DOWNLOAD_ERROR_INVALID_PARAMETER;
218 dp_interface_add_http_header_field(download_id, field, value);
221 int download_get_http_header_field(int download_id,
222 const char *field, char **value)
225 if (field == NULL || value == NULL)
226 return DOWNLOAD_ERROR_INVALID_PARAMETER;
228 dp_interface_get_http_header_field(download_id, field, value);
231 int download_get_http_header_field_list(int download_id, char ***fields,
235 if (fields == NULL || length == NULL)
236 return DOWNLOAD_ERROR_INVALID_PARAMETER;
237 return dp_interface_get_http_header_field_list(download_id, fields,
241 int download_remove_http_header_field(int download_id,
246 return DOWNLOAD_ERROR_INVALID_PARAMETER;
247 return dp_interface_remove_http_header_field(download_id, field);
250 // download_state_changed_cb is different with dp_interface_state_changed_cb.
251 int download_set_state_changed_cb(int download_id,
252 download_state_changed_cb callback, void* user_data)
255 return dp_interface_set_state_changed_cb(download_id,
256 (dp_interface_state_changed_cb)callback, user_data);
259 int download_unset_state_changed_cb(int download_id)
262 return dp_interface_unset_state_changed_cb(download_id);
265 // download_progress_cb is same with dp_interface_progress_cb.
266 int download_set_progress_cb(int download_id,
267 download_progress_cb callback, void *user_data)
270 return dp_interface_set_progress_cb(download_id,
271 (dp_interface_progress_cb)callback, user_data);
274 int download_unset_progress_cb(int download_id)
277 return dp_interface_unset_progress_cb(download_id);
280 int download_get_state(int download_id, download_state_e *state)
285 TRACE_ERROR("Parameter NULL Check");
286 return DOWNLOAD_ERROR_INVALID_PARAMETER;
288 int ret = dp_interface_get_state(download_id, &statecode);
289 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
294 int download_get_temp_path(int download_id, char **temp_path)
297 if (temp_path == NULL)
298 return DOWNLOAD_ERROR_INVALID_PARAMETER;
299 return dp_interface_get_temp_path(download_id, temp_path);
302 int download_get_content_name(int download_id, char **content_name)
305 if (content_name == NULL)
306 return DOWNLOAD_ERROR_INVALID_PARAMETER;
307 return dp_interface_get_content_name(download_id, content_name);
310 int download_get_content_size(int download_id,
311 unsigned long long *content_size)
314 if (content_size == NULL)
315 return DOWNLOAD_ERROR_INVALID_PARAMETER;
316 return dp_interface_get_content_size(download_id, content_size);
319 int download_get_mime_type(int download_id, char **mime_type)
322 if (mime_type == NULL)
323 return DOWNLOAD_ERROR_INVALID_PARAMETER;
324 return dp_interface_get_mime_type(download_id, mime_type);
327 int download_set_auto_download(int download_id, bool enable)
330 return dp_interface_set_auto_download(download_id, (int)enable);
333 int download_get_auto_download(int download_id, bool *enable)
337 if (enable == NULL) {
338 TRACE_ERROR("Parameter NULL Check");
339 return DOWNLOAD_ERROR_INVALID_PARAMETER;
341 int ret = dp_interface_get_auto_download(download_id, &is_set);
342 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
343 *enable = (bool)is_set;
347 int download_get_error(int download_id, download_error_e *error)
352 TRACE_ERROR("Parameter NULL Check");
353 return DOWNLOAD_ERROR_INVALID_PARAMETER;
355 int ret = dp_interface_get_error(download_id, &errorcode);
356 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
361 int download_get_http_status(int download_id, int *http_status)
364 if (http_status == NULL)
365 return DOWNLOAD_ERROR_INVALID_PARAMETER;
366 return dp_interface_get_http_status(download_id, http_status);
369 int download_set_notification_app_control(int download_id, download_notification_app_control_type_e type, app_control_h handle)
373 return DOWNLOAD_ERROR_INVALID_PARAMETER;
374 return dp_interface_set_notification_service_handle(download_id, (int)type, handle);
377 int download_get_notification_app_control(int download_id, download_notification_app_control_type_e type, app_control_h *handle)
381 return DOWNLOAD_ERROR_INVALID_PARAMETER;
382 return dp_interface_get_notification_service_handle(download_id, (int)type, (void **)handle);
385 int download_set_notification_title(int download_id, const char *title)
389 return DOWNLOAD_ERROR_INVALID_PARAMETER;
390 return dp_interface_set_notification_title(download_id, title);
393 int download_get_notification_title(int download_id, char **title)
397 return DOWNLOAD_ERROR_INVALID_PARAMETER;
398 return dp_interface_get_notification_title(download_id, title);
401 int download_set_notification_description(int download_id, const char *description)
404 if (description == NULL)
405 return DOWNLOAD_ERROR_INVALID_PARAMETER;
406 return dp_interface_set_notification_description(download_id, description);
409 int download_get_notification_description(int download_id, char **description)
412 if (description == NULL)
413 return DOWNLOAD_ERROR_INVALID_PARAMETER;
414 return dp_interface_get_notification_description(download_id, description);
417 int download_set_notification_type(int download_id, download_notification_type_e type)
420 return dp_interface_set_notification_type(download_id, (int)type);
423 int download_get_notification_type(int download_id, download_notification_type_e *type)
428 TRACE_ERROR("Parameter NULL Check");
429 return DOWNLOAD_ERROR_INVALID_PARAMETER;
431 int ret = dp_interface_get_notification_type(download_id, ¬i_type);
432 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
433 *type = (download_notification_type_e)noti_type;
437 int download_get_etag(int download_id, char **etag)
441 return DOWNLOAD_ERROR_INVALID_PARAMETER;
442 return dp_interface_get_etag(download_id, etag);
445 int download_set_temp_file_path(int download_id, char *path)
449 return DOWNLOAD_ERROR_INVALID_PARAMETER;
450 return dp_interface_set_temp_file_path(download_id, path);