Sync to the latest code 04/10404/3 accepted/tizen/20131014.080211 accepted/tizen/20131014.171855 accepted/tizen/20131014.173836 submit/tizen/20131014.075729
authorjunsuk77.oh <junsuk77.oh@samsung.com>
Tue, 1 Oct 2013 12:12:01 +0000 (21:12 +0900)
committerjunsuk77.oh <junsuk77.oh@samsung.com>
Wed, 2 Oct 2013 08:46:07 +0000 (17:46 +0900)
1. add get char api to remove null string
2. dont check db/setting/theme vconf key duging checking of icon path
3. add submode info to desktop file
4. install fail when insert db is failed
5. implement mdm policy
6. change log api to use uniformed debug message
7. delete null string in pkgmgr db
8. change mdparser api name
9. add tag parser plugin
10. dont use global variable that is used for db query
11. fix bug - set-label api does not work properly
12. Fixed Prevent issue 31276

Change-Id: I6d8e5973c18ee46918beec6cd1c61cc9a004929e
Signed-off-by: junsuk77.oh <junsuk77.oh@samsung.com>
12 files changed:
include/pkgmgr-info-debug.h
metadata_parser_list.txt.in [new file with mode: 0644]
parser/CMakeLists.txt
parser/manifest.xsd.in
parser/pkgmgr_parser.c
parser/pkgmgr_parser.h
parser/pkgmgr_parser_db.c
parser/pkgmgr_parser_internal.h
parser/pkgmgr_parser_signature.c [new file with mode: 0644]
parser/pkgmgr_parser_signature.h [new file with mode: 0644]
src/pkgmgr-info.c
tag_parser_list.txt.in [new file with mode: 0644]

index 888a9b1..061fc50 100644 (file)
@@ -24,8 +24,6 @@
 
 #include <dlog.h>
 
-#undef LOG_TAG
-#define LOG_TAG                "PKGMGR_INFO"
 #define _LOGE(fmt, arg...) LOGE(fmt, ##arg)
 #define _LOGD(fmt, arg...) LOGD(fmt, ##arg)
 
diff --git a/metadata_parser_list.txt.in b/metadata_parser_list.txt.in
new file mode 100644 (file)
index 0000000..d7587fd
--- /dev/null
@@ -0,0 +1,4 @@
+http://developer.samsung.com/tizen/metadata/sticker
+http://developer.samsung.com/tizen/metadata/ttsengine
+http://developer.samsung.com/tizen/metadata/downloadable_filters
+http://developer.samsung.com/tizen/metadata/dictionary
\ No newline at end of file
index 7bb9f3f..8904ecc 100755 (executable)
@@ -45,7 +45,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
 
 ## pkgmgr_parser object (by sewook.park)
 # This library is for installer backend
-add_library(pkgmgr_parser SHARED pkgmgr_parser.c pkgmgr_parser_db.c)
+add_library(pkgmgr_parser SHARED pkgmgr_parser.c pkgmgr_parser_db.c pkgmgr_parser_signature.c)
 #add_library(pkgmgr_parser SHARED pkgmgr_parser.c)
 set_target_properties(pkgmgr_parser PROPERTIES SOVERSION ${VERSION_MAJOR})
 set_target_properties(pkgmgr_parser PROPERTIES VERSION ${VERSION})
index 0f77a7a..cdf17f6 100755 (executable)
@@ -27,6 +27,7 @@
          <xs:attribute name="storeclient-id" type="xs:string"/>
       <xs:attribute name="install-location" type="packages:InstallLocationType"/>
       <xs:attribute name="package" use="required" type="xs:string"/>
+         <xs:attribute name="main_package" type="xs:string"/>
       <xs:attribute name="type" type="packages:PackageType"/>
       <xs:attribute name="version" use="required" type="xs:NMTOKEN"/>
       <xs:attribute name="size" type="xs:NMTOKEN"/>
index 256b2f4..d97fad6 100755 (executable)
 #include "pkgmgr_parser_internal.h"
 #include "pkgmgr_parser_db.h"
 #include "pkgmgr-info.h"
+#include "pkgmgr_parser_signature.h"
+#include "pkgmgr-info-debug.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "PKGMGR_PARSER"
 
 #define MANIFEST_RW_DIRECTORY "/opt/share/packages"
 #define MANIFEST_RO_DIRECTORY "/usr/share/packages"
 #define ASCII(s) (const char *)s
 #define XMLCHAR(s) (const xmlChar *)s
 
-#define MDPARSER_LIST "/usr/etc/package-manager/parserlib/metadata/mdparser_list.txt"
-#define MDPARSER_NAME  "mdparser:"
+#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/metadata_parser_list.txt"
+#define METADATA_PARSER_NAME   "metadataparser:"
 
-#define CATEGORY_PARSER_LIST "/usr/etc/package-manager/parserlib/category/category_parser_list.txt"
+#define CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
 #define CATEGORY_PARSER_NAME   "categoryparser:"
 
+#define TAG_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/tag_parser_list.txt"
+#define TAG_PARSER_NAME        "parserlib:"
+
 #define PKG_TAG_LEN_MAX 128
 
 /* operation_type */
@@ -57,6 +67,7 @@ typedef enum {
        ACTION_INSTALL = 0,
        ACTION_UPGRADE,
        ACTION_UNINSTALL,
+       ACTION_FOTA,
        ACTION_MAX
 } ACTION_TYPE;
 
@@ -157,6 +168,25 @@ static void __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *con
 static void __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid);
 static int __validate_appid(const char *pkgid, const char *appid, char **newappid);
 
