Change internal function to static
[platform/core/uifw/tts.git] / engine-parser / src / tts-engine-parser.c
index 53c3e41..0f6c34d 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <fcntl.h>
 #include <tzplatform_config.h>
 #include <systemd/sd-login.h>
 
 #define TTS_TAG_ENGINE_VOICE_TYPE              "type"
 #define TTS_TAG_ENGINE_PITCH_SUPPORT           "pitch-support"
 #define TTS_TAG_ENGINE_CREDENTIAL              "credential"
+#define TTS_TAG_ENGINE_TEXT_SIZE               "text-size"
 
-#define TTS_CONFIG_BASE                tzplatform_mkpath(TZ_USER_HOME, "share/.voice")
-#define TTS_HOME               tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts")
-#define TTS_ENGINE_BASE                tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts/1.0")
-#define TTS_ENGINE_INFO                tzplatform_mkpath(TZ_USER_SHARE, ".voice/tts/1.0/engine-info")
+#define TTS_TAG_VOICE_BASE                     "tts-voice"
+
+#define TTS_CONFIG_BASE                tzplatform_mkpath(tzplatform_getid("TZ_USER_HOME"), "share/.voice")
+#define TTS_HOME               tzplatform_mkpath(tzplatform_getid("TZ_USER_HOME"), "share/.voice/tts")
+#define TTS_ENGINE_BASE                tzplatform_mkpath(tzplatform_getid("TZ_USER_HOME"), "share/.voice/tts/1.0")
+#define TTS_ENGINE_INFO                tzplatform_mkpath(tzplatform_getid("TZ_USER_SHARE"), ".voice/tts/1.0/engine-info")
+
+#define TTS_VOICE_INFO tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_SHARE"), "voice/tts/1.0/tts-voice.xml")
 
 #define TTS_GLOBAL_CONFIG_BASE         "/etc/skel/share/.voice"
 #define TTS_GLOBAL_HOME                "/etc/skel/share/.voice/tts"
 #define TTS_GLOBAL_ENGINE_BASE         "/etc/skel/share/.voice/tts/1.0"
 #define TTS_GLOBAL_ENGINE_INFO         "/etc/skel/share/.voice/tts/1.0/engine-info"
 
+#define TTS_METADATA_NAME                      "http://tizen.org/metadata/tts-engine/name"
 #define TTS_METADATA_LANGUAGE                  "http://tizen.org/metadata/tts-engine/language"
 #define TTS_METADATA_CREDENTIAL_REQUIRED       "http://tizen.org/metadata/tts-engine/credential-required"
+#define TTS_METADATA_SETTING           "http://tizen.org/metadata/tts-engine/setting"
+#define TTS_METADATA_TEXT_SIZE         "http://tizen.org/metadata/tts-engine/text-size"
+#define TTS_METADATA_PITCH_SUPPORT     "http://tizen.org/metadata/tts-engine/pitch-support"
 
+#define TTS_MAX_TEXT_SIZE      "2000"
+
+/* Define Macro */
+#define FREE(x)        { if (NULL != x)        { free(x);      x = NULL; } }
+#define G_FREE(x)      { if (NULL != x) { g_free(x);   x = NULL; } }
 
 typedef struct metadata {
        const char *key;
        const char *value;
 } metadata;
 
+typedef struct {
+       char *lang;
+       char *type;
+} voice_info_s;
+
+typedef struct {
+       voice_info_s *voice_info;
+       int size;
+} voice_info_list_s;
+
 static xmlDocPtr g_doc;
 GumUser *g_guser = NULL;
 uid_t g_uid = 301;     // app_fw
@@ -83,21 +108,23 @@ char *g_dir_home = NULL;
 char *g_dir_engine_base = NULL;
 char *g_dir_engine_info = NULL;
 
