2 * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
18 #include "stt_config_parser.h"
21 #define STT_TAG_ENGINE_BASE_TAG "stt-engine"
22 #define STT_TAG_ENGINE_NAME "name"
23 #define STT_TAG_ENGINE_ID "id"
24 #define STT_TAG_ENGINE_SETTING "setting"
25 #define STT_TAG_ENGINE_AGREEMENT "agreement"
26 #define STT_TAG_ENGINE_LANGUAGE_SET "languages"
27 #define STT_TAG_ENGINE_LANGUAGE "lang"
28 #define STT_TAG_ENGINE_SILENCE_SUPPORT "silence-detection-support"
30 #define STT_TAG_CONFIG_BASE_TAG "stt-config"
31 #define STT_TAG_CONFIG_ENGINE_ID "engine"
32 #define STT_TAG_CONFIG_ENGINE_SETTING "engine-setting"
33 #define STT_TAG_CONFIG_AUTO_LANGUAGE "auto"
34 #define STT_TAG_CONFIG_LANGUAGE "language"
35 #define STT_TAG_CONFIG_SILENCE_DETECTION "silence-detection"
38 #define STT_TAG_TIME_BASE_TAG "stt-time"
39 #define STT_TAG_TIME_INDEX "index"
40 #define STT_TAG_TIME_COUNT "count"
41 #define STT_TAG_TIME_TIME_INFO "time-info"
42 #define STT_TAG_TIME_TEXT "text-info"
43 #define STT_TAG_TIME_START "start"
44 #define STT_TAG_TIME_END "end"
46 extern const char* stt_tag();
48 static xmlDocPtr g_config_doc = NULL;
50 int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info)
52 if (NULL == path || NULL == engine_info) {
53 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
58 xmlNodePtr cur = NULL;
61 doc = xmlParseFile(path);
66 cur = xmlDocGetRootElement(doc);
68 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
73 if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_BASE_TAG)) {
74 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT 'stt-engine'");
79 cur = cur->xmlChildrenNode;
81 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
86 /* alloc engine info */
87 stt_engine_info_s* temp;
88 temp = (stt_engine_info_s*)calloc(1, sizeof(stt_engine_info_s));
91 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
98 temp->agreement = NULL;
99 temp->languages = NULL;
100 temp->support_silence_detection = false;
102 while (cur != NULL) {
103 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) {
104 key = xmlNodeGetContent(cur);
106 /* SLOG(LOG_DEBUG, stt_tag(), "Engine name : %s", (char *)key); */
107 if (NULL != temp->name) free(temp->name);
108 temp->name = strdup((char*)key);
111 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_NAME);
113 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_ID)) {
114 key = xmlNodeGetContent(cur);
116 /* SLOG(LOG_DEBUG, stt_tag(), "Engine uuid : %s", (char *)key); */
117 if (NULL != temp->uuid) free(temp->uuid);
118 temp->uuid = strdup((char*)key);
121 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_ID);
123 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SETTING)) {
124 key = xmlNodeGetContent(cur);
126 SLOG(LOG_DEBUG, stt_tag(), "Engine setting : %s", (char *)key);
127 if (NULL != temp->setting) free(temp->setting);
128 temp->setting = strdup((char*)key);
131 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SETTING);
133 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_AGREEMENT)) {
134 key = xmlNodeGetContent(cur);
136 SLOG(LOG_DEBUG, stt_tag(), "Engine agreement : %s", (char *)key);
137 if (NULL != temp->agreement) free(temp->agreement);
138 temp->agreement = strdup((char*)key);
141 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT);
143 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE_SET)) {
144 xmlNodePtr lang_node = NULL;
145 char* temp_lang = NULL;
147 lang_node = cur->xmlChildrenNode;
149 while (lang_node != NULL) {
150 if (0 == xmlStrcmp(lang_node->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE)) {
151 key = xmlNodeGetContent(lang_node);
153 /* SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */
154 temp_lang = strdup((char*)key);
155 temp->languages = g_slist_append(temp->languages, temp_lang);
158 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_LANGUAGE);
162 lang_node = lang_node->next;
164 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SILENCE_SUPPORT)) {
165 key = xmlNodeGetContent(cur);
167 /*SLOG(LOG_DEBUG, stt_tag(), "silence-detection-support : %s", (char *)key); */
169 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
170 temp->support_silence_detection = true;
172 temp->support_silence_detection = false;
176 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT);
187 if (NULL == temp->name || NULL == temp->uuid) {
189 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Invalid engine : %s", path);
190 stt_parser_free_engine_info(temp);
199 int stt_parser_free_engine_info(stt_engine_info_s* engine_info)
201 if (NULL == engine_info) {
202 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
206 if (NULL != engine_info->name) free(engine_info->name);
207 if (NULL != engine_info->uuid) free(engine_info->uuid);
208 if (NULL != engine_info->setting) free(engine_info->setting);
209 if (NULL != engine_info->agreement) free(engine_info->agreement);
211 int count = g_slist_length(engine_info->languages);
216 for (i = 0; i < count ; i++) {
217 temp_lang = g_slist_nth_data(engine_info->languages, 0);
219 if (NULL != temp_lang) {
220 engine_info->languages = g_slist_remove(engine_info->languages, temp_lang);
222 if (NULL != temp_lang)
227 if (NULL != engine_info) free(engine_info);
232 int stt_parser_print_engine_info(stt_engine_info_s* engine_info)
234 if (NULL == engine_info)
237 SLOG(LOG_DEBUG, stt_tag(), "== get engine info ==");
238 SECURE_SLOG(LOG_DEBUG, stt_tag(), " name : %s", engine_info->name);
239 SECURE_SLOG(LOG_DEBUG, stt_tag(), " id : %s", engine_info->uuid);
240 if (NULL != engine_info->setting) SECURE_SLOG(LOG_DEBUG, stt_tag(), " setting : %s", engine_info->setting);
242 SLOG(LOG_DEBUG, stt_tag(), " languages");
245 if (g_slist_length(engine_info->languages) > 0) {
246 /* Get a first item */
247 iter = g_slist_nth(engine_info->languages, 0);
250 while (NULL != iter) {
251 /*Get handle data from list*/
254 SECURE_SLOG(LOG_DEBUG, stt_tag(), " [%dth] %s", i, lang);
257 iter = g_slist_next(iter);
261 SLOG(LOG_ERROR, stt_tag(), " language is NONE");
263 SECURE_SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", engine_info->support_silence_detection ? "true" : "false");
264 SLOG(LOG_DEBUG, stt_tag(), "=====================");
269 int stt_parser_load_config(stt_config_s** config_info)
271 if (NULL == config_info) {
272 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
276 xmlDocPtr doc = NULL;
277 xmlNodePtr cur = NULL;
279 bool is_default_open = false;
281 doc = xmlParseFile(STT_CONFIG);
283 doc = xmlParseFile(STT_DEFAULT_CONFIG);
285 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG);
288 is_default_open = true;
291 cur = xmlDocGetRootElement(doc);
293 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
298 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
299 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
304 cur = cur->xmlChildrenNode;
306 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
311 /* alloc engine info */
313 temp = (stt_config_s*)calloc(1, sizeof(stt_config_s));
316 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
320 temp->engine_id = NULL;
321 temp->setting = NULL;
322 temp->language = NULL;
324 while (cur != NULL) {
325 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
326 key = xmlNodeGetContent(cur);
328 /*SLOG(LOG_DEBUG, stt_tag(), "Engine id : %s", (char *)key); */
329 if (NULL != temp->engine_id) free(temp->engine_id);
330 temp->engine_id = strdup((char*)key);
333 SLOG(LOG_ERROR, stt_tag(), "[ERROR] engine id is NULL");
335 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
336 key = xmlNodeGetContent(cur);
338 /*SECURE_SLOG(LOG_DEBUG, stt_tag(), "Setting path : %s", (char *)key); */
339 if (NULL != temp->setting) free(temp->setting);
340 temp->setting = strdup((char*)key);
343 SLOG(LOG_ERROR, stt_tag(), "[ERROR] setting path is NULL");
346 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
347 key = xmlNodeGetContent(cur);
349 /*SECURE_SLOG(LOG_DEBUG, stt_tag(), "Auto language : %s", (char *)key); */
351 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
352 temp->auto_lang = true;
353 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
354 temp->auto_lang = false;
356 SLOG(LOG_ERROR, stt_tag(), "Auto voice is wrong");
357 temp->auto_lang = true;
362 SLOG(LOG_ERROR, stt_tag(), "[ERROR] auto langauge is NULL");
364 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
365 key = xmlNodeGetContent(cur);
367 /*SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */
368 if (NULL != temp->language) free(temp->language);
369 temp->language = strdup((char*)key);
372 SLOG(LOG_ERROR, stt_tag(), "[ERROR] language is NULL");
374 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
375 key = xmlNodeGetContent(cur);
377 /*SLOG(LOG_DEBUG, stt_tag(), "silence-detection : %s", (char *)key); */
379 if (0 == xmlStrcmp(key, (const xmlChar *)"on"))
380 temp->silence_detection = true;
382 temp->silence_detection = false;
386 SLOG(LOG_ERROR, stt_tag(), "[ERROR] silence-detection is NULL");
399 xmlSaveFile(STT_CONFIG, g_config_doc);
404 int stt_parser_unload_config(stt_config_s* config_info)
406 if (NULL != g_config_doc) xmlFreeDoc(g_config_doc);
407 if (NULL != config_info) {
408 if (NULL != config_info->engine_id) free(config_info->engine_id);
409 if (NULL != config_info->setting) free(config_info->setting);
410 if (NULL != config_info->language) free(config_info->language);
418 int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence)
420 if (NULL == g_config_doc || NULL == engine_id)
423 xmlNodePtr cur = NULL;
424 cur = xmlDocGetRootElement(g_config_doc);
426 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
430 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
431 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
435 cur = cur->xmlChildrenNode;
437 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
441 while (cur != NULL) {
442 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
443 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
446 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
447 xmlNodeSetContent(cur, (const xmlChar *)language);
450 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
451 xmlNodeSetContent(cur, (const xmlChar *)setting);
454 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
456 xmlNodeSetContent(cur, (const xmlChar *)"on");
458 xmlNodeSetContent(cur, (const xmlChar *)"off");
464 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
465 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
470 int stt_parser_set_language(const char* language)
472 if (NULL == g_config_doc || NULL == language)
475 xmlNodePtr cur = NULL;
476 cur = xmlDocGetRootElement(g_config_doc);
478 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
482 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
483 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
487 cur = cur->xmlChildrenNode;
489 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
493 while (cur != NULL) {
494 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
495 xmlNodeSetContent(cur, (const xmlChar *)language);
501 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
502 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
508 int stt_parser_set_auto_lang(bool value)
510 if (NULL == g_config_doc)
513 xmlNodePtr cur = NULL;
514 cur = xmlDocGetRootElement(g_config_doc);
516 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
520 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
521 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
525 cur = cur->xmlChildrenNode;
527 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
531 while (cur != NULL) {
532 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
534 xmlNodeSetContent(cur, (const xmlChar *)"on");
535 } else if (false == value) {
536 xmlNodeSetContent(cur, (const xmlChar *)"off");
538 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong value of auto voice");
546 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
547 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
552 int stt_parser_set_silence_detection(bool value)
554 if (NULL == g_config_doc)
557 xmlNodePtr cur = NULL;
558 cur = xmlDocGetRootElement(g_config_doc);
560 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
564 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
565 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
569 cur = cur->xmlChildrenNode;
571 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
575 while (cur != NULL) {
576 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
578 xmlNodeSetContent(cur, (const xmlChar *)"on");
580 xmlNodeSetContent(cur, (const xmlChar *)"off");
586 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
587 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
592 int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence)
594 if (NULL == engine || NULL == language || NULL == silence) {
595 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
599 xmlDocPtr doc = NULL;
600 xmlNodePtr cur_new = NULL;
601 xmlNodePtr cur_old = NULL;
606 doc = xmlParseFile(STT_CONFIG);
608 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG);
612 cur_new = xmlDocGetRootElement(doc);
613 cur_old = xmlDocGetRootElement(g_config_doc);
614 if (cur_new == NULL || cur_old == NULL) {
615 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
620 if (xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG)) {
621 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
626 cur_new = cur_new->xmlChildrenNode;
627 cur_old = cur_old->xmlChildrenNode;
628 if (cur_new == NULL || cur_old == NULL) {
629 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
638 while (cur_new != NULL && cur_old != NULL) {
639 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
640 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
641 key_old = xmlNodeGetContent(cur_old);
642 if (NULL != key_old) {
643 key_new = xmlNodeGetContent(cur_new);
644 if (NULL != key_new) {
645 if (0 != xmlStrcmp(key_old, key_new)) {
646 SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new);
647 if (NULL != *engine) free(*engine);
648 *engine = strdup((char*)key_new);
655 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
657 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
658 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
659 key_old = xmlNodeGetContent(cur_old);
660 if (NULL != key_old) {
661 key_new = xmlNodeGetContent(cur_new);
662 if (NULL != key_new) {
663 if (0 != xmlStrcmp(key_old, key_new)) {
664 SLOG(LOG_DEBUG, stt_tag(), "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new);
665 if (NULL != *setting) free(*setting);
666 *setting = strdup((char*)key_new);
673 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
675 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
676 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
677 key_old = xmlNodeGetContent(cur_old);
678 if (NULL != key_old) {
679 key_new = xmlNodeGetContent(cur_new);
680 if (NULL != key_new) {
681 if (0 != xmlStrcmp(key_old, key_new)) {
682 SLOG(LOG_DEBUG, stt_tag(), "Old auto lang(%s), New auto lang(%s)", (char*)key_old, (char*)key_new);
683 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
684 *auto_lang = (int)true;
686 *auto_lang = (int)false;
695 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
697 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
698 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
699 key_old = xmlNodeGetContent(cur_old);
700 if (NULL != key_old) {
701 key_new = xmlNodeGetContent(cur_new);
702 if (NULL != key_new) {
703 if (0 != xmlStrcmp(key_old, key_new)) {
704 SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new);
705 if (NULL != *language) free(*language);
706 *language = strdup((char*)key_new);
713 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
715 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
716 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
717 key_old = xmlNodeGetContent(cur_old);
718 if (NULL != key_old) {
719 key_new = xmlNodeGetContent(cur_new);
720 if (NULL != key_new) {
721 if (0 != xmlStrcmp(key_old, key_new)) {
722 SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old silence(%s), New silence(%s)", (char*)key_old, (char*)key_new);
723 if (0 == xmlStrcmp(key_new, (const xmlChar*)"on")) {
735 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
741 cur_new = cur_new->next;
742 cur_old = cur_old->next;
745 xmlFreeDoc(g_config_doc);
755 int stt_parser_set_time_info(GSList* time_list)
757 if (0 == g_slist_length(time_list)) {
758 SLOG(LOG_WARN, stt_tag(), "[WARNING] There is no time info to save");
762 if (-1 == remove(STT_TIME_INFO_PATH)) {
763 SECURE_SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH);
766 xmlDocPtr doc = NULL;
767 xmlNodePtr cur = NULL;
769 doc = xmlNewDoc((const xmlChar*)"1.0");
771 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make new doc");
775 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_BASE_TAG);
776 xmlDocSetRootElement(doc, cur);
778 xmlNodePtr inode = NULL;
780 stt_result_time_info_s *data = NULL;
783 snprintf(temp_str, 256, "%d", g_slist_length(time_list));
785 inode = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_INDEX);
786 xmlNewProp(inode, (const xmlChar*)STT_TAG_TIME_COUNT, (const xmlChar*)temp_str);
787 xmlAddChild(cur, inode);
789 /* Get a first item */
790 iter = g_slist_nth(time_list, 0);
791 while (NULL != iter) {
794 xmlNodePtr temp_node = NULL;
796 SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%d) e(%d)",
797 data->index, data->event, data->text, data->start_time, data->end_time);
799 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_TEXT);
800 xmlNodeSetContent(temp_node, (const xmlChar*)data->text);
801 xmlAddChild(inode, temp_node);
803 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_START);
804 snprintf(temp_str, 256, "%ld", data->start_time);
805 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
806 xmlAddChild(inode, temp_node);
808 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_END);
809 snprintf(temp_str, 256, "%ld", data->end_time);
810 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
811 xmlAddChild(inode, temp_node);
814 iter = g_slist_next(iter);
817 int ret = xmlSaveFormatFile(STT_TIME_INFO_PATH, doc, 1);
818 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
824 int stt_parser_get_time_info(GSList** time_list)
826 if (NULL == time_list) {
827 SLOG(LOG_ERROR, stt_tag(), "Invalid paramter : text is NULL");
831 xmlDocPtr doc = NULL;
832 xmlNodePtr cur = NULL;
834 doc = xmlParseFile(STT_TIME_INFO_PATH);
836 SLOG(LOG_WARN, stt_tag(), "[WARNING] File is not exist");
840 cur = xmlDocGetRootElement(doc);
842 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
847 if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_BASE_TAG)) {
848 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT '%s'", STT_TAG_TIME_BASE_TAG);
853 cur = cur->xmlChildrenNode;
855 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
860 /* alloc time info */
861 GSList *temp_time_list = NULL;
865 while (cur != NULL) {
866 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_INDEX)) {
867 key = xmlGetProp(cur, (const xmlChar*)STT_TAG_TIME_COUNT);
869 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_COUNT);
873 SLOG(LOG_DEBUG, stt_tag(), "Count : %s", (char *)key);
877 count = atoi((char*)key);
881 SLOG(LOG_ERROR, stt_tag(), "[ERROR] count is invalid : %d", count);
885 xmlNodePtr time_node = NULL;
886 time_node = cur->xmlChildrenNode;
889 for (i = 0; i < count; i++) {
891 time_node = time_node->next;
893 stt_result_time_info_s* temp_info;
894 temp_info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s));
896 if (NULL == temp_info) {
897 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!");
901 temp_info->index = index;
902 SLOG(LOG_DEBUG, stt_tag(), "index : %d", temp_info->index);
904 if (0 == i) temp_info->event = 0;
905 else if (count -1 == i) temp_info->event = 2;
906 else temp_info->event = 1;
908 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_TEXT)) {
909 key = xmlNodeGetContent(time_node);
911 SLOG(LOG_DEBUG, stt_tag(), "text : %s", (char *)key);
912 temp_info->text = strdup((char*)key);
915 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_TEXT);
922 time_node = time_node->next;
923 time_node = time_node->next;
925 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_START)) {
926 key = xmlNodeGetContent(time_node);
928 SLOG(LOG_DEBUG, stt_tag(), "Start time : %s", (char *)key);
929 temp_info->start_time = atoi((char*)key);
932 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_START);
933 if (NULL != temp_info->text) free(temp_info->text);
940 time_node = time_node->next;
941 time_node = time_node->next;
943 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_END)) {
944 key = xmlNodeGetContent(time_node);
946 SLOG(LOG_DEBUG, stt_tag(), "End time : %s", (char *)key);
947 temp_info->end_time = atoi((char*)key);
950 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_END);
951 if (NULL != temp_info->text) free(temp_info->text);
957 time_node = time_node->next;
959 temp_time_list = g_slist_append(temp_time_list, temp_info);
968 *time_list = temp_time_list;
973 int stt_parser_clear_time_info()
975 if (-1 == remove(STT_TIME_INFO_PATH)) {
976 SECURE_SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH);