#define SIZE_MAX ((size_t) - 1)
#endif
+static const char *dp_db_column[] = {
+ [DP_PROP_NONE] = NULL,
+ [DP_PROP_URL] = DP_DB_COL_URL,
+ [DP_PROP_PROXY] = DP_DB_COL_PROXY,
+ [DP_PROP_DESTINATION] = DP_DB_COL_DESTINATION,
+ [DP_PROP_FILENAME] = DP_DB_COL_FILENAME,
+ [DP_PROP_STATE_CALLBACK] = DP_DB_COL_STATE_EVENT,
+ [DP_PROP_PROGRESS_CALLBACK] = DP_DB_COL_PROGRESS_EVENT,
+ [DP_PROP_AUTO_DOWNLOAD] = DP_DB_COL_AUTO_DOWNLOAD,
+ [DP_PROP_NETWORK_TYPE] = DP_DB_COL_NETWORK_TYPE,
+ [DP_PROP_NETWORK_BONDING] = DP_DB_COL_NETWORK_BONDING,
+ [DP_PROP_SAVED_PATH] = DP_DB_COL_SAVED_PATH,
+ [DP_PROP_TEMP_SAVED_PATH] = DP_DB_COL_TMP_SAVED_PATH,
+ [DP_PROP_MIME_TYPE] = DP_DB_COL_MIMETYPE,
+ [DP_PROP_RECEIVED_SIZE] = NULL,
+ [DP_PROP_TOTAL_FILE_SIZE] = DP_DB_COL_CONTENT_SIZE,
+ [DP_PROP_CONTENT_NAME] = DP_DB_COL_CONTENT_NAME,
+ [DP_PROP_HTTP_STATUS] = DP_DB_COL_HTTP_STATUS,
+ [DP_PROP_ETAG] = DP_DB_COL_ETAG,
+ [DP_PROP_STATE] = DP_DB_COL_STATE,
+ [DP_PROP_ERROR] = DP_DB_COL_ERRORCODE,
+ [DP_PROP_HTTP_HEADERS] = NULL,
+ [DP_PROP_HTTP_HEADER] = NULL,
+ [DP_PROP_NOTIFICATION_RAW] = NULL,
+ [DP_PROP_NOTIFICATION_SUBJECT] = DP_DB_COL_NOTI_SUBJECT,
+ [DP_PROP_NOTIFICATION_DESCRIPTION] = DP_DB_COL_NOTI_DESCRIPTION,
+ [DP_PROP_NOTIFICATION_TYPE] = DP_DB_COL_NOTI_TYPE,
+ [DP_PROP_CREATE] = NULL,
+ [DP_PROP_START] = NULL,
+ [DP_PROP_PAUSE] = NULL,
+ [DP_PROP_CANCEL] = NULL,
+ [DP_PROP_DESTROY] = NULL,
+};
+
char *dp_print_state(int state)
{
switch (state) {
return "UNKNOWN";
}
+static const char *__dp_get_db_table_name(unsigned property)
+{
+ switch (property) {
+ case DP_PROP_URL:
+ case DP_PROP_PROXY:
+ case DP_PROP_DESTINATION:
+ case DP_PROP_FILENAME:
+ case DP_PROP_STATE_CALLBACK:
+ case DP_PROP_PROGRESS_CALLBACK:
+ case DP_PROP_NETWORK_TYPE:
+ case DP_PROP_NETWORK_BONDING:
+ return DP_TABLE_REQUEST;
+ case DP_PROP_AUTO_DOWNLOAD:
+ case DP_PROP_STATE:
+ case DP_PROP_ERROR:
+ return DP_TABLE_LOGGING;
+ case DP_PROP_SAVED_PATH:
+ case DP_PROP_TEMP_SAVED_PATH:
+ case DP_PROP_MIME_TYPE:
+ case DP_PROP_CONTENT_NAME:
+ case DP_PROP_ETAG:
+ case DP_PROP_TOTAL_FILE_SIZE:
+ case DP_PROP_HTTP_STATUS:
+ return DP_TABLE_DOWNLOAD;
+ case DP_PROP_NOTIFICATION_RAW:
+ case DP_PROP_NOTIFICATION_SUBJECT:
+ case DP_PROP_NOTIFICATION_DESCRIPTION:
+ case DP_PROP_NOTIFICATION_TYPE:
+ return DP_TABLE_NOTIFICATION;
+ case DP_PROP_HTTP_HEADERS:
+ case DP_PROP_HTTP_HEADER:
+ return DP_TABLE_HEADERS;
+ case DP_PROP_RECEIVED_SIZE:
+ case DP_PROP_NONE:
+ case DP_PROP_CREATE:
+ case DP_PROP_START:
+ case DP_PROP_PAUSE:
+ case DP_PROP_CANCEL:
+ case DP_PROP_DESTROY:
+ default:
+ break;
+ }
+ return NULL;
+}
+
static int __dp_get_download_id(dp_client_fmt *client)
{
int download_id = -1;
return errorcode;
}
-static int __dp_request_get_info(dp_client_fmt *client, dp_ipc_fmt *ipc_info, dp_request_fmt *requestp)
+static int __dp_request_get_info_string(dp_client_fmt *client, dp_ipc_fmt *ipc_info)
{
int errorcode = DP_ERROR_NONE;
- switch (ipc_info->property) {
- case DP_PROP_URL:
- {
- char *string = NULL;
- unsigned length = 0;
- if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_URL, (unsigned char **)&string, &length, &errorcode) < 0) {
- 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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
- break;
- }
- case DP_PROP_PROXY:
- {
- char *string = NULL;
- unsigned length = 0;
- if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_PROXY, (unsigned char **)&string, &length, &errorcode) < 0) {
- 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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
- break;
- }
- case DP_PROP_DESTINATION:
- {
- char *string = NULL;
- unsigned length = 0;
- if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_DESTINATION, (unsigned char **)&string, &length, &errorcode) < 0) {
- 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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
- break;
- }
- case DP_PROP_FILENAME:
- {
- char *string = NULL;
- unsigned length = 0;
- if (dp_db_get_property_string(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_FILENAME, (unsigned char **)&string, &length, &errorcode) < 0) {
- 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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
- break;
- }
- case DP_PROP_STATE_CALLBACK:
- {
- int callback = 0;
- if (requestp != NULL) {
- 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 %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_NO_DATA;
- }
- }
- int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&callback, errorcode, sizeof(int));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- break;
- }
- case DP_PROP_PROGRESS_CALLBACK:
- {
- int callback = 0;
- if (requestp != NULL) {
- 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 %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_NO_DATA;
- }
- }
- int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&callback, errorcode, sizeof(int));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- break;
- }
- case DP_PROP_AUTO_DOWNLOAD:
- {
- 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 %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));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- break;
- }
- case DP_PROP_NETWORK_TYPE:
- {
- int network = 0;
- if (requestp != NULL) {
- 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 %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_NO_DATA;
- }
- }
- int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&network, errorcode, sizeof(int));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- break;
- }
- case DP_PROP_NETWORK_BONDING:
- {
- 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 %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));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- break;
- }
- case DP_PROP_SAVED_PATH:
- {
- 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 %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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
- break;
- }
- case DP_PROP_TEMP_SAVED_PATH:
- {
- 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 %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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
- break;
- }
- case DP_PROP_MIME_TYPE:
- {
- 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 %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 (result == DP_ERROR_IO_ERROR) {
+ int bundle_type = -1; // DP_PROP_NOTIFICATION_RAW
+ unsigned length = 0;
+ char *string = NULL;
+ const char *table = __dp_get_db_table_name(ipc_info->property);
+ const char *column = dp_db_column[ipc_info->property];
+
+ if (ipc_info->property == DP_PROP_NOTIFICATION_RAW) {
+ errorcode = __dp_request_read_int(client->channel, ipc_info, &bundle_type);
+ TRACE_DEBUG("read %s type:%d", dp_print_property(ipc_info->property), bundle_type);
+
+ if (bundle_type == DP_NOTIFICATION_BUNDLE_TYPE_ONGOING)
+ column = DP_DB_COL_NOTI_RAW_ONGOING;
+ else if (bundle_type == DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE)
+ column = DP_DB_COL_NOTI_RAW_COMPLETE;
+ else if (bundle_type == DP_NOTIFICATION_BUNDLE_TYPE_FAILED)
+ column = DP_DB_COL_NOTI_RAW_FAIL;
+
+ if (column == NULL) {
+ errorcode = DP_ERROR_INVALID_PARAMETER;
+ 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);
}
- free(string);
- break;
+ return errorcode;
}
- case DP_PROP_RECEIVED_SIZE:
- {
- unsigned long long recv_size = 0;
- if (requestp != NULL)
- recv_size = requestp->received_size;
- else
- errorcode = DP_ERROR_INVALID_STATE;
+ }
- int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&recv_size, errorcode, sizeof(unsigned long long));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
+ if (dp_db_get_property_string(client->dbhandle, ipc_info->id,
+ table, column, (unsigned char **)&string, &length, &errorcode) < 0)
+ errorcode = DP_ERROR_NO_DATA;
+
+ if (__dp_request_feedback_string(client->channel, ipc_info,
+ string, length, errorcode) == DP_ERROR_IO_ERROR) {
+ errorcode = DP_ERROR_IO_ERROR;
+ TRACE_ERROR("check ipc sock:%d", client->channel);
+ }
+
+ free(string);
+
+ return errorcode;
+}
+
+static int __dp_request_get_info_int_from_db(dp_client_fmt *client, dp_ipc_fmt *ipc_info)
+{
+ int errorcode = DP_ERROR_NONE;
+ int is_file_size = 0;
+ int ival = 0;
+ unsigned long long lval = 0;
+ const char *table = __dp_get_db_table_name(ipc_info->property);
+ size_t size = sizeof(int);
+
+ if (ipc_info->property == DP_PROP_RECEIVED_SIZE
+ || ipc_info->property == DP_PROP_TOTAL_FILE_SIZE) {
+ is_file_size = 1;
+ size = sizeof(unsigned long long);
+ }
+
+ if (dp_db_get_property_int(client->dbhandle, ipc_info->id,
+ table, dp_db_column[ipc_info->property],
+ (is_file_size ? (void *)&lval : (void *)&ival), &errorcode) < 0) {
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
+ errorcode = DP_ERROR_NO_DATA;
+ }
+
+ if (__dp_request_feedback_int(client->channel, ipc_info,
+ (is_file_size ? (void *)&lval : (void *)&ival),
+ errorcode, size) == DP_ERROR_IO_ERROR) {
+ errorcode = DP_ERROR_IO_ERROR;
+ TRACE_ERROR("check ipc sock:%d", client->channel);
+ }
+ return errorcode;
+}
+
+
+static int __dp_request_get_info_int_from_request(dp_client_fmt *client,
+ dp_ipc_fmt *ipc_info, dp_request_fmt *requestp)
+{
+ void *val = NULL;
+ int errorcode = DP_ERROR_NONE;
+ size_t size = sizeof(int);
+
+ if (requestp) {
+ switch (ipc_info->property) {
+ case DP_PROP_RECEIVED_SIZE:
+ val = &requestp->received_size;
+ size = sizeof(unsigned long long);
break;
- }
- case DP_PROP_TOTAL_FILE_SIZE:
- {
- unsigned long long file_size = 0;
- if (requestp != NULL) {
- file_size = requestp->file_size;
- } 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 %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_NO_DATA;
- }
- }
- int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&file_size, errorcode, sizeof(unsigned long long));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
+ case DP_PROP_STATE_CALLBACK:
+ val = &requestp->state_cb;
break;
- }
- case DP_PROP_CONTENT_NAME:
- {
- 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 %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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
+ case DP_PROP_PROGRESS_CALLBACK:
+ val = &requestp->progress_cb;
break;
- }
- case DP_PROP_HTTP_STATUS:
- {
- 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 %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));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
+ case DP_PROP_NETWORK_TYPE:
+ val = &requestp->network_type;
break;
- }
- case DP_PROP_ETAG:
- {
- 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 %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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
+ case DP_PROP_STATE:
+ val = &requestp->state;
break;
- }
- case DP_PROP_STATE:
- {
- int state = DP_STATE_NONE;
- if (requestp != NULL) {
- 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 %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_ID_NOT_FOUND;
- }
- }
- int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&state, errorcode, sizeof(int));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
+ case DP_PROP_ERROR:
+ val = &requestp->error;
break;
- }
- case DP_PROP_ERROR:
- {
- int errorvalue = DP_ERROR_NONE;
- if (requestp != NULL) {
- 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 %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_ID_NOT_FOUND;
- }
- }
- int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&errorvalue, errorcode, sizeof(int));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
+ case DP_PROP_TOTAL_FILE_SIZE:
+ val = &requestp->file_size;
+ size = sizeof(unsigned long long);
break;
- }
- case DP_PROP_NOTIFICATION_TYPE:
- {
- int noti_type = 0;
- if (requestp != NULL) {
- noti_type = requestp->noti_type;
- // 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 %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_NO_DATA;
- }
- }
- int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)¬i_type, errorcode, sizeof(int));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
+ case DP_PROP_NOTIFICATION_TYPE:
+ val = &requestp->noti_type;
break;
- }
- case DP_PROP_NOTIFICATION_SUBJECT:
- {
- 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 %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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
+ default:
break;
}
- case DP_PROP_NOTIFICATION_DESCRIPTION:
- {
- 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 %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 (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(string);
- break;
+ } else {
+ if (ipc_info->property == DP_PROP_RECEIVED_SIZE) {
+ errorcode = DP_ERROR_INVALID_STATE;
+ goto DONE;
}
- case DP_PROP_NOTIFICATION_RAW: // read type, send raw binary for type
- {
- int bundle_type = -1;
- errorcode = __dp_request_read_int(client->channel, ipc_info, &bundle_type);
- TRACE_DEBUG("read %s type:%d", dp_print_property(ipc_info->property), bundle_type);
- char *raw_column = NULL;
- if (bundle_type == DP_NOTIFICATION_BUNDLE_TYPE_ONGOING)
- raw_column = DP_DB_COL_NOTI_RAW_ONGOING;
- else if (bundle_type == DP_NOTIFICATION_BUNDLE_TYPE_COMPLETE)
- raw_column = DP_DB_COL_NOTI_RAW_COMPLETE;
- else if (bundle_type == DP_NOTIFICATION_BUNDLE_TYPE_FAILED)
- raw_column = DP_DB_COL_NOTI_RAW_FAIL;
+ return __dp_request_get_info_int_from_db(client, ipc_info);
+ }
- if (raw_column == NULL) {
- errorcode = DP_ERROR_INVALID_PARAMETER;
- 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);
- }
- }
- if (errorcode == DP_ERROR_NONE) {
- unsigned char *raws_buffer = NULL;
+DONE:
+ if (__dp_request_feedback_int(client->channel, ipc_info,
+ val, errorcode, size) == DP_ERROR_IO_ERROR) {
+ errorcode = DP_ERROR_IO_ERROR;
+ TRACE_ERROR("check ipc sock:%d", client->channel);
+ }
+ return errorcode;
+}
+
+static int __dp_request_get_http_headers_info(dp_client_fmt *client, dp_ipc_fmt *ipc_info)
+{
+ int errorcode = DP_ERROR_NONE;
+ int field_count = dp_db_check_duplicated_int(client->dbhandle,
+ DP_TABLE_HEADERS, DP_DB_COL_ID, ipc_info->id, &errorcode);
+
+ if (field_count < 0) {
+ TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
+ errorcode = DP_ERROR_DISK_BUSY;
+ field_count = 0;
+ }
+
+ int result = __dp_request_feedback_int(client->channel,
+ ipc_info, (void *)&field_count, errorcode, sizeof(int));
+ if (result == DP_ERROR_IO_ERROR) {
+ errorcode = DP_ERROR_IO_ERROR;
+ TRACE_ERROR("check ipc sock:%d", client->channel);
+ } else if (field_count > 0) {
+ // get fields from database.
+ int *ids = (int *)calloc(field_count, sizeof(int));
+ if (ids == NULL) {
+ TRACE_ERROR("failed to allocate the clients");
+ errorcode = DP_ERROR_OUT_OF_MEMORY;
+ } else {
+ // getting ids of clients
+ int i = 0;
+ int rows_count = dp_db_get_cond_ids(client->dbhandle,
+ DP_TABLE_HEADERS, DP_DB_COL_ROW_ID, DP_DB_COL_ID,
+ ipc_info->id, ids, field_count, &errorcode);
+ for (; i < rows_count; i++) {
+ char *string = NULL;
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) {
+ if (dp_db_get_cond_string(client->dbhandle,
+ DP_TABLE_HEADERS, DP_DB_COL_ROW_ID,
+ ids[i], DP_DB_COL_HEADER_FIELD,
+ (unsigned char **)&string, &length, &errorcode) < 0) {
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);
+ result = __dp_request_feedback_string(client->channel,
+ ipc_info, string, length, errorcode);
+ free(string);
if (result == DP_ERROR_IO_ERROR) {
errorcode = DP_ERROR_IO_ERROR;
TRACE_ERROR("check ipc sock:%d", client->channel);
}
- free(raws_buffer);
}
- break;
}
+ if (ids)
+ free(ids);
+ }
+ return errorcode;
+}
+
+
+/* 1. read field string
+ * 2. response with extra size
+ * 3. send string.
+ */
+static int __dp_request_get_http_header_info(dp_client_fmt *client, dp_ipc_fmt *ipc_info)
+{
+ char *header_field = NULL;
+ char *string = NULL;
+ unsigned length = 0;
+ int errorcode = __dp_request_read_string(client->channel, ipc_info, &header_field);
+ if (errorcode == DP_ERROR_NONE && header_field != NULL) {
+ if (dp_db_get_header_value(client->dbhandle, ipc_info->id,
+ header_field, (unsigned char **)&string, &length, &errorcode) < 0)
+ errorcode = DP_ERROR_NO_DATA;
+ } else if (header_field == NULL) {
+ errorcode = DP_ERROR_INVALID_PARAMETER;
+ }
+
+ if (__dp_request_feedback_string(client->channel,
+ ipc_info, string, length, errorcode) == DP_ERROR_IO_ERROR) {
+ errorcode = DP_ERROR_IO_ERROR;
+ TRACE_ERROR("check ipc sock:%d", client->channel);
+ }
+
+ free(header_field);
+ free(string);
+
+ return errorcode;
+}
+
+static int __dp_request_get_info(dp_client_fmt *client, dp_ipc_fmt *ipc_info, dp_request_fmt *requestp)
+{
+ int errorcode = DP_ERROR_NONE;
+
+ switch (ipc_info->property) {
+ case DP_PROP_URL:
+ case DP_PROP_PROXY:
+ case DP_PROP_DESTINATION:
+ case DP_PROP_FILENAME:
+ case DP_PROP_SAVED_PATH:
+ case DP_PROP_TEMP_SAVED_PATH:
+ case DP_PROP_MIME_TYPE:
+ case DP_PROP_CONTENT_NAME:
+ case DP_PROP_ETAG:
+ case DP_PROP_NOTIFICATION_SUBJECT:
+ case DP_PROP_NOTIFICATION_DESCRIPTION:
+ case DP_PROP_NOTIFICATION_RAW:
+ errorcode = __dp_request_get_info_string(client, ipc_info);
+ break;
+ case DP_PROP_RECEIVED_SIZE:
+ case DP_PROP_STATE_CALLBACK:
+ case DP_PROP_PROGRESS_CALLBACK:
+ case DP_PROP_NETWORK_TYPE:
+ case DP_PROP_STATE:
+ case DP_PROP_ERROR:
+ case DP_PROP_TOTAL_FILE_SIZE:
+ case DP_PROP_NOTIFICATION_TYPE:
+ errorcode = __dp_request_get_info_int_from_request(client, ipc_info, requestp);
+ break;
+ case DP_PROP_NETWORK_BONDING:
+ case DP_PROP_AUTO_DOWNLOAD:
+ case DP_PROP_HTTP_STATUS:
+ errorcode = __dp_request_get_info_int_from_db(client, ipc_info);
+ break;
case DP_PROP_HTTP_HEADERS:
- {
- // 1. response
- // 2. send the number of header fields by id
- // 3. send response & field string for each fields
- int field_count = dp_db_check_duplicated_int(client->dbhandle, DP_TABLE_HEADERS, DP_DB_COL_ID, ipc_info->id, &errorcode);
- if (field_count < 0) {
- TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_DISK_BUSY;
- field_count = 0;
- }
- int result = __dp_request_feedback_int(client->channel, ipc_info, (void *)&field_count, errorcode, sizeof(int));
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- } else if (field_count > 0) {
- // get fields from database.
- int *ids = (int *)calloc(field_count, sizeof(int));
- if (ids == NULL) {
- TRACE_ERROR("failed to allocate the clients");
- errorcode = DP_ERROR_OUT_OF_MEMORY;
- } else {
- // getting ids of clients
- int i = 0;
- int rows_count = dp_db_get_cond_ids(client->dbhandle, DP_TABLE_HEADERS, DP_DB_COL_ROW_ID, DP_DB_COL_ID, ipc_info->id, ids, field_count, &errorcode);
- for (; i < rows_count; i++) {
- char *string = NULL;
- unsigned length = 0;
- if (dp_db_get_cond_string(client->dbhandle, DP_TABLE_HEADERS, DP_DB_COL_ROW_ID, ids[i], DP_DB_COL_HEADER_FIELD, (unsigned char **)&string, &length, &errorcode) < 0) {
- 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);
- free(string);
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- break;
- }
- }
- }
- if (ids)
- free(ids);
- }
- break;
- }
+ errorcode = __dp_request_get_http_headers_info(client, ipc_info);
+ break;
case DP_PROP_HTTP_HEADER:
- {
- // 1. read field string
- // 2. response with extra size
- // 3. send string.
- char *header_field = NULL;
- char *string = NULL;
- unsigned length = 0;
- errorcode = __dp_request_read_string(client->channel, ipc_info, &header_field);
- if (errorcode == DP_ERROR_NONE && header_field != NULL) {
- if (dp_db_get_header_value(client->dbhandle, ipc_info->id, header_field, (unsigned char **)&string, &length, &errorcode) < 0) {
- TRACE_ERROR("failed to get %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_NO_DATA;
- }
- } else {
- if (errorcode != DP_ERROR_NONE)
- TRACE_ERROR("failed to set %s, error:%s", dp_print_property(ipc_info->property), dp_print_errorcode(errorcode));
- if (header_field == NULL) {
- TRACE_ERROR("failed to set %s", dp_print_property(ipc_info->property));
- errorcode = DP_ERROR_INVALID_PARAMETER;
- }
- }
- int result = __dp_request_feedback_string(client->channel, ipc_info, string, length, errorcode);
- if (result == DP_ERROR_IO_ERROR) {
- errorcode = DP_ERROR_IO_ERROR;
- TRACE_ERROR("check ipc sock:%d", client->channel);
- }
- free(header_field);
- free(string);
- break;
- }
+ errorcode = __dp_request_get_http_header_info(client, ipc_info);
+ break;
default:
errorcode = DP_ERROR_INVALID_PARAMETER;
break;
}
+
+ if (errorcode != DP_ERROR_NONE)
+ TRACE_ERROR("failed to get %s, error:%s",
+ dp_print_property(ipc_info->property), dp_print_errorcode(errorcode));
+
return errorcode;
}