+GSList *g_voice_info_list = NULL;
+
 static int __create_engine_info_xml(const char *pkgid)
 {
-       LOGD("=== Create engine info doc");
+       LOGD("@@@ Create engine info doc");
        g_doc = xmlNewDoc((xmlChar*)"1.0");
        if (NULL == g_doc) {
                LOGE("[ERROR] Fail to new doc");
                return -1;
        }
-       LOGD("===");
+       LOGD("@@@");
        return 0;
 }
 
 static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t gid)
 {
-       LOGD("=== Save engine info doc");
+       LOGD("@@@ Save engine info doc");
        char *dir_config_base = NULL;
        char *dir_home = NULL;
        char *dir_engine_base = NULL;
@@ -138,22 +165,11 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
 
        if (NULL == dir_config_base || NULL == dir_home || NULL == dir_engine_base || NULL == dir_engine_info) {
                LOGE("[ERROR] Fail to allocate memory");
-               if (NULL != dir_config_base) {
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-               }
-               if (NULL != dir_home) {
-                       free(dir_home);
-                       dir_home = NULL;
-               }
-               if (NULL != dir_engine_base) {
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-               }
-               if (NULL != dir_engine_info) {
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
-               }
+               FREE(dir_config_base)
+               FREE(dir_home)
+               FREE(dir_engine_base)
+               FREE(dir_engine_info)
+
                return -1;
        }
 
@@ -161,92 +177,97 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
 
 
        /* Make directories */
-       if (0 != access(dir_config_base, F_OK)) {
+       int fd = -1;
+//     if (0 != access(dir_config_base, F_OK)) {
+       fd = open(dir_config_base, O_DIRECTORY);
+       if (-1 == fd) {
+               LOGE("[INFO] No directory : %s, errno : %d", dir_config_base, errno);
                if (0 != mkdir(dir_config_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", dir_config_base);
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-                       free(dir_home);
-                       dir_home = NULL;
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_config_base, errno);
+                       FREE(dir_config_base)
+                       FREE(dir_home)
+                       FREE(dir_engine_base)
+                       FREE(dir_engine_info)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_config_base);
                        if (0 != chown(dir_config_base, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
-       if (0 != access(dir_home, F_OK)) {
+//     if (0 != access(dir_home, F_OK)) {
+       fd = open(dir_home, O_DIRECTORY);
+       if (-1 == fd) {
+               LOGE("[INFO] No directory : %s, errno : %d", dir_home, errno);
                if (0 != mkdir(dir_home, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", dir_home);
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-                       free(dir_home);
-                       dir_home = NULL;
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_home, errno);
+                       FREE(dir_config_base)
+                       FREE(dir_home)
+                       FREE(dir_engine_base)
+                       FREE(dir_engine_info)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_home);
                        if (0 != chown(dir_home, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
-       if (0 != access(dir_engine_base, F_OK)) {
+//     if (0 != access(dir_engine_base, F_OK)) {
+       fd = open(dir_engine_base, O_DIRECTORY);
+       if (-1 == fd) {
+               LOGE("[INFO] No directory : %s, errno : %d", dir_engine_base, errno);
                if (0 != mkdir(dir_engine_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", dir_engine_base);
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-                       free(dir_home);
-                       dir_home = NULL;
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_base, errno);
+                       FREE(dir_config_base)
+                       FREE(dir_home)
+                       FREE(dir_engine_base)
+                       FREE(dir_engine_info)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_engine_base);
                        if (0 != chown(dir_engine_base, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
-       if (0 != access(dir_engine_info, F_OK)) {
+//     if (0 != access(dir_engine_info, F_OK)) {
+       fd = open(dir_engine_info, O_DIRECTORY);
+       if (-1 == fd) {
+               LOGE("[INFO] No directory : %s, errno : %d", dir_engine_info, errno);
                if (0 != mkdir(dir_engine_info, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", dir_engine_info);
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-                       free(dir_home);
-                       dir_home = NULL;
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_info, errno);
+                       FREE(dir_config_base)
+                       FREE(dir_home)
+                       FREE(dir_engine_base)
+                       FREE(dir_engine_info)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_engine_info);
                        if (0 != chown(dir_engine_info, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
 
@@ -262,22 +283,18 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                }
        }
 
-       free(dir_config_base);
-       dir_config_base = NULL;
-       free(dir_home);
-       dir_home = NULL;
-       free(dir_engine_base);
-       dir_engine_base = NULL;
-       free(dir_engine_info);
-       dir_engine_info = NULL;
+       FREE(dir_config_base)
+       FREE(dir_home)
+       FREE(dir_engine_base)
+       FREE(dir_engine_info)
 
-       LOGD("===");
+       LOGD("@@@");
        return 0;
 }
 
 static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
 {
-       LOGD("=== Remove engine info doc");
+       LOGD("@@@ Remove engine info doc");
 
        char *dir_engine_info = NULL;
 
@@ -316,19 +333,22 @@ static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
                }
        }
 
-       free(dir_engine_info);
-       dir_engine_info = NULL;
+       FREE(dir_engine_info)
 
-       LOGD("===");
+       LOGD("@@@");
        return 0;
 }
 
 static void __insert_language_from_metadata(xmlNodePtr root, const char *language)
 {
-       LOGD("==== Insert language");
+       LOGD("@@@ Insert language");
        char* voice = NULL;
        char* lang = NULL;
        char* type = NULL;
+       if (NULL == root || NULL == language) {
+               LOGE("Invalid parameter, root(%p), language(%s)", root, language);
+               return;
+       }
 
        char *tmp_lang = NULL;
        char *tmp_free = NULL;
@@ -355,10 +375,154 @@ static void __insert_language_from_metadata(xmlNodePtr root, const char *languag
                xmlAddChild(voices_node, voice_node);
                voice = strsep(&tmp_lang, ",");
        }
+
+       /* add extra voices */
+       LOGD("Add extra voices");
+       if (NULL != g_voice_info_list) {
+               GSList *iter;
+               voice_info_s *extra_voice = NULL;
+               for (iter = g_voice_info_list ; iter != NULL ; iter = g_slist_next(iter)) {
+                       extra_voice = (voice_info_s*)iter->data;
+                       if (NULL != extra_voice) {
+                               lang = strdup(extra_voice->lang);
+                               type = strdup(extra_voice->type);
+                               LOGD("lang(%s), type(%s)", lang, type);
+
+                               if (NULL != lang) {
+                                       voice_node = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_VOICE);
+                                       xmlSetProp(voice_node, (const xmlChar*)TTS_TAG_ENGINE_VOICE_TYPE, (const xmlChar*)type);
+                                       xmlNodeSetContent(voice_node, (const xmlChar*)lang);
+                                       xmlAddChild(voices_node, voice_node);
+                               }
+
+                               LOGD("Finish to add voice node");
+
+                               if (NULL != lang) {
+                                       free(lang);
+                               }
+                               if (NULL != type) {
+                                       free(type);
+                               }
+                               LOGD("Memory release");
+
+                               if (NULL != extra_voice->lang) {
+                                       free(extra_voice->lang);
+                               }
+                               if (NULL != extra_voice->type) {
+                                       free(extra_voice->type);
+                               }
+                               LOGD("Free extra_voice");
+                               free(extra_voice);
+                               extra_voice = NULL;
+                       }
+               }
+
+               LOGD("Free voice info list");
+               g_slist_free(g_voice_info_list);
+               g_voice_info_list = NULL;
+       }
+
        xmlAddChild(root, voices_node);
 
-       free(tmp_free);
-       tmp_free = NULL;
+       FREE(tmp_free)
+}
+
+static int __get_voice_inxml()
+{
+       xmlDocPtr doc = NULL;
+       xmlNodePtr cur = NULL;
+
+       LOGD("TTS voice info xml (%s)", TTS_VOICE_INFO);
+
+       if (0 != access(TTS_VOICE_INFO, F_OK)) {
+               LOGD("There is no extra voice info.");
+               return 0;
+       } else {
+               doc = xmlParseFile(TTS_VOICE_INFO);
+               if (NULL == doc) {
+                       LOGE("Fail to parse file");
+                       return -1;
+               }
+
+               cur = xmlDocGetRootElement(doc);
+               if (NULL == cur) {
+                       LOGE("Empty document");
+                       xmlFreeDoc(doc);
+                       return -1;
+               }
+
+               if (xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_VOICE_BASE)) {
+                       LOGE("root node is NOT %s", TTS_TAG_VOICE_BASE);
+                       xmlFreeDoc(doc);
+                       return -1;
+               }
+
+               cur = cur->xmlChildrenNode;
+               if (NULL == cur) {
+                       LOGE("<tts-voice> child NULL");
+                       xmlFreeDoc(doc);
+                       return -1;
+               }
+
+               xmlChar *attr = NULL;
+               xmlChar *key = NULL;
+//             char lang[16];
+//             char type[16];
+
+               while (NULL != cur) {
+                       if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE_SET)) {
+                               LOGD("<voices>");
+                               xmlNodePtr voice_node = NULL;
+                               voice_node = cur->xmlChildrenNode;
+
+                               while (NULL != voice_node) {
+                                       if (0 == xmlStrcmp(voice_node->name, (const xmlChar *)TTS_TAG_ENGINE_VOICE)) {
+                                               voice_info_s *voice_info = (voice_info_s *)calloc(1, sizeof(voice_info_s));
+                                               if (NULL == voice_info) {
+                                                       LOGE("Fail to allocate memory");
+                                                       xmlFreeDoc(doc);
+                                                       return -1;
+                                               }
+
+                                               LOGD("Get property and keys");
+                                               attr = xmlGetProp(voice_node, (const xmlChar *)TTS_TAG_ENGINE_VOICE_TYPE);
+                                               if (NULL != attr) {
+//                                                     strncpy(type, (char*)attr, strlen((char*)attr));
+                                                       voice_info->type = strdup((char*)attr);
+                                                       LOGD("type(%s)", voice_info->type);
+                                                       xmlFree(attr);
+                                                       attr = NULL;
+                                               } else {
+                                                       LOGD("No voice type");
+                                               }
+
+                                               key = xmlNodeGetContent(voice_node);
+                                               if (NULL != key) {
+//                                                     strncpy(lang, (char*)key, strlen((char*)key));
+                                                       voice_info->lang = strdup((char*)key);
+                                                       LOGD("lang(%s)", voice_info->lang);
+                                                       xmlFree(key);
+                                                       key = NULL;
+                                               } else {
+                                                       LOGD("No voice info");
+                                               }
+
+                                               g_voice_info_list = g_slist_append(g_voice_info_list, voice_info);
+                                       }
+
+                                       voice_node = voice_node->next;
+                               }
+                       } else {
+                               LOGD("Unknown tag (%s)", (const char*)cur->name);
+                       }
+
+                       cur = cur->next;
+               }
+
+               xmlFreeDoc(doc);
+       }
+
+       return 0;
 }
 
 static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *list)
@@ -366,6 +530,8 @@ static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *l
        GList *iter = NULL;
        metadata *md = NULL;
 
+       bool isTextsize = false;
+
        __create_engine_info_xml(pkgid);
 
        xmlNodePtr root = NULL;
@@ -380,9 +546,9 @@ static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *l
        xmlDocSetRootElement(g_doc, root);
 
        /* Save name */
-       cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_NAME);
-       xmlNodeSetContent(cur, (const xmlChar*)pkgid);
-       xmlAddChild(root, cur);
+//     cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_NAME);
+//     xmlNodeSetContent(cur, (const xmlChar*)pkgid);
+//     xmlAddChild(root, cur);
 
 
        iter = g_list_first(list);
@@ -391,11 +557,29 @@ static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *l
                if (NULL != md && NULL != md->key) {
                        LOGD(" - key(%s) value(%s)", md->key, md->value);
                        if (!strcmp(md->key, TTS_METADATA_LANGUAGE)) {
+                               __get_voice_inxml();
                                __insert_language_from_metadata(root, md->value);
                        } else if (!strcmp(md->key, TTS_METADATA_CREDENTIAL_REQUIRED)) {
                                cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_CREDENTIAL);
                                xmlNodeSetContent(cur, (const xmlChar*)md->value);
                                xmlAddChild(root, cur);
+                       } else if (!strcmp(md->key, TTS_METADATA_SETTING)) {
+                               cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_SETTING);
+                               xmlNodeSetContent(cur, (const xmlChar*)md->value);
+                               xmlAddChild(root, cur);
+                       } else if (!strcmp(md->key, TTS_METADATA_NAME)) {
+                               cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_NAME);
+                               xmlNodeSetContent(cur, (const xmlChar*)md->value);
+                               xmlAddChild(root, cur);
+                       } else if (!strcmp(md->key, TTS_METADATA_TEXT_SIZE)) {
+                               cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_TEXT_SIZE);
+                               xmlNodeSetContent(cur, (const xmlChar*)md->value);
+                               xmlAddChild(root, cur);
+                               isTextsize = true;
+                       } else if (!strcmp(md->key, TTS_METADATA_PITCH_SUPPORT)) {
+                               cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_PITCH_SUPPORT);
+                               xmlNodeSetContent(cur, (const xmlChar*)md->value);
+                               xmlAddChild(root, cur);
                        } else {
                                LOGW("[WARNING] Unknown metadata type");
                        }
@@ -403,6 +587,13 @@ static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *l
                iter = g_list_next(iter);
        }
 
+       if (false == isTextsize) {
+               cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_TEXT_SIZE);
+               xmlNodeSetContent(cur, (const xmlChar*)TTS_MAX_TEXT_SIZE);
+               xmlAddChild(root, cur);
+               LOGD("[DEBUG] Max text size is set as %s.", TTS_MAX_TEXT_SIZE);
+       }
+
        cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_ID);
        xmlNodeSetContent(cur, (const xmlChar*)pkgid);
        xmlAddChild(root, cur);
