#include <unistd.h>
#include <math.h>
#include <errno.h>
-#include <tzplatform_config.h>
#include "download-agent-client-mgr.h"
#include "download-agent-debug.h"
return DA_ERR_INVALID_ARGUMENT;
- /* If the installed path which user want is set, the temporary directory is same to the installation directory.
- * Otherwise, the default temporary directory is used.
+ /* The destination path is set by user or by CAPI already
*/
user_install_path = GET_DL_USER_INSTALL_PATH(GET_STAGE_DL_ID(stage));
- if (user_install_path) {
- len = strlen(user_install_path);
- temp_dir = (char *)calloc(len + 1, sizeof(char));
- if (!temp_dir) {
- ret = DA_ERR_FAIL_TO_MEMALLOC;
- goto ERR;
- }
- memcpy(temp_dir, user_install_path, len);
- temp_dir[len] = '\0';
+ len = strlen(user_install_path);
+ temp_dir = (char *)calloc(len + 1, sizeof(char));
+ if (!temp_dir) {
+ ret = DA_ERR_FAIL_TO_MEMALLOC;
+ goto ERR;
+ }
+ memcpy(temp_dir, user_install_path, len);
+ temp_dir[len] = '\0';
+
- } else {
- ret = get_default_install_dir(&temp_dir);
- if (DA_RESULT_OK != ret || DA_NULL == temp_dir) {
- goto ERR;
- }
- }
ret = __get_candidate_file_name(stage, &file_name_without_extension, &extension);
if (ret != DA_RESULT_OK)
return DA_RESULT_OK;
}
-da_result_t create_dir(const char *install_dir)
-{
- da_result_t ret = DA_RESULT_OK;
- /* read/write/search permissions for owner and group,
- * and with read/search permissions for others. */
- if (mkdir(install_dir, S_IRWXU | S_IRWXG | S_IRWXO)) {
- DA_LOG_ERR(FileManager, "Fail to creaate directory");
- ret = DA_ERR_FAIL_TO_ACCESS_STORAGE;
- } else {
- DA_SECURE_LOGD("[%s] is created!", install_dir);
- if (chown(install_dir, tzplatform_getuid(TZ_USER_NAME),tzplatform_getuid(TZ_SYS_USER_GROUP)) < 0) {
- DA_LOG_ERR(FileManager, "Fail to chown");
- ret = DA_ERR_FAIL_TO_ACCESS_STORAGE;
- }
- }
- return ret;
-}
-
-da_result_t get_default_install_dir(char **out_path)
-{
- char *default_path = DA_NULL;
- da_result_t ret = DA_RESULT_OK;
- int len = 0;
-
- if (!out_path) {
- DA_LOG_ERR(ClientNoti, "DA_ERR_INVALID_ARGUMENT");
- return DA_ERR_INVALID_ARGUMENT;
- }
-
- len = strlen(DA_DEFAULT_INSTALL_PATH_FOR_PHONE);
-
- default_path = calloc(len + 1, sizeof(char));
- if (!default_path) {
- return DA_ERR_FAIL_TO_MEMALLOC;
- }
-
- memcpy(default_path, DA_DEFAULT_INSTALL_PATH_FOR_PHONE, len);
- default_path[len] = '\0';
-
- *out_path = default_path;
-
- if (!is_dir_exist(default_path)) {
- ret = create_dir(default_path);
- }
- DA_SECURE_LOGD("default temp path = [%s]", *out_path);
- return DA_RESULT_OK;
-}
da_result_t set_hdr_fields_on_download_info(stage_info *stage);
da_result_t _check_content_type_is_matched(stage_info *stage);
-da_result_t _check_enough_memory_for_this_download(stage_info *stage);
da_result_t _check_downloaded_file_size_is_same_with_header_content_size(
stage_info *stage);
ret = _check_content_type_is_matched(stage);
if (ret != DA_RESULT_OK)
goto ERR;
- ret = _check_enough_memory_for_this_download(stage);
- if (ret != DA_RESULT_OK)
- goto ERR;
CHANGE_HTTP_STATE(HTTP_STATE_DOWNLOAD_STARTED,stage);
CHANGE_DOWNLOAD_STATE(DOWNLOAD_STATE_NEW_DOWNLOAD,stage); // ?
break;
return ret;
}
-da_result_t _check_enough_memory_for_this_download(stage_info *stage)
-{
- da_result_t ret = DA_RESULT_OK;
-
- req_dl_info *request_info = DA_NULL;
-
- unsigned long long cont_len = 0;
- da_storage_size_t memory;
-
- DA_LOG_FUNC_LOGV(HTTPManager);
-
- memset(&memory, 0x00, sizeof(da_storage_size_t));
- request_info = GET_STAGE_TRANSACTION_INFO(stage);
-
- cont_len = (unsigned long long) GET_REQUEST_HTTP_HDR_CONT_LEN(request_info);
- if (cont_len) {
- ret = get_available_memory(&memory);
- if (DA_RESULT_OK == ret) {
- DA_LOG(HTTPManager, "Memory avail: %lu, Memory block :%lu Content: %llu",
- memory.b_available,memory.b_size, cont_len);
- if (memory.b_available < ((cont_len
- + (unsigned long long)SAVE_FILE_BUFFERING_SIZE_50KB)
- / (unsigned long long)memory.b_size)) /* 50KB buffering */
- {
- ret = DA_ERR_DISK_FULL;
- goto ERR;
- }
- }
- }
-
-ERR:
- return ret;
-}
-
da_result_t _check_this_partial_download_is_available(stage_info *stage,
http_msg_response_t *new_http_msg_response)
{
char *origin_ETag = NULL;
char *new_ETag = NULL;
unsigned long long remained_content_len = 0;
- da_storage_size_t memory;
char *value = NULL;
unsigned long long size = 0;
goto ERR;
}
- if (remained_content_len) {
- ret = get_available_memory(&memory);
- if (DA_RESULT_OK == ret) {
- DA_LOG(HTTPManager, "Memory avail: %lu, Memory block :%lu Content: %llu",
- memory.b_available,memory.b_size, remained_content_len);
- if (memory.b_available < ((remained_content_len
- + SAVE_FILE_BUFFERING_SIZE_50KB)
- / memory.b_size)) /* 50KB buffering */
- {
- ret = DA_ERR_DISK_FULL;
- goto ERR;
- }
- }
- }
-
ERR:
if (new_ETag) {
free(new_ETag);
char *origin_ETag = NULL;
char *new_ETag = NULL;
unsigned long long remained_content_len = 0;
- da_storage_size_t memory;
char *value = NULL;
unsigned long long size = 0;
char *temp_file_path = DA_NULL;
goto ERR;
}
- if (remained_content_len) {
- ret = get_available_memory(&memory);
- if (DA_RESULT_OK == ret) {
- DA_LOG(HTTPManager, "Memory avail: %lu, Memory block :%lu Content: %llu",
- memory.b_available,memory.b_size, remained_content_len);
- if (memory.b_available < ((remained_content_len
- + SAVE_FILE_BUFFERING_SIZE_50KB)
- / memory.b_size)) /* 50KB buffering */
- {
- ret = DA_ERR_DISK_FULL;
- goto ERR;
- }
- }
- }
b_ret = http_msg_response_get_content_type(new_http_msg_response, &value);
if (b_ret) {
GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info) = value;
return buffer_len;
}
-da_result_t get_available_memory(da_storage_size_t *avail_memory)
-{
- da_result_t ret = DA_RESULT_OK;
- int fs_ret = 0;
- struct statfs filesys_info = {0, };
- char *default_install_dir = NULL;
-
- DA_LOG_FUNC_LOGD(Default);
-
- if (!avail_memory)
- return DA_ERR_INVALID_ARGUMENT;
-
- ret = get_default_install_dir(&default_install_dir);
-
- if (ret == DA_RESULT_OK && default_install_dir) {
- fs_ret = statfs(default_install_dir, &filesys_info);
- } else {
- return DA_ERR_FAIL_TO_ACCESS_STORAGE;
- }
-
- if (fs_ret != 0) {
- DA_LOG_ERR(Default,"Phone file path :statfs error - [%d]", errno);
- free(default_install_dir);
- return DA_ERR_INVALID_INSTALL_PATH;
- }
-
- avail_memory->b_available = filesys_info.f_bavail;
- avail_memory->b_size = filesys_info.f_bsize;
-
- DA_LOG_VERBOSE(Default, "Available Memory(f_bavail) : %llu", filesys_info.f_bavail);
- DA_LOG_VERBOSE(Default, "Available Memory(f_bsize) : %d", filesys_info.f_bsize);
- DA_LOG_VERBOSE(Default, "Available Memory(kbytes) : %lu", (filesys_info.f_bavail/1024)*filesys_info.f_bsize);
-
- free(default_install_dir);
- return DA_RESULT_OK;
-}
-
da_mime_type_id_t get_mime_type_id(char *content_type)
{
int i = 0;
#include "download-agent-type.h"
#include "download-agent-dl-mgr.h"
-#define DA_DEFAULT_INSTALL_PATH_FOR_PHONE tzplatform_getenv(TZ_USER_DOWNLOADS)
-
da_bool_t is_file_exist(const char *file_path);
da_bool_t is_dir_exist(const char *dir_path);
da_result_t discard_download(stage_info *stage) ;
void clean_paused_file(stage_info *stage);
da_result_t replace_content_file_in_stage(stage_info *stage, const char *dest_dd_file_path);
-da_result_t decide_tmp_file_path(stage_info *stage);
char *get_full_path_avoided_duplication(char *in_dir, char *in_candidate_file_name, char *in_extension);
da_result_t copy_file(const char *src, const char *dest);
-da_result_t create_dir(const char *install_dir);
-da_result_t get_default_install_dir(char **out_path);
#endif
nanosleep(&interval,&remainder); \
} while(0)
-typedef struct _da_storage_size_t {
- unsigned long b_available;
- unsigned long b_size;
-} da_storage_size_t;
-
typedef enum {
DA_MIME_TYPE_NONE,
DA_MIME_TYPE_DRM1_MESSATE,
da_result_t get_available_dd_id(int *available_id);
da_result_t get_extension_from_mime_type(char *mime_type, char **extension);
da_mime_type_id_t get_mime_type_id(char *content_type);
-da_result_t get_available_memory(da_storage_size_t *avail_memory);
da_bool_t is_valid_url(const char *url, da_result_t *err_code);
int read_data_from_file(char *file, char**out_buffer);
Requires(post): vconf
Requires: sqlite
Requires: connman
+Requires: net-config
%description
Description: download the contents in background
#include <dlog.h>
#include <download-provider-interface.h>
#include <download-provider.h>
+#include <tzplatform_config.h>
+
+#define DEFAULT_INSTALL_PATH tzplatform_getenv(TZ_USER_DOWNLOADS)
#ifdef SUPPORT_CHECK_IPC
#include <sys/ioctl.h>
// clear read buffer. call in head of API before calling IPC_SEND
static void __clear_read_buffer(int fd)
{
- long i;
- long unread_count;
+ int i;
+ int unread_count;
char tmp_char;
// FIONREAD : Returns the number of bytes immediately readable
}
+static int _mkdir(const char *dir, mode_t mode) {
+ char tmp[256];
+ char *p = NULL;
+ size_t len;
+
+ snprintf(tmp, sizeof(tmp),"%s",dir);
+ len = strlen(tmp);
+ if(tmp[len - 1] == '/')
+ tmp[len - 1] = 0;
+ for(p = tmp + 1; *p; p++)
+ if(*p == '/') {
+ *p = 0;
+ mkdir(tmp, mode);
+ *p = '/';
+ }
+ return mkdir(tmp, mode);
+}
+
+static dp_error_type __create_dir(const char *install_dir)
+{
+ dp_error_type ret = DP_ERROR_NONE;
+ /* read/write/search permissions for owner and group,
+ * and with read/search permissions for others as fas as
+ * umask allows. */
+ if (_mkdir(install_dir, S_IRWXU | S_IRWXG | S_IRWXO)) {
+ ret = DP_ERROR_PERMISSION_DENIED;
+ }
+ return ret;
+}
+
+
/////////////////////// APIs /////////////////////////////////
int dp_interface_create(int *id)
if (errorcode == DP_ERROR_IO_ERROR)
__disconnect_from_provider();
pthread_mutex_unlock(&g_function_mutex);
+ if (errorcode == DP_ERROR_NONE){
+ // safely set the default path, maybe overwritten by the user later
+ const char* dest_path = DEFAULT_INSTALL_PATH;
+ if (dest_path){
+ struct stat dir_state;
+ int stat_ret = stat(dest_path, &dir_state);
+ if (stat_ret != 0) {
+ __create_dir(dest_path);
+ }
+ dp_interface_set_destination(t_id, dest_path);
+ }
+ }
return __dp_interface_convert_errorcode(errorcode);
}
return __dp_interface_convert_errorcode(errorcode);
}
+
int dp_interface_start(const int id)
{
- int errorcode = DP_ERROR_NONE;
+ int errorcode = DP_ERROR_NONE;
DP_PRE_CHECK_ID;
pthread_mutex_lock(&g_function_mutex);
int dp_interface_set_destination(const int id, const char *path)
{
- return __dp_interface_set_string(id, DP_CMD_SET_DESTINATION, path);
+ if (path && strlen(path)>0) {
+ return __dp_interface_set_string(id, DP_CMD_SET_DESTINATION, path);
+ } else {
+ return __dp_interface_convert_errorcode(DP_ERROR_NONE);
+ }
}
#include <sys/time.h>
#include <sys/statfs.h>
+#include <sys/smack.h>
#include "download-provider.h"
#include "download-provider-log.h"
#include "download-provider-notification.h"
-#define SMACKFS_MAGIC 0x43415d53
-#define SMACKFS_MNT "/smack"
///////// below functions are called by main thread of thread-request.c
//////////////////////////////////////////////////////////////////////////
int dp_is_smackfs_mounted()
{
- struct statfs sfs;
- int ret;
- do {
- ret = statfs(SMACKFS_MNT, &sfs);
- } while (ret < 0 && errno == EINTR);
- if (ret) {
- TRACE_ERROR("[SMACK ERROR]");
- return -1;
- }
- if (sfs.f_type == SMACKFS_MAGIC) {
- return 1;
- }
+ if(smack_smackfs_path() != NULL)
+ return 1;
TRACE_ERROR("[SMACK DISABLE]");
return 0;
}
if (dp_is_smackfs_mounted() == 1) {
ret = smack_new_label_from_socket(clientfd, &smack_label);
- if (ret != 0) {
+ if (ret < 0) {
TRACE_ERROR("[CRITICAL] cannot get smack label");
free(pkgname);
free(smack_label);