5 #include <sys/socket.h>
13 #include <download-provider-interface.h>
21 #define LOG_TAG "TIZEN_N_URL_DOWNLOAD"
22 #define TRACE_ERROR(format, ARG...) \
24 LOGE(format, ##ARG); \
26 #define TRACE_STRERROR(format, ARG...) \
28 LOGE(format" [%s]", ##ARG, strerror(errno)); \
30 #define TRACE_INFO(format, ARG...) \
32 LOGI(format, ##ARG); \
35 #define TRACE_DEBUG_MSG(format, ARG...) ;
38 /////////////////////// APIs /////////////////////////////////
40 int download_create(int *download_id)
43 return dp_interface_create(download_id);
46 int download_destroy(int download_id)
49 return dp_interface_destroy(download_id);
52 int download_start(int download_id)
55 return dp_interface_start(download_id);
58 int download_pause(int download_id)
61 return dp_interface_pause(download_id);
64 int download_cancel(int download_id)
67 return dp_interface_cancel(download_id);
71 int download_set_url(int download_id, const char *url)
74 return dp_interface_set_url(download_id, url);
78 int download_get_url(int download_id, char **url)
81 return dp_interface_get_url(download_id, url);
84 int download_set_network_type(int download_id,
85 download_network_type_e net_type)
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)
96 if (net_type == NULL) {
97 TRACE_ERROR("Parameter NULL Check");
98 return DOWNLOAD_ERROR_INVALID_PARAMETER;
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;
107 int download_set_destination(int download_id, const char *path)
110 return dp_interface_set_destination(download_id, path);
114 int download_get_destination(int download_id, char **path)
117 return dp_interface_get_destination(download_id, path);
120 int download_set_file_name(int download_id, const char *file_name)
123 return dp_interface_set_file_name(download_id, file_name);
126 int download_get_file_name(int download_id, char **file_name)
129 return dp_interface_get_file_name(download_id, file_name);
132 int download_set_notification(int download_id, bool enable)
135 return dp_interface_set_notification(download_id, (int)enable);
138 int download_get_notification(int download_id, bool *enable)
142 if (enable == NULL) {
143 TRACE_ERROR("Parameter NULL Check");
144 return DOWNLOAD_ERROR_INVALID_PARAMETER;
146 int ret = dp_interface_get_notification(download_id, &is_set);
147 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
148 *enable = (bool)is_set;
152 int download_get_downloaded_file_path(int download_id, char **path)
155 return dp_interface_get_downloaded_file_path(download_id, path);
158 int download_add_notification_extra_param(
159 int download_id, const char *key,
160 const char **value, const unsigned int length)
163 return dp_interface_add_noti_extra(download_id, key, value, length);
166 int download_remove_notification_extra_param(int download_id, const char *key)
169 return dp_interface_remove_noti_extra_key(download_id, key);
172 int download_get_notification_extra_param(
173 int download_id, const char *key,
174 char ***values, unsigned int *length)
177 return dp_interface_get_noti_extra_values(download_id, key, values, length);
180 int download_add_http_header_field(int download_id, const char *field,
185 dp_interface_add_http_header_field(download_id, field, value);
188 int download_get_http_header_field(int download_id,
189 const char *field, char **value)
193 dp_interface_get_http_header_field(download_id, field, value);
196 int download_get_http_header_field_list(int download_id, char ***fields,
200 return dp_interface_get_http_header_field_list(download_id, fields,
204 int download_remove_http_header_field(int download_id,
208 return dp_interface_remove_http_header_field(download_id, field);
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)
216 return dp_interface_set_state_changed_cb(download_id,
217 (dp_interface_state_changed_cb)callback, user_data);
220 int download_unset_state_changed_cb(int download_id)
223 return dp_interface_unset_state_changed_cb(download_id);
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)
231 return dp_interface_set_progress_cb(download_id,
232 (dp_interface_progress_cb)callback, user_data);
235 int download_unset_progress_cb(int download_id)
238 return dp_interface_unset_progress_cb(download_id);
241 int download_get_state(int download_id, download_state_e *state)
246 TRACE_ERROR("Parameter NULL Check");
247 return DOWNLOAD_ERROR_INVALID_PARAMETER;
249 int ret = dp_interface_get_state(download_id, &statecode);
250 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
255 int download_get_temp_path(int download_id, char **temp_path)
258 return dp_interface_get_temp_path(download_id, temp_path);
261 int download_get_content_name(int download_id, char **content_name)
264 return dp_interface_get_content_name(download_id, content_name);
267 int download_get_content_size(int download_id,
268 unsigned long long *content_size)
271 return dp_interface_get_content_size(download_id, content_size);
274 int download_get_mime_type(int download_id, char **mime_type)
277 return dp_interface_get_mime_type(download_id, mime_type);
280 int download_set_auto_download(int download_id, bool enable)
283 return dp_interface_set_auto_download(download_id, (int)enable);
286 int download_get_auto_download(int download_id, bool *enable)
290 if (enable == NULL) {
291 TRACE_ERROR("Parameter NULL Check");
292 return DOWNLOAD_ERROR_INVALID_PARAMETER;
294 int ret = dp_interface_get_auto_download(download_id, &is_set);
295 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
296 *enable = (bool)is_set;
300 int download_get_error(int download_id, download_error_e *error)
305 TRACE_ERROR("Parameter NULL Check");
306 return DOWNLOAD_ERROR_INVALID_PARAMETER;
308 int ret = dp_interface_get_error(download_id, &errorcode);
309 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
314 int download_get_http_status(int download_id, int *http_status)
317 return dp_interface_get_http_status(download_id, http_status);
320 int download_set_notification_bundle(int download_id, download_notification_bundle_type_e type, bundle *b)
323 return dp_interface_set_notification_bundle(download_id, (int)type, b);
326 int download_get_notification_bundle(int download_id, download_notification_bundle_type_e type, bundle **b)
329 return dp_interface_get_notification_bundle(download_id, (int)type, b);
332 int download_set_notification_title(int download_id, const char *title)
335 return dp_interface_set_notification_title(download_id, title);
338 int download_get_notification_title(int download_id, char **title)
341 return dp_interface_get_notification_title(download_id, title);
344 int download_set_notification_description(int download_id, const char *description)
347 return dp_interface_set_notification_description(download_id, description);
350 int download_get_notification_description(int download_id, char **description)
353 return dp_interface_get_notification_description(download_id, description);
356 int download_set_notification_type(int download_id, download_notification_type_e type)
359 return dp_interface_set_notification_type(download_id, (int)type);
362 int download_get_notification_type(int download_id, download_notification_type_e *type)
367 TRACE_ERROR("Parameter NULL Check");
368 return DOWNLOAD_ERROR_INVALID_PARAMETER;
370 int ret = dp_interface_get_notification_type(download_id, ¬i_type);
371 if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
372 *type = (download_notification_type_e)noti_type;