@@ -458,7 +649,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                LOGE("[ERROR] Fail to get target uid");
                g_object_unref(g_guser);
                g_guser = NULL;
-               g_free(g_user_type);
+               G_FREE(g_user_type)
                return -1;
        }
 
@@ -467,14 +658,14 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                LOGD("[DEBUG] usertype: %s", g_user_type);
                if (0 >= g_list_length(list)) {
                        LOGE("[ERROR] No Engine Metadata");
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return 0;
                }
 
                if (0 != __write_metadata_inxml(pkgid, appid, list)) {
                        LOGE("[ERROR] Fail to write metadata in the xml");
                        xmlFreeDoc(g_doc);
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -486,31 +677,20 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
 
                if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
                        LOGE("[ERROR] Fail to allocate memory");
-                       if (NULL != g_dir_config_base) {
-                               free(g_dir_config_base);
-                               g_dir_config_base = NULL;
-                       }
-                       if (NULL != g_dir_home) {
-                               free(g_dir_home);
-                               g_dir_home = NULL;
-                       }
-                       if (NULL != g_dir_engine_base) {
-                               free(g_dir_engine_base);
-                               g_dir_engine_base = NULL;
-                       }
-                       if (NULL != g_dir_engine_info) {
-                               free(g_dir_engine_info);
-                               g_dir_engine_info = NULL;
-                       }
+                       FREE(g_dir_config_base)
+                       FREE(g_dir_home)
+                       FREE(g_dir_engine_base)
+                       FREE(g_dir_engine_info)
+
                        xmlFreeDoc(g_doc);
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
                if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
                        LOGE("[ERROR] Fail to make engine info file");
                        xmlFreeDoc(g_doc);
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -531,7 +711,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                gus = gum_user_service_create_sync(TRUE);
                if (!gus) {
                        LOGE("Failed to create gum user service");
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -541,11 +721,11 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                g_strfreev(query);
 
                if (!users) {
-                       LOGE("Failed to get gum user list");
+                       LOGD("NO users");
                        g_object_unref(gus);
                        gus = NULL;
-                       g_free(g_user_type);
-                       return -1;
+                       G_FREE(g_user_type)
+                       return 0;
                }
 
                /* Make new user list */
@@ -554,16 +734,15 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                while (iter != NULL) {
                        user = (GumUser*) iter->data;
                        g_object_get(G_OBJECT(user), "uid", &uid, NULL);
-                       if (NULL != home_dir) {
-                               free(home_dir);
-                               home_dir = NULL;
-                       }
+                       G_FREE(home_dir)
+
                        g_object_get(G_OBJECT(user), "gid", &gid, NULL);
                        g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
                        g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
                        user_type = g_strdup(gum_user_type_to_string(gumut));
                        if (NULL == user_type) {
                                gum_user_service_list_free(users);
+                               G_FREE(home_dir)
                                g_object_unref(gus);
                                gus = NULL;
                                return -1;
@@ -580,25 +759,15 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
 
                                if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
                                        LOGE("[ERROR] Fail to allocate memory");
-                                       if (NULL != g_dir_config_base) {
-                                               free(g_dir_config_base);
-                                               g_dir_config_base = NULL;
-                                       }
-                                       if (NULL != g_dir_home) {
-                                               free(g_dir_home);
-                                               g_dir_home = NULL;
-                                       }
-                                       if (NULL != g_dir_engine_base) {
-                                               free(g_dir_engine_base);
-                                               g_dir_engine_base = NULL;
-                                       }
-                                       if (NULL != g_dir_engine_info) {
-                                               free(g_dir_engine_info);
-                                               g_dir_engine_info = NULL;
-                                       }
+                                       FREE(g_dir_config_base)
+                                       FREE(g_dir_home)
+                                       FREE(g_dir_engine_base)
+                                       FREE(g_dir_engine_info)
                                        gum_user_service_list_free(users);
                                        g_object_unref(gus);
                                        gus = NULL;
+                                       G_FREE(user_type)
+                                       G_FREE(home_dir)
                                        return -1;
                                }
                                snprintf(g_dir_config_base, strlen(home_dir) + 14, "%s/share/.voice", home_dir);
@@ -612,29 +781,16 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                                        LOGE("[ERROR] Fail to make engine info file");
                                }
 
-                               free(g_dir_config_base);
-                               g_dir_config_base = NULL;
-                               free(g_dir_home);
-                               g_dir_home = NULL;
-                               free(g_dir_engine_base);
-                               g_dir_engine_base = NULL;
-                               free(g_dir_engine_info);
-                               g_dir_engine_info = NULL;
-
-                               g_free(user_type);
-                               user_type = NULL;
-                               free(home_dir);
-                               home_dir = NULL;
-
-                               iter = g_list_next(iter);
-                       } else {
-                               iter = g_list_next(iter);
-                       }
+                               FREE(g_dir_config_base)
+                               FREE(g_dir_home)
+                               FREE(g_dir_engine_base)
+                               FREE(g_dir_engine_info)
 
-                       if (NULL != user_type) {
-                               g_free(user_type);
-                               user_type = NULL;
+                               G_FREE(home_dir)
                        }
+
+                       G_FREE(user_type)
+                       iter = g_list_next(iter);
                }
 
                gum_user_service_list_free(users);
