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.
20 #include "tts_config_parser.h"
24 #define TTS_TAG_ENGINE_BASE_TAG "tts-engine"
25 #define TTS_TAG_ENGINE_NAME "name"
26 #define TTS_TAG_ENGINE_ID "id"
27 #define TTS_TAG_ENGINE_SETTING "setting"
28 #define TTS_TAG_ENGINE_VOICE_SET "voices"
29 #define TTS_TAG_ENGINE_VOICE "voice"
30 #define TTS_TAG_ENGINE_VOICE_TYPE "type"
31 #define TTS_TAG_ENGINE_PITCH_SUPPORT "pitch-support"
33 #define TTS_TAG_CONFIG_BASE_TAG "tts-config"
34 #define TTS_TAG_CONFIG_ENGINE_ID "engine"
35 #define TTS_TAG_CONFIG_ENGINE_SETTING "engine-setting"
36 #define TTS_TAG_CONFIG_AUTO_VOICE "auto"
37 #define TTS_TAG_CONFIG_VOICE_TYPE "voice-type"
38 #define TTS_TAG_CONFIG_LANGUAGE "language"
39 #define TTS_TAG_CONFIG_SPEECH_RATE "speech-rate"
40 #define TTS_TAG_CONFIG_PITCH "pitch"
41 #define TTS_TAG_VOICE_TYPE_FEMALE "female"
42 #define TTS_TAG_VOICE_TYPE_MALE "male"
43 #define TTS_TAG_VOICE_TYPE_CHILD "child"
46 extern char* tts_tag();
48 static xmlDocPtr g_config_doc = NULL;
50 int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
52 if (NULL == path || NULL == engine_info) {
53 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
58 xmlNodePtr cur = NULL;
62 doc = xmlParseFile(path);
67 cur = xmlDocGetRootElement(doc);
69 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
74 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
75 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'");
80 cur = cur->xmlChildrenNode;
82 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
87 /* alloc engine info */
88 tts_engine_info_s* temp;
89 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
91 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
100 temp->pitch_support = false;
102 while (cur != NULL) {
103 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
104 key = xmlNodeGetContent(cur);
106 if (NULL != temp->name) free(temp->name);
107 temp->name = strdup((char*)key);
110 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
112 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
113 key = xmlNodeGetContent(cur);
115 if (NULL != temp->uuid) free(temp->uuid);
116 temp->uuid = strdup((char*)key);
119 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
121 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
122 key = xmlNodeGetContent(cur);
124 if (NULL != temp->setting) free(temp->setting);
125 temp->setting = strdup((char*)key);
128 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
130 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
131 xmlNodePtr voice_node = NULL;
132 voice_node = cur->xmlChildrenNode;
134 while (NULL != voice_node) {
135 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
137 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
138 if (NULL == temp_voice) {
139 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
143 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
145 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
146 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
147 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
148 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
149 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
150 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
152 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
156 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
159 key = xmlNodeGetContent(voice_node);
161 if (NULL != temp_voice->language) free(temp_voice->language);
162 temp_voice->language = strdup((char*)key);
164 temp->voices = g_slist_append(temp->voices, temp_voice);
166 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
167 if (NULL != temp_voice) {
172 voice_node = voice_node->next;
174 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
175 key = xmlNodeGetContent(cur);
177 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
178 temp->pitch_support = true;
182 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
190 if (NULL == temp->name || NULL == temp->uuid) {
192 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
193 tts_parser_free_engine_info(temp);
202 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
204 if (NULL == engine_info) {
205 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
209 if (NULL != engine_info->name) free(engine_info->name);
210 if (NULL != engine_info->uuid) free(engine_info->uuid);
211 if (NULL != engine_info->setting) free(engine_info->setting);
213 tts_config_voice_s *temp_voice;
214 temp_voice = g_slist_nth_data(engine_info->voices, 0);
216 while (NULL != temp_voice) {
217 if (NULL != temp_voice) {
218 if (NULL != temp_voice->language) free(temp_voice->language);
219 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
223 temp_voice = g_slist_nth_data(engine_info->voices, 0);
226 if (NULL != engine_info) free(engine_info);
231 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
233 if (NULL == engine_info) {
234 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
238 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
239 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
240 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
241 if (NULL != engine_info->setting)
242 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
244 SLOG(LOG_DEBUG, tts_tag(), " voices");
246 tts_config_voice_s *temp_voice;
248 if (g_slist_length(engine_info->voices) > 0) {
249 /* Get a first item */
250 iter = g_slist_nth(engine_info->voices, 0);
253 while (NULL != iter) {
254 /*Get handle data from list*/
255 temp_voice = iter->data;
257 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
258 i, temp_voice->type, temp_voice->language);
261 iter = g_slist_next(iter);
265 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
268 SLOG(LOG_DEBUG, tts_tag(), "=====================");
273 int tts_parser_load_config(tts_config_s** config_info)
275 if (NULL == config_info) {
276 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
280 xmlDocPtr doc = NULL;
281 xmlNodePtr cur = NULL;
283 bool is_default_open = false;
285 if (0 != access(TTS_CONFIG, F_OK)) {
286 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
288 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
291 is_default_open = true;
295 while (NULL == doc) {
296 doc = xmlParseFile(TTS_CONFIG);
303 if (TTS_RETRY_COUNT == retry_count) {
304 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
310 cur = xmlDocGetRootElement(doc);
312 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
317 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
318 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
323 cur = cur->xmlChildrenNode;
325 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
330 /* alloc engine info */
332 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
334 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
339 temp->engine_id = NULL;
340 temp->setting = NULL;
341 temp->language = NULL;
343 while (cur != NULL) {
344 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
345 key = xmlNodeGetContent(cur);
347 if (NULL != temp->engine_id) free(temp->engine_id);
348 temp->engine_id = strdup((char*)key);
351 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
353 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
354 key = xmlNodeGetContent(cur);
356 if (NULL != temp->setting) free(temp->setting);
357 temp->setting = strdup((char*)key);
360 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
363 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
364 key = xmlNodeGetContent(cur);
366 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
367 temp->auto_voice = true;
368 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
369 temp->auto_voice = false;
371 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
372 temp->auto_voice = true;
377 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
379 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
380 key = xmlNodeGetContent(cur);
382 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
383 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
384 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
385 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
386 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
387 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
389 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
390 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
395 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
397 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
398 key = xmlNodeGetContent(cur);
400 if (NULL != temp->language) free(temp->language);
401 temp->language = strdup((char*)key);
404 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
407 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
408 key = xmlNodeGetContent(cur);
410 temp->speech_rate = atoi((char*)key);
413 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
415 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
416 key = xmlNodeGetContent(cur);
418 temp->pitch = atoi((char*)key);
421 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
433 if (true == is_default_open) {
434 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
436 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
440 if (0 > chmod(TTS_CONFIG, 0666)) {
441 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
445 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
446 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
448 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
454 int tts_parser_unload_config(tts_config_s* config_info)
456 if (NULL != g_config_doc) xmlFreeDoc(g_config_doc);
457 if (NULL != config_info) {
458 if (NULL != config_info->engine_id) free(config_info->engine_id);
459 if (NULL != config_info->setting) free(config_info->setting);
460 if (NULL != config_info->language) free(config_info->language);
467 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
469 if (NULL == engine_id) {
470 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
474 xmlNodePtr cur = NULL;
475 cur = xmlDocGetRootElement(g_config_doc);
477 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
481 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
482 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
486 cur = cur->xmlChildrenNode;
488 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
492 while (cur != NULL) {
493 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
494 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
497 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
498 xmlNodeSetContent(cur, (const xmlChar *)language);
501 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
502 xmlNodeSetContent(cur, (const xmlChar *)setting);
505 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
507 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
508 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
509 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
510 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
517 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
519 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
525 int tts_parser_set_voice(const char* language, int type)
527 if (NULL == language) {
528 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
532 xmlNodePtr cur = NULL;
533 cur = xmlDocGetRootElement(g_config_doc);
535 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
539 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
540 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
544 cur = cur->xmlChildrenNode;
546 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
550 while (cur != NULL) {
551 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
552 xmlNodeSetContent(cur, (const xmlChar *)language);
555 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
557 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
558 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
559 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
561 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
562 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
570 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
572 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
578 int tts_parser_set_auto_voice(bool value)
580 xmlNodePtr cur = NULL;
581 cur = xmlDocGetRootElement(g_config_doc);
583 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
587 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
588 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
592 cur = cur->xmlChildrenNode;
594 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
598 while (cur != NULL) {
599 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
601 xmlNodeSetContent(cur, (const xmlChar *)"on");
602 } else if (false == value) {
603 xmlNodeSetContent(cur, (const xmlChar *)"off");
605 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
613 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
615 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
621 int tts_parser_set_speech_rate(int value)
623 xmlNodePtr cur = NULL;
624 cur = xmlDocGetRootElement(g_config_doc);
626 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
630 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
631 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
635 cur = cur->xmlChildrenNode;
637 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
641 while (cur != NULL) {
642 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
644 memset(temp, '\0', 10);
645 snprintf(temp, 10, "%d", value);
647 xmlNodeSetContent(cur, (const xmlChar *)temp);
649 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
656 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
658 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
664 int tts_parser_set_pitch(int value)
666 xmlNodePtr cur = NULL;
667 cur = xmlDocGetRootElement(g_config_doc);
669 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
673 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
674 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
678 cur = cur->xmlChildrenNode;
680 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
684 while (cur != NULL) {
685 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
687 memset(temp, '\0', 10);
688 snprintf(temp, 10, "%d", value);
689 xmlNodeSetContent(cur, (const xmlChar *)temp);
696 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
698 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
704 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
705 int* speech_rate, int* pitch)
707 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
708 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
712 xmlDocPtr doc = NULL;
713 xmlNodePtr cur_new = NULL;
714 xmlNodePtr cur_old = NULL;
720 while (NULL == doc) {
721 doc = xmlParseFile(TTS_CONFIG);
728 if (TTS_RETRY_COUNT == retry_count) {
729 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
734 cur_new = xmlDocGetRootElement(doc);
735 cur_old = xmlDocGetRootElement(g_config_doc);
736 if (cur_new == NULL || cur_old == NULL) {
737 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
742 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
743 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
744 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
749 cur_new = cur_new->xmlChildrenNode;
750 cur_old = cur_old->xmlChildrenNode;
751 if (cur_new == NULL || cur_old == NULL) {
752 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
757 while (cur_new != NULL && cur_old != NULL) {
758 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
759 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
760 key_old = xmlNodeGetContent(cur_old);
761 if (NULL != key_old) {
762 key_new = xmlNodeGetContent(cur_new);
763 if (NULL != key_new) {
764 if (0 != xmlStrcmp(key_old, key_new)) {
765 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
766 (char*)key_old, (char*)key_new);
767 if (NULL != *engine) free(*engine);
768 *engine = strdup((char*)key_new);
775 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
777 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
778 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
779 key_old = xmlNodeGetContent(cur_old);
780 if (NULL != key_old) {
781 key_new = xmlNodeGetContent(cur_new);
782 if (NULL != key_new) {
783 if (0 != xmlStrcmp(key_old, key_new)) {
784 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
785 (char*)key_old, (char*)key_new);
786 if (NULL != *setting) free(*setting);
787 *setting = strdup((char*)key_new);
794 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
796 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
797 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
798 key_old = xmlNodeGetContent(cur_old);
799 if (NULL != key_old) {
800 key_new = xmlNodeGetContent(cur_new);
801 if (NULL != key_new) {
802 if (0 != xmlStrcmp(key_old, key_new)) {
803 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
804 (char*)key_old, (char*)key_new);
805 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
816 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
818 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
819 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
820 key_old = xmlNodeGetContent(cur_old);
821 if (NULL != key_old) {
822 key_new = xmlNodeGetContent(cur_new);
823 if (NULL != key_new) {
824 if (0 != xmlStrcmp(key_old, key_new)) {
825 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
826 (char*)key_old, (char*)key_new);
827 if (NULL != *language) free(*language);
828 *language = strdup((char*)key_new);
835 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
837 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
838 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
839 key_old = xmlNodeGetContent(cur_old);
840 if (NULL != key_old) {
841 key_new = xmlNodeGetContent(cur_new);
842 if (NULL != key_new) {
843 if (0 != xmlStrcmp(key_old, key_new)) {
844 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
845 (char*)key_old, (char*)key_new);
846 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
847 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
848 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
849 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
850 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
851 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
853 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
861 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
863 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
864 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
865 key_old = xmlNodeGetContent(cur_old);
866 if (NULL != key_old) {
867 key_new = xmlNodeGetContent(cur_new);
868 if (NULL != key_new) {
869 if (0 != xmlStrcmp(key_old, key_new)) {
870 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
871 (char*)key_old, (char*)key_new);
872 *speech_rate = atoi((char*)key_new);
879 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
881 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
882 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
883 key_old = xmlNodeGetContent(cur_old);
884 if (NULL != key_old) {
885 key_new = xmlNodeGetContent(cur_new);
886 if (NULL != key_new) {
887 if (0 != xmlStrcmp(key_old, key_new)) {
888 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
889 (char*)key_old, (char*)key_new);
890 *pitch = atoi((char*)key_new);
897 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
903 cur_new = cur_new->next;
904 cur_old = cur_old->next;
907 xmlFreeDoc(g_config_doc);