}
}
- if (0 != access(TTS_DOWNLOAD_PERSONAL_INFO, F_OK)) {
- if (0 != mkdir(TTS_DOWNLOAD_PERSONAL_INFO, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to make directory : %s", TTS_DOWNLOAD_PERSONAL_INFO);
- release_config_client(uid);
- return TTS_CONFIG_ERROR_OPERATION_FAILED;
- } else {
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Success to make directory : %s", TTS_DOWNLOAD_PERSONAL_INFO);
- }
- }
-
SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type : %d", client_type);
g_client_type |= client_type;
return ret;
}
-
-int tts_config_mgr_update_personal_voice(const char* engine_id, const char* language, const char* unique_id, const char* display_name, const char* device_name)
-{
- char* default_engine = get_default_engine_app_id();
- // tts_engine_info_s *engine_info = __get_engine_info(default_engine);
- // free(default_engine);
- // if (NULL == engine_info) {
- // SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] engine info is NULL");
- // return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
- // }
-
- engine_id = strdup(default_engine);
-
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] engine id = %s", engine_id);
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] language(%s), unique_id(%s), display_name(%s), device_name(%s)", language, unique_id, display_name, device_name);
- if (NULL == engine_id || NULL == language || NULL == unique_id || NULL == display_name || NULL == device_name) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input Parameter is null");
- return TTS_CONFIG_ERROR_INVALID_PARAMETER;
- }
-
- char filepath[512] = {'\0',};
-
- memset(filepath, '\0', 512);
- snprintf(filepath, 512, "%s/%s-%s", TTS_DOWNLOAD_PERSONAL_INFO, engine_id, "personal.xml");
-
- SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[CONFIG] Filepath(%s)", filepath);
-
- if (0 != tts_parser_update_personal_info(filepath, engine_id, language, unique_id, display_name, device_name)) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to update personal info xml");
- return -1;
- }
-
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Finish update personal info");
- tts_personal_info_s* info = NULL;
- int ret = tts_parser_get_personal_info(filepath, &info);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get personal info");
- return -1;
- }
-
- return 0;
-}
#include <sys/stat.h>
#include <unistd.h>
#include <vconf.h>
-#include <errno.h>
#include "tts_config_parser.h"
#include "tts_defs.h"
#define TTS_TAG_VOICE_TYPE_MALE "male"
#define TTS_TAG_VOICE_TYPE_CHILD "child"
-#define TTS_TAG_PERSONAL_BASE_TAG "tts-personal-voice"
-#define TTS_TAG_PERSONAL_VOICE_SET "personal-voices"
-#define TTS_TAG_PERSONAL_VOICE "personal-voice"
-#define TTS_TAG_PERSONAL_VOICE_LANGUAGE "language"
-#define TTS_TAG_PERSONAL_VOICE_UNIQUE_ID "unique-id"
-#define TTS_TAG_PERSONAL_VOICE_DISPLAY_NAME "display-name"
-#define TTS_TAG_PERSONAL_VOICE_DEVICE_NAME "device-name"
-#define TTS_TAG_PERSONAL_VOICE_ENGINE_ID "id"
-
#define TTS_MAX_TEXT_SIZE 2000
#define VOLUME_BASE_VALUE 100.0
char g_setting[128] = {0,};
char g_language[128] = {0,};
-static xmlDocPtr g_personal_info_doc = NULL;
-
static tts_config_s* g_config_info = NULL;
static pthread_mutex_t g_config_info_mutex = PTHREAD_MUTEX_INITIALIZER;
-int __create_personal_info_xml(const char* engine_id, const char* language, const char* unique_id, const char* display_name, const char* device_name)
-{
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@ Create personal info doc");
- g_personal_info_doc = xmlNewDoc((xmlChar*)"1.0");
- if (NULL == g_personal_info_doc) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to new doc");
- return -1;
- }
- xmlNodePtr root = NULL;
- xmlNodePtr cur = NULL;
-
- root = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_BASE_TAG);
- if (NULL == root) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get new node");
- return -1;
- }
-
- xmlDocSetRootElement(g_personal_info_doc, root);
-
- xmlNodePtr node = NULL;
- xmlNodePtr personal_voice_node = NULL;
-
- node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_SET);
-
- personal_voice_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE);
-
- cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_LANGUAGE);
- xmlNodeSetContent(cur, (const xmlChar*)language);
- xmlAddChild(personal_voice_node, cur);
-
- cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_UNIQUE_ID);
- xmlNodeSetContent(cur, (const xmlChar*)unique_id);
- xmlAddChild(personal_voice_node, cur);
-
- cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_DISPLAY_NAME);
- xmlNodeSetContent(cur, (const xmlChar*)display_name);
- xmlAddChild(personal_voice_node, cur);
-
- cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_DEVICE_NAME);
- xmlNodeSetContent(cur, (const xmlChar*)device_name);
- xmlAddChild(personal_voice_node, cur);
-
- xmlAddChild(node, personal_voice_node);
- xmlAddChild(root, node);
-
- node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_ENGINE_ID);
- xmlNodeSetContent(node, (const xmlChar*)engine_id);
- xmlAddChild(root, node);
-
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Finish to create personal voice info");
-
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@");
- return 0;
-}
-
-int tts_parser_update_personal_info(const char* path, const char* engine_id, const char* language, const char* unique_id, const char* display_name, const char* device_name)
-{
- if (NULL == path) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
- return -1;
- }
-
- if (0 == access(path, F_OK)) {
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", path);
-
- xmlNodePtr cur = NULL;
-
- g_personal_info_doc = xmlParseFile(path);
- if (g_personal_info_doc == NULL) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse xml file");
- return -1;
- }
- cur = xmlDocGetRootElement(g_personal_info_doc);
- if (cur == NULL) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, g_personal_info_doc);
- xmlFreeDoc(g_personal_info_doc);
- g_personal_info_doc = NULL;
- return -1;
- }
-
- if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_PERSONAL_BASE_TAG)) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT 'tts-personal-info'. doc path(%s, %p)", path, g_personal_info_doc);
- xmlFreeDoc(g_personal_info_doc);
- g_personal_info_doc = NULL;
- return -1;
- }
-
- cur = cur->xmlChildrenNode; // TTS_TAG_PERSONAL_VOICE_SET
- if (cur == NULL) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, g_personal_info_doc);
- xmlFreeDoc(g_personal_info_doc);
- g_personal_info_doc = NULL;
- return -1;
- }
-
- while (cur != NULL) {
- if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_PERSONAL_VOICE_SET)) {
- xmlNodePtr personal_voice_node = NULL;
- personal_voice_node = xmlNewNode(NULL, (const xmlChar *)TTS_TAG_PERSONAL_VOICE);
-
- xmlNodePtr info_node = NULL;
- info_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_LANGUAGE);
- xmlNodeSetContent(info_node, (const xmlChar*)language);
- xmlAddChild(personal_voice_node, info_node);
-
- info_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_UNIQUE_ID);
- xmlNodeSetContent(info_node, (const xmlChar*)unique_id);
- xmlAddChild(personal_voice_node, info_node);
-
- info_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_DISPLAY_NAME);
- xmlNodeSetContent(info_node, (const xmlChar*)display_name);
- xmlAddChild(personal_voice_node, info_node);
-
- info_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_PERSONAL_VOICE_DEVICE_NAME);
- xmlNodeSetContent(info_node, (const xmlChar*)device_name);
- xmlAddChild(personal_voice_node, info_node);
-
- xmlAddChild(cur, personal_voice_node);
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Finish to add personal voice info");
- // break;
- }
- cur = cur->next;
- }
- } else {
- switch (errno) {
- case ENOENT:
- SLOG(LOG_INFO, TAG_TTSCONFIG, "[INFO] No such file or directory. Create new personal info.");
- int ret = __create_personal_info_xml(engine_id, language, unique_id, display_name, device_name);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to create new personal info");
- return -1;
- }
- SLOG(LOG_INFO, TAG_TTSCONFIG, "[INFO] Success to create new personal info");
- break;
- default:
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s (%d)", path, errno);
- return -1;
- }
- }
-
- int ret = xmlSaveFormatFile(path, g_personal_info_doc, 1);
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "xmlSaveFile to path(%s) (%d)", path, ret);
- if (0>ret) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
- } else {
- static FILE* pFile;
- pFile = fopen(path, "r");
- int fd = -1;
- if (NULL == pFile) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", path);
- } else {
- fd = fileno(pFile);
- fsync(fd);
- fclose(pFile);
- SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", path);
- }
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", path);
- }
-
- /* Set mode */
- if (0 > chmod(path, 0664)) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to change file mode : %d", ret);
- }
-
- if (NULL != g_personal_info_doc) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] doc path(%p)", g_personal_info_doc);
- xmlFreeDoc(g_personal_info_doc);
- g_personal_info_doc = NULL;
- }
-
- return 0;
-}
-
-int tts_parser_get_personal_info(const char* path, tts_personal_info_s** personal_info)
-{
- if (NULL == path || NULL == personal_info) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
- return -1;
- }
-
- xmlDocPtr doc = NULL;
- xmlNodePtr cur = NULL;
-
- if (0 == access(path, F_OK)) {
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] Success to access to %s", path);
- doc = xmlParseFile(path);
- if (doc == NULL) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse xml file. errno(%d)", errno);
- return -1;
- }
- } else {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s (%d)", path, errno);
- return -1;
- }
-
- cur = xmlDocGetRootElement(doc);
- if (cur == NULL) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc);
- xmlFreeDoc(doc);
- doc = NULL;
- return -1;
- }
-
- if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_PERSONAL_BASE_TAG)) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT 'tts-personal-voice'. doc path(%s, %p)", path, doc);
- xmlFreeDoc(doc);
- doc = NULL;
- return -1;
- }
-
- cur = cur->xmlChildrenNode; // tts_tag_personal_voice_set
- if (cur == NULL) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document. doc path(%s, %p)", path, doc);
- xmlFreeDoc(doc);
- doc = NULL;
- return -1;
- }
-
- /* alloc personal info */
- tts_personal_info_s* temp;
- temp = (tts_personal_info_s*)calloc(1, sizeof(tts_personal_info_s));
- if (NULL == temp) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory. doc path(%s, %p)", path, doc);
- xmlFreeDoc(doc);
- doc = NULL;
- return -1;
- }
-
- temp->engine_id = NULL;
- temp->personal_voices = NULL;
-
- while (cur != NULL) {
- if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_PERSONAL_VOICE_SET)) {
- xmlNodePtr personal_voice_node = NULL;
- personal_voice_node = cur->xmlChildrenNode;
-
- while (NULL != personal_voice_node) {
- if (0 == xmlStrcmp(personal_voice_node->name, (const xmlChar *)TTS_TAG_PERSONAL_VOICE)) {
- xmlNodePtr info_node = NULL;
- info_node = personal_voice_node->xmlChildrenNode;
-
- tts_config_personal_s* temp_personal_voice = (tts_config_personal_s*)calloc(1, sizeof(tts_config_personal_s));
- if (NULL == temp_personal_voice) {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory");
- break;
- }
-
- while (NULL != info_node) {
- if (0 == xmlStrcmp(info_node->name, (const xmlChar *)TTS_TAG_PERSONAL_VOICE_LANGUAGE)) {
- xmlChar *key = xmlNodeGetContent(info_node);
- if (NULL != key) {
- if (NULL != temp_personal_voice->language) {
- free(temp_personal_voice->language);
- temp_personal_voice->language = NULL;
- }
- temp_personal_voice->language = strdup((char*)key);
- xmlFree(key);
- key = NULL;
- } else {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_PERSONAL_VOICE_LANGUAGE);
- }
- } else if (0 == xmlStrcmp(info_node->name, (const xmlChar *)TTS_TAG_PERSONAL_VOICE_UNIQUE_ID)) {
- xmlChar *key = xmlNodeGetContent(info_node);
- if (NULL != key) {
- if (NULL != temp_personal_voice->unique_id) {
- free(temp_personal_voice->unique_id);
- temp_personal_voice->unique_id = NULL;
- }
- temp_personal_voice->unique_id = strdup((char*)key);
- xmlFree(key);
- key = NULL;
- } else {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_PERSONAL_VOICE_UNIQUE_ID);
- }
- } else if (0 == xmlStrcmp(info_node->name, (const xmlChar *)TTS_TAG_PERSONAL_VOICE_DISPLAY_NAME)) {
- xmlChar *key = xmlNodeGetContent(info_node);
- if (NULL != key) {
- if (NULL != temp_personal_voice->display_name) {
- free(temp_personal_voice->display_name);
- temp_personal_voice->display_name = NULL;
- }
- temp_personal_voice->display_name = strdup((char*)key);
- xmlFree(key);
- key = NULL;
- } else {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_PERSONAL_VOICE_DISPLAY_NAME);
- }
- } else if (0 == xmlStrcmp(info_node->name, (const xmlChar *)TTS_TAG_PERSONAL_VOICE_DEVICE_NAME)) {
- xmlChar *key = xmlNodeGetContent(info_node);
- if (NULL != key) {
- if (NULL != temp_personal_voice->device_name) {
- free(temp_personal_voice->device_name);
- temp_personal_voice->device_name = NULL;
- }
- temp_personal_voice->device_name = strdup((char*)key);
- xmlFree(key);
- key = NULL;
- } else {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_PERSONAL_VOICE_DEVICE_NAME);
- }
- }
- info_node = info_node->next;
- }
-
- temp->personal_voices = g_slist_append(temp->personal_voices, temp_personal_voice);
- }
- personal_voice_node = personal_voice_node->next;
- }
- } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_PERSONAL_VOICE_ENGINE_ID)) {
- xmlChar *key = xmlNodeGetContent(cur);
- if (NULL != key) {
- if (NULL != temp->engine_id) {
- free(temp->engine_id);
- temp->engine_id = NULL;
- }
- temp->engine_id = strdup((char*)key);
- xmlFree(key);
- key = NULL;
- } else {
- SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] <%s> has no content", TTS_TAG_PERSONAL_VOICE_ENGINE_ID);
- }
- }
- cur = cur->next;
- }
-
- if (NULL != doc) {
- SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[DEBUG] doc path(%s, %p)", path, doc);
- xmlFreeDoc(doc);
- doc = NULL;
- }
-
- if (NULL == temp->engine_id) {
- /* Invalid engine */
- SECURE_SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Invalid engine : %s", path);
- // free personal info
- return -1;
- }
-
- *personal_info = temp;
-
- return 0;
-
-}
-
int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info)
{
if (NULL == path || NULL == engine_info) {