NULL_CHECK_RET(file_info);
file_path = file_info->file_path;
+
+ NULL_CHECK_RET(file_path);
+
ptr = strrchr(file_path, '/');
if (ptr) {
ptr++;
file_info->file_path = strdup(file_path);
free(origin_path);
ret = __decide_file_path_for_resume(file_info);
+ if(file_info) {
+ ret = __decide_file_path_for_resume(file_info);
+ }
} else {
ret = __decide_file_path(da_info);
}
DA_LOGE("Invalid Argument");
return DA_ERR_INVALID_ARGUMENT;
}
-
+#if 0
key = VCONFKEY_BROWSER_USER_AGENT;
ret = __get_conf_string(key, uagent_str);
if(ret == DA_RESULT_OK) {
return ret;
}
}
+#endif
DA_LOGI("No UA information from vconf !!");
*uagent_str = strdup(DEFAULT_UA_STR);
DA_LOGV("Set default UA");
#define DA_ERR_DRM_FAIL -600
// string to check invalid characters in path before using open() and fopen() API's
-#define DA_INVALID_PATH_STRING ";\\\":*?<>|()"
+#define DA_INVALID_PATH_STRING ";\\\":*?<>|"
#endif
%define _ux_define tizen2.3
Name: download-provider
Summary: Download the contents in background
-Version: 2.1.26
+Version: 2.1.30
Release: 0
Group: Development/Libraries
License: Apache-2.0
%define download_booster OFF
%define sys_resource OFF
%define support_oma_drm OFF
+%ifarch armv7l
%define wifi_direct ON
+%else
+%define wifi_direct OFF
+%endif
%define support_security_privilege OFF
%define support_companion_mode OFF
%define support_notification ON
struct sockaddr_un clientaddr;
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- TRACE_STRERROR("[CRITICAL] socket system error");
+ TRACE_ERROR("[CRITICAL] socket system error");
return -1;
}
(struct sockaddr*)&clientaddr, sizeof(clientaddr)) < 0) {
close(sockfd);
if (errno == EACCES || errno == EPERM) {
- TRACE_STRERROR("check permission");
+ TRACE_ERROR("check permission");
return -DP_ERROR_PERMISSION_DENIED;
}
return -1;
if (g_dp_event_thread_id > 0 &&
pthread_kill(g_dp_event_thread_id, 0) != ESRCH) {
if (pthread_cancel(g_dp_event_thread_id) != 0) {
- TRACE_STRERROR("pthread:%d", (int)g_dp_event_thread_id);
+ TRACE_ERROR("pthread:%d", (int)g_dp_event_thread_id);
}
g_dp_event_thread_id = 0;
}
static void *__dp_event_manager(void *arg)
{
if (g_dp_client == NULL) {
- TRACE_STRERROR("[CRITICAL] INTERFACE null");
+ TRACE_ERROR("[CRITICAL] INTERFACE null");
return 0;
}
TRACE_DEBUG("IPC ESTABILISH %s", notify_fifo);
g_dp_client->notify = open(notify_fifo, O_RDONLY, 0600);
if (g_dp_client->notify < 0) {
- TRACE_STRERROR("[CRITICAL] failed to ESTABILISH IPC %s", notify_fifo);
+ TRACE_ERROR("[CRITICAL] failed to ESTABILISH IPC %s", notify_fifo);
g_dp_event_thread_id = 0;
CLIENT_MUTEX_LOCK(&g_function_mutex);
__clear_interface();
if (ipc_info == NULL || ipc_info->section != section ||
ipc_info->property != property ||
(download_id >= 0 && ipc_info->id != download_id)) {
- TRACE_STRERROR("socket read ipcinfo");
+ TRACE_ERROR("socket read ipcinfo");
free(ipc_info);
return DP_ERROR_IO_ERROR;
}
while(g_dp_client->channel < 0 && connect_retry-- > 0) {
int ret = __create_socket();
if (ret == -1) {
- TRACE_STRERROR("failed to connect to provider(remains:%d)", connect_retry);
+ TRACE_ERROR("failed to connect to provider(remains:%d)", connect_retry);
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 20000000;
struct timeval tv_timeo = { 5, 500000 }; // 5.5 second
g_dp_client->channel = ret;
if (setsockopt(g_dp_client->channel, SOL_SOCKET, SO_RCVTIMEO, &tv_timeo, sizeof(tv_timeo)) < 0) {
- TRACE_STRERROR("[CRITICAL] setsockopt SO_RCVTIMEO");
+ TRACE_ERROR("[CRITICAL] setsockopt SO_RCVTIMEO");
errorcode = DP_ERROR_IO_ERROR;
goto EXIT_CONNECT;
}
} else {
errorcode = -ret;
- TRACE_STRERROR("check error:%d", errorcode);
+ TRACE_ERROR("check error:%d", errorcode);
goto EXIT_CONNECT;
}
}
if (g_dp_client->channel < 0) {
- TRACE_STRERROR("[CRITICAL] connect system error");
+ TRACE_ERROR("[CRITICAL] connect system error");
errorcode = DP_ERROR_IO_ERROR;
goto EXIT_CONNECT;
}
if (errorcode == DP_ERROR_NONE && g_dp_event_thread_id <= 0) {
if (pthread_create(&g_dp_event_thread_id, NULL,
__dp_event_manager, g_dp_client) != 0) {
- TRACE_STRERROR("failed to create event-manager");
+ TRACE_ERROR("failed to create event-manager");
errorcode = DP_ERROR_IO_ERROR;
} else {
pthread_detach(g_dp_event_thread_id);
if (string_length > 0) {
char *recv_str = (char *)calloc((string_length + (size_t)1), sizeof(char));
if (recv_str == NULL) {
- TRACE_STRERROR("check memory length:%d", string_length);
+ TRACE_ERROR("check memory length:%d", string_length);
errorcode = DP_ERROR_OUT_OF_MEMORY;
__dp_ipc_clear_garbage(sock, string_length);
} else {
if (errorcode == DP_ERROR_NONE && extra_size > 0) {
unsigned char *recv_raws = (unsigned char *)calloc(extra_size, sizeof(unsigned char));
if (recv_raws == NULL) {
- TRACE_STRERROR("sock:%d check memory length:%d", sock, extra_size);
+ TRACE_ERROR("sock:%d check memory length:%d", sock, extra_size);
errorcode = DP_ERROR_OUT_OF_MEMORY;
__dp_ipc_clear_garbage(sock, extra_size);
} else {
if (errorcode == DP_ERROR_NONE && extra_size > 0) {
unsigned char *recv_raws = (unsigned char *)calloc(extra_size, sizeof(unsigned char));
if (recv_raws == NULL) {
- TRACE_STRERROR("sock:%d check memory length:%d", sock, extra_size);
+ TRACE_ERROR("sock:%d check memory length:%d", sock, extra_size);
errorcode = DP_ERROR_OUT_OF_MEMORY;
__dp_ipc_clear_garbage(sock, extra_size);
} else {
if (string_length > 0) {
char *recv_str = (char *)calloc((string_length + (size_t)1), sizeof(char));
if (recv_str == NULL) {
- TRACE_STRERROR("check memory length:%d", string_length);
+ TRACE_ERROR("check memory length:%d", string_length);
errorcode = DP_ERROR_OUT_OF_MEMORY;
__dp_ipc_clear_garbage(sock, string_length);
} else {
char **recv_strings = NULL;
recv_strings = (char **)calloc(array_size, sizeof(char *));
if (recv_strings == NULL) {
- TRACE_STRERROR("check memory size:%d", array_size);
+ TRACE_ERROR("check memory size:%d", array_size);
errorcode = DP_ERROR_OUT_OF_MEMORY;
*length = 0;
} else {
if (errorcode == DP_ERROR_NONE && string_length > 0) {
char *recv_str = (char *)calloc((string_length + (size_t)1), sizeof(char));
if (recv_str == NULL) {
- TRACE_STRERROR("check memory length:%d", string_length * sizeof(char));
+ TRACE_ERROR("check memory length:%d", string_length * sizeof(char));
errorcode = DP_ERROR_OUT_OF_MEMORY;
break;
} else {
dlog
libsystemd-daemon
vconf
+ libcurl
cynara-client
cynara-client-async
cynara-creds-socket
dp_client_slots_fmt *g_dp_client_slots = NULL;
static void *g_db_handle = 0;
static pthread_mutex_t g_db_mutex = PTHREAD_MUTEX_INITIALIZER;
+extern pthread_t g_client_manager_tid;
void dp_terminate(int signo)
{
TRACE_DEBUG("Received SIGTERM:%d", signo);
close(g_dp_sock);
g_dp_sock = -1;
+ if (g_client_manager_tid > 0)
+ pthread_kill(g_client_manager_tid, SIGUSR1);
}
void dp_broadcast_signal()
static int __dp_db_open_client_manager()
{
- CLIENT_MUTEX_LOCK(&g_db_mutex);
- if (dp_db_open_client_manager(&g_db_handle) < 0) {
- TRACE_ERROR("[CRITICAL] can not open SQL");
- CLIENT_MUTEX_UNLOCK(&g_db_mutex);
- return -1;
- }
- CLIENT_MUTEX_UNLOCK(&g_db_mutex);
- return 0;
+ int errorcode = DP_ERROR_NONE;
+ CLIENT_MUTEX_LOCK(&g_db_mutex);
+ if (g_db_handle == 0 || dp_db_check_connection(g_db_handle) < 0) {
+ if (dp_db_open_client_manager(&g_db_handle, &errorcode) < 0) {
+ TRACE_ERROR("failed to open database errorcode:%d", errorcode);
+ }
+ }
+ CLIENT_MUTEX_UNLOCK(&g_db_mutex);
+ return errorcode;
}
static void __dp_db_free_client_manager()
// make notify fifo
slot->client.notify = dp_notify_init(credential.pid);
if (slot->client.notify < 0) {
- TRACE_STRERROR("failed to open fifo slot:%d", clientfd);
+ TRACE_ERROR("failed to open fifo slot:%d", clientfd);
errorcode = DP_ERROR_IO_ERROR;
} else {
char *smack_label = NULL;
g_dp_sock = __dp_accept_socket_new();
if (g_dp_sock < 0) {
- TRACE_STRERROR("failed to open listen socket");
+ TRACE_ERROR("failed to open listen socket");
g_main_loop_quit(event_loop);
return 0;
}
dp_rebuild_dir(NOTIFY_DIR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
#endif
- if (__dp_db_open_client_manager() < 0) {
- TRACE_STRERROR("failed to open database for client-manager");
- g_main_loop_quit(event_loop);
- return 0;
- }
-
dp_client_slots_fmt *clients =
(dp_client_slots_fmt *)calloc(DP_MAX_CLIENTS,
sizeof(dp_client_slots_fmt));
eset = except_fdset;
if (select((maxfd + 1), &rset, 0, &eset, &timeout) < 0) {
- TRACE_STRERROR("interrupted by terminating");
+ TRACE_ERROR("interrupted by terminating");
break;
}
}
if (FD_ISSET(g_dp_sock, &eset) > 0) {
- TRACE_STRERROR("exception of socket");
+ TRACE_ERROR("exception of socket");
break;
} else if (FD_ISSET(g_dp_sock, &rset) > 0) {
clientfd = accept(g_dp_sock, (struct sockaddr *)&clientaddr,
&clientlen);
if (clientfd < 0) {
- TRACE_STRERROR("too many client ? accept failure");
+ TRACE_ERROR("too many client ? accept failure");
// provider need the time of refresh.
- break;
+ errorcode = DP_ERROR_DISK_BUSY;
}
// blocking & timeout to prevent the lockup by client.
if (setsockopt(clientfd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeo,
sizeof(tv_timeo)) < 0) {
TRACE_ERROR("failed to set timeout in blocking socket");
- close(clientfd);
- continue;
}
dp_ipc_fmt ipc_info;
ipc_info.id != -1 ||
ipc_info.size != 0) {
TRACE_ERROR("peer terminate ? ignore this connection");
- close(clientfd);
- continue;
+ errorcode = DP_ERROR_INVALID_PARAMETER;
}
#ifdef SO_PEERCRED // getting the info of client
if (getsockopt(clientfd, SOL_SOCKET, SO_PEERCRED,
&credential, &cr_len) < 0) {
TRACE_ERROR("failed to cred from sock:%d", clientfd);
- close(clientfd);
- continue;
+ errorcode = DP_ERROR_PERMISSION_DENIED;
}
#else // In case of not supported SO_PEERCRED
if (read(clientfd, &credential, sizeof(dp_credential)) <= 0) {
TRACE_ERROR("failed to cred from client:%d", clientfd);
- close(clientfd);
- continue;
+ errorcode = DP_ERROR_PERMISSION_DENIED;
}
#endif
- CLIENT_MUTEX_LOCK(&g_db_mutex);
- if (dp_db_check_connection(g_db_handle) < 0) {
- TRACE_ERROR("check database, provider can't work anymore");
- CLIENT_MUTEX_UNLOCK(&g_db_mutex);
- close(clientfd);
- break;
- }
- CLIENT_MUTEX_UNLOCK(&g_db_mutex);
-
- if (ipc_info.section == DP_SEC_INIT) {
-
- // new client
- errorcode = __dp_client_new(clientfd, clients, credential);
-
- } else {
- errorcode = DP_ERROR_INVALID_PARAMETER;
- }
- if (dp_ipc_query(clientfd, -1, DP_SEC_INIT, DP_PROP_NONE, errorcode, 0) < 0) {
- TRACE_ERROR("check ipc sock:%d", clientfd);
- }
- if (errorcode == DP_ERROR_NONE) {
- // write client info into database
-
- } else {
- TRACE_ERROR("sock:%d id:%d section:%s property:%s errorcode:%s size:%d",
- clientfd, ipc_info.id,
- dp_print_section(ipc_info.section),
- dp_print_property(ipc_info.property),
- dp_print_errorcode(ipc_info.errorcode),
- ipc_info.size);
- close(clientfd); // ban this client
- }
+ errorcode = __dp_db_open_client_manager();
+
+ if (errorcode == DP_ERROR_NONE) {
+ if (ipc_info.section == DP_SEC_INIT) {
+
+ // new client
+ errorcode = __dp_client_new(clientfd, clients, credential);
+
+ } else {
+ errorcode = DP_ERROR_INVALID_PARAMETER;
+ }
+ }
+ if (dp_ipc_query(clientfd, -1, ipc_info.section, DP_PROP_NONE, errorcode, 0) < 0) {
+ TRACE_ERROR("check ipc sock:%d", clientfd);
+ }
+
+ if (errorcode != DP_ERROR_NONE) {
+ TRACE_ERROR("sock:%d id:%d section:%s property:%s errorcode:%s size:%d",
+ clientfd, ipc_info.id,
+ dp_print_section(ipc_info.section),
+ dp_print_property(ipc_info.property),
+ dp_print_errorcode(ipc_info.errorcode),
+ ipc_info.size);
+ close(clientfd); // ban this client
+ }
+ if (errorcode == DP_ERROR_NO_SPACE || errorcode == DP_ERROR_DISK_BUSY) {
+ TRACE_ERROR("provider can't work anymore errorcode:%s", dp_print_errorcode(errorcode));
+ //break; // provider will be terminated after sending errorcode by each thread
+ }
} else {
#include <stdlib.h>
#include <sys/stat.h>
#include <signal.h>
+#include <limits.h>
#include <download-provider-log.h>
#include <download-provider-config.h>
static int __dp_get_download_id(dp_client_fmt *client)
{
- int download_id = -1;
- static int last_download_id = 0;
- int check_duplicate = 0;
- int errorcode = DP_ERROR_NONE;
-
- do {
- do {
- struct timeval tval;
- int cipher = 1;
- int c = 0;
-
- download_id = -1;
- gettimeofday(&tval, NULL);
-
- int usec = tval.tv_usec;
- for (c = 0; ; c++, cipher++) {
- if ((usec /= 10) <= 0)
- break;
- }
- if (tval.tv_usec == 0)
- tval.tv_usec = (tval.tv_sec & 0x0fff);
- int disit_unit = 10;
- for (c = 0; c < cipher - 3; c++)
- disit_unit = disit_unit * 10;
- download_id = 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_download_id == download_id);
- last_download_id = download_id;
- check_duplicate = dp_db_check_duplicated_int(client->dbhandle,
- DP_TABLE_LOGGING, DP_DB_COL_ID, download_id, &errorcode);
- if (errorcode != DP_ERROR_NONE) {
- TRACE_ERROR("ERROR [%d]", errorcode);
- }
- } while (check_duplicate != 0); // means duplicated id
- return download_id;
+ int download_id = -1;
+ int check_duplicate = 1;
+ int retry_count = 0;
+ int errorcode = DP_ERROR_NONE;
+ struct timeval tval;
+
+ if (dp_db_get_max_download_id(client->dbhandle,
+ DP_TABLE_LOGGING, &download_id, &errorcode) < 0) {
+ TRACE_ERROR("ERROR [%d]", errorcode);
+ // database is empty start with id : 1
+ download_id = DP_FIRST_DOWNLOAD_ID;
+ } else {
+ if (download_id < INT_MAX)
+ download_id++;
+ }
+
+ retry_count = 0;
+ do {
+ retry_count++;
+ if (download_id < INT_MAX) {
+ TRACE_DEBUG("download_id [%d]", download_id);
+ check_duplicate = dp_db_check_duplicated_int(client->dbhandle,
+ DP_TABLE_LOGGING, DP_DB_COL_ID, download_id, &errorcode);
+ if (errorcode == DP_ERROR_NONE) {
+ if (check_duplicate == 0) {
+ break;
+ }
+ } else {
+ TRACE_ERROR("ERROR [%d]", errorcode);
+ }
+ if (retry_count < 3) {
+ download_id++;
+ } else if (retry_count < 10) {
+ gettimeofday(&tval, NULL);
+ tval.tv_usec = (tval.tv_usec & 0x0fff);
+ download_id += 1171 * retry_count + tval.tv_usec;
+ } else if (retry_count < 20) {
+ gettimeofday(&tval, NULL);
+ tval.tv_usec = (tval.tv_usec & 0xff33ff) + retry_count;
+ download_id += tval.tv_usec;
+ } else {
+ TRACE_ERROR("failed to generate unique download_id [%d]", download_id);
+ return -1;
+ }
+ } else {
+ TRACE_ERROR("reached INT_MAX limit");
+ download_id = DP_FIRST_DOWNLOAD_ID;
+ }
+ } while (check_duplicate != 0);
+ return download_id;
}
void dp_request_create(dp_client_fmt *client, dp_request_fmt *request)
return DP_ERROR_OUT_OF_MEMORY;
}
- if (dp_db_new_logging(client->dbhandle, download_id, DP_STATE_READY, DP_ERROR_NONE, &errorcode) < 0) {
- TRACE_ERROR("new log sock:%d download-id:%d", client->channel, download_id);
- free(request);
- return DP_ERROR_DISK_BUSY;
- }
+ if (dp_db_new_logging(client->dbhandle, download_id, DP_STATE_READY, DP_ERROR_NONE, &errorcode) < 0) {
+ TRACE_ERROR("new log sock:%d download-id:%d errorcode:%s", client->channel, download_id, dp_print_errorcode(errorcode));
+ free(request);
+ return errorcode;
+ }
request->id = download_id;
request->agent_id = -1;
if (ipc_info->size > 0) {
char *recv_str = (char *)calloc((ipc_info->size + (size_t)1), sizeof(char));
if (recv_str == NULL) {
- TRACE_STRERROR("sock:%d check memory length:%d", sock, ipc_info->size);
+ TRACE_ERROR("sock:%d check memory length:%d", sock, ipc_info->size);
errorcode = DP_ERROR_OUT_OF_MEMORY;
} else {
if (dp_ipc_read(sock, recv_str, ipc_info->size, __FUNCTION__) <= 0) {
callback = requestp->state_cb;
} else {
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_STATE_EVENT, &callback, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
}
callback = requestp->progress_cb;
} else {
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_PROGRESS_EVENT, &callback, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
}
{
int autodownload = 0;
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_LOGGING, DP_DB_COL_AUTO_DOWNLOAD, &autodownload, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&autodownload, errorcode, sizeof(int));
network = requestp->network_type;
} else {
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_NETWORK_TYPE, &network, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
}
{
int network_bonding = 0;
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_NETWORK_BONDING, &network_bonding, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&network_bonding, errorcode, sizeof(int));
char *string = NULL;
unsigned length = 0;
if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_DOWNLOAD, DP_DB_COL_SAVED_PATH, (unsigned char **)&string, &length, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_string(client->channel, ipc_info, string, length, errorcode);
char *string = NULL;
unsigned length = 0;
if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_DOWNLOAD, DP_DB_COL_TMP_SAVED_PATH, (unsigned char **)&string, &length, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_string(client->channel, ipc_info, string, length, errorcode);
char *string = NULL;
unsigned length = 0;
if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_DOWNLOAD, DP_DB_COL_MIMETYPE, (unsigned char **)&string, &length, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_string(client->channel, ipc_info, string, length, errorcode);
} else {
// load content_size(INT64) from database;
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_DOWNLOAD, DP_DB_COL_CONTENT_SIZE, &file_size, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
}
char *string = NULL;
unsigned length = 0;
if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_DOWNLOAD, DP_DB_COL_CONTENT_NAME, (unsigned char **)&string, &length, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_string(client->channel, ipc_info, string, length, errorcode);
{
int httpstatus = 0;
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_DOWNLOAD, DP_DB_COL_HTTP_STATUS, &httpstatus, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&httpstatus, errorcode, sizeof(int));
char *string = NULL;
unsigned length = 0;
if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_DOWNLOAD, DP_DB_COL_ETAG, (unsigned char **)&string, &length, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_string(client->channel, ipc_info, string, length, errorcode);
state = requestp->state;
} else {
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_LOGGING, DP_DB_COL_STATE, &state, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_ID_NOT_FOUND;
}
}
errorvalue = requestp->error;
} else {
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_LOGGING, DP_DB_COL_ERRORCODE, &errorvalue, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_ID_NOT_FOUND;
}
}
// if already notification, unregister from notification bar.
} else {
if (dp_db_get_property_int(client->dbhandle, ipc_info->id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_TYPE, ¬i_type, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
}
char *string = NULL;
unsigned length = 0;
if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_SUBJECT, (unsigned char **)&string, &length, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_string(client->channel, ipc_info, string, length, errorcode);
char *string = NULL;
unsigned length = 0;
if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_DESCRIPTION, (unsigned char **)&string, &length, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_string(client->channel, ipc_info, string, length, errorcode);
if (raw_column == NULL) {
errorcode = DP_ERROR_INVALID_PARAMETER;
- TRACE_ERROR("invalid type %d type:%d", dp_print_property(ipc_info->property), bundle_type);
+ TRACE_ERROR("invalid type %s type:%d", dp_print_property(ipc_info->property), bundle_type);
if (dp_ipc_query(client->channel, ipc_info->id, ipc_info->section, ipc_info->property, errorcode, 0) < 0) {
errorcode = DP_ERROR_IO_ERROR;
TRACE_ERROR("check ipc sock:%d", client->channel);
unsigned length = 0;
// get blob binary from database by raw_column
if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_NOTIFICATION, raw_column, &raws_buffer, &length, &errorcode) < 0) {
- TRACE_ERROR("failed to get %d", dp_print_property(ipc_info->property));
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
errorcode = DP_ERROR_NO_DATA;
}
int result = __dp_request_feedback_string(client->channel, ipc_info, raws_buffer, (size_t)length, errorcode);
if (raw_info != NULL && raw_info->size > 0) {
unsigned char *recv_raws = (unsigned char *)calloc(raw_info->size, sizeof(unsigned char));
if (recv_raws == NULL) {
- TRACE_STRERROR("sock:%d check memory length:%d", client->channel, raw_info->size);
+ TRACE_ERROR("sock:%d check memory length:%d", client->channel, raw_info->size);
errorcode = DP_ERROR_OUT_OF_MEMORY;
} else {
if (dp_ipc_read(client->channel, recv_raws, raw_info->size, __FUNCTION__) <= 0) {
CLIENT_MUTEX_UNLOCK(&slot->mutex);
continue;
} else {
- TRACE_STRERROR("interrupted by client-manager sock:%d", client_sock);
+ TRACE_ERROR("interrupted by client-manager sock:%d", client_sock);
break;
}
}
CLIENT_MUTEX_LOCK(&slot->mutex);
- if (client->dbhandle == 0 || dp_db_check_connection(client->dbhandle) < 0) {
- if (dp_db_open_client(&client->dbhandle, slot->pkgname) < 0) {
- TRACE_ERROR("failed to open database for sock:%d", client_sock);
- CLIENT_MUTEX_UNLOCK(&slot->mutex);
- break;
- }
- }
+ errorcode = DP_ERROR_NONE;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
client->access_time = (int)time(NULL);
// read ipc_fmt first. below func will deal followed packets
dp_ipc_fmt *ipc_info = dp_ipc_get_fmt(client_sock);
if (ipc_info == NULL) {
- TRACE_STRERROR("sock:%d maybe closed", client_sock);
+ TRACE_ERROR("sock:%d maybe closed", client_sock);
errorcode = DP_ERROR_IO_ERROR;
} else {
TRACE_DEBUG("sock:%d id:%d section:%s property:%s errorcode:%s size:%d",
dp_print_errorcode(ipc_info->errorcode),
ipc_info->size);
- // JOB
- errorcode = __dp_client_requests(slot, ipc_info);
+ if (client->dbhandle == 0 || dp_db_check_connection(client->dbhandle) < 0) {
+ if (dp_db_open_client(&client->dbhandle, slot->pkgname, &errorcode) < 0) {
+ TRACE_ERROR("failed to open database for sock:%d errorcode:%s", client_sock, dp_print_errorcode(errorcode));
+ if (dp_ipc_query(client->channel, ipc_info->id,
+ ipc_info->section, ipc_info->property, errorcode, 0) < 0) {
+ TRACE_ERROR("check ipc sock:%d", client->channel);
+ }
+ }
+ }
+
+ if (errorcode == DP_ERROR_NONE) {
+ // JOB
+ errorcode = __dp_client_requests(slot, ipc_info);
+ }
+
}
free(ipc_info);
// 1. clear zombie requests. clean requests finished. paused or ready for long time
dp_client_clear_requests(slot);
- int sql_errorcode = DP_ERROR_NONE;
-
- // 2. maintain only 1000 rows for each client
- if (dp_db_limit_rows(client->dbhandle, DP_TABLE_LOGGING, DP_LOG_DB_LIMIT_ROWS, &sql_errorcode) < 0) {
- TRACE_INFO("limit rows error:%s", dp_print_errorcode(sql_errorcode));
- }
- // 3. maintain for 48 hours
- if (dp_db_limit_time(client->dbhandle, DP_TABLE_LOGGING, DP_CARE_CLIENT_INFO_PERIOD, &sql_errorcode) < 0) {
- TRACE_INFO("limit rows error:%s", dp_print_errorcode(sql_errorcode));
+ if (client->dbhandle != 0) {
+ int sql_errorcode = DP_ERROR_NONE;
+ // 2. maintain only 1000 rows for each client
+ if (dp_db_limit_rows(client->dbhandle, DP_TABLE_LOGGING, DP_LOG_DB_LIMIT_ROWS, &sql_errorcode) < 0) {
+ TRACE_INFO("limit rows error:%s", dp_print_errorcode(sql_errorcode));
+ }
+ // 3. maintain for 48 hours
+ if (dp_db_limit_time(client->dbhandle, DP_TABLE_LOGGING, DP_CARE_CLIENT_INFO_PERIOD, &sql_errorcode) < 0) {
+ TRACE_INFO("limit rows error:%s", dp_print_errorcode(sql_errorcode));
+ }
}
// 4. if no requests, exit by itself.
if (slot->client.requests == NULL) {
// if no requests, clear slot after disconnect with client.
CLIENT_MUTEX_LOCK(&slot->mutex);
- TRACE_INFO("thread done slot %p thread:%0x sock:%d", slot, slot->thread, client_sock);
+ TRACE_INFO("thread done slot %p thread:%0x", slot, slot->thread);
slot->thread = 0;// to prevent kill thread twice
return 0;
}
-static int __db_open(sqlite3 **handle, char *database)
+static int __db_open(sqlite3 **handle, char *database, int *errorcode)
{
- if (sqlite3_open_v2(database, handle, SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK) {
- int errorcode = sqlite3_errcode(*handle);
- TRACE_ERROR("error(%d):%s", errorcode, sqlite3_errmsg(*handle));
- *handle = 0;
- if (errorcode == SQLITE_CORRUPT) { // remove & re-create
- TRACE_SECURE_INFO("unlink [%s]", database);
- unlink(database);
- errorcode = SQLITE_CANTOPEN;
- }
- if (errorcode == SQLITE_CANTOPEN) {
- // create empty database
- if (sqlite3_open(database, handle) != SQLITE_OK ) {
- TRACE_SECURE_INFO("failed to connect:%s", database);
- unlink(database);
- *handle = 0;
- return -1;
- }
- } else {
- TRACE_ERROR("can not handle this error:%d", errorcode);
- *handle = 0;
- return -1;
- }
- }
- __basic_property(*handle);
- return 0;
+ if (sqlite3_open_v2(database, handle, SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK) {
+ int sqlerrcode = sqlite3_errcode(*handle);
+ TRACE_ERROR("database open error(%d):%s", sqlerrcode, sqlite3_errmsg(*handle));
+ if (sqlerrcode == SQLITE_CORRUPT) { // remove & re-create
+ TRACE_SECURE_INFO("unlink [%s]", database);
+ unlink(database);
+ sqlerrcode = SQLITE_CANTOPEN;
+ }
+ if (sqlerrcode == SQLITE_CANTOPEN) {
+ *handle = 0;
+ // create empty database
+ if (sqlite3_open(database, handle) != SQLITE_OK ) {
+ sqlerrcode = sqlite3_errcode(*handle);
+ TRACE_SECURE_ERROR("failed to create %s error:%d", database, sqlerrcode);
+ TRACE_ERROR("database new error(%d):%s", sqlerrcode, sqlite3_errmsg(*handle));
+ if (sqlerrcode == SQLITE_FULL || sqlerrcode == SQLITE_CANTOPEN) { // can not create temporary file for connection
+ *errorcode = DP_ERROR_NO_SPACE; // DP_ERROR_OUT_OF_MEMORY
+ } else {
+ *errorcode = DP_ERROR_DISK_BUSY;
+ unlink(database);
+ }
+ *handle = 0;
+ return -1;
+ }
+ } else {
+ TRACE_ERROR("can not handle this error(%d):%s", sqlerrcode, sqlite3_errmsg(*handle));
+ *errorcode = DP_ERROR_OUT_OF_MEMORY;
+ *handle = 0;
+ return -1;
+ }
+ }
+ __basic_property(*handle);
+ return 0;
}
int dp_db_check_connection(void *handle)
return 0;
}
-int dp_db_open_client_manager(void **handle)
+int dp_db_open_client_manager(void **handle, int *errorcode)
{
- if (*handle == 0) {
- char *database = sqlite3_mprintf("%s/%s", DATABASE_DIR, DP_DBFILE_CLIENTS);
- if (database == NULL) {
- TRACE_ERROR("failed to make clients database file path");
- return -1;
- }
- if (__db_open((sqlite3 **)handle, database) < 0) {
- TRACE_ERROR("failed to open %s", database);
- *handle = 0;
- } else {
- // whenever open new handle, check all tables. it's simple
- if (__rebuild_client_manager_tables(*handle) < 0) {
- dp_db_close(*handle);
- *handle = 0;
- }
- }
- sqlite3_free(database);
- }
- return *handle ? 0 : -1;
+ if (*handle == 0) {
+ char *database = sqlite3_mprintf("%s/%s", DATABASE_DIR, DP_DBFILE_CLIENTS);
+ if (database == NULL) {
+ TRACE_ERROR("failed to make clients database file path");
+ *errorcode = DP_ERROR_OUT_OF_MEMORY;
+ return -1;
+ }
+ if (__db_open((sqlite3 **)handle, database, errorcode) < 0) {
+ TRACE_ERROR("failed to open clients database file");
+ *handle = 0;
+ } else {
+ // whenever open new handle, check all tables. it's simple
+ if (__rebuild_client_manager_tables(*handle) < 0) {
+ *errorcode = DP_ERROR_NO_SPACE;
+ dp_db_close(*handle);
+ *handle = 0;
+ }
+ }
+ sqlite3_free(database);
+ }
+ return *handle ? 0 : -1;
}
static char *__dp_db_get_client_db_path(char *pkgname)
return 0;
}
-int dp_db_open_client(void **handle, char *pkgname)
+int dp_db_open_client(void **handle, char *pkgname, int *errorcode)
{
- if (*handle == 0) {
- char *database = __dp_db_get_client_db_path(pkgname);
- if (database == NULL) {
- TRACE_ERROR("failed to make db file path");
- return -1;
- }
- if (__db_open((sqlite3 **)handle, database) < 0) {
- TRACE_SECURE_ERROR("failed to open %s", database);
- *handle = 0;
- } else {
- // whenever open new handle, check all tables. it's simple
- if (__rebuild_client_tables(*handle) < 0) {
- dp_db_close(*handle);
- *handle = 0;
- }
- }
- sqlite3_free(database);
- }
- return *handle ? 0 : -1;
+ if (*handle == 0) {
+ char *database = __dp_db_get_client_db_path(pkgname);
+ if (database == NULL) {
+ TRACE_ERROR("failed to make db file path");
+ *errorcode = DP_ERROR_OUT_OF_MEMORY;
+ return -1;
+ }
+ if (__db_open((sqlite3 **)handle, database, errorcode) < 0) {
+ TRACE_SECURE_ERROR("failed to open %s", database);
+ *handle = 0;
+ } else {
+ // whenever open new handle, check all tables. it's simple
+ if (__rebuild_client_tables(*handle) < 0) {
+ *errorcode = DP_ERROR_NO_SPACE;
+ dp_db_close(*handle);
+ *handle = 0;
+ }
+ }
+ sqlite3_free(database);
+ }
+ return *handle ? 0 : -1;
}
void dp_db_close(void *handle)
return headers_index;
}
+int dp_db_get_max_download_id(void *handle, const char *table, int *pvalue, int *error)
+{
+ TRACE_DEBUG("");
+ int errorcode = SQLITE_OK;
+ sqlite3_stmt *stmt = NULL;
+ *error = DP_ERROR_NONE;
+ DP_DB_PARAM_NULL_CHECK;
+
+ char *query = sqlite3_mprintf("SELECT MAX(%s) FROM %s", DP_DB_COL_ID, table);
+ DP_DB_BUFFER_NULL_CHECK(query);
+ //TRACE_DEBUG("debug query:%s", query);
+ errorcode = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
+ DP_DB_BASIC_EXCEPTION_CHECK;
+
+ errorcode = sqlite3_step(stmt);
+ if (errorcode == SQLITE_ROW) {
+ int data_type = sqlite3_column_type(stmt, 0);
+ if (data_type == SQLITE_INTEGER) {
+ int recv_int = sqlite3_column_int(stmt, 0);
+ *pvalue = recv_int;
+ } else if (data_type == SQLITE_NULL) {
+ /* table has no any entry */
+ TRACE_DEBUG("table has no entry");
+ *error = DP_ERROR_NO_DATA;
+ } else {
+ TRACE_ERROR("check column type:%d", data_type);
+ *error = DP_ERROR_INVALID_PARAMETER;
+ }
+ } else if (errorcode == SQLITE_DONE) {
+ TRACE_DEBUG("no data");
+ *error = DP_ERROR_NO_DATA;
+ } else {
+ if ((*error = dp_db_get_errorcode(handle)) == DP_ERROR_NONE) {
+ TRACE_ERROR("ERROR :: unknown");
+ *error = DP_ERROR_DISK_BUSY;
+ }
+ }
+ __dp_finalize(stmt);
+ if (*error != DP_ERROR_NONE)
+ return -1;
+ return 0;
+}
+
+
{
int errorcode = basecode;
if (errno == EPIPE) {
- TRACE_STRERROR("[EPIPE:%d] Broken Pipe", errno);
+ TRACE_ERROR("[EPIPE:%d] Broken Pipe", errno);
errorcode = DP_ERROR_IO_ERROR;
} else if (errno == EAGAIN) {
- TRACE_STRERROR("[EAGAIN:%d]", errno);
+ TRACE_ERROR("[EAGAIN:%d]", errno);
errorcode = DP_ERROR_IO_EAGAIN;
} else if (errno == EINTR) {
- TRACE_STRERROR("[EINTR:%d]", errno);
+ TRACE_ERROR("[EINTR:%d]", errno);
errorcode = DP_ERROR_IO_EINTR;
} else if (errno == ENOENT) {
- TRACE_STRERROR("[ENOENT:%d]", errno);
+ TRACE_ERROR("[ENOENT:%d]", errno);
errorcode = DP_ERROR_IO_ERROR;
} else {
- TRACE_STRERROR("[errno:%d]", errno);
+ TRACE_ERROR("[errno:%d]", errno);
}
return errorcode;
}
TRACE_ERROR("[ERROR] check buffer sock:%d", sock);
return -1;
} else if (write(sock, value, type_size) <= 0) {
- TRACE_STRERROR("[IPC.Write] exception sock:%d", sock);
+ TRACE_ERROR("[IPC.Write] exception sock:%d", sock);
return -1;
}
return 0;
memset(ipc_info, 0x00, sizeof(dp_ipc_fmt));
ssize_t recv_size = read(sock, ipc_info, sizeof(dp_ipc_fmt));
if (recv_size <= 0 || recv_size != sizeof(dp_ipc_fmt)) {
- TRACE_STRERROR("socket read ipcinfo read size:%d", recv_size);
+ TRACE_ERROR("socket read ipcinfo read size:%d", recv_size);
free(ipc_info);
return NULL;
}
#include <systemd/sd-daemon.h>
#include <glib-object.h>
+#include <curl/curl.h>
#include "download-provider-config.h"
#include "download-provider-log.h"
#include "download-provider-client-manager.h"
#include "download-provider-network.h"
+pthread_t g_client_manager_tid;
void *dp_client_manager(void *arg);
int main(int argc, char **argv)
{
GMainLoop *event_loop;
- pthread_t tid;
TRACE_INFO("download-provider's working is started");
g_type_init();
TRACE_ERROR("failed to init network-manager");
return 0;
}
- // create a thread for main thread
- if (pthread_create(&tid, NULL, dp_client_manager, (void *)event_loop) != 0) {
- TRACE_ERROR("failed to create main thread");
- return 0;
- } else {
- pthread_detach(tid);
- TRACE_INFO("download main thread is created[%lu]", tid);
- }
+ //Requested By platform team, It should be in main thread.
+ curl_global_init(CURL_GLOBAL_ALL);
+
+ // create a thread for main thread
+ if (pthread_create(&g_client_manager_tid, NULL, dp_client_manager, (void *)event_loop) != 0) {
+ TRACE_ERROR("failed to create main thread");
+ curl_global_cleanup();
+ return 0;
+ } else {
+ pthread_detach(g_client_manager_tid);
+ TRACE_INFO("download main thread is created[%lu]", g_client_manager_tid);
+ }
TRACE_INFO("g main loop is started");
g_main_loop_run(event_loop);
+ curl_global_cleanup();
dp_network_connection_destroy();
g_main_loop_unref(event_loop);
TRACE_DEBUG("try to create notification-manager");
if (pthread_create(&g_dp_notification_manager_tid, NULL,
__dp_notification_manager, NULL) != 0) {
- TRACE_STRERROR("failed to create notification-manager");
+ TRACE_ERROR("failed to create notification-manager");
return -1;
}
}
snprintf(sender, len + 1, "%s", temp);
} else {
sender = dp_strdup(temp);
+ if (sender == NULL)
+ return NULL;
}
// For credential URL
size_t path_size = sizeof(NOTIFY_DIR) + 21;
char *notify_fifo = (char *)calloc(path_size, sizeof(char));
if (notify_fifo == NULL) {
- TRACE_STRERROR("failed to alocalte fifo path pid:%d", (int)pid);
+ TRACE_ERROR("failed to alocalte fifo path pid:%d", (int)pid);
return NULL;
}
if (snprintf(notify_fifo, path_size,"%s/%d", NOTIFY_DIR, pid) < 0) {
- TRACE_STRERROR("failed to make fifo path pid:%d", (int)pid);
+ TRACE_ERROR("failed to make fifo path pid:%d", (int)pid);
free(notify_fifo);
return NULL;
}
if (stat(notify_fifo, &fifo_state) == 0) // found
unlink(notify_fifo);
if (mkfifo(notify_fifo, 0644/*-rwrr*/) < 0) {
- TRACE_STRERROR("failed to make fifo %s", notify_fifo);
+ TRACE_ERROR("failed to make fifo %s", notify_fifo);
} else {
notify_fd = open(notify_fifo, O_RDWR | O_NONBLOCK, 0644);
}
if ((fchown(fd, cred.uid, cred.gid) != 0) ||
(fchmod(fd, S_IRUSR | S_IWUSR |
S_IRGRP | S_IROTH) != 0)) {
- TRACE_STRERROR("[ERROR][%d] permission user:%d group:%d",
+ TRACE_ERROR("[ERROR][%d] permission user:%d group:%d",
request->id, cred.uid, cred.gid);
errorcode = DP_ERROR_PERMISSION_DENIED;
}
} else {
- TRACE_STRERROR("fstat & lstat info have not matched");
+ TRACE_ERROR("fstat & lstat info have not matched");
errorcode = DP_ERROR_PERMISSION_DENIED;
}
} else {
- TRACE_STRERROR("fstat call failed");
+ TRACE_ERROR("fstat call failed");
errorcode = DP_ERROR_PERMISSION_DENIED;
}
close(fd);
errorcode = DP_ERROR_IO_ERROR;
}
} else {
- TRACE_STRERROR("lstat call failed");
+ TRACE_ERROR("lstat call failed");
errorcode = DP_ERROR_PERMISSION_DENIED;
}
if (errorcode == DP_ERROR_NONE && dp_smack_is_mounted() == 1) {
errorcode = dp_smack_set_label(smack_label, dir_path, saved_path);
free(dir_path);
} else {
- TRACE_STRERROR("[ERROR] calloc");
+ TRACE_ERROR("[ERROR] calloc");
errorcode = DP_ERROR_OUT_OF_MEMORY;
}
free(smack_label);
base_req->id, tmp_saved_path);
if (dp_is_file_exist(tmp_saved_path) == 0) {
if (unlink(tmp_saved_path) != 0)
- TRACE_STRERROR("failed to remove file id:%d", base_req->id);
+ TRACE_ERROR("failed to remove file id:%d", base_req->id);
}
}
}
if (0 == ret || EBUSY == ret)
return 0;
else
- TRACE_STRERROR("error:%d.%s", ret, __print_pthread_error(ret));
+ TRACE_ERROR("error:%d.%s", ret, __print_pthread_error(ret));
return -1;
}
{
int ret = pthread_mutex_lock(mutex);
if (ret != 0)
- TRACE_STRERROR("%s:%d error:%d.%s", func, line, ret,
+ TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
__print_pthread_error(ret));
}
{
int ret = pthread_mutex_lock(mutex);
if (ret != 0)
- TRACE_STRERROR("%s:%d error:%d.%s", func, line, ret,
+ TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
__print_pthread_error(ret));
return ret;
}
{
int ret = pthread_mutex_trylock(mutex);
if (ret != 0 && ret != EINVAL) {
- TRACE_STRERROR("%s:%d error:%d.%s", func, line, ret,
+ TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
__print_pthread_error(ret));
}
return ret;
deltatime.tv_nsec = 0;
int ret = pthread_mutex_timedlock(mutex, &deltatime);
if (ret != 0) {
- TRACE_STRERROR("%s:%d error:%d.%s", func, line, ret,
+ TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
__print_pthread_error(ret));
}
return ret;
{
int ret = pthread_mutex_unlock(mutex);
if (ret != 0)
- TRACE_STRERROR("%s:%d error:%d.%s", func, line, ret,
+ TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
__print_pthread_error(ret));
}
{
int ret = pthread_mutex_destroy(mutex);
if (ret != 0) {
- TRACE_STRERROR("error:%d.%s", ret, __print_pthread_error(ret));
+ TRACE_ERROR("error:%d.%s", ret, __print_pthread_error(ret));
if(EBUSY == ret) {
if (pthread_mutex_unlock(mutex) == 0)
pthread_mutex_destroy(mutex);
TRACE_DEBUG("try to create queue-manager");
if (pthread_create(&g_dp_queue_manager_tid, NULL,
__dp_queue_manager, NULL) != 0) {
- TRACE_STRERROR("failed to create queue-manager");
+ TRACE_ERROR("failed to create queue-manager");
return -1;
}
}
TRACE_SECURE_ERROR("failed to set smack label:%s", dirpath);
}
} else {
- TRACE_STRERROR("failed to create directory:%s", dirpath);
+ TRACE_ERROR("failed to create directory:%s", dirpath);
}
}
}
dest = (char *)calloc(src_len + 1, sizeof(char));
if (dest == NULL) {
- TRACE_STRERROR("[CHECK] allocation");
+ TRACE_ERROR("[CHECK] allocation");
return NULL;
}
memcpy(dest, src, src_len * sizeof(char));
if ((file_path != NULL && strlen(file_path) > 0) &&
dp_is_file_exist(file_path) == 0) {
if (unlink(file_path) != 0) {
- TRACE_STRERROR("failed to remove file");
+ TRACE_ERROR("failed to remove file");
return -1;
}
return 0;
#define DOWNLOAD_PROVIDER_DB_H
int dp_db_check_connection(void *handle);
-int dp_db_open_client_manager(void **handle);
-int dp_db_open_client(void **handle, char *pkgname);
+int dp_db_open_client_manager(void **handle, int *errorcode);
+int dp_db_open_client(void **handle, char *pkgname, int *errorcode);
int dp_db_open_client_v2(void **handle, char *pkgname);
int dp_db_remove_database(char *pkgname, long now_time, long diff_time);
int dp_db_get_ids(void *handle, const char *table, char *idcolumn, int *ids, const char *where, const int limit, char *ordercolumn, char *ordering, int *error);
int dp_db_limit_rows(void *handle, const char *table, int limit, int *error);
int dp_db_limit_time(void *handle, const char *table, int hours, int *error);
int dp_db_get_http_headers_list(void *handle, int id, char **headers, int *error);
+int dp_db_get_max_download_id(void *handle, const char *table, int *pvalue, int *error);
#endif
#else
#define TRACE_DEBUG(...) do { } while(0)
#define TRACE_ERROR(...) do { } while(0)
-#define TRACE_STRERROR(...) do { } while(0)
+#define TRACE_ERROR(...) do { } while(0)
#define TRACE_INFO(...) do { } while(0)
#define TRACE_WARN(...) do { } while(0)
#define TRACE_SECURE_DEBUG(...) do { } while(0)
// string to check invalid characters in path before using open() and fopen() API's
#define DP_INVALID_PATH_STRING ";\\\":*?<>|()"
-
+// download provider first download id.
+#define DP_FIRST_DOWNLOAD_ID 1
#include <unistd.h>