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)) {
141 tts_config_voice_s* temp_voice = (tts_config_voice_s*)calloc(1, sizeof(tts_config_voice_s));
142 if (NULL == temp_voice) {
143 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
147 attr = xmlGetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE);
149 if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
150 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
151 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
152 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
153 } else if (0 == xmlStrcmp(attr, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
154 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
156 temp_voice->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
160 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE_TYPE);
166 key = xmlNodeGetContent(voice_node);
168 if (NULL != temp_voice->language) free(temp_voice->language);
169 temp_voice->language = strdup((char*)key);
171 temp->voices = g_slist_append(temp->voices, temp_voice);
173 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_VOICE);
174 if (NULL != temp_voice) {
180 voice_node = voice_node->next;
182 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_PITCH_SUPPORT)) {
183 key = xmlNodeGetContent(cur);
185 if (0 == xmlStrcmp(key, (const xmlChar *)"true")) {
186 temp->pitch_support = true;
191 SLOG(LOG_ERROR, tts_tag(), "[ERROR] <%s> has no content", TTS_TAG_ENGINE_PITCH_SUPPORT);
200 if (NULL == temp->name || NULL == temp->uuid) {
202 SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid engine : %s", path);
203 tts_parser_free_engine_info(temp);
212 int tts_parser_free_engine_info(tts_engine_info_s* engine_info)
214 if (NULL == engine_info) {
215 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
219 if (NULL != engine_info->name) free(engine_info->name);
220 if (NULL != engine_info->uuid) free(engine_info->uuid);
221 if (NULL != engine_info->setting) free(engine_info->setting);
223 tts_config_voice_s *temp_voice;
224 temp_voice = g_slist_nth_data(engine_info->voices, 0);
226 while (NULL != temp_voice) {
227 if (NULL != temp_voice) {
228 if (NULL != temp_voice->language) free(temp_voice->language);
229 engine_info->voices = g_slist_remove(engine_info->voices, temp_voice);
233 temp_voice = g_slist_nth_data(engine_info->voices, 0);
236 if (NULL != engine_info) free(engine_info);
241 int tts_parser_print_engine_info(tts_engine_info_s* engine_info)
243 if (NULL == engine_info) {
244 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
248 SLOG(LOG_DEBUG, tts_tag(), "== get engine info ==");
249 SLOG(LOG_DEBUG, tts_tag(), " name : %s", engine_info->name);
250 SLOG(LOG_DEBUG, tts_tag(), " id : %s", engine_info->uuid);
251 if (NULL != engine_info->setting)
252 SLOG(LOG_DEBUG, tts_tag(), " setting : %s", engine_info->setting);
254 SLOG(LOG_DEBUG, tts_tag(), " voices");
256 tts_config_voice_s *temp_voice;
258 if (g_slist_length(engine_info->voices) > 0) {
259 /* Get a first item */
260 iter = g_slist_nth(engine_info->voices, 0);
263 while (NULL != iter) {
264 /*Get handle data from list*/
265 temp_voice = iter->data;
267 SLOG(LOG_DEBUG, tts_tag(), " [%dth] type(%d) lang(%s)",
268 i, temp_voice->type, temp_voice->language);
271 iter = g_slist_next(iter);
275 SLOG(LOG_ERROR, tts_tag(), " Voice is NONE");
278 SLOG(LOG_DEBUG, tts_tag(), "=====================");
283 int tts_parser_load_config(tts_config_s** config_info)
285 if (NULL == config_info) {
286 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
290 xmlDocPtr doc = NULL;
291 xmlNodePtr cur = NULL;
293 bool is_default_open = false;
295 /* For Thread safety */
298 if (0 != access(TTS_CONFIG, F_OK)) {
299 doc = xmlParseFile(TTS_DEFAULT_CONFIG);
301 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG);
304 is_default_open = true;
308 while (NULL == doc) {
309 doc = xmlParseFile(TTS_CONFIG);
316 if (TTS_RETRY_COUNT == retry_count) {
317 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
323 cur = xmlDocGetRootElement(doc);
325 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
331 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
332 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
338 cur = cur->xmlChildrenNode;
340 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
346 /* alloc engine info */
348 temp = (tts_config_s*)calloc(1, sizeof(tts_config_s));
350 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Out of memory");
355 temp->engine_id = NULL;
356 temp->setting = NULL;
357 temp->language = NULL;
359 while (cur != NULL) {
360 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
361 key = xmlNodeGetContent(cur);
363 if (NULL != temp->engine_id) free(temp->engine_id);
364 temp->engine_id = strdup((char*)key);
367 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine id is NULL");
369 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
370 key = xmlNodeGetContent(cur);
372 if (NULL != temp->setting) free(temp->setting);
373 temp->setting = strdup((char*)key);
376 SLOG(LOG_ERROR, tts_tag(), "[ERROR] setting path is NULL");
379 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
380 key = xmlNodeGetContent(cur);
382 if (0 == xmlStrcmp(key, (const xmlChar *)"on")) {
383 temp->auto_voice = true;
384 } else if (0 == xmlStrcmp(key, (const xmlChar *)"off")) {
385 temp->auto_voice = false;
387 SLOG(LOG_ERROR, tts_tag(), "Auto voice is wrong");
388 temp->auto_voice = true;
393 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
395 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
396 key = xmlNodeGetContent(cur);
398 if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
399 temp->type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
400 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
401 temp->type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
402 } else if (0 == xmlStrcmp(key, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
403 temp->type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
405 SLOG(LOG_WARN, tts_tag(), "Voice type is user defined");
406 temp->type = (int)TTS_CONFIG_VOICE_TYPE_USER_DEFINED;
411 SLOG(LOG_ERROR, tts_tag(), "[ERROR] voice type is NULL");
413 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
414 key = xmlNodeGetContent(cur);
416 if (NULL != temp->language) free(temp->language);
417 temp->language = strdup((char*)key);
420 SLOG(LOG_ERROR, tts_tag(), "[ERROR] engine uuid is NULL");
423 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
424 key = xmlNodeGetContent(cur);
426 temp->speech_rate = atoi((char*)key);
429 SLOG(LOG_ERROR, tts_tag(), "[ERROR] speech rate is NULL");
431 } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
432 key = xmlNodeGetContent(cur);
434 temp->pitch = atoi((char*)key);
437 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Pitch is NULL");
449 if (true == is_default_open) {
450 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
452 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
456 if (0 > chmod(TTS_CONFIG, 0666)) {
457 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
461 if (0 > chown(TTS_CONFIG, 5000, 5000)) {
462 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file owner : %d", ret);
464 SLOG(LOG_DEBUG, tts_tag(), "Default config is changed : pid(%d)", getpid());
470 int tts_parser_unload_config(tts_config_s* config_info)
472 if (NULL != g_config_doc) {
473 xmlFreeDoc(g_config_doc);
476 if (NULL != config_info) {
477 if (NULL != config_info->engine_id) free(config_info->engine_id);
478 if (NULL != config_info->setting) free(config_info->setting);
479 if (NULL != config_info->language) free(config_info->language);
487 int tts_parser_copy_xml(const char* original, const char* destination)
489 if (NULL == original || NULL == destination) {
490 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
494 xmlDocPtr doc = NULL;
495 doc = xmlParseFile(original);
497 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", original);
501 int ret = xmlSaveFile(destination, doc);
503 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
507 if (0 > chmod(destination, 0666)) {
508 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to change file mode : %d", ret);
512 SLOG(LOG_DEBUG, tts_tag(), "[SUCCESS] Copying xml");
517 int tts_parser_set_engine(const char* engine_id, const char* setting, const char* language, int type)
519 if (NULL == engine_id) {
520 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
524 xmlNodePtr cur = NULL;
525 cur = xmlDocGetRootElement(g_config_doc);
527 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
531 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
532 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
536 cur = cur->xmlChildrenNode;
538 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
542 while (cur != NULL) {
543 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_ID)) {
544 xmlNodeSetContent(cur, (const xmlChar *)engine_id);
547 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
548 xmlNodeSetContent(cur, (const xmlChar *)language);
551 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_ENGINE_SETTING)) {
552 xmlNodeSetContent(cur, (const xmlChar *)setting);
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;
560 default: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
567 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
569 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
575 int tts_parser_set_voice(const char* language, int type)
577 if (NULL == language) {
578 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
582 xmlNodePtr cur = NULL;
583 cur = xmlDocGetRootElement(g_config_doc);
585 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
589 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
590 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
594 cur = cur->xmlChildrenNode;
596 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
600 while (cur != NULL) {
601 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_LANGUAGE)) {
602 xmlNodeSetContent(cur, (const xmlChar *)language);
605 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_VOICE_TYPE)) {
607 case TTS_CONFIG_VOICE_TYPE_MALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_MALE); break;
608 case TTS_CONFIG_VOICE_TYPE_FEMALE: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE); break;
609 case TTS_CONFIG_VOICE_TYPE_CHILD: xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_CHILD); break;
611 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid type : %d", type);
612 xmlNodeSetContent(cur, (const xmlChar*)TTS_TAG_VOICE_TYPE_FEMALE);
620 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
622 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
628 int tts_parser_set_auto_voice(bool value)
630 xmlNodePtr cur = NULL;
631 cur = xmlDocGetRootElement(g_config_doc);
633 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
637 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
638 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
642 cur = cur->xmlChildrenNode;
644 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
648 while (cur != NULL) {
649 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_AUTO_VOICE)) {
651 xmlNodeSetContent(cur, (const xmlChar *)"on");
652 } else if (false == value) {
653 xmlNodeSetContent(cur, (const xmlChar *)"off");
655 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong value of auto voice");
663 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
665 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
671 int tts_parser_set_speech_rate(int value)
673 xmlNodePtr cur = NULL;
674 cur = xmlDocGetRootElement(g_config_doc);
676 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
680 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
681 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
685 cur = cur->xmlChildrenNode;
687 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
691 while (cur != NULL) {
692 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_SPEECH_RATE)) {
694 memset(temp, '\0', 10);
695 snprintf(temp, 10, "%d", value);
697 xmlNodeSetContent(cur, (const xmlChar *)temp);
699 SLOG(LOG_DEBUG, tts_tag(), "Set speech rate : %s", temp);
706 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
708 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
714 int tts_parser_set_pitch(int value)
716 xmlNodePtr cur = NULL;
717 cur = xmlDocGetRootElement(g_config_doc);
719 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
723 if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
724 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
728 cur = cur->xmlChildrenNode;
730 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
734 while (cur != NULL) {
735 if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_PITCH)) {
737 memset(temp, '\0', 10);
738 snprintf(temp, 10, "%d", value);
739 xmlNodeSetContent(cur, (const xmlChar *)temp);
746 int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
748 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Save result : %d", ret);
754 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type,
755 int* speech_rate, int* pitch)
757 if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
758 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is NULL");
762 xmlDocPtr doc = NULL;
763 xmlNodePtr cur_new = NULL;
764 xmlNodePtr cur_old = NULL;
770 while (NULL == doc) {
771 doc = xmlParseFile(TTS_CONFIG);
778 if (TTS_RETRY_COUNT == retry_count) {
779 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to parse file error : %s", TTS_CONFIG);
784 cur_new = xmlDocGetRootElement(doc);
785 cur_old = xmlDocGetRootElement(g_config_doc);
786 if (cur_new == NULL || cur_old == NULL) {
787 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
793 if (xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG) ||
794 xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BASE_TAG)) {
795 SLOG(LOG_ERROR, tts_tag(), "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
801 cur_new = cur_new->xmlChildrenNode;
802 cur_old = cur_old->xmlChildrenNode;
803 if (cur_new == NULL || cur_old == NULL) {
804 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty document");
810 while (cur_new != NULL && cur_old != NULL) {
811 if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
812 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_ID)) {
813 key_old = xmlNodeGetContent(cur_old);
814 if (NULL != key_old) {
815 key_new = xmlNodeGetContent(cur_new);
816 if (NULL != key_new) {
817 if (0 != xmlStrcmp(key_old, key_new)) {
818 SLOG(LOG_DEBUG, tts_tag(), "Old engine id(%s), New engine(%s)",
819 (char*)key_old, (char*)key_new);
820 if (NULL != *engine) free(*engine);
821 *engine = strdup((char*)key_new);
828 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
830 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
831 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_ENGINE_SETTING)) {
832 key_old = xmlNodeGetContent(cur_old);
833 if (NULL != key_old) {
834 key_new = xmlNodeGetContent(cur_new);
835 if (NULL != key_new) {
836 if (0 != xmlStrcmp(key_old, key_new)) {
837 SLOG(LOG_DEBUG, tts_tag(), "Old engine setting(%s), New engine setting(%s)",
838 (char*)key_old, (char*)key_new);
839 if (NULL != *setting) free(*setting);
840 *setting = strdup((char*)key_new);
847 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
849 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
850 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_AUTO_VOICE)) {
851 key_old = xmlNodeGetContent(cur_old);
852 if (NULL != key_old) {
853 key_new = xmlNodeGetContent(cur_new);
854 if (NULL != key_new) {
855 if (0 != xmlStrcmp(key_old, key_new)) {
856 SLOG(LOG_DEBUG, tts_tag(), "Old auto voice (%s), New auto voice(%s)",
857 (char*)key_old, (char*)key_new);
858 if (0 == xmlStrcmp((const xmlChar*)"on", key_new)) {
869 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
871 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
872 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_LANGUAGE)) {
873 key_old = xmlNodeGetContent(cur_old);
874 if (NULL != key_old) {
875 key_new = xmlNodeGetContent(cur_new);
876 if (NULL != key_new) {
877 if (0 != xmlStrcmp(key_old, key_new)) {
878 SLOG(LOG_DEBUG, tts_tag(), "Old language(%s), New language(%s)",
879 (char*)key_old, (char*)key_new);
880 if (NULL != *language) free(*language);
881 *language = strdup((char*)key_new);
888 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
890 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
891 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_VOICE_TYPE)) {
892 key_old = xmlNodeGetContent(cur_old);
893 if (NULL != key_old) {
894 key_new = xmlNodeGetContent(cur_new);
895 if (NULL != key_new) {
896 if (0 != xmlStrcmp(key_old, key_new)) {
897 SLOG(LOG_DEBUG, tts_tag(), "Old voice type(%s), New voice type(%s)",
898 (char*)key_old, (char*)key_new);
899 if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_FEMALE)) {
900 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_FEMALE;
901 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_MALE)) {
902 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_MALE;
903 } else if (0 == xmlStrcmp(key_new, (const xmlChar *)TTS_TAG_VOICE_TYPE_CHILD)) {
904 *voice_type = (int)TTS_CONFIG_VOICE_TYPE_CHILD;
906 SLOG(LOG_ERROR, tts_tag(), "[ERROR] New voice type is not valid");
914 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
916 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
917 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_SPEECH_RATE)) {
918 key_old = xmlNodeGetContent(cur_old);
919 if (NULL != key_old) {
920 key_new = xmlNodeGetContent(cur_new);
921 if (NULL != key_new) {
922 if (0 != xmlStrcmp(key_old, key_new)) {
923 SLOG(LOG_DEBUG, tts_tag(), "Old speech rate(%s), New speech rate(%s)",
924 (char*)key_old, (char*)key_new);
925 *speech_rate = atoi((char*)key_new);
932 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
934 } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
935 if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_PITCH)) {
936 key_old = xmlNodeGetContent(cur_old);
937 if (NULL != key_old) {
938 key_new = xmlNodeGetContent(cur_new);
939 if (NULL != key_new) {
940 if (0 != xmlStrcmp(key_old, key_new)) {
941 SLOG(LOG_DEBUG, tts_tag(), "Old pitch(%s), New pitch(%s)",
942 (char*)key_old, (char*)key_new);
943 *pitch = atoi((char*)key_new);
950 SLOG(LOG_ERROR, tts_tag(), "[ERROR] old config and new config are different");
956 cur_new = cur_new->next;
957 cur_old = cur_old->next;
960 if (NULL != g_config_doc) {
961 xmlFreeDoc(g_config_doc);