@@ -649,7 +805,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        LOGE("[ERROR] Invalid uid");
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return 0;
                } else {
                        LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
@@ -660,7 +816,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        LOGE("[ERROR] No Engine Metadata");
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return 0;
                }
 
@@ -669,7 +825,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        xmlFreeDoc(g_doc);
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -680,26 +836,14 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
 
                if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
                        LOGE("[ERROR] Fail to allocate memory");
-                       if (NULL != g_dir_config_base) {
-                               free(g_dir_config_base);
-                               g_dir_config_base = NULL;
-                       }
-                       if (NULL != g_dir_home) {
-                               free(g_dir_home);
-                               g_dir_home = NULL;
-                       }
-                       if (NULL != g_dir_engine_base) {
-                               free(g_dir_engine_base);
-                               g_dir_engine_base = NULL;
-                       }
-                       if (NULL != g_dir_engine_info) {
-                               free(g_dir_engine_info);
-                               g_dir_engine_info = NULL;
-                       }
+                       FREE(g_dir_config_base)
+                       FREE(g_dir_home)
+                       FREE(g_dir_engine_base)
+                       FREE(g_dir_engine_info)
                        xmlFreeDoc(g_doc);
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -710,7 +854,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                                g_object_unref(g_guser);
                                g_guser = NULL;
                        }
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
        }
