From 975c2c5a1de2b281618453dc563606d80433ee2b Mon Sep 17 00:00:00 2001 From: jomui Date: Thu, 25 May 2017 14:01:13 +0900 Subject: [PATCH] hide the key value in log Signed-off-by: jomui Change-Id: I3907268ac6348a48dc4cac8a80a03247c38cc2d3 --- src/mapzen/mapzen_restcurl.c | 41 +++++++++++++++++++++++++++++++++++++++-- src/mapzen/tangram_view.cpp | 3 ++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/mapzen/mapzen_restcurl.c b/src/mapzen/mapzen_restcurl.c index 87d8546..05547aa 100644 --- a/src/mapzen/mapzen_restcurl.c +++ b/src/mapzen/mapzen_restcurl.c @@ -23,6 +23,7 @@ #include "mapzen_types.h" #include "mapzen_jsonparser.hpp" #include "mapzen_debug.h" +#include "mapzen_util.h" #define RESTCURL_USE_MULTI_CURL @@ -61,6 +62,38 @@ struct MultiCurlArg_List { struct MultiCurlArg_List *head = NULL; struct MultiCurlArg_List *curr = NULL; +static void __show_url_log(const char *url) +{ + char urlLog[1024] = {}, *tmp = NULL; + int url_index = 0, urlLog_index = 0; + + if (!url) return; + tmp = strstr(url, "api_key="); + if (!tmp) { + MAP_DEBUG("HTTP URL [%s]", url); + return; + } + for (; url_index < strlen(url) && url_index < 1024; url_index++) { + if (&url[url_index] == tmp) + break; + urlLog[url_index] = url[url_index]; + } + STRCAT(urlLog, "api_key="); + url_index = url_index + 8; + urlLog_index = url_index; + if ((url_index + 3 < strlen(url) && url[url_index] != '&') && (url[url_index] != 'n' || url[url_index+1] != 'u' || url[url_index+2] != 'l' || url[url_index+3] != 'l')) { + STRCAT(urlLog, "xxxx-xxxx"); + for(;url_index < strlen(url); url_index++) { + if (url[url_index] == '&') + break; + } + urlLog_index = urlLog_index + 9; + } + for (; url_index < strlen(url); url_index++, urlLog_index++) + urlLog[urlLog_index] = url[url_index]; + MAP_DEBUG("HTTP URL [%s]", urlLog); +} + static struct MultiCurlArg_List *__create_list(struct MultiCurlArg *mcArg) { MAP_DEBUG("\n creating list with headnode as [%p]\n", mcArg); @@ -344,7 +377,9 @@ int add_handle(const char *url, mapzen_req_type type, void *user_data) } #ifdef RESTCURL_USE_MULTI_CURL - MAP_DEBUG("HTTP Req URL [%s]", url); + // block to hide key in log + //MAP_DEBUG("HTTP Req URL [%s]", url); + __show_url_log(url); CURL *curl_handle; struct MultiCurlArg *pMultiCurlArg = (struct MultiCurlArg *)g_malloc0(sizeof(struct MultiCurlArg)); @@ -472,7 +507,9 @@ static void *__curl_thread_handler(void *user_data) pthread_mutex_unlock(&__MultiCurlArgsLock); if (del && del->mcArg) { - MAP_DEBUG("HTTP Url [%s]", del->mcArg->url); + // block to hide key in log + //MAP_DEBUG("HTTP Url [%s]", del->mcArg->url); + __show_url_log(del->mcArg->url); MAP_DEBUG("Posting the result.."); __post_curl(del->mcArg->req_type, &(del->mcArg->m_chunk), del->mcArg->user_data); diff --git a/src/mapzen/tangram_view.cpp b/src/mapzen/tangram_view.cpp index bdf9e16..a23b1c1 100644 --- a/src/mapzen/tangram_view.cpp +++ b/src/mapzen/tangram_view.cpp @@ -895,7 +895,8 @@ void TangramView::setMapType(maps_view_h view) // set provider key for vector tiles if (m_providerKey.size() > 0 && !m_isProviderKeySet) { - MAPS_LOGD("Queueing API key update: %s", m_providerKey.c_str()); + // block to hide key in log + //MAPS_LOGD("Queueing API key update: %s", m_providerKey.c_str()); sceneUpdates.push_back( {"global.sdk_mapzen_api_key", m_providerKey.c_str()} ); m_isProviderKeySet = true; } -- 2.7.4