hide the key value in log 11/131011/2 accepted/tizen/unified/20170531.082528 submit/tizen/20170526.054123
authorjomui <jongmun.woo@samsung.com>
Thu, 25 May 2017 05:01:13 +0000 (14:01 +0900)
committerjomui <jongmun.woo@samsung.com>
Fri, 26 May 2017 05:10:45 +0000 (14:10 +0900)
Signed-off-by: jomui <jongmun.woo@samsung.com>
Change-Id: I3907268ac6348a48dc4cac8a80a03247c38cc2d3

src/mapzen/mapzen_restcurl.c
src/mapzen/tangram_view.cpp

index 87d8546..05547aa 100644 (file)
@@ -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);
 
index bdf9e16..a23b1c1 100644 (file)
@@ -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;
        }