Fix spelling errata
[platform/core/uifw/stt.git] / common / stt_config_parser.c
index 8116ba4..8b45fc3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved
+*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
@@ -12,6 +12,8 @@
 */
 
 #include <dlog.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <vconf.h>
 
 #include "stt_defs.h"
@@ -23,6 +25,7 @@
 #define STT_TAG_ENGINE_ID              "id"
 #define STT_TAG_ENGINE_SETTING         "setting"
 #define STT_TAG_ENGINE_AGREEMENT       "agreement"
+#define STT_TAG_ENGINE_DEFAULT         "default"
 #define STT_TAG_ENGINE_LANGUAGE_SET    "languages"
 #define STT_TAG_ENGINE_LANGUAGE                "lang"
 #define STT_TAG_ENGINE_SILENCE_SUPPORT "silence-detection-support"
@@ -52,7 +55,7 @@ static xmlDocPtr g_config_doc = NULL;
 int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info)
 {
        if (NULL == path || NULL == engine_info) {
-               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
                return -1;
        }
 
@@ -67,41 +70,52 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
 
        cur = xmlDocGetRootElement(doc);
        if (cur == NULL) {
+               //LCOV_EXCL_START
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
                xmlFreeDoc(doc);
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_BASE_TAG)) {
+               //LCOV_EXCL_START
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT 'stt-engine'");
                xmlFreeDoc(doc);
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        cur = cur->xmlChildrenNode;
        if (cur == NULL) {
+               //LCOV_EXCL_START
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
                xmlFreeDoc(doc);
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        /* alloc engine info */
        stt_engine_info_s* temp;
        temp = (stt_engine_info_s*)calloc(1, sizeof(stt_engine_info_s));
        if (NULL == temp) {
+               //LCOV_EXCL_START
                xmlFreeDoc(doc);
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        temp->name = NULL;
        temp->uuid = NULL;
        temp->setting = NULL;
        temp->agreement = NULL;
+       temp->default_lang = NULL;
        temp->languages = NULL;
        temp->support_silence_detection = false;
        temp->need_credential = false;
 
+       bool is_default_lang_set = false;
+
        while (cur != NULL) {
                if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) {
                        key = xmlNodeGetContent(cur);
@@ -111,7 +125,7 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
                                temp->name = strdup((char*)key);
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_NAME);
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_NAME); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_ID)) {
                        key = xmlNodeGetContent(cur);
@@ -121,7 +135,7 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
                                temp->uuid = strdup((char*)key);
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_ID);
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_ID); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SETTING)) {
                        key = xmlNodeGetContent(cur);
@@ -131,7 +145,7 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
                                temp->setting = strdup((char*)key);
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SETTING);
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SETTING); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_AGREEMENT)) {
                        key = xmlNodeGetContent(cur);
@@ -141,7 +155,19 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
                                temp->agreement = strdup((char*)key);
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT);
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT); //LCOV_EXCL_LINE
+                       }
+               } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_DEFAULT)) {
+                       key = xmlNodeGetContent(cur);
+                       if (NULL != key) {
+                               SLOG(LOG_DEBUG, stt_tag(), "Engine agreement : %s", (char *)key);
+                               if (NULL != temp->default_lang) free(temp->default_lang);
+                               temp->default_lang = strdup((char*)key);
+
+                               is_default_lang_set = true;
+                               xmlFree(key);
+                       } else {
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_DEFAULT);
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE_SET)) {
                        xmlNodePtr lang_node = NULL;
@@ -156,9 +182,16 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
                                                /* SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */
                                                temp_lang = strdup((char*)key);
                                                temp->languages = g_slist_append(temp->languages, temp_lang);
+
+                                               if (false == is_default_lang_set) {
+                                                       if (NULL != temp->default_lang) free(temp->default_lang);
+                                                       temp->default_lang = strdup((char*)key);
+
+                                                       is_default_lang_set = true;
+                                               }
                                                xmlFree(key);
                                        } else {
-                                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_LANGUAGE);
+                                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_LANGUAGE); //LCOV_EXCL_LINE
                                        }
                                }
 
