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
}
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;
}
}
- 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;
}
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;
}
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;
}
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;
}
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;
}
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 */