static da_result_t __cancel_download_with_slot_id(int slot_id) { da_result_t ret = DA_RESULT_OK; download_state_t download_state; stage_info *stage = DA_NULL; DA_LOG_FUNC_START(Default); _da_thread_mutex_lock (&mutex_download_state[slot_id]); download_state = GET_DL_STATE_ON_ID(slot_id); DA_LOG(Default, "download_state = %d", GET_DL_STATE_ON_ID(slot_id)); if (download_state == DOWNLOAD_STATE_FINISH || download_state == DOWNLOAD_STATE_CANCELED) { DA_LOG_CRITICAL(Default, "Already download is finished. Do not send cancel request"); _da_thread_mutex_unlock (&mutex_download_state[slot_id]); return ret; } _da_thread_mutex_unlock (&mutex_download_state[slot_id]); stage = GET_DL_CURRENT_STAGE(slot_id); if (!stage) return DA_RESULT_OK; ret = request_to_cancel_http_download(stage); if (ret != DA_RESULT_OK) goto ERR; DA_LOG(Default, "Download cancel Successful for download id - %d", slot_id); ERR: return ret; }
da_result_t requesting_download(stage_info *stage) { da_result_t ret = DA_RESULT_OK; req_dl_info *request_session = DA_NULL; DA_LOG_FUNC_START(Default); if (!stage) { DA_LOG_ERR(Default, "stage is null.."); ret = DA_ERR_INVALID_ARGUMENT; goto ERR; } ret = make_req_dl_info_http(stage, GET_STAGE_TRANSACTION_INFO(stage)); if (ret != DA_RESULT_OK) goto ERR; request_session = GET_STAGE_TRANSACTION_INFO(stage); ret = request_http_download(stage); if (DA_RESULT_OK == ret) { DA_LOG(Default, "Http download is complete."); } else { DA_LOG_ERR(Default, "Http download is failed. ret = %d", ret); goto ERR; } ERR: return ret; }
da_result_t suspend_download(int dl_id, da_bool_t is_enable_cb) { da_result_t ret = DA_RESULT_OK; int slot_id = DA_INVALID_ID; DA_LOG_FUNC_START(Default); ret = get_slot_id_for_dl_id(dl_id, &slot_id); if (ret != DA_RESULT_OK) { DA_LOG_ERR(Default, "dl req ID is not Valid"); goto ERR; } GET_DL_ENABLE_PAUSE_UPDATE(slot_id) = is_enable_cb; if (DA_FALSE == is_valid_slot_id(slot_id)) { DA_LOG_ERR(Default, "Download ID is not Valid"); ret = DA_ERR_INVALID_ARGUMENT; goto ERR; } ret = __suspend_download_with_slot_id(slot_id); ERR: return ret; }
da_result_t cancel_download(int dl_id) { da_result_t ret = DA_RESULT_OK; int slot_id = DA_INVALID_ID; DA_LOG_FUNC_START(Default); ret = get_slot_id_for_dl_id(dl_id, &slot_id); if (ret != DA_RESULT_OK) { DA_LOG_ERR(Default, "dl req ID is not Valid"); goto ERR; } if (DA_FALSE == is_valid_slot_id(slot_id)) { DA_LOG_ERR(Default, "Download ID is not Valid"); ret = DA_ERR_INVALID_ARGUMENT; goto ERR; } ret = __cancel_download_with_slot_id(slot_id); ERR: return ret; }
da_result_t send_client_update_dl_info ( int download_id, int dl_req_id, char *file_type, unsigned long int file_size, char *tmp_saved_path, char *http_response_header, char *http_chunked_data ) { client_noti_t *client_noti = DA_NULL; user_download_info_t *update_dl_info = DA_NULL; DA_LOG_FUNC_START(ClientNoti); if (!is_valid_dl_ID(download_id)) { DA_LOG_ERR(ClientNoti, "Download ID is not valid"); return DA_ERR_INVALID_DL_REQ_ID; } client_noti = (client_noti_t *)calloc(1, sizeof(client_noti_t)); if (!client_noti) { DA_LOG_ERR(ClientNoti, "calloc fail"); return DA_ERR_FAIL_TO_MEMALLOC; } client_noti->download_id = download_id; client_noti->user_data = GET_DL_USER_DATA(download_id); client_noti->noti_type = Q_CLIENT_NOTI_TYPE_UPDATE_DL_INFO; client_noti->next = DA_NULL; update_dl_info = (user_download_info_t *)&(client_noti->type.update_dl_info); update_dl_info->da_dl_req_id = dl_req_id; update_dl_info->file_size = file_size; /* These strings MUST be copied to detach __thread_for_client_noti from download_info */ if (file_type) update_dl_info->file_type = strdup(file_type); if (tmp_saved_path) update_dl_info->tmp_saved_path = strdup(tmp_saved_path); if (http_response_header) { update_dl_info->http_response_header = strdup(http_response_header); } if (http_chunked_data) { update_dl_info->http_chunked_data = calloc (1, file_size); if (update_dl_info->http_chunked_data) memcpy(update_dl_info->http_chunked_data, http_chunked_data, file_size); } DA_LOG(ClientNoti, "pushing file_size=%lu, download_id=%d, dl_req_id=%d", file_size, download_id, dl_req_id); push_client_noti(client_noti); return DA_RESULT_OK; }
da_result_t send_client_da_state (int download_id, da_state state, int err) { client_noti_t *client_noti = DA_NULL; user_notify_info_t *send_state_info = DA_NULL; da_state cur_da_state; DA_LOG_FUNC_START(ClientNoti); DA_LOG_VERBOSE(ClientNoti, "da_state[%s], download_id[%d]", print_dl_state(state), download_id); if (!is_valid_dl_ID(download_id)) { DA_LOG_ERR(ClientNoti, "Download ID is not valid"); /* Returning DA_RESULT_OK if download_id is not valid, * because sending da_state should not effect to download flow. */ return DA_RESULT_OK; } if (state_watcher_need_redirect_Q(download_id)) { state_watcher_redirect_state(download_id, state, err); return DA_RESULT_OK; } cur_da_state = GET_DL_DA_STATE(download_id); if ((DA_STATE_SUSPENDED != state) && (cur_da_state == state)) { DA_LOG(ClientNoti, "inserting da_state is same with current da_state! Not inserting! inserting: %d, cur : %d", state, cur_da_state); return DA_RESULT_OK; } GET_DL_DA_STATE(download_id) = state; DA_LOG_VERBOSE(ClientNoti, "change da_state to %d", state); client_noti = (client_noti_t *)calloc(1, sizeof(client_noti_t)); if (!client_noti) { DA_LOG_ERR(ClientNoti, "calloc fail"); return DA_ERR_FAIL_TO_MEMALLOC; } client_noti->download_id = download_id; client_noti->user_data = GET_DL_USER_DATA(download_id); client_noti->noti_type = Q_CLIENT_NOTI_TYPE_SEND_STATE; client_noti->next = DA_NULL; send_state_info = (user_notify_info_t *)&(client_noti->type.da_state_info); send_state_info->da_dl_req_id = GET_DL_REQ_ID(download_id); send_state_info->state = state; send_state_info->err = err; DA_LOG(ClientNoti, "pushing da_state=%d, download_id=%d, err=%d, dl_req_id=%d", state, download_id, err, GET_DL_REQ_ID(download_id)); push_client_noti(client_noti); return DA_RESULT_OK; }
void remove_file(const char *file_path) { DA_LOG_FUNC_START(FileManager); if (file_path) { DA_LOG(FileManager,"remove file [%s]", file_path); if (unlink(file_path) < 0) { DA_LOG_ERR(FileManager,"file removing failed."); } } }
da_result_t __launch_client_thread(void) { pthread_t thread_id = DA_NULL; DA_LOG_FUNC_START(Thread); if (pthread_create(&thread_id,DA_NULL,__thread_for_client_noti,DA_NULL) < 0) { DA_LOG_ERR(Thread, "making thread failed.."); return DA_ERR_FAIL_TO_CREATE_THREAD; } DA_LOG(Thread, "client mgr thread id[%d]", thread_id); client_app_mgr.thread_id = thread_id; return DA_RESULT_OK; }
da_result_t check_enough_storage(stage_info *stage) { da_result_t ret = DA_RESULT_OK; unsigned long cont_size = 0; da_storage_size_t avail_memory = {0, }; da_storage_type_t type = DA_STORAGE_PHONE; DA_LOG_FUNC_START(Default); /* check enough storage here because of multiple download */ ret = get_storage_type(&type); if (DA_RESULT_OK != ret) return ret; cont_size = GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage)); DA_LOG(Default,"cont_size [%d]", cont_size); if (cont_size) { ret = get_available_memory(DA_STORAGE_PHONE, &avail_memory); if (DA_RESULT_OK == ret && (avail_memory.b_available < ((cont_size + SAVE_FILE_BUFFERING_SIZE_5MB) / avail_memory.b_size))) /* 5MB buffering */ { DA_LOG_ERR(Default,"There is no space for content in Phone memory"); return DA_ERR_DISK_FULL; } else if (DA_RESULT_OK != ret) { return ret; } /* If default memeory type is mmc, * it need to check phone memroy for temproary folder * and mmc memory for actual install folder */ if (type == DA_STORAGE_MMC) { DA_LOG(Default,"Storage type == DA_STORAGE_MMC\n"); ret = get_available_memory(type, &avail_memory); if (DA_RESULT_OK == ret && (avail_memory.b_available < ((cont_size + SAVE_FILE_BUFFERING_SIZE_50KB) / avail_memory.b_size))) /* 50KB buffering */ { DA_LOG_ERR(Default,"There is no space for content in MMC memory"); return DA_ERR_DISK_FULL; } else if (DA_RESULT_OK != ret) { return ret; } } } return ret; }
da_result_t init_client_app_mgr() { DA_LOG_FUNC_START(ClientNoti); if(client_app_mgr.is_init) return DA_RESULT_OK; client_app_mgr.is_init = DA_TRUE; client_app_mgr.client_app_info.is_using = DA_FALSE; client_app_mgr.client_app_info.is_manual_download = DA_FALSE; client_app_mgr.client_app_info.client_user_agent = DA_NULL; client_app_mgr.is_thread_init = DA_FALSE; return DA_RESULT_OK; }
char *get_user_agent() { char *uagent_str = DA_NULL; DA_LOG_FUNC_START(Default); uagent_str = get_client_user_agent_string(); if (!uagent_str) { da_result_t ret = DA_RESULT_OK; ret = get_user_agent_string(&uagent_str); if (ret != DA_RESULT_OK) return NULL; } return uagent_str; }
da_result_t dereg_client_app(void) { client_noti_t *client_noti = DA_NULL; DA_LOG_FUNC_START(ClientNoti); client_noti = (client_noti_t *)calloc(1, sizeof(client_noti_t)); if (!client_noti) { DA_LOG_ERR(ClientNoti, "calloc fail"); return DA_ERR_FAIL_TO_MEMALLOC; } client_noti->download_id = DA_INVALID_ID; client_noti->noti_type = Q_CLIENT_NOTI_TYPE_TERMINATE; client_noti->next = DA_NULL; _da_thread_mutex_lock(&(client_app_mgr.mutex_client_mgr)); if (client_app_mgr.is_thread_init != DA_TRUE) { DA_LOG_CRITICAL(ClientNoti, "try to cancel client mgr thread id[%lu]", client_app_mgr.thread_id); if (pthread_cancel(client_app_mgr.thread_id) < 0) { DA_LOG_ERR(ClientNoti, "cancel thread is failed!!!"); } } else { void *t_return = NULL; DA_LOG_VERBOSE(ClientNoti, "pushing Q_CLIENT_NOTI_TYPE_TERMINATE"); push_client_noti(client_noti); DA_LOG_CRITICAL(Thread, "===try to join client mgr thread id[%lu]===", client_app_mgr.thread_id); if (pthread_join(client_app_mgr.thread_id, &t_return) < 0) { DA_LOG_ERR(Thread, "join client thread is failed!!!"); } DA_LOG_CRITICAL(Thread, "===thread join return[%d]===", (char*)t_return); } _da_thread_mutex_unlock(&(client_app_mgr.mutex_client_mgr)); /* ToDo: This clean up should be done at the end of client_thread. */ client_app_mgr.client_app_info.is_using= DA_FALSE; client_app_mgr.client_app_info.is_manual_download = DA_FALSE; if(client_app_mgr.client_app_info.client_user_agent) { free(client_app_mgr.client_app_info.client_user_agent); client_app_mgr.client_app_info.client_user_agent = DA_NULL; } _da_thread_mutex_lock(&(client_app_mgr.mutex_client_mgr)); client_app_mgr.is_thread_init = DA_FALSE; _da_thread_mutex_unlock(&(client_app_mgr.mutex_client_mgr)); _da_thread_mutex_destroy(&(client_app_mgr.mutex_client_mgr)); return DA_RESULT_OK; }
da_result_t send_user_noti_and_finish_download_flow( int slot_id, char *installed_path, char *etag) { da_result_t ret = DA_RESULT_OK; download_state_t download_state = DA_NULL; da_bool_t need_destroy_download_info = DA_FALSE; DA_LOG_FUNC_START(Default); _da_thread_mutex_lock (&mutex_download_state[slot_id]); download_state = GET_DL_STATE_ON_ID(slot_id); DA_LOG(Default, "state = %d", download_state); _da_thread_mutex_unlock (&mutex_download_state[slot_id]); switch (download_state) { case DOWNLOAD_STATE_FINISH: send_client_finished_info(slot_id, GET_DL_ID(slot_id), installed_path, DA_NULL, DA_RESULT_OK, get_http_status(slot_id)); need_destroy_download_info = DA_TRUE; break; case DOWNLOAD_STATE_CANCELED: send_client_finished_info(slot_id, GET_DL_ID(slot_id), installed_path, etag, DA_RESULT_USER_CANCELED, get_http_status(slot_id)); need_destroy_download_info = DA_TRUE; break; #ifdef PAUSE_EXIT case DOWNLOAD_STATE_PAUSED: need_destroy_download_info = DA_TRUE; break; #endif default: DA_LOG(Default, "download state = %d", download_state); break; } if (need_destroy_download_info == DA_TRUE) { destroy_download_info(slot_id); } else { DA_LOG_CRITICAL(Default, "download info is not destroyed"); } 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_LOG_FUNC_START(Default); if (DA_NULL == url || DA_NULL == ext) { ret = DA_FALSE; DA_LOG_ERR(Default,"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_LOG_ERR(Default,"Memory Fail"); goto ERR; } strncpy(*ext,buff,buf_len); DA_LOG(Default,"extention name[%s]",*ext); return ret; } } ERR: if (*ext) { free(*ext); *ext = DA_NULL; } return ret; }
da_result_t reg_client_app( da_client_cb_t *da_client_callback, da_download_managing_method download_method ) { da_result_t ret = DA_RESULT_OK; client_queue_t *queue = DA_NULL; client_noti_t *client_noti = DA_NULL; DA_LOG_FUNC_START(ClientNoti); if (client_app_mgr.client_app_info.is_using) return DA_ERR_CLIENT_IS_ALREADY_REGISTERED; client_app_mgr.client_app_info.is_using = DA_TRUE; if (download_method == DA_DOWNLOAD_MANAGING_METHOD_MANUAL) client_app_mgr.client_app_info.is_manual_download = DA_TRUE; else client_app_mgr.client_app_info.is_manual_download = DA_FALSE; memset(&(client_app_mgr.client_app_info.client_callback), 0, sizeof(da_client_cb_t)); memcpy(&(client_app_mgr.client_app_info.client_callback), da_client_callback, sizeof(da_client_cb_t)); _da_thread_mutex_init(&(client_app_mgr.mutex_client_mgr), DA_NULL); /* If some noti is existed at queue, delete all */ do { __pop_client_noti(&client_noti); destroy_client_noti(client_noti); } while(client_noti != DA_NULL); queue = &(client_app_mgr.client_queue); DA_LOG_VERBOSE(ClientNoti, "client queue = %p", queue); _da_thread_mutex_init(&(queue->mutex_client_queue), DA_NULL); _da_thread_cond_init(&(queue->cond_client_queue), DA_NULL); ret = __launch_client_thread(); return ret; }
da_result_t get_available_memory( da_storage_type_t storage_type, da_storage_size_t *avail_memory) { int fs_ret = 0; struct statfs filesys_info = {0, }; DA_LOG_FUNC_START(Default); if (!avail_memory) return DA_ERR_INVALID_ARGUMENT; if (storage_type == DA_STORAGE_PHONE) { fs_ret = statfs(DA_DEFAULT_TMP_FILE_DIR_PATH, &filesys_info); } else if (storage_type == DA_STORAGE_MMC) { char *default_install_dir = NULL; default_install_dir = PI_get_default_install_dir(); if (default_install_dir) { fs_ret = statfs(default_install_dir, &filesys_info); } else { return DA_ERR_FAIL_TO_ACCESS_STORAGE; } } else { DA_LOG_ERR(Default,"Invalid storage type"); return DA_ERR_INVALID_ARGUMENT; } if (fs_ret != 0) { DA_LOG_ERR(Default,"Phone file path :statfs error - [%d]", errno); return DA_ERR_FAIL_TO_ACCESS_FILE; } avail_memory->b_available = filesys_info.f_bavail; avail_memory->b_size = filesys_info.f_bsize; DA_LOG(Default, "Memory type : %d", storage_type); DA_LOG(Default, "Available Memory(f_bavail) : %lu", filesys_info.f_bavail); DA_LOG(Default, "Available Memory(f_bsize) : %d", filesys_info.f_bsize); DA_LOG(Default, "Available Memory(kbytes) : %lu", (filesys_info.f_bavail/1024)*filesys_info.f_bsize); return DA_RESULT_OK; }
da_result_t send_client_update_downloading_info ( int download_id, int dl_req_id, unsigned long int total_received_size, char *saved_path ) { client_noti_t *client_noti = DA_NULL; user_downloading_info_t *downloading_info = DA_NULL; DA_LOG_FUNC_START(ClientNoti); if (!is_valid_dl_ID(download_id)) { DA_LOG_ERR(ClientNoti, "Download ID is not valid"); return DA_ERR_INVALID_DL_REQ_ID; } client_noti = (client_noti_t *)calloc(1, sizeof(client_noti_t)); if (!client_noti) { DA_LOG_ERR(ClientNoti, "calloc fail"); return DA_ERR_FAIL_TO_MEMALLOC; } client_noti->download_id = download_id; client_noti->user_data = GET_DL_USER_DATA(download_id); client_noti->noti_type = Q_CLIENT_NOTI_TYPE_UPDATE_DOWNLOADING_INFO; client_noti->next = DA_NULL; downloading_info = (user_downloading_info_t *)&(client_noti->type.update_downloading_info); downloading_info->da_dl_req_id = dl_req_id; downloading_info->total_received_size = total_received_size; /* These strings MUST be copied to detach __thread_for_client_noti from download_info */ if (saved_path) downloading_info->saved_path = strdup(saved_path); DA_LOG(ClientNoti, "pushing received_size=%lu, download_id=%d, dl_req_id=%d", total_received_size, download_id, dl_req_id); push_client_noti(client_noti); return DA_RESULT_OK; }
static da_result_t __resume_download_with_slot_id(int slot_id) { da_result_t ret = DA_RESULT_OK; download_state_t download_state; stage_info *stage = DA_NULL; DA_LOG_FUNC_START(Default); _da_thread_mutex_lock (&mutex_download_state[slot_id]); download_state = GET_DL_STATE_ON_ID(slot_id); DA_LOG(Default, "download_state = %d", GET_DL_STATE_ON_ID(slot_id)); _da_thread_mutex_unlock (&mutex_download_state[slot_id]); stage = GET_DL_CURRENT_STAGE(slot_id); ret = request_to_resume_http_download(stage); if (ret != DA_RESULT_OK) goto ERR; DA_LOG(Default, "Download Resume Successful for download id-%d", slot_id); ERR: return ret; }
da_result_t handle_after_download(stage_info *stage) { da_result_t ret = DA_RESULT_OK; da_mime_type_id_t mime_type = DA_MIME_TYPE_NONE; DA_LOG_FUNC_START(Default); mime_type = get_mime_type_id( GET_CONTENT_STORE_CONTENT_TYPE(GET_STAGE_CONTENT_STORE_INFO(stage))); switch (mime_type) { case DA_MIME_TYPE_NONE: DA_LOG(Default, "DA_MIME_TYPE_NONE"); ret = DA_ERR_MISMATCH_CONTENT_TYPE; break; default: CHANGE_DOWNLOAD_STATE(DOWNLOAD_STATE_FINISH, stage); break; } /* end of switch */ return ret; }
da_result_t get_extension_from_mime_type(char *mime_type, char **extension) { da_result_t ret = DA_RESULT_OK; char *ext = DA_NULL; DA_LOG_FUNC_START(Default); if (DA_NULL == mime_type || DA_NULL == extension) { DA_LOG_ERR(Default,"received mime_type is null"); ret = DA_ERR_INVALID_ARGUMENT; goto ERR; } DA_LOG(Default,"input mime type = %s", mime_type); if (DA_RESULT_OK != (ret = da_mime_get_ext_name(mime_type, &ext))) { DA_LOG_ERR(Default,"can't find proper extension!"); goto ERR; } *extension = ext; DA_LOG(Default,"found extension = %s", *extension); ERR: return ret; }
static void *__thread_for_client_noti(void *data) { da_result_t ret = DA_RESULT_OK; da_bool_t need_wait = DA_TRUE; client_queue_t *queue = DA_NULL; client_noti_t *client_noti = DA_NULL; DA_LOG_FUNC_START(Thread); _da_thread_mutex_lock(&(client_app_mgr.mutex_client_mgr)); client_app_mgr.is_thread_init = DA_TRUE; _da_thread_mutex_unlock(&(client_app_mgr.mutex_client_mgr)); queue = &(client_app_mgr.client_queue); DA_LOG(ClientNoti, "client queue = %p", queue); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, DA_NULL); pthread_cleanup_push(__thread_clean_up_handler_for_client_thread, (void *)DA_NULL); do { _da_thread_mutex_lock(&(queue->mutex_client_queue)); if (DA_FALSE == IS_CLIENT_Q_HAVING_DATA(queue)) { DA_LOG(Thread, "Sleep @ thread_for_client_noti!"); __client_q_goto_sleep_without_lock(); DA_LOG(Thread, "Woke up @ thread_for_client_noti"); } _da_thread_mutex_unlock(&(queue->mutex_client_queue)); do { __pop_client_noti(&client_noti); if (client_noti == DA_NULL) { DA_LOG_ERR(ClientNoti, "There is no data on client queue!"); ret = DA_ERR_INVALID_STATE; need_wait = DA_FALSE; } else { switch (client_noti->noti_type) { case Q_CLIENT_NOTI_TYPE_UPDATE_DL_INFO: { user_download_info_t *update_dl_info = DA_NULL;; update_dl_info = (user_download_info_t*)(&(client_noti->type.update_dl_info)); if (client_app_mgr.client_app_info.client_callback.update_dl_info_cb) { client_app_mgr.client_app_info.client_callback.update_dl_info_cb(update_dl_info, client_noti->user_data); DA_LOG(ClientNoti, "Update download info for download_id=%d, dl_req_id=%d, received size=%lu- DONE", client_noti->download_id, update_dl_info->da_dl_req_id, update_dl_info->file_size ); } } break; case Q_CLIENT_NOTI_TYPE_UPDATE_DOWNLOADING_INFO: { user_downloading_info_t *downloading_info = DA_NULL;; downloading_info = (user_downloading_info_t*)(&(client_noti->type.update_downloading_info)); if (client_app_mgr.client_app_info.client_callback.update_progress_info_cb) { client_app_mgr.client_app_info.client_callback.update_progress_info_cb(downloading_info, client_noti->user_data); DA_LOG(ClientNoti, "Update downloading info for download_id=%d, dl_req_id=%d, received size=%lu - DONE", client_noti->download_id, downloading_info->da_dl_req_id, downloading_info->total_received_size); } } break; case Q_CLIENT_NOTI_TYPE_SEND_STATE: { user_notify_info_t *da_state_info = DA_NULL; da_state_info = (user_notify_info_t *)(&(client_noti->type.da_state_info)); if (client_app_mgr.client_app_info.client_callback.user_noti_cb) { DA_LOG(ClientNoti, "User Noti info for download_id=%d, dl_req_id=%d, da_state=%d, err=%d", client_noti->download_id, da_state_info->da_dl_req_id, da_state_info->state, da_state_info->err); client_app_mgr.client_app_info.client_callback.user_noti_cb(da_state_info, client_noti->user_data); DA_LOG(ClientNoti, "User Noti info for download_id=%d, dl_req_id=%d, da_state=%d, err=%d - DONE", client_noti->download_id, da_state_info->da_dl_req_id, da_state_info->state, da_state_info->err); } } break; case Q_CLIENT_NOTI_TYPE_TERMINATE: DA_LOG_CRITICAL(ClientNoti, "Q_CLIENT_NOTI_TYPE_TERMINATE"); need_wait = DA_FALSE; break; } destroy_client_noti(client_noti); } if(DA_TRUE == need_wait) { _da_thread_mutex_lock(&(queue->mutex_client_queue)); if (DA_FALSE == IS_CLIENT_Q_HAVING_DATA(queue)) { _da_thread_mutex_unlock (&(queue->mutex_client_queue)); break; } else { _da_thread_mutex_unlock (&(queue->mutex_client_queue)); } } else { break; } } while (1); } while (DA_TRUE == need_wait); _da_thread_mutex_destroy(&(queue->mutex_client_queue)); _da_thread_cond_destroy(&(queue->cond_client_queue)); pthread_cleanup_pop(0); DA_LOG_CRITICAL(Thread, "=====thread_for_client_noti- EXIT====="); pthread_exit((void *)NULL); return DA_NULL; }
da_result_t da_mime_get_ext_name(char *mime, char **ext) { da_result_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_LOG_FUNC_START(Default); if (DA_NULL == mime || DA_NULL == ext) { ret = DA_ERR_INVALID_ARGUMENT; DA_LOG_ERR(Default,"Invalid mime type"); goto ERR; } DA_LOG_VERBOSE(Default,"mime str[%s]ptr[%p]len[%d]",mime,mime,strlen(mime)); /* unaliased_mimetype means representative mime among similar types */ unaliased_mimetype = xdg_mime_unalias_mime_type(mime); if (unaliased_mimetype == DA_NULL) { ret = DA_ERR_INVALID_MIME_TYPE; DA_LOG_ERR(Default,"Invalid mime type : No unsaliased mime type"); goto ERR; } DA_LOG(Default,"unaliased_mimetype[%s]\n",unaliased_mimetype); /* Get extension name from shared-mime-info */ extlist = xdg_mime_get_file_names_from_mime_type(unaliased_mimetype); if (extlist == DA_NULL || *extlist == DA_NULL) { int i = 0; ret = DA_ERR_INVALID_MIME_TYPE; DA_LOG(Default,"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_LOG(Default,"extlist[%s]\n",*extlist); strncpy(ext_temp, *extlist, DA_MAX_STR_LEN); /* 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_LOG(Default,"index[%d]\n",i); /* If there is a mime at extension transform table */ if (i < MAX_EXT_TABLE_INDEX) { break; } DA_LOG(Default,"extlist[%s]\n",*extlist); extlist++; } DA_LOG(Default,"extension from shared mime info[%s]",ext_temp); } if (strlen(ext_temp) < 1) { /* If there is no mime string for OMD 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_STR,mime,strlen(DD_MIME_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_LOG_ERR(Default,"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_LOG(Default,"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; }
/* 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_LOG_FUNC_START(Default); if (DA_NULL == url || DA_NULL == name) { ret = DA_FALSE; DA_LOG_ERR(Default,"Invalid Argument"); goto ERR; } *name = DA_NULL; if (!strstr(url, "http") && !strstr(url, "https")) { ret = DA_FALSE; DA_LOG_ERR(Default,"Invalid Argument"); goto ERR; } buff = (char*) calloc(1, strlen(url) +1); if(DA_NULL == buff) { ret = DA_FALSE; DA_LOG_ERR(Default,"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_LOG(Default,"file name BEFORE removing prohibited character = %s", name_buff); delete_prohibited_char(name_buff, strlen(name_buff)); DA_LOG(Default,"file name AFTER removing prohibited character = %s", name_buff); len_name = strlen(name_buff); *name = (char*) calloc(1, len_name + 1); if (*name) { strncpy(*name, name_buff,len_name); } } DA_LOG(Default,"Extracted file name : %s", *name); ERR: if (buff) { free (buff); buff = DA_NULL; } return ret; }