@@ -176,7 +209,7 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
 
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT);
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_CREDENTIAL_NEED)) {
                        key = xmlNodeGetContent(cur);
@@ -216,7 +249,7 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
 int stt_parser_free_engine_info(stt_engine_info_s* engine_info)
 {
        if (NULL == engine_info) {
-               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
                return -1;
        }
 
@@ -246,6 +279,7 @@ int stt_parser_free_engine_info(stt_engine_info_s* engine_info)
        return 0;
 }
 
+//LCOV_EXCL_START
 int stt_parser_print_engine_info(stt_engine_info_s* engine_info)
 {
        if (NULL == engine_info)
@@ -283,11 +317,12 @@ int stt_parser_print_engine_info(stt_engine_info_s* engine_info)
 
        return 0;
 }
+//LCOV_EXCL_STOP
 
 int stt_parser_load_config(stt_config_s** config_info)
 {
        if (NULL == config_info) {
-               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
                return -1;
        }
 
@@ -296,32 +331,55 @@ int stt_parser_load_config(stt_config_s** config_info)
        xmlChar *key;
        bool is_default_open = false;
 
-       doc = xmlParseFile(STT_CONFIG);
-       if (doc == NULL) {
+       if (0 != access(STT_CONFIG, F_OK)) {
                doc = xmlParseFile(STT_DEFAULT_CONFIG);
                if (doc == NULL) {
-                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG);
+                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG); //LCOV_EXCL_LINE
+                       xmlCleanupParser();
                        return -1;
                }
                is_default_open = true;
+       } else {
+               int retry_count = 0;
+
+               while (NULL == doc) {
+                       doc = xmlParseFile(STT_CONFIG);
+                       if (NULL != doc) {
+                               break;
+                       }
+                       retry_count++;
+                       usleep(10000);
+
+                       if (STT_RETRY_COUNT == retry_count) {
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG);
+                               doc = xmlParseFile(STT_DEFAULT_CONFIG);
+                               if (NULL == doc) {
+                                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG);
+                                       xmlCleanupParser();
+                                       return -1;
+                               }
+                               is_default_open = true;
+                               break;
+                       }
+               }
        }
 
        cur = xmlDocGetRootElement(doc);
        if (cur == NULL) {
-               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); //LCOV_EXCL_LINE
                xmlFreeDoc(doc);
                return -1;
        }
 
        if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
-               SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); //LCOV_EXCL_LINE
                xmlFreeDoc(doc);
                return -1;
        }
 
        cur = cur->xmlChildrenNode;
        if (cur == NULL) {
-               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document"); //LCOV_EXCL_LINE
                xmlFreeDoc(doc);
                return -1;
        }
@@ -331,7 +389,7 @@ int stt_parser_load_config(stt_config_s** config_info)
        temp = (stt_config_s*)calloc(1, sizeof(stt_config_s));
        if (NULL == temp) {
                xmlFreeDoc(doc);
-               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
                return -1;
        }
 
@@ -348,7 +406,7 @@ int stt_parser_load_config(stt_config_s** config_info)
                                temp->engine_id = strdup((char*)key);
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] engine id is NULL");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] engine id is NULL"); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
                        key = xmlNodeGetContent(cur);
@@ -358,7 +416,7 @@ int stt_parser_load_config(stt_config_s** config_info)
                                temp->setting = strdup((char*)key);
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] setting path is NULL");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] setting path is NULL"); //LCOV_EXCL_LINE
                        }
 
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
@@ -371,13 +429,13 @@ int stt_parser_load_config(stt_config_s** config_info)
                                } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
                                        temp->auto_lang = false;
                                } else {
-                                       SLOG(LOG_ERROR, stt_tag(), "Auto voice is wrong");
+                                       SLOG(LOG_ERROR, stt_tag(), "Auto voice is wrong"); //LCOV_EXCL_LINE
                                        temp->auto_lang = true;
                                }
 
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] auto langauge is NULL");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] auto language is NULL"); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
                        key = xmlNodeGetContent(cur);
@@ -387,7 +445,7 @@ int stt_parser_load_config(stt_config_s** config_info)
                                temp->language = strdup((char*)key);
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] language is NULL");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] language is NULL"); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
                        key = xmlNodeGetContent(cur);
