From 5bec6e4dc6eb7dcf78e4b958d25ffa4a968064c8 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Tue, 7 Feb 2023 23:03:53 +0900 Subject: [PATCH] Check a exception proxy list before transmitting HTTP request Change-Id: I3e54200a9dcb34001ae8e7d6f9a188fabafe3b11 Signed-off-by: pyun --- agent/download-agent-http-mgr.c | 67 +++++++++++++++++++++++++++++++++-- agent/download-agent-plugin-libcurl.c | 14 ++++---- 2 files changed, 72 insertions(+), 9 deletions(-) diff --git a/agent/download-agent-http-mgr.c b/agent/download-agent-http-mgr.c index ddb5286..b3932d1 100755 --- a/agent/download-agent-http-mgr.c +++ b/agent/download-agent-http-mgr.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "download-agent-dl-info.h" #include "download-agent-file.h" @@ -35,6 +36,11 @@ static proxy_info_t *__get_proxy_info(); #define CONVERT_STR(NAME) (#NAME) +#define VCONF_KEY_PROXY_EXCEPTION_LIST "db/menu/network/server_network_settings/proxy_exceptional_address" +#define PROXY_EXCEPTION_LIST_DELIMITER ";" +#define HTTP_PREFIX "http://" +#define HTTPS_PREFIX "https://" + static const char *__get_state_str(http_state_t state) { char *str = NULL; @@ -91,6 +97,57 @@ static const char *__get_state_str(http_state_t state) return str; } +// 0: not required, 1: required +static int __is_proxy_required(char *url) +{ + char *parsed_url = NULL; + char *exception_list = vconf_get_str(VCONF_KEY_PROXY_EXCEPTION_LIST); + char *ptr = NULL; + char *next_ptr = NULL; + char *next_ptr2 = NULL; + + if (!exception_list) + return 1; + + DA_LOGI("proxy exception list[%s]", exception_list); + + if (url && strstr(url, HTTP_PREFIX)) + parsed_url = url + strlen(HTTP_PREFIX); + else if (url && strstr(url, HTTPS_PREFIX)) + parsed_url = url + strlen(HTTPS_PREFIX); + else + parsed_url = url; + + DA_LOGI("compared url[%s] parsed url[%s]", url, parsed_url); + + ptr = strtok_r(exception_list, PROXY_EXCEPTION_LIST_DELIMITER, &next_ptr); + while (ptr) { + // Ignore protocol prefix + if (strstr(ptr, HTTP_PREFIX)) + ptr = ptr + strlen(HTTP_PREFIX); + else if (strstr(ptr, HTTPS_PREFIX)) + ptr = ptr + strlen(HTTPS_PREFIX); + + // Remove file path + if (ptr && strstr(ptr, "/")) + ptr = strtok_r(ptr, "/", &next_ptr2); + + if (ptr && strncmp(parsed_url, ptr, strlen(ptr)) == 0) { + DA_LOGI("[%s/%s] is exist in exception list.", url, ptr); + free(exception_list); + return 0; + } + + ptr = strtok_r(NULL, PROXY_EXCEPTION_LIST_DELIMITER, &next_ptr); + } + + free(exception_list); + + DA_LOGI("There is no matched address in exception list"); + + return 1; +} + void __init_http_info(http_info_t *http_info) { DA_LOGV(""); @@ -346,7 +403,12 @@ 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_info = __get_proxy_info(); + + // Check exception list for proxy + if (__is_proxy_required(da_info->req_info->url)) + http_info->proxy_info = __get_proxy_info(); + else + http_info->proxy_info = NULL; ret = PI_http_start(da_info); @@ -1166,6 +1228,7 @@ static proxy_info_t *__get_proxy_info() } } else { proxy_info->addr = strdup(proxy_uri); + DA_LOGI("proxy_info->addr[%s] will be used.", proxy_info->addr); } proxy_info->user_name = strlen(user_name) > 0 ? strdup(user_name) : DA_NULL; proxy_info->password = strlen(password) > 0 ? strdup(password) : DA_NULL; @@ -1174,7 +1237,7 @@ static proxy_info_t *__get_proxy_info() if (proxy_uri) free(proxy_uri); - DA_LOGD("host[%s] user_name[%s] password[***]", host, user_name); + DA_LOGI("host[%s] user_name[%s] password[***]", host, user_name); return proxy_info; } diff --git a/agent/download-agent-plugin-libcurl.c b/agent/download-agent-plugin-libcurl.c index e3023dd..e1a7532 100755 --- a/agent/download-agent-plugin-libcurl.c +++ b/agent/download-agent-plugin-libcurl.c @@ -67,28 +67,28 @@ int my_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *us switch (type) { case CURLINFO_TEXT: if (data) - DA_SECURE_LOGI("[curl] Info:%s", data); + DA_LOGI("[curl] Info:%s", data); break; case CURLINFO_HEADER_OUT: - DA_LOGD("[curl] Send header"); + DA_LOGI("[curl] Send header"); if (data) DA_SECURE_LOGI("[curl] %s", data); break; case CURLINFO_DATA_OUT: - DA_LOGD("[curl] Send data"); + DA_LOGI("[curl] Send data"); if (data) DA_SECURE_LOGI("[curl] %s", data); break; case CURLINFO_SSL_DATA_OUT: - DA_LOGD("[curl] Send SSL data"); + DA_LOGI("[curl] Send SSL data"); break; case CURLINFO_HEADER_IN: - DA_LOGD("[curl] Recv header"); + DA_LOGI("[curl] Recv header"); if (data) DA_SECURE_LOGI("[curl] %s", data); break; case CURLINFO_SSL_DATA_IN: - DA_SECURE_LOGI("[curl] Recv SSL data"); + DA_LOGI("[curl] Recv SSL data"); break; default: return 0; @@ -183,7 +183,7 @@ void __store_header(void *msg, da_info_t *da_info, size_t header_size, DA_LOGI("Proxy is set."); res = curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE, &status); } else { - res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status); + res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status); } if (res != CURLE_OK) { DA_LOGE("Fail to get response status code"); -- 2.7.4