Expose new API to set/get http proxy from apps. 07/208107/2
authorsowmya.b1 <sowmya.b1@samsung.com>
Thu, 6 Apr 2017 13:12:28 +0000 (18:42 +0530)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 18 Jun 2019 11:25:41 +0000 (20:25 +0900)
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 <sowmya.b1@samsung.com>
agent/download-agent-dl-info.c
agent/download-agent-http-mgr.c
agent/download-agent-interface.c
agent/include/download-agent-dl-info.h
agent/include/download-agent-interface.h
provider-interface/download-provider-interface.c
provider-interface/include/download-provider-interface.h
provider/download-provider-client.c
provider/download-provider-plugin-download-agent.c
provider/include/download-provider-db-defs.h
provider/include/download-provider.h

index 2b6b142..b1d42a7 100644 (file)
@@ -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);
index c04f879..56228db 100755 (executable)
@@ -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);
 
index 7a844f0..9b16308 100755 (executable)
@@ -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)
index 123a8dd..50192e9 100644 (file)
@@ -56,6 +56,7 @@ typedef enum {
 
 typedef struct {
        char *url;
+       char *proxy;
        char **req_header;
        int req_header_count;
        char *install_path;
index f5ce653..2b3495c 100755 (executable)
@@ -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;
index f7ea32d..9863540 100755 (executable)
@@ -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, };
index 1fd3241..aaa893c 100755 (executable)
@@ -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);
index 35adb1b..78126af 100755 (executable)
@@ -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)
index 27cee73..d61f63e 100755 (executable)
@@ -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);
index 2617696..ae22f6d 100644 (file)
@@ -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\
index 29d7874..bb9aaa8 100755 (executable)
@@ -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,