Fix memory leak and Delete an unnecessary file
[platform/core/uifw/stt.git] / common / stt_config_parser.c
old mode 100755 (executable)
new mode 100644 (file)
index dadfed4..7221d3b
@@ -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
@@ -26,6 +26,7 @@
 #define STT_TAG_ENGINE_LANGUAGE_SET    "languages"
 #define STT_TAG_ENGINE_LANGUAGE                "lang"
 #define STT_TAG_ENGINE_SILENCE_SUPPORT "silence-detection-support"
+#define STT_TAG_ENGINE_CREDENTIAL_NEED "app-credential-need"
 
 #define STT_TAG_CONFIG_BASE_TAG                "stt-config"
 #define STT_TAG_CONFIG_ENGINE_ID       "engine"
@@ -33,6 +34,7 @@
 #define STT_TAG_CONFIG_AUTO_LANGUAGE   "auto"
 #define STT_TAG_CONFIG_LANGUAGE                "language"
 #define STT_TAG_CONFIG_SILENCE_DETECTION "silence-detection"
+#define STT_TAG_CONFIG_CREDENTIAL      "credential"
 
 
 #define STT_TAG_TIME_BASE_TAG          "stt-time"
@@ -98,6 +100,7 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
        temp->agreement = NULL;
        temp->languages = NULL;
        temp->support_silence_detection = false;
+       temp->need_credential = false;
 
        while (cur != NULL) {
                if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) {
@@ -175,6 +178,20 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
                        } else {
                                SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT);
                        }
+               } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_CREDENTIAL_NEED)) {
+                       key = xmlNodeGetContent(cur);
+                       if (NULL != key) {
+                               //SLOG(LOG_DEBUG, stt_tag(), "app-credential-need : %s", (char *)key);
+
+                               if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
+                                       temp->need_credential = true;
+                               else
+                                       temp->need_credential = false;
+
+                               xmlFree(key);
+                       } else {
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_CREDENTIAL_NEED);
+                       }
                } else {
 
                }
@@ -261,6 +278,7 @@ int stt_parser_print_engine_info(stt_engine_info_s* engine_info)
                SLOG(LOG_ERROR, stt_tag(), "  language is NONE");
        }
        SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", engine_info->support_silence_detection ? "true" : "false");
+       SLOG(LOG_DEBUG, stt_tag(), " credential need : %s", engine_info->need_credential ? "true" : "false");
        SLOG(LOG_DEBUG, stt_tag(), "=====================");
 
        return 0;
@@ -385,6 +403,20 @@ int stt_parser_load_config(stt_config_s** config_info)
                        } else {
                                SLOG(LOG_ERROR, stt_tag(), "[ERROR] silence-detection is NULL");
                        }
+               } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
+                       key = xmlNodeGetContent(cur);
+                       if (NULL != key) {
+                               //SLOG(LOG_DEBUG, stt_tag(), "credential : %s", (char *)key);
+
+                               if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
+                                       temp->credential = true;
+                               else
+                                       temp->credential = false;
+
+                               xmlFree(key);
+                       } else {
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] credential is NULL");
+                       }
                } else {
 
                }
@@ -405,9 +437,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);
        }
@@ -415,7 +456,7 @@ int stt_parser_unload_config(stt_config_s* config_info)
        return 0;
 }
 
-int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence)
+int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence, bool credential)
 {
        if (NULL == g_config_doc || NULL == engine_id)
                return -1;
@@ -458,6 +499,13 @@ int stt_parser_set_engine(const char* engine_id, const char* setting, const char
                                xmlNodeSetContent(cur, (const xmlChar *)"off");
                }
 
+               if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
+                       if (true == credential)
+                               xmlNodeSetContent(cur, (const xmlChar *)"true");
+                       else
+                               xmlNodeSetContent(cur, (const xmlChar *)"false");
+               }
+
                cur = cur->next;
        }
 
@@ -589,9 +637,9 @@ int stt_parser_set_silence_detection(bool value)
        return 0;
 }
 
-int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence)
+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) {
+       if (NULL == engine || NULL == language || NULL == silence || NULL == credential) {
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
                return -1;
        }
@@ -734,6 +782,28 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang
                        } else {
                                SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
                        }
+               } 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)) {
+                               key_old = xmlNodeGetContent(cur_old);
+                               if (NULL != key_old) {
+                                       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);
+                                                       if (0 == xmlStrcmp(key_new, (const xmlChar*)"true")) {
+                                                               *credential = 1;
+                                                       } else {
+                                                               *credential = 0;
+                                                       }
+                                               }
+                                               xmlFree(key_new);
+                                       }
+                                       xmlFree(key_old);
+                               }
+                       } else {
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
+                       }
+
                } else {
 
                }
@@ -872,6 +942,7 @@ int stt_parser_get_time_info(GSList** time_list)
                        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);
+                               xmlFreeDoc(doc);
                                return -1;
                        }
 
@@ -900,6 +971,7 @@ int stt_parser_get_time_info(GSList** time_list)
 
                                if (NULL == temp_info) {
                                        SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!");
+                                       xmlFreeDoc(doc);
                                        return -1;
                                }