*/
#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"
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);
} else {
SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT);
}
+ } 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;
char* temp_lang = 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);
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);
+ 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);
*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;
}
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);
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) {
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_ERROR, stt_tag(), "[ERROR] Memory alloc error!!");
if (NULL != temp_time_list) {
- g_slist_free_full(temp_time_list, free);
+ g_slist_free_full(temp_time_list, __stt_parser_time_info_free);
temp_time_list = NULL;
}
xmlFreeDoc(doc);