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_DEFAULT "default"
27 #define STT_TAG_ENGINE_LANGUAGE_SET "languages"
28 #define STT_TAG_ENGINE_LANGUAGE "lang"
29 #define STT_TAG_ENGINE_SILENCE_SUPPORT "silence-detection-support"
30 #define STT_TAG_ENGINE_CREDENTIAL_NEED "app-credential-need"
32 #define STT_TAG_CONFIG_BASE_TAG "stt-config"
33 #define STT_TAG_CONFIG_ENGINE_ID "engine"
34 #define STT_TAG_CONFIG_ENGINE_SETTING "engine-setting"
35 #define STT_TAG_CONFIG_AUTO_LANGUAGE "auto"
36 #define STT_TAG_CONFIG_LANGUAGE "language"
37 #define STT_TAG_CONFIG_SILENCE_DETECTION "silence-detection"
38 #define STT_TAG_CONFIG_CREDENTIAL "credential"
41 #define STT_TAG_TIME_BASE_TAG "stt-time"
42 #define STT_TAG_TIME_INDEX "index"
43 #define STT_TAG_TIME_COUNT "count"
44 #define STT_TAG_TIME_TIME_INFO "time-info"
45 #define STT_TAG_TIME_TEXT "text-info"
46 #define STT_TAG_TIME_START "start"
47 #define STT_TAG_TIME_END "end"
49 extern const char* stt_tag();
51 static xmlDocPtr g_config_doc = NULL;
53 int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info)
55 if (NULL == path || NULL == engine_info) {
56 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
61 xmlNodePtr cur = NULL;
64 doc = xmlParseFile(path);
69 cur = xmlDocGetRootElement(doc);
71 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
76 if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_BASE_TAG)) {
77 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT 'stt-engine'");
82 cur = cur->xmlChildrenNode;
84 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
89 /* alloc engine info */
90 stt_engine_info_s* temp;
91 temp = (stt_engine_info_s*)calloc(1, sizeof(stt_engine_info_s));
94 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
100 temp->setting = NULL;
101 temp->agreement = NULL;
102 temp->default_lang = NULL;
103 temp->languages = NULL;
104 temp->support_silence_detection = false;
105 temp->need_credential = false;
107 bool is_default_lang_set = false;
109 while (cur != NULL) {
110 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) {
111 key = xmlNodeGetContent(cur);
113 /* SLOG(LOG_DEBUG, stt_tag(), "Engine name : %s", (char *)key); */
114 if (NULL != temp->name) free(temp->name);
115 temp->name = strdup((char*)key);
118 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_NAME);
120 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_ID)) {
121 key = xmlNodeGetContent(cur);
123 /* SLOG(LOG_DEBUG, stt_tag(), "Engine uuid : %s", (char *)key); */
124 if (NULL != temp->uuid) free(temp->uuid);
125 temp->uuid = strdup((char*)key);
128 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_ID);
130 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SETTING)) {
131 key = xmlNodeGetContent(cur);
133 SLOG(LOG_DEBUG, stt_tag(), "Engine setting : %s", (char *)key);
134 if (NULL != temp->setting) free(temp->setting);
135 temp->setting = strdup((char*)key);
138 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SETTING);
140 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_AGREEMENT)) {
141 key = xmlNodeGetContent(cur);
143 SLOG(LOG_DEBUG, stt_tag(), "Engine agreement : %s", (char *)key);
144 if (NULL != temp->agreement) free(temp->agreement);
145 temp->agreement = strdup((char*)key);
148 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT);
150 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_DEFAULT)) {
151 key = xmlNodeGetContent(cur);
153 SLOG(LOG_DEBUG, stt_tag(), "Engine agreement : %s", (char *)key);
154 if (NULL != temp->default_lang) free(temp->default_lang);
155 temp->default_lang = strdup((char*)key);
157 is_default_lang_set = true;
160 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_DEFAULT);
162 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE_SET)) {
163 xmlNodePtr lang_node = NULL;
164 char* temp_lang = NULL;
166 lang_node = cur->xmlChildrenNode;
168 while (lang_node != NULL) {
169 if (0 == xmlStrcmp(lang_node->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE)) {
170 key = xmlNodeGetContent(lang_node);
172 /* SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */
173 temp_lang = strdup((char*)key);
174 temp->languages = g_slist_append(temp->languages, temp_lang);
176 if (false == is_default_lang_set) {
177 if (NULL != temp->default_lang) free(temp->default_lang);
178 temp->default_lang = strdup((char*)key);
180 is_default_lang_set = true;
184 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_LANGUAGE);
188 lang_node = lang_node->next;
190 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_SILENCE_SUPPORT)) {
191 key = xmlNodeGetContent(cur);
193 /*SLOG(LOG_DEBUG, stt_tag(), "silence-detection-support : %s", (char *)key); */
195 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
196 temp->support_silence_detection = true;
198 temp->support_silence_detection = false;
202 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT);
204 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_CREDENTIAL_NEED)) {
205 key = xmlNodeGetContent(cur);
207 //SLOG(LOG_DEBUG, stt_tag(), "app-credential-need : %s", (char *)key);
209 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
210 temp->need_credential = true;
212 temp->need_credential = false;
216 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_CREDENTIAL_NEED);
227 if (NULL == temp->name || NULL == temp->uuid) {
229 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Invalid engine : %s", path);
230 stt_parser_free_engine_info(temp);
239 int stt_parser_free_engine_info(stt_engine_info_s* engine_info)
241 if (NULL == engine_info) {
242 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
246 if (NULL != engine_info->name) free(engine_info->name);
247 if (NULL != engine_info->uuid) free(engine_info->uuid);
248 if (NULL != engine_info->setting) free(engine_info->setting);
249 if (NULL != engine_info->agreement) free(engine_info->agreement);
251 int count = g_slist_length(engine_info->languages);
256 for (i = 0; i < count ; i++) {
257 temp_lang = g_slist_nth_data(engine_info->languages, 0);
259 if (NULL != temp_lang) {
260 engine_info->languages = g_slist_remove(engine_info->languages, temp_lang);
262 if (NULL != temp_lang)
267 if (NULL != engine_info) free(engine_info);
272 int stt_parser_print_engine_info(stt_engine_info_s* engine_info)
274 if (NULL == engine_info)
277 SLOG(LOG_DEBUG, stt_tag(), "== get engine info ==");
278 SLOG(LOG_DEBUG, stt_tag(), " name : %s", engine_info->name);
279 SLOG(LOG_DEBUG, stt_tag(), " id : %s", engine_info->uuid);
280 if (NULL != engine_info->setting) SLOG(LOG_DEBUG, stt_tag(), " setting : %s", engine_info->setting);
282 SLOG(LOG_DEBUG, stt_tag(), " languages");
285 if (g_slist_length(engine_info->languages) > 0) {
286 /* Get a first item */
287 iter = g_slist_nth(engine_info->languages, 0);
290 while (NULL != iter) {
291 /*Get handle data from list*/
294 SLOG(LOG_DEBUG, stt_tag(), " [%dth] %s", i, lang);
297 iter = g_slist_next(iter);
301 SLOG(LOG_ERROR, stt_tag(), " language is NONE");
303 SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", engine_info->support_silence_detection ? "true" : "false");
304 SLOG(LOG_DEBUG, stt_tag(), " credential need : %s", engine_info->need_credential ? "true" : "false");
305 SLOG(LOG_DEBUG, stt_tag(), "=====================");
310 int stt_parser_load_config(stt_config_s** config_info)
312 if (NULL == config_info) {
313 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
317 xmlDocPtr doc = NULL;
318 xmlNodePtr cur = NULL;
320 bool is_default_open = false;
322 doc = xmlParseFile(STT_CONFIG);
324 doc = xmlParseFile(STT_DEFAULT_CONFIG);
326 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG);
329 is_default_open = true;
332 cur = xmlDocGetRootElement(doc);
334 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
339 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
340 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
345 cur = cur->xmlChildrenNode;
347 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
352 /* alloc engine info */
354 temp = (stt_config_s*)calloc(1, sizeof(stt_config_s));
357 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
361 temp->engine_id = NULL;
362 temp->setting = NULL;
363 temp->language = NULL;
365 while (cur != NULL) {
366 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
367 key = xmlNodeGetContent(cur);
369 /*SLOG(LOG_DEBUG, stt_tag(), "Engine id : %s", (char *)key); */
370 if (NULL != temp->engine_id) free(temp->engine_id);
371 temp->engine_id = strdup((char*)key);
374 SLOG(LOG_ERROR, stt_tag(), "[ERROR] engine id is NULL");
376 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
377 key = xmlNodeGetContent(cur);
379 /*SLOG(LOG_DEBUG, stt_tag(), "Setting path : %s", (char *)key); */
380 if (NULL != temp->setting) free(temp->setting);
381 temp->setting = strdup((char*)key);
384 SLOG(LOG_ERROR, stt_tag(), "[ERROR] setting path is NULL");
387 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
388 key = xmlNodeGetContent(cur);
390 /*SLOG(LOG_DEBUG, stt_tag(), "Auto language : %s", (char *)key); */
392 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
393 temp->auto_lang = true;
394 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
395 temp->auto_lang = false;
397 SLOG(LOG_ERROR, stt_tag(), "Auto voice is wrong");
398 temp->auto_lang = true;
403 SLOG(LOG_ERROR, stt_tag(), "[ERROR] auto langauge is NULL");
405 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
406 key = xmlNodeGetContent(cur);
408 /*SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */
409 if (NULL != temp->language) free(temp->language);
410 temp->language = strdup((char*)key);
413 SLOG(LOG_ERROR, stt_tag(), "[ERROR] language is NULL");
415 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
416 key = xmlNodeGetContent(cur);
418 /*SLOG(LOG_DEBUG, stt_tag(), "silence-detection : %s", (char *)key); */
420 if (0 == xmlStrcmp(key, (const xmlChar *)"on"))
421 temp->silence_detection = true;
423 temp->silence_detection = false;
427 SLOG(LOG_ERROR, stt_tag(), "[ERROR] silence-detection is NULL");
429 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
430 key = xmlNodeGetContent(cur);
432 //SLOG(LOG_DEBUG, stt_tag(), "credential : %s", (char *)key);
434 if (0 == xmlStrcmp(key, (const xmlChar *)"true"))
435 temp->credential = true;
437 temp->credential = false;
441 SLOG(LOG_ERROR, stt_tag(), "[ERROR] credential is NULL");
454 xmlSaveFile(STT_CONFIG, g_config_doc);
459 int stt_parser_unload_config(stt_config_s* config_info)
461 if (NULL != g_config_doc) xmlFreeDoc(g_config_doc);
462 if (NULL != config_info) {
463 if (NULL != config_info->engine_id) {
464 free(config_info->engine_id);
465 config_info->engine_id = NULL;
467 if (NULL != config_info->setting) {
468 free(config_info->setting);
469 config_info->setting = NULL;
471 if (NULL != config_info->language) {
472 free(config_info->language);
473 config_info->language = NULL;
482 int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence, bool credential)
484 if (NULL == g_config_doc || NULL == engine_id)
487 xmlNodePtr cur = NULL;
488 cur = xmlDocGetRootElement(g_config_doc);
490 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
494 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
495 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
499 cur = cur->xmlChildrenNode;
501 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
505 while (cur != NULL) {
506 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_ID)) {
507 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
510 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
511 xmlNodeSetContent(cur, (const xmlChar *)language);
514 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_ENGINE_SETTING)) {
515 xmlNodeSetContent(cur, (const xmlChar *)setting);
518 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
520 xmlNodeSetContent(cur, (const xmlChar *)"on");
522 xmlNodeSetContent(cur, (const xmlChar *)"off");
525 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) {
526 if (true == credential)
527 xmlNodeSetContent(cur, (const xmlChar *)"true");
529 xmlNodeSetContent(cur, (const xmlChar *)"false");
535 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
536 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
541 int stt_parser_set_language(const char* language)
543 if (NULL == g_config_doc || NULL == language)
546 xmlNodePtr cur = NULL;
547 cur = xmlDocGetRootElement(g_config_doc);
549 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
553 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
554 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
558 cur = cur->xmlChildrenNode;
560 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
564 while (cur != NULL) {
565 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_LANGUAGE)) {
566 xmlNodeSetContent(cur, (const xmlChar *)language);
572 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
573 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
579 int stt_parser_set_auto_lang(bool value)
581 if (NULL == g_config_doc)
584 xmlNodePtr cur = NULL;
585 cur = xmlDocGetRootElement(g_config_doc);
587 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
591 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
592 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
596 cur = cur->xmlChildrenNode;
598 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
602 while (cur != NULL) {
603 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
605 xmlNodeSetContent(cur, (const xmlChar *)"on");
606 } else if (false == value) {
607 xmlNodeSetContent(cur, (const xmlChar *)"off");
609 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong value of auto voice");
617 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
618 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
623 int stt_parser_set_silence_detection(bool value)
625 if (NULL == g_config_doc)
628 xmlNodePtr cur = NULL;
629 cur = xmlDocGetRootElement(g_config_doc);
631 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
635 if (xmlStrcmp(cur->name, (const xmlChar *) STT_TAG_CONFIG_BASE_TAG)) {
636 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
640 cur = cur->xmlChildrenNode;
642 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
646 while (cur != NULL) {
647 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_SILENCE_DETECTION)) {
649 xmlNodeSetContent(cur, (const xmlChar *)"on");
651 xmlNodeSetContent(cur, (const xmlChar *)"off");
657 int ret = xmlSaveFile(STT_CONFIG, g_config_doc);
658 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
663 int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence, int* credential)
665 if (NULL == engine || NULL == language || NULL == silence || NULL == credential) {
666 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
670 xmlDocPtr doc = NULL;
671 xmlNodePtr cur_new = NULL;
672 xmlNodePtr cur_old = NULL;
677 doc = xmlParseFile(STT_CONFIG);
679 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG);
683 cur_new = xmlDocGetRootElement(doc);
684 cur_old = xmlDocGetRootElement(g_config_doc);
685 if (cur_new == NULL || cur_old == NULL) {
686 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
691 if (xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG) || xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_BASE_TAG)) {
692 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT %s", STT_TAG_CONFIG_BASE_TAG);
697 cur_new = cur_new->xmlChildrenNode;
698 cur_old = cur_old->xmlChildrenNode;
699 if (cur_new == NULL || cur_old == NULL) {
700 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
709 while (cur_new != NULL && cur_old != NULL) {
710 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
711 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_ID)) {
712 key_old = xmlNodeGetContent(cur_old);
713 if (NULL != key_old) {
714 key_new = xmlNodeGetContent(cur_new);
715 if (NULL != key_new) {
716 if (0 != xmlStrcmp(key_old, key_new)) {
717 SLOG(LOG_DEBUG, stt_tag(), "Old engine id(%s), New engine(%s)", (char*)key_old, (char*)key_new);
718 if (NULL != *engine) free(*engine);
719 *engine = strdup((char*)key_new);
726 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
728 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
729 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_ENGINE_SETTING)) {
730 key_old = xmlNodeGetContent(cur_old);
731 if (NULL != key_old) {
732 key_new = xmlNodeGetContent(cur_new);
733 if (NULL != key_new) {
734 if (0 != xmlStrcmp(key_old, key_new)) {
735 SLOG(LOG_DEBUG, stt_tag(), "Old engine setting(%s), New engine setting(%s)", (char*)key_old, (char*)key_new);
736 if (NULL != *setting) free(*setting);
737 *setting = strdup((char*)key_new);
744 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Old config and new config are different");
746 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
747 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_AUTO_LANGUAGE)) {
748 key_old = xmlNodeGetContent(cur_old);
749 if (NULL != key_old) {
750 key_new = xmlNodeGetContent(cur_new);
751 if (NULL != key_new) {
752 if (0 != xmlStrcmp(key_old, key_new)) {
753 SLOG(LOG_DEBUG, stt_tag(), "Old auto lang(%s), New auto lang(%s)", (char*)key_old, (char*)key_new);
754 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
755 *auto_lang = (int)true;
757 *auto_lang = (int)false;
766 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
768 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
769 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_LANGUAGE)) {
770 key_old = xmlNodeGetContent(cur_old);
771 if (NULL != key_old) {
772 key_new = xmlNodeGetContent(cur_new);
773 if (NULL != key_new) {
774 if (0 != xmlStrcmp(key_old, key_new)) {
775 SLOG(LOG_DEBUG, stt_tag(), "Old language(%s), New language(%s)", (char*)key_old, (char*)key_new);
776 if (NULL != *language) free(*language);
777 *language = strdup((char*)key_new);
784 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
786 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
787 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_SILENCE_DETECTION)) {
788 key_old = xmlNodeGetContent(cur_old);
789 if (NULL != key_old) {
790 key_new = xmlNodeGetContent(cur_new);
791 if (NULL != key_new) {
792 if (0 != xmlStrcmp(key_old, key_new)) {
793 SLOG(LOG_DEBUG, stt_tag(), "Old silence(%s), New silence(%s)", (char*)key_old, (char*)key_new);
794 if (0 == xmlStrcmp(key_new, (const xmlChar*)"on")) {
806 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
808 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
809 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) {
810 key_old = xmlNodeGetContent(cur_old);
811 if (NULL != key_old) {
812 key_new = xmlNodeGetContent(cur_new);
813 if (NULL != key_new) {
814 if (0 != xmlStrcmp(key_old, key_new)) {
815 SLOG(LOG_DEBUG, stt_tag(), "Old credential(%s), New credential(%s)", (char*)key_old, (char*)key_new);
816 if (0 == xmlStrcmp(key_new, (const xmlChar*)"true")) {
827 SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different");
834 cur_new = cur_new->next;
835 cur_old = cur_old->next;
838 xmlFreeDoc(g_config_doc);
848 int stt_parser_set_time_info(GSList* time_list)
850 if (0 == g_slist_length(time_list)) {
851 SLOG(LOG_WARN, stt_tag(), "[WARNING] There is no time info to save");
855 if (-1 == remove(STT_TIME_INFO_PATH)) {
856 SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH);
859 xmlDocPtr doc = NULL;
860 xmlNodePtr cur = NULL;
862 doc = xmlNewDoc((const xmlChar*)"1.0");
864 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make new doc");
868 cur = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_BASE_TAG);
869 xmlDocSetRootElement(doc, cur);
871 xmlNodePtr inode = NULL;
873 stt_result_time_info_s *data = NULL;
876 snprintf(temp_str, 256, "%d", g_slist_length(time_list));
878 inode = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_INDEX);
879 xmlNewProp(inode, (const xmlChar*)STT_TAG_TIME_COUNT, (const xmlChar*)temp_str);
880 xmlAddChild(cur, inode);
882 /* Get a first item */
883 iter = g_slist_nth(time_list, 0);
884 while (NULL != iter) {
888 SLOG(LOG_DEBUG, stt_tag(), "data is NULL");
892 xmlNodePtr temp_node = NULL;
894 SECURE_SLOG(LOG_DEBUG, stt_tag(), "[%d] i(%d) t(%s) s(%ld) e(%ld)",
895 data->index, data->event, data->text, data->start_time, data->end_time);
897 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_TEXT);
898 xmlNodeSetContent(temp_node, (const xmlChar*)data->text);
899 xmlAddChild(inode, temp_node);
901 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_START);
902 snprintf(temp_str, 256, "%ld", data->start_time);
903 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
904 xmlAddChild(inode, temp_node);
906 temp_node = xmlNewNode(NULL, (const xmlChar*)STT_TAG_TIME_END);
907 snprintf(temp_str, 256, "%ld", data->end_time);
908 xmlNodeSetContent(temp_node, (const xmlChar*)temp_str);
909 xmlAddChild(inode, temp_node);
912 iter = g_slist_next(iter);
915 int ret = xmlSaveFormatFile(STT_TIME_INFO_PATH, doc, 1);
916 SLOG(LOG_DEBUG, stt_tag(), "Save result : %d", ret);
922 void __stt_parser_time_info_free(void* data)
924 stt_result_time_info_s* time_info = (stt_result_time_info_s*)data;
926 if (NULL != time_info) {
927 if (NULL != time_info->text) {
928 free(time_info->text);
929 time_info->text = NULL;
936 int stt_parser_get_time_info(GSList** time_list)
938 if (NULL == time_list) {
939 SLOG(LOG_ERROR, stt_tag(), "Invalid paramter : text is NULL");
943 xmlDocPtr doc = NULL;
944 xmlNodePtr cur = NULL;
946 doc = xmlParseFile(STT_TIME_INFO_PATH);
948 SLOG(LOG_WARN, stt_tag(), "[WARNING] File is not exist");
952 cur = xmlDocGetRootElement(doc);
954 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
959 if (xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_BASE_TAG)) {
960 SLOG(LOG_ERROR, stt_tag(), "[ERROR] The wrong type, root node is NOT '%s'", STT_TAG_TIME_BASE_TAG);
965 cur = cur->xmlChildrenNode;
967 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Empty document");
972 /* alloc time info */
973 GSList *temp_time_list = NULL;
977 while (cur != NULL) {
978 if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_TIME_INDEX)) {
979 key = xmlGetProp(cur, (const xmlChar*)STT_TAG_TIME_COUNT);
981 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_COUNT);
983 if (NULL != temp_time_list) {
984 g_slist_free_full(temp_time_list, __stt_parser_time_info_free);
985 temp_time_list = NULL;
991 SLOG(LOG_DEBUG, stt_tag(), "Count : %s", (char *)key);
995 count = atoi((char*)key);
999 SLOG(LOG_ERROR, stt_tag(), "[ERROR] count is invalid : %d", count);
1003 xmlNodePtr time_node = NULL;
1004 time_node = cur->xmlChildrenNode;
1007 for (i = 0; i < count; i++) {
1009 time_node = time_node->next;
1011 stt_result_time_info_s* temp_info;
1012 temp_info = (stt_result_time_info_s*)calloc(1, sizeof(stt_result_time_info_s));
1014 if (NULL == temp_info) {
1015 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Memory alloc error!!");
1017 if (NULL != temp_time_list) {
1018 g_slist_free_full(temp_time_list, __stt_parser_time_info_free);
1019 temp_time_list = NULL;
1025 temp_info->index = index;
1026 SLOG(LOG_DEBUG, stt_tag(), "index : %d", temp_info->index);
1028 if (0 == i) temp_info->event = 0;
1029 else if (count -1 == i) temp_info->event = 2;
1030 else temp_info->event = 1;
1032 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_TEXT)) {
1033 key = xmlNodeGetContent(time_node);
1035 SLOG(LOG_DEBUG, stt_tag(), "text : %s", (char *)key);
1036 temp_info->text = strdup((char*)key);
1039 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_TEXT);
1046 time_node = time_node->next;
1047 time_node = time_node->next;
1049 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_START)) {
1050 key = xmlNodeGetContent(time_node);
1052 SLOG(LOG_DEBUG, stt_tag(), "Start time : %s", (char *)key);
1053 temp_info->start_time = atoi((char*)key);
1056 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_START);
1057 if (NULL != temp_info->text) free(temp_info->text);
1064 time_node = time_node->next;
1065 time_node = time_node->next;
1067 if (0 == xmlStrcmp(time_node->name, (const xmlChar *)STT_TAG_TIME_END)) {
1068 key = xmlNodeGetContent(time_node);
1070 SLOG(LOG_DEBUG, stt_tag(), "End time : %s", (char *)key);
1071 temp_info->end_time = atoi((char*)key);
1074 SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_TIME_END);
1075 if (NULL != temp_info->text) free(temp_info->text);
1081 time_node = time_node->next;
1083 temp_time_list = g_slist_append(temp_time_list, temp_info);
1092 *time_list = temp_time_list;
1097 int stt_parser_clear_time_info()
1099 if (-1 == remove(STT_TIME_INFO_PATH)) {
1100 /* SLOG(LOG_WARN, stt_tag(), "[PLAYER WARNING] Fail to remove file(%s)", STT_TIME_INFO_PATH); */