/*
-* 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
*/
#include <dlog.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <vconf.h>
#include "stt_defs.h"
#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"
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;
}
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);
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);
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);
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);
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;
/* 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
}
}
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);
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;
}
return 0;
}
+//LCOV_EXCL_START
int stt_parser_print_engine_info(stt_engine_info_s* engine_info)
{
if (NULL == 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;
}
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;
}
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;
}
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);
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)) {
} 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);
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);
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);
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 {
*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;
}
{
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);
}
return 0;
}
+//LCOV_EXCL_START
int stt_parser_set_auto_lang(bool value)
{
if (NULL == g_config_doc)
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;
}
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;
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)) {
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);
}
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)) {
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 {
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)) {
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);
}
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)) {
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 {
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)) {
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 {
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 {
/**
* time function
*/
-
+//LCOV_EXCL_START
int stt_parser_set_time_info(GSList* time_list)
{
if (0 == g_slist_length(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);
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;
}
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 */
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;
}
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;
}
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;
}
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;
}
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;
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;