@@ -401,7 +459,7 @@ int stt_parser_load_config(stt_config_s** config_info)
 
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] silence-detection is NULL");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] silence-detection is NULL"); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
                        key = xmlNodeGetContent(cur);
@@ -415,7 +473,7 @@ int stt_parser_load_config(stt_config_s** config_info)
 
                                xmlFree(key);
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] credential is NULL");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] credential is NULL"); //LCOV_EXCL_LINE
                        }
                } else {
 
@@ -427,8 +485,33 @@ int stt_parser_load_config(stt_config_s** config_info)
        *config_info = temp;
        g_config_doc = doc;
 
-       if (is_default_open)
-               xmlSaveFile(STT_CONFIG, g_config_doc);
+       if (is_default_open) {
+               int retry_count = 0;
+               int ret = -1;
+               do {
+                       ret = xmlSaveFile(STT_CONFIG, g_config_doc);
+                       if (0 < ret)
+                               break;
+                       retry_count++;
+                       usleep(10000);
+
+                       if (STT_RETRY_COUNT == retry_count) {
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Save result : %d", ret);
+                               return -1;
+                       }
+               } while (0 != ret);
+
+               /* Set mode */
+               if (0 > chmod(STT_CONFIG, 0600)) {
+                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to change file mode : %d", ret);
+               }
+
+               /* Set owner */
+               if (0 > chown(STT_CONFIG, 5000, 5000)) {
+                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to change file owner : %d", ret);
+               }
+               SLOG(LOG_DEBUG, stt_tag(), "Default config is changed : pid(%d)", getpid());
+       }
 
        return 0;
 }
@@ -437,9 +520,18 @@ int stt_parser_unload_config(stt_config_s* config_info)
 {
        if (NULL != g_config_doc)       xmlFreeDoc(g_config_doc);
        if (NULL != config_info) {
-               if (NULL != config_info->engine_id)     free(config_info->engine_id);
-               if (NULL != config_info->setting)       free(config_info->setting);
-               if (NULL != config_info->language)      free(config_info->language);
+               if (NULL != config_info->engine_id) {
+                       free(config_info->engine_id);
+                       config_info->engine_id = NULL;
+               }
+               if (NULL != config_info->setting) {
+                       free(config_info->setting);
+                       config_info->setting = NULL;
+               }
+               if (NULL != config_info->language) {
+                       free(config_info->language);
+                       config_info->language = NULL;
+               }
 
                free(config_info);
        }
@@ -544,6 +636,7 @@ int stt_parser_set_language(const char* language)
        return 0;
 }
 
+//LCOV_EXCL_START
 int stt_parser_set_auto_lang(bool value)
 {
        if (NULL == g_config_doc)
@@ -627,11 +720,12 @@ int stt_parser_set_silence_detection(bool value)
 
        return 0;
 }
