From: wn.jang Date: Thu, 7 Jul 2022 01:56:49 +0000 (+0900) Subject: Extract to get base node from config X-Git-Tag: submit/tizen/20220725.004613~4^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ddbaea53fb3ba7cbe590f61ae64144304c87f1e2;p=platform%2Fcore%2Fuifw%2Fstt.git Extract to get base node from config Change-Id: Icd8c0c2270f7aa3ce1dbdd05606c50078177a31f --- diff --git a/common/stt_config_parser.c b/common/stt_config_parser.c index 3459ff3..8f53330 100644 --- a/common/stt_config_parser.c +++ b/common/stt_config_parser.c @@ -51,35 +51,19 @@ static xmlDocPtr g_config_doc = NULL; -int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info) +static int __stt_parser_get_base_node_from_config(xmlDocPtr config_doc, xmlNodePtr* node_ptr, const char* base_tag) { - if (NULL == path || NULL == engine_info) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return -1; - } - - xmlDocPtr doc = NULL; - xmlNodePtr cur = NULL; - xmlChar *key; - - doc = xmlParseFile(path); - if (doc == NULL) { - return -1; - } - - cur = xmlDocGetRootElement(doc); + xmlNodePtr cur = xmlDocGetRootElement(config_doc); if (cur == NULL) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); - xmlFreeDoc(doc); return -1; //LCOV_EXCL_STOP } - if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_BASE_TAG)) { + if (xmlStrcmp(cur->name, (const xmlChar *)base_tag)) { //LCOV_EXCL_START - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] The wrong type, root node is NOT 'stt-engine'"); - xmlFreeDoc(doc); + SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] The wrong type, root node is NOT %s", base_tag); return -1; //LCOV_EXCL_STOP } @@ -88,10 +72,34 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info if (cur == NULL) { //LCOV_EXCL_START SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); - xmlFreeDoc(doc); return -1; //LCOV_EXCL_STOP } + *node_ptr = cur; + return 0; +} + +int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info) +{ + if (NULL == path || NULL == engine_info) { + SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE + return -1; + } + + xmlDocPtr doc = NULL; + xmlNodePtr cur = NULL; + xmlChar *key; + + doc = xmlParseFile(path); + if (doc == NULL) { + return -1; + } + + if (0 != __stt_parser_get_base_node_from_config(doc, &cur, STT_TAG_ENGINE_BASE_TAG)) { + SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config"); + xmlFreeDoc(doc); + return -1; + } /* alloc engine info */ stt_engine_info_s* temp; @@ -366,22 +374,8 @@ int stt_parser_load_config(stt_config_s** config_info) } } - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); //LCOV_EXCL_LINE - xmlFreeDoc(doc); - return -1; - } - - if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[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, TAG_STTCONFIG, "[ERROR] Empty document"); //LCOV_EXCL_LINE + if (0 != __stt_parser_get_base_node_from_config(doc, &cur, STT_TAG_CONFIG_BASE_TAG)) { + SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config"); xmlFreeDoc(doc); return -1; } @@ -550,20 +544,8 @@ int stt_parser_set_engine(const char* engine_id, const char* setting, const char return -1; xmlNodePtr cur = NULL; - cur = xmlDocGetRootElement(g_config_doc); - if (cur == NULL) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); - return -1; - } - - if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); - return -1; - } - - cur = cur->xmlChildrenNode; - if (cur == NULL) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); + if (0 != __stt_parser_get_base_node_from_config(g_config_doc, &cur, STT_TAG_CONFIG_BASE_TAG)) { + SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config"); return -1; } @@ -609,20 +591,8 @@ int stt_parser_set_language(const char* language) return -1; xmlNodePtr cur = NULL; - cur = xmlDocGetRootElement(g_config_doc); - if (cur == NULL) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); - return -1; - } - - if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); - return -1; - } - - cur = cur->xmlChildrenNode; - if (cur == NULL) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); + if (0 != __stt_parser_get_base_node_from_config(g_config_doc, &cur, STT_TAG_CONFIG_BASE_TAG)) { + SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config"); return -1; } @@ -648,20 +618,8 @@ int stt_parser_set_auto_lang(bool value) return -1; xmlNodePtr cur = NULL; - cur = xmlDocGetRootElement(g_config_doc); - if (cur == NULL) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); - return -1; - } - - if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); - return -1; - } - - cur = cur->xmlChildrenNode; - if (cur == NULL) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); + if (0 != __stt_parser_get_base_node_from_config(g_config_doc, &cur, STT_TAG_CONFIG_BASE_TAG)) { + SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config"); return -1; } @@ -692,20 +650,8 @@ int stt_parser_set_silence_detection(bool value) return -1; xmlNodePtr cur = NULL; - cur = xmlDocGetRootElement(g_config_doc); - if (cur == NULL) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); - return -1; - } - - if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG); - return -1; - } - - cur = cur->xmlChildrenNode; - if (cur == NULL) { - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); + if (0 != __stt_parser_get_base_node_from_config(g_config_doc, &cur, STT_TAG_CONFIG_BASE_TAG)) { + SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config"); return -1; } @@ -1023,30 +969,9 @@ int stt_parser_get_time_info(GSList** time_list) return -1; } - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - //LCOV_EXCL_START - SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Empty document"); - xmlFreeDoc(doc); + if (0 != __stt_parser_get_base_node_from_config(g_config_doc, &cur, STT_TAG_TIME_BASE_TAG)) { + SLOG(LOG_ERROR, TAG_STTCONFIG, "[ERROR] Fail to get base node from config"); return -1; - //LCOV_EXCL_STOP - } - - if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_BASE_TAG)) { - //LCOV_EXCL_START - SLOG(LOG_ERROR, TAG_STTCONFIG, "[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, TAG_STTCONFIG, "[ERROR] Empty document"); - xmlFreeDoc(doc); - return -1; - //LCOV_EXCL_STOP } /* alloc time info */