diff options
author | gloryj.kim <gloryj.kim@samsung.com> | 2015-03-03 21:10:12 +0900 |
---|---|---|
committer | gloryj.kim <gloryj.kim@samsung.com> | 2015-03-03 21:10:12 +0900 |
commit | a6d45b6f285e5caa1537992e6c42dd3ddb80a430 (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /agent | |
parent | d7efab678d65d5ea8c470d328427f24f4d683af9 (diff) | |
download | download-provider-a6d45b6f285e5caa1537992e6c42dd3ddb80a430.tar.gz download-provider-a6d45b6f285e5caa1537992e6c42dd3ddb80a430.tar.bz2 download-provider-a6d45b6f285e5caa1537992e6c42dd3ddb80a430.zip |
Remove the old initial version for the new version
Change-Id: Ief2b258de06b2e722bd4197d51edcce72db288e6
Diffstat (limited to 'agent')
29 files changed, 0 insertions, 7297 deletions
diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt deleted file mode 100755 index c92fc48..0000000 --- a/agent/CMakeLists.txt +++ /dev/null @@ -1,116 +0,0 @@ -PROJECT(downloadagent2 C) - -SET(VERSION "0.1.0") - -FIND_PROGRAM(UNAME NAMES uname) -EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") -IF("${ARCH}" MATCHES "^arm.*") - ADD_DEFINITIONS("-D_TARGET") - SET(CMAKE_C_FLAGS_RELEASE "-mabi=aapcs-linux -msoft-float -O2") -ENDIF("${ARCH}" MATCHES "^arm.*") - -#DA Engine Include Directory -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include) - -SET(SRCS_PATH ".") -SET(SRCS_DA - ${SRCS_PATH}/download-agent-interface.c - ${SRCS_PATH}/download-agent-client-mgr.c - ${SRCS_PATH}/download-agent-dl-mgr.c - ${SRCS_PATH}/download-agent-dl-info.c - ${SRCS_PATH}/download-agent-http-mgr.c - ${SRCS_PATH}/download-agent-http-msg-handler.c - ${SRCS_PATH}/download-agent-encoding.c - ${SRCS_PATH}/download-agent-file.c - ${SRCS_PATH}/download-agent-plugin-conf.c - ${SRCS_PATH}/download-agent-mime-util.c -) - -SET(HEADERS - include/download-agent-defs.h - include/download-agent-interface.h -) - -INCLUDE(FindPkgConfig) - -MESSAGE("SUPPORT_SYS_RESOURCE: ${SUPPORT_SYS_RESOURCE}") -IF (SUPPORT_SYS_RESOURCE) -pkg_check_modules(subpkgs REQUIRED - xdgmime - vconf - capi-network-connection - dlog - system-resource - storage -) -ELSE (SUPPORT_SYS_RESOURCE) -pkg_check_modules(subpkgs REQUIRED - xdgmime - vconf - capi-network-connection - dlog - storage -) -ENDIF (SUPPORT_SYS_RESOURCE) - -IF ("${HTTP_LIB}" MATCHES "libcurl") - MESSAGE("HTTP_LIB: ${HTTP_LIB}") - pkg_check_modules(httppkgs REQUIRED - libcurl - ) - LIST(APPEND SRCS_DA - ${SRCS_PATH}/download-agent-plugin-libcurl.c - ) -ENDIF ("${HTTP_LIB}" MATCHES "libcurl") - -IF (SUPPORT_OMA_DRM) - MESSAGE("SUPPORT_OMA_DRM: ${SUPPORT_OMA_DRM}") - ADD_DEFINITIONS("-D_ENABLE_OMA_DRM") - LIST(APPEND SRCS_DA - ${SRCS_PATH}/download-agent-plugin-drm.c - ) - pkg_check_modules(drmpkgs REQUIRED - drm-client - drm-trusted - ) -ENDIF (SUPPORT_OMA_DRM) - -IF (SUPPORT_SYS_RESOURCE) - ADD_DEFINITIONS("-D_ENABLE_SYS_RESOURCE") -ENDIF (SUPPORT_SYS_RESOURCE) - -IF (SUPPORT_DOWNLOAD_BOOSTER) - MESSAGE("SUPPORT_DOWNLOAD_BOOSTER:${SUPPORT_DOWNLOAD_BOOSTER}") - ADD_DEFINITIONS("-D_RAF_SUPPORT") - ADD_DEFINITIONS("-D_DOWNLOAD_BOOSTER_SUPPORT") -ENDIF (SUPPORT_DOWNLOAD_BOOSTER) - -FOREACH(flag ${subpkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -FOREACH(flag ${httppkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -IF (SUPPORT_OMA_DRM) - FOREACH(flag ${drmpkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") - ENDFOREACH(flag) - #This is request of DRM Team. - ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64") -ENDIF (SUPPORT_OMA_DRM) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") -SET(CMAKE_C_FLAGS_DEBUG "-O0 -Wall") - -ADD_DEFINITIONS("-D_ENABLE_DLOG") -#This should be removed when release a target -ADD_DEFINITIONS("-D_SAMSUNG_MIME_POLICY") - -ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS_DA}) - -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${subpkgs_LDFLAGS} ${httppkgs_LDFLAGS} ${drmpkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION}) - -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/agent/download-agent-client-mgr.c b/agent/download-agent-client-mgr.c deleted file mode 100755 index 82dd516..0000000 --- a/agent/download-agent-client-mgr.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> - -#include "download-agent-client-mgr.h" - -da_ret_t send_client_paused_info(da_info_t *da_info) -{ - req_info_t *req_info = DA_NULL; - NULL_CHECK_RET(da_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - - if (da_info->is_cb_update && da_info->cb_info.paused_cb) { - da_info->cb_info.paused_cb(da_info->da_id, - req_info->user_req_data, req_info->user_client_data); - DA_LOGV("id[%d]", da_info->da_id); - } else { - DA_LOGV("No CB:id[%d]", da_info->da_id); - } - - return DA_RESULT_OK; -} - -da_ret_t send_client_update_dl_info(da_info_t *da_info) -{ - download_info_t *info = DA_NULL; - file_info_t *file_info = DA_NULL; - http_info_t *http_info = DA_NULL; - req_info_t *req_info = DA_NULL; - NULL_CHECK_RET(da_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - - if (da_info->is_cb_update && da_info->cb_info.download_info_cb) { - info = (download_info_t *)calloc(1, sizeof(download_info_t)); - if (!info) - return DA_ERR_FAIL_TO_MEMALLOC; - info->download_id = da_info->da_id; - info->file_size = http_info->content_len_from_header; - if (http_info->content_type_from_header) - info->file_type = strdup(http_info->content_type_from_header); - if (file_info->file_path) - info->tmp_saved_path = strdup(file_info->file_path); - if (file_info->pure_file_name) - info->content_name = strdup(file_info->pure_file_name); - if (http_info->etag_from_header) { - info->etag = strdup(http_info->etag_from_header); - //DA_SECURE_LOGI("etag[%s]", info->etag); - } - da_info->cb_info.download_info_cb(info, - req_info->user_req_data, req_info->user_client_data); - DA_LOGD("id[%d]", info->download_id); - //DA_LOGI("id[%d]total_size[%lu]", info->download_id, info->file_size); - //if (http_info->content_type_from_header) - //DA_SECURE_LOGI("mime_type[%s]", http_info->content_type_from_header); - } else { - DA_LOGI("No CB:id[%d]", da_info->da_id); - } - return DA_RESULT_OK; -} - -da_ret_t send_client_update_progress_info(da_info_t *da_info) -{ - file_info_t *file_info = DA_NULL; - req_info_t *req_info = DA_NULL; - NULL_CHECK_RET(da_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - - if (!file_info->is_updated) - return DA_RESULT_OK; - - if (da_info->is_cb_update && da_info->cb_info.progress_cb) { - da_info->cb_info.progress_cb(da_info->da_id, - file_info->bytes_written_to_file, - req_info->user_req_data, req_info->user_client_data); - DA_LOGV("id[%d],size[%llu]", da_info->da_id, - file_info->bytes_written_to_file); - } else { - DA_LOGI("No CB:id[%d]", da_info->da_id); - } - file_info->is_updated = DA_FALSE; - return DA_RESULT_OK; -} - -da_ret_t send_client_finished_info(da_info_t *da_info, int err) -{ - finished_info_t *info = DA_NULL; - file_info_t *file_info = DA_NULL; - http_info_t *http_info = DA_NULL; - req_info_t *req_info = DA_NULL; - NULL_CHECK_RET(da_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - - if (da_info->is_cb_update && da_info->cb_info.finished_cb) { - info = (finished_info_t *)calloc(1, sizeof(finished_info_t)); - if (!info) - return DA_ERR_FAIL_TO_MEMALLOC; - info->download_id = da_info->da_id; - if (http_info->http_msg_response) - info->http_status = http_info->http_msg_response->status_code; - else - DA_LOGE("http_msg_response is NULL"); - if (file_info->file_path) - info->saved_path = strdup(file_info->file_path); - if (http_info->etag_from_header) - info->etag = strdup(http_info->etag_from_header); - info->err = err; - da_info->cb_info.finished_cb(info, - req_info->user_req_data, req_info->user_client_data); - DA_LOGD("id[%d]", info->download_id); - //DA_LOGI("id[%d],err[%d], http_status[%d]", info->download_id, - //info->err, info->http_status); - } else { - DA_LOGI("No CB:id[%d]", da_info->da_id); - } - return DA_RESULT_OK; -} - diff --git a/agent/download-agent-dl-info.c b/agent/download-agent-dl-info.c deleted file mode 100644 index 6e49145..0000000 --- a/agent/download-agent-dl-info.c +++ /dev/null @@ -1,462 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string.h> -#include <stdlib.h> - -#include "download-agent-dl-info.h" -#include "download-agent-http-mgr.h" -#include "download-agent-http-msg-handler.h" - -static pthread_mutex_t mutex_da_info_list = PTHREAD_MUTEX_INITIALIZER; - -static void __init_da_info(int id) -{ - da_info_t *da_info = DA_NULL; - file_info_t *file_info = DA_NULL; - http_info_t *http_info = DA_NULL; - req_info_t *req_info = DA_NULL; - - da_info = (da_info_t *)calloc(1, sizeof(da_info_t)); - if (!da_info) { - DA_LOGE("Fail to calloc. id[%d]",id); - da_info_list[id] = DA_NULL; - return; - } - file_info = (file_info_t *)calloc(1, sizeof(file_info_t)); - if (!file_info) { - DA_LOGE("Fail to calloc. id[%d]",id); - free(da_info); - da_info_list[id] = DA_NULL; - return; - } - http_info = (http_info_t *)calloc(1, sizeof(http_info_t)); - if (!http_info) { - DA_LOGE("Fail to calloc. id[%d]",id); - free(da_info); - free(file_info); - da_info_list[id] = DA_NULL; - return; - } - req_info = (req_info_t *)calloc(1, sizeof(req_info_t)); - if (!req_info) { - DA_LOGE("Fail to calloc. id[%d]",id); - free(da_info); - free(file_info); - free(http_info); - da_info_list[id] = DA_NULL; - return; - } - - da_info->da_id = DA_INVALID_ID; - da_info->tid = DA_INVALID_ID; - memset(&(da_info->cb_info), 0x00, sizeof(da_cb_t)); - da_info->is_cb_update = DA_FALSE; - da_info->http_info = http_info; - da_info->file_info = file_info; - da_info->req_info = req_info; - da_info->update_time = 0; - da_info_list[id] = da_info; -} - -da_ret_t init_http_msg_t(http_msg_t **http_msg) -{ - da_ret_t ret = DA_RESULT_OK; - http_msg_t *temp = DA_NULL; - temp = (http_msg_t *)calloc(1, sizeof(http_msg_t)); - if (!temp) { - DA_LOGE("Fail to calloc. id"); - return DA_ERR_FAIL_TO_MEMALLOC; - } - *http_msg = temp; - return ret; -} - -void destroy_http_msg_t(http_msg_t *http_msg) -{ - if (http_msg) - free(http_msg); - http_msg = DA_NULL; - return; -} - -da_ret_t get_available_da_id(int *available_id) -{ - da_ret_t ret = DA_ERR_ALREADY_MAX_DOWNLOAD; - int i = 0; - - DA_MUTEX_LOCK(&mutex_da_info_list); - for (i = 0; i < DA_MAX_ID; i++) { - if (da_info_list[i] == DA_NULL) { - *available_id = i; - DA_LOGV("available download id[%d]", *available_id); - __init_da_info(i); - ret = DA_RESULT_OK; - break; - } - } - DA_MUTEX_UNLOCK(&mutex_da_info_list); - - return ret; -} - -da_ret_t get_da_info_with_da_id(int id, da_info_t **out_info) -{ - da_ret_t ret = DA_ERR_INVALID_ARGUMENT; - int i = 0; - - DA_MUTEX_LOCK(&mutex_da_info_list); - for (i = 0; i < DA_MAX_ID; i++) { - if (DA_NULL != da_info_list[i] && da_info_list[i]->da_id == id) { - *out_info = da_info_list[i]; - ret = DA_RESULT_OK; - break; - } - } - DA_MUTEX_UNLOCK(&mutex_da_info_list); - - return ret; -} - -da_ret_t __is_supporting_protocol(const char *url) -{ - da_ret_t ret = DA_RESULT_OK; - int wanted_str_len = 0; - char *protocol = NULL; - char *wanted_str_start = NULL; - char *wanted_str_end = NULL; - - if (DA_NULL == url || strlen(url) < 1) - return DA_ERR_INVALID_URL; - - wanted_str_start = (char*)url; - wanted_str_end = strstr(url, "://"); - if (!wanted_str_end) { - DA_LOGE("No protocol on this url"); - return DA_ERR_INVALID_URL; - } - - wanted_str_len = wanted_str_end - wanted_str_start; - protocol = (char*)calloc(1, wanted_str_len + 1); - if (!protocol) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - return DA_ERR_FAIL_TO_MEMALLOC; - } - strncpy(protocol, wanted_str_start, wanted_str_len); - - if (strlen(protocol) < 1) - ret = DA_ERR_UNSUPPORTED_PROTOCAL; - else if (strcasecmp(protocol, "http") != 0 && - strcasecmp(protocol, "https") != 0) - ret = DA_ERR_UNSUPPORTED_PROTOCAL; - - free(protocol); - return ret; -} - -da_ret_t copy_user_input_data(da_info_t *da_info, const char *url, - req_data_t *ext_data, da_cb_t *da_cb_data) -{ - da_ret_t ret = DA_RESULT_OK; - - if (!url || !da_info) { - DA_LOGE("Invalid Param"); - return DA_ERR_INVALID_ARGUMENT; - } - - ret = __is_supporting_protocol(url); - if (ret != DA_RESULT_OK) { - DA_SECURE_LOGE("url[%s]", url); - return ret; - } - - if (ext_data) { - req_info_t *req_info = da_info->req_info; - - if (ext_data->request_header_count > 0) { - int i = 0; - int count = ext_data->request_header_count; - req_info->req_header = (char **)calloc(count, sizeof(char *)); - if(DA_NULL == req_info->req_header) { - DA_LOGE("Fail to calloc"); - free(req_info); - da_info->req_info = DA_NULL; - return DA_ERR_FAIL_TO_MEMALLOC; - } - for (i = 0; i < count; i++) { - if (ext_data->request_header[i]) - req_info->req_header[i] = - strdup(ext_data->request_header[i]); - } - req_info->req_header_count = count; - } - - if (url) - req_info->url = strdup(url); - if (ext_data->install_path) - req_info->install_path = strdup(ext_data->install_path); - if (ext_data->file_name) - req_info->file_name = strdup(ext_data->file_name); - if (ext_data->etag) - req_info->etag = strdup(ext_data->etag); - if (ext_data->temp_file_path) - req_info->temp_file_path = strdup(ext_data->temp_file_path); - if (ext_data->pkg_name) - req_info->pkg_name = strdup(ext_data->pkg_name); - req_info->network_bonding = ext_data->network_bonding; - if (ext_data->user_req_data) - req_info->user_req_data = ext_data->user_req_data; - if (ext_data->user_client_data) - req_info->user_client_data = ext_data->user_client_data; - da_info->req_info = req_info; - } - if (da_cb_data) { - da_info->is_cb_update = DA_TRUE; - memcpy(&(da_info->cb_info), da_cb_data, sizeof(da_cb_t)); - } - return ret; -} - -static void __destroy_http_msg(http_msg_t *msg) -{ - msg->curl = DA_NULL; - free(msg); -} - -static void __destroy_http_msg_request(http_msg_request_t *msg) -{ - if (msg) { - http_msg_request_destroy(&msg); - free(msg); - } -} - -static void __destroy_http_msg_response(http_msg_response_t *msg) -{ - if (msg) { - http_msg_response_destroy(&msg); - free(msg); - } -} - -static void __destroy_req_info(req_info_t *req_info) -{ - if (req_info) { - free(req_info->url); - if (req_info->req_header && req_info->req_header_count > 0) { - int i = 0; - int count = req_info->req_header_count; - for (i = 0; i < count; i++) { - free(req_info->req_header[i]); - req_info->req_header[i] = DA_NULL; - } - free(req_info->req_header); - req_info->req_header = DA_NULL; - req_info->req_header_count = 0; - } - free(req_info->install_path); - free(req_info->file_name); - free(req_info->etag); - free(req_info->temp_file_path); - free(req_info->pkg_name); - req_info->user_req_data = DA_NULL; - req_info->user_client_data = DA_NULL; - free(req_info); - } -} - -void destroy_http_info(http_info_t *http_info) -{ - if (http_info) { - DA_LOGI("[TEST] location_url[%p]",http_info->location_url); - free(http_info->location_url); - free(http_info->proxy_addr); - free(http_info->content_type_from_header); - free(http_info->etag_from_header); - free(http_info->file_name_from_header); - if (http_info->http_msg_request) { - __destroy_http_msg_request(http_info->http_msg_request); - http_info->http_msg_request = DA_NULL; - } - if (http_info->http_msg_response) { - __destroy_http_msg_response(http_info->http_msg_response); - http_info->http_msg_response = DA_NULL; - } - if (http_info->http_msg) { - __destroy_http_msg(http_info->http_msg); - http_info->http_msg = DA_NULL; - } - DA_MUTEX_DESTROY(&(http_info->mutex_state)); - DA_MUTEX_DESTROY(&(http_info->mutex_http)); - DA_COND_DESTROY(&(http_info->cond_http)); - http_info->state = HTTP_STATE_READY_TO_DOWNLOAD; - http_info->http_method = HTTP_METHOD_GET; - http_info->content_len_from_header = 0; - http_info->total_size = 0; - http_info->error_code = 0; - free(http_info); - } -} - -void destroy_file_info(file_info_t *file_info) -{ - if (file_info) { - file_info->file_handle = DA_NULL; - free(file_info->pure_file_name); - free(file_info->extension); - free(file_info->file_path); - free(file_info->mime_type); - free(file_info->buffer); - file_info->buffer_len = 0; - file_info->file_size = 0; -#ifdef _RAF_SUPPORT - file_info->file_size_of_temp_file = 0; -#endif - file_info->bytes_written_to_file = 0; - file_info->is_updated = DA_FALSE; - free(file_info); - } -} - -// For pause and resume case -void reset_http_info_for_resume(http_info_t *http_info) -{ - if (http_info) { - DA_LOGI("[TEST] location_url[%p]",http_info->location_url); - free(http_info->location_url); - http_info->location_url = DA_NULL; - free(http_info->proxy_addr); - http_info->proxy_addr = DA_NULL; - free(http_info->content_type_from_header); - http_info->content_type_from_header = DA_NULL; - if (http_info->http_msg_response) { - __destroy_http_msg_response(http_info->http_msg_response); - http_info->http_msg_response = DA_NULL; - } - if (http_info->http_msg) { - __destroy_http_msg(http_info->http_msg); - http_info->http_msg = DA_NULL; - } - http_info->http_method = HTTP_METHOD_GET; - http_info->content_len_from_header = 0; - http_info->total_size = 0; - } -} - -void reset_http_info(http_info_t *http_info) -{ - if (http_info) { - DA_LOGI("[TEST] location_url[%p]",http_info->location_url); - free(http_info->location_url); - http_info->location_url = DA_NULL; - free(http_info->proxy_addr); - http_info->proxy_addr = DA_NULL; - free(http_info->content_type_from_header); - http_info->content_type_from_header = DA_NULL; - if (http_info->http_msg_request) { - __destroy_http_msg_request(http_info->http_msg_request); - http_info->http_msg_request = DA_NULL; - } - if (http_info->http_msg_response) { - __destroy_http_msg_response(http_info->http_msg_response); - http_info->http_msg_response = DA_NULL; - } - if (http_info->http_msg) { - __destroy_http_msg(http_info->http_msg); - http_info->http_msg = DA_NULL; - } - http_info->http_method = HTTP_METHOD_GET; - http_info->content_len_from_header = 0; - http_info->total_size = 0; - } -} - -da_bool_t is_valid_download_id(int download_id) -{ - da_ret_t ret = DA_RESULT_OK; - - DA_LOGV(""); - DA_MUTEX_LOCK(&mutex_da_info_list); - if (DA_NULL == da_info_list[download_id]) { - DA_MUTEX_UNLOCK(&mutex_da_info_list); - return DA_FALSE; - } - if (is_stopped_state(da_info_list[download_id])) { - DA_MUTEX_UNLOCK(&mutex_da_info_list); - return DA_TRUE; - } - if (da_info_list[download_id]->da_id != DA_INVALID_ID) { - DA_MUTEX_UNLOCK(&mutex_da_info_list); - return DA_TRUE; - } else { - DA_MUTEX_UNLOCK(&mutex_da_info_list); - return DA_FALSE; - } - DA_MUTEX_UNLOCK(&mutex_da_info_list); - return ret; -} - -void destroy_da_info_list() -{ - int i = 0; - DA_MUTEX_LOCK(&mutex_da_info_list); - for (i = 0; i < DA_MAX_ID; i++) { - if(DA_NULL != da_info_list[i]) { - if (da_info_list[i]->req_info) { - __destroy_req_info(da_info_list[i]->req_info); - da_info_list[i]->req_info = DA_NULL; - } - if (da_info_list[i]->http_info) { - destroy_http_info(da_info_list[i]->http_info); - da_info_list[i]->http_info = DA_NULL; - } - if (da_info_list[i]->file_info) { - destroy_file_info(da_info_list[i]->file_info); - da_info_list[i]->file_info = DA_NULL; - } - free(da_info_list[i]); - da_info_list[i] = DA_NULL; - } - } - DA_MUTEX_UNLOCK(&mutex_da_info_list); -} - -void destroy_da_info(int id) -{ - da_info_t *da_info = DA_NULL; - DA_MUTEX_LOCK(&mutex_da_info_list); - da_info = da_info_list[id]; - if (da_info) { - if (da_info->req_info) { - __destroy_req_info(da_info->req_info); - da_info->req_info = DA_NULL; - } - if (da_info->http_info) { - destroy_http_info(da_info->http_info); - da_info->http_info = DA_NULL; - } - if (da_info->file_info) { - destroy_file_info(da_info->file_info); - da_info->file_info = DA_NULL; - } - da_info->da_id = DA_INVALID_ID; - da_info->tid = DA_INVALID_ID; - memset(&(da_info->cb_info), 0x00, sizeof(da_cb_t)); - free(da_info); - da_info_list[id] = DA_NULL; - } - DA_MUTEX_UNLOCK(&mutex_da_info_list); -} diff --git a/agent/download-agent-dl-mgr.c b/agent/download-agent-dl-mgr.c deleted file mode 100755 index e57f3f3..0000000 --- a/agent/download-agent-dl-mgr.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> -#include <sys/syscall.h> -#include <signal.h> - -#ifdef _ENABLE_SYS_RESOURCE -#include "resourced.h" -#endif - -#include "download-agent-dl-mgr.h" -#include "download-agent-dl-info.h" -#include "download-agent-http-mgr.h" - -void __thread_clean_up_handler_for_start_download(void *arg) -{ - DA_LOGI("cleanup for thread id[%lu]", pthread_self()); -} - -da_ret_t __download_content(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - - DA_LOGV(""); - if (!da_info) { - DA_LOGE("NULL CHECK!: da_info"); - ret = DA_ERR_INVALID_ARGUMENT; - return ret; - } - - ret = request_http_download(da_info); - return ret; -} - - -static void *__thread_start_download(void *data) -{ - da_info_t *da_info = DA_NULL; - req_info_t *req_info = DA_NULL; - int da_id = DA_INVALID_ID; - -// DA_LOGV(""); - - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, DA_NULL); - - da_info = (da_info_t *)data; - NULL_CHECK_RET_OPT(da_info, DA_NULL); - req_info = da_info->req_info; - NULL_CHECK_RET_OPT(req_info, DA_NULL); - - da_id = da_info->da_id; - pthread_cleanup_push(__thread_clean_up_handler_for_start_download, DA_NULL); -#ifdef _ENABLE_SYS_RESOURCE - if (req_info->pkg_name) { - pid_t tid = (pid_t) syscall(SYS_gettid); - da_info->tid = (pid_t) syscall(SYS_gettid); - DA_SECURE_LOGI("pkg_name[%s] threadid[%lu]", - req_info->pkg_name,pthread_self()); - if (join_app_performance(req_info->pkg_name, tid) != - RESOURCED_ERROR_OK) { - DA_LOGE("Can not put app to network performance id[%d]", da_id); - } - } -#endif - __download_content(da_info); - destroy_da_info(da_id); - pthread_cleanup_pop(0); - DA_LOGI("=====EXIT thread : da_id[%d]=====", da_id); - pthread_exit((void *)DA_NULL); - return DA_NULL; -} - -da_ret_t start_download(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - pthread_attr_t thread_attr; - pthread_t tid; - if (pthread_attr_init(&thread_attr) != 0) { - ret = DA_ERR_FAIL_TO_CREATE_THREAD; - goto ERR; - } - - if (pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED) != 0) { - ret = DA_ERR_FAIL_TO_CREATE_THREAD; - goto ERR; - } - - if (pthread_create(&(tid), &thread_attr, - __thread_start_download, da_info) < 0) { - DA_LOGE("Fail to make thread:id[%d]", da_info->da_id); - ret = DA_ERR_FAIL_TO_CREATE_THREAD; - } else { - if (tid < 1) { - DA_LOGE("The thread start is failed before calling this"); -// When http resource is leaked, the thread ID is initialized at error handling section of thread_start_download() -// Because the thread ID is initialized, the ptrhead_detach should not be called. This is something like timing issue between threads. -// thread info and basic_dl_input is freed at thread_start_download(). And it should not returns error code in this case. - ret = DA_ERR_FAIL_TO_CREATE_THREAD; - goto ERR; - } - } - da_info->thread_id = tid; - DA_LOGI("Thread create:thread id[%lu]", da_info->thread_id); -ERR: - if (DA_RESULT_OK != ret) { - destroy_da_info(da_info->da_id); - } - return ret; -} - -da_ret_t cancel_download(int dl_id, da_bool_t is_enable_cb) -{ - da_ret_t ret = DA_RESULT_OK; - da_info_t *da_info = DA_NULL; - - DA_LOGV(""); - - ret = get_da_info_with_da_id(dl_id, &da_info); - if (ret != DA_RESULT_OK || !da_info) { - return DA_ERR_INVALID_ARGUMENT; - } - da_info->is_cb_update = is_enable_cb; - ret = request_to_cancel_http_download(da_info); - if (ret != DA_RESULT_OK) - goto ERR; - DA_LOGI("Download cancel Successful for download id[%d]", da_info->da_id); - -ERR: - return ret; -} - -da_ret_t suspend_download(int dl_id, da_bool_t is_enable_cb) -{ - da_ret_t ret = DA_RESULT_OK; - da_info_t *da_info = DA_NULL; - - DA_LOGV(""); - - ret = get_da_info_with_da_id(dl_id, &da_info); - if (ret != DA_RESULT_OK || !da_info) { - return DA_ERR_INVALID_ARGUMENT; - } - da_info->is_cb_update = is_enable_cb; - ret = request_to_suspend_http_download(da_info); - if (ret != DA_RESULT_OK) - goto ERR; - DA_LOGV("Download Suspend Successful for download id[%d]", da_info->da_id); -ERR: - return ret; - -} - -da_ret_t resume_download(int dl_id) -{ - da_ret_t ret = DA_RESULT_OK; - da_info_t *da_info = DA_NULL; - - DA_LOGV(""); - - ret = get_da_info_with_da_id(dl_id, &da_info); - if (ret != DA_RESULT_OK || !da_info) { - return DA_ERR_INVALID_ARGUMENT; - } - da_info->is_cb_update = DA_TRUE; - ret = request_to_resume_http_download(da_info); - if (ret != DA_RESULT_OK) - goto ERR; - DA_LOGV("Download Resume Successful for download id[%d]", da_info->da_id); -ERR: - return ret; -} - diff --git a/agent/download-agent-encoding.c b/agent/download-agent-encoding.c deleted file mode 100755 index 3f14fca..0000000 --- a/agent/download-agent-encoding.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string.h> -#include <stdlib.h> -#include "glib.h" - -#include "download-agent-debug.h" -#include "download-agent-encoding.h" - -da_ret_t _parsing_base64_encoded_str(const char *in_encoded_str, - char **out_charset_type, - char *out_encoding_type, - char **out_raw_encoded_str); - -da_bool_t is_base64_encoded_word(const char *in_str) -{ - const char *haystack = DA_NULL; - char first_needle[8] = {0,}; - char second_needle[8] = {0,}; - char *found_str = DA_NULL; - - if (!in_str) { - DA_LOGE("input string is NULL"); - return DA_FALSE; - } - - haystack = in_str; - if (haystack[0] == '"') { - snprintf(first_needle, sizeof(first_needle), "%s", "\"=?"); // "=? - snprintf(second_needle, sizeof(second_needle), "%s", "?=\""); // ?=" - } else { - snprintf(first_needle, sizeof(first_needle), "%s", "=?"); // =? - snprintf(second_needle, sizeof(second_needle), "%s", "?="); // ?= - } - - found_str = strstr(haystack, first_needle); - if (found_str) { - if (found_str == haystack) { - haystack = haystack + strlen(haystack) - strlen(second_needle); - if(!strcmp(haystack, second_needle)) - return DA_TRUE; - } - } - return DA_FALSE; -} - -da_ret_t decode_base64_encoded_str(const char *in_encoded_str, - char **out_decoded_ascii_str) -{ - da_ret_t ret = DA_RESULT_OK; - const char *org_str = DA_NULL; - char *charset_type = NULL; - char encoding_type = '\0'; - char *raw_encoded_str = NULL; - char *decoded_str = NULL; - const gchar *g_encoded_text = NULL; - guchar *g_decoded_text = NULL; - gsize g_decoded_text_len = 0; - - DA_SECURE_LOGD("input str = [%s]", in_encoded_str); - - org_str = in_encoded_str; - if(!org_str) { - DA_LOGE("Input string is NULL"); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } - - ret = _parsing_base64_encoded_str(org_str, &charset_type, - &encoding_type, &raw_encoded_str); - if(ret != DA_RESULT_OK) { - goto ERR; - } - - if(encoding_type != 'B') { - DA_LOGE("Encoded Word is not encoded with Base64, but %c. We can only handle Base64.", encoding_type); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } - - /* - * on glib/gtype.h - * typedef char gchar; - * typedef unsigned char guchar; - * - */ - g_encoded_text = (const gchar*)raw_encoded_str; - g_decoded_text = g_base64_decode(g_encoded_text, &g_decoded_text_len); - - if(g_decoded_text) { - DA_SECURE_LOGD("g_decoded_text = [%s]", g_decoded_text); - decoded_str = (char*)calloc(1, g_decoded_text_len+1); - if(!decoded_str) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - ret = DA_ERR_FAIL_TO_MEMALLOC; - goto ERR; - } else { - memcpy(decoded_str, g_decoded_text, g_decoded_text_len); - } - } - DA_SECURE_LOGD("decoded_str = [%s]", decoded_str); - -ERR: - *out_decoded_ascii_str = decoded_str; - if(charset_type) { - free(charset_type); - charset_type = NULL; - } - if(raw_encoded_str) { - free(raw_encoded_str); - raw_encoded_str = NULL; - } - if(g_decoded_text) { - g_free(g_decoded_text); - } - return ret; -} - -da_ret_t _parsing_base64_encoded_str(const char *in_encoded_str, - char **out_charset_type, - char *out_encoding_type, - char **out_raw_encoded_str) -{ - da_ret_t ret = DA_RESULT_OK; - const char *org_str = DA_NULL; // e.g. =?UTF-8?B?7Jew7JWE7JmA7IKs7J6QLmpwZw==?= - char *charset_type = NULL; // e.g. UTF-8 - char encoding_type = '\0'; // e.g. B (means Base64) - char *raw_encoded_str = NULL; // e.g. 7Jew7JWE7JmA7IKs7J6QLmpwZw== - char *haystack = DA_NULL; - char needle[8] = {0,}; - char *wanted_str = DA_NULL; - int wanted_str_len = 0; - char *wanted_str_start = DA_NULL; - char *wanted_str_end = DA_NULL; - - org_str = in_encoded_str; - if (!org_str) { - DA_LOGE("Input string is NULL"); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } - - // strip "=?" - haystack = (char*)org_str; - snprintf(needle, sizeof(needle), "=?"); - wanted_str_end = strstr(haystack, needle); - if (!wanted_str_end) { - DA_LOGE("DA_ERR_INVALID_ARGUMENT"); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } else { - wanted_str = wanted_str_end + strlen(needle); - } - - // for charset - haystack = wanted_str_start = wanted_str; - needle[0] = '?'; - wanted_str_end = strchr(haystack, needle[0]); - if (!wanted_str_end) { - DA_LOGE("DA_ERR_INVALID_ARGUMENT"); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } else { - wanted_str_len = wanted_str_end - wanted_str_start + 1; - wanted_str = (char*)calloc(1, wanted_str_len+1); - if (!wanted_str) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - ret = DA_ERR_FAIL_TO_MEMALLOC; - goto ERR; - } else { - snprintf(wanted_str, wanted_str_len+1, "%s", wanted_str_start); - charset_type = wanted_str; - wanted_str = DA_NULL; - } - - DA_LOGV("charset [%s]", charset_type); - } - - // for encoding - encoding_type = *(++wanted_str_end); - DA_LOGV("encoding [%c]", encoding_type); - - // for raw encoded str - haystack = wanted_str_start = wanted_str_end + 1; - snprintf(needle, sizeof(needle), "?="); - wanted_str_end = strstr(haystack, needle); - if (!wanted_str_end) { - DA_LOGE("DA_ERR_INVALID_ARGUMENT"); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } else { - wanted_str_len = wanted_str_end - wanted_str_start + 1; - wanted_str = (char*)calloc(1, wanted_str_len+1); - if (!wanted_str) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - ret = DA_ERR_FAIL_TO_MEMALLOC; - goto ERR; - } else { - snprintf(wanted_str, wanted_str_len+1, "%s", wanted_str_start); - raw_encoded_str = wanted_str; - wanted_str = NULL; - } - - DA_SECURE_LOGD("raw encoded str [%s]", raw_encoded_str); - } -ERR: - if (ret != DA_RESULT_OK) { - if (charset_type) { - free(charset_type); - charset_type = NULL; - } - } - *out_charset_type = charset_type; - *out_encoding_type = encoding_type; - *out_raw_encoded_str = raw_encoded_str; - return ret; -} - -void decode_url_encoded_str(const char *in_encoded_str, char **out_str) -{ - char *in = NULL; - char *out = NULL; - *out_str = calloc(1, strlen(in_encoded_str) + 1); - if (*out_str == NULL) - return; - out = *out_str; - in = (char *)in_encoded_str; - while (*in) - { - if (*in == '%') { - int hex = 0; - in++; - if (sscanf(in, "%2x", &hex) <= 0) { - return; - } else { - *out = hex; - in++; - } - } else if (*in == '+') { - *out = ' '; - } else { - *out = *in; - } - in++; - out++; - } -} diff --git a/agent/download-agent-file.c b/agent/download-agent-file.c deleted file mode 100755 index ea901e2..0000000 --- a/agent/download-agent-file.c +++ /dev/null @@ -1,908 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> -#include <dirent.h> -#include <unistd.h> -#include <string.h> -#include <sys/vfs.h> -#include <math.h> -#include <errno.h> - -#include "download-agent-debug.h" -#include "download-agent-file.h" -#include "download-agent-mime-util.h" -/* FIXME Later */ -#include "download-agent-http-msg-handler.h" -#include "download-agent-plugin-drm.h" -#include "download-agent-plugin-conf.h" -#include <storage.h> - - -#define NO_NAME_TEMP_STR "No name" -#define MAX_SUFFIX_COUNT 1000000000 - -da_ret_t __saved_file_open(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - char *actual_file_path = DA_NULL; - void *fd = DA_NULL; - - DA_LOGV(""); - - actual_file_path = file_info->file_path; - if (!actual_file_path) - return DA_ERR_INVALID_ARGUMENT; - - fd = fopen(actual_file_path, "a+"); // for resume - if (fd == DA_NULL) { - DA_LOGE("File open failed"); - if (errno == ENOSPC) - ret = DA_ERR_DISK_FULL; - else - ret = DA_ERR_FAIL_TO_ACCESS_FILE; - goto ERR; - } - - file_info->file_handle = fd; - //DA_SECURE_LOGD("file path for saving[%s]", file_info->file_path); - -ERR: - if (DA_RESULT_OK != ret) { - file_info->file_handle = DA_NULL; - } - return ret; -} - -da_ret_t __divide_file_name_into_pure_name_N_extesion(const char *in_file_name, char **out_pure_file_name, char **out_extension) -{ - char *file_name = DA_NULL; - char *tmp_ptr = DA_NULL; - char temp_file[DA_MAX_FILE_PATH_LEN] = {0,}; - char tmp_ext[DA_MAX_STR_LEN] = {0,}; - int len = 0; - da_ret_t ret = DA_RESULT_OK; - - DA_LOGV(""); - - if (!in_file_name) - return DA_ERR_INVALID_ARGUMENT; - - file_name = (char *)in_file_name; - tmp_ptr = strrchr(file_name, '.'); - if (tmp_ptr) - tmp_ptr++; - if (tmp_ptr && out_extension) { - strncpy((char*) tmp_ext, tmp_ptr, sizeof(tmp_ext) - 1); - *out_extension = strdup((const char*) tmp_ext); - DA_SECURE_LOGD("extension [%s]", *out_extension); - } - - if (!out_pure_file_name) - return ret; - - if (tmp_ptr) - len = tmp_ptr - file_name - 1; - else - len = strlen(file_name); - - if (len >= DA_MAX_FILE_PATH_LEN) { - strncpy((char*) temp_file, file_name, - DA_MAX_FILE_PATH_LEN - 1); - } else { - strncpy((char*) temp_file, file_name, len); - } - - delete_prohibited_char((char*) temp_file, - strlen((char*) temp_file)); - if (strlen(temp_file) < 1) { - *out_pure_file_name = strdup(NO_NAME_TEMP_STR); - } else { - *out_pure_file_name = strdup( - (const char*) temp_file); - } - - DA_LOGV( "pure file name [%s]", *out_pure_file_name); - return ret; -} - -da_ret_t __file_write_buf_make_buf(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - char *buffer = DA_NULL; - - DA_LOGV(""); - - buffer = (char*) calloc(1, DA_FILE_BUF_SIZE); - if (DA_NULL == buffer) { - DA_LOGE("Calloc failure "); - ret = DA_ERR_FAIL_TO_MEMALLOC; - } else { - file_info->buffer_len = 0; - file_info->buffer = buffer; - } - - return ret; -} - -da_ret_t __file_write_buf_destroy_buf(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - - DA_LOGV(""); - NULL_CHECK_RET(file_info); - - free(file_info->buffer); - file_info->buffer = DA_NULL; - file_info->buffer_len = 0; - - return ret; -} - -da_ret_t __file_write_buf_flush_buf(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - char *buffer = DA_NULL; - int buffer_size = 0; - int write_success_len = 0; - void *fd = DA_NULL; - - // DA_LOGV(""); - - buffer = file_info->buffer; - buffer_size = file_info->buffer_len; - - if (buffer_size == 0) { - DA_LOGE("no data on buffer.."); - return ret; - } - - fd = file_info->file_handle; - if (DA_NULL == fd) { - DA_LOGE("There is no file handle."); - - ret = DA_ERR_FAIL_TO_ACCESS_FILE; - goto ERR; - } - - write_success_len = fwrite(buffer, sizeof(char), buffer_size, - (FILE *) fd); - /* FIXME : This can be necessary later due to progressive download. - * The solution for reducing fflush is needed */ - //fflush((FILE *) fd); - if (write_success_len != buffer_size) { - DA_LOGE("write fails "); - if (errno == ENOSPC) - ret = DA_ERR_DISK_FULL; - else - ret = DA_ERR_FAIL_TO_ACCESS_FILE; - goto ERR; - } - file_info->bytes_written_to_file += write_success_len; - file_info->is_updated = DA_TRUE; - file_info->buffer_len = 0; -ERR: - return ret; -} - -da_ret_t __file_write_buf_copy_to_buf(file_info_t *file_info, char *body, - int body_len) -{ - da_ret_t ret = DA_RESULT_OK; - char *buffer = DA_NULL; - int buffer_size = 0; - - DA_LOGV(""); - - NULL_CHECK_RET(file_info->buffer); - buffer = file_info->buffer; - buffer_size = file_info->buffer_len; - - memcpy(buffer + buffer_size, body, body_len); - file_info->buffer_len += body_len; - - return ret; -} - -da_ret_t __file_write_buf_directly_write(file_info_t *file_info, - char *body, int body_len) -{ - da_ret_t ret = DA_RESULT_OK; - size_t write_success_len = 0; - void *fd = DA_NULL; - - // DA_LOGV(""); - - fd = file_info->file_handle; - if (DA_NULL == fd) { - DA_LOGE("There is no file handle."); - ret = DA_ERR_FAIL_TO_ACCESS_FILE; - goto ERR; - } - - write_success_len = fwrite(body, sizeof(char), (size_t)body_len, - (FILE *) fd); - /* FIXME : This can be necessary later due to progressive download. - * The solution for reducing fflush is needed */ - //fflush((FILE *) fd); - if (write_success_len != (size_t)body_len) { - DA_LOGE("write fails "); - if (errno == ENOSPC) - ret = DA_ERR_DISK_FULL; - else - ret = DA_ERR_FAIL_TO_ACCESS_FILE; - goto ERR; - } - file_info->bytes_written_to_file += write_success_len; - DA_LOGV( "write %llu bytes", write_success_len); - file_info->is_updated = DA_TRUE; - -ERR: - return ret; -} - -/* Priority to derive extension - * 1. extension name which client set - * 2. according to MIME-Type - * 3. if MIME-Type is ambiguous or blank, - * 3-1. derived from <Content-Disposition> field's "filename" attribute - * 3-2. derived from url - * 4. if url does not have extension, leave blank for extension - */ -char *__get_extension_name(char *mime_type, - char *file_name_from_header, char *url) -{ - char *extension = DA_NULL; - - /* Priority 1 */ - if (mime_type && !is_ambiguous_MIME_Type(mime_type)) { - char *extension = DA_NULL; - da_ret_t ret = get_extension_from_mime_type(mime_type, &extension); - if (ret == DA_RESULT_OK && extension) - return extension; - } - /* Priority 2-1 */ - if (file_name_from_header) { - char *extension = DA_NULL; - DA_SECURE_LOGI("Content-Disposition :[%s]", file_name_from_header); - __divide_file_name_into_pure_name_N_extesion(file_name_from_header, - DA_NULL, &extension); - if (extension) - return extension; - } - /* Priority 2-2 */ - if (url) { - DA_LOGV("Get extension from url"); - da_bool_t b_ret = da_get_extension_name_from_url(url, &extension); - if (b_ret && extension) - return extension; - } - return DA_NULL; -} - -/** Priority for deciding file name - * 1. file name which client set - * 2. 'filename' option on HTTP response header's Content-Disposition field - * 3. requesting URL - * 4. Otherwise, define it as "No name" - */ -da_ret_t __get_candidate_file_name(char *user_file_name, char *url, - char *file_name_from_header, - char **out_pure_file_name, char **out_extension) -{ - da_ret_t ret = DA_RESULT_OK; - - DA_LOGV(""); - - /* Priority 1 */ - if (user_file_name) { - __divide_file_name_into_pure_name_N_extesion( - user_file_name, out_pure_file_name, out_extension); - } - if (*out_pure_file_name) - return ret; - /* Priority 2 */ - if (file_name_from_header) { - DA_SECURE_LOGI("Content-Disposition:[%s]", file_name_from_header); - __divide_file_name_into_pure_name_N_extesion(file_name_from_header, - out_pure_file_name, DA_NULL); - } - if (*out_pure_file_name) - return ret ; - /* Priority 3 */ - if (url) { - DA_LOGV("Get file name from url"); - da_get_file_name_from_url(url, out_pure_file_name); - } - if (*out_pure_file_name) - return ret ; - /* Priority 4 */ - *out_pure_file_name = strdup(NO_NAME_TEMP_STR); - if (*out_pure_file_name == DA_NULL) - ret = DA_ERR_FAIL_TO_MEMALLOC; - return ret; -} - -da_ret_t __decide_file_path(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - char *extension = DA_NULL; - char *file_name = DA_NULL; - char *tmp_file_path = DA_NULL; - char *install_dir = DA_DEFAULT_INSTALL_PATH_FOR_PHONE; - char *user_file_name = DA_NULL; - char *file_name_from_header = DA_NULL; - char *url = DA_NULL; - file_info_t *file_info = DA_NULL; - req_info_t *req_info = DA_NULL; - http_info_t *http_info = DA_NULL; - - DA_LOGV(""); - - NULL_CHECK_RET(da_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - - if (req_info->install_path) - install_dir = req_info->install_path; - user_file_name = req_info->file_name; - /* If there is location url from response header in case of redirection, - * it try to parse the file name from the location url */ - if (http_info->location_url) { - url = http_info->location_url; - DA_LOGI("[TEST] location_url[%s][%p]",http_info->location_url, http_info->location_url); - } else - url = req_info->url; - - file_name_from_header = http_info->file_name_from_header; - - /* extension is extracted only if User set specific name */ - ret = __get_candidate_file_name(user_file_name, url, file_name_from_header, - &file_name, &extension); - if (ret != DA_RESULT_OK) - goto ERR; - - if (file_name && strpbrk(file_name, DA_INVALID_PATH_STRING) != NULL) { - DA_LOGI("Invalid string at file name"); - free(file_name); - file_name = strdup(NO_NAME_TEMP_STR); - if (!file_name) { - ret = DA_ERR_FAIL_TO_MEMALLOC; - goto ERR; - } - - } - - DA_SECURE_LOGI("candidate file name [%s]", file_name); - - if (!extension) { - extension = __get_extension_name(file_info->mime_type, - file_name_from_header, url); - } - if (file_name && !file_info->pure_file_name) { - file_info->pure_file_name = file_name; - file_name = DA_NULL; - } - if (extension && !file_info->extension) { - DA_LOGV("candidate extension [%s]", extension); - file_info->extension = extension; - extension = DA_NULL; - } - - // for resume - tmp_file_path = get_full_path_avoided_duplication(install_dir, - file_info->pure_file_name, file_info->extension); - if (tmp_file_path) { - file_info->file_path = tmp_file_path; - tmp_file_path = DA_NULL; - } else { - ret = DA_ERR_FAIL_TO_ACCESS_FILE; - goto ERR; - } - -ERR: - DA_SECURE_LOGI("decided file path [%s]", file_info->file_path); - free(file_name); - free(extension); - return ret; -} - -// for resume with new download request -da_ret_t __decide_file_path_for_resume(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - char *extension = DA_NULL; - char *file_name = DA_NULL; - char *file_path = DA_NULL; - char *ptr = DA_NULL; - char *ptr2 = DA_NULL; - - DA_LOGV(""); - - NULL_CHECK_RET(file_info); - - file_path = file_info->file_path; - ptr = strrchr(file_path, '/'); - if (ptr) { - ptr++; - ptr2 = strrchr(ptr, '.'); - if (ptr2) { - int len = 0; - len = ptr2 - ptr; - ptr2++; - extension = strdup(ptr2); - file_name = calloc(1, len + 1); - if (file_name) - snprintf(file_name, len + 1, "%s", ptr); - } else { - file_name = strdup(ptr); - } - } - - if (file_name && !file_info->pure_file_name) { - file_info->pure_file_name = file_name; - file_name = DA_NULL; - } else { - free(file_name); - } - if (extension && !file_info->extension) { - DA_LOGV( "candidate extension [%s]", extension); - file_info->extension = extension; - extension = DA_NULL; - } else { - free(extension); - } - return ret; -} - -da_ret_t start_file_writing(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - file_info_t *file_info = DA_NULL; - req_info_t *req_info = DA_NULL; - - DA_LOGV(""); - - NULL_CHECK_RET(da_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - - /* resume case */ - if (req_info->etag || req_info->temp_file_path) { - char *file_path = DA_NULL; - char *origin_path = DA_NULL; - file_path = req_info->temp_file_path; - if (!file_path) - return DA_ERR_INVALID_ARGUMENT; - origin_path = file_info->file_path; - file_info->file_path = strdup(file_path); - free(origin_path); - ret = __decide_file_path_for_resume(file_info); - } else { - ret = __decide_file_path(da_info); - } - - if (ret != DA_RESULT_OK) - goto ERR; - - if (req_info->etag || req_info->temp_file_path) { - da_size_t file_size = 0; - get_file_size(req_info->temp_file_path, &file_size); - if (file_size < 1) - goto ERR; -#ifdef _RAF_SUPPORT - file_info->file_size_of_temp_file = file_size; -#endif - file_info->bytes_written_to_file = file_size; - } else { - file_info->bytes_written_to_file = 0; - } - ret = __saved_file_open(file_info); -ERR: - return ret; -} - -da_ret_t start_file_append(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - - DA_LOGV(""); - - NULL_CHECK_RET(file_info); - - ret = __saved_file_open(file_info); - return ret; -} - -da_ret_t file_write_ongoing(file_info_t *file_info, char *body, int body_len) -{ - da_ret_t ret = DA_RESULT_OK; - int buffer_size = 0; - char *buffer = DA_NULL; - - DA_LOGV(""); - - buffer = file_info->buffer; - buffer_size = file_info->buffer_len; - - if (DA_NULL == buffer) { - if (body_len < DA_FILE_BUF_SIZE) { - ret = __file_write_buf_make_buf(file_info); - if (ret != DA_RESULT_OK) - goto ERR; - __file_write_buf_copy_to_buf(file_info, body, body_len); - } else { - ret = __file_write_buf_directly_write(file_info, - body, body_len); - if (ret != DA_RESULT_OK) - goto ERR; - } - } else { - if (DA_FILE_BUF_SIZE <= body_len) { - ret = __file_write_buf_flush_buf(file_info); - if (ret != DA_RESULT_OK) - goto ERR; - ret = __file_write_buf_directly_write(file_info, - body, body_len); - if (ret != DA_RESULT_OK) - goto ERR; - } else if ((DA_FILE_BUF_SIZE - buffer_size) <= body_len) { - ret = __file_write_buf_flush_buf(file_info); - if (ret != DA_RESULT_OK) - goto ERR; - __file_write_buf_copy_to_buf(file_info, body, body_len); - } else { - __file_write_buf_copy_to_buf(file_info, body, body_len); - } - } -ERR: - if (ret != DA_RESULT_OK) { - file_info->buffer_len = 0; - free(file_info->buffer); - file_info->buffer = DA_NULL; - } - return ret; -} - -#ifdef _RAF_SUPPORT -da_ret_t file_write_complete_for_raf(file_info_t *file_info) { - da_ret_t ret = DA_RESULT_OK; - char *buffer = DA_NULL; - da_size_t wrriten_size = 0; - da_size_t file_size = 0; - void *fd = DA_NULL; - - DA_LOGV(""); - fd = file_info->file_handle; - - wrriten_size = file_info->bytes_written_to_file; - // test code - get_file_size(file_info->file_path, &file_size); - DA_LOGI("wrriten_size:%llu file_size:%llu file[%s]", - wrriten_size, file_size, file_info->file_path); - if (fd) { - fclose(fd); - fd = DA_NULL; - } - file_info->file_handle = DA_NULL; - if (wrriten_size < file_size) { - DA_LOGD("Try truncate"); - if (truncate(file_info->file_path, wrriten_size) < 0) { - DA_LOGE("Fail to ftruncate: errno[%d,%s]", errno, strerror(errno)); - } - DA_LOGD("Try truncate done"); - } - - ERR: - return ret; -} -#endif - -da_ret_t file_write_complete(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - char *buffer = DA_NULL; - unsigned int buffer_size = 0; - void *fd = DA_NULL; - - DA_LOGV(""); - - buffer = file_info->buffer; - buffer_size = file_info->buffer_len; - - if (DA_NULL == buffer) { - DA_LOGE("file buffer is NULL"); - } else { - if (buffer_size != 0) { - ret = __file_write_buf_flush_buf(file_info); - if (ret != DA_RESULT_OK) - goto ERR; - } - __file_write_buf_destroy_buf(file_info); - } - fd = file_info->file_handle; - - if (fd) { - fclose(fd); - fd = DA_NULL; - } - file_info->file_handle = DA_NULL; -ERR: - return ret; -} - -da_ret_t discard_download(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - FILE *f_handle = DA_NULL; - - DA_LOGV(""); - - f_handle = file_info->file_handle; - if (f_handle) { - fclose(f_handle); - file_info->file_handle = DA_NULL; - } - return ret; -} - -void clean_paused_file(file_info_t *file_info) -{ - char *paused_file_path = DA_NULL; - FILE *fd = DA_NULL; - - DA_LOGV(""); - - fd = file_info->file_handle; - if (fd) { - fclose(fd); - file_info->file_handle = DA_NULL; - } - - paused_file_path = file_info->file_path; - file_info->bytes_written_to_file = 0; // Ignore resume flow after failed or cancled. - remove_file((const char*) paused_file_path); - - return; -} - -da_bool_t is_file_exist(const char *file_path) -{ - struct stat dir_state; - int stat_ret; - - if (file_path == DA_NULL) { - DA_LOGE("file path is DA_NULL"); - return DA_FALSE; - } - stat_ret = stat(file_path, &dir_state); - if (stat_ret == 0) { - if (dir_state.st_mode & S_IFREG) { - //DA_SECURE_LOGD("Exist! %s is a regular file & its size = %lu", file_path, dir_state.st_size); - return DA_TRUE; - } - - return DA_FALSE; - } - return DA_FALSE; - -} - -void get_file_size(char *file_path, da_size_t *out_file_size) -{ - struct stat dir_state; - int stat_ret; - - *out_file_size = -1; - - if (file_path == DA_NULL) { - DA_LOGE("file path is DA_NULL"); - return; - } - /* Please do not use ftell() to obtain file size, use stat instead. - * This is a guide from www.securecoding.cert.org - * : FIO19-C. Do not use fseek() and ftell() to compute the size of a file - */ - stat_ret = stat(file_path, &dir_state); - if (stat_ret == 0) { - if (dir_state.st_mode & S_IFREG) { - DA_LOGV( "size = %lu", dir_state.st_size); - *out_file_size = dir_state.st_size; - } - } - return; -} - -char *get_full_path_avoided_duplication(char *in_dir, - char *in_candidate_file_name, char *in_extension) -{ - char *dir = in_dir; - char *file_name = in_candidate_file_name; - char *extension = in_extension; - char *final_path = DA_NULL; - - int dir_path_len = 0; - int final_path_len = 0; - int extension_len = 0; - - int suffix_count = 0; /* means suffix on file name. up to "_99" */ - int suffix_len = (int)log10(MAX_SUFFIX_COUNT + 1) + 1; /* 1 means "_" */ - - if (!in_dir || !in_candidate_file_name) - return DA_NULL; - - //DA_SECURE_LOGI("in_candidate_file_name=[%s],in_extension=[%s]", - //in_candidate_file_name, in_extension); - - if (extension) - extension_len = strlen(extension); - - // to remove trailing slash from dir path - dir_path_len = strlen(dir); - if (dir[dir_path_len - 1] == '/') { - dir[dir_path_len - 1] = '\0'; - --dir_path_len; - } - - /* first 1 for "/", second 1 for ".", last 1 for DA_NULL */ - final_path_len = dir_path_len + 1 + strlen(file_name) + 1 - + suffix_len + extension_len + 1; - - final_path = (char*)calloc(1, final_path_len); - if (!final_path) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - return DA_NULL; - } - - do { - /* e.g) /tmp/abc.jpg - * if there is no extension name, just make a file name without extension */ - if (0 == extension_len) { - if (suffix_count == 0) { - snprintf(final_path, final_path_len, - "%s/%s", dir, file_name); - } else { - snprintf(final_path, final_path_len, - "%s/%s_%d", dir, file_name, suffix_count); - } - } else { - if (suffix_count == 0) { - snprintf(final_path, final_path_len, - "%s/%s.%s", dir, file_name, extension); - } else { - snprintf(final_path, final_path_len, - "%s/%s_%d.%s", - dir, file_name, suffix_count, extension); - } - } - if (is_file_exist(final_path)) { - suffix_count++; - if (suffix_count > MAX_SUFFIX_COUNT) { - free(final_path); - final_path = DA_NULL; - break; - } else { - memset(final_path, 0x00, final_path_len); - continue; - } - } - break; - } while (1); - - //DA_SECURE_LOGD("decided path = [%s]", final_path); - return final_path; -} - - -da_ret_t check_drm_convert(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - da_bool_t ret_b = DA_TRUE; - - DA_LOGD(""); - - NULL_CHECK_RET(file_info); - -#ifdef _ENABLE_OMA_DRM - - /* In case of OMA DRM 1.0 SD, it is not necessary to call DRM convert API. - * Because it is already converted itself. - * And, the case will return fail because The SD is not supported now. - */ - if (is_content_drm_dcf(file_info->mime_type)) { - DA_LOGI("DRM SD case"); - unlink(file_info->file_path); - free(file_info->file_path); - file_info->file_path = DA_NULL; - return DA_ERR_DRM_FAIL; - } - if (is_content_drm_dm(file_info->mime_type)) { - char *actual_file_path = DA_NULL; - char *out_file_path = DA_NULL; - - actual_file_path = file_info->file_path; - DA_SECURE_LOGD("actual_file_path = %s", actual_file_path); - if (!actual_file_path) - return DA_ERR_INVALID_ARGUMENT; - ret_b = EDRM_convert(actual_file_path, &out_file_path); - unlink(actual_file_path); - free(actual_file_path); - if (!ret_b) - ret = DA_ERR_DRM_FAIL; - file_info->file_path = out_file_path; - } else { - return ret; - } -#endif - - return ret; -} - -void remove_file(const char *file_path) -{ - DA_LOGV(""); - - if (file_path && is_file_exist(file_path)) { - DA_SECURE_LOGD("remove file [%s]", file_path); - if (unlink(file_path) < 0) { - DA_LOGE("file removing failed."); - } - } -} - -da_ret_t get_available_memory(char *dir_path, da_size_t len) -{ - da_ret_t ret = DA_RESULT_OK; - int fs_ret = 0; - //struct statfs filesys_info = {0, }; - struct statvfs filesys_info; - - DA_LOGV(""); - - if (!dir_path) - return DA_ERR_INVALID_INSTALL_PATH; - - //fs_ret = statfs(dir_path, &filesys_info); - // Using this as it considers FOTA memory while returning available memory - fs_ret = storage_get_internal_memory_size(&filesys_info); - - if (fs_ret != 0) { - // DA_LOGE("statfs error[%s]", strerror(errno)); - return DA_ERR_INVALID_ARGUMENT; - // return DA_ERR_INVALID_INSTALL_PATH; - } - - double available_size = (double)filesys_info.f_bsize * filesys_info.f_bavail; - double total_size = (double)filesys_info.f_frsize * filesys_info.f_blocks; - DA_SECURE_LOGI(" total = %lf ", total_size); - DA_SECURE_LOGI(" available = %lf ",available_size); - - DA_LOGV("Available Memory(f_bavail) : %lu", filesys_info.f_bavail); - DA_LOGV("Available Memory(f_bsize) : %d", filesys_info.f_bsize); - DA_LOGD("Available Memory(kbytes) : %d", (filesys_info.f_bavail/1024)*filesys_info.f_bsize); - DA_LOGV("Content: %llu", len); - if (available_size < (len - + SAVE_FILE_BUFFERING_SIZE_50KB)) /* 50KB buffering */ - ret = DA_ERR_DISK_FULL; - - return ret; -} diff --git a/agent/download-agent-http-mgr.c b/agent/download-agent-http-mgr.c deleted file mode 100755 index 3a2feb9..0000000 --- a/agent/download-agent-http-mgr.c +++ /dev/null @@ -1,1519 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <time.h> - -#include "download-agent-dl-info.h" -#include "download-agent-file.h" -#include "download-agent-mime-util.h" -#include "download-agent-client-mgr.h" -#include "download-agent-http-msg-handler.h" -#include "download-agent-plugin-conf.h" -#include "download-agent-plugin-drm.h" -#include "download-agent-plugin-libcurl.h" - -void __http_update_cb(http_raw_data_t *data, void *user_param); - -#define CONVERT_STR(NAME) (#NAME) - -static const char *__get_state_str(http_state_t state) -{ - char *str = NULL; - switch(state) { - case HTTP_STATE_READY_TO_DOWNLOAD: - str = CONVERT_STR(HTTP_STATE_READY_TO_DOWNLOAD); - break; - case HTTP_STATE_REDIRECTED: - str = CONVERT_STR(HTTP_STATE_REDIRECTED); - break; - case HTTP_STATE_DOWNLOAD_REQUESTED: - str = CONVERT_STR(HTTP_STATE_DOWNLOAD_REQUESTED); - break; - case HTTP_STATE_DOWNLOAD_STARTED: - str = CONVERT_STR(HTTP_STATE_DOWNLOAD_STARTED); - break; - case HTTP_STATE_DOWNLOADING: - str = CONVERT_STR(HTTP_STATE_DOWNLOADING); - break; - case HTTP_STATE_DOWNLOAD_FINISH: - str = CONVERT_STR(HTTP_STATE_DOWNLOAD_FINISH); - break; - case HTTP_STATE_REQUEST_CANCEL: - str = CONVERT_STR(HTTP_STATE_REQUEST_CANCEL); - break; - case HTTP_STATE_REQUEST_PAUSE: - str = CONVERT_STR(HTTP_STATE_REQUEST_PAUSE); - break; - case HTTP_STATE_REQUEST_RESUME: - str = CONVERT_STR(HTTP_STATE_REQUEST_RESUME); - break; - case HTTP_STATE_CANCELED: - str = CONVERT_STR(HTTP_STATE_CANCELED); - break; - case HTTP_STATE_FAILED: - str = CONVERT_STR(HTTP_STATE_FAILED); - break; - case HTTP_STATE_PAUSED: - str = CONVERT_STR(HTTP_STATE_PAUSED); - break; - case HTTP_STATE_RESUMED: - str = CONVERT_STR(HTTP_STATE_RESUMED); - break; - case HTTP_STATE_ABORTED: - str = CONVERT_STR(HTTP_STATE_ABORTED); - break; - case HTTP_STATE_WAIT_FOR_NET_ERR: - str = CONVERT_STR(HTTP_STATE_WAIT_FOR_NET_ERR); - break; - default: - str = "Unknown State"; - break; - } - return str; -} - -void __init_http_info(http_info_t *http_info) -{ - DA_LOGV(""); - - http_info->state = HTTP_STATE_READY_TO_DOWNLOAD; - http_info->update_cb = __http_update_cb; - DA_MUTEX_INIT(&(http_info->mutex_state), DA_NULL); - DA_MUTEX_INIT(&(http_info->mutex_http), DA_NULL); - DA_COND_INIT(&(http_info->cond_http), DA_NULL); -} - -void __parsing_user_request_header(char *user_request_header, - char **out_field, char **out_value) -{ - int len = 0; - char *pos = NULL; - char *temp_pos = NULL; - char *field = NULL; - char *value = NULL; - - DA_LOGV(""); - - if (!user_request_header) { - DA_LOGE("NULL CHECK!: user_request_header"); - goto ERR; - } - - pos = strchr(user_request_header, ':'); - if (!pos) { - DA_LOGE("Fail to parse"); - goto ERR; - } - temp_pos = (char *)user_request_header; - while (*temp_pos) - { - if (temp_pos == pos || *temp_pos == ' ') { - len = temp_pos - user_request_header; - break; - } - temp_pos++; - } - if (len < 1) { - DA_LOGE("Wrong field name"); - goto ERR; - } - field = (char *)calloc(1, len + 1); - if (!field) { - DA_LOGE("Fail to calloc"); - goto ERR; - } - strncpy(field, user_request_header, len); - pos++; - while (*pos) - { - if (*pos != ' ') - break; - pos++; - } - len = strlen(pos) + 1; - value = (char *)calloc(1, len + 1); - if (!value) { - DA_LOGE("Fail to calloc"); - goto ERR; - } - strncpy(value, pos, len); - *out_field = field; - *out_value = value; - DA_SECURE_LOGD("field[%s], value[%s]", field, value); - - return; -ERR: - if (field) { - free(field); - field = NULL; - } - return; -} - - -da_ret_t __set_http_request_hdr(req_info_t *req_info, http_info_t *http_info, file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_msg_request_t *http_msg_request = NULL; - char *user_agent = NULL; - int count = 0; - - DA_LOGV(""); - - NULL_CHECK_RET(req_info); - NULL_CHECK_RET(http_info); - NULL_CHECK_RET(file_info); - NULL_CHECK_RET_OPT(req_info->url, DA_ERR_INVALID_URL); - count = req_info->req_header_count; - - ret = http_msg_request_create(&http_msg_request); - if (ret != DA_RESULT_OK) - goto ERR; - - ret = http_msg_request_set_url(http_msg_request, req_info->url); - if (ret != DA_RESULT_OK) - goto ERR; - - ret = get_user_agent_string(&user_agent); - if (user_agent && ret == DA_RESULT_OK) - http_msg_request_add_field(http_msg_request, - HTTP_FIELD_UAGENT, user_agent); - - - http_msg_request_add_field(http_msg_request, - HTTP_FIELD_ACCEPT_LANGUAGE, "en"); - http_msg_request_add_field(http_msg_request, - HTTP_FIELD_ACCEPT_CHARSET, "utf-8"); - - if (req_info->req_header && count > 0) { - int i = 0; - for (i = 0; i < count; i++) { - char *field = NULL; - char *value = NULL; - __parsing_user_request_header(req_info->req_header[i], - &field, &value); - if (field && value) { - http_msg_request_add_field(http_msg_request, field, value); - if (field) { - free(field); - field = NULL; - } - if (value) { - free(value); - value= NULL; - } - } else { - if (field) { - free(field); - field = NULL; - } - if (value) { - free(value); - value= NULL; - } - DA_LOGE("Fail to parse user request header"); - } - } - } - if (req_info->etag) { - char buff[64] = {0,}; - da_size_t size = 0; - http_msg_request_add_field(http_msg_request, - HTTP_FIELD_IF_RANGE, req_info->etag); - get_file_size(req_info->temp_file_path, &size); -#ifdef _RAF_SUPPORT - file_info->file_size_of_temp_file = size; -#endif - snprintf(buff, sizeof(buff)-1, "bytes=%llu-", size); - http_msg_request_add_field(http_msg_request, - HTTP_FIELD_RANGE, buff); - } - - http_info->http_msg_request = http_msg_request; - free(user_agent); - return ret; -ERR: - if (http_msg_request) - http_msg_request_destroy(&http_msg_request); - - return ret; - -} - -da_ret_t __create_http_resume_hdr(req_info_t *req_info, http_info_t *http_info, - file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - da_bool_t b_ret = DA_FALSE; - char *value = NULL; - char temp_size_str[32] = { 0, }; - char *etag_from_response = NULL; - char *date_from_response = NULL; - http_msg_response_t *first_response = NULL; - http_msg_request_t *resume_request = NULL; - http_msg_request_t *old_request = NULL; - - DA_LOGV(""); - - first_response = http_info->http_msg_response; - if (first_response) { - b_ret = http_msg_response_get_ETag(first_response, &value); - if (b_ret) { - etag_from_response = value; - value = NULL; - DA_SECURE_LOGD("[ETag][%s]", etag_from_response); - } - b_ret = http_msg_response_get_date(first_response, &value); - if (b_ret) { - date_from_response = value; - value = NULL; - DA_LOGV("[Date][%s]", date_from_response); - } - DA_SECURE_LOGD("downloaded_size[%u]", file_info->bytes_written_to_file); - snprintf(temp_size_str, sizeof(temp_size_str), "bytes=%llu-", - file_info->bytes_written_to_file); - DA_SECURE_LOGD("size str[%s]", temp_size_str); - free(first_response); - http_info->http_msg_response = DA_NULL; - } - old_request = http_info->http_msg_request; - free(old_request); - http_info->http_msg_request = DA_NULL; - - ret = __set_http_request_hdr(req_info, http_info, file_info); - if (ret != DA_RESULT_OK) - goto ERR; - - resume_request = http_info->http_msg_request; - if (etag_from_response) { - http_msg_request_add_field(resume_request, HTTP_FIELD_IF_RANGE, - etag_from_response); - } else { - if (date_from_response) { - http_msg_request_add_field(resume_request, - HTTP_FIELD_IF_RANGE, date_from_response); - } - } - - if (strlen(temp_size_str) > 0) - http_msg_request_add_field(resume_request, HTTP_FIELD_RANGE, - temp_size_str); - -ERR: - if (etag_from_response) { - free(etag_from_response); - etag_from_response = NULL; - } - if (date_from_response) { - free(date_from_response); - date_from_response = NULL; - } - return ret; -} - - -da_ret_t __start_transaction(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_info_t *http_info; - DA_LOGV(""); - - if (!da_info) { - DA_LOGE("NULL CHECK!: da_info"); - return DA_ERR_INVALID_ARGUMENT; - } - http_info = da_info->http_info; - if (!http_info) { - DA_LOGE("NULL CHECK!: http_info"); - return DA_ERR_INVALID_ARGUMENT; - } - http_info->http_method = HTTP_METHOD_GET; - http_info->proxy_addr = get_proxy_address(); - - ret = PI_http_start(da_info); - - return ret; -} - -da_ret_t __start_resume_transaction(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_info_t *http_info = DA_NULL; - file_info_t *file_info = DA_NULL; - req_info_t *req_info = DA_NULL; - - NULL_CHECK_RET(da_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - - ret = __create_http_resume_hdr(req_info, http_info, - file_info); - if (ret != DA_RESULT_OK) - return ret; - - reset_http_info_for_resume(http_info); - if (file_info->file_path) { - req_info->temp_file_path = strdup(file_info->file_path); - } else { - DA_LOGE("file_path cannot be NULL in resume case"); - return DA_ERR_INVALID_ARGUMENT; - } - ret = __start_transaction(da_info); - return ret; -} - - -da_ret_t __start_new_transaction(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - - if (!da_info) { - DA_LOGE("NULL CHECK!: da_info"); - return DA_ERR_INVALID_ARGUMENT; - } - - ret = __set_http_request_hdr(da_info->req_info, da_info->http_info, da_info->file_info); - if (ret != DA_RESULT_OK) - return ret; - - ret = __start_transaction(da_info); - return ret; -} - -int __check_wait_for_auto_retry(http_info_t *http_info) -{ - da_ret_t ret = DA_RESULT_OK; - struct timespec ts; - struct timeval tp; - NULL_CHECK_RET_OPT(http_info, 0); - gettimeofday(&tp, NULL); - ts.tv_sec = tp.tv_sec + DA_MAX_TIME_OUT; - ts.tv_nsec = tp.tv_usec * 1000; - DA_LOGI("Network Fail case, wait for a while"); - - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_WAIT_FOR_NET_ERR; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_MUTEX_LOCK(&(http_info->mutex_http)); - ret = pthread_cond_timedwait(&(http_info->cond_http), - &(http_info->mutex_http), &ts); - DA_MUTEX_UNLOCK(&(http_info->mutex_http)); - if (ret == ETIMEDOUT) { - DA_LOGI("Waiting is done by timeout"); - } else if (ret != 0) { - DA_LOGE("fail to pthread_cond_waittime[%d][%s]",ret, strerror(ret)); - } else { - DA_LOGI("Waiting is done by control"); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - DA_LOGI("http_state[%s]", __get_state_str(http_info->state)); - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - return 1; - } - - return 0; -} - -// In download thread -da_ret_t request_http_download(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - req_info_t *req_info = DA_NULL; - http_info_t *http_info = DA_NULL; - http_state_t http_state = 0; - da_bool_t need_wait = DA_TRUE; - - DA_LOGV(""); - - NULL_CHECK_RET(da_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - __init_http_info(http_info); - - do { - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGD("http_state[%s][%d]",__get_state_str(http_info->state), da_info->da_id); - switch (http_state) { - case HTTP_STATE_READY_TO_DOWNLOAD: - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOAD_REQUESTED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - ret = __start_new_transaction(da_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_LOGD("http_state[%s][%d]",__get_state_str(http_info->state), da_info->da_id); - http_info->error_code = ret; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - if (ret == DA_ERR_NETWORK_FAIL && http_state != HTTP_STATE_PAUSED) { - DA_LOGE("Network failed"); - if (__check_wait_for_auto_retry(http_info) == 1) - need_wait = DA_TRUE; - else - need_wait = DA_FALSE; - } - break; - case HTTP_STATE_REDIRECTED: - case HTTP_STATE_DOWNLOAD_REQUESTED: - case HTTP_STATE_DOWNLOAD_STARTED: - case HTTP_STATE_DOWNLOADING: - case HTTP_STATE_REQUEST_PAUSE: - DA_LOGE("Cannot enter here:[%s][id]", - __get_state_str(http_info->state), da_info->da_id); - break; - case HTTP_STATE_REQUEST_CANCEL: - break; - case HTTP_STATE_REQUEST_RESUME: - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_READY_TO_DOWNLOAD; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - need_wait = DA_TRUE; - break; - case HTTP_STATE_CANCELED: - need_wait = DA_FALSE; - ret = DA_RESULT_USER_CANCELED; - break; - case HTTP_STATE_PAUSED: - DA_LOGD("error_code[%d]", http_info->error_code); - send_client_paused_info(da_info); - DA_LOGD("Waiting thread for paused state"); - DA_MUTEX_LOCK(&(http_info->mutex_http)); - pthread_cond_wait(&(http_info->cond_http),&(http_info->mutex_http)); - DA_MUTEX_UNLOCK(&(http_info->mutex_http)); - DA_LOGD("Wake up thread due to resume"); - break; - case HTTP_STATE_RESUMED: - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOAD_REQUESTED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - ret = __start_resume_transaction(da_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - if (ret == DA_ERR_NETWORK_FAIL && http_state != HTTP_STATE_PAUSED) { - DA_LOGE("Network failed"); - if (__check_wait_for_auto_retry(http_info) == 1) - need_wait = DA_TRUE; - else - need_wait = DA_FALSE; - } - break; - case HTTP_STATE_DOWNLOAD_FINISH: - need_wait = DA_FALSE; - if (ret == DA_RESULT_OK) - ret = check_drm_convert(da_info->file_info); - break; - case HTTP_STATE_FAILED: - if (ret == DA_ERR_NETWORK_FAIL) { - if (__check_wait_for_auto_retry(http_info) == 1) - need_wait = DA_TRUE; - else - need_wait = DA_FALSE; - } else { - need_wait = DA_FALSE; - } - break; - case HTTP_STATE_ABORTED: - need_wait = DA_FALSE; - break; - default: - break; - } - } while (need_wait == DA_TRUE); - DA_LOGD("Final http_state[%s][%d] err[%d]",__get_state_str(http_info->state), da_info->da_id, ret); - if (http_info->state != HTTP_STATE_PAUSED) - send_client_finished_info(da_info ,ret); - DA_LOGI("=== Exiting http_download ret[%d] ===", ret); - return ret; -} - -da_ret_t __disconnect_transaction(http_info_t *http_info) -{ - da_ret_t ret = DA_RESULT_OK; - DA_LOGD(""); - ret = PI_http_disconnect(http_info); - return ret; -} - -da_ret_t __handle_event_abort(http_info_t *http_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_state_t state = 0; - - DA_LOGD(""); - - DA_MUTEX_LOCK(&(http_info->mutex_state)); - state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGV("http_state[%s]", __get_state_str(state)); - - switch (state) { - case HTTP_STATE_READY_TO_DOWNLOAD: - case HTTP_STATE_REDIRECTED: - case HTTP_STATE_DOWNLOAD_REQUESTED: - case HTTP_STATE_DOWNLOAD_STARTED: - case HTTP_STATE_DOWNLOADING: - case HTTP_STATE_REQUEST_CANCEL: - case HTTP_STATE_REQUEST_PAUSE: - case HTTP_STATE_REQUEST_RESUME: - case HTTP_STATE_CANCELED: - case HTTP_STATE_PAUSED: - case HTTP_STATE_RESUMED: - case HTTP_STATE_ABORTED: - case HTTP_STATE_WAIT_FOR_NET_ERR: - /* IF the network session is terminated due to some error, - * the state can be aborted.(data aborted case) */ - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_ABORTED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - __disconnect_transaction(http_info); - break; - case HTTP_STATE_DOWNLOAD_FINISH: - break; - default: - DA_LOGE("Cannot enter here"); - break; - } - return ret; -} - -da_ret_t __check_enough_memory(http_info_t *http_info, char *user_install_path) -{ - da_ret_t ret = DA_RESULT_OK; - da_size_t cont_len = 0; - char *dir_path = DA_DEFAULT_INSTALL_PATH_FOR_PHONE; - - DA_LOGV(""); - NULL_CHECK_RET(http_info); - cont_len = http_info->content_len_from_header; - if (cont_len > 0) { - if (user_install_path) - dir_path = user_install_path; - ret = get_available_memory(dir_path, cont_len); - } - return ret; -} - -da_ret_t request_to_abort_http_download(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - ret = __handle_event_abort(da_info->http_info); - return ret; -} - -da_ret_t request_to_cancel_http_download(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_info_t *http_info = DA_NULL; - http_state_t http_state = 0; - DA_LOGV(""); - - NULL_CHECK_RET(da_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGD("http_state[%s]", __get_state_str(http_state)); - switch (http_state) { - case HTTP_STATE_READY_TO_DOWNLOAD: - ret = PI_http_cancel(http_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_CANCELED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - if (da_info->thread_id > 0) { - if (pthread_cancel(da_info->thread_id) != 0) { - DA_LOGE("Fail to cancel thread id[%d] err[%s]", - da_info->thread_id, strerror(errno)); - } else { - DA_LOGI("====Exit thread with cancel:da_id[%d]===", - da_info->da_id); - } - } - break; - case HTTP_STATE_WAIT_FOR_NET_ERR: - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_CANCELED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_MUTEX_LOCK(&(http_info->mutex_http)); - DA_COND_SIGNAL(&(http_info->cond_http)); - DA_MUTEX_UNLOCK(&(http_info->mutex_http)); - break; - case HTTP_STATE_PAUSED: - reset_http_info(http_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_CANCELED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - break; - case HTTP_STATE_DOWNLOAD_REQUESTED: - case HTTP_STATE_DOWNLOAD_STARTED: - case HTTP_STATE_DOWNLOADING: - case HTTP_STATE_REQUEST_RESUME: - case HTTP_STATE_RESUMED: - ret = PI_http_cancel(http_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_REQUEST_CANCEL; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - break; - case HTTP_STATE_DOWNLOAD_FINISH: - ret = DA_ERR_INVALID_STATE; - break; - case HTTP_STATE_REQUEST_CANCEL: - DA_LOGV("cancel is already in progress... "); - ret = DA_ERR_INVALID_STATE; - break; - default: - ret = DA_ERR_INVALID_STATE; - DA_LOGE("Cannot enter here"); - break; - } - return ret; -} - -da_ret_t request_to_suspend_http_download(da_info_t *da_info) -{ - - da_ret_t ret = DA_RESULT_OK; - http_info_t *http_info = DA_NULL; - http_state_t http_state = 0; - - DA_LOGV(""); - - NULL_CHECK_RET(da_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGD("http_state[%s]", __get_state_str(http_state)); - - switch (http_state) { - case HTTP_STATE_PAUSED: - case HTTP_STATE_REQUEST_PAUSE: - DA_LOGI("Already paused. http_state[%s]", __get_state_str(http_state)); - ret = DA_ERR_ALREADY_SUSPENDED; - break; - case HTTP_STATE_READY_TO_DOWNLOAD: - DA_LOGE("Download has not been started yet"); - ret = DA_ERR_INVALID_STATE; - break; - case HTTP_STATE_WAIT_FOR_NET_ERR: - DA_LOGD("error_code[%d]", http_info->error_code); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_PAUSED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_MUTEX_LOCK(&(http_info->mutex_http)); - DA_COND_SIGNAL(&(http_info->cond_http)); - DA_MUTEX_UNLOCK(&(http_info->mutex_http)); - break; - default: - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_REQUEST_PAUSE; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGD("error_code[%d]", http_info->error_code); - if (http_info->error_code != DA_ERR_NETWORK_FAIL) - ret = PI_http_pause(http_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_PAUSED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - - break; - } - return ret; -} - -da_ret_t request_to_resume_http_download(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_info_t *http_info = DA_NULL; - http_state_t http_state = 0; - int retry_count = 0; - - DA_LOGV(""); - - NULL_CHECK_RET(da_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGD("http_state[%s]", __get_state_str(http_state)); - - switch (http_state) { - case HTTP_STATE_PAUSED: - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_RESUMED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGD("Wake up thread for paused state"); - DA_MUTEX_LOCK(&(http_info->mutex_http)); - DA_COND_SIGNAL(&(http_info->cond_http)); - DA_MUTEX_UNLOCK(&(http_info->mutex_http)); - DA_LOGD("error_code[%d]", http_info->error_code); - if (http_info->error_code != DA_ERR_NETWORK_FAIL) { - ret = PI_http_unpause(http_info); - if (ret != DA_RESULT_OK) - PI_http_cancel(http_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOADING; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - - } - break; - case HTTP_STATE_REQUEST_PAUSE: - DA_LOGD("Waiting to handle pause request"); - do { - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - if (http_state == HTTP_STATE_PAUSED) { - DA_LOGD("Change to paused state"); - ret = PI_http_unpause(http_info); - break; - } - retry_count++; - } while(retry_count < 10000); - if (ret != DA_RESULT_OK || retry_count >= 10000) - PI_http_cancel(http_info); - break; - case HTTP_STATE_RESUMED: - ret = DA_ERR_ALREADY_RESUMED; - break; - default: - DA_LOGE("Fail to resume. Invalid state check. http_state[%s]", - __get_state_str(http_state)); - ret = DA_ERR_INVALID_STATE; - // If resume is failed due to invalid state, the previous pause should be canceled. - PI_http_cancel(http_info); - break; - } - return ret; -} - -da_ret_t __check_resume_download_is_available( - req_info_t *req_info, http_info_t *http_info, file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - da_bool_t b_ret = DA_FALSE; - char *origin_ETag = NULL; - char *new_ETag = NULL; - da_size_t remained_content_len = 0; - char *value = NULL; - da_size_t size = 0; - char *temp_file_path = DA_NULL; - char *dir_path = DA_DEFAULT_INSTALL_PATH_FOR_PHONE; - - DA_LOGV(""); - - origin_ETag = req_info->etag; - - b_ret = http_msg_response_get_content_length(http_info->http_msg_response, - &size); - if (b_ret) { - remained_content_len = size; - size = 0; - DA_SECURE_LOGD("remained_content_len[%llu]", remained_content_len); - } - - b_ret = http_msg_response_get_ETag(http_info->http_msg_response, &value); - if (b_ret) { - new_ETag = value; - value = NULL; - DA_SECURE_LOGD("new ETag[%s]", new_ETag); - } else { - goto ERR; - } - - if (origin_ETag && new_ETag && - 0 != strncmp(origin_ETag, new_ETag, strlen(new_ETag))) { - DA_LOGE("ETag is not identical! revoke!"); - /* FIXME Later : Need to detail error exception handling */ - ret = DA_ERR_NETWORK_FAIL; - /*ret = DA_ERR_MISMATCH_HTTP_HEADER; */ - goto ERR; - } - - if (remained_content_len > 0) { - if (req_info->install_path) - dir_path = req_info->install_path; - ret = get_available_memory(dir_path, remained_content_len); - if (ret != DA_RESULT_OK) - goto ERR; - } - - if (!http_info->content_type_from_header) { - b_ret = http_msg_response_get_content_type(http_info->http_msg_response, - &value); - if (b_ret) { - http_info->content_type_from_header = value; - value = NULL; - DA_SECURE_LOGD("Content-Type[%s]", - http_info->content_type_from_header); - } - } - temp_file_path = req_info->temp_file_path; - if (!temp_file_path) { - DA_LOGE("Temporary file path cannot be NULL"); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } - get_file_size(temp_file_path, &size); - http_info->content_len_from_header = remained_content_len + size; - DA_SECURE_LOGD("Content-Length[%llu]", http_info->content_len_from_header); -ERR: - if (new_ETag) { - free(new_ETag); - new_ETag = DA_NULL; - } - return ret; -} - - -da_ret_t __check_content_type_is_matched(http_info_t *http_info) -{ - da_ret_t ret = DA_RESULT_OK; - char *content_type_from_server = DA_NULL; - - DA_LOGV(""); - - content_type_from_server = http_info->content_type_from_header; - if (content_type_from_server == DA_NULL) { - DA_LOGV("http header has no Content-Type field, no need to compare"); - return DA_RESULT_OK; - } - return ret; -} - -da_ret_t __handle_http_status_code(http_info_t *http_info, - file_info_t *file_info, req_info_t *req_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_state_t http_state = 0; - http_msg_response_t *http_msg_response = DA_NULL; - char *location = DA_NULL; - char *if_range_str = DA_NULL; - char *range_str = DA_NULL; - int http_status = 0; - - NULL_CHECK_RET(http_info); - NULL_CHECK_RET(file_info); - NULL_CHECK_RET(req_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGD("http_state[%s]", __get_state_str(http_state)); - http_msg_response = http_info->http_msg_response; - NULL_CHECK_RET(http_msg_response); - http_status = http_msg_response->status_code; - switch (http_status) { - case 200: - case 201: - case 202: - case 203: -// Although expecting 206, 200 response is received. Remove temporary file and reset file info - if (http_info->http_msg_request && - http_msg_request_get_if_range(http_info->http_msg_request, &if_range_str) == DA_TRUE && - http_msg_request_get_range(http_info->http_msg_request, &range_str) == DA_TRUE) { - DA_LOGI("Server do not support if-range option"); - clean_paused_file(file_info); - } - free(if_range_str); - free(range_str); - if (http_state == HTTP_STATE_REQUEST_RESUME) - clean_paused_file(file_info); - ret = __check_content_type_is_matched(http_info); - if (ret != DA_RESULT_OK) - goto ERR; - ret = __check_enough_memory(http_info, req_info->install_path); - if (ret != DA_RESULT_OK) - goto ERR; - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOAD_STARTED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - break; - - case 206: - DA_LOGV("HTTP Status is %d - Partial download for resume!", http_status); - /* The resume can be started with start API. - * So the state should be not HTTP_STATE_RESUME_REQUESTED but HTTP_STATE_DOWNLOAD_REQUESTED*/ - if (http_state == HTTP_STATE_DOWNLOAD_REQUESTED) { - ret = __check_resume_download_is_available(req_info, http_info, file_info); - if (ret != DA_RESULT_OK) - goto ERR; - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOAD_STARTED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - - } else if (http_state == HTTP_STATE_REQUEST_RESUME) { - ///FIXME later : how get previous response header - ///ret = __check_this_partial_download_is_available(http_info, - /// previous_ http_msg_response); - //if (ret != DA_RESULT_OK) - //goto ERR; - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_RESUMED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - } else { - DA_LOGE("This download is not resumed, revoke"); - ret = DA_ERR_INVALID_STATE; - goto ERR; - } - break; - - case 300: - case 301: - case 302: - case 303: - case 305: - case 306: - case 307: - DA_LOGV("HTTP Status is %d - redirection!",http_status); - if (http_msg_response_get_location(http_msg_response, &location)) { - DA_SECURE_LOGD("location = %s\n", location); - http_info->location_url = location; - DA_LOGI("[TEST] location_url[%p]",http_info->location_url); - } - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_REDIRECTED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - http_msg_response_destroy(&http_msg_response); - http_info->http_msg_response = DA_NULL; - break; - - case 100: - case 101: - case 102: - case 204: - case 304: - DA_LOGV("HTTP Status is %d - 204 server got the request, \ - but no content to reply back, \ - 304 means not modified!", http_status); - ret = DA_ERR_SERVER_RESPOND_BUT_SEND_NO_CONTENT; - break; - - case 416: // Requested range not satisfiable - case 503: - case 504: - default: -/// GET_REQUEST_HTTP_RESULT(request_info) -/// = DA_ERR_UNREACHABLE_SERVER; - DA_LOGI("set internal error code : DA_ERR_UNREACHABLE_SERVER"); - break; - } - -ERR: - return ret; -} - -da_ret_t __check_before_downloading(da_info_t *da_info, http_state_t state) -{ - da_ret_t ret = DA_RESULT_OK; - http_info_t *http_info = DA_NULL; - req_info_t *req_info = DA_NULL; - file_info_t *file_info = DA_NULL; - NULL_CHECK_RET(da_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - DA_LOGD("state:%s",__get_state_str(state)); - // resume case - if (req_info->temp_file_path && file_info->bytes_written_to_file > 0) { - ret = start_file_append(file_info); - } else if (state == HTTP_STATE_DOWNLOAD_STARTED) { - ret = start_file_writing(da_info); - } else { - DA_LOGE("Cannot enter here!"); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } - if (DA_RESULT_OK != ret) - goto ERR; - - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOADING; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - - ret = send_client_update_dl_info(da_info); -ERR: - return ret; -} - -da_ret_t __handle_event_http_header(http_raw_data_t *raw_data, da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_state_t http_state = 0; - http_info_t *http_info = DA_NULL; - file_info_t *file_info = DA_NULL; - req_info_t *req_info = DA_NULL; - http_msg_response_t *http_msg_response = DA_NULL; - da_size_t size = 0; - char *mime_type = DA_NULL; - char *etag = DA_NULL; - char *file_name = DA_NULL; - - NULL_CHECK_RET(da_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - req_info = da_info->req_info; - NULL_CHECK_RET(req_info); - NULL_CHECK_RET(raw_data); - - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGV("http_state[%s]", __get_state_str(http_state)); - http_msg_response = http_info->http_msg_response; - switch (http_state) { - case HTTP_STATE_DOWNLOAD_REQUESTED: - case HTTP_STATE_REQUEST_PAUSE: - case HTTP_STATE_REQUEST_RESUME: - case HTTP_STATE_REDIRECTED: - http_msg_response_get_content_length(http_msg_response, &size); - http_info->content_len_from_header = size; - http_msg_response_get_content_type(http_msg_response, &mime_type); - http_info->content_type_from_header = mime_type; - if (mime_type) - file_info->mime_type = strdup(mime_type); - http_msg_response_get_ETag(http_msg_response, &etag); - http_info->etag_from_header = etag; - http_msg_response_get_content_disposition( - http_msg_response, DA_NULL, &file_name); - http_info->file_name_from_header = file_name; - ret = __handle_http_status_code(http_info, file_info, req_info); - if (ret != DA_RESULT_OK) { - DA_LOGE("Fail to handle http status code"); - goto ERR; - } -#ifdef _RAF_SUPPORT - char *val = NULL; - http_msg_response_get_RAF_mode(http_msg_response, &val); - if (!val) { - DA_LOGE("Fail to raf mode value from response header"); - } else { - DA_LOGI("[RAF] val[%s:%s]", HTTP_FIELD_RAF_MODE, val); - if (strncmp(val, "yes", strlen("yes")) == 0) { - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOAD_STARTED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - ret = __check_before_downloading(da_info, http_info->state); - if (ret != DA_RESULT_OK) { - free(val); - goto ERR; - } - http_info->is_raf_mode_confirmed = DA_TRUE; - ret = PI_http_set_file_name_to_curl(http_info->http_msg, file_info->file_path); - if (ret != DA_RESULT_OK) { - DA_LOGE("Fail to set file name to curl"); - free(val); - goto ERR; - } - } - free(val); - } -#endif - break; - case HTTP_STATE_REQUEST_CANCEL: - DA_LOGV("Cancel is in progress.. http_state[%s]", - __get_state_str(http_state)); - break; - - default: - DA_LOGE("http_state[%s]", __get_state_str(http_state)); - goto ERR; - } - -ERR: - if (ret != DA_RESULT_OK) { - DA_LOGE("Request to cancel due to error[%d]", ret); - PI_http_cancel(http_info); - http_info->error_code = ret; - discard_download(file_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_FAILED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - } - free(raw_data); - return ret; -} - -da_ret_t __handle_event_http_packet(http_raw_data_t *raw_data, da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_state_t http_state = 0; - http_info_t *http_info = DA_NULL; - file_info_t *file_info = DA_NULL; - time_t t; - struct tm *lc_time; - DA_LOGV(""); - - NULL_CHECK_RET(da_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - NULL_CHECK_RET(raw_data); - - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - - switch (http_state) { - case HTTP_STATE_DOWNLOAD_STARTED: -#ifdef _RAF_SUPPORT - if (http_info->is_raf_mode_confirmed == DA_FALSE) { -#endif - ret = __check_before_downloading(da_info, http_state); - if (ret != DA_RESULT_OK) - goto ERR; - ret = file_write_ongoing(file_info, - raw_data->body, raw_data->body_len); - if (ret != DA_RESULT_OK) - goto ERR; -#ifdef _RAF_SUPPORT - } else { - file_info->bytes_written_to_file = - raw_data->received_len + file_info->file_size_of_temp_file; - file_info->is_updated = DA_TRUE; - } -#endif - ret = send_client_update_progress_info(da_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = HTTP_STATE_DOWNLOADING; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - break; - case HTTP_STATE_RESUMED: -#ifdef _RAF_SUPPORT - if (http_info->is_raf_mode_confirmed == DA_FALSE) { -#endif - __check_before_downloading(da_info, http_state); - ret = file_write_ongoing(file_info, - raw_data->body, raw_data->body_len); - if (ret != DA_RESULT_OK) - goto ERR; -#ifdef _RAF_SUPPORT - } else { - file_info->bytes_written_to_file = - raw_data->received_len + file_info->file_size_of_temp_file; - file_info->is_updated = DA_TRUE; - } -#endif - ret = send_client_update_progress_info(da_info); - break; - case HTTP_STATE_REDIRECTED: - DA_LOGV("http_state[%s]", __get_state_str(http_state)); - break; - case HTTP_STATE_DOWNLOADING: -#ifdef _RAF_SUPPORT - if (http_info->is_raf_mode_confirmed == DA_FALSE) { -#endif - /* Should this function before updating download info - * Because it extract mime type at once only if first download updating at client */ - ret = file_write_ongoing(file_info, - raw_data->body, raw_data->body_len); - if (ret != DA_RESULT_OK) - goto ERR; -#ifdef _RAF_SUPPORT - } else { - file_info->bytes_written_to_file = - raw_data->received_len + file_info->file_size_of_temp_file; - file_info->is_updated = DA_TRUE; - } -#endif - // send event every 1 second. - if ((t = time(DA_NULL)) > 0) { - if ((lc_time = localtime(&t)) != DA_NULL) { - if (da_info->update_time != lc_time->tm_sec) { - da_info->update_time = lc_time->tm_sec; - ret = send_client_update_progress_info(da_info); - } - } else { - DA_LOGE("Fail to call localtime[%s]",strerror(errno)); - ret = send_client_update_progress_info(da_info); - } - } else { - DA_LOGE("Fail to call time[%s]",strerror(errno)); - ret = send_client_update_progress_info(da_info); - } - break; - case HTTP_STATE_REQUEST_PAUSE: -#ifdef _RAF_SUPPORT - if (http_info->is_raf_mode_confirmed == DA_FALSE) { -#endif - DA_LOGV("http_state[%s]", __get_state_str(http_state)); - ret = file_write_ongoing(file_info, - raw_data->body, raw_data->body_len); - if (ret != DA_RESULT_OK) - goto ERR; -#ifdef _RAF_SUPPORT - } else { - file_info->bytes_written_to_file = - raw_data->received_len + file_info->file_size_of_temp_file; - file_info->is_updated = DA_TRUE; - } -#endif - - break; - default: - DA_LOGE("Do nothing! http_state is in case[%s]", - __get_state_str(http_state)); - goto ERR; - } -ERR: - if (ret != DA_RESULT_OK) { - DA_LOGE("Request to cancel due to error[%d]", ret); - PI_http_cancel(http_info); - http_info->error_code = ret; - discard_download(da_info->file_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_FAILED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - } - if (raw_data->body) - free(raw_data->body); - free(raw_data); - return ret; -} - -da_ret_t __check_file_size_with_header_content_size(file_info_t *file_info) -{ - da_ret_t ret = DA_RESULT_OK; - unsigned long long tmp_file_size = 0; - - DA_LOGV(""); - - if (file_info->file_size > 0) { - -#ifdef _ENABLE_OMA_DRM - if (is_content_drm_dm(file_info->mime_type)) { - /* FIXME Later : How can get the file size of DRM file. */ - return ret; - } -#endif - - get_file_size(file_info->file_path, &tmp_file_size); - - if (tmp_file_size != file_info->file_size) { - DA_SECURE_LOGE("Real file size[%llu], MISMATCH CONTENT SIZE", - tmp_file_size); - ret = DA_ERR_MISMATCH_CONTENT_SIZE; - } - } - return ret; -} - -da_ret_t __handle_event_http_final(http_raw_data_t *raw_data, da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_state_t http_state = 0; - http_info_t *http_info = DA_NULL; - file_info_t *file_info = DA_NULL; - - DA_LOGV(""); - - NULL_CHECK_RET(da_info); - http_info = da_info->http_info; - NULL_CHECK_RET(http_info); - file_info = da_info->file_info; - NULL_CHECK_RET(file_info); - NULL_CHECK_RET(raw_data); - - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGD("http_state[%s]", __get_state_str(http_state)); - - switch (http_state) { - case HTTP_STATE_REDIRECTED: - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_READY_TO_DOWNLOAD; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - break; - case HTTP_STATE_DOWNLOAD_REQUESTED: - DA_LOGV("case HTTP_STATE_DOWNLOAD_REQUESTED"); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOAD_FINISH; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - break; - case HTTP_STATE_DOWNLOADING: - DA_LOGD("case HTTP_STATE_DOWNLOADING"); -#ifdef _RAF_SUPPORT - if (http_info->is_raf_mode_confirmed == DA_TRUE) { - ret = file_write_complete_for_raf(file_info); - } else { - ret = file_write_complete(file_info); - } -#else - ret = file_write_complete(file_info); -#endif - if (ret != DA_RESULT_OK) { - discard_download(file_info); - goto ERR; - } - ret = __check_file_size_with_header_content_size(file_info); - if(ret != DA_RESULT_OK) { - discard_download(file_info) ; - goto ERR; - } - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOAD_FINISH; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - ret = send_client_update_progress_info(da_info); - break; - case HTTP_STATE_REQUEST_PAUSE: -#ifdef _RAF_SUPPORT - if (http_info->is_raf_mode_confirmed == DA_TRUE) { - if (file_info->file_handle) - ret = file_write_complete_for_raf(file_info); - } else { - ret = file_write_complete(file_info); - } -#else - if (file_info->file_handle) { - ret = file_write_complete(file_info); -// send_client_update_progress_info(da_info); - } -#endif - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_PAUSED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - DA_LOGV("Server Notification code is set to NULL"); - break; - case HTTP_STATE_ABORTED: - case HTTP_STATE_CANCELED: - discard_download(file_info); - break; - case HTTP_STATE_REQUEST_CANCEL: -#ifdef _RAF_SUPPORT - if (http_info->is_raf_mode_confirmed == DA_TRUE) { - ret = file_write_complete_for_raf(file_info); - } else { - ret = file_write_complete(file_info); - } -#else - ret = file_write_complete(file_info); -#endif - if (ret != DA_RESULT_OK) - goto ERR; - discard_download(file_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_CANCELED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - break; - case HTTP_STATE_PAUSED: - DA_LOGD("Remain paused stated"); - break; - default: -#ifdef _RAF_SUPPORT - if (http_info->is_raf_mode_confirmed == DA_TRUE) { - ret = file_write_complete_for_raf(file_info); - } else { - ret = file_write_complete(file_info); - } -#else - ret = file_write_complete(file_info); -#endif - if (ret != DA_RESULT_OK) - goto ERR; - discard_download(file_info); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_FAILED; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - break; - } - -ERR: - /* When file complete is failed */ - if (DA_RESULT_OK != ret) { - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_info->state = HTTP_STATE_DOWNLOAD_FINISH; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - } - if (raw_data->body) - free(raw_data->body); - free(raw_data); - return ret; -} - -void __http_update_cb(http_raw_data_t *data, void *user_param) -{ - http_raw_data_t *raw_data = DA_NULL; - da_info_t *da_info = DA_NULL; - if (!data || !user_param) { - DA_LOGE("NULL CHECK!: data, user_param"); - return; - } - DA_LOGV(""); - raw_data = data; - da_info = (da_info_t *)user_param; - - switch(data->type) { - case HTTP_EVENT_GOT_HEADER: - __handle_event_http_header(raw_data, da_info); - break; - case HTTP_EVENT_GOT_PACKET: - __handle_event_http_packet(raw_data, da_info); - break; - case HTTP_EVENT_FINAL: - __handle_event_http_final(raw_data, da_info); - break; -/* - case HTTP_EVENT_ABORT: - ret = __handle_event_http_abort(raw_data, da_info); - break; -*/ - } -} - -da_bool_t is_stopped_state(da_info_t *da_info) -{ - http_info_t *http_info = DA_NULL; - http_state_t http_state; - NULL_CHECK_RET_OPT(da_info, DA_FALSE); - http_info = da_info->http_info; - NULL_CHECK_RET_OPT(http_info, DA_FALSE); - DA_MUTEX_LOCK(&(http_info->mutex_state)); - http_state = http_info->state; - DA_MUTEX_UNLOCK(&(http_info->mutex_state)); - switch (http_state) { - case HTTP_STATE_REQUEST_CANCEL: - case HTTP_STATE_CANCELED: - case HTTP_STATE_FAILED: - case HTTP_STATE_ABORTED: - //case HTTP_STATE_REQUEST_PAUSE: - //case HTTP_STATE_REQUEST_RESUME: - //case HTTP_STATE_WAIT_FOR_NET_ERR: - return DA_TRUE; - default: - return DA_FALSE; - } - return DA_FALSE; -} diff --git a/agent/download-agent-http-msg-handler.c b/agent/download-agent-http-msg-handler.c deleted file mode 100755 index 231a61d..0000000 --- a/agent/download-agent-http-msg-handler.c +++ /dev/null @@ -1,1125 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string.h> -#include <stdlib.h> -#include <ctype.h> - -#include "download-agent-http-msg-handler.h" -#include "download-agent-debug.h" -#include "download-agent-encoding.h" - -// '.' and ';' are request from Vodafone -#define IS_TERMINATING_CHAR(c) ( ((c) == ';') || ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20) ) -#define IS_TERMINATING_CHAR_EX(c) ( ((c) == '"') || ((c) == ';') || ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20) ) -#define IS_URI_TERMINATING_CHAR(c) ( ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20) ) - -enum parsing_type { - WITH_PARSING_OPTION, - WITHOUT_PARSING_OPTION -}; - -static da_ret_t __http_header_add_field(http_header_t **head, - const char *field, const char *value, enum parsing_type type); -static void __http_header_destroy_all_field(http_header_t **head); -static da_bool_t __get_http_header_for_field( - http_msg_response_t *http_msg_response, const char *in_field, - http_header_t **out_header); -static void __exchange_header_value(http_header_t *header, - const char *in_raw_value); -static http_header_options_t *__create_http_header_option(const char *field, - const char *value); -static void __http_header_destroy_all_option(http_header_options_t **head); -static da_bool_t __get_http_header_option_for_field( - http_header_options_t *header_option, const char *in_field, - char **out_value); -static http_header_options_t *__parsing_N_create_option_str(char *org_str); -static http_header_options_t *__parsing_options(char *org_str); -static void __parsing_raw_value(http_header_t *http_header); - -da_ret_t http_msg_request_create(http_msg_request_t **http_msg_request) -{ - http_msg_request_t *temp_http_msg_request = NULL; - -// DA_LOGV(""); - - temp_http_msg_request = (http_msg_request_t *)calloc(1, - sizeof(http_msg_request_t)); - if (!temp_http_msg_request) { - *http_msg_request = NULL; - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - return DA_ERR_FAIL_TO_MEMALLOC; - } - - temp_http_msg_request->http_method = NULL; - temp_http_msg_request->url = NULL; - temp_http_msg_request->head = NULL; - temp_http_msg_request->http_body = NULL; - - *http_msg_request = temp_http_msg_request; - DA_LOGV( "http_msg_request: %x", (unsigned int)(*http_msg_request)); - - return DA_RESULT_OK; -} - -void http_msg_request_destroy(http_msg_request_t **http_msg_request) -{ - http_msg_request_t *temp_http_msg_request = *http_msg_request; - - DA_LOGV(""); - - if (temp_http_msg_request) { - if (temp_http_msg_request->http_method) { - free(temp_http_msg_request->http_method); - temp_http_msg_request->http_method = NULL; - } - if (temp_http_msg_request->url) { - free(temp_http_msg_request->url); - temp_http_msg_request->url = NULL; - } - if (temp_http_msg_request->http_body) { - free(temp_http_msg_request->http_body); - temp_http_msg_request->http_body = NULL; - } - __http_header_destroy_all_field(&(temp_http_msg_request->head)); - free(temp_http_msg_request); - *http_msg_request = NULL; - } -} - -da_ret_t http_msg_request_set_url(http_msg_request_t *http_msg_request, - const char *url) -{ - DA_LOGV(""); - - if (!http_msg_request) { - DA_LOGE("http_msg_request is NULL; DA_ERR_INVALID_ARGUMENT"); - return DA_ERR_INVALID_ARGUMENT; - } - - if (!url) { - DA_LOGE("url is NULL; DA_ERR_INVALID_ARGUMENT"); - return DA_ERR_INVALID_URL; - } - - http_msg_request->url = strdup(url); - DA_SECURE_LOGI("http url[%s]", http_msg_request->url); - return DA_RESULT_OK; -} - -da_ret_t http_msg_request_get_url(http_msg_request_t *http_msg_request, - const char **url) -{ - DA_LOGV(""); - - if (!http_msg_request) { - DA_LOGE("http_msg_request is NULL; DA_ERR_INVALID_ARGUMENT"); - return DA_ERR_INVALID_ARGUMENT; - } - - if (http_msg_request->url) { - *url = http_msg_request->url; - return DA_RESULT_OK; - } else { - *url = DA_NULL; - return DA_ERR_INVALID_ARGUMENT; - } -} - -da_ret_t http_msg_request_add_field(http_msg_request_t *http_msg_request, - const char *field, const char *value) -{ - // DA_LOGV(""); - - if (!http_msg_request) { - DA_LOGE("Check NULL! : http_msg_request"); - return DA_ERR_INVALID_ARGUMENT; - } - - return __http_header_add_field(&(http_msg_request->head), field, value, WITHOUT_PARSING_OPTION); -} - -da_ret_t http_msg_response_create(http_msg_response_t **http_msg_response) -{ - http_msg_response_t *temp_http_msg_response = NULL; - - DA_LOGV(""); - - temp_http_msg_response = (http_msg_response_t *)calloc(1, - sizeof(http_msg_response_t)); - if (!temp_http_msg_response) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - return DA_ERR_FAIL_TO_MEMALLOC; - } else { - temp_http_msg_response->status_code = 0; - temp_http_msg_response->head = NULL; - *http_msg_response = temp_http_msg_response; - return DA_RESULT_OK; - } -} - -void http_msg_response_destroy(http_msg_response_t **http_msg_response) -{ - http_msg_response_t *temp_http_msg_response = *http_msg_response; - - DA_LOGV(""); - if (temp_http_msg_response) { - __http_header_destroy_all_field(&(temp_http_msg_response->head)); - free(temp_http_msg_response); - *http_msg_response = DA_NULL; - } -} - -da_ret_t http_msg_response_add_field(http_msg_response_t *http_msg_response, - const char *field, const char *value) -{ - DA_LOGV(""); - - if (!http_msg_response) { - DA_LOGE("DA_ERR_INVALID_ARGUMENT"); - return DA_ERR_INVALID_ARGUMENT; - } - return __http_header_add_field(&(http_msg_response->head), field, value, WITH_PARSING_OPTION); -} - -da_ret_t __http_header_add_field(http_header_t **head, - const char *field, const char *value, enum parsing_type type) -{ - http_header_t *pre = NULL; - http_header_t *cur = NULL; - - //DA_SECURE_LOGD("[%s][%s]", field, value); - - pre = cur = *head; - while (cur) { - pre = cur; - /* Replace default value with user wanted value - * Remove the value which is stored before and add a new value. - */ - if (cur->field && cur->raw_value && - strncasecmp(cur->field, field, strlen(field)) == 0) { - DA_SECURE_LOGD("Remove value for replacement [%s][%s]", cur->field, cur->raw_value); - if (cur->field) { - free(cur->field); - cur->field = NULL; - } - if (cur->raw_value) { - free(cur->raw_value); - cur->raw_value= NULL; - } - } - cur = cur->next; - } - - cur = (http_header_t *)calloc(1, sizeof(http_header_t)); - if (cur) { - cur->field = strdup(field); - cur->raw_value = strdup(value); - cur->options = NULL; - cur->next = NULL; - - if (type == WITHOUT_PARSING_OPTION) { - cur->value = strdup(value); - cur->options = NULL; - } else { - __parsing_raw_value(cur); - } - - if (pre) - pre->next = cur; - else - *head = cur; - } else { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - return DA_ERR_FAIL_TO_MEMALLOC; - } - - return DA_RESULT_OK; -} - -void __http_header_destroy_all_field(http_header_t **head) -{ - http_header_t *pre = NULL; - http_header_t *cur = NULL; - - cur = *head; - - while (cur) { - if (cur->field) { - free(cur->field); - cur->field = DA_NULL; - } - if (cur->value) { - free(cur->value); - cur->value = DA_NULL; - } - if (cur->raw_value) { - free(cur->raw_value); - cur->raw_value = DA_NULL; - } - __http_header_destroy_all_option(&(cur->options)); - free(cur->options); - cur->options = DA_NULL; - pre = cur; - cur = cur->next; - free(pre); - } - *head = DA_NULL; -} - -http_header_options_t *__create_http_header_option(const char *field, - const char *value) -{ - http_header_options_t *option = NULL; - - option = (http_header_options_t *)calloc(1, - sizeof(http_header_options_t)); - if (option) { - if (field) - option->field = strdup(field); - if (value) - option->value = strdup(value); - option->next = NULL; - } - return option; -} - -void __http_header_destroy_all_option(http_header_options_t **head) -{ - http_header_options_t *pre = NULL; - http_header_options_t *cur = NULL; - - // DA_LOGV(""); - - cur = *head; - - while (cur) { - if (cur->field) { - DA_SECURE_LOGD("field= %s", cur->field); - free(cur->field); - cur->field = DA_NULL; - } - if (cur->value) { - free(cur->value); - cur->value = DA_NULL; - } - pre = cur; - cur = cur->next; - free(pre); - } - *head = DA_NULL; -} - -da_ret_t http_msg_request_get_iter(http_msg_request_t *http_msg_request, - http_msg_iter_t *http_msg_iter) -{ - DA_LOGV(""); - - if (!http_msg_request) { - DA_LOGE("DA_ERR_INVALID_ARGUMENT"); - return DA_ERR_INVALID_ARGUMENT; - } - - *http_msg_iter = http_msg_request->head; - - return DA_RESULT_OK; -} - -da_ret_t http_msg_response_get_iter(http_msg_response_t *http_msg_response, - http_msg_iter_t *http_msg_iter) -{ - if (!http_msg_response) { - DA_LOGE("DA_ERR_INVALID_ARGUMENT"); - return DA_ERR_INVALID_ARGUMENT; - } - - *http_msg_iter = http_msg_response->head; - return DA_RESULT_OK; -} - -da_bool_t http_msg_get_field_with_iter(http_msg_iter_t *http_msg_iter, - char **out_field, char **out_value) -{ - http_header_t *cur = *http_msg_iter; - - if (cur) { - *out_field = cur->field; - *out_value = cur->value; - *http_msg_iter = cur->next; - return DA_TRUE; - } else { - return DA_FALSE; - } -} - -da_bool_t http_msg_get_header_with_iter(http_msg_iter_t *http_msg_iter, - char **out_field, http_header_t **out_header) -{ - http_header_t *cur = *http_msg_iter; - - if (cur) { - *out_field = cur->field; - *out_header = cur; - *http_msg_iter = cur->next; - return DA_TRUE; - } else { - return DA_FALSE; - } -} - -http_header_options_t *__parsing_N_create_option_str(char *org_str) -{ - char *option_field = NULL; - char *option_value = NULL; - int option_field_len = 0; - int option_value_len = 0; - char *org_pos = NULL; - int org_str_len = 0; - char *working_str = NULL; - char *working_pos = NULL; - char *working_pos_field_start = NULL; - char *working_pos_value_start = NULL; - da_bool_t is_inside_quotation = DA_FALSE; - da_bool_t is_working_for_field = DA_TRUE; - int i = 0; - http_header_options_t *option = NULL; - - // DA_LOGV(""); - - if (!org_str) - return NULL; - - org_str_len = strlen(org_str); - if (org_str_len <= 0) - return NULL; - - working_str = (char *)calloc(1, org_str_len + 1); - if (!working_str) - return NULL; - - org_pos = org_str; - working_pos_field_start = working_pos = working_str; - - for (i = 0; i < org_str_len; i++) { - if (*org_pos == '"') - is_inside_quotation = !is_inside_quotation; - if (is_inside_quotation) { - // Leave anything including blank if it is inside of double quotation mark. - *working_pos = *org_pos; - is_working_for_field ? option_field_len++ - : option_value_len++; - working_pos++; - org_pos++; - } else { - if (*org_pos == ' ') { - org_pos++; - } else if (*org_pos == '=') { - if (is_working_for_field) { - is_working_for_field = DA_FALSE; - working_pos_value_start = working_pos; - } - org_pos++; - } else { - *working_pos = *org_pos; - is_working_for_field ? option_field_len++ - : option_value_len++; - working_pos++; - org_pos++; - } - } - } - - if (option_field_len > 0 && working_pos_field_start) { - option_field = (char *)calloc(1, option_field_len + 1); - if (option_field) - strncpy(option_field, working_pos_field_start, - option_field_len); - } - if (option_value_len > 0 && working_pos_value_start) { - option_value = (char *)calloc(1, option_value_len + 1); - if (option_value) - strncpy(option_value, working_pos_value_start, - option_value_len); - } - if (working_str) { - free(working_str); - working_pos = working_str = NULL; - } - - DA_SECURE_LOGD("option_field = [%s], option_value = [%s]", - option_field, option_value); - - if (option_field || option_value) { - option = __create_http_header_option( - option_field, option_value); - if (option_field) { - free(option_field); - option_field = NULL; - } - if (option_value) { - free(option_value); - option_value = NULL; - } - } - return option; -} - -http_header_options_t *__parsing_options(char *org_str) -{ - da_ret_t ret = DA_RESULT_OK; - http_header_options_t *head = NULL; - http_header_options_t *pre = NULL; - http_header_options_t *cur = NULL; - - int wanted_str_len = 0; - char *wanted_str = NULL; - char *wanted_str_start = NULL; - char *wanted_str_end = NULL; - char *cur_pos = NULL; - - DA_LOGV(""); - - if (!org_str) - return NULL; - - /* Do Not use strtok(). It's not thread safe. */ - // DA_SECURE_LOGD("org_str = %s", org_str); - - cur_pos = org_str; - - while (cur_pos) { - wanted_str_start = cur_pos; - wanted_str_end = strchr(cur_pos, ';'); - if (wanted_str_end) { - cur_pos = wanted_str_end + 1; - } else { - wanted_str_end = org_str + strlen(org_str); - cur_pos = NULL; - } - wanted_str_len = wanted_str_end - wanted_str_start; - wanted_str = (char *)calloc(1, wanted_str_len + 1); - if (!wanted_str) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - ret = DA_ERR_FAIL_TO_MEMALLOC; - goto ERR; - } - strncpy(wanted_str, wanted_str_start, wanted_str_len); - - // DA_SECURE_LOGD("wanted_str = [%s]", wanted_str); - cur = __parsing_N_create_option_str(wanted_str); - if (pre) { - pre->next = cur; - pre = cur; - } else { - head = pre = cur; - } - - free(wanted_str); - wanted_str = NULL; - } - -ERR: - if (ret != DA_RESULT_OK) - __http_header_destroy_all_option(&head); - return head; -} - -void __parsing_raw_value(http_header_t *http_header_field) -{ - char *raw_value = NULL; - char *option_str_start = NULL; - char *trimed_value = NULL; - int trimed_value_len = 0; - char *trimed_value_start = NULL; - char *trimed_value_end = NULL; - - raw_value = http_header_field->raw_value; - // DA_SECURE_LOGD("raw_value = [%s]", raw_value); - - if (!raw_value) - return; - - trimed_value_start = raw_value; - trimed_value_end = strchr(raw_value, ';'); - if (!trimed_value_end) { - // No options - http_header_field->value = strdup(raw_value); - http_header_field->options = NULL; - - return; - } - - // for trimed value - trimed_value_len = trimed_value_end - trimed_value_start; - trimed_value = (char *)calloc(1, trimed_value_len + 1); - if (!trimed_value) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - return; - } - strncpy(trimed_value, trimed_value_start, trimed_value_len); - http_header_field->value = trimed_value; - - // for option parsing - option_str_start = trimed_value_end + 1; - http_header_field->options = __parsing_options(option_str_start); - - /////////////// show - http_header_options_t *cur = NULL; - cur = http_header_field->options; - while (cur) { -// DA_SECURE_LOGD("field = [%s], value = [%s]", cur->field, cur->value); - cur = cur->next; - } -} - -da_bool_t __get_http_header_option_for_field( - http_header_options_t *header_option, const char *in_field, - char **out_value) -{ - http_header_options_t *cur = NULL; - - // DA_LOGV(""); - - if (!header_option) { - DA_LOGE("input header_option is NULL."); - return DA_FALSE; - } - - cur = header_option; - while (cur) { - if (cur->field) { - if (!strncasecmp(cur->field, in_field, strlen(cur->field)) && - cur->value) { - DA_SECURE_LOGD("[%s][%s]", cur->field, cur->value); - *out_value = cur->value; - return DA_TRUE; - } - - } - cur = cur->next; - } - return DA_FALSE; -} - -da_bool_t __get_http_header_for_field(http_msg_response_t *http_msg_response, - const char *in_field, http_header_t **out_header) -{ - http_msg_iter_t http_msg_iter; - http_header_t *header = NULL; - char *field = NULL; - - //DA_LOGV(""); - - http_msg_response_get_iter(http_msg_response, &http_msg_iter); - while (http_msg_get_header_with_iter(&http_msg_iter, &field, &header)) { - if (field && header && !strncasecmp(field, in_field, strlen(field))) { - //DA_SECURE_LOGD("[%s][%s]", field, header->value); - *out_header = header; - return DA_TRUE; - } - } - - return DA_FALSE; -} - -da_bool_t __get_http_req_header_for_field(http_msg_request_t *http_msg_request, - const char *in_field, http_header_t **out_header) -{ - http_msg_iter_t http_msg_iter; - http_header_t *header = NULL; - char *field = NULL; - - //DA_LOGV(""); - - http_msg_request_get_iter(http_msg_request, &http_msg_iter); - while (http_msg_get_header_with_iter(&http_msg_iter, &field, &header)) { - if (field && header && !strncasecmp(field, in_field, strlen(field))) { - //DA_SECURE_LOGD("[%s][%s]", field, header->value); - *out_header = header; - return DA_TRUE; - } - } - - return DA_FALSE; -} - -void __exchange_header_value(http_header_t *header, const char *in_raw_value) -{ - DA_LOGV(""); - - if (!header || !in_raw_value) - return; - - __http_header_destroy_all_option(&(header->options)); - - if (header->value) { - free(header->value); - header->value = DA_NULL; - } - if (header->raw_value) - free(header->raw_value); - header->raw_value = strdup(in_raw_value); - - __parsing_raw_value(header); -} - -da_bool_t http_msg_response_get_content_type( - http_msg_response_t *http_msg_response, char **out_type) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - - DA_LOGV(""); - - b_ret = __get_http_header_for_field(http_msg_response, - HTTP_FIELD_CONTENT_TYPE, &header); - if (!b_ret) { - DA_LOGV("no Content-Type"); - return DA_FALSE; - } - if (out_type) - *out_type = strdup(header->value); - - return DA_TRUE; -} - -void http_msg_response_set_content_type(http_msg_response_t *http_msg_response, - const char *in_type) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - - DA_LOGV(""); - - if (!http_msg_response || !in_type) - return; - - b_ret = __get_http_header_for_field(http_msg_response, - HTTP_FIELD_CONTENT_TYPE, &header); - if (b_ret) { - if (header->raw_value && (!strncmp(header->raw_value, in_type, - strlen(header->raw_value)))) - return; - - DA_SECURE_LOGD("exchange Content-Type to [%s] from [%s]", in_type, header->value); - __exchange_header_value(header, in_type); - } else { - __http_header_add_field(&(http_msg_response->head), - HTTP_FIELD_CONTENT_TYPE, in_type, WITH_PARSING_OPTION); - } -} - -da_bool_t http_msg_response_get_content_length( - http_msg_response_t *http_msg_response, da_size_t *out_length) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - - DA_LOGV(""); - - b_ret = __get_http_header_for_field(http_msg_response, - HTTP_FIELD_CONTENT_LENGTH, &header); - if (!b_ret) { - DA_LOGV( "no Content-Length"); - return DA_FALSE; - } - - if (out_length) - *out_length = atoll(header->value); - - return DA_TRUE; -} - -da_bool_t http_msg_response_get_content_disposition( - http_msg_response_t *http_msg_response, char **out_disposition, - char **out_file_name) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - char *file_name = NULL; - char *wanted_str = NULL; - char *wanted_str_start = NULL; - char *wanted_str_end = NULL; - char *decoded_str = NULL; - int wanted_str_len = 0; - - DA_LOGV(""); - - b_ret = __get_http_header_for_field(http_msg_response, - HTTP_FIELD_CONTENT_DISPOSITION, &header); - if (!b_ret) { - DA_LOGV( "no Content-Disposition"); - return DA_FALSE; - } - if (out_disposition) - *out_disposition = strdup(header->value); - if (!out_file_name) - return DA_FALSE; - - b_ret = __get_http_header_option_for_field(header->options, "filename", - &file_name); - if (!b_ret) { - DA_LOGV( "no option"); - return DA_FALSE; - } - - // eliminate double quotation mark if it exists on derived value - wanted_str_start = strchr(file_name, '"'); - if (!wanted_str_start) { - *out_file_name = strdup(file_name); - return DA_TRUE; - } else { - // DA_SECURE_LOGD("wanted_str_start = [%s]", wanted_str_start); - wanted_str_start++; - wanted_str_end = strchr(wanted_str_start, '"'); - if (wanted_str_end) { - wanted_str_len = wanted_str_end - wanted_str_start; - wanted_str = (char*)calloc(1, wanted_str_len + 1); - if (!wanted_str) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - return DA_FALSE; - } - strncpy(wanted_str, wanted_str_start, wanted_str_len); - - b_ret = is_base64_encoded_word(wanted_str); - if (b_ret) { - DA_LOGV("It's base64 encoded-word string"); - if (DA_RESULT_OK == decode_base64_encoded_str( - wanted_str, &decoded_str)) { - DA_SECURE_LOGD("base64 decoded str = [%s]", decoded_str); - free(wanted_str); - wanted_str = decoded_str; - decoded_str = NULL; - } else { - DA_LOGV("Fail to base64 decode. Just use un-decoded string."); - } - } else { - DA_LOGV("It's NOT base64 encoded-word string"); - } - decode_url_encoded_str(wanted_str, &decoded_str); - /* If it is url encoded string */ - if (decoded_str) { - DA_SECURE_LOGD("Url decoded str = [%s]", decoded_str); - free(wanted_str); - wanted_str = decoded_str; - decoded_str = NULL; - } - *out_file_name = wanted_str; - DA_SECURE_LOGI("out_file_name = [%s]", *out_file_name); - return DA_TRUE; - } else { - DA_LOGE("Not matched \" !"); - return DA_FALSE; - } - } -} - -da_bool_t http_msg_response_get_ETag(http_msg_response_t *http_msg_response, - char **out_value) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - - DA_LOGV(""); - - b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_ETAG, - &header); - if (!b_ret) { - DA_LOGV( "no ETag"); - return DA_FALSE; - } - if (out_value) - *out_value = strdup(header->value); - - return DA_TRUE; -} - -#ifdef _RAF_SUPPORT -da_bool_t http_msg_response_get_RAF_mode(http_msg_response_t *http_msg_response, - char **out_value) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - - DA_LOGV(""); - - b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_RAF_MODE, - &header); - if (!b_ret) { - DA_LOGV( "no RAF mode"); - return DA_FALSE; - } - if (out_value) - *out_value = strdup(header->value); - - return DA_TRUE; -} -#endif - -da_bool_t http_msg_response_get_date(http_msg_response_t *http_msg_response, - char **out_value) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - - DA_LOGV(""); - - b_ret = __get_http_header_for_field(http_msg_response, - HTTP_FIELD_DATA, &header); - if (!b_ret) { - DA_LOGV( "no Date"); - return DA_FALSE; - } - if (out_value) - *out_value = strdup(header->value); - - return DA_TRUE; -} - -da_bool_t http_msg_response_get_location(http_msg_response_t *http_msg_response, - char **out_value) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - - DA_LOGV(""); - - b_ret = __get_http_header_for_field(http_msg_response, - HTTP_FIELD_LOCATION, &header); - if (!b_ret) { - DA_LOGV( "no Location"); - return DA_FALSE; - } - if (out_value) - *out_value = strdup(header->value); - - return DA_TRUE; -} - -char *__stristr(const char *long_str, const char *find_str) -{ - int i = 0; - int length_long = 0; - int length_find = 0; - char *ret_ptr = NULL; - char *org_ptr = NULL; - char *look_ptr = NULL; - - if (long_str == NULL || find_str == NULL) { - DA_LOGE("INVALID ARGUMENT"); - return NULL; - } - - length_long = strlen(long_str); - length_find = strlen(find_str); - - org_ptr = (char*)calloc(1, length_long + 1); - - if (org_ptr == NULL) { - DA_LOGE("INVALID ARGUMENT"); - return NULL; - } - - look_ptr = (char*)calloc(1, length_find + 1); - - if (look_ptr == NULL) { - DA_LOGE("INVALID ARGUMENT"); - free(org_ptr); - return NULL; - } - - while (i < length_long) { - if (isalpha(long_str[i]) != 0) { - if (isupper(long_str[i]) != 0) { - org_ptr[i] = long_str[i]; - } else { - org_ptr[i] = toupper(long_str[i]); - } - } else { - org_ptr[i] = long_str[i]; - } - i++; - } - - i = 0; - - while (i < length_find) { - if (isalpha(find_str[i]) != 0) { - if (isupper(find_str[i]) != 0) { - look_ptr[i] = find_str[i]; - } else { - look_ptr[i] = toupper(find_str[i]); - } - } else { - look_ptr[i] = find_str[i]; - } - i++; - } - - ret_ptr = strstr(org_ptr, look_ptr); - - if (ret_ptr == 0) { - free(org_ptr); - free(look_ptr); - return NULL; - } else { - i = ret_ptr - org_ptr; - } - - free(org_ptr); - free(look_ptr); - - return (char*)(long_str + i); -} - -/* This is not used. But it can be needed if there is no http header parser at http library.*/ -da_bool_t extract_attribute_from_header( - char *szHeadStr, - const char *szFindStr, - char **ppRtnValue) -{ - char *pValuePos = NULL; - int index = 0; - int startPos = 0; - int strLen = 0; - int need_to_end_quataion_mark = 0; - - if (szHeadStr == DA_NULL || szFindStr == DA_NULL) { - DA_LOGE("INVALID ARGUMENT"); - return DA_FALSE; - } - if (strlen(szHeadStr) <= 0 || strlen(szFindStr) <= 0) { - DA_LOGE("INVALID ARGUMENT");; - - return DA_FALSE; - } - if (ppRtnValue == NULL) { - return DA_FALSE; - } - - pValuePos = __stristr(szHeadStr, (char*)szFindStr); - if (pValuePos == NULL) { - *ppRtnValue = NULL; - goto ERR; - } - - index = strlen(szFindStr); - - while (pValuePos[index] != ':' && pValuePos[index] != '=') { - index++; - - if (pValuePos[index] == '\0') { - return DA_FALSE; - } - } - - index++; - - /* jump space */ - while (pValuePos[index] == ' ') { - index++; - } - - /* jump quatation mark */ - while (pValuePos[index] == '"') { - need_to_end_quataion_mark = 1; - index++; - } - - startPos = index; - - /* Find the end of data. */ - if (0 == strncasecmp(szFindStr, HTTP_FIELD_LOCATION, - strlen(HTTP_FIELD_LOCATION)))//terminate character list does not contain ';' in case of URI - { - while (DA_FALSE == IS_URI_TERMINATING_CHAR(pValuePos[index])) { - index++; - } - } else if (need_to_end_quataion_mark) { - while (DA_FALSE == IS_TERMINATING_CHAR_EX(pValuePos[index])) { - index++; - } - } else { - while (DA_FALSE == IS_TERMINATING_CHAR(pValuePos[index])) { - index++; - } - } - - strLen = index - startPos; - - if (strLen < 1) { - DA_LOGE(" strLen is < 1"); - goto ERR; - } - - *ppRtnValue = (char*)calloc(1, sizeof(char) * (strLen + 1)); - - if (*ppRtnValue == NULL) { - DA_LOGE(" *ppRtnValue is NULL"); - goto ERR; - } - - strncpy(*ppRtnValue, pValuePos + startPos, strLen); - *(*ppRtnValue + strLen) = '\0'; - - return DA_TRUE; -ERR: - if (*ppRtnValue) { - free(*ppRtnValue); - *ppRtnValue = NULL; - } - return DA_FALSE; -} - -da_bool_t http_msg_request_get_if_range(http_msg_request_t *http_msg_request, - char **out_value) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - - DA_LOGV(""); - - b_ret = __get_http_req_header_for_field(http_msg_request, HTTP_FIELD_IF_RANGE, - &header); - if (!b_ret) { - DA_LOGV( "no If Range"); - return DA_FALSE; - } - if (out_value) - *out_value = strdup(header->value); - - return DA_TRUE; -} - -da_bool_t http_msg_request_get_range(http_msg_request_t *http_msg_request, - char **out_value) -{ - da_bool_t b_ret = DA_FALSE; - http_header_t *header = NULL; - - DA_LOGV(""); - - b_ret = __get_http_req_header_for_field(http_msg_request, HTTP_FIELD_RANGE, - &header); - if (!b_ret) { - DA_LOGV( "no Range"); - return DA_FALSE; - } - if (out_value) - *out_value = strdup(header->value); - - return DA_TRUE; -} diff --git a/agent/download-agent-interface.c b/agent/download-agent-interface.c deleted file mode 100755 index 0b19813..0000000 --- a/agent/download-agent-interface.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "download-agent-interface.h" -#include "download-agent-dl-mgr.h" - -int da_init() -{ - DA_LOGV(""); - da_ret_t ret = DA_RESULT_OK; - DA_LOGI("Return ret = %d", ret); - return ret; -} - -int da_deinit() -{ - da_ret_t ret = DA_RESULT_OK; - - DA_LOGV(""); - destroy_da_info_list(); - DA_LOGI("====== da_deint EXIT ====="); - return ret; -} - -int da_start_download(const char *url, req_data_t *ext_data, - da_cb_t *da_cb_data, int *download_id) -{ - da_ret_t ret = DA_RESULT_OK; - int req_header_count = 0; - int i = 0; - int da_id = DA_INVALID_ID; - da_info_t *da_info = DA_NULL; - - *download_id = DA_INVALID_ID; - - if (ext_data->request_header_count > 0) { - DA_LOGI("request_header_count[%d]", ext_data->request_header_count); - for (i = 0; i < ext_data->request_header_count; i++) { - if (ext_data->request_header[i]) { - req_header_count++; - DA_SECURE_LOGI("request_header[%s]", ext_data->request_header[i]); - } - } - DA_LOGI("actual request_header_count[%d]", req_header_count); - if (ext_data->request_header_count != req_header_count) { - DA_LOGE("Request header count is not matched with number of request header array"); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } - } - - if (ext_data->install_path) - DA_SECURE_LOGI("install path[%s]", ext_data->install_path); - if (ext_data->file_name) - DA_SECURE_LOGI("file_name[%s]", ext_data->file_name); - if (ext_data->temp_file_path) - DA_SECURE_LOGI("temp_file_path[%s]", ext_data->temp_file_path); - if (ext_data->etag) - DA_SECURE_LOGI("etag[%s]", ext_data->etag); - if (ext_data->pkg_name) - DA_SECURE_LOGI("pkg_name[%s]", ext_data->pkg_name); - if (ext_data->network_bonding) - DA_LOGD("network bonding option[%d]", ext_data->network_bonding); - if (ext_data->user_req_data) - DA_LOGI("user_req_data[%p]", ext_data->user_req_data); - if (ext_data->user_client_data) - DA_LOGI("user_client_data[%p]", ext_data->user_client_data); - - ret = get_available_da_id(&da_id); - if (ret != DA_RESULT_OK) - goto ERR; - - da_info = da_info_list[da_id]; - da_info->da_id = da_id; - - ret = copy_user_input_data(da_info, url, ext_data, da_cb_data); - if (ret != DA_RESULT_OK) - goto ERR; - *download_id = da_id; - ret = start_download(da_info); -ERR: - DA_LOGI("Return:id[%d],ret[%d]", *download_id, ret); - return ret; -} - -int da_cancel_download(int download_id) -{ - da_ret_t ret = DA_RESULT_OK; - - DA_LOGV("download_id[%d]", download_id); - ret = cancel_download(download_id, DA_TRUE); - DA_LOGI("Return:id[%d],ret[%d]", download_id, ret); - return ret; -} - -int da_cancel_download_without_update(int download_id) -{ - da_ret_t ret = DA_RESULT_OK; - DA_LOGV("download_id[%d]", download_id); - ret = cancel_download(download_id, DA_FALSE); - DA_LOGI("Return:id[%d],ret[%d]", download_id, ret); - return ret; -} - -int da_suspend_download(int download_id) -{ - da_ret_t ret = DA_RESULT_OK; - DA_LOGV("download_id[%d]", download_id); - ret = suspend_download(download_id, DA_TRUE); - DA_LOGI("Return:id[%d],ret[%d]", download_id, ret); - return ret; -} - -int da_suspend_download_without_update(int download_id) -{ - da_ret_t ret = DA_RESULT_OK; - DA_LOGV("download_id[%d]", download_id); - ret = suspend_download(download_id, DA_FALSE); - DA_LOGI("Return:id[%d],ret[%d]", download_id, ret); - return ret; -} - - -int da_resume_download(int download_id) -{ - da_ret_t ret = DA_RESULT_OK; - DA_LOGV("download_id[%d]", download_id); - ret = resume_download(download_id); - DA_LOGI("Return:id[%d],ret[%d]", download_id, ret); - return ret; -} - -int da_is_valid_download_id(int download_id) -{ - da_bool_t ret = DA_FALSE; - ret = is_valid_download_id(download_id); - DA_LOGI("Return:id[%d],ret[%d]", download_id, ret); - return ret; -} diff --git a/agent/download-agent-mime-util.c b/agent/download-agent-mime-util.c deleted file mode 100755 index 71e08eb..0000000 --- a/agent/download-agent-mime-util.c +++ /dev/null @@ -1,449 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string.h> -#include <stdlib.h> - -#include <xdgmime.h> - -#include "download-agent-debug.h" -#include "download-agent-mime-util.h" -#include "download-agent-pthread.h" - -#define IS_PROHIBITED_CHAR(c) ((c) == ';' || (c) == '\\' || (c) == '/' || (c) == ':' || (c) == '*' || (c) == '?' || (c) == '"' || (c) == '>' || (c) == '<' || (c) == '|' || (c) == '(' || (c) == ')') -#define IS_SPACE_CHARACTER(c) ((c) == '\t') - -#define MAX_EXT_TABLE_INDEX 16 -Ext_translation_table ext_trans_table [MAX_EXT_TABLE_INDEX] = { - {"*.xla", "*.xls"}, - {"*.pot", "*.ppt"}, - {"*.xsl", "*.xml"}, - {"*.spl", "*.swf"}, - {"*.oga", "*.ogg"}, - {"*.jpe", "*.jpg"},//5 - {"*.CSSL", "*.css"}, - {"*.htm", "*.html"}, - {"*.hxx", "*.hpp"}, - {"*.c++", "*.cpp"}, - {"CMakeLists.txt", "*.cmake"},//10 - {"*.ime", "*.imy"}, - {"Makefile", "makefile"}, - {"*.3g2", "*.3gp"}, - {"*.mp2", "*.mpg"}, - {"*.divx", "*.avi"},//15 - }; -/* This is samsung mime policy - * 1. if the mime is audio/m4a, the extension name is defined as "m4a" for launching music player -*/ -#ifdef _SAMSUNG_MIME_POLICY -#define MAX_SEC_MIME_TABLE_INDEX 1 -struct sec_mime_table_t { - char *mime; - char *ext; -}; -struct sec_mime_table_t sec_mime_table [MAX_SEC_MIME_TABLE_INDEX] = { - {"audio/m4a", "m4a"}, -}; -#endif - -const char *ambiguous_MIME_Type_list[] = { - "text/plain", - "application/octet-stream" -}; - -/* Because xdgmime is not thread safety, this mutex is necessary */ -pthread_mutex_t mutex_for_xdgmime = PTHREAD_MUTEX_INITIALIZER; - -da_bool_t is_ambiguous_MIME_Type(const char *in_mime_type) -{ - if (!in_mime_type) - return DA_FALSE; - - int index = 0; - int list_size = sizeof(ambiguous_MIME_Type_list) / sizeof(const char *); - for (index = 0 ; index < list_size ; index++) { - if (0 == strncmp(in_mime_type, ambiguous_MIME_Type_list[index], - strlen(ambiguous_MIME_Type_list[index]))) { - //DA_SECURE_LOGD("It is ambiguous! [%s]", ambiguous_MIME_Type_list[index]); - return DA_TRUE; - } - } - - return DA_FALSE; -} - -da_ret_t da_mime_get_ext_name(char *mime, char **ext) -{ - da_ret_t ret = DA_RESULT_OK; - const char **extlist = DA_NULL; - const char *unaliased_mimetype = DA_NULL; - char ext_temp[DA_MAX_STR_LEN] = {0,}; - char *temp = NULL; - - DA_LOGV(""); - - if (DA_NULL == mime || DA_NULL == ext) { - ret = DA_ERR_INVALID_ARGUMENT; - DA_LOGE("Invalid mime type"); - goto ERR; - } -// DA_SECURE_LOGD("mime str[%s]ptr[%p]len[%d]",mime,mime,strlen(mime)); - /* unaliased_mimetype means representative mime among similar types */ - DA_MUTEX_LOCK(&mutex_for_xdgmime); - unaliased_mimetype = xdg_mime_unalias_mime_type(mime); - - if (unaliased_mimetype == DA_NULL) { - ret = DA_ERR_INVALID_MIME_TYPE; - DA_LOGI("Invalid mime type : No unsaliased mime type"); - DA_MUTEX_UNLOCK(&mutex_for_xdgmime); - goto ERR; - } - DA_SECURE_LOGD("unaliased_mimetype[%s]\n",unaliased_mimetype); - - /* Get extension name from shared-mime-info */ - extlist = xdg_mime_get_file_names_from_mime_type(unaliased_mimetype); - DA_MUTEX_UNLOCK(&mutex_for_xdgmime); - if (extlist == DA_NULL || *extlist == DA_NULL) { - int i = 0; - ret = DA_ERR_INVALID_MIME_TYPE; - DA_LOGV("No extension list"); -#ifdef _SAMSUNG_MIME_POLICY - for (i = 0; i < MAX_SEC_MIME_TABLE_INDEX; i++) - { - if (strncmp(sec_mime_table[i].mime, mime, strlen(mime)) == 0) { - strncpy(ext_temp, sec_mime_table[i].ext, DA_MAX_STR_LEN-1); - ret = DA_RESULT_OK; - break; - } - } -#endif - } else { /* For drm case, this else statement is needed */ -// DA_LOGD("extlist[%s]\n",*extlist); - strncpy(ext_temp, *extlist, DA_MAX_STR_LEN - 1); - /* If only one extension name is existed, don't enter here */ - while (*extlist != NULL) { - int i = 0; - /* If there are existed many extension names, - * try to search common extension name from table - * with first mime type at extension list*/ - for (i = 0; i < MAX_EXT_TABLE_INDEX; i++) - { - if (strncmp(ext_trans_table[i].standard,*extlist, - strlen(*extlist)) == 0) { - memset(ext_temp, 0x00, DA_MAX_STR_LEN); - strncpy(ext_temp,ext_trans_table[i].normal, DA_MAX_STR_LEN-1); - break; - } - } - DA_LOGV("index[%d]\n",i); - /* If there is a mime at extension transform table */ - if (i < MAX_EXT_TABLE_INDEX) { - break; - } -// DA_LOGD("extlist[%s]\n",*extlist); - extlist++; - } -// DA_SECURE_LOGD("extension from shared mime info[%s]",ext_temp); - } - - if (strlen(ext_temp) < 1) { - /* If there is no mime string for OMA descriptor mime type */ - if (strncmp(DD_MIME_STR, mime, strlen(DD_MIME_STR)) == 0) { - strncpy(ext_temp, DD_EXT_STR, DA_MAX_STR_LEN - 1); - ret = DA_RESULT_OK; - /* If there is no extension name for "applicaion/vnd.oma.drm.messeages" - * at shared-mime-info*/ - } else if (strncmp(DRM_MIME_MSG_STR, mime, strlen(DRM_MIME_MSG_STR)) == - 0) { - strncpy(ext_temp, DRM_EXT_STR, DA_MAX_STR_LEN - 1); - /* If there is extension name at extlist, the return value can have an error.*/ - ret = DA_RESULT_OK; - } else { - ret = DA_ERR_INVALID_MIME_TYPE; - DA_LOGI("Invalid mime type : no extension name at list"); - } - } - if (ret != DA_RESULT_OK) - goto ERR; - - temp = strchr(ext_temp,'.'); - if (temp == NULL) - temp = ext_temp; - else - temp++; - - DA_SECURE_LOGD("final extension name:[%s]",temp); - *ext = (char*)calloc(1, strlen(temp) + 1); - if (*ext != DA_NULL) { - strncpy(*ext, temp,strlen(temp)); - } else { - ret = DA_ERR_FAIL_TO_MEMALLOC ; - goto ERR ; - } -ERR: - return ret; -} - -da_bool_t da_get_extension_name_from_url(char *url, char **ext) -{ - da_bool_t ret = DA_TRUE; - char *buff = DA_NULL; - char *temp_str = DA_NULL; - int buf_len = 0; - - DA_LOGV(""); - - if (DA_NULL == url || DA_NULL == ext) { - ret = DA_FALSE; - DA_LOGE("Invalid Argument"); - return ret; - } - - if ((temp_str = strrchr(url,'/'))) { - if ((buff = strrchr(temp_str,'.'))) { - char *q = DA_NULL; - buff++; - /* check to exist "?" after extension name */ - q = strrchr(buff,'?'); - if (q) { - buf_len = strlen(buff) - strlen(q); - } else { - buf_len = strlen(buff); - } - *ext = (char*) calloc(1, buf_len + 1) ; - - if (DA_NULL == *ext) { - ret = DA_FALSE; - DA_LOGE("Memory Fail"); - goto ERR; - } - strncpy(*ext,buff,buf_len); - DA_SECURE_LOGD("extention name[%s]",*ext); - return ret; - } - } -ERR: - if (*ext) { - free(*ext); - *ext = DA_NULL; - } - return ret; -} - -/* FIXME move this function to another file */ -da_bool_t da_get_file_name_from_url(char *url, char **name) -{ - da_bool_t ret = DA_TRUE; - char *buff = DA_NULL; - char *Start = NULL; - char *End = NULL; - char c = 0; - int i = 0; - int j = 0; - int len_name = 0; - char name_buff[DA_MAX_FILE_PATH_LEN] = {0,}; - - DA_LOGV(""); - - if (DA_NULL == url || DA_NULL == name) { - ret = DA_FALSE; - DA_LOGE("Invalid Argument"); - goto ERR; - } - - if (!strstr(url, "http") && !strstr(url, "https")) { - ret = DA_FALSE; - DA_LOGE("Invalid Argument"); - goto ERR; - } - - buff = (char*) calloc(1, strlen(url) +1); - if(DA_NULL == buff) { - ret = DA_FALSE; - DA_LOGE("Memory Fail"); - goto ERR; - } - - while((c = url[i++]) != 0) { - if(c == '%') { - char buffer[3] = {0,}; - buffer[0] = url[i++]; - buffer[1] = url[i++]; - buff[j++] = (char)strtol(buffer,NULL,16); - } else { - buff[j++] = c; - } - } - End = strstr(buff, "?"); - if (DA_NULL != End) { - Start = End -1; - while(*(Start) != '/') { - Start--; - } - if ((*(Start) == '/') && ((len_name = (End - Start)) > 1)) { - Start++; - if (DA_MAX_FILE_PATH_LEN <= len_name) { - strncpy(name_buff, Start, DA_MAX_FILE_PATH_LEN-1); - name_buff[DA_MAX_FILE_PATH_LEN-1] = '\0'; - } else { - strncpy(name_buff, Start, len_name); - name_buff[len_name] = '\0'; - } - } else { - ret = DA_FALSE; - goto ERR ; /*Name not found*/ - } - } else { - int urlLen = strlen (buff); - int Start_pos = 0; - Start_pos = urlLen - 1; - - while(Start_pos > 0) { - if(buff[Start_pos] == '/') - break; - Start_pos--; - } - Start_pos++; - if (Start_pos == 0 || urlLen - Start_pos <= 0) { - ret = DA_FALSE; - goto ERR; - } - while(Start_pos < urlLen) { - name_buff[len_name++] = buff[Start_pos++]; - if (DA_MAX_FILE_PATH_LEN <= len_name) { - name_buff[DA_MAX_FILE_PATH_LEN-1] ='\0'; - break; - } - } - } - - if (len_name) { - End = strrchr(name_buff, '.'); - if (End != NULL) { - *End = '\0'; - } -// DA_SECURE_LOGD("file name BEFORE removing prohibited character = %s", name_buff); - delete_prohibited_char(name_buff, strlen(name_buff)); - len_name = strlen(name_buff); - *name = (char*) calloc(1, len_name + 1); - if (*name) { - strncpy(*name, name_buff,len_name); - } - } -// DA_SECURE_LOGD("Extracted file name : %s", *name); -ERR: - if (buff) { - free (buff); - buff = DA_NULL; - } - return ret; -} - -void delete_prohibited_char(char *szTarget, int str_len) -{ - char *chk_str = NULL; - int i = 0; - int j = 0; - int tar_len = 0; - - if(szTarget == NULL || str_len <= 0 || strlen(szTarget) != str_len) { - DA_LOGE("Invaild Parameter\n"); - return; - } - - chk_str = (char *)calloc(1, str_len + 1); - if(chk_str == NULL) - return; - - while(szTarget[j] != '\0') { - if(IS_PROHIBITED_CHAR(szTarget[j]) == DA_FALSE && - IS_SPACE_CHARACTER(szTarget[j]) == DA_FALSE) { - chk_str[i] = szTarget[j]; - i++; - } - j++; - } - - chk_str[i] = '\0'; - tar_len = strlen(chk_str); - - if(tar_len <= 0) - szTarget[0] = '\0'; - else { - for(i = 0; i < tar_len; i++) - { - szTarget[i] = chk_str[i]; - } - szTarget[i] = '\0'; - } - - if(chk_str != NULL) { - free(chk_str); - } - return; -} - -#ifdef _ENABLE_OMA_DRM -da_bool_t is_content_drm_dcf(char *content_type) -{ - if (content_type == DA_NULL) - return DA_FALSE; - - if (0 == strcmp(content_type, DRM_MIME_CONTENT_STR)) { - DA_LOGV("DRM_DM content"); - return DA_TRUE; - } else { - return DA_FALSE; - } -} - -da_bool_t is_content_drm_dm(char *content_type) -{ - if (content_type == DA_NULL) - return DA_FALSE; - - if (0 == strcmp(content_type, DRM_MIME_MSG_STR)) { - DA_LOGV("DRM_DM content"); - return DA_TRUE; - } else { - return DA_FALSE; - } -} -#endif - -da_ret_t get_extension_from_mime_type(char *mime_type, char **extension) -{ - da_ret_t ret = DA_RESULT_OK; - char *ext = DA_NULL; - - DA_LOGV(""); - if (DA_NULL == mime_type || DA_NULL == extension) { - DA_LOGE("received mime_type is null"); - ret = DA_ERR_INVALID_ARGUMENT; - goto ERR; - } -// DA_SECURE_LOGD("input mime type = %s", mime_type); - if (DA_RESULT_OK != (ret = da_mime_get_ext_name(mime_type, &ext))) { - DA_LOGE("can't find proper extension!"); - goto ERR; - } - *extension = ext; -// DA_SECURE_LOGD("found extension = %s", *extension); - -ERR: - return ret; -} - diff --git a/agent/download-agent-plugin-conf.c b/agent/download-agent-plugin-conf.c deleted file mode 100755 index 6cb76cb..0000000 --- a/agent/download-agent-plugin-conf.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string.h> -#include <stdlib.h> -#include <glib-object.h> -#include "vconf.h" -#include "vconf-keys.h" -#include "net_connection.h" - -#include "download-agent-plugin-conf.h" -#include "download-agent-debug.h" -#include "download-agent-file.h" - -#define DEFAULT_UA_STR "Mozilla/5.0 (Linux; U; Tizen 1.0; en-us) AppleWebKit/534.46 (KHTML, like Gecko) Mobile Tizen Browser/1.0" - -da_ret_t __get_conf_string(const char *key, char **out_string) -{ - if (!key || !out_string) { - DA_LOGE("Invalid Argument"); - return DA_ERR_INVALID_ARGUMENT; - } - - *out_string = vconf_get_str(key); - return DA_RESULT_OK; -} - -da_ret_t get_user_agent_string(char **uagent_str) -{ - da_ret_t ret = DA_RESULT_OK; - char *key = DA_NULL; - - DA_LOGV(""); - - if (!uagent_str) { - DA_LOGE("Invalid Argument"); - return DA_ERR_INVALID_ARGUMENT; - } - - key = VCONFKEY_BROWSER_USER_AGENT; - ret = __get_conf_string(key, uagent_str); - if(ret == DA_RESULT_OK) { - if(*uagent_str) { -// DA_SECURE_LOGD("getting uagent_str = \n%s", *uagent_str); - return ret; - } - } - DA_LOGI("No UA information from vconf !!"); - *uagent_str = strdup(DEFAULT_UA_STR); - DA_LOGV("Set default UA"); - return ret; -} - -char *get_proxy_address(void) -{ - char *proxy = NULL; - char *proxyRet = NULL; - connection_h handle = NULL; - connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4; - - DA_LOGV(""); - if (connection_create(&handle) < 0) { - DA_LOGE("Fail to create connection handle"); - return NULL; - } - - if (connection_get_proxy(handle, family, &proxyRet) < 0) { - DA_LOGE("Fail to get proxy address"); - connection_destroy(handle); - return NULL; - } - - if (proxyRet) { - DA_SECURE_LOGD("===== Proxy address[%s] =====", proxyRet); - proxy = strdup(proxyRet); - free(proxyRet); - proxyRet = NULL; - connection_destroy(handle); - return proxy; - } - - if (connection_destroy(handle) < 0) { - DA_LOGE("Fail to desctory connection handle"); - return NULL; - } - return NULL; -} -#ifdef _RAF_SUPPORT -// test code -void get_smart_bonding_vconf() -{ - int ret = 0; - vconf_get_int("file/private/wifi/network_bonding", &ret); - DA_LOGI("Smart Bonding Vconf:%d", ret); -} -#endif diff --git a/agent/download-agent-plugin-drm.c b/agent/download-agent-plugin-drm.c deleted file mode 100644 index 22e6f34..0000000 --- a/agent/download-agent-plugin-drm.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string.h> - -#include "drm_client.h" -#include "drm_client_types.h" -#include "drm_trusted_client.h" -#include "drm_trusted_client_types.h" - -#include "download-agent-debug.h" -#include "download-agent-plugin-drm.h" - - -void __EDRM_clean_up() -{ - int ret = 0; - ret = drm_trusted_handle_request(DRM_TRUSTED_REQ_TYPE_CLIENT_CLEAN_UP, NULL, NULL); - if (DRM_RETURN_SUCCESS == ret) { - DA_LOGD( "Clean up successfull"); - } else { - DA_LOGE("ret[%0x%x]",ret); - } -} - -da_bool_t EDRM_convert(const char *in_file_path, char **out_file_path) -{ - drm_trusted_conv_info_s input; - drm_trusted_conv_resp_info_s output; - size_t len = 0; - int ret = 0; - - memset(&input, 0x0, sizeof(drm_trusted_conv_info_s)); - memset(&output, 0x0, sizeof(drm_trusted_conv_resp_info_s)); - - len = strlen(in_file_path); - if (len >= sizeof(input.filePath)) - len = sizeof(input.filePath) - 1; - memcpy(input.filePath, in_file_path, len); - - ret = drm_trusted_convert_dm(&input, &output); - - if (DRM_TRUSTED_RETURN_SUCCESS != ret) { - DA_LOGE("ret[%0x%x]",ret); - __EDRM_clean_up(); - return DA_FALSE; - } else { - DA_SECURE_LOGD("Returned filePath[%s]", output.filePath); - *out_file_path = strdup(output.filePath); - } - __EDRM_clean_up(); - return DA_TRUE; -} - -da_ret_t EDRM_wm_get_license(char *rights_url, char **out_content_url) -{ - int ret = 0; - int len = 0; - drm_initiator_info_s init_info; - drm_web_server_resp_data_s resp_data; - - if (rights_url == NULL) - return DA_ERR_DRM_FAIL; - - memset(&init_info, 0, sizeof(init_info)); - memset(&resp_data, 0, sizeof(resp_data)); - strncpy(init_info.initiator_url, rights_url, - DRM_MAX_LEN_INITIATOR_URL - 1); - len = strlen(rights_url); - if (len > DRM_MAX_LEN_INITIATOR_URL - 1) - init_info.initiator_url_len = (unsigned int)len; - else - init_info.initiator_url_len = DRM_MAX_LEN_INITIATOR_URL; - ret = drm_process_request(DRM_REQUEST_TYPE_SUBMIT_INITIATOR_URL, - &init_info, &resp_data); - if (DRM_RETURN_SUCCESS == ret) { - DA_SECURE_LOGD("resp_data.content_url = %s", resp_data.content_url); - /* Rights or Domain Certificate are installed successfully */ - /* Check for contentURL */ - if (strlen(resp_data.content_url) > 0) { - char *content_url = NULL; - size_t content_url_len = 0; - content_url_len = strlen(resp_data.content_url); - content_url = (char *)calloc(1, content_url_len + 1); - if (content_url) { - strncpy(content_url, resp_data.content_url, - content_url_len); - *out_content_url = content_url; - DA_SECURE_LOGD("drm sumitted initiator url " - "succeeded with [%s]", *out_content_url); - __EDRM_clean_up(); - return DA_RESULT_OK; - } else { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - __EDRM_clean_up(); - return DA_ERR_FAIL_TO_MEMALLOC; - } - } else { - DA_LOGV("content_url is NULL.\ - Join/Leave Domain, Metering case."); - *out_content_url = DA_NULL; - __EDRM_clean_up(); - return DA_RESULT_OK; - } - } else { - DA_LOGE("drm_process_request() failed"); - __EDRM_clean_up(); - return DA_ERR_DRM_FAIL; - } -} - diff --git a/agent/download-agent-plugin-libcurl.c b/agent/download-agent-plugin-libcurl.c deleted file mode 100644 index 0c221d2..0000000 --- a/agent/download-agent-plugin-libcurl.c +++ /dev/null @@ -1,702 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include "glib.h" - -#include "download-agent-dl-info.h" -#include "download-agent-http-msg-handler.h" -#include "download-agent-plugin-libcurl.h" - -da_bool_t using_content_sniffing = DA_FALSE; - -int __translate_error_code(int curl_error) -{ - switch (curl_error) { - case CURLE_OPERATION_TIMEDOUT: - return DA_ERR_HTTP_TIMEOUT; - case CURLE_SSL_CONNECT_ERROR: - case CURLE_SSL_ENGINE_NOTFOUND: - case CURLE_SSL_ENGINE_SETFAILED: - case CURLE_SSL_CERTPROBLEM: - case CURLE_SSL_CIPHER: - case CURLE_SSL_CACERT: - case CURLE_SSL_ENGINE_INITFAILED: - case CURLE_SSL_CACERT_BADFILE: - case CURLE_SSH: - case CURLE_SSL_SHUTDOWN_FAILED: - case CURLE_SSL_CRL_BADFILE: - case CURLE_SSL_ISSUER_ERROR: - return DA_ERR_SSL_FAIL; - case CURLE_TOO_MANY_REDIRECTS: - return DA_ERR_TOO_MANY_REDIRECTS; - case CURLE_OUT_OF_MEMORY: - return DA_ERR_FAIL_TO_MEMALLOC; - case CURLE_UNSUPPORTED_PROTOCOL: - case CURLE_URL_MALFORMAT: - case CURLE_COULDNT_RESOLVE_PROXY: - case CURLE_COULDNT_RESOLVE_HOST: - case CURLE_COULDNT_CONNECT: - case CURLE_REMOTE_ACCESS_DENIED: - case CURLE_HTTP_POST_ERROR: - case CURLE_BAD_DOWNLOAD_RESUME: - return DA_ERR_CONNECTION_FAIL; - case CURLE_ABORTED_BY_CALLBACK: - return DA_RESULT_USER_CANCELED; - default: - return DA_ERR_NETWORK_FAIL; - } -} - -int my_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *user) -{ - switch(type) { - case CURLINFO_TEXT: - if (data) - DA_SECURE_LOGI("[curl] Info:%s", data); - break; - case CURLINFO_HEADER_OUT: - DA_LOGD("[curl] Send header"); - if (data) - DA_SECURE_LOGI("[curl] %s", data); - break; - case CURLINFO_DATA_OUT: - DA_LOGD("[curl] Send data"); - if (data) - DA_SECURE_LOGI("[curl] %s", data); - break; - case CURLINFO_SSL_DATA_OUT: - DA_LOGD("[curl] Send SSL data"); - break; - case CURLINFO_HEADER_IN: - DA_LOGD("[curl] Recv header"); - if (data) - DA_SECURE_LOGI("[curl] %s", data); - break; -#if 0 - case CURLINFO_DATA_IN: - DA_LOGD("[curl] Recv data"); - if (data) - DA_SECURE_LOGI("[curl] %d", strlen(data)); - break; -#endif - case CURLINFO_SSL_DATA_IN: - DA_SECURE_LOGI("[curl] Recv SSL data"); - break; - default: - return 0; - } - return 0; -} - -void __parse_raw_header(const char *raw_data, http_info_t *http_info) -{ - char *ptr = DA_NULL; - char *ptr2 = DA_NULL; - int len = 0; - char *field = DA_NULL; - char *value = DA_NULL; - http_msg_response_t *http_msg_response = NULL; - - if (!raw_data || !http_info) { - DA_LOGE("NULL Check!: raw_data or http_info"); - return; - } - - if (!http_info->http_msg_response) { - http_info->http_msg_response = (http_msg_response_t *)calloc(1, - sizeof(http_msg_response_t)); - if (!http_info->http_msg_response) { - DA_LOGE("Fail to calloc"); - return; - } - http_info->http_msg_response->head = DA_NULL; - } - http_msg_response = http_info->http_msg_response; - - ptr = strchr(raw_data, ':'); - if (!ptr) - return; - len = ptr - (char *)raw_data; - field = (char *)calloc(len + 1, sizeof(char)); - if (!field) { - DA_LOGE("Fail to calloc"); - return; - } - memcpy(field, raw_data, len); - field[len] = '\0'; - ptr++; - while(ptr) { - if (*ptr == ' ') - ptr++; - else - break; - } - ptr2 = strchr(raw_data, '\n'); - if (ptr2) { - len = ptr2 - ptr -1; - } else { - len = strlen(ptr); - } - value = (char *)calloc(len + 1, sizeof(char)); - if (!value) { - DA_LOGE("Fail to calloc"); - free(field); - return; - } - memcpy(value, ptr, len); - value[len] = '\0'; - http_msg_response_add_field(http_msg_response, field, value); - free(field); - free(value); -} - -void __store_header(void *msg, da_info_t *da_info, size_t header_size, - const char *sniffed_type) -{ - http_info_t *http_info = DA_NULL; - - if (!da_info || !msg) { - DA_LOGE("NULL Check!: da_info or msg"); - return; - } - http_info = da_info->http_info; - if (!http_info) { - DA_LOGE("NULL Check!: http_info"); - return; - } - - // FIXME later : check status code and redirection case check. - - if (strncmp(msg, HTTP_FIELD_END_OF_FIELD, - strlen(HTTP_FIELD_END_OF_FIELD)) == 0) { - long status = 0; - CURLcode res; - CURL *curl; - http_raw_data_t *raw_data = DA_NULL; - curl = http_info->http_msg->curl; - res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status); - if (res != CURLE_OK) { - DA_LOGE("Fail to get response status code"); - return; - } - DA_LOGV("status code[%d]", (int)status); - if (http_info->http_msg_response) { - http_info->http_msg_response->status_code = (int)status; - } - raw_data = (http_raw_data_t *)calloc(1, sizeof(http_raw_data_t)); - if (!raw_data) { - DA_LOGE("Fail to calloc"); - return; - } - - raw_data->status_code = (int)status; - raw_data->type = HTTP_EVENT_GOT_HEADER; - - if (http_info->update_cb) { - http_info->update_cb(raw_data, da_info); - } else { - free(raw_data); - } - return; - } - DA_LOGI("%s",(char *)msg); - __parse_raw_header((const char *)msg, http_info); -} - -size_t __http_gotheaders_cb(void *ptr, size_t size, size_t nmemb, void *userdata) -{ - da_info_t *da_info = DA_NULL; - if (!ptr || !userdata) { - DA_LOGE("Check NULL!: ptr, userdata"); - return 0; - } - da_info = (da_info_t *)userdata; - if (da_info->http_info && da_info->http_info->http_msg - && da_info->http_info->http_msg->is_cancel_reqeusted) { - DA_LOGI("Cancel requested"); - return -1; - } - if (!using_content_sniffing) - __store_header(ptr, da_info, (size * nmemb), DA_NULL); - else - DA_LOGV("ignore because content sniffing is turned on"); -/* -#ifdef _RAF_SUPPORT - DA_LOGI("[RAF] __http_gotheaders_cb done"); -#endif -*/ - return (size * nmemb); -} - -#ifdef _RAF_SUPPORT -da_ret_t PI_http_set_file_name_to_curl(http_msg_t *http_msg, char *file_path) -{ - NULL_CHECK_RET(http_msg); - NULL_CHECK_RET(file_path); - DA_LOGI("[RAF]set file_path[%s]", file_path); - curl_easy_setopt(http_msg->curl, CURLOPT_BOOSTER_RAF_FILE, file_path); - return DA_RESULT_OK; -} -#endif - -size_t __http_gotchunk_cb(void *ptr, size_t size, size_t nmemb, void *userdata) -{ - http_info_t *http_info = DA_NULL; - da_info_t *da_info = DA_NULL; - http_raw_data_t *raw_data = DA_NULL; - if (!ptr || !userdata) { - DA_LOGE("Check NULL!: ptr, stream"); - return 0; - } - da_info = (da_info_t *)userdata; - NULL_CHECK_RET_OPT(da_info, 0); - http_info = da_info->http_info; - NULL_CHECK_RET_OPT(http_info, 0); - NULL_CHECK_RET_OPT(http_info->http_msg, 0); - if (da_info->http_info->http_msg->is_cancel_reqeusted) { - DA_LOGI("Cancel requested"); - return -1; - } - //DA_LOGV("size=%ld, nmemb=%ld, datalen=%ld", size, nmemb, strlen((const char *)ptr)); -#ifdef _RAF_SUPPORT - //DA_LOGI("size=%ld, nmemb=%ld, datalen=%ld", size, nmemb, strlen((const char *)ptr)); - if (http_info->is_raf_mode_confirmed) { - DA_LOGI("[RAF] return chunked callback"); - return (size * nmemb); - } -#endif - - if (ptr && size * nmemb > 0) { - if (http_info->update_cb) { - raw_data = (http_raw_data_t *)calloc(1, sizeof(http_raw_data_t)); - if (!raw_data) { - DA_LOGE("Fail to calloc"); - return 0; - } - raw_data->body = (char *)calloc(size, nmemb); - if (!(raw_data->body)) { - DA_LOGE("Fail to calloc"); - free(raw_data); - return 0; - } - memcpy(raw_data->body, ptr, size * nmemb); - raw_data->body_len = size*nmemb; - raw_data->type = HTTP_EVENT_GOT_PACKET; - http_info->update_cb(raw_data, da_info); - } - } - return (size * nmemb); -} - -long __http_finished_cb(void *ptr) -{ - if (!ptr) { - DA_LOGE("Check NULL!: ptr"); - return CURL_CHUNK_END_FUNC_FAIL; - } - DA_LOGI(""); - return CURL_CHUNK_END_FUNC_OK; -} - - -da_ret_t __set_proxy_on_soup_session(char *proxy_addr, CURL *curl) -{ - da_ret_t ret = DA_RESULT_OK; - - if (proxy_addr && strlen(proxy_addr) > 0) { - DA_SECURE_LOGI("received proxy[%s]", proxy_addr); - if (!strstr(proxy_addr, "0.0.0.0")) { - if (strstr((const char *)proxy_addr, "http") == DA_NULL) { - char *tmp_str = DA_NULL; - int needed_len = 0; - - needed_len = strlen(proxy_addr) + strlen( - SCHEME_HTTP) + 1; - tmp_str = (char *) calloc(1, needed_len); - if (!tmp_str) { - DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC"); - ret = DA_ERR_FAIL_TO_MEMALLOC; - goto ERR; - } - snprintf(tmp_str, needed_len, "%s%s", - SCHEME_HTTP, proxy_addr); - - curl_easy_setopt(curl, CURLOPT_PROXY, proxy_addr); - - free(tmp_str); - } else { - DA_LOGV("There is \"http\" on uri, so, push this address to soup directly."); - curl_easy_setopt(curl, CURLOPT_PROXY, proxy_addr); - } - } - } -ERR: - return ret; -} - -struct curl_slist *__fill_soup_msg_header(CURL *curl, http_info_t *info) -{ - http_msg_request_t *input_http_msg_request; - struct curl_slist *headers = DA_NULL; - - if (!curl) { - DA_LOGE("NULL Check!: curl"); - return DA_NULL; - } - input_http_msg_request = info->http_msg_request; - - if (input_http_msg_request) { - char *field = DA_NULL; - char *value = DA_NULL; - char *buff = DA_NULL; - int len = 0; - http_header_t *cur = DA_NULL; - cur = input_http_msg_request->head; - while (cur) { - field = cur->field; - value = cur->value; - if (field && value) { - len = strlen(field) + strlen(value) + 1; - buff = (char *)calloc(len + 1, sizeof(char)); - if (!buff) { - DA_LOGE("Fail to memalloc"); - break; - } -// DA_SECURE_LOGI("[%s] %s", field, value); - snprintf(buff, len + 1, "%s:%s", field, value); - headers = curl_slist_append(headers, (const char *)buff); - free(buff); - buff = DA_NULL; - } - cur = cur->next; - } - } else { - DA_LOGE("NULL Check!: input_http_msg_request"); - return DA_NULL; - } - if (input_http_msg_request->http_body) { - char buff[256] = {0,}; - int body_len = strlen(input_http_msg_request->http_body); - snprintf(buff, sizeof(buff), "%s:%d", HTTP_FIELD_CONTENT_LENGTH, - body_len); - headers = curl_slist_append(headers, buff); - memset(buff, 0x00, 256); - snprintf(buff, sizeof(buff), "%s:text/plain", HTTP_FIELD_CONTENT_TYPE); - headers = curl_slist_append(headers, buff); - headers = curl_slist_append(headers, input_http_msg_request->http_body); - } - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - return headers; -} - -#ifdef _RAF_SUPPORT -int __http_progress_cb(void *clientp, double dltotal, double dlnow, - double ultotal, double ulnow) -{ - da_info_t *da_info = DA_NULL; - http_info_t *http_info = DA_NULL; - http_raw_data_t *raw_data = DA_NULL; -/* - if (dlnow > 0 || ulnow > 0) - DA_LOGI("[RAF]dlnow/ulnow[%llu/%llu][%llu,%llu]", (da_size_t)dlnow, (da_size_t)ulnow, (da_size_t)dltotal, (da_size_t)ultotal); -*/ - -/* - if (dlnow == 0) { - DA_LOGI("[RAF]dlnow is zero. Why is this callback called although there is zero size?"); - } -*/ - NULL_CHECK_RET_OPT(clientp, -1); - da_info = (da_info_t *)clientp; - http_info = da_info->http_info; - NULL_CHECK_RET_OPT(http_info, -1); - NULL_CHECK_RET_OPT(http_info->http_msg, -1); - - if (http_info->http_msg->is_cancel_reqeusted) { - DA_LOGI("Cancel requested"); - return -1; - } - - if (dlnow > 0) { - if (http_info->update_cb) { - raw_data = (http_raw_data_t *)calloc(1, sizeof(http_raw_data_t)); - if (!raw_data) { - DA_LOGE("Fail to calloc"); - return 0; - } - raw_data->received_len = (da_size_t)dlnow; - raw_data->type = HTTP_EVENT_GOT_PACKET; - http_info->update_cb(raw_data, da_info); - } - } - return CURLE_OK; -} -#endif - -da_ret_t PI_http_start(da_info_t *da_info) -{ - da_ret_t ret = DA_RESULT_OK; - http_method_t http_method; - CURL *curl = DA_NULL; - CURLcode res; - http_msg_t *http_msg = DA_NULL; - char *url = DA_NULL; - http_info_t *http_info = DA_NULL; - long http_status = 0; - struct curl_httppost* post = NULL; - struct curl_slist *headers = DA_NULL; - char err_buffer[CURL_ERROR_SIZE] = {0,}; - - DA_LOGV(""); -#ifdef _RAF_SUPPORT - // test code - get_smart_bonding_vconf(); -#endif - NULL_CHECK_GOTO(da_info); - NULL_CHECK_GOTO(da_info->req_info); - url = da_info->req_info->url; - NULL_CHECK_GOTO(url); - http_info = da_info->http_info; - NULL_CHECK_GOTO(http_info); - - http_method = http_info->http_method; - ret = init_http_msg_t(&http_msg); - if (ret != DA_RESULT_OK) - goto ERR; - http_info->http_msg = http_msg; - - curl_global_init(CURL_GLOBAL_ALL); - curl = curl_easy_init(); - - if (!curl) { - DA_LOGE("Fail to create curl"); - return DA_ERR_FAIL_TO_MEMALLOC; - } - DA_LOGI("curl[%p]", curl); - - curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, MAX_SESSION_COUNT); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, MAX_TIMEOUT); - - __set_proxy_on_soup_session(http_info->proxy_addr, curl); - - curl_easy_setopt(curl, CURLOPT_URL, url); - switch (http_method) { - case HTTP_METHOD_GET: - curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); - break; - case HTTP_METHOD_POST: - // FIXME later : If the post method is supprot, the post data should be set with curl_fromadd - curl_easy_setopt(curl, CURLOPT_HTTPPOST, post); - DA_LOGI("Need more information for post filed"); - break; - case HTTP_METHOD_HEAD: - DA_LOGI("Donnot implement yet"); - break; - default: - DA_LOGE("Cannot enter here"); - break; - } - - if (using_content_sniffing) { - /* FIXME later*/ - } else { - /* FIXME later*/ - } - headers = __fill_soup_msg_header(curl, http_info); - - curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, __http_gotheaders_cb); // can replace to started_cb - curl_easy_setopt(curl, CURLOPT_HEADERDATA, da_info); // param .. same with CURLOPT_WRITEHEADER - curl_easy_setopt(curl, CURLOPT_HEADER, 0L); // does not include header to body - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, __http_gotchunk_cb); // can replace to progress_ - curl_easy_setopt(curl, CURLOPT_WRITEDATA, da_info); // param .. same with CURLOPT_WRITEHEADERcb - curl_easy_setopt(curl, CURLOPT_CHUNK_END_FUNCTION, __http_finished_cb); - curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, da_info); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); -// curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace); - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err_buffer); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); -#ifdef _RAF_SUPPORT - curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, __http_progress_cb); - curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, da_info); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); -#endif - - if (da_info->req_info->network_bonding) { -#ifdef _DOWNLOAD_BOOSTER_SUPPORT - DA_LOGI("network bonding enable"); - curl_easy_setopt(curl, CURLOPT_MULTIRAT_NEEDED, 1L); -#endif -#ifdef _RAF_SUPPORT - curl_easy_setopt(curl, CURLOPT_BOOSTER_RAF_MODE, 1L); -#endif - } - http_msg->curl = curl; - res = curl_easy_perform(curl); - DA_LOGD("perform done! res[%d]",res); - if (res != CURLE_OK) { - //DA_LOGE("Fail to send data :%d[%s]", res, curl_easy_strerror(res)); - DA_LOGE("Fail to perform :%d[%s]", res, curl_multi_strerror(res)); - if (strlen(err_buffer) > 1) - DA_LOGE("Fail to error buffer[%s]", err_buffer); - } - if (res != CURLE_OK) { - //DA_LOGE("Fail to send data :%d[%s]", res, curl_easy_strerror(res)); - DA_LOGE("Fail to send data :%d[%s]", res, curl_easy_strerror(res)); - if (strlen(err_buffer) > 1) - DA_LOGE("Fail to error buffer[%s]", err_buffer); - } else { - res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status); - if (res != CURLE_OK) { - //DA_LOGE("Fail to get response code:%d[%s]", res, curl_easy_strerror(res)); - DA_LOGE("Fail to get response code:%d[%s]", res, curl_easy_strerror(res)); - ret = DA_ERR_FAIL_TO_MEMALLOC;; - goto ERR; - } else { - DA_LOGD("Response Http Status code[%d]", (int)http_status); - } - } - if (http_info->update_cb) { - http_raw_data_t *raw_data = DA_NULL; - raw_data = (http_raw_data_t *)calloc(1, sizeof(http_raw_data_t)); - if (!raw_data) { - DA_LOGE("Fail to calloc"); - ret = DA_ERR_FAIL_TO_MEMALLOC; - goto ERR; - } - if (http_msg->is_cancel_reqeusted || - res == CURLE_ABORTED_BY_CALLBACK) { - DA_LOGI("canceled exit. Err[%d]", http_info->error_code); - if (http_info->error_code < 0) - ret = http_info->error_code; - else - ret = DA_RESULT_USER_CANCELED; - } else if ((http_status > 0 && http_status < 100)) { - raw_data->error = __translate_error_code(res); - ret = DA_ERR_NETWORK_FAIL; - } else if (res != CURLE_OK) { - raw_data->error = __translate_error_code(res); - ret = DA_ERR_NETWORK_FAIL; - } else { - raw_data->status_code = (int)http_status; - } - raw_data->type = HTTP_EVENT_FINAL; - http_info->update_cb(raw_data, da_info); - } - if (DA_NULL != headers) - curl_slist_free_all(headers); - curl_easy_cleanup(curl); - http_msg->curl = DA_NULL; - DA_MUTEX_INIT(&(http_msg->mutex), DA_NULL); -ERR: - DA_LOGD("Done"); - return ret; - -} - -da_ret_t PI_http_disconnect(http_info_t *info) -{ - da_ret_t ret = DA_RESULT_OK; - http_msg_t *http_msg = DA_NULL; - - DA_LOGD(""); - NULL_CHECK_RET(info); - http_msg = info->http_msg; - NULL_CHECK_RET(http_msg); - DA_LOGV("session [%p]", http_msg->curl); - DA_MUTEX_LOCK(&(http_msg->mutex)); - if (http_msg->is_paused) - PI_http_unpause(info); - if (http_msg->curl) - curl_easy_cleanup(http_msg->curl); - - http_msg->curl = DA_NULL; - http_msg->is_paused = DA_FALSE; - http_msg->is_cancel_reqeusted = DA_FALSE; - DA_MUTEX_UNLOCK(&(http_msg->mutex)); - DA_MUTEX_DESTROY(&(http_msg->mutex)); - destroy_http_msg_t(http_msg); - info->http_msg = DA_NULL; - return ret; -} - -da_ret_t PI_http_cancel(http_info_t *info) -{ - da_ret_t ret = DA_RESULT_OK; - http_msg_t *http_msg = DA_NULL; - - DA_LOGV(""); - - NULL_CHECK_RET(info); - http_msg = info->http_msg; - NULL_CHECK_RET(http_msg); - NULL_CHECK_RET(http_msg->curl); - DA_MUTEX_LOCK(&(http_msg->mutex)); - DA_LOGI("curl[%p]", http_msg->curl); - http_msg->is_cancel_reqeusted = DA_TRUE; - DA_MUTEX_UNLOCK(&(http_msg->mutex)); - DA_LOGD("Done - soup cancel"); - return ret; -} - -da_ret_t PI_http_pause(http_info_t *info) -{ - da_ret_t ret = DA_RESULT_OK; - http_msg_t *http_msg = DA_NULL; - CURLcode res = CURLE_OK; - DA_LOGV(""); - - NULL_CHECK_RET(info); - http_msg = info->http_msg; - NULL_CHECK_RET(http_msg); - DA_LOGD("curl [%p]", http_msg->curl); - NULL_CHECK_RET(http_msg->curl); - DA_MUTEX_LOCK(&(http_msg->mutex)); - DA_LOGE("curl_easy_pause call"); - curl_easy_pause(http_msg->curl, CURLPAUSE_ALL); - DA_LOGE("curl_easy_pause:%d", res); - if (res == CURLE_OK) { - http_msg->is_paused = DA_TRUE; - } else { - ret = DA_ERR_CANNOT_SUSPEND; - } - DA_MUTEX_UNLOCK(&(http_msg->mutex)); - return ret; -} - -da_ret_t PI_http_unpause(http_info_t *info) -{ - da_ret_t ret = DA_RESULT_OK; - http_msg_t *http_msg = DA_NULL; - CURLcode res = CURLE_OK; - DA_LOGV(""); - - NULL_CHECK_RET(info); - http_msg = info->http_msg; - DA_LOGV("curl [%p]", http_msg->curl); - NULL_CHECK_RET(http_msg->curl); - DA_MUTEX_LOCK(&(http_msg->mutex)); - res = curl_easy_pause(http_msg->curl, CURLPAUSE_CONT); - if (res == CURLE_OK) - http_msg->is_paused = DA_FALSE; - else - ret = DA_ERR_CANNOT_RESUME; - DA_MUTEX_UNLOCK(&(http_msg->mutex)); - return ret; -} diff --git a/agent/include/download-agent-client-mgr.h b/agent/include/download-agent-client-mgr.h deleted file mode 100755 index b2ce1c8..0000000 --- a/agent/include/download-agent-client-mgr.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DOWNLOAD_AGENT_CLIENT_MGR_H -#define DOWNLOAD_AGENT_CLIENT_MGR_H - -#include "download-agent-dl-info.h" - -da_ret_t send_client_paused_info(da_info_t *da_info); -da_ret_t send_client_update_dl_info(da_info_t *da_info); -da_ret_t send_client_update_progress_info(da_info_t *da_info); -da_ret_t send_client_finished_info(da_info_t *da_info, int err); - -#endif diff --git a/agent/include/download-agent-debug.h b/agent/include/download-agent-debug.h deleted file mode 100755 index 23c2a66..0000000 --- a/agent/include/download-agent-debug.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _DOWNLOAD_AGENT_DEBUG_H -#define _DOWNLOAD_AGENT_DEBUG_H - -#include "download-agent-type.h" - -#include <stdio.h> -#include <stdarg.h> -#include <pthread.h> - -// ansi color -#define COLOR_RED "\033[0;31m" -#define COLOR_GREEN "\033[0;32m" -#define COLOR_BROWN "\033[0;33m" -#define COLOR_LIGHTBLUE "\033[0;37m" -#define COLOR_END "\033[0;m" - -#ifdef _ENABLE_DLOG -#include <unistd.h> -#include <syscall.h> -#include <dlog.h> - - #ifdef LOG_TAG - #undef LOG_TAG - #endif /* LOG_TAG */ - - #define LOG_TAG "DP_DA" - #define DA_LOGV(format, ...) ((void)0)//LOGD("[%d]:"format, syscall(__NR_gettid), ##__VA_ARGS__) - #define DA_LOGD(format, ...) LOGD(COLOR_LIGHTBLUE "[%d]:"format COLOR_END, syscall(__NR_gettid), ##__VA_ARGS__) - #define DA_LOGI(format, ...) LOGI(COLOR_BROWN "[%d]:"format COLOR_END, syscall(__NR_gettid), ##__VA_ARGS__) - #define DA_LOGE(format, ...) LOGE(COLOR_RED "[%d]:"format COLOR_END, syscall(__NR_gettid), ##__VA_ARGS__) - #define DA_SECURE_LOGD(format, ...) SECURE_LOGD(COLOR_GREEN format COLOR_END, ##__VA_ARGS__) - #define DA_SECURE_LOGI(format, ...) SECURE_LOGI(COLOR_GREEN format COLOR_END, ##__VA_ARGS__) - #define DA_SECURE_LOGE(format, ...) SECURE_LOGE(COLOR_GREEN format COLOR_END, ##__VA_ARGS__) -#else - -#include <unistd.h> -#include <syscall.h> - - #define DA_LOGD(format, ...) do {\ - fprintf(stderr, "[DA][%d][%s():%d] "format"\n",syscall(__NR_gettid), __FUNCTION__,__LINE__, ##__VA_ARGS__);\ - }while(0) - #define DA_LOGE(format, ...) do {\ - fprintf(stderr, "[DA][%d][ERR][%s():%d]\n",syscall(__NR_gettid), __FUNCTION__,__LINE__, ##__VA_ARGS__);\ - }while(0) - #define DA_LOGV DA_LOGD - #define DA_LOGI DA_LOGD - #define DA_SECURE_LOGD(format, ...) ((void)0) - #define DA_SECURE_LOGI(format, ...) ((void)0) - #define DA_SECURE_LOGE(format, ...) ((void)0) -#endif /* _ENABLE_DLOG */ - -#endif /* DOWNLOAD_AGENT_DEBUG_H */ diff --git a/agent/include/download-agent-defs.h b/agent/include/download-agent-defs.h deleted file mode 100755 index d5b6a5e..0000000 --- a/agent/include/download-agent-defs.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _DOWNLOAD_AGENT_DEFS_H -#define _DOWNLOAD_AGENT_DEFS_H - -#ifndef DEPRECATED -#define DEPRECATED __attribute__((deprecated)) -#endif - -/** - * Max count to download files simultaneously. \n - * Main reason for this restriction is because of Network bandwidth. - */ -#define DA_MAX_DOWNLOAD_REQ_AT_ONCE 50 -#define DA_MAX_TIME_OUT 65 - -#define DA_RESULT_OK 0 - -#define DA_TRUE 1 -#define DA_FALSE 0 -#define DA_NULL (void *)0 -#define DA_INVALID_ID -1 - -#define DA_RESULT_USER_CANCELED -10 - -// InputError Input error (-100 ~ -199) -// Client passed wrong parameter -#define DA_ERR_INVALID_ARGUMENT -100 -#define DA_ERR_INVALID_DL_REQ_ID -101 -#define DA_ERR_INVALID_URL -103 -#define DA_ERR_INVALID_INSTALL_PATH -104 -#define DA_ERR_INVALID_MIME_TYPE -105 - -// Client passed correct parameter, but Download Agent rejects the request because of internal policy. -#define DA_ERR_ALREADY_CANCELED -160 -#define DA_ERR_ALREADY_SUSPENDED -161 -#define DA_ERR_ALREADY_RESUMED -162 -#define DA_ERR_CANNOT_SUSPEND -170 -#define DA_ERR_CANNOT_RESUME -171 -#define DA_ERR_INVALID_STATE -190 -#define DA_ERR_ALREADY_MAX_DOWNLOAD -191 -#define DA_ERR_UNSUPPORTED_PROTOCAL -192 - -// System error (-200 ~ -299) -#define DA_ERR_FAIL_TO_MEMALLOC -200 -#define DA_ERR_FAIL_TO_CREATE_THREAD -210 -#define DA_ERR_FAIL_TO_ACCESS_FILE -230 -#define DA_ERR_DISK_FULL -240 - -// Network error (-400 ~ -499) -#define DA_ERR_NETWORK_FAIL -400 -#define DA_ERR_UNREACHABLE_SERVER -410 -#define DA_ERR_CONNECTION_FAIL -420 -#define DA_ERR_HTTP_TIMEOUT -430 -#define DA_ERR_SSL_FAIL -440 -#define DA_ERR_TOO_MANY_REDIRECTS -450 -#define DA_ERR_NETWORK_UNAUTHORIZED -460 - -// HTTP error - not conforming with HTTP spec (-500 ~ -599) -#define DA_ERR_MISMATCH_CONTENT_TYPE -500 -#define DA_ERR_SERVER_RESPOND_BUT_SEND_NO_CONTENT -501 -#define DA_ERR_MISMATCH_CONTENT_SIZE -502 - -// DRM error - not conforming with DRM spec (-600 ~ -699) -#define DA_ERR_DRM_FAIL -600 - -// string to check invalid characters in path before using open() and fopen() API's -#define DA_INVALID_PATH_STRING ";\\\":*?<>|()" - -#endif - diff --git a/agent/include/download-agent-dl-info.h b/agent/include/download-agent-dl-info.h deleted file mode 100644 index 820135e..0000000 --- a/agent/include/download-agent-dl-info.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _DOWNLOAD_AGENT_INFO_H -#define _DOWNLOAD_AGENT_INFO_H - -#include "download-agent-type.h" -#include "download-agent-interface.h" -#include "download-agent-pthread.h" - -#include "curl/curl.h" - -typedef struct { - CURL *curl; - pthread_mutex_t mutex; - da_bool_t is_paused; - da_bool_t is_cancel_reqeusted; -} http_msg_t; - -typedef enum { - HTTP_STATE_READY_TO_DOWNLOAD = 0, - HTTP_STATE_REDIRECTED = 1, - HTTP_STATE_DOWNLOAD_REQUESTED = 2, - HTTP_STATE_DOWNLOAD_STARTED = 3, - HTTP_STATE_DOWNLOADING = 4, - HTTP_STATE_DOWNLOAD_FINISH = 5, - HTTP_STATE_REQUEST_CANCEL = 6, - HTTP_STATE_REQUEST_PAUSE = 7, - HTTP_STATE_REQUEST_RESUME = 8, - HTTP_STATE_CANCELED = 9, - HTTP_STATE_FAILED = 10, - HTTP_STATE_PAUSED = 11, - HTTP_STATE_RESUMED = 12, - HTTP_STATE_ABORTED = 13, - HTTP_STATE_WAIT_FOR_NET_ERR = 14, -} http_state_t; - -typedef enum { - HTTP_METHOD_GET = 1, - HTTP_METHOD_HEAD, - HTTP_METHOD_POST -} http_method_t; - -typedef struct { - char *url; - char **req_header; - int req_header_count; - char *install_path; - char *file_name; - char *etag; - char *temp_file_path; - char *pkg_name; - int network_bonding; - void *user_req_data; - void *user_client_data; -} req_info_t; - -typedef enum { - HTTP_EVENT_GOT_HEADER = 0, - HTTP_EVENT_GOT_PACKET, - HTTP_EVENT_FINAL, -// HTTP_EVENT_ABORT -} http_event_type_t; - -typedef struct _http_header_options_t http_header_options_t; -struct _http_header_options_t{ - char *field; - char *value; - http_header_options_t *next; -}; - -typedef struct _http_header_t http_header_t; -typedef http_header_t *http_msg_iter_t; -struct _http_header_t{ - char *field; - char *value; - http_header_options_t *options; - char *raw_value; // raw string including options - http_header_t *next; -}; - -typedef struct{ - char *http_method; - char *url; - http_header_t *head; - char *http_body; -} http_msg_request_t; - - -typedef struct{ - int status_code; - http_header_t *head; -} http_msg_response_t; - -typedef struct { - http_event_type_t type; - char *body; - int body_len; -#ifdef _RAF_SUPPORT - da_size_t received_len; -#endif - int status_code; - int error; -} http_raw_data_t; - -typedef void (*http_update_cb) (http_raw_data_t *data, void *user_param); - -typedef struct { - char *location_url; - http_state_t state; - pthread_mutex_t mutex_state; - pthread_mutex_t mutex_http; - pthread_cond_t cond_http; - http_msg_request_t *http_msg_request; - http_msg_response_t *http_msg_response; - http_method_t http_method; - http_msg_t *http_msg; - char *proxy_addr; - char *content_type_from_header; - char *file_name_from_header; - da_size_t content_len_from_header; - char *etag_from_header; - int error_code; // for error value for http abort. - da_size_t total_size; -#ifdef _RAF_SUPPORT - da_bool_t is_raf_mode_confirmed; -#endif - http_update_cb update_cb; -} http_info_t; - -typedef struct { - void *file_handle; - char *pure_file_name; - char *extension; - char *file_path; /* malloced in set_file_path_for_final_saving */ - char *mime_type;// For drm converting - char *buffer; - da_size_t buffer_len; - da_size_t file_size; /* http header's Content-Length has higher priority than DD's <size> */ - da_size_t bytes_written_to_file; /* The file size to be written at actual file */ -#ifdef _RAF_SUPPORT - da_size_t file_size_of_temp_file; /* If the temporary file is existed, the file size of it */ -#endif - da_bool_t is_updated; /* The flag for updating progress event only if the data is wrriten to file not buffer */ -} file_info_t; - -typedef struct { - int da_id; - int tid; - pthread_t thread_id; - http_info_t *http_info; - file_info_t *file_info; - req_info_t *req_info; - da_cb_t cb_info; - da_bool_t is_cb_update; - int update_time; -} da_info_t; - -da_info_t *da_info_list[DA_MAX_ID]; - -#define GET_STATE_MUTEX(INFO) (INFO->mutex_state) -#define GET_STATE(INFO) (INFO->state) -#define CHANGE_STATE(STATE,INFO) {\ - DA_MUTEX_LOCK (&GET_STATE_MUTEX(INFO));\ - GET_STATE(INFO) = STATE;\ - DA_LOGV("Changed state[%d]", GET_STATE(INFO));\ - DA_MUTEX_UNLOCK (&GET_STATE_MUTEX(INFO));\ - } - -da_ret_t get_available_da_id(int *available_id); -da_ret_t copy_user_input_data(da_info_t *da_info, const char *url, - req_data_t *ext_data, da_cb_t *da_cb_data); -da_bool_t is_valid_download_id(int id); -void destroy_da_info(int id); -void destroy_da_info_list(void); -da_ret_t get_da_info_with_da_id(int id, da_info_t **out_info); -da_ret_t init_http_msg_t(http_msg_t **http_msg); -void destroy_http_msg_t(http_msg_t *http_msg); -void reset_http_info(http_info_t *http_info); -void reset_http_info_for_resume(http_info_t *http_info); -void destroy_http_info(http_info_t *http_info); -void destroy_file_info(file_info_t *file_info); - -#endif /* _DOWNLOAD_AGENT_INFO_H */ diff --git a/agent/include/download-agent-dl-mgr.h b/agent/include/download-agent-dl-mgr.h deleted file mode 100755 index c6be7c7..0000000 --- a/agent/include/download-agent-dl-mgr.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _Download_Agent_Basic_H -#define _Download_Agent_Basic_H - -#include "download-agent-dl-info.h" - -da_ret_t start_download(da_info_t *da_info); -da_ret_t cancel_download(int dl_id, da_bool_t is_enable_cb); -da_ret_t suspend_download(int dl_id, da_bool_t is_enable_cb); -da_ret_t resume_download(int dl_id); - -#endif diff --git a/agent/include/download-agent-encoding.h b/agent/include/download-agent-encoding.h deleted file mode 100755 index 49e74e9..0000000 --- a/agent/include/download-agent-encoding.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _Download_Agent_Encoding_H -#define _Download_Agent_Encoding_H - -#include "download-agent-type.h" - -da_bool_t is_base64_encoded_word(const char *in_str); -da_ret_t decode_base64_encoded_str(const char *in_encoded_str, - char **out_decoded_ascii_str); -void decode_url_encoded_str(const char *in_encoded_str, char **out_str); - -#endif // _Download_Agent_Encoding_H diff --git a/agent/include/download-agent-file.h b/agent/include/download-agent-file.h deleted file mode 100755 index 2788fdd..0000000 --- a/agent/include/download-agent-file.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _DOWNLOAD_AGENT_FILE_H -#define _DOWNLOAD_AGENT_FILE_H - -#include <stdio.h> -#include <sys/types.h> -#include <sys/stat.h> - -#include "download-agent-type.h" -#include "download-agent-dl-info.h" - -#define DA_FILE_BUF_SIZE (1024*32) //bytes - -da_ret_t check_drm_convert(file_info_t *file_info); -da_bool_t is_file_exist(const char *file_path); -void get_file_size(char *file_path, da_size_t *out_file_size); -da_ret_t file_write_ongoing(file_info_t *file_info, char *body, int body_len); -da_ret_t file_write_complete(file_info_t *file_info); -#ifdef _RAF_SUPPORT -da_ret_t file_write_complete_for_raf(file_info_t *file_info); -#endif -da_ret_t start_file_writing(da_info_t *da_info); -da_ret_t start_file_append(file_info_t *file_info); -da_ret_t discard_download(file_info_t *file_info) ; -void clean_paused_file(file_info_t *file_info); -char *get_full_path_avoided_duplication(char *in_dir, - char *in_candidate_file_name, char *in_extension); -void remove_file(const char *file_path); -da_ret_t get_available_memory(char *dir_path, da_size_t len); -#endif diff --git a/agent/include/download-agent-http-mgr.h b/agent/include/download-agent-http-mgr.h deleted file mode 100755 index 95a0b3a..0000000 --- a/agent/include/download-agent-http-mgr.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _Download_Agent_Http_Mgr_H -#define _Download_Agent_Http_Mgr_H - -#include <string.h> - -#include "download-agent-type.h" -#include "download-agent-dl-mgr.h" - -#define DA_MAX_SESSION_INFO DA_MAX_DOWNLOAD_ID - -da_ret_t request_http_download(da_info_t *da_info); -da_ret_t request_to_cancel_http_download(da_info_t *da_info); -da_ret_t request_to_abort_http_download(da_info_t *da_info); -da_ret_t request_to_suspend_http_download(da_info_t *da_info); -da_ret_t request_to_resume_http_download(da_info_t *da_info); -da_bool_t is_stopped_state(da_info_t *da_info); - -#endif diff --git a/agent/include/download-agent-http-msg-handler.h b/agent/include/download-agent-http-msg-handler.h deleted file mode 100755 index 70abbda..0000000 --- a/agent/include/download-agent-http-msg-handler.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _Download_Agent_Http_Msg_Handler_H -#define _Download_Agent_Http_Msg_Handler_H - -#include "download-agent-type.h" -#include "download-agent-dl-info.h" - -// Reqeust Header -#define HTTP_FIELD_UAGENT "User-Agent" -#define HTTP_FIELD_HOST "Host" -#define HTTP_FIELD_UAPROF "X-Wap-Profile" -#define HTTP_FIELD_IF_MATCH "If-Match" -#define HTTP_FIELD_RANGE "Range" -#define HTTP_FIELD_IF_RANGE "If-Range" -#define HTTP_FIELD_ACCEPT_LANGUAGE "Accept-Language" -#define HTTP_FIELD_ACCEPT_CHARSET "Accept-Charset" - -// Response Header -#define HTTP_FIELD_CONTENT_LENGTH "Content-Length" -#define HTTP_FIELD_CONTENT_TYPE "Content-Type" -#define HTTP_FIELD_CONTENT_DISPOSITION "Content-Disposition" -#define HTTP_FIELD_LOCATION "Location" -#define HTTP_FIELD_DATA "Date" -#define HTTP_FIELD_ETAG "ETag" -#ifdef _RAF_SUPPORT -#define HTTP_FIELD_RAF_MODE "x-direct-write" -#endif - -#define HTTP_FIELD_END_OF_FIELD "\r\n" - -da_ret_t http_msg_request_create(http_msg_request_t **http_msg_request); -void http_msg_request_destroy(http_msg_request_t **http_msg_request); -da_ret_t http_msg_request_set_url(http_msg_request_t *http_msg_request, const char *url); -da_ret_t http_msg_request_get_url(http_msg_request_t *http_msg_request, const char **url); -da_ret_t http_msg_request_add_field(http_msg_request_t *http_msg_request, const char *field, const char *value); - -da_ret_t http_msg_response_create(http_msg_response_t **http_msg_response); -void http_msg_response_destroy(http_msg_response_t **http_msg_response); -da_ret_t http_msg_response_add_field(http_msg_response_t *http_msg_response, const char *field, const char *value); -/* Caution! Caller must free memory for every "char** out_xxx" for followings */ -da_bool_t http_msg_response_get_content_type(http_msg_response_t *http_msg_response, char **out_type); -void http_msg_response_set_content_type(http_msg_response_t *http_msg_response, const char *in_type); - -da_bool_t http_msg_response_get_content_length(http_msg_response_t *http_msg_response, da_size_t *out_length); -da_bool_t http_msg_response_get_content_disposition(http_msg_response_t *http_msg_response, char **out_disposition, char **out_file_name); -da_bool_t http_msg_response_get_ETag(http_msg_response_t *http_msg_response, char **out_value); -da_bool_t http_msg_response_get_date(http_msg_response_t *http_msg_response, char **out_value); -da_bool_t http_msg_response_get_location(http_msg_response_t *http_msg_response, char **out_value); -#ifdef _RAF_SUPPORT -da_bool_t http_msg_response_get_RAF_mode(http_msg_response_t *http_msg_response, - char **out_value); -#endif -da_ret_t http_msg_request_get_iter(http_msg_request_t *http_msg_request, http_msg_iter_t *http_msg_iter); -da_ret_t http_msg_response_get_iter(http_msg_response_t *http_msg_response, http_msg_iter_t *http_msg_iter); -// should remove later -da_bool_t http_msg_get_field_with_iter(http_msg_iter_t *http_msg_iter, char **field, char **value); -da_bool_t http_msg_get_header_with_iter(http_msg_iter_t *http_msg_iter, char **out_field, http_header_t **out_header); -da_bool_t extract_attribute_from_header(char *szHeadStr, const char *szFindStr, char **ppRtnValue); -da_bool_t http_msg_request_get_if_range(http_msg_request_t *http_msg_request, char **out_value); -da_bool_t http_msg_request_get_range(http_msg_request_t *http_msg_request, char **out_value); - -#endif // _Download_Agent_Http_Msg_Handler_H diff --git a/agent/include/download-agent-interface.h b/agent/include/download-agent-interface.h deleted file mode 100755 index f5ce653..0000000 --- a/agent/include/download-agent-interface.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _DOWNLOAD_AGENT_INTERFACE_H -#define _DOWNLOAD_AGENT_INTERFACE_H - -#ifndef EXPORT_API -#define EXPORT_API __attribute__((visibility("default"))) -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "download-agent-defs.h" -#include <stdarg.h> - -typedef struct { - int download_id; - char *file_type; - unsigned long long file_size; - char *tmp_saved_path; - char *content_name; - char *etag; -} download_info_t; - -typedef struct { - int download_id; - char *saved_path; - char *etag; - int err; - int http_status; -} finished_info_t; - -typedef struct { - const char **request_header; - int request_header_count; - const char *install_path; - const char *file_name; - const char *temp_file_path; - const char *etag; - const char *pkg_name; - int network_bonding; - void *user_req_data; - void *user_client_data; -} req_data_t; - -typedef void (*da_paused_cb) (int download_id, - void *user_param1, void *user_param2); -typedef void (*da_progress_cb) (int download_id, - unsigned long long received_size, - void *user_param1, void *user_param2); -typedef void (*da_started_cb) (download_info_t *download_info, - void *user_param1, void *user_param2); -typedef void (*da_finished_cb) (finished_info_t *finished_info, - void *user_param1, void *user_param2); - -typedef struct { - da_started_cb download_info_cb; - da_progress_cb progress_cb; - da_finished_cb finished_cb; - da_paused_cb paused_cb; -} da_cb_t; - -EXPORT_API int da_init(); -EXPORT_API int da_deinit(); - -EXPORT_API int da_start_download(const char *url, req_data_t *ext_data, - da_cb_t *da_cb_data, int *download_id); -EXPORT_API int da_cancel_download(int download_id); -EXPORT_API int da_cancel_download_without_update(int download_id); -EXPORT_API int da_suspend_download(int download_id); -EXPORT_API int da_suspend_download_without_update(int download_id); -EXPORT_API int da_resume_download(int download_id); -EXPORT_API int da_is_valid_download_id(int download_id); - -#ifdef __cplusplus -} -#endif - -#endif //_DOWNLOAD_AGENT_INTERFACE_H - - diff --git a/agent/include/download-agent-mime-util.h b/agent/include/download-agent-mime-util.h deleted file mode 100755 index 7f57899..0000000 --- a/agent/include/download-agent-mime-util.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _Download_Agent_Mime_Table_H -#define _Download_Agent_Mime_Table_H - -#include "download-agent-type.h" - -#define NO_EXTENSION_NAME_STR "dat" - -#define DD_MIME_STR "application/vnd.oma.dd+xml" -#define DD_EXT_STR "*.dd" -#define DRM_MIME_MSG_STR "application/vnd.oma.drm.message" -#define DRM_EXT_STR "*.dm" -#define DRM_MIME_CONTENT_STR "application/vnd.oma.drm.content" - -typedef struct { - char *standard; - char *normal; -} Ext_translation_table; - -da_bool_t is_ambiguous_MIME_Type(const char *in_mime_type); -da_bool_t da_get_extension_name_from_url(char *url, char **ext); -da_ret_t da_mime_get_ext_name(char *mime, char **ext); -da_bool_t da_get_file_name_from_url(char *url, char **name) ; -void delete_prohibited_char(char *szTarget, int str_len); -da_ret_t get_extension_from_mime_type(char *mime_type, char **extension); -#ifdef _ENABLE_OMA_DRM -da_bool_t is_content_drm_dcf(char *content_type); -da_bool_t is_content_drm_dm(char *content_type); -#endif - - - -#endif diff --git a/agent/include/download-agent-plugin-conf.h b/agent/include/download-agent-plugin-conf.h deleted file mode 100755 index 11e8095..0000000 --- a/agent/include/download-agent-plugin-conf.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _Download_Agent_Plugin_Conf_H -#define _Download_Agent_Plugin_Conf_H - -#include "download-agent-type.h" -#include "download-agent-interface.h" - -da_ret_t get_user_agent_string(char **uagent_str); -char *get_proxy_address(void); -#ifdef _RAF_SUPPORT -//test code -void get_smart_bonding_vconf(); -#endif - -#endif diff --git a/agent/include/download-agent-plugin-drm.h b/agent/include/download-agent-plugin-drm.h deleted file mode 100644 index 361f387..0000000 --- a/agent/include/download-agent-plugin-drm.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _Download_Agent_Plugin_Drm_H -#define _Download_Agent_Plugin_Drm_H - -#include "download-agent-type.h" - -da_bool_t EDRM_convert(const char *in_file_path, char **out_file_path); -da_ret_t EDRM_wm_get_license(char *rights_url, char **out_content_url); - -#endif diff --git a/agent/include/download-agent-plugin-libcurl.h b/agent/include/download-agent-plugin-libcurl.h deleted file mode 100644 index 67a4c53..0000000 --- a/agent/include/download-agent-plugin-libcurl.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _Download_Agent_Plugin_Libcurl_H -#define _Download_Agent_Plugin_Libcrul_H - -#include "download-agent-type.h" -#include "download-agent-dl-info.h" - -#define MAX_SESSION_COUNT DA_MAX_DOWNLOAD_REQ_AT_ONCE -#define MAX_TIMEOUT DA_MAX_TIME_OUT - -da_ret_t PI_http_start(da_info_t *da_info); -da_ret_t PI_http_disconnect(http_info_t *info); -da_ret_t PI_http_cancel(http_info_t *info); -da_ret_t PI_http_pause(http_info_t *info); -da_ret_t PI_http_unpause(http_info_t *info); -#ifdef _RAF_SUPPORT -da_ret_t PI_http_set_file_name_to_curl(http_msg_t *http_msg, char *file_path); -#endif - -#endif diff --git a/agent/include/download-agent-pthread.h b/agent/include/download-agent-pthread.h deleted file mode 100755 index 2748581..0000000 --- a/agent/include/download-agent-pthread.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _DOWNLOAD_AGENT_PTHREAD_H -#define _DOWNLOAD_AGENT_PTHREAD_H - -#include <pthread.h> -#include <errno.h> -#include <time.h> - -#include "download-agent-debug.h" - -#define DA_MUTEX_INIT(mutex_add, attr) {\ - int ret = 0;\ - do {\ - ret = pthread_mutex_init(mutex_add, attr);\ - if (0 == ret){\ - break;\ - }\ - else if (EINVAL == ret){\ - DA_LOGE("pthread_mutex_init FAIL with EINVAL.");\ - break;\ - }\ - else if (ENOMEM == ret){\ - DA_LOGE("pthread_mutex_init FAIL with ENOMEM.");\ - break;\ - }\ - else{\ - DA_LOGE("pthread_mutex_init FAIL with %d.", ret);\ - break;\ - }\ - } while(1);\ -} - -#define DA_COND_INIT(cond_add, attr) do {\ - if (0 != pthread_cond_init(cond_add, attr)){\ - DA_LOGE("pthread_cond_init FAIL");\ - }\ -} while(0) - -#define DA_MUTEX_LOCK(mutex_add) {\ - int ret = 0;\ - do {\ - ret = pthread_mutex_lock(mutex_add);\ - if (0 == ret){\ - break;\ - }\ - else if (EINVAL == ret){\ - DA_LOGE("pthread_mutex_lock FAIL with EINVAL.");\ - break;\ - }\ - else if (EDEADLK == ret){\ - DA_LOGE("pthread_mutex_lock FAIL with EDEADLK.");\ - break;\ - }\ - else{\ - DA_LOGE("pthread_mutex_lock FAIL with %d.", ret);\ - break;\ - }\ - } while(1);\ -} - -#define DA_MUTEX_UNLOCK(mutex_add) {\ - int ret = 0;\ - do {\ - ret = pthread_mutex_unlock(mutex_add);\ - if (0 == ret){\ - break;\ - }\ - else if (EINVAL == ret) {\ - DA_LOGE("pthread_mutex_unlock FAIL with EINVAL.");\ - break;\ - }\ - else if (EPERM == ret) {\ - DA_LOGE("pthread_mutex_unlock FAIL with EPERM.");\ - break;\ - }\ - else {\ - DA_LOGE("pthread_mutex_unlock FAIL with %d.", ret);\ - break;\ - }\ - } while(1);\ -} - -#define DA_COND_SIGNAL(cond_add) do {\ - if (0 != pthread_cond_signal(cond_add)) {\ - DA_LOGE("pthread_cond_signal FAIL");\ - }\ - } while(0) - -#define DA_COND_WAIT(cond_add, mutex_add) do {\ - if (0 != pthread_cond_wait(cond_add, mutex_add)){\ - DA_LOGE("pthread_cond_wait FAIL");\ - }\ - } while(0) - -#define DA_COND_TIMED_WAIT(cond_add, mutex_add, time) do {\ - if (0 != pthread_cond_timedwait(cond_add, mutex_add, time)){\ - DA_LOGE("pthread_cond_wait FAIL");\ - }\ - } while(0) - - -#define DA_COND_DESTROY(cond_add) do {\ - if (0 != pthread_cond_destroy(cond_add)){\ - DA_LOGE("pthread_cond_destroy FAIL");\ - }\ - } while(0) - -#define DA_MUTEX_DESTROY(mutex_add) {\ - int ret = 0;\ - do {\ - ret = pthread_mutex_destroy(mutex_add);\ - if (0 == ret){\ - break;\ - }\ - else if (EINVAL == ret){\ - DA_LOGE("pthread_mutex_destroy FAIL with EINVAL.");\ - break;\ - }\ - else if (EBUSY == ret){\ - DA_LOGE("pthread_mutex_destroy FAIL with EBUSY.");\ - break;\ - }\ - else {\ - DA_LOGE("pthread_mutex_destroy FAIL with %d.", ret);\ - break;\ - }\ - } while(1);\ -} -#endif diff --git a/agent/include/download-agent-type.h b/agent/include/download-agent-type.h deleted file mode 100755 index e77c121..0000000 --- a/agent/include/download-agent-type.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _DOWNLOAD_AGENT_TYPE_H -#define _DOWNLOAD_AGENT_TYPE_H - -#include "download-agent-defs.h" - -typedef int da_ret_t; -typedef int da_bool_t; -typedef unsigned long long da_size_t; - -#define IS_NOT_VALID_ID(x) (x <= DA_INVALID_ID) - -#define DA_MAX_URI_LEN 1024 -#define DA_MAX_FULL_PATH_LEN 356 // need configuration -#define DA_MAX_FILE_PATH_LEN 256 // need configuration -#define DA_MAX_STR_LEN 256 -#define DA_MAX_MIME_STR_LEN 256 -#define DA_MAX_PROXY_ADDR_LEN 64 // e.g. 100.200.300.400:10000 - -#define SCHEME_HTTP "http://" - -#define DA_DEFAULT_INSTALL_PATH_FOR_PHONE "/opt/usr/media/Downloads" - -#define DA_MAX_ID DA_MAX_DOWNLOAD_REQ_AT_ONCE - -#define SAVE_FILE_BUFFERING_SIZE_50KB (50*1024) - -#define NULL_CHECK(DATA) {\ - if (!DATA) {\ - DA_LOGE("NULL CHECK!:%s",(#DATA));\ - return;\ - }\ -} - -#define NULL_CHECK_RET(DATA) {\ - if (!DATA) {\ - DA_LOGE("NULL CHECK!:%s",(#DATA));\ - return DA_ERR_INVALID_ARGUMENT;\ - }\ -} - -#define NULL_CHECK_GOTO(DATA) {\ - if (!DATA) {\ - DA_LOGE("NULL CHECK!:%s",(#DATA));\ - ret = DA_ERR_INVALID_ARGUMENT;\ - goto ERR;\ - }\ -} - -#define NULL_CHECK_RET_OPT(DATA, RET_DATA) {\ - if (!DATA) {\ - DA_LOGE("NULL CHECK!:%s",(#DATA));\ - return RET_DATA;\ - }\ -} - -#endif - |