2 * Copyright (c) 2011-2016 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"
29 #define STT_TAG_ENGINE_CREDENTIAL_NEED "app-credential-need"
31 #define STT_TAG_CONFIG_BASE_TAG "stt-config"
32 #define STT_TAG_CONFIG_ENGINE_ID "engine"
33 #define STT_TAG_CONFIG_ENGINE_SETTING "engine-setting"
34 #define STT_TAG_CONFIG_AUTO_LANGUAGE "auto"
35 #define STT_TAG_CONFIG_LANGUAGE "language"
36 #define STT_TAG_CONFIG_SILENCE_DETECTION "silence-detection"
37 #define STT_TAG_CONFIG_CREDENTIAL "credential"
40 #define STT_TAG_TIME_BASE_TAG "stt-time"
41 #define STT_TAG_TIME_INDEX "index"
42 #define STT_TAG_TIME_COUNT "count"
43 #define STT_TAG_TIME_TIME_INFO "time-info"
44 #define STT_TAG_TIME_TEXT "text-info"
45 #define STT_TAG_TIME_START "start"
46 #define STT_TAG_TIME_END "end"
48 extern const char* stt_tag();
50 static xmlDocPtr g_config_doc = NULL;
52 int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info)
54 if (NULL == path || NULL == engine_info) {
55 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
60 xmlNodePtr cur = NULL;
63 doc = xmlParseFile(path);
68 cur = xmlDocGetRootElement(doc);
70 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
75 if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_BASE_TAG)) {
76 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT 'stt-engine'");
81 cur = cur->xmlChildrenNode;
83 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
88 /* alloc engine info */
89 stt_engine_info_s* temp;
90 temp = (stt_engine_info_s*)calloc(1, sizeof(stt_engine_info_s));
93 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
100 temp->agreement = NULL;
101 temp->languages = NULL;
102 temp->support_silence_detection = false;
103 temp->need_credential = false;
105 while (cur != NULL) {
106 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) {
107 key = xmlNodeGetContent(cur);
109 /* SLOG(LOG_DEBUG, stt_tag(), "Engine name : %s", (char *)key); */
110 if (NULL != temp->name) free(temp->name);
111 temp->name = strdup((char*)key);
114 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_NAME);
116 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_ID)) {
117 key = xmlNodeGetContent(cur);
119 /* SLOG(LOG_DEBUG, stt_tag(), "Engine uuid : %s", (char *)key); */
120 if (NULL != temp->uuid) free(temp->uuid);
121 temp->uuid = strdup((char*)key);
124 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_ID);
126 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SETTING)) {
127 key = xmlNodeGetContent(cur);
129 SLOG(LOG_DEBUG, stt_tag(), "Engine setting : %s", (char *)key);
130 if (NULL != temp->setting) free(temp->setting);
131 temp->setting = strdup((char*)key);
134 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SETTING);
136 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_AGREEMENT)) {
137 key = xmlNodeGetContent(cur);
139 SLOG(LOG_DEBUG, stt_tag(), "Engine agreement : %s", (char *)key);
140 if (NULL != temp->agreement) free(temp->agreement);
141 temp->agreement = strdup((char*)key);
144 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT);
146 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE_SET)) {
147 xmlNodePtr lang_node = NULL;
148 char* temp_lang = NULL;
150 lang_node = cur->xmlChildrenNode;
152 while (lang_node != NULL) {
153 if (0 == xmlStrcmp(lang_node->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE)) {
154 key = xmlNodeGetContent(lang_node);
156 /* SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */
157 temp_lang = strdup((char*)key);
158 temp->languages = g_slist_append(temp->languages, temp_lang);
161 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_LANGUAGE);
165 lang_node = lang_node->next;
167 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SILENCE_SUPPORT)) {
168 key = xmlNodeGetContent(cur);
170 /*SLOG(LOG_DEBUG, stt_tag(), "silence-detection-support : %s", (char *)key); */
172 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
173 temp->support_silence_detection = true;
175 temp->support_silence_detection = false;
179 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT);
181 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_CREDENTIAL_NEED)) {
182 key = xmlNodeGetContent(cur);
184 //SLOG(LOG_DEBUG, stt_tag(), "app-credential-need : %s", (char *)key);
186 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
187 temp->need_credential = true;
189 temp->need_credential = false;
193 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_CREDENTIAL_NEED);
204 if (NULL == temp->name || NULL == temp->uuid) {
206 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Invalid engine : %s", path);
207 stt_parser_free_engine_info(temp);
216 int stt_parser_free_engine_info(stt_engine_info_s* engine_info)
218 if (NULL == engine_info) {
219 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
223 if (NULL != engine_info->name) free(engine_info->name);
224 if (NULL != engine_info->uuid) free(engine_info->uuid);
225 if (NULL != engine_info->setting) free(engine_info->setting);
226 if (NULL != engine_info->agreement) free(engine_info->agreement);
228 int count = g_slist_length(engine_info->languages);
233 for (i = 0; i < count ; i++) {
234 temp_lang = g_slist_nth_data(engine_info->languages, 0);
236 if (NULL != temp_lang) {
237 engine_info->languages = g_slist_remove(engine_info->languages, temp_lang);
239 if (NULL != temp_lang)
244 if (NULL != engine_info) free(engine_info);
249 int stt_parser_print_engine_info(stt_engine_info_s* engine_info)
251 if (NULL == engine_info)
254 SLOG(LOG_DEBUG, stt_tag(), "== get engine info ==");
255 SLOG(LOG_DEBUG, stt_tag(), " name : %s", engine_info->name);
256 SLOG(LOG_DEBUG, stt_tag(), " id : %s", engine_info->uuid);
257 if (NULL != engine_info->setting) SLOG(LOG_DEBUG, stt_tag(), " setting : %s", engine_info->setting);
259 SLOG(LOG_DEBUG, stt_tag(), " languages");
262 if (g_slist_length(engine_info->languages) > 0) {
263 /* Get a first item */
264 iter = g_slist_nth(engine_info->languages, 0);
267 while (NULL != iter) {
268 /*Get handle data from list*/
271 SLOG(LOG_DEBUG, stt_tag(), " [%dth] %s", i, lang);
274 iter = g_slist_next(iter);
278 SLOG(LOG_ERROR, stt_tag(), " language is NONE");
280 SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", engine_info->support_silence_detection ? "true" : "false");
281 SLOG(LOG_DEBUG, stt_tag(), " credential need : %s", engine_info->need_credential ? "true" : "false");
282 SLOG(LOG_DEBUG, stt_tag(), "=====================");
287 int stt_parser_load_config(stt_config_s** config_info)
289 if (NULL == config_info) {
290 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
294 xmlDocPtr doc = NULL;
295 xmlNodePtr cur = NULL;
297 bool is_default_open = false;
299 doc = xmlParseFile(STT_CONFIG);
301 doc = xmlParseFile(STT_DEFAULT_CONFIG);
303 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG);
306 is_default_open = true;
309 cur = xmlDocGetRootElement(doc);
311 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
316 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
317 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
322 cur = cur->xmlChildrenNode;
324 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
329 /* alloc engine info */
331 temp = (stt_config_s*)calloc(1, sizeof(stt_config_s));
334 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
338 temp->engine_id = NULL;
339 temp->setting = NULL;
340 temp->language = NULL;
342 while (cur != NULL) {
343 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
344 key = xmlNodeGetContent(cur);
346 /*SLOG(LOG_DEBUG, stt_tag(), "Engine id : %s", (char *)key); */
347 if (NULL != temp->engine_id) free(temp->engine_id);
348 temp->engine_id = strdup((char*)key);
351 SLOG(LOG_ERROR, stt_tag(), "[ERROR] engine id is NULL");
353 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
354 key = xmlNodeGetContent(cur);
356 /*SLOG(LOG_DEBUG, stt_tag(), "Setting path : %s", (char *)key); */
357 if (NULL != temp->setting) free(temp->setting);
358 temp->setting = strdup((char*)key);
361 SLOG(LOG_ERROR, stt_tag(), "[ERROR] setting path is NULL");
364 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
365 key = xmlNodeGetContent(cur);
367 /*SLOG(LOG_DEBUG, stt_tag(), "Auto language : %s", (char *)key); */
369 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
370 temp->auto_lang = true;
371 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
372 temp->auto_lang = false;
374 SLOG(LOG_ERROR, stt_tag(), "Auto voice is wrong");
375 temp->auto_lang = true;
380 SLOG(LOG_ERROR, stt_tag(), "[ERROR] auto langauge is NULL");
382 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
383 key = xmlNodeGetContent(cur);
385 /*SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */
386 if (NULL != temp->language) free(temp->language);
387 temp->language = strdup((char*)key);
390 SLOG(LOG_ERROR, stt_tag(), "[ERROR] language is NULL");
392 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
393 key = xmlNodeGetContent(cur);
395 /*SLOG(LOG_DEBUG, stt_tag(), "silence-detection : %s", (char *)key); */
397 if (0 == xmlStrcmp(key, (const xmlChar *)"on"))
398 temp->silence_detection = true;
400 temp->silence_detection = false;
404 SLOG(LOG_ERROR, stt_tag(), "[ERROR] silence-detection is NULL");
406 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
407 key = xmlNodeGetContent(cur);
409 //SLOG(LOG_DEBUG, stt_tag(), "credential : %s", (char *)key);
411 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
412 temp->credential = true;
414 temp->credential = false;
418 SLOG(LOG_ERROR, stt_tag(), "[ERROR] credential is NULL");
431 xmlSaveFile(STT_CONFIG, g_config_doc);
436 int stt_parser_unload_config(stt_config_s* config_info)
438 if (NULL != g_config_doc) xmlFreeDoc(g_config_doc);
439 if (NULL != config_info) {
440 if (NULL != config_info->engine_id) {
441 free(config_info->engine_id);
442 config_info->engine_id = NULL;
444 if (NULL != config_info->setting) {
445 free(config_info->setting);
446 config_info->setting = NULL;
448 if (NULL != config_info->language) {
449 free(config_info->language);
450 config_info->language = NULL;
459 int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence, bool credential)
461 if (NULL == g_config_doc || NULL == engine_id)
464 xmlNodePtr cur = NULL;
465 cur = xmlDocGetRootElement(g_config_doc);
467 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
471 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
472 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
476 cur = cur->xmlChildrenNode;
478 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
482 while (cur != NULL) {
483 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
484 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
487 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
488 xmlNodeSetContent(cur, (const xmlChar *)language);
491 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
492 xmlNodeSetContent(cur, (const xmlChar *)setting);
495 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
497 xmlNodeSetContent(cur, (const xmlChar *)"on");
499 xmlNodeSetContent(cur, (const xmlChar *)"off");
502 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
503 if (true == credential)
504 xmlNodeSetContent(cur, (const xmlChar *)"true");
506 xmlNodeSetContent(cur, (const xmlChar *)"false");
512 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
513 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
518 int stt_parser_set_language(const char* language)
520 if (NULL == g_config_doc || NULL == language)
523 xmlNodePtr cur = NULL;
524 cur = xmlDocGetRootElement(g_config_doc);
526 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
530 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
531 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
535 cur = cur->xmlChildrenNode;
537 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
541 while (cur != NULL) {
542 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
543 xmlNodeSetContent(cur, (const xmlChar *)language);
549 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
550 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
556 int stt_parser_set_auto_lang(bool value)
558 if (NULL == g_config_doc)
561 xmlNodePtr cur = NULL;
562 cur = xmlDocGetRootElement(g_config_doc);
564 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
568 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
569 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
573 cur = cur->xmlChildrenNode;
575 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
579 while (cur != NULL) {
580 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
582 xmlNodeSetContent(cur, (const xmlChar *)"on");
583 } else if (false == value) {
584 xmlNodeSetContent(cur, (const xmlChar *)"off");
586 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong value of auto voice");
594 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
595 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
600 int stt_parser_set_silence_detection(bool value)
602 if (NULL == g_config_doc)
605 xmlNodePtr cur = NULL;
606 cur = xmlDocGetRootElement(g_config_doc);
608 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
612 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
613 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
617 cur = cur->xmlChildrenNode;
619 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
623 while (cur != NULL) {
624 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
626 xmlNodeSetContent(cur, (const xmlChar *)"on");
628 xmlNodeSetContent(cur, (const xmlChar *)"off");
634 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
635 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
640 int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence, int* credential)
642 if (NULL == engine || NULL == language || NULL == silence || NULL == credential) {
643 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
647 xmlDocPtr doc = NULL;
648 xmlNodePtr cur_new = NULL;
649 xmlNodePtr cur_old = NULL;
654 doc = xmlParseFile(STT_CONFIG);
656 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG);
660 cur_new = xmlDocGetRootElement(doc);
661 cur_old = xmlDocGetRootElement(g_config_doc);
662 if (cur_new == NULL || cur_old == NULL) {
663 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
668 if (xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG)) {
669 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
674 cur_new = cur_new->xmlChildrenNode;
675 cur_old = cur_old->xmlChildrenNode;
676 if (cur_new == NULL || cur_old == NULL) {
677 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
686 while (cur_new != NULL && cur_old != NULL) {
687 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
688 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
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 SLOG(LOG_DEBUG, stt_tag(), "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new);
695 if (NULL != *engine) free(*engine);
696 *engine = 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_ENGINE_SETTING)) {
706 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
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 SLOG(LOG_DEBUG, stt_tag(), "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new);
713 if (NULL != *setting) free(*setting);
714 *setting = strdup((char*)key_new);
721 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
723 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
724 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
725 key_old = xmlNodeGetContent(cur_old);
726 if (NULL != key_old) {
727 key_new = xmlNodeGetContent(cur_new);
728 if (NULL != key_new) {
729 if (0 != xmlStrcmp(key_old, key_new)) {
730 SLOG(LOG_DEBUG, stt_tag(), "Old auto lang(%s), New auto lang(%s)", (char*)key_old, (char*)key_new);
731 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
732 *auto_lang = (int)true;
734 *auto_lang = (int)false;
743 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
745 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
746 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
747 key_old = xmlNodeGetContent(cur_old);
748 if (NULL != key_old) {
749 key_new = xmlNodeGetContent(cur_new);
750 if (NULL != key_new) {
751 if (0 != xmlStrcmp(key_old, key_new)) {
752 SLOG(LOG_DEBUG, stt_tag(), "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new);
753 if (NULL != *language) free(*language);
754 *language = strdup((char*)key_new);
761 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
763 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
764 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
765 key_old = xmlNodeGetContent(cur_old);
766 if (NULL != key_old) {
767 key_new = xmlNodeGetContent(cur_new);
768 if (NULL != key_new) {
769 if (0 != xmlStrcmp(key_old, key_new)) {
770 SLOG(LOG_DEBUG, stt_tag(), "Old silence(%s), New silence(%s)", (char*)key_old, (char*)key_new);
771 if (0 == xmlStrcmp(key_new, (const xmlChar*)"on")) {
783 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
785 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
786 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
787 key_old = xmlNodeGetContent(cur_old);
788 if (NULL != key_old) {
789 key_new = xmlNodeGetContent(cur_new);
790 if (NULL != key_new) {
791 if (0 != xmlStrcmp(key_old, key_new)) {
792 SLOG(LOG_DEBUG, stt_tag(), "Old credential(%s), New credential(%s)", (char*)key_old, (char*)key_new);
793 if (0 == xmlStrcmp(key_new, (const xmlChar*)"true")) {
804 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
811 cur_new = cur_new->next;
812 cur_old = cur_old->next;
815 xmlFreeDoc(g_config_doc);
825 int stt_parser_set_time_info(GSList* time_list)
827 if (0 == g_slist_length(time_list)) {
828 SLOG(LOG_WARN, stt_tag(), "[WARNING] There is no time info to save");
832 if (-1 == remove(STT_TIME_INFO_PATH)) {
833 SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH);
836 xmlDocPtr doc = NULL;
837 xmlNodePtr cur = NULL;
839 doc = xmlNewDoc((const xmlChar*)"1.0");
841 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make new doc");
845 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_BASE_TAG);
846 xmlDocSetRootElement(doc, cur);
848 xmlNodePtr inode = NULL;
850 stt_result_time_info_s *data = NULL;
853 snprintf(temp_str, 256, "%d", g_slist_length(time_list));
855 inode = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_INDEX);
856 xmlNewProp(inode, (const xmlChar*)STT_TAG_TIME_COUNT, (const xmlChar*)temp_str);
857 xmlAddChild(cur, inode);
859 /* Get a first item */
860 iter = g_slist_nth(time_list, 0);
861 while (NULL != iter) {
865 SLOG(LOG_DEBUG, stt_tag(), "data is NULL");
869 xmlNodePtr temp_node = NULL;
871 SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%d) e(%d)",
872 data->index, data->event, data->text, data->start_time, data->end_time);
874 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_TEXT);
875 xmlNodeSetContent(temp_node, (const xmlChar*)data->text);
876 xmlAddChild(inode, temp_node);
878 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_START);
879 snprintf(temp_str, 256, "%ld", data->start_time);
880 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
881 xmlAddChild(inode, temp_node);
883 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_END);
884 snprintf(temp_str, 256, "%ld", data->end_time);
885 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
886 xmlAddChild(inode, temp_node);
889 iter = g_slist_next(iter);
892 int ret = xmlSaveFormatFile(STT_TIME_INFO_PATH, doc, 1);
893 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
899 int stt_parser_get_time_info(GSList** time_list)
901 if (NULL == time_list) {
902 SLOG(LOG_ERROR, stt_tag(), "Invalid paramter : text is NULL");
906 xmlDocPtr doc = NULL;
907 xmlNodePtr cur = NULL;
909 doc = xmlParseFile(STT_TIME_INFO_PATH);
911 SLOG(LOG_WARN, stt_tag(), "[WARNING] File is not exist");
915 cur = xmlDocGetRootElement(doc);
917 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
922 if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_BASE_TAG)) {
923 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT '%s'", STT_TAG_TIME_BASE_TAG);
928 cur = cur->xmlChildrenNode;
930 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
935 /* alloc time info */
936 GSList *temp_time_list = NULL;
940 while (cur != NULL) {
941 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_INDEX)) {
942 key = xmlGetProp(cur, (const xmlChar*)STT_TAG_TIME_COUNT);
944 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_COUNT);
948 SLOG(LOG_DEBUG, stt_tag(), "Count : %s", (char *)key);
952 count = atoi((char*)key);
956 SLOG(LOG_ERROR, stt_tag(), "[ERROR] count is invalid : %d", count);
960 xmlNodePtr time_node = NULL;
961 time_node = cur->xmlChildrenNode;
964 for (i = 0; i < count; i++) {
966 time_node = time_node->next;
968 stt_result_time_info_s* temp_info;
969 temp_info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s));
971 if (NULL == temp_info) {
972 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!");
976 temp_info->index = index;
977 SLOG(LOG_DEBUG, stt_tag(), "index : %d", temp_info->index);
979 if (0 == i) temp_info->event = 0;
980 else if (count -1 == i) temp_info->event = 2;
981 else temp_info->event = 1;
983 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_TEXT)) {
984 key = xmlNodeGetContent(time_node);
986 SLOG(LOG_DEBUG, stt_tag(), "text : %s", (char *)key);
987 temp_info->text = strdup((char*)key);
990 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_TEXT);
997 time_node = time_node->next;
998 time_node = time_node->next;
1000 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_START)) {
1001 key = xmlNodeGetContent(time_node);
1003 SLOG(LOG_DEBUG, stt_tag(), "Start time : %s", (char *)key);
1004 temp_info->start_time = atoi((char*)key);
1007 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_START);
1008 if (NULL != temp_info->text) free(temp_info->text);
1015 time_node = time_node->next;
1016 time_node = time_node->next;
1018 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_END)) {
1019 key = xmlNodeGetContent(time_node);
1021 SLOG(LOG_DEBUG, stt_tag(), "End time : %s", (char *)key);
1022 temp_info->end_time = atoi((char*)key);
1025 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_END);
1026 if (NULL != temp_info->text) free(temp_info->text);
1032 time_node = time_node->next;
1034 temp_time_list = g_slist_append(temp_time_list, temp_info);
1043 *time_list = temp_time_list;
1048 int stt_parser_clear_time_info()
1050 if (-1 == remove(STT_TIME_INFO_PATH)) {
1051 /* SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); */