From 074c6b1517c3a4c5c9f918e821cd54aeeb3c9330 Mon Sep 17 00:00:00 2001 From: "sowmya.b1" Date: Thu, 6 Apr 2017 18:42:28 +0530 Subject: [PATCH] Expose new API to set/get http proxy from apps. Need an API in download provider to set http proxy from app side. There was no API defined in download provider interface for setting proxy. Added new API dp_interface_{set,get}_proxy() Change-Id: Ie79d34cebd4c27f372c7e50a42a0a809f88ca165 Signed-off-by: Sowmya B --- agent/download-agent-dl-info.c | 3 ++ agent/download-agent-http-mgr.c | 8 ++++- agent/download-agent-interface.c | 2 ++ agent/include/download-agent-dl-info.h | 1 + agent/include/download-agent-interface.h | 1 + provider-interface/download-provider-interface.c | 16 +++++++++ .../include/download-provider-interface.h | 2 ++ provider/download-provider-client.c | 40 ++++++++++++++++++++++ provider/download-provider-plugin-download-agent.c | 8 +++++ provider/include/download-provider-db-defs.h | 2 ++ provider/include/download-provider.h | 1 + 11 files changed, 83 insertions(+), 1 deletion(-) diff --git a/agent/download-agent-dl-info.c b/agent/download-agent-dl-info.c index 2b6b142..b1d42a7 100644 --- a/agent/download-agent-dl-info.c +++ b/agent/download-agent-dl-info.c @@ -264,6 +264,8 @@ da_ret_t copy_user_input_data(da_info_t *da_info, const char *url, if (url) req_info->url = strdup(url); + if (ext_data->proxy) + req_info->proxy = strdup(ext_data->proxy); if (ext_data->install_path) req_info->install_path = strdup(ext_data->install_path); if (ext_data->file_name) @@ -325,6 +327,7 @@ static void __destroy_req_info(req_info_t *req_info) req_info->req_header = DA_NULL; req_info->req_header_count = 0; } + NULL_CHECK_AND_FREE(req_info->proxy); NULL_CHECK_AND_FREE(req_info->install_path); NULL_CHECK_AND_FREE(req_info->file_name); NULL_CHECK_AND_FREE(req_info->etag); diff --git a/agent/download-agent-http-mgr.c b/agent/download-agent-http-mgr.c index c04f879..56228db 100755 --- a/agent/download-agent-http-mgr.c +++ b/agent/download-agent-http-mgr.c @@ -346,7 +346,13 @@ da_ret_t __start_transaction(da_info_t *da_info) return DA_ERR_INVALID_ARGUMENT; } http_info->http_method = HTTP_METHOD_GET; - http_info->proxy_addr = get_proxy_address(); + char* proxy_addr = da_info->req_info->proxy; + if (proxy_addr && strlen(proxy_addr) > 0) { + DA_LOGI("User proxy : %s", proxy_addr); + http_info->proxy_addr = strdup(proxy_addr); + } else { + http_info->proxy_addr = get_proxy_address(); + } ret = PI_http_start(da_info); diff --git a/agent/download-agent-interface.c b/agent/download-agent-interface.c index 7a844f0..9b16308 100755 --- a/agent/download-agent-interface.c +++ b/agent/download-agent-interface.c @@ -66,6 +66,8 @@ int da_start_download(const char *url, req_data_t *ext_data, } } + if (ext_data->proxy) + DA_SECURE_LOGI("proxy[%s]", ext_data->proxy); if (ext_data->install_path) DA_SECURE_LOGI("install path[%s]", ext_data->install_path); if (ext_data->file_name) diff --git a/agent/include/download-agent-dl-info.h b/agent/include/download-agent-dl-info.h index 123a8dd..50192e9 100644 --- a/agent/include/download-agent-dl-info.h +++ b/agent/include/download-agent-dl-info.h @@ -56,6 +56,7 @@ typedef enum { typedef struct { char *url; + char *proxy; char **req_header; int req_header_count; char *install_path; diff --git a/agent/include/download-agent-interface.h b/agent/include/download-agent-interface.h index f5ce653..2b3495c 100755 --- a/agent/include/download-agent-interface.h +++ b/agent/include/download-agent-interface.h @@ -49,6 +49,7 @@ typedef struct { typedef struct { const char **request_header; int request_header_count; + const char *proxy; const char *install_path; const char *file_name; const char *temp_file_path; diff --git a/provider-interface/download-provider-interface.c b/provider-interface/download-provider-interface.c index f7ea32d..9863540 100755 --- a/provider-interface/download-provider-interface.c +++ b/provider-interface/download-provider-interface.c @@ -828,6 +828,22 @@ int dp_interface_get_url(const int id, char **url) return __dp_ipc_get_string(id, DP_PROP_URL, url, __FUNCTION__); } +int dp_interface_set_proxy(const int id, const char *proxy) +{ + if (proxy == NULL) + return __dp_ipc_echo(id, DP_SEC_UNSET, DP_PROP_PROXY, __FUNCTION__); + if (proxy && strlen(proxy) == 0) { + char* invalid_proxy = "0.0.0.0"; + return __dp_ipc_set_string(id, DP_SEC_SET, DP_PROP_PROXY, invalid_proxy, __FUNCTION__); + } + return __dp_ipc_set_string(id, DP_SEC_SET, DP_PROP_PROXY, proxy, __FUNCTION__); +} + +int dp_interface_get_proxy(const int id, char **proxy) +{ + return __dp_ipc_get_string(id, DP_PROP_PROXY, proxy, __FUNCTION__); +} + int dp_interface_set_destination(const int id, const char *path) { char set_filename[DOWNLOAD_FILENAME_MAX] = {0, }; diff --git a/provider-interface/include/download-provider-interface.h b/provider-interface/include/download-provider-interface.h index 1fd3241..aaa893c 100755 --- a/provider-interface/include/download-provider-interface.h +++ b/provider-interface/include/download-provider-interface.h @@ -96,12 +96,14 @@ EXPORT_API int dp_interface_pause(const int id); EXPORT_API int dp_interface_cancel(const int id); EXPORT_API int dp_interface_set_url(const int id, const char *url); +EXPORT_API int dp_interface_set_proxy(const int id, const char *proxy); EXPORT_API int dp_interface_set_destination(const int id, const char *path); EXPORT_API int dp_interface_set_file_name(const int id, const char *file_name); EXPORT_API int dp_interface_set_network_type(const int id, int net_type); EXPORT_API int dp_interface_set_network_bonding(const int id, int enable); EXPORT_API int dp_interface_set_auto_download(const int id, int enable); EXPORT_API int dp_interface_get_url(const int id, char **url); +EXPORT_API int dp_interface_get_proxy(const int id, char **proxy); EXPORT_API int dp_interface_get_network_type(const int id, int *net_type); EXPORT_API int dp_interface_get_network_bonding(const int id, int *enable); EXPORT_API int dp_interface_get_destination(const int id, char **path); diff --git a/provider/download-provider-client.c b/provider/download-provider-client.c index 35adb1b..78126af 100755 --- a/provider/download-provider-client.c +++ b/provider/download-provider-client.c @@ -168,6 +168,8 @@ char *dp_print_property(unsigned property) return "DESTROY"; case DP_PROP_URL: return "URL"; + case DP_PROP_PROXY: + return "PROXY"; case DP_PROP_DESTINATION: return "DESTINATION"; case DP_PROP_FILENAME: @@ -550,6 +552,22 @@ static int __dp_request_get_info(dp_client_fmt *client, dp_ipc_fmt *ipc_info, dp 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; @@ -1053,6 +1071,23 @@ static int __dp_request_set_info(dp_client_slots_fmt *slot, dp_ipc_fmt *ipc_info } break; } + case DP_PROP_PROXY: + { + char *recv_str = NULL; + errorcode = __dp_request_read_string(client->channel, ipc_info, &recv_str); + if (errorcode == DP_ERROR_NONE) { + if (recv_str == NULL) { + errorcode = DP_ERROR_INVALID_PARAMETER; + } else { + // write to database here + if (dp_db_replace_property(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_PROXY, (void *)recv_str, ipc_info->size, 2, &errorcode) < 0) { + TRACE_ERROR("failed to set %s errorcode:%s", dp_print_property(ipc_info->property), dp_print_errorcode(errorcode)); + } + free(recv_str); + } + } + break; + } case DP_PROP_DESTINATION: { char *recv_str = NULL; @@ -1421,6 +1456,11 @@ static int __dp_request_unset_info(dp_client_fmt *client, dp_ipc_fmt *ipc_info, if (dp_db_unset_property_string(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_URL, &errorcode) < 0) TRACE_ERROR("failed to unset %s", dp_print_property(ipc_info->property)); break; + case DP_PROP_PROXY: + if (dp_db_unset_property_string(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_PROXY, &errorcode) < 0) { + TRACE_ERROR("failed to unset %s errorcode:%s", dp_print_property(ipc_info->property), dp_print_errorcode(errorcode)); + } + break; case DP_PROP_DESTINATION: // if downloading, change destination to da_agent if (dp_db_unset_property_string(client->dbhandle, ipc_info->id, DP_TABLE_REQUEST, DP_DB_COL_DESTINATION, &errorcode) < 0) diff --git a/provider/download-provider-plugin-download-agent.c b/provider/download-provider-plugin-download-agent.c index 27cee73..d61f63e 100755 --- a/provider/download-provider-plugin-download-agent.c +++ b/provider/download-provider-plugin-download-agent.c @@ -839,6 +839,7 @@ int dp_start_agent_download(void *slot, void *request) int errorcode = DP_ERROR_NONE; unsigned length = 0; char *url = NULL; + char *proxy = NULL; char *destination = NULL; char *tmp_saved_path = NULL; char *user_tmp_file_path = NULL; @@ -857,6 +858,13 @@ int dp_start_agent_download(void *slot, void *request) return DP_ERROR_DISK_BUSY; } } + if (dp_db_get_property_string(base_slot->client.dbhandle, base_req->id, DP_TABLE_REQUEST, DP_DB_COL_PROXY, (unsigned char **)&proxy, &length, &errorcode) < 0 || + proxy == NULL) { + TRACE_DEBUG("proxy id:%d NO_DATA", base_req->id); + req_data->proxy = NULL; + } else { + req_data->proxy = proxy; + } if (dp_db_get_property_string(base_slot->client.dbhandle, base_req->id, DP_TABLE_REQUEST, DP_DB_COL_TEMP_FILE_PATH, (unsigned char **)&user_tmp_file_path, &length, &errorcode) < 0 || user_tmp_file_path == NULL) { TRACE_DEBUG("user_tmp_file_path id:%d NO_DATA", base_req->id); diff --git a/provider/include/download-provider-db-defs.h b/provider/include/download-provider-db-defs.h index 2617696..ae22f6d 100644 --- a/provider/include/download-provider-db-defs.h +++ b/provider/include/download-provider-db-defs.h @@ -49,6 +49,7 @@ // request table #define DP_DB_COL_URL "url" +#define DP_DB_COL_PROXY "proxy" #define DP_DB_COL_DESTINATION "destination" #define DP_DB_COL_FILENAME "filename" #define DP_DB_COL_STATE_EVENT "state_event" @@ -113,6 +114,7 @@ network_type TINYINT DEFAULT 3,\ filename TEXT DEFAULT NULL,\ destination TEXT DEFAULT NULL,\ url TEXT DEFAULT NULL,\ +proxy TEXT DEFAULT NULL,\ temp_file_path TEXT DEFAULT NULL,\ network_bonding BOOLEAN DEFAULT 0,\ FOREIGN KEY(id) REFERENCES logging(id) ON DELETE CASCADE\ diff --git a/provider/include/download-provider.h b/provider/include/download-provider.h index 29d7874..bb9aaa8 100755 --- a/provider/include/download-provider.h +++ b/provider/include/download-provider.h @@ -127,6 +127,7 @@ typedef enum { DP_PROP_CANCEL, DP_PROP_DESTROY, DP_PROP_URL, + DP_PROP_PROXY, DP_PROP_DESTINATION, DP_PROP_FILENAME, DP_PROP_STATE_CALLBACK, -- 2.7.4