2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "download-agent-interface.h"
18 #include "download-agent-debug.h"
19 #include "download-agent-utils.h"
20 #include "download-agent-http-mgr.h"
21 #include "download-agent-http-misc.h"
22 #include "download-agent-client-mgr.h"
23 #include "download-agent-dl-mgr.h"
24 #include "download-agent-basic.h"
25 #include "download-agent-file.h"
28 da_client_cb_t *da_client_callback)
30 da_result_t ret = DA_RESULT_OK;
32 DA_LOG_FUNC_START(Default);
34 if (!da_client_callback) {
35 ret = DA_ERR_INVALID_ARGUMENT;
40 if (ret != DA_RESULT_OK)
43 ret = init_client_app_mgr();
44 if (ret != DA_RESULT_OK)
47 ret = reg_client_app(da_client_callback);
48 if (ret != DA_RESULT_OK)
51 ret = init_http_mgr();
52 if (ret != DA_RESULT_OK)
55 ret = init_download_mgr();
56 if (ret != DA_RESULT_OK)
59 ret = create_saved_dir();
60 if (ret != DA_RESULT_OK)
64 if (DA_RESULT_OK != ret)
67 DA_LOG_CRITICAL(Default, "Return ret = %d", ret);
72 /* TODO:: deinit should clean up all the clients... */
75 da_result_t ret = DA_RESULT_OK;
77 DA_LOG_FUNC_START(Default);
80 deinit_download_mgr();
81 /* Do not clean temporary download path
82 * The client can resume or restart download with temporary file in case of failed download.
85 DA_LOG(Default, "====== da_deinit EXIT =====");
90 int da_start_download(
94 da_result_t ret = DA_RESULT_OK;
96 DA_LOG_FUNC_START(Default);
98 *download_id = DA_INVALID_ID;
100 if (DA_FALSE == is_valid_url(url, &ret))
103 DA_LOG(Default, "url = %s", url);
105 ret = start_download(url, download_id);
106 if (ret != DA_RESULT_OK)
110 DA_LOG_CRITICAL(Default, "Return: Dl req id = %d, ret = %d", *download_id, ret);
114 int da_start_download_with_extension(
116 extension_data_t *extension_data,
120 da_result_t ret = DA_RESULT_OK;
121 int req_header_count = 0;
124 DA_LOG_FUNC_START(Default);
126 *download_id = DA_INVALID_ID;
128 if (DA_FALSE == is_valid_url(url, &ret))
131 DA_LOG(Default, "url = %s", url);
133 if (ret != DA_RESULT_OK)
135 if (!extension_data) {
136 ret = DA_ERR_INVALID_ARGUMENT;
140 if (extension_data->request_header_count > 0) {
141 DA_LOG_VERBOSE(Default, "input request_header_count = [%d]",
142 extension_data->request_header_count);
143 for (i = 0; i < extension_data->request_header_count; i++) {
144 if (extension_data->request_header[i]) {
146 DA_LOG_VERBOSE(Default, "request_header = [%s]",
147 extension_data->request_header[i]);
150 DA_LOG(Default, "actual request_header_count = [%d]", req_header_count);
151 if (extension_data->request_header_count != req_header_count) {
152 DA_LOG_ERR(Default, "Request header count is not matched with number of request header array");
153 extension_data->request_header = NULL;
154 extension_data->request_header_count = 0;
155 ret = DA_ERR_INVALID_ARGUMENT;
160 if (extension_data->install_path) {
161 if (!is_dir_exist(extension_data->install_path))
162 return DA_ERR_INVALID_INSTALL_PATH;
163 DA_LOG_VERBOSE(Default, "install_path = [%s]", extension_data->install_path);
166 if (extension_data->file_name)
167 DA_LOG_VERBOSE(Default, "file_name = [%s]", extension_data->file_name);
168 if (extension_data->temp_file_path)
169 DA_LOG_VERBOSE(Default, "temp_file_path = [%s]", extension_data->temp_file_path);
170 if (extension_data->etag)
171 DA_LOG_VERBOSE(Default, "etag = [%s]", extension_data->etag);
173 if (extension_data->user_data)
174 DA_LOG_VERBOSE(Default, "user_data = [%p]", extension_data->user_data);
176 ret = start_download_with_extension(url, download_id, extension_data);
179 DA_LOG_CRITICAL(Default, "Return: Dl req id = %d, ret = %d", *download_id, ret);
183 int da_cancel_download(int download_id)
185 da_result_t ret = DA_RESULT_OK;
187 DA_LOG_VERBOSE(Default, "Cancel for dl_id = %d", download_id);
189 ret = cancel_download(download_id);
191 DA_LOG_CRITICAL(Default, "Return: Cancel id = %d, ret = %d", download_id, ret);
195 int da_suspend_download(int download_id)
197 da_result_t ret = DA_RESULT_OK;
199 DA_LOG_VERBOSE(Default, "Suspend for dl_id = %d", download_id);
201 ret = suspend_download(download_id, DA_TRUE);
203 DA_LOG_CRITICAL(Default, "Return: Suspend id = %d, ret = %d", download_id, ret);
207 int da_suspend_download_without_update(int download_id)
209 da_result_t ret = DA_RESULT_OK;
211 DA_LOG_VERBOSE(Default, "Suspend for dl_id = %d", download_id);
213 ret = suspend_download(download_id, DA_FALSE);
215 DA_LOG_CRITICAL(Default, "Return: Suspend id = %d, ret = %d", download_id, ret);
220 int da_resume_download(int download_id)
222 da_result_t ret = DA_RESULT_OK;
224 DA_LOG_VERBOSE(Default, "Resume for dl_id = %d", download_id);
226 ret = resume_download(download_id);
228 DA_LOG_CRITICAL(Default, "Return: Resume id = %d, ret = %d", download_id, ret);
232 int da_is_valid_download_id(int download_id)
234 da_bool_t ret = DA_FALSE;
235 ret = is_valid_download_id(download_id);