@@ -720,24 +864,12 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                g_object_unref(g_guser);
                g_guser = NULL;
        }
-       g_free(g_user_type);
+       G_FREE(g_user_type)
 
-       if (NULL != g_dir_config_base) {
-               free(g_dir_config_base);
-               g_dir_config_base = NULL;
-       }
-       if (NULL != g_dir_home) {
-               free(g_dir_home);
-               g_dir_home = NULL;
-       }
-       if (NULL != g_dir_engine_base) {
-               free(g_dir_engine_base);
-               g_dir_engine_base = NULL;
-       }
-       if (NULL != g_dir_engine_info) {
-               free(g_dir_engine_info);
-               g_dir_engine_info = NULL;
-       }
+       FREE(g_dir_config_base)
+       FREE(g_dir_home)
+       FREE(g_dir_engine_base)
+       FREE(g_dir_engine_info)
 
        return 0;
 }
@@ -761,6 +893,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
        uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
        if (globalapp_uid == g_uid) {
                g_user_type = g_strdup("admin");
+               LOGD("[DEBUG] g_user_type: %s (%d)", g_user_type, globalapp_uid);
        } else {
                g_guser = gum_user_get_sync(g_uid, FALSE);
                if (NULL == g_guser) {
@@ -770,6 +903,8 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
 
                g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
                g_user_type = g_strdup(gum_user_type_to_string(g_ut));
+
+               LOGD("[DEBUG] g_user_type: %s (%d)", g_user_type, globalapp_uid);
        }
 
        if (NULL == g_user_type) {
@@ -786,7 +921,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                LOGE("[ERROR] Fail to get target uid");
                g_object_unref(g_guser);
                g_guser = NULL;
-               g_free(g_user_type);
+               G_FREE(g_user_type)
                return -1;
        }
 
@@ -798,7 +933,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
                if (NULL == g_dir_engine_info) {
                        LOGE("[ERROR] Fail to allocate memory");
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -825,7 +960,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                gus = gum_user_service_create_sync(TRUE);
                if (!gus) {
                        LOGE("Failed to create gum user service");
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -835,11 +970,11 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                g_strfreev(query);
 
                if (!users) {
-                       LOGE("Failed to get gum user list");
+                       LOGD("NO users");
                        g_object_unref(gus);
                        gus = NULL;
-                       g_free(g_user_type);
-                       return -1;
+                       G_FREE(g_user_type)
+                       return 0;
                }
 
                /* Make new user list */
@@ -848,15 +983,13 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                while (iter != NULL) {
                        user = (GumUser*) iter->data;
                        g_object_get(G_OBJECT(user), "uid", &uid, NULL);
-                       if (NULL != home_dir) {
-                               free(home_dir);
-                               home_dir = NULL;
-                       }
+                       G_FREE(home_dir)
                        g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
                        g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
                        user_type = g_strdup(gum_user_type_to_string(gumut));
                        if (NULL == user_type) {
                                gum_user_service_list_free(users);
+                               G_FREE(home_dir)
                                g_object_unref(gus);
                                gus = NULL;
                                return -1;
@@ -866,8 +999,10 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                                g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
                                if (NULL == g_dir_engine_info) {
                                        gum_user_service_list_free(users);
+                                       G_FREE(home_dir)
                                        g_object_unref(gus);
                                        gus = NULL;
+                                       G_FREE(user_type)
                                        return -1;
                                }
 
@@ -884,20 +1019,14 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                                        LOGE("[ERROR] Fail to remove engine info file");
                                }
 
-                               free(home_dir);
-                               home_dir = NULL;
-
-                               free(g_dir_engine_info);
-                               g_dir_engine_info = NULL;
-
-                               g_free(user_type);
-
-                               LOGD("Finish release memory");
-                               iter = g_list_next(iter);
-                               LOGD("Finish next iter");
-                       } else {
-                               iter = g_list_next(iter);
+                               G_FREE(home_dir)
+                               FREE(g_dir_engine_info)
                        }
+                       G_FREE(user_type)
+
+                       LOGD("Finish release memory");
+                       iter = g_list_next(iter);
+                       LOGD("Finish next iter");
                }
 
                gum_user_service_list_free(users);
@@ -912,7 +1041,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                        LOGE("[ERROR] Invalid uid");
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                } else {
                        LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
@@ -924,7 +1053,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                        LOGE("[ERROR] Fail to allocate memory");
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -938,12 +1067,9 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                g_object_unref(g_guser);
                g_guser = NULL;
        }
-       g_free(g_user_type);
+       G_FREE(g_user_type)
 
-       if (NULL != g_dir_engine_info) {
-               free(g_dir_engine_info);
-               g_dir_engine_info = NULL;
-       }
+       FREE(g_dir_engine_info)
 
        LOGD("");
        return 0;