X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=common%2Fstt_config_parser.c;h=aba6692afd12219b6340ade7a57a049fd3059d2d;hb=refs%2Fchanges%2F99%2F123399%2F1;hp=564705d2063c23f7c57ad7e2f9fbed79cd041785;hpb=23e300999f1c74be9a304e681ce2c0c776558071;p=platform%2Fcore%2Fuifw%2Fstt.git diff --git a/common/stt_config_parser.c b/common/stt_config_parser.c index 564705d..aba6692 100644 --- a/common/stt_config_parser.c +++ b/common/stt_config_parser.c @@ -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" @@ -86,6 +88,11 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info /* alloc engine info */ stt_engine_info_s* temp; temp = (stt_engine_info_s*)calloc(1, sizeof(stt_engine_info_s)); + if (NULL == temp) { + xmlFreeDoc(doc); + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory"); + return -1; + } temp->name = NULL; temp->uuid = NULL; @@ -93,27 +100,28 @@ 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)) { key = xmlNodeGetContent(cur); if (NULL != key) { - // SLOG(LOG_DEBUG, stt_tag(), "Engine name : %s", (char *)key); + /* SLOG(LOG_DEBUG, stt_tag(), "Engine name : %s", (char *)key); */ if (NULL != temp->name) free(temp->name); temp->name = strdup((char*)key); xmlFree(key); } else { - SECURE_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); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_ID)) { key = xmlNodeGetContent(cur); if (NULL != key) { - // SLOG(LOG_DEBUG, stt_tag(), "Engine uuid : %s", (char *)key); + /* SLOG(LOG_DEBUG, stt_tag(), "Engine uuid : %s", (char *)key); */ if (NULL != temp->uuid) free(temp->uuid); temp->uuid = strdup((char*)key); xmlFree(key); } else { - SECURE_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); } } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SETTING)) { key = xmlNodeGetContent(cur); @@ -142,15 +150,15 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info lang_node = cur->xmlChildrenNode; while (lang_node != NULL) { - if (0 == xmlStrcmp(lang_node->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE)){ + if (0 == xmlStrcmp(lang_node->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE)) { key = xmlNodeGetContent(lang_node); if (NULL != key) { - // SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); + /* SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */ temp_lang = strdup((char*)key); temp->languages = g_slist_append(temp->languages, temp_lang); xmlFree(key); } else { - SECURE_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); } } @@ -159,16 +167,30 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SILENCE_SUPPORT)) { key = xmlNodeGetContent(cur); if (NULL != key) { - //SLOG(LOG_DEBUG, stt_tag(), "silence-detection-support : %s", (char *)key); + /*SLOG(LOG_DEBUG, stt_tag(), "silence-detection-support : %s", (char *)key); */ if (0 == xmlStrcmp(key, (const xmlChar *)"true")) temp->support_silence_detection = true; else temp->support_silence_detection = false; - + xmlFree(key); } else { - SECURE_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); + } + } 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 { @@ -181,7 +203,7 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info if (NULL == temp->name || NULL == temp->uuid) { /* Invalid engine */ - SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Invalid engine : %s", path); + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Invalid engine : %s", path); stt_parser_free_engine_info(temp); return -1; } @@ -208,7 +230,7 @@ int stt_parser_free_engine_info(stt_engine_info_s* engine_info) int i ; char *temp_lang; - for (i = 0;i < count ;i++) { + for (i = 0; i < count ; i++) { temp_lang = g_slist_nth_data(engine_info->languages, 0); if (NULL != temp_lang) { @@ -216,12 +238,12 @@ int stt_parser_free_engine_info(stt_engine_info_s* engine_info) if (NULL != temp_lang) free(temp_lang); - } + } } if (NULL != engine_info) free(engine_info); - return 0; + return 0; } int stt_parser_print_engine_info(stt_engine_info_s* engine_info) @@ -230,9 +252,9 @@ int stt_parser_print_engine_info(stt_engine_info_s* engine_info) return -1; SLOG(LOG_DEBUG, stt_tag(), "== get engine info =="); - SECURE_SLOG(LOG_DEBUG, stt_tag(), " name : %s", engine_info->name); - SECURE_SLOG(LOG_DEBUG, stt_tag(), " id : %s", engine_info->uuid); - if (NULL != engine_info->setting) SECURE_SLOG(LOG_DEBUG, stt_tag(), " setting : %s", engine_info->setting); + SLOG(LOG_DEBUG, stt_tag(), " name : %s", engine_info->name); + SLOG(LOG_DEBUG, stt_tag(), " id : %s", engine_info->uuid); + if (NULL != engine_info->setting) SLOG(LOG_DEBUG, stt_tag(), " setting : %s", engine_info->setting); SLOG(LOG_DEBUG, stt_tag(), " languages"); GSList *iter = NULL; @@ -241,12 +263,12 @@ int stt_parser_print_engine_info(stt_engine_info_s* engine_info) /* Get a first item */ iter = g_slist_nth(engine_info->languages, 0); - int i = 1; + int i = 1; while (NULL != iter) { /*Get handle data from list*/ lang = iter->data; - SECURE_SLOG(LOG_DEBUG, stt_tag(), " [%dth] %s", i, lang); + SLOG(LOG_DEBUG, stt_tag(), " [%dth] %s", i, lang); /*Get next item*/ iter = g_slist_next(iter); @@ -255,7 +277,8 @@ int stt_parser_print_engine_info(stt_engine_info_s* engine_info) } else { SLOG(LOG_ERROR, stt_tag(), " language is NONE"); } - SECURE_SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", engine_info->support_silence_detection ? "true" : "false"); + 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; @@ -277,7 +300,7 @@ int stt_parser_load_config(stt_config_s** config_info) if (doc == NULL) { doc = xmlParseFile(STT_DEFAULT_CONFIG); if (doc == NULL) { - SECURE_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); return -1; } is_default_open = true; @@ -291,7 +314,7 @@ int stt_parser_load_config(stt_config_s** config_info) } if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { - SECURE_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); xmlFreeDoc(doc); return -1; } @@ -306,6 +329,11 @@ int stt_parser_load_config(stt_config_s** config_info) /* alloc engine info */ stt_config_s* temp; 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"); + return -1; + } temp->engine_id = NULL; temp->setting = NULL; @@ -315,7 +343,7 @@ int stt_parser_load_config(stt_config_s** config_info) if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) { key = xmlNodeGetContent(cur); if (NULL != key) { - //SLOG(LOG_DEBUG, stt_tag(), "Engine id : %s", (char *)key); + /*SLOG(LOG_DEBUG, stt_tag(), "Engine id : %s", (char *)key); */ if (NULL != temp->engine_id) free(temp->engine_id); temp->engine_id = strdup((char*)key); xmlFree(key); @@ -325,7 +353,7 @@ int stt_parser_load_config(stt_config_s** config_info) } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) { key = xmlNodeGetContent(cur); if (NULL != key) { - //SECURE_SLOG(LOG_DEBUG, stt_tag(), "Setting path : %s", (char *)key); + /*SLOG(LOG_DEBUG, stt_tag(), "Setting path : %s", (char *)key); */ if (NULL != temp->setting) free(temp->setting); temp->setting = strdup((char*)key); xmlFree(key); @@ -336,7 +364,7 @@ int stt_parser_load_config(stt_config_s** config_info) } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) { key = xmlNodeGetContent(cur); if (NULL != key) { - //SECURE_SLOG(LOG_DEBUG, stt_tag(), "Auto language : %s", (char *)key); + /*SLOG(LOG_DEBUG, stt_tag(), "Auto language : %s", (char *)key); */ if (0 == xmlStrcmp(key, (const xmlChar *)"on")) { temp->auto_lang = true; @@ -354,7 +382,7 @@ int stt_parser_load_config(stt_config_s** config_info) } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) { key = xmlNodeGetContent(cur); if (NULL != key) { - //SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); + /*SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */ if (NULL != temp->language) free(temp->language); temp->language = strdup((char*)key); xmlFree(key); @@ -364,7 +392,7 @@ int stt_parser_load_config(stt_config_s** config_info) } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) { key = xmlNodeGetContent(cur); if (NULL != key) { - //SLOG(LOG_DEBUG, stt_tag(), "silence-detection : %s", (char *)key); + /*SLOG(LOG_DEBUG, stt_tag(), "silence-detection : %s", (char *)key); */ if (0 == xmlStrcmp(key, (const xmlChar *)"on")) temp->silence_detection = true; @@ -375,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 { } @@ -395,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); } @@ -405,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; @@ -418,7 +469,7 @@ int stt_parser_set_engine(const char* engine_id, const char* setting, const char } if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { - SECURE_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); return -1; } @@ -444,10 +495,17 @@ int stt_parser_set_engine(const char* engine_id, const char* setting, const char if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) { if (true == silence) xmlNodeSetContent(cur, (const xmlChar *)"on"); - else + else 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; } @@ -470,7 +528,7 @@ int stt_parser_set_language(const char* language) } if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { - SECURE_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); return -1; } @@ -483,7 +541,7 @@ int stt_parser_set_language(const char* language) while (cur != NULL) { if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) { xmlNodeSetContent(cur, (const xmlChar *)language); - } + } cur = cur->next; } @@ -552,7 +610,7 @@ int stt_parser_set_silence_detection(bool value) } if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) { - SECURE_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); return -1; } @@ -566,9 +624,9 @@ int stt_parser_set_silence_detection(bool value) if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) { if (true == value) xmlNodeSetContent(cur, (const xmlChar *)"on"); - else + else xmlNodeSetContent(cur, (const xmlChar *)"off"); - } + } cur = cur->next; } @@ -579,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; } @@ -595,7 +653,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang doc = xmlParseFile(STT_CONFIG); if (doc == NULL) { - SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG); + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG); return -1; } @@ -608,7 +666,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang } if (xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG)) { - SECURE_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); xmlFreeDoc(doc); return -1; } @@ -633,7 +691,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)) { - SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new); + SLOG(LOG_DEBUG, stt_tag(), "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new); if (NULL != *engine) free(*engine); *engine = strdup((char*)key_new); } @@ -691,7 +749,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)) { - SECURE_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); if (NULL != *language) free(*language); *language = strdup((char*)key_new); } @@ -709,14 +767,14 @@ 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)) { - SECURE_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); if (0 == xmlStrcmp(key_new, (const xmlChar*)"on")) { *silence = 1; } else { *silence = 0; } } - + xmlFree(key_new); } xmlFree(key_old); @@ -724,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 { } @@ -731,7 +811,7 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang cur_new = cur_new->next; cur_old = cur_old->next; } - + xmlFreeDoc(g_config_doc); g_config_doc = doc; @@ -750,7 +830,7 @@ int stt_parser_set_time_info(GSList* time_list) } if (-1 == remove(STT_TIME_INFO_PATH)) { - SECURE_SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); + SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); } xmlDocPtr doc = NULL; @@ -758,7 +838,7 @@ int stt_parser_set_time_info(GSList* time_list) doc = xmlNewDoc((const xmlChar*)"1.0"); if (doc == NULL) { - SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make new doc"); + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make new doc"); return -1; } @@ -780,16 +860,21 @@ int stt_parser_set_time_info(GSList* time_list) iter = g_slist_nth(time_list, 0); while (NULL != iter) { data = iter->data; - + + if (NULL == data) { + SLOG(LOG_DEBUG, stt_tag(), "data is NULL"); + continue; + } + xmlNodePtr temp_node = NULL; - SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%d) e(%d)", + SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%d) e(%d)", data->index, data->event, data->text, data->start_time, data->end_time); - + temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_TEXT); xmlNodeSetContent(temp_node, (const xmlChar*)data->text); xmlAddChild(inode, temp_node); - + temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_START); snprintf(temp_str, 256, "%ld", data->start_time); xmlNodeSetContent(temp_node, (const xmlChar*)temp_str); @@ -811,6 +896,20 @@ int stt_parser_set_time_info(GSList* time_list) return 0; } +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) { @@ -857,9 +956,15 @@ 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); + + 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; } - + SLOG(LOG_DEBUG, stt_tag(), "Count : %s", (char *)key); /* Get time count */ @@ -876,7 +981,7 @@ int stt_parser_get_time_info(GSList** time_list) time_node = cur->xmlChildrenNode; int i = 0; - for (i = 0;i < count;i++) { + for (i = 0; i < count; i++) { /* text */ time_node = time_node->next; @@ -885,6 +990,12 @@ int stt_parser_get_time_info(GSList** time_list) if (NULL == temp_info) { SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!"); + + 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; } @@ -893,7 +1004,7 @@ int stt_parser_get_time_info(GSList** time_list) if (0 == i) temp_info->event = 0; else if (count -1 == i) temp_info->event = 2; - else temp_info->event = 1; + else temp_info->event = 1; if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_TEXT)) { key = xmlNodeGetContent(time_node); @@ -902,7 +1013,7 @@ int stt_parser_get_time_info(GSList** time_list) temp_info->text = strdup((char*)key); xmlFree(key); } else { - SECURE_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); free(temp_info); break; } @@ -919,13 +1030,13 @@ int stt_parser_get_time_info(GSList** time_list) temp_info->start_time = atoi((char*)key); xmlFree(key); } else { - SECURE_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); if (NULL != temp_info->text) free(temp_info->text); free(temp_info); break; } } - + /* text */ time_node = time_node->next; time_node = time_node->next; @@ -937,7 +1048,7 @@ int stt_parser_get_time_info(GSList** time_list) temp_info->end_time = atoi((char*)key); xmlFree(key); } else { - SECURE_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); if (NULL != temp_info->text) free(temp_info->text); free(temp_info); break; @@ -963,7 +1074,7 @@ int stt_parser_get_time_info(GSList** time_list) int stt_parser_clear_time_info() { if (-1 == remove(STT_TIME_INFO_PATH)) { - SECURE_SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); + /* SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); */ } return 0;