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.
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));
95 temp->pitch_support = false;
98 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
99 key = xmlNodeGetContent(cur);
101 if (NULL != temp->name) free(temp->name);
102 temp->name = strdup((char*)key);
105 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
107 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
108 key = xmlNodeGetContent(cur);
110 if (NULL != temp->uuid) free(temp->uuid);
111 temp->uuid = strdup((char*)key);
114 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
116 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
117 key = xmlNodeGetContent(cur);
119 if (NULL != temp->setting) free(temp->setting);
120 temp->setting = strdup((char*)key);
123 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
125 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
126 xmlNodePtr voice_node = NULL;
127 voice_node = cur->xmlChildrenNode;
129 while (NULL != voice_node) {
130 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
132 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
134 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
136 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
137 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
138 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
139 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
140 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
141 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
143 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
147 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
150 key = xmlNodeGetContent(voice_node);
152 if (NULL != temp_voice->language) free(temp_voice->language);
153 temp_voice->language = strdup((char*)key);
156 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
159 temp->voices = g_slist_append(temp->voices, temp_voice);
161 voice_node = voice_node->next;
163 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
164 key = xmlNodeGetContent(cur);
166 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
167 temp->pitch_support = true;
171 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
179 if (NULL == temp->name || NULL == temp->uuid) {
181 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
182 tts_parser_free_engine_info(temp);
191 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
193 if (NULL == engine_info) {
194 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
198 if (NULL != engine_info->name) free(engine_info->name);
199 if (NULL != engine_info->uuid) free(engine_info->uuid);
200 if (NULL != engine_info->setting) free(engine_info->setting);
202 tts_config_voice_s *temp_voice;
203 temp_voice = g_slist_nth_data(engine_info->voices, 0);
205 while (NULL != temp_voice) {
206 if (NULL != temp_voice) {
207 if (NULL != temp_voice->language) free(temp_voice->language);
208 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
212 temp_voice = g_slist_nth_data(engine_info->voices, 0);
215 if (NULL != engine_info) free(engine_info);
220 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
222 if (NULL == engine_info) {
223 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
227 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
228 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
229 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
230 if (NULL != engine_info->setting)
231 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
233 SLOG(LOG_DEBUG, tts_tag(), " voices");
235 tts_config_voice_s *temp_voice;
237 if (g_slist_length(engine_info->voices) > 0) {
238 /* Get a first item */
239 iter = g_slist_nth(engine_info->voices, 0);
242 while (NULL != iter) {
243 /*Get handle data from list*/
244 temp_voice = iter->data;
246 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
247 i, temp_voice->type, temp_voice->language);
250 iter = g_slist_next(iter);
254 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
257 SLOG(LOG_DEBUG, tts_tag(), "=====================");
262 int tts_parser_load_config(tts_config_s** config_info)
264 if (NULL == config_info) {
265 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
269 xmlDocPtr doc = NULL;
270 xmlNodePtr cur = NULL;
272 bool is_default_open = false;
274 if (0 != access(TTS_CONFIG, F_OK)) {
275 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
277 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
280 is_default_open = true;
284 while (NULL == doc) {
285 doc = xmlParseFile(TTS_CONFIG);
292 if (100 == retry_count) {
293 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
299 cur = xmlDocGetRootElement(doc);
301 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
306 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
307 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
312 cur = cur->xmlChildrenNode;
314 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
319 /* alloc engine info */
321 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
323 temp->engine_id = NULL;
324 temp->setting = NULL;
325 temp->language = NULL;
327 while (cur != NULL) {
328 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
329 key = xmlNodeGetContent(cur);
331 if (NULL != temp->engine_id) free(temp->engine_id);
332 temp->engine_id = strdup((char*)key);
335 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
337 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
338 key = xmlNodeGetContent(cur);
340 if (NULL != temp->setting) free(temp->setting);
341 temp->setting = strdup((char*)key);
344 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
347 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
348 key = xmlNodeGetContent(cur);
350 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
351 temp->auto_voice = true;
352 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
353 temp->auto_voice = false;
355 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
356 temp->auto_voice = true;
361 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
363 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
364 key = xmlNodeGetContent(cur);
366 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
367 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
368 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
369 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
370 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
371 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
373 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
374 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
379 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
381 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
382 key = xmlNodeGetContent(cur);
384 if (NULL != temp->language) free(temp->language);
385 temp->language = strdup((char*)key);
388 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
391 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
392 key = xmlNodeGetContent(cur);
394 temp->speech_rate = atoi((char*)key);
397 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
399 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
400 key = xmlNodeGetContent(cur);
402 temp->pitch = atoi((char*)key);
405 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
417 if (true == is_default_open) {
418 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
420 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
424 if (0 > chmod(TTS_CONFIG, 0666)) {
425 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
429 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
430 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
432 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
438 int tts_parser_unload_config(tts_config_s* config_info)
440 if (NULL != g_config_doc) xmlFreeDoc(g_config_doc);
441 if (NULL != config_info) {
442 if (NULL != config_info->engine_id) free(config_info->engine_id);
443 if (NULL != config_info->setting) free(config_info->setting);
444 if (NULL != config_info->language) free(config_info->language);
451 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
453 if (NULL == engine_id) {
454 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
458 xmlNodePtr cur = NULL;
459 cur = xmlDocGetRootElement(g_config_doc);
461 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
465 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
466 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
470 cur = cur->xmlChildrenNode;
472 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
476 while (cur != NULL) {
477 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
478 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
481 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
482 xmlNodeSetContent(cur, (const xmlChar *)language);
485 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
486 xmlNodeSetContent(cur, (const xmlChar *)setting);
489 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
491 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
492 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
493 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
494 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
501 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
503 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
509 int tts_parser_set_voice(const char* language, int type)
511 if (NULL == language) {
512 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
516 xmlNodePtr cur = NULL;
517 cur = xmlDocGetRootElement(g_config_doc);
519 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
523 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
524 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
528 cur = cur->xmlChildrenNode;
530 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
534 while (cur != NULL) {
535 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
536 xmlNodeSetContent(cur, (const xmlChar *)language);
539 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
541 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
542 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
543 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
545 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
546 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
554 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
556 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
562 int tts_parser_set_auto_voice(bool value)
564 xmlNodePtr cur = NULL;
565 cur = xmlDocGetRootElement(g_config_doc);
567 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
571 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
572 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
576 cur = cur->xmlChildrenNode;
578 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
582 while (cur != NULL) {
583 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
585 xmlNodeSetContent(cur, (const xmlChar *)"on");
586 } else if (false == value) {
587 xmlNodeSetContent(cur, (const xmlChar *)"off");
589 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
597 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
599 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
605 int tts_parser_set_speech_rate(int value)
607 xmlNodePtr cur = NULL;
608 cur = xmlDocGetRootElement(g_config_doc);
610 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
614 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
615 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
619 cur = cur->xmlChildrenNode;
621 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
625 while (cur != NULL) {
626 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
628 memset(temp, '\0', 10);
629 snprintf(temp, 10, "%d", value);
631 xmlNodeSetContent(cur, (const xmlChar *)temp);
633 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
640 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
642 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
648 int tts_parser_set_pitch(int value)
650 xmlNodePtr cur = NULL;
651 cur = xmlDocGetRootElement(g_config_doc);
653 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
657 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
658 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
662 cur = cur->xmlChildrenNode;
664 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
668 while (cur != NULL) {
669 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
671 memset(temp, '\0', 10);
672 snprintf(temp, 10, "%d", value);
673 xmlNodeSetContent(cur, (const xmlChar *)temp);
680 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
682 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
688 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
689 int* speech_rate, int* pitch)
691 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
692 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
696 xmlDocPtr doc = NULL;
697 xmlNodePtr cur_new = NULL;
698 xmlNodePtr cur_old = NULL;
704 while (NULL == doc) {
705 doc = xmlParseFile(TTS_CONFIG);
712 if (100 == retry_count) {
713 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
718 cur_new = xmlDocGetRootElement(doc);
719 cur_old = xmlDocGetRootElement(g_config_doc);
720 if (cur_new == NULL || cur_old == NULL) {
721 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
726 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
727 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
728 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
733 cur_new = cur_new->xmlChildrenNode;
734 cur_old = cur_old->xmlChildrenNode;
735 if (cur_new == NULL || cur_old == NULL) {
736 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
741 while (cur_new != NULL && cur_old != NULL) {
742 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
743 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
744 key_old = xmlNodeGetContent(cur_old);
745 if (NULL != key_old) {
746 key_new = xmlNodeGetContent(cur_new);
747 if (NULL != key_new) {
748 if (0 != xmlStrcmp(key_old, key_new)) {
749 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
750 (char*)key_old, (char*)key_new);
751 if (NULL != *engine) free(*engine);
752 *engine = strdup((char*)key_new);
759 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
761 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
762 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
763 key_old = xmlNodeGetContent(cur_old);
764 if (NULL != key_old) {
765 key_new = xmlNodeGetContent(cur_new);
766 if (NULL != key_new) {
767 if (0 != xmlStrcmp(key_old, key_new)) {
768 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
769 (char*)key_old, (char*)key_new);
770 if (NULL != *setting) free(*setting);
771 *setting = strdup((char*)key_new);
778 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
780 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
781 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
782 key_old = xmlNodeGetContent(cur_old);
783 if (NULL != key_old) {
784 key_new = xmlNodeGetContent(cur_new);
785 if (NULL != key_new) {
786 if (0 != xmlStrcmp(key_old, key_new)) {
787 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
788 (char*)key_old, (char*)key_new);
789 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
800 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
802 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
803 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
804 key_old = xmlNodeGetContent(cur_old);
805 if (NULL != key_old) {
806 key_new = xmlNodeGetContent(cur_new);
807 if (NULL != key_new) {
808 if (0 != xmlStrcmp(key_old, key_new)) {
809 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
810 (char*)key_old, (char*)key_new);
811 if (NULL != *language) free(*language);
812 *language = strdup((char*)key_new);
819 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
821 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
822 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
823 key_old = xmlNodeGetContent(cur_old);
824 if (NULL != key_old) {
825 key_new = xmlNodeGetContent(cur_new);
826 if (NULL != key_new) {
827 if (0 != xmlStrcmp(key_old, key_new)) {
828 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
829 (char*)key_old, (char*)key_new);
830 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
831 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
832 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
833 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
834 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
835 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
837 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
845 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
847 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
848 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
849 key_old = xmlNodeGetContent(cur_old);
850 if (NULL != key_old) {
851 key_new = xmlNodeGetContent(cur_new);
852 if (NULL != key_new) {
853 if (0 != xmlStrcmp(key_old, key_new)) {
854 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
855 (char*)key_old, (char*)key_new);
856 *speech_rate = atoi((char*)key_new);
863 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
865 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
866 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
867 key_old = xmlNodeGetContent(cur_old);
868 if (NULL != key_old) {
869 key_new = xmlNodeGetContent(cur_new);
870 if (NULL != key_new) {
871 if (0 != xmlStrcmp(key_old, key_new)) {
872 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
873 (char*)key_old, (char*)key_new);
874 *pitch = atoi((char*)key_new);
881 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
887 cur_new = cur_new->next;
888 cur_old = cur_old->next;
891 xmlFreeDoc(g_config_doc);