SET(VERSION ${PKG_VERSION}-${PKG_RELEASE})
MESSAGE("VERSION : ${VERSION}")
-IF(DEFINED SUPPORT_DBUS_SYSTEM)
- MESSAGE("SUPPORT DBUS SYSTEM : ${SUPPORT_DBUS_SYSTEM}")
- IF(SUPPORT_DBUS_SYSTEM)
- ADD_DEFINITIONS(-DDP_SUPPORT_DBUS_ACTIVATION)
- ENDIF(SUPPORT_DBUS_SYSTEM)
-ENDIF(DEFINED SUPPORT_DBUS_SYSTEM)
-
IF(DEFINED SUPPORT_WIFI_DIRECT)
MESSAGE("SUPPORT_WIFI_DIRECT: ${SUPPORT_WIFI_DIRECT}")
IF(SUPPORT_WIFI_DIRECT)
ADD_SUBDIRECTORY(agent)
ADD_SUBDIRECTORY(provider-interface)
ADD_SUBDIRECTORY(provider)
+# i18n
+ADD_SUBDIRECTORY(po)
# INSTALL
CONFIGURE_FILE(download-provider.pc.in download-provider.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/download-provider.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-INSTALL(PROGRAMS download-provider-service DESTINATION /etc/rc.d/init.d)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/download-provider.service DESTINATION /usr/lib/systemd/system)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/download-provider.socket DESTINATION /usr/lib/systemd/system)
+
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/download-provider-schema.sql DESTINATION ${DATABASE_SCHEMA_DIR})
# install images
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/res/images/ DESTINATION ${IMAGE_DIR}
FILES_MATCHING
PATTERN "*.png"
+ PATTERN "*.gif"
)
-IF(DEFINED DBUS_SERVICE_DIR)
- CONFIGURE_FILE(org.download-provider.service.in org.download-provider.service @ONLY)
- INSTALL(FILES org.download-provider.service DESTINATION ${DBUS_SERVICE_DIR})
-ENDIF(DEFINED DBUS_SERVICE_DIR)
-
IF(DEFINED LICENSE_DIR)
CONFIGURE_FILE(LICENSE.APLv2 share/license/${PROJECT_NAME})
INSTALL(FILES share/license/${PROJECT_NAME} DESTINATION ${LICENSE_DIR})
ENDIF(DEFINED LICENSE_DIR)
+
+IF(DEFINED SMACK_RULE_DIR)
+ INSTALL(FILES ${PROJECT_NAME}.rule DESTINATION ${SMACK_RULE_DIR})
+ENDIF(DEFINED SMACK_RULE_DIR)
+
da_result_t start_download(const char *url , int *dl_id)
{
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
return start_download_with_extension(url, dl_id, NULL);
}
const char *file_name = DA_NULL;
const char *etag = DA_NULL;
const char *temp_file_path = DA_NULL;
+ const char *pkg_name = DA_NULL;
int request_header_count = 0;
void *user_data = DA_NULL;
client_input_t *client_input = DA_NULL;
download_thread_input *thread_info = DA_NULL;
pthread_attr_t thread_attr;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (extension_data) {
request_header = extension_data->request_header;
user_data = extension_data->user_data;
etag = extension_data->etag;
temp_file_path = extension_data->temp_file_path;
+ pkg_name = extension_data->pkg_name;
}
ret = get_available_slot_id(&slot_id);
strncpy(client_input->temp_file_path, temp_file_path, strlen(temp_file_path));
}
+ if (pkg_name) {
+ client_input->pkg_name = (char *)calloc(strlen(pkg_name)+1, sizeof(char));
+ if (client_input->pkg_name)
+ strncpy(client_input->pkg_name, pkg_name, strlen(pkg_name));
+ }
client_input_basic = &(client_input->client_input_basic);
client_input_basic->req_url = (char *)calloc(strlen(url)+1, sizeof(char));
if(DA_NULL == client_input_basic->req_url) {
goto ERR;
}
}
- DA_LOG_CRITICAL(Thread, "download thread create slot_id[%d] thread id[%lu]",
+ DA_LOG_DEBUG(Thread, "download thread create slot_id[%d] thread id[%lu]",
slot_id,GET_DL_THREAD_ID(slot_id));
ERR:
source_info_t *source_info = DA_NULL;
source_info_basic_t *source_info_basic = DA_NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (!stage) {
DA_LOG_ERR(Default, "no stage; DA_ERR_INVALID_ARGUMENT");
source_info->source_info_type.source_info_basic = source_info_basic;
- DA_LOG(Default, "BASIC HTTP STARTED: URL=%s",
- source_info->source_info_type.source_info_basic->url);
+// DA_SECURE_LOGI("BASIC HTTP STARTED: URL=%s",
+// source_info->source_info_type.source_info_basic->url);
ERR:
return ret;
}
int slot_id = DA_INVALID_ID;
- DA_LOG_FUNC_START(Thread);
+ DA_LOG_FUNC_LOGV(Thread);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, DA_NULL);
DA_LOG_ERR(Default, "STAGE ADDITION FAIL!");
goto ERR;
}
- DA_LOG(Default, "new added Stage : %p", stage);
+ DA_LOG_VERBOSE(Default, "new added Stage : %p", stage);
GET_DL_USER_DATA(slot_id) = client_input->user_data;
client_input->user_data = DA_NULL;
client_input->etag = DA_NULL;
GET_DL_USER_TEMP_FILE_PATH(slot_id) = client_input->temp_file_path;
client_input->temp_file_path = DA_NULL;
+
ret = __make_source_info_basic_download(stage, client_input);
- /* to save memory */
- if (client_input) {
- clean_up_client_input_info(client_input);
- free(client_input);
- client_input = DA_NULL;
- }
- if (ret == DA_RESULT_OK)
- ret = __download_content(stage);
+ if (ret == DA_RESULT_OK) {
+ /* to save memory */
+ if (client_input) {
+ clean_up_client_input_info(client_input);
+ free(client_input);
+ client_input = DA_NULL;
+ }
+ ret = __download_content(stage);
+ if (stage != GET_DL_CURRENT_STAGE(slot_id)) {
+ DA_LOG_ERR(Default,"Playready download case. The next stage is present stage");
+ stage = GET_DL_CURRENT_STAGE(slot_id);
+ }
+ }
ERR:
if (client_input) {
clean_up_client_input_info(client_input);
char *etag = DA_NULL;
req_dl_info *request_info = NULL;
file_info *file_storage = NULL;
- DA_LOG_CRITICAL(Default, "Whole download flow is finished.");
+ DA_LOG_VERBOSE(Default, "Whole download flow is finished.");
_da_thread_mutex_lock (&mutex_download_state[GET_STAGE_DL_ID(stage)]);
download_state = GET_DL_STATE_ON_STAGE(stage);
_da_thread_mutex_unlock (&mutex_download_state[GET_STAGE_DL_ID(stage)]);
}
pthread_cleanup_pop(0);
- DA_LOG_CRITICAL(Thread, "=====thread_start_download - EXIT=====");
+ DA_LOG_CRITICAL(Thread, "==thread_start_download - EXIT==");
pthread_exit((void *)NULL);
return DA_NULL;
}
da_bool_t isDownloadComplete = DA_FALSE;
int slot_id = DA_INVALID_ID;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
slot_id = GET_STAGE_DL_ID(stage);
CHANGE_DOWNLOAD_STATE(DOWNLOAD_STATE_NEW_DOWNLOAD, stage);
stage = GET_DL_CURRENT_STAGE(slot_id);
_da_thread_mutex_lock (&mutex_download_state[GET_STAGE_DL_ID(stage)]);
download_state = GET_DL_STATE_ON_STAGE(stage);
- DA_LOG(Default, "download_state to - [%d] ", download_state);
+ DA_LOG_VERBOSE(Default, "download_state to - [%d] ", download_state);
_da_thread_mutex_unlock (&mutex_download_state[GET_STAGE_DL_ID(stage)]);
switch(download_state) {
da_result_t init_client_app_mgr()
{
- DA_LOG_FUNC_START(ClientNoti);
+ DA_LOG_FUNC_LOGV(ClientNoti);
if(client_app_mgr.is_init)
return DA_RESULT_OK;
client_queue_t *queue = DA_NULL;
client_noti_t *client_noti = DA_NULL;
- DA_LOG_FUNC_START(ClientNoti);
+ DA_LOG_FUNC_LOGD(ClientNoti);
memset(&(client_app_mgr.client_app_info.client_callback),
0, sizeof(da_client_cb_t));
{
client_noti_t *client_noti = DA_NULL;
- DA_LOG_FUNC_START(ClientNoti);
+ DA_LOG_FUNC_LOGV(ClientNoti);
client_noti = (client_noti_t *)calloc(1, sizeof(client_noti_t));
if (!client_noti) {
_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 (client_app_mgr.thread_id && pthread_cancel(client_app_mgr.thread_id) < 0) {
+ DA_LOG_CRITICAL(ClientNoti, "try to cancel client mgr thread id[%lu]",
+ client_app_mgr.thread_id);
+ if (client_app_mgr.thread_id &&
+ pthread_cancel(client_app_mgr.thread_id) < 0) {
DA_LOG_ERR(ClientNoti, "cancel thread is failed!!!");
}
free(client_noti);
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 (client_app_mgr.thread_id && pthread_join(client_app_mgr.thread_id, &t_return) < 0) {
+ DA_LOG_DEBUG(Thread, "===try to join client mgr thread id[%lu]===",
+ client_app_mgr.thread_id);
+ if (client_app_mgr.thread_id &&
+ 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_LOG_DEBUG(Thread, "===thread join return[%d]===", (char*)t_return);
}
_da_thread_mutex_unlock(&(client_app_mgr.mutex_client_mgr));
user_paused_info_t *paused_info = DA_NULL;
download_state_t state = GET_DL_STATE_ON_ID(slot_id);
- DA_LOG_FUNC_START(ClientNoti);
+ DA_LOG_FUNC_LOGD(ClientNoti);
if (!GET_DL_ENABLE_PAUSE_UPDATE(slot_id)) {
DA_LOG(ClientNoti, "Do not call pause cb");
client_noti_t *client_noti = DA_NULL;
user_progress_info_t *progress_info = DA_NULL;
- //DA_LOG_FUNC_START(ClientNoti);
+ DA_LOG_FUNC_LOGV(ClientNoti);
if (!is_valid_slot_id(slot_id)) {
DA_LOG_ERR(ClientNoti, "Download ID is not valid");
user_download_info_t *update_dl_info = DA_NULL;
int len = 0;
- DA_LOG_FUNC_START(ClientNoti);
+ DA_LOG_FUNC_LOGV(ClientNoti);
if (!is_valid_slot_id(slot_id)) {
DA_LOG_ERR(ClientNoti, "Download ID is not valid");
if (etag)
update_dl_info->etag = strdup(etag);
- DA_LOG(ClientNoti, "pushing file_size=%lu, slot_id=%d, dl_id=%d",
- file_size, slot_id, dl_id);
+ DA_LOG_DEBUG(ClientNoti, "pushing slot_id=%d, dl_id=%d", slot_id, dl_id);
push_client_noti(client_noti);
client_noti_t *client_noti = DA_NULL;
user_finished_info_t *finished_info = DA_NULL;
- DA_LOG_FUNC_START(ClientNoti);
+ DA_LOG_FUNC_LOGV(ClientNoti);
if (!is_valid_slot_id(slot_id)) {
DA_LOG_ERR(ClientNoti, "Download ID is not valid");
if (saved_path) {
finished_info->saved_path = strdup(saved_path);
- DA_LOG(ClientNoti, "saved path=%s", saved_path);
+ DA_SECURE_LOGD("saved path=%s", saved_path);
}
if (etag) {
finished_info->etag = strdup(etag);
- DA_LOG(ClientNoti, "pushing finished info. etag[%s]", etag);
+ DA_SECURE_LOGD("pushing finished info. etag[%s]", etag);
}
- DA_LOG(ClientNoti, "user_data=%p", client_noti->user_data);
- DA_LOG(ClientNoti, "http_status=%d", http_status);
+ DA_LOG_VERBOSE(ClientNoti, "user_data=%p", client_noti->user_data);
+ DA_LOG_VERBOSE(ClientNoti, "http_status=%d", http_status);
DA_LOG(ClientNoti, "pushing slot_id=%d, dl_id=%d err=%d", slot_id, dl_id, error);
push_client_noti(client_noti);
{
pthread_t thread_id = 0;
- DA_LOG_FUNC_START(Thread);
+ DA_LOG_FUNC_LOGV(Thread);
- if (pthread_create(&thread_id,DA_NULL,__thread_for_client_noti,DA_NULL) < 0) {
+ 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);
+ DA_LOG_VERBOSE(Thread, "client mgr thread id[%d]", thread_id);
client_app_mgr.thread_id = thread_id;
return DA_RESULT_OK;
}
client_noti_t *pre = DA_NULL;
client_noti_t *cur = DA_NULL;
- /* DA_LOG_FUNC_START(ClientNoti); */
-
queue = &(client_app_mgr.client_queue);
_da_thread_mutex_lock (&(queue->mutex_client_queue));
{
client_queue_t *queue = DA_NULL;
- /* DA_LOG_FUNC_START(ClientNoti); */
-
queue = &(client_app_mgr.client_queue);
_da_thread_mutex_lock (&(queue->mutex_client_queue));
void __client_q_goto_sleep_without_lock(void)
{
client_queue_t *queue = DA_NULL;
-
- /* DA_LOG_FUNC_START(ClientNoti); */
-
queue = &(client_app_mgr.client_queue);
_da_thread_cond_wait(&(queue->cond_client_queue), &(queue->mutex_client_queue));
}
void __client_q_wake_up_without_lock(void)
{
client_queue_t *queue = DA_NULL;
-
- /* DA_LOG_FUNC_START(ClientNoti); */
-
queue = &(client_app_mgr.client_queue);
_da_thread_cond_signal(&(queue->cond_client_queue));
}
client_queue_t *queue = DA_NULL;
client_noti_t *client_noti = DA_NULL;
- //DA_LOG_FUNC_START(Thread);
+ DA_LOG_FUNC_LOGV(Thread);
_da_thread_mutex_lock(&(client_app_mgr.mutex_client_mgr));
client_app_mgr.is_thread_init = DA_TRUE;
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);
if (update_dl_info->etag)
- DA_LOG(ClientNoti, "Etag:[%s]", update_dl_info->etag);
- DA_LOG(ClientNoti, "Update download info for slot_id=%d, dl_id=%d, received size=%lu- DONE",
+ DA_SECURE_LOGD("Etag:[%s]", update_dl_info->etag);
+ DA_SECURE_LOGD("file size=%lu", update_dl_info->file_size);
+ DA_LOG(ClientNoti, "Update download info for slot_id=%d, dl_id=%d- DONE",
client_noti->slot_id,
- update_dl_info->download_id,
- update_dl_info->file_size
+ update_dl_info->download_id
);
}
}
if (client_app_mgr.client_app_info.client_callback.finished_info_cb) {
client_app_mgr.client_app_info.client_callback.finished_info_cb(
finished_info, client_noti->user_data);
- DA_LOG(ClientNoti, "Completed info for slot_id=%d, dl_id=%d, saved_path=%s etag=%s err=%d http_state=%d user_data=%p- DONE",
+ DA_LOG(ClientNoti, "Completed info for slot_id=%d, dl_id=%d, err=%d http_state=%d user_data=%p- DONE",
client_noti->slot_id,
finished_info->download_id,
- finished_info->saved_path,
- finished_info->etag,
finished_info->err,
finished_info->http_status,
client_noti->user_data);
+ if (finished_info->etag)
+ DA_SECURE_LOGD("Completed info for etag=%s - DONE",
+ finished_info->etag);
+
}
}
break;
}
break;
case Q_CLIENT_NOTI_TYPE_TERMINATE:
- DA_LOG_CRITICAL(ClientNoti, "Q_CLIENT_NOTI_TYPE_TERMINATE");
+ DA_LOG_VERBOSE(ClientNoti, "Q_CLIENT_NOTI_TYPE_TERMINATE");
need_wait = DA_FALSE;
break;
}
_da_thread_cond_destroy(&(queue->cond_client_queue));
pthread_cleanup_pop(0);
- DA_LOG_CRITICAL(Thread, "=====thread_for_client_noti- EXIT=====");
+ DA_LOG_DEBUG(Thread, "=====thread_for_client_noti- EXIT=====");
pthread_exit((void *)NULL);
return DA_NULL;
}
da_result_t ret = DA_RESULT_OK;
int i = 0;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
_da_thread_mutex_lock(&mutex_download_mgr);
da_result_t deinit_download_mgr(void) {
da_result_t ret = DA_RESULT_OK;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
_da_thread_mutex_lock(&mutex_download_mgr);
if (download_mgr.is_init == DA_TRUE) {
{
dl_info_t *dl_info = DA_NULL;
-// DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
_da_thread_mutex_lock(&mutex_download_state[slot_id]);
-// DA_LOG_VERBOSE(Default, "Init slot_id [%d] Info", slot_id);
dl_info = &(download_mgr.dl_info[slot_id]);
-
dl_info->is_using = DA_FALSE;
dl_info->state = DOWNLOAD_STATE_IDLE;
dl_info->download_stage_data = DA_NULL;
{
dl_info_t *dl_info = DA_NULL;
- DA_LOG_FUNC_START(Default);
-
- DA_LOG(Default, "Destroying slot_id [%d] Info", slot_id);
+ DA_LOG_VERBOSE(Default, "Destroying slot_id [%d] Info", slot_id);
if (slot_id == DA_INVALID_ID) {
DA_LOG_ERR(Default, "invalid slot_id");
dl_info = &(download_mgr.dl_info[slot_id]);
if (DA_FALSE == dl_info->is_using) {
-/* DA_LOG_ERR(Default, "invalid slot_id"); */
return;
}
_da_thread_mutex_lock (&mutex_download_state[slot_id]);
dl_info->state = DOWNLOAD_STATE_IDLE;
- DA_LOG(Default, "Changed download_state to - [%d] ", dl_info->state);
-
dl_info->active_dl_thread_id = 0;
if (dl_info->download_stage_data != DA_NULL) {
dl_info->user_etag = DA_NULL;
}
- if (dl_info->user_temp_file_path ) {
- free(dl_info->user_temp_file_path );
- dl_info->user_temp_file_path = DA_NULL;
+ if (dl_info->user_temp_file_path) {
+ free(dl_info->user_temp_file_path);
+ dl_info->user_temp_file_path = DA_NULL;
}
dl_info->user_data = DA_NULL;
dl_info->is_using = DA_FALSE;
- DA_LOG(Default, "Destroying slot_id [%d] Info END", slot_id);
+ DA_LOG_DEBUG(Default, "Destroying slot_id [%d] Info END", slot_id);
_da_thread_mutex_unlock (&mutex_download_state[slot_id]);
return;
}
stage_info *download_stage_data = NULL;
stage_info *new_download_stage_data = NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
new_download_stage_data = (stage_info*)calloc(1, sizeof(stage_info));
if (!new_download_stage_data)
} else {
GET_DL_CURRENT_STAGE(slot_id) = new_download_stage_data;
}
- DA_LOG(Default, "NEW STAGE ADDED FOR DOWNLOAD ID[%d] new_stage[%p]", slot_id,new_download_stage_data);
+ DA_LOG_VERBOSE(Default, "NEW STAGE ADDED FOR DOWNLOAD ID[%d] new_stage[%p]", slot_id,new_download_stage_data);
ERR:
return new_download_stage_data;
{
stage_info *stage = DA_NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
stage = GET_DL_CURRENT_STAGE(slot_id);
if (DA_NULL == stage) {
req_dl_info *request_download_info = NULL;
file_info *file_information = NULL;
- DA_LOG_FUNC_START(Default);
-
- DA_LOG(Default, "Stage to Remove:[%p]", in_stage);
+ DA_LOG_VERBOSE(Default, "Stage to Remove:[%p]", in_stage);
source_information = GET_STAGE_SOURCE_INFO(in_stage);
cleanup_source_info_basic_download(
if (NULL == source_info_basic)
goto ERR;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (NULL != source_info_basic->url) {
free(source_info_basic->url);
void cleanup_req_dl_info_http(req_dl_info *http_download)
{
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (http_download->http_info.http_msg_request) {
http_msg_request_destroy(
&(http_download->http_info.http_msg_request));
+ http_download->http_info.http_msg_request = DA_NULL;
}
if (http_download->http_info.http_msg_response) {
http_msg_response_destroy(
&(http_download->http_info.http_msg_response));
+ http_download->http_info.http_msg_response = DA_NULL;
}
if (DA_NULL != http_download->location_url) {
void destroy_file_info(file_info *file_information)
{
-// DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (!file_information)
return;
void clean_up_client_input_info(client_input_t *client_input)
{
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (client_input) {
client_input->user_data = NULL;
client_input->temp_file_path = DA_NULL;
}
+ if (client_input->pkg_name) {
+ free(client_input->pkg_name);
+ client_input->pkg_name = DA_NULL;
+ }
+
client_input_basic_t *client_input_basic =
&(client_input->client_input_basic);
= get_available_dl_id(&(download_mgr.dl_id_history));
*available_id = i;
- DA_LOG_CRITICAL(Default, "available download id = %d", *available_id);
+ DA_LOG_VERBOSE(Default, "available download id = %d", *available_id);
ret = DA_RESULT_OK;
break;
da_result_t ret = DA_RESULT_OK;
req_dl_info *request_session = DA_NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (!stage) {
DA_LOG_ERR(Default, "stage is null..");
request_session = GET_STAGE_TRANSACTION_INFO(stage);
ret = request_http_download(stage);
if (DA_RESULT_OK == ret) {
- DA_LOG(Default, "Http download is complete.");
+ DA_LOG_VERBOSE(Default, "Http download is complete.");
} else {
DA_LOG_ERR(Default, "Http download is failed. ret = %d", ret);
goto ERR;
da_result_t ret = DA_RESULT_OK;
da_mime_type_id_t mime_type = DA_MIME_TYPE_NONE;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
mime_type = get_mime_type_id(
GET_CONTENT_STORE_CONTENT_TYPE(GET_STAGE_CONTENT_STORE_INFO(stage)));
download_state_t download_state;
stage_info *stage = DA_NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
_da_thread_mutex_lock (&mutex_download_state[slot_id]);
download_state = GET_DL_STATE_ON_ID(slot_id);
int slot_id = DA_INVALID_ID;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
ret = get_slot_id_for_dl_id(dl_id, &slot_id);
if (ret != DA_RESULT_OK) {
download_state_t download_state;
stage_info *stage = DA_NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
_da_thread_mutex_lock (&mutex_download_state[slot_id]);
download_state = GET_DL_STATE_ON_ID(slot_id);
da_result_t ret = DA_RESULT_OK;
int slot_id = DA_INVALID_ID;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
ret = get_slot_id_for_dl_id(dl_id, &slot_id);
if (ret != DA_RESULT_OK) {
download_state_t download_state;
stage_info *stage = DA_NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
_da_thread_mutex_lock (&mutex_download_state[slot_id]);
download_state = GET_DL_STATE_ON_ID(slot_id);
da_result_t ret = DA_RESULT_OK;
int slot_id = DA_INVALID_ID;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
ret = get_slot_id_for_dl_id(dl_id, &slot_id);
if (ret != DA_RESULT_OK)
int slot_id, char *installed_path, char *etag)
{
da_result_t ret = DA_RESULT_OK;
- download_state_t download_state = DA_NULL;
+ download_state_t download_state = HTTP_STATE_READY_TO_DOWNLOAD;
da_bool_t need_destroy_download_info = DA_FALSE;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(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_LOG_DEBUG(Default, "state = %d", download_state);
_da_thread_mutex_unlock (&mutex_download_state[slot_id]);
switch (download_state) {
snprintf(second_needle, sizeof(second_needle), "%s", "?="); // ?=
}
-// DA_LOG(Default, "needle = [%s], haystack = [%s]", first_needle, haystack);
+// DA_SECURE_LOGD("needle = [%s], haystack = [%s]", first_needle, haystack);
found_str = strstr(haystack, first_needle);
if (found_str) {
if (found_str == haystack) {
-// DA_LOG(Default, "Input string is starting with %s", needle);
+// DA_SECURE_LOGD("Input string is starting with %s", needle);
haystack = haystack + strlen(haystack) - strlen(second_needle);
-// DA_LOG(Default, "second haystack is [%s]", haystack);
+// DA_SECURE_LOGD("second haystack is [%s]", haystack);
if(!strcmp(haystack, second_needle))
return DA_TRUE;
}
guchar *g_decoded_text = NULL;
gsize g_decoded_text_len = 0;
- DA_LOG(Default, "input str = [%s]", in_encoded_str);
+ DA_SECURE_LOGD("input str = [%s]", in_encoded_str);
org_str = in_encoded_str;
if(!org_str) {
goto ERR;
}
-// DA_LOG(Default, "charset = [%s], encoding = [%c], raw = [%s]", charset_type, encoding_type, raw_encoded_str);
+// DA_SECURE_LOGD("charset = [%s], encoding = [%c], raw = [%s]", charset_type, encoding_type, raw_encoded_str);
if(encoding_type != 'B') {
DA_LOG_ERR(Default, "Encoded Word is not encoded with Base64, but %c. We can only handle Base64.", encoding_type);
g_decoded_text = g_base64_decode(g_encoded_text, &g_decoded_text_len);
if(g_decoded_text) {
- DA_LOG(Default, "g_decoded_text = [%s]", 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_LOG_ERR(Default, "DA_ERR_FAIL_TO_MEMALLOC");
memcpy(decoded_str, g_decoded_text, g_decoded_text_len);
}
}
- DA_LOG(Default, "decoded_str = [%s]", decoded_str);
+ DA_SECURE_LOGD("decoded_str = [%s]", decoded_str);
ERR:
*out_decoded_ascii_str = decoded_str;
goto ERR;
} else {
wanted_str = wanted_str_end + strlen(needle);
- DA_LOG(Default, "strip [%s]", wanted_str);
+ DA_SECURE_LOGD("strip [%s]", wanted_str);
}
// for charset
wanted_str = NULL;
}
- DA_LOG(Default, "raw encoded str [%s]", raw_encoded_str);
+ DA_SECURE_LOGD("raw encoded str [%s]", raw_encoded_str);
}
ERR:
* limitations under the License.
*/
+#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <math.h>
-
+#include <errno.h>
#include "download-agent-client-mgr.h"
#include "download-agent-debug.h"
#include "download-agent-utils.h"
#include "download-agent-http-mgr.h"
#include "download-agent-plugin-conf.h"
-#ifdef _ENABLE_OMA_DRM
-#include "download-agent-plugin-drm.h"
-#endif
-
-
#define NO_NAME_TEMP_STR "No name"
static da_result_t __set_file_size(stage_info *stage);
static da_result_t __file_write_buf_directly_write(stage_info *stage,
file_info *file_storage, char *body, int body_len);
-
da_result_t clean_files_from_dir(char *dir_path)
{
da_result_t ret = DA_RESULT_OK;
DIR *dir;
char file_path[DA_MAX_FULL_PATH_LEN] = { 0, };
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGD(FileManager);
if (dir_path == DA_NULL)
return DA_ERR_INVALID_ARGUMENT;
if (is_dir_exist(dir_path)) {
dir = opendir(dir_path);
if (DA_NULL == dir) {
- DA_LOG_ERR(FileManager, "opendir() for %s is failed.", dir_path);
+ DA_LOG_ERR(FileManager, "opendir() is failed.");
ret = DA_ERR_INVALID_INSTALL_PATH;
} else {
while (DA_NULL != (d = readdir(dir))) {
- DA_LOG(FileManager, "%s",d->d_name);
+ DA_SECURE_LOGD("%s",d->d_name);
if (0 == strncmp(d->d_name, ".", strlen("."))
|| 0 == strncmp(d->d_name,
"..",
/* Priority 1 */
if (GET_REQUEST_HTTP_HDR_CONT_TYPE(GET_STAGE_TRANSACTION_INFO(stage))) {
mime_type = GET_REQUEST_HTTP_HDR_CONT_TYPE(GET_STAGE_TRANSACTION_INFO(stage));
- DA_LOG(FileManager, "content type from HTTP response header [%s]", mime_type);
+// DA_SECURE_LOGI("content type from HTTP response header [%s]", mime_type);
}
if (!mime_type) {
*out_mime_type = (char *)calloc(1, strlen(mime_type) + 1);
if (*out_mime_type) {
strncpy(*out_mime_type, mime_type, strlen(mime_type));
- DA_LOG_VERBOSE(FileManager, "out_mime_type str[%s] ptr[%p] len[%d]",
- *out_mime_type,*out_mime_type,strlen(*out_mime_type));
+// DA_SECURE_LOGD("out_mime_type str[%s] ptr[%p] len[%d]",
+// *out_mime_type,*out_mime_type,strlen(*out_mime_type));
} else {
DA_LOG_ERR(FileManager, "fail to allocate memory");
return DA_ERR_FAIL_TO_MEMALLOC;
}
- DA_LOG(FileManager, "mime type = %s", *out_mime_type);
+// DA_SECURE_LOGD("mime type = %s", *out_mime_type);
return DA_RESULT_OK;
}
if (stat_ret == 0) {
if (dir_state.st_mode & S_IFREG) {
- DA_LOG(FileManager, "Exist! %s is a regular file & its size = %lu", file_path, dir_state.st_size);
+ DA_SECURE_LOGD("Exist! %s is a regular file & its size = %lu", file_path, dir_state.st_size);
return DA_TRUE;
}
if (stat_ret == 0) {
if (dir_state.st_mode & S_IFDIR) {
- DA_LOG(FileManager, "Exist! %s is a directory.", file_path);
+ DA_LOG_VERBOSE(FileManager, "Existed directory.");
return DA_TRUE;
}
char *actual_file_path = DA_NULL;
void *fd = DA_NULL;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
if (!file_storage)
return DA_ERR_INVALID_ARGUMENT;
actual_file_path = GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_storage);
- DA_LOG(FileManager, "actual_file_path = %s", actual_file_path);
if (!actual_file_path)
return DA_ERR_INVALID_ARGUMENT;
-
fd = fopen(actual_file_path, "a+"); // for resume
if (fd == DA_NULL) {
DA_LOG_ERR(FileManager, "File open failed");
- ret = DA_ERR_FAIL_TO_ACCESS_FILE;
+ if (errno == ENOSPC)
+ ret = DA_ERR_DISK_FULL;
+ else
+ ret = DA_ERR_FAIL_TO_ACCESS_FILE;
goto ERR;
}
GET_CONTENT_STORE_FILE_HANDLE(file_storage) = fd;
- DA_LOG(FileManager, "file path for saving = %s",
- GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_storage));
+// DA_SECURE_LOGD("file path for saving = %s",
+// GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_storage));
ERR:
if (DA_RESULT_OK != ret) {
req_dl_info *stage_req_info = DA_NULL;
file_info *file_storage = DA_NULL;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
if (!stage) {
ret = DA_ERR_INVALID_ARGUMENT;
if (!file_storage)
goto ERR;
- if (GET_REQUEST_HTTP_HDR_CONT_LEN(stage_req_info) != DA_NULL) {
+ if (GET_REQUEST_HTTP_HDR_CONT_LEN(stage_req_info) != 0) {
GET_CONTENT_STORE_FILE_SIZE(file_storage)
= GET_REQUEST_HTTP_HDR_CONT_LEN(stage_req_info);
} else {
GET_CONTENT_STORE_FILE_SIZE(file_storage) = 0;
}
- DA_LOG(FileManager, "file size = %d", GET_CONTENT_STORE_FILE_SIZE(file_storage));
+ DA_LOG_VERBOSE(FileManager, "file size = %d", GET_CONTENT_STORE_FILE_SIZE(file_storage));
ERR:
return ret;
DA_NULL, &file_name);
if (b_ret && file_name) {
char *extension = DA_NULL;
- DA_LOG(FileManager, "Name from Content-Disposition :[%s]", file_name);
+ DA_SECURE_LOGD("Name from Content-Disposition :[%s]", file_name);
__divide_file_name_into_pure_name_N_extesion(file_name, DA_NULL, &extension);
if (file_name) {
free(file_name);
else
url = GET_SOURCE_BASIC_URL(source_info);
if (url) {
- DA_LOG(FileManager, "url:[%s]", url);
+ DA_SECURE_LOGD("url:[%s]", url);
da_bool_t b_ret = da_get_extension_name_from_url(url, &extension);
if (b_ret && extension)
return extension;
char *pure_file_name = DA_NULL;
char *extension = DA_NULL;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
if (!stage || !out_pure_file_name)
return DA_ERR_INVALID_ARGUMENT;
da_bool_t b_ret = http_msg_response_get_content_disposition(http_msg_response,
DA_NULL, &file_name);
if (b_ret && file_name) {
- DA_LOG(FileManager, "Name from Content-Disposition :[%s]", file_name);
- __divide_file_name_into_pure_name_N_extesion(file_name, &pure_file_name, DA_NULL);
+ DA_SECURE_LOGD("Name from Content-Disposition :[%s]", file_name);
+ __divide_file_name_into_pure_name_N_extesion(file_name, &pure_file_name, &extension);
if (file_name) {
free(file_name);
file_name = DA_NULL;
else
url = GET_SOURCE_BASIC_URL(source_info);
if (url) {
- DA_LOG(FileManager, "url: [%s]", url);
+ DA_SECURE_LOGD("url: [%s]", url);
da_get_file_name_from_url(url, &pure_file_name);
}
}
*out_pure_file_name = pure_file_name;
pure_file_name = DA_NULL;
- DA_LOG(FileManager, "candidate file name [%s]", *out_pure_file_name);
+ DA_SECURE_LOGD("candidate file name [%s]", *out_pure_file_name);
if (out_extension) {
if (extension) {
extension = DA_NULL;
} else {
*out_extension = __derive_extension(stage);
- DA_LOG(FileManager, "candidate extension [%s]", *out_extension);
+ DA_SECURE_LOGD("candidate extension [%s]", *out_extension);
}
}
char *user_install_path = DA_NULL;
file_info *file_info_data = DA_NULL;
int len = 0;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
file_info_data = GET_STAGE_CONTENT_STORE_INFO(stage);
if (!file_info_data)
}
ERR:
- DA_LOG(FileManager, "decided file path = %s", GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_info_data));
+ DA_SECURE_LOGI("decided file path = %s", GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_info_data));
if (temp_dir) {
free(temp_dir);
temp_dir = DA_NULL;
int final_path_len = 0;
int extension_len = 0;
- int suffix_count = 0; /* means suffix on file name. up to "_99" */
- const int max_suffix_count = 99;
+ int suffix_count = 0; /* means suffix on file name. up to "_1000000000" */
+ const int max_suffix_count = 1000000000;
int suffix_len = (int)log10(max_suffix_count+1) + 1; /* 1 means "_" */
if (!in_dir || !in_candidate_file_name)
return DA_NULL;
-// DA_LOG_FUNC_START(FileManager);
- DA_LOG(FileManager, "in_candidate_file_name=[%s], in_extension=[%s]", in_candidate_file_name, in_extension);
+// DA_SECURE_LOGD("in_candidate_file_name=[%s], in_extension=[%s]", in_candidate_file_name, in_extension);
if (extension)
extension_len = strlen(extension);
break;
} while (1);
- DA_LOG(FileManager, "decided path = [%s]", final_path);
+// DA_SECURE_LOGD("decided path = [%s]", final_path);
return final_path;
}
int len = 0;
da_result_t ret = DA_RESULT_OK;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGD(FileManager);
if (!in_file_name)
return DA_ERR_INVALID_ARGUMENT;
if (tmp_ptr && out_extension) {
strncpy((char*) tmp_ext, tmp_ptr, sizeof(tmp_ext) - 1);
*out_extension = strdup((const char*) tmp_ext);
- DA_LOG(FileManager, "extension [%s]", *out_extension);
+ DA_SECURE_LOGD("extension [%s]", *out_extension);
}
if (!out_pure_file_name)
(const char*) temp_file);
}
- DA_LOG(FileManager, "pure file name [%s]", *out_pure_file_name);
+ DA_SECURE_LOGD("pure file name [%s]", *out_pure_file_name);
return ret;
}
da_result_t ret = DA_RESULT_OK;
char *buffer = DA_NULL;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
buffer = (char*) calloc(DOWNLOAD_NOTIFY_LIMIT, 1);
if (DA_NULL == buffer) {
{
da_result_t ret = DA_RESULT_OK;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
if (GET_CONTENT_STORE_FILE_BUFFER(file_storage))
free(GET_CONTENT_STORE_FILE_BUFFER(file_storage));
int write_success_len = 0;
void *fd = DA_NULL;
- // DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
buffer = GET_CONTENT_STORE_FILE_BUFFER(file_storage);
buffer_size = GET_CONTENT_STORE_FILE_BUFF_LEN(file_storage);
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.
//fflush((FILE *) fd);
if (write_success_len != buffer_size) {
DA_LOG_ERR(FileManager, "write fails ");
- ret = DA_ERR_FAIL_TO_ACCESS_FILE;
+ if (errno == ENOSPC)
+ ret = DA_ERR_DISK_FULL;
+ else
+ ret = DA_ERR_FAIL_TO_ACCESS_FILE;
goto ERR;
}
GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage))
+= write_success_len;
- DA_LOG(FileManager, "write %d bytes", write_success_len);
-
+ DA_LOG_VERBOSE(FileManager, "write %d bytes", write_success_len);
IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(file_storage) = DA_TRUE;
GET_CONTENT_STORE_FILE_BUFF_LEN(file_storage) = 0;
char *buffer = DA_NULL;
int buffer_size = 0;
- // DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
buffer = GET_CONTENT_STORE_FILE_BUFFER(file_storage);
buffer_size = GET_CONTENT_STORE_FILE_BUFF_LEN(file_storage);
int write_success_len = 0;
void *fd = DA_NULL;
- // DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
fd = GET_CONTENT_STORE_FILE_HANDLE(file_storage);
if (DA_NULL == fd) {
ret = DA_ERR_FAIL_TO_ACCESS_FILE;
goto ERR;
}
-
write_success_len = fwrite(body, sizeof(char), body_len,
(FILE *) fd);
/* FIXME : This can be necessary later due to progressive download.
//fflush((FILE *) fd);
if (write_success_len != body_len) {
DA_LOG_ERR(FileManager, "write fails ");
- ret = DA_ERR_FAIL_TO_ACCESS_FILE;
+ if (errno == ENOSPC)
+ ret = DA_ERR_DISK_FULL;
+ else
+ ret = DA_ERR_FAIL_TO_ACCESS_FILE;
goto ERR;
}
GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage))
int buffer_size = 0;
char *buffer = DA_NULL;
- // DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
if (!file_storage) {
unsigned int buffer_size = 0;
void *fd = DA_NULL;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
if (!file_storage) {
da_result_t ret = DA_RESULT_OK;
file_info *file_info_data = DA_NULL;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGV(FileManager);
file_info_data = GET_STAGE_CONTENT_STORE_INFO(stage);
ret = get_mime_type(stage,
{
da_result_t ret = DA_RESULT_OK;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGD(FileManager);
ret = __saved_file_open(stage);
req_dl_info *request_info = DA_NULL;
unsigned long long temp_file_size = 0;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGD(FileManager);
file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
if (!file_storage)
file_info *file_storage = DA_NULL;
FILE *f_handle = DA_NULL;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGD(FileManager);
file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);
char *paused_file_path = DA_NULL;
FILE *fd = DA_NULL;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGD(FileManager);
file_info_data = GET_STAGE_CONTENT_STORE_INFO(stage);
char *dd_file_path = DA_NULL;
int len;
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGD(FileManager);
if (!dest_dd_file_path
&& (DA_FALSE == is_file_exist(dest_dd_file_path))) {
int fwritenum = 0;
char buff[4096] = { 0, };
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGD(FileManager);
/* open files to copy */
fs = fopen(src, "rb");
/* 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 [%s]", install_dir);
+ DA_LOG_ERR(FileManager, "Fail to creaate directory");
ret = DA_ERR_FAIL_TO_ACCESS_STORAGE;
} else {
- DA_LOG(FileManager, "[%s] is created!", install_dir);
+ DA_SECURE_LOGD("[%s] is created!", install_dir);
if (chown(install_dir, 5000, 5000) < 0) {
DA_LOG_ERR(FileManager, "Fail to chown");
ret = DA_ERR_FAIL_TO_ACCESS_STORAGE;
return ret;
}
-
-da_result_t get_default_dir(char **out_path)
-{
- char *tmp_default_path = DA_NULL;
- int len = 0;
-
- if (!out_path) {
- DA_LOG_ERR(ClientNoti, "DA_ERR_INVALID_ARGUMENT");
- return DA_ERR_INVALID_ARGUMENT;
- }
-
- len = strlen(DA_DEFAULT_FILE_DIR_PATH);
- tmp_default_path = calloc(len + 1, sizeof(char));
- if (!tmp_default_path) {
- return DA_ERR_FAIL_TO_MEMALLOC;
- }
-
- memcpy(tmp_default_path, DA_DEFAULT_FILE_DIR_PATH, len);
- tmp_default_path[len] = '\0';
-
- *out_path = tmp_default_path;
-
- DA_LOG_VERBOSE(FileManager, "default temp path = [%s]", *out_path);
-
- return DA_RESULT_OK;
-}
-
da_result_t get_default_install_dir(char **out_path)
{
char *default_path = DA_NULL;
- da_storage_type_t type;
da_result_t ret = DA_RESULT_OK;
int len = 0;
DA_LOG_ERR(ClientNoti, "DA_ERR_INVALID_ARGUMENT");
return DA_ERR_INVALID_ARGUMENT;
}
- ret = get_storage_type(&type);
- if (DA_RESULT_OK != ret)
- return ret;
- if (type == DA_STORAGE_MMC)
- len = strlen(DA_DEFAULT_INSTALL_PATH_FOR_MMC);
- else
- len = strlen(DA_DEFAULT_INSTALL_PATH_FOR_PHONE);
+
+ len = strlen(DA_DEFAULT_INSTALL_PATH_FOR_PHONE);
default_path = calloc(len + 1, sizeof(char));
if (!default_path) {
return DA_ERR_FAIL_TO_MEMALLOC;
}
- if (type == DA_STORAGE_MMC)
- memcpy(default_path, DA_DEFAULT_INSTALL_PATH_FOR_MMC, len);
- else // DA_STROAGE_PHONE
- memcpy(default_path, DA_DEFAULT_INSTALL_PATH_FOR_PHONE, len);
+
+ 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_LOG_VERBOSE(FileManager, "default temp path = [%s]", *out_path);
+ DA_SECURE_LOGD("default temp path = [%s]", *out_path);
return DA_RESULT_OK;
}
{
da_result_t ret = DA_RESULT_OK;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (http_mgr.is_http_init == DA_FALSE) {
http_mgr.is_http_init = DA_TRUE;
da_result_t ret = DA_RESULT_OK;
q_event_t *q_event = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
if (!stage) {
DA_LOG_ERR(HTTPManager, "Stage is NULL. download info is already destroyed");
return DA_ERR_INVALID_ARGUMENT;
void deinit_http_mgr(void)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (http_mgr.is_http_init == DA_TRUE) {
http_mgr.is_http_init = DA_FALSE;
queue_t *queue = DA_NULL;
req_dl_info *req_info = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
-
slot_id = GET_STAGE_DL_ID(stage);
queue = GET_DL_QUEUE(slot_id);
req_info = GET_STAGE_TRANSACTION_INFO(stage);
- DA_LOG(HTTPManager, "queue = %p", GET_DL_QUEUE(slot_id));
+ DA_LOG_VERBOSE(HTTPManager, "queue = %p", GET_DL_QUEUE(slot_id));
CHANGE_HTTP_STATE(HTTP_STATE_READY_TO_DOWNLOAD, stage);
#ifdef PAUSE_EXIT
case HTTP_STATE_PAUSED:
#endif
- DA_LOG(HTTPManager, "exiting...");
+ DA_LOG_VERBOSE(HTTPManager, "exiting...");
need_wait = DA_FALSE;
break;
if (DA_FALSE == GET_IS_Q_HAVING_DATA(queue)) {
unpause_for_flow_control(stage);
-// DA_LOG(HTTPManager, "Waiting for input");
+// DA_LOG_VERBOSE(HTTPManager, "Waiting for input");
Q_goto_sleep(queue);
-// DA_LOG(HTTPManager, "Woke up to receive new packet or control event");
+// DA_LOG_VERBOSE(HTTPManager, "Woke up to receive new packet or control event");
}
_da_thread_mutex_unlock (&(queue->mutex_queue));
} while (need_wait == DA_TRUE);
ret = GET_REQUEST_HTTP_RESULT(req_info);
- DA_LOG(HTTPManager, "--------------Exiting request_http_download! ret = %d", ret);
+ DA_LOG_DEBUG(HTTPManager, "Exit request_http_download! ret[%d]slot_id[%d]",
+ ret, slot_id);
return ret;
}
da_result_t ret = DA_RESULT_OK;
q_event_t *q_event = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
DA_LOG(HTTPManager, "Q_EVENT_TYPE_CONTROL_CANCEL");
ret = Q_make_control_event(Q_EVENT_TYPE_CONTROL_CANCEL, &q_event);
http_state_t http_state = 0;
q_event_t *q_event = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
http_state = GET_HTTP_STATE_ON_STAGE(stage);
http_state_t http_state = 0;
q_event_t *q_event = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
http_state = GET_HTTP_STATE_ON_STAGE(stage);
http_msg_request_t *http_msg_request = NULL;
char *user_agent = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!url) {
DA_LOG_ERR(HTTPManager, "DA_ERR_NO_URL");
char *user_request_temp_file_path = DA_NULL;
http_msg_request_t* http_msg_request = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
request_info = GET_STAGE_TRANSACTION_INFO(stage);
user_request_temp_file_path = GET_REQUEST_HTTP_USER_REQUEST_TEMP_FILE_PATH(
request_info);
if (user_request_etag) {
- DA_LOG(HTTPManager, "user_request_etag[%s]",user_request_etag);
+ DA_SECURE_LOGD("user_request_etag[%s]",user_request_etag);
} else {
- DA_LOG_ERR(HTTPManager, "user_request_etag is NULL");
+ DA_LOG_VERBOSE(HTTPManager, "user_request_etag is NULL");
}
ret = make_default_http_request_hdr(url, user_request_header,
user_request_header_count, &http_msg_request,
input_for_tranx_t *input_for_tranx = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
slot_id = GET_STAGE_DL_ID(stage);
int dl_id = -1;
source_info_t *source_info = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!stage) {
DA_LOG_ERR(HTTPManager, "stage is NULL");
user_request_etag = GET_DL_USER_ETAG(GET_STAGE_DL_ID(stage));
user_request_temp_file_path = GET_DL_USER_TEMP_FILE_PATH(GET_STAGE_DL_ID(stage));
- DA_LOG(HTTPManager, "url [%s]", url);
+ DA_SECURE_LOGD("url [%s]", url);
if (url) {
GET_REQUEST_HTTP_REQ_URL(out_info) = url;
{
da_result_t ret = DA_RESULT_OK;
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
PI_http_unpause_transaction(
GET_REQUEST_HTTP_TRANS_ID(GET_STAGE_TRANSACTION_INFO(stage)));
da_result_t ret = DA_RESULT_OK;
http_state_t state = 0;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
state = GET_HTTP_STATE_ON_STAGE(stage);
da_result_t ret = DA_RESULT_OK;
http_state_t state = 0;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
state = GET_HTTP_STATE_ON_STAGE(stage);
char *etag_from_response = NULL;
char *date_from_response = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
request_info = GET_STAGE_TRANSACTION_INFO(stage);
if (b_ret) {
etag_from_response = value;
value = NULL;
- DA_LOG(HTTPManager, "[ETag][%s]", etag_from_response);
+ 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_LOG(HTTPManager, "[Date][%s]", date_from_response);
+ DA_SECURE_LOGD("[Date][%s]", date_from_response);
}
downloaded_data_size
queue_t *queue = DA_NULL;
q_event_t *event = DA_NULL;
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
queue = GET_DL_QUEUE(slot_id);
Q_pop_event(queue, &event);
if (event == DA_NULL) {
- DA_LOG(HTTPManager, "There is no data on the queue!");
+ DA_LOG_DEBUG(HTTPManager, "There is no data on the queue!");
return DA_RESULT_OK;
}
{
da_result_t ret = DA_RESULT_OK;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
if (event->event_type == Q_EVENT_TYPE_CONTROL) {
switch (event->type.q_event_control.control_type) {
case Q_EVENT_TYPE_CONTROL_NET_DISCONNECTED:
DA_LOG(HTTPManager, "Q_EVENT_TYPE_CONTROL_NET_DISCONNECTED");
break;
+ case Q_EVENT_TYPE_CONTROL_NONE:
+ default:
+ DA_LOG_ERR(HTTPManager, "Cannot enter here");
+ break;
}
}
da_result_t ret = DA_RESULT_OK;
q_event_data_http_t *q_event_data_http = DA_NULL;
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (event->event_type == Q_EVENT_TYPE_DATA_HTTP) {
q_event_data_http = &(event->type.q_event_data_http);
switch (q_event_data_http->data_type) {
case Q_EVENT_TYPE_DATA_PACKET:
ret = handle_event_http_packet(stage, event);
-
break;
-
case Q_EVENT_TYPE_DATA_FINAL:
- DA_LOG(HTTPManager, "Q_EVENT_TYPE_DATA_FINAL");
+ DA_LOG_VERBOSE(HTTPManager, "Q_EVENT_TYPE_DATA_FINAL");
ret = handle_event_http_final(stage, event);
-
break;
-
case Q_EVENT_TYPE_DATA_ABORT:
- DA_LOG(HTTPManager, "Q_EVENT_TYPE_DATA_ABORT");
+ DA_LOG_VERBOSE(HTTPManager, "Q_EVENT_TYPE_DATA_ABORT");
ret = handle_event_http_abort(stage, event);
-
break;
}
}
da_bool_t is_handle_hdr_success = DA_TRUE;
q_event_data_http_t *received_data = DA_NULL;
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
received_data = &(event->type.q_event_data_http);
da_result_t handle_event_http_final(stage_info *stage, q_event_t *event)
{
da_result_t ret = DA_RESULT_OK;
-
http_state_t http_state = 0;
int slot_id = DA_INVALID_ID;
+ int http_status = 0;
+ q_event_data_http_t *received_data = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+
+ DA_LOG_FUNC_LOGV(HTTPManager);
slot_id = GET_STAGE_DL_ID(stage);
_disconnect_transaction(stage);
case HTTP_STATE_DOWNLOAD_REQUESTED:
DA_LOG(HTTPManager, "case HTTP_STATE_DOWNLOAD_REQUESTED");
CHANGE_HTTP_STATE(HTTP_STATE_DOWNLOAD_FINISH, stage);
+ /* Most of http status is decided when got headers.
+ * But it is ignored for credential url when got headers in case of 401 status code.
+ * So, when the download is finished, it means unauthorized error if the status code has still 401.
+ */
+ received_data = &(event->type.q_event_data_http);
+ http_status = received_data->status_code;
+ if (http_status == 401) {
+ store_http_status(slot_id, http_status);
+ ret = DA_ERR_NETWORK_FAIL;
+ }
break;
case HTTP_STATE_DOWNLOADING:
- DA_LOG(HTTPManager, "case HTTP_STATE_DOWNLOADING");
+ DA_LOG_VERBOSE(HTTPManager, "case HTTP_STATE_DOWNLOADING");
ret = file_write_complete(stage);
if (ret != DA_RESULT_OK) {
discard_download(stage);
goto ERR;
}
- /* ret = _check_downloaded_file_size_is_same_with_header_content_size(stage);
- if(ret != DA_RESULT_OK)
- {
- discard_download(stage) ;
- goto ERR;
- }
+ /* Sometimes, the server can send "0" byte package data although whole data are not sent.
+ * At that case, the libsoup call finished callback function with 200 Ok.
+ * Only if the DA know content size form response header, it can check the error or not
*/
+ ret = _check_downloaded_file_size_is_same_with_header_content_size(stage);
+ if(ret != DA_RESULT_OK) {
+ discard_download(stage) ;
+ goto ERR;
+ }
CHANGE_HTTP_STATE(HTTP_STATE_DOWNLOAD_FINISH, stage);
send_client_update_progress_info(
slot_id,
case HTTP_STATE_REQUEST_PAUSE:
if (GET_CONTENT_STORE_FILE_HANDLE(GET_STAGE_CONTENT_STORE_INFO(stage))) {
ret = file_write_complete(stage);
+
+ IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage))
+ = DA_FALSE;
+
send_client_update_progress_info(
slot_id,
GET_DL_ID(slot_id),
GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage))
);
- IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage))
- = DA_FALSE;
}
CHANGE_HTTP_STATE(HTTP_STATE_PAUSED,stage);
CHANGE_DOWNLOAD_STATE(DOWNLOAD_STATE_PAUSED, stage);
{
da_result_t ret = DA_RESULT_OK;
http_state_t http_state = 0;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
GET_REQUEST_HTTP_RESULT(GET_STAGE_TRANSACTION_INFO(stage))
= event->type.q_event_data_http.error_type;
int slot_id = DA_INVALID_ID;
http_state_t http_state = 0;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
slot_id = GET_STAGE_DL_ID(stage);
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
http_state = GET_HTTP_STATE_ON_STAGE(stage);
- DA_LOG(HTTPManager, "http_state = %d", http_state);
+ DA_LOG_DEBUG(HTTPManager, "http_state = %d", http_state);
_da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
switch (http_state) {
req_dl_info *request_info = DA_NULL;
http_state_t http_state = 0;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
slot_id = GET_STAGE_DL_ID(stage);
request_info = GET_STAGE_TRANSACTION_INFO(stage);
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
http_state = GET_HTTP_STATE_ON_STAGE(stage);
- DA_LOG(HTTPManager, "http_state = %d", http_state);
+ DA_LOG_VERBOSE(HTTPManager, "http_state = %d", http_state);
_da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
store_http_status(slot_id, http_status);
goto ERR;
CHANGE_HTTP_STATE(HTTP_STATE_REDIRECTED,stage);
http_msg_response_destroy(&http_msg_response);
+ request_info->http_info.http_msg_response = DA_NULL;
break;
case 100:
da_result_t ret = DA_RESULT_OK;
char *location = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
if (http_msg_response_get_location(http_msg_response, &location)) {
- DA_LOG(HTTPManager, "location = %s\n", location);
+ DA_SECURE_LOGD("location = %s\n", location);
GET_REQUEST_HTTP_REQ_LOCATION(GET_STAGE_TRANSACTION_INFO(stage)) = location;
}
http_state_t http_state = 0;
int slot_id = DA_INVALID_ID;
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
slot_id = GET_STAGE_DL_ID(stage);
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
http_state = GET_HTTP_STATE_ON_STAGE(stage);
- // DA_LOG(HTTPManager, "http_state = %d", http_state);
_da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
if (http_state == HTTP_STATE_DOWNLOAD_STARTED) {
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
http_state = GET_HTTP_STATE_ON_STAGE(stage);
- // DA_LOG(HTTPManager, "http_state = %d", http_state);
_da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
switch (http_state) {
goto ERR;
if ((DA_TRUE ==
IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage)))) {
+
+ IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage))
+ = DA_FALSE;
send_client_update_progress_info(
slot_id,
GET_DL_ID(slot_id),
GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage))
);
- IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(GET_STAGE_CONTENT_STORE_INFO(stage))
- = DA_FALSE;
}
break;
char *value = NULL;
unsigned long long size = 0;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
request_info = GET_STAGE_TRANSACTION_INFO(stage);
if (b_ret) {
GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info) = value;
value = NULL;
- DA_LOG_VERBOSE(HTTPManager, "[Content-Type][%s] - stored", GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info));
+// DA_SECURE_LOGD("[Content-Type][%s] - stored", GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info));
}
b_ret = http_msg_response_get_content_length(http_msg_response,
if (b_ret) {
GET_REQUEST_HTTP_HDR_CONT_LEN(request_info) = size;
size = 0;
- DA_LOG_VERBOSE(HTTPManager, "[Content-Length][%d] - stored", GET_REQUEST_HTTP_HDR_CONT_LEN(request_info));
}
b_ret = http_msg_response_get_ETag(http_msg_response, &value);
if (b_ret) {
GET_REQUEST_HTTP_HDR_ETAG(request_info) = value;
value = NULL;
- DA_LOG_VERBOSE(HTTPManager, "[ETag][%s] - stored ", GET_REQUEST_HTTP_HDR_ETAG(request_info));
+ DA_SECURE_LOGD("[ETag][%s] - stored ", GET_REQUEST_HTTP_HDR_ETAG(request_info));
}
ERR:
source_info_t *source_info = DA_NULL;
char *content_type_from_server = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
request_info = GET_STAGE_TRANSACTION_INFO(stage);
source_info = GET_STAGE_SOURCE_INFO(stage);
req_dl_info *request_info = DA_NULL;
- long long cont_len = 0;
+ unsigned long long cont_len = 0;
da_storage_size_t memory;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
memset(&memory, 0x00, sizeof(da_storage_size_t));
request_info = GET_STAGE_TRANSACTION_INFO(stage);
- cont_len = (long long) GET_REQUEST_HTTP_HDR_CONT_LEN(request_info);
+ cont_len = (unsigned long long) GET_REQUEST_HTTP_HDR_CONT_LEN(request_info);
if (cont_len) {
- ret = get_available_memory(DA_STORAGE_PHONE, &memory);
+ 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);
+ 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
- + SAVE_FILE_BUFFERING_SIZE_50KB)
- / memory.b_size)) /* 50KB buffering */
+ + (unsigned long long)SAVE_FILE_BUFFERING_SIZE_50KB)
+ / (unsigned long long)memory.b_size)) /* 50KB buffering */
{
ret = DA_ERR_DISK_FULL;
goto ERR;
char *value = NULL;
unsigned long long size = 0;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
origin_ETag
= GET_REQUEST_HTTP_HDR_ETAG(GET_STAGE_TRANSACTION_INFO(stage));
if (b_ret) {
new_ETag = value;
value = NULL;
- DA_LOG(HTTPManager, "[new ETag][%s]", new_ETag);
+ DA_SECURE_LOGD("[new ETag][%s]", new_ETag);
} else {
goto ERR;
}
}
if (remained_content_len) {
- ret = get_available_memory(DA_STORAGE_PHONE, &memory);
+ 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);
char *temp_file_path = DA_NULL;
req_dl_info *request_info = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
request_info = GET_STAGE_TRANSACTION_INFO(stage);
origin_ETag
if (b_ret) {
new_ETag = value;
value = NULL;
- DA_LOG(HTTPManager, "[new ETag][%s]", new_ETag);
+ DA_SECURE_LOGD("[new ETag][%s]", new_ETag);
} else {
goto ERR;
}
}
if (remained_content_len) {
- ret = get_available_memory(DA_STORAGE_PHONE, &memory);
+ 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 (b_ret) {
GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info) = value;
value = NULL;
- DA_LOG(HTTPManager, "[Content-Type][%s]",
+ DA_SECURE_LOGD("[Content-Type][%s]",
GET_REQUEST_HTTP_HDR_CONT_TYPE(request_info));
}
temp_file_path = GET_REQUEST_HTTP_USER_REQUEST_TEMP_FILE_PATH(request_info);
get_file_size(temp_file_path, &size);
GET_REQUEST_HTTP_HDR_CONT_LEN(request_info) = remained_content_len + size;
- DA_LOG(HTTPManager, "[Content-Length][%d]",
+ DA_SECURE_LOGD("[Content-Length][%llu]",
GET_REQUEST_HTTP_HDR_CONT_LEN(request_info));
unsigned long long content_size_from_real_file = 0;
unsigned long long content_size_from_http_header = 0;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
request_info = GET_STAGE_TRANSACTION_INFO(stage);
file_info_data = GET_STAGE_CONTENT_STORE_INFO(stage);
if (content_size_from_real_file
!= content_size_from_http_header) {
- DA_LOG_ERR(HTTPManager, "size from header = %llu, real size = %llu, DA_ERR_MISMATCH_CONTENT_SIZE",
+ DA_SECURE_LOGE("size from header = %llu, real size = %llu,\
+ DA_ERR_MISMATCH_CONTENT_SIZE",
content_size_from_http_header, content_size_from_real_file);
ret = DA_ERR_MISMATCH_CONTENT_SIZE;
}
da_result_t ret = DA_RESULT_OK;
int transaction_id = DA_INVALID_ID;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
transaction_id
= GET_REQUEST_HTTP_TRANS_ID(GET_STAGE_TRANSACTION_INFO(stage));
da_result_t ret = DA_RESULT_OK;
int transaction_id = DA_INVALID_ID;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
transaction_id
= GET_REQUEST_HTTP_TRANS_ID(GET_STAGE_TRANSACTION_INFO(stage));
http_state_t state = 0;
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
state = GET_HTTP_STATE_ON_STAGE(stage);
- if (state <= HTTP_STATE_DOWNLOAD_REQUESTED)
+ if (state <= HTTP_STATE_DOWNLOAD_REQUESTED) {
+ _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
ret = PI_http_cancel_transaction(transaction_id, DA_TRUE);
- else
+ } else {
+ _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
ret = PI_http_cancel_transaction(transaction_id, DA_FALSE);
- _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(stage)));
- }
+ }
+ }
return ret;
}
char *field = NULL;
char *value = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!user_request_header) {
DA_LOG_ERR(HTTPManager, "user_request_header is NULL");
strncpy(value, pos, len);
*out_field = field;
*out_value = value;
- DA_LOG(HTTPManager, "field[%s], value[%s]", field, value);
+ DA_SECURE_LOGD("field[%s], value[%s]", field, value);
return;
ERR:
{
char *uagent_str = DA_NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
uagent_str = get_client_user_agent_string();
if (!uagent_str) {
{
http_msg_request_t *temp_http_msg_request = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
temp_http_msg_request = (http_msg_request_t *)calloc(1,
sizeof(http_msg_request_t));
temp_http_msg_request->http_body = NULL;
*http_msg_request = temp_http_msg_request;
- DA_LOG(HTTPManager, "http_msg_request: %x", (unsigned int)(*http_msg_request));
+ DA_LOG_DEBUG(HTTPManager, "http_msg_request: %x", (unsigned int)(*http_msg_request));
return DA_RESULT_OK;
}
{
http_msg_request_t *temp_http_msg_request = *http_msg_request;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (temp_http_msg_request) {
if (temp_http_msg_request->http_method) {
da_result_t http_msg_request_set_method(http_msg_request_t *http_msg_request,
const char *method)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
if (!http_msg_request || !method) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
da_result_t http_msg_request_get_method(http_msg_request_t *http_msg_request,
const char **method)
{
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_request) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
da_result_t http_msg_request_set_url(http_msg_request_t *http_msg_request,
const char *url)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_request) {
DA_LOG_ERR(HTTPManager, "http_msg_request is NULL; DA_ERR_INVALID_ARGUMENT");
http_msg_request->url = strdup(url);
- DA_LOG(HTTPManager, "http url : %s", http_msg_request->url);
+ //DA_SECURE_LOGD("http url : %s", http_msg_request->url);
return DA_RESULT_OK;
}
da_result_t http_msg_request_get_url(http_msg_request_t *http_msg_request,
const char **url)
{
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_request) {
DA_LOG_ERR(HTTPManager, "http_msg_request is NULL; DA_ERR_INVALID_ARGUMENT");
da_result_t http_msg_request_set_body(http_msg_request_t *http_msg_request,
const char *body)
{
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_request) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
http_msg_request->http_body = strdup(body);
- DA_LOG(HTTPManager, "http body : %s", http_msg_request->http_body);
+ DA_SECURE_LOGD("http body : %s", http_msg_request->http_body);
return DA_RESULT_OK;
}
da_result_t http_msg_request_get_body(http_msg_request_t *http_msg_request,
const char **body)
{
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_request) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
da_result_t http_msg_request_add_field(http_msg_request_t *http_msg_request,
const char *field, const char *value)
{
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_request) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
{
http_msg_response_t *temp_http_msg_response = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
temp_http_msg_response = (http_msg_response_t *)calloc(1,
sizeof(http_msg_response_t));
{
http_msg_response_t *temp_http_msg_response = *http_msg_response;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (temp_http_msg_response) {
__http_header_destroy_all_field(&(temp_http_msg_response->head));
da_result_t http_msg_response_set_status_code(
http_msg_response_t *http_msg_response, int status_code)
{
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_response) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
da_result_t http_msg_response_get_status_code(
http_msg_response_t *http_msg_response, int *status_code)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
if (!http_msg_response) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
da_result_t http_msg_response_add_field(http_msg_response_t *http_msg_response,
const char *field, const char *value)
{
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_response) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
http_header_t *pre = NULL;
http_header_t *cur = NULL;
- // DA_LOG_FUNC_START(HTTPManager);
- DA_LOG(HTTPManager, "[%s][%s]", field, value);
+ //DA_SECURE_LOGD("[%s][%s]", field, value);
pre = cur = *head;
while (cur) {
* Remove the value which is stored before and add a new value.
*/
if (cur->field && cur->raw_value &&
- strncmp(cur->field, field, strlen(field)) == 0) {
- DA_LOG(HTTPManager, "Remove value for replacement [%s][%s]", 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;
http_header_t *pre = NULL;
http_header_t *cur = NULL;
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
cur = *head;
while (cur) {
if (cur->field) {
- DA_LOG_VERBOSE(HTTPManager, "field= %s", cur->field);
free(cur->field);
cur->field = DA_NULL;
}
http_header_options_t *pre = NULL;
http_header_options_t *cur = NULL;
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
cur = *head;
while (cur) {
if (cur->field) {
- DA_LOG_VERBOSE(HTTPManager, "field= %s", cur->field);
+ DA_LOG_VERBOSE("field= %s", cur->field);
free(cur->field);
cur->field = DA_NULL;
}
da_result_t http_msg_request_get_iter(http_msg_request_t *http_msg_request,
http_msg_iter_t *http_msg_iter)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_request) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
da_result_t http_msg_response_get_iter(http_msg_response_t *http_msg_response,
http_msg_iter_t *http_msg_iter)
{
- // DA_LOG_FUNC_START(HTTPManager);
-
if (!http_msg_response) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
return DA_ERR_INVALID_ARGUMENT;
}
*http_msg_iter = http_msg_response->head;
- // DA_LOG(HTTPManager, "retrieve iter = 0x%x", (unsigned int)http_msg_iter);
+ // DA_LOG_VERBOSE(HTTPManager, "retrieve iter = 0x%x", (unsigned int)http_msg_iter);
return DA_RESULT_OK;
}
{
http_header_t *cur = *http_msg_iter;
- // DA_LOG_FUNC_START(HTTPManager);
-
- // DA_LOG(HTTPManager, "getting iter = 0x%x", (unsigned int)cur);
+ // DA_LOG_VERBOSE(HTTPManager, "getting iter = 0x%x", (unsigned int)cur);
if (cur) {
*out_field = cur->field;
return DA_TRUE;
} else {
- // DA_LOG(HTTPManager, "end of iter");
+ // DA_LOG_VERBOSE(HTTPManager, "end of iter");
return DA_FALSE;
}
}
{
http_header_t *cur = *http_msg_iter;
- // DA_LOG_FUNC_START(HTTPManager);
-
- // DA_LOG(HTTPManager, "getting iter = 0x%x", (unsigned int)cur);
+ // DA_LOG_VERBOSE(HTTPManager, "getting iter = 0x%x", (unsigned int)cur);
if (cur) {
*out_field = cur->field;
return DA_TRUE;
} else {
- // DA_LOG(HTTPManager, "end of iter");
+ // DA_LOG_VERBOSE(HTTPManager, "end of iter");
return DA_FALSE;
}
}
int i = 0;
http_header_options_t *option = NULL;
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!org_str)
return NULL;
working_pos = working_str = NULL;
}
- DA_LOG(HTTPManager, "option_field = [%s], option_value = [%s]",
- option_field, option_value);
+// DA_SECURE_LOGD("option_field = [%s], option_value = [%s]",
+// option_field, option_value);
if (option_field || option_value) {
option = __create_http_header_option(
char *wanted_str_end = NULL;
char *cur_pos = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!org_str)
return NULL;
/* Do Not use strtok(). It's not thread safe. */
- // DA_LOG_CRITICAL(HTTPManager, "org_str = %s", org_str);
+ // DA_SECURE_LOGD("org_str = %s", org_str);
cur_pos = org_str;
}
strncpy(wanted_str, wanted_str_start, wanted_str_len);
- // DA_LOG_CRITICAL(HTTPManager, "wanted_str = [%s]", wanted_str);
+ // DA_SECURE_LOGD("wanted_str = [%s]", wanted_str);
cur = __parsing_N_create_option_str(wanted_str);
if (pre) {
pre->next = cur;
char *trimed_value_start = NULL;
char *trimed_value_end = NULL;
- // DA_LOG_FUNC_START(HTTPManager);
-
raw_value = http_header_field->raw_value;
- // DA_LOG_CRITICAL(HTTPManager, "raw_value = [%s]", raw_value);
+ // DA_SECURE_LOGD("raw_value = [%s]", raw_value);
if (!raw_value)
return;
cur = http_header_field->options;
while (cur) {
- DA_LOG(HTTPManager, "field = [%s], value = [%s]", cur->field, cur->value);
+// DA_SECURE_LOGD("field = [%s], value = [%s]", cur->field, cur->value);
cur = cur->next;
}
{
http_header_options_t *cur = NULL;
- // DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!header_option) {
DA_LOG_ERR(HTTPManager, "input header_option is NULL.");
cur = header_option;
while (cur) {
if (cur->field) {
- if (!strncmp(cur->field, in_field, strlen(cur->field)) &&
+ if (!strncasecmp(cur->field, in_field, strlen(cur->field)) &&
cur->value) {
- DA_LOG(HTTPManager, "[%s][%s]", cur->field, cur->value);
+ DA_SECURE_LOGD("[%s][%s]", cur->field, cur->value);
*out_value = cur->value;
return DA_TRUE;
}
http_header_t *header = NULL;
char *field = NULL;
- //DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
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 && !strncmp(field, in_field, strlen(field))) {
- DA_LOG_VERBOSE(HTTPManager, "[%s][%s]", field, header->value);
+ if (field && header && !strncasecmp(field, in_field, strlen(field))) {
+// DA_SECURE_LOGD("[%s][%s]", field, header->value);
*out_header = header;
return DA_TRUE;
}
void __exchange_header_value(http_header_t *header, const char *in_raw_value)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!header || !in_raw_value)
return;
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
b_ret = __get_http_header_for_field(http_msg_response, "Content-Type",
&header);
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_response || !in_type)
return;
strlen(header->raw_value))))
return;
- DA_LOG(HTTPManager, "exchange Content-Type to [%s] from [%s]", in_type, header->value);
+ 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),
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
b_ret = __get_http_header_for_field(http_msg_response,
"Content-Length", &header);
char *decoded_str = NULL;
int wanted_str_len = 0;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
b_ret = __get_http_header_for_field(http_msg_response,
"Content-Disposition", &header);
if (!b_ret) {
- DA_LOG(HTTPManager, "no Content-Disposition");
+ DA_LOG_VERBOSE(HTTPManager, "no Content-Disposition");
return DA_FALSE;
}
*out_file_name = strdup(file_name);
return DA_TRUE;
} else {
- // DA_LOG(HTTPManager, "wanted_str_start = [%s]", wanted_str_start);
+ // DA_SECURE_LOGD("wanted_str_start = [%s]", wanted_str_start);
wanted_str_start++;
wanted_str_end = strchr(wanted_str_start, '"');
if (wanted_str_end) {
DA_LOG(HTTPManager, "It's base64 encoded-word string");
if (DA_RESULT_OK == decode_base64_encoded_str(
wanted_str, &decoded_str)) {
- DA_LOG(HTTPManager, "base64 decoded str = [%s]", decoded_str);
+ DA_SECURE_LOGD("base64 decoded str = [%s]", decoded_str);
free(wanted_str);
wanted_str = decoded_str;
decoded_str = NULL;
decode_url_encoded_str(wanted_str, &decoded_str);
/* If it is url encoded string */
if (decoded_str) {
- DA_LOG(HTTPManager, "Url decoded str = [%s]", 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_LOG(HTTPManager, "out_file_name = [%s]", *out_file_name);
+ DA_SECURE_LOGD("out_file_name = [%s]", *out_file_name);
return DA_TRUE;
} else {
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
b_ret = __get_http_header_for_field(http_msg_response, "ETag", &header);
if (!b_ret) {
- DA_LOG(HTTPManager, "no ETag");
+ DA_LOG_VERBOSE(HTTPManager, "no ETag");
return DA_FALSE;
}
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
b_ret = __get_http_header_for_field(http_msg_response, "Date", &header);
if (!b_ret) {
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
b_ret = __get_http_header_for_field(http_msg_response, "Location", &header);
if (!b_ret) {
char *value = NULL;
char *boundary = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!http_msg_response) {
DA_LOG_ERR(HTTPManager, "DA_ERR_INVALID_ARGUMENT");
http_msg_response_get_iter(http_msg_response, &http_msg_iter);
while (http_msg_get_field_with_iter(&http_msg_iter, &field, &value)) {
if ((field != DA_NULL) && (value != DA_NULL)) {
- if (!strncmp(field, "Content-Type",
+ if (!strncasecmp(field, "Content-Type",
strlen("Content-Type"))) {
char *org_str = NULL;
char *boundary_str_start = NULL;
}
strncpy(boundary, boundary_value_start,
boundary_value_len);
- DA_LOG(HTTPManager, "[boundary][%s]", boundary);
+ DA_SECURE_LOGD("[boundary][%s]", boundary);
break;
}
}
int len = 0;
char *buff = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
http_msg_response_get_iter(http_msg_response, &http_msg_iter);
while (http_msg_get_header_with_iter(&http_msg_iter, &field, &header)) {
return DA_NULL;
}
memcpy(buff, tmp_buf, strlen(tmp_buf));
- DA_LOG(HTTPManager, "\n---raw response header---\n%s\n------\n",buff);
+ DA_SECURE_LOGD("\n---raw response header---\n%s\n------\n",buff);
return buff;
} else {
return DA_NULL;
startPos = index;
/* Find the end of data. */
- if (0 == strcmp(szFindStr, "Location"))//terminate character list does not contain ';' in case of URI
+ if (0 == strncasecmp(szFindStr, "Location", strlen("Location")))//terminate character list does not contain ';' in case of URI
{
while (DA_FALSE == IS_URI_TERMINATING_CHAR(pValuePos[index])) {
index++;
{
q_event_t *event = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
do {
Q_pop_event(queue, &event);
if(q_event == DA_NULL)
return;
-// DA_LOG(HTTPManager, "destroying size = %d", q_event->size);
-
switch(q_event->event_type) {
case Q_EVENT_TYPE_DATA_HTTP:
init_q_event_data_http(q_event);
da_result_t ret = DA_RESULT_OK;
q_event_t *q_event = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
q_event = (q_event_t *)calloc(1, sizeof(q_event_t));
if(q_event == DA_NULL) {
da_result_t ret = DA_RESULT_OK;
q_event_t *q_event = DA_NULL;
-// DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
q_event = (q_event_t *)calloc(1, sizeof(q_event_t));
if(q_event == DA_NULL) {
*out_event = q_event;
-// DA_LOG(HTTPManager, "made event = %x", *out_event);
+// DA_LOG_VERBOSE(HTTPManager, "made event = %x", *out_event);
}
return ret;
{
da_result_t ret = DA_RESULT_OK;
-// DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if(q_event->event_type != Q_EVENT_TYPE_DATA_HTTP) {
DA_LOG_ERR(HTTPManager, "status_code can be set only for Q_EVENT_TYPE_DATA_HTTP.");
q_event->type.q_event_data_http.status_code = status_code;
-// DA_LOG(HTTPManager, "status_code = %d, q_event = %x", q_event->type.q_event_data_http.status_code, q_event);
+// DA_LOG_VERBOSE(HTTPManager, "status_code = %d, q_event = %x", q_event->type.q_event_data_http.status_code, q_event);
ERR:
return ret;
{
da_result_t ret = DA_RESULT_OK;
-// DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if(q_event->event_type != Q_EVENT_TYPE_DATA_HTTP) {
DA_LOG_ERR(HTTPManager, "http body can be set only for Q_EVENT_TYPE_DATA_HTTP.");
q_event->type.q_event_data_http.body_data = body_data;
q_event->size = body_len;
-// DA_LOG(HTTPManager, "body_len = %d, body_data = %x, q_event = %x", q_event->type.q_event_data_http.body_len, q_event->type.q_event_data_http.body_data, q_event);
+// DA_LOG_VERBOSE(HTTPManager, "body_len = %d, body_data = %x, q_event = %x", q_event->type.q_event_data_http.body_len, q_event->type.q_event_data_http.body_data, q_event);
ERR:
return ret;
{
da_result_t ret = DA_RESULT_OK;
-// DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if(q_event->event_type != Q_EVENT_TYPE_DATA_HTTP) {
DA_LOG_ERR(HTTPManager, "error_type can be set only for Q_EVENT_TYPE_DATA_HTTP.");
q_event->type.q_event_data_http.error_type = error_type;
- DA_LOG(HTTPManager, "error_type = %d, q_event = %p", q_event->type.q_event_data_http.error_type, q_event);
+ DA_LOG_VERBOSE(HTTPManager, "error_type = %d, q_event = %p", q_event->type.q_event_data_http.error_type, q_event);
ERR:
return ret;
q_event_t *head = DA_NULL;
q_event_t *cur = DA_NULL;
-// DA_LOG_FUNC_START(HTTPManager);
-// DA_LOG(HTTPManager, "queue = %x", in_queue);
+// DA_LOG_VERBOSE(HTTPManager, "queue = %x", in_queue);
event_type = event->event_type;
}
queue->queue_size += event->size;
-// DA_LOG(HTTPManager, "queue size is %d", queue->queue_size);
+// DA_LOG_VERBOSE(HTTPManager, "queue size is %d", queue->queue_size);
b_ret = DA_TRUE;
} else {
{
queue_t *queue = (queue_t*)in_queue;
-// DA_LOG_FUNC_START(HTTPManager);
-// DA_LOG(HTTPManager, "queue = %x", in_queue);
+// DA_LOG_VERBOSE(HTTPManager, "queue = %x", in_queue);
/** Pop Priority
* 1. If there are control event, control event should pop first
*out_event = queue->data_head;
queue->data_head = queue->data_head->next;
queue->queue_size -= (*out_event)->size;
-// DA_LOG(HTTPManager, "queue size is %d", queue->queue_size);
+ DA_LOG_VERBOSE(HTTPManager, "queue size is %d", queue->queue_size);
} else {/* Priority 3 */
*out_event = DA_NULL;
}
void Q_goto_sleep(const queue_t *in_queue)
{
-// DA_LOG_FUNC_START(HTTPManager);
DA_LOG_VERBOSE(HTTPManager, "sleep for %p", in_queue);
//** SHOULD NOT use mutex **//
void Q_wake_up(const queue_t *in_queue)
{
-// DA_LOG_FUNC_START(HTTPManager);
DA_LOG_VERBOSE(HTTPManager, "wake up for %p", in_queue);
//** SHOULD NOT use mutex **//
{
q_event_data_http_t *q_event_data_http;
-// DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if(q_event->event_type == Q_EVENT_TYPE_DATA_HTTP) {
q_event_data_http = &(q_event->type.q_event_data_http);
if(q_event_data_http) {
- q_event_data_http->status_code = DA_NULL;
+ q_event_data_http->status_code = 0;
if(q_event_data_http->http_response_msg) {
http_msg_response_destroy(&(q_event_data_http->http_response_msg));
+ q_event_data_http->http_response_msg = DA_NULL;
}
if(q_event_data_http->body_len > 0 ) {
q_event_data_http->body_data = DA_NULL;
}
}
- q_event_data_http->error_type = DA_NULL;
+ q_event_data_http->error_type = 0;
}
}
}
{
q_event_control_t *q_event_control;
-// DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if(q_event->event_type == Q_EVENT_TYPE_CONTROL) {
q_event_control = &(q_event->type.q_event_control);
if(q_event_control) {
- q_event_control->control_type = DA_NULL;
+ q_event_control->control_type = Q_EVENT_TYPE_CONTROL_NONE;
}
}
{
da_result_t ret = DA_RESULT_OK;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
if (!da_client_callback) {
ret = DA_ERR_INVALID_ARGUMENT;
{
da_result_t ret = DA_RESULT_OK;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
deinit_http_mgr();
deinit_download_mgr();
{
da_result_t ret = DA_RESULT_OK;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
*download_id = DA_INVALID_ID;
if (DA_FALSE == is_valid_url(url, &ret))
goto ERR;
- DA_LOG(Default, "url = %s", url);
+ DA_SECURE_LOGI("url = %s", url);
ret = start_download(url, download_id);
if (ret != DA_RESULT_OK)
int req_header_count = 0;
int i = 0;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
*download_id = DA_INVALID_ID;
if (DA_FALSE == is_valid_url(url, &ret))
goto ERR;
- DA_LOG(Default, "url = %s", url);
+ DA_SECURE_LOGI("url = %s", url);
if (ret != DA_RESULT_OK)
goto ERR;
for (i = 0; i < extension_data->request_header_count; i++) {
if (extension_data->request_header[i]) {
req_header_count++;
- DA_LOG_VERBOSE(Default, "request_header = [%s]",
+ DA_SECURE_LOGI("request_header = [%s]",
extension_data->request_header[i]);
}
}
- DA_LOG(Default, "actual request_header_count = [%d]", req_header_count);
+ DA_LOG_VERBOSE(Default, "actual request_header_count = [%d]", req_header_count);
if (extension_data->request_header_count != req_header_count) {
DA_LOG_ERR(Default, "Request header count is not matched with number of request header array");
extension_data->request_header = NULL;
if (extension_data->install_path) {
if (!is_dir_exist(extension_data->install_path))
return DA_ERR_INVALID_INSTALL_PATH;
- DA_LOG_VERBOSE(Default, "install_path = [%s]", extension_data->install_path);
+ DA_SECURE_LOGI("install_path = [%s]", extension_data->install_path);
}
if (extension_data->file_name)
- DA_LOG_VERBOSE(Default, "file_name = [%s]", extension_data->file_name);
+ DA_SECURE_LOGI("file_name = [%s]", extension_data->file_name);
if (extension_data->temp_file_path)
- DA_LOG_VERBOSE(Default, "temp_file_path = [%s]", extension_data->temp_file_path);
+ DA_SECURE_LOGI("temp_file_path = [%s]", extension_data->temp_file_path);
if (extension_data->etag)
- DA_LOG_VERBOSE(Default, "etag = [%s]", extension_data->etag);
-
+ DA_SECURE_LOGI("etag = [%s]", extension_data->etag);
+ if (extension_data->pkg_name)
+ DA_SECURE_LOGI("pkg_name = [%s]", extension_data->pkg_name);
if (extension_data->user_data)
DA_LOG_VERBOSE(Default, "user_data = [%p]", extension_data->user_data);
#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) == ' ' || (c) == '\t')
+#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 DD_MIME_STR "application/vnd.oma.dd+xml"
-#define DD_EXT_STR "*.dd"
-#define DRM_MIME_STR "application/vnd.oma.drm.message"
-#define DRM_EXT_STR "*.dcf"
#define MAX_EXT_TABLE_INDEX 16
Ext_translation_table ext_trans_table [MAX_EXT_TABLE_INDEX] = {
{"*.xla", "*.xls"},
da_bool_t is_ambiguous_MIME_Type(const char *in_mime_type)
{
-// DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (!in_mime_type)
return DA_FALSE;
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_LOG(Default,"It is ambiguous! [%s]", ambiguous_MIME_Type_list[index]);
+ DA_SECURE_LOGD("It is ambiguous! [%s]", ambiguous_MIME_Type_list[index]);
return DA_TRUE;
}
}
char ext_temp[DA_MAX_STR_LEN] = {0,};
char *temp = NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(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));
+// DA_SECURE_LOGD("mime str[%s]ptr[%p]len[%d]",mime,mime,strlen(mime));
/* unaliased_mimetype means representative mime among similar types */
_da_thread_mutex_lock(&mutex_for_xdgmime);
unaliased_mimetype = xdg_mime_unalias_mime_type(mime);
DA_LOG_ERR(Default,"Invalid mime type : No unsaliased mime type");
goto ERR;
}
- DA_LOG(Default,"unaliased_mimetype[%s]\n",unaliased_mimetype);
+ DA_SECURE_LOGD("unaliased_mimetype[%s]\n",unaliased_mimetype);
/* Get extension name from shared-mime-info */
_da_thread_mutex_lock(&mutex_for_xdgmime);
}
#endif
} else { /* For drm case, this else statement is needed */
- DA_LOG(Default,"extlist[%s]\n",*extlist);
+ DA_SECURE_LOGD("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) {
break;
}
}
- DA_LOG(Default,"index[%d]\n",i);
+ DA_LOG_VERBOSE(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);
+ DA_SECURE_LOGD("extlist[%s]\n",*extlist);
extlist++;
}
- DA_LOG(Default,"extension from shared mime info[%s]",ext_temp);
+// DA_SECURE_LOGD("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) {
+ /* 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_STR,mime,strlen(DD_MIME_STR)) == 0) {
+ } 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
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));
char *temp_str = DA_NULL;
int buf_len = 0;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (DA_NULL == url || DA_NULL == ext) {
ret = DA_FALSE;
goto ERR;
}
strncpy(*ext,buff,buf_len);
- DA_LOG(Default,"extention name[%s]",*ext);
+ DA_SECURE_LOGD("extention name[%s]",*ext);
return ret;
}
}
int len_name = 0;
char name_buff[DA_MAX_FILE_PATH_LEN] = {0,};
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (DA_NULL == url || DA_NULL == name) {
ret = DA_FALSE;
if (End != NULL) {
*End = '\0';
}
- DA_LOG(Default,"file name BEFORE removing prohibited character = %s", name_buff);
+// DA_SECURE_LOGD("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);
+// DA_SECURE_LOGD("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);
+// DA_SECURE_LOGD("Extracted file name : %s", *name);
ERR:
if (buff) {
free (buff);
#endif
}
-da_result_t get_storage_type(da_storage_type_t *type)
-{
- da_result_t ret = DA_RESULT_OK;
-#ifdef _EFL_PLATFORM
- int value = -1;
-#endif
-
- if (!type) {
- DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
- ret = DA_ERR_INVALID_ARGUMENT;
- goto ERR;
- }
-
-#ifdef _EFL_PLATFORM
- if (0 != vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_WAP_INT, &value)) {
- DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
- ret = DA_ERR_FAIL_TO_GET_CONF_VALUE;
- goto ERR;
- }
-
- switch (value) {
- case SETTING_DEF_MEMORY_PHONE:
- DA_LOG(Default,"Storage set - DA_STORAGE_PHONE");
- *type = DA_STORAGE_PHONE;
- break;
- case SETTING_DEF_MEMORY_MMC:
- *type = DA_STORAGE_MMC;
- DA_LOG(Default,"Storage set - DA_STORAGE_MMC");
- break;
- case SETTING_DEF_MEMORY_MAX:
- *type = DA_STORAGE_SYSTEM;
- DA_LOG(Default,"Storage set - DA_STORAGE_SYSTEM");
- break;
- default:
- DA_LOG_ERR(Default,"DA_ERR_CONF_FAIL");
- ret = DA_ERR_FAIL_TO_GET_CONF_VALUE;
- break;
- }
-#endif
-
-ERR:
- return ret;
-
-}
-
da_result_t get_user_agent_string(char **uagent_str)
{
da_result_t ret = DA_RESULT_OK;
char *key = DA_NULL;
#endif
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (!uagent_str) {
DA_LOG_ERR(Default,"Invalid Argument");
ret = __get_conf_string(key, uagent_str);
if(ret == DA_RESULT_OK) {
if(*uagent_str) {
- DA_LOG(Default,"getting uagent_str = \n%s", *uagent_str);
+ DA_SECURE_LOGD("getting uagent_str = \n%s", *uagent_str);
return ret;
}
}
connection_h handle = NULL;
connection_address_family_e family = CONNECTION_ADDRESS_FAMILY_IPV4;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(Default);
if (connection_create(&handle) < 0) {
DA_LOG_ERR(Default,"Fail to create connection handle");
return NULL;
}
if (proxyRet) {
- DA_LOG(Default,"===== Proxy address[%s] =====", proxyRet);
+ DA_SECURE_LOGD("===== Proxy address[%s] =====", proxyRet);
proxy = strdup(proxyRet);
free(proxyRet);
proxyRet = NULL;
da_result_t PI_http_init(void)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
using_content_sniffing = DA_TRUE;
void PI_http_deinit(void)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
return;
}
if (proxy_addr && strlen(proxy_addr) > 0) {
- DA_LOG_CRITICAL(HTTPManager,"received proxy = %s \n", proxy_addr);
+ DA_SECURE_LOGD("received proxy = %s \n", proxy_addr);
if (!strstr(proxy_addr, "0.0.0.0")) {
if (strstr((const char *)proxy_addr, "http") == DA_NULL) {
- /* DA_LOG(Default,"There is no \"http://\" on received uri, so, add it."); */
+ DA_LOG_VERBOSE(Default,"There is no \"http://\" on received uri, so, add it.");
char *tmp_str = DA_NULL;
int needed_len = 0;
}
}
} else {
- DA_LOG(HTTPManager,"There is no proxy value");
+ DA_LOG_VERBOSE(HTTPManager,"There is no proxy value");
}
ERR:
return ret;
http_msg_iter_pre = http_msg_iter;
while (http_msg_get_field_with_iter(&http_msg_iter, &field, &value)) {
if ((field != DA_NULL) && (value != DA_NULL)) {
- DA_LOG(HTTPManager,"[%s] %s", field, value);
+ DA_SECURE_LOGD("[%s] %s", field, value);
soup_message_headers_append(headers, field, value);
}
http_msg_iter_pre = http_msg_iter;
SoupSession *session = DA_NULL;
SoupMessage *msg = DA_NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (DA_FALSE == _pi_http_is_valid_input_for_tranx(input_for_tranx)) {
DA_LOG_ERR(HTTPManager,"input_for_tranx is invalid");
ret = DA_ERR_ALREADY_MAX_DOWNLOAD;
goto ERR;
}
- DA_LOG(HTTPManager,"session_table_entry = %d", session_table_entry);
+ DA_LOG_VERBOSE(HTTPManager,"session_table_entry = %d", session_table_entry);
if (DA_FALSE == _pi_http_register_queue_to_session_table(
session_table_entry, queue)) {
DA_LOG_ERR(HTTPManager,"Cannot enter here");
break;
}
- DA_LOG(HTTPManager,"msg[%p]", msg);
+ DA_LOG_VERBOSE(HTTPManager,"msg[%p]", msg);
/* if it is failed to create a msg, the url can be invalid, becasue of the input argument of soup_message_new API */
if (msg == NULL) {
DA_LOG_ERR(HTTPManager,"Fail to create message");
da_result_t ret = DA_RESULT_OK;
int session_table_entry = -1;
- DA_LOG_FUNC_START(HTTPManager);
-
- DA_LOG(HTTPManager,"in_tranx_id = %d", in_tranx_id);
+ DA_LOG_VERBOSE(HTTPManager,"in_tranx_id = %d", in_tranx_id);
session_table_entry = in_tranx_id;
SoupMessage *msg;
int session_table_entry = -1;
- DA_LOG_FUNC_START(HTTPManager);
-
- DA_LOG(HTTPManager,"in_tranx_id = %d", in_tranx_id);
+ DA_LOG_FUNC_LOGV(HTTPManager);
session_table_entry = in_tranx_id;
if (!_pi_http_is_this_session_table_entry_using(session_table_entry)) {
DA_LOG_ERR(HTTPManager,"invalid message = %p", msg);
goto ERR;
}
- DA_LOG(HTTPManager,"Call soup cancel API : abort option[%d]",abort_option);
+ DA_LOG(HTTPManager,"soup cancel API:abort option[%d] tranx_id[%d]",
+ abort_option, in_tranx_id);
if (abort_option)
soup_session_abort(session);
else
soup_session_cancel_message(session, msg, SOUP_STATUS_CANCELLED);
- DA_LOG(HTTPManager,"Call soup cancel API-Done");
+ DA_LOG(HTTPManager,"soup cancel API-Done");
ERR:
return ret;
}
pthread_mutex_t *mutex;
pthread_cond_t *cond;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
DA_LOG(HTTPManager,"in_tranx_id = %d", transaction_id);
pthread_mutex_t *mutex;
pthread_cond_t *cond;
- /* DA_LOG_FUNC_START(Default); */
+ DA_LOG_FUNC_LOGV(Default);
session_table_entry = transaction_id;
http_msg_response_t *http_msg_response = NULL;
- /* DA_LOG_FUNC_START(Default); */
-
if (msg->response_headers) {
ret = http_msg_response_create(&http_msg_response);
if (ret != DA_RESULT_OK)
http_msg_response_set_status_code(http_msg_response,
msg->status_code);
- DA_LOG(HTTPManager,"\n----raw header---------------------------------------------");
- DA_LOG_CRITICAL(HTTPManager,"status code = %d", msg->status_code);
+ DA_LOG_VERBOSE(HTTPManager,"\n----raw header---------------------------------------------");
+ DA_LOG(HTTPManager,"status code = %d", msg->status_code);
soup_message_headers_iter_init(&headers_iter,
msg->response_headers);
while (soup_message_headers_iter_next(&headers_iter,
!= DA_NULL)) {
http_msg_response_add_field(http_msg_response,
header_name, header_value);
+ DA_SECURE_LOGI("[%s][%s]", header_name, header_value);
}
}
- DA_LOG(HTTPManager,"\n-------------------------------------------------------------\n");
+ DA_LOG_VERBOSE(HTTPManager,"\n-------------------------------------------------------------\n");
}
int session_table_entry = -1;
int http_status = -1;
- /* DA_LOG_FUNC_START(Default); */
-
http_status = msg->status_code;
session_table_entry
}
if (received_body_len == 0) {
- DA_LOG(HTTPManager,"Q_EVENT_TYPE_DATA_FINAL");
+ DA_LOG_VERBOSE(HTTPManager,"Q_EVENT_TYPE_DATA_FINAL");
da_event_type_data = Q_EVENT_TYPE_DATA_FINAL;
} else {
da_event_type_data = Q_EVENT_TYPE_DATA_PACKET;
q_event_t *da_event = NULL;
int session_table_entry = -1;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
error_type = _translate_error_code(msg->status_code);
{
char *url = NULL;
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!msg) {
DA_LOG_ERR(HTTPManager, "Check NULL:msg");
url = soup_uri_to_string(soup_message_get_uri(msg), DA_FALSE);
- DA_LOG(HTTPManager,"status_code[%d], reason[%s], url[%s]",msg->status_code,msg->reason_phrase,url);
+ DA_SECURE_LOGI("status_code[%d], reason[%s], url[%s]",msg->status_code,msg->reason_phrase,url);
if (url) {
free(url);
/* this callback is called in case of redirection */
void _pi_http_restarted_cb(SoupMessage *msg, gpointer data)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
/* Location URL is needed when extracting the file name from url.
* So, the response header should be handled by http mgr.*/
void _pi_http_gotheaders_cb(SoupMessage *msg, gpointer data)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGV(HTTPManager);
if (!msg) {
DA_LOG_ERR(HTTPManager, "Check NULL:msg");
if (!using_content_sniffing)
_pi_http_store_read_header_to_queue(msg, NULL);
else
- DA_LOG(HTTPManager,"ignore because content sniffing is turned on");
+ DA_LOG_DEBUG(HTTPManager,"ignore because content sniffing is turned on");
}
void _pi_http_contentsniffed_cb(SoupMessage *msg, const char *sniffedType,
GHashTable *params, gpointer data)
{
- DA_LOG_FUNC_START(HTTPManager);
+ DA_LOG_FUNC_LOGD(HTTPManager);
if (!msg) {
DA_LOG_ERR(HTTPManager, "Check NULL:msg");
void _pi_http_gotchunk_cb(SoupMessage *msg, SoupBuffer *chunk, gpointer data)
{
-// DA_LOG_FUNC_START(HTTPManager);
+// DA_LOG_FUNC_LOGV(HTTPManager);
if (!msg) {
DA_LOG_ERR(HTTPManager, "Check NULL:msg");
dl_id_history->cur_dl_id = DA_INVALID_ID;
_da_thread_mutex_unlock(&(dl_id_history->mutex));
- DA_LOG_CRITICAL(Default,"starting num = %d", dl_id_history->starting_num);
+ DA_LOG_VERBOSE(Default,"starting num = %d", dl_id_history->starting_num);
return ret;
}
_da_thread_mutex_unlock(&(dl_id_history->mutex));
- DA_LOG_CRITICAL(Default,"dl_id = %d", dl_id);
+ DA_LOG_VERBOSE(Default,"dl_id = %d", dl_id);
return dl_id;
}
da_result_t ret = DA_RESULT_OK;
char *ext = DA_NULL;
- DA_LOG_FUNC_START(Default);
+ DA_LOG_FUNC_LOGV(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);
+// DA_SECURE_LOGD("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);
+// DA_SECURE_LOGD("found extension = %s", *extension);
ERR:
return ret;
/* open file with "rb", because fread() handles the file as binary mode */
fd = fopen(file, "rb");
if (!fd) {
- DA_LOG_ERR(FileManager,"File open err! received file path = [%s]", file);
+ DA_LOG_ERR(FileManager,"File open err! received file path");
return 0;
}
return buffer_len;
}
-da_result_t get_available_memory(
- da_storage_type_t storage_type,
- da_storage_size_t *avail_memory)
+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_START(Default);
+ DA_LOG_FUNC_LOGD(Default);
if (!avail_memory)
return DA_ERR_INVALID_ARGUMENT;
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_VERBOSE(Default, "Available Memory(f_bavail) : %lu", filesys_info.f_bavail);
+ 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(Default, "Available Memory(kbytes) : %lu", (filesys_info.f_bavail/1024)*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;
{
int i = 0;
- DA_LOG_FUNC_START(Default);
-
- DA_LOG(Default,"received content_type = %s", content_type);
-
if (content_type == NULL) {
- DA_LOG_ERR(Default, "No Mime Type\n");
+ DA_LOG_CRITICAL(Default, "No Mime Type Id");
return DA_MIME_TYPE_NONE;
}
}
i++;
}
- DA_LOG(Default, "dd mime type check: index[%d] type[%d]", i, descriptor_mime_table[i].mime_type);
+ //DA_LOG_VERBOSE(Default, "dd mime type check: index[%d] type[%d]", i, descriptor_mime_table[i].mime_type);
return descriptor_mime_table[i].mime_type;
}
void remove_file(const char *file_path)
{
- DA_LOG_FUNC_START(FileManager);
+ DA_LOG_FUNC_LOGD(FileManager);
if (file_path && is_file_exist(file_path)) {
- DA_LOG(FileManager,"remove file [%s]", file_path);
+ DA_SECURE_LOGD("remove file [%s]", file_path);
if (unlink(file_path) < 0) {
DA_LOG_ERR(FileManager,"file removing failed.");
}
#define DA_LOG_CRITICAL(channel, format, ...) ((void)0)
#define DA_LOG_VERBOSE(channel, format, ...) ((void)0)
#define DA_LOG_ERR(channel, format, ...) ((void)0)
- #define DA_LOG_FUNC_START(channel, ...) ((void)0)
+ #define DA_LOG_FUNC_LOGD(channel, ...) ((void)0)
+ #define DA_LOG_FUNC_LOGV(channel, ...) ((void)0)
+ #define DA_SECURE_LOGD(format, ...) ((void)0)
+ #define DA_SECURE_LOGI(format, ...) ((void)0)
+ #define DA_SECURE_LOGE(format, ...) ((void)0)
#else /* NODEBUG */
#include <stdio.h>
#endif /* LOG_TAG */
#define LOG_TAG "DOWNLOAD_AGENT"
- #define DA_LOG(channel, format, ...) LOGD_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__);
- #define DA_LOG_CRITICAL(channel, format, ...) LOGE_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__);
- #define DA_LOG_VERBOSE(channel, format, ...) LOGV_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__);
- #define DA_LOG_ERR(channel, format, ...) LOGE_IF(IS_LOG_ON(channel), "ERR! "format, ##__VA_ARGS__);
- #define DA_LOG_FUNC_START(channel, ...) LOGV_IF(IS_LOG_ON(channel), "starting...");
+ #define DA_LOG(channel, format, ...) LOGI_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__)
+ #define DA_LOG_DEBUG(channel, format, ...) LOGD_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__)
+ #define DA_LOG_CRITICAL(channel, format, ...) LOGI_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__)
+ #define DA_LOG_VERBOSE(channel, format, ...) ((void)0)//LOGD_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__)
+ #define DA_LOG_ERR(channel, format, ...) LOGE_IF(IS_LOG_ON(channel), "ERR! "format, ##__VA_ARGS__)
+ #define DA_LOG_FUNC_LOGD(channel, ...) LOGD_IF(IS_LOG_ON(channel), "starting...")
+ #define DA_LOG_FUNC_LOGV(channel, ...) ((void)0)//LOGD_IF(IS_LOG_ON(channel), "starting...")
+ #define DA_SECURE_LOGD(format, ...) SECURE_LOGD(format, ##__VA_ARGS__)
+ #define DA_SECURE_LOGI(format, ...) SECURE_LOGI(format, ##__VA_ARGS__)
+ #define DA_SECURE_LOGE(format, ...) SECURE_LOGE(format, ##__VA_ARGS__)
#else /* DA_DEBUG_USING_DLOG */
#include <unistd.h>
#include <syscall.h>
? fprintf(stderr, "[DA][%u][ERR][%s(): %d]\n",(unsigned int)syscall(__NR_gettid), __FUNCTION__,__LINE__, ##__VA_ARGS__) \
: ((void)0); \
}while(0)
- #define DA_LOG_FUNC_START(channel, ...) do {\
+ #define DA_LOG_FUNC_LOGD(channel, ...) do {\
IS_LOG_ON(channel) \
? fprintf(stderr, "[DA][%u][%s(): %d] starting\n",(unsigned int)syscall(__NR_gettid), __FUNCTION__,__LINE__) \
: ((void)0); \
}while(0)
#define DA_LOG_CRITICAL DA_LOG
#define DA_LOG_VERBOSE DA_LOG
+ #define DA_LOG_FUNC_LOGV ((void)0)
+ #define DA_SECURE_LOGD(format, ...) ((void)0)
+ #define DA_SECURE_LOGI(format, ...) ((void)0)
+ #define DA_SECURE_LOGE(format, ...) ((void)0)
#endif /* DA_DEBUG_USING_DLOG */
#endif /* NDEBUG */
#endif /* _Download_Agent_Debug_H */
#define DA_TRUE 1
#define DA_FALSE 0
-#define DA_NULL 0
+#define DA_NULL (void *)0
#define DA_INVALID_ID -1
#define DA_RESULT_USER_CANCELED -10
char *file_name;
char *etag;
char *temp_file_path;
+ char *pkg_name;
client_input_basic_t client_input_basic;
} client_input_t;
/*************** will be depreciated ***********************/
/* ToDo : previous http_info should be saved in case of pause */
char *content_type_from_header; /* calloced in set hdr fiels on download info */
- int content_len_from_header;
+ unsigned long long content_len_from_header;
char *etag_from_header;
unsigned long int downloaded_data_size;
#define CHANGE_HTTP_STATE(STATE,STAGE) {\
_da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(STAGE)));\
GET_HTTP_STATE_ON_STAGE(STAGE) = STATE;\
- DA_LOG_CRITICAL(Default, "Changed http_state to - [%d] ", GET_HTTP_STATE_ON_STAGE(STAGE));\
+ DA_LOG_DEBUG(Default, "Changed http_state to - [%d] ", GET_HTTP_STATE_ON_STAGE(STAGE));\
_da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(STAGE)));\
}
typedef struct _stage_info {
int dl_id;
+ int thread_id;
source_info_t dl_request;
req_dl_info dl_tansaction_context;
file_info dl_content_storage;
} stage_info;
#define GET_STAGE_DL_ID(STAGE) ((STAGE)->dl_id)
+#define GET_STAGE_THREAD_ID(STAGE) ((STAGE)->thread_id)
#define GET_STAGE_SOURCE_INFO(STAGE) (&((STAGE)->dl_request))
#define GET_STAGE_TRANSACTION_INFO(STAGE) (&((STAGE)->dl_tansaction_context))
#define GET_STAGE_CONTENT_STORE_INFO(STAGE) (&((STAGE)->dl_content_storage))
#define CHANGE_DOWNLOAD_STATE(STATE,STAGE) {\
_da_thread_mutex_lock (&mutex_download_state[GET_STAGE_DL_ID(STAGE)]);\
GET_DL_STATE_ON_STAGE(STAGE) = STATE;\
- DA_LOG_CRITICAL(Default, "Changed download_state to - [%d] ", GET_DL_STATE_ON_STAGE(STAGE));\
+ DA_LOG_DEBUG(Default, "Changed download_state to - [%d] ", GET_DL_STATE_ON_STAGE(STAGE));\
_da_thread_mutex_unlock (&mutex_download_state[GET_STAGE_DL_ID(STAGE)]);\
}
#include "download-agent-type.h"
#include "download-agent-dl-mgr.h"
-#define DA_DEFAULT_FILE_DIR_PATH "/opt/usr/media/.tmp_download"
#define DA_DEFAULT_INSTALL_PATH_FOR_PHONE "/opt/usr/media/Downloads"
-#define DA_DEFAULT_INSTALL_PATH_FOR_MMC "/opt/storage/sdcard/Downloads"
da_bool_t is_file_exist(const char *file_path);
da_bool_t is_dir_exist(const char *dir_path);
void get_file_size(char *file_path, unsigned long long *out_file_size);
da_result_t clean_files_from_dir(char *dir_path);
-da_result_t create_saved_dir(void);
-
da_result_t file_write_ongoing(stage_info *stage, char *body, int body_len);
da_result_t file_write_complete(stage_info *stage);
da_result_t start_file_writing(stage_info *stage);
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_dir(char **out_path);
da_result_t get_default_install_dir(char **out_path);
#endif
typedef enum
{
+ Q_EVENT_TYPE_CONTROL_NONE = 0,
Q_EVENT_TYPE_CONTROL_CANCEL,
Q_EVENT_TYPE_CONTROL_SUSPEND,
Q_EVENT_TYPE_CONTROL_RESUME,
const char *file_name;
const char *temp_file_path; /* For resume download, the "etag" value should be existed together */
const char *etag; /* For resume download */
+ const char *pkg_name; /* For system resource */
void *user_data;
} extension_data_t;
#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;
#include "download-agent-utils.h"
da_result_t get_user_agent_string(char **uagent_str);
-da_result_t get_storage_type(da_storage_type_t *type);
char *get_proxy_address(void);
#endif
#include "download-agent-interface.h"
#include "download-agent-dl-mgr.h"
-/* Todo : move these to mime-util.c */
-#define MIME_DRM_MESSAGE "application/vnd.oma.drm.message"
-#define MIME_ODF "application/vnd.oasis.opendocument.formula"
-#define MIME_OMA_DD "application/vnd.oma.dd+xml"
-#define MIME_MIDP_JAR "application/vnd.sun.j2me.java-archive"
-#define MIME_MULTIPART_MESSAGE "multipart/related"
-#define MIME_TEXT_PLAIN "text/plain"
-
#define SAVE_FILE_BUFFERING_SIZE_50KB (50*1024)
#define SAVE_FILE_BUFFERING_SIZE_5MB (5*1024*1024)
nanosleep(&interval,&remainder); \
} while(0)
-typedef enum {
- DA_STORAGE_PHONE, /*To Store in Phone memory*/
- DA_STORAGE_MMC, /*To Store in MMC */
- DA_STORAGE_SYSTEM /*To Store in both Phone and MMC*/
-} da_storage_type_t;
-
typedef struct _da_storage_size_t {
unsigned long b_available;
unsigned long b_size;
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_type_t storage_type, da_storage_size_t *avail_memory);
+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);
--- /dev/null
+CREATE TABLE IF NOT EXISTS groups
+(
+id INTEGER UNIQUE PRIMARY KEY,
+uid INTEGER DEFAULT 0,
+gid INTEGER DEFAULT 0,
+extra_int INTEGER DEFAULT 0,
+packagename TEXT DEFAULT NULL,
+smack_label TEXT DEFAULT NULL,
+extra TEXT DEFAULT NULL,
+date_first_connected DATE,
+date_last_connected DATE
+);
+
+CREATE TABLE IF NOT EXISTS logging
+(
+id INTEGER UNIQUE PRIMARY KEY,
+state INTEGER DEFAULT 0,
+errorcode INTEGER DEFAULT 0,
+startcount INTEGER DEFAULT 0,
+packagename TEXT DEFAULT NULL,
+createtime DATE,
+accesstime DATE
+);
+
+CREATE TABLE IF NOT EXISTS requestinfo
+(
+id INTEGER UNIQUE PRIMARY KEY,
+auto_download BOOLEAN DEFAULT 0,
+state_event BOOLEAN DEFAULT 0,
+progress_event BOOLEAN DEFAULT 0,
+noti_enable BOOLEAN DEFAULT 0,
+network_type TINYINT DEFAULT 0,
+filename TEXT DEFAULT NULL,
+destination TEXT DEFAULT NULL,
+url TEXT DEFAULT NULL,
+FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS downloadinfo
+(
+id INTEGER UNIQUE PRIMARY KEY,
+http_status INTEGER DEFAULT 0,
+content_size UNSIGNED BIG INT DEFAULT 0,
+mimetype VARCHAR(64) DEFAULT NULL,
+content_name TEXT DEFAULT NULL,
+saved_path TEXT DEFAULT NULL,
+tmp_saved_path TEXT DEFAULT NULL,
+etag TEXT DEFAULT NULL,
+FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS httpheaders
+(
+id INTEGER NOT NULL,
+header_field TEXT DEFAULT NULL,
+header_data TEXT DEFAULT NULL,
+FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS notification
+(
+id INTEGER NOT NULL,
+extra_key TEXT DEFAULT NULL,
+extra_data TEXT DEFAULT NULL,
+raw_bundle_data_complete_state BLOB DEFAULT NULL,
+raw_bundle_data_fail_state BLOB DEFAULT NULL,
+raw_bundle_data_ongoing_state BLOB DEFAULT NULL,
+title TEXT DEFAULT NULL,
+description TEXT DEFAULT NULL,
+noti_type INTEGER DEFAULT 0,
+FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
+);
+
+CREATE UNIQUE INDEX IF NOT EXISTS requests_index ON logging (id, state, errorcode, packagename, createtime, accesstime);
+++ /dev/null
-#!/bin/sh
-
-### A script for running download daemon in booting time.
-#dlogutil -v long -f /var/log/download-capi.log -r 100 -n 10 TIZEN_N_URL_DOWNLOAD &
-#dlogutil -v long -f /var/log/download-daemon.log -r 1000 -n 10 download-provider DownloadAgent &
-
-if [ -x /usr/bin/download-provider ]; then
-/usr/bin/download-provider &
-fi
--- /dev/null
+<manifest>
+ <define>
+ <domain name="download-provider" />
+ <provide>
+ <label name="download-provider::db" />
+ </provide>
+ <request>
+ <smack request="download-provider::db" type="rw" />
+ <smack request="system::use_internet" type="w" />
+ <smack request="sys-assert::core" type="rwxat" />
+ <smack request="device::sys_logging" type="w" />
+ <smack request="system::media" type="arwxt" />
+ <smack request="system::ext_media" type="arwxt" />
+ <smack request="connman" type="rw" />
+ <smack request="net-config" type="rw" />
+ </request>
+ <permit>
+ <smack permit="org.tizen.indicator" type="rx" />
+ <smack permit="org.tizen.quickpanel" type="rx" />
+ <smack permit="system::use_internet" type="w" />
+ </permit>
+ </define>
+ <request>
+ <domain name="download-provider" />
+ </request>
+ <assign>
+ <filesystem path="/usr/lib/libdownload-provider-interface.so*" label="_" exec_label="none" />
+ <filesystem path="/usr/lib/libdownloadagent2.so*" label="_" exec_label="none" />
+ <filesystem path="/usr/lib/systemd/user/download-provider.service" label="_" exec_label="none" />
+ <filesystem path="/usr/lib/systemd/user/tizen-middleware.target.wants/download-provider.service" label="_" exec_label="none" />
+ <filesystem path="/usr/lib/systemd/user/download-provider.socket" label="_" exec_label="none" />
+ <filesystem path="/usr/lib/systemd/user/sockets.target.wants/download-provider.socket" label="_" exec_label="none" />
+ </assign>
+</manifest>
--- /dev/null
+root download-provider rw---
+_default_ download-provider rw---
+download-provider _ -w---
+download-provider data-provider-master::notification.client -w---
+download-provider data-provider-master::notification rw---
+download-provider ail::db rw---
+download-provider device::app_logging -w---
+download-provider system::vconf rwx--
+download-provider system::ext_media rwxat
+download-provider system::media rwxat
+download-provider device::sys_logging -w---
+download-provider sys-assert::core rwxat
+download-provider system::use_internet -w---
+download-provider download-provider::db rw---
+system::use_internet download-provider -w---
+org.tizen.quickpanel download-provider r-x--
+org.tizen.indicator download-provider rwx--
+++ /dev/null
-[D-BUS Service]
-Name=org.download-provider
-Exec=/usr/bin/download-provider service
-User=root
+++ /dev/null
-* Tue Nov 26 2013 Baptiste DURAND <baptiste.durand@eurogiciel.fr> ivi_oct_m2@db80c75
-- Fix TIVI-2045 : move systemd service from user directory to system directory
-- add dbus policy conf file
-- keep only one %manifest entry in spec file
-- Fix and install .service files into dbus system service directory
-
-* Wed Jun 05 2013 Xavier Roche <xavrock.os@gmail.com> submit/tizen/20130523.172942@a691ed7
-- Replace manifest with default floor
-
-* Wed Jun 05 2013 Xavier Roche <xavrock.os@gmail.com> submit/tizen/20130523.172942@cc56f08
-- Fix rpmlint issues
-
-* Tue May 21 2013 Rusty Lynch <rusty.lynch@intel.com> accepted/tizen/20130520.101559@b4e2464
-- Fix spec file according to RPMLINT rules
-- Fix build for 64 bits arch
-
+++ /dev/null
-<manifest>
- <request>
- <domain name="_"/>
- </request>
-</manifest>
-
Name: download-provider
Summary: Download the contents in background
-Version: 1.0.5
-Release: 10
+Version: 1.1.6
+Release: 0
Group: Development/Libraries
License: Apache License, Version 2.0
Source0: %{name}-%{version}.tar.gz
-Source1: download-provider.service
-Source101: org.download-provider.conf
-Source1001: download-provider.manifest
-Requires(post): /usr/bin/sqlite3
+Requires(post): sys-assert
+Requires(post): libdevice-node
+Requires(post): org.tizen.indicator
+Requires(post): org.tizen.quickpanel
+Requires(post): sqlite
+Requires(post): connman
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
BuildRequires: cmake
+BuildRequires: libprivilege-control-conf
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(gobject-2.0)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(libsoup-2.4)
BuildRequires: pkgconfig(xdgmime)
BuildRequires: pkgconfig(vconf)
-BuildRequires: pkgconfig(db-util)
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(bundle)
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(capi-network-connection)
BuildRequires: pkgconfig(notification)
BuildRequires: pkgconfig(appsvc)
-BuildRequires: pkgconfig(dbus-1)
BuildRequires: pkgconfig(wifi-direct)
-Requires(post): /sbin/ldconfig
-Requires(postun): /sbin/ldconfig
+BuildRequires: pkgconfig(libsmack)
+BuildRequires: gettext-devel
+BuildRequires: pkgconfig(libsystemd-daemon)
+
%description
Description: download the contents in background
Requires: %{name} = %{version}-%{release}
%description devel
-Description: download the contents in background (developement files)
+Description: download the contents in background (development files)
%prep
%setup -q
-cp %{SOURCE101} .
-cp %{SOURCE1001} .
-%define _imagedir /usr/share/download-provider
+%define _data_install_path /usr/share/%{name}
+%define _imagedir %{_data_install_path}/images
+%define _localedir %{_data_install_path}/locales
+%define _sqlschemadir %{_data_install_path}/sql
%define _databasedir /opt/usr/dbspace
%define _databasefile %{_databasedir}/.download-provider.db
-%define _dbusservicedir /usr/share/dbus-1/system-services
-%define _dbuspolicydir /etc/dbus-1/system.d
+%define _sqlschemafile %{_sqlschemadir}/download-provider-schema.sql
%define _licensedir /usr/share/license
+%define _smackruledir /opt/etc/smack/accesses.d
%define cmake \
CFLAGS="${CFLAGS:-%optflags} -fPIC -D_REENTRANT -fvisibility=hidden"; export CFLAGS \
-DPKG_VERSION=%{version} \\\
-DPKG_RELEASE=%{release} \\\
-DIMAGE_DIR:PATH=%{_imagedir} \\\
+ -DLOCALE_DIR:PATH=%{_localedir} \\\
+ -DDATABASE_SCHEMA_DIR=%{_sqlschemadir} \\\
-DDATABASE_FILE:PATH=%{_databasefile} \\\
- -DDBUS_SERVICE_DIR:PATH=%{_dbusservicedir} \\\
+ -DDATABASE_SCHEMA_FILE=%{_sqlschemafile} \\\
-DLICENSE_DIR:PATH=%{_licensedir} \\\
- -DSUPPORT_DBUS_SYSTEM:BOOL=ON \\\
+ -DSMACK_RULE_DIR:PATH=%{_smackruledir} \\\
-DSUPPORT_WIFI_DIRECT:BOOL=OFF \\\
-DSUPPORT_LOG_MESSAGE:BOOL=ON \\\
-DSUPPORT_CHECK_IPC:BOOL=ON \\\
-DBUILD_SHARED_LIBS:BOOL=ON
%build
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+%endif
%cmake .
make %{?jobs:-j%jobs}
%install
rm -rf %{buildroot}
%make_install
-
-install -d -m 755 %{buildroot}%{_dbuspolicydir}
-install -m 644 %{SOURCE101} %{buildroot}%{_dbuspolicydir}
-
mkdir -p %{buildroot}%{_licensedir}
-mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc3.d
-ln -s %{_sysconfdir}/rc.d/init.d/download-provider-service %{buildroot}%{_sysconfdir}/rc.d/rc3.d/S70download-provider-service
-mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc5.d
-ln -s %{_sysconfdir}/rc.d/init.d/download-provider-service %{buildroot}%{_sysconfdir}/rc.d/rc5.d/S70download-provider-service
-
-mkdir -p %{buildroot}/%{_unitdir}/graphical.target.wants
-install %{SOURCE1} %{buildroot}/%{_unitdir}/
-ln -s ../download-provider.service %{buildroot}/%{_unitdir}/graphical.target.wants/
-
-mkdir -p %{buildroot}/opt/data/%{name}
-mkdir -p %{buildroot}%{_databasedir}
-if [ ! -f %{buildroot}%{_databasefile} ];
-then
-sqlite3 %{buildroot}%{_databasefile} 'PRAGMA journal_mode=PERSIST;
-PRAGMA foreign_keys=ON;
-CREATE TABLE logging
-(
-id INTEGER UNIQUE PRIMARY KEY,
-state INTEGER DEFAULT 0,
-errorcode INTEGER DEFAULT 0,
-startcount INTEGER DEFAULT 0,
-packagename TEXT DEFAULT NULL,
-createtime DATE,
-accesstime DATE
-);
-
-CREATE TABLE requestinfo
-(
-id INTEGER UNIQUE PRIMARY KEY,
-auto_download BOOLEAN DEFAULT 0,
-state_event BOOLEAN DEFAULT 0,
-progress_event BOOLEAN DEFAULT 0,
-noti_enable BOOLEAN DEFAULT 0,
-network_type TINYINT DEFAULT 0,
-filename TEXT DEFAULT NULL,
-destination TEXT DEFAULT NULL,
-url TEXT DEFAULT NULL,
-FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
-);
-
-CREATE TABLE downloadinfo
-(
-id INTEGER UNIQUE PRIMARY KEY,
-http_status INTEGER DEFAULT 0,
-content_size UNSIGNED BIG INT DEFAULT 0,
-mimetype VARCHAR(64) DEFAULT NULL,
-content_name TEXT DEFAULT NULL,
-saved_path TEXT DEFAULT NULL,
-tmp_saved_path TEXT DEFAULT NULL,
-etag TEXT DEFAULT NULL,
-FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
-);
-
-CREATE TABLE httpheaders
-(
-id INTEGER NOT NULL,
-header_field TEXT DEFAULT NULL,
-header_data TEXT DEFAULT NULL,
-FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
-);
-
-CREATE TABLE notification
-(
-id INTEGER NOT NULL,
-extra_key TEXT DEFAULT NULL,
-extra_data TEXT DEFAULT NULL,
-FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE
-);
-
-CREATE UNIQUE INDEX requests_index ON logging (id, state, errorcode, packagename, createtime, accesstime);
-'
-fi
+mkdir -p %{buildroot}/%{_data_install_path}
+mkdir -p %{buildroot}%{_libdir}/systemd/system/graphical.target.wants
+mkdir -p %{buildroot}%{_libdir}/systemd/system/sockets.target.wants
+ln -s ../download-provider.service %{buildroot}%{_libdir}/systemd/system/graphical.target.wants/
+ln -s ../download-provider.socket %{buildroot}%{_libdir}/systemd/system/sockets.target.wants/
+%post devel
+/sbin/ldconfig
-%post
+%postun devel
/sbin/ldconfig
%postun
/sbin/ldconfig
+%post
+mkdir -p %{_databasedir}
+/sbin/ldconfig
+
+if [ ! -f %{_databasefile} ];
+then
+sqlite3 %{_databasefile} '.read %{_sqlschemafile}'
+chmod 660 %{_databasefile}
+chmod 660 %{_databasefile}-journal
+fi
%files
%defattr(-,root,root,-)
-%manifest %{name}.manifest
-%dir %attr(0775,root,app) /opt/data/%{name}
+%manifest download-provider.manifest
%{_imagedir}/*.png
+%{_imagedir}/*.gif
+%{_localedir}/*
%{_libdir}/libdownloadagent2.so.0.0.1
%{_libdir}/libdownloadagent2.so
-%{_unitdir}/download-provider.service
-%{_unitdir}/graphical.target.wants/download-provider.service
+%{_libdir}/systemd/system/download-provider.service
+%{_libdir}/systemd/system/graphical.target.wants/download-provider.service
+%{_libdir}/systemd/system/download-provider.socket
+%{_libdir}/systemd/system/sockets.target.wants/download-provider.socket
%{_libdir}/libdownload-provider-interface.so.%{version}
%{_libdir}/libdownload-provider-interface.so.0
%{_bindir}/%{name}
-%{_sysconfdir}/rc.d/init.d/download-provider-service
-%{_sysconfdir}/rc.d/rc3.d/S70download-provider-service
-%{_sysconfdir}/rc.d/rc5.d/S70download-provider-service
%{_licensedir}/%{name}
-%{_dbusservicedir}/org.download-provider.service
-%{_dbuspolicydir}/org.download-provider.conf
-%attr(660,root,app) /opt/usr/dbspace/.download-provider.db
-%attr(660,root,app) /opt/usr/dbspace/.download-provider.db-journal
+%{_smackruledir}/%{name}.rule
+%{_sqlschemafile}
%files devel
-%manifest %{name}.manifest
%defattr(-,root,root,-)
+%{_libdir}/libdownloadagent2.so.0.0.1
%{_libdir}/libdownloadagent2.so
%{_libdir}/libdownload-provider-interface.so
%{_includedir}/download-provider/download-provider-defs.h
%{_libdir}/pkgconfig/download-provider.pc
%{_libdir}/pkgconfig/download-provider-interface.pc
+%changelog
+++ /dev/null
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
- <policy user="root">
- <allow own="org.download-provider"/>
- </policy>
- <policy context="default">
- <allow send_destination="org.download-provider"/>
- </policy>
-</busconfig>
-
--- /dev/null
+# for i18n
+
+SET(POFILES ar.po az.po bg.po ca.po cs.po da.po de_DE.po el_GR.po en.po en_PH.po
+ en_US.po es_ES.po es_MX.po et.po eu.po fi.po fr_CA.po fr_FR.po ga.po gl.po hi.po
+ hr.po hu.po hy.po is.po it_IT.po ja_JP.po ka.po kk.po ko_KR.po lt.po lv.po mk.po
+ nb.po nl_NL.po pl.po pt_BR.po pt_PT.po ro.po ru_RU.po sk.po sl.po sr.po sv.po
+ tr_TR.po uk.po uz.po zh_CN.po zh_HK.po zh_SG.po zh_TW.po)
+
+SET(MSGFMT "/usr/bin/msgfmt")
+
+FOREACH(pofile ${POFILES})
+ SET(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${pofile})
+ MESSAGE("PO: ${pofile}")
+ GET_FILENAME_COMPONENT(absPofile ${pofile} ABSOLUTE)
+ GET_FILENAME_COMPONENT(lang ${absPofile} NAME_WE)
+ SET(moFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.mo)
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${moFile}
+ COMMAND ${MSGFMT} -o ${moFile} ${absPofile}
+ DEPENDS ${absPofile}
+ )
+ INSTALL(FILES ${moFile}
+ DESTINATION ${LOCALE_DIR}/${lang}/LC_MESSAGES RENAME ${PKG_NAME}.mo)
+ SET(moFiles ${moFiles} ${moFile})
+ENDFOREACH(pofile)
+
+MESSAGE(".mo files: ${moFiles}")
+ADD_CUSTOM_TARGET(po ALL DEPENDS ${moFiles})
--- /dev/null
+# List of source files containing translatable strings.
+@@APPNAME@@.c
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "تم التنزيل"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Yükləmə tamamlandı"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Изтеглянето завършено"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descàrrega completa"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Stahování dokončeno"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Overførsel fuldført"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download beendet"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Η λήψη ολοκληρώθηκε"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download complete"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download complete"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download complete"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descarga completa"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descarga completa"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Allalaadimine on lõpule viidud"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Deskarga osatuta"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Lataus valmis"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Téléchargement terminé"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Téléchargement terminé"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Íoslódáilte"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descarga completa"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "डाउनलोड पूर्ण"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Skidanje dovršeno"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "A letöltés befejeződött"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Ներբեռնումն ավարտվեց"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Niðurhali lokið"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download completato"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "ダウンロード完了"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "ჩამოტვირთვა დასრულდა"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Жүктеу аяқталды"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "다운로드 완료"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Atsisiuntimas baigtas"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Lejupielāde pabeigta"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Преземањето заврши"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Nedlasting fullført"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Downloaden voltooid"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Pobieranie zakończone"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Download concluído"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Transferência concluída"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Descărcare finalizată"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Загрузка завершена"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Sťahovanie je dokončené"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Prenos je končan"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Preuzimanje završeno"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Hämtningen är klar"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "İndirme tamamlandı"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Завантаження завершено"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "Yuklab olish yakunlandi"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "下载完成"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "下載完成"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "下载完成"
+
--- /dev/null
+msgid "IDS_DM_HEADER_DOWNLOAD_COMPLETE"
+msgstr "下載完成"
+
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
-SET(PC_REQUIRED "glib-2.0 gobject-2.0 dlog capi-base-common capi-appfw-app-manager dbus-1")
+SET(PC_REQUIRED "glib-2.0 gobject-2.0 dlog capi-base-common capi-appfw-app-manager bundle")
INCLUDE(FindPkgConfig)
#include <download-provider-interface.h>
#include <download-provider.h>
-#ifdef DP_DBUS_ACTIVATION
-#include <dbus/dbus.h>
-#endif
-
#ifdef SUPPORT_CHECK_IPC
#include <sys/ioctl.h>
#endif
#define DP_CHECK_CONNECTION do {\
- TRACE_INFO("");\
if (__check_connections() != DP_ERROR_NONE) {\
pthread_mutex_unlock(&g_function_mutex);\
return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;\
errorcode = __ipc_check_ready_status(g_interface_info->cmd_socket);\
if (errorcode != DP_ERROR_NONE) {\
pthread_mutex_unlock(&g_interface_info->mutex);\
- pthread_mutex_unlock(&g_function_mutex);\
if (errorcode == DP_ERROR_IO_ERROR)\
__disconnect_from_provider();\
+ pthread_mutex_unlock(&g_function_mutex);\
return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;\
}\
} while(0)
#undef LOG_TAG
#endif
#define LOG_TAG "DOWNLOAD_PROVIDER_INTERFACE"
-#define TRACE_ERROR(format, ARG...) \
-{ \
-LOGE(format, ##ARG); \
-}
-#define TRACE_STRERROR(format, ARG...) \
-{ \
-LOGE(format" [%s]", ##ARG, strerror(errno)); \
-}
-#define TRACE_INFO(format, ARG...) \
-{ \
-LOGI(format, ##ARG); \
-}
+#define TRACE_DEBUG(format, ARG...) LOGD(format, ##ARG)
+#define TRACE_ERROR(format, ARG...) LOGE(format, ##ARG)
+#define TRACE_STRERROR(format, ARG...) LOGE(format" [%s]", ##ARG, strerror(errno))
+#define TRACE_INFO(format, ARG...) LOGI(format, ##ARG)
+
+#ifdef SECURE_LOGD
+#define TRACE_SECURE_DEBUG(format, ARG...) SECURE_LOGD(format, ##ARG)
#else
-#define TRACE_ERROR(format, ARG...) ;
-#define TRACE_STRERROR(format, ARG...) ;
-#define TRACE_INFO(format, ARG...) ;
+#define TRACE_SECURE_DEBUG(...) do { } while(0)
+#endif
+#ifdef SECURE_LOGI
+#define TRACE_SECURE_INFO(format, ARG...) SECURE_LOGI(format, ##ARG)
+#else
+#define TRACE_SECURE_INFO(...) do { } while(0)
+#endif
+#ifdef SECURE_LOGE
+#define TRACE_SECURE_ERROR(format, ARG...) SECURE_LOGE(format, ##ARG)
+#else
+#define TRACE_SECURE_ERROR(...) do { } while(0)
+#endif
+
+#else
+#define TRACE_DEBUG(...) do { } while(0)
+#define TRACE_ERROR(...) do { } while(0)
+#define TRACE_STRERROR(...) do { } while(0)
+#define TRACE_INFO(...) do { } while(0)
+#define TRACE_SECURE_DEBUG(...) do { } while(0)
+#define TRACE_SECURE_INFO(...) do { } while(0)
+#define TRACE_SECURE_ERROR(...) do { } while(0)
#endif
// define type
dp_interface_info *g_interface_info = NULL;
dp_interface_slot g_interface_slots[MAX_DOWNLOAD_HANDLE];
static pthread_mutex_t g_function_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t g_clear_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t g_interface_event_thread_id = 0;
-#ifdef DP_DBUS_ACTIVATION
-/* DBUS Activation */
-static int __dp_call_dp_interface_service(void)
-{
- DBusConnection *connection = NULL;
- DBusError dbus_error;
-
- dbus_error_init(&dbus_error);
-
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
- if (connection == NULL) {
- TRACE_ERROR("[ERROR] dbus_bus_get");
- if (dbus_error_is_set(&dbus_error)) {
- TRACE_ERROR("[DBUS] dbus_bus_get: %s", dbus_error.message);
- dbus_error_free(&dbus_error);
- }
- return -1;
- }
-
- dbus_uint32_t result = 0;
- if (dbus_bus_start_service_by_name
- (connection,
- DP_DBUS_SERVICE_DBUS, 0, &result, &dbus_error) == FALSE) {
- if (dbus_error_is_set(&dbus_error)) {
- TRACE_ERROR("[DBUS] dbus_bus_start_service_by_name: %s",
- dbus_error.message);
- dbus_error_free(&dbus_error);
- }
- dbus_connection_unref(connection);
- return -1;
- }
- if (result == DBUS_START_REPLY_ALREADY_RUNNING) {
- TRACE_INFO("DBUS_START_REPLY_ALREADY_RUNNING [%d]", result);
- } else if (result == DBUS_START_REPLY_SUCCESS) {
- TRACE_INFO("DBUS_START_REPLY_SUCCESS [%d]", result);
- }
- dbus_connection_unref(connection);
- return 0;
-}
-#endif
-
//////////// defines functions /////////////////
return DP_NETWORK_TYPE_DATA_NETWORK;
case DOWNLOAD_ADAPTOR_NETWORK_WIFI_DIRECT:
return DP_NETWORK_TYPE_WIFI_DIRECT;
+ case DOWNLOAD_ADAPTOR_NETWORK_ALL:
+ return DP_NETWORK_TYPE_ALL;
default:
break;
}
- return DP_NETWORK_TYPE_ALL;
+ return type;
}
static int __dp_interface_convert_network_provider(int type)
return DOWNLOAD_ADAPTOR_NETWORK_DATA_NETWORK;
case DP_NETWORK_TYPE_WIFI_DIRECT:
return DOWNLOAD_ADAPTOR_NETWORK_WIFI_DIRECT;
+ case DOWNLOAD_ADAPTOR_NETWORK_ALL:
+ return DP_NETWORK_TYPE_ALL;
default:
break;
}
- return DOWNLOAD_ADAPTOR_NETWORK_ALL;
+ return type;
}
static int __dp_interface_convert_state(int state)
{
switch (state) {
case DP_STATE_READY:
- TRACE_INFO("READY");
+ TRACE_DEBUG("READY");
return DOWNLOAD_ADPATOR_STATE_READY;
case DP_STATE_CONNECTING:
- TRACE_INFO("CONNECTING/QUEUED");
+ TRACE_DEBUG("CONNECTING/QUEUED");
return DOWNLOAD_ADPATOR_STATE_QUEUED;
case DP_STATE_QUEUED:
- TRACE_INFO("QUEUED");
+ TRACE_DEBUG("QUEUED");
return DOWNLOAD_ADPATOR_STATE_QUEUED;
case DP_STATE_DOWNLOADING:
- TRACE_INFO("DOWNLOADING");
+ TRACE_DEBUG("DOWNLOADING");
return DOWNLOAD_ADPATOR_STATE_DOWNLOADING;
case DP_STATE_PAUSE_REQUESTED:
- TRACE_INFO("PAUSE_REQUESTED/DOWNLOADING");
+ TRACE_DEBUG("PAUSE_REQUESTED/DOWNLOADING");
return DOWNLOAD_ADPATOR_STATE_DOWNLOADING;
case DP_STATE_PAUSED:
- TRACE_INFO("PAUSED");
+ TRACE_DEBUG("PAUSED");
return DOWNLOAD_ADPATOR_STATE_PAUSED;
case DP_STATE_COMPLETED:
- TRACE_INFO("COMPLETED");
+ TRACE_DEBUG("COMPLETED");
return DOWNLOAD_ADPATOR_STATE_COMPLETED;
case DP_STATE_CANCELED:
- TRACE_INFO("CANCELED");
+ TRACE_DEBUG("CANCELED");
return DOWNLOAD_ADPATOR_STATE_CANCELED;
case DP_STATE_FAILED:
- TRACE_INFO("FAILED");
+ TRACE_DEBUG("FAILED");
return DOWNLOAD_ADPATOR_STATE_FAILED;
default:
break;
{
switch (errorcode) {
case DP_ERROR_NONE:
- TRACE_INFO("ERROR_NONE");
return DOWNLOAD_ADAPTOR_ERROR_NONE;
case DP_ERROR_INVALID_PARAMETER:
- TRACE_INFO("ERROR_INVALID_PARAMETER");
+ TRACE_DEBUG("ERROR_INVALID_PARAMETER");
return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
case DP_ERROR_OUT_OF_MEMORY:
- TRACE_INFO("ERROR_OUT_OF_MEMORY");
+ TRACE_DEBUG("ERROR_OUT_OF_MEMORY");
return DOWNLOAD_ADAPTOR_ERROR_OUT_OF_MEMORY;
case DP_ERROR_IO_EAGAIN:
- TRACE_INFO("ERROR_IO_ERROR(EAGAIN)");
+ TRACE_DEBUG("ERROR_IO_ERROR(EAGAIN)");
return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;
case DP_ERROR_IO_EINTR:
- TRACE_INFO("ERROR_IO_ERROR(EINTR)");
+ TRACE_DEBUG("ERROR_IO_ERROR(EINTR)");
return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;
case DP_ERROR_IO_ERROR:
- TRACE_INFO("ERROR_IO_ERROR");
+ TRACE_DEBUG("ERROR_IO_ERROR");
return DOWNLOAD_ADAPTOR_ERROR_IO_ERROR;
case DP_ERROR_NETWORK_UNREACHABLE:
- TRACE_INFO("ERROR_NETWORK_UNREACHABLE");
+ TRACE_DEBUG("ERROR_NETWORK_UNREACHABLE");
return DOWNLOAD_ADAPTOR_ERROR_NETWORK_UNREACHABLE;
case DP_ERROR_NO_SPACE:
- TRACE_INFO("ERROR_NO_SPACE");
+ TRACE_DEBUG("ERROR_NO_SPACE");
return DOWNLOAD_ADAPTOR_ERROR_NO_SPACE;
case DP_ERROR_FIELD_NOT_FOUND:
- TRACE_INFO("ERROR_FIELD_NOT_FOUND");
+ TRACE_DEBUG("ERROR_FIELD_NOT_FOUND");
return DOWNLOAD_ADAPTOR_ERROR_FIELD_NOT_FOUND;
case DP_ERROR_INVALID_STATE:
- TRACE_INFO("ERROR_INVALID_STATE");
+ TRACE_DEBUG("ERROR_INVALID_STATE");
return DOWNLOAD_ADAPTOR_ERROR_INVALID_STATE;
case DP_ERROR_CONNECTION_FAILED:
- TRACE_INFO("ERROR_CONNECTION_TIMED_OUT/CONNECTION_FAILED");
+ TRACE_DEBUG("ERROR_CONNECTION_TIMED_OUT/CONNECTION_FAILED");
return DOWNLOAD_ADAPTOR_ERROR_CONNECTION_TIMED_OUT;
case DP_ERROR_INVALID_URL:
- TRACE_INFO("ERROR_INVALID_URL");
+ TRACE_DEBUG("ERROR_INVALID_URL");
return DOWNLOAD_ADAPTOR_ERROR_INVALID_URL;
case DP_ERROR_INVALID_DESTINATION:
- TRACE_INFO("ERROR_INVALID_DESTINATION");
+ TRACE_DEBUG("ERROR_INVALID_DESTINATION");
return DOWNLOAD_ADAPTOR_ERROR_INVALID_DESTINATION;
+ case DP_ERROR_PERMISSION_DENIED:
+ TRACE_DEBUG("ERROR_PERMISSION_DENIED");
+ return DOWNLOAD_ADAPTOR_ERROR_PERMISSION_DENIED;
case DP_ERROR_QUEUE_FULL:
- TRACE_INFO("ERROR_QUEUE_FULL");
+ TRACE_DEBUG("ERROR_QUEUE_FULL");
return DOWNLOAD_ADAPTOR_ERROR_QUEUE_FULL;
case DP_ERROR_ALREADY_COMPLETED:
- TRACE_INFO("ERROR_ALREADY_COMPLETED");
+ TRACE_DEBUG("ERROR_ALREADY_COMPLETED");
return DOWNLOAD_ADAPTOR_ERROR_ALREADY_COMPLETED;
case DP_ERROR_FILE_ALREADY_EXISTS:
- TRACE_INFO("ERROR_FILE_ALREADY_EXISTS");
+ TRACE_DEBUG("ERROR_FILE_ALREADY_EXISTS");
return DOWNLOAD_ADAPTOR_ERROR_FILE_ALREADY_EXISTS;
case DP_ERROR_TOO_MANY_DOWNLOADS:
- TRACE_INFO("ERROR_TOO_MANY_DOWNLOADS");
+ TRACE_DEBUG("ERROR_TOO_MANY_DOWNLOADS");
return DOWNLOAD_ADAPTOR_ERROR_TOO_MANY_DOWNLOADS;
case DP_ERROR_NO_DATA:
- TRACE_INFO("ERROR_NO_DATA");
+ TRACE_DEBUG("ERROR_NO_DATA");
return DOWNLOAD_ADAPTOR_ERROR_NO_DATA;
case DP_ERROR_UNHANDLED_HTTP_CODE:
- TRACE_INFO("ERROR_UNHANDLED_HTTP_CODE");
+ TRACE_DEBUG("ERROR_UNHANDLED_HTTP_CODE");
return DOWNLOAD_ADAPTOR_ERROR_UNHANDLED_HTTP_CODE;
case DP_ERROR_CANNOT_RESUME:
- TRACE_INFO("ERROR_CANNOT_RESUME");
+ TRACE_DEBUG("ERROR_CANNOT_RESUME");
return DOWNLOAD_ADAPTOR_ERROR_CANNOT_RESUME;
case DP_ERROR_ID_NOT_FOUND:
- TRACE_INFO("ERROR_ID_NOT_FOUND");
+ TRACE_DEBUG("ERROR_ID_NOT_FOUND");
return DOWNLOAD_ADAPTOR_ERROR_ID_NOT_FOUND;
case DP_ERROR_UNKNOWN:
- TRACE_INFO("ERROR_INVALID_STATE/UNKNOWN");
+ TRACE_DEBUG("ERROR_INVALID_STATE/UNKNOWN");
return DOWNLOAD_ADAPTOR_ERROR_INVALID_STATE;
default:
break;
errorcode = DP_ERROR_IO_EAGAIN;
} else if (errno == EINTR) {
TRACE_ERROR("[EINTR] Interrupted System Call [%d]", errno);
- errorcode = DP_ERROR_IO_EINTR;
+ errorcode = DP_ERROR_IO_ERROR;
}
return errorcode;
}
return -1;
}
- if (read(fd, value, type_size) < 0) {
+ ssize_t recv_bytes = read(fd, value, type_size);
+ if (recv_bytes < 0) {
TRACE_STRERROR("[CRITICAL] read");
return -1;
}
TRACE_ERROR("[CHECK SOCKET]");
return -1;
}
- if (read(fd, &value, sizeof(int)) < 0) {
+ ssize_t recv_bytes = read(fd, &value, sizeof(int));
+ if (recv_bytes < 0) {
TRACE_STRERROR("[CRITICAL] read");
return -1;
}
return value;
}
+static int __ipc_read_download_id(int fd)
+{
+ int value = -1;
+ int read_len = 0;
+ int try_count = 5;
+
+ if (fd < 0) {
+ TRACE_ERROR("[CHECK SOCKET]");
+ return -1;
+ }
+ do {
+ read_len = read(fd, &value, sizeof(int));
+ if (read_len < 0) {
+ TRACE_STRERROR("[CRITICAL] read");
+ return -1;
+ }
+ try_count--;
+ } while (read_len == 0 && value == 0 && try_count > 0);
+ return value;
+}
+
// keep the order/ unsigned , str
static char *__ipc_read_string(int fd)
{
unsigned length = 0;
+ size_t recv_size = 0;
+ unsigned remain_size = 0;
+ size_t buffer_size = 0;
char *str = NULL;
if (fd < 0) {
- TRACE_ERROR("[CHECK FD]");
+ TRACE_ERROR("[ERROR] CHECK FD[%d]", fd);
return NULL;
}
- if (read(fd, &length, sizeof(unsigned)) < 0) {
- TRACE_STRERROR("failed to read length [%d]", length);
+ // read flexible URL from client.
+ ssize_t recv_bytes = read(fd, &length, sizeof(unsigned));
+ if (recv_bytes < 0) {
+ TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
return NULL;
}
if (length < 1 || length > DP_MAX_URL_LEN) {
}
str = (char *)calloc((length + 1), sizeof(char));
if (str == NULL) {
- TRACE_STRERROR("[CRITICAL] allocation");
+ TRACE_STRERROR("[ERROR] calloc length:%d FD[%d]", length, fd);
return NULL;
}
- if (read(fd, str, length * sizeof(char)) < 0) {
- TRACE_STRERROR("failed to read string");
+ remain_size = length;
+ do {
+ buffer_size = 0;
+ if (remain_size > DP_DEFAULT_BUFFER_SIZE)
+ buffer_size = DP_DEFAULT_BUFFER_SIZE;
+ else
+ buffer_size = remain_size;
+ recv_size = (size_t)read(fd, str + (int)(length - remain_size),
+ buffer_size * sizeof(char));
+ if (recv_size > DP_DEFAULT_BUFFER_SIZE) {
+ recv_size = -1;
+ break;
+ }
+ if (recv_size > 0)
+ remain_size = remain_size - (unsigned)recv_size;
+ } while (recv_size > 0 && remain_size > 0);
+
+ if (recv_size == 0) {
+ TRACE_STRERROR("[ERROR] closed peer:%d", fd);
free(str);
- str = NULL;
return NULL;
}
str[length] = '\0';
return str;
}
+int __ipc_read_bundle(int fd, bundle_raw **b)
+{
+ unsigned length = 0;
+ size_t recv_size = 0;
+ unsigned remain_size = 0;
+ size_t buffer_size = 0;
+ bundle_raw *b_raw = NULL;
+
+ if (fd < 0) {
+ TRACE_ERROR("[ERROR] CHECK FD[%d]", fd);
+ return 0;
+ }
+
+ // read bundle data from client.
+ ssize_t recv_bytes = read(fd, &length, sizeof(unsigned));
+ if (recv_bytes < 0) {
+ TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
+ return 0;
+ }
+ if (length < 1 || length > DP_MAX_URL_LEN) {
+ TRACE_ERROR("[STRING LEGNTH] [%d]", length);
+ return 0;
+ }
+ b_raw = (bundle_raw *)calloc(length, 1);
+ if (b_raw == NULL) {
+ TRACE_STRERROR("[ERROR] calloc length:%d FD[%d]", length, fd);
+ return 0;
+ }
+ remain_size = length;
+ do {
+ buffer_size = 0;
+ if (remain_size > DP_DEFAULT_BUFFER_SIZE)
+ buffer_size = DP_DEFAULT_BUFFER_SIZE;
+ else
+ buffer_size = remain_size;
+ recv_size = (size_t)read(fd, b_raw + (int)(length - remain_size),
+ buffer_size);
+ if (recv_size > DP_DEFAULT_BUFFER_SIZE) {
+ recv_size = -1;
+ break;
+ }
+ if (recv_size > 0)
+ remain_size = remain_size - (unsigned)recv_size;
+ } while (recv_size > 0 && remain_size > 0);
+
+ if (recv_size == 0) {
+ TRACE_STRERROR("[ERROR] closed peer:%d", fd);
+ bundle_free_encoded_rawdata(&b_raw);
+ return 0;
+ }
+ *b = b_raw;
+ return (int)length;
+}
+
static dp_error_type __ipc_return(int fd)
{
dp_error_type errorcode = DP_ERROR_NONE;
TRACE_ERROR("[CHECK SOCKET]");
return DP_ERROR_IO_ERROR;
}
-
- if (read(fd, &errorcode, sizeof(dp_error_type)) < 0) {
+ ssize_t recv_bytes = read(fd, &errorcode, sizeof(dp_error_type));
+ if (recv_bytes < 0) {
TRACE_STRERROR("[CRITICAL] read");
return __get_standard_errorcode(DP_ERROR_IO_ERROR);
}
- TRACE_INFO("return : %d", errorcode);
+ if (errorcode != DP_ERROR_NONE)
+ TRACE_ERROR("return : %d", errorcode);
return errorcode;
}
TRACE_ERROR("[CHECK ALLOCATION]");
return NULL;
}
- if (read(fd, event, sizeof(dp_event_info)) < 0) {
+ ssize_t recv_bytes = read(fd, event, sizeof(dp_event_info));
+ if (recv_bytes < 0) {
TRACE_STRERROR("[CRITICAL] read");
free(event);
return NULL;
}
-
- TRACE_INFO("EVENT INFO (ID : %d state : %d error : %d)",
- event->id, event->state, event->err);
return event;
}
return DP_ERROR_NONE;
}
+static dp_error_type __ipc_send_raw_bundle(int fd, int type, const bundle_raw *b, int len)
+{
+ if (fd < 0) {
+ TRACE_ERROR("[CHECK FD]");
+ return DP_ERROR_IO_ERROR;
+ }
+ if (b == NULL || len <= 0) {
+ TRACE_ERROR("[CHECK STRING]");
+ return DP_ERROR_INVALID_PARAMETER;
+ }
+ if (fd >= 0 && write(fd, &type, sizeof(unsigned)) < 0) {
+ TRACE_STRERROR("[CRITICAL] send");
+ return DP_ERROR_IO_ERROR;
+ }
+ if (fd >= 0 && write(fd, &len, sizeof(unsigned)) < 0) {
+ TRACE_STRERROR("[CRITICAL] send");
+ return DP_ERROR_IO_ERROR;
+ }
+ if (fd >= 0 && write(fd, b, len) < 0) {
+ TRACE_STRERROR("[CRITICAL] send");
+ return DP_ERROR_IO_ERROR;
+ }
+ return DP_ERROR_NONE;
+}
+
static dp_error_type __ipc_send_command
(int fd, int id, dp_command_type cmd)
{
static dp_error_type __ipc_send_command_return
(int id, dp_command_type cmd)
{
- TRACE_INFO("");
-
if (cmd <= DP_CMD_NONE) {
TRACE_ERROR("[CHECK COMMAND] (%d)", cmd);
return DP_ERROR_INVALID_PARAMETER;
struct timeval tv_timeo = { 2, 500000 }; //2.5 second
struct sockaddr_un clientaddr;
- TRACE_INFO("");
-
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
TRACE_STRERROR("[CRITICAL] socket system error");
return -1;
close(sockfd);
return -1;
}
- TRACE_INFO("sockfd [%d]", sockfd);
+ TRACE_DEBUG("sockfd [%d]", sockfd);
return sockfd;
}
-static int __disconnect_from_provider()
+static void __clear_interface()
{
- TRACE_INFO("");
-
+ TRACE_DEBUG("");
+ pthread_mutex_lock(&g_clear_mutex);
if (g_interface_info != NULL) {
shutdown(g_interface_info->cmd_socket, 0);
close(g_interface_info->cmd_socket);
free(g_interface_info);
g_interface_info = NULL;
}
- if (g_interface_event_thread_id > 0) {
- TRACE_INFO("STOP event thread");
- pthread_cancel(g_interface_event_thread_id);
+ pthread_mutex_unlock(&g_clear_mutex);
+}
+
+static int __disconnect_from_provider()
+{
+ TRACE_DEBUG("");
+ if (g_interface_event_thread_id > 0 &&
+ pthread_kill(g_interface_event_thread_id, 0) != ESRCH) {
+ if (pthread_cancel(g_interface_event_thread_id) != 0) {
+ TRACE_STRERROR("pthread:%d", (int)g_interface_event_thread_id);
+ }
g_interface_event_thread_id = 0;
- TRACE_INFO("OK terminate event thread");
}
+ __clear_interface();
return DP_ERROR_NONE;
}
// FIONREAD : Returns the number of bytes immediately readable
if (ioctl(fd, FIONREAD, &unread_count) >= 0) {
if (unread_count > 0) {
- TRACE_INFO("[CLEAN] garbage packet[%ld]", unread_count);
+ TRACE_DEBUG("[CLEAN] garbage packet[%ld]", unread_count);
for ( i = 0; i < unread_count; i++) {
if (read(fd, &tmp_char, sizeof(char)) < 0) {
TRACE_STRERROR("[CHECK] read");
return 0;
}
- // deferred wait to cencal until next function called.
+ // deferred wait to cancal until next function called.
// ex) function : select, read in this thread
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
- TRACE_INFO("FD [%d]", g_interface_info->event_socket);
-
maxfd = g_interface_info->event_socket;
FD_ZERO(&read_fdset);
FD_SET(g_interface_info->event_socket, &read_fdset);
+ int sock = g_interface_info->event_socket;
+
while(g_interface_info != NULL
&& g_interface_info->event_socket >= 0) {
rset = read_fdset;
("[CRITICAL] [CHECK TID] SELF ID [%d] Global ID (%d)",
pthread_self(), g_interface_event_thread_id);
// another thread may work. just terminate
- return 0;
- }
-
- pthread_mutex_lock(&g_function_mutex);
-
- if (g_interface_info == NULL
- || g_interface_info->event_socket < 0) {
- TRACE_ERROR("[CRITICAL] IPC BROKEN Ending Event Thread");
- pthread_mutex_unlock(&g_function_mutex);
- // disconnected by main thread. just terminate
- return 0;
+ break;
}
- if (FD_ISSET(g_interface_info->event_socket, &rset) > 0) {
+ if (FD_ISSET(sock, &rset) > 0) {
// read state info from socket
- eventinfo = __ipc_event(g_interface_info->event_socket);
+ eventinfo = __ipc_event(sock);
if (eventinfo == NULL || eventinfo->id <= 0) {
// failed to read from socket // ignore this status
free(eventinfo);
TRACE_STRERROR("[CRITICAL] Can not read Event packet");
- pthread_mutex_unlock(&g_function_mutex);
- if (__get_standard_errorcode(DP_ERROR_IO_ERROR) ==
- DP_ERROR_IO_ERROR) // if not timeout. end thread
- break;
- continue;
+ g_interface_event_thread_id = 0;
+ __clear_interface();
+ return 0;
}
if ((index = __get_my_slot_index(eventinfo->id)) < 0) {
TRACE_ERROR("[CRITICAL] not found slot for [%d]",
eventinfo->id);
free(eventinfo);
- pthread_mutex_unlock(&g_function_mutex);
continue;
}
- pthread_mutex_unlock(&g_function_mutex);
-
- // begin protect callback sections
+ // begin protect callback sections & thread safe
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
-
dp_interface_callback *callback =
&g_interface_slots[index].callback;
if (eventinfo->state == DP_STATE_DOWNLOADING
&& eventinfo->received_size > 0) {
- if (callback->progress != NULL) {
+ if (eventinfo->id == g_interface_slots[index].id &&
+ callback->progress != NULL) {
// progress event
- TRACE_INFO("ID %d progress callback %p",
- eventinfo->id, callback->progress );
callback->progress(eventinfo->id,
eventinfo->received_size,
callback->progress_data);
}
} else {
- if (callback->state != NULL) {
+ if (eventinfo->id == g_interface_slots[index].id &&
+ callback->state != NULL) {
// state event
- TRACE_INFO("ID %d state callback %p", eventinfo->id,
- callback->state);
callback->state(eventinfo->id,
__dp_interface_convert_state(eventinfo->state),
callback->state_data);
}
}
free(eventinfo);
-
- // end protect callback sections
- pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
- continue;
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
}
- pthread_mutex_unlock(&g_function_mutex);
} // while
- FD_ZERO(&read_fdset);
-
- TRACE_INFO("Terminate Event Thread");
- pthread_mutex_lock(&g_function_mutex);
- TRACE_INFO("Disconnect All Connection");
+ FD_CLR(sock, &read_fdset);
g_interface_event_thread_id = 0; // set 0 to not call pthread_cancel
- __disconnect_from_provider();
- pthread_mutex_unlock(&g_function_mutex);
+ TRACE_DEBUG("thread end by itself");
return 0;
}
static int __connect_to_provider()
{
- TRACE_INFO("");
-
+ pthread_mutex_lock(&g_clear_mutex);
if (g_interface_info == NULL) {
-#ifdef DP_DBUS_ACTIVATION
- if (__dp_call_dp_interface_service() < 0) {
- TRACE_ERROR("[DBUS IO] __dp_call_dp_interface_service");
- return DP_ERROR_IO_ERROR;
- }
-#endif
-
g_interface_info =
(dp_interface_info *) calloc(1, sizeof(dp_interface_info));
}
TRACE_STRERROR("[CRITICAL] connect system error");
free(g_interface_info);
g_interface_info = NULL;
+ pthread_mutex_unlock(&g_clear_mutex);
return DP_ERROR_IO_ERROR;
}
// send a command
close(g_interface_info->cmd_socket);
free(g_interface_info);
g_interface_info = NULL;
+ pthread_mutex_unlock(&g_clear_mutex);
return DP_ERROR_IO_ERROR;
}
#ifndef SO_PEERCRED
close(g_interface_info->cmd_socket);
free(g_interface_info);
g_interface_info = NULL;
+ pthread_mutex_unlock(&g_clear_mutex);
+ return DP_ERROR_IO_ERROR;
+ }
+ if (__ipc_send_int(g_interface_info->cmd_socket, getuid()) < 0) {
+ close(g_interface_info->cmd_socket);
+ free(g_interface_info);
+ g_interface_info = NULL;
+ pthread_mutex_unlock(&g_clear_mutex);
+ return DP_ERROR_IO_ERROR;
+ }
+ if (__ipc_send_int(g_interface_info->cmd_socket, getgid()) < 0) {
+ close(g_interface_info->cmd_socket);
+ free(g_interface_info);
+ g_interface_info = NULL;
+ pthread_mutex_unlock(&g_clear_mutex);
return DP_ERROR_IO_ERROR;
}
#endif
close(g_interface_info->cmd_socket);
free(g_interface_info);
g_interface_info = NULL;
+ pthread_mutex_unlock(&g_clear_mutex);
return DP_ERROR_IO_ERROR;
}
// send a command
close(g_interface_info->event_socket);
free(g_interface_info);
g_interface_info = NULL;
+ pthread_mutex_unlock(&g_clear_mutex);
return DP_ERROR_IO_ERROR;
}
#ifndef SO_PEERCRED
close(g_interface_info->event_socket);
free(g_interface_info);
g_interface_info = NULL;
+ pthread_mutex_unlock(&g_clear_mutex);
return DP_ERROR_IO_ERROR;
}
#endif
int ret = pthread_mutex_init(&g_interface_info->mutex, NULL);
if (ret != 0) {
TRACE_STRERROR("ERR:pthread_mutex_init FAIL with %d.", ret);
- __disconnect_from_provider();
+ __clear_interface();
+ pthread_mutex_unlock(&g_clear_mutex);
return DP_ERROR_IO_ERROR;
}
- if (g_interface_event_thread_id <= 0) {
- // create thread here ( getting event_socket )
- pthread_attr_t thread_attr;
- if (pthread_attr_init(&thread_attr) != 0) {
- TRACE_STRERROR("[CRITICAL] pthread_attr_init");
- __disconnect_from_provider();
- return DP_ERROR_IO_ERROR;
- }
- if (pthread_attr_setdetachstate(&thread_attr,
- PTHREAD_CREATE_DETACHED) != 0) {
- TRACE_STRERROR
- ("[CRITICAL] pthread_attr_setdetachstate");
- __disconnect_from_provider();
- return DP_ERROR_IO_ERROR;
- }
- if (pthread_create(&g_interface_event_thread_id,
- &thread_attr, __dp_interface_event_manager,
- g_interface_info) != 0) {
- TRACE_STRERROR("[CRITICAL] pthread_create");
- __disconnect_from_provider();
- return DP_ERROR_IO_ERROR;
- }
+ }
+ pthread_mutex_unlock(&g_clear_mutex);
+ if (g_interface_event_thread_id <= 0) {
+ // create thread here ( getting event_socket )
+ pthread_attr_t thread_attr;
+ if (pthread_attr_init(&thread_attr) != 0) {
+ TRACE_STRERROR("[CRITICAL] pthread_attr_init");
+ __disconnect_from_provider();
+ return DP_ERROR_IO_ERROR;
+ }
+ if (pthread_attr_setdetachstate(&thread_attr,
+ PTHREAD_CREATE_DETACHED) != 0) {
+ TRACE_STRERROR
+ ("[CRITICAL] pthread_attr_setdetachstate");
+ __disconnect_from_provider();
+ return DP_ERROR_IO_ERROR;
+ }
+ if (pthread_create(&g_interface_event_thread_id,
+ &thread_attr, __dp_interface_event_manager,
+ g_interface_info) != 0) {
+ TRACE_STRERROR("[CRITICAL] pthread_create");
+ __clear_interface();
+ g_interface_event_thread_id = 0;
+ return DP_ERROR_IO_ERROR;
}
}
return DP_ERROR_NONE;
int fd = g_interface_info->cmd_socket;
// send commnad with ID
- errorcode = __ipc_send_command(fd, id, cmd);
+ errorcode = __ipc_send_command_return(id, cmd);
if (errorcode == DP_ERROR_NONE) {
// send string
errorcode = __ipc_send_string(fd, value);
int fd = g_interface_info->cmd_socket;
// send commnad with ID
- errorcode = __ipc_send_command(fd, id, cmd);
+ errorcode = __ipc_send_command_return(id, cmd);
if (errorcode == DP_ERROR_NONE) {
if (__ipc_send_int(fd, (int)count) == 0) {
int i = 0;
int fd = g_interface_info->cmd_socket;
- errorcode = __ipc_send_command(fd, id, cmd);
+ errorcode = __ipc_send_command_return(id, cmd);
if (errorcode == DP_ERROR_NONE) {
if (length > 0 && strings != NULL) {
if (__ipc_send_int(fd, (int)length) == 0) {
recv_int = __ipc_read_int(fd);
if (recv_int >= 0) {
*value = recv_int;
- TRACE_INFO("ID : %d recv_int : %d", id, *value);
+ TRACE_DEBUG("ID : %d recv_int : %d", id, *value);
} else {
errorcode = __get_standard_errorcode(DP_ERROR_IO_ERROR);
}
int fd = g_interface_info->cmd_socket;
// send commnad with ID
- errorcode = __ipc_send_command(fd, id, cmd);
+ errorcode = __ipc_send_command_return(id, cmd);
if (errorcode == DP_ERROR_NONE) {
// send string
if (__ipc_send_int(fd, value) == 0) {
return __dp_interface_convert_errorcode(errorcode);
}
+static dp_error_type __dp_interface_set_raw_bundle
+ (const int id, const dp_command_type cmd, int type, const bundle_raw *b, int len)
+{
+ dp_error_type errorcode = DP_ERROR_NONE;
+ if (b == NULL) {
+ TRACE_ERROR("[CHECK bundle]");
+ return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
+ }
+
+ DP_PRE_CHECK_ID;
+
+ pthread_mutex_lock(&g_function_mutex);
+
+ DP_CHECK_CONNECTION;
+
+ pthread_mutex_lock(&g_interface_info->mutex);
+
+ DP_CHECK_PROVIDER_STATUS;
+
+ int fd = g_interface_info->cmd_socket;
+
+ // send commnad with ID
+ errorcode = __ipc_send_command_return(id, cmd);
+ if (errorcode == DP_ERROR_NONE) {
+ // send raw bundle
+ errorcode = __ipc_send_raw_bundle(fd, type, b, len);
+ if (errorcode == DP_ERROR_NONE) {
+ // return from provider.
+ errorcode = __ipc_return(fd);
+ }
+ }
+ pthread_mutex_unlock(&g_interface_info->mutex);
+ if (errorcode == DP_ERROR_IO_ERROR)
+ __disconnect_from_provider();
+ pthread_mutex_unlock(&g_function_mutex);
+ return __dp_interface_convert_errorcode(errorcode);
+}
+
+static dp_error_type __dp_interface_get_raw_bundle
+ (const int id, const dp_command_type cmd, int type, bundle_raw **value, int *len)
+{
+ int errorcode = DP_ERROR_NONE;
+
+ if (value == NULL) {
+ TRACE_ERROR("[CHECK buffer]");
+ return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
+ }
+
+ DP_PRE_CHECK_ID;
+
+ pthread_mutex_lock(&g_function_mutex);
+
+ DP_CHECK_CONNECTION;
+
+ pthread_mutex_lock(&g_interface_info->mutex);
+
+ DP_CHECK_PROVIDER_STATUS;
+
+ int fd = g_interface_info->cmd_socket;
+
+ errorcode = __ipc_send_command_return(id, cmd);
+ if (errorcode == DP_ERROR_NONE) {
+ errorcode = __ipc_send_int(fd, type);
+ if(errorcode == 0) {
+ errorcode = __ipc_return(g_interface_info->cmd_socket);
+ if (errorcode == DP_ERROR_NONE) {
+ *len = __ipc_read_bundle(fd, value);
+ if (*len <= 0)
+ errorcode = __get_standard_errorcode(DP_ERROR_IO_ERROR);
+ } else {
+ TRACE_ERROR("[ERROR] Fail to get result for sending type value]");
+ errorcode = DP_ERROR_IO_ERROR;
+ }
+ } else {
+ TRACE_ERROR("[ERROR] Fail to send type]");
+ errorcode = DP_ERROR_IO_ERROR;
+ }
+ } else {
+ TRACE_ERROR("[ERROR] Fail to send command]");
+ errorcode = DP_ERROR_IO_ERROR;
+ }
+ pthread_mutex_unlock(&g_interface_info->mutex);
+ if (errorcode == DP_ERROR_IO_ERROR)
+ __disconnect_from_provider();
+ pthread_mutex_unlock(&g_function_mutex);
+ return __dp_interface_convert_errorcode(errorcode);
+}
+
/////////////////////// APIs /////////////////////////////////
errorcode = __ipc_send_command_return(-1, DP_CMD_CREATE);
if (errorcode == DP_ERROR_NONE) {
// getting state with ID from provider.
- t_id = __ipc_read_int(g_interface_info->cmd_socket);
- if (t_id >= 0) {
+ t_id = __ipc_read_download_id(g_interface_info->cmd_socket);
+ if (t_id > 0) {
*id = t_id;
g_interface_slots[index].id = t_id;
g_interface_slots[index].callback.state = NULL;
errorcode = __ipc_send_command_return(id, DP_CMD_DESTROY);
if (errorcode == DP_ERROR_NONE) {
// after getting errorcode, send FREE to provider.
- TRACE_INFO("Request to Free the memory for ID : %d", id);
// send again DP_CMD_FREE with ID.
errorcode = __ipc_send_command
(g_interface_info->cmd_socket, id, DP_CMD_FREE);
int dp_interface_set_url(const int id, const char *url)
{
- TRACE_INFO("");
return __dp_interface_set_string(id, DP_CMD_SET_URL, url);
}
int dp_interface_get_url(const int id, char **url)
{
- TRACE_INFO("");
return __dp_interface_get_string(id, DP_CMD_GET_URL, url);
}
int dp_interface_set_network_type(const int id, int net_type)
{
- TRACE_INFO("");
return __dp_interface_set_int(id, DP_CMD_SET_NETWORK_TYPE,
__dp_interface_convert_network_adaptor(net_type));
}
int dp_interface_get_network_type(const int id, int *net_type)
{
- TRACE_INFO("");
if (net_type == NULL) {
TRACE_ERROR("[CHECK buffer]");
return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
int dp_interface_set_destination(const int id, const char *path)
{
- TRACE_INFO("");
return __dp_interface_set_string(id, DP_CMD_SET_DESTINATION, path);
}
int dp_interface_get_destination(const int id, char **path)
{
- TRACE_INFO("");
return __dp_interface_get_string(id, DP_CMD_GET_DESTINATION, path);
}
int dp_interface_set_file_name(const int id, const char *file_name)
{
- TRACE_INFO("");
return __dp_interface_set_string(id, DP_CMD_SET_FILENAME, file_name);
}
int dp_interface_get_file_name(const int id, char **file_name)
{
- TRACE_INFO("");
return __dp_interface_get_string(id, DP_CMD_GET_FILENAME, file_name);
}
int dp_interface_set_notification(const int id, int enable)
{
- TRACE_INFO("");
return __dp_interface_set_int(id, DP_CMD_SET_NOTIFICATION, enable);
}
int dp_interface_get_notification(const int id, int *enable)
{
- TRACE_INFO("");
return __dp_interface_get_int(id, DP_CMD_GET_NOTIFICATION, enable);
}
int dp_interface_get_downloaded_file_path(const int id, char **path)
{
- TRACE_INFO("");
return __dp_interface_get_string(id, DP_CMD_GET_SAVED_PATH, path);
}
*key = key_str;
*value = value_str;
- TRACE_INFO("ID : %d key : %s value : %s", id, *key, *value);
pthread_mutex_unlock(&g_function_mutex);
#endif
return DOWNLOAD_ADAPTOR_ERROR_NONE;
DP_CHECK_PROVIDER_STATUS;
// send commnad with ID
- if (__ipc_send_command
- (g_interface_info->cmd_socket, id, DP_CMD_SET_HTTP_HEADER)
- != DP_ERROR_NONE) {
+ if (__ipc_send_command_return(id, DP_CMD_SET_HTTP_HEADER) !=
+ DP_ERROR_NONE) {
pthread_mutex_unlock(&g_interface_info->mutex);
__disconnect_from_provider();
pthread_mutex_unlock(&g_function_mutex);
DP_CHECK_PROVIDER_STATUS;
- if (__ipc_send_command
- (g_interface_info->cmd_socket, id, DP_CMD_GET_HTTP_HEADER)
- != DP_ERROR_NONE) {
+ if (__ipc_send_command_return(id, DP_CMD_GET_HTTP_HEADER) !=
+ DP_ERROR_NONE) {
pthread_mutex_unlock(&g_interface_info->mutex);
__disconnect_from_provider();
pthread_mutex_unlock(&g_function_mutex);
str = __ipc_read_string(g_interface_info->cmd_socket);
if (str != NULL) {
*value = str;
- TRACE_INFO("ID : %d field:%s value: %s", id, field, *value);
} else {
errorcode = __get_standard_errorcode(DP_ERROR_IO_ERROR);
}
int dp_interface_get_http_header_field_list(const int id, char ***fields,
int *length)
{
- TRACE_INFO("");
return __dp_interface_get_strings(id, DP_CMD_GET_HTTP_HEADER_LIST,
NULL, 0, fields, (unsigned *)length);
}
DP_CHECK_PROVIDER_STATUS;
// send commnad with ID
- if (__ipc_send_command
- (g_interface_info->cmd_socket, id, DP_CMD_DEL_HTTP_HEADER)
- != DP_ERROR_NONE) {
+ if (__ipc_send_command_return(id, DP_CMD_DEL_HTTP_HEADER) !=
+ DP_ERROR_NONE) {
pthread_mutex_unlock(&g_interface_info->mutex);
__disconnect_from_provider();
pthread_mutex_unlock(&g_function_mutex);
int dp_interface_get_state(const int id, int *state)
{
- TRACE_INFO("");
if (state == NULL) {
TRACE_ERROR("[CHECK buffer]");
return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
int dp_interface_get_temp_path(const int id, char **temp_path)
{
- TRACE_INFO("");
return __dp_interface_get_string
(id, DP_CMD_GET_TEMP_SAVED_PATH, temp_path);
}
int dp_interface_get_content_name(const int id, char **content_name)
{
- TRACE_INFO("");
return __dp_interface_get_string
(id, DP_CMD_GET_CONTENT_NAME, content_name);
}
if (__ipc_read_custom_type(g_interface_info->cmd_socket,
content_size, sizeof(unsigned long long)) < 0) {
errorcode = __get_standard_errorcode(DP_ERROR_IO_ERROR);
- } else {
- TRACE_INFO("ID : %d content_size %lld", id, *content_size);
}
}
pthread_mutex_unlock(&g_interface_info->mutex);
int dp_interface_get_mime_type(const int id, char **mime_type)
{
- TRACE_INFO("");
return __dp_interface_get_string
(id, DP_CMD_GET_MIME_TYPE, mime_type);
}
int dp_interface_set_auto_download(const int id, int enable)
{
- TRACE_INFO("");
return __dp_interface_set_int(id, DP_CMD_SET_AUTO_DOWNLOAD, enable);
}
int dp_interface_get_auto_download(const int id, int *enable)
{
- TRACE_INFO("");
return __dp_interface_get_int(id, DP_CMD_GET_AUTO_DOWNLOAD, enable);
}
int dp_interface_get_error(const int id, int *error)
{
- TRACE_INFO("");
if (error == NULL) {
TRACE_ERROR("[CHECK buffer error]");
return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
int dp_interface_get_http_status(const int id, int *http_status)
{
- TRACE_INFO("");
return __dp_interface_get_int
(id, DP_CMD_GET_HTTP_STATUS, http_status);
}
{
int i = 0;
- TRACE_INFO("");
-
if (key == NULL || values == NULL) {
TRACE_ERROR("[CHECK key/values] (%d)", id);
return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
int dp_interface_get_noti_extra_values(const int id, const char *key,
char ***values, unsigned *length)
{
- TRACE_INFO("");
return __dp_interface_get_strings(id, DP_CMD_GET_EXTRA_PARAM,
&key, 1, values, length);
}
int dp_interface_remove_noti_extra_key(const int id, const char *key)
{
- TRACE_INFO("");
return __dp_interface_set_string
(id, DP_CMD_REMOVE_EXTRA_PARAM, key);
}
+
+int dp_interface_set_notification_bundle(const int id, int type, bundle *b)
+{
+ bundle_raw *r = NULL;
+ int len = 0;
+ int retval = -1;
+ retval = bundle_encode_raw(b, &r, &len);
+ if (retval == 0)
+ retval = __dp_interface_set_raw_bundle(id, DP_CMD_SET_NOTIFICATION_BUNDLE, type, r, len);
+ else {
+ bundle_free_encoded_rawdata(&r);
+ return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
+ }
+ bundle_free_encoded_rawdata(&r);
+ return retval;
+}
+
+int dp_interface_get_notification_bundle(const int id, int type, bundle **b)
+{
+ bundle_raw *r = NULL;
+ int len = 0;
+ download_adaptor_error_e error = DOWNLOAD_ADAPTOR_ERROR_NONE;
+
+ if (b == NULL) {
+ TRACE_ERROR("[CHECK bundle] (%d)", id);
+ return DOWNLOAD_ADAPTOR_ERROR_INVALID_PARAMETER;
+ }
+
+ error = __dp_interface_get_raw_bundle(id, DP_CMD_GET_NOTIFICATION_BUNDLE, type, &r, &len);
+ if (error == DOWNLOAD_ADAPTOR_ERROR_NONE) {
+ *b = bundle_decode_raw(r, len);
+ }
+ bundle_free_encoded_rawdata(&r);
+ return error;
+}
+
+int dp_interface_set_notification_title(const int id, const char *title)
+{
+ return __dp_interface_set_string(id, DP_CMD_SET_NOTIFICATION_TITLE, title);
+}
+
+int dp_interface_get_notification_title(const int id, char **title)
+{
+ return __dp_interface_get_string(id, DP_CMD_GET_NOTIFICATION_TITLE, title);
+}
+
+int dp_interface_set_notification_description(const int id, const char *description)
+{
+ return __dp_interface_set_string(id, DP_CMD_SET_NOTIFICATION_DESCRIPTION, description);
+}
+
+int dp_interface_get_notification_description(const int id, char **description)
+{
+ return __dp_interface_get_string(id, DP_CMD_GET_NOTIFICATION_DESCRIPTION, description);
+}
+
+int dp_interface_set_notification_type(const int id, int type)
+{
+ return __dp_interface_set_int(id, DP_CMD_SET_NOTIFICATION_TYPE, type);
+}
+
+int dp_interface_get_notification_type(const int id, int *type)
+{
+ return __dp_interface_get_int(id, DP_CMD_GET_NOTIFICATION_TYPE, type);
+}
#endif
#include <tizen.h>
+#include <bundle.h>
#ifdef __cplusplus
extern "C"
DOWNLOAD_ADAPTOR_ERROR_CONNECTION_TIMED_OUT = TIZEN_ERROR_CONNECTION_TIME_OUT, /**< Http session time-out */
DOWNLOAD_ADAPTOR_ERROR_NO_SPACE = TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE, /**< No space left on device */
DOWNLOAD_ADAPTOR_ERROR_FIELD_NOT_FOUND = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Specified field not found */
+ DOWNLOAD_ADAPTOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
DOWNLOAD_ADAPTOR_ERROR_INVALID_STATE = TIZEN_ERROR_WEB_CLASS | 0x21, /**< Invalid state */
DOWNLOAD_ADAPTOR_ERROR_CONNECTION_FAILED = TIZEN_ERROR_WEB_CLASS | 0x22, /**< Connection failed */
DOWNLOAD_ADAPTOR_ERROR_INVALID_URL = TIZEN_ERROR_WEB_CLASS | 0x24, /**< Invalid URL */
DOWNLOAD_ADAPTOR_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data because the set API is not called */
DOWNLOAD_ADAPTOR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR , /**< Internal I/O error */
} download_adaptor_error_e;
-// sync with url-download
-
// sync types with url-download..
typedef void (*dp_interface_state_changed_cb) (int id, int state, void *user_data);
EXPORT_API int dp_interface_get_noti_extra_values(const int id, const char *key, char ***values, unsigned *length);
EXPORT_API int dp_interface_remove_noti_extra_key(const int id, const char *key);
+EXPORT_API int dp_interface_set_notification_bundle(const int id, int type, bundle *b);
+EXPORT_API int dp_interface_get_notification_bundle(const int id, int type, bundle **b);
+EXPORT_API int dp_interface_set_notification_title(const int id, const char *title);
+EXPORT_API int dp_interface_get_notification_title(const int id, char **title);
+EXPORT_API int dp_interface_set_notification_description(const int id, const char *description);
+EXPORT_API int dp_interface_get_notification_description(const int id, char **description);
+EXPORT_API int dp_interface_set_notification_type(const int id, int type);
+EXPORT_API int dp_interface_get_notification_type(const int id, int *type);
#ifdef __cplusplus
}
#endif
pkg_check_modules(dp2_pkgs REQUIRED glib-2.0
gobject-2.0
- db-util
sqlite3
capi-appfw-app-manager
capi-network-connection
wifi-direct
notification
appsvc
- dbus-1
bundle
- dlog)
+ libsmack
+ dlog
+ libsystemd-daemon)
FOREACH(flag ${dp2_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
${GOBJECT-2_LIBRARIES}
pthread
capi-appfw-app-manager
- downloadagent2
)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
ADD_DEFINITIONS(-DDATABASE_FILE=\"${DATABASE_FILE}\")
ENDIF(DEFINED DATABASE_FILE)
+IF(DEFINED DATABASE_SCHEMA_FILE)
+ ADD_DEFINITIONS(-DDATABASE_SCHEMA_FILE=\"${DATABASE_SCHEMA_FILE}\")
+ENDIF(DEFINED DATABASE_SCHEMA_FILE)
+
IF(DEFINED IMAGE_DIR)
ADD_DEFINITIONS(-DIMAGE_DIR=\"${IMAGE_DIR}\")
ENDIF(DEFINED IMAGE_DIR)
+IF(DEFINED LOCALE_DIR)
+ ADD_DEFINITIONS(-DPKG_NAME=\"${PKG_NAME}\")
+ ADD_DEFINITIONS(-DLOCALE_DIR=\"${LOCALE_DIR}\")
+ENDIF(DEFINED LOCALE_DIR)
+
+
ADD_EXECUTABLE(${PROJECT_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/download-provider-pid.c
${CMAKE_CURRENT_SOURCE_DIR}/download-provider-socket.c
${CMAKE_CURRENT_SOURCE_DIR}/download-provider-thread-queue.c
${CMAKE_CURRENT_SOURCE_DIR}/download-provider-notification.c
${CMAKE_CURRENT_SOURCE_DIR}/download-provider-main.c )
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${dp2_pkgs_LDFLAGS} ${DP2_LINK_LIBRARIES})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${dp2_pkgs_LDFLAGS} ${DP2_LINK_LIBRARIES} -ldl)
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BIN_INSTALL_DIR})
INSTALL(FILES include/download-provider-defs.h DESTINATION ${INCLUDE_INSTALL_DIR}/${PKG_NAME})
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
+#include <string.h>
+#include <dlfcn.h> // dlopen
+#include <sys/smack.h>
#include "download-provider.h"
#include "download-provider-log.h"
#include "download-provider-pthread.h"
#include "download-provider-queue.h"
#include "download-provider-notification.h"
#include "download-provider-request.h"
+#include "download-provider-network.h"
+#include "download-provider-da-interface.h"
#include "download-agent-defs.h"
#include "download-agent-interface.h"
+#define DP_SDCARD_MNT_POINT "/opt/storage/sdcard"
+
+static void *g_da_handle = NULL;
+static int (*download_agent_init)(da_client_cb_t *) = NULL; // int da_init(da_client_cb_t *da_client_callback);
+static int (*download_agent_deinit)() = NULL; // int da_deinit();
+static int (*download_agent_is_alive)(int) = NULL; // int da_is_valid_download_id(int download_id);
+static int (*download_agent_suspend)(int) = NULL; // int da_suspend_download(int download_id);
+static int (*download_agent_resume)(int) = NULL; // int da_resume_download(int download_id);
+static int (*download_agent_cancel)(int) = NULL; // int da_cancel_download(int download_id);
+static int (*download_agent_start)(const char *, extension_data_t *, int *) = NULL; // int da_start_download_with_extension(const char *url, extension_data_t *ext_data, int *download_id);
+
+
int dp_is_file_exist(const char *file_path)
{
struct stat file_state;
return ;
}
dp_request_slots *request_slot = (dp_request_slots *) user_data;
- if (request_slot == NULL || request_slot->request == NULL) {
+ if (request_slot == NULL) {
+ TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+ return ;
+ }
+ CLIENT_MUTEX_LOCK(&request_slot->mutex);
+ if (request_slot->request == NULL) {
TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
return ;
}
dp_request *request = request_slot->request;
if (request->id < 0 || (request->agent_id != info->download_id)) {
TRACE_ERROR("[NULL-CHECK] agent_id : %d req_id %d",
request->agent_id, info->download_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
return ;
}
int request_id = request->id;
// update info before sending event
- if (info->tmp_saved_path) {
- TRACE_INFO("[STARTED][%d] [%s]", request_id, info->tmp_saved_path);
- if (dp_db_replace_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO,
- DP_DB_COL_TMP_SAVED_PATH, DP_DB_COL_TYPE_TEXT,
- info->tmp_saved_path) == 0) {
- if (info->file_type) {
- TRACE_INFO("[MIME-TYPE][%d] [%s]", request_id, info->file_type);
- if (dp_db_set_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO,
- DP_DB_COL_MIMETYPE, DP_DB_COL_TYPE_TEXT,
- info->file_type) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
- }
-
- if (info->file_size > 0) {
- TRACE_INFO
- ("[FILE-SIZE][%d] [%lld]", request_id, info->file_size);
- CLIENT_MUTEX_LOCK(&request->mutex);
- request->file_size = info->file_size;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- if (dp_db_set_column
- (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
- DP_DB_COL_CONTENT_SIZE,
- DP_DB_COL_TYPE_INT64, &info->file_size) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
- }
+ if (info->tmp_saved_path != NULL) {
+
+ TRACE_SECURE_DEBUG("[STARTED][%d] [%s]", request_id, info->tmp_saved_path);
+ int conds_count = 6; // id + tmp_saved_path + file_size + content_name + etag
+ int conds_index = 0;
+ db_conds_list_fmt conds_p[conds_count];
+ memset(&conds_p, 0x00, conds_count * sizeof(db_conds_list_fmt));
+
+ conds_p[conds_index].column = DP_DB_COL_TMP_SAVED_PATH;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[conds_index].value = info->tmp_saved_path;
+ conds_index++;
+ if (info->file_type != NULL) {
+ conds_p[conds_index].column = DP_DB_COL_MIMETYPE;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[conds_index].value = info->file_type;
+ conds_index++;
+ }
+ if (info->content_name != NULL) {
+ conds_p[conds_index].column = DP_DB_COL_CONTENT_NAME;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[conds_index].value = info->content_name;
+ conds_index++;
+ }
+ if (info->etag != NULL) {
+ conds_p[conds_index].column = DP_DB_COL_ETAG;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[conds_index].value = info->etag;
+ conds_index++;
+ }
+ if (info->file_size > 0) {
+ request->file_size = info->file_size;
+ conds_p[conds_index].column = DP_DB_COL_CONTENT_SIZE;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_INT64;
+ conds_p[conds_index].value = &info->file_size;
+ conds_index++;
+ }
- if (info->content_name) {
- TRACE_INFO
- ("[CONTENTNAME][%d] [%s]", request_id, info->content_name);
- if (dp_db_set_column
- (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
- DP_DB_COL_CONTENT_NAME,
- DP_DB_COL_TYPE_TEXT, info->content_name) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+ int check_id = dp_db_get_int_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_ID);
+ if (check_id == request_id) { // update
+ if (dp_db_update_columns(request_id, DP_DB_TABLE_DOWNLOAD_INFO, conds_index, conds_p) < 0) {
+ if (dp_db_is_full_error() == 0) {
+ request->error = DP_ERROR_NO_SPACE;
+ TRACE_ERROR("[SQLITE_FULL][%d]", request_id);
+ if (dp_cancel_agent_download(request->agent_id) < 0)
+ TRACE_ERROR("[fail][%d]cancel_agent", request_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+ return ;
+ }
}
- if (info->etag) {
- TRACE_INFO("[ETAG][%d] [%s]", request_id, info->etag);
- if (dp_db_replace_column
- (request_id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_ETAG,
- DP_DB_COL_TYPE_TEXT, info->etag) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+ } else { // insert
+ conds_p[conds_index].column = DP_DB_COL_ID;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_INT;
+ conds_p[conds_index].value = &request_id;
+ conds_index++;
+ if (dp_db_insert_columns(DP_DB_TABLE_DOWNLOAD_INFO, conds_index, conds_p) < 0) {
+ if (dp_db_is_full_error() == 0) {
+ request->error = DP_ERROR_NO_SPACE;
+ TRACE_ERROR("[SQLITE_FULL][%d]", request_id);
+ if (dp_cancel_agent_download(request->agent_id) < 0)
+ TRACE_ERROR("[fail][%d]cancel_agent", request_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+ return ;
+ }
}
- } else {
- TRACE_ERROR
- ("[ERROR][%d][SQL] failed to insert downloadinfo",
- request_id);
}
- }
- CLIENT_MUTEX_LOCK(&request->mutex);
+ }
+ request->ip_changed = 0;
request->state = DP_STATE_DOWNLOADING;
- if (dp_db_set_column(request->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &request->state) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request->id);
-
- if (request->group && request->group->event_socket >= 0 &&
- request->state_cb)
- dp_ipc_send_event(request->group->event_socket,
- request->id, DP_STATE_DOWNLOADING, DP_ERROR_NONE, 0);
+ request->error = DP_ERROR_NONE;
+ dp_request_state_response(request);
- if (request->auto_notification)
- request->noti_priv_id =
- dp_set_downloadinginfo_notification
- (request->id, request->packagename);
-
- CLIENT_MUTEX_UNLOCK(&request->mutex);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
}
static void __progress_cb(user_progress_info_t *info, void *user_data)
return ;
}
dp_request_slots *request_slot = (dp_request_slots *) user_data;
- if (request_slot == NULL || request_slot->request == NULL) {
+ if (request_slot == NULL) {
TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
return ;
}
+ CLIENT_MUTEX_LOCK(&request_slot->mutex);
+ if (request_slot->request == NULL) {
+ TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+ return ;
+ }
dp_request *request = request_slot->request;
if (request->id < 0 || (request->agent_id != info->download_id)) {
TRACE_ERROR("[NULL-CHECK] agent_id : %d req_id %d",
request->agent_id, info->download_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
return ;
}
- CLIENT_MUTEX_LOCK(&request->mutex);
if (request->state == DP_STATE_DOWNLOADING) {
request->received_size = info->received_size;
time_t tt = time(NULL);
// send event every 1 second.
if (request->progress_lasttime != localTime->tm_sec) {
request->progress_lasttime = localTime->tm_sec;
- if (request->progress_cb && request->group &&
- request->group->event_socket >= 0 &&
- request->received_size > 0)
- dp_ipc_send_event(request->group->event_socket,
- request->id, request->state, request->error,
- request->received_size);
- if (request->auto_notification)
+ if (request->auto_notification) {
dp_update_downloadinginfo_notification
(request->noti_priv_id,
(double)request->received_size,
(double)request->file_size);
+ } else {
+ int noti_type = dp_db_get_int_column(request->id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+ if(noti_type == DP_NOTIFICATION_TYPE_ALL)
+ dp_update_downloadinginfo_notification
+ (request->noti_priv_id,
+ (double)request->received_size,
+ (double)request->file_size);
+ }
+
+ if (request->progress_cb && request->group != NULL &&
+ request->group->event_socket >= 0 &&
+ request->received_size > 0)
+ dp_ipc_send_event(request->group->event_socket,
+ request->id, request->state, request->error,
+ request->received_size);
}
}
- CLIENT_MUTEX_UNLOCK(&request->mutex);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+}
+
+static int __is_transmute_smack(char *path)
+{
+ char *dir_label = NULL;
+ int ret = -1;
+ if (smack_getlabel(path, &dir_label, SMACK_LABEL_TRANSMUTE) == 0 &&
+ dir_label != NULL) {
+ if (strncmp(dir_label, "TRUE", strlen(dir_label)) == 0)
+ ret = 0;
+ }
+ free(dir_label);
+ return ret;
+}
+
+static dp_error_type __set_dir_smack_label(char *smack_label, char *dir_path, char *saved_path)
+{
+ if (smack_label == NULL || dir_path== NULL || saved_path == NULL)
+ return DP_ERROR_PERMISSION_DENIED;
+
+ int is_setted_dir_label = 0;
+ dp_error_type errorcode = DP_ERROR_NONE;
+
+ TRACE_SECURE_INFO("[PARSE] dir path [%s]", dir_path);
+ if (__is_transmute_smack(dir_path) < 0) {
+ TRACE_DEBUG("[SMACK] no transmute");
+ } else {
+ char *dir_label = NULL;
+ if (smack_getlabel(dir_path, &dir_label,
+ SMACK_LABEL_ACCESS) == 0) {
+ if (smack_have_access(smack_label, dir_label, "t") > 0) {
+ if (smack_setlabel(saved_path, dir_label,
+ SMACK_LABEL_ACCESS) != 0) {
+ TRACE_SECURE_ERROR("[SMACK ERROR] label:%s",
+ dir_label);
+ errorcode = DP_ERROR_PERMISSION_DENIED;
+ } else {
+ is_setted_dir_label = 1;
+ }
+ } else {
+ TRACE_SECURE_ERROR("[SMACK ERROR] access:%s/%s",
+ smack_label, dir_label);
+ errorcode = DP_ERROR_PERMISSION_DENIED;
+ }
+ } else {
+ TRACE_SECURE_ERROR("[SMACK ERROR] no label:", dir_path);
+ errorcode = DP_ERROR_PERMISSION_DENIED;
+ }
+ free(dir_label);
+ }
+ if (is_setted_dir_label == 0 &&
+ smack_setlabel(saved_path, smack_label,
+ SMACK_LABEL_ACCESS) != 0) {
+ TRACE_SECURE_ERROR("[SMACK ERROR] label:%s", smack_label);
+ errorcode = DP_ERROR_PERMISSION_DENIED;
+ // remove file.
+ if (dp_is_file_exist(saved_path) == 0)
+ unlink(saved_path);
+ }
+ return errorcode;
+}
+
+static dp_error_type __set_file_permission_to_client(dp_request *request, char *saved_path)
+{
+ dp_error_type errorcode = DP_ERROR_NONE;
+ char *str = NULL;
+ char *smack_label = NULL;
+ str = strrchr(saved_path, '/');
+ dp_credential cred;
+ if (request->group == NULL) {
+ cred.uid = dp_db_cond_get_int(DP_DB_TABLE_GROUPS,
+ DP_DB_GROUPS_COL_UID,
+ DP_DB_GROUPS_COL_PKG,
+ DP_DB_COL_TYPE_TEXT, request->packagename);
+ cred.gid = dp_db_cond_get_int(DP_DB_TABLE_GROUPS,
+ DP_DB_GROUPS_COL_GID,
+ DP_DB_GROUPS_COL_PKG,
+ DP_DB_COL_TYPE_TEXT, request->packagename);
+ } else {
+ cred = request->group->credential;
+ }
+ TRACE_DEBUG
+ ("[chown][%d] [%d][%d]", request->id, cred.uid, cred.gid);
+ if (chown(saved_path, cred.uid, cred.gid) < 0)
+ TRACE_STRERROR("[ERROR][%d] chown", request->id);
+ if (chmod(saved_path,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0)
+ TRACE_STRERROR("[ERROR][%d] chmod", request->id);
+ if (dp_is_smackfs_mounted() == 1) {
+ if (request->group == NULL) {
+ // get smack_label from sql
+ smack_label =
+ dp_db_cond_get_text(DP_DB_TABLE_GROUPS,
+ DP_DB_GROUPS_COL_SMACK_LABEL,
+ DP_DB_GROUPS_COL_PKG,
+ DP_DB_COL_TYPE_TEXT, request->packagename);
+ } else {
+ smack_label = dp_strdup(request->group->smack_label);
+ }
+ if (smack_label == NULL) {
+ TRACE_SECURE_ERROR("[SMACK][%d] no label", request->id);
+ errorcode = DP_ERROR_PERMISSION_DENIED;
+ } else {
+ size_t len = str - (saved_path);
+ char *dir_path = (char *)calloc(len + 1, sizeof(char));
+ if (dir_path != NULL) {
+ strncpy(dir_path, saved_path, len);
+ errorcode =
+ __set_dir_smack_label(smack_label, dir_path,
+ saved_path);
+ free(dir_path);
+ } else {
+ TRACE_SECURE_ERROR("[ERROR] calloc");
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ }
+ free(smack_label);
+ }
+ }
+ return errorcode;
}
static void __finished_cb(user_finished_info_t *info, void *user_data)
TRACE_ERROR("[NULL-CHECK] Agent info");
return ;
}
- TRACE_INFO("Agent ID[%d] err[%d] http_status[%d]",
- info->download_id, info->err, info->http_status);
dp_request_slots *request_slot = (dp_request_slots *) user_data;
- if (request_slot == NULL || request_slot->request == NULL) {
+ if (request_slot == NULL) {
TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
return ;
}
+ CLIENT_MUTEX_LOCK(&request_slot->mutex);
+ if (request_slot->request == NULL) {
+ TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+ return ;
+ }
dp_request *request = request_slot->request;
if (request->id < 0 || (request->agent_id != info->download_id)) {
TRACE_ERROR("[NULL-CHECK] agent_id : %d req_id %d",
request->agent_id, info->download_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
return ;
}
- CLIENT_MUTEX_LOCK(&request->mutex);
-
int request_id = request->id;
- dp_credential cred = request->credential;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
dp_state_type state = DP_STATE_NONE;
dp_error_type errorcode = DP_ERROR_NONE;
- // update info before sending event
- if (dp_db_update_date
- (request_id, DP_DB_TABLE_LOG, DP_DB_COL_ACCESS_TIME) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
-
if (info->http_status > 0)
if (dp_db_replace_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO,
DP_DB_COL_HTTP_STATUS,
TRACE_ERROR("[ERROR][%d][SQL]", request_id);
if (info->err == DA_RESULT_OK) {
- if (info->saved_path) {
- char *str = NULL;
- char *content_name = NULL;
+ int conds_count = 5; // id + saved_path + content_name + http_status + file_size
+ int conds_index = 0;
+ db_conds_list_fmt conds_p[conds_count];
+ memset(&conds_p, 0x00, conds_count * sizeof(db_conds_list_fmt));
+
+ char *content_name = NULL;
+ if (info->saved_path != NULL) {
+ char *str = NULL;
+ if(!(strncmp(DP_SDCARD_MNT_POINT, info->saved_path,
+ strlen(DP_SDCARD_MNT_POINT)) == 0)) {
+ errorcode = __set_file_permission_to_client(request,
+ info->saved_path);
+ }
str = strrchr(info->saved_path, '/');
- if (str) {
+ if (str != NULL) {
str++;
content_name = dp_strdup(str);
- TRACE_INFO("[PARSE][%d] content_name [%s]",
+ TRACE_SECURE_DEBUG("[PARSE][%d] content_name [%s]",
request_id, content_name);
}
- TRACE_INFO
- ("[chown][%d] [%d][%d]", request_id, cred.uid, cred.gid);
- if (chown(info->saved_path, cred.uid, cred.gid) < 0)
- TRACE_STRERROR("[ERROR][%d] chown", request_id);
- if (dp_db_replace_column
- (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
- DP_DB_COL_SAVED_PATH,
- DP_DB_COL_TYPE_TEXT, info->saved_path) == 0) {
- if (content_name != NULL) {
- if (dp_db_set_column
- (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
- DP_DB_COL_CONTENT_NAME,
- DP_DB_COL_TYPE_TEXT, content_name) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
- }
- } else {
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
- }
- if (content_name != NULL)
- free(content_name);
- errorcode = DP_ERROR_NONE;
- state = DP_STATE_COMPLETED;
+ conds_p[conds_index].column = DP_DB_COL_SAVED_PATH;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[conds_index].value = info->saved_path;
+ conds_index++;
+ if (content_name != NULL) {
+ conds_p[conds_index].column = DP_DB_COL_CONTENT_NAME;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[conds_index].value = content_name;
+ conds_index++;
+ }
- TRACE_INFO("[COMPLETED][%d] saved to [%s]",
+ if (errorcode == DP_ERROR_NONE) {
+ state = DP_STATE_COMPLETED;
+ TRACE_SECURE_INFO("[COMPLETED][%d] saved to [%s]",
+ request_id, info->saved_path);
+ } else {
+ state = DP_STATE_FAILED;
+ TRACE_SECURE_INFO("[FAILED][%d] saved to [%s]",
request_id, info->saved_path);
+ }
} else {
TRACE_ERROR("Cannot enter here");
TRACE_ERROR("[ERROR][%d] No SavedPath", request_id);
errorcode = DP_ERROR_INVALID_DESTINATION;
state = DP_STATE_FAILED;
}
- CLIENT_MUTEX_LOCK(&request->mutex);
if (request->file_size == 0) {
request->file_size = request->received_size;
- if (dp_db_replace_column
- (request_id, DP_DB_TABLE_DOWNLOAD_INFO,
- DP_DB_COL_CONTENT_SIZE,
- DP_DB_COL_TYPE_INT64, &request->file_size ) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+ conds_p[conds_index].column = DP_DB_COL_CONTENT_SIZE;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_INT64;
+ conds_p[conds_index].value = &request->file_size;
+ conds_index++;
+ }
+
+ int check_id = dp_db_get_int_column(request_id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_ID);
+ if (check_id == request_id) { // update
+ if (dp_db_update_columns(request_id, DP_DB_TABLE_DOWNLOAD_INFO, conds_index, conds_p) < 0) {
+ if (dp_db_is_full_error() == 0) {
+ request->error = DP_ERROR_NO_SPACE;
+ TRACE_ERROR("[SQLITE_FULL][%d]", request_id);
+ if (dp_cancel_agent_download(request->agent_id) < 0)
+ TRACE_ERROR("[fail][%d]cancel_agent", request_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+ return ;
+ }
+ }
+ } else { // insert
+ conds_p[conds_index].column = DP_DB_COL_ID;
+ conds_p[conds_index].type = DP_DB_COL_TYPE_INT;
+ conds_p[conds_index].value = &request_id;
+ conds_index++;
+ if (dp_db_insert_columns(DP_DB_TABLE_DOWNLOAD_INFO, conds_index, conds_p) < 0) {
+ if (dp_db_is_full_error() == 0) {
+ request->error = DP_ERROR_NO_SPACE;
+ TRACE_ERROR("[SQLITE_FULL][%d]", request_id);
+ if (dp_cancel_agent_download(request->agent_id) < 0)
+ TRACE_ERROR("[fail][%d]cancel_agent", request_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+ return ;
+ }
+ }
}
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- } else if (info->err == DA_RESULT_USER_CANCELED) {
- state = DP_STATE_CANCELED;
- errorcode = DP_ERROR_NONE;
- TRACE_INFO("[CANCELED][%d]", request_id);
+ free(content_name);
} else {
- state = DP_STATE_FAILED;
- errorcode = __change_error(info->err);
- TRACE_INFO("[FAILED][%d][%s]", request_id,
- dp_print_errorcode(errorcode));
- }
+ char *tmp_saved_path =
+ dp_request_get_tmpsavedpath(request_id, request, &errorcode);
- if (dp_db_set_column
- (request_id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &state) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+ if (tmp_saved_path != NULL) {
+ errorcode = __set_file_permission_to_client(request, tmp_saved_path);
+ free(tmp_saved_path);
+ } else {
+ TRACE_ERROR("Cannot enter here");
+ TRACE_ERROR("[ERROR][%d] No SavedPath", request_id);
+ }
- if (errorcode != DP_ERROR_NONE) {
- if (dp_db_set_column(request_id, DP_DB_TABLE_LOG,
- DP_DB_COL_ERRORCODE, DP_DB_COL_TYPE_INT,
- &errorcode) < 0)
- TRACE_ERROR("[ERROR][%d][SQL]", request_id);
+ if (info->err == DA_RESULT_USER_CANCELED) {
+ state = DP_STATE_CANCELED;
+ errorcode = request->error;
+ TRACE_INFO("[CANCELED][%d]", request_id);
+ } else {
+ state = DP_STATE_FAILED;
+ errorcode = __change_error(info->err);
+ TRACE_ERROR("[FAILED][%d][%s]", request_id,
+ dp_print_errorcode(errorcode));
+ }
}
- // need MUTEX LOCK
- CLIENT_MUTEX_LOCK(&request->mutex);
-
request->state = state;
request->error = errorcode;
- // stay on memory till called destroy by client or timeout
- if (request->group != NULL && request->group->event_socket >= 0) {
- /* update the received file size.
- * The last received file size cannot update
- * because of reducing update algorithm*/
- if (request->received_size > 0)
- dp_ipc_send_event(request->group->event_socket,
- request->id, DP_STATE_DOWNLOADING, request->error,
- request->received_size);
- if (request->state_cb)
- dp_ipc_send_event(request->group->event_socket,
- request->id, request->state, request->error, 0);
- request->group->queued_count--;
+ // auto resume when failed by ip_changed.
+ if (state == DP_STATE_FAILED && info->err == DA_ERR_NETWORK_FAIL &&
+ request->network_type != DP_NETWORK_TYPE_WIFI_DIRECT) {
+ if (request->ip_changed == 1 &&
+ dp_get_network_connection_instant_status() !=
+ DP_NETWORK_TYPE_OFF) {
+ // resume
+ TRACE_DEBUG("[RESUME][%d] will be queued", request_id);
+ request->state = DP_STATE_QUEUED;
+ request->error = DP_ERROR_NONE;
+ } else {
+ TRACE_DEBUG("[CHECK][%d] check again in timeout", request_id);
+ }
+ } else {
+ // stay on memory till called destroy by client or timeout
+ if (request->group != NULL &&
+ request->group->event_socket >= 0) {
+ /* update the received file size.
+ * The last received file size cannot update
+ * because of reducing update algorithm*/
+ if (request->received_size > 0) {
+ dp_ipc_send_event(request->group->event_socket,
+ request->id, DP_STATE_DOWNLOADING, request->error,
+ request->received_size);
+ }
+ }
+ dp_request_state_response(request);
}
- // to prevent the crash . check packagename of request
- if (request->auto_notification && request->packagename != NULL)
- request->noti_priv_id =
- dp_set_downloadedinfo_notification(request->noti_priv_id,
- request->id, request->packagename, request->state);
-
- request->stop_time = (int)time(NULL);
-
- CLIENT_MUTEX_UNLOCK(&request->mutex);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
dp_thread_queue_manager_wake_up();
}
static void __paused_cb(user_paused_info_t *info, void *user_data)
{
- TRACE_INFO("");
dp_request_slots *request_slot = (dp_request_slots *) user_data;
- if (request_slot == NULL || request_slot->request == NULL) {
+ if (request_slot == NULL) {
+ TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+ return ;
+ }
+ CLIENT_MUTEX_LOCK(&request_slot->mutex);
+ if (request_slot->request == NULL) {
TRACE_ERROR("[NULL-CHECK] request req_id:%d", info->download_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
return ;
}
dp_request *request = request_slot->request;
if (request->id < 0 || (request->agent_id != info->download_id)) {
TRACE_ERROR("[NULL-CHECK] agent_id : %d req_id %d",
request->agent_id, info->download_id);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+ return ;
+ }
+
+ if (request->state != DP_STATE_PAUSE_REQUESTED) {
+ TRACE_ERROR("[CHECK] now status:%d", request->state);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
return ;
}
- CLIENT_MUTEX_LOCK(&request->mutex);
int request_id = request->id;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
if (dp_db_update_date
(request_id, DP_DB_TABLE_LOG, DP_DB_COL_ACCESS_TIME) < 0)
TRACE_ERROR("[ERROR][%d][SQL]", request_id);
- // need MUTEX LOCK
- CLIENT_MUTEX_LOCK(&request->mutex);
-
request->state = DP_STATE_PAUSED;
+ request->error = DP_ERROR_NONE;
+ dp_request_state_response(request);
- if (dp_db_set_column
- (request->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &request->state) < 0) {
- TRACE_ERROR("[ERROR][%d][SQL]", request->id);
- }
-
- if (request->group &&
- request->group->event_socket >= 0 && request->state_cb)
- dp_ipc_send_event(request->group->event_socket,
- request->id, request->state, request->error, 0);
-
- if (request->group)
- request->group->queued_count--;
-
- CLIENT_MUTEX_UNLOCK(&request->mutex);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
dp_thread_queue_manager_wake_up();
}
int dp_init_agent()
{
- int da_ret = 0;
+
+ g_da_handle = dlopen("/usr/lib/libdownloadagent2.so", RTLD_LAZY | RTLD_GLOBAL);
+ if (!g_da_handle) {
+ TRACE_ERROR("[dlopen] %s", dlerror());
+ g_da_handle = NULL;
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+ dlerror(); /* Clear any existing error */
+
+ *(void **) (&download_agent_init) = dlsym(g_da_handle, "da_init");
+ if (download_agent_init == NULL ) {
+ TRACE_ERROR("[dlsym] da_init:%s", dlerror());
+ dlclose(g_da_handle);
+ g_da_handle = NULL;
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ *(void **) (&download_agent_deinit) = dlsym(g_da_handle, "da_deinit");
+ if (download_agent_deinit == NULL ) {
+ TRACE_ERROR("[dlsym] da_deinit:%s", dlerror());
+ dlclose(g_da_handle);
+ g_da_handle = NULL;
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ *(void **) (&download_agent_is_alive) = dlsym(g_da_handle, "da_is_valid_download_id");
+ if (download_agent_is_alive == NULL ) {
+ TRACE_ERROR("[dlsym] da_is_valid_download_id:%s", dlerror());
+ dlclose(g_da_handle);
+ g_da_handle = NULL;
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ *(void **) (&download_agent_suspend) = dlsym(g_da_handle, "da_suspend_download");
+ if (download_agent_suspend == NULL ) {
+ TRACE_ERROR("[dlsym] da_suspend_download:%s", dlerror());
+ dlclose(g_da_handle);
+ g_da_handle = NULL;
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ *(void **) (&download_agent_resume) = dlsym(g_da_handle, "da_resume_download");
+ if (download_agent_resume == NULL ) {
+ TRACE_ERROR("[dlsym] da_resume_download:%s", dlerror());
+ dlclose(g_da_handle);
+ g_da_handle = NULL;
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ *(void **) (&download_agent_cancel) = dlsym(g_da_handle, "da_cancel_download");
+ if (download_agent_cancel == NULL ) {
+ TRACE_ERROR("[dlsym] da_cancel_download:%s", dlerror());
+ dlclose(g_da_handle);
+ g_da_handle = NULL;
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ *(void **) (&download_agent_start) = dlsym(g_da_handle, "da_start_download_with_extension");
+ if (download_agent_start == NULL ) {
+ TRACE_ERROR("[dlsym] da_start_download_with_extension:%s", dlerror());
+ dlclose(g_da_handle);
+ g_da_handle = NULL;
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ int da_ret = -1;
da_client_cb_t da_cb = {
__download_info_cb,
__progress_cb,
__finished_cb,
__paused_cb
};
- da_ret = da_init(&da_cb);
+ da_ret = (*download_agent_init)(&da_cb);
if (da_ret != DA_RESULT_OK) {
return DP_ERROR_OUT_OF_MEMORY;
}
void dp_deinit_agent()
{
- da_deinit();
+ if (g_da_handle != NULL) {
+ if (download_agent_deinit != NULL)
+ (*download_agent_deinit)();
+
+ dlclose(g_da_handle);
+ g_da_handle = NULL;
+ }
}
// 1 : alive
TRACE_ERROR("[NULL-CHECK] req_id");
return 0;
}
- da_ret = da_is_valid_download_id(req_id);
+ if (download_agent_is_alive != NULL)
+ da_ret = (*download_agent_is_alive)(req_id);
return da_ret;
}
TRACE_ERROR("[CHECK agent-id:%d] dead request", req_id);
return -1;
}
- if (da_cancel_download(req_id) == DA_RESULT_OK)
- return 0;
+ if (download_agent_cancel != NULL) {
+ if ((*download_agent_cancel)(req_id) == DA_RESULT_OK)
+ return 0;
+ }
return -1;
}
TRACE_ERROR("[CHECK agent-id:%d] dead request", req_id);
return -1;
}
- if (da_suspend_download(req_id) == DA_RESULT_OK)
- return 0;
+ if (download_agent_suspend != NULL) {
+ if ((*download_agent_suspend)(req_id) == DA_RESULT_OK)
+ return 0;
+ }
return -1;
}
extension_data_t ext_data = {0,};
char *etag = NULL;
- TRACE_INFO("");
- if (request_slot == NULL || request_slot->request == NULL) {
+ if (request_slot == NULL) {
TRACE_ERROR("[NULL-CHECK] download_clientinfo_slot");
return DP_ERROR_INVALID_PARAMETER;
}
+
+ if (request_slot->request == NULL) {
+ TRACE_ERROR("[NULL-CHECK] download_clientinfo_slot");
+ return DP_ERROR_INVALID_PARAMETER;
+ }
+
dp_request *request = request_slot->request;
- CLIENT_MUTEX_LOCK(&(request->mutex));
- char *url = dp_request_get_url(request->id, request, &errorcode);
+ char *url = dp_request_get_url(request->id, &errorcode);
if (url == NULL) {
TRACE_ERROR("[ERROR][%d] URL is NULL", request->id);
- CLIENT_MUTEX_UNLOCK(&(request->mutex));
return DP_ERROR_INVALID_URL;
}
char *destination =
if (tmp_saved_path) {
etag = dp_request_get_etag(request->id, request, &errorcode);
if (etag) {
- TRACE_INFO("[RESUME][%d]", request->id);
+ TRACE_DEBUG("[RESUME][%d]", request->id);
ext_data.etag = etag;
ext_data.temp_file_path = tmp_saved_path;
} else {
/* FIXME later : It is better to handle the unlink function in download agaent module
* or in upload the request data to memory after the download provider process is restarted */
- TRACE_INFO("[RESTART][%d] try to remove tmp file [%s]",
+ TRACE_SECURE_INFO("[RESTART][%d] try to remove tmp file [%s]",
request->id, tmp_saved_path);
if (dp_is_file_exist(tmp_saved_path) == 0)
if (unlink(tmp_saved_path) != 0)
("[ERROR][%d] remove file", request->id);
}
}
+ char *pkg_name = dp_request_get_pkg_name(request->id, request, &errorcode);
+ if (pkg_name != NULL)
+ ext_data.pkg_name = pkg_name;
// get headers list from httpheaders table(DB)
int headers_count = dp_db_get_cond_rows_count
(request->id, DP_DB_TABLE_HTTP_HEADERS, NULL, 0, NULL);
ext_data.user_data = (void *)request_slot;
// call start API of agent lib
- da_ret =
- da_start_download_with_extension(url, &ext_data, &req_dl_id);
+ if (download_agent_start != NULL)
+ da_ret = (*download_agent_start)(url, &ext_data, &req_dl_id);
if (ext_data.request_header_count > 0) {
int len = 0;
int i = 0;
free(tmp_saved_path);
if (etag)
free(etag);
+ if (pkg_name)
+ free(pkg_name);
// if start_download() return error cause of maximun download limitation,
// set state to DOWNLOAD_STATE_PENDED.
if (da_ret == DA_ERR_ALREADY_MAX_DOWNLOAD) {
- TRACE_INFO("[PENDING][%d] DA_ERR_ALREADY_MAX_DOWNLOAD [%d]",
+ TRACE_DEBUG("[PENDING][%d] DA_ERR_ALREADY_MAX_DOWNLOAD [%d]",
request->id, da_ret);
- CLIENT_MUTEX_UNLOCK(&(request->mutex));
return DP_ERROR_TOO_MANY_DOWNLOADS;
} else if (da_ret != DA_RESULT_OK) {
TRACE_ERROR("[ERROR][%d] DP_ERROR_CONNECTION_FAILED [%d]",
request->id, da_ret);
- CLIENT_MUTEX_UNLOCK(&(request->mutex));
return __change_error(da_ret);
}
- TRACE_INFO("[SUCCESS][%d] agent_id [%d]", request->id, req_dl_id);
+ TRACE_DEBUG("[SUCCESS][%d] agent_id [%d]", request->id, req_dl_id);
request->agent_id = req_dl_id;
- CLIENT_MUTEX_UNLOCK(&(request->mutex));
return DP_ERROR_NONE;
}
TRACE_ERROR("[NULL-CHECK] req_id");
return DP_ERROR_INVALID_PARAMETER;
}
- da_ret = da_resume_download(req_id);
+ if (download_agent_resume != NULL)
+ da_ret = (*download_agent_resume)(req_id);
if (da_ret == DA_RESULT_OK)
return DP_ERROR_NONE;
else if (da_ret == DA_ERR_INVALID_STATE)
* limitations under the License.
*/
-#include <db-util.h>
-
+#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <stdlib.h>
+#include <sqlite3.h>
+
#include "download-provider-config.h"
#include "download-provider-db.h"
#include "download-provider-slots.h"
} db_query_type;
sqlite3 *g_dp_db_handle = 0;
+sqlite3_stmt *g_dp_db_logging_new_stmt = NULL;
+sqlite3_stmt *g_dp_db_logging_status_stmt = NULL;
+sqlite3_stmt *g_dp_db_logging_get_state_stmt = NULL;
+
+static void __dp_finalize(sqlite3_stmt *stmt)
+{
+ if (sqlite3_finalize(stmt) != SQLITE_OK)
+ TRACE_ERROR("failed sqlite3_finalize [%s]",
+ sqlite3_errmsg(g_dp_db_handle));
+}
// called when terminating process
void dp_db_close()
{
if (g_dp_db_handle) {
+ if (g_dp_db_logging_new_stmt != NULL)
+ __dp_finalize(g_dp_db_logging_new_stmt);
+ if (g_dp_db_logging_status_stmt != NULL)
+ __dp_finalize(g_dp_db_logging_status_stmt);
sqlite3_exec(g_dp_db_handle, "VACUUM;", 0, 0, 0); // remove empty page of db
- db_util_close(g_dp_db_handle);
+ sqlite3_close(g_dp_db_handle);
}
g_dp_db_handle = 0;
}
+static void __load_sql_schema()
+{
+ char *rebuild_query =
+ sqlite3_mprintf("sqlite3 %s '.read %s'", DATABASE_FILE, DATABASE_SCHEMA_FILE);
+ if (rebuild_query != NULL) {
+ TRACE_SECURE_INFO("[QUERY] %s", rebuild_query);
+ system(rebuild_query);
+ sqlite3_free(rebuild_query);
+ }
+}
+
+static int __dp_sql_open()
+{
+ return dp_db_open();
+}
+
+static int __check_table(char *table)
+{
+ //"SELECT name FROM sqlite_master WHERE type='table' AND name='" + table +"'";
+ sqlite3_stmt *stmt = NULL;
+
+ if (table == NULL) {
+ TRACE_ERROR("[CHECK TABLE NAME]");
+ return -1;
+ }
+
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+
+ char *query = sqlite3_mprintf("SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", table);
+ if (query == NULL) {
+ TRACE_ERROR("[CHECK COMBINE]");
+ return -1;
+ }
+
+ int ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
+ sqlite3_free(query);
+ if (ret != SQLITE_OK) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
+ if (sqlite3_step(stmt) == SQLITE_ROW) {
+ __dp_finalize(stmt);
+ return 1;
+ }
+ __dp_finalize(stmt);
+ return 0;
+}
+
// called when launching process or in every API
int dp_db_open()
{
if (g_dp_db_handle == 0) {
- if (db_util_open(DATABASE_FILE, &g_dp_db_handle,
- DB_UTIL_REGISTER_HOOK_METHOD) != SQLITE_OK) {
- TRACE_ERROR("failed db_util_open [%s][%s]", DATABASE_FILE,
+ TRACE_SECURE_INFO("TRY to open [%s]", DATABASE_FILE);
+ if (sqlite3_open_v2(DATABASE_FILE, &g_dp_db_handle,
+ SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK) {
+ TRACE_ERROR("[ERROR][%s][%s]", DATABASE_FILE,
sqlite3_errmsg(g_dp_db_handle));
+ int errorcode = sqlite3_errcode(g_dp_db_handle);
dp_db_close();
+ if (errorcode == SQLITE_CORRUPT) {
+ TRACE_SECURE_INFO("unlink [%s]", DATABASE_FILE);
+ unlink(DATABASE_FILE);
+ errorcode = SQLITE_CANTOPEN;
+ }
+ if (errorcode == SQLITE_CANTOPEN) {
+ __load_sql_schema();
+ return dp_db_open();
+ }
return -1;
}
sqlite3_exec(g_dp_db_handle, "PRAGMA journal_mode=PERSIST;", 0, 0, 0);
sqlite3_exec(g_dp_db_handle, "PRAGMA foreign_keys=ON;", 0, 0, 0);
+
+ // if not found group table. load again. (FOTA)
+ // new table(groups) created by smack_label. 2013.07.09
+ if (__check_table(DP_DB_TABLE_GROUPS) == 0)
+ __load_sql_schema();
}
return g_dp_db_handle ? 0 : -1;
}
-static int __dp_sql_open()
-{
- return dp_db_open();
-}
-
-static void __dp_finalize(sqlite3_stmt *stmt)
+int dp_db_is_full_error()
{
- if (sqlite3_finalize(stmt) != SQLITE_OK)
- TRACE_ERROR("failed sqlite3_finalize [%s]",
- sqlite3_errmsg(g_dp_db_handle));
+ if (g_dp_db_handle == 0) {
+ TRACE_ERROR("HANDLE is null");
+ return -1;
+ }
+ if (sqlite3_errcode(g_dp_db_handle) == SQLITE_FULL)
+ return 0;
+ return -1;
}
int dp_db_get_count_by_limit_time()
requests[i].request->id = sqlite3_column_int(stmt, 0);
// state
requests[i].request->state = sqlite3_column_int(stmt, 1);
-
- TRACE_INFO("ID : %d", requests[i].request->id);
- TRACE_INFO("state : %d", requests[i].request->state);
i++;
}
requests[i].request->packagename[buffer_length] = '\0';
}
}
-
- TRACE_INFO("ID : %d", requests[i].request->id);
- TRACE_INFO("state : %d", requests[i].request->state);
- TRACE_INFO("packagename : %s", requests[i].request->packagename);
i++;
}
return NULL;
}
- TRACE_INFO("[QUERY] %s", query);
-
ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
sqlite3_free(query);
if ( ret != SQLITE_OK) {
return -1;
}
+int dp_db_insert_blob_column(int id, char *table, char *column,
+ void *value, unsigned length)
+{
+ sqlite3_stmt *stmt = NULL;
+
+ if (id <= 0) {
+ TRACE_ERROR("[CHECK ID]");
+ return -1;
+ }
+
+ if (!table) {
+ TRACE_ERROR("[CHECK TABLE NAME]");
+ return -1;
+ }
+
+ if (!column) {
+ TRACE_ERROR("[CHECK COLUMN NAME]");
+ return -1;
+ }
+
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+
+ stmt = __prepare_query
+ (g_dp_db_handle, DP_DB_QUERY_TYPE_INSERT, table, column);
+ if (stmt == NULL) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+
+ int errorcode = SQLITE_OK;
+ errorcode = sqlite3_bind_blob(stmt, 2, value, (int)length, NULL);
+
+ if (errorcode != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
+
+ // VALUES ( id )
+ if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
+
+ errorcode = sqlite3_step(stmt);
+ if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+ __dp_finalize(stmt);
+ return 0;
+ }
+ TRACE_ERROR("[SQL] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+}
+
int dp_db_set_column(int id, char *table, char *column,
db_column_data_type datatype, void *value)
{
return -1;
}
+int dp_db_set_blob_column(int id, char *table, char *column,
+ void *value, unsigned length)
+{
+ sqlite3_stmt *stmt = NULL;
+
+ if (id <= 0) {
+ TRACE_ERROR("[CHECK ID]");
+ return -1;
+ }
+
+ if (!table) {
+ TRACE_ERROR("[CHECK TABLE NAME]");
+ return -1;
+ }
+
+ if (!column) {
+ TRACE_ERROR("[CHECK COLUMN NAME]");
+ return -1;
+ }
+
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+
+ stmt = __prepare_query
+ (g_dp_db_handle, DP_DB_QUERY_TYPE_SET, table, column);
+ if (stmt == NULL) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+
+ int errorcode = SQLITE_OK;
+ errorcode = sqlite3_bind_blob(stmt, 1, value, (int)length, NULL);
+
+ if (errorcode != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
+
+ // WHERE id = ?
+ if (sqlite3_bind_int(stmt, 2, id) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
+
+ errorcode = sqlite3_step(stmt);
+ if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+ __dp_finalize(stmt);
+ return 0;
+ }
+ TRACE_ERROR("[SQL] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+}
+
int dp_db_replace_column(int id, char *table, char *column,
db_column_data_type datatype, void *value)
{
return dp_db_set_column(id, table, column, datatype, value);
}
+int dp_db_replace_blob_column(int id, char *table, char *column1,
+ void *value, unsigned length)
+{
+ if (id <= 0) {
+ TRACE_ERROR("[CHECK ID]");
+ return -1;
+ }
+ if (!table) {
+ TRACE_ERROR("[CHECK TABLE NAME]");
+ return -1;
+ }
+ if (!column1) {
+ TRACE_ERROR("[CHECK COLUMN NAME]");
+ return -1;
+ }
+ int check_id = dp_db_get_int_column(id, table, DP_DB_COL_ID);
+ if (check_id != id) // INSERT
+ {
+ return dp_db_insert_blob_column(id, table, column1, value, length);
+ }
+ // UPDATE
+ return dp_db_set_blob_column(id, table, column1, value, length);
+}
+
// success : 0
// error : -1
char *dp_db_get_text_column(int id, char *table, char *column)
__dp_finalize(stmt);
return columntext;
}
- TRACE_INFO("[No DATA]");
__dp_finalize(stmt);
return NULL;
}
+// success : 0
+// error : -1
+void *dp_db_get_blob_column(int id, char *table, char *column, int *length)
+{
+ sqlite3_stmt *stmt = NULL;
+
+ if (id <= 0) {
+ TRACE_ERROR("[CHECK ID]");
+ return NULL;
+ }
+
+ if (!table) {
+ TRACE_ERROR("[CHECK TABLE NAME]");
+ return NULL;
+ }
+
+ if (!column) {
+ TRACE_ERROR("[CHECK COLUMN NAME]");
+ return NULL;
+ }
+
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return NULL;
+ }
+
+ stmt = __prepare_query
+ (g_dp_db_handle, DP_DB_QUERY_TYPE_GET, table, column);
+ if (stmt == NULL) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return NULL;
+ }
+
+ // WHERE id = ?
+ if (sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return NULL;
+ }
+
+ if (sqlite3_step(stmt) == SQLITE_ROW) {
+ int blob_length = 0;
+ void *blob_data = NULL;
+ blob_length = sqlite3_column_bytes(stmt, 0);
+ if(blob_length > 0){
+ blob_data = (void*)calloc(blob_length, sizeof(unsigned char));
+ if(blob_data != NULL){
+ memcpy(blob_data, sqlite3_column_blob(stmt, 0),
+ sizeof(unsigned char)*blob_length);
+ } else {
+ TRACE_ERROR("[MEM] allocating");
+ blob_length = -1;
+ }
+ } else {
+ TRACE_ERROR("NO DATA");
+ blob_length = -1;
+ }
+ __dp_finalize(stmt);
+ *length = blob_length;
+ return blob_data;
+ }
+ __dp_finalize(stmt);
+ return NULL;
+}
+
+
int dp_db_get_int_column(int id, char *table, char *column)
{
sqlite3_stmt *stmt = NULL;
__dp_finalize(stmt);
return columnvalue;
}
- TRACE_INFO("[No DATA]");
__dp_finalize(stmt);
return -1;
}
__dp_finalize(stmt);
return columnvalue;
}
- TRACE_INFO("[No DATA]");
__dp_finalize(stmt);
return -1;
}
return NULL;
}
- TRACE_INFO("[QUERY] %s", query);
-
ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
sqlite3_free(query);
if ( ret != SQLITE_OK) {
return -1;
}
- TRACE_INFO("[QUERY] %s", query);
-
ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
sqlite3_free(query);
if ( ret != SQLITE_OK) {
return -1;
}
-int dp_db_get_cond_rows_count(int id, char *table,
- char *condcolumn, db_column_data_type condtype,
- void *condvalue)
+static int __dp_sql_bind_value(sqlite3_stmt *stmt,
+ db_column_data_type condtype, void *value, int index)
{
- int errorcode = SQLITE_OK;
- int ret = -1;
- sqlite3_stmt *stmt = NULL;
+ int errorcode = SQLITE_ERROR;
+ int *cast_value = 0;
+
+ if (stmt == NULL)
+ return SQLITE_ERROR;
+
+ switch (condtype) {
+ case DP_DB_COL_TYPE_INT:
+ cast_value = value;
+ errorcode = sqlite3_bind_int(stmt, index, *cast_value);
+ break;
+ case DP_DB_COL_TYPE_INT64:
+#ifdef SQLITE_INT64_TYPE
+ sqlite3_int64 *cast_value = value;
+ errorcode = sqlite3_bind_int64(stmt, index, *cast_value);
+#else
+ cast_value = value;
+ errorcode = sqlite3_bind_int(stmt, index, *cast_value);
+#endif
+ break;
+ case DP_DB_COL_TYPE_TEXT:
+ errorcode =
+ sqlite3_bind_text(stmt, index, (char *)value, -1, SQLITE_STATIC);
+ break;
+ default:
+ errorcode = SQLITE_ERROR;
+ break;
+ }
+ return errorcode;
+}
+
+char *dp_db_cond_get_text(char *table, char *column, char *condcolumn,
+ db_column_data_type condtype, void *condvalue)
+{
+ sqlite3_stmt *stmt = NULL;
+ char *query = NULL;
+ int ret = -1;
+
+ if (table == NULL) {
+ TRACE_ERROR("[CHECK TABLE NAME]");
+ return NULL;
+ }
+
+ if (column == NULL) {
+ TRACE_ERROR("[CHECK COLUMN NAME]");
+ return NULL;
+ }
+ if (condcolumn == NULL) {
+ TRACE_ERROR("[CHECK Condition]");
+ return NULL;
+ }
+
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("__dp_sql_open[%s]", sqlite3_errmsg(g_dp_db_handle));
+ return NULL;
+ }
+
+ query = sqlite3_mprintf("SELECT %s FROM %s WHERE %s IS ?",
+ column, table, condcolumn);
+ if (query == NULL) {
+ TRACE_ERROR("[CHECK COMBINE]");
+ return NULL;
+ }
+ ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
+ sqlite3_free(query);
+ if ( ret != SQLITE_OK) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return NULL;
+ }
+
+ if (__dp_sql_bind_value(stmt, condtype, condvalue, 1) != SQLITE_OK) {
+ TRACE_ERROR
+ ("[BIND][%d][%s]", condtype, sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return NULL;
+ }
+ if (sqlite3_step(stmt) == SQLITE_ROW &&
+ sqlite3_column_type(stmt, 0) == SQLITE_TEXT) {
+ int getbytes = sqlite3_column_bytes(stmt, 0);
+ if (getbytes > 0) {
+ char *getstr = (char *)calloc(getbytes + 1, sizeof(char));
+ if (getstr != NULL) {
+ memcpy(getstr, sqlite3_column_text(stmt, 0),
+ getbytes * sizeof(char));
+ getstr[getbytes] = '\0';
+ }
+ __dp_finalize(stmt);
+ return getstr;
+ }
+ }
+ __dp_finalize(stmt);
+ return NULL;
+}
+
+int dp_db_cond_get_int(char *table, char *column, char *condcolumn,
+ db_column_data_type condtype, void *condvalue)
+{
+ sqlite3_stmt *stmt = NULL;
+ char *query = NULL;
+ int ret = -1;
+
+ if (table == NULL) {
+ TRACE_ERROR("[CHECK TABLE NAME]");
+ return -1;
+ }
+
+ if (column == NULL) {
+ TRACE_ERROR("[CHECK COLUMN NAME]");
+ return -1;
+ }
+ if (condcolumn == NULL) {
+ TRACE_ERROR("[CHECK Condition]");
+ return -1;
+ }
+
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("__dp_sql_open[%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+
+ query = sqlite3_mprintf("SELECT %s FROM %s WHERE %s IS ?",
+ column, table, condcolumn);
+ if (query == NULL) {
+ TRACE_ERROR("[CHECK COMBINE]");
+ return -1;
+ }
+ ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
+ sqlite3_free(query);
+ if ( ret != SQLITE_OK) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
+
+ if (__dp_sql_bind_value(stmt, condtype, condvalue, 1) != SQLITE_OK) {
+ TRACE_ERROR
+ ("[BIND][%d][%s]", condtype, sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
+ if (sqlite3_step(stmt) == SQLITE_ROW &&
+ sqlite3_column_type(stmt, 0) == SQLITE_INTEGER) {
+ int columnvalue = sqlite3_column_int(stmt, 0);
+ __dp_finalize(stmt);
+ return columnvalue;
+ }
+ __dp_finalize(stmt);
+ return -1;
+}
+
+int dp_db_get_cond_rows_count(int id, char *table,
+ char *condcolumn, db_column_data_type condtype,
+ void *condvalue)
+{
+ int errorcode = SQLITE_OK;
+ int ret = -1;
+ sqlite3_stmt *stmt = NULL;
char *query = NULL;
if (id <= 0) {
return -1;
}
- TRACE_INFO("[QUERY] %s", query);
-
ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
sqlite3_free(query);
- if ( ret != SQLITE_OK) {
+ if (ret != SQLITE_OK) {
TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
__dp_finalize(stmt);
return -1;
case DP_DB_COL_TYPE_INT:
cast_value = value;
errorcode = sqlite3_bind_int(stmt, index, *cast_value);
- TRACE_INFO("INT %d", *cast_value);
break;
case DP_DB_COL_TYPE_INT64:
#ifdef SQLITE_INT64_TYPE
sqlite3_int64 *cast_value = value;
errorcode = sqlite3_bind_int64(stmt, index, *cast_value);
- TRACE_INFO("INT %ld", *cast_value);
#else
cast_value = value;
errorcode = sqlite3_bind_int(stmt, index, *cast_value);
- TRACE_INFO("INT %d", *cast_value);
#endif
break;
case DP_DB_COL_TYPE_TEXT:
TRACE_ERROR("[CHECK COMBINE]");
return -1;
}
+ TRACE_DEBUG("query:%s", query);
+
+ ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
+ sqlite3_free(query);
+ if ( ret != SQLITE_OK) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
+
+ for (i = 0; i < column_count; i++) {
+ if (__bind_value
+ (stmt, columns[i].type, columns[i].value, (i + 1)) !=
+ SQLITE_OK) {
+ TRACE_ERROR("[BIND][%d][%s]", columns[i].type,
+ sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
+ }
+
+ errorcode = sqlite3_step(stmt);
+ if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+ __dp_finalize(stmt);
+ return 0;
+ }
+ TRACE_ERROR("[SQL] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+}
+
+int dp_db_update_columns(int id, char *table, int column_count,
+ db_conds_list_fmt *columns)
+{
+ int errorcode = SQLITE_OK;
+ int ret = -1;
+ sqlite3_stmt *stmt = NULL;
+ char *query = NULL;
+ int i = 0;
+
+ if (id <= 0) {
+ TRACE_ERROR("[CHECK ID]");
+ return -1;
+ }
+ if (table == NULL) {
+ TRACE_ERROR("[CHECK TABLE NAME]");
+ return -1;
+ }
+ if (column_count <= 0) {
+ TRACE_ERROR("[CHECK db_conds_list_fmt count]");
+ return -1;
+ }
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("[SQL HANDLE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
- TRACE_INFO("[QUERY] %s", query);
+ query =
+ sqlite3_mprintf("UPDATE %s SET %s = ?", table, columns[0].column);
+ for (i = 1; i < column_count; i++) {
+ char *column_query = NULL;
+ column_query = sqlite3_mprintf("%s = ?", columns[i].column);
+ query = __merge_strings(query, column_query, ',');
+ sqlite3_free(column_query);
+ }
+ query = __merge_strings(query, "WHERE id = ?", ' ');
+ if (query == NULL) {
+ TRACE_ERROR("[CHECK COMBINE]");
+ return -1;
+ }
+ TRACE_DEBUG("query:%s", query);
ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
sqlite3_free(query);
return -1;
}
}
+ if (sqlite3_bind_int(stmt, column_count + 1, id) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] ID [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_finalize(stmt);
+ return -1;
+ }
errorcode = sqlite3_step(stmt);
if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
return -1;
}
- TRACE_INFO("[QUERY] %s", query);
-
ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
sqlite3_free(query);
if (ret != SQLITE_OK) {
TRACE_ERROR("[CHECK COMBINE]");
return -1;
}
- TRACE_INFO("[QUERY] %s", query);
errorcode =
sqlite3_prepare_v2(g_dp_db_handle, query, -1, &stmt, NULL);
return rows_count;
}
+static void __dp_db_reset(sqlite3_stmt *stmt)
+{
+ if (stmt != 0) {
+ sqlite3_clear_bindings(stmt);
+ if (sqlite3_reset(stmt) != SQLITE_OK) {
+ sqlite3 *handle = sqlite3_db_handle(stmt);
+ TRACE_ERROR("failed sqlite3_reset [%s]",
+ sqlite3_errmsg(handle));
+ }
+ }
+}
+
+int dp_db_request_new_logging(const int id, const int state, const char *pkgname)
+{
+ int errorcode = SQLITE_OK;
+ int ret = -1;
+ char *query = NULL;
+
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("[SQL HANDLE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+
+ if (g_dp_db_logging_new_stmt == NULL) {
+ query =
+ sqlite3_mprintf("INSERT INTO %s (%s, %s, %s, %s) VALUES (?, ?, ?, DATETIME('now'))",
+ DP_DB_TABLE_LOG, DP_DB_COL_ID, DP_DB_COL_STATE,
+ DP_DB_COL_PACKAGENAME, DP_DB_COL_CREATE_TIME);
+ if (query == NULL) {
+ TRACE_ERROR("[CHECK COMBINE]");
+ return -1;
+ }
+
+ TRACE_DEBUG("query:%s", query);
+
+ ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &g_dp_db_logging_new_stmt, NULL);
+ sqlite3_free(query);
+ if (ret != SQLITE_OK) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+ }
+ if (sqlite3_bind_int(g_dp_db_logging_new_stmt, 1, id) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_db_reset(g_dp_db_logging_new_stmt);
+ return -1;
+ }
+ if (sqlite3_bind_int(g_dp_db_logging_new_stmt, 2, state) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_db_reset(g_dp_db_logging_new_stmt);
+ return -1;
+ }
+ if (sqlite3_bind_text(g_dp_db_logging_new_stmt, 3, pkgname, -1, SQLITE_STATIC) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_db_reset(g_dp_db_logging_new_stmt);
+ return -1;
+ }
+
+ errorcode = sqlite3_step(g_dp_db_logging_new_stmt);
+ __dp_db_reset(g_dp_db_logging_new_stmt);
+ if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+ return 0;
+ }
+ return -1;
+}
+
+int dp_db_request_update_status(const int id, const int state, const int download_error)
+{
+ int errorcode = SQLITE_OK;
+ int ret = -1;
+ char *query = NULL;
+
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("[SQL HANDLE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+
+ if (g_dp_db_logging_status_stmt == NULL) {
+ query =
+ sqlite3_mprintf("UPDATE %s SET %s = ?, %s = ?, %s = DATETIME('now') WHERE %s = ?",
+ DP_DB_TABLE_LOG, DP_DB_COL_STATE, DP_DB_COL_ERRORCODE,
+ DP_DB_COL_ACCESS_TIME, DP_DB_COL_ID);
+ if (query == NULL) {
+ TRACE_ERROR("[CHECK COMBINE]");
+ return -1;
+ }
+
+ TRACE_DEBUG("query:%s", query);
+
+ ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &g_dp_db_logging_status_stmt, NULL);
+ sqlite3_free(query);
+ if (ret != SQLITE_OK) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+ }
+ if (sqlite3_bind_int(g_dp_db_logging_status_stmt, 1, state) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_db_reset(g_dp_db_logging_status_stmt);
+ return -1;
+ }
+ if (sqlite3_bind_int(g_dp_db_logging_status_stmt, 2, download_error) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_db_reset(g_dp_db_logging_status_stmt);
+ return -1;
+ }
+ if (sqlite3_bind_int(g_dp_db_logging_status_stmt, 3, id) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_db_reset(g_dp_db_logging_status_stmt);
+ return -1;
+ }
+
+ errorcode = sqlite3_step(g_dp_db_logging_status_stmt);
+ __dp_db_reset(g_dp_db_logging_status_stmt);
+ if (errorcode == SQLITE_OK || errorcode == SQLITE_DONE) {
+ return 0;
+ }
+ return -1;
+}
+
+int dp_db_get_state(int id)
+{
+ if (id <= 0) {
+ TRACE_ERROR("[CHECK ID]");
+ return -1;
+ }
+
+ if (__dp_sql_open() < 0) {
+ TRACE_ERROR("[OPEN] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+
+ if (g_dp_db_logging_get_state_stmt == NULL) {
+ char *query = sqlite3_mprintf("SELECT %s FROM %s WHERE %s = ?",
+ DP_DB_COL_STATE, DP_DB_TABLE_LOG, DP_DB_COL_ID);
+ if (query == NULL) {
+ TRACE_ERROR("[CHECK COMBINE]");
+ return -1;
+ }
+
+ TRACE_DEBUG("query:%s", query);
+
+ int ret = sqlite3_prepare_v2(g_dp_db_handle, query, -1, &g_dp_db_logging_get_state_stmt, NULL);
+ sqlite3_free(query);
+ if (ret != SQLITE_OK) {
+ TRACE_ERROR("[PREPARE] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ return -1;
+ }
+ }
+
+ if (sqlite3_bind_int(g_dp_db_logging_get_state_stmt, 1, id) != SQLITE_OK) {
+ TRACE_ERROR("[BIND] [%s]", sqlite3_errmsg(g_dp_db_handle));
+ __dp_db_reset(g_dp_db_logging_get_state_stmt);
+ return -1;
+ }
+
+ int state = DP_STATE_NONE;
+ if (sqlite3_step(g_dp_db_logging_get_state_stmt) == SQLITE_ROW) {
+ state = sqlite3_column_int(g_dp_db_logging_get_state_stmt, 0);
+ }
+ __dp_db_reset(g_dp_db_logging_get_state_stmt);
+ return state;
+}
#include <glib.h>
#include <glib-object.h>
#include <pthread.h>
+#include <locale.h>
+#include <libintl.h>
+#include <systemd/sd-daemon.h>
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
-#include <dbus/dbus.h>
-#endif
+#include "vconf.h"
#include "download-provider-config.h"
#include "download-provider-log.h"
// need for libsoup, decided the life-time by mainloop.
GMainLoop *g_main_loop_handle = 0;
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
-static int __register_dbus_service(void)
-{
- DBusError dbus_error;
- DBusConnection *dp_dbus_connection = NULL;
-
- dbus_error_init(&dbus_error);
-
- dp_dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
- if (dp_dbus_connection == NULL) {
- TRACE_ERROR("[DBUS] dbus_bus_get: %s", dbus_error.message);
- dbus_error_free(&dbus_error);
- return -1;
- }
-
- if (dbus_bus_request_name
- (dp_dbus_connection, DP_DBUS_SERVICE_DBUS, 0, &dbus_error) < 0 ||
- dbus_error_is_set(&dbus_error)) {
- TRACE_ERROR("[DBUS] request_name %s", dbus_error.message);
- dbus_error_free(&dbus_error);
- dbus_connection_unref(dp_dbus_connection);
- dp_dbus_connection = NULL;
- return -1;
- }
- dbus_connection_unref(dp_dbus_connection);
- dp_dbus_connection = NULL;
- return 0;
-}
-
-#endif
-
void dp_terminate(int signo)
{
- TRACE_INFO("Received SIGTERM");
+ TRACE_DEBUG("Received SIGTERM:%d", signo);
if (g_main_loop_is_running(g_main_loop_handle))
g_main_loop_quit(g_main_loop_handle);
}
static gboolean __dp_idle_start_service(void *data)
{
- TRACE_INFO("Launch threads .....");
-
// declare all resources
pthread_t thread_pid;
pthread_attr_t thread_attr;
return FALSE;
}
+void __set_locale()
+{
+ char *str = NULL;
+ str = vconf_get_str(VCONFKEY_LANGSET);
+ if (str != NULL) {
+ setlocale(LC_ALL, str);
+ bindtextdomain(PKG_NAME, LOCALE_DIR);
+ textdomain(PKG_NAME);
+ }
+ free(str);
+}
+void __lang_changed_cb(keynode_t *key, void* data)
+{
+ __set_locale();
+}
+
int main(int argc, char **argv)
{
dp_privates *privates = NULL;
TRACE_ERROR("failed to register signal callback");
exit(EXIT_FAILURE);
}
+ if (signal(SIGINT, dp_terminate) == SIG_ERR) {
+ TRACE_ERROR("failed to register signal callback");
+ exit(EXIT_FAILURE);
+ }
// write IPC_FD_PATH. and lock
if ((lock_fd = dp_lock_pid(DP_LOCK_PID)) < 0) {
TRACE_ERROR
DP_LOCK_PID);
exit(EXIT_FAILURE);
}
- // if exit socket file, delete it
- if (access(DP_IPC, F_OK) == 0) {
- unlink(DP_IPC);
- }
g_type_init();
+ // locale
+ __set_locale();
+ if (vconf_notify_key_changed(VCONFKEY_LANGSET, __lang_changed_cb, NULL) != 0)
+ TRACE_ERROR("Fail to set language changed vconf callback");
+
privates = (dp_privates *) calloc(1, sizeof(dp_privates));
if (!privates) {
TRACE_ERROR("[CRITICAL] failed to alloc for private info");
goto DOWNLOAD_EXIT;
}
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
- TRACE_INFO("SUPPORT DBUS-ACTIVATION");
- if (__register_dbus_service() < 0) {
- TRACE_ERROR("[LAUNCH ERROR] __register_dbus_service");
- goto DOWNLOAD_EXIT;
- }
-#else
- TRACE_INFO("Not SUPPORT DBUS-ACTIVATION");
-#endif
-
dp_db_open();
// convert to request type, insert all to privates->requests
if (!privates->requests[i].request)
continue;
dp_request *request = privates->requests[i].request;
- TRACE_INFO
+ TRACE_DEBUG
("ID [%d] state[%d]", request->id, request->state);
// load to memory, Can be started automatically.
}
} // query crashed_list
+#if 0
if (argc != 2 || memcmp(argv[1], "service", 7) != 0) {
// in first launch in booting time, not request. terminate by self
if (dp_get_request_count(privates->requests) <= 0) {
- TRACE_INFO("First Boot, No Request");
+ TRACE_DEBUG("First Boot, No Request");
goto DOWNLOAD_EXIT;
}
}
+#endif
dp_clear_downloadinginfo_notification();
privates->connection = 0;
privates->network_status = DP_NETWORK_TYPE_OFF;
if (dp_network_connection_init(privates) < 0) {
- TRACE_INFO("use instant network check");
+ TRACE_DEBUG("use instant network check");
privates->connection = 0;
}
g_idle_add(__dp_idle_start_service, privates);
+ sd_notify(0, "READY=1");
+
g_main_loop_run(g_main_loop_handle);
DOWNLOAD_EXIT :
- TRACE_INFO("Download-Provider will be terminated.");
+ TRACE_DEBUG("Download-Provider will be terminated.");
+ if (vconf_ignore_key_changed(VCONFKEY_LANGSET, __lang_changed_cb) != 0)
+ TRACE_ERROR("Fail to unset language changed vconf callback");
dp_deinit_agent();
if (privates->connection)
dp_network_connection_destroy(privates->connection);
- if (privates->listen_fd >= 0) {
- dp_socket_free(privates->listen_fd);
+ if (privates->listen_fd >= 0)
privates->listen_fd = -1;
- }
+
if (g_dp_thread_queue_manager_pid > 0 &&
pthread_kill(g_dp_thread_queue_manager_pid, 0) != ESRCH) {
//pthread_cancel(g_dp_thread_queue_manager_pid);
}
dp_db_close();
- // if exit socket file, delete it
- if (access(DP_IPC, F_OK) == 0) {
- unlink(DP_IPC);
- }
// delete pid file
if (access(DP_LOCK_PID, F_OK) == 0) {
close(lock_fd);
switch(errorcode)
{
case CONNECTION_ERROR_INVALID_PARAMETER :
- TRACE_INFO("CONNECTION_ERROR_INVALID_PARAMETER");
+ TRACE_DEBUG("CONNECTION_ERROR_INVALID_PARAMETER");
break;
case CONNECTION_ERROR_OUT_OF_MEMORY :
- TRACE_INFO("CONNECTION_ERROR_OUT_OF_MEMORY");
+ TRACE_DEBUG("CONNECTION_ERROR_OUT_OF_MEMORY");
break;
case CONNECTION_ERROR_INVALID_OPERATION :
- TRACE_INFO("CONNECTION_ERROR_INVALID_OPERATION");
+ TRACE_DEBUG("CONNECTION_ERROR_INVALID_OPERATION");
break;
case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED :
- TRACE_INFO("CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED");
+ TRACE_DEBUG("CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED");
break;
case CONNECTION_ERROR_OPERATION_FAILED :
- TRACE_INFO("CONNECTION_ERROR_OPERATION_FAILED");
+ TRACE_DEBUG("CONNECTION_ERROR_OPERATION_FAILED");
break;
case CONNECTION_ERROR_ITERATOR_END :
- TRACE_INFO("CONNECTION_ERROR_ITERATOR_END");
+ TRACE_DEBUG("CONNECTION_ERROR_ITERATOR_END");
break;
case CONNECTION_ERROR_NO_CONNECTION :
- TRACE_INFO("CONNECTION_ERROR_NO_CONNECTION");
+ TRACE_DEBUG("CONNECTION_ERROR_NO_CONNECTION");
break;
case CONNECTION_ERROR_NOW_IN_PROGRESS :
- TRACE_INFO("CONNECTION_ERROR_NOW_IN_PROGRESS");
+ TRACE_DEBUG("CONNECTION_ERROR_NOW_IN_PROGRESS");
break;
case CONNECTION_ERROR_ALREADY_EXISTS :
- TRACE_INFO("CONNECTION_ERROR_ALREADY_EXISTS");
+ TRACE_DEBUG("CONNECTION_ERROR_ALREADY_EXISTS");
break;
case CONNECTION_ERROR_OPERATION_ABORTED :
- TRACE_INFO("CONNECTION_ERROR_OPERATION_ABORTED");
+ TRACE_DEBUG("CONNECTION_ERROR_OPERATION_ABORTED");
break;
case CONNECTION_ERROR_DHCP_FAILED :
- TRACE_INFO("CONNECTION_ERROR_DHCP_FAILED");
+ TRACE_DEBUG("CONNECTION_ERROR_DHCP_FAILED");
break;
case CONNECTION_ERROR_INVALID_KEY :
- TRACE_INFO("CONNECTION_ERROR_INVALID_KEY");
+ TRACE_DEBUG("CONNECTION_ERROR_INVALID_KEY");
break;
case CONNECTION_ERROR_NO_REPLY :
- TRACE_INFO("CONNECTION_ERROR_NO_REPLY");
+ TRACE_DEBUG("CONNECTION_ERROR_NO_REPLY");
break;
default :
- TRACE_INFO("CONNECTION_ERROR_NONE");
+ TRACE_DEBUG("CONNECTION_ERROR_NONE");
break;
}
}
// support WIFI-Direct
static void __dp_network_wifi_direct_connection_state_changed_cb(wifi_direct_error_e error_code, wifi_direct_connection_state_e connection_state, const char *mac_address, void *data)
{
- TRACE_INFO("");
-
dp_privates *privates = (dp_privates*)data;
if (privates == NULL) {
TRACE_ERROR("[CRITICAL] Invalid data");
}
if (connection_state == WIFI_DIRECT_CONNECTION_RSP) {
- TRACE_INFO("WIFI_DIRECT_CONNECTION_RSP");
+ TRACE_DEBUG("WIFI_DIRECT_CONNECTION_RSP");
privates->is_connected_wifi_direct = 1;
return ;
}
switch (wifi_state)
{
case WIFI_DIRECT_STATE_DEACTIVATED :
- TRACE_INFO("WIFI_DIRECT_STATE_DEACTIVATED");
+ TRACE_DEBUG("WIFI_DIRECT_STATE_DEACTIVATED");
break;
case WIFI_DIRECT_STATE_DEACTIVATING :
- TRACE_INFO("WIFI_DIRECT_STATE_DEACTIVATING");
+ TRACE_DEBUG("WIFI_DIRECT_STATE_DEACTIVATING");
break;
case WIFI_DIRECT_STATE_ACTIVATING :
- TRACE_INFO("WIFI_DIRECT_STATE_ACTIVATING");
+ TRACE_DEBUG("WIFI_DIRECT_STATE_ACTIVATING");
break;
case WIFI_DIRECT_STATE_ACTIVATED :
- TRACE_INFO("WIFI_DIRECT_STATE_ACTIVATED");
+ TRACE_DEBUG("WIFI_DIRECT_STATE_ACTIVATED");
break;
case WIFI_DIRECT_STATE_DISCOVERING :
- TRACE_INFO("WIFI_DIRECT_STATE_DISCOVERING");
+ TRACE_DEBUG("WIFI_DIRECT_STATE_DISCOVERING");
break;
case WIFI_DIRECT_STATE_CONNECTING :
- TRACE_INFO("WIFI_DIRECT_STATE_CONNECTING");
+ TRACE_DEBUG("WIFI_DIRECT_STATE_CONNECTING");
break;
case WIFI_DIRECT_STATE_DISCONNECTING :
- TRACE_INFO("WIFI_DIRECT_STATE_DISCONNECTING");
+ TRACE_DEBUG("WIFI_DIRECT_STATE_DISCONNECTING");
break;
case WIFI_DIRECT_STATE_CONNECTED :
is_connected = 0;
- TRACE_INFO("WIFI_DIRECT_STATE_CONNECTED");
+ TRACE_DEBUG("WIFI_DIRECT_STATE_CONNECTED");
break;
default :
break;
(connection, &wifi_state) != CONNECTION_ERROR_NONE)
TRACE_ERROR("Failed connection_get_wifi_state");
if (wifi_state == CONNECTION_WIFI_STATE_CONNECTED) {
- TRACE_INFO("[CONNECTION_WIFI] CONNECTED");
+ TRACE_DEBUG("[CONNECTION_WIFI] CONNECTED");
network_type = DP_NETWORK_TYPE_WIFI;
} else {
- TRACE_INFO("[CONNECTION_WIFI] [%d]", wifi_state);
+ TRACE_DEBUG("[CONNECTION_WIFI] [%d]", wifi_state);
}
} else if (type == CONNECTION_TYPE_CELLULAR) {
connection_cellular_state_e cellular_state;
(connection, &cellular_state) != CONNECTION_ERROR_NONE)
TRACE_ERROR("Failed connection_get_cellular_state");
if (cellular_state == CONNECTION_CELLULAR_STATE_CONNECTED) {
- TRACE_INFO("[CONNECTION_CELLULAR] DATA NETWORK CONNECTED");
+ TRACE_DEBUG("[CONNECTION_CELLULAR] DATA NETWORK CONNECTED");
network_type = DP_NETWORK_TYPE_DATA_NETWORK;
} else {
- TRACE_INFO("[CONNECTION_CELLULAR] [%d]", cellular_state);
+ TRACE_DEBUG("[CONNECTION_CELLULAR] [%d]", cellular_state);
}
} else if (type == CONNECTION_TYPE_ETHERNET) {
connection_ethernet_state_e ethernet_state;
(connection, ðernet_state) != CONNECTION_ERROR_NONE)
TRACE_ERROR("Failed connection_get_ethernet_state");
if (ethernet_state == CONNECTION_ETHERNET_STATE_CONNECTED) {
- TRACE_INFO("[CONNECTION_ETHERNET] ETHERNET CONNECTED");
+ TRACE_DEBUG("[CONNECTION_ETHERNET] ETHERNET CONNECTED");
network_type = DP_NETWORK_TYPE_ETHERNET;
} else {
- TRACE_INFO("[CONNECTION_ETHERNET] [%d]", ethernet_state);
+ TRACE_DEBUG("[CONNECTION_ETHERNET] [%d]", ethernet_state);
}
} else {
- TRACE_INFO("[DISCONNECTED]");
+ TRACE_DEBUG("[DISCONNECTED]");
network_type = DP_NETWORK_TYPE_OFF;
}
return network_type;
/// @todo care requests by network status
static void __dp_network_connection_type_changed_cb(connection_type_e type, void *data)
{
- TRACE_INFO("type[%d]", type);
dp_privates *privates = (dp_privates*)data;
- if (!privates) {
+ if (privates == NULL) {
TRACE_ERROR("[CRITICAL] Invalid data");
return ;
}
CLIENT_MUTEX_LOCK(&(g_dp_queue_mutex));
#if 1 // this callback guarantee that already connectdd
if (type == CONNECTION_TYPE_WIFI) {
- TRACE_INFO("[CONNECTION_WIFI] CONNECTED");
+ TRACE_DEBUG("[CONNECTION_WIFI] CONNECTED");
privates->network_status = DP_NETWORK_TYPE_WIFI;
} else if (type == CONNECTION_TYPE_CELLULAR) {
- TRACE_INFO("[CONNECTION_CELLULAR] DATA NETWORK CONNECTED");
+ TRACE_DEBUG("[CONNECTION_CELLULAR] DATA NETWORK CONNECTED");
privates->network_status = DP_NETWORK_TYPE_DATA_NETWORK;
} else if (type == CONNECTION_TYPE_ETHERNET) {
- TRACE_INFO("[CONNECTION_ETHERNET] ETHERNET CONNECTED");
+ TRACE_DEBUG("[CONNECTION_ETHERNET] ETHERNET CONNECTED");
privates->network_status = DP_NETWORK_TYPE_ETHERNET;
} else {
- TRACE_INFO("[DISCONNECTED]");
+ TRACE_DEBUG("[DISCONNECTED]");
privates->network_status = DP_NETWORK_TYPE_OFF;
}
if (privates->network_status != DP_NETWORK_TYPE_OFF)
}
//////////////////////////////////////////////////////////////////////////
+/// @brief [callback] called when changed network ip
+/// @todo auto resume feature
+static void __dp_network_connection_ip_changed_cb(const char *ip, const char *ipv6, void *data)
+{
+ dp_privates *privates = (dp_privates*)data;
+ if (privates == NULL) {
+ TRACE_ERROR("[CRITICAL] Invalid data");
+ return ;
+ }
+ if (privates->network_status != DP_NETWORK_TYPE_OFF) {
+ dp_request_slots *requests = privates->requests;
+ int i = 0;
+ for (i = 0; i < DP_MAX_REQUEST; i++) {
+ int locked = pthread_mutex_trylock(&requests[i].mutex);
+ // locking failure means it used by other thread.
+ if (locked == 0) {
+ if (requests[i].request != NULL) {
+ if (requests[i].request->state == DP_STATE_DOWNLOADING ||
+ (requests[i].request->state == DP_STATE_FAILED &&
+ requests[i].request->error == DP_ERROR_CONNECTION_FAILED)) {
+ requests[i].request->ip_changed = 1;
+ }
+ }
+ CLIENT_MUTEX_UNLOCK(&requests[i].mutex);
+ }
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
/// @brief create connection handle & regist callback
/// @return 0 : success -1 : failed
int dp_network_connection_init(dp_privates *privates)
{
int retcode = 0;
- TRACE_INFO("");
if (!privates) {
TRACE_ERROR("[CRITICAL] Invalid data");
return -1;
connection_destroy(privates->connection);
return -1;
}
+ if ((retcode = connection_set_ip_address_changed_cb
+ (privates->connection, __dp_network_connection_ip_changed_cb,
+ privates)) != CONNECTION_ERROR_NONE) {
+ TRACE_ERROR("Failed __dp_network_connection_ip_changed_cb [%d]", retcode);
+ connection_destroy(privates->connection);
+ return -1;
+ }
connection_type_e type = CONNECTION_TYPE_DISCONNECTED;
if ((retcode = connection_get_type(privates->connection, &type)) !=
CONNECTION_ERROR_NONE) {
/// @brief destroy connection handle
void dp_network_connection_destroy(connection_h connection)
{
- TRACE_INFO("");
-
#ifdef SUPPORT_WIFI_DIRECT
wifi_direct_unset_connection_state_changed_cb();
wifi_direct_deinitialize();
#endif
- connection_unset_type_changed_cb (connection);
+ connection_unset_type_changed_cb(connection);
+ connection_unset_ip_address_changed_cb(connection);
connection_destroy(connection);
}
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
+#include <stdio.h>
#include "bundle.h"
#include "notification.h"
#include "appsvc.h"
+#include "download-provider-defs.h"
+
#include "download-provider-notification.h"
#include "download-provider-request.h"
#include "download-provider-db.h"
#include <libintl.h>
#define S_(s) dgettext("sys_string", s)
+#define __(s) dgettext(PKG_NAME, s)
-#define DP_NOTIFICATION_ICON_PATH IMAGE_DIR"/Q02_Notification_Download_failed.png"
+#define DP_NOTIFICATION_ICON_PATH IMAGE_DIR"/Q02_Notification_download_complete.png"
+#define DP_NOTIFICATION_ONGOING_ICON_PATH IMAGE_DIR"/Notification_download_animation.gif"
+#define DP_NOTIFICATION_DOWNLOADING_ICON_PATH "reserved://indicator/ani/downloading"
+#define DP_NOTIFICATION_FAILED_ICON_PATH IMAGE_DIR"/Q02_Notification_download_failed.png"
static const char *__noti_error_str(
notification_error_e err)
return "Unknown error";
}
+static char *__get_string_sender(char *url)
+{
+ char *temp = NULL;
+ char *found = NULL;
+ char *found1 = NULL;
+ char *sender = NULL;
+ char *credential_sender = NULL;
+
+ if (url == NULL)
+ return NULL;
+
+ found = strstr(url, "://");
+ if (found) {
+ temp = found + 3;
+ } else {
+ temp = url;
+ }
+ found = strchr(temp, '/');
+ if (found) {
+ int len = 0;
+ len = found - temp;
+ sender = calloc(len + 1, sizeof(char));
+ if (sender == NULL)
+ return NULL;
+ snprintf(sender, len + 1, "%s", temp);
+ } else {
+ sender = dp_strdup(temp);
+ }
+
+ // For credential URL
+ found = strchr(sender, '@');
+ found1 = strchr(sender, ':');
+ if (found && found1 && found1 < found) {
+ int len = 0;
+ found = found + 1;
+ len = strlen(found);
+ credential_sender = calloc(len + 1, sizeof(char));
+ if (credential_sender == NULL) {
+ free(sender);
+ return NULL;
+ }
+ snprintf(credential_sender, len + 1, "%s", found);
+ free(sender);
+ return credential_sender;
+ } else {
+ return sender;
+ }
+}
+
+static char *__get_string_size(long long file_size)
+{
+ const char *unitStr[4] = {"B", "KB", "MB", "GB"};
+ double doubleTypeBytes = 0.0;
+ int unit = 0;
+ long long bytes = file_size;
+ long long unitBytes = bytes;
+ char *temp = NULL;
+
+ /* using bit operation to avoid floating point arithmetic */
+ for (unit = 0; (unitBytes > 1024 && unit < 4); unit++) {
+ unitBytes = unitBytes >> 10;
+ }
+ unitBytes = 1 << (10 * unit);
+
+ if (unit > 3)
+ unit = 3;
+
+ char str[64] = {0};
+ if (unit == 0) {
+ snprintf(str, sizeof(str), "%lld %s", bytes, unitStr[unit]);
+ } else {
+ doubleTypeBytes = ((double)bytes / (double)unitBytes);
+ snprintf(str, sizeof(str), "%.2f %s", doubleTypeBytes, unitStr[unit]);
+ }
+
+ str[63] = '\0';
+ temp = dp_strdup(str);
+ return temp;
+}
+
static char *__get_string_status(dp_state_type state)
{
char *message = NULL;
switch (state) {
case DP_STATE_COMPLETED:
- //message = S_("IDS_COM_POP_SUCCESS");
- message = "Completed";
+ message = __("IDS_DM_HEADER_DOWNLOAD_COMPLETE");
break;
case DP_STATE_CANCELED:
- //message = S_("IDS_COM_POP_CANCELLED");
- message = "Canceled";
- break;
case DP_STATE_FAILED:
- //message = S_("IDS_COM_POP_FAILED");
- message = "Failed";
+ message = S_("IDS_COM_POP_DOWNLOAD_FAILED");
break;
default:
break;
}
return message;
}
-static void __free_char_pointer_array(char **array, int count)
-{
- int i = 0;
- if (count < 0)
- count = 0;
- for (i = 0; i < count; i++) {
- if (array[i])
- free(array[i]);
- }
- free(array);
-}
-
-static int __set_extra_data(bundle *b, int id)
-{
- db_conds_list_fmt conds_p;
- int conds_count = 0;
- int count = 0;
- // get count of key list.
- conds_count = 1;
- memset(&conds_p, 0x00, sizeof(db_conds_list_fmt));
- conds_p.column = DP_DB_COL_ID;
- conds_p.type = DP_DB_COL_TYPE_INT;
- conds_p.value = &id;
- count = dp_db_get_conds_rows_count(DP_DB_TABLE_NOTIFICATION,
- DP_DB_COL_DISTINCT_EXTRA_KEY, "AND", 1, &conds_p);
- if (count > 0) {
- char **keys_array = NULL;
- int i = 0;
- keys_array = (char **)calloc(count, sizeof(char *));
- if (keys_array == NULL) {
- TRACE_ERROR("[FAIL] calloc failed");
- return -1;
- }
- // get key list
- int keys_count =
- dp_db_get_conds_list(DP_DB_TABLE_NOTIFICATION,
- DP_DB_COL_DISTINCT_EXTRA_KEY , DP_DB_COL_TYPE_TEXT,
- (void **)keys_array, count, -1, NULL, NULL,
- "AND", 1, &conds_p);
- if (keys_count <= 0) {
- TRACE_ERROR("[FAIL] Wrong db data");
- __free_char_pointer_array(keys_array, 0);
- return -1;
- }
- for (i = 0; i < keys_count; i++) {
- db_conds_list_fmt conds_p2[2];
- int conds_count2 = 2;
- char **values_array = NULL;
- int check_rows = 0;
- int values_count = 0;
-
- memset(conds_p2, 0x00, conds_count2 * sizeof(db_conds_list_fmt));
- conds_p2[0].column = DP_DB_COL_ID;
- conds_p2[0].type = DP_DB_COL_TYPE_INT;
- conds_p2[0].value = &id;
- conds_p2[1].column = DP_DB_COL_EXTRA_KEY;
- conds_p2[1].type = DP_DB_COL_TYPE_TEXT;
- conds_p2[1].value = (void *)(keys_array[i]);
- // get value list
- check_rows = dp_db_get_conds_rows_count(
- DP_DB_TABLE_NOTIFICATION, DP_DB_COL_EXTRA_VALUE, "AND",
- conds_count2, conds_p2);
- if (check_rows <= 0) {
- TRACE_ERROR("[FAIL] No values about key");
- __free_char_pointer_array(keys_array, keys_count);
- return -1;
- }
- values_array = (char **)calloc(check_rows, sizeof(char *));
- if (values_array == NULL) {
- TRACE_ERROR("[FAIL] calloc failed");
- __free_char_pointer_array(keys_array, keys_count);
- return -1;
- }
- values_count =
- dp_db_get_conds_list(DP_DB_TABLE_NOTIFICATION,
- DP_DB_COL_EXTRA_VALUE, DP_DB_COL_TYPE_TEXT,
- (void **)values_array, check_rows, -1, NULL, NULL,
- "AND", conds_count2, conds_p2);
- if (values_count <= 0) {
- TRACE_ERROR("[FAIL] No values about key");
- __free_char_pointer_array(keys_array, keys_count);
- __free_char_pointer_array(values_array, 0);
- return -1;
- }
- if (values_count == 1) {
- char *key = keys_array[i];
- char *value = values_array[values_count-1];
- if (appsvc_add_data(b, key, value) !=
- APPSVC_RET_OK) {
- TRACE_ERROR("[FAIL] set add data");
- __free_char_pointer_array(keys_array, keys_count);
- __free_char_pointer_array(values_array, values_count);
- return -1;
- }
- } else {
- char *key = keys_array[i];
- if (appsvc_add_data_array(b, key, (const char **)values_array,
- values_count) != APPSVC_RET_OK) {
- TRACE_ERROR("[FAIL] set add data");
- __free_char_pointer_array(keys_array, keys_count);
- __free_char_pointer_array(values_array, values_count);
- return -1;
- }
- }
- __free_char_pointer_array(values_array, values_count);
- }
- __free_char_pointer_array(keys_array, keys_count);
- }
- return 0;
-}
int dp_set_downloadinginfo_notification(int id, char *packagename)
{
notification_error_e err = NOTIFICATION_ERROR_NONE;
int privId = 0;
bundle *b = NULL;
+ void *blob_data = NULL;
+ bundle_raw* b_raw = NULL;
+ int length;
noti_handle = notification_create(NOTIFICATION_TYPE_ONGOING);
if (!noti_handle) {
return -1;
}
- char *content_name =
- dp_db_get_text_column
- (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
+ char *title = dp_db_get_text_column(id,
+ DP_DB_TABLE_NOTIFICATION, DP_DB_COL_TITLE);
+ if(title != NULL) {
+ err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE,
+ title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ free(title);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
+ notification_free(noti_handle);
+ return -1;
+ }
+ } else {
+ char *content_name =
+ dp_db_get_text_column
+ (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
- if (content_name == NULL)
- content_name = strdup("No Name");
+ if (content_name == NULL)
+ content_name = strdup("No Name");
- err = notification_set_text(noti_handle,
- NOTIFICATION_TEXT_TYPE_TITLE, content_name, NULL,
- NOTIFICATION_VARIABLE_TYPE_NONE);
- if (content_name)
- free(content_name);
+ err = notification_set_text(noti_handle,
+ NOTIFICATION_TEXT_TYPE_TITLE, content_name, NULL,
+ NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (content_name)
+ free(content_name);
+ }
if (err != NOTIFICATION_ERROR_NONE) {
TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
}
err = notification_set_image(noti_handle,
- NOTIFICATION_IMAGE_TYPE_ICON, DP_NOTIFICATION_ICON_PATH);
+ NOTIFICATION_IMAGE_TYPE_ICON, DP_NOTIFICATION_ONGOING_ICON_PATH);
if (err != NOTIFICATION_ERROR_NONE) {
TRACE_ERROR("[FAIL] set icon [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
- b = bundle_create();
- if (!b) {
- TRACE_ERROR("[FAIL] create bundle");
- notification_free(noti_handle);
- return -1;
- }
+ blob_data = dp_db_get_blob_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_RAW_BUNDLE_ONGOING, &length);
+ if (blob_data != NULL) {
+ b_raw = (bundle_raw*)blob_data;
+ if (b_raw != NULL) {
+ b = bundle_decode_raw(b_raw, length);
+ if (b != NULL) {
+ err = notification_set_execute_option(noti_handle,
+ NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
+ bundle_free_encoded_rawdata(&b_raw);
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+ }
+ bundle_free_encoded_rawdata(&b_raw);
+ bundle_free(b);
+ }
+ }
+ } else {
+ b = bundle_create();
+ if (!b) {
+ TRACE_ERROR("[FAIL] create bundle");
+ notification_free(noti_handle);
+ return -1;
+ }
- if (packagename &&
- appsvc_set_pkgname(b, packagename) != APPSVC_RET_OK) {
- TRACE_ERROR("[FAIL] set pkg name");
- bundle_free(b);
- notification_free(noti_handle);
- return -1;
- }
+ if (packagename &&
+ appsvc_set_pkgname(b, packagename) != APPSVC_RET_OK) {
+ TRACE_ERROR("[FAIL] set pkg name");
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+ }
+ err = notification_set_execute_option(noti_handle,
+ NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
- if (__set_extra_data(b, id) < 0) {
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+ }
bundle_free(b);
+ }
+ err = notification_set_property(noti_handle,
+ NOTIFICATION_PROP_DISABLE_TICKERNOTI);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set property [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
- err = notification_set_execute_option(noti_handle,
- NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
-
+ err = notification_set_image(noti_handle,
+ NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, DP_NOTIFICATION_DOWNLOADING_ICON_PATH);
if (err != NOTIFICATION_ERROR_NONE) {
- TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
- bundle_free(b);
+ TRACE_ERROR("[FAIL] set icon indicator [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
- bundle_free(b);
- err = notification_set_property(noti_handle,
- NOTIFICATION_PROP_DISABLE_TICKERNOTI);
+ err = notification_set_display_applist(noti_handle, NOTIFICATION_DISPLAY_APP_ALL);
if (err != NOTIFICATION_ERROR_NONE) {
- TRACE_ERROR("[FAIL] set property [%s]", __noti_error_str(err));
+ TRACE_ERROR("[FAIL] set disable icon [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
return -1;
}
- TRACE_INFO("m_noti_id [%d]", privId);
+ TRACE_DEBUG("m_noti_id [%d]", privId);
notification_free(noti_handle);
return privId;
}
notification_error_e err = NOTIFICATION_ERROR_NONE;
int privId = 0;
bundle *b = NULL;
+ void *blob_data = NULL;
+ bundle_raw* b_raw = NULL;
+ int length = 0;
if (priv_id >= 0) {
err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_ONGOING,
return -1;
}
- char *content_name =
- dp_db_get_text_column
- (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
-
- if (content_name == NULL)
- content_name = strdup("No Name");
-
- err = notification_set_text(noti_handle,
- NOTIFICATION_TEXT_TYPE_TITLE, content_name,
- NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
- if (content_name)
- free(content_name);
-
if (err != NOTIFICATION_ERROR_NONE) {
TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
- err = notification_set_text(noti_handle,
- NOTIFICATION_TEXT_TYPE_CONTENT,
- __get_string_status(state), NULL,
- NOTIFICATION_VARIABLE_TYPE_NONE);
+ err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE,
+ __get_string_status(state), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
if (err != NOTIFICATION_ERROR_NONE) {
- TRACE_ERROR("[FAIL] set text [%s]", __noti_error_str(err));
- notification_free(noti_handle);
- return -1;
- }
- time_t tt = time(NULL);
-
- err = notification_set_time(noti_handle, tt);
- if (err != NOTIFICATION_ERROR_NONE) {
- TRACE_ERROR("[FAIL] set time [%s]", __noti_error_str(err));
- notification_free(noti_handle);
- return -1;
- }
-
- b = bundle_create();
- if (!b) {
- TRACE_ERROR("[FAIL] create bundle");
+ TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
- if (state == DP_STATE_COMPLETED) {
- if (appsvc_set_operation(b, APPSVC_OPERATION_VIEW) != APPSVC_RET_OK) {
- TRACE_ERROR("[FAIL] appsvc set operation");
- bundle_free(b);
+ char *description =
+ dp_db_get_text_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_DESCRIPTION);
+ if(description != NULL) {
+ err = notification_set_text(noti_handle,
+ NOTIFICATION_TEXT_TYPE_INFO_2, description,
+ NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ free(description);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set description [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
-
- char *savedpath =
- dp_db_get_text_column
- (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_SAVED_PATH);
- if (savedpath && appsvc_set_uri(b, savedpath) !=
- APPSVC_RET_OK) {
- TRACE_ERROR("[FAIL] appsvc set uri");
- free(savedpath);
- bundle_free(b);
- notification_free(noti_handle);
- return -1;
+ } else {
+ char *url = NULL;
+ url = dp_db_get_text_column
+ (id, DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_URL);
+ if (url) {
+ char *sender_str = __get_string_sender(url);
+ err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_2,
+ sender_str, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
+ free(sender_str);
+ free(url);
+ notification_free(noti_handle);
+ return -1;
+ }
+ free(sender_str);
+ free(url);
}
- if (savedpath)
- free(savedpath);
- err = notification_set_execute_option(noti_handle,
- NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+ }
+
+ char *title = dp_db_get_text_column(id,
+ DP_DB_TABLE_NOTIFICATION, DP_DB_COL_TITLE);
+ if(title != NULL) {
+ err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT,
+ title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ free(title);
if (err != NOTIFICATION_ERROR_NONE) {
- TRACE_ERROR("[FAIL] set execute option[%s]", __noti_error_str(err));
- bundle_free(b);
+ TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
+ } else {
+ char *content_name =
+ dp_db_get_text_column
+ (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
+ if (content_name == NULL)
+ content_name = strdup("No Name");
+
+ err = notification_set_text(noti_handle,
+ NOTIFICATION_TEXT_TYPE_CONTENT, content_name,
+ NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ free(content_name);
+ }
- } else if (state == DP_STATE_CANCELED || state == DP_STATE_FAILED) {
- if (__set_extra_data(b, id) < 0) {
+ time_t tt = time(NULL);
+ err = notification_set_time_to_text(noti_handle,
+ NOTIFICATION_TEXT_TYPE_INFO_SUB_1, tt);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set time [%s]", __noti_error_str(err));
+ notification_free(noti_handle);
+ return -1;
+ }
+ if (state == DP_STATE_COMPLETED) {
+ blob_data = dp_db_get_blob_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_RAW_BUNDLE_COMPLETE, &length);
+ if (blob_data != NULL) {
+ b_raw = (bundle_raw*)blob_data;
+ if (b_raw != NULL) {
+ b = bundle_decode_raw(b_raw, length);
+ if (b != NULL) {
+ err = notification_set_execute_option(noti_handle,
+ NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
+ bundle_free_encoded_rawdata(&b_raw);
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+ }
+ bundle_free_encoded_rawdata(&b_raw);
+ }
+ }
+ } else {
+ char *file_path = NULL;
+ b = bundle_create();
+ if (!b) {
+ TRACE_ERROR("[FAIL] create bundle");
+ notification_free(noti_handle);
+ return -1;
+ }
+ if (appsvc_set_operation(b, APPSVC_OPERATION_VIEW) != APPSVC_RET_OK) {
+ TRACE_ERROR("[FAIL] appsvc set operation");
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+ }
+ file_path = dp_db_get_text_column
+ (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_SAVED_PATH);
+ if (file_path == NULL) {
+ TRACE_ERROR("[FAIL] get file path");
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+
+ }
+ if (appsvc_set_uri(b, file_path) != APPSVC_RET_OK) {
+ TRACE_ERROR("[FAIL] appsvc set uri");
+ bundle_free(b);
+ notification_free(noti_handle);
+ free(file_path);
+ return -1;
+ }
+ free(file_path);
+ err = notification_set_execute_option(noti_handle,
+ NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set execute option[%s]", __noti_error_str(err));
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+ }
+ }
+ long long file_size = dp_db_get_int64_column(id,
+ DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_SIZE);
+ char *size_str = __get_string_size(file_size);
+
+ err = notification_set_text(noti_handle, NOTIFICATION_TEXT_TYPE_INFO_1,
+ size_str, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set title [%s]", __noti_error_str(err));
+ free(size_str);
bundle_free(b);
notification_free(noti_handle);
return -1;
}
+ free(size_str);
- if (packagename &&
- appsvc_set_pkgname(b, packagename) !=
- APPSVC_RET_OK) {
- TRACE_ERROR("[FAIL] set pkg name");
- bundle_free(b);
+ err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
+ DP_NOTIFICATION_ICON_PATH);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set icon [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
- err = notification_set_execute_option(noti_handle,
- NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+ } else if (state == DP_STATE_CANCELED || state == DP_STATE_FAILED) {
+ blob_data = dp_db_get_blob_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_RAW_BUNDLE_FAIL, &length);
+ if (blob_data != NULL) {
+ b_raw = (bundle_raw *)blob_data;
+ if (b_raw != NULL) {
+ b = bundle_decode_raw(b_raw, length);
+ if (b != NULL) {
+ err = notification_set_execute_option(noti_handle,
+ NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set execute option [%s]", __noti_error_str(err));
+ bundle_free_encoded_rawdata(&b_raw);
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+ }
+ bundle_free_encoded_rawdata(&b_raw);
+ }
+ }
+ } else {
+ b = bundle_create();
+ if (!b) {
+ TRACE_ERROR("[FAIL] create bundle");
+ notification_free(noti_handle);
+ return -1;
+ }
+ if (packagename &&
+ appsvc_set_pkgname(b, packagename) !=
+ APPSVC_RET_OK) {
+ TRACE_ERROR("[FAIL] set pkg name");
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+ }
+ err = notification_set_execute_option(noti_handle,
+ NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ TRACE_ERROR("[FAIL] set execute option[%s]", __noti_error_str(err));
+ bundle_free(b);
+ notification_free(noti_handle);
+ return -1;
+ }
+ }
+ err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
+ DP_NOTIFICATION_FAILED_ICON_PATH);
if (err != NOTIFICATION_ERROR_NONE) {
- TRACE_ERROR("[FAIL] set execute option[%s]", __noti_error_str(err));
+ TRACE_ERROR("[FAIL] set icon [%s]", __noti_error_str(err));
bundle_free(b);
notification_free(noti_handle);
return -1;
bundle_free(b);
- err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
- DP_NOTIFICATION_ICON_PATH);
+ err = notification_set_property(noti_handle,
+ NOTIFICATION_PROP_DISABLE_TICKERNOTI);
if (err != NOTIFICATION_ERROR_NONE) {
- TRACE_ERROR("[FAIL] set icon [%s]", __noti_error_str(err));
+ TRACE_ERROR("[FAIL] set property [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
- err = notification_set_property(noti_handle,
- NOTIFICATION_PROP_DISABLE_TICKERNOTI);
+ err = notification_set_display_applist(noti_handle,
+ NOTIFICATION_DISPLAY_APP_ALL ^ NOTIFICATION_DISPLAY_APP_INDICATOR);
if (err != NOTIFICATION_ERROR_NONE) {
- TRACE_ERROR("[FAIL] set property [%s]", __noti_error_str(err));
+ TRACE_ERROR("[FAIL] set disable icon [%s]", __noti_error_str(err));
notification_free(noti_handle);
return -1;
}
return -1;
}
- TRACE_INFO("m_noti_id [%d]", privId);
+ TRACE_DEBUG("m_noti_id [%d]", privId);
notification_free(noti_handle);
return privId;
}
#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
#include <sys/time.h>
-
+#include <sys/statfs.h>
#include "download-provider.h"
#include "download-provider-log.h"
#include "download-provider-db.h"
#include "download-provider-pthread.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
-
-
//////////////////////////////////////////////////////////////////////////
/// @brief create unique id as integer type
/// @return unique id combined local time and the special calculation
static int __get_download_request_id(void)
{
- int uniquetime = 0;
- struct timeval tval;
static int last_uniquetime = 0;
+ int uniquetime = 0;
do {
- uniquetime = (int)time(NULL);
+ struct timeval tval;
+ int cipher = 1;
+ int c = 0;
+
gettimeofday(&tval, NULL);
+
+ int usec = tval.tv_usec;
+ for (c = 0; ; c++, cipher++) {
+ if ((usec /= 10) <= 0)
+ break;
+ }
if (tval.tv_usec == 0)
- uniquetime = uniquetime + (tval.tv_usec + 1) % 0xfffff;
- else
- uniquetime = uniquetime + tval.tv_usec;
- TRACE_INFO("ID : %d", uniquetime);
+ tval.tv_usec = (tval.tv_sec & 0x0fff);
+ int disit_unit = 10;
+ for (c = 0; c < cipher - 3; c++)
+ disit_unit = disit_unit * 10;
+ uniquetime = tval.tv_sec + ((tval.tv_usec << 2) * 100) +
+ ((tval.tv_usec >> (cipher - 1)) * disit_unit) +
+ ((tval.tv_usec + (tval.tv_usec % 10)) & 0x0fff);
} while (last_uniquetime == uniquetime);
- last_uniquetime = uniquetime; // store
+ last_uniquetime = uniquetime;
return uniquetime;
}
return "UNHANDLED_HTTP_CODE";
case DP_ERROR_CANNOT_RESUME :
return "CANNOT_RESUME";
+ case DP_ERROR_PERMISSION_DENIED :
+ return "PERMISSION_DENIED";
case DP_ERROR_RESPONSE_TIMEOUT :
return "RESPONSE_TIMEOUT";
case DP_ERROR_REQUEST_TIMEOUT :
return "UNKNOWN";
}
+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;
+ }
+ TRACE_ERROR("[SMACK DISABLE]");
+ return 0;
+}
+
char *dp_strdup(char *src)
{
char *dest = NULL;
return DP_ERROR_OUT_OF_MEMORY;
}
- new_request->id = __get_download_request_id();
+ int check_id = -1;
+ do {
+ new_request->id = __get_download_request_id();
+ check_id = dp_db_get_int_column(new_request->id,
+ DP_DB_TABLE_LOG, DP_DB_COL_ID);
+ } while (check_id == new_request->id); // means duplicated id
+
new_request->group = group;
- if (group->pkgname && strlen(group->pkgname) > 1)
+ if (group->pkgname != NULL && strlen(group->pkgname) > 1)
new_request->packagename = dp_strdup(group->pkgname);
- new_request->credential = group->credential;
if (new_request->packagename == NULL) {
dp_request_free(new_request);
TRACE_ERROR("[ERROR][%d] OUT_OF_MEMORY [PACKAGENAME]", id);
}
new_request->state = DP_STATE_READY;
new_request->error = DP_ERROR_NONE;
+ new_request->create_time = (int)time(NULL);
- int conds_count = 3; // id + state + pkgname
- db_conds_list_fmt conds_p[conds_count];
- memset(&conds_p, 0x00, conds_count * sizeof(db_conds_list_fmt));
- conds_p[0].column = DP_DB_COL_ID;
- conds_p[0].type = DP_DB_COL_TYPE_INT;
- conds_p[0].value = &new_request->id;
- conds_p[1].column = DP_DB_COL_STATE;
- conds_p[1].type = DP_DB_COL_TYPE_INT;
- conds_p[1].value = &new_request->state;
- conds_p[2].column = DP_DB_COL_PACKAGENAME;
- conds_p[2].type = DP_DB_COL_TYPE_TEXT;
- conds_p[2].value = new_request->packagename;
- if (dp_db_insert_columns(DP_DB_TABLE_LOG, conds_count, conds_p) < 0) {
+ if (dp_db_request_new_logging(new_request->id, new_request->state,
+ new_request->packagename) < 0) {
dp_request_free(new_request);
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL]");
+ return DP_ERROR_NO_SPACE;
+ }
return DP_ERROR_OUT_OF_MEMORY;
}
-
- if (dp_db_update_date(new_request->id, DP_DB_TABLE_LOG,
- DP_DB_COL_CREATE_TIME) < 0)
- TRACE_ERROR("[CHECK SQL][%d]", id);
- new_request->create_time = (int)time(NULL);
-
*empty_slot = new_request;
return DP_ERROR_NONE;
}
}
} else {
// check id in logging table.
- dp_state_type state =
- dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+ dp_state_type state = dp_db_get_state(id);
// check again from logging table
if (state == DP_STATE_CONNECTING ||
state == DP_STATE_DOWNLOADING ||
(id, DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_URL,
DP_DB_COL_TYPE_TEXT, url) < 0) {
TRACE_ERROR("[CHECK SQL][%d]", id);
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", id);
+ return DP_ERROR_NO_SPACE;
+ }
return DP_ERROR_OUT_OF_MEMORY;
}
return DP_ERROR_NONE;
}
} else {
// check id in logging table.
- dp_state_type state =
- dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+ dp_state_type state = dp_db_get_state(id);
// check again from logging table
if (state == DP_STATE_CONNECTING ||
state == DP_STATE_DOWNLOADING ||
(id, DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_DESTINATION,
DP_DB_COL_TYPE_TEXT, dest) < 0) {
TRACE_ERROR("[CHECK SQL][%d]", id);
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", id);
+ return DP_ERROR_NO_SPACE;
+ }
return DP_ERROR_OUT_OF_MEMORY;
}
return DP_ERROR_NONE;
}
} else {
// check id in logging table.
- dp_state_type state =
- dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+ dp_state_type state = dp_db_get_state(id);
// check again from logging table
if (state == DP_STATE_CONNECTING ||
state == DP_STATE_DOWNLOADING ||
(id, DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_FILENAME,
DP_DB_COL_TYPE_TEXT, filename) < 0) {
TRACE_ERROR("[CHECK SQL][%d]", id);
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", id);
+ return DP_ERROR_NO_SPACE;
+ }
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ TRACE_SECURE_DEBUG("ID [%d] Filename[%s]", id, filename);
+ return DP_ERROR_NONE;
+}
+
+dp_error_type dp_request_set_title(int id, dp_request *request, char *title)
+{
+ int length = 0;
+ if (!title || (length = strlen(title)) <= 1)
+ return DP_ERROR_INVALID_PARAMETER;
+
+ if (request != NULL) {
+ if (request->state == DP_STATE_COMPLETED) {
+ TRACE_ERROR
+ ("[ERROR][%d] now[%s]", id, dp_print_state(request->state));
+ return DP_ERROR_INVALID_STATE;
+ }
+ } else {
+ // check id in logging table.
+ dp_state_type state = dp_db_get_state(id);
+ // check again from logging table
+ if (state == DP_STATE_COMPLETED) {
+ TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
+ return DP_ERROR_INVALID_STATE;
+ }
+ }
+
+ if (dp_db_replace_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_TITLE,
+ DP_DB_COL_TYPE_TEXT, title) < 0) {
+ TRACE_ERROR("[CHECK SQL][%d]", id);
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", id);
+ return DP_ERROR_NO_SPACE;
+ }
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ TRACE_SECURE_DEBUG("ID [%d] title[%s]", id, title);
+ return DP_ERROR_NONE;
+}
+
+dp_error_type dp_request_set_bundle(int id, dp_request *request, int type, bundle_raw *b, unsigned length)
+{
+ char *column = NULL;
+ if (b == NULL || (length < 1))
+ return DP_ERROR_INVALID_PARAMETER;
+
+ if (request != NULL) {
+ if (request->state == DP_STATE_COMPLETED) {
+ TRACE_ERROR
+ ("[ERROR][%d] now[%s]", id, dp_print_state(request->state));
+ return DP_ERROR_INVALID_STATE;
+ }
+ } else {
+ // check id in logging table.
+ dp_state_type state = dp_db_get_state(id);
+ // check again from logging table
+ if (state == DP_STATE_COMPLETED) {
+ TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
+ return DP_ERROR_INVALID_STATE;
+ }
+ }
+
+ switch(type) {
+ case DP_NOTIFICATION_BUNDLE_TYPE_ONGOING:
+ column = DP_DB_COL_RAW_BUNDLE_ONGOING;
+ break;
+ case DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE:
+ column = DP_DB_COL_RAW_BUNDLE_COMPLETE;
+ break;
+ case DP_NOTIFICATION_BUNDLE_TYPE_FAILED:
+ column = DP_DB_COL_RAW_BUNDLE_FAIL;
+ break;
+ default:
+ TRACE_ERROR("[CHECK TYPE][%d]", type);
+ return DP_ERROR_INVALID_PARAMETER;
+ }
+ if (dp_db_replace_blob_column
+ (id, DP_DB_TABLE_NOTIFICATION, column, b, length) < 0) {
+ TRACE_ERROR("[CHECK SQL][%d]", id);
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", id);
+ return DP_ERROR_NO_SPACE;
+ }
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+
+ //TRACE_SECURE_DEBUG("ID [%d] title[%s]", id, title);
+ return DP_ERROR_NONE;
+}
+
+dp_error_type dp_request_set_description(int id, dp_request *request, char *description)
+{
+ int length = 0;
+ if (!description || (length = strlen(description)) <= 1)
+ return DP_ERROR_INVALID_PARAMETER;
+
+ if (request != NULL) {
+ if (request->state == DP_STATE_COMPLETED) {
+ TRACE_ERROR
+ ("[ERROR][%d] now[%s]", id, dp_print_state(request->state));
+ return DP_ERROR_INVALID_STATE;
+ }
+ } else {
+ // check id in logging table.
+ dp_state_type state = dp_db_get_state(id);
+ // check again from logging table
+ if (state == DP_STATE_COMPLETED) {
+ TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
+ return DP_ERROR_INVALID_STATE;
+ }
+ }
+
+ if (dp_db_replace_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_DESCRIPTION,
+ DP_DB_COL_TYPE_TEXT, description) < 0) {
+ TRACE_ERROR("[CHECK SQL][%d]", id);
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", id);
+ return DP_ERROR_NO_SPACE;
+ }
return DP_ERROR_OUT_OF_MEMORY;
}
- TRACE_INFO("ID [%d] Filename[%s]", id, filename);
+ TRACE_SECURE_DEBUG("ID [%d] description[%s]", id, description);
+ return DP_ERROR_NONE;
+}
+
+dp_error_type dp_request_set_noti_type(int id, dp_request *request, unsigned type)
+{
+ if (request != NULL) {
+ if (request->state == DP_STATE_COMPLETED) {
+ TRACE_ERROR
+ ("[ERROR][%d] now[%s]", id, dp_print_state(request->state));
+ return DP_ERROR_INVALID_STATE;
+ }
+ } else {
+ // check id in logging table.
+ dp_state_type state = dp_db_get_state(id);
+ // check again from logging table
+ if (state == DP_STATE_COMPLETED) {
+ TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
+ return DP_ERROR_INVALID_STATE;
+ }
+ }
+
+ if (dp_db_replace_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE,
+ DP_DB_COL_TYPE_INT, &type) < 0) {
+ TRACE_ERROR("[CHECK SQL][%d]", id);
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", id);
+ return DP_ERROR_NO_SPACE;
+ }
+ return DP_ERROR_OUT_OF_MEMORY;
+ }
+ if (request)
+ {
+ if(!type)
+ request->auto_notification = 0;
+ else
+ request->auto_notification = 1;
+ }
+ TRACE_SECURE_DEBUG("ID [%d] enable[%d]", id, type);
return DP_ERROR_NONE;
}
}
} else {
// check id in logging table.
- dp_state_type state =
- dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+ dp_state_type state = dp_db_get_state(id);
// check again from logging table
if (state == DP_STATE_COMPLETED) {
TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
}
} else {
// check id in logging table.
- dp_state_type state =
- dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+ dp_state_type state = dp_db_get_state(id);
// check again from logging table
if (state == DP_STATE_COMPLETED) {
TRACE_ERROR("[ERROR][%d] now[%s]", id, dp_print_state(state));
{
if (request == NULL) {
// check id in logging table.
- dp_state_type state =
- dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+ dp_state_type state = dp_db_get_state(id);
if (state == DP_STATE_DOWNLOADING ||
state == DP_STATE_COMPLETED) {
return DP_ERROR_OUT_OF_MEMORY;
}
// update memory
- if (request)
+ if (request != NULL)
request->state_cb = enable;
return DP_ERROR_NONE;
}
{
if (request == NULL) {
// check id in logging table.
- dp_state_type state =
- dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+ dp_state_type state = dp_db_get_state(id);
if (state == DP_STATE_DOWNLOADING ||
state == DP_STATE_COMPLETED) {
}
} else {
// check id in logging table.
- dp_state_type state =
- dp_db_get_int_column(id, DP_DB_TABLE_LOG, DP_DB_COL_STATE);
+ dp_state_type state = dp_db_get_state(id);
// check again from logging table
if (state == DP_STATE_CONNECTING ||
state == DP_STATE_DOWNLOADING ||
return DP_ERROR_NONE;
}
-char *dp_request_get_url(int id, dp_request *request, dp_error_type *errorcode)
+char *dp_request_get_url(int id, dp_error_type *errorcode)
{
char *url = NULL;
url = dp_db_get_text_column
return filename;
}
+char *dp_request_get_title(int id, dp_request *request, dp_error_type *errorcode)
+{
+ char *title = NULL;
+ title = dp_db_get_text_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_TITLE);
+ if (title == NULL) {
+ *errorcode = DP_ERROR_NO_DATA;
+ return NULL;
+ }
+ return title;
+}
+
+bundle_raw *dp_request_get_bundle(int id, dp_request *request, dp_error_type *errorcode, char* column, int *length)
+{
+ void *blob_data = NULL;
+ blob_data = dp_db_get_blob_column
+ (id, DP_DB_TABLE_NOTIFICATION, column, length);
+ if (blob_data == NULL) {
+ *errorcode = DP_ERROR_NO_DATA;
+ return NULL;
+ }
+ return (bundle_raw*)blob_data;
+}
+
+
+char *dp_request_get_description(int id, dp_request *request, dp_error_type *errorcode)
+{
+ char *description = NULL;
+ description = dp_db_get_text_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_DESCRIPTION);
+ if (description == NULL) {
+ *errorcode = DP_ERROR_NO_DATA;
+ return NULL;
+ }
+ return description;
+}
+
+int dp_request_get_noti_type(int id, dp_request *request, dp_error_type *errorcode)
+{
+ int type = -1;
+ type = dp_db_get_int_column
+ (id, DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+ if (type == -1)
+ *errorcode = DP_ERROR_NO_DATA;
+ return type;
+}
+
+
+
char *dp_request_get_contentname(int id, dp_request *request, dp_error_type *errorcode)
{
char *content = NULL;
return mimetype;
}
+char *dp_request_get_pkg_name(int id, dp_request *request, dp_error_type *errorcode)
+{
+ char *pkg_name = NULL;
+ pkg_name = dp_db_get_text_column
+ (id, DP_DB_TABLE_LOG, DP_DB_COL_PACKAGENAME);
+ if (pkg_name == NULL) {
+ *errorcode = DP_ERROR_NO_DATA;
+ return NULL;
+ }
+ return pkg_name;
+}
+
dp_request *dp_request_load_from_log(int id, dp_error_type *errorcode)
{
dp_request *request = NULL;
return request;
}
+
+void dp_request_state_response(dp_request *request)
+{
+ if (request == NULL) {
+ return ;
+ }
+
+ TRACE_INFO("[INFO][%d] state:%s error:%s", request->id,
+ dp_print_state(request->state),
+ dp_print_errorcode(request->error));
+
+ if (dp_db_request_update_status(request->id, request->state,
+ request->error) < 0)
+ TRACE_ERROR("[ERROR][%d][SQL]", request->id);
+
+ if (request->group != NULL && request->group->event_socket >= 0 &&
+ request->state_cb == 1) {
+ dp_ipc_send_event(request->group->event_socket, request->id,
+ request->state, request->error, 0);
+ }
+
+ if (request->state == DP_STATE_DOWNLOADING) {
+ if (request->auto_notification == 1 &&
+ request->packagename != NULL) {
+ if (request->noti_priv_id != -1) {
+ dp_update_downloadinginfo_notification
+ (request->noti_priv_id,
+ (double)request->received_size,
+ (double)request->file_size);
+ } else {
+ request->noti_priv_id = dp_set_downloadinginfo_notification
+ (request->id, request->packagename);
+ }
+ } else {
+ int noti_type = dp_db_get_int_column(request->id,
+ DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+ if (noti_type == DP_NOTIFICATION_TYPE_ALL &&
+ request->packagename != NULL) {
+ if (request->noti_priv_id != -1) {
+ dp_update_downloadinginfo_notification
+ (request->noti_priv_id,
+ (double)request->received_size,
+ (double)request->file_size);
+ } else {
+ request->noti_priv_id = dp_set_downloadinginfo_notification
+ (request->id, request->packagename);
+ }
+ }
+ }
+ request->start_time = (int)time(NULL);
+ request->pause_time = 0;
+ request->stop_time = 0;
+ } else if (request->state == DP_STATE_PAUSED) {
+ if (request->group != NULL)
+ request->group->queued_count--;
+ request->pause_time = (int)time(NULL);
+ } else {
+ if (request->group != NULL )
+ request->group->queued_count--;
+
+ if (request->auto_notification == 1 &&
+ request->packagename != NULL) {
+ request->noti_priv_id = dp_set_downloadedinfo_notification
+ (request->noti_priv_id, request->id,
+ request->packagename, request->state);
+
+ } else {
+ int noti_type = dp_db_get_int_column(request->id,
+ DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+ if (noti_type > DP_NOTIFICATION_TYPE_NONE &&
+ request->packagename != NULL)
+ request->noti_priv_id = dp_set_downloadedinfo_notification
+ (request->noti_priv_id, request->id,
+ request->packagename, request->state);
+ }
+
+ request->stop_time = (int)time(NULL);
+ }
+}
dp_group_slots *dp_client_group_slots_new(int size)
{
- TRACE_INFO("");
dp_group_slots *slots = NULL;
if (size <= 0)
return NULL;
dp_request_slots *dp_request_slots_new(int size)
{
- TRACE_INFO("");
+ int i = 0;
dp_request_slots *slots = NULL;
if (size <= 0)
return NULL;
slots = (dp_request_slots *) calloc(size,
sizeof(dp_request_slots));
+ for (; i < size; i++)
+ CLIENT_MUTEX_INIT(&slots[i].mutex, NULL);
return slots;
}
void dp_request_init(dp_request *request)
{
- TRACE_INFO("");
- if (!request)
+ if (request == NULL)
return ;
request->id = -1;
sizeof(dp_request));
if (!request)
return NULL;
- CLIENT_MUTEX_INIT(&(request->mutex), NULL);
dp_request_init(request);
return request;
}
-int dp_request_free(dp_request *request)
+int dp_request_slot_free(dp_request_slots *request_slot)
{
- TRACE_INFO("");
+ if (request_slot == NULL)
+ return -1;
+ CLIENT_MUTEX_LOCK(&request_slot->mutex);
+ dp_request_free(request_slot->request);
+ request_slot->request = NULL;
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+ return 0;
+}
- if (!request)
+int dp_request_free(dp_request *request)
+{
+ if (request == NULL)
return -1;
- CLIENT_MUTEX_LOCK(&(request->mutex));
- if (request->packagename)
- free(request->packagename);
+ free(request->packagename);
dp_request_init(request);
- CLIENT_MUTEX_UNLOCK(&(request->mutex));
- CLIENT_MUTEX_DESTROY(&(request->mutex));
free(request);
return 0;
}
int dp_client_group_free(dp_client_group *group)
{
- TRACE_INFO("");
if (group != NULL) {
if (group->cmd_socket > 0)
dp_socket_free(group->cmd_socket);
group->event_socket = -1;
group->queued_count = 0;
free(group->pkgname);
+ free(group->smack_label);
free(group);
}
return 0;
int dp_client_group_slots_free(dp_group_slots *slots, int size)
{
- TRACE_INFO("");
int i = 0;
if (slots) {
for (; i < size; i++) {
int dp_request_slots_free(dp_request_slots *slots, int size)
{
- TRACE_INFO("");
int i = 0;
- if (slots) {
+ if (slots != NULL) {
for (; i < size; i++) {
- if (slots->request)
- dp_request_free(slots->request);
- slots->request = NULL;
+ dp_request_free(slots[i].request);
+ slots[i].request = NULL;
+ CLIENT_MUTEX_DESTROY(&slots[i].mutex);
}
free(slots);
}
if (!slots)
return -1;
- for (i = 0; i < DP_MAX_REQUEST; i++)
- if (slots[i].request)
+ for (i = 0; i < DP_MAX_REQUEST; i++) {
+ if (slots[i].request != NULL)
count++;
+ }
return count;
}
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
-
+#include <systemd/sd-daemon.h>
#include <signal.h>
#include "download-provider.h"
char *dp_ipc_read_string(int fd)
{
unsigned length = 0;
+ size_t recv_size = 0;
+ unsigned remain_size = 0;
+ size_t buffer_size = 0;
char *str = NULL;
if (fd < 0) {
}
// read flexible URL from client.
- if (read(fd, &length, sizeof(unsigned)) < 0) {
+ ssize_t recv_bytes = read(fd, &length, sizeof(unsigned));
+ if (recv_bytes < 0) {
TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
return NULL;
}
return NULL;
}
str = (char *)calloc((length + 1), sizeof(char));
- if (read(fd, str, length * sizeof(char)) < 0) {
- TRACE_STRERROR("[ERROR] read FD[%d]", fd);
+ if (str == NULL) {
+ TRACE_STRERROR("[ERROR] calloc length:%d FD[%d]", length, fd);
+ return NULL;
+ }
+ remain_size = length;
+ do {
+ buffer_size = 0;
+ if (remain_size > DP_DEFAULT_BUFFER_SIZE)
+ buffer_size = DP_DEFAULT_BUFFER_SIZE;
+ else
+ buffer_size = remain_size;
+ recv_size = (size_t)read(fd, str + (int)(length - remain_size),
+ buffer_size * sizeof(char));
+ if (recv_size > DP_DEFAULT_BUFFER_SIZE) {
+ recv_size = -1;
+ break;
+ }
+ if (recv_size > 0)
+ remain_size = remain_size - (unsigned)recv_size;
+ } while (recv_size > 0 && remain_size > 0);
+
+ if (recv_size == 0) {
+ TRACE_STRERROR("[ERROR] closed peer:%d", fd);
free(str);
- str = NULL;
return NULL;
}
str[length] = '\0';
return str;
}
+
+// 0 : Socket Error
+// -1 : Invalid type
+unsigned dp_ipc_read_bundle(int fd, int *type, bundle_raw **b)
+{
+ unsigned length = 0;
+ size_t recv_size = 0;
+ unsigned remain_size = 0;
+ size_t buffer_size = 0;
+ bundle_raw *b_raw = NULL;
+
+ if (fd < 0) {
+ TRACE_ERROR("[ERROR] CHECK FD[%d]", fd);
+ return 0;
+ }
+
+ // read flexible URL from client.
+ ssize_t recv_bytes = read(fd, type, sizeof(int));
+ if (recv_bytes < 0) {
+ TRACE_STRERROR("[ERROR] read FD[%d] type[%d]", fd, type);
+ return 0;
+ }
+ if ((*type) != DP_NOTIFICATION_BUNDLE_TYPE_ONGOING &&
+ (*type) != DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE &&
+ (*type) != DP_NOTIFICATION_BUNDLE_TYPE_FAILED) {
+ TRACE_ERROR("[NOTI TYPE] [%d]", *type);
+ return -1;
+ }
+ // read flexible URL from client.
+ recv_bytes = read(fd, &length, sizeof(unsigned));
+ if (recv_bytes < 0) {
+ TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
+ return 0;
+ }
+ if (length < 1 || length > DP_MAX_URL_LEN) {
+ TRACE_ERROR("[STRING LEGNTH] [%d]", length);
+ return 0;
+ }
+ b_raw = (bundle_raw *)calloc(length, 1);
+ if (b_raw == NULL) {
+ TRACE_STRERROR("[ERROR] calloc length:%d FD[%d]", length, fd);
+ return 0;
+ }
+ remain_size = length;
+ do {
+ buffer_size = 0;
+ if (remain_size > DP_DEFAULT_BUFFER_SIZE)
+ buffer_size = DP_DEFAULT_BUFFER_SIZE;
+ else
+ buffer_size = remain_size;
+ recv_size = (size_t)read(fd, b_raw + (int)(length - remain_size),
+ buffer_size * sizeof(char));
+ if (recv_size > DP_DEFAULT_BUFFER_SIZE) {
+ recv_size = -1;
+ break;
+ }
+ if (recv_size > 0)
+ remain_size = remain_size - (unsigned)recv_size;
+ } while (recv_size > 0 && remain_size > 0);
+
+ if (recv_size <= 0) {
+ TRACE_STRERROR("[ERROR] closed peer:%d", fd);
+ bundle_free_encoded_rawdata(&b_raw);
+ return 0;
+ }
+ *b = b_raw;
+ return length;
+}
+
// keep the order/ unsigned , str
int dp_ipc_send_string(int fd, const char *str)
{
return 0;
}
+int dp_ipc_send_bundle(int fd, bundle_raw *b, unsigned length)
+{
+ if (fd < 0) {
+ TRACE_ERROR("[ERROR] CHECK FD[%d]", fd);
+ return -1;
+ }
+ if (b == NULL) {
+ TRACE_ERROR("[ERROR] CHECK STRING FD[%d]", fd);
+ return -1;
+ }
+
+ if (length < 1) {
+ TRACE_ERROR("[ERROR] CHECK LENGTH FD[%d]", fd);
+ return -1;
+ }
+ if (fd >= 0 && write(fd, &length, sizeof(unsigned)) <= 0) {
+ TRACE_STRERROR("[ERROR] read FD[%d] length[%d]", fd, length);
+ return -1;
+ }
+ if (fd >= 0 && write(fd, b, length) <= 0) {
+ TRACE_STRERROR("[ERROR] write FD[%d]", fd);
+ return -1;
+ }
+ return 0;
+}
+
int dp_ipc_send_custom_type(int fd, void *value, size_t type_size)
{
if (fd < 0) {
return -1;
}
- if (read(fd, value, type_size) < 0) {
+ ssize_t recv_bytes = read(fd, value, type_size);
+ if (recv_bytes < 0) {
TRACE_STRERROR("[ERROR] read FD[%d]", fd);
return -1;
}
int sockfd = -1;
struct sockaddr_un listenaddr;
- if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- TRACE_STRERROR("failed to create socket");
+ int n = sd_listen_fds(1);
+ if (n > 1) {
+ TRACE_STRERROR("too many file descriptors received");
return -1;
- }
+ } else if (n == 1) {
+ int r;
+ if ((r = sd_is_socket_unix(SD_LISTEN_FDS_START, SOCK_STREAM, 1, DP_IPC, 0)) <= 0) {
+ TRACE_STRERROR("passed systemd file descriptor is of wrong type");
+ return -1;
+ }
+ sockfd = SD_LISTEN_FDS_START + 0;
+ } else {
+ if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ TRACE_STRERROR("failed to create socket");
+ return -1;
+ }
- bzero(&listenaddr, sizeof(listenaddr));
- listenaddr.sun_family = AF_UNIX;
- strcpy(listenaddr.sun_path, DP_IPC);
+ bzero(&listenaddr, sizeof(listenaddr));
+ listenaddr.sun_family = AF_UNIX;
+ strcpy(listenaddr.sun_path, DP_IPC);
- if (bind(sockfd, (struct sockaddr *)&listenaddr, sizeof listenaddr) !=
- 0) {
- TRACE_STRERROR("[CRITICAL] bind");
- close(sockfd);
- return -1;
- }
+ if (bind(sockfd, (struct sockaddr *)&listenaddr, sizeof listenaddr) !=
+ 0) {
+ TRACE_STRERROR("[CRITICAL] bind");
+ close(sockfd);
+ return -1;
+ }
- if (chmod(listenaddr.sun_path, 0777) < 0) {
- TRACE_STRERROR("[CRITICAL] chmod");
- close(sockfd);
- return -1;
- }
+ if (chmod(listenaddr.sun_path, 0777) < 0) {
+ TRACE_STRERROR("[CRITICAL] chmod");
+ close(sockfd);
+ return -1;
+ }
- // need 3 socket per a group
- if (listen(sockfd, DP_MAX_GROUP * 3) != 0) {
- TRACE_STRERROR("[CRITICAL] listen");
- close(sockfd);
- return -1;
+ // need 3 socket per a group
+ if (listen(sockfd, DP_MAX_GROUP * 3) != 0) {
+ TRACE_STRERROR("[CRITICAL] listen");
+ close(sockfd);
+ return -1;
+ }
}
return sockfd;
}
int dp_socket_free(int sockfd)
{
- TRACE_INFO("[%d]", sockfd);
+ TRACE_DEBUG("[%d]", sockfd);
if (sockfd < 0)
return -1;
shutdown(sockfd, 0);
#include <signal.h>
+#include <pthread.h>
+
#include "download-provider.h"
#include "download-provider-log.h"
#include "download-provider-config.h"
unsigned count = 0;
unsigned i = 0;
- if (!requests)
+ if (requests == NULL)
return 0;
for (i = 0; i < DP_MAX_REQUEST; i++) {
- if (requests[i].request) {
- if (requests[i].request->state == DP_STATE_CONNECTING ||
- requests[i].request->state == DP_STATE_DOWNLOADING)
- count++;
+ int locked = pthread_mutex_trylock(&requests[i].mutex);
+ // locking failure means it used by other thread.
+ if (locked == 0) {
+ if (requests[i].request != NULL) {
+ if (requests[i].request->state == DP_STATE_CONNECTING ||
+ requests[i].request->state == DP_STATE_DOWNLOADING)
+ count++;
+ }
+ CLIENT_MUTEX_UNLOCK(&requests[i].mutex);
}
}
return count;
oldest_time++; // most last time
int oldest_index = -1;
- if (!requests)
+ if (requests == NULL)
return -1;
for (i = 0; i < DP_MAX_REQUEST; i++) {
- if (requests[i].request != NULL) {
- if (requests[i].request->state == state &&
- requests[i].request->start_time > 0 &&
- requests[i].request->start_time < oldest_time &&
- __is_matched_network
- (now_state, requests[i].request->network_type) == 0) {
- oldest_time = requests[i].request->start_time;
- oldest_index = i;
+ int locked = pthread_mutex_trylock(&requests[i].mutex);
+ // locking failure means it used by other thread.
+ if (locked == 0) {
+ if (requests[i].request != NULL) {
+ if (requests[i].request->state == state &&
+ requests[i].request->start_time > 0 &&
+ requests[i].request->start_time < oldest_time &&
+ __is_matched_network(now_state,
+ requests[i].request->network_type) == 0) {
+ oldest_time = requests[i].request->start_time;
+ oldest_index = i;
+ }
}
+ CLIENT_MUTEX_UNLOCK(&requests[i].mutex);
}
}
return oldest_index;
dp_error_type errcode = DP_ERROR_NONE;
dp_request_slots *request_slot = (dp_request_slots *) args;
- if (request_slot == NULL || request_slot->request == NULL) {
- TRACE_ERROR("[NULL-CHECK] download_clientinfo_slot");
+ if (request_slot == NULL) {
+ TRACE_ERROR("[NULL-CHECK] request_slot");
+ pthread_exit(NULL);
+ return 0;
+ }
+
+ CLIENT_MUTEX_LOCK(&request_slot->mutex);
+
+ if (request_slot->request == NULL) {
+ TRACE_ERROR("[NULL-CHECK] request");
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
pthread_exit(NULL);
return 0;
}
+
dp_request *request = request_slot->request;
if (dp_is_alive_download(request->agent_id)) {
// call agent start function
errcode = dp_start_agent_download(request_slot);
}
-
- CLIENT_MUTEX_LOCK(&(request->mutex));
// send to state callback.
if (errcode == DP_ERROR_NONE) {
// CONNECTING
// FAILED
request->state = DP_STATE_FAILED;
request->error = DP_ERROR_CONNECTION_FAILED;
- dp_ipc_send_event(request->group->event_socket,
- request->id, request->state, request->error, 0);
- dp_thread_queue_manager_wake_up();
+ if (request->group != NULL &&
+ request->group->event_socket >= 0) {
+ dp_ipc_send_event(request->group->event_socket,
+ request->id, request->state, request->error, 0);
+ }
+ } else if (errcode == DP_ERROR_INVALID_STATE) {
+ // API FAILED
+ request->error = DP_ERROR_INVALID_STATE;
+ if (request->group != NULL &&
+ request->group->event_socket >= 0) {
+ dp_ipc_send_event(request->group->event_socket,
+ request->id, request->state, request->error, 0);
+ }
} else {
request->state = DP_STATE_FAILED;
request->error = errcode;
- dp_ipc_send_event(request->group->event_socket,
- request->id, request->state, request->error, 0);
- dp_thread_queue_manager_wake_up();
+ if (request->group != NULL &&
+ request->group->event_socket >= 0) {
+ dp_ipc_send_event(request->group->event_socket,
+ request->id, request->state, request->error, 0);
+ }
}
- if (dp_db_set_column
- (request->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &request->state) < 0)
+ if (dp_db_request_update_status(request->id, request->state, request->error) < 0) {
TRACE_ERROR("[ERROR][%d][SQL]", request->id);
+ }
+
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
+
+ if (errcode == DP_ERROR_NONE) {
+ TRACE_DEBUG("try other requests -----------------");
+ dp_thread_queue_manager_wake_up();
+ }
- CLIENT_MUTEX_UNLOCK(&(request->mutex));
pthread_exit(NULL);
return 0;
}
pthread_t thread_pid;
pthread_attr_t thread_attr;
- TRACE_INFO("");
if (request_slot == NULL || request_slot->request == NULL) {
TRACE_ERROR("[CRITICAL] Invalid Address");
return -1;
void dp_thread_queue_manager_wake_up()
{
- TRACE_INFO("");
CLIENT_MUTEX_LOCK(&(g_dp_queue_mutex));
pthread_cond_signal(&g_dp_queue_cond);
CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
dp_client_group *group = NULL;
dp_request *request = NULL;
- TRACE_INFO("Start Queue Thread");
-
dp_privates *privates = (dp_privates*)arg;
if (!privates) {
TRACE_ERROR("[CRITICAL] Invalid Address");
CLIENT_MUTEX_LOCK(&(g_dp_queue_mutex));
pthread_cond_wait(&g_dp_queue_cond, &g_dp_queue_mutex);
+ // request thread response instantly
+ CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
+
if (privates == NULL || privates->requests == NULL ||
privates->listen_fd < 0) {
- TRACE_INFO("Terminate Thread");
- CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
+ TRACE_DEBUG("Terminate Thread");
break;
}
if (privates->network_status == DP_NETWORK_TYPE_OFF &&
privates->is_connected_wifi_direct == 0) {
- TRACE_INFO("[CHECK NETWORK STATE]");
- CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
+ TRACE_DEBUG("[CHECK NETWORK STATE]");
continue;
}
active_count = __get_active_count(privates->requests);
+ TRACE_DEBUG("Status Queue: now active[%d] max[%d]",
+ active_count, DP_MAX_DOWNLOAD_AT_ONCE);
+
// Start Conditions
// 1. state is QUEUED
// 2. 1 QUEUED per 1 Group : need not to check max limitation.!!
// guarantee 1 instant download per 1 group
if (active_count >= DP_MAX_DOWNLOAD_AT_ONCE) {
for (i = 0; i < DP_MAX_REQUEST; i++) {
+ CLIENT_MUTEX_LOCK(&privates->requests[i].mutex);
request = privates->requests[i].request;
- if (request && request->state == DP_STATE_QUEUED) {
+ if (request != NULL && request->state == DP_STATE_QUEUED) {
group = privates->requests[i].request->group;
if (group && group->queued_count == 1) {
if (__is_matched_network
request->network_type ==
DP_NETWORK_TYPE_WIFI_DIRECT)) {
if (__request_download_start_thread(&privates->requests[i]) == 0) {
- TRACE_INFO
+ TRACE_DEBUG
("[Guarantee Intant Download] Group [%s]", group->pkgname);
active_count++;
}
}
}
}
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
}
}
if (active_count >= DP_MAX_DOWNLOAD_AT_ONCE) {
- TRACE_INFO("[BUSY] Active[%d] Max[%d]",
+ TRACE_DEBUG("[BUSY] Active[%d] Max[%d]",
active_count, DP_MAX_DOWNLOAD_AT_ONCE);
- CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
continue;
}
i = __get_oldest_request_with_network(privates->requests,
DP_STATE_QUEUED, DP_NETWORK_TYPE_WIFI_DIRECT);
if (i >= 0) {
- TRACE_INFO("Found WIFI-Direct request %d", i);
- request = privates->requests[i].request;
+ TRACE_DEBUG("Found WIFI-Direct request %d", i);
if (__request_download_start_thread(&privates->requests[i]) == 0)
active_count++;
continue;
i = __get_oldest_request_with_network(privates->requests,
DP_STATE_QUEUED, privates->network_status);
if (i < 0) {
- TRACE_INFO
+ TRACE_DEBUG
("No Request now active[%d] max[%d]",
active_count, DP_MAX_DOWNLOAD_AT_ONCE);
break;
}
- TRACE_INFO("QUEUE Status now %d active %d/%d", i,
+ TRACE_DEBUG("QUEUE Status now %d active %d/%d", i,
active_count, DP_MAX_DOWNLOAD_AT_ONCE);
- request = privates->requests[i].request;
__request_download_start_thread(&privates->requests[i]);
active_count++;
}
- CLIENT_MUTEX_UNLOCK(&(g_dp_queue_mutex));
}
pthread_cond_destroy(&g_dp_queue_cond);
pthread_exit(NULL);
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <signal.h>
#include <app_manager.h>
+#include <sys/smack.h>
+#include <bundle.h>
#include "download-provider.h"
#include "download-provider-log.h"
#include "download-provider-db.h"
#include "download-provider-queue.h"
#include "download-provider-request.h"
+#include "download-provider-network.h"
#include "download-provider-da-interface.h"
+#include "download-provider-notification.h"
void dp_terminate(int signo);
return "SET_COMMAND_SOCKET";
case DP_CMD_SET_EVENT_SOCKET :
return "SET_EVENT_SOCKET";
+ case DP_CMD_SET_NOTIFICATION_BUNDLE:
+ return "SET_NOTIFICATION_BUNDLE";
+ case DP_CMD_SET_NOTIFICATION_TITLE:
+ return "SET_NOTIFICATION_TITLE";
+ case DP_CMD_SET_NOTIFICATION_DESCRIPTION:
+ return "SET_NOTIFICATION_DESCRIPTION";
+ case DP_CMD_SET_NOTIFICATION_TYPE:
+ return "SET_NOTIFICATION_TYPE";
+ case DP_CMD_GET_NOTIFICATION_BUNDLE:
+ return "GET_NOTIFICATION_BUNDLE";
+ case DP_CMD_GET_NOTIFICATION_TITLE:
+ return "GET_NOTIFICATION_TITLE";
+ case DP_CMD_GET_NOTIFICATION_DESCRIPTION:
+ return "GET_NOTIFICATION_DESCRIPTION";
+ case DP_CMD_GET_NOTIFICATION_TYPE:
+ return "GET_NOTIFICATION_TYPE";
default :
break;
}
size_t s1_len = 0;
size_t s2_len = 0;
- if (!s1 || !s2) {
+ if (s1 == NULL || s2 == NULL) {
TRACE_ERROR("[CHECK PARAM]");
return -1;
}
{
int i = 0;
- if (!slots)
+ if (slots == NULL)
return -1;
- for (i = 0; i < DP_MAX_REQUEST; i++)
- if (!slots[i].request)
+ for (i = 0; i < DP_MAX_REQUEST; i++) {
+ if (slots[i].request == NULL)
return i;
+ }
return -1;
}
return -1;
for (i = 0; i < DP_MAX_REQUEST; i++) {
- if (slots[i].request) {
- if (slots[i].request->id == id) {
+ if (slots[i].request != NULL) {
+ if (slots[i].request->id == id)
return i;
- }
}
}
return -1;
{
dp_request *request = NULL;
int i = 0;
- int state = DP_STATE_FAILED;
- int errorcode = DP_ERROR_CLIENT_DOWN;
-
- TRACE_INFO("");
for (i = 0; i < DP_MAX_REQUEST; i++) {
- if (privates->requests[i].request == NULL)
- continue;
- if (privates->requests[i].request->group == NULL)
- continue;
- if (privates->requests[i].request->id <= 0)
- continue;
- if (privates->requests[i].request->group != group)
+
+ CLIENT_MUTEX_LOCK(&privates->requests[i].mutex);
+
+ if (privates->requests[i].request == NULL) {
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
continue;
+ }
request = privates->requests[i].request;
- CLIENT_MUTEX_LOCK(&request->mutex);
+ if (request->group == NULL || request->id <= 0 ||
+ request->group != group) {
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+ continue;
+ }
// if stopped, paused or not started yet, clear request
if (__is_started(request->state) < 0) {
- TRACE_INFO("[FREE][%d] state[%s]", request->id,
+ TRACE_DEBUG("[FREE][%d] state[%s]", request->id,
dp_print_state(request->state));
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- dp_request_free(request);
- privates->requests[i].request = NULL;
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+ dp_request_slot_free(&privates->requests[i]);
continue;
}
// disconnect the request from group.
- TRACE_INFO("[DISCONNECT][%d] state:%s pkg:%s sock:%d",
+ TRACE_SECURE_DEBUG("[DISCONNECT][%d] state:%s pkg:%s sock:%d",
request->id, dp_print_state(request->state),
request->group->pkgname, request->group->cmd_socket);
request->group = NULL;
request->state_cb = 0;
request->progress_cb = 0;
- // care started requests (queued, connecting, downloading)
- int auto_download = dp_db_get_int_column(request->id,
- DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_AUTO_DOWNLOAD);
- if (auto_download <= 0) {
- // cancel the requests which not setted auto-downloading
- TRACE_INFO("[CLEAR][%d] no-auto state:%s",
- request->id, dp_print_state(request->state));
-
- if (dp_db_set_column(request->id, DP_DB_TABLE_LOG,
- DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) == 0) {
- if (dp_db_set_column(request->id, DP_DB_TABLE_LOG,
- DP_DB_COL_ERRORCODE, DP_DB_COL_TYPE_INT,
- &errorcode) < 0) {
- TRACE_ERROR("[fail][%d][sql] set error:%s",
- request->id, dp_print_errorcode(errorcode));
- }
- // regardless errorcode, if success to update the state.
- if (request->agent_id >= 0) {
- TRACE_INFO("[%d]cancel_agent(%d) state:%s error:%s",
- request->id, request->agent_id,
- dp_print_state(state),
- dp_print_errorcode(errorcode));
- if (dp_cancel_agent_download(request->agent_id) < 0)
- TRACE_INFO("[fail][%d]cancel_agent", request->id);
- }
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- dp_request_free(request);
- privates->requests[i].request = NULL;
- continue;
- } else {
- TRACE_ERROR("[fail][%d][sql] set state:%s", request->id,
- dp_print_state(state));
- }
- }
- CLIENT_MUTEX_UNLOCK(&request->mutex);
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
}
// clear this group
if (errorcode == DP_ERROR_NONE &&
(path != NULL && strlen(path) > 0) &&
dp_is_file_exist(path) == 0) {
- TRACE_INFO("[REMOVE][%d] TEMP FILE [%s]", id, path);
+ TRACE_SECURE_DEBUG("[REMOVE][%d] TEMP FILE [%s]", id, path);
if (unlink(path) != 0)
TRACE_STRERROR("[ERROR][%d] remove file", id);
}
free(path);
}
+static int __dp_check_valid_directory(dp_request *request, char *dir)
+{
+ int ret = -1;
+ int ret_val = 0;
+ char *dir_label = NULL;
+ struct stat dir_state;
+
+ ret_val = stat(dir, &dir_state);
+ if (ret_val == 0) {
+ dp_credential cred;
+ if (request->group == NULL) {
+ cred.uid = dp_db_cond_get_int(DP_DB_TABLE_GROUPS,
+ DP_DB_GROUPS_COL_UID,
+ DP_DB_GROUPS_COL_PKG,
+ DP_DB_COL_TYPE_TEXT, request->packagename);
+ cred.gid = dp_db_cond_get_int(DP_DB_TABLE_GROUPS,
+ DP_DB_GROUPS_COL_GID,
+ DP_DB_GROUPS_COL_PKG,
+ DP_DB_COL_TYPE_TEXT, request->packagename);
+ } else {
+ cred = request->group->credential;
+ }
+ if (dir_state.st_uid == cred.uid
+ && (dir_state.st_mode & (S_IRUSR | S_IWUSR))
+ == (S_IRUSR | S_IWUSR)) {
+ ret = 0;
+ } else if (dir_state.st_gid == cred.gid
+ && (dir_state.st_mode & (S_IRGRP | S_IWGRP))
+ == (S_IRGRP | S_IWGRP)) {
+ ret = 0;
+ } else if ((dir_state.st_mode & (S_IROTH | S_IWOTH))
+ == (S_IROTH | S_IWOTH)) {
+ ret = 0;
+ }
+ }
+
+ if (ret != 0)
+ return ret;
+
+ ret_val = smack_getlabel(dir, &dir_label, SMACK_LABEL_ACCESS);
+ if (ret_val != 0) {
+ TRACE_SECURE_ERROR("[ERROR][%d][SMACK ERROR]", request->id);
+ free(dir_label);
+ return -1;
+ }
+
+ char *smack_label = NULL;
+ if (request->group == NULL) {
+ // get smack_label from sql
+ smack_label = dp_db_cond_get_text(DP_DB_TABLE_GROUPS,
+ DP_DB_GROUPS_COL_SMACK_LABEL, DP_DB_GROUPS_COL_PKG,
+ DP_DB_COL_TYPE_TEXT, request->packagename);
+ if (smack_label != NULL) {
+ ret_val = smack_have_access(smack_label, dir_label, "rw");
+ free(smack_label);
+ }
+ } else {
+ if (request->group->smack_label != NULL) {
+ ret_val = smack_have_access(request->group->smack_label, dir_label, "rw");
+ }
+ }
+ if (ret_val == 0) {
+ TRACE_SECURE_ERROR("[ERROR][%d][SMACK NO RULE]", request->id);
+ ret = -1;
+ } else if (ret_val < 0){
+ TRACE_SECURE_ERROR("[ERROR][%d][SMACK ERROR]", request->id);
+ ret = -1;
+ }
+ free(dir_label);
+ return ret;
+}
+
static int __dp_call_cancel_agent(dp_request *request)
{
int ret = -1;
if (dp_cancel_agent_download(request->agent_id) == 0)
ret = 0;
} else {
- TRACE_INFO("[CHECK] agent-id");
+ TRACE_DEBUG("[CHECK] agent-id");
}
}
return ret;
TRACE_ERROR("[ERROR][%d] [DP_ERROR_IO_ERROR]", id);
ret = DP_ERROR_IO_ERROR;
} else {
- TRACE_INFO("[RECV] length %d", length);
+ TRACE_DEBUG("[RECV] length %d", length);
if (length <= 0) {
ret = DP_ERROR_INVALID_PARAMETER;
} else {
ret = DP_ERROR_IO_ERROR;
} else {
if (length > 1) {
- TRACE_INFO("[RECV] key : %s", key);
+ TRACE_SECURE_DEBUG("[RECV] key : %s", key);
// get values
values = (char **)calloc((length - 1), sizeof(char *));
if (values == NULL) {
// insert
if (dp_db_insert_columns(DP_DB_TABLE_NOTIFICATION,
conds_count, conds_p) < 0) {
- ret = DP_ERROR_OUT_OF_MEMORY;
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", id);
+ ret = DP_ERROR_NO_SPACE;
+ } else {
+ ret = DP_ERROR_OUT_OF_MEMORY;
+ }
break;
}
} // else skip. already exist
TRACE_ERROR("[ERROR][%d] [DP_ERROR_IO_ERROR]", id);
ret = DP_ERROR_IO_ERROR;
} else {
- TRACE_INFO("[RECV] length %d", length);
+ TRACE_DEBUG("[RECV] length %d", length);
if (length != 1) { // only a key
ret = DP_ERROR_INVALID_PARAMETER;
} else {
if (ret == DP_ERROR_NONE) {
if (dp_db_cond_remove(id, DP_DB_TABLE_NOTIFICATION,
DP_DB_COL_EXTRA_KEY, DP_DB_COL_TYPE_TEXT, key) < 0) {
- TRACE_ERROR("[fail][%d][sql] set key:%s", id, key);
+ TRACE_ERROR("[fail][%d][sql]", id);
+ TRACE_SECURE_ERROR("[fail]key:%s", key);
ret = DP_ERROR_OUT_OF_MEMORY;
}
}
- TRACE_ERROR
- ("[ERROR][%d][%s] key:%s", id, dp_print_errorcode(ret), key);
+ TRACE_DEBUG("[ERROR][%d][%s]", id, dp_print_errorcode(ret));
+ TRACE_SECURE_DEBUG("key:%s", key);
free(key);
return ret;
}
int i = 0;
struct timeval tv_timeo; // 2.5 sec
char *pkgname = NULL;
+ char *smack_label = NULL;
+ int ret = 0;
tv_timeo.tv_sec = 2;
tv_timeo.tv_usec = 500000;
// getting the package name via pid
if (app_manager_get_package(credential.pid, &pkgname) ==
APP_MANAGER_ERROR_NONE) {
- TRACE_INFO("package : %s", pkgname);
+ TRACE_SECURE_DEBUG("package : %s", pkgname);
} else
TRACE_ERROR("[CRITICAL] app_manager_get_package");
//// TEST CODE ... to allow sample client ( no package name ).
if (pkgname == NULL) {
pkgname = dp_strdup("unknown_app");
- TRACE_INFO("default package naming : %s", pkgname);
+ TRACE_DEBUG("default package naming : %s", pkgname);
}
if (pkgname == NULL) {
strncmp(groups[i].group->pkgname, pkgname,
pkg_len) == 0 ) {
// Found Same Group
- TRACE_INFO("UPDATE Group: slot:%d pid:%d sock:%d [%s]",
+ TRACE_SECURE_INFO("UPDATE Group: slot:%d pid:%d sock:%d [%s]",
i, credential.pid, clientfd, pkgname);
if (groups[i].group->cmd_socket > 0 &&
groups[i].group->cmd_socket != clientfd) {
free(pkgname);
return -1;
}
+
// fill info
groups[i].group->cmd_socket = clientfd;
groups[i].group->event_socket = -1;
groups[i].group->credential.pid = credential.pid;
groups[i].group->credential.uid = credential.uid;
groups[i].group->credential.gid = credential.gid;
- TRACE_INFO("New Group: slot:%d pid:%d sock:%d [%s]", i,
+
+ int conds_count = 4;
+ db_conds_list_fmt conds_p[conds_count];
+ memset(&conds_p, 0x00, conds_count * sizeof(db_conds_list_fmt));
+ conds_p[0].column = DP_DB_GROUPS_COL_UID;
+ conds_p[0].type = DP_DB_COL_TYPE_INT;
+ conds_p[0].value = &credential.uid;
+ conds_p[1].column = DP_DB_GROUPS_COL_GID;
+ conds_p[1].type = DP_DB_COL_TYPE_INT;
+ conds_p[1].value = &credential.gid;
+ conds_p[2].column = DP_DB_GROUPS_COL_PKG;
+ conds_p[2].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[2].value = pkgname;
+
+ if (dp_is_smackfs_mounted() == 1) {
+ ret = smack_new_label_from_socket(clientfd, &smack_label);
+ if (ret != 0) {
+ TRACE_ERROR("[CRITICAL] cannot get smack label");
+ free(pkgname);
+ free(smack_label);
+ return -1;
+ }
+ TRACE_SECURE_INFO("credential label:[%s]", smack_label);
+ groups[i].group->smack_label = smack_label;
+
+ conds_p[3].column = DP_DB_GROUPS_COL_SMACK_LABEL;
+ conds_p[3].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[3].value = smack_label;
+ } else {
+ conds_count = 3; // ignore smack label
+ groups[i].group->smack_label = NULL;
+ }
+
+ if (dp_db_insert_columns(DP_DB_TABLE_GROUPS, conds_count, conds_p) < 0) {
+ free(pkgname);
+ free(smack_label);
+ if (dp_db_is_full_error() == 0)
+ TRACE_ERROR("[SQLITE_FULL]");
+ return -1;
+ }
+
+ TRACE_SECURE_INFO("New Group: slot:%d pid:%d sock:%d [%s]", i,
credential.pid, clientfd, pkgname);
free(pkgname);
return 0;
{
int i = 0;
- TRACE_INFO("Check event pid:%d sock:%d", credential.pid, clientfd);
+ TRACE_DEBUG("Check event pid:%d sock:%d", credential.pid, clientfd);
// search same pid in groups
for (i = 0; i < DP_MAX_GROUP; i++) {
if (groups[i].group != NULL &&
groups[i].group->event_socket != clientfd)
dp_socket_free(groups[i].group->event_socket);
groups[i].group->event_socket = clientfd;
- TRACE_INFO
+ TRACE_SECURE_INFO
("Found Group : slot:%d pid:%d csock:%d esock:%d [%s]",
i, credential.pid, groups[i].group->cmd_socket,
clientfd, groups[i].group->pkgname);
return 0;
}
+static dp_error_type __dp_do_get_command(int sock, dp_command* cmd, dp_request *request)
+{
+ unsigned is_checked = 1;
+ dp_error_type errorcode = DP_ERROR_NONE;
+
+ char *read_str = NULL;
+ // No read(), write a string
+ switch(cmd->cmd) {
+ case DP_CMD_GET_URL:
+ read_str = dp_request_get_url(cmd->id, &errorcode);
+ break;
+ case DP_CMD_GET_DESTINATION:
+ read_str = dp_request_get_destination(cmd->id, request, &errorcode);
+ break;
+ case DP_CMD_GET_FILENAME:
+ read_str = dp_request_get_filename(cmd->id, request, &errorcode);
+ break;
+ case DP_CMD_GET_SAVED_PATH:
+ read_str = dp_request_get_savedpath(cmd->id, request, &errorcode);
+ break;
+ case DP_CMD_GET_TEMP_SAVED_PATH:
+ read_str = dp_request_get_tmpsavedpath(cmd->id, request, &errorcode);
+ break;
+ case DP_CMD_GET_MIME_TYPE:
+ read_str = dp_request_get_mimetype(cmd->id, request, &errorcode);
+ break;
+ case DP_CMD_GET_CONTENT_NAME:
+ read_str = dp_request_get_contentname(cmd->id, request, &errorcode);
+ break;
+ case DP_CMD_GET_ETAG:
+ read_str = dp_request_get_etag(cmd->id, request, &errorcode);
+ break;
+ case DP_CMD_GET_NOTIFICATION_TITLE:
+ read_str = dp_request_get_title(cmd->id, request, &errorcode);
+ break;
+ case DP_CMD_GET_NOTIFICATION_DESCRIPTION:
+ read_str = dp_request_get_description(cmd->id, request, &errorcode);
+ break;
+ default:
+ is_checked = 0;
+ break;
+ }
+ if (is_checked == 1) {
+ if (read_str == NULL || strlen(read_str) < 1)
+ errorcode = DP_ERROR_NO_DATA;
+ dp_ipc_send_errorcode(sock, errorcode);
+ if (errorcode == DP_ERROR_NONE) {
+ dp_ipc_send_string(sock, read_str);
+ } else {
+ TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+ __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+ }
+ free(read_str);
+ return errorcode;
+ }
+
+ // No read(), write a integer variable
+ int read_int = 0;
+ errorcode = DP_ERROR_NONE;
+ is_checked = 1;
+ switch(cmd->cmd) {
+ case DP_CMD_GET_NOTIFICATION:
+ read_int = dp_db_get_int_column(cmd->id, DP_DB_TABLE_REQUEST_INFO,
+ DP_DB_COL_NOTIFICATION_ENABLE);
+ break;
+ case DP_CMD_GET_AUTO_DOWNLOAD:
+ read_int = dp_db_get_int_column(cmd->id, DP_DB_TABLE_REQUEST_INFO,
+ DP_DB_COL_AUTO_DOWNLOAD);
+ break;
+ case DP_CMD_GET_NETWORK_TYPE:
+ read_int = dp_db_get_int_column(cmd->id, DP_DB_TABLE_REQUEST_INFO,
+ DP_DB_COL_NETWORK_TYPE);
+ break;
+ case DP_CMD_GET_HTTP_STATUS:
+ read_int = dp_db_get_int_column(cmd->id, DP_DB_TABLE_DOWNLOAD_INFO,
+ DP_DB_COL_HTTP_STATUS);
+ break;
+ case DP_CMD_GET_STATE:
+ if (request == NULL) {
+ read_int = dp_db_get_state(cmd->id);
+ } else {
+ read_int = request->state;
+ }
+ break;
+ case DP_CMD_GET_NOTIFICATION_TYPE:
+ TRACE_DEBUG("DP_CMD_GET_NOTIFICATION_TYPE");
+ read_int = dp_request_get_noti_type(cmd->id, request, &errorcode);
+ break;
+ case DP_CMD_GET_ERROR:
+ if (request == NULL) {
+ read_int = dp_db_get_int_column(cmd->id,
+ DP_DB_TABLE_LOG, DP_DB_COL_ERRORCODE);
+ } else {
+ read_int = request->error;
+ }
+ break;
+ default:
+ is_checked = 0;
+ break;
+ }
+ if (is_checked == 1) {
+ if (read_int < 0)
+ errorcode = DP_ERROR_NO_DATA;
+ dp_ipc_send_errorcode(sock, errorcode);
+ if (errorcode == DP_ERROR_NONE) {
+ dp_ipc_send_custom_type(sock, &read_int, sizeof(int));
+ } else {
+ TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+ __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+ }
+ return errorcode;
+ }
+
+ // No read(), write a long long variable
+ unsigned long long recv_long = 0;
+ errorcode = DP_ERROR_NONE;
+ is_checked = 1;
+ switch(cmd->cmd) {
+ case DP_CMD_GET_RECEIVED_SIZE:
+ if (request == NULL)
+ errorcode = DP_ERROR_NO_DATA;
+ else
+ recv_long = request->received_size;
+ break;
+ case DP_CMD_GET_TOTAL_FILE_SIZE:
+ if (request != NULL) {
+ recv_long = request->file_size;
+ } else {
+ long long file_size =
+ dp_db_get_int64_column(cmd->id,
+ DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_SIZE);
+ if (file_size < 0)
+ errorcode = DP_ERROR_NO_DATA;
+ else // casting
+ recv_long = file_size;
+ }
+ break;
+ default:
+ is_checked = 0;
+ break;
+ }
+ if (is_checked == 1) {
+ dp_ipc_send_errorcode(sock, errorcode);
+ if (errorcode == DP_ERROR_NONE) {
+ dp_ipc_send_custom_type(sock, &recv_long,
+ sizeof(unsigned long long));
+ } else {
+ TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+ __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+ }
+ return errorcode;
+ }
+
+ // No read(), write a bundle variable
+ bundle_raw *b_raw = NULL;
+ int length = -1;
+ char *column = NULL;
+ errorcode = DP_ERROR_NONE;
+ is_checked = 1;
+ switch(cmd->cmd) {
+ case DP_CMD_GET_NOTIFICATION_BUNDLE:
+ TRACE_DEBUG("DP_CMD_GET_NOTIFICATION_BUNDLE");
+ dp_ipc_send_errorcode(sock, DP_ERROR_NONE);
+ if ((dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0)) {
+ TRACE_ERROR("DP_CMD_GET_NOTIFICATION_BUNDLE read fail");
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ switch(read_int) {
+ case DP_NOTIFICATION_BUNDLE_TYPE_ONGOING:
+ column = DP_DB_COL_RAW_BUNDLE_ONGOING;
+ break;
+ case DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE:
+ column = DP_DB_COL_RAW_BUNDLE_COMPLETE;
+ break;
+ case DP_NOTIFICATION_BUNDLE_TYPE_FAILED:
+ column = DP_DB_COL_RAW_BUNDLE_FAIL;
+ break;
+ default:
+ TRACE_ERROR("[CHECK TYPE][%d]", read_int);
+ errorcode = DP_ERROR_INVALID_PARAMETER;
+ break;
+ }
+ b_raw = dp_request_get_bundle(cmd->id, request,
+ &errorcode, column, &length);
+ break;
+ default:
+ is_checked = 0;
+ break;
+ }
+ if (is_checked == 1) {
+ dp_ipc_send_errorcode(sock, errorcode);
+ if (errorcode == DP_ERROR_NONE) {
+ dp_ipc_send_bundle(sock, b_raw, length);
+ } else {
+ TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+ __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+ }
+ bundle_free_encoded_rawdata(&b_raw);
+ return errorcode;
+ }
+
+ dp_ipc_send_errorcode(sock, DP_ERROR_NONE);
+ // complex read() and write().
+ char *read_str2 = NULL;
+ errorcode = DP_ERROR_NONE;
+ read_str = NULL;
+ is_checked = 1;
+ switch(cmd->cmd) {
+ case DP_CMD_GET_HTTP_HEADER:
+ if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ read_str2 = dp_db_cond_get_text_column(cmd->id,
+ DP_DB_TABLE_HTTP_HEADERS, DP_DB_COL_HEADER_DATA,
+ DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT, read_str);
+ if (read_str2 == NULL)
+ errorcode = DP_ERROR_NO_DATA;
+ dp_ipc_send_errorcode(sock, errorcode);
+ if (errorcode == DP_ERROR_NONE)
+ dp_ipc_send_string(sock, read_str2);
+ break;
+ case DP_CMD_GET_HTTP_HEADER_LIST:
+ {
+ char **values = NULL;
+ unsigned rows_count = 0;
+ errorcode = __dp_get_http_header_fields(sock,
+ cmd->id, &values, &rows_count);
+ if (errorcode == DP_ERROR_NONE) {
+ __send_return_custom_type(sock, DP_ERROR_NONE,
+ &rows_count, sizeof(int));
+ // sending strings
+ int i = 0;
+ for (i = 0; i < rows_count; i++) {
+ if (dp_ipc_send_string(sock, values[i]) < 0)
+ break;
+ }
+ for (i = 0; i < rows_count; i++)
+ free(values[i]);
+ } else {
+ if (errorcode != DP_ERROR_IO_ERROR)
+ dp_ipc_send_errorcode(sock, errorcode);
+ }
+ free(values);
+ break;
+ }
+ case DP_CMD_GET_EXTRA_PARAM:
+ {
+ char **values = NULL;
+ unsigned rows_count = 0;
+ errorcode = __dp_get_extra_param_values(sock,
+ cmd->id, &values, &rows_count);
+ if (errorcode == DP_ERROR_NONE) {
+ __send_return_custom_type(sock, DP_ERROR_NONE,
+ &rows_count, sizeof(int));
+ // sending strings
+ int i = 0;
+ for (i = 0; i < rows_count; i++) {
+ if (dp_ipc_send_string(sock, values[i]) < 0)
+ break;
+ }
+ for (i = 0; i < rows_count; i++)
+ free(values[i]);
+ } else {
+ if (errorcode != DP_ERROR_IO_ERROR)
+ dp_ipc_send_errorcode(sock, errorcode);
+ }
+ free(values);
+ break;
+ }
+ default:
+ is_checked = 0;
+ break;
+ }
+ if (is_checked == 1) {
+ if (errorcode != DP_ERROR_NONE) {
+ TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+ __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+ }
+ free(read_str);
+ free(read_str2);
+ return errorcode;
+ }
+ return DP_ERROR_UNKNOWN;
+}
+
+static dp_error_type __dp_do_set_command(int sock, dp_command *cmd, dp_request *request)
+{
+ unsigned is_checked = 1;
+ int read_int = 0;
+ dp_error_type errorcode = DP_ERROR_NONE;
+ char *read_str = NULL;
+ bundle_raw *b_raw = NULL;
+ unsigned bundle_length = 0;
+ int noti_bundle_type = 0;
+
+ dp_ipc_send_errorcode(sock, DP_ERROR_NONE);
+ // read a interger or a string, return errorcode.
+ errorcode = DP_ERROR_NONE;
+ switch(cmd->cmd) {
+ case DP_CMD_SET_STATE_CALLBACK:
+ if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ errorcode = dp_request_set_state_event(cmd->id, request, read_int);
+ break;
+ case DP_CMD_SET_PROGRESS_CALLBACK:
+ if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ errorcode = dp_request_set_progress_event(cmd->id, request, read_int);
+ break;
+ case DP_CMD_SET_NETWORK_TYPE:
+ if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ if (read_int == DP_NETWORK_TYPE_ALL ||
+ read_int == DP_NETWORK_TYPE_WIFI ||
+ read_int == DP_NETWORK_TYPE_DATA_NETWORK ||
+ read_int == DP_NETWORK_TYPE_ETHERNET ||
+ read_int == DP_NETWORK_TYPE_WIFI_DIRECT)
+ errorcode = dp_request_set_network_type(cmd->id, request, read_int);
+ else
+ errorcode = DP_ERROR_INVALID_PARAMETER;
+ break;
+ case DP_CMD_SET_AUTO_DOWNLOAD:
+ if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ errorcode = dp_request_set_auto_download(cmd->id, request, read_int);
+ break;
+ case DP_CMD_SET_NOTIFICATION:
+ if (dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ errorcode = dp_request_set_notification(cmd->id, request, read_int);
+ break;
+ case DP_CMD_SET_URL:
+ if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ errorcode = dp_request_set_url(cmd->id, request, read_str);
+ break;
+ case DP_CMD_SET_DESTINATION:
+ if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ if (dp_is_smackfs_mounted() == 1 &&
+ __dp_check_valid_directory(request, read_str) != 0){
+ errorcode = DP_ERROR_PERMISSION_DENIED;
+ break;
+ }
+ errorcode = dp_request_set_destination(cmd->id, request, read_str);
+ break;
+ case DP_CMD_SET_FILENAME:
+ if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ errorcode = dp_request_set_filename(cmd->id, request, read_str);
+ break;
+ case DP_CMD_SET_NOTIFICATION_BUNDLE:
+ bundle_length = dp_ipc_read_bundle(sock, ¬i_bundle_type, &b_raw);
+ if (bundle_length == 0) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ } else if (bundle_length == -1) {
+ errorcode = DP_ERROR_INVALID_PARAMETER;
+ break;
+ }
+ errorcode = dp_request_set_bundle(cmd->id, request,
+ noti_bundle_type, b_raw, bundle_length);
+ break;
+ case DP_CMD_SET_NOTIFICATION_TITLE:
+ if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ errorcode = dp_request_set_title(cmd->id, request, read_str);
+ break;
+ case DP_CMD_SET_NOTIFICATION_DESCRIPTION:
+ if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ errorcode = dp_request_set_description(cmd->id, request, read_str);
+ break;
+ case DP_CMD_SET_NOTIFICATION_TYPE:
+ if ((dp_ipc_read_custom_type(sock, &read_int, sizeof(int)) < 0)) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ if (read_int == DP_NOTIFICATION_TYPE_NONE ||
+ read_int == DP_NOTIFICATION_TYPE_COMPLETE_ONLY ||
+ read_int == DP_NOTIFICATION_TYPE_ALL)
+ errorcode = dp_request_set_noti_type(cmd->id, request, read_int);
+ else
+ errorcode = DP_ERROR_INVALID_PARAMETER;
+ break;
+ default:
+ is_checked = 0;
+ break;
+ }
+ if (is_checked == 1) {
+ free(read_str);
+ bundle_free_encoded_rawdata(&b_raw);
+ if (errorcode != DP_ERROR_NONE) {
+ TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+ __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+ }
+ if (errorcode == DP_ERROR_IO_ERROR)
+ return errorcode;
+ dp_ipc_send_errorcode(sock, errorcode);
+ return errorcode;
+ }
+
+ // complex read() and write().
+ char *read_str2 = NULL;
+ errorcode = DP_ERROR_NONE;
+ read_str = NULL;
+ is_checked = 1;
+ switch(cmd->cmd) {
+ case DP_CMD_SET_HTTP_HEADER:
+ {
+ if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ if ((read_str2 = dp_ipc_read_string(sock)) == NULL) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ int conds_count = 3; // id + field + data
+ db_conds_list_fmt conds_p[conds_count];
+ memset(&conds_p, 0x00,
+ conds_count * sizeof(db_conds_list_fmt));
+ conds_p[0].column = DP_DB_COL_ID;
+ conds_p[0].type = DP_DB_COL_TYPE_INT;
+ conds_p[0].value = &cmd->id;
+ conds_p[1].column = DP_DB_COL_HEADER_FIELD;
+ conds_p[1].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[1].value = read_str;
+ conds_p[2].column = DP_DB_COL_HEADER_DATA;
+ conds_p[2].type = DP_DB_COL_TYPE_TEXT;
+ conds_p[2].value = read_str2;
+ if (dp_db_get_conds_rows_count(DP_DB_TABLE_HTTP_HEADERS,
+ DP_DB_COL_ID, "AND", 2, conds_p) <= 0) { // insert
+ if (dp_db_insert_columns(DP_DB_TABLE_HTTP_HEADERS,
+ conds_count, conds_p) < 0) {
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", cmd->id);
+ errorcode = DP_ERROR_NO_SPACE;
+ } else {
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ }
+ }
+ } else { // update data by field
+ if (dp_db_cond_set_column(cmd->id, DP_DB_TABLE_HTTP_HEADERS,
+ DP_DB_COL_HEADER_DATA, DP_DB_COL_TYPE_TEXT, read_str2,
+ DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT, read_str) < 0) {
+ if (dp_db_is_full_error() == 0) {
+ TRACE_ERROR("[SQLITE_FULL][%d]", cmd->id);
+ errorcode = DP_ERROR_NO_SPACE;
+ } else {
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ }
+ }
+ }
+ dp_ipc_send_errorcode(sock, errorcode);
+ break;
+ }
+ case DP_CMD_DEL_HTTP_HEADER:
+ if ((read_str = dp_ipc_read_string(sock)) == NULL) {
+ errorcode = DP_ERROR_IO_ERROR;
+ break;
+ }
+ if (dp_db_get_cond_rows_count(cmd->id, DP_DB_TABLE_HTTP_HEADERS,
+ DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT,
+ read_str) <= 0) {
+ errorcode = DP_ERROR_NO_DATA;
+ } else {
+ if (dp_db_cond_remove(cmd->id, DP_DB_TABLE_HTTP_HEADERS,
+ DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT, read_str) < 0)
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ }
+ dp_ipc_send_errorcode(sock, errorcode);
+ break;
+ case DP_CMD_ADD_EXTRA_PARAM:
+ errorcode = __dp_add_extra_param(sock, cmd->id);
+ if (errorcode != DP_ERROR_IO_ERROR)
+ dp_ipc_send_errorcode(sock, errorcode);
+ break;
+ case DP_CMD_REMOVE_EXTRA_PARAM:
+ errorcode = __dp_remove_extra_param(sock, cmd->id);
+ if (errorcode != DP_ERROR_IO_ERROR)
+ dp_ipc_send_errorcode(sock, errorcode);
+ break;
+ default:
+ is_checked = 0;
+ break;
+ }
+ if (is_checked == 1) {
+ if (errorcode != DP_ERROR_NONE) {
+ TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+ __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+ }
+ free(read_str);
+ free(read_str2);
+ return errorcode;
+ }
+ return DP_ERROR_UNKNOWN;
+}
+
+static dp_error_type __dp_do_action_command(int sock, dp_command* cmd, dp_request *request)
+{
+ unsigned is_checked = 1;
+ int read_int = 0;
+ dp_error_type errorcode = DP_ERROR_NONE;
+
+ read_int = 0;
+ errorcode = DP_ERROR_NONE;
+ is_checked = 1;
+ switch(cmd->cmd) {
+ case DP_CMD_DESTROY:
+ if (request != NULL) {// just update the state
+ if (__is_started(request->state) == 0) {
+ read_int = DP_STATE_CANCELED;
+ if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
+ DP_DB_COL_TYPE_INT, &read_int) < 0) {
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ } else {
+ if (__dp_call_cancel_agent(request) < 0)
+ TRACE_ERROR("[fail][%d]cancel_agent", cmd->id);
+ request->state = DP_STATE_CANCELED;
+ if (request->auto_notification == 1 &&
+ request->packagename != NULL) {
+ request->noti_priv_id = dp_set_downloadedinfo_notification
+ (request->noti_priv_id, request->id,
+ request->packagename, request->state);
+ } else {
+ int noti_type = dp_db_get_int_column(request->id,
+ DP_DB_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE);
+ if (noti_type > DP_NOTIFICATION_TYPE_NONE &&
+ request->packagename != NULL)
+ request->noti_priv_id = dp_set_downloadedinfo_notification
+ (request->noti_priv_id, request->id,
+ request->packagename, request->state);
+ }
+ }
+ }
+ }
+ break;
+ case DP_CMD_PAUSE:
+ {
+ // to check fastly, divide the case by request value
+ if (request == NULL) {
+ dp_state_type state = dp_db_get_state(cmd->id);
+ // already paused or stopped
+ if (state > DP_STATE_DOWNLOADING) {
+ errorcode = DP_ERROR_INVALID_STATE;
+ } else {
+ // change state to paused.
+ state = DP_STATE_PAUSED;
+ if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG,
+ DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) < 0)
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ }
+ break;
+ }
+
+ if (request->state > DP_STATE_DOWNLOADING) {
+ errorcode = DP_ERROR_INVALID_STATE;
+ break;
+ }
+
+ // before downloading including QUEUED
+ if (__is_downloading(request->state) < 0) {
+ dp_state_type state = DP_STATE_PAUSED;
+ if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
+ DP_DB_COL_TYPE_INT, &state) < 0) {
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ } else {
+ request->state = state;
+ }
+ break;
+ }
+ // only downloading.
+ dp_state_type state = DP_STATE_PAUSE_REQUESTED;
+ if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG,
+ DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) < 0) {
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ } else {
+ TRACE_INFO("[%s][%d]pause_agent(%d) state:%s",
+ __print_command(cmd->cmd), cmd->id,
+ request->agent_id,
+ dp_print_state(request->state));
+ if (dp_pause_agent_download
+ (request->agent_id) < 0) {
+ TRACE_ERROR("[fail][%d]pause_agent(%d)",
+ cmd->id, request->agent_id);
+ }
+ request->state = state;
+ request->error = DP_ERROR_NONE;
+ request->pause_time = (int)time(NULL);
+ dp_db_update_date(cmd->id, DP_DB_TABLE_LOG,
+ DP_DB_COL_ACCESS_TIME);
+ }
+ break;
+ }
+ case DP_CMD_CANCEL:
+ {
+ // to check fastly, divide the case by request value
+ if (request == NULL) {
+ dp_state_type state = dp_db_get_state(cmd->id);
+ // already paused or stopped
+ if (__is_stopped(state) == 0) {
+ errorcode = DP_ERROR_INVALID_STATE;
+ } else {
+ // change state to canceled.
+ state = DP_STATE_CANCELED;
+ if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG,
+ DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) < 0)
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ }
+ break;
+ }
+
+ if (__is_stopped(request->state) == 0) {
+ TRACE_ERROR("[%s][%d]__is_stopped agentid:%d state:%s",
+ __print_command(cmd->cmd), cmd->id,
+ request->agent_id, dp_print_state(request->state));
+ errorcode = DP_ERROR_INVALID_STATE;
+ } else {
+ // change state to canceled.
+ dp_state_type state = DP_STATE_CANCELED;
+ if (dp_db_set_column(cmd->id, DP_DB_TABLE_LOG, DP_DB_COL_STATE,
+ DP_DB_COL_TYPE_INT, &state) < 0)
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ }
+ if (errorcode == DP_ERROR_NONE) {
+ if (__dp_call_cancel_agent(request) < 0)
+ TRACE_ERROR("[fail][%d]cancel_agent", cmd->id);
+ request->state = DP_STATE_CANCELED;
+ }
+ dp_db_update_date(cmd->id, DP_DB_TABLE_LOG, DP_DB_COL_ACCESS_TIME);
+ break;
+ }
+ default:
+ is_checked = 0;
+ break;
+ }
+ if (is_checked == 1) {
+ if (errorcode != DP_ERROR_NONE) {
+ TRACE_ERROR("[ERROR][%d][%s][%s]", cmd->id,
+ __print_command(cmd->cmd), dp_print_errorcode(errorcode));
+ }
+ dp_ipc_send_errorcode(sock, errorcode);
+ return errorcode;
+ }
+ return DP_ERROR_UNKNOWN;
+}
+
+static dp_error_type __do_dp_start_command(int sock, int id, dp_privates *privates,
+ dp_client_group *group, dp_request *request)
+{
+ dp_error_type errorcode = DP_ERROR_NONE;
+
+ // need URL at least
+ char *url = dp_request_get_url(id, &errorcode);
+ free(url);
+ if (errorcode == DP_ERROR_NO_DATA) {
+ errorcode = DP_ERROR_INVALID_URL;
+ dp_ipc_send_errorcode(sock, errorcode);
+ return errorcode;
+ }
+
+ if (request == NULL) { // Support Re-download
+ // Support Re-download
+ int index = __get_empty_request_index(privates->requests);
+ if (index < 0) { // Busy, No Space in slot
+ errorcode = DP_ERROR_QUEUE_FULL;
+ TRACE_SECURE_ERROR("[ERROR][%d][RESTORE][%s]", id,
+ dp_print_errorcode(errorcode));
+ } else {
+ CLIENT_MUTEX_LOCK(&privates->requests[index].mutex);
+ dp_request *tmp_request =
+ dp_request_load_from_log (id, &errorcode);
+ if (tmp_request != NULL) {
+ // restore callback info
+ tmp_request->state_cb = dp_db_get_int_column(id,
+ DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_STATE_EVENT);
+ tmp_request->progress_cb = dp_db_get_int_column(id,
+ DP_DB_TABLE_REQUEST_INFO, DP_DB_COL_PROGRESS_EVENT);
+ tmp_request->auto_notification =
+ dp_db_get_int_column(id, DP_DB_TABLE_REQUEST_INFO,
+ DP_DB_COL_NOTIFICATION_ENABLE);
+ if (group != NULL) // for send event to client
+ tmp_request->group = group;
+ privates->requests[index].request = tmp_request;
+ request = privates->requests[index].request;
+ } else {
+ TRACE_SECURE_ERROR("[ERROR][%d][RESTORE][%s]", id,
+ dp_print_errorcode(errorcode));
+ dp_ipc_send_errorcode(sock, errorcode);
+ CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
+ return errorcode;
+ }
+ CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
+ }
+ }
+
+ // check status
+ if (errorcode == DP_ERROR_NONE &&
+ (__is_started(request->state) == 0 ||
+ request->state == DP_STATE_COMPLETED))
+ errorcode = DP_ERROR_INVALID_STATE;
+
+ if (errorcode == DP_ERROR_NONE) {
+
+ dp_state_type state = DP_STATE_QUEUED;
+ if (dp_db_set_column(id, DP_DB_TABLE_LOG,
+ DP_DB_COL_STATE, DP_DB_COL_TYPE_INT, &state) < 0) {
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ } else {
+ if (group != NULL)
+ group->queued_count++;
+ request->start_time = (int)time(NULL);
+ request->pause_time = 0;
+ request->stop_time = 0;
+ request->state = state;
+ request->error = DP_ERROR_NONE;
+ dp_db_update_date(id, DP_DB_TABLE_LOG, DP_DB_COL_ACCESS_TIME);
+ }
+
+ }
+
+ dp_ipc_send_errorcode(sock, errorcode);
+ if (errorcode != DP_ERROR_NONE) {
+ TRACE_SECURE_ERROR("[ERROR][%d][START][%s]", id,
+ dp_print_errorcode(errorcode));
+ }
+ return errorcode;
+}
+
// in url-download, make 3 connection before send CREATE command.
// after accepting, fill info to pacakgelist.
// 3 socket per 1 package ( info/request/progress )
listenfd = privates->listen_fd;
maxfd = listenfd;
- TRACE_INFO("Ready to listen [%d][%s]", listenfd, DP_IPC);
+ TRACE_DEBUG("Ready to listen [%d][%s]", listenfd, DP_IPC);
FD_ZERO(&listen_fdset);
FD_ZERO(&except_fdset);
break;
}
- if (privates == NULL) {
- TRACE_INFO("Terminate Thread");
+ if (privates == NULL || privates->listen_fd < 0) {
+ TRACE_DEBUG("Terminate Thread");
break;
}
socklen_t cr_len = sizeof(credential);
if (getsockopt(clientfd, SOL_SOCKET, SO_PEERCRED,
&credential, &cr_len) == 0) {
- TRACE_INFO
+ TRACE_DEBUG
("credential : pid=%d, uid=%d, gid=%d",
credential.pid, credential.uid, credential.gid);
}
continue;
}
credential.pid = client_pid;
- credential.uid = 5000;
- credential.gid = 5000;
+ if (dp_ipc_read_custom_type(clientfd,
+ &credential.uid, sizeof(int)) < 0) {
+ TRACE_ERROR("[CRITICAL] not support SO_PEERCRED");
+ close(clientfd);
+ continue;
+ }
+ if (dp_ipc_read_custom_type(clientfd,
+ &credential.gid, sizeof(int)) < 0) {
+ TRACE_ERROR("[CRITICAL] not support SO_PEERCRED");
+ close(clientfd);
+ continue;
+ }
#endif
switch(connect_cmd) {
if (group == NULL || group->cmd_socket < 0)
continue;
const int sock = group->cmd_socket;
+ int time_of_job = (int)time(NULL);
if (FD_ISSET(sock, &rset) > 0) {
int index = -1;
dp_command command;
continue;
}
- // print detail info
- TRACE_INFO("[%s] id:%d sock:%d pkg:%s pid:%d slot:%d",
- __print_command(command.cmd), command.id, sock,
- group->pkgname, group->credential.pid, i);
-
- if (command.cmd == 0) { // Client meet some Error.
- TRACE_INFO("[Closed Peer] pkg:%s sock:%d slot:%d",
+ if (command.cmd == 0 || command.cmd >= DP_CMD_LAST_SECT) { // Client meet some Error.
+ TRACE_SECURE_INFO("[Closed Peer] pkg:%s sock:%d slot:%d",
group->pkgname, sock, i);
// check all request included to this group
FD_CLR(sock, &listen_fdset);
// Echo .client can check whether provider is busy
if (command.cmd == DP_CMD_ECHO) {
// provider can clear read buffer here
- TRACE_INFO("[ECHO] sock:%d", sock);
+ TRACE_DEBUG("[ECHO] sock:%d", sock);
if (dp_ipc_send_errorcode(sock,
DP_ERROR_NONE) < 0) {
// disconnect this group, bad client
+ TRACE_ERROR("[ECHO] IO ERROR CLEAN sock:%d", sock);
FD_CLR(sock, &listen_fdset);
__clear_group(privates, group);
privates->groups[i].group = NULL;
}
if (command.cmd == DP_CMD_CREATE) {
+ TRACE_SECURE_INFO("[CREATE] id:%d sock:%d pid:%d gindex:%d pkg:%s",
+ command.id, sock,
+ group->credential.pid, i, group->pkgname);
// search empty slot in privates->requests
index =
__get_empty_request_index(privates->requests);
dp_ipc_send_errorcode(sock, DP_ERROR_QUEUE_FULL);
} else {
errorcode = DP_ERROR_NONE;
+ CLIENT_MUTEX_LOCK(&privates->requests[index].mutex);
errorcode = dp_request_create(command.id, group,
&privates->requests[index].request);
dp_ipc_send_errorcode(sock, errorcode);
if (errorcode == DP_ERROR_NONE) {
- TRACE_INFO("[CREATE] GOOD id:%d slot:%d",
- privates->requests[index].request->id,
- index);
dp_ipc_send_custom_type(sock,
&privates->requests[index].request->id,
sizeof(int));
+ TRACE_DEBUG("[CREATE] GOOD id:%d slot:%d time:%d",
+ privates->requests[index].request->id,
+ index, ((int)time(NULL) - time_of_job));
} else {
TRACE_ERROR("[ERROR][%s]",
dp_print_errorcode(errorcode));
}
+ CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
}
continue;
}
index = __get_same_request_index(privates->requests,
command.id);
- // GET API works even if request is NULL.
- dp_request *request = NULL;
- if (index >= 0)
- request = privates->requests[index].request;
+ dp_request_slots *request_slot = NULL;
+ unsigned is_loaded = 0;
+ errorcode = DP_ERROR_NONE;
- // check for all command.
- if (request == NULL) {
- int check_id = dp_db_get_int_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_ID);
- if (check_id < 0 || check_id != command.id) {
- errorcode = DP_ERROR_ID_NOT_FOUND;
- TRACE_ERROR("[ERROR][%d][%s]", command.id,
- dp_print_errorcode(errorcode));
- dp_ipc_send_errorcode(sock, errorcode);
- continue;
- }
+ if (index >= 0) {
+ CLIENT_MUTEX_LOCK(&privates->requests[index].mutex);
+ if (privates->requests[index].request != NULL)
+ is_loaded = 1;
+ else
+ CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
}
- // Authentication by packagename.
- char *auth_pkgname = NULL;
- errorcode = DP_ERROR_NONE;
- if (request != NULL) {
- auth_pkgname = dp_strdup(request->packagename);
- if (auth_pkgname == NULL)
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- } else {
- auth_pkgname = dp_db_get_text_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_PACKAGENAME);
- if (auth_pkgname == NULL)
- errorcode = DP_ERROR_ID_NOT_FOUND;
- }
- if (errorcode == DP_ERROR_NONE) {
- // auth by pkgname
- if (__cmp_string(group->pkgname, auth_pkgname) < 0) {
- TRACE_ERROR("[ERROR][%d] Auth [%s]/[%s]",
- command.id, group->pkgname, auth_pkgname);
- errorcode = DP_ERROR_INVALID_PARAMETER;
- }
- }
- free(auth_pkgname);
- if (errorcode != DP_ERROR_NONE) {
- TRACE_ERROR("[ERROR][%d][%s]", command.id,
- dp_print_errorcode(errorcode));
- dp_ipc_send_errorcode(sock, errorcode);
- continue;
- }
+ errorcode = DP_ERROR_UNKNOWN; // check matched command
- // if no group, update group.
- if (request != NULL && request->group == NULL)
- request->group = group;
+ // divide on memory or from DB
+ if (is_loaded == 1 && index >= 0) { // already locked
- unsigned is_checked = 1;
- int read_int = 0;
- char *read_str = NULL;
+ TRACE_SECURE_INFO("[%s] id:%d sock:%d pid:%d gindex:%d slot:%d pkg:%s",
+ __print_command(command.cmd), command.id, sock,
+ group->credential.pid, i, index, group->pkgname);
- // read a interger or a string, return errorcode.
- errorcode = DP_ERROR_NONE;
- switch(command.cmd) {
- case DP_CMD_SET_STATE_CALLBACK:
- if (dp_ipc_read_custom_type(sock, &read_int,
- sizeof(int)) < 0) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- errorcode = dp_request_set_state_event(command.id,
- request, read_int);
- break;
- case DP_CMD_SET_PROGRESS_CALLBACK:
- if (dp_ipc_read_custom_type(sock, &read_int,
- sizeof(int)) < 0) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- errorcode = dp_request_set_progress_event
- (command.id, request, read_int);
- break;
- case DP_CMD_SET_NETWORK_TYPE:
- if (dp_ipc_read_custom_type(sock, &read_int,
- sizeof(int)) < 0) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- errorcode = dp_request_set_network_type(command.id,
- request, read_int);
- break;
- case DP_CMD_SET_AUTO_DOWNLOAD:
- if (dp_ipc_read_custom_type(sock, &read_int,
- sizeof(int)) < 0) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- errorcode = dp_request_set_auto_download(command.id,
- request, read_int);
- break;
- case DP_CMD_SET_NOTIFICATION:
- if (dp_ipc_read_custom_type(sock, &read_int,
- sizeof(int)) < 0) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- errorcode = dp_request_set_notification(command.id,
- request, read_int);
- break;
- case DP_CMD_SET_URL:
- if ((read_str = dp_ipc_read_string(sock)) == NULL) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- errorcode = dp_request_set_url(command.id, request,
- read_str);
- break;
- case DP_CMD_SET_DESTINATION:
- if ((read_str = dp_ipc_read_string(sock)) == NULL) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- errorcode = dp_request_set_destination(command.id,
- request, read_str);
- break;
- case DP_CMD_SET_FILENAME:
- if ((read_str = dp_ipc_read_string(sock)) == NULL) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- errorcode = dp_request_set_filename(command.id,
- request, read_str);
- break;
- default:
- is_checked = 0;
- break;
- }
- if (is_checked == 1) {
- free(read_str);
- if (errorcode != DP_ERROR_NONE) {
- TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
- __print_command(command.cmd),
- dp_print_errorcode(errorcode));
- }
- if (errorcode == DP_ERROR_IO_ERROR) {
- FD_CLR(sock, &listen_fdset);
- __clear_group(privates, group);
- privates->groups[i].group = NULL;
+ request_slot = &privates->requests[index];
+
+ // auth by pkgname
+ if (__cmp_string(group->pkgname, request_slot->request->packagename) < 0) {
+ TRACE_SECURE_ERROR("[ERROR][%d] Auth [%s]/[%s]",
+ command.id, group->pkgname, request_slot->request->packagename);
+ TRACE_ERROR("[ERROR][%d][INVALID_PARAMETER]", command.id);
+ dp_ipc_send_errorcode(sock, DP_ERROR_INVALID_PARAMETER);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
continue;
}
- dp_ipc_send_errorcode(sock, errorcode);
- continue;
- }
- // No read(), write a string
- read_str = NULL;
- errorcode = DP_ERROR_NONE;
- is_checked = 1;
- switch(command.cmd) {
- case DP_CMD_GET_URL:
- read_str = dp_request_get_url(command.id, request,
- &errorcode);
- break;
- case DP_CMD_GET_DESTINATION:
- read_str = dp_request_get_destination(command.id,
- request, &errorcode);
- break;
- case DP_CMD_GET_FILENAME:
- read_str = dp_request_get_filename(command.id,
- request, &errorcode);
- break;
- case DP_CMD_GET_SAVED_PATH:
- read_str = dp_request_get_savedpath(command.id,
- request, &errorcode);
- break;
- case DP_CMD_GET_TEMP_SAVED_PATH:
- read_str = dp_request_get_tmpsavedpath(command.id,
- request, &errorcode);
- break;
- case DP_CMD_GET_MIME_TYPE:
- read_str = dp_request_get_mimetype(command.id,
- request, &errorcode);
- break;
- case DP_CMD_GET_CONTENT_NAME:
- read_str = dp_request_get_contentname(command.id,
- request, &errorcode);
- break;
- case DP_CMD_GET_ETAG:
- read_str = dp_request_get_etag(command.id, request,
- &errorcode);
- break;
- default:
- is_checked = 0;
- break;
- }
- if (is_checked == 1) {
- if (read_str == NULL || strlen(read_str) < 1)
- errorcode = DP_ERROR_NO_DATA;
- dp_ipc_send_errorcode(sock, errorcode);
- if (errorcode == DP_ERROR_NONE) {
- dp_ipc_send_string(sock, read_str);
- } else {
- TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
- __print_command(command.cmd),
- dp_print_errorcode(errorcode));
- }
- free(read_str);
- continue;
- }
+ // if no group, update group.
+ if (request_slot->request->group == NULL)
+ request_slot->request->group = group;
- // No read(), write a integer variable
- read_int = 0;
- errorcode = DP_ERROR_NONE;
- is_checked = 1;
- switch(command.cmd) {
- case DP_CMD_GET_NOTIFICATION:
- read_int = dp_db_get_int_column(command.id,
- DP_DB_TABLE_REQUEST_INFO,
- DP_DB_COL_NOTIFICATION_ENABLE);
- break;
- case DP_CMD_GET_AUTO_DOWNLOAD:
- read_int = dp_db_get_int_column(command.id,
- DP_DB_TABLE_REQUEST_INFO,
- DP_DB_COL_AUTO_DOWNLOAD);
- break;
- case DP_CMD_GET_NETWORK_TYPE:
- read_int = dp_db_get_int_column(command.id,
- DP_DB_TABLE_REQUEST_INFO,
- DP_DB_COL_NETWORK_TYPE);
- break;
- case DP_CMD_GET_HTTP_STATUS:
- read_int = dp_db_get_int_column(command.id,
- DP_DB_TABLE_DOWNLOAD_INFO,
- DP_DB_COL_HTTP_STATUS);
- break;
- case DP_CMD_GET_STATE:
- if (request == NULL) {
- read_int = dp_db_get_int_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_STATE);
- } else {
- CLIENT_MUTEX_LOCK(&request->mutex);
- read_int = request->state;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- }
- break;
- case DP_CMD_GET_ERROR:
- if (request == NULL) {
- read_int = dp_db_get_int_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_ERRORCODE);
- } else {
- CLIENT_MUTEX_LOCK(&request->mutex);
- read_int = request->error;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- }
- break;
- default:
- is_checked = 0;
- break;
- }
- if (is_checked == 1) {
- if (read_int < 0)
- errorcode = DP_ERROR_NO_DATA;
- dp_ipc_send_errorcode(sock, errorcode);
- if (errorcode == DP_ERROR_NONE) {
- dp_ipc_send_custom_type(sock, &read_int,
- sizeof(int));
- } else {
- TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
- __print_command(command.cmd),
- dp_print_errorcode(errorcode));
- }
- continue;
- }
-
- // No read(), write a long long variable
- unsigned long long recv_long = 0;
- errorcode = DP_ERROR_NONE;
- is_checked = 1;
- switch(command.cmd) {
- case DP_CMD_GET_RECEIVED_SIZE:
- if (request == NULL) {
- errorcode = DP_ERROR_NO_DATA;
- } else {
- CLIENT_MUTEX_LOCK(&request->mutex);
- recv_long = request->received_size;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- }
- break;
- case DP_CMD_GET_TOTAL_FILE_SIZE:
- if (request != NULL) {
- CLIENT_MUTEX_LOCK(&request->mutex);
- recv_long = request->file_size;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- } else {
- long long file_size = dp_db_get_int64_column
- (command.id, DP_DB_TABLE_DOWNLOAD_INFO,
- DP_DB_COL_CONTENT_SIZE);
- if (file_size < 0)
- errorcode = DP_ERROR_NO_DATA;
- else // casting
- recv_long = file_size;
- }
- break;
- default:
- is_checked = 0;
- break;
- }
- if (is_checked == 1) {
- dp_ipc_send_errorcode(sock, errorcode);
- if (errorcode == DP_ERROR_NONE) {
- dp_ipc_send_custom_type(sock, &recv_long,
- sizeof(unsigned long long));
- } else {
- TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
- __print_command(command.cmd),
- dp_print_errorcode(errorcode));
- }
- continue;
- }
+ if (command.cmd == DP_CMD_START)
+ errorcode = __do_dp_start_command(sock, command.id, privates, group, request_slot->request);
+ else if (command.cmd > DP_CMD_SET_SECT && command.cmd < DP_CMD_LAST_SECT)
+ errorcode = __dp_do_set_command(sock, &command, request_slot->request);
+ else if (command.cmd > DP_CMD_GET_SECT && command.cmd < DP_CMD_SET_SECT)
+ errorcode = __dp_do_get_command(sock, &command, request_slot->request);
+ else if (command.cmd > DP_CMD_ACTION_SECT && command.cmd < DP_CMD_GET_SECT)
+ errorcode = __dp_do_action_command(sock, &command, request_slot->request);
- read_int = 0;
- errorcode = DP_ERROR_NONE;
- is_checked = 1;
- switch(command.cmd) {
- case DP_CMD_DESTROY:
- if (request == NULL) {// just update the state
- if (dp_db_set_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &read_int) < 0)
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- break;
- }
- if (request != NULL) { // call cancel in some cases
- CLIENT_MUTEX_LOCK(&request->mutex);
- if (__is_started(request->state) == 0) {
- read_int = DP_STATE_CANCELED;
- if (dp_db_set_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &read_int) < 0) {
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- } else {
- if (__dp_call_cancel_agent(request) < 0)
- TRACE_INFO("[fail][%d]cancel_agent",
- command.id);
- request->state = DP_STATE_CANCELED;
- }
- }
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- }
- break;
- case DP_CMD_FREE:
- // [destory]-[return]-[free]
- // No return errorcode
- if (request != NULL) {
- dp_request_free(request);
- privates->requests[index].request = NULL;
- }
- break;
- case DP_CMD_START:
- {
- if (request != NULL) {
- CLIENT_MUTEX_LOCK(&request->mutex);
- if (__is_started(request->state) == 0 ||
- request->state == DP_STATE_COMPLETED)
- errorcode = DP_ERROR_INVALID_STATE;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- }
- if (errorcode != DP_ERROR_NONE)
- break;
-
- // need URL at least
- char *url = dp_request_get_url(command.id, request,
- &errorcode);
- if (url == NULL) {
- errorcode = DP_ERROR_INVALID_URL;
- break;
- }
- free(url);
+ CLIENT_MUTEX_UNLOCK(&request_slot->mutex);
- if (request == NULL) { // Support Re-download
- index = __get_empty_request_index
- (privates->requests);
- if (index < 0) { // Busy, No Space in slot
- errorcode = DP_ERROR_QUEUE_FULL;
- } else {
- request = dp_request_load_from_log
- (command.id, &errorcode);
- if (request != NULL) {
- // restore callback info
- CLIENT_MUTEX_LOCK(&request->mutex);
- request->state_cb =
- dp_db_get_int_column(command.id,
- DP_DB_TABLE_REQUEST_INFO,
- DP_DB_COL_STATE_EVENT);
- request->progress_cb =
- dp_db_get_int_column(command.id,
- DP_DB_TABLE_REQUEST_INFO,
- DP_DB_COL_PROGRESS_EVENT);
- privates->requests[index].request =
- request;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- }
- }
- }
- if (errorcode != DP_ERROR_NONE)
- break;
-
- dp_state_type state = DP_STATE_QUEUED;
- if (dp_db_set_column(command.id, DP_DB_TABLE_LOG,
- DP_DB_COL_STATE, DP_DB_COL_TYPE_INT,
- &state) < 0) {
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- } else {
- group->queued_count++;
- CLIENT_MUTEX_LOCK(&request->mutex);
- request->start_time = (int)time(NULL);
- request->pause_time = 0;
- request->stop_time = 0;
- request->state = state;
- request->error = DP_ERROR_NONE;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- dp_db_update_date(command.id, DP_DB_TABLE_LOG,
- DP_DB_COL_ACCESS_TIME);
+ if (command.cmd == DP_CMD_START && errorcode == DP_ERROR_NONE) {
//send signal to queue thread
dp_thread_queue_manager_wake_up();
}
- break;
- }
- case DP_CMD_PAUSE:
- {
- // to check fastly, divide the case by request value
- if (request == NULL) {
- dp_state_type state =
- dp_db_get_int_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_STATE);
- // already paused or stopped
- if (state > DP_STATE_DOWNLOADING) {
- errorcode = DP_ERROR_INVALID_STATE;
- } else {
- // change state to paused.
- state = DP_STATE_PAUSED;
- if (dp_db_set_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &state) < 0)
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- }
- break;
+ if (command.cmd == DP_CMD_FREE) {// enter after unlock
+ dp_request_slot_free(request_slot);
+ errorcode = DP_ERROR_NONE;
}
- CLIENT_MUTEX_LOCK(&request->mutex);
+ } else { // not found on the slots
- if (request->state > DP_STATE_DOWNLOADING) {
- errorcode = DP_ERROR_INVALID_STATE;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- break;
- }
+ TRACE_SECURE_INFO("[%s] id:%d sock:%d pid:%d gindex:%d slot:no pkg:%s",
+ __print_command(command.cmd), command.id, sock,
+ group->credential.pid, i, group->pkgname);
- // before downloading including QUEUED
- if (__is_downloading(request->state) < 0) {
- dp_state_type state = DP_STATE_PAUSED;
- if (dp_db_set_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &state) < 0) {
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- } else {
- request->state = state;
- }
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- break;
+ int check_id = dp_db_get_int_column(command.id,
+ DP_DB_TABLE_LOG, DP_DB_COL_ID);
+ if (check_id < 0 || check_id != command.id) {
+ errorcode = DP_ERROR_ID_NOT_FOUND;
+ TRACE_ERROR("[ERROR][%d][ID_NOT_FOUND]", command.id);
+ dp_ipc_send_errorcode(sock, DP_ERROR_ID_NOT_FOUND);
+ continue;
}
- // only downloading.
- dp_state_type state = DP_STATE_PAUSE_REQUESTED;
- if (dp_db_set_column(command.id, DP_DB_TABLE_LOG,
- DP_DB_COL_STATE, DP_DB_COL_TYPE_INT,
- &state) < 0) {
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- } else {
- TRACE_INFO("[%s][%d]pause_agent(%d) state:%s",
- __print_command(command.cmd), command.id,
- request->agent_id,
- dp_print_state(request->state));
- if (dp_pause_agent_download
- (request->agent_id) < 0) {
- TRACE_INFO("[fail][%d]pause_agent(%d)",
- command.id, request->agent_id);
- }
- request->state = state;
- request->error = DP_ERROR_NONE;
- request->pause_time = (int)time(NULL);
- dp_db_update_date(command.id, DP_DB_TABLE_LOG,
- DP_DB_COL_ACCESS_TIME);
+ // auth by pkgname
+ char *auth_pkgname = dp_db_get_text_column(command.id,
+ DP_DB_TABLE_LOG, DP_DB_COL_PACKAGENAME);
+ if (auth_pkgname == NULL) {
+ TRACE_ERROR("[ERROR][%d][ID_NOT_FOUND]", command.id);
+ dp_ipc_send_errorcode(sock, DP_ERROR_ID_NOT_FOUND);
+ continue;
}
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- break;
- }
- case DP_CMD_CANCEL:
- {
- // to check fastly, divide the case by request value
- if (request == NULL) {
- dp_state_type state =
- dp_db_get_int_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_STATE);
- // already paused or stopped
- if (__is_stopped(state) == 0) {
- errorcode = DP_ERROR_INVALID_STATE;
- } else {
- // change state to canceled.
- state = DP_STATE_CANCELED;
- if (dp_db_set_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &state) < 0)
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- }
- break;
+ // auth by pkgname
+ if (__cmp_string(group->pkgname, auth_pkgname) < 0) {
+ TRACE_SECURE_ERROR("[ERROR][%d] Auth [%s]/[%s]",
+ command.id, group->pkgname, auth_pkgname);
+ TRACE_ERROR("[ERROR][%d][INVALID_PARAMETER]", command.id);
+ dp_ipc_send_errorcode(sock, DP_ERROR_INVALID_PARAMETER);
+ free(auth_pkgname);
+ continue;
}
+ free(auth_pkgname);
- CLIENT_MUTEX_LOCK(&request->mutex);
-
- if (__is_stopped(request->state) == 0) {
- errorcode = DP_ERROR_INVALID_STATE;
- } else {
- // change state to canceled.
- dp_state_type state = DP_STATE_CANCELED;
- if (dp_db_set_column(command.id,
- DP_DB_TABLE_LOG, DP_DB_COL_STATE,
- DP_DB_COL_TYPE_INT, &state) < 0)
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- }
- if (errorcode == DP_ERROR_NONE) {
- TRACE_INFO("[%s][%d]cancel_agent(%d) state:%s",
- __print_command(command.cmd), command.id,
- request->agent_id,
- dp_print_state(request->state));
- if (__dp_call_cancel_agent(request) < 0)
- TRACE_INFO("[fail][%d]cancel_agent",
- command.id);
- request->state = DP_STATE_CANCELED;
- }
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- dp_db_update_date(command.id, DP_DB_TABLE_LOG,
- DP_DB_COL_ACCESS_TIME);
- break;
- }
- default:
- is_checked = 0;
- break;
- }
- if (is_checked == 1) {
- if (errorcode != DP_ERROR_NONE) {
- TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
- __print_command(command.cmd),
- dp_print_errorcode(errorcode));
+ if (command.cmd == DP_CMD_START)
+ errorcode = __do_dp_start_command(sock, command.id, privates, group, NULL);
+ else if (command.cmd == DP_CMD_FREE)
+ errorcode = DP_ERROR_NONE;
+ else if (command.cmd > DP_CMD_SET_SECT && command.cmd < DP_CMD_LAST_SECT)
+ errorcode = __dp_do_set_command(sock, &command, NULL);
+ else if (command.cmd > DP_CMD_GET_SECT && command.cmd < DP_CMD_SET_SECT)
+ errorcode = __dp_do_get_command(sock, &command, NULL);
+ else if (command.cmd > DP_CMD_ACTION_SECT && command.cmd < DP_CMD_GET_SECT)
+ errorcode = __dp_do_action_command(sock, &command, NULL);
+
+ if (command.cmd == DP_CMD_START && errorcode == DP_ERROR_NONE) {
+ //send signal to queue thread
+ dp_thread_queue_manager_wake_up();
}
- if (command.cmd != DP_CMD_FREE) // free no return
- dp_ipc_send_errorcode(sock, errorcode);
- continue;
}
- // complex read() and write().
- char *read_str2 = NULL;
- errorcode = DP_ERROR_NONE;
- read_str = NULL;
- is_checked = 1;
- switch(command.cmd) {
- case DP_CMD_SET_HTTP_HEADER:
- {
- if ((read_str = dp_ipc_read_string(sock)) == NULL) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- read_str2 = dp_ipc_read_string(sock);
- if (read_str2 == NULL) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- int conds_count = 3; // id + field + data
- db_conds_list_fmt conds_p[conds_count];
- memset(&conds_p, 0x00,
- conds_count * sizeof(db_conds_list_fmt));
- conds_p[0].column = DP_DB_COL_ID;
- conds_p[0].type = DP_DB_COL_TYPE_INT;
- conds_p[0].value = &command.id;
- conds_p[1].column = DP_DB_COL_HEADER_FIELD;
- conds_p[1].type = DP_DB_COL_TYPE_TEXT;
- conds_p[1].value = read_str;
- conds_p[2].column = DP_DB_COL_HEADER_DATA;
- conds_p[2].type = DP_DB_COL_TYPE_TEXT;
- conds_p[2].value = read_str2;
- if (dp_db_get_conds_rows_count
- (DP_DB_TABLE_HTTP_HEADERS, DP_DB_COL_ID,
- "AND", 2, conds_p) <= 0) { // insert
- if (dp_db_insert_columns
- (DP_DB_TABLE_HTTP_HEADERS, conds_count,
- conds_p) < 0)
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- } else { // update data by field
- if (dp_db_cond_set_column(command.id,
- DP_DB_TABLE_HTTP_HEADERS,
- DP_DB_COL_HEADER_DATA,
- DP_DB_COL_TYPE_TEXT, read_str2,
- DP_DB_COL_HEADER_FIELD,
- DP_DB_COL_TYPE_TEXT, read_str) < 0)
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- }
- dp_ipc_send_errorcode(sock, errorcode);
- break;
- }
- case DP_CMD_DEL_HTTP_HEADER:
- if ((read_str = dp_ipc_read_string(sock)) == NULL) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- if (dp_db_get_cond_rows_count(command.id,
- DP_DB_TABLE_HTTP_HEADERS,
- DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT,
- read_str) < 0) {
- errorcode = DP_ERROR_NO_DATA;
- } else {
- if (dp_db_cond_remove(command.id,
- DP_DB_TABLE_HTTP_HEADERS,
- DP_DB_COL_HEADER_FIELD,
- DP_DB_COL_TYPE_TEXT, read_str) < 0)
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- }
- dp_ipc_send_errorcode(sock, errorcode);
- break;
- case DP_CMD_GET_HTTP_HEADER:
- if ((read_str = dp_ipc_read_string(sock)) == NULL) {
- errorcode = DP_ERROR_IO_ERROR;
- break;
- }
- read_str2 = dp_db_cond_get_text_column(command.id,
- DP_DB_TABLE_HTTP_HEADERS, DP_DB_COL_HEADER_DATA,
- DP_DB_COL_HEADER_FIELD, DP_DB_COL_TYPE_TEXT,
- read_str);
- if (read_str2 == NULL)
- errorcode = DP_ERROR_NO_DATA;
- dp_ipc_send_errorcode(sock, errorcode);
- if (errorcode == DP_ERROR_NONE)
- dp_ipc_send_string(sock, read_str2);
- break;
- case DP_CMD_GET_HTTP_HEADER_LIST:
- {
- char **values = NULL;
- unsigned rows_count = 0;
- errorcode = __dp_get_http_header_fields(sock,
- command.id, &values, &rows_count);
- if (errorcode == DP_ERROR_NONE) {
- __send_return_custom_type(sock, DP_ERROR_NONE,
- &rows_count, sizeof(int));
- // sending strings
- int i = 0;
- for (i = 0; i < rows_count; i++) {
- if (dp_ipc_send_string(sock, values[i]) < 0)
- break;
- }
- for (i = 0; i < rows_count; i++)
- free(values[i]);
- } else {
- if (errorcode != DP_ERROR_IO_ERROR)
- dp_ipc_send_errorcode(sock, errorcode);
- }
- free(values);
- break;
- }
- case DP_CMD_ADD_EXTRA_PARAM:
- errorcode = __dp_add_extra_param(sock, command.id);
- if (errorcode != DP_ERROR_IO_ERROR)
- dp_ipc_send_errorcode(sock, errorcode);
- break;
- case DP_CMD_GET_EXTRA_PARAM:
- {
- char **values = NULL;
- unsigned rows_count = 0;
- errorcode = __dp_get_extra_param_values(sock,
- command.id, &values, &rows_count);
- if (errorcode == DP_ERROR_NONE) {
- __send_return_custom_type(sock, DP_ERROR_NONE,
- &rows_count, sizeof(int));
- // sending strings
- int i = 0;
- for (i = 0; i < rows_count; i++) {
- if (dp_ipc_send_string(sock, values[i]) < 0)
- break;
- }
- for (i = 0; i < rows_count; i++)
- free(values[i]);
- } else {
- if (errorcode != DP_ERROR_IO_ERROR)
- dp_ipc_send_errorcode(sock, errorcode);
- }
- free(values);
- break;
- }
- case DP_CMD_REMOVE_EXTRA_PARAM:
- errorcode =
- __dp_remove_extra_param(sock, command.id);
- if (errorcode != DP_ERROR_IO_ERROR)
- dp_ipc_send_errorcode(sock, errorcode);
- break;
- default: // UNKNOWN COMMAND
- is_checked = 0;
- break;
+ if (errorcode == DP_ERROR_IO_ERROR) {
+ TRACE_ERROR("[IO_ERROR][%d] slot:%d pid:%d",
+ command.id, i,
+ privates->groups[i].group->credential.pid);
+ FD_CLR(sock, &listen_fdset);
+ __clear_group(privates, group);
+ privates->groups[i].group = NULL;
+ continue;
}
- if (is_checked == 1) {
- if (errorcode != DP_ERROR_NONE) {
- TRACE_ERROR("[ERROR][%d][%s][%s]", command.id,
- __print_command(command.cmd),
- dp_print_errorcode(errorcode));
- if (errorcode == DP_ERROR_IO_ERROR) {
- FD_CLR(sock, &listen_fdset);
- __clear_group(privates, group);
- privates->groups[i].group = NULL;
- }
- }
- free(read_str);
- free(read_str2);
- } else { // UnKnown Command
+ if (errorcode == DP_ERROR_UNKNOWN) { // UnKnown Command
TRACE_INFO("[UNKNOWN][%d] slot:%d pid:%d",
command.id, i,
privates->groups[i].group->credential.pid);
// timeout
if (is_timeout == 1) {
int now_timeout = (int)time(NULL);
- TRACE_INFO("[TIMEOUT] prev %ld, now %ld, setted %ld sec",
+ TRACE_DEBUG("[TIMEOUT] prev %ld, now %ld, setted %ld sec",
prev_timeout, now_timeout, flexible_timeout);
if (prev_timeout == 0) {
prev_timeout = now_timeout;
+ } else if (now_timeout < prev_timeout ||
+ (now_timeout - prev_timeout) > flexible_timeout) {
+ TRACE_ERROR("[WARN] check system date prev[%ld]now[%ld]",
+ prev_timeout, now_timeout);
} else {
if ((now_timeout - prev_timeout) <
DP_CARE_CLIENT_MIN_INTERVAL) {
if (old_request_count > DP_LOG_DB_CLEAR_LIMIT_ONE_TIME)
old_request_count = DP_LOG_DB_CLEAR_LIMIT_ONE_TIME;
- TRACE_INFO
+ TRACE_DEBUG
("[CLEAR] [%d] old reqeusts", old_request_count);
dp_request_slots *old_requests =
(privates->requests,
old_requests[i].request->id);
if (index >= 0) {
+ CLIENT_MUTEX_LOCK(&privates->requests[index].mutex);
dp_request *request =
privates->requests[index].request;
// if downloading..remain it.
- CLIENT_MUTEX_LOCK(&request->mutex);
- if (__is_downloading(request->state) == 0) {
- CLIENT_MUTEX_UNLOCK(&request->mutex);
+ if (request == NULL || __is_downloading(request->state) == 0) {
+ CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
continue;
}
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- TRACE_INFO("[CLEAR][%d] 48 hour state:%s",
+ CLIENT_MUTEX_UNLOCK(&privates->requests[index].mutex);
+ TRACE_DEBUG("[CLEAR][%d] 48 hour state:%s",
request->id,
dp_print_state(request->state));
// unload from slots ( memory )
- dp_request_free(request);
- privates->requests[index].request = NULL;
+ dp_request_slot_free(&privates->requests[index]);
}
// remove tmp file regardless
__dp_remove_tmpfile
// clean slots
int ready_requests = 0;
for (i = 0; i < DP_MAX_REQUEST; i++) {
- if (privates->requests[i].request == NULL)
+ CLIENT_MUTEX_LOCK(&privates->requests[i].mutex);
+ if (privates->requests[i].request == NULL) {
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
continue;
+ }
dp_request *request = privates->requests[i].request;
- CLIENT_MUTEX_LOCK(&request->mutex);
-
// If downloading is too slow ? how to deal this request?
// can limit too slot download using starttime.(48 hours)
if (__is_downloading(request->state) == 0) {
- CLIENT_MUTEX_UNLOCK(&request->mutex);
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
continue;
}
// paused & agent_id not exist.... unload from memory.
if (request->state == DP_STATE_PAUSED &&
dp_is_alive_download(request->agent_id) == 0) {
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- TRACE_INFO("[FREE][%d] dead agent-id(%d) state:%s",
+ TRACE_DEBUG("[FREE][%d] dead agent-id(%d) state:%s",
request->id, request->agent_id,
dp_print_state(request->state));
- dp_request_free(request);
- privates->requests[i].request = NULL;
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+ dp_request_slot_free(&privates->requests[i]);
continue;
}
int download_id = request->id;
dp_state_type state = DP_STATE_FAILED;
errorcode = DP_ERROR_RESPONSE_TIMEOUT;
- TRACE_INFO
+ TRACE_DEBUG
("[FREE][%d] start in %d sec state:%s last:%ld",
download_id, DP_CARE_CLIENT_MAX_INTERVAL,
dp_print_state(request->state),
request->group->event_socket >= 0)
dp_ipc_send_event(request->group->event_socket,
download_id, state, errorcode, 0);
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- dp_request_free(request);
- privates->requests[i].request = NULL;
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+ dp_request_slot_free(&privates->requests[i]);
// no problem although updating is failed.
- if (dp_db_set_column(download_id, DP_DB_TABLE_LOG,
- DP_DB_COL_STATE, DP_DB_COL_TYPE_INT,
- &state) < 0)
- TRACE_ERROR("[fail][%d][sql] set state:%s",
- download_id, dp_print_state(state));
- if (dp_db_set_column(download_id, DP_DB_TABLE_LOG,
- DP_DB_COL_ERRORCODE, DP_DB_COL_TYPE_INT,
- &errorcode) < 0)
- TRACE_ERROR("[fail][%d][sql] set error:%s",
- download_id, dp_print_errorcode(errorcode));
+ if (dp_db_request_update_status(download_id, state, errorcode) < 0) {
+ TRACE_ERROR("[fail][%d][sql] set state:%s error:%s",
+ download_id, dp_print_state(state), dp_print_errorcode(errorcode));
+ }
continue;
}
- // client should call DESTROY command in 60 sec after finished
+ // stopped by ipchanged. decide auto resume
+ if (request->stop_time <= 0 &&
+ request->state == DP_STATE_FAILED &&
+ request->error == DP_ERROR_CONNECTION_FAILED) {
+ if (dp_get_network_connection_instant_status() !=
+ DP_NETWORK_TYPE_OFF &&
+ request->ip_changed == 1) {
+ TRACE_DEBUG("[RESUME][%d] will be queued",
+ request->id);
+ request->state = DP_STATE_QUEUED;
+ request->error = DP_ERROR_NONE;
+ ready_requests++;
+ } else {
+ dp_request_state_response(request);
+ }
+ }
+
+ // client should call DESTROY command in MAX_INTERVAL sec after finished
if (request->stop_time > 0 &&
(now_timeout - request->stop_time) >
DP_CARE_CLIENT_MAX_INTERVAL) {
// check state again. stop_time means it's stopped
if (__is_stopped(request->state) == 0) {
- CLIENT_MUTEX_UNLOCK(&request->mutex);
- TRACE_INFO
+ TRACE_DEBUG
("[FREE][%d] by timeout state:%s stop:%ld",
request->id,
dp_print_state(request->state),
request->stop_time);
- dp_request_free(request);
- privates->requests[i].request = NULL;
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
+ dp_request_slot_free(&privates->requests[i]);
continue;
}
}
if (request->state == DP_STATE_QUEUED)
ready_requests++;
- CLIENT_MUTEX_UNLOCK(&request->mutex);
+ CLIENT_MUTEX_UNLOCK(&privates->requests[i].mutex);
}
if (ready_requests > 0) {
//send signal to queue thread will check queue.
dp_thread_queue_manager_wake_up();
} else {
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
// if no request & timeout is bigger than 60 sec
// terminate by self.
if ((now_timeout - prev_timeout) >= flexible_timeout &&
dp_get_request_count(privates->requests) <= 0) {
- TRACE_INFO("No Request. Terminate Daemon");
+ TRACE_DEBUG("No Request. Terminate Daemon");
break;
}
-#endif
}
prev_timeout = now_timeout;
- } // timeout
+ } else {
+ prev_timeout = 0;
+ }
}
- TRACE_INFO("terminate main thread ...");
+ TRACE_DEBUG("terminate main thread ...");
dp_terminate(SIGTERM);
pthread_exit(NULL);
return 0;
#define DP_LOCK_PID "/tmp/download-provider.lock"
#define DP_CARE_CLIENT_MIN_INTERVAL 5
-#define DP_CARE_CLIENT_MAX_INTERVAL 60
+#define DP_CARE_CLIENT_MAX_INTERVAL 120
// check this value should be lower than DP_MAX_REQUEST
#define DP_MAX_DOWNLOAD_AT_ONCE 50
* notification : id, noti_enable, extra_key, extra_data
*/
/*
+CREATE TABLE IF NOT EXISTS groups
+(
+ id INTEGER UNIQUE PRIMARY KEY,
+ uid INTEGER DEFAULT 0,
+ gid INTEGER DEFAULT 0,
+ extra_int INTEGER DEFAULT 0,
+ packagename TEXT DEFAULT NULL,
+ smack_label TEXT DEFAULT NULL,
+ extra TEXT DEFAULT NULL,
+ date_first_connected DATE,
+ date_last_connected DATE
+);
+
CREATE TABLE logging
(
id INTEGER UNIQUE PRIMARY KEY,
CREATE UNIQUE INDEX requests_index ON logging (id, state, errorcode, packagename, createtime, accesstime);
*/
+#define DP_DB_TABLE_GROUPS "groups"
#define DP_DB_TABLE_LOG "logging"
#define DP_DB_TABLE_REQUEST_INFO "requestinfo"
#define DP_DB_TABLE_DOWNLOAD_INFO "downloadinfo"
#define DP_DB_COL_EXTRA_KEY "extra_key"
#define DP_DB_COL_DISTINCT_EXTRA_KEY "DISTINCT extra_key"
#define DP_DB_COL_EXTRA_VALUE "extra_data"
+#define DP_DB_COL_RAW_BUNDLE_ONGOING "raw_bundle_data_ongoing_state"
+#define DP_DB_COL_RAW_BUNDLE_COMPLETE "raw_bundle_data_complete_state"
+#define DP_DB_COL_RAW_BUNDLE_FAIL "raw_bundle_data_fail_state"
+#define DP_DB_COL_TITLE "title"
+#define DP_DB_COL_DESCRIPTION "description"
+#define DP_DB_COL_NOTI_TYPE "noti_type"
+
+#define DP_DB_GROUPS_COL_UID "uid"
+#define DP_DB_GROUPS_COL_GID "gid"
+#define DP_DB_GROUPS_COL_PKG "packagename"
+#define DP_DB_GROUPS_COL_SMACK_LABEL "smack_label"
+
typedef enum {
DP_DB_COL_TYPE_NONE = 0,
int dp_db_open();
void dp_db_close();
+int dp_db_is_full_error();
+
int dp_db_remove_all(int id);
int dp_db_remove(int id, char *table);
int dp_db_insert_column(int id, char *table, char *column,
db_column_data_type datatype, void *value);
+int dp_db_insert_blob_column(int id, char *table, char *column,
+ void *value, unsigned length);
int dp_db_set_column(int id, char *table, char *column,
db_column_data_type datatype, void *value);
+int dp_db_set_blob_column(int id, char *table, char *column,
+ void *value, unsigned length);
int dp_db_replace_column(int id, char *table, char *column,
db_column_data_type datatype, void *value);
+int dp_db_replace_blob_column(int id, char *table, char *column,
+ void *value, unsigned length);
char *dp_db_get_text_column(int id, char *table, char *column);
+void *dp_db_get_blob_column(int id, char *table, char *column, int *length);
int dp_db_get_int_column(int id, char *table, char *column);
long long dp_db_get_int64_column(int id, char *table, char *column);
int dp_db_update_date(int id, char *table, char *column);
char *condcolumn, db_column_data_type condtype,
void *condvalue);
+char *dp_db_cond_get_text(char *table, char *column, char *condcolumn,
+ db_column_data_type condtype, void *condvalue);
+int dp_db_cond_get_int(char *table, char *column, char *condcolumn,
+ db_column_data_type condtype, void *condvalue);
+
// Special API for http headers
int dp_db_get_http_headers_list(int id, char **headers);
int dp_db_insert_columns(char *table, int column_count,
db_conds_list_fmt *columns);
+int dp_db_update_columns(int id, char *table, int column_count,
+ db_conds_list_fmt *columns);
int dp_db_get_conds_rows_count(char *table, char *getcolumn, char *op,
int conds_count, db_conds_list_fmt *conds);
char *ordercolumn, char *ordering,
char *op, int conds_count,
db_conds_list_fmt *conds);
+
+int dp_db_request_new_logging(const int id, const int state, const char *pkgname);
+int dp_db_request_update_status(const int id, const int state, const int download_error);
+int dp_db_get_state(int id);
+int dp_db_request_new_logging(const int id,
+ const int state, const char *pkgname);
#endif
extern "C" {
#endif
-#ifdef DP_SUPPORT_DBUS_ACTIVATION
-#define DP_DBUS_ACTIVATION
-#define DP_DBUS_SERVICE_DBUS "org.download-provider"
-#endif
-
typedef enum {
DP_STATE_NONE = 0,
DP_STATE_READY = DP_STATE_NONE + 5, // created id, set some info.
} dp_state_type;
typedef enum {
- DP_ERROR_NONE = 0,
+ DP_ERROR_NONE = 10,
DP_ERROR_INVALID_PARAMETER = DP_ERROR_NONE + 1,
DP_ERROR_OUT_OF_MEMORY = DP_ERROR_NONE + 2,
DP_ERROR_IO_ERROR = DP_ERROR_NONE + 3,
DP_ERROR_NO_DATA = DP_ERROR_NONE + 17,
DP_ERROR_UNHANDLED_HTTP_CODE = DP_ERROR_NONE + 18,
DP_ERROR_CANNOT_RESUME = DP_ERROR_NONE + 19,
+ DP_ERROR_PERMISSION_DENIED = DP_ERROR_NONE + 20,
DP_ERROR_RESPONSE_TIMEOUT = DP_ERROR_NONE + 50,
DP_ERROR_REQUEST_TIMEOUT = DP_ERROR_NONE + 55,
DP_ERROR_SYSTEM_DOWN = DP_ERROR_NONE + 60,
DP_NETWORK_TYPE_WIFI_DIRECT = 4
} dp_network_type;
+typedef enum {
+ DP_NOTIFICATION_BUNDLE_TYPE_ONGOING = 0, // Ongoing, Failed
+ DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE, // Completed
+ DP_NOTIFICATION_BUNDLE_TYPE_FAILED // Failed
+} dp_notification_bundle_type;
+
+typedef enum {
+ DP_NOTIFICATION_TYPE_NONE = 0, // Not register Noti.
+ DP_NOTIFICATION_TYPE_COMPLETE_ONLY, // Success, Failed
+ DP_NOTIFICATION_TYPE_ALL // Ongoing, Success, Failed
+} dp_notification_type;
+
#ifdef __cplusplus
}
#endif
#undef LOG_TAG
#endif
#define LOG_TAG "DOWNLOAD_PROVIDER"
-#define TRACE_ERROR(format, ARG...) \
-{ \
-LOGE(format, ##ARG); \
-}
-#define TRACE_STRERROR(format, ARG...) \
-{ \
-LOGE(format" [%s]", ##ARG, strerror(errno)); \
-}
-#define TRACE_INFO(format, ARG...) \
-{ \
-LOGI(format, ##ARG); \
-}
+#define TRACE_DEBUG(format, ARG...) LOGD(format, ##ARG)
+#define TRACE_ERROR(format, ARG...) LOGE(format, ##ARG)
+#define TRACE_STRERROR(format, ARG...) LOGE(format" [%s]", ##ARG, strerror(errno))
+#define TRACE_INFO(format, ARG...) LOGI(format, ##ARG)
+
+#ifdef SECURE_LOGD
+#define TRACE_SECURE_DEBUG(format, ARG...) SECURE_LOGD(format, ##ARG)
+#else
+#define TRACE_SECURE_DEBUG(...) do { } while(0)
+#endif
+#ifdef SECURE_LOGI
+#define TRACE_SECURE_INFO(format, ARG...) SECURE_LOGI(format, ##ARG)
+#else
+#define TRACE_SECURE_INFO(...) do { } while(0)
+#endif
+#ifdef SECURE_LOGE
+#define TRACE_SECURE_ERROR(format, ARG...) SECURE_LOGE(format, ##ARG)
+#else
+#define TRACE_SECURE_ERROR(...) do { } while(0)
+#endif
+
#else
-#define TRACE_ERROR(format, ARG...) ;
-#define TRACE_STRERROR(format, ARG...) ;
-#define TRACE_INFO(format, ARG...) ;
+#define TRACE_DEBUG(...) do { } while(0)
+#define TRACE_ERROR(...) do { } while(0)
+#define TRACE_STRERROR(...) do { } while(0)
+#define TRACE_INFO(...) do { } while(0)
+#define TRACE_SECURE_DEBUG(...) do { } while(0)
+#define TRACE_SECURE_INFO(...) do { } while(0)
+#define TRACE_SECURE_ERROR(...) do { } while(0)
#endif
#endif
#ifndef DOWNLOAD_PROVIDER2_NETWORK_H
#define DOWNLOAD_PROVIDER2_NETWORK_H
+#include <net_connection.h>
+
#include "download-provider.h"
dp_network_type dp_get_network_connection_status(connection_h connection, connection_type_e type);
#define DOWNLOAD_PROVIDER2_REQUEST_H
#include "download-provider.h"
+#include <bundle.h>
// for Debugging
char *dp_print_state(dp_state_type state);
char *dp_print_errorcode(dp_error_type errorcode);
+int dp_is_smackfs_mounted(void);
char *dp_strdup(char *src);
dp_error_type dp_request_create(int id, dp_client_group *group, dp_request** empty_slot);
dp_error_type dp_request_set_url(int id, dp_request *request, char *url);
dp_error_type dp_request_set_destination(int id, dp_request *request, char *dest);
dp_error_type dp_request_set_filename(int id, dp_request *request, char *filename);
+dp_error_type dp_request_set_title(int id, dp_request *request, char *filename);
+dp_error_type dp_request_set_bundle(int id, dp_request *request, int type, bundle_raw *b, unsigned length);
+dp_error_type dp_request_set_description(int id, dp_request *request, char *description);
+dp_error_type dp_request_set_noti_type(int id, dp_request *request, unsigned type);
dp_error_type dp_request_set_notification(int id, dp_request *request, unsigned enable);
dp_error_type dp_request_set_auto_download(int id, dp_request *request, unsigned enable);
dp_error_type dp_request_set_state_event(int id, dp_request *request, unsigned enable);
dp_error_type dp_request_set_progress_event(int id, dp_request *request, unsigned enable);
dp_error_type dp_request_set_network_type(int id, dp_request *request, int type);
-char *dp_request_get_url(int id, dp_request *request, dp_error_type *errorcode);
+char *dp_request_get_url(int id, dp_error_type *errorcode);
char *dp_request_get_destination(int id, dp_request *request, dp_error_type *errorcode);
char *dp_request_get_filename(int id, dp_request *request, dp_error_type *errorcode);
+char *dp_request_get_title(int id, dp_request *request, dp_error_type *errorcode);
+bundle_raw *dp_request_get_bundle(int id, dp_request *request, dp_error_type *errorcode, char* column, int* length);
+char *dp_request_get_description(int id, dp_request *request, dp_error_type *errorcode);
+int dp_request_get_noti_type(int id, dp_request *request, dp_error_type *errorcode);
char *dp_request_get_contentname(int id, dp_request *request, dp_error_type *errorcode);
char *dp_request_get_etag(int id, dp_request *request, dp_error_type *errorcode);
char *dp_request_get_savedpath(int id, dp_request *request, dp_error_type *errorcode);
char *dp_request_get_tmpsavedpath(int id, dp_request *request, dp_error_type *errorcode);
char *dp_request_get_mimetype(int id, dp_request *request, dp_error_type *errorcode);
+char *dp_request_get_pkg_name(int id, dp_request *request, dp_error_type *errorcode);
dp_request *dp_request_load_from_log(int id, dp_error_type *errorcode);
+void dp_request_state_response(dp_request *request);
#endif
// fill by app-manager
char *pkgname;
dp_credential credential;
+ char *smack_label;
} dp_client_group;
typedef struct {
unsigned progress_cb; // set : 1 unset : 0
unsigned startcount;
unsigned auto_notification;
+ unsigned ip_changed;
dp_state_type state; // downloading state
dp_error_type error;
dp_network_type network_type;
unsigned long long received_size; // progress
unsigned long long file_size;
char *packagename;
- dp_credential credential;
dp_client_group *group; // indicate dp_client_group included this request
- pthread_mutex_t mutex;
} dp_request;
typedef struct {
} dp_group_slots;
typedef struct {
+ pthread_mutex_t mutex;
dp_request *request;
} dp_request_slots;
dp_request *dp_request_new();
void dp_request_init(dp_request *request);
int dp_request_free(dp_request *request);
+int dp_request_slot_free(dp_request_slots *request_slot);
int dp_request_slots_free(dp_request_slots *slots, int size);
int dp_get_request_count(dp_request_slots *slots);
#ifndef DOWNLOAD_PROVIDER2_SOCKET_H
#define DOWNLOAD_PROVIDER2_SOCKET_H
+#include <bundle.h>
#include "download-provider.h"
#include "download-provider-slots.h"
dp_error_type errorcode);
#endif
char *dp_ipc_read_string(int fd);
+unsigned dp_ipc_read_bundle(int fd, int *type, bundle_raw **b);
int dp_ipc_send_string(int fd, const char *str);
+int dp_ipc_send_bundle(int fd, bundle_raw *b, unsigned length);
int dp_ipc_send_custom_type(int fd, void *value, size_t type_size);
int dp_ipc_read_custom_type(int fd, void *value, size_t type_size);
int dp_accept_socket_new();
#define DP_MAX_STR_LEN 256
#define DP_MAX_PATH_LEN DP_MAX_STR_LEN
#define DP_MAX_URL_LEN 2048
+#define DP_DEFAULT_BUFFER_SIZE 1024
typedef enum {
DP_CMD_NONE = 0,
- DP_CMD_CREATE = DP_CMD_NONE + 1,
- DP_CMD_START = DP_CMD_NONE + 2,
- DP_CMD_PAUSE = DP_CMD_NONE + 3,
- DP_CMD_CANCEL = DP_CMD_NONE + 4,
- DP_CMD_DESTROY = DP_CMD_NONE + 9,
- DP_CMD_FREE = DP_CMD_NONE + 10,
- DP_CMD_ECHO = DP_CMD_NONE + 15,
- DP_CMD_SET_URL = DP_CMD_NONE + 21,
- DP_CMD_SET_DESTINATION = DP_CMD_NONE + 22,
- DP_CMD_SET_FILENAME = DP_CMD_NONE + 23,
- DP_CMD_SET_NOTIFICATION = DP_CMD_NONE + 24,
- DP_CMD_SET_STATE_CALLBACK = DP_CMD_NONE + 25,
- DP_CMD_SET_PROGRESS_CALLBACK = DP_CMD_NONE + 26,
- DP_CMD_SET_AUTO_DOWNLOAD = DP_CMD_NONE + 28,
- DP_CMD_SET_NETWORK_TYPE = DP_CMD_NONE + 29,
- DP_CMD_SET_HTTP_HEADER = DP_CMD_NONE + 30,
- DP_CMD_SET_EXTRA_PARAM = DP_CMD_NONE + 31, // prevent build error
- DP_CMD_DEL_HTTP_HEADER = DP_CMD_NONE + 35,
- DP_CMD_GET_URL = DP_CMD_NONE + 41,
- DP_CMD_GET_DESTINATION = DP_CMD_NONE + 42,
- DP_CMD_GET_FILENAME = DP_CMD_NONE + 43,
- DP_CMD_GET_NOTIFICATION = DP_CMD_NONE + 44,
- DP_CMD_GET_STATE_CALLBACK = DP_CMD_NONE + 45,
- DP_CMD_GET_PROGRESS_CALLBACK = DP_CMD_NONE + 46,
- DP_CMD_GET_HTTP_HEADERS = DP_CMD_NONE + 47,
- DP_CMD_GET_AUTO_DOWNLOAD = DP_CMD_NONE + 48,
- DP_CMD_GET_NETWORK_TYPE = DP_CMD_NONE + 49,
- DP_CMD_GET_SAVED_PATH = DP_CMD_NONE + 50,
- DP_CMD_GET_TEMP_SAVED_PATH = DP_CMD_NONE + 51,
- DP_CMD_GET_MIME_TYPE = DP_CMD_NONE + 52,
- DP_CMD_GET_HTTP_HEADER = DP_CMD_NONE + 53,
- DP_CMD_GET_HTTP_HEADER_LIST = DP_CMD_NONE + 54,
- DP_CMD_ADD_EXTRA_PARAM = DP_CMD_NONE + 63,
- DP_CMD_GET_EXTRA_PARAM = DP_CMD_NONE + 64,
- DP_CMD_REMOVE_EXTRA_PARAM = DP_CMD_NONE + 65,
- DP_CMD_GET_RECEIVED_SIZE = DP_CMD_NONE + 71,
- DP_CMD_GET_TOTAL_FILE_SIZE = DP_CMD_NONE + 72,
- DP_CMD_GET_CONTENT_NAME = DP_CMD_NONE + 73,
- DP_CMD_GET_HTTP_STATUS = DP_CMD_NONE + 74,
- DP_CMD_GET_ETAG = DP_CMD_NONE + 75,
- DP_CMD_GET_STATE = DP_CMD_NONE + 81,
- DP_CMD_GET_ERROR = DP_CMD_NONE + 91,
- DP_CMD_SET_COMMAND_SOCKET = DP_CMD_NONE + 100,
- DP_CMD_SET_EVENT_SOCKET = DP_CMD_NONE + 101
+ DP_CMD_ECHO,
+ DP_CMD_CREATE,
+ DP_CMD_START,
+ DP_CMD_SET_COMMAND_SOCKET,
+ DP_CMD_SET_EVENT_SOCKET,
+ DP_CMD_FREE,
+
+ DP_CMD_ACTION_SECT = 100,
+ DP_CMD_PAUSE,
+ DP_CMD_CANCEL,
+ DP_CMD_DESTROY,
+
+ DP_CMD_GET_SECT = 200,
+ DP_CMD_GET_URL,
+ DP_CMD_GET_DESTINATION,
+ DP_CMD_GET_FILENAME,
+ DP_CMD_GET_NOTIFICATION,
+ DP_CMD_GET_STATE_CALLBACK,
+ DP_CMD_GET_PROGRESS_CALLBACK,
+ DP_CMD_GET_HTTP_HEADERS,
+ DP_CMD_GET_AUTO_DOWNLOAD,
+ DP_CMD_GET_NETWORK_TYPE,
+ DP_CMD_GET_SAVED_PATH,
+ DP_CMD_GET_TEMP_SAVED_PATH,
+ DP_CMD_GET_MIME_TYPE,
+ DP_CMD_GET_HTTP_HEADER,
+ DP_CMD_GET_HTTP_HEADER_LIST,
+ DP_CMD_GET_EXTRA_PARAM,
+ DP_CMD_GET_RECEIVED_SIZE,
+ DP_CMD_GET_TOTAL_FILE_SIZE,
+ DP_CMD_GET_CONTENT_NAME,
+ DP_CMD_GET_HTTP_STATUS,
+ DP_CMD_GET_ETAG,
+ DP_CMD_GET_STATE,
+ DP_CMD_GET_ERROR,
+ DP_CMD_GET_NOTIFICATION_BUNDLE,
+ DP_CMD_GET_NOTIFICATION_TITLE,
+ DP_CMD_GET_NOTIFICATION_DESCRIPTION,
+ DP_CMD_GET_NOTIFICATION_TYPE,
+
+ DP_CMD_SET_SECT = 300,
+ DP_CMD_SET_URL,
+ DP_CMD_SET_DESTINATION,
+ DP_CMD_SET_FILENAME,
+ DP_CMD_SET_NOTIFICATION,
+ DP_CMD_SET_STATE_CALLBACK,
+ DP_CMD_SET_PROGRESS_CALLBACK,
+ DP_CMD_SET_AUTO_DOWNLOAD,
+ DP_CMD_SET_NETWORK_TYPE,
+ DP_CMD_SET_HTTP_HEADER,
+ DP_CMD_SET_EXTRA_PARAM, // prevent build error
+ DP_CMD_DEL_HTTP_HEADER,
+ DP_CMD_ADD_EXTRA_PARAM,
+ DP_CMD_REMOVE_EXTRA_PARAM,
+ DP_CMD_SET_NOTIFICATION_BUNDLE,
+ DP_CMD_SET_NOTIFICATION_TITLE,
+ DP_CMD_SET_NOTIFICATION_DESCRIPTION,
+ DP_CMD_SET_NOTIFICATION_TYPE,
+
+ DP_CMD_LAST_SECT = 400
} dp_command_type;
typedef struct {
[Unit]
Description=Download provider service
+After=check-mount.service
[Service]
Type=simple
ExecStart=/usr/bin/download-provider
[Install]
-WantedBy=tizen-middleware.target
+WantedBy=graphical.target
--- /dev/null
+[Socket]
+ListenStream=/tmp/download-provider
+SocketMode=0777
+
+[Install]
+WantedBy=sockets.target