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));
93 temp->agreement = NULL;
94 temp->languages = NULL;
95 temp->support_silence_detection = false;
98 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) {
99 key = xmlNodeGetContent(cur);
101 // SLOG(LOG_DEBUG, stt_tag(), "Engine name : %s", (char *)key);
102 if (NULL != temp->name) free(temp->name);
103 temp->name = strdup((char*)key);
106 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_NAME);
108 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_ID)) {
109 key = xmlNodeGetContent(cur);
111 // SLOG(LOG_DEBUG, stt_tag(), "Engine uuid : %s", (char *)key);
112 if (NULL != temp->uuid) free(temp->uuid);
113 temp->uuid = strdup((char*)key);
116 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_ID);
118 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SETTING)) {
119 key = xmlNodeGetContent(cur);
121 SLOG(LOG_DEBUG, stt_tag(), "Engine setting : %s", (char *)key);
122 if (NULL != temp->setting) free(temp->setting);
123 temp->setting = strdup((char*)key);
126 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SETTING);
128 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_AGREEMENT)) {
129 key = xmlNodeGetContent(cur);
131 SLOG(LOG_DEBUG, stt_tag(), "Engine agreement : %s", (char *)key);
132 if (NULL != temp->agreement) free(temp->agreement);
133 temp->agreement = strdup((char*)key);
136 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT);
138 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE_SET)) {
139 xmlNodePtr lang_node = NULL;
140 char* temp_lang = NULL;
142 lang_node = cur->xmlChildrenNode;
144 while (lang_node != NULL) {
145 if (0 == xmlStrcmp(lang_node->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE)){
146 key = xmlNodeGetContent(lang_node);
148 // SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key);
149 temp_lang = strdup((char*)key);
150 temp->languages = g_slist_append(temp->languages, temp_lang);
153 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_LANGUAGE);
157 lang_node = lang_node->next;
159 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SILENCE_SUPPORT)) {
160 key = xmlNodeGetContent(cur);
162 //SLOG(LOG_DEBUG, stt_tag(), "silence-detection-support : %s", (char *)key);
164 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
165 temp->support_silence_detection = true;
167 temp->support_silence_detection = false;
171 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT);
182 if (NULL == temp->name || NULL == temp->uuid) {
184 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Invalid engine : %s", path);
185 stt_parser_free_engine_info(temp);
194 int stt_parser_free_engine_info(stt_engine_info_s* engine_info)
196 if (NULL == engine_info) {
197 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
201 if (NULL != engine_info->name) free(engine_info->name);
202 if (NULL != engine_info->uuid) free(engine_info->uuid);
203 if (NULL != engine_info->setting) free(engine_info->setting);
204 if (NULL != engine_info->agreement) free(engine_info->agreement);
206 int count = g_slist_length(engine_info->languages);
211 for (i = 0;i < count ;i++) {
212 temp_lang = g_slist_nth_data(engine_info->languages, 0);
214 if (NULL != temp_lang) {
215 engine_info->languages = g_slist_remove(engine_info->languages, temp_lang);
217 if (NULL != temp_lang)
222 if (NULL != engine_info) free(engine_info);
227 int stt_parser_print_engine_info(stt_engine_info_s* engine_info)
229 if (NULL == engine_info)
232 SLOG(LOG_DEBUG, stt_tag(), "== get engine info ==");
233 SECURE_SLOG(LOG_DEBUG, stt_tag(), " name : %s", engine_info->name);
234 SECURE_SLOG(LOG_DEBUG, stt_tag(), " id : %s", engine_info->uuid);
235 if (NULL != engine_info->setting) SECURE_SLOG(LOG_DEBUG, stt_tag(), " setting : %s", engine_info->setting);
237 SLOG(LOG_DEBUG, stt_tag(), " languages");
240 if (g_slist_length(engine_info->languages) > 0) {
241 /* Get a first item */
242 iter = g_slist_nth(engine_info->languages, 0);
245 while (NULL != iter) {
246 /*Get handle data from list*/
249 SECURE_SLOG(LOG_DEBUG, stt_tag(), " [%dth] %s", i, lang);
252 iter = g_slist_next(iter);
256 SLOG(LOG_ERROR, stt_tag(), " language is NONE");
258 SECURE_SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", engine_info->support_silence_detection ? "true" : "false");
259 SLOG(LOG_DEBUG, stt_tag(), "=====================");
264 int stt_parser_load_config(stt_config_s** config_info)
266 if (NULL == config_info) {
267 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
271 xmlDocPtr doc = NULL;
272 xmlNodePtr cur = NULL;
274 bool is_default_open = false;
276 doc = xmlParseFile(STT_CONFIG);
278 doc = xmlParseFile(STT_DEFAULT_CONFIG);
280 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG);
283 is_default_open = true;
286 cur = xmlDocGetRootElement(doc);
288 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
293 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
294 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
299 cur = cur->xmlChildrenNode;
301 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
306 /* alloc engine info */
308 temp = (stt_config_s*)calloc(1, sizeof(stt_config_s));
310 temp->engine_id = NULL;
311 temp->setting = NULL;
312 temp->language = NULL;
314 while (cur != NULL) {
315 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
316 key = xmlNodeGetContent(cur);
318 //SLOG(LOG_DEBUG, stt_tag(), "Engine id : %s", (char *)key);
319 if (NULL != temp->engine_id) free(temp->engine_id);
320 temp->engine_id = strdup((char*)key);
323 SLOG(LOG_ERROR, stt_tag(), "[ERROR] engine id is NULL");
325 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
326 key = xmlNodeGetContent(cur);
328 //SECURE_SLOG(LOG_DEBUG, stt_tag(), "Setting path : %s", (char *)key);
329 if (NULL != temp->setting) free(temp->setting);
330 temp->setting = strdup((char*)key);
333 SLOG(LOG_ERROR, stt_tag(), "[ERROR] setting path is NULL");
336 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
337 key = xmlNodeGetContent(cur);
339 //SECURE_SLOG(LOG_DEBUG, stt_tag(), "Auto language : %s", (char *)key);
341 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
342 temp->auto_lang = true;
343 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
344 temp->auto_lang = false;
346 SLOG(LOG_ERROR, stt_tag(), "Auto voice is wrong");
347 temp->auto_lang = true;
352 SLOG(LOG_ERROR, stt_tag(), "[ERROR] auto langauge is NULL");
354 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
355 key = xmlNodeGetContent(cur);
357 //SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key);
358 if (NULL != temp->language) free(temp->language);
359 temp->language = strdup((char*)key);
362 SLOG(LOG_ERROR, stt_tag(), "[ERROR] language is NULL");
364 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
365 key = xmlNodeGetContent(cur);
367 //SLOG(LOG_DEBUG, stt_tag(), "silence-detection : %s", (char *)key);
369 if (0 == xmlStrcmp(key, (const xmlChar *)"on"))
370 temp->silence_detection = true;
372 temp->silence_detection = false;
376 SLOG(LOG_ERROR, stt_tag(), "[ERROR] silence-detection is NULL");
389 xmlSaveFile(STT_CONFIG, g_config_doc);
394 int stt_parser_unload_config(stt_config_s* config_info)
396 if (NULL != g_config_doc) xmlFreeDoc(g_config_doc);
397 if (NULL != config_info) {
398 if (NULL != config_info->engine_id) free(config_info->engine_id);
399 if (NULL != config_info->setting) free(config_info->setting);
400 if (NULL != config_info->language) free(config_info->language);
408 int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence)
410 if (NULL == g_config_doc || NULL == engine_id)
413 xmlNodePtr cur = NULL;
414 cur = xmlDocGetRootElement(g_config_doc);
416 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
420 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
421 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
425 cur = cur->xmlChildrenNode;
427 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
431 while (cur != NULL) {
432 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
433 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
436 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
437 xmlNodeSetContent(cur, (const xmlChar *)language);
440 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
441 xmlNodeSetContent(cur, (const xmlChar *)setting);
444 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
446 xmlNodeSetContent(cur, (const xmlChar *)"on");
448 xmlNodeSetContent(cur, (const xmlChar *)"off");
454 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
455 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
460 int stt_parser_set_language(const char* language)
462 if (NULL == g_config_doc || NULL == language)
465 xmlNodePtr cur = NULL;
466 cur = xmlDocGetRootElement(g_config_doc);
468 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
472 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
473 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
477 cur = cur->xmlChildrenNode;
479 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
483 while (cur != NULL) {
484 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
485 xmlNodeSetContent(cur, (const xmlChar *)language);
491 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
492 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
498 int stt_parser_set_auto_lang(bool value)
500 if (NULL == g_config_doc)
503 xmlNodePtr cur = NULL;
504 cur = xmlDocGetRootElement(g_config_doc);
506 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
510 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
511 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
515 cur = cur->xmlChildrenNode;
517 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
521 while (cur != NULL) {
522 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
524 xmlNodeSetContent(cur, (const xmlChar *)"on");
525 } else if (false == value) {
526 xmlNodeSetContent(cur, (const xmlChar *)"off");
528 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong value of auto voice");
536 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
537 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
542 int stt_parser_set_silence_detection(bool value)
544 if (NULL == g_config_doc)
547 xmlNodePtr cur = NULL;
548 cur = xmlDocGetRootElement(g_config_doc);
550 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
554 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
555 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
559 cur = cur->xmlChildrenNode;
561 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
565 while (cur != NULL) {
566 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
568 xmlNodeSetContent(cur, (const xmlChar *)"on");
570 xmlNodeSetContent(cur, (const xmlChar *)"off");
576 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
577 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
582 int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence)
584 if (NULL == engine || NULL == language || NULL == silence) {
585 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
589 xmlDocPtr doc = NULL;
590 xmlNodePtr cur_new = NULL;
591 xmlNodePtr cur_old = NULL;
596 doc = xmlParseFile(STT_CONFIG);
598 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG);
602 cur_new = xmlDocGetRootElement(doc);
603 cur_old = xmlDocGetRootElement(g_config_doc);
604 if (cur_new == NULL || cur_old == NULL) {
605 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
610 if (xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG)) {
611 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
616 cur_new = cur_new->xmlChildrenNode;
617 cur_old = cur_old->xmlChildrenNode;
618 if (cur_new == NULL || cur_old == NULL) {
619 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
628 while (cur_new != NULL && cur_old != NULL) {
629 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
630 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
631 key_old = xmlNodeGetContent(cur_old);
632 if (NULL != key_old) {
633 key_new = xmlNodeGetContent(cur_new);
634 if (NULL != key_new) {
635 if (0 != xmlStrcmp(key_old, key_new)) {
636 SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new);
637 if (NULL != *engine) free(*engine);
638 *engine = strdup((char*)key_new);
645 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
647 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
648 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
649 key_old = xmlNodeGetContent(cur_old);
650 if (NULL != key_old) {
651 key_new = xmlNodeGetContent(cur_new);
652 if (NULL != key_new) {
653 if (0 != xmlStrcmp(key_old, key_new)) {
654 SLOG(LOG_DEBUG, stt_tag(), "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new);
655 if (NULL != *setting) free(*setting);
656 *setting = strdup((char*)key_new);
663 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
665 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
666 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
667 key_old = xmlNodeGetContent(cur_old);
668 if (NULL != key_old) {
669 key_new = xmlNodeGetContent(cur_new);
670 if (NULL != key_new) {
671 if (0 != xmlStrcmp(key_old, key_new)) {
672 SLOG(LOG_DEBUG, stt_tag(), "Old auto lang(%s), New auto lang(%s)", (char*)key_old, (char*)key_new);
673 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
674 *auto_lang = (int)true;
676 *auto_lang = (int)false;
685 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
687 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
688 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
689 key_old = xmlNodeGetContent(cur_old);
690 if (NULL != key_old) {
691 key_new = xmlNodeGetContent(cur_new);
692 if (NULL != key_new) {
693 if (0 != xmlStrcmp(key_old, key_new)) {
694 SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new);
695 if (NULL != *language) free(*language);
696 *language = strdup((char*)key_new);
703 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
705 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
706 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
707 key_old = xmlNodeGetContent(cur_old);
708 if (NULL != key_old) {
709 key_new = xmlNodeGetContent(cur_new);
710 if (NULL != key_new) {
711 if (0 != xmlStrcmp(key_old, key_new)) {
712 SECURE_SLOG(LOG_DEBUG, stt_tag(), "Old silence(%s), New silence(%s)", (char*)key_old, (char*)key_new);
713 if (0 == xmlStrcmp(key_new, (const xmlChar*)"on")) {
725 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
731 cur_new = cur_new->next;
732 cur_old = cur_old->next;
735 xmlFreeDoc(g_config_doc);
745 int stt_parser_set_time_info(GSList* time_list)
747 if (0 == g_slist_length(time_list)) {
748 SLOG(LOG_WARN, stt_tag(), "[WARNING] There is no time info to save");
752 if (-1 == remove(STT_TIME_INFO_PATH)) {
753 SECURE_SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH);
756 xmlDocPtr doc = NULL;
757 xmlNodePtr cur = NULL;
759 doc = xmlNewDoc((const xmlChar*)"1.0");
761 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make new doc");
765 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_BASE_TAG);
766 xmlDocSetRootElement(doc, cur);
768 xmlNodePtr inode = NULL;
770 stt_result_time_info_s *data = NULL;
773 snprintf(temp_str, 256, "%d", g_slist_length(time_list));
775 inode = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_INDEX);
776 xmlNewProp(inode, (const xmlChar*)STT_TAG_TIME_COUNT, (const xmlChar*)temp_str);
777 xmlAddChild(cur, inode);
779 /* Get a first item */
780 iter = g_slist_nth(time_list, 0);
781 while (NULL != iter) {
784 xmlNodePtr temp_node = NULL;
786 SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%d) e(%d)",
787 data->index, data->event, data->text, data->start_time, data->end_time);
789 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_TEXT);
790 xmlNodeSetContent(temp_node, (const xmlChar*)data->text);
791 xmlAddChild(inode, temp_node);
793 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_START);
794 snprintf(temp_str, 256, "%ld", data->start_time);
795 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
796 xmlAddChild(inode, temp_node);
798 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_END);
799 snprintf(temp_str, 256, "%ld", data->end_time);
800 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
801 xmlAddChild(inode, temp_node);
804 iter = g_slist_next(iter);
807 int ret = xmlSaveFormatFile(STT_TIME_INFO_PATH, doc, 1);
808 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
814 int stt_parser_get_time_info(GSList** time_list)
816 if (NULL == time_list) {
817 SLOG(LOG_ERROR, stt_tag(), "Invalid paramter : text is NULL");
821 xmlDocPtr doc = NULL;
822 xmlNodePtr cur = NULL;
824 doc = xmlParseFile(STT_TIME_INFO_PATH);
826 SLOG(LOG_WARN, stt_tag(), "[WARNING] File is not exist");
830 cur = xmlDocGetRootElement(doc);
832 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
837 if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_BASE_TAG)) {
838 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT '%s'", STT_TAG_TIME_BASE_TAG);
843 cur = cur->xmlChildrenNode;
845 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
850 /* alloc time info */
851 GSList *temp_time_list = NULL;
855 while (cur != NULL) {
856 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_INDEX)) {
857 key = xmlGetProp(cur, (const xmlChar*)STT_TAG_TIME_COUNT);
859 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_COUNT);
863 SLOG(LOG_DEBUG, stt_tag(), "Count : %s", (char *)key);
867 count = atoi((char*)key);
871 SLOG(LOG_ERROR, stt_tag(), "[ERROR] count is invalid : %d", count);
875 xmlNodePtr time_node = NULL;
876 time_node = cur->xmlChildrenNode;
879 for (i = 0;i < count;i++) {
881 time_node = time_node->next;
883 stt_result_time_info_s* temp_info;
884 temp_info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s));
886 if (NULL == temp_info) {
887 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!");
891 temp_info->index = index;
892 SLOG(LOG_DEBUG, stt_tag(), "index : %d", temp_info->index);
894 if (0 == i) temp_info->event = 0;
895 else if (count -1 == i) temp_info->event = 2;
896 else temp_info->event = 1;
898 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_TEXT)) {
899 key = xmlNodeGetContent(time_node);
901 SLOG(LOG_DEBUG, stt_tag(), "text : %s", (char *)key);
902 temp_info->text = strdup((char*)key);
905 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_TEXT);
912 time_node = time_node->next;
913 time_node = time_node->next;
915 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_START)) {
916 key = xmlNodeGetContent(time_node);
918 SLOG(LOG_DEBUG, stt_tag(), "Start time : %s", (char *)key);
919 temp_info->start_time = atoi((char*)key);
922 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_START);
923 if (NULL != temp_info->text) free(temp_info->text);
930 time_node = time_node->next;
931 time_node = time_node->next;
933 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_END)) {
934 key = xmlNodeGetContent(time_node);
936 SLOG(LOG_DEBUG, stt_tag(), "End time : %s", (char *)key);
937 temp_info->end_time = atoi((char*)key);
940 SECURE_SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_END);
941 if (NULL != temp_info->text) free(temp_info->text);
947 time_node = time_node->next;
949 temp_time_list = g_slist_append(temp_time_list, temp_info);
958 *time_list = temp_time_list;
963 int stt_parser_clear_time_info()
965 if (-1 == remove(STT_TIME_INFO_PATH)) {
966 SECURE_SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH);