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"
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) free(config_info->engine_id);
441 if (NULL != config_info->setting) free(config_info->setting);
442 if (NULL != config_info->language) free(config_info->language);
450 int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence, bool credential)
452 if (NULL == g_config_doc || NULL == engine_id)
455 xmlNodePtr cur = NULL;
456 cur = xmlDocGetRootElement(g_config_doc);
458 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
462 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
463 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
467 cur = cur->xmlChildrenNode;
469 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
473 while (cur != NULL) {
474 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
475 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
478 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
479 xmlNodeSetContent(cur, (const xmlChar *)language);
482 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
483 xmlNodeSetContent(cur, (const xmlChar *)setting);
486 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
488 xmlNodeSetContent(cur, (const xmlChar *)"on");
490 xmlNodeSetContent(cur, (const xmlChar *)"off");
493 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
494 if (true == credential)
495 xmlNodeSetContent(cur, (const xmlChar *)"true");
497 xmlNodeSetContent(cur, (const xmlChar *)"false");
503 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
504 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
509 int stt_parser_set_language(const char* language)
511 if (NULL == g_config_doc || NULL == language)
514 xmlNodePtr cur = NULL;
515 cur = xmlDocGetRootElement(g_config_doc);
517 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
521 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
522 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
526 cur = cur->xmlChildrenNode;
528 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
532 while (cur != NULL) {
533 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
534 xmlNodeSetContent(cur, (const xmlChar *)language);
540 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
541 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
547 int stt_parser_set_auto_lang(bool value)
549 if (NULL == g_config_doc)
552 xmlNodePtr cur = NULL;
553 cur = xmlDocGetRootElement(g_config_doc);
555 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
559 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
560 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
564 cur = cur->xmlChildrenNode;
566 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
570 while (cur != NULL) {
571 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
573 xmlNodeSetContent(cur, (const xmlChar *)"on");
574 } else if (false == value) {
575 xmlNodeSetContent(cur, (const xmlChar *)"off");
577 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong value of auto voice");
585 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
586 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
591 int stt_parser_set_silence_detection(bool value)
593 if (NULL == g_config_doc)
596 xmlNodePtr cur = NULL;
597 cur = xmlDocGetRootElement(g_config_doc);
599 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
603 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
604 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
608 cur = cur->xmlChildrenNode;
610 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
614 while (cur != NULL) {
615 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
617 xmlNodeSetContent(cur, (const xmlChar *)"on");
619 xmlNodeSetContent(cur, (const xmlChar *)"off");
625 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
626 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
631 int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence, int* credential)
633 if (NULL == engine || NULL == language || NULL == silence || NULL == credential) {
634 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
638 xmlDocPtr doc = NULL;
639 xmlNodePtr cur_new = NULL;
640 xmlNodePtr cur_old = NULL;
645 doc = xmlParseFile(STT_CONFIG);
647 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG);
651 cur_new = xmlDocGetRootElement(doc);
652 cur_old = xmlDocGetRootElement(g_config_doc);
653 if (cur_new == NULL || cur_old == NULL) {
654 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
659 if (xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG)) {
660 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
665 cur_new = cur_new->xmlChildrenNode;
666 cur_old = cur_old->xmlChildrenNode;
667 if (cur_new == NULL || cur_old == NULL) {
668 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
677 while (cur_new != NULL && cur_old != NULL) {
678 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
679 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
680 key_old = xmlNodeGetContent(cur_old);
681 if (NULL != key_old) {
682 key_new = xmlNodeGetContent(cur_new);
683 if (NULL != key_new) {
684 if (0 != xmlStrcmp(key_old, key_new)) {
685 SLOG(LOG_DEBUG, stt_tag(), "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new);
686 if (NULL != *engine) free(*engine);
687 *engine = strdup((char*)key_new);
694 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
696 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
697 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
698 key_old = xmlNodeGetContent(cur_old);
699 if (NULL != key_old) {
700 key_new = xmlNodeGetContent(cur_new);
701 if (NULL != key_new) {
702 if (0 != xmlStrcmp(key_old, key_new)) {
703 SLOG(LOG_DEBUG, stt_tag(), "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new);
704 if (NULL != *setting) free(*setting);
705 *setting = strdup((char*)key_new);
712 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
714 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
715 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
716 key_old = xmlNodeGetContent(cur_old);
717 if (NULL != key_old) {
718 key_new = xmlNodeGetContent(cur_new);
719 if (NULL != key_new) {
720 if (0 != xmlStrcmp(key_old, key_new)) {
721 SLOG(LOG_DEBUG, stt_tag(), "Old auto lang(%s), New auto lang(%s)", (char*)key_old, (char*)key_new);
722 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
723 *auto_lang = (int)true;
725 *auto_lang = (int)false;
734 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
736 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
737 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
738 key_old = xmlNodeGetContent(cur_old);
739 if (NULL != key_old) {
740 key_new = xmlNodeGetContent(cur_new);
741 if (NULL != key_new) {
742 if (0 != xmlStrcmp(key_old, key_new)) {
743 SLOG(LOG_DEBUG, stt_tag(), "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new);
744 if (NULL != *language) free(*language);
745 *language = strdup((char*)key_new);
752 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
754 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
755 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
756 key_old = xmlNodeGetContent(cur_old);
757 if (NULL != key_old) {
758 key_new = xmlNodeGetContent(cur_new);
759 if (NULL != key_new) {
760 if (0 != xmlStrcmp(key_old, key_new)) {
761 SLOG(LOG_DEBUG, stt_tag(), "Old silence(%s), New silence(%s)", (char*)key_old, (char*)key_new);
762 if (0 == xmlStrcmp(key_new, (const xmlChar*)"on")) {
774 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
776 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
777 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
778 key_old = xmlNodeGetContent(cur_old);
779 if (NULL != key_old) {
780 key_new = xmlNodeGetContent(cur_new);
781 if (NULL != key_new) {
782 if (0 != xmlStrcmp(key_old, key_new)) {
783 SLOG(LOG_DEBUG, stt_tag(), "Old credential(%s), New credential(%s)", (char*)key_old, (char*)key_new);
784 if (0 == xmlStrcmp(key_new, (const xmlChar*)"true")) {
795 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
802 cur_new = cur_new->next;
803 cur_old = cur_old->next;
806 xmlFreeDoc(g_config_doc);
816 int stt_parser_set_time_info(GSList* time_list)
818 if (0 == g_slist_length(time_list)) {
819 SLOG(LOG_WARN, stt_tag(), "[WARNING] There is no time info to save");
823 if (-1 == remove(STT_TIME_INFO_PATH)) {
824 SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH);
827 xmlDocPtr doc = NULL;
828 xmlNodePtr cur = NULL;
830 doc = xmlNewDoc((const xmlChar*)"1.0");
832 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make new doc");
836 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_BASE_TAG);
837 xmlDocSetRootElement(doc, cur);
839 xmlNodePtr inode = NULL;
841 stt_result_time_info_s *data = NULL;
844 snprintf(temp_str, 256, "%d", g_slist_length(time_list));
846 inode = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_INDEX);
847 xmlNewProp(inode, (const xmlChar*)STT_TAG_TIME_COUNT, (const xmlChar*)temp_str);
848 xmlAddChild(cur, inode);
850 /* Get a first item */
851 iter = g_slist_nth(time_list, 0);
852 while (NULL != iter) {
856 SLOG(LOG_DEBUG, stt_tag(), "data is NULL");
860 xmlNodePtr temp_node = NULL;
862 SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%d) e(%d)",
863 data->index, data->event, data->text, data->start_time, data->end_time);
865 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_TEXT);
866 xmlNodeSetContent(temp_node, (const xmlChar*)data->text);
867 xmlAddChild(inode, temp_node);
869 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_START);
870 snprintf(temp_str, 256, "%ld", data->start_time);
871 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
872 xmlAddChild(inode, temp_node);
874 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_END);
875 snprintf(temp_str, 256, "%ld", data->end_time);
876 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
877 xmlAddChild(inode, temp_node);
880 iter = g_slist_next(iter);
883 int ret = xmlSaveFormatFile(STT_TIME_INFO_PATH, doc, 1);
884 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
890 int stt_parser_get_time_info(GSList** time_list)
892 if (NULL == time_list) {
893 SLOG(LOG_ERROR, stt_tag(), "Invalid paramter : text is NULL");
897 xmlDocPtr doc = NULL;
898 xmlNodePtr cur = NULL;
900 doc = xmlParseFile(STT_TIME_INFO_PATH);
902 SLOG(LOG_WARN, stt_tag(), "[WARNING] File is not exist");
906 cur = xmlDocGetRootElement(doc);
908 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
913 if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_BASE_TAG)) {
914 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT '%s'", STT_TAG_TIME_BASE_TAG);
919 cur = cur->xmlChildrenNode;
921 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
926 /* alloc time info */
927 GSList *temp_time_list = NULL;
931 while (cur != NULL) {
932 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_INDEX)) {
933 key = xmlGetProp(cur, (const xmlChar*)STT_TAG_TIME_COUNT);
935 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_COUNT);
939 SLOG(LOG_DEBUG, stt_tag(), "Count : %s", (char *)key);
943 count = atoi((char*)key);
947 SLOG(LOG_ERROR, stt_tag(), "[ERROR] count is invalid : %d", count);
951 xmlNodePtr time_node = NULL;
952 time_node = cur->xmlChildrenNode;
955 for (i = 0; i < count; i++) {
957 time_node = time_node->next;
959 stt_result_time_info_s* temp_info;
960 temp_info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s));
962 if (NULL == temp_info) {
963 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!");
967 temp_info->index = index;
968 SLOG(LOG_DEBUG, stt_tag(), "index : %d", temp_info->index);
970 if (0 == i) temp_info->event = 0;
971 else if (count -1 == i) temp_info->event = 2;
972 else temp_info->event = 1;
974 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_TEXT)) {
975 key = xmlNodeGetContent(time_node);
977 SLOG(LOG_DEBUG, stt_tag(), "text : %s", (char *)key);
978 temp_info->text = strdup((char*)key);
981 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_TEXT);
988 time_node = time_node->next;
989 time_node = time_node->next;
991 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_START)) {
992 key = xmlNodeGetContent(time_node);
994 SLOG(LOG_DEBUG, stt_tag(), "Start time : %s", (char *)key);
995 temp_info->start_time = atoi((char*)key);
998 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_START);
999 if (NULL != temp_info->text) free(temp_info->text);
1006 time_node = time_node->next;
1007 time_node = time_node->next;
1009 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_END)) {
1010 key = xmlNodeGetContent(time_node);
1012 SLOG(LOG_DEBUG, stt_tag(), "End time : %s", (char *)key);
1013 temp_info->end_time = atoi((char*)key);
1016 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_END);
1017 if (NULL != temp_info->text) free(temp_info->text);
1023 time_node = time_node->next;
1025 temp_time_list = g_slist_append(temp_time_list, temp_info);
1034 *time_list = temp_time_list;
1039 int stt_parser_clear_time_info()
1041 if (-1 == remove(STT_TIME_INFO_PATH)) {
1042 /* SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); */