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);
64 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse xml file");
68 cur = xmlDocGetRootElement(doc);
70 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
76 if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_BASE_TAG)) {
77 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT 'tts-engine'");
83 cur = cur->xmlChildrenNode;
85 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
91 /* alloc engine info */
92 tts_engine_info_s* temp;
93 temp = (tts_engine_info_s*)calloc(1, sizeof(tts_engine_info_s));
95 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
103 temp->setting = NULL;
104 temp->pitch_support = false;
106 while (cur != NULL) {
107 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_NAME)) {
108 key = xmlNodeGetContent(cur);
110 if (NULL != temp->name) free(temp->name);
111 temp->name = strdup((char*)key);
114 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_NAME);
116 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_ID)) {
117 key = xmlNodeGetContent(cur);
119 if (NULL != temp->uuid) free(temp->uuid);
120 temp->uuid = strdup((char*)key);
123 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_ID);
125 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_SETTING)) {
126 key = xmlNodeGetContent(cur);
128 if (NULL != temp->setting) free(temp->setting);
129 temp->setting = strdup((char*)key);
132 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_SETTING);
134 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
135 xmlNodePtr voice_node = NULL;
136 voice_node = cur->xmlChildrenNode;
138 while (NULL != voice_node) {
139 if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
140 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
141 if (NULL == temp_voice) {
142 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
146 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
148 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
149 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
150 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
151 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
152 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
153 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
155 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
159 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
165 key = xmlNodeGetContent(voice_node);
167 if (NULL != temp_voice->language) free(temp_voice->language);
168 temp_voice->language = strdup((char*)key);
170 temp->voices = g_slist_append(temp->voices, temp_voice);
172 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
173 if (NULL != temp_voice) {
179 voice_node = voice_node->next;
181 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
182 key = xmlNodeGetContent(cur);
184 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
185 temp->pitch_support = true;
190 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
199 if (NULL == temp->name || NULL == temp->uuid) {
201 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
202 tts_parser_free_engine_info(temp);
211 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
213 if (NULL == engine_info) {
214 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
218 if (NULL != engine_info->name) free(engine_info->name);
219 if (NULL != engine_info->uuid) free(engine_info->uuid);
220 if (NULL != engine_info->setting) free(engine_info->setting);
222 tts_config_voice_s *temp_voice;
223 temp_voice = g_slist_nth_data(engine_info->voices, 0);
225 while (NULL != temp_voice) {
226 if (NULL != temp_voice) {
227 if (NULL != temp_voice->language) free(temp_voice->language);
228 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
232 temp_voice = g_slist_nth_data(engine_info->voices, 0);
235 if (NULL != engine_info) free(engine_info);
240 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
242 if (NULL == engine_info) {
243 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
247 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
248 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
249 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
250 if (NULL != engine_info->setting)
251 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
253 SLOG(LOG_DEBUG, tts_tag(), " voices");
255 tts_config_voice_s *temp_voice;
257 if (g_slist_length(engine_info->voices) > 0) {
258 /* Get a first item */
259 iter = g_slist_nth(engine_info->voices, 0);
262 while (NULL != iter) {
263 /*Get handle data from list*/
264 temp_voice = iter->data;
266 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
267 i, temp_voice->type, temp_voice->language);
270 iter = g_slist_next(iter);
274 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
277 SLOG(LOG_DEBUG, tts_tag(), "=====================");
282 int tts_parser_load_config(tts_config_s** config_info)
284 if (NULL == config_info) {
285 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
289 xmlDocPtr doc = NULL;
290 xmlNodePtr cur = NULL;
292 bool is_default_open = false;
294 /* For Thread safety */
297 if (0 != access(TTS_CONFIG, F_OK)) {
298 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
300 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
303 is_default_open = true;
307 while (NULL == doc) {
308 doc = xmlParseFile(TTS_CONFIG);
315 if (TTS_RETRY_COUNT == retry_count) {
316 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
322 cur = xmlDocGetRootElement(doc);
324 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
330 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
331 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
337 cur = cur->xmlChildrenNode;
339 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
345 /* alloc engine info */
347 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
349 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
354 temp->engine_id = NULL;
355 temp->setting = NULL;
356 temp->language = NULL;
358 while (cur != NULL) {
359 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
360 key = xmlNodeGetContent(cur);
362 if (NULL != temp->engine_id) free(temp->engine_id);
363 temp->engine_id = strdup((char*)key);
366 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
368 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
369 key = xmlNodeGetContent(cur);
371 if (NULL != temp->setting) free(temp->setting);
372 temp->setting = strdup((char*)key);
375 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
378 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
379 key = xmlNodeGetContent(cur);
381 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
382 temp->auto_voice = true;
383 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
384 temp->auto_voice = false;
386 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
387 temp->auto_voice = true;
392 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
394 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
395 key = xmlNodeGetContent(cur);
397 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
398 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
399 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
400 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
401 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
402 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
404 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
405 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
410 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
412 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
413 key = xmlNodeGetContent(cur);
415 if (NULL != temp->language) free(temp->language);
416 temp->language = strdup((char*)key);
419 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
422 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
423 key = xmlNodeGetContent(cur);
425 temp->speech_rate = atoi((char*)key);
428 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
430 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
431 key = xmlNodeGetContent(cur);
433 temp->pitch = atoi((char*)key);
436 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
448 if (true == is_default_open) {
449 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
451 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
455 if (0 > chmod(TTS_CONFIG, 0666)) {
456 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
460 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
461 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
463 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
469 int tts_parser_unload_config(tts_config_s* config_info)
471 if (NULL != g_config_doc) {
472 xmlFreeDoc(g_config_doc);
475 if (NULL != config_info) {
476 if (NULL != config_info->engine_id) free(config_info->engine_id);
477 if (NULL != config_info->setting) free(config_info->setting);
478 if (NULL != config_info->language) free(config_info->language);
486 int tts_parser_copy_xml(const char* original, const char* destination)
488 if (NULL == original || NULL == destination) {
489 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
493 xmlDocPtr doc = NULL;
494 doc = xmlParseFile(original);
496 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
500 int ret = xmlSaveFile(destination, doc);
502 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
506 if (0 > chmod(destination, 0666)) {
507 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
511 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
516 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
518 if (NULL == engine_id) {
519 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
523 xmlNodePtr cur = NULL;
524 cur = xmlDocGetRootElement(g_config_doc);
526 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
530 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
531 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
535 cur = cur->xmlChildrenNode;
537 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
541 while (cur != NULL) {
542 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
543 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
546 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
547 xmlNodeSetContent(cur, (const xmlChar *)language);
550 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
551 xmlNodeSetContent(cur, (const xmlChar *)setting);
554 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
556 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
557 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
558 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
559 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
566 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
568 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
574 int tts_parser_set_voice(const char* language, int type)
576 if (NULL == language) {
577 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
581 xmlNodePtr cur = NULL;
582 cur = xmlDocGetRootElement(g_config_doc);
584 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
588 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
589 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
593 cur = cur->xmlChildrenNode;
595 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
599 while (cur != NULL) {
600 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
601 xmlNodeSetContent(cur, (const xmlChar *)language);
604 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
606 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
607 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
608 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
610 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
611 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
619 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
621 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
627 int tts_parser_set_auto_voice(bool value)
629 xmlNodePtr cur = NULL;
630 cur = xmlDocGetRootElement(g_config_doc);
632 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
636 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
637 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
641 cur = cur->xmlChildrenNode;
643 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
647 while (cur != NULL) {
648 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
650 xmlNodeSetContent(cur, (const xmlChar *)"on");
651 } else if (false == value) {
652 xmlNodeSetContent(cur, (const xmlChar *)"off");
654 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
662 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
664 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
670 int tts_parser_set_speech_rate(int value)
672 xmlNodePtr cur = NULL;
673 cur = xmlDocGetRootElement(g_config_doc);
675 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
679 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
680 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
684 cur = cur->xmlChildrenNode;
686 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
690 while (cur != NULL) {
691 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
693 memset(temp, '\0', 10);
694 snprintf(temp, 10, "%d", value);
696 xmlNodeSetContent(cur, (const xmlChar *)temp);
698 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
705 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
707 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
713 int tts_parser_set_pitch(int value)
715 xmlNodePtr cur = NULL;
716 cur = xmlDocGetRootElement(g_config_doc);
718 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
722 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
723 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
727 cur = cur->xmlChildrenNode;
729 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
733 while (cur != NULL) {
734 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
736 memset(temp, '\0', 10);
737 snprintf(temp, 10, "%d", value);
738 xmlNodeSetContent(cur, (const xmlChar *)temp);
745 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
747 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
753 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
754 int* speech_rate, int* pitch)
756 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
757 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
761 xmlDocPtr doc = NULL;
762 xmlNodePtr cur_new = NULL;
763 xmlNodePtr cur_old = NULL;
769 while (NULL == doc) {
770 doc = xmlParseFile(TTS_CONFIG);
777 if (TTS_RETRY_COUNT == retry_count) {
778 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
783 cur_new = xmlDocGetRootElement(doc);
784 cur_old = xmlDocGetRootElement(g_config_doc);
785 if (cur_new == NULL || cur_old == NULL) {
786 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
792 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
793 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
794 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
800 cur_new = cur_new->xmlChildrenNode;
801 cur_old = cur_old->xmlChildrenNode;
802 if (cur_new == NULL || cur_old == NULL) {
803 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
809 while (cur_new != NULL && cur_old != NULL) {
810 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
811 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
812 key_old = xmlNodeGetContent(cur_old);
813 if (NULL != key_old) {
814 key_new = xmlNodeGetContent(cur_new);
815 if (NULL != key_new) {
816 if (0 != xmlStrcmp(key_old, key_new)) {
817 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
818 (char*)key_old, (char*)key_new);
819 if (NULL != *engine) free(*engine);
820 *engine = strdup((char*)key_new);
827 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
829 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
830 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
831 key_old = xmlNodeGetContent(cur_old);
832 if (NULL != key_old) {
833 key_new = xmlNodeGetContent(cur_new);
834 if (NULL != key_new) {
835 if (0 != xmlStrcmp(key_old, key_new)) {
836 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
837 (char*)key_old, (char*)key_new);
838 if (NULL != *setting) free(*setting);
839 *setting = strdup((char*)key_new);
846 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
848 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
849 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
850 key_old = xmlNodeGetContent(cur_old);
851 if (NULL != key_old) {
852 key_new = xmlNodeGetContent(cur_new);
853 if (NULL != key_new) {
854 if (0 != xmlStrcmp(key_old, key_new)) {
855 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
856 (char*)key_old, (char*)key_new);
857 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
868 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
870 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
871 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
872 key_old = xmlNodeGetContent(cur_old);
873 if (NULL != key_old) {
874 key_new = xmlNodeGetContent(cur_new);
875 if (NULL != key_new) {
876 if (0 != xmlStrcmp(key_old, key_new)) {
877 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
878 (char*)key_old, (char*)key_new);
879 if (NULL != *language) free(*language);
880 *language = strdup((char*)key_new);
887 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
889 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
890 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
891 key_old = xmlNodeGetContent(cur_old);
892 if (NULL != key_old) {
893 key_new = xmlNodeGetContent(cur_new);
894 if (NULL != key_new) {
895 if (0 != xmlStrcmp(key_old, key_new)) {
896 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
897 (char*)key_old, (char*)key_new);
898 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
899 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
900 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
901 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
902 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
903 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
905 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
913 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
915 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
916 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
917 key_old = xmlNodeGetContent(cur_old);
918 if (NULL != key_old) {
919 key_new = xmlNodeGetContent(cur_new);
920 if (NULL != key_new) {
921 if (0 != xmlStrcmp(key_old, key_new)) {
922 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
923 (char*)key_old, (char*)key_new);
924 *speech_rate = atoi((char*)key_new);
931 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
933 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
934 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
935 key_old = xmlNodeGetContent(cur_old);
936 if (NULL != key_old) {
937 key_new = xmlNodeGetContent(cur_new);
938 if (NULL != key_new) {
939 if (0 != xmlStrcmp(key_old, key_new)) {
940 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
941 (char*)key_old, (char*)key_new);
942 *pitch = atoi((char*)key_new);
949 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
955 cur_new = cur_new->next;
956 cur_old = cur_old->next;
959 if (NULL != g_config_doc) {
960 xmlFreeDoc(g_config_doc);