+//LCOV_EXCL_STOP
 
 int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence, int* credential)
 {
        if (NULL == engine || NULL == language || NULL == silence || NULL == credential) {
-               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
+               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
                return -1;
        }
 
@@ -651,23 +745,29 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
        cur_new = xmlDocGetRootElement(doc);
        cur_old = xmlDocGetRootElement(g_config_doc);
        if (cur_new == NULL || cur_old == NULL) {
+               //LCOV_EXCL_START
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
                xmlFreeDoc(doc);
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        if (xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG)) {
+               //LCOV_EXCL_START
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
                xmlFreeDoc(doc);
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        cur_new = cur_new->xmlChildrenNode;
        cur_old = cur_old->xmlChildrenNode;
        if (cur_new == NULL || cur_old == NULL) {
+               //LCOV_EXCL_START
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
                xmlFreeDoc(doc);
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        *engine = NULL;
@@ -691,7 +791,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        xmlFree(key_old);
                                }
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different"); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
@@ -700,7 +800,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
-                                                       SLOG(LOG_DEBUG, stt_tag(), "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new);
+                                                       SLOG(LOG_DEBUG, stt_tag(), "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
                                                        if (NULL != *setting)   free(*setting);
                                                        *setting = strdup((char*)key_new);
                                                }
@@ -709,7 +809,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        xmlFree(key_old);
                                }
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different"); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
@@ -718,7 +818,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
-                                                       SLOG(LOG_DEBUG, stt_tag(), "Old auto lang(%s), New auto lang(%s)", (char*)key_old, (char*)key_new);
+                                                       SLOG(LOG_DEBUG, stt_tag(), "Old auto lang(%s), New auto lang(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
                                                        if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
                                                                *auto_lang = (int)true;
                                                        } else {
@@ -731,7 +831,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        xmlFree(key_old);
                                }
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different"); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
@@ -740,7 +840,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
-                                                       SLOG(LOG_DEBUG, stt_tag(), "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new);
+                                                       SLOG(LOG_DEBUG, stt_tag(), "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
                                                        if (NULL != *language)  free(*language);
                                                        *language = strdup((char*)key_new);
                                                }
@@ -749,7 +849,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        xmlFree(key_old);
                                }
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different"); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
@@ -758,7 +858,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
-                                                       SLOG(LOG_DEBUG, stt_tag(), "Old silence(%s), New silence(%s)", (char*)key_old, (char*)key_new);
+                                                       SLOG(LOG_DEBUG, stt_tag(), "Old silence(%s), New silence(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
                                                        if (0 == xmlStrcmp(key_new, (const xmlChar*)"on")) {
                                                                *silence = 1;
                                                        } else {
@@ -771,7 +871,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        xmlFree(key_old);
                                }
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different"); //LCOV_EXCL_LINE
                        }
                } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
                        if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
@@ -780,7 +880,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        key_new = xmlNodeGetContent(cur_new);
                                        if (NULL != key_new) {
                                                if (0 != xmlStrcmp(key_old, key_new)) {
-                                                       SLOG(LOG_DEBUG, stt_tag(), "Old credential(%s), New credential(%s)", (char*)key_old, (char*)key_new);
+                                                       SLOG(LOG_DEBUG, stt_tag(), "Old credential(%s), New credential(%s)", (char*)key_old, (char*)key_new); //LCOV_EXCL_LINE
                                                        if (0 == xmlStrcmp(key_new, (const xmlChar*)"true")) {
                                                                *credential = 1;
                                                        } else {
@@ -792,7 +892,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                                        xmlFree(key_old);
                                }
                        } else {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different"); //LCOV_EXCL_LINE
                        }
 
                } else {
@@ -812,7 +912,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
 /**
 * time function
 */
-
+//LCOV_EXCL_START
 int stt_parser_set_time_info(GSList* time_list)
 {
        if (0 == g_slist_length(time_list)) {
@@ -859,7 +959,7 @@ int stt_parser_set_time_info(GSList* time_list)
 
                xmlNodePtr temp_node = NULL;
 
-               SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%d) e(%d)",
+               SECURE_SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%ld) e(%ld)",
                        data->index, data->event, data->text, data->start_time, data->end_time);
 
                temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_TEXT);
@@ -886,11 +986,26 @@ int stt_parser_set_time_info(GSList* time_list)
        xmlFreeDoc(doc);
        return 0;
 }
+//LCOV_EXCL_STOP
+
+void __stt_parser_time_info_free(void* data)
+{
+       stt_result_time_info_s* time_info = (stt_result_time_info_s*)data;
+
+       if (NULL != time_info) {
+               if (NULL != time_info->text) {
+                       free(time_info->text);
+                       time_info->text = NULL;
+               }
+
+               free(time_info);
+       }
+}
 
 int stt_parser_get_time_info(GSList** time_list)
 {
        if (NULL == time_list) {
-               SLOG(LOG_ERROR, stt_tag(), "Invalid paramter : text is NULL");
+               SLOG(LOG_ERROR, stt_tag(), "Invalid parameter : text is NULL"); //LCOV_EXCL_LINE
                return -1;
        }
 
@@ -899,28 +1014,34 @@ int stt_parser_get_time_info(GSList** time_list)
 
        doc = xmlParseFile(STT_TIME_INFO_PATH);
        if (doc == NULL) {
-               SLOG(LOG_WARN, stt_tag(), "[WARNING] File is not exist");
+               SLOG(LOG_WARN, stt_tag(), "[WARNING] File is not exist"); //LCOV_EXCL_LINE
                return -1;
        }
 
        cur = xmlDocGetRootElement(doc);
        if (cur == NULL) {
+               //LCOV_EXCL_START
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
                xmlFreeDoc(doc);
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_BASE_TAG)) {
+               //LCOV_EXCL_START
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT '%s'", STT_TAG_TIME_BASE_TAG);
                xmlFreeDoc(doc);
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        cur = cur->xmlChildrenNode;
        if (cur == NULL) {
+               //LCOV_EXCL_START
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
                xmlFreeDoc(doc);
                return -1;
+               //LCOV_EXCL_STOP
        }
 
        /* alloc time info */
@@ -932,7 +1053,13 @@ int stt_parser_get_time_info(GSList** time_list)
                if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_INDEX)) {
                        key = xmlGetProp(cur, (const xmlChar*)STT_TAG_TIME_COUNT);
                        if (NULL == key) {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_COUNT);
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_COUNT); //LCOV_EXCL_LINE
+
+                               if (NULL != temp_time_list) {
+                                       g_slist_free_full(temp_time_list, __stt_parser_time_info_free);
+                                       temp_time_list = NULL;
+                               }
+                               xmlFreeDoc(doc);
                                return -1;
                        }
 