+void *__open_lib_handle(char *tag)
+{
+       char *lib_path = NULL;
+       void *lib_handle = NULL;
+
+       lib_path = __get_parser_plugin(tag);
+       retvm_if(!lib_path, NULL, "lib_path get fail");
+
+       lib_handle = dlopen(lib_path, RTLD_LAZY);
+       retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
+
+       return lib_handle;
+}
+
+void __close_lib_handle(void *lib_handle)
+{
+       dlclose(lib_handle);
+}
+
 static void __str_trim(char *input)
 {
        char *trim_str = input;
@@ -179,7 +209,7 @@ static void __str_trim(char *input)
 static int __validate_appid(const char *pkgid, const char *appid, char **newappid)
 {
        if (!pkgid || !appid || !newappid) {
-               DBG("Arg supplied is NULL\n");
+               _LOGD("Arg supplied is NULL\n");
                return -1;
        }
        int pkglen = strlen(pkgid);
@@ -191,17 +221,17 @@ static int __validate_appid(const char *pkgid, const char *appid, char **newappi
                len = pkglen + applen + 1;
                newapp = calloc(1,len);
                if (newapp == NULL) {
-                       DBG("Malloc failed\n");
+                       _LOGD("Malloc failed\n");
                        return -1;
                }
                strncpy(newapp, pkgid, pkglen);
                strncat(newapp, appid, applen);
-               DBG("new appid is %s\n", newapp);
+               _LOGD("new appid is %s\n", newapp);
                *newappid = newapp;
                return 0;
        }
        if (applen < pkglen) {
-               DBG("app id is not proper\n");
+               _LOGD("app id is not proper\n");
                *newappid = NULL;
 #ifdef _VALIDATE_APPID_
                return -1;
@@ -210,7 +240,7 @@ static int __validate_appid(const char *pkgid, const char *appid, char **newappi
 #endif
        }
        if (!strcmp(appid, pkgid)) {
-               DBG("appid is proper\n");
+               _LOGD("appid is proper\n");
                *newappid = NULL;
                return 0;
        }
@@ -218,12 +248,12 @@ static int __validate_appid(const char *pkgid, const char *appid, char **newappi
                ptr = strstr(appid, pkgid);
                ptr = ptr + pkglen;
                if (strncmp(ptr, ".", 1) == 0) {
-                       DBG("appid is proper\n");
+                       _LOGD("appid is proper\n");
                        *newappid = NULL;
                        return 0;
                }
                else {
-                       DBG("appid is not proper\n");
+                       _LOGD("appid is not proper\n");
                        *newappid = NULL;
 #ifdef _VALIDATE_APPID_
                        return -1;
@@ -232,7 +262,7 @@ static int __validate_appid(const char *pkgid, const char *appid, char **newappi
 #endif
                }
        } else {
-               DBG("appid is not proper\n");
+               _LOGD("appid is not proper\n");
                *newappid = NULL;
 #ifdef _VALIDATE_APPID_
                return -1;
@@ -248,7 +278,7 @@ static char * __get_tag_by_key(char *md_key)
        char *md_tag = NULL;
 
        if (md_key == NULL) {
-               DBG("md_key is NULL\n");
+               _LOGD("md_key is NULL\n");
                return NULL;
        }
 
@@ -258,7 +288,7 @@ static char * __get_tag_by_key(char *md_key)
        return strdup(md_tag);
 }
 
-static char *__get_mdparser_plugin(const char *type)
+static char *__get_metadata_parser_plugin(const char *type)
 {
        FILE *fp = NULL;
        char buffer[1024] = { 0 };
@@ -266,13 +296,13 @@ static char *__get_mdparser_plugin(const char *type)
        char *path = NULL;
 
        if (type == NULL) {
-               DBGE("invalid argument\n");
+               _LOGE("invalid argument\n");
                return NULL;
        }
 
        fp = fopen(PKG_PARSER_CONF_PATH, "r");
        if (fp == NULL) {
-               DBGE("no matching mdparser\n");
+               _LOGE("no matching metadata parser\n");
                return NULL;
        }
 
@@ -282,8 +312,8 @@ static char *__get_mdparser_plugin(const char *type)
 
                __str_trim(buffer);
 
-               if ((path = strstr(buffer, MDPARSER_NAME)) != NULL) {
-                       path = path + strlen(MDPARSER_NAME);
+               if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
+                       path = path + strlen(METADATA_PARSER_NAME);
 
                        break;
                }
@@ -295,7 +325,7 @@ static char *__get_mdparser_plugin(const char *type)
                fclose(fp);
 
        if (path == NULL) {
-               DBGE("no matching [%s] [%s]\n", MDPARSER_NAME,type);
+               _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
                return NULL;
        }
 
@@ -312,13 +342,13 @@ static char *__get_category_parser_plugin(const char *type)
        char *path = NULL;
 
        if (type == NULL) {
-               DBGE("invalid argument\n");
+               _LOGE("invalid argument\n");
                return NULL;
        }
 
        fp = fopen(PKG_PARSER_CONF_PATH, "r");
        if (fp == NULL) {
-               DBGE("no matching mdparser\n");
+               _LOGE("no matching metadata parser\n");
                return NULL;
        }
 
@@ -341,7 +371,7 @@ static char *__get_category_parser_plugin(const char *type)
                fclose(fp);
 
        if (path == NULL) {
-               DBGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
+               _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
                return NULL;
        }
 
@@ -358,13 +388,13 @@ static char *__get_parser_plugin(const char *type)
        char *path = NULL;
 
        if (type == NULL) {
-               DBGE("invalid argument\n");
+               _LOGE("invalid argument\n");
                return NULL;
        }
 
        fp = fopen(PKG_PARSER_CONF_PATH, "r");
        if (fp == NULL) {
-               DBGE("no matching backendlib\n");
+               _LOGE("no matching backendlib\n");
                return NULL;
        }
 
@@ -386,7 +416,7 @@ static char *__get_parser_plugin(const char *type)
                fclose(fp);
 
        if (path == NULL) {
-               DBGE("no matching backendlib\n");
+               _LOGE("no matching backendlib\n");
                return NULL;
        }
 
@@ -395,12 +425,46 @@ static char *__get_parser_plugin(const char *type)
        return strdup(temp_path);
 }
 
-static int __ps_run_mdparser(GList *md_list, const char *tag,
+static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
+                          ACTION_TYPE action, const char *pkgid)
+{
+       int (*plugin_install) (xmlDocPtr, const char *);
+       int ret = -1;
+       char *ac = NULL;
+
+       switch (action) {
+       case ACTION_INSTALL:
+               ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
+               break;
+       case ACTION_UPGRADE:
+               ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
+               break;
+       case ACTION_UNINSTALL:
+               ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
+               break;
+       default:
+               goto END;
+       }
+
+       if ((plugin_install =
+               dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
+               _LOGE("can not find symbol[%s] \n", ac);
+               goto END;
+       }
+
+       ret = plugin_install(docPtr, pkgid);
+       _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
+
+END:
+       return ret;
+}
+
+static int __ps_run_metadata_parser(GList *md_list, const char *tag,
                                ACTION_TYPE action, const char *pkgid, const char *appid)
 {
        char *lib_path = NULL;
        void *lib_handle = NULL;
-       int (*mdparser_plugin) (const char *, const char *, GList *);
+       int (*metadata_parser_plugin) (const char *, const char *, GList *);
        int ret = -1;
        char *ac = NULL;
 
@@ -418,28 +482,28 @@ static int __ps_run_mdparser(GList *md_list, const char *tag,
                goto END;
        }
 
-       lib_path = __get_mdparser_plugin(tag);
+       lib_path = __get_metadata_parser_plugin(tag);
        if (!lib_path) {
-               DBGE("get %s parser fail\n", tag);
+               _LOGE("get %s parser fail\n", tag);
                goto END;
        }
 
        if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
-               DBGE("dlopen is failed lib_path[%s]\n", lib_path);
+               _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
                goto END;
        }
 
-       if ((mdparser_plugin =
+       if ((metadata_parser_plugin =
                dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol[%s] \n",ac);
+               _LOGE("can not find symbol[%s] \n",ac);
                goto END;
        }
 
-       ret = mdparser_plugin(pkgid, appid, md_list);
+       ret = metadata_parser_plugin(pkgid, appid, md_list);
        if (ret < 0)
-               DBG("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
+               _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
        else
-               DBG("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
+               _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
 
 END:
        if (lib_path)
@@ -474,26 +538,26 @@ static int __ps_run_category_parser(GList *category_list, const char *tag,
 
        lib_path = __get_category_parser_plugin(tag);
        if (!lib_path) {
-               DBGE("get %s parser fail\n", tag);
+               _LOGE("get %s parser fail\n", tag);
                goto END;
        }
 
        if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
-               DBGE("dlopen is failed lib_path[%s]\n", lib_path);
+               _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
                goto END;
        }
 
        if ((category_parser_plugin =
                dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol[%s] \n",ac);
+               _LOGE("can not find symbol[%s] \n",ac);
                goto END;
        }
 
        ret = category_parser_plugin(pkgid, appid, category_list);
        if (ret < 0)
-               DBG("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
+               _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
        else
-               DBG("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
+               _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
 
 END:
        if (lib_path)
@@ -532,20 +596,20 @@ static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
        }
 
        if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
-               DBGE("dlopen is failed lib_path[%s]\n", lib_path);
+               _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
                goto END;
        }
        if ((plugin_install =
                dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol[%s] \n", ac);
+               _LOGE("can not find symbol[%s] \n", ac);
                goto END;
        }
 
        ret = plugin_install(docPtr, pkgid);
        if (ret < 0)
-               DBG("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
+               _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
        else
-               DBG("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
+               _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
 
 END:
        if (lib_path)
@@ -561,14 +625,14 @@ static char *__pkgid_to_manifest(const char *pkgid)
        int size;
 
        if (pkgid == NULL) {
-               DBGE("pkgid is NULL");
+               _LOGE("pkgid is NULL");
                return NULL;
        }
 
        size = strlen(MANIFEST_RW_DIRECTORY) + strlen(pkgid) + 10;
        manifest = malloc(size);
        if (manifest == NULL) {
-               DBGE("No memory");
+               _LOGE("No memory");
                return NULL;
        }
        memset(manifest, '\0', size);
@@ -581,7 +645,7 @@ static char *__pkgid_to_manifest(const char *pkgid)
        return manifest;
 }
 
-static void __mdparser_clear_dir_list(GList* dir_list)
+static void __metadata_parser_clear_dir_list(GList* dir_list)
 {
        GList *list = NULL;
        __metadata_t* detail = NULL;
@@ -624,7 +688,88 @@ static void __category_parser_clear_dir_list(GList* dir_list)
        }
 }
 
-static int __run_mdparser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
+static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
+{
+       int ret = -1;
+       const xmlChar *name;
+
+       if (xmlTextReaderDepth(reader) != 1) {
+               _LOGE("Node depth is not 1");
+               goto END;
+       }
+
+       if (xmlTextReaderNodeType(reader) != 1) {
+               _LOGE("Node type is not 1");
+               goto END;
+       }
+
+       const xmlChar *value;
+       name = xmlTextReaderConstName(reader);
+       if (name == NULL) {
+               _LOGE("TEST TEST TES\n");
+               name = BAD_CAST "--";
+       }
+
+       value = xmlTextReaderConstValue(reader);
+       if (value != NULL) {
+               if (xmlStrlen(value) > 40) {
+                       _LOGD(" %.40s...", value);
+               } else {
+                       _LOGD(" %s", value);
+               }
+       }
+
+       name = xmlTextReaderConstName(reader);
+       if (name == NULL) {
+               _LOGE("TEST TEST TES\n");
+               name = BAD_CAST "--";
+       }
+
+       xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
+       xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
+       if (copyDocPtr == NULL)
+               return -1;
+       xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
+       if (rootElement == NULL)
+               return -1;
+       xmlNode *cur_node = xmlFirstElementChild(rootElement);
+       if (cur_node == NULL)
+               return -1;
+       xmlNode *temp = xmlTextReaderExpand(reader);
+       if (temp == NULL)
+               return -1;
+       xmlNode *next_node = NULL;
+       while(cur_node != NULL) {
+               if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
+                       (temp->line == cur_node->line) ) {
+                       break;
+               }
+               else {
+                       next_node = xmlNextElementSibling(cur_node);
+                       xmlUnlinkNode(cur_node);
+                       xmlFreeNode(cur_node);
+                       cur_node = next_node;
+               }
+       }
+       if (cur_node == NULL)
+               return -1;
+       next_node = xmlNextElementSibling(cur_node);
+       if (next_node) {
+               cur_node->next = NULL;
+               next_node->prev = NULL;
+               xmlFreeNodeList(next_node);
+               xmlSetTreeDoc(cur_node, copyDocPtr);
+       } else {
+               xmlSetTreeDoc(cur_node, copyDocPtr);
+       }
+
+       ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
+ END:
+
+       return ret;
+}
+
+static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
 {
        int ret = -1;
        int tag_exist = 0;
@@ -638,7 +783,7 @@ static int __run_mdparser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE ac
 
        md_tag = __get_tag_by_key(md_key);
        if (md_tag == NULL) {
-               DBG("md_tag is NULL\n");
+               _LOGD("md_tag is NULL\n");
                return -1;
        }
 
@@ -647,19 +792,19 @@ static int __run_mdparser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE ac
                md = up->metadata;
                while (md != NULL)
                {
-                       //get glist of meatdata key and value combination
+                       //get glist of metadata key and value combination
                        memset(buffer, 0x00, 1024);
                        snprintf(buffer, 1024, "%s/", md_key);
                        if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
                                md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
                                if (md_detail == NULL) {
-                                       DBG("Memory allocation failed\n");
+                                       _LOGD("Memory allocation failed\n");
                                        goto END;
                                }
 
                                md_detail->key = (char*) calloc(1, sizeof(char)*(strlen(md->key)+2));
                                if (md_detail->key == NULL) {
-                                       DBG("Memory allocation failed\n");
+                                       _LOGD("Memory allocation failed\n");
                                        free(md_detail);
                                        goto END;
                                }
@@ -667,7 +812,7 @@ static int __run_mdparser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE ac
 
                                md_detail->value = (char*) calloc(1, sizeof(char)*(strlen(md->value)+2));
                                if (md_detail->value == NULL) {
-                                       DBG("Memory allocation failed\n");
+                                       _LOGD("Memory allocation failed\n");
                                        free(md_detail->key);
                                        free(md_detail);
                                        goto END;
@@ -682,13 +827,13 @@ static int __run_mdparser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE ac
 
                //send glist to parser when tags for metadata plugin parser exist.
                if (tag_exist) {
-                       ret = __ps_run_mdparser(md_list, md_tag, action, mfx->package, up->appid);
+                       ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, up->appid);
                        if (ret < 0)
-                               DBG("mdparser failed[%d] for tag[%s]\n", ret, md_tag);
+                               _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
                        else
-                               DBG("mdparser success for tag[%s]\n", md_tag);
+                               _LOGD("metadata_parser success for tag[%s]\n", md_tag);
                }
-               __mdparser_clear_dir_list(md_list);
+               __metadata_parser_clear_dir_list(md_list);
                md_list = NULL;
                tag_exist = 0;
                up = up->next;
@@ -696,7 +841,7 @@ static int __run_mdparser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE ac
 
        return 0;
 END:
-       __mdparser_clear_dir_list(md_list);
+       __metadata_parser_clear_dir_list(md_list);
 
        if (md_tag)
                free(md_tag);
@@ -718,7 +863,7 @@ static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, A
 
        category_tag = __get_tag_by_key(category_key);
        if (category_tag == NULL) {
-               DBG("md_tag is NULL\n");
+               _LOGD("md_tag is NULL\n");
                return -1;
        }
 
@@ -727,19 +872,19 @@ static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, A
                category = up->category;
                while (category != NULL)
                {
-                       //get glist of meatdata key and value combination
+                       //get glist of category key and value combination
                        memset(buffer, 0x00, 1024);
                        snprintf(buffer, 1024, "%s/", category_key);
                        if ((category->name) && (strncmp(category->name, category_key, strlen(category_key)) == 0)) {
                                category_detail = (__category_t*) calloc(1, sizeof(__category_t));
                                if (category_detail == NULL) {
-                                       DBG("Memory allocation failed\n");
+                                       _LOGD("Memory allocation failed\n");
                                        goto END;
                                }
 
                                category_detail->name = (char*) calloc(1, sizeof(char)*(strlen(category->name)+2));
                                if (category_detail->name == NULL) {
-                                       DBG("Memory allocation failed\n");
+                                       _LOGD("Memory allocation failed\n");
                                        free(category_detail);
                                        goto END;
                                }
@@ -755,9 +900,9 @@ static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, A
                if (tag_exist) {
                        ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, up->appid);
                        if (ret < 0)
-                               DBG("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
+                               _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
                        else
-                               DBG("category_parser success for tag[%s]\n", category_tag);
+                               _LOGD("category_parser success for tag[%s]\n", category_tag);
                }
                __category_parser_clear_dir_list(category_list);
                category_list = NULL;
@@ -780,50 +925,48 @@ static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, con
        int ret = -1;
        const xmlChar *name;
 
-       DBG("__run_parser_prestep");
+//     _LOGD("__run_parser_prestep");
 
        if (xmlTextReaderDepth(reader) != 1) {
-               DBGE("Node depth is not 1");
+               _LOGE("Node depth is not 1");
                goto END;
        }
 
        if (xmlTextReaderNodeType(reader) != 1) {
-               DBGE("Node type is not 1");
+               _LOGE("Node type is not 1");
                goto END;
        }
 
        const xmlChar *value;
        name = xmlTextReaderConstName(reader);
        if (name == NULL) {
-               DBGE("TEST TEST TES\n");
+               _LOGE("TEST TEST TES\n");
                name = BAD_CAST "--";
        }
 
        value = xmlTextReaderConstValue(reader);
-       DBG("%d %d %s %d %d",
+       _LOGD("%d %d %s %d %d",
            xmlTextReaderDepth(reader),
            xmlTextReaderNodeType(reader),
            name,
            xmlTextReaderIsEmptyElement(reader), xmlTextReaderHasValue(reader));
 
-       if (value == NULL) {
-               DBG("ConstValue NULL");
-       } else {
+       if (value != NULL) {
                if (xmlStrlen(value) > 40) {
-                       DBG(" %.40s...", value);
+                       _LOGD(" %.40s...", value);
                } else {
-                       DBG(" %s", value);
+                       _LOGD(" %s", value);
                }
        }
 
        name = xmlTextReaderConstName(reader);
        if (name == NULL) {
-               DBGE("TEST TEST TES\n");
+               _LOGE("TEST TEST TES\n");
                name = BAD_CAST "--";
        }
 
        xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
-       DBG("docPtr->URL %s\n", (char *)docPtr->URL);
+       _LOGD("docPtr->URL %s\n", (char *)docPtr->URL);
        xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
        if (copyDocPtr == NULL)
                return -1;
@@ -864,7 +1007,7 @@ static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, con
 #ifdef __DEBUG__
 
 //#else
-       DBG("node type: %d, name: %s children->name: %s last->name: %s\n"
+       _LOGD("node type: %d, name: %s children->name: %s last->name: %s\n"
            "parent->name: %s next->name: %s prev->name: %s\n",
            cur_node->type, cur_node->name,
            cur_node->children ? cur_node->children->name : "NULL",
@@ -894,7 +1037,7 @@ __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], c
        switch (xmlTextReaderNodeType(reader)) {
        case XML_READER_TYPE_END_ELEMENT:
                {
-                       //            DBG("XML_READER_TYPE_END_ELEMENT");
+                       //            _LOGD("XML_READER_TYPE_END_ELEMENT");
                        break;
                }
 
@@ -906,29 +1049,29 @@ __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], c
                        const xmlChar *elementName =
                            xmlTextReaderLocalName(reader);
                        if (elementName == NULL) {
-//                             DBG("elementName %s\n", (char *)elementName);
+//                             _LOGD("elementName %s\n", (char *)elementName);
                                break;
                        }
 
                        const xmlChar *nameSpace =
                            xmlTextReaderConstNamespaceUri(reader);
                        if (nameSpace) {
-//                             DBG("nameSpace %s\n", (char *)nameSpace);
+//                             _LOGD("nameSpace %s\n", (char *)nameSpace);
                        }
 /*
-                       DBG("XML_READER_TYPE_ELEMENT %s, %s\n",
+                       _LOGD("XML_READER_TYPE_ELEMENT %s, %s\n",
                            elementName ? elementName : "NULL",
                            nameSpace ? nameSpace : "NULL");
 */
                        if (tagv == NULL) {
-                               DBG("__run_parser_prestep pkgid[%s]\n", pkgid);
+                               _LOGD("__run_parser_prestep pkgid[%s]\n", pkgid);
                                __run_parser_prestep(reader, action, pkgid);
                        }
                        else {
                                i = 0;
                                for (tag = tagv[0]; tag; tag = tagv[++i])
                                        if (strcmp(tag, ASCII(elementName)) == 0) {
-                                               DBG("__run_parser_prestep tag[%s] pkgid[%s]\n", tag, pkgid);
+                                               _LOGD("__run_parser_prestep tag[%s] pkgid[%s]\n", tag, pkgid);
                                                __run_parser_prestep(reader,
                                                                     action, pkgid);
                                                break;
@@ -942,25 +1085,101 @@ __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], c
                {
                        const xmlChar *value = xmlTextReaderConstValue(reader);
                        if (value) {
-//                             DBG("value %s\n", value);
+//                             _LOGD("value %s\n", value);
                        }
 
                        const xmlChar *lang = xmlTextReaderConstXmlLang(reader);
                        if (lang) {
-//                             DBG("lang\n", lang);
+//                             _LOGD("lang\n", lang);
                        }
 
-/*                     DBG("XML_READER_TYPE_TEXT %s, %s\n",
+/*                     _LOGD("XML_READER_TYPE_TEXT %s, %s\n",
                            value ? value : "NULL", lang ? lang : "NULL");
 */
                        break;
                }
        default:
-//             DBG("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
+//             _LOGD("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
                break;
        }
 }
 
+static void
+__processTag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
+{
+       switch (xmlTextReaderNodeType(reader)) {
+       case XML_READER_TYPE_END_ELEMENT:
+               {
+                       break;
+               }
+       case XML_READER_TYPE_ELEMENT:
+               {
+                       // Elements without closing tag don't receive
+                       const xmlChar *elementName =
+                           xmlTextReaderLocalName(reader);
+                       if (elementName == NULL) {
+                               break;
+                       }
+
+                       if (strcmp(tag, ASCII(elementName)) == 0) {
+                               _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
+                               __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
+                               break;
+                       }
+                       break;
+               }
+
+       default:
+               break;
+       }
+}
+
+static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
+{
+       int (*plugin_install) (const char *);
+       int ret = -1;
+       char *ac = NULL;
+
+       if (process == PLUGIN_PRE_PROCESS) {
+               switch (action) {
+               case ACTION_INSTALL:
+                       ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
+                       break;
+               case ACTION_UPGRADE:
+                       ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
+                       break;
+               case ACTION_UNINSTALL:
+                       ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
+                       break;
+               default:
+                       return -1;
+               }
+       } else if (process == PLUGIN_POST_PROCESS) {
+               switch (action) {
+               case ACTION_INSTALL:
+                       ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
+                       break;
+               case ACTION_UPGRADE:
+                       ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
+                       break;
+               case ACTION_UNINSTALL:
+                       ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
+                       break;
+               default:
+                       return -1;
+               }
+       } else
+               return -1;
+
+       if ((plugin_install =
+               dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
+               return -1;
+       }
+
+       ret = plugin_install(pkgid);
+       return ret;
+}
+
 static void __plugin_send_tag(const char *tag, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
 {
        char *lib_path = NULL;
@@ -1006,20 +1225,20 @@ static void __plugin_send_tag(const char *tag, ACTION_TYPE action, PLUGIN_PROCES
        }
 
        if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
-               DBGE("dlopen is failed lib_path[%s] for tag[%s]\n", lib_path, tag);
+               _LOGE("dlopen is failed lib_path[%s] for tag[%s]\n", lib_path, tag);
                goto END;
        }
        if ((plugin_install =
                dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol[%s] for tag[%s] \n", ac, tag);
+//             _LOGE("can not find symbol[%s] for tag[%s] \n", ac, tag);
                goto END;
        }
 
        ret = plugin_install(pkgid);
        if (ret < 0)
-               DBG("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin fail\n", process, pkgid, tag);
+               _LOGD("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin fail\n", process, pkgid, tag);
        else
-               DBG("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin success\n", process, pkgid, tag);
+               _LOGD("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin success\n", process, pkgid, tag);
 
 END:
        if (lib_path)
@@ -1067,46 +1286,18 @@ __plugin_save_tag(xmlTextReaderPtr reader, char *const tagv[], char *tag_list[])
                        break;
                }
        default:
-//             DBG("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
+//             _LOGD("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
                break;
        }
 }
 
 static void
-__plugin_find_tag(const char *filename, char *const tagv[], char *tag_list[])
-{
-       xmlTextReaderPtr reader;
-       xmlDocPtr docPtr;
-       int ret;
-
-       docPtr = xmlReadFile(filename, NULL, 0);
-       reader = xmlReaderWalker(docPtr);
-       if (reader != NULL) {
-               ret = xmlTextReaderRead(reader);
-               while (ret == 1) {
-                       __plugin_save_tag(reader, tagv, tag_list);
-                       ret = xmlTextReaderRead(reader);
-               }
-               xmlFreeTextReader(reader);
-
-               if (ret != 0) {
-                       DBG("xmlReaderWalker fail");
-               }
-       } else {
-               DBG("xmlReaderWalker fail");
-       }
-}
-
-static void
 __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid)
 {
        xmlTextReaderPtr reader;
        xmlDocPtr docPtr;
        int ret;
-       char *tag_list[PKG_TAG_LEN_MAX] = {'\0'};
-
-       __plugin_find_tag(filename, tagv, tag_list);
-       __plugin_process_tag(tag_list, action, PLUGIN_PRE_PROCESS, pkgid);
+       __plugin_process_tag(tagv, action, PLUGIN_PRE_PROCESS, pkgid);
 
        docPtr = xmlReadFile(filename, NULL, 0);
        reader = xmlReaderWalker(docPtr);
@@ -1119,13 +1310,13 @@ __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const
                xmlFreeTextReader(reader);
 
                if (ret != 0) {
-                       DBGE("%s : failed to parse", filename);
+                       _LOGD("%s : failed to parse", filename);
                }
        } else {
-               DBGE("Unable to open %s", filename);
+               _LOGD("Unable to open %s", filename);
        }
 
-       __plugin_process_tag(tag_list, action, PLUGIN_POST_PROCESS, pkgid);
+       __plugin_process_tag(tagv, action, PLUGIN_POST_PROCESS, pkgid);
 }
 
 static int __next_child_element(xmlTextReaderPtr reader, int depth)
@@ -1159,6 +1350,43 @@ static int __next_child_element(xmlTextReaderPtr reader, int depth)
        return ret;
 }
 
+static bool __check_action_fota(char *const tagv[])
+{
+       int i = 0;
+       char delims[] = "=";
+       char *ret_result = NULL;
+       char *tag = NULL;
+       int ret = false;
+
+       if (tagv == NULL)
+               return ret;
+
+       for (tag = strdup(tagv[0]); tag != NULL; ) {
+               ret_result = strtok(tag, delims);
+
+               /*check tag :  fota is true */
+               if (strcmp(ret_result, "fota") == 0) {
+                       ret_result = strtok(NULL, delims);
+                       if (strcmp(ret_result, "true") == 0) {
+                               ret = true;
+                       }
+               } else
+                       _LOGD("tag process [%s]is not defined\n", ret_result);
+
+               free(tag);
+
+               /*check next value*/
+               if (tagv[++i] != NULL)
+                       tag = strdup(tagv[i]);
+               else {
+                       _LOGD("tag process success...%d\n" , ret);
+                       return ret;
+               }
+       }
+
+       return ret;
+}
+
 static void __ps_free_category(category_x *category)
 {
        if (category == NULL)
@@ -2179,21 +2407,74 @@ static void __ps_free_ime(ime_x *ime)
        ime = NULL;
 }
 
-int __ps_process_mdparser(manifest_x *mfx, ACTION_TYPE action)
+int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
+{
+       xmlTextReaderPtr reader;
+       xmlDocPtr docPtr;
+       int ret = -1;
+       FILE *fp = NULL;
+       void *lib_handle = NULL;
+       char tag[PKG_STRING_LEN_MAX] = { 0 };
+
+       fp = fopen(TAG_PARSER_LIST, "r");
+       retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
+
+       while (fgets(tag, sizeof(tag), fp) != NULL) {
+               __str_trim(tag);
+
+               lib_handle = __open_lib_handle(tag);
+               if (lib_handle == NULL)
+                       continue;
+
+               ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
+               _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
+
+               docPtr = xmlReadFile(filename, NULL, 0);
+               reader = xmlReaderWalker(docPtr);
+               if (reader != NULL) {
+                       ret = xmlTextReaderRead(reader);
+                       while (ret == 1) {
+                               __processTag(lib_handle, reader, action, tag, mfx->package);
+                               ret = xmlTextReaderRead(reader);
+                       }
+                       xmlFreeTextReader(reader);
+
+                       if (ret != 0) {
+                               _LOGD("%s : failed to parse", filename);
+                       }
+               } else {
+                       _LOGD("Unable to open %s", filename);
+               }
+
+               ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
+               _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
+
+               __close_lib_handle(lib_handle);
+
+               memset(tag, 0x00, sizeof(tag));
+       }
+
+       if (fp != NULL)
+               fclose(fp);
+
+       return 0;
+}
+
+int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
 {
        int ret = -1;
        FILE *fp = NULL;
        char md_key[PKG_STRING_LEN_MAX] = { 0 };
 
-       fp = fopen(MDPARSER_LIST, "r");
+       fp = fopen(METADATA_PARSER_LIST, "r");
        if (fp == NULL) {
-               DBG("no preload list\n");
+               _LOGD("no preload list\n");
                return -1;
        }
 
        while (fgets(md_key, sizeof(md_key), fp) != NULL) {
                __str_trim(md_key);
-               ret = __run_mdparser_prestep(mfx, md_key, action);
+               ret = __run_metadata_parser_prestep(mfx, md_key, action);
 
                memset(md_key, 0x00, sizeof(md_key));
        }
@@ -2212,7 +2493,7 @@ int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
 
        fp = fopen(CATEGORY_PARSER_LIST, "r");
        if (fp == NULL) {
-               DBG("no category parser list\n");
+               _LOGD("no category parser list\n");
                return -1;
        }
 
@@ -2383,14 +2664,14 @@ static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (!strcmp(ASCII(node), "allowed")) {
                        allowed_x *allowed= malloc(sizeof(allowed_x));
                        if (allowed == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(allowed, '\0', sizeof(allowed_x));
@@ -2399,7 +2680,7 @@ static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
                } else if (!strcmp(ASCII(node), "request")) {
                        request_x *request = malloc(sizeof(request_x));
                        if (request == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(request, '\0', sizeof(request_x));
@@ -2408,7 +2689,7 @@ static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing define failed\n");
+                       _LOGD("Processing define failed\n");
                        return ret;
                }
        }
@@ -2437,54 +2718,54 @@ static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcon
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (!strcmp(ASCII(node), "operation")) {
                        operation_x *operation = malloc(sizeof(operation_x));
                        if (operation == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(operation, '\0', sizeof(operation_x));
                        LISTADD(appcontrol->operation, operation);
                        ret = __ps_process_operation(reader, operation);
-                       DBG("operation processing\n");
+                       _LOGD("operation processing\n");
                } else if (!strcmp(ASCII(node), "uri")) {
                        uri_x *uri= malloc(sizeof(uri_x));
                        if (uri == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(uri, '\0', sizeof(uri_x));
                        LISTADD(appcontrol->uri, uri);
                        ret = __ps_process_uri(reader, uri);
-                       DBG("uri processing\n");
+                       _LOGD("uri processing\n");
                } else if (!strcmp(ASCII(node), "mime")) {
                        mime_x *mime = malloc(sizeof(mime_x));
                        if (mime == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(mime, '\0', sizeof(mime_x));
                        LISTADD(appcontrol->mime, mime);
                        ret = __ps_process_mime(reader, mime);
-                       DBG("mime processing\n");
+                       _LOGD("mime processing\n");
                } else if (!strcmp(ASCII(node), "subapp")) {
                        subapp_x *subapp = malloc(sizeof(subapp_x));
                        if (subapp == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(subapp, '\0', sizeof(subapp_x));
                        LISTADD(appcontrol->subapp, subapp);
                        ret = __ps_process_subapp(reader, subapp);
-                       DBG("subapp processing\n");
+                       _LOGD("subapp processing\n");
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing appcontrol failed\n");
+                       _LOGD("Processing appcontrol failed\n");
                        return ret;
                }
        }
@@ -2526,54 +2807,54 @@ static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (!strcmp(ASCII(node), "operation")) {
                        operation_x *operation = malloc(sizeof(operation_x));
                        if (operation == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(operation, '\0', sizeof(operation_x));
                        LISTADD(appsvc->operation, operation);
                        ret = __ps_process_operation(reader, operation);
-                       DBG("operation processing\n");
+                       _LOGD("operation processing\n");
                } else if (!strcmp(ASCII(node), "uri")) {
                        uri_x *uri= malloc(sizeof(uri_x));
                        if (uri == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(uri, '\0', sizeof(uri_x));
                        LISTADD(appsvc->uri, uri);
                        ret = __ps_process_uri(reader, uri);
-                       DBG("uri processing\n");
+                       _LOGD("uri processing\n");
                } else if (!strcmp(ASCII(node), "mime")) {
                        mime_x *mime = malloc(sizeof(mime_x));
                        if (mime == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(mime, '\0', sizeof(mime_x));
                        LISTADD(appsvc->mime, mime);
                        ret = __ps_process_mime(reader, mime);
-                       DBG("mime processing\n");
+                       _LOGD("mime processing\n");
                } else if (!strcmp(ASCII(node), "subapp")) {
                        subapp_x *subapp = malloc(sizeof(subapp_x));
                        if (subapp == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(subapp, '\0', sizeof(subapp_x));
                        LISTADD(appsvc->subapp, subapp);
                        ret = __ps_process_subapp(reader, subapp);
-                       DBG("subapp processing\n");
+                       _LOGD("subapp processing\n");
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing appsvc failed\n");
+                       _LOGD("Processing appsvc failed\n");
                        return ret;
                }
        }
@@ -2613,14 +2894,14 @@ static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privil
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (strcmp(ASCII(node), "privilege") == 0) {
                        privilege_x *privilege = malloc(sizeof(privilege_x));
                        if (privilege == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(privilege, '\0', sizeof(privilege_x));
@@ -2629,7 +2910,7 @@ static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privil
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing privileges failed\n");
+                       _LOGD("Processing privileges failed\n");
                        return ret;
                }
        }
@@ -2651,14 +2932,14 @@ static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditio
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (strcmp(ASCII(node), "condition") == 0) {
                        condition_x *condition = malloc(sizeof(condition_x));
                        if (condition == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(condition, '\0', sizeof(condition_x));
@@ -2667,7 +2948,7 @@ static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditio
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing launchconditions failed\n");
+                       _LOGD("Processing launchconditions failed\n");
                        return ret;
                }
        }
@@ -2694,14 +2975,14 @@ static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashar
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (!strcmp(ASCII(node), "define")) {
                        define_x *define= malloc(sizeof(define_x));
                        if (define == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(define, '\0', sizeof(define_x));
@@ -2710,7 +2991,7 @@ static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashar
                } else if (!strcmp(ASCII(node), "request")) {
                        request_x *request= malloc(sizeof(request_x));
                        if (request == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(request, '\0', sizeof(request_x));
@@ -2719,7 +3000,7 @@ static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashar
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing data-share failed\n");
+                       _LOGD("Processing data-share failed\n");
                        return ret;
                }
        }
@@ -2748,6 +3029,8 @@ __get_icon_with_path(const char* icon)
                if (!package)
                        return NULL;
 
+/* "db/setting/theme" is not exist */
+#if 0
                theme = vconf_get_str("db/setting/theme");
                if (!theme) {
                        theme = strdup("default");
@@ -2755,11 +3038,14 @@ __get_icon_with_path(const char* icon)
                                return NULL;
                        }
                }
+#else
+               theme = strdup("default");
+#endif
 
                len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
                icon_with_path = malloc(len);
                if(icon_with_path == NULL) {
-                       DBG("(icon_with_path == NULL) return\n");
+                       _LOGD("(icon_with_path == NULL) return\n");
                        free(theme);
                        return NULL;
                }
@@ -2771,19 +3057,19 @@ __get_icon_with_path(const char* icon)
                        if (access(icon_with_path, R_OK) == 0) break;
                        snprintf(icon_with_path, len, "/usr/share/icons/%s/small/%s", theme, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
-                       DBG("cannot find icon %s", icon_with_path);
+                       _LOGD("cannot find icon %s", icon_with_path);
                        snprintf(icon_with_path, len,"/opt/share/icons/default/small/%s", icon);
                        if (access(icon_with_path, R_OK) == 0) break;
                        snprintf(icon_with_path, len, "/usr/share/icons/default/small/%s", icon);
                        if (access(icon_with_path, R_OK) == 0) break;
 
                        /* icon path is going to be moved intto the app directory */
-                       DBGE("icon file must be moved to %s", icon_with_path);
+                       _LOGE("icon file must be moved to %s", icon_with_path);
                        snprintf(icon_with_path, len, "/opt/apps/%s/res/icons/%s/small/%s", package, theme, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
                        snprintf(icon_with_path, len, "/usr/apps/%s/res/icons/%s/small/%s", package, theme, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
-                       DBG("cannot find icon %s", icon_with_path);
+                       _LOGD("cannot find icon %s", icon_with_path);
                        snprintf(icon_with_path, len, "/opt/apps/%s/res/icons/default/small/%s", package, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
                        snprintf(icon_with_path, len, "/usr/apps/%s/res/icons/default/small/%s", package, icon);
@@ -2794,7 +3080,7 @@ __get_icon_with_path(const char* icon)
 
                free(theme);
 
-               DBG("Icon path : %s ---> %s", icon, icon_with_path);
+               _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
 
                return icon_with_path;
        } else {
@@ -2842,7 +3128,7 @@ static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
                        }
                /*check tag :  not matched*/
                } else
-                       DBG("tag process [%s]is not defined\n", ret_result);
+                       _LOGD("tag process [%s]is not defined\n", ret_result);
 
                free(tag);
 
@@ -2850,7 +3136,7 @@ static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
                if (tagv[++i] != NULL)
                        tag = strdup(tagv[i]);
                else {
-                       DBG("tag process success...\n");
+                       _LOGD("tag process success...\n");
                        return;
                }
        }
@@ -2920,9 +3206,9 @@ static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
        if (xmlTextReaderValue(reader))
                label->text = ASCII(xmlTextReaderValue(reader));
 
-/*     DBG("lable name %s\n", label->name);
-       DBG("lable lang %s\n", label->lang);
-       DBG("lable text %s\n", label->text);
+/*     _LOGD("lable name %s\n", label->name);
+       _LOGD("lable lang %s\n", label->lang);
+       _LOGD("lable text %s\n", label->text);
 */
        return 0;
 
@@ -3005,14 +3291,14 @@ static int __ps_process_capability(xmlTextReaderPtr reader, capability_x *capabi
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (!strcmp(ASCII(node), "resolution")) {
                        resolution_x *resolution = malloc(sizeof(resolution_x));
                        if (resolution == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(resolution, '\0', sizeof(resolution_x));
@@ -3021,7 +3307,7 @@ static int __ps_process_capability(xmlTextReaderPtr reader, capability_x *capabi
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing capability failed\n");
+                       _LOGD("Processing capability failed\n");
                        return ret;
                }
        }
@@ -3048,14 +3334,14 @@ static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *data
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (!strcmp(ASCII(node), "capability")) {
                        capability_x *capability = malloc(sizeof(capability_x));
                        if (capability == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(capability, '\0', sizeof(capability_x));
@@ -3064,7 +3350,7 @@ static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *data
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing datacontrol failed\n");
+                       _LOGD("Processing datacontrol failed\n");
                        return ret;
                }
        }
@@ -3098,17 +3384,17 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
        if (xmlTextReaderGetAttribute(reader, XMLCHAR("appid"))) {
                uiapplication->appid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appid")));
                if (uiapplication->appid == NULL) {
-                       DBG("appid cant be NULL\n");
+                       _LOGD("appid cant be NULL\n");
                        return -1;
                }
        } else {
-               DBG("appid is mandatory\n");
+               _LOGD("appid is mandatory\n");
                return -1;
        }
        /*check appid*/
        ret = __validate_appid(package, uiapplication->appid, &newappid);
        if (ret == -1) {
-               DBG("appid is not proper\n");
+               _LOGD("appid is not proper\n");
                return -1;
        } else {
                if (newappid) {
@@ -3235,13 +3521,13 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
                if (!strcmp(ASCII(node), "label")) {
                        label_x *label = malloc(sizeof(label_x));
                        if (label == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(label, '\0', sizeof(label_x));
@@ -3250,7 +3536,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "icon")) {
                        icon_x *icon = malloc(sizeof(icon_x));
                        if (icon == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(icon, '\0', sizeof(icon_x));
@@ -3259,7 +3545,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "image")) {
                        image_x *image = malloc(sizeof(image_x));
                        if (image == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(image, '\0', sizeof(image_x));
@@ -3268,7 +3554,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "category")) {
                        category_x *category = malloc(sizeof(category_x));
                        if (category == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(category, '\0', sizeof(category_x));
@@ -3277,7 +3563,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "metadata")) {
                        metadata_x *metadata = malloc(sizeof(metadata_x));
                        if (metadata == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(metadata, '\0', sizeof(metadata_x));
@@ -3286,7 +3572,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "permission")) {
                        permission_x *permission = malloc(sizeof(permission_x));
                        if (permission == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(permission, '\0', sizeof(permission_x));
@@ -3295,7 +3581,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "app-control")) {
                        appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
                        if (appcontrol == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(appcontrol, '\0', sizeof(appcontrol_x));
@@ -3304,7 +3590,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "application-service")) {
                        appsvc_x *appsvc = malloc(sizeof(appsvc_x));
                        if (appsvc == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(appsvc, '\0', sizeof(appsvc_x));
@@ -3313,7 +3599,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "data-share")) {
                        datashare_x *datashare = malloc(sizeof(datashare_x));
                        if (datashare == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(datashare, '\0', sizeof(datashare_x));
@@ -3322,7 +3608,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "launch-conditions")) {
                        launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
                        if (launchconditions == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(launchconditions, '\0', sizeof(launchconditions_x));
@@ -3331,7 +3617,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else if (!strcmp(ASCII(node), "notification")) {
                        notification_x *notification = malloc(sizeof(notification_x));
                        if (notification == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(notification, '\0', sizeof(notification_x));
@@ -3340,7 +3626,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing uiapplication failed\n");
+                       _LOGD("Processing uiapplication failed\n");
                        return ret;
                }
        }
@@ -3414,17 +3700,17 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
        if (xmlTextReaderGetAttribute(reader, XMLCHAR("appid"))) {
                serviceapplication->appid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appid")));
                if (serviceapplication->appid == NULL) {
-                       DBG("appid cant be NULL\n");
+                       _LOGD("appid cant be NULL\n");
                        return -1;
                }
        } else {
-               DBG("appid is mandatory\n");
+               _LOGD("appid is mandatory\n");
                return -1;
        }
        /*check appid*/
        ret = __validate_appid(package, serviceapplication->appid, &newappid);
        if (ret == -1) {
-               DBG("appid is not proper\n");
+               _LOGD("appid is not proper\n");
                return -1;
        } else {
                if (newappid) {
@@ -3463,14 +3749,14 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (!strcmp(ASCII(node), "label")) {
                        label_x *label = malloc(sizeof(label_x));
                        if (label == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(label, '\0', sizeof(label_x));
@@ -3479,7 +3765,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "icon")) {
                        icon_x *icon = malloc(sizeof(icon_x));
                        if (icon == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(icon, '\0', sizeof(icon_x));
@@ -3488,7 +3774,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "category")) {
                        category_x *category = malloc(sizeof(category_x));
                        if (category == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(category, '\0', sizeof(category_x));
@@ -3497,7 +3783,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "metadata")) {
                        metadata_x *metadata = malloc(sizeof(metadata_x));
                        if (metadata == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(metadata, '\0', sizeof(metadata_x));
@@ -3506,7 +3792,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "permission")) {
                        permission_x *permission = malloc(sizeof(permission_x));
                        if (permission == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(permission, '\0', sizeof(permission_x));
@@ -3515,7 +3801,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "app-control")) {
                        appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
                        if (appcontrol == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(appcontrol, '\0', sizeof(appcontrol_x));
@@ -3524,7 +3810,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "application-service")) {
                        appsvc_x *appsvc = malloc(sizeof(appsvc_x));
                        if (appsvc == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(appsvc, '\0', sizeof(appsvc_x));
@@ -3533,7 +3819,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "data-share")) {
                        datashare_x *datashare = malloc(sizeof(datashare_x));
                        if (datashare == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(datashare, '\0', sizeof(datashare_x));
@@ -3542,7 +3828,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "launch-conditions")) {
                        launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
                        if (launchconditions == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(launchconditions, '\0', sizeof(launchconditions_x));
@@ -3551,7 +3837,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "notification")) {
                        notification_x *notification = malloc(sizeof(notification_x));
                        if (notification == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(notification, '\0', sizeof(notification_x));
@@ -3560,7 +3846,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else if (!strcmp(ASCII(node), "data-control")) {
                        datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
                        if (datacontrol == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(datacontrol, '\0', sizeof(datacontrol_x));
@@ -3569,7 +3855,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing serviceapplication failed\n");
+                       _LOGD("Processing serviceapplication failed\n");
                        return ret;
                }
        }
@@ -3654,7 +3940,7 @@ static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
 
 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
 {
-       DBG("__start_process\n");
+       _LOGD("__start_process\n");
        const xmlChar *node;
        int ret = -1;
        int depth = -1;
@@ -3677,14 +3963,14 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
                if (!strcmp(ASCII(node), "label")) {
                        label_x *label = malloc(sizeof(label_x));
                        if (label == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(label, '\0', sizeof(label_x));
@@ -3693,7 +3979,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "author")) {
                        author_x *author = malloc(sizeof(author_x));
                        if (author == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(author, '\0', sizeof(author_x));
@@ -3702,7 +3988,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "description")) {
                        description_x *description = malloc(sizeof(description_x));
                        if (description == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(description, '\0', sizeof(description_x));
@@ -3711,7 +3997,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "license")) {
                        license_x *license = malloc(sizeof(license_x));
                        if (license == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(license, '\0', sizeof(license_x));
@@ -3720,7 +4006,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "privileges")) {
                        privileges_x *privileges = malloc(sizeof(privileges_x));
                        if (privileges == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(privileges, '\0', sizeof(privileges_x));
@@ -3729,7 +4015,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "ui-application")) {
                        uiapplication_x *uiapplication = malloc(sizeof(uiapplication_x));
                        if (uiapplication == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(uiapplication, '\0', sizeof(uiapplication_x));
@@ -3738,7 +4024,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "service-application")) {
                        serviceapplication_x *serviceapplication = malloc(sizeof(serviceapplication_x));
                        if (serviceapplication == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(serviceapplication, '\0', sizeof(serviceapplication_x));
@@ -3747,7 +4033,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "daemon")) {
                        daemon_x *daemon = malloc(sizeof(daemon_x));
                        if (daemon == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(daemon, '\0', sizeof(daemon_x));
@@ -3756,7 +4042,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "theme")) {
                        theme_x *theme = malloc(sizeof(theme_x));
                        if (theme == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(theme, '\0', sizeof(theme_x));
@@ -3765,7 +4051,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "font")) {
                        font_x *font = malloc(sizeof(font_x));
                        if (font == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(font, '\0', sizeof(font_x));
@@ -3774,7 +4060,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "ime")) {
                        ime_x *ime = malloc(sizeof(ime_x));
                        if (ime == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(ime, '\0', sizeof(ime_x));
@@ -3783,7 +4069,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "icon")) {
                        icon_x *icon = malloc(sizeof(icon_x));
                        if (icon == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(icon, '\0', sizeof(icon_x));
@@ -3792,7 +4078,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "device-profile")) {
                        deviceprofile_x *deviceprofile = malloc(sizeof(deviceprofile_x));
                        if (deviceprofile == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(deviceprofile, '\0', sizeof(deviceprofile_x));
@@ -3801,7 +4087,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                } else if (!strcmp(ASCII(node), "compatibility")) {
                        compatibility_x *compatibility = malloc(sizeof(compatibility_x));
                        if (compatibility == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
                        memset(compatibility, '\0', sizeof(compatibility_x));
@@ -3821,7 +4107,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                        return -1;
 
                if (ret < 0) {
-                       DBG("Processing manifest failed\n");
+                       _LOGD("Processing manifest failed\n");
                        return ret;
                }
        }
@@ -3892,7 +4178,7 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
        if ((ret = __next_child_element(reader, -1))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
@@ -3902,11 +4188,11 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
                        if (xmlTextReaderGetAttribute(reader, XMLCHAR("package"))) {
                                mfx->package= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("package")));
                                if (mfx->package == NULL) {
-                                       DBG("package cant be NULL\n");
+                                       _LOGD("package cant be NULL\n");
                                        return -1;
                                }
                        } else {
-                               DBG("package field is mandatory\n");
+                               _LOGD("package field is mandatory\n");
                                return -1;
                        }
                        package = mfx->package;
@@ -3923,6 +4209,8 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
                                mfx->root_path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("root_path")));
                        if (xmlTextReaderGetAttribute(reader, XMLCHAR("csc_path")))
                                mfx->csc_path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("csc_path")));
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("main_package")))
+                               mfx->main_package = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("main_package")));
                        if (xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting"))) {
                                mfx->appsetting = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting")));
                                if (mfx->appsetting == NULL)
@@ -3960,7 +4248,7 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
 
                        ret = __start_process(reader, mfx);
                } else {
-                       DBG("No Manifest element found\n");
+                       _LOGD("No Manifest element found\n");
                        return -1;
                }
        }
@@ -3978,7 +4266,7 @@ static char* __convert_to_system_locale(const char *mlocale)
        char *locale = NULL;
        locale = (char *)calloc(1, 6);
        if (!locale) {
-               DBGE("Malloc Failed\n");
+               _LOGE("Malloc Failed\n");
                return NULL;
        }
 
@@ -3997,6 +4285,7 @@ typedef enum {
        AIL_UPDATE,
        AIL_REMOVE,
        AIL_CLEAN,
+       AIL_FOTA,
        AIL_MAX
 } AIL_TYPE;
 
@@ -4008,7 +4297,7 @@ static int __ail_change_info(int op, const char *appid)
        int ret = 0;
 
        if ((lib_handle = dlopen(LIBAIL_PATH, RTLD_LAZY)) == NULL) {
-               DBGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAIL_PATH);
+               _LOGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAIL_PATH);
                goto END;
        }
 
@@ -4026,6 +4315,9 @@ static int __ail_change_info(int op, const char *appid)
                case 3:
                        aop  = "ail_desktop_clean";
                        break;
+               case 4:
+                       aop  = "ail_desktop_fota";
+                       break;
                default:
                        goto END;
                        break;
@@ -4033,7 +4325,7 @@ static int __ail_change_info(int op, const char *appid)
 
        if ((ail_desktop_operation =
             dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol \n");
+               _LOGE("can not find symbol \n");
                goto END;
        }
 
@@ -4050,7 +4342,7 @@ END:
 /* desktop shoud be generated automatically based on manifest */
 /* Currently removable, taskmanage, etc fields are not considerd. it will be decided soon.*/
 #define BUFMAX 1024*128
-static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, bool is_update)
+static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, ACTION_TYPE action)
 {
         FILE* file = NULL;
         int fd = 0;
@@ -4061,18 +4353,18 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
 
        buf = (char *)calloc(1, BUFMAX);
        if (!buf) {
-               DBGE("Malloc Failed\n");
+               _LOGE("Malloc Failed\n");
                return -1;
        }
 
        buftemp = (char *)calloc(1, BUFMAX);
        if (!buftemp) {
-               DBGE("Malloc Failed\n");
+               _LOGE("Malloc Failed\n");
                free(buf);
                return -1;
        }
 
-       if (is_update)
+       if (action == ACTION_UPGRADE)
                __ail_change_info(AIL_CLEAN, mfx->package);
 
        for(; mfx->uiapplication; mfx->uiapplication=mfx->uiapplication->next) {
@@ -4081,7 +4373,7 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
                        /* skip making a deskfile and update ail, if preload app is updated */
                        if(strstr(manifest, MANIFEST_RO_PREFIX)) {
                                __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
-                   DBGE("preload app is update : skip and update ail : %s", manifest);
+                   _LOGE("preload app is update : skip and update ail : %s", manifest);
                                continue;
                        }
                }
@@ -4099,7 +4391,7 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
                file = fopen(filepath, "w");
                if(file == NULL)
                {
-                   DBGE("Can't open %s", filepath);
+                   _LOGD("Can't open %s", filepath);
                    free(buf);
                    free(buftemp);
                    return -1;
@@ -4165,7 +4457,7 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
                                while (mi) {
                                        mime_count++;
                                        mime = mi->name;
-                                       DBG("MIME type: %s\n", mime);
+                                       _LOGD("MIME type: %s\n", mime);
                                        strncat(buf, mime, BUFMAX-strlen(buf)-1);
                                        if(mi->next) {
                                                strncat(buf, mime_delim, BUFMAX-strlen(buf)-1);
@@ -4176,8 +4468,8 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
                                }
                                asvc = asvc->next;
                        }
-                       DBG("MIME types: buf[%s]\n", buf);
-                       DBG("MIME count: %d\n", mime_count);
+                       _LOGD("MIME types: buf[%s]\n", buf);
+                       _LOGD("MIME count: %d\n", mime_count);
                        if(mime_count)
                                fwrite(buf, 1, strlen(buf), file);
                }
@@ -4232,6 +4524,13 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
                        fwrite(buf, 1, strlen(buf), file);
                }
 
+               if(mfx->uiapplication->submode && !strcasecmp(mfx->uiapplication->submode, "True")) {
+                       snprintf(buf, BUFMAX, "X-TIZEN-Submode=%s\n", mfx->uiapplication->submode);
+                       fwrite(buf, 1, strlen(buf), file);
+                       snprintf(buf, BUFMAX, "X-TIZEN-SubmodeMainid=%s\n", mfx->uiapplication->submode_mainid);
+                       fwrite(buf, 1, strlen(buf), file);
+               }
+
                snprintf(buf, BUFMAX, "X-TIZEN-PkgID=%s\n", mfx->package);
                fwrite(buf, 1, strlen(buf), file);
 
@@ -4242,7 +4541,7 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
 
                if(mfx->uiapplication->appsvc) {
                        snprintf(buf, BUFMAX, "X-TIZEN-Svc=");
-                       DBG("buf[%s]\n", buf);
+                       _LOGD("buf[%s]\n", buf);
 
 
                        uiapplication_x *up = mfx->uiapplication;
@@ -4289,7 +4588,7 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
 
                                                                strncpy(buftemp, buf, BUFMAX);
                                                                snprintf(buf, BUFMAX, "%s%s|%s|%s|%s", buftemp, operation?operation:"NULL", uri?uri:"NULL", mime?mime:"NULL", subapp?subapp:"NULL");
-                                                               DBG("buf[%s]\n", buf);
+                                                               _LOGD("buf[%s]\n", buf);
 
                                                                if (ui)
                                                                        ui = ui->next;
@@ -4320,7 +4619,7 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
 
                if(mfx->uiapplication->appcontrol) {
                        snprintf(buf, BUFMAX, "X-TIZEN-Svc=");
-                       DBG("buf[%s]\n", buf);
+                       _LOGD("buf[%s]\n", buf);
 
                        uiapplication_x *up = mfx->uiapplication;
                        appcontrol_x *acontrol = NULL;
@@ -4364,7 +4663,7 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
 
                                                                strncpy(buftemp, buf, BUFMAX);
                                                                snprintf(buf, BUFMAX, "%s%s|%s|%s|%s", buftemp, operation?operation:"NULL", uri?uri:"NULL", mime?mime:"NULL", subapp?subapp:"NULL");
-                                                               DBG("buf[%s]\n", buf);
+                                                               _LOGD("buf[%s]\n", buf);
 
                                                                if (ui)
                                                                        ui = ui->next;
@@ -4397,8 +4696,10 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, b
                fd = fileno(file);
                fsync(fd);
                fclose(file);
-
-               __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
+               if (action == ACTION_FOTA)
+                       __ail_change_info(AIL_FOTA, mfx->uiapplication->appid);
+               else
+                       __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
        }
 
        free(buf);
@@ -4436,20 +4737,20 @@ static int __ps_remove_appsvc_db(manifest_x *mfx)
        uiapplication_x *uiapplication = mfx->uiapplication;
 
        if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
-               DBGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAPPSVC_PATH);
+               _LOGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAPPSVC_PATH);
                goto END;
        }
 
        if ((appsvc_operation =
                 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol \n");
+               _LOGE("can not find symbol \n");
                goto END;
        }
 
        for(; uiapplication; uiapplication=uiapplication->next) {
                ret = appsvc_operation(uiapplication->appid);
                if (ret <0)
-                       DBGE("can not operation  symbol \n");
+                       _LOGE("can not operation  symbol \n");
        }
 
 END:
@@ -4484,7 +4785,7 @@ static int __add_preload_info(manifest_x * mfx, const char *manifest)
 
        fp = fopen(PRELOAD_PACKAGE_LIST, "r");
        if (fp == NULL) {
-               DBGE("no preload list\n");
+               _LOGE("no preload list\n");
                return -1;
        }
 
@@ -4553,14 +4854,14 @@ API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
 {
         int ret = 0;
        if (mfx == NULL) {
-               DBG("Manifest pointer is NULL\n");
+               _LOGD("Manifest pointer is NULL\n");
                return -1;
        }
-        ret = __ps_make_nativeapp_desktop(mfx, NULL, 0);
+        ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL);
         if (ret == -1)
-                DBG("Creating desktop file failed\n");
+                _LOGD("Creating desktop file failed\n");
         else
-                DBG("Creating desktop file Success\n");
+                _LOGD("Creating desktop file Success\n");
         return ret;
 }
 
@@ -4648,6 +4949,10 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
                free((void *)mfx->nodisplay_setting);
                mfx->nodisplay_setting = NULL;
        }
+       if (mfx->main_package) {
+               free((void *)mfx->main_package);
+               mfx->main_package = NULL;
+       }
 
        /*Free Icon*/
        if (mfx->icon) {
@@ -4796,7 +5101,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
 
 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
 {
-       DBG("parsing start\n");
+       _LOGD("parsing start\n");
        xmlTextReaderPtr reader;
        manifest_x *mfx = NULL;
 
@@ -4806,17 +5111,17 @@ API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
                if (mfx) {
                        memset(mfx, '\0', sizeof(manifest_x));
                        if (__process_manifest(reader, mfx) < 0) {
-                               DBG("Parsing Failed\n");
+                               _LOGD("Parsing Failed\n");
                                pkgmgr_parser_free_manifest_xml(mfx);
                                mfx = NULL;
                        } else
-                               DBG("Parsing Success\n");
+                               _LOGD("Parsing Success\n");
                } else {
-                       DBG("Memory allocation error\n");
+                       _LOGD("Memory allocation error\n");
                }
                xmlFreeTextReader(reader);
        } else {
-               DBG("Unable to create xml reader\n");
+               _LOGD("Unable to create xml reader\n");
        }
        return mfx;
 }
@@ -4825,50 +5130,52 @@ API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
 
 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
-       if (manifest == NULL) {
-               DBG("argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       DBG("parsing manifest for installation: %s\n", manifest);
+//     char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("parsing manifest for installation: %s\n", manifest);
+
        manifest_x *mfx = NULL;
        int ret = -1;
-       char roxml_check[PKG_STRING_LEN_MAX] = {'\0'};
 
        xmlInitParser();
        mfx = pkgmgr_parser_process_manifest_xml(manifest);
-       DBG("Parsing Finished\n");
-       if (mfx == NULL)
-               return PMINFO_R_ERROR;
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
 
-       __streamFile(manifest, ACTION_INSTALL, temp, mfx->package);
+       _LOGD("Parsing Finished\n");
+
+//     __streamFile(manifest, ACTION_INSTALL, temp, mfx->package);
+       __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
        __add_preload_info(mfx, manifest);
-       DBG("Added preload infomation\n");
+
+       _LOGD("Added preload infomation\n");
 
        __ps_process_tag(mfx, tagv);
 
        ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
-       if (ret == -1)
-               DBG("DB Insert failed\n");
-       else
-               DBG("DB Insert Success\n");
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
+
+       _LOGD("DB Insert Success\n");
 
-       ret = __ps_process_mdparser(mfx, ACTION_INSTALL);
+       ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
        if (ret == -1)
-               DBG("Creating metadata parser failed\n");
+               _LOGD("Creating metadata parser failed\n");
 
        ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
        if (ret == -1)
-               DBG("Creating category parser failed\n");
+               _LOGD("Creating category parser failed\n");
+
+       if (__check_action_fota(tagv))
+               ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_FOTA);
+       else
+               ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL);
 
-       ret = __ps_make_nativeapp_desktop(mfx, NULL, 0);
        if (ret == -1)
-               DBG("Creating desktop file failed\n");
+               _LOGD("Creating desktop file failed\n");
        else
-               DBG("Creating desktop file Success\n");
+               _LOGD("Creating desktop file Success\n");
 
        pkgmgr_parser_free_manifest_xml(mfx);
-       DBG("Free Done\n");
+       _LOGD("Free Done\n");
        xmlCleanupParser();
 
        return PMINFO_R_OK;
@@ -4876,12 +5183,10 @@ API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char
 
 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
-       if (manifest == NULL) {
-               DBG("argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       DBG("parsing manifest for upgradation: %s\n", manifest);
+//     char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("parsing manifest for upgradation: %s\n", manifest);
+
        manifest_x *mfx = NULL;
        int ret = -1;
        bool preload = false;
@@ -4891,22 +5196,23 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
 
        xmlInitParser();
        mfx = pkgmgr_parser_process_manifest_xml(manifest);
-       DBG("Parsing Finished\n");
-       if (mfx == NULL)
-               return PMINFO_R_ERROR;
-       
-       __streamFile(manifest, ACTION_UPGRADE, temp, mfx->package);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+
+       _LOGD("Parsing Finished\n");
+
+//     __streamFile(manifest, ACTION_UPGRADE, temp, mfx->package);
+       __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
        __add_preload_info(mfx, manifest);
-       DBG("Added preload infomation\n");
+       _LOGD("Added preload infomation\n");
        __check_preload_updated(mfx, manifest);
 
        ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
        if (ret != PMINFO_R_OK)
-               DBG("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
+               _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
 
        ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
        if (ret != PMINFO_R_OK)
-               DBG("pkgmgrinfo_pkginfo_is_preload failed\n");
+               _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
 
        if (preload) {
                free((void *)mfx->preload);
@@ -4915,7 +5221,7 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
 
        ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
        if (ret != PMINFO_R_OK)
-               DBG("pkgmgrinfo_pkginfo_is_system failed\n");
+               _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
 
        if (system) {
                free((void *)mfx->system);
@@ -4924,7 +5230,7 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
 
        ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
        if (ret != PMINFO_R_OK)
-               DBG("pkgmgrinfo_pkginfo_get_csc_path failed\n");
+               _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
 
        if (csc_path != NULL) {
                if (mfx->csc_path)
@@ -4933,28 +5239,26 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        }
 
        ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
-       if (ret == -1)
-               DBG("DB Update failed\n");
-       else
-               DBG("DB Update Success\n");
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
+       _LOGD("DB Update Success\n");
 
-       ret = __ps_process_mdparser(mfx, ACTION_UPGRADE);
+       ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
        if (ret == -1)
-               DBG("Upgrade metadata parser failed\n");
+               _LOGD("Upgrade metadata parser failed\n");
 
        ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
        if (ret == -1)
-               DBG("Creating category parser failed\n");
+               _LOGD("Creating category parser failed\n");
 
-       ret = __ps_make_nativeapp_desktop(mfx, manifest, 1);
+       ret = __ps_make_nativeapp_desktop(mfx, manifest, ACTION_UPGRADE);
        if (ret == -1)
-               DBG("Creating desktop file failed\n");
+               _LOGD("Creating desktop file failed\n");
        else
-               DBG("Creating desktop file Success\n");
+               _LOGD("Creating desktop file Success\n");
 
        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
        pkgmgr_parser_free_manifest_xml(mfx);
-       DBG("Free Done\n");
+       _LOGD("Free Done\n");
        xmlCleanupParser();
 
        return PMINFO_R_OK;
@@ -4962,52 +5266,52 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
 
 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
-       if (manifest == NULL) {
-               DBG("argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       DBG("parsing manifest for uninstallation: %s\n", manifest);
+//     char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("parsing manifest for uninstallation: %s\n", manifest);
+
        manifest_x *mfx = NULL;
        int ret = -1;
        xmlInitParser();
        mfx = pkgmgr_parser_process_manifest_xml(manifest);
-       DBG("Parsing Finished\n");
-       if (mfx == NULL)
-               return PMINFO_R_ERROR;
-       
-       __streamFile(manifest, ACTION_UNINSTALL, temp, mfx->package);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+
+       _LOGD("Parsing Finished\n");
+
+//     __streamFile(manifest, ACTION_UNINSTALL, temp, mfx->package);
+       __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
+
        __add_preload_info(mfx, manifest);
-       DBG("Added preload infomation\n");
+       _LOGD("Added preload infomation\n");
 
-       ret = __ps_process_mdparser(mfx, ACTION_UNINSTALL);
+       ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
        if (ret == -1)
-               DBG("Removing metadata parser failed\n");
+               _LOGD("Removing metadata parser failed\n");
 
        ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
        if (ret == -1)
-               DBG("Creating category parser failed\n");
+               _LOGD("Creating category parser failed\n");
 
        ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
        if (ret == -1)
-               DBG("DB Delete failed\n");
+               _LOGD("DB Delete failed\n");
        else
-               DBG("DB Delete Success\n");
+               _LOGD("DB Delete Success\n");
 
        ret = __ps_remove_nativeapp_desktop(mfx);
        if (ret == -1)
-               DBG("Removing desktop file failed\n");
+               _LOGD("Removing desktop file failed\n");
        else
-               DBG("Removing desktop file Success\n");
+               _LOGD("Removing desktop file Success\n");
 
        ret = __ps_remove_appsvc_db(mfx);
        if (ret == -1)
-               DBG("Removing appsvc_db failed\n");
+               _LOGD("Removing appsvc_db failed\n");
        else
-               DBG("Removing appsvc_db Success\n");
+               _LOGD("Removing appsvc_db Success\n");
 
        pkgmgr_parser_free_manifest_xml(mfx);
-       DBG("Free Done\n");
+       _LOGD("Free Done\n");
        xmlCleanupParser();
 
        return PMINFO_R_OK;
@@ -5043,7 +5347,7 @@ API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char
 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
 {
        if (manifest == NULL) {
-               DBGE("manifest file is NULL\n");
+               _LOGE("manifest file is NULL\n");
                return PMINFO_R_EINVAL;
        }
        int ret = -1;
@@ -5052,29 +5356,29 @@ API int pkgmgr_parser_check_manifest_validation(const char *manifest)
        xmlSchemaPtr xschema;
        ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
        if (ctx == NULL) {
-               DBGE("xmlSchemaNewParserCtxt() Failed\n");
+               _LOGE("xmlSchemaNewParserCtxt() Failed\n");
                return PMINFO_R_ERROR;
        }
        xschema = xmlSchemaParse(ctx);
        if (xschema == NULL) {
-               DBGE("xmlSchemaParse() Failed\n");
+               _LOGE("xmlSchemaParse() Failed\n");
                return PMINFO_R_ERROR;
        }
        vctx = xmlSchemaNewValidCtxt(xschema);
        if (vctx == NULL) {
-               DBGE("xmlSchemaNewValidCtxt() Failed\n");
+               _LOGE("xmlSchemaNewValidCtxt() Failed\n");
                return PMINFO_R_ERROR;
        }
        xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
        ret = xmlSchemaValidateFile(vctx, manifest, 0);
        if (ret == -1) {
-               DBGE("xmlSchemaValidateFile() failed\n");
+               _LOGE("xmlSchemaValidateFile() failed\n");
                return PMINFO_R_ERROR;
        } else if (ret == 0) {
-               DBGE("Manifest is Valid\n");
+               _LOGE("Manifest is Valid\n");
                return PMINFO_R_OK;
        } else {
-               DBGE("Manifest Validation Failed with error code %d\n", ret);
+               _LOGE("Manifest Validation Failed with error code %d\n", ret);
                return PMINFO_R_ERROR;
        }
        return PMINFO_R_OK;
@@ -5091,7 +5395,7 @@ API int pkgmgr_parser_check_manifest_validation(const char *manifest)
 
        switch (pid) {
        case -1:
-               DBGE("fork failed\n");
+               _LOGE("fork failed\n");
                return -1;
        case 0:
                /* child */
@@ -5106,7 +5410,7 @@ API int pkgmgr_parser_check_manifest_validation(const char *manifest)
 
                        if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
                                SCHEMA_FILE, NULL) < 0) {
-                               DBGE("execl error\n");
+                               _LOGE("execl error\n");
                        }
 
                        _exit(100);
@@ -5120,7 +5424,7 @@ API int pkgmgr_parser_check_manifest_validation(const char *manifest)
                if (err < 0) {
                        if (errno == EINTR)
                                continue;
-                       DBGE("waitpid failed\n");
+                       _LOGE("waitpid failed\n");
                        return -1;
                }
        }
index b85984b..e9b933c 100755 (executable)
@@ -53,6 +53,8 @@ extern "C" {
 
 #define PKG_STRING_LEN_MAX 1024
 
+#define PKGMGR_PARSER_EMPTY_STR                ""
+
 /**
  * @brief List definitions.
  * All lists are doubly-linked, the last element is stored to list pointer,
@@ -467,6 +469,7 @@ typedef struct manifest_x {
        const char *root_path;          /**< package root path*/
        const char *csc_path;           /**< package csc path*/
        const char *nodisplay_setting;          /**< package no display setting menu*/
+       const char *main_package;               /**< main package id for sub-package(ug)*/
        struct icon_x *icon;            /**< package icon*/
        struct label_x *label;          /**< package label*/
        struct author_x *author;                /**< package author*/
index de46f96..3a65f26 100755 (executable)
 #include "pkgmgr_parser_internal.h"
 #include "pkgmgr_parser_db.h"
 
+#include "pkgmgr-info-debug.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "PKGMGR_PARSER"
+
 #define PKGMGR_PARSER_DB_FILE "/opt/dbspace/.pkgmgr_parser.db"
 #define PKGMGR_CERT_DB_FILE "/opt/dbspace/.pkgmgr_cert.db"
 #define MAX_QUERY_LEN          4096
+
 sqlite3 *pkgmgr_parser_db;
 sqlite3 *pkgmgr_cert_db;
 
@@ -247,6 +255,7 @@ static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
 static int __insert_manifest_info_in_db(manifest_x *mfx);
 static int __delete_manifest_info_from_db(manifest_x *mfx);
+static int __delete_subpkg_info_from_db(char *appid);
 static int __delete_appinfo_from_db(char *db_table, const char *appid);
 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
 static int __exec_query(char *query);
@@ -258,6 +267,24 @@ static void __preserve_guestmode_visibility_value(manifest_x *mfx);
 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
 
+static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
+{
+       if (coltxt[0])
+               __delete_subpkg_info_from_db(coltxt[0]);
+
+       return 0;
+}
+
+static char *__get_str(const char *str)
+{
+       if (str == NULL)
+       {
+               return PKGMGR_PARSER_EMPTY_STR;
+       }
+
+       return str;
+}
+
 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
 {
        int ret = -1;
@@ -267,21 +294,21 @@ static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
                    db_util_open(db_path, &handle,
                                 DB_UTIL_REGISTER_HOOK_METHOD);
                if (ret != SQLITE_OK) {
-                       DBG("connect db [%s] failed!\n",
+                       _LOGD("connect db [%s] failed!\n",
                               db_path);
                        return -1;
                }
                *db_handle = handle;
                return 0;
        }
-       DBG("%s DB does not exists. Create one!!\n", db_path);
+       _LOGD("%s DB does not exists. Create one!!\n", db_path);
 
        ret =
            db_util_open(db_path, &handle,
                         DB_UTIL_REGISTER_HOOK_METHOD);
 
        if (ret != SQLITE_OK) {
-               DBG("connect db [%s] failed!\n", db_path);
+               _LOGD("connect db [%s] failed!\n", db_path);
                return -1;
        }
        *db_handle = handle;
@@ -307,7 +334,7 @@ static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char
                }
        }
        if (appid == NULL) {
-               DBG("app id is NULL\n");
+               _LOGD("app id is NULL\n");
                return -1;
        }
        /*update guest mode visibility*/
@@ -338,7 +365,7 @@ static void __preserve_guestmode_visibility_value(manifest_x *mfx)
        if (SQLITE_OK !=
            sqlite3_exec(pkgmgr_parser_db, query,
                         __guestmode_visibility_cb, (void *)mfx, &error_message)) {
-               DBG("Don't execute query = %s error message = %s\n",
+               _LOGD("Don't execute query = %s error message = %s\n",
                       query, error_message);
                sqlite3_free(error_message);
        }
@@ -351,7 +378,7 @@ static int __initialize_db(sqlite3 *db_handle, const char *db_query)
        if (SQLITE_OK !=
            sqlite3_exec(db_handle, db_query,
                         NULL, NULL, &error_message)) {
-               DBG("Don't execute query = %s error message = %s\n",
+               _LOGD("Don't execute query = %s error message = %s\n",
                       db_query, error_message);
                sqlite3_free(error_message);
                return -1;
@@ -365,7 +392,7 @@ static int __exec_query(char *query)
        char *error_message = NULL;
        if (SQLITE_OK !=
            sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
-               DBG("Don't execute query = %s error message = %s\n", query,
+               _LOGD("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
                return -1;
@@ -447,7 +474,7 @@ static GList *__create_image_list(GList *locale, image_x *image)
 
 static void __printfunc(gpointer data, gpointer userdata)
 {
-       DBG("%s  ", (char*)data);
+       _LOGD("%s  ", (char*)data);
 }
 
 static void __trimfunc(GList* trim_list)
@@ -596,13 +623,21 @@ static void __insert_pkglocale_info(gpointer data, gpointer userdata)
        __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
        if (!label && !description && !icon && !license && !author)
                return;
+
        sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
                "package_label, package_icon, package_description, package_license, package_author) values " \
-               "('%q', '%q', '%q', '%q', '%q', '%q', '%q')", mfx->package, (char*)data,
-               label, icon, description, license, author);
+               "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
+               mfx->package,
+               (char*)data,
+               label,
+               icon,
+               __get_str(description),
+               __get_str(license),
+               __get_str(author));
+
        ret = __exec_query(query);
        if (ret == -1)
-               DBG("Package Localized Info DB Insert failed\n");
+               _LOGD("Package Localized Info DB Insert failed\n");
 }
 
 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
@@ -625,14 +660,21 @@ static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
                label, icon);
        ret = __exec_query(query);
        if (ret == -1)
-               DBG("Package UiApp Localized Info DB Insert failed\n");
+               _LOGD("Package UiApp Localized Info DB Insert failed\n");
 
        /*insert ui app locale info to pkg locale to get mainapp data */
        if (strcasecmp(up->mainapp, "true")==0) {
                sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
                        "package_label, package_icon, package_description, package_license, package_author) values " \
-                       "('%q', '%q', '%q', '%q', '%q', '%q', '%q')", up->package, (char*)data,
-                       label, icon, NULL, NULL, NULL);
+                       "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
+                       up->package,
+                       (char*)data,
+                       label,
+                       icon,
+                       PKGMGR_PARSER_EMPTY_STR,
+                       PKGMGR_PARSER_EMPTY_STR,
+                       PKGMGR_PARSER_EMPTY_STR);
+
                ret = __exec_query_no_msg(query);
 
                if (icon != NULL) {
@@ -663,7 +705,7 @@ static void __insert_uiapplication_icon_section_info(gpointer data, gpointer use
 
        ret = __exec_query(query);
        if (ret == -1)
-               DBG("Package UiApp Localized Info DB Insert failed\n");
+               _LOGD("Package UiApp Localized Info DB Insert failed\n");
 
 }
 
@@ -686,7 +728,7 @@ static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
 
        ret = __exec_query(query);
        if (ret == -1)
-               DBG("Package UiApp image Info DB Insert failed\n");
+               _LOGD("Package UiApp image Info DB Insert failed\n");
 
 }
 
@@ -711,7 +753,7 @@ static void __insert_serviceapplication_locale_info(gpointer data, gpointer user
                label, icon);
        ret = __exec_query(query);
        if (ret == -1)
-               DBG("Package ServiceApp Localized Info DB Insert failed\n");
+               _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
 }
 
 static int __insert_ui_mainapp_info(manifest_x *mfx)
@@ -726,7 +768,7 @@ static int __insert_ui_mainapp_info(manifest_x *mfx)
 
                ret = __exec_query(query);
                if (ret == -1) {
-                       DBG("Package UiApp Info DB Insert Failed\n");
+                       _LOGD("Package UiApp Info DB Insert Failed\n");
                        return -1;
                }
                if (strcasecmp(up->mainapp, "True")==0)
@@ -740,13 +782,13 @@ static int __insert_ui_mainapp_info(manifest_x *mfx)
                if (mfx->uiapplication && mfx->uiapplication->appid) {
                        snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
                } else {
-                       DBG("Not valid appid\n");
+                       _LOGD("Not valid appid\n");
                        return -1;
                }
 
                ret = __exec_query(query);
                if (ret == -1) {
-                       DBG("Package UiApp Info DB Insert Failed\n");
+                       _LOGD("Package UiApp Info DB Insert Failed\n");
                        return -1;
                }
 
@@ -760,7 +802,7 @@ static int __insert_ui_mainapp_info(manifest_x *mfx)
                "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
        ret = __exec_query(query);
        if (ret == -1) {
-               DBG("Package Info DB update Failed\n");
+               _LOGD("Package Info DB update Failed\n");
                return -1;
        }
 
@@ -782,13 +824,35 @@ static int __insert_uiapplication_info(manifest_x *mfx)
                        "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
                        "app_preload, app_submode, app_submode_mainid, component_type, package) " \
                        "values('%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
-                        up->appid, "uiapp", up->exec, up->nodisplay, up->type, "\0", up->multiple,
-                        "\0", up->taskmanage, up->enabled, up->hwacceleration, up->screenreader, up->mainapp, up->recentimage,
-                        up->launchcondition, up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_visibility, up->permission_type,
-                        mfx->preload, up->submode, up->submode_mainid, up->component_type, mfx->package);
+                        up->appid,
+                        "uiapp",
+                        up->exec,
+                        up->nodisplay,
+                        up->type,
+                        PKGMGR_PARSER_EMPTY_STR,
+                        up->multiple,
+                        PKGMGR_PARSER_EMPTY_STR,
+                        up->taskmanage,
+                        up->enabled,
+                        up->hwacceleration,
+                        up->screenreader,
+                        up->mainapp,
+                        __get_str(up->recentimage),
+                        up->launchcondition,
+                        up->indicatordisplay,
+                        __get_str(up->portraitimg),
+                        __get_str(up->landscapeimg),
+                        up->guestmode_visibility,
+                        up->permission_type,
+                        mfx->preload,
+                        up->submode,
+                        __get_str(up->submode_mainid),
+                        up->component_type,
+                        mfx->package);
+
                ret = __exec_query(query);
                if (ret == -1) {
-                       DBG("Package UiApp Info DB Insert Failed\n");
+                       _LOGD("Package UiApp Info DB Insert Failed\n");
                        return -1;
                }
                up = up->next;
@@ -814,7 +878,7 @@ static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
                                 up->appid, ct->name);
                        ret = __exec_query(query);
                        if (ret == -1) {
-                               DBG("Package UiApp Category Info DB Insert Failed\n");
+                               _LOGD("Package UiApp Category Info DB Insert Failed\n");
                                return -1;
                        }
                        ct = ct->next;
@@ -843,7 +907,7 @@ static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
                                         up->appid, md->key, md->value);
                                ret = __exec_query(query);
                                if (ret == -1) {
-                                       DBG("Package UiApp Metadata Info DB Insert Failed\n");
+                                       _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
                                        return -1;
                                }
                        }
@@ -872,7 +936,7 @@ static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
                                 up->appid, pm->type, pm->value);
                        ret = __exec_query(query);
                        if (ret == -1) {
-                               DBG("Package UiApp permission Info DB Insert Failed\n");
+                               _LOGD("Package UiApp permission Info DB Insert Failed\n");
                                return -1;
                        }
                        pm = pm->next;
@@ -930,7 +994,7 @@ static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
 
                                                        ret = __exec_query(query);
                                                        if (ret == -1) {
-                                                               DBG("Package UiApp AppSvc DB Insert Failed\n");
+                                                               _LOGD("Package UiApp AppSvc DB Insert Failed\n");
                                                                return -1;
                                                        }
                                                        memset(query, '\0', MAX_QUERY_LEN);
@@ -1000,11 +1064,15 @@ static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
                                                        snprintf(query, MAX_QUERY_LEN,
                                                                 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
                                                                "values('%s', '%s', '%s', '%s', '%s')",\
-                                                                up->appid, operation, uri, mime, subapp);
+                                                                up->appid,
+                                                                operation,
+                                                                __get_str(uri),
+                                                                __get_str(mime),
+                                                                __get_str(subapp));
 
                                                        ret = __exec_query(query);
                                                        if (ret == -1) {
-                                                               DBG("Package UiApp AppSvc DB Insert Failed\n");
+                                                               _LOGD("Package UiApp AppSvc DB Insert Failed\n");
                                                                return -1;
                                                        }
                                                        memset(query, '\0', MAX_QUERY_LEN);
@@ -1052,7 +1120,7 @@ static int __insert_uiapplication_share_request_info(manifest_x *mfx)
                                         up->appid, rq->text);
                                ret = __exec_query(query);
                                if (ret == -1) {
-                                       DBG("Package UiApp Share Request DB Insert Failed\n");
+                                       _LOGD("Package UiApp Share Request DB Insert Failed\n");
                                        return -1;
                                }
                                memset(query, '\0', MAX_QUERY_LEN);
@@ -1090,7 +1158,7 @@ static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
                                                 up->appid, df->path, al->text);
                                        ret = __exec_query(query);
                                        if (ret == -1) {
-                                               DBG("Package UiApp Share Allowed DB Insert Failed\n");
+                                               _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
                                                return -1;
                                        }
                                        memset(query, '\0', MAX_QUERY_LEN);
@@ -1120,7 +1188,7 @@ static int __insert_serviceapplication_info(manifest_x *mfx)
                         sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
                ret = __exec_query(query);
                if (ret == -1) {
-                       DBG("Package ServiceApp Info DB Insert Failed\n");
+                       _LOGD("Package ServiceApp Info DB Insert Failed\n");
                        return -1;
                }
                sp = sp->next;
@@ -1146,7 +1214,7 @@ static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
                                 sp->appid, ct->name);
                        ret = __exec_query(query);
                        if (ret == -1) {
-                               DBG("Package ServiceApp Category Info DB Insert Failed\n");
+                               _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
                                return -1;
                        }
                        ct = ct->next;
@@ -1175,7 +1243,7 @@ static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
                                         sp->appid, md->key, md->value);
                                ret = __exec_query(query);
                                if (ret == -1) {
-                                       DBG("Package ServiceApp Metadata Info DB Insert Failed\n");
+                                       _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
                                        return -1;
                                }
                        }
@@ -1204,7 +1272,7 @@ static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
                                 sp->appid, pm->type, pm->value);
                        ret = __exec_query(query);
                        if (ret == -1) {
-                               DBG("Package ServiceApp permission Info DB Insert Failed\n");
+                               _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
                                return -1;
                        }
                        pm = pm->next;
@@ -1260,7 +1328,7 @@ static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
                                                                 sp->appid, operation, uri, mime, subapp);
                                                        ret = __exec_query(query);
                                                        if (ret == -1) {
-                                                               DBG("Package UiApp AppSvc DB Insert Failed\n");
+                                                               _LOGD("Package UiApp AppSvc DB Insert Failed\n");
                                                                return -1;
                                                        }
                                                        memset(query, '\0', MAX_QUERY_LEN);
@@ -1329,10 +1397,14 @@ static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
                                                                snprintf(query, MAX_QUERY_LEN,
                                                                         "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
                                                                        "values('%s', '%s', '%s', '%s', '%s')",\
-                                                                        sp->appid, operation, uri, mime, subapp);
+                                                                        sp->appid,
+                                                                        operation,
+                                                                       __get_str(uri),
+                                                                       __get_str(mime),
+                                                                       __get_str(subapp));
                                                                ret = __exec_query(query);
                                                                if (ret == -1) {
-                                                                       DBG("Package UiApp AppSvc DB Insert Failed\n");
+                                                                       _LOGD("Package UiApp AppSvc DB Insert Failed\n");
                                                                        return -1;
                                                                }
                                                                memset(query, '\0', MAX_QUERY_LEN);
@@ -1382,7 +1454,7 @@ static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
                                         sp->appid, rq->text);
                                ret = __exec_query(query);
                                if (ret == -1) {
-                                       DBG("Package ServiceApp Share Request DB Insert Failed\n");
+                                       _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
                                        return -1;
                                }
                                memset(query, '\0', MAX_QUERY_LEN);
@@ -1422,7 +1494,7 @@ static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
                                                 sp->appid, df->path, al->text);
                                        ret = __exec_query(query);
                                        if (ret == -1) {
-                                               DBG("Package App Share Allowed DB Insert Failed\n");
+                                               _LOGD("Package App Share Allowed DB Insert Failed\n");
                                                return -1;
                                        }
                                        memset(query, '\0', MAX_QUERY_LEN);
@@ -1494,21 +1566,56 @@ static int __insert_manifest_info_in_db(manifest_x *mfx)
                "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
                "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
                "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
-                mfx->package, type, mfx->version, mfx->installlocation, mfx->package_size, mfx->removable, mfx->preload,
-                mfx->readonly, mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system,
-                auth_name, auth_email, auth_href, mfx->installed_time, mfx->installed_storage, mfx->storeclient_id, mfx->mainapp_id, mfx->package_url, path, mfx->csc_path);
-       ret = __exec_query(query);
-       if (ret == -1) {
-               DBG("Package Info DB Insert Failed\n");
-               if (type) {
-                       free(type);
-                       type = NULL;
+                mfx->package,
+                type,
+                mfx->version,
+                __get_str(mfx->installlocation),
+                __get_str(mfx->package_size),
+                mfx->removable,
+                mfx->preload,
+                mfx->readonly,
+                mfx->update,
+                mfx->appsetting,
+                mfx->nodisplay_setting,
+                mfx->system,
+                __get_str(auth_name),
+                __get_str(auth_email),
+                __get_str(auth_href),
+                mfx->installed_time,
+                mfx->installed_storage,
+                __get_str(mfx->storeclient_id),
+                mfx->mainapp_id,
+                __get_str(mfx->package_url),
+                path,
+                __get_str(mfx->csc_path));
+
+       /*If package dont have main_package tag, this package is main package.*/
+       if (mfx->main_package == NULL) {
+               ret = __exec_query(query);
+               if (ret == -1) {
+                       _LOGD("Package Info DB Insert Failed\n");
+                       if (type) {
+                               free(type);
+                               type = NULL;
+                       }
+                       if (path) {
+                               free(path);
+                               path = NULL;
+                       }
+                       return -1;
                }
-               if (path) {
-                       free(path);
-                       path = NULL;
+       } else {
+               /*If package has main_package tag, this package is sub package(ug, efl).
+               skip __exec_query for package_info and change pkgid with main_package*/
+               memset(root, '\0', MAX_QUERY_LEN);
+               snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
+               if (access(root, F_OK) == 0) {
+                       free((void *)mfx->package);
+                       mfx->package = strdup(mfx->main_package);
+               } else {
+                       _LOGE("main package[%s] is not installed\n", root);
+                       return -1;
                }
-               return -1;
        }
        if (type) {
                free(type);
@@ -1531,7 +1638,7 @@ static int __insert_manifest_info_in_db(manifest_x *mfx)
                                 mfx->package, pv->text);
                        ret = __exec_query(query);
                        if (ret == -1) {
-                               DBG("Package Privilege Info DB Insert Failed\n");
+                               _LOGD("Package Privilege Info DB Insert Failed\n");
                                return -1;
                        }
                        pv = pv->next;
@@ -1581,11 +1688,13 @@ static int __insert_manifest_info_in_db(manifest_x *mfx)
        __trimfunc(appimage);
 
        /*g_list_foreach(pkglocale, __printfunc, NULL);*/
-       /*DBG("\n");*/
+       /*_LOGD("\n");*/
        /*g_list_foreach(applocale, __printfunc, NULL);*/
 
-       /*package locale info*/
-       g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
+       /*package locale info, it is only for main package.*/
+       if (mfx->main_package == NULL)
+               g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
+
        /*native app locale info*/
        up = mfx->uiapplication;
        while(up != NULL)
@@ -1704,12 +1813,72 @@ static int __delete_appinfo_from_db(char *db_table, const char *appid)
                 "delete from %s where app_id='%s'", db_table, appid);
        ret = __exec_query(query);
        if (ret == -1) {
-               DBG("DB Deletion from table (%s) Failed\n", db_table);
+               _LOGD("DB Deletion from table (%s) Failed\n", db_table);
                return -1;
        }
        return 0;
 }
 
+static int __delete_subpkg_info_from_db(char *appid)
+{
+       int ret = -1;
+
+       ret = __delete_appinfo_from_db("package_app_info", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_localized_info", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_image_info", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_app_svc", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_app_control", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_app_category", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_app_permission", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
+       if (ret < 0)
+               return ret;
+       ret = __delete_appinfo_from_db("package_app_share_request", appid);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int __delete_subpkg_from_db(manifest_x *mfx)
+{
+       char query[MAX_QUERY_LEN] = { '\0' };
+       int ret = -1;
+       char *error_message = NULL;
+
+       snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
+       if (SQLITE_OK !=
+           sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
+               _LOGE("Don't execute query = %s error message = %s\n", query,
+                      error_message);
+               sqlite3_free(error_message);
+               return -1;
+       }
+       sqlite3_free(error_message);
+
+       return 0;
+}
+
 static int __delete_manifest_info_from_db(manifest_x *mfx)
 {
        char query[MAX_QUERY_LEN] = { '\0' };
@@ -1719,7 +1888,7 @@ static int __delete_manifest_info_from_db(manifest_x *mfx)
        /*Delete from cert table*/
        ret = pkgmgrinfo_delete_certinfo(mfx->package);
        if (ret) {
-               DBG("Cert Info  DB Delete Failed\n");
+               _LOGD("Cert Info  DB Delete Failed\n");
                return -1;
        }
 
@@ -1728,7 +1897,7 @@ static int __delete_manifest_info_from_db(manifest_x *mfx)
                 "delete from package_info where package='%s'", mfx->package);
        ret = __exec_query(query);
        if (ret == -1) {
-               DBG("Package Info DB Delete Failed\n");
+               _LOGD("Package Info DB Delete Failed\n");
                return -1;
        }
        memset(query, '\0', MAX_QUERY_LEN);
@@ -1738,7 +1907,7 @@ static int __delete_manifest_info_from_db(manifest_x *mfx)
                 "delete from package_localized_info where package='%s'", mfx->package);
        ret = __exec_query(query);
        if (ret == -1) {
-               DBG("Package Localized Info DB Delete Failed\n");
+               _LOGD("Package Localized Info DB Delete Failed\n");
                return -1;
        }
 
@@ -1747,7 +1916,7 @@ static int __delete_manifest_info_from_db(manifest_x *mfx)
                 "delete from package_privilege_info where package='%s'", mfx->package);
        ret = __exec_query(query);
        if (ret == -1) {
-               DBG("Package Privilege Info DB Delete Failed\n");
+               _LOGD("Package Privilege Info DB Delete Failed\n");
                return -1;
        }
 
@@ -1824,6 +1993,10 @@ static int __delete_manifest_info_from_db(manifest_x *mfx)
                        return ret;
                sp = sp->next;
        }
+
+       /* if main package has sub pkg, delete sub pkg data*/
+       __delete_subpkg_from_db(mfx);
+
        return 0;
 }
 
@@ -1836,7 +2009,7 @@ static int __update_preload_condition_in_db()
 
        ret = __exec_query(query);
        if (ret == -1)
-               DBG("Package preload_condition update failed\n");
+               _LOGD("Package preload_condition update failed\n");
 
        return ret;
 }
@@ -1847,83 +2020,83 @@ int pkgmgr_parser_initialize_db()
        /*Manifest DB*/
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
        if (ret == -1) {
-               DBG("package info DB initialization failed\n");
+               _LOGD("package info DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
        if (ret == -1) {
-               DBG("package localized info DB initialization failed\n");
+               _LOGD("package localized info DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
        if (ret == -1) {
-               DBG("package app app privilege DB initialization failed\n");
+               _LOGD("package app app privilege DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
        if (ret == -1) {
-               DBG("package app info DB initialization failed\n");
+               _LOGD("package app info DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
        if (ret == -1) {
-               DBG("package app localized info DB initialization failed\n");
+               _LOGD("package app localized info DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
        if (ret == -1) {
-               DBG("package app icon localized info DB initialization failed\n");
+               _LOGD("package app icon localized info DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
        if (ret == -1) {
-               DBG("package app image info DB initialization failed\n");
+               _LOGD("package app image info DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
        if (ret == -1) {
-               DBG("package app app control DB initialization failed\n");
+               _LOGD("package app app control DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
        if (ret == -1) {
-               DBG("package app app category DB initialization failed\n");
+               _LOGD("package app app category DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
        if (ret == -1) {
-               DBG("package app app category DB initialization failed\n");
+               _LOGD("package app app category DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
        if (ret == -1) {
-               DBG("package app app permission DB initialization failed\n");
+               _LOGD("package app app permission DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
        if (ret == -1) {
-               DBG("package app app svc DB initialization failed\n");
+               _LOGD("package app app svc DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
        if (ret == -1) {
-               DBG("package app share allowed DB initialization failed\n");
+               _LOGD("package app share allowed DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
        if (ret == -1) {
-               DBG("package app share request DB initialization failed\n");
+               _LOGD("package app share request DB initialization failed\n");
                return ret;
        }
        /*Cert DB*/
        ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
        if (ret == -1) {
-               DBG("package cert info DB initialization failed\n");
+               _LOGD("package cert info DB initialization failed\n");
                return ret;
        }
        ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
        if (ret == -1) {
-               DBG("package cert index info DB initialization failed\n");
+               _LOGD("package cert index info DB initialization failed\n");
                return ret;
        }
        return 0;
@@ -1935,13 +2108,13 @@ int pkgmgr_parser_check_and_create_db()
        /*Manifest DB*/
        ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, PKGMGR_PARSER_DB_FILE);
        if (ret) {
-               DBG("Manifest DB creation Failed\n");
+               _LOGD("Manifest DB creation Failed\n");
                return -1;
        }
        /*Cert DB*/
        ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, PKGMGR_CERT_DB_FILE);
        if (ret) {
-               DBG("Cert DB creation Failed\n");
+               _LOGD("Cert DB creation Failed\n");
                return -1;
        }
        return 0;
@@ -1956,13 +2129,13 @@ void pkgmgr_parser_close_db()
 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
 {
        if (mfx == NULL) {
-               DBG("manifest pointer is NULL\n");
+               _LOGD("manifest pointer is NULL\n");
                return -1;
        }
        int ret = 0;
        ret = pkgmgr_parser_check_and_create_db();
        if (ret == -1) {
-               DBG("Failed to open DB\n");
+               _LOGD("Failed to open DB\n");
                return ret;
        }
        ret = pkgmgr_parser_initialize_db();
@@ -1971,26 +2144,26 @@ API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
        /*Begin transaction*/
        ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
-               DBG("Failed to begin transaction\n");
+               _LOGD("Failed to begin transaction\n");
                ret = -1;
                goto err;
        }
-       DBG("Transaction Begin\n");
+       _LOGD("Transaction Begin\n");
        ret = __insert_manifest_info_in_db(mfx);
        if (ret == -1) {
-               DBG("Insert into DB failed. Rollback now\n");
+               _LOGD("Insert into DB failed. Rollback now\n");
                sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
                goto err;
        }
        /*Commit transaction*/
        ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
-               DBG("Failed to commit transaction. Rollback now\n");
+               _LOGD("Failed to commit transaction. Rollback now\n");
                sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
                ret = -1;
                goto err;
        }
-       DBG("Transaction Commit and End\n");
+       _LOGD("Transaction Commit and End\n");
 err:
        pkgmgr_parser_close_db();
        return ret;
@@ -1999,13 +2172,13 @@ err:
 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
 {
        if (mfx == NULL) {
-               DBG("manifest pointer is NULL\n");
+               _LOGD("manifest pointer is NULL\n");
                return -1;
        }
        int ret = 0;
        ret = pkgmgr_parser_check_and_create_db();
        if (ret == -1) {
-               DBG("Failed to open DB\n");
+               _LOGD("Failed to open DB\n");
                return ret;
        }
        ret = pkgmgr_parser_initialize_db();
@@ -2016,20 +2189,20 @@ API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
        /*Begin transaction*/
        ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
-               DBG("Failed to begin transaction\n");
+               _LOGD("Failed to begin transaction\n");
                ret = -1;
                goto err;
        }
-       DBG("Transaction Begin\n");
+       _LOGD("Transaction Begin\n");
        ret = __delete_manifest_info_from_db(mfx);
        if (ret == -1) {
-               DBG("Delete from DB failed. Rollback now\n");
+               _LOGD("Delete from DB failed. Rollback now\n");
                sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
                goto err;
        }
        ret = __insert_manifest_info_in_db(mfx);
        if (ret == -1) {
-               DBG("Insert into DB failed. Rollback now\n");
+               _LOGD("Insert into DB failed. Rollback now\n");
                sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
                goto err;
        }
@@ -2037,12 +2210,12 @@ API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
        /*Commit transaction*/
        ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
-               DBG("Failed to commit transaction. Rollback now\n");
+               _LOGD("Failed to commit transaction. Rollback now\n");
                sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
                ret = -1;
                goto err;
        }
-       DBG("Transaction Commit and End\n");
+       _LOGD("Transaction Commit and End\n");
 err:
        pkgmgr_parser_close_db();
        return ret;
@@ -2051,38 +2224,38 @@ err:
 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
 {
        if (mfx == NULL) {
-               DBG("manifest pointer is NULL\n");
+               _LOGD("manifest pointer is NULL\n");
                return -1;
        }
        int ret = 0;
        ret = pkgmgr_parser_check_and_create_db();
        if (ret == -1) {
-               DBG("Failed to open DB\n");
+               _LOGD("Failed to open DB\n");
                return ret;
        }
        /*Begin transaction*/
        ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
-               DBG("Failed to begin transaction\n");
+               _LOGD("Failed to begin transaction\n");
                ret = -1;
                goto err;
        }
-       DBG("Transaction Begin\n");
+       _LOGD("Transaction Begin\n");
        ret = __delete_manifest_info_from_db(mfx);
        if (ret == -1) {
-               DBG("Delete from DB failed. Rollback now\n");
+               _LOGD("Delete from DB failed. Rollback now\n");
                sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
                goto err;
        }
        /*Commit transaction*/
        ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
-               DBG("Failed to commit transaction, Rollback now\n");
+               _LOGD("Failed to commit transaction, Rollback now\n");
                sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
                ret = -1;
                goto err;
        }
-       DBG("Transaction Commit and End\n");
+       _LOGD("Transaction Commit and End\n");
 err:
        pkgmgr_parser_close_db();
        return ret;
@@ -2093,32 +2266,32 @@ API int pkgmgr_parser_update_preload_info_in_db()
        int ret = 0;
        ret = pkgmgr_parser_check_and_create_db();
        if (ret == -1) {
-               DBG("Failed to open DB\n");
+               _LOGD("Failed to open DB\n");
                return ret;
        }
        /*Begin transaction*/
        ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
-               DBG("Failed to begin transaction\n");
+               _LOGD("Failed to begin transaction\n");
                ret = -1;
                goto err;
        }
-       DBG("Transaction Begin\n");
+       _LOGD("Transaction Begin\n");
        ret = __update_preload_condition_in_db();
        if (ret == -1) {
-               DBG("__update_preload_condition_in_db failed. Rollback now\n");
+               _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
                sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
                goto err;
        }
        /*Commit transaction*/
        ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
-               DBG("Failed to commit transaction, Rollback now\n");
+               _LOGD("Failed to commit transaction, Rollback now\n");
                sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
                ret = -1;
                goto err;
        }
-       DBG("Transaction Commit and End\n");
+       _LOGD("Transaction Commit and End\n");
 err:
        pkgmgr_parser_close_db();
        return ret;
index 7d422b3..a891b0b 100755 (executable)
 #ifndef __PKGMGR_PARSER_INTERNAL_H__
 #define __PKGMGR_PARSER_INTERNAL_H__
 
-
-/* debug output */
-#if defined(NDEBUG)
-#define DBG(fmt, args...)
-#define __SET_DBG_OUTPUT(fp)
-#elif defined(PRINT)
-#include <stdio.h>
-FILE *___log = NULL;
-#define DBG(fmt, args...) \
-       {if (!___log) ___log = stderr; \
-        fprintf(___log, "[DBG:PMS]%s:%d:%s(): " fmt "\n",\
-        basename(__FILE__), __LINE__, __func__, ##args); fflush(___log); }
-#define __SET_DBG_OUTPUT(fp) \
-       (___log = fp)
-#else
-#include <dlog.h>
-#undef LOG_TAG
-#define LOG_TAG "PKGMGR_PARSER"
-
-#define DBGE(fmt, arg...) LOGE(fmt,##arg)
-#define DBG(fmt, arg...) LOGD(fmt,##arg)
-#endif
-
-
 #ifndef API
 #define API __attribute__ ((visibility("default")))
 #endif
diff --git a/parser/pkgmgr_parser_signature.c b/parser/pkgmgr_parser_signature.c
new file mode 100644 (file)
index 0000000..ede335d
--- /dev/null
@@ -0,0 +1,734 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <pkgmgr_parser.h>
+#include "pkgmgr_parser_signature.h"
+
+#define ASCII(s) (const char *)s
+#define XMLCHAR(s) (const xmlChar *)s
+
+static int _ri_next_child_element(xmlTextReaderPtr reader, int depth)
+{
+       int ret = xmlTextReaderRead(reader);
+       int cur = xmlTextReaderDepth(reader);
+       while (ret == 1) {
+
+               switch (xmlTextReaderNodeType(reader)) {
+               case XML_READER_TYPE_ELEMENT:
+                       if (cur == depth + 1)
+                               return 1;
+                       break;
+               case XML_READER_TYPE_TEXT:
+                       if (cur == depth + 1)
+                               return 0;
+                       break;
+               case XML_READER_TYPE_END_ELEMENT:
+                       if (cur == depth)
+                               return 0;
+                       break;
+               default:
+                       if (cur <= depth)
+                               return 0;
+                       break;
+               }
+               ret = xmlTextReaderRead(reader);
+               cur = xmlTextReaderDepth(reader);
+       }
+       return ret;
+}
+
+static void _ri_free_transform(transform_x *transform)
+{
+       if (transform == NULL)
+               return;
+       if (transform->algorithm) {
+               free((void *)transform->algorithm);
+               transform->algorithm = NULL;
+       }
+       free((void*)transform);
+       transform = NULL;
+}
+
+static void _ri_free_cannonicalizationmethod(cannonicalizationmethod_x *cannonicalizationmethod)
+{
+       if (cannonicalizationmethod == NULL)
+               return;
+       if (cannonicalizationmethod->algorithm) {
+               free((void *)cannonicalizationmethod->algorithm);
+               cannonicalizationmethod->algorithm = NULL;
+       }
+       free((void*)cannonicalizationmethod);
+       cannonicalizationmethod = NULL;
+}
+
+static void _ri_free_signaturemethod(signaturemethod_x *signaturemethod)
+{
+       if (signaturemethod == NULL)
+               return;
+       if (signaturemethod->algorithm) {
+               free((void *)signaturemethod->algorithm);
+               signaturemethod->algorithm = NULL;
+       }
+       free((void*)signaturemethod);
+       signaturemethod = NULL;
+}
+
+static void _ri_free_digestmethod(digestmethod_x *digestmethod)
+{
+       if (digestmethod == NULL)
+               return;
+       if (digestmethod->algorithm) {
+               free((void *)digestmethod->algorithm);
+               digestmethod->algorithm = NULL;
+       }
+       free((void*)digestmethod);
+       digestmethod = NULL;
+}
+
+static void _ri_free_digestvalue(digestvalue_x *digestvalue)
+{
+       if (digestvalue == NULL)
+               return;
+       if (digestvalue->text) {
+               free((void *)digestvalue->text);
+               digestvalue->text = NULL;
+       }
+       free((void*)digestvalue);
+       digestvalue = NULL;
+}
+
+static void _ri_free_signaturevalue(signaturevalue_x *signaturevalue)
+{
+       if (signaturevalue == NULL)
+               return;
+       if (signaturevalue->text) {
+               free((void *)signaturevalue->text);
+               signaturevalue->text = NULL;
+       }
+       free((void*)signaturevalue);
+       signaturevalue = NULL;
+}
+
+static void _ri_free_x509certificate(x509certificate_x *x509certificate)
+{
+       if (x509certificate == NULL)
+               return;
+       if (x509certificate->text) {
+               free((void *)x509certificate->text);
+               x509certificate->text = NULL;
+       }
+       free((void*)x509certificate);
+       x509certificate = NULL;
+}
+
+static void _ri_free_x509data(x509data_x *x509data)
+{
+       if (x509data == NULL)
+               return;
+       if (x509data->x509certificate) {
+               x509certificate_x *x509certificate = x509data->x509certificate;
+               x509certificate_x *tmp = NULL;
+               while(x509certificate != NULL) {
+                       tmp = x509certificate->next;
+                       _ri_free_x509certificate(x509certificate);
+                       x509certificate = tmp;
+               }
+       }
+       free((void*)x509data);
+       x509data = NULL;
+}
+
+static void _ri_free_keyinfo(keyinfo_x *keyinfo)
+{
+       if (keyinfo == NULL)
+               return;
+       if (keyinfo->x509data) {
+               x509data_x *x509data = keyinfo->x509data;
+               x509data_x *tmp = NULL;
+               while(x509data != NULL) {
+                       tmp = x509data->next;
+                       _ri_free_x509data(x509data);
+                       x509data = tmp;
+               }
+       }
+       free((void*)keyinfo);
+       keyinfo = NULL;
+}
+
+static void _ri_free_transforms(transforms_x *transforms)
+{
+       if (transforms == NULL)
+               return;
+       if (transforms->transform) {
+               transform_x *transform = transforms->transform;
+               transform_x *tmp = NULL;
+               while(transform != NULL) {
+                       tmp = transform->next;
+                       _ri_free_transform(transform);
+                       transform = tmp;
+               }
+       }
+       free((void*)transforms);
+       transforms = NULL;
+}
+
+static void _ri_free_reference(reference_x *reference)
+{
+       if (reference == NULL)
+               return;
+       if (reference->digestmethod) {
+               digestmethod_x *digestmethod = reference->digestmethod;
+               digestmethod_x *tmp = NULL;
+               while(digestmethod != NULL) {
+                       tmp = digestmethod->next;
+                       _ri_free_digestmethod(digestmethod);
+                       digestmethod = tmp;
+               }
+       }
+       if (reference->digestvalue) {
+               digestvalue_x *digestvalue = reference->digestvalue;
+               digestvalue_x *tmp = NULL;
+               while(digestvalue != NULL) {
+                       tmp = digestvalue->next;
+                       _ri_free_digestvalue(digestvalue);
+                       digestvalue = tmp;
+               }
+       }
+       if (reference->transforms) {
+               transforms_x *transforms = reference->transforms;
+               transforms_x *tmp = NULL;
+               while(transforms != NULL) {
+                       tmp = transforms->next;
+                       _ri_free_transforms(transforms);
+                       transforms = tmp;
+               }
+       }
+       free((void*)reference);
+       reference = NULL;
+}
+
+static void _ri_free_signedinfo(signedinfo_x *signedinfo)
+{
+       if (signedinfo == NULL)
+               return;
+       if (signedinfo->cannonicalizationmethod) {
+               cannonicalizationmethod_x *cannonicalizationmethod = signedinfo->cannonicalizationmethod;
+               cannonicalizationmethod_x *tmp = NULL;
+               while(cannonicalizationmethod != NULL) {
+                       tmp = cannonicalizationmethod->next;
+                       _ri_free_cannonicalizationmethod(cannonicalizationmethod);
+                       cannonicalizationmethod = tmp;
+               }
+       }
+       if (signedinfo->signaturemethod) {
+               signaturemethod_x *signaturemethod = signedinfo->signaturemethod;
+               signaturemethod_x *tmp = NULL;
+               while(signaturemethod != NULL) {
+                       tmp = signaturemethod->next;
+                       _ri_free_signaturemethod(signaturemethod);
+                       signaturemethod = tmp;
+               }
+       }
+       if (signedinfo->reference) {
+               reference_x *reference = signedinfo->reference;
+               reference_x *tmp = NULL;
+               while(reference != NULL) {
+                       tmp = reference->next;
+                       _ri_free_reference(reference);
+                       reference = tmp;
+               }
+       }
+       free((void*)signedinfo);
+       signedinfo = NULL;
+}
+
+void _ri_free_signature_xml(signature_x *sigx)
+{
+       if (sigx == NULL)
+               return;
+       if (sigx->id) {
+               free((void *)sigx->id);
+               sigx->id = NULL;
+       }
+       if (sigx->xmlns) {
+               free((void *)sigx->xmlns);
+               sigx->xmlns = NULL;
+       }
+       if (sigx->signedinfo) {
+               signedinfo_x *signedinfo = sigx->signedinfo;
+               signedinfo_x *tmp = NULL;
+               while(signedinfo != NULL) {
+                       tmp = signedinfo->next;
+                       _ri_free_signedinfo(signedinfo);
+                       signedinfo = tmp;
+               }
+       }
+       if (sigx->signaturevalue) {
+               signaturevalue_x *signaturevalue = sigx->signaturevalue;
+               signaturevalue_x *tmp = NULL;
+               while(signaturevalue != NULL) {
+                       tmp = signaturevalue->next;
+                       _ri_free_signaturevalue(signaturevalue);
+                       signaturevalue = tmp;
+               }
+       }
+       if (sigx->keyinfo) {
+               keyinfo_x *keyinfo = sigx->keyinfo;
+               keyinfo_x *tmp = NULL;
+               while(keyinfo != NULL) {
+                       tmp = keyinfo->next;
+                       _ri_free_keyinfo(keyinfo);
+                       keyinfo = tmp;
+               }
+       }
+       /*Object will be freed when it will be parsed in future*/
+       free((void*)sigx);
+       sigx = NULL;
+}
+
+static int _ri_process_digestmethod(xmlTextReaderPtr reader, digestmethod_x *digestmethod)
+{
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")))
+               digestmethod->algorithm = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")));
+       return 0;
+}
+
+static int _ri_process_digestvalue(xmlTextReaderPtr reader, digestvalue_x *digestvalue)
+{
+       xmlTextReaderRead(reader);
+       if (xmlTextReaderValue(reader))
+               digestvalue->text = ASCII(xmlTextReaderValue(reader));
+       return 0;
+}
+
+static int _ri_process_transform(xmlTextReaderPtr reader, transform_x *transform)
+{
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")))
+               transform->algorithm = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")));
+       return 0;
+}
+
+static int _ri_process_transforms(xmlTextReaderPtr reader, transforms_x *transforms)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       transform_x *tmp1 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       // _d_msg(DEBUG_ERR, "node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "Transform") == 0) {
+                       transform_x *transform = calloc(1, sizeof(transform_x));
+                       if (transform == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(transforms->transform, transform);
+                       ret = _ri_process_transform(reader, transform);
+               } else {
+                       // _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (transforms->transform) {
+               LISTHEAD(transforms->transform, tmp1);
+               transforms->transform = tmp1;
+       }
+       return ret;
+}
+
+static int _ri_process_cannonicalizationmethod(xmlTextReaderPtr reader, cannonicalizationmethod_x *cannonicalizationmethod)
+{
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")))
+               cannonicalizationmethod->algorithm = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")));
+       return 0;
+}
+
+static int _ri_process_signaturemethod(xmlTextReaderPtr reader, signaturemethod_x *signaturemethod)
+{
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")))
+               signaturemethod->algorithm = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Algorithm")));
+       return 0;
+}
+
+static int _ri_process_reference(xmlTextReaderPtr reader, reference_x *reference)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       digestmethod_x *tmp1 = NULL;
+       digestvalue_x *tmp2 = NULL;
+       transforms_x *tmp3 = NULL;
+
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("URI")))
+               reference->uri = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("URI")));
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       // _d_msg(DEBUG_ERR, "node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "DigestMethod") == 0) {
+                       digestmethod_x *digestmethod = calloc(1, sizeof(digestmethod_x));
+                       if (digestmethod == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(reference->digestmethod, digestmethod);
+                       ret = _ri_process_digestmethod(reader, digestmethod);
+               } else if (strcmp(ASCII(node), "DigestValue") == 0) {
+                       digestvalue_x *digestvalue = calloc(1, sizeof(digestvalue_x));
+                       if (digestvalue == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(reference->digestvalue, digestvalue);
+                       ret = _ri_process_digestvalue(reader, digestvalue);
+               } else if (strcmp(ASCII(node), "Transforms") == 0) {
+                       transforms_x *transforms = calloc(1, sizeof(transforms_x));
+                       if (transforms == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(reference->transforms, transforms);
+                       ret = _ri_process_transforms(reader, transforms);
+               } else {
+                       // _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (reference->digestmethod) {
+               LISTHEAD(reference->digestmethod, tmp1);
+               reference->digestmethod = tmp1;
+       }
+       if (reference->digestvalue) {
+               LISTHEAD(reference->digestvalue, tmp2);
+               reference->digestvalue = tmp2;
+       }
+       if (reference->transforms) {
+               LISTHEAD(reference->transforms, tmp3);
+               reference->transforms = tmp3;
+       }
+       return ret;
+}
+
+static int _ri_process_x509certificate(xmlTextReaderPtr reader, x509certificate_x *x509certificate)
+{
+       xmlTextReaderRead(reader);
+       if (xmlTextReaderValue(reader)) {
+               x509certificate->text = ASCII(xmlTextReaderValue(reader));
+               // _d_msg(DEBUG_INFO, "certlen=%d, x509certificate : %s", strlen(x509certificate->text), x509certificate->text);
+       }
+       return 0;
+}
+
+static int _ri_process_x509data(xmlTextReaderPtr reader, x509data_x *x509data)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       x509certificate_x *tmp1 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       // _d_msg(DEBUG_ERR, "node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "X509Certificate") == 0) {
+                       x509certificate_x *x509certificate = calloc(1, sizeof(x509certificate_x));
+                       if (x509certificate == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(x509data->x509certificate, x509certificate);
+                       ret = _ri_process_x509certificate(reader, x509certificate);
+               } else {
+                       // _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (x509data->x509certificate) {
+               LISTHEAD(x509data->x509certificate, tmp1);
+               x509data->x509certificate = tmp1;
+       }
+       return ret;
+}
+
+#if 0
+static int _ri_process_object(xmlTextReaderPtr reader, object_x *object)
+{
+       /*To be parsed later*/
+       return 0;
+}
+#endif
+
+static int _ri_process_keyinfo(xmlTextReaderPtr reader, keyinfo_x *keyinfo)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       x509data_x *tmp1 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       // _d_msg(DEBUG_ERR, "node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "X509Data") == 0) {
+                       x509data_x *x509data = calloc(1, sizeof(x509data_x));
+                       if (x509data == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(keyinfo->x509data, x509data);
+                       ret = _ri_process_x509data(reader, x509data);
+               } else {
+                       // _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (keyinfo->x509data) {
+               LISTHEAD(keyinfo->x509data, tmp1);
+               keyinfo->x509data = tmp1;
+       }
+       return ret;
+}
+
+static int _ri_process_signaturevalue(xmlTextReaderPtr reader, signaturevalue_x *signaturevalue)
+{
+       xmlTextReaderRead(reader);
+       if (xmlTextReaderValue(reader)) {
+               signaturevalue->text = ASCII(xmlTextReaderValue(reader));
+               // _d_msg(DEBUG_INFO, "siglen=%d SignatureValue %s", strlen(signaturevalue->text), signaturevalue->text);
+       }
+       return 0;
+}
+
+static int _ri_process_signedinfo(xmlTextReaderPtr reader, signedinfo_x *signedinfo)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       cannonicalizationmethod_x *tmp1 = NULL;
+       signaturemethod_x *tmp2 = NULL;
+       reference_x *tmp3 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       // _d_msg(DEBUG_ERR, "node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "CanonicalizationMethod") == 0) {
+                       cannonicalizationmethod_x *cannonicalizationmethod = calloc(1, sizeof(cannonicalizationmethod_x));
+                       if (cannonicalizationmethod == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(signedinfo->cannonicalizationmethod, cannonicalizationmethod);
+                       ret = _ri_process_cannonicalizationmethod(reader, cannonicalizationmethod);
+               } else if (strcmp(ASCII(node), "SignatureMethod") == 0) {
+                       signaturemethod_x *signaturemethod = calloc(1, sizeof(signaturemethod_x));
+                       if (signaturemethod == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(signedinfo->signaturemethod, signaturemethod);
+                       ret = _ri_process_signaturemethod(reader, signaturemethod);
+               } else if (strcmp(ASCII(node), "Reference") == 0) {
+                       reference_x *reference = calloc(1, sizeof(reference_x));
+                       if (reference == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(signedinfo->reference, reference);
+                       ret = _ri_process_reference(reader, reference);
+               } else {
+                       // _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (signedinfo->cannonicalizationmethod) {
+               LISTHEAD(signedinfo->cannonicalizationmethod, tmp1);
+               signedinfo->cannonicalizationmethod = tmp1;
+       }
+       if (signedinfo->signaturemethod) {
+               LISTHEAD(signedinfo->signaturemethod, tmp2);
+               signedinfo->signaturemethod = tmp2;
+       }
+       if (signedinfo->reference) {
+               LISTHEAD(signedinfo->reference, tmp3);
+               signedinfo->reference = tmp3;
+       }
+       return ret;
+}
+
+static int _ri_process_sign(xmlTextReaderPtr reader, signature_x *sigx)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       signedinfo_x *tmp1 = NULL;
+       signaturevalue_x *tmp2 = NULL;
+       keyinfo_x *tmp3 = NULL;
+       object_x *tmp4 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       // _d_msg(DEBUG_ERR, "node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "SignedInfo") == 0) {
+                       signedinfo_x *signedinfo = calloc(1, sizeof(signedinfo_x));
+                       if (signedinfo == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(sigx->signedinfo, signedinfo);
+                       ret = _ri_process_signedinfo(reader, signedinfo);
+               } else if (strcmp(ASCII(node), "SignatureValue") == 0) {
+                       signaturevalue_x *signaturevalue = calloc(1, sizeof(signaturevalue_x));
+                       if (signaturevalue == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(sigx->signaturevalue, signaturevalue);
+                       ret = _ri_process_signaturevalue(reader, signaturevalue);
+               } else if (strcmp(ASCII(node), "KeyInfo") == 0) {
+                       keyinfo_x *keyinfo = calloc(1, sizeof(keyinfo_x));
+                       if (keyinfo == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(sigx->keyinfo, keyinfo);
+                       ret = _ri_process_keyinfo(reader, keyinfo);
+               } else if (strcmp(ASCII(node), "Object") == 0) {
+                       /*
+                       object_x *object = calloc(1, sizeof(object_x));
+                       if (object == NULL) {
+                               // _d_msg(DEBUG_ERR, "Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(sigx->object, object);
+                       ret = _ri_process_object(reader, object);
+                       */
+                       continue;
+               } else {
+                       // _d_msg(DEBUG_INFO, "Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (sigx->signedinfo) {
+               LISTHEAD(sigx->signedinfo, tmp1);
+               sigx->signedinfo = tmp1;
+       }
+       if (sigx->signaturevalue) {
+               LISTHEAD(sigx->signaturevalue, tmp2);
+               sigx->signaturevalue = tmp2;
+       }
+       if (sigx->keyinfo) {
+               LISTHEAD(sigx->keyinfo, tmp3);
+               sigx->keyinfo = tmp3;
+       }
+       if (sigx->object) {
+               LISTHEAD(sigx->object, tmp4);
+               sigx->object = tmp4;
+       }
+       return ret;
+}
+
+static int _ri_process_signature(xmlTextReaderPtr reader, signature_x *sigx)
+{
+       const xmlChar *node = NULL;
+       int ret = -1;
+
+       if ((ret = _ri_next_child_element(reader, -1))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       // _d_msg(DEBUG_ERR, "Node is null");
+                       return -1;
+               }
+               if (!strcmp(ASCII(node), "Signature")) {
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("Id")))
+                               sigx->id = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("Id")));
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")))
+                               sigx->xmlns = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")));
+                       ret = _ri_process_sign(reader, sigx);
+               } else {
+                       // _d_msg(DEBUG_ERR, "No Signature element found\n");
+                       return -1;
+               }
+       }
+       return ret;
+}
+
+signature_x *_ri_process_signature_xml(const char *signature_file)
+{
+       xmlTextReaderPtr reader;
+       signature_x *sigx = NULL;
+
+       reader = xmlReaderForFile(signature_file, NULL, 0);
+
+       if (reader) {
+               sigx = calloc(1, sizeof(signature_x));
+               if (sigx) {
+                       if (_ri_process_signature(reader, sigx) < 0) {
+                               /* error in parsing. Let's display some hint where we failed */
+                               // _d_msg(DEBUG_ERR, "Syntax error in processing signature in the above line\n");
+                               _ri_free_signature_xml(sigx);
+                               xmlFreeTextReader(reader);
+                               return NULL;
+                       }
+               } else {
+                       // _d_msg(DEBUG_ERR, "Calloc failed\n");
+               }
+               xmlFreeTextReader(reader);
+       } else {
+               // _d_msg(DEBUG_ERR, "Unable to create xml reader\n");
+       }
+       return sigx;
+}
diff --git a/parser/pkgmgr_parser_signature.h b/parser/pkgmgr_parser_signature.h
new file mode 100644 (file)
index 0000000..d1d8449
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __PKGMGR_PARSER_SIGNATURE_H_
+#define __PKGMGR_PARSER_SIGNATURE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
+
+typedef struct transform_x {
+       const char *algorithm;
+       struct transform_x *prev;
+       struct transform_x *next;
+} transform_x;
+
+typedef struct digestmethod_x {
+       const char *algorithm;
+       struct digestmethod_x *prev;
+       struct digestmethod_x *next;
+} digestmethod_x;
+
+typedef struct digestvalue_x {
+       const char *text;
+       struct digestvalue_x *prev;
+       struct digestvalue_x *next;
+} digestvalue_x;
+
+typedef struct transforms_x {
+       struct transform_x *transform;
+       struct transforms_x *prev;
+       struct transforms_x *next;
+} transforms_x;
+
+typedef struct x509certificate_x {
+       const char *text;
+       struct x509certificate_x *prev;
+       struct x509certificate_x *next;
+} x509certificate_x;
+
+typedef struct reference_x {
+       const char *uri;
+       struct transforms_x *transforms;
+       struct digestmethod_x *digestmethod;
+       struct digestvalue_x *digestvalue;
+       struct reference_x *prev;
+       struct reference_x *next;
+} reference_x;
+
+typedef struct cannonicalizationmethod_x {
+       const char *algorithm;
+       struct cannonicalizationmethod_x *prev;
+       struct cannonicalizationmethod_x *next;
+} cannonicalizationmethod_x;
+
+typedef struct signaturemethod_x {
+       const char *algorithm;
+       struct signaturemethod_x *prev;
+       struct signaturemethod_x *next;
+} signaturemethod_x;
+
+typedef struct x509data_x {
+       x509certificate_x *x509certificate;
+       struct x509data_x *prev;
+       struct x509data_x *next;
+} x509data_x;
+
+typedef struct signedinfo_x {
+       struct cannonicalizationmethod_x *cannonicalizationmethod;
+       struct signaturemethod_x *signaturemethod;
+       struct reference_x *reference;
+       struct signedinfo_x *prev;
+       struct signedinfo_x *next;
+} signedinfo_x;
+
+typedef struct signaturevalue_x {
+       const char *text;
+       struct signaturevalue_x *prev;
+       struct signaturevalue_x *next;
+} signaturevalue_x;
+
+typedef struct keyinfo_x {
+       struct x509data_x *x509data;
+       struct keyinfo_x *prev;
+       struct keyinfo_x *next;
+} keyinfo_x;
+
+/*This will be parsed later when requirement arises*/
+typedef struct object_x {
+       const char *id;
+       struct object_x *prev;
+       struct object_x *next;
+} object_x;
+
+typedef struct signature_x {   /*signature xml*/
+       const char *id;         /* distributor or author sign*/
+       const char *xmlns;      /* namespace*/
+       struct signedinfo_x *signedinfo;        /*signature data*/
+       struct signaturevalue_x *signaturevalue;        /* signature value*/
+       struct keyinfo_x *keyinfo;      /*cert info*/
+       struct object_x *object;        /*other parameters in object tag*/
+} signature_x;
+
+
+signature_x *_ri_process_signature_xml(const char *signature_file);
+void _ri_free_signature_xml(signature_x *sigx);
+
+#ifdef __cplusplus
+}
+#endif                         /* __cplusplus */
+#endif                         /* __PKGMGR_PARSER_SIGNATURE_H_ */
index 0883a71..4691148 100755 (executable)
 #include <dirent.h>
 #include <sys/stat.h>
 
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "PKGMGR_INFO"
+
 #define ASC_CHAR(s) (const char *)s
 #define XML_CHAR(s) (const xmlChar *)s
 
@@ -1100,6 +1105,11 @@ static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->manifest_info->mainapp_id = strdup(coltxt[i]);
                        else
                                info->manifest_info->mainapp_id = NULL;
+               } else if (strcmp(colname[i], "storeclient_id") == 0 ){
+                       if (coltxt[i])
+                               info->manifest_info->storeclient_id = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->storeclient_id = NULL;
                } else if (strcmp(colname[i], "root_path") == 0 ){
                        if (coltxt[i])
                                info->manifest_info->root_path = strdup(coltxt[i]);
@@ -2747,7 +2757,7 @@ API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **d
                if (ptr->lang) {
                        if (strcmp(ptr->lang, locale) == 0) {
                                *description = (char *)ptr->text;
-                               if (strcasecmp(*description, "(null)") == 0) {
+                               if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
                                        locale = DEFAULT_LOCALE;
                                        continue;
                                } else
@@ -2778,7 +2788,7 @@ API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **a
                if (ptr->lang) {
                        if (strcmp(ptr->lang, locale) == 0) {
                                *author_name = (char *)ptr->text;
-                               if (strcasecmp(*author_name, "(null)") == 0) {
+                               if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
                                        locale = DEFAULT_LOCALE;
                                        continue;
                                } else
@@ -3847,7 +3857,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
 
        /*get system locale*/
        syslocale = vconf_get_str(VCONFKEY_LANGSET);
-       tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
+       retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
 
        /*get locale on db*/
        locale = __convert_system_locale_to_manifest_locale(syslocale);
@@ -3875,7 +3885,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
 
        /*open db */
        ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
-       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+       tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
 
        appinfo->package = strdup(info->manifest_info->package);
        snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
diff --git a/tag_parser_list.txt.in b/tag_parser_list.txt.in
new file mode 100644 (file)
index 0000000..df204e2
--- /dev/null
@@ -0,0 +1,7 @@
+shortcut-list
+livebox
+account
+notifications
+privileges
+ime
+font
\ No newline at end of file