@@ -944,7 +1071,7 @@ int stt_parser_get_time_info(GSList** time_list)
                        xmlFree(key);
 
                        if (count <= 0) {
-                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] count is invalid : %d", count);
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] count is invalid : %d", count); //LCOV_EXCL_LINE
                                break;
                        }
 
@@ -960,7 +1087,13 @@ int stt_parser_get_time_info(GSList** time_list)
                                temp_info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s));
 
                                if (NULL == temp_info) {
-                                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!");
+                                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!"); //LCOV_EXCL_LINE
+
+                                       if (NULL != temp_time_list) {
+                                               g_slist_free_full(temp_time_list, __stt_parser_time_info_free);
+                                               temp_time_list = NULL;
+                                       }
+                                       xmlFreeDoc(doc);
                                        return -1;
                                }
 
@@ -974,11 +1107,11 @@ int stt_parser_get_time_info(GSList** time_list)
                                if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_TEXT)) {
                                        key = xmlNodeGetContent(time_node);
                                        if (NULL != key) {
-                                               SLOG(LOG_DEBUG, stt_tag(), "text : %s", (char *)key);
+                                               SLOG(LOG_DEBUG, stt_tag(), "text : %s", (char *)key); //LCOV_EXCL_LINE
                                                temp_info->text = strdup((char*)key);
                                                xmlFree(key);
                                        } else {
-                                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_TEXT);
+                                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_TEXT); //LCOV_EXCL_LINE
                                                free(temp_info);
                                                break;
                                        }
@@ -991,11 +1124,11 @@ int stt_parser_get_time_info(GSList** time_list)
                                if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_START)) {
                                        key = xmlNodeGetContent(time_node);
                                        if (NULL != key) {
-                                               SLOG(LOG_DEBUG, stt_tag(), "Start time : %s", (char *)key);
+                                               SLOG(LOG_DEBUG, stt_tag(), "Start time : %s", (char *)key); //LCOV_EXCL_LINE
                                                temp_info->start_time = atoi((char*)key);
                                                xmlFree(key);
                                        } else {
-                                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_START);
+                                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_START); //LCOV_EXCL_LINE
                                                if (NULL != temp_info->text)    free(temp_info->text);
                                                free(temp_info);
                                                break;
@@ -1009,11 +1142,11 @@ int stt_parser_get_time_info(GSList** time_list)
                                if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_END)) {
                                        key = xmlNodeGetContent(time_node);
                                        if (NULL != key) {
-                                               SLOG(LOG_DEBUG, stt_tag(), "End time : %s", (char *)key);
+                                               SLOG(LOG_DEBUG, stt_tag(), "End time : %s", (char *)key); //LCOV_EXCL_LINE
                                                temp_info->end_time = atoi((char*)key);
                                                xmlFree(key);
                                        } else {
-                                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_END);
+                                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_END); //LCOV_EXCL_LINE
                                                if (NULL != temp_info->text)    free(temp_info->text);
                                                free(temp_info);
                                                break;