Fix the exception about getting effectimage
[platform/core/appfw/pkgmgr-info.git] / parser / pkgmgr_parser.c
old mode 100755 (executable)
new mode 100644 (file)
index f553ec5..b672cf3
 #include <libxml/xmlreader.h>
 #include <libxml/xmlschemas.h>
 #include <vconf.h>
+#include <glib.h>
+#include <grp.h>
+
+#include "pkgmgr-info.h"
+#include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_debug.h"
 
 #include "pkgmgr_parser.h"
 #include "pkgmgr_parser_internal.h"
 #include "pkgmgr_parser_db.h"
-#include "pkgmgr-info.h"
 
-#define MANIFEST_RW_DIRECTORY "/opt/share/packages"
-#define MANIFEST_RO_DIRECTORY "/usr/share/packages"
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "PKGMGR_PARSER"
+
 #define ASCII(s) (const char *)s
 #define XMLCHAR(s) (const xmlChar *)s
 
+//#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/metadata_parser_list.txt"
+#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/mdparser_list.txt"
+#define METADATA_PARSER_NAME   "metadataparser:"
+
+#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
+#define OWNER_ROOT 0
+#define BUFSIZE 4096
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+
 /* operation_type */
 typedef enum {
        ACTION_INSTALL = 0,
        ACTION_UPGRADE,
        ACTION_UNINSTALL,
+       ACTION_FOTA,
        ACTION_MAX
 } ACTION_TYPE;
 
+/* plugin process_type */
+typedef enum {
+       PLUGIN_PRE_PROCESS = 0,
+       PLUGIN_POST_PROCESS
+} PLUGIN_PROCESS_TYPE;
+
+typedef struct {
+       const char *key;
+       const char *value;
+} __metadata_t;
+
+typedef struct {
+       const char *name;
+} __category_t;
+
 const char *package;
 
 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label);
-static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege);
-static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges);
-static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile);
-static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed);
-static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation);
-static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri);
-static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime);
-static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp);
-static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition);
+static int __ps_process_privilege(xmlTextReaderPtr reader, const char **privilege);
+static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges);
+static int __ps_process_allowed(xmlTextReaderPtr reader, const char **allowed);
+static int __ps_process_condition(xmlTextReaderPtr reader, const char **condition);
 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
-static int __ps_process_category(xmlTextReaderPtr reader, category_x *category);
+static int __ps_process_category(xmlTextReaderPtr reader, const char **category);
 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
-static int __ps_process_resolution(xmlTextReaderPtr reader, resolution_x *resolution);
-static int __ps_process_request(xmlTextReaderPtr reader, request_x *request);
+static int __ps_process_request(xmlTextReaderPtr reader, const char **request);
 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
-static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc);
-static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions);
+static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions);
 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
-static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon);
+static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
-static int __ps_process_capability(xmlTextReaderPtr reader, capability_x *capability);
 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
-static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol);
+static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol);
 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
-static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication);
-static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication);
-static int __ps_process_font(xmlTextReaderPtr reader, font_x *font);
-static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme);
-static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon);
-static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime);
-static void __ps_free_label(label_x *label);
-static void __ps_free_privilege(privilege_x *privilege);
-static void __ps_free_privileges(privileges_x *privileges);
-static void __ps_free_deviceprofile(deviceprofile_x * deviceprofile);
-static void __ps_free_allowed(allowed_x *allowed);
-static void __ps_free_operation(operation_x *operation);
-static void __ps_free_uri(uri_x *uri);
-static void __ps_free_mime(mime_x *mime);
-static void __ps_free_subapp(subapp_x *subapp);
-static void __ps_free_condition(condition_x *condition);
-static void __ps_free_notification(notification_x *notifiation);
-static void __ps_free_category(category_x *category);
-static void __ps_free_metadata(metadata_x *metadata);
-static void __ps_free_permission(permission_x *permission);
-static void __ps_free_compatibility(compatibility_x *compatibility);
-static void __ps_free_resolution(resolution_x *resolution);
-static void __ps_free_request(request_x *request);
-static void __ps_free_define(define_x *define);
-static void __ps_free_appsvc(appsvc_x *appsvc);
-static void __ps_free_launchconditions(launchconditions_x *launchconditions);
-static void __ps_free_datashare(datashare_x *datashare);
-static void __ps_free_icon(icon_x *icon);
-static void __ps_free_author(author_x *author);
-static void __ps_free_description(description_x *description);
-static void __ps_free_capability(capability_x *capability);
-static void __ps_free_license(license_x *license);
-static void __ps_free_appcontrol(appcontrol_x *appcontrol);
-static void __ps_free_datacontrol(datacontrol_x *datacontrol);
-static void __ps_free_uiapplication(uiapplication_x *uiapplication);
-static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication);
-static void __ps_free_font(font_x *font);
-static void __ps_free_theme(theme_x *theme);
-static void __ps_free_daemon(daemon_x *daemon);
-static void __ps_free_ime(ime_x *ime);
-static char *__pkgid_to_manifest(const char *pkgid);
+static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid);
+static char *__pkgid_to_manifest(const char *pkgid, uid_t uid);
 static int __next_child_element(xmlTextReaderPtr reader, int depth);
-static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx);
-static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx);
+static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
+static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
 static void __str_trim(char *input);
 static char *__get_parser_plugin(const char *type);
 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
-static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid);
-static void __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], const char *pkgid);
-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);
+API int __is_admin();
+
+static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, const char **xml_attribute, char *default_value)
+{
+       xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
+       if (attrib_val) {
+               *xml_attribute = strdup((const char *)attrib_val);
+               xmlFree(attrib_val);
+       } else {
+               if (default_value != NULL) {
+                       *xml_attribute = strdup(default_value);
+               }
+       }
+}
+
+static void __save_xml_lang(xmlTextReaderPtr reader, const char **xml_attribute)
+{
+       const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
+       if (attrib_val != NULL)
+               *xml_attribute = strdup(ASCII(attrib_val));
+       else
+               *xml_attribute = strdup(DEFAULT_LOCALE);
+}
+
+static void __save_xml_value(xmlTextReaderPtr reader, const char **xml_attribute)
+{
+       xmlTextReaderRead(reader);
+       const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
+
+       if (attrib_val)
+               *xml_attribute = strdup((const char *)attrib_val);
+}
+
+static void __save_xml_installed_time(manifest_x *mfx)
+{
+       char buf[PKG_STRING_LEN_MAX] = {'\0'};
+       char *val = NULL;
+       time_t current_time;
+       time(&current_time);
+       snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
+       val = strndup(buf, PKG_STRING_LEN_MAX - 1);
+       mfx->installed_time = val;
+}
+
+static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
+{
+       char root[PKG_STRING_LEN_MAX] = { '\0' };
+       const char *path;
+
+       if (mfx->root_path)
+               return;
+
+       tzplatform_set_user(uid);
+       path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
+       snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
+
+       mfx->root_path = strdup(root);
+
+       tzplatform_reset_user();
+}
+
+static void __save_xml_default_value(manifest_x * mfx)
+{
+       mfx->preload = strdup("False");
+       mfx->removable = strdup("True");
+       mfx->readonly = strdup("False");
+       mfx->update = strdup("False");
+       mfx->system = strdup("False");
+       mfx->installed_storage= strdup("installed_internal");
+       package = mfx->package;
+}
+
+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)
 {
@@ -152,73 +230,123 @@ static void __str_trim(char *input)
        return;
 }
 
-static int __validate_appid(const char *pkgid, const char *appid, char **newappid)
+API int __is_admin()
 {
-       if (!pkgid || !appid || !newappid) {
-               DBG("Arg supplied is NULL\n");
-               return -1;
-       }
-       int pkglen = strlen(pkgid);
-       int applen = strlen(appid);
-       char *ptr = NULL;
-       char *newapp = NULL;
-       int len = 0;
-       if (strncmp(appid, ".", 1) == 0) {
-               len = pkglen + applen + 1;
-               newapp = calloc(1,len);
-               if (newapp == NULL) {
-                       DBG("Malloc failed\n");
-                       return -1;
-               }
-               strncpy(newapp, pkgid, pkglen);
-               strncat(newapp, appid, applen);
-               DBG("new appid is %s\n", newapp);
-               *newappid = newapp;
+       uid_t uid = getuid();
+       if ((uid_t) 0 == uid )
+               return 1;
+       else
                return 0;
+}
+
+
+
+static char * __get_tag_by_key(char *md_key)
+{
+       char *md_tag = NULL;
+
+       if (md_key == NULL) {
+               _LOGD("md_key is NULL\n");
+               return NULL;
        }
-       if (applen < pkglen) {
-               DBG("app id is not proper\n");
-               *newappid = NULL;
-#ifdef _VALIDATE_APPID_
-               return -1;
-#else
-               return 0;
-#endif
+
+       md_tag = strrchr(md_key, 47) + 1;
+
+
+       return strdup(md_tag);
+}
+
+static char *__get_metadata_parser_plugin(const char *type)
+{
+       FILE *fp = NULL;
+       char buffer[1024] = { 0 };
+       char temp_path[1024] = { 0 };
+       char *path = NULL;
+
+       if (type == NULL) {
+               _LOGE("invalid argument\n");
+               return NULL;
        }
-       if (!strcmp(appid, pkgid)) {
-               DBG("appid is proper\n");
-               *newappid = NULL;
-               return 0;
+
+       fp = fopen(PKG_PARSER_CONF_PATH, "r");
+       if (fp == NULL) {
+               _LOGE("no matching metadata parser\n");
+               return NULL;
        }
-       else if (strncmp(appid, pkgid, pkglen) == 0) {
-               ptr = strstr(appid, pkgid);
-               ptr = ptr + pkglen;
-               if (strncmp(ptr, ".", 1) == 0) {
-                       DBG("appid is proper\n");
-                       *newappid = NULL;
-                       return 0;
-               }
-               else {
-                       DBG("appid is not proper\n");
-                       *newappid = NULL;
-#ifdef _VALIDATE_APPID_
-                       return -1;
-#else
-                       return 0;
-#endif
+
+       while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+               if (buffer[0] == '#')
+                       continue;
+
+               __str_trim(buffer);
+
+               if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
+                       path = path + strlen(METADATA_PARSER_NAME);
+
+                       break;
                }
-       } else {
-               DBG("appid is not proper\n");
-               *newappid = NULL;
-#ifdef _VALIDATE_APPID_
-               return -1;
-#else
-               return 0;
-#endif
+
+               memset(buffer, 0x00, 1024);
        }
-       return 0;
+
+       if (fp != NULL)
+               fclose(fp);
+
+       if (path == NULL) {
+               _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
+               return NULL;
+       }
+
+       snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
+
+       return strdup(temp_path);
 }
 
+static char *__get_category_parser_plugin(const char *type)
+{
+       FILE *fp = NULL;
+       char buffer[1024] = { 0 };
+       char temp_path[1024] = { 0 };
+       char *path = NULL;
+
+       if (type == NULL) {
+               _LOGE("invalid argument\n");
+               return NULL;
+       }
+
+       fp = fopen(PKG_PARSER_CONF_PATH, "r");
+       if (fp == NULL) {
+               _LOGE("no matching metadata parser\n");
+               return NULL;
+       }
+
+       while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+               if (buffer[0] == '#')
+                       continue;
+
+               __str_trim(buffer);
+
+               if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
+                       path = path + strlen(CATEGORY_PARSER_NAME);
+
+                       break;
+               }
+
+               memset(buffer, 0x00, 1024);
+       }
+
+       if (fp != NULL)
+               fclose(fp);
+
+       if (path == NULL) {
+               _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
+               return NULL;
+       }
+
+       snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
+
+       return strdup(temp_path);
+}
 
 static char *__get_parser_plugin(const char *type)
 {
@@ -228,13 +356,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;
        }
 
@@ -245,10 +373,7 @@ static char *__get_parser_plugin(const char *type)
                __str_trim(buffer);
 
                if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
-                       DBG("[%s]\n", path);
                        path = path + strlen(PKG_PARSERLIB);
-                       DBG("[%s]\n", path);
-
                        break;
                }
 
@@ -259,7 +384,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;
        }
 
@@ -268,11 +393,9 @@ static char *__get_parser_plugin(const char *type)
        return strdup(temp_path);
 }
 
-static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
+static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
                           ACTION_TYPE action, const char *pkgid)
 {
-       char *lib_path = NULL;
-       void *lib_handle = NULL;
        int (*plugin_install) (xmlDocPtr, const char *);
        int ret = -1;
        char *ac = NULL;
@@ -291,22 +414,64 @@ static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
                goto END;
        }
 
-       lib_path = __get_parser_plugin(tag);
+       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 (*metadata_parser_plugin) (const char *, const char *, GList *);
+       int ret = -1;
+       char *ac = NULL;
+
+       switch (action) {
+       case ACTION_INSTALL:
+               ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
+               break;
+       case ACTION_UPGRADE:
+               ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
+               break;
+       case ACTION_UNINSTALL:
+               ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
+               break;
+       default:
+               goto END;
+       }
+
+       lib_path = __get_metadata_parser_plugin(tag);
        if (!lib_path) {
+               _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 ((plugin_install =
+
+       if ((metadata_parser_plugin =
                dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol \n");
+               _LOGE("can not find symbol[%s] \n",ac);
                goto END;
        }
 
-       ret = plugin_install(docPtr, pkgid);
+       ret = metadata_parser_plugin(pkgid, appid, md_list);
+       if (ret < 0)
+               _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
+       else
+               _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
 
 END:
        if (lib_path)
@@ -316,81 +481,219 @@ END:
        return ret;
 }
 
-static char *__pkgid_to_manifest(const char *pkgid)
+static int __ps_run_category_parser(GList *category_list, const char *tag,
+                               ACTION_TYPE action, const char *pkgid, const char *appid)
 {
-       char *manifest;
-       int size;
+       char *lib_path = NULL;
+       void *lib_handle = NULL;
+       int (*category_parser_plugin) (const char *, const char *, GList *);
+       int ret = -1;
+       char *ac = NULL;
 
-       if (pkgid == NULL) {
-               DBGE("pkgid is NULL");
-               return NULL;
+       switch (action) {
+       case ACTION_INSTALL:
+               ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
+               break;
+       case ACTION_UPGRADE:
+               ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
+               break;
+       case ACTION_UNINSTALL:
+               ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
+               break;
+       default:
+               goto END;
        }
 
-       size = strlen(MANIFEST_RW_DIRECTORY) + strlen(pkgid) + 10;
-       manifest = malloc(size);
-       if (manifest == NULL) {
-               DBGE("No memory");
-               return NULL;
+       lib_path = __get_category_parser_plugin(tag);
+       if (!lib_path) {
+               _LOGE("get %s parser fail\n", tag);
+               goto END;
        }
-       memset(manifest, '\0', size);
-       snprintf(manifest, size, MANIFEST_RW_DIRECTORY "/%s.xml", pkgid);
 
-       if (access(manifest, F_OK)) {
-               snprintf(manifest, size, MANIFEST_RO_DIRECTORY "/%s.xml", pkgid);
+       if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
+               _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
+               goto END;
        }
 
-       return manifest;
+       if ((category_parser_plugin =
+               dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
+               _LOGE("can not find symbol[%s] \n",ac);
+               goto END;
+       }
+
+       ret = category_parser_plugin(pkgid, appid, category_list);
+       if (ret < 0)
+               _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
+       else
+               _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
+
+END:
+       if (lib_path)
+               free(lib_path);
+       if (lib_handle)
+               dlclose(lib_handle);
+       return ret;
 }
 
-static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
+static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
+                          ACTION_TYPE action, const char *pkgid)
 {
+       char *lib_path = NULL;
+       void *lib_handle = NULL;
+       int (*plugin_install) (xmlDocPtr, const char *);
        int ret = -1;
-       const xmlChar *name;
-
-       DBG("__run_parser_prestep");
+       char *ac = NULL;
 
-       if (xmlTextReaderDepth(reader) != 1) {
-               DBGE("Node depth is not 1");
+       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;
+       }
+
+       lib_path = __get_parser_plugin(tag);
+       if (!lib_path) {
+               goto END;
+       }
+
+       if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
+               _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
+               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);
+       if (ret < 0)
+               _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
+       else
+               _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
+
+END:
+       if (lib_path)
+               free(lib_path);
+       if (lib_handle)
+               dlclose(lib_handle);
+       return ret;
+}
+
+static char *__pkgid_to_manifest(const char *pkgid, uid_t uid)
+{
+       char *manifest;
+       int size;
+
+       if (pkgid == NULL) {
+               _LOGE("pkgid is NULL");
+               return NULL;
+       }
+
+       size = strlen(getUserManifestPath(uid)) + strlen(pkgid) + 10;
+       manifest = malloc(size);
+       if (manifest == NULL) {
+               _LOGE("No memory");
+               return NULL;
+       }
+       memset(manifest, '\0', size);
+       snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
+
+       if (access(manifest, F_OK)) {
+               snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
+       }
+
+       return manifest;
+}
+
+static void __metadata_parser_clear_dir_list(GList* dir_list)
+{
+       GList *list = NULL;
+       __metadata_t* detail = NULL;
+
+       if (dir_list) {
+               list = g_list_first(dir_list);
+               while (list) {
+                       detail = (__metadata_t *)list->data;
+                       if (detail) {
+                               if (detail->key)
+                                       free((void *)detail->key);
+                               if (detail->value)
+                                       free((void *)detail->value);
+                               free(detail);
+                       }
+                       list = g_list_next(list);
+               }
+               g_list_free(dir_list);
+       }
+}
+
+static void __category_parser_clear_dir_list(GList* dir_list)
+{
+       GList *list = NULL;
+       __category_t* detail = NULL;
+
+       if (dir_list) {
+               list = g_list_first(dir_list);
+               while (list) {
+                       detail = (__category_t *)list->data;
+                       if (detail) {
+                               if (detail->name)
+                                       free((void *)detail->name);
+
+                               free(detail);
+                       }
+                       list = g_list_next(list);
+               }
+               g_list_free(dir_list);
+       }
+}
+
+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) {
-               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",
-           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);
        xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
        if (copyDocPtr == NULL)
                return -1;
@@ -428,129 +731,239 @@ static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, con
                xmlSetTreeDoc(cur_node, copyDocPtr);
        }
 
-#ifdef __DEBUG__
-
-//#else
-       DBG("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",
-           cur_node->last ? cur_node->last->name : "NULL",
-           cur_node->parent ? cur_node->parent->name : "NULL",
-           cur_node->next ? cur_node->next->name : "NULL",
-           cur_node->prev ? cur_node->prev->name : "NULL");
-
-       FILE *fp = fopen("/opt/share/test.xml", "a");
-       xmlDocDump(fp, copyDocPtr);
-       fprintf(fp, "\n");
-       fclose(fp);
-#endif
-
-       ret = __ps_run_parser(copyDocPtr, ASCII(name), action, pkgid);
+       ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
  END:
 
        return ret;
 }
 
-static void
-__processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], const char *pkgid)
+static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
 {
-       char *tag = NULL;
-       int i = 0;
+       int ret = -1;
+       int tag_exist = 0;
+       char buffer[1024] = { 0, };
+       GList *app_tmp;
+       application_x *app;
+       GList *md_tmp = NULL;
+       metadata_x *md;
+       char *md_tag = NULL;
+
+       GList *md_list = NULL;
+       __metadata_t *md_detail = NULL;
+
+       md_tag = __get_tag_by_key(md_key);
+       if (md_tag == NULL) {
+               _LOGD("md_tag is NULL\n");
+               return -1;
+       }
+
+       for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
+               app = (application_x *)app_tmp->data;
+               if (app == NULL)
+                       continue;
+               for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
+                       md = (metadata_x *)md_tmp->data;
+                       if (md == NULL)
+                               continue;
+                       //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) {
+                                       _LOGD("Memory allocation failed\n");
+                                       goto END;
+                               }
+
+                               md_detail->key = strdup(md->key);
+                               if (md_detail->key == NULL) {
+                                       _LOGD("Memory allocation failed\n");
+                                       free(md_detail);
+                                       goto END;
+                               }
+
+                               md_detail->value = strdup(md->value);
+                               if (md_detail->value == NULL) {
+                                       _LOGD("Memory allocation failed\n");
+                                       free((void *)md_detail->key);
+                                       free(md_detail);
+                                       goto END;
+                               }
+
+                               md_list = g_list_append(md_list, (gpointer)md_detail);
+                               tag_exist = 1;
+                       }
+               }
+
+               //send glist to parser when tags for metadata plugin parser exist.
+               if (tag_exist) {
+                       ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
+                       if (ret < 0){
+                               _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
+                       }
+                       else{
+                               _LOGD("metadata_parser success for tag[%s]\n", md_tag);
+                       }
+               }
+               __metadata_parser_clear_dir_list(md_list);
+               md_list = NULL;
+               tag_exist = 0;
+       }
+
+       return 0;
+END:
+       __metadata_parser_clear_dir_list(md_list);
+
+       if (md_tag)
+               free(md_tag);
+
+       return ret;
+}
+
+static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
+{
+       int ret = -1;
+       int tag_exist = 0;
+       char buffer[1024] = { 0, };
+       GList *app_tmp;
+       application_x *app;
+       GList *category_tmp;
+       const char *category;
+       char *category_tag = NULL;
+
+       GList *category_list = NULL;
+       __category_t *category_detail = NULL;
+
+       category_tag = __get_tag_by_key(category_key);
+       if (category_tag == NULL) {
+               _LOGD("md_tag is NULL\n");
+               return -1;
+       }
+
+       for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
+               app = (application_x *)app_tmp->data;
+               if (app == NULL)
+                       continue;
+               for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
+                       category = (const char *)category_tmp->data;
+                       //get glist of category key and value combination
+                       memset(buffer, 0x00, 1024);
+                       snprintf(buffer, 1024, "%s/", category_key);
+                       if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
+                               category_detail = (__category_t*) calloc(1, sizeof(__category_t));
+                               if (category_detail == NULL) {
+                                       _LOGD("Memory allocation failed\n");
+                                       goto END;
+                               }
+
+                               category_detail->name = strdup(category);
+                               if (category_detail->name == NULL) {
+                                       _LOGD("Memory allocation failed\n");
+                                       free(category_detail);
+                                       goto END;
+                               }
+
+                               category_list = g_list_append(category_list, (gpointer)category_detail);
+                               tag_exist = 1;
+                       }
+               }
+
+               //send glist to parser when tags for metadata plugin parser exist.
+               if (tag_exist) {
+                       ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
+                       if (ret < 0)
+                               _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
+                       else
+                               _LOGD("category_parser success for tag[%s]\n", category_tag);
+               }
+               __category_parser_clear_dir_list(category_list);
+               category_list = NULL;
+               tag_exist = 0;
+       }
+
+       return 0;
+END:
+       __category_parser_clear_dir_list(category_list);
+
+       if (category_tag)
+               free(category_tag);
+
+       return ret;
+}
 
+static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
+{
        switch (xmlTextReaderNodeType(reader)) {
        case XML_READER_TYPE_END_ELEMENT:
                {
-                       //            DBG("XML_READER_TYPE_END_ELEMENT");
                        break;
                }
-
        case XML_READER_TYPE_ELEMENT:
                {
                        // Elements without closing tag don't receive
-                       // XML_READER_TYPE_END_ELEMENT event.
-
                        const xmlChar *elementName =
                            xmlTextReaderLocalName(reader);
                        if (elementName == NULL) {
-//                             DBG("elementName %s\n", (char *)elementName);
                                break;
                        }
 
-                       const xmlChar *nameSpace =
-                           xmlTextReaderConstNamespaceUri(reader);
-                       if (nameSpace) {
-//                             DBG("nameSpace %s\n", (char *)nameSpace);
-                       }
-/*
-                       DBG("XML_READER_TYPE_ELEMENT %s, %s\n",
-                           elementName ? elementName : "NULL",
-                           nameSpace ? nameSpace : "NULL");
-*/
-                       if (tagv == NULL) {
-                               DBG("__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);
-                                               __run_parser_prestep(reader,
-                                                                    action, pkgid);
-                                               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;
                }
-       case XML_READER_TYPE_TEXT:
-       case XML_READER_TYPE_CDATA:
-               {
-                       const xmlChar *value = xmlTextReaderConstValue(reader);
-                       if (value) {
-//                             DBG("value %s\n", value);
-                       }
 
-                       const xmlChar *lang = xmlTextReaderConstXmlLang(reader);
-                       if (lang) {
-//                             DBG("lang\n", lang);
-                       }
-
-/*                     DBG("XML_READER_TYPE_TEXT %s, %s\n",
-                           value ? value : "NULL", lang ? lang : "NULL");
-*/
-                       break;
-               }
        default:
-//             DBG("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
                break;
        }
 }
 
-static void
-__streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid)
+static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
 {
-       xmlTextReaderPtr reader;
-       xmlDocPtr docPtr;
-       int ret;
+       int (*plugin_install) (const char *);
+       int ret = -1;
+       char *ac = NULL;
 
-       docPtr = xmlReadFile(filename, NULL, 0);
-       reader = xmlReaderWalker(docPtr);
-       if (reader != NULL) {
-               ret = xmlTextReaderRead(reader);
-               while (ret == 1) {
-                       __processNode(reader, action, tagv, pkgid);
-                       ret = xmlTextReaderRead(reader);
+       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;
                }
-               xmlFreeTextReader(reader);
-
-               if (ret != 0) {
-                       DBGE("%s : failed to parse", filename);
+       } 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 {
-               DBGE("Unable to open %s", filename);
+       } else
+               return -1;
+
+       if ((plugin_install =
+               dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
+               return -1;
        }
+
+       ret = plugin_install(pkgid);
+       return ret;
 }
 
 static int __next_child_element(xmlTextReaderPtr reader, int depth)
@@ -583,1127 +996,165 @@ static int __next_child_element(xmlTextReaderPtr reader, int depth)
        }
        return ret;
 }
-
-static void __ps_free_category(category_x *category)
+int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
 {
-       if (category == NULL)
-               return;
-       if (category->name) {
-               free((void *)category->name);
-               category->name = NULL;
+       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) {
+                               __process_tag(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));
        }
-       free((void*)category);
-       category = NULL;
+
+       if (fp != NULL)
+               fclose(fp);
+
+       return 0;
 }
 
-static void __ps_free_privilege(privilege_x *privilege)
+int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
 {
-       if (privilege == NULL)
-               return;
-       if (privilege->text) {
-               free((void *)privilege->text);
-               privilege->text = NULL;
+       fprintf(stdout,"__ps_process_metadata_parser\n");
+       int ret = 0;
+       FILE *fp = NULL;
+       char md_key[PKG_STRING_LEN_MAX] = { 0 };
+
+       fp = fopen(METADATA_PARSER_LIST, "r");
+       if (fp == NULL) {
+               _LOGD("no preload list\n");
+               return -1;
        }
-       free((void*)privilege);
-       privilege = NULL;
-}
 
-static void __ps_free_privileges(privileges_x *privileges)
-{
-       if (privileges == NULL)
-               return;
-       /*Free Privilege*/
-       if (privileges->privilege) {
-               privilege_x *privilege = privileges->privilege;
-               privilege_x *tmp = NULL;
-               while(privilege != NULL) {
-                       tmp = privilege->next;
-                       __ps_free_privilege(privilege);
-                       privilege = tmp;
-               }
+       while (fgets(md_key, sizeof(md_key), fp) != NULL) {
+               __str_trim(md_key);
+               ret = __run_metadata_parser_prestep(mfx, md_key, action);
+               if (ret < 0)
+                       break;
        }
-       free((void*)privileges);
-       privileges = NULL;
+
+       if (fp != NULL)
+               fclose(fp);
+
+       return ret;
 }
 
-static void __ps_free_metadata(metadata_x *metadata)
+int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
 {
-       if (metadata == NULL)
-               return;
-       if (metadata->key) {
-               free((void *)metadata->key);
-               metadata->key = NULL;
+       int ret = 0;
+       FILE *fp = NULL;
+       char category_key[PKG_STRING_LEN_MAX] = { 0 };
+
+       fp = fopen(CATEGORY_PARSER_LIST, "r");
+       if (fp == NULL) {
+               _LOGD("no category parser list\n");
+               return -1;
        }
-       if (metadata->value) {
-               free((void *)metadata->value);
-               metadata->value = NULL;
+
+       while (fgets(category_key, sizeof(category_key), fp) != NULL) {
+               __str_trim(category_key);
+               ret = __run_category_parser_prestep(mfx, category_key, action);
+               if (ret < 0)
+                       break;
        }
-       free((void*)metadata);
-       metadata = NULL;
+
+       if (fp != NULL)
+               fclose(fp);
+
+       return ret;
 }
 
-static void __ps_free_permission(permission_x *permission)
+static int __ps_process_allowed(xmlTextReaderPtr reader, const char **allowed)
 {
-       if (permission == NULL)
-               return;
-       if (permission->type) {
-               free((void *)permission->type);
-               permission->type = NULL;
-       }
-       if (permission->value) {
-               free((void *)permission->value);
-               permission->value = NULL;
-       }
-       free((void*)permission);
-       permission = NULL;
+       __save_xml_value(reader, allowed);
+       return 0;
 }
 
-static void __ps_free_icon(icon_x *icon)
+static int __ps_process_condition(xmlTextReaderPtr reader, const char **condition)
 {
-       if (icon == NULL)
-               return;
-       if (icon->text) {
-               free((void *)icon->text);
-               icon->text = NULL;
-       }
-       if (icon->lang) {
-               free((void *)icon->lang);
-               icon->lang = NULL;
-       }
-       if (icon->name) {
-               free((void *)icon->name);
-               icon->name= NULL;
-       }
-       if (icon->section) {
-               free((void *)icon->section);
-               icon->section = NULL;
-       }
-       if (icon->size) {
-               free((void *)icon->size);
-               icon->size = NULL;
-       }
-       if (icon->resolution) {
-               free((void *)icon->resolution);
-               icon->resolution = NULL;
-       }
-       free((void*)icon);
-       icon = NULL;
+       __save_xml_attribute(reader, "name", condition, NULL);
+       return 0;
 }
 
-static void __ps_free_image(image_x *image)
+static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
 {
-       if (image == NULL)
-               return;
-       if (image->text) {
-               free((void *)image->text);
-               image->text = NULL;
-       }
-       if (image->lang) {
-               free((void *)image->lang);
-               image->lang = NULL;
-       }
-       if (image->name) {
-               free((void *)image->name);
-               image->name= NULL;
-       }
-       if (image->section) {
-               free((void *)image->section);
-               image->section = NULL;
-       }
-       free((void*)image);
-       image = NULL;
+       __save_xml_attribute(reader, "name", &notification->name, NULL);
+       __save_xml_value(reader, &notification->text);
+       return 0;
 }
 
-static void __ps_free_operation(operation_x *operation)
+static int __ps_process_category(xmlTextReaderPtr reader, const char **category)
 {
-       if (operation == NULL)
-               return;
-       if (operation->text) {
-               free((void *)operation->text);
-               operation->text = NULL;
-       }
-       free((void*)operation);
-       operation = NULL;
+       __save_xml_attribute(reader, "name", category, NULL);
+       return 0;
 }
 
-static void __ps_free_uri(uri_x *uri)
+static int __ps_process_privilege(xmlTextReaderPtr reader, const char **privilege)
 {
-       if (uri == NULL)
-               return;
-       if (uri->text) {
-               free((void *)uri->text);
-               uri->text = NULL;
-       }
-       free((void*)uri);
-       uri = NULL;
+       __save_xml_value(reader, privilege);
+       return 0;
 }
 
-static void __ps_free_mime(mime_x *mime)
+static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
 {
-       if (mime == NULL)
-               return;
-       if (mime->text) {
-               free((void *)mime->text);
-               mime->text = NULL;
-       }
-       free((void*)mime);
-       mime = NULL;
+       __save_xml_attribute(reader, "key", &metadata->key, NULL);
+       __save_xml_attribute(reader, "value", &metadata->value, NULL);
+       return 0;
 }
 
-static void __ps_free_subapp(subapp_x *subapp)
+static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
 {
-       if (subapp == NULL)
-               return;
-       if (subapp->text) {
-               free((void *)subapp->text);
-               subapp->text = NULL;
-       }
-       free((void*)subapp);
-       subapp = NULL;
+       __save_xml_attribute(reader, "type", &permission->type, NULL);
+       __save_xml_value(reader, &permission->value);
+       return 0;
 }
 
-static void __ps_free_condition(condition_x *condition)
+static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
 {
-       if (condition == NULL)
-               return;
-       if (condition->text) {
-               free((void *)condition->text);
-               condition->text = NULL;
-       }
-       if (condition->name) {
-               free((void *)condition->name);
-               condition->name = NULL;
-       }
-       free((void*)condition);
-       condition = NULL;
+       __save_xml_attribute(reader, "name", &compatibility->name, NULL);
+       __save_xml_value(reader, &compatibility->text);
+       return 0;
 }
 
-static void __ps_free_notification(notification_x *notification)
+static int __ps_process_request(xmlTextReaderPtr reader, const char **request)
 {
-       if (notification == NULL)
-               return;
-       if (notification->text) {
-               free((void *)notification->text);
-               notification->text = NULL;
-       }
-       if (notification->name) {
-               free((void *)notification->name);
-               notification->name = NULL;
-       }
-       free((void*)notification);
-       notification = NULL;
-}
-
-static void __ps_free_compatibility(compatibility_x *compatibility)
-{
-       if (compatibility == NULL)
-               return;
-       if (compatibility->text) {
-               free((void *)compatibility->text);
-               compatibility->text = NULL;
-       }
-       if (compatibility->name) {
-               free((void *)compatibility->name);
-               compatibility->name = NULL;
-       }
-       free((void*)compatibility);
-       compatibility = NULL;
-}
-
-static void __ps_free_resolution(resolution_x *resolution)
-{
-       if (resolution == NULL)
-               return;
-       if (resolution->mimetype) {
-               free((void *)resolution->mimetype);
-               resolution->mimetype = NULL;
-       }
-       if (resolution->urischeme) {
-               free((void *)resolution->urischeme);
-               resolution->urischeme = NULL;
-       }
-       free((void*)resolution);
-       resolution = NULL;
-}
-
-static void __ps_free_capability(capability_x *capability)
-{
-       if (capability == NULL)
-               return;
-       if (capability->operationid) {
-               free((void *)capability->operationid);
-               capability->operationid = NULL;
-       }
-       /*Free Resolution*/
-       if (capability->resolution) {
-               resolution_x *resolution = capability->resolution;
-               resolution_x *tmp = NULL;
-               while(resolution != NULL) {
-                       tmp = resolution->next;
-                       __ps_free_resolution(resolution);
-                       resolution = tmp;
-               }
-       }
-       free((void*)capability);
-       capability = NULL;
-}
-
-static void __ps_free_allowed(allowed_x *allowed)
-{
-       if (allowed == NULL)
-               return;
-       if (allowed->name) {
-               free((void *)allowed->name);
-               allowed->name = NULL;
-       }
-       if (allowed->text) {
-               free((void *)allowed->text);
-               allowed->text = NULL;
-       }
-       free((void*)allowed);
-       allowed = NULL;
-}
-
-static void __ps_free_request(request_x *request)
-{
-       if (request == NULL)
-               return;
-       if (request->text) {
-               free((void *)request->text);
-               request->text = NULL;
-       }
-       free((void*)request);
-       request = NULL;
-}
-
-static void __ps_free_datacontrol(datacontrol_x *datacontrol)
-{
-       if (datacontrol == NULL)
-               return;
-       if (datacontrol->providerid) {
-               free((void *)datacontrol->providerid);
-               datacontrol->providerid = NULL;
-       }
-       /*Free Capability*/
-       if (datacontrol->capability) {
-               capability_x *capability = datacontrol->capability;
-               capability_x *tmp = NULL;
-               while(capability != NULL) {
-                       tmp = capability->next;
-                       __ps_free_capability(capability);
-                       capability = tmp;
-               }
-       }
-       free((void*)datacontrol);
-       datacontrol = NULL;
-}
-
-static void __ps_free_launchconditions(launchconditions_x *launchconditions)
-{
-       if (launchconditions == NULL)
-               return;
-       if (launchconditions->text) {
-               free((void *)launchconditions->text);
-               launchconditions->text = NULL;
-       }
-       /*Free Condition*/
-       if (launchconditions->condition) {
-               condition_x *condition = launchconditions->condition;
-               condition_x *tmp = NULL;
-               while(condition != NULL) {
-                       tmp = condition->next;
-                       __ps_free_condition(condition);
-                       condition = tmp;
-               }
-       }
-       free((void*)launchconditions);
-       launchconditions = NULL;
-}
-
-static void __ps_free_appcontrol(appcontrol_x *appcontrol)
-{
-       if (appcontrol == NULL)
-               return;
-       if (appcontrol->text) {
-               free((void *)appcontrol->text);
-               appcontrol->text = NULL;
-       }
-       /*Free Operation*/
-       if (appcontrol->operation) {
-               operation_x *operation = appcontrol->operation;
-               operation_x *tmp = NULL;
-               while(operation != NULL) {
-                       tmp = operation->next;
-                       __ps_free_operation(operation);
-                       operation = tmp;
-               }
-       }
-       /*Free Uri*/
-       if (appcontrol->uri) {
-               uri_x *uri = appcontrol->uri;
-               uri_x *tmp = NULL;
-               while(uri != NULL) {
-                       tmp = uri->next;
-                       __ps_free_uri(uri);
-                       uri = tmp;
-               }
-       }
-       /*Free Mime*/
-       if (appcontrol->mime) {
-               mime_x *mime = appcontrol->mime;
-               mime_x *tmp = NULL;
-               while(mime != NULL) {
-                       tmp = mime->next;
-                       __ps_free_mime(mime);
-                       mime = tmp;
-               }
-       }
-       /*Free subapp*/
-       if (appcontrol->subapp) {
-               subapp_x *subapp = appcontrol->subapp;
-               subapp_x *tmp = NULL;
-               while(subapp != NULL) {
-                       tmp = subapp->next;
-                       __ps_free_subapp(subapp);
-                       subapp = tmp;
-               }
-       }
-       free((void*)appcontrol);
-       appcontrol = NULL;
-}
-
-static void __ps_free_appsvc(appsvc_x *appsvc)
-{
-       if (appsvc == NULL)
-               return;
-       if (appsvc->text) {
-               free((void *)appsvc->text);
-               appsvc->text = NULL;
-       }
-       /*Free Operation*/
-       if (appsvc->operation) {
-               operation_x *operation = appsvc->operation;
-               operation_x *tmp = NULL;
-               while(operation != NULL) {
-                       tmp = operation->next;
-                       __ps_free_operation(operation);
-                       operation = tmp;
-               }
-       }
-       /*Free Uri*/
-       if (appsvc->uri) {
-               uri_x *uri = appsvc->uri;
-               uri_x *tmp = NULL;
-               while(uri != NULL) {
-                       tmp = uri->next;
-                       __ps_free_uri(uri);
-                       uri = tmp;
-               }
-       }
-       /*Free Mime*/
-       if (appsvc->mime) {
-               mime_x *mime = appsvc->mime;
-               mime_x *tmp = NULL;
-               while(mime != NULL) {
-                       tmp = mime->next;
-                       __ps_free_mime(mime);
-                       mime = tmp;
-               }
-       }
-       /*Free subapp*/
-       if (appsvc->subapp) {
-               subapp_x *subapp = appsvc->subapp;
-               subapp_x *tmp = NULL;
-               while(subapp != NULL) {
-                       tmp = subapp->next;
-                       __ps_free_subapp(subapp);
-                       subapp = tmp;
-               }
-       }
-       free((void*)appsvc);
-       appsvc = NULL;
-}
-
-static void __ps_free_deviceprofile(deviceprofile_x *deviceprofile)
-{
-       return;
-}
-
-static void __ps_free_define(define_x *define)
-{
-       if (define == NULL)
-               return;
-       if (define->path) {
-               free((void *)define->path);
-               define->path = NULL;
-       }
-       /*Free Request*/
-       if (define->request) {
-               request_x *request = define->request;
-               request_x *tmp = NULL;
-               while(request != NULL) {
-                       tmp = request->next;
-                       __ps_free_request(request);
-                       request = tmp;
-               }
-       }
-       /*Free Allowed*/
-       if (define->allowed) {
-               allowed_x *allowed = define->allowed;
-               allowed_x *tmp = NULL;
-               while(allowed != NULL) {
-                       tmp = allowed->next;
-                       __ps_free_allowed(allowed);
-                       allowed = tmp;
-               }
-       }
-       free((void*)define);
-       define = NULL;
-}
-
-static void __ps_free_datashare(datashare_x *datashare)
-{
-       if (datashare == NULL)
-               return;
-       /*Free Define*/
-       if (datashare->define) {
-               define_x *define =  datashare->define;
-               define_x *tmp = NULL;
-               while(define != NULL) {
-                       tmp = define->next;
-                       __ps_free_define(define);
-                       define = tmp;
-               }
-       }
-       /*Free Request*/
-       if (datashare->request) {
-               request_x *request = datashare->request;
-               request_x *tmp = NULL;
-               while(request != NULL) {
-                       tmp = request->next;
-                       __ps_free_request(request);
-                       request = tmp;
-               }
-       }
-       free((void*)datashare);
-       datashare = NULL;
-}
-
-static void __ps_free_label(label_x *label)
-{
-       if (label == NULL)
-               return;
-       if (label->name) {
-               free((void *)label->name);
-               label->name = NULL;
-       }
-       if (label->text) {
-               free((void *)label->text);
-               label->text = NULL;
-       }
-       if (label->lang) {
-               free((void *)label->lang);
-               label->lang= NULL;
-       }
-       free((void*)label);
-       label = NULL;
-}
-
-static void __ps_free_author(author_x *author)
-{
-       if (author == NULL)
-               return;
-       if (author->email) {
-               free((void *)author->email);
-               author->email = NULL;
-       }
-       if (author->text) {
-               free((void *)author->text);
-               author->text = NULL;
-       }
-       if (author->href) {
-               free((void *)author->href);
-               author->href = NULL;
-       }
-       if (author->lang) {
-               free((void *)author->lang);
-               author->lang = NULL;
-       }
-       free((void*)author);
-       author = NULL;
-}
-
-static void __ps_free_description(description_x *description)
-{
-       if (description == NULL)
-               return;
-       if (description->name) {
-               free((void *)description->name);
-               description->name = NULL;
-       }
-       if (description->text) {
-               free((void *)description->text);
-               description->text = NULL;
-       }
-       if (description->lang) {
-               free((void *)description->lang);
-               description->lang = NULL;
-       }
-       free((void*)description);
-       description = NULL;
-}
-
-static void __ps_free_license(license_x *license)
-{
-       if (license == NULL)
-               return;
-       if (license->text) {
-               free((void *)license->text);
-               license->text = NULL;
-       }
-       if (license->lang) {
-               free((void *)license->lang);
-               license->lang = NULL;
-       }
-       free((void*)license);
-       license = NULL;
-}
-
-static void __ps_free_uiapplication(uiapplication_x *uiapplication)
-{
-       if (uiapplication == NULL)
-               return;
-       if (uiapplication->exec) {
-               free((void *)uiapplication->exec);
-               uiapplication->exec = NULL;
-       }
-       if (uiapplication->appid) {
-               free((void *)uiapplication->appid);
-               uiapplication->appid = NULL;
-       }
-       if (uiapplication->nodisplay) {
-               free((void *)uiapplication->nodisplay);
-               uiapplication->nodisplay = NULL;
-       }
-       if (uiapplication->multiple) {
-               free((void *)uiapplication->multiple);
-               uiapplication->multiple = NULL;
-       }
-       if (uiapplication->type) {
-               free((void *)uiapplication->type);
-               uiapplication->type = NULL;
-       }
-       if (uiapplication->categories) {
-               free((void *)uiapplication->categories);
-               uiapplication->categories = NULL;
-       }
-       if (uiapplication->extraid) {
-               free((void *)uiapplication->extraid);
-               uiapplication->extraid = NULL;
-       }
-       if (uiapplication->taskmanage) {
-               free((void *)uiapplication->taskmanage);
-               uiapplication->taskmanage = NULL;
-       }
-       if (uiapplication->enabled) {
-               free((void *)uiapplication->enabled);
-               uiapplication->enabled = NULL;
-       }
-       if (uiapplication->hwacceleration) {
-               free((void *)uiapplication->hwacceleration);
-               uiapplication->hwacceleration = NULL;
-       }
-       if (uiapplication->mainapp) {
-               free((void *)uiapplication->mainapp);
-               uiapplication->mainapp = NULL;
-       }
-       if (uiapplication->recentimage) {
-               free((void *)uiapplication->recentimage);
-               uiapplication->recentimage = NULL;
-       }
-       if (uiapplication->package) {
-               free((void *)uiapplication->package);
-               uiapplication->package = NULL;
-       }
-       /*Free Label*/
-       if (uiapplication->label) {
-               label_x *label = uiapplication->label;
-               label_x *tmp = NULL;
-               while(label != NULL) {
-                       tmp = label->next;
-                       __ps_free_label(label);
-                       label = tmp;
-               }
-       }
-       /*Free Icon*/
-       if (uiapplication->icon) {
-               icon_x *icon = uiapplication->icon;
-               icon_x *tmp = NULL;
-               while(icon != NULL) {
-                       tmp = icon->next;
-                       __ps_free_icon(icon);
-                       icon = tmp;
-               }
-       }
-       /*Free image*/
-       if (uiapplication->image) {
-               image_x *image = uiapplication->image;
-               image_x *tmp = NULL;
-               while(image != NULL) {
-                       tmp = image->next;
-                       __ps_free_image(image);
-                       image = tmp;
-               }
-       }
-       /*Free AppControl*/
-       if (uiapplication->appcontrol) {
-               appcontrol_x *appcontrol = uiapplication->appcontrol;
-               appcontrol_x *tmp = NULL;
-               while(appcontrol != NULL) {
-                       tmp = appcontrol->next;
-                       __ps_free_appcontrol(appcontrol);
-                       appcontrol = tmp;
-               }
-       }
-       /*Free LaunchConditions*/
-       if (uiapplication->launchconditions) {
-               launchconditions_x *launchconditions = uiapplication->launchconditions;
-               launchconditions_x *tmp = NULL;
-               while(launchconditions != NULL) {
-                       tmp = launchconditions->next;
-                       __ps_free_launchconditions(launchconditions);
-                       launchconditions = tmp;
-               }
-       }
-       /*Free Notification*/
-       if (uiapplication->notification) {
-               notification_x *notification = uiapplication->notification;
-               notification_x *tmp = NULL;
-               while(notification != NULL) {
-                       tmp = notification->next;
-                       __ps_free_notification(notification);
-                       notification = tmp;
-               }
-       }
-       /*Free DataShare*/
-       if (uiapplication->datashare) {
-               datashare_x *datashare = uiapplication->datashare;
-               datashare_x *tmp = NULL;
-               while(datashare != NULL) {
-                       tmp = datashare->next;
-                       __ps_free_datashare(datashare);
-                       datashare = tmp;
-               }
-       }
-       /*Free AppSvc*/
-       if (uiapplication->appsvc) {
-               appsvc_x *appsvc = uiapplication->appsvc;
-               appsvc_x *tmp = NULL;
-               while(appsvc != NULL) {
-                       tmp = appsvc->next;
-                       __ps_free_appsvc(appsvc);
-                       appsvc = tmp;
-               }
-       }
-       /*Free Category*/
-       if (uiapplication->category) {
-               category_x *category = uiapplication->category;
-               category_x *tmp = NULL;
-               while(category != NULL) {
-                       tmp = category->next;
-                       __ps_free_category(category);
-                       category = tmp;
-               }
-       }
-       /*Free Metadata*/
-       if (uiapplication->metadata) {
-               metadata_x *metadata = uiapplication->metadata;
-               metadata_x *tmp = NULL;
-               while(metadata != NULL) {
-                       tmp = metadata->next;
-                       __ps_free_metadata(metadata);
-                       metadata = tmp;
-               }
-       }
-       /*Free permission*/
-       if (uiapplication->permission) {
-               permission_x *permission = uiapplication->permission;
-               permission_x *tmp = NULL;
-               while(permission != NULL) {
-                       tmp = permission->next;
-                       __ps_free_permission(permission);
-                       permission = tmp;
-               }
-       }
-       /* _PRODUCT_LAUNCHING_ENHANCED_ START */
-       if (uiapplication->indicatordisplay) {
-               free((void *)uiapplication->indicatordisplay);
-               uiapplication->indicatordisplay = NULL;
-       }
-       if (uiapplication->portraitimg) {
-               free((void *)uiapplication->portraitimg);
-               uiapplication->portraitimg = NULL;
-       }
-       if (uiapplication->landscapeimg) {
-               free((void *)uiapplication->landscapeimg);
-               uiapplication->landscapeimg = NULL;
-       }
-       /* _PRODUCT_LAUNCHING_ENHANCED_ END */
-       if (uiapplication->guestmode_visibility) {
-               free((void *)uiapplication->guestmode_visibility);
-               uiapplication->guestmode_visibility = NULL;
-       }
-       free((void*)uiapplication);
-       uiapplication = NULL;
-}
-
-static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication)
-{
-       if (serviceapplication == NULL)
-               return;
-       if (serviceapplication->exec) {
-               free((void *)serviceapplication->exec);
-               serviceapplication->exec = NULL;
-       }
-       if (serviceapplication->appid) {
-               free((void *)serviceapplication->appid);
-               serviceapplication->appid = NULL;
-       }
-       if (serviceapplication->onboot) {
-               free((void *)serviceapplication->onboot);
-               serviceapplication->onboot = NULL;
-       }
-       if (serviceapplication->autorestart) {
-               free((void *)serviceapplication->autorestart);
-               serviceapplication->autorestart = NULL;
-       }
-       if (serviceapplication->type) {
-               free((void *)serviceapplication->type);
-               serviceapplication->type = NULL;
-       }
-       if (serviceapplication->enabled) {
-               free((void *)serviceapplication->enabled);
-               serviceapplication->enabled = NULL;
-       }
-       if (serviceapplication->package) {
-               free((void *)serviceapplication->package);
-               serviceapplication->package = NULL;
-       }
-       /*Free Label*/
-       if (serviceapplication->label) {
-               label_x *label = serviceapplication->label;
-               label_x *tmp = NULL;
-               while(label != NULL) {
-                       tmp = label->next;
-                       __ps_free_label(label);
-                       label = tmp;
-               }
-       }
-       /*Free Icon*/
-       if (serviceapplication->icon) {
-               icon_x *icon = serviceapplication->icon;
-               icon_x *tmp = NULL;
-               while(icon != NULL) {
-                       tmp = icon->next;
-                       __ps_free_icon(icon);
-                       icon = tmp;
-               }
-       }
-       /*Free AppControl*/
-       if (serviceapplication->appcontrol) {
-               appcontrol_x *appcontrol = serviceapplication->appcontrol;
-               appcontrol_x *tmp = NULL;
-               while(appcontrol != NULL) {
-                       tmp = appcontrol->next;
-                       __ps_free_appcontrol(appcontrol);
-                       appcontrol = tmp;
-               }
-       }
-       /*Free DataControl*/
-       if (serviceapplication->datacontrol) {
-               datacontrol_x *datacontrol = serviceapplication->datacontrol;
-               datacontrol_x *tmp = NULL;
-               while(datacontrol != NULL) {
-                       tmp = datacontrol->next;
-                       __ps_free_datacontrol(datacontrol);
-                       datacontrol = tmp;
-               }
-       }
-       /*Free LaunchConditions*/
-       if (serviceapplication->launchconditions) {
-               launchconditions_x *launchconditions = serviceapplication->launchconditions;
-               launchconditions_x *tmp = NULL;
-               while(launchconditions != NULL) {
-                       tmp = launchconditions->next;
-                       __ps_free_launchconditions(launchconditions);
-                       launchconditions = tmp;
-               }
-       }
-       /*Free Notification*/
-       if (serviceapplication->notification) {
-               notification_x *notification = serviceapplication->notification;
-               notification_x *tmp = NULL;
-               while(notification != NULL) {
-                       tmp = notification->next;
-                       __ps_free_notification(notification);
-                       notification = tmp;
-               }
-       }
-       /*Free DataShare*/
-       if (serviceapplication->datashare) {
-               datashare_x *datashare = serviceapplication->datashare;
-               datashare_x *tmp = NULL;
-               while(datashare != NULL) {
-                       tmp = datashare->next;
-                       __ps_free_datashare(datashare);
-                       datashare = tmp;
-               }
-       }
-       /*Free AppSvc*/
-       if (serviceapplication->appsvc) {
-               appsvc_x *appsvc = serviceapplication->appsvc;
-               appsvc_x *tmp = NULL;
-               while(appsvc != NULL) {
-                       tmp = appsvc->next;
-                       __ps_free_appsvc(appsvc);
-                       appsvc = tmp;
-               }
-       }
-       /*Free Category*/
-       if (serviceapplication->category) {
-               category_x *category = serviceapplication->category;
-               category_x *tmp = NULL;
-               while(category != NULL) {
-                       tmp = category->next;
-                       __ps_free_category(category);
-                       category = tmp;
-               }
-       }
-       /*Free Metadata*/
-       if (serviceapplication->metadata) {
-               metadata_x *metadata = serviceapplication->metadata;
-               metadata_x *tmp = NULL;
-               while(metadata != NULL) {
-                       tmp = metadata->next;
-                       __ps_free_metadata(metadata);
-                       metadata = tmp;
-               }
-       }
-       /*Free permission*/
-       if (serviceapplication->permission) {
-               permission_x *permission = serviceapplication->permission;
-               permission_x *tmp = NULL;
-               while(permission != NULL) {
-                       tmp = permission->next;
-                       __ps_free_permission(permission);
-                       permission = tmp;
-               }
-       }
-       free((void*)serviceapplication);
-       serviceapplication = NULL;
-}
-
-static void __ps_free_font(font_x *font)
-{
-       if (font == NULL)
-               return;
-       if (font->name) {
-               free((void *)font->name);
-               font->name = NULL;
-       }
-       if (font->text) {
-               free((void *)font->text);
-               font->text = NULL;
-       }
-       free((void*)font);
-       font = NULL;
-}
-
-static void __ps_free_theme(theme_x *theme)
-{
-       if (theme == NULL)
-               return;
-       if (theme->name) {
-               free((void *)theme->name);
-               theme->name = NULL;
-       }
-       if (theme->text) {
-               free((void *)theme->text);
-               theme->text = NULL;
-       }
-       free((void*)theme);
-       theme = NULL;
-}
-
-static void __ps_free_daemon(daemon_x *daemon)
-{
-       if (daemon == NULL)
-               return;
-       if (daemon->name) {
-               free((void *)daemon->name);
-               daemon->name = NULL;
-       }
-       if (daemon->text) {
-               free((void *)daemon->text);
-               daemon->text = NULL;
-       }
-       free((void*)daemon);
-       daemon = NULL;
-}
-
-static void __ps_free_ime(ime_x *ime)
-{
-       if (ime == NULL)
-               return;
-       if (ime->name) {
-               free((void *)ime->name);
-               ime->name = NULL;
-       }
-       if (ime->text) {
-               free((void *)ime->text);
-               ime->text = NULL;
-       }
-       free((void*)ime);
-       ime = NULL;
-}
-
-
-static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed)
-{
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               allowed->text = ASCII(xmlTextReaderValue(reader));
-       return 0;
-}
-
-static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               operation->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-/* Text does not exist. Only attribute exists
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               operation->text = ASCII(xmlTextReaderValue(reader));
-*/
-       return 0;
-}
-
-static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               uri->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-/* Text does not exist. Only attribute exists
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               uri->text = ASCII(xmlTextReaderValue(reader));
-*/
-       return 0;
-}
-
-static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               mime->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-/* Text does not exist. Only attribute exists
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               mime->text = ASCII(xmlTextReaderValue(reader));
-*/
-       return 0;
-}
-
-static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               subapp->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-/* Text does not exist. Only attribute exists
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               mime->text = ASCII(xmlTextReaderValue(reader));
-*/
-       return 0;
-}
-
-static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               condition->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               condition->text = ASCII(xmlTextReaderValue(reader));
-       return 0;
-}
-
-static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               notification->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               notification->text = ASCII(xmlTextReaderValue(reader));
-       return 0;
-}
-
-static int __ps_process_category(xmlTextReaderPtr reader, category_x *category)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               category->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-       return 0;
-}
-
-static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
-{
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader)) {
-               privilege->text = ASCII(xmlTextReaderValue(reader));
-       }
-       return 0;
-}
-
-static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("key")))
-               metadata->key = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("key")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("value")))
-               metadata->value = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("value")));
-       return 0;
-}
-
-static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
-               permission->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
-
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               permission->value = ASCII(xmlTextReaderValue(reader));
-       return 0;
-}
-
-static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               compatibility->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               compatibility->text = ASCII(xmlTextReaderValue(reader));
-       return 0;
-}
-
-static int __ps_process_resolution(xmlTextReaderPtr reader, resolution_x *resolution)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("mime-type")))
-               resolution->mimetype = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("mime-type")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("uri-scheme")))
-               resolution->urischeme = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("uri-scheme")));
-       return 0;
-}
-
-static int __ps_process_request(xmlTextReaderPtr reader, request_x *request)
-{
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               request->text = ASCII(xmlTextReaderValue(reader));
+       __save_xml_value(reader, request);
        return 0;
 }
 
@@ -1712,312 +1163,240 @@ static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
        const xmlChar *node;
        int ret = -1;
        int depth = -1;
-       allowed_x *tmp1 = NULL;
-       request_x *tmp2 = NULL;
+       const char *val;
 
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("path")))
-               define->path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("path")));
+       __save_xml_attribute(reader, "path", &define->path, NULL);
 
        depth = xmlTextReaderDepth(reader);
        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");
-                               return -1;
-                       }
-                       memset(allowed, '\0', sizeof(allowed_x));
-                       LISTADD(define->allowed, allowed);
-                       ret = __ps_process_allowed(reader, allowed);
+                       val = NULL;
+                       ret = __ps_process_allowed(reader, &val);
+                       if (val)
+                               define->allowed = g_list_append(define->allowed, (gpointer)val);
                } else if (!strcmp(ASCII(node), "request")) {
-                       request_x *request = malloc(sizeof(request_x));
-                       if (request == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(request, '\0', sizeof(request_x));
-                       LISTADD(define->request, request);
-                       ret = __ps_process_request(reader, request);
-               } else
+                       val = NULL;
+                       ret = __ps_process_request(reader, &val);
+                       if (val)
+                               define->request = g_list_append(define->request, (gpointer)val);
+               } else {
                        return -1;
+               }
                if (ret < 0) {
-                       DBG("Processing define failed\n");
+                       _LOGD("Processing define failed\n");
                        return ret;
                }
        }
-       if (define->allowed) {
-               LISTHEAD(define->allowed, tmp1);
-               define->allowed = tmp1;
-       }
-       if (define->request) {
-               LISTHEAD(define->request, tmp2);
-               define->request = tmp2;
-       }
        return ret;
 }
 
-static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol)
+struct appcontrol_data {
+       GList *operations;
+       GList *uris;
+       GList *mimes;
+       GList *appcontrols;
+       char operation[BUFSIZE];
+       char uri[BUFSIZE];
+       char mime[BUFSIZE];
+};
+
+static void __ps_process_mime(gpointer data, gpointer user_data)
 {
-       const xmlChar *node;
-       int ret = -1;
-       int depth = -1;
-       operation_x *tmp1 = NULL;
-       uri_x *tmp2 = NULL;
-       mime_x *tmp3 = NULL;
-       subapp_x *tmp4 = NULL;
+       char *mime = (char *)data;
+       struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
+       appcontrol_x *appcontrol;
 
-       depth = xmlTextReaderDepth(reader);
-       while ((ret = __next_child_element(reader, depth))) {
-               node = xmlTextReaderConstName(reader);
-               if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
-                       return -1;
-               }
+       snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
 
-               if (!strcmp(ASCII(node), "operation")) {
-                       operation_x *operation = malloc(sizeof(operation_x));
-                       if (operation == NULL) {
-                               DBG("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");
-               } else if (!strcmp(ASCII(node), "uri")) {
-                       uri_x *uri= malloc(sizeof(uri_x));
-                       if (uri == NULL) {
-                               DBG("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");
-               } else if (!strcmp(ASCII(node), "mime")) {
-                       mime_x *mime = malloc(sizeof(mime_x));
-                       if (mime == NULL) {
-                               DBG("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");
-               } else if (!strcmp(ASCII(node), "subapp")) {
-                       subapp_x *subapp = malloc(sizeof(subapp_x));
-                       if (subapp == NULL) {
-                               DBG("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");
-               } else
-                       return -1;
-               if (ret < 0) {
-                       DBG("Processing appcontrol failed\n");
-                       return ret;
-               }
-       }
-       if (appcontrol->operation) {
-               LISTHEAD(appcontrol->operation, tmp1);
-               appcontrol->operation = tmp1;
-       }
-       if (appcontrol->uri) {
-               LISTHEAD(appcontrol->uri, tmp2);
-               appcontrol->uri = tmp2;
-       }
-       if (appcontrol->mime) {
-               LISTHEAD(appcontrol->mime, tmp3);
-               appcontrol->mime = tmp3;
+       appcontrol = calloc(1, sizeof(appcontrol_x));
+       if (strlen(ad->operation))
+               appcontrol->operation = strdup(ad->operation);
+       if (strlen(ad->uri))
+               appcontrol->uri = strdup(ad->uri);
+       appcontrol->mime = strdup(ad->mime);
+       ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
+}
+
+static void __ps_process_uri(gpointer data, gpointer user_data)
+{
+       char *uri = (char *)data;
+       struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
+       appcontrol_x *appcontrol;
+
+       snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
+
+       if (ad->mimes != NULL) {
+               g_list_foreach(ad->mimes, __ps_process_mime, user_data);
+       } else {
+               appcontrol = calloc(1, sizeof(appcontrol_x));
+               if (strlen(ad->operation))
+                       appcontrol->operation = strdup(ad->operation);
+               appcontrol->uri = strdup(ad->uri);
+               ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
        }
-       if (appcontrol->subapp) {
-               LISTHEAD(appcontrol->subapp, tmp4);
-               appcontrol->subapp = tmp4;
+}
+
+static void __ps_process_operation(gpointer data, gpointer user_data)
+{
+       char *operation = (char *)data;
+       struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
+       appcontrol_x *appcontrol;
+
+       snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
+
+       if (ad->uris != NULL) {
+               g_list_foreach(ad->uris, __ps_process_uri, user_data);
+       } else if (ad->mimes != NULL) {
+               g_list_foreach(ad->mimes, __ps_process_mime, user_data);
+       } else {
+               appcontrol = calloc(1, sizeof(appcontrol_x));
+               appcontrol->operation = strdup(ad->operation);
+               ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
        }
+}
+
+static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
+{
+       struct appcontrol_data ad = {0, };
+
+       ad.operations = operations;
+       ad.uris = uris;
+       ad.mimes = mimes;
 
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               appcontrol->text = ASCII(xmlTextReaderValue(reader));
+       if (ad.operations == NULL)
+               return NULL;
 
-       return ret;
+       g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
+
+       return ad.appcontrols;
 }
 
-static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
+static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
 {
        const xmlChar *node;
        int ret = -1;
        int depth = -1;
-       operation_x *tmp1 = NULL;
-       uri_x *tmp2 = NULL;
-       mime_x *tmp3 = NULL;
-       subapp_x *tmp4 = NULL;
+       const char *val;
+       GList *operations = NULL;
+       GList *uris = NULL;
+       GList *mimes = NULL;
+       GList *result;
 
        depth = xmlTextReaderDepth(reader);
-       while ((ret = __next_child_element(reader, depth))) {
+       while ((ret = __next_child_element(reader, depth)) > 0) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
+                       _LOGD("xmlTextReaderConstName value is NULL\n");
                        return -1;
                }
 
+               val = NULL;
                if (!strcmp(ASCII(node), "operation")) {
-                       operation_x *operation = malloc(sizeof(operation_x));
-                       if (operation == NULL) {
-                               DBG("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");
+                       __save_xml_attribute(reader, "name", &val, NULL);
+                       if (val)
+                               operations = g_list_append(operations, (gpointer)val);
+                       _LOGD("operation processing\n");
                } else if (!strcmp(ASCII(node), "uri")) {
-                       uri_x *uri= malloc(sizeof(uri_x));
-                       if (uri == NULL) {
-                               DBG("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");
+                       __save_xml_attribute(reader, "name", &val, NULL);
+                       if (val)
+                               uris = g_list_append(uris, (gpointer)val);
+                       _LOGD("uri processing\n");
                } else if (!strcmp(ASCII(node), "mime")) {
-                       mime_x *mime = malloc(sizeof(mime_x));
-                       if (mime == NULL) {
-                               DBG("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");
+                       __save_xml_attribute(reader, "name", &val, NULL);
+                       if (val)
+                               mimes = g_list_append(mimes, (gpointer)val);
+                       _LOGD("mime processing\n");
                } else if (!strcmp(ASCII(node), "subapp")) {
-                       subapp_x *subapp = malloc(sizeof(subapp_x));
-                       if (subapp == NULL) {
-                               DBG("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");
-               } else
-                       return -1;
-               if (ret < 0) {
-                       DBG("Processing appsvc failed\n");
-                       return ret;
+                       continue;
+               } else {
+                       ret = -1;
                }
        }
-       if (appsvc->operation) {
-               LISTHEAD(appsvc->operation, tmp1);
-               appsvc->operation = tmp1;
-       }
-       if (appsvc->uri) {
-               LISTHEAD(appsvc->uri, tmp2);
-               appsvc->uri = tmp2;
-       }
-       if (appsvc->mime) {
-               LISTHEAD(appsvc->mime, tmp3);
-               appsvc->mime = tmp3;
-       }
-       if (appsvc->subapp) {
-               LISTHEAD(appsvc->subapp, tmp4);
-               appsvc->subapp = tmp4;
+
+       if (ret < 0) {
+               _LOGD("Processing appcontrol failed\n");
+               g_list_free_full(operations, free);
+               g_list_free_full(uris, free);
+               g_list_free_full(mimes, free);
+               return ret;
        }
 
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               appsvc->text = ASCII(xmlTextReaderValue(reader));
+       result = __make_appcontrol_list(operations, uris, mimes);
+       if (result)
+               *appcontrol = g_list_concat(*appcontrol, result);
+       else
+               ret = -1;
+
+       g_list_free_full(operations, free);
+       g_list_free_full(uris, free);
+       g_list_free_full(mimes, free);
 
        return ret;
 }
 
-
-static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges)
+static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
 {
        const xmlChar *node;
        int ret = -1;
        int depth = -1;
-       privilege_x *tmp1 = NULL;
+       const char *val;
 
        depth = xmlTextReaderDepth(reader);
        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");
-                               return -1;
-                       }
-                       memset(privilege, '\0', sizeof(privilege_x));
-                       LISTADD(privileges->privilege, privilege);
-                       ret = __ps_process_privilege(reader, privilege);
+                       val = NULL;
+                       ret = __ps_process_privilege(reader, &val);
+                       if (val)
+                               *privileges = g_list_append(*privileges, (gpointer)val);
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing privileges failed\n");
+                       _LOGD("Processing privileges failed\n");
                        return ret;
                }
        }
-       if (privileges->privilege) {
-               LISTHEAD(privileges->privilege, tmp1);
-               privileges->privilege = tmp1;
-       }
        return ret;
 }
 
-static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions)
+static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
 {
        const xmlChar *node;
        int ret = -1;
        int depth = -1;
-       condition_x *tmp1 = NULL;
+       const char *val;
 
        depth = xmlTextReaderDepth(reader);
        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");
-                               return -1;
-                       }
-                       memset(condition, '\0', sizeof(condition_x));
-                       LISTADD(launchconditions->condition, condition);
-                       ret = __ps_process_condition(reader, condition);
+                       val = NULL;
+                       ret = __ps_process_condition(reader, &val);
+                       if (val)
+                               *launchconditions = g_list_append(*launchconditions, (gpointer)val);
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing launchconditions failed\n");
+                       _LOGD("Processing launchconditions failed\n");
                        return ret;
                }
        }
-       if (launchconditions->condition) {
-               LISTHEAD(launchconditions->condition, tmp1);
-               launchconditions->condition = tmp1;
-       }
-
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               launchconditions->text = ASCII(xmlTextReaderValue(reader));
 
        return ret;
 }
@@ -2027,1014 +1406,451 @@ static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashar
        const xmlChar *node;
        int ret = -1;
        int depth = -1;
-       define_x *tmp1 = NULL;
-       request_x *tmp2 = NULL;
+       const char *val;
        depth = xmlTextReaderDepth(reader);
        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));
+                       define_x *define = calloc(1, sizeof(define_x));
                        if (define == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(define, '\0', sizeof(define_x));
-                       LISTADD(datashare->define, define);
+                       datashare->define = g_list_append(datashare->define, define);
                        ret = __ps_process_define(reader, define);
                } else if (!strcmp(ASCII(node), "request")) {
-                       request_x *request= malloc(sizeof(request_x));
-                       if (request == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(request, '\0', sizeof(request_x));
-                       LISTADD(datashare->request, request);
-                       ret = __ps_process_request(reader, request);
+                       val = NULL;
+                       ret = __ps_process_request(reader, &val);
+                       if (val)
+                               datashare->request = g_list_append(datashare->request, (gpointer)val);
                } else
                        return -1;
                if (ret < 0) {
-                       DBG("Processing data-share failed\n");
+                       _LOGD("Processing data-share failed\n");
                        return ret;
                }
        }
-       if (datashare->define) {
-               LISTHEAD(datashare->define, tmp1);
-               datashare->define = tmp1;
-       }
-       if (datashare->request) {
-               LISTHEAD(datashare->request, tmp2);
-               datashare->request = tmp2;
-       }
        return ret;
 }
 
-static char*
-__get_icon_with_path(const char* icon)
+static char *__get_icon_with_path(const char *icon, uid_t uid)
 {
-       if (!icon)
-               return NULL;
+       char icon_with_path[BUFSIZE];
+       const char *app_path;
 
-       if (index(icon, '/') == NULL) {
-               char* theme = NULL;
-               char* icon_with_path = NULL;
-               int len;
-
-               if (!package)
-                       return NULL;
-
-               theme = vconf_get_str("db/setting/theme");
-               if (!theme) {
-                       theme = strdup("default");
-                       if(!theme) {
-                               return NULL;
-                       }
-               }
-
-               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");
-                       free(theme);
-                       return NULL;
-               }
+       if (!icon || !package)
+               return NULL;
 
-               memset(icon_with_path, 0, len);
-
-               snprintf(icon_with_path, len, "/opt/share/icons/%s/small/%s", theme, icon);
-               do {
-                       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);
-                       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);
-                       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);
-                       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);
-                       if (access(icon_with_path, R_OK) == 0) break;
-               } while (0);
-
-               free(theme);
-
-               DBG("Icon path : %s ---> %s", icon, icon_with_path);
-
-               return icon_with_path;
-       } else {
-               char* confirmed_icon = NULL;
+       /* just use absolute path */
+       if (index(icon, '/'))
+               return strdup(icon);
 
-               confirmed_icon = strdup(icon);
-               if (!confirmed_icon)
-                       return NULL;
-               return confirmed_icon;
-       }
-}
+       do {
+               snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
+                               getIconPath(uid), icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
 
+               /* for backward compatibility (.../default/small/...)
+                * this should be removed
+                */
+               snprintf(icon_with_path, sizeof(icon_with_path),
+                               "%sdefault/small/%s",
+                               getIconPath(uid), icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
 
-static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               icon->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-       if (xmlTextReaderConstXmlLang(reader)) {
-               icon->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
-               if (icon->lang == NULL)
-                       icon->lang = strdup(DEFAULT_LOCALE);
-       } else {
-               icon->lang = strdup(DEFAULT_LOCALE);
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("section")))
-               icon->section = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("section")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("size")))
-               icon->size = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("size")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("resolution")))
-               icon->resolution = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("resolution")));
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader)) {
-               const char *text  = ASCII(xmlTextReaderValue(reader));
-               if(text) {
-                       icon->text = (const char *)__get_icon_with_path(text);
-                       free((void *)text);
+               if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
+                       app_path = tzplatform_getenv(TZ_SYS_RW_APP);
+               } else {
+                       tzplatform_set_user(uid);
+                       app_path = tzplatform_getenv(TZ_USER_APP);
+                       tzplatform_reset_user();
                }
-       }
-
-       return 0;
-}
-
-static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               image->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-       if (xmlTextReaderConstXmlLang(reader)) {
-               image->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
-               if (image->lang == NULL)
-                       image->lang = strdup(DEFAULT_LOCALE);
-       } else {
-               image->lang = strdup(DEFAULT_LOCALE);
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("section")))
-               image->section = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("section")));
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               image->text = ASCII(xmlTextReaderValue(reader));
-
-       return 0;
-}
-
-static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
-               label->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
-       if (xmlTextReaderConstXmlLang(reader)) {
-               label->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
-               if (label->lang == NULL)
-                       label->lang = strdup(DEFAULT_LOCALE);
-       } else {
-               label->lang = strdup(DEFAULT_LOCALE);
-       }
-       xmlTextReaderRead(reader);
-       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);
-*/
-       return 0;
-
-}
-
-static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
-{
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("email")))
-               author->email = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("email")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("href")))
-               author->href = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("href")));
-       if (xmlTextReaderConstXmlLang(reader)) {
-               author->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
-               if (author->lang == NULL)
-                       author->lang = strdup(DEFAULT_LOCALE);
-       } else {
-               author->lang = strdup(DEFAULT_LOCALE);
-       }
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               author->text = ASCII(xmlTextReaderValue(reader));
-       return 0;
-}
-
-static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
-{
-       if (xmlTextReaderConstXmlLang(reader)) {
-               description->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
-               if (description->lang == NULL)
-                       description->lang = strdup(DEFAULT_LOCALE);
-       } else {
-               description->lang = strdup(DEFAULT_LOCALE);
-       }
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               description->text = ASCII(xmlTextReaderValue(reader));
-       return 0;
-}
 
-static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
-{
-       if (xmlTextReaderConstXmlLang(reader)) {
-               license->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
-               if (license->lang == NULL)
-                       license->lang = strdup(DEFAULT_LOCALE);
-       } else {
-               license->lang = strdup(DEFAULT_LOCALE);
-       }
-       xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
-               license->text = ASCII(xmlTextReaderValue(reader));
-       return 0;
-}
-
-static int __ps_process_capability(xmlTextReaderPtr reader, capability_x *capability)
-{
-       const xmlChar *node;
-       int ret = -1;
-       int depth = -1;
-       resolution_x *tmp1 = NULL;
+               /* If doesn't exist in case of Global app,
+                * try to get icon directly into app's directory
+                */
+               snprintf(icon_with_path, sizeof(icon_with_path),
+                               "%s/%s/%s", app_path, package, icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
 
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("operation-id")))
-               capability->operationid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("operation-id")));
+               /* some preload package has icons at below path */
+               snprintf(icon_with_path, sizeof(icon_with_path),
+                               "%s/%s/res/icons/%s", app_path, package, icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
 
-       depth = xmlTextReaderDepth(reader);
-       while ((ret = __next_child_element(reader, depth))) {
-               node = xmlTextReaderConstName(reader);
-               if (!node) {
-                       DBG("xmlTextReaderConstName value is NULL\n");
-                       return -1;
-               }
+               /* since 2.3 tpk package */
+               snprintf(icon_with_path, sizeof(icon_with_path),
+                               "%s/%s/shared/res/%s", app_path, package, icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
 
-               if (!strcmp(ASCII(node), "resolution")) {
-                       resolution_x *resolution = malloc(sizeof(resolution_x));
-                       if (resolution == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(resolution, '\0', sizeof(resolution_x));
-                       LISTADD(capability->resolution, resolution);
-                       ret = __ps_process_resolution(reader, resolution);
-               } else
-                       return -1;
-               if (ret < 0) {
-                       DBG("Processing capability failed\n");
-                       return ret;
-               }
-       }
+               _LOGE("cannot find icon path for [%s]", icon);
+               return NULL;
+       } while (0);
 
-       if (capability->resolution) {
-               LISTHEAD(capability->resolution, tmp1);
-               capability->resolution = tmp1;
-       }
+       _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
 
-       return ret;
+       return strdup(icon_with_path);
 }
 
-static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
+static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
 {
-       const xmlChar *node;
-       int ret = -1;
-       int depth = -1;
-       capability_x *tmp1 = NULL;
-
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("provider-id")))
-               datacontrol->providerid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("provider-id")));
-
-       depth = xmlTextReaderDepth(reader);
-       while ((ret = __next_child_element(reader, depth))) {
-               node = xmlTextReaderConstName(reader);
-               if (!node) {
-                       DBG("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");
-                               return -1;
-                       }
-                       memset(capability, '\0', sizeof(capability_x));
-                       LISTADD(datacontrol->capability, capability);
-                       ret = __ps_process_capability(reader, capability);
-               } else
-                       return -1;
-               if (ret < 0) {
-                       DBG("Processing datacontrol failed\n");
-                       return ret;
-               }
-       }
-
-       if (datacontrol->capability) {
-               LISTHEAD(datacontrol->capability, tmp1);
-               datacontrol->capability = tmp1;
-       }
-
-       return ret;
-}
+       int i = 0;
+       char delims[] = "=";
+       char *ret_result = NULL;
+       char *tag = NULL;
 
-static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication)
-{
-       const xmlChar *node;
-       int ret = -1;
-       int depth = -1;
-       char *newappid = NULL;
-       label_x *tmp1 = NULL;
-       icon_x *tmp2 = NULL;
-       appsvc_x *tmp3 = NULL;
-       appcontrol_x *tmp4 = NULL;
-       launchconditions_x *tmp5 = NULL;
-       notification_x *tmp6 = NULL;
-       datashare_x *tmp7 = NULL;
-       category_x *tmp8 = NULL;
-       metadata_x *tmp9 = NULL;
-       image_x *tmp10 = NULL;
-       permission_x *tmp11 = NULL;
-
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("appid"))) {
-               uiapplication->appid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appid")));
-               if (uiapplication->appid == NULL) {
-                       DBG("appid cant be NULL\n");
-                       return -1;
-               }
-       } else {
-               DBG("appid is mandatory\n");
-               return -1;
-       }
-       /*check appid*/
-       ret = __validate_appid(package, uiapplication->appid, &newappid);
-       if (ret == -1) {
-               DBG("appid is not proper\n");
-               return -1;
-       } else {
-               if (newappid) {
-                       if (uiapplication->appid)
-                               free((void *)uiapplication->appid);
-                       uiapplication->appid = newappid;
-               }
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("exec")))
-               uiapplication->exec = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("exec")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay"))) {
-               uiapplication->nodisplay = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay")));
-               if (uiapplication->nodisplay == NULL)
-                       uiapplication->nodisplay = strdup("false");
-       } else {
-               uiapplication->nodisplay = strdup("false");
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("multiple"))) {
-               uiapplication->multiple = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("multiple")));
-               if (uiapplication->multiple == NULL)
-                       uiapplication->multiple = strdup("false");
-       } else {
-               uiapplication->multiple = strdup("false");
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
-               uiapplication->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("categories")))
-               uiapplication->categories = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("categories")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("extraid")))
-               uiapplication->extraid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("extraid")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("taskmanage"))) {
-               uiapplication->taskmanage = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("taskmanage")));
-               if (uiapplication->taskmanage == NULL)
-                       uiapplication->taskmanage = strdup("true");
-       } else {
-               uiapplication->taskmanage = strdup("true");
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("enabled"))) {
-               uiapplication->enabled = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("enabled")));
-               if (uiapplication->enabled == NULL)
-                       uiapplication->enabled = strdup("true");
-       } else {
-               uiapplication->enabled = strdup("true");
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("hw-acceleration"))) {
-               uiapplication->hwacceleration = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("hw-acceleration")));
-               if (uiapplication->hwacceleration == NULL)
-                       uiapplication->hwacceleration = strdup("use-system-setting");
-       } else {
-               uiapplication->hwacceleration = strdup("use-system-setting");
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("recentimage")))
-               uiapplication->recentimage = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("recentimage")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("mainapp"))) {
-               uiapplication->mainapp = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("mainapp")));
-               if (uiapplication->mainapp == NULL)
-                       uiapplication->mainapp = strdup("false");
-       } else {
-               uiapplication->mainapp = strdup("false");
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay"))) {
-               uiapplication->indicatordisplay = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay")));
-               if (uiapplication->indicatordisplay == NULL)
-                       uiapplication->indicatordisplay = strdup("true");
-       } else {
-               uiapplication->indicatordisplay = strdup("true");
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("portrait-effectimage")))
-               uiapplication->portraitimg = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("portrait-effectimage")));
-       else
-               uiapplication->portraitimg = NULL;
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("landscape-effectimage")))
-               uiapplication->landscapeimg = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("landscape-effectimage")));
-       else
-               uiapplication->landscapeimg = NULL;
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("guestmode-visibility"))) {
-               uiapplication->guestmode_visibility = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("guestmode-visibility")));
-               if (uiapplication->guestmode_visibility == NULL)
-                       uiapplication->guestmode_visibility = strdup("true");
-       } else {
-               uiapplication->guestmode_visibility = strdup("true");
-       }
+       if (tagv == NULL)
+               return;
 
-       depth = xmlTextReaderDepth(reader);
-       while ((ret = __next_child_element(reader, depth))) {
-               node = xmlTextReaderConstName(reader);
-               if (!node) {
-                       DBG("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");
-                               return -1;
-                       }
-                       memset(label, '\0', sizeof(label_x));
-                       LISTADD(uiapplication->label, label);
-                       ret = __ps_process_label(reader, label);
-               } else if (!strcmp(ASCII(node), "icon")) {
-                       icon_x *icon = malloc(sizeof(icon_x));
-                       if (icon == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(icon, '\0', sizeof(icon_x));
-                       LISTADD(uiapplication->icon, icon);
-                       ret = __ps_process_icon(reader, icon);
-               } else if (!strcmp(ASCII(node), "image")) {
-                       image_x *image = malloc(sizeof(image_x));
-                       if (image == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(image, '\0', sizeof(image_x));
-                       LISTADD(uiapplication->image, image);
-                       ret = __ps_process_image(reader, image);
-               } else if (!strcmp(ASCII(node), "category")) {
-                       category_x *category = malloc(sizeof(category_x));
-                       if (category == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(category, '\0', sizeof(category_x));
-                       LISTADD(uiapplication->category, category);
-                       ret = __ps_process_category(reader, category);
-               } else if (!strcmp(ASCII(node), "metadata")) {
-                       metadata_x *metadata = malloc(sizeof(metadata_x));
-                       if (metadata == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(metadata, '\0', sizeof(metadata_x));
-                       LISTADD(uiapplication->metadata, metadata);
-                       ret = __ps_process_metadata(reader, metadata);
-               } else if (!strcmp(ASCII(node), "permission")) {
-                       permission_x *permission = malloc(sizeof(permission_x));
-                       if (permission == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(permission, '\0', sizeof(permission_x));
-                       LISTADD(uiapplication->permission, permission);
-                       ret = __ps_process_permission(reader, permission);
-               } else if (!strcmp(ASCII(node), "app-control")) {
-                       appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
-                       if (appcontrol == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(appcontrol, '\0', sizeof(appcontrol_x));
-                       LISTADD(uiapplication->appcontrol, appcontrol);
-                       ret = __ps_process_appcontrol(reader, appcontrol);
-               } else if (!strcmp(ASCII(node), "application-service")) {
-                       appsvc_x *appsvc = malloc(sizeof(appsvc_x));
-                       if (appsvc == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(appsvc, '\0', sizeof(appsvc_x));
-                       LISTADD(uiapplication->appsvc, appsvc);
-                       ret = __ps_process_appsvc(reader, appsvc);
-               } else if (!strcmp(ASCII(node), "data-share")) {
-                       datashare_x *datashare = malloc(sizeof(datashare_x));
-                       if (datashare == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(datashare, '\0', sizeof(datashare_x));
-                       LISTADD(uiapplication->datashare, datashare);
-                       ret = __ps_process_datashare(reader, datashare);
-               } else if (!strcmp(ASCII(node), "launch-conditions")) {
-                       launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
-                       if (launchconditions == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(launchconditions, '\0', sizeof(launchconditions_x));
-                       LISTADD(uiapplication->launchconditions, launchconditions);
-                       ret = __ps_process_launchconditions(reader, launchconditions);
-               } else if (!strcmp(ASCII(node), "notification")) {
-                       notification_x *notification = malloc(sizeof(notification_x));
-                       if (notification == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
+       for (tag = strdup(tagv[0]); tag != NULL; ) {
+               ret_result = strtok(tag, delims);
+
+               /*check tag :  preload */
+               if (strcmp(ret_result, "preload") == 0) {
+                       ret_result = strtok(NULL, delims);
+                       if (strcmp(ret_result, "true") == 0) {
+                               free((void *)mfx->preload);
+                               mfx->preload = strdup("true");
+                       } else if (strcmp(ret_result, "false") == 0) {
+                               free((void *)mfx->preload);
+                               mfx->preload = strdup("false");
+                       }
+               /*check tag :  removable*/
+               } else if (strcmp(ret_result, "removable") == 0) {
+                       ret_result = strtok(NULL, delims);
+                       if (strcmp(ret_result, "true") == 0){
+                               free((void *)mfx->removable);
+                               mfx->removable = strdup("true");
+                       } else if (strcmp(ret_result, "false") == 0) {
+                               free((void *)mfx->removable);
+                               mfx->removable = strdup("false");
                        }
-                       memset(notification, '\0', sizeof(notification_x));
-                       LISTADD(uiapplication->notification, notification);
-                       ret = __ps_process_notification(reader, notification);
+               /*check tag :  not matched*/
                } else
-                       return -1;
-               if (ret < 0) {
-                       DBG("Processing uiapplication failed\n");
-                       return ret;
-               }
-       }
+                       _LOGD("tag process [%s]is not defined\n", ret_result);
 
-       if (uiapplication->label) {
-               LISTHEAD(uiapplication->label, tmp1);
-               uiapplication->label = tmp1;
-       }
-       if (uiapplication->icon) {
-               LISTHEAD(uiapplication->icon, tmp2);
-               uiapplication->icon = tmp2;
-       }
-       if (uiapplication->appsvc) {
-               LISTHEAD(uiapplication->appsvc, tmp3);
-               uiapplication->appsvc = tmp3;
-       }
-       if (uiapplication->appcontrol) {
-               LISTHEAD(uiapplication->appcontrol, tmp4);
-               uiapplication->appcontrol = tmp4;
-       }
-       if (uiapplication->launchconditions) {
-               LISTHEAD(uiapplication->launchconditions, tmp5);
-               uiapplication->launchconditions = tmp5;
-       }
-       if (uiapplication->notification) {
-               LISTHEAD(uiapplication->notification, tmp6);
-               uiapplication->notification = tmp6;
-       }
-       if (uiapplication->datashare) {
-               LISTHEAD(uiapplication->datashare, tmp7);
-               uiapplication->datashare = tmp7;
-       }
-       if (uiapplication->category) {
-               LISTHEAD(uiapplication->category, tmp8);
-               uiapplication->category = tmp8;
-       }
-       if (uiapplication->metadata) {
-               LISTHEAD(uiapplication->metadata, tmp9);
-               uiapplication->metadata = tmp9;
-       }
-       if (uiapplication->image) {
-               LISTHEAD(uiapplication->image, tmp10);
-               uiapplication->image = tmp10;
+               free(tag);
+
+               /*check next value*/
+               if (tagv[++i] != NULL)
+                       tag = strdup(tagv[i]);
+               else {
+                       _LOGD("tag process success...\n");
+                       return;
+               }
        }
-       if (uiapplication->permission) {
-               LISTHEAD(uiapplication->permission, tmp11);
-               uiapplication->permission = tmp11;
+}
+
+static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
+{
+       __save_xml_attribute(reader, "name", &icon->name, NULL);
+       __save_xml_attribute(reader, "section", &icon->section, NULL);
+       __save_xml_attribute(reader, "size", &icon->size, NULL);
+       __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
+       __save_xml_lang(reader, &icon->lang);
+
+       xmlTextReaderRead(reader);
+       const char *text  = ASCII(xmlTextReaderValue(reader));
+       if (text) {
+               icon->text = (const char *)__get_icon_with_path(text, uid);
+               free((void *)text);
        }
 
-       return ret;
+       return 0;
+}
+
+static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
+{
+       __save_xml_attribute(reader, "name", &image->name, NULL);
+       __save_xml_attribute(reader, "section", &image->section, NULL);
+       __save_xml_lang(reader, &image->lang);
+       __save_xml_value(reader, &image->text);
+       return 0;
+}
+
+static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
+{
+       __save_xml_attribute(reader, "name", &label->name, NULL);
+       __save_xml_lang(reader, &label->lang);
+       __save_xml_value(reader, &label->text);
+       return 0;
+
+}
+
+static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
+{
+       __save_xml_attribute(reader, "email", &author->email, NULL);
+       __save_xml_attribute(reader, "href", &author->href, NULL);
+       __save_xml_value(reader, &author->text);
+       return 0;
+}
+
+static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
+{
+       __save_xml_lang(reader, &description->lang);
+       __save_xml_value(reader, &description->text);
+       return 0;
+}
+
+static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
+{
+       __save_xml_lang(reader, &license->lang);
+       __save_xml_value(reader, &license->text);
+       return 0;
+}
+
+static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
+{
+       __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
+       __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
+       __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
+       return 0;
 }
 
-static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication)
+static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
 {
        const xmlChar *node;
        int ret = -1;
        int depth = -1;
-       char *newappid = NULL;
-       label_x *tmp1 = NULL;
-       icon_x *tmp2 = NULL;
-       appsvc_x *tmp3 = NULL;
-       appcontrol_x *tmp4 = NULL;
-       datacontrol_x *tmp5 = NULL;
-       launchconditions_x *tmp6 = NULL;
-       notification_x *tmp7 = NULL;
-       datashare_x *tmp8 = NULL;
-       category_x *tmp9 = NULL;
-       metadata_x *tmp10 = NULL;
-       permission_x *tmp11 = NULL;
-
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("appid"))) {
-               serviceapplication->appid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appid")));
-               if (serviceapplication->appid == NULL) {
-                       DBG("appid cant be NULL\n");
-                       return -1;
-               }
-       } else {
-               DBG("appid is mandatory\n");
-               return -1;
-       }
-       /*check appid*/
-       ret = __validate_appid(package, serviceapplication->appid, &newappid);
-       if (ret == -1) {
-               DBG("appid is not proper\n");
-               return -1;
-       } else {
-               if (newappid) {
-                       if (serviceapplication->appid)
-                               free((void *)serviceapplication->appid);
-                       serviceapplication->appid = newappid;
-               }
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("exec")))
-               serviceapplication->exec = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("exec")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
-               serviceapplication->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("on-boot"))) {
-               serviceapplication->onboot = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("on-boot")));
-               if (serviceapplication->onboot == NULL)
-                       serviceapplication->onboot = strdup("false");
-       } else {
-               serviceapplication->onboot = strdup("false");
-       }
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("auto-restart"))) {
-               serviceapplication->autorestart = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("auto-restart")));
-               if (serviceapplication->autorestart == NULL)
-                       serviceapplication->autorestart = strdup("false");
-       } else {
-               serviceapplication->autorestart = strdup("false");
+       const char *val;
+
+       __save_xml_attribute(reader, "appid", &application->appid, NULL);
+       retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
+       __save_xml_attribute(reader, "exec", &application->exec, NULL);
+       __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
+       __save_xml_attribute(reader, "multiple", &application->multiple, "false");
+       __save_xml_attribute(reader, "type", &application->type, NULL);
+       __save_xml_attribute(reader, "categories", &application->categories, NULL);
+       __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
+       __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
+       __save_xml_attribute(reader, "enabled", &application->enabled, "true");
+       __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
+       __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
+       __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
+       __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
+       __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
+       __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
+       __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
+       __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
+       __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
+       __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
+       __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
+       /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
+       retvm_if(((strcmp(application->component_type, "svcapp") != 0) && (strcmp(application->component_type, "uiapp") != 0) && (strcmp(application->component_type, "widgetapp") != 0)), PM_PARSER_R_ERROR, "invalid component_type[%s]", application->component_type);
+       __save_xml_attribute(reader, "submode", &application->submode, "false");
+       __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
+       __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
+       __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
+       __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
+       __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
+       __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
+
+       application->package= strdup(package);
+       /* overwrite some attributes if the app is widgetapp */
+       if (type == PMINFO_WIDGET_APP) {
+               free((void *)application->nodisplay);
+               application->nodisplay = strdup("true");
+               free((void *)application->multiple);
+               application->multiple = strdup("true");
+               free((void *)application->type);
+               application->type = strdup("capp");
+               free((void *)application->taskmanage);
+               application->taskmanage = strdup("false");
+               free((void *)application->indicatordisplay);
+               application->indicatordisplay = strdup("false");
        }
 
        depth = xmlTextReaderDepth(reader);
        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));
+                       label_x *label = calloc(1, sizeof(label_x));
                        if (label == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(label, '\0', sizeof(label_x));
-                       LISTADD(serviceapplication->label, label);
+                       application->label = g_list_append(application->label, label);
                        ret = __ps_process_label(reader, label);
                } else if (!strcmp(ASCII(node), "icon")) {
-                       icon_x *icon = malloc(sizeof(icon_x));
+                       icon_x *icon = calloc(1, sizeof(icon_x));
                        if (icon == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(icon, '\0', sizeof(icon_x));
-                       LISTADD(serviceapplication->icon, icon);
-                       ret = __ps_process_icon(reader, icon);
-               } else if (!strcmp(ASCII(node), "category")) {
-                       category_x *category = malloc(sizeof(category_x));
-                       if (category == NULL) {
-                               DBG("Malloc Failed\n");
+                       application->icon = g_list_append(application->icon, icon);
+                       ret = __ps_process_icon(reader, icon, uid);
+               } else if (!strcmp(ASCII(node), "image")) {
+                       image_x *image = calloc(1, sizeof(image_x));
+                       if (image == NULL) {
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(category, '\0', sizeof(category_x));
-                       LISTADD(serviceapplication->category, category);
-                       ret = __ps_process_category(reader, category);
+                       application->image = g_list_append(application->image, image);
+                       ret = __ps_process_image(reader, image);
+               } else if (!strcmp(ASCII(node), "category")) {
+                       val = NULL;
+                       ret = __ps_process_category(reader, &val);
+                       if (val)
+                               application->category = g_list_append(application->category, (gpointer)val);
                } else if (!strcmp(ASCII(node), "metadata")) {
-                       metadata_x *metadata = malloc(sizeof(metadata_x));
+                       metadata_x *metadata = calloc(1, sizeof(metadata_x));
                        if (metadata == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(metadata, '\0', sizeof(metadata_x));
-                       LISTADD(serviceapplication->metadata, metadata);
+                       application->metadata = g_list_append(application->metadata, metadata);
                        ret = __ps_process_metadata(reader, metadata);
                } else if (!strcmp(ASCII(node), "permission")) {
-                       permission_x *permission = malloc(sizeof(permission_x));
+                       permission_x *permission = calloc(1, sizeof(permission_x));
                        if (permission == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(permission, '\0', sizeof(permission_x));
-                       LISTADD(serviceapplication->permission, permission);
+                       application->permission = g_list_append(application->permission, permission);
                        ret = __ps_process_permission(reader, permission);
                } else if (!strcmp(ASCII(node), "app-control")) {
-                       appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
-                       if (appcontrol == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(appcontrol, '\0', sizeof(appcontrol_x));
-                       LISTADD(serviceapplication->appcontrol, appcontrol);
-                       ret = __ps_process_appcontrol(reader, appcontrol);
+                       ret = __ps_process_appcontrol(reader, &application->appcontrol);
                } else if (!strcmp(ASCII(node), "application-service")) {
-                       appsvc_x *appsvc = malloc(sizeof(appsvc_x));
-                       if (appsvc == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(appsvc, '\0', sizeof(appsvc_x));
-                       LISTADD(serviceapplication->appsvc, appsvc);
-                       ret = __ps_process_appsvc(reader, appsvc);
+                       ret = __ps_process_appcontrol(reader, &application->appcontrol);
                } else if (!strcmp(ASCII(node), "data-share")) {
-                       datashare_x *datashare = malloc(sizeof(datashare_x));
+                       datashare_x *datashare = calloc(1, sizeof(datashare_x));
                        if (datashare == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(datashare, '\0', sizeof(datashare_x));
-                       LISTADD(serviceapplication->datashare, datashare);
+                       application->datashare = g_list_append(application->datashare, datashare);
                        ret = __ps_process_datashare(reader, datashare);
                } else if (!strcmp(ASCII(node), "launch-conditions")) {
-                       launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
-                       if (launchconditions == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(launchconditions, '\0', sizeof(launchconditions_x));
-                       LISTADD(serviceapplication->launchconditions, launchconditions);
-                       ret = __ps_process_launchconditions(reader, launchconditions);
+                       ret = __ps_process_launchconditions(reader, &application->launchconditions);
                } else if (!strcmp(ASCII(node), "notification")) {
-                       notification_x *notification = malloc(sizeof(notification_x));
+                       notification_x *notification = calloc(1, sizeof(notification_x));
                        if (notification == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(notification, '\0', sizeof(notification_x));
-                       LISTADD(serviceapplication->notification, notification);
+                       application->notification = g_list_append(application->notification, notification);
                        ret = __ps_process_notification(reader, notification);
-               } else if (!strcmp(ASCII(node), "data-control")) {
-                       datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
+               } else if (!strcmp(ASCII(node), "datacontrol")) {
+                       datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
                        if (datacontrol == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(datacontrol, '\0', sizeof(datacontrol_x));
-                       LISTADD(serviceapplication->datacontrol, datacontrol);
+                       application->datacontrol = g_list_append(application->datacontrol, datacontrol);
                        ret = __ps_process_datacontrol(reader, datacontrol);
                } else
-                       return -1;
+                       continue;
                if (ret < 0) {
-                       DBG("Processing serviceapplication failed\n");
+                       _LOGD("Processing application failed\n");
                        return ret;
                }
        }
 
-       if (serviceapplication->label) {
-               LISTHEAD(serviceapplication->label, tmp1);
-               serviceapplication->label = tmp1;
-       }
-       if (serviceapplication->icon) {
-               LISTHEAD(serviceapplication->icon, tmp2);
-               serviceapplication->icon = tmp2;
-       }
-       if (serviceapplication->appsvc) {
-               LISTHEAD(serviceapplication->appsvc, tmp3);
-               serviceapplication->appsvc = tmp3;
-       }
-       if (serviceapplication->appcontrol) {
-               LISTHEAD(serviceapplication->appcontrol, tmp4);
-               serviceapplication->appcontrol = tmp4;
-       }
-       if (serviceapplication->datacontrol) {
-               LISTHEAD(serviceapplication->datacontrol, tmp5);
-               serviceapplication->datacontrol = tmp5;
-       }
-       if (serviceapplication->launchconditions) {
-               LISTHEAD(serviceapplication->launchconditions, tmp6);
-               serviceapplication->launchconditions = tmp6;
-       }
-       if (serviceapplication->notification) {
-               LISTHEAD(serviceapplication->notification, tmp7);
-               serviceapplication->notification = tmp7;
-       }
-       if (serviceapplication->datashare) {
-               LISTHEAD(serviceapplication->datashare, tmp8);
-               serviceapplication->datashare = tmp8;
-       }
-       if (serviceapplication->category) {
-               LISTHEAD(serviceapplication->category, tmp9);
-               serviceapplication->category = tmp9;
-       }
-       if (serviceapplication->metadata) {
-               LISTHEAD(serviceapplication->metadata, tmp10);
-               serviceapplication->metadata = tmp10;
-       }
-       if (serviceapplication->permission) {
-               LISTHEAD(serviceapplication->permission, tmp11);
-               serviceapplication->permission = tmp11;
-       }
-
        return ret;
 }
 
-static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile)
-{
-       /*TODO: once policy is set*/
-       return 0;
-}
-
-static int __ps_process_font(xmlTextReaderPtr reader, font_x *font)
-{
-       /*TODO: once policy is set*/
-       return 0;
-}
-
-static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme)
-{
-       /*TODO: once policy is set*/
-       return 0;
-}
-
-static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon)
-{
-       /*TODO: once policy is set*/
-       return 0;
-}
-
-static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
+static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
 {
-       /*TODO: once policy is set*/
-       return 0;
-}
-
-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;
-       label_x *tmp1 = NULL;
-       author_x *tmp2 = NULL;
-       description_x *tmp3 = NULL;
-       license_x *tmp4 = NULL;
-       uiapplication_x *tmp5 = NULL;
-       serviceapplication_x *tmp6 = NULL;
-       daemon_x *tmp7 = NULL;
-       theme_x *tmp8 = NULL;
-       font_x *tmp9 = NULL;
-       ime_x *tmp10 = NULL;
-       icon_x *tmp11 = NULL;
-       compatibility_x *tmp12 = NULL;
-       deviceprofile_x *tmp13 = NULL;
-       privileges_x *tmp14 = NULL;
 
        depth = xmlTextReaderDepth(reader);
        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));
+                       label_x *label = calloc(1, sizeof(label_x));
                        if (label == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(label, '\0', sizeof(label_x));
-                       LISTADD(mfx->label, label);
+                       mfx->label = g_list_append(mfx->label, label);
                        ret = __ps_process_label(reader, label);
                } else if (!strcmp(ASCII(node), "author")) {
-                       author_x *author = malloc(sizeof(author_x));
+                       author_x *author = calloc(1, sizeof(author_x));
                        if (author == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(author, '\0', sizeof(author_x));
-                       LISTADD(mfx->author, author);
+                       mfx->author = g_list_append(mfx->author, author);
                        ret = __ps_process_author(reader, author);
                } else if (!strcmp(ASCII(node), "description")) {
-                       description_x *description = malloc(sizeof(description_x));
+                       description_x *description = calloc(1, sizeof(description_x));
                        if (description == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(description, '\0', sizeof(description_x));
-                       LISTADD(mfx->description, description);
+                       mfx->description = g_list_append(mfx->description, description);
                        ret = __ps_process_description(reader, description);
                } else if (!strcmp(ASCII(node), "license")) {
-                       license_x *license = malloc(sizeof(license_x));
+                       license_x *license = calloc(1, sizeof(license_x));
                        if (license == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(license, '\0', sizeof(license_x));
-                       LISTADD(mfx->license, license);
+                       mfx->license = g_list_append(mfx->license, license);
                        ret = __ps_process_license(reader, license);
                } else if (!strcmp(ASCII(node), "privileges")) {
-                       privileges_x *privileges = malloc(sizeof(privileges_x));
-                       if (privileges == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(privileges, '\0', sizeof(privileges_x));
-                       LISTADD(mfx->privileges, privileges);
-                       ret = __ps_process_privileges(reader, privileges);
+                       ret = __ps_process_privileges(reader, &mfx->privileges);
                } else if (!strcmp(ASCII(node), "ui-application")) {
-                       uiapplication_x *uiapplication = malloc(sizeof(uiapplication_x));
-                       if (uiapplication == NULL) {
-                               DBG("Malloc Failed\n");
+                       application_x *application = calloc(1, sizeof(application_x));
+                       if (application == NULL) {
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(uiapplication, '\0', sizeof(uiapplication_x));
-                       LISTADD(mfx->uiapplication, uiapplication);
-                       ret = __ps_process_uiapplication(reader, uiapplication);
+                       mfx->application = g_list_append(mfx->application, application);
+                       ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
                } else if (!strcmp(ASCII(node), "service-application")) {
-                       serviceapplication_x *serviceapplication = malloc(sizeof(serviceapplication_x));
-                       if (serviceapplication == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(serviceapplication, '\0', sizeof(serviceapplication_x));
-                       LISTADD(mfx->serviceapplication, serviceapplication);
-                       ret = __ps_process_serviceapplication(reader, serviceapplication);
-               } else if (!strcmp(ASCII(node), "daemon")) {
-                       daemon_x *daemon = malloc(sizeof(daemon_x));
-                       if (daemon == NULL) {
-                               DBG("Malloc Failed\n");
+                       application_x *application = calloc(1, sizeof(application_x));
+                       if (application == NULL) {
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(daemon, '\0', sizeof(daemon_x));
-                       LISTADD(mfx->daemon, daemon);
-                       ret = __ps_process_daemon(reader, daemon);
-               } else if (!strcmp(ASCII(node), "theme")) {
-                       theme_x *theme = malloc(sizeof(theme_x));
-                       if (theme == NULL) {
-                               DBG("Malloc Failed\n");
+                       mfx->application = g_list_append(mfx->application, application);
+                       ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
+               } else if (!strcmp(ASCII(node), "widget-application")) {
+                       application_x *application = calloc(1, sizeof(application_x));
+                       if (application == NULL) {
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(theme, '\0', sizeof(theme_x));
-                       LISTADD(mfx->theme, theme);
-                       ret = __ps_process_theme(reader, theme);
-               } else if (!strcmp(ASCII(node), "font")) {
-                       font_x *font = malloc(sizeof(font_x));
-                       if (font == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(font, '\0', sizeof(font_x));
-                       LISTADD(mfx->font, font);
-                       ret = __ps_process_font(reader, font);
-               } else if (!strcmp(ASCII(node), "ime")) {
-                       ime_x *ime = malloc(sizeof(ime_x));
-                       if (ime == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(ime, '\0', sizeof(ime_x));
-                       LISTADD(mfx->ime, ime);
-                       ret = __ps_process_ime(reader, ime);
+                       mfx->application = g_list_append(mfx->application, application);
+                       ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
                } else if (!strcmp(ASCII(node), "icon")) {
-                       icon_x *icon = malloc(sizeof(icon_x));
+                       icon_x *icon = calloc(1, sizeof(icon_x));
                        if (icon == NULL) {
-                               DBG("Malloc Failed\n");
-                               return -1;
-                       }
-                       memset(icon, '\0', sizeof(icon_x));
-                       LISTADD(mfx->icon, icon);
-                       ret = __ps_process_icon(reader, icon);
-               } 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));
-                       LISTADD(mfx->deviceprofile, deviceprofile);
-                       ret = __ps_process_deviceprofile(reader, deviceprofile);
+                       mfx->icon = g_list_append(mfx->icon, icon);
+                       ret = __ps_process_icon(reader, icon, uid);
                } else if (!strcmp(ASCII(node), "compatibility")) {
-                       compatibility_x *compatibility = malloc(sizeof(compatibility_x));
+                       compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
                        if (compatibility == NULL) {
-                               DBG("Malloc Failed\n");
+                               _LOGD("Malloc Failed\n");
                                return -1;
                        }
-                       memset(compatibility, '\0', sizeof(compatibility_x));
-                       LISTADD(mfx->compatibility, compatibility);
+                       mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
                        ret = __ps_process_compatibility(reader, compatibility);
                } else if (!strcmp(ASCII(node), "shortcut-list")) {
                        continue;
@@ -3046,74 +1862,22 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                        continue;
                } else if (!strcmp(ASCII(node), "ime")) {
                        continue;
-               } else
-                       return -1;
+               } else if (!strcmp(ASCII(node), "feature")) {
+                       continue;
+               } else {
+                       _LOGI("Unknown element: %s", ASCII(node));
+                       continue;
+               }
 
                if (ret < 0) {
-                       DBG("Processing manifest failed\n");
+                       _LOGD("Processing manifest failed\n");
                        return ret;
                }
        }
-       if (mfx->label) {
-               LISTHEAD(mfx->label, tmp1);
-               mfx->label = tmp1;
-       }
-       if (mfx->author) {
-               LISTHEAD(mfx->author, tmp2);
-               mfx->author = tmp2;
-       }
-       if (mfx->description) {
-               LISTHEAD(mfx->description, tmp3);
-               mfx->description= tmp3;
-       }
-       if (mfx->license) {
-               LISTHEAD(mfx->license, tmp4);
-               mfx->license= tmp4;
-       }
-       if (mfx->uiapplication) {
-               LISTHEAD(mfx->uiapplication, tmp5);
-               mfx->uiapplication = tmp5;
-       }
-       if (mfx->serviceapplication) {
-               LISTHEAD(mfx->serviceapplication, tmp6);
-               mfx->serviceapplication = tmp6;
-       }
-       if (mfx->daemon) {
-               LISTHEAD(mfx->daemon, tmp7);
-               mfx->daemon= tmp7;
-       }
-       if (mfx->theme) {
-               LISTHEAD(mfx->theme, tmp8);
-               mfx->theme= tmp8;
-       }
-       if (mfx->font) {
-               LISTHEAD(mfx->font, tmp9);
-               mfx->font= tmp9;
-       }
-       if (mfx->ime) {
-               LISTHEAD(mfx->ime, tmp10);
-               mfx->ime= tmp10;
-       }
-       if (mfx->icon) {
-               LISTHEAD(mfx->icon, tmp11);
-               mfx->icon= tmp11;
-       }
-       if (mfx->compatibility) {
-               LISTHEAD(mfx->compatibility, tmp12);
-               mfx->compatibility= tmp12;
-       }
-       if (mfx->deviceprofile) {
-               LISTHEAD(mfx->deviceprofile, tmp13);
-               mfx->deviceprofile= tmp13;
-       }
-       if (mfx->privileges) {
-               LISTHEAD(mfx->privileges, tmp14);
-               mfx->privileges = tmp14;
-       }
        return ret;
 }
 
-static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
+static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
 {
        const xmlChar *node;
        int ret = -1;
@@ -3121,134 +1885,70 @@ 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;
                }
 
                if (!strcmp(ASCII(node), "manifest")) {
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")))
-                               mfx->ns = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")));
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("package"))) {
-                               mfx->package= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("package")));
-                               if (mfx->package == NULL) {
-                                       DBG("package cant be NULL\n");
-                                       return -1;
-                               }
-                       } else {
-                               DBG("package field is mandatory\n");
-                               return -1;
-                       }
-                       package = mfx->package;
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("version")))
-                               mfx->version= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("version")));
-                       /*app2ext needs package size for external installation*/
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("size")))
-                               mfx->package_size = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("size")));
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("install-location")))
-                               mfx->installlocation = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("install-location")));
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
-                               mfx->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("root_path")))
-                               mfx->root_path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("root_path")));
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting"))) {
-                               mfx->appsetting = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting")));
-                               if (mfx->appsetting == NULL)
-                                       mfx->appsetting = strdup("false");
-                       } else {
-                               mfx->appsetting = strdup("false");
-                       }
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")))
-                               mfx->storeclient_id= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")));
-
+                       __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
+                       __save_xml_attribute(reader, "package", &mfx->package, NULL);
+                       retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
+                       __save_xml_attribute(reader, "version", &mfx->version, NULL);
+                       __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
+                       __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
+                       __save_xml_attribute(reader, "type", &mfx->type, "rpm");
+                       __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
+                       __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
+                       __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
+                       __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
+                       __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
+                       __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
+                       __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
+                       __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
+
+                       __save_xml_installed_time(mfx);
+                       __save_xml_root_path(mfx, uid);
                        /*Assign default values. If required it will be overwritten in __add_preload_info()*/
-                       mfx->preload = strdup("False");
-                       mfx->removable = strdup("True");
-                       mfx->readonly = strdup("False");
-                       char buf[PKG_STRING_LEN_MAX] = {'\0'};
-                       char *val = NULL;
-                       time_t current_time;
-                       time(&current_time);
-                       snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", current_time);
-                       val = strndup(buf, PKG_STRING_LEN_MAX - 1);
-                       mfx->installed_time = val;
-
-                       mfx->installed_storage= strdup("installed_internal");
-
-                       ret = __start_process(reader, mfx);
+                       __save_xml_default_value(mfx);
+
+                       ret = __start_process(reader, mfx, uid);
                } else {
-                       DBG("No Manifest element found\n");
+                       _LOGD("No Manifest element found\n");
                        return -1;
                }
        }
        return ret;
 }
 
-#define DESKTOP_RW_PATH "/opt/share/applications/"
-#define DESKTOP_RO_PATH "/usr/share/applications/"
-
-static char* __convert_to_system_locale(const char *mlocale)
-{
-       if (mlocale == NULL)
-               return NULL;
-       char *locale = NULL;
-       locale = (char *)calloc(1, 6);
-       if (!locale) {
-               DBGE("Malloc Failed\n");
-               return NULL;
-       }
-
-       strncpy(locale, mlocale, 2);
-       strncat(locale, "_", 1);
-       locale[3] = toupper(mlocale[3]);
-       locale[4] = toupper(mlocale[4]);
-       return locale;
-}
-
-#define LIBAIL_PATH "/usr/lib/libail.so.0"
-
-/* operation_type */
-typedef enum {
-       AIL_INSTALL = 0,
-       AIL_UPDATE,
-       AIL_REMOVE,
-       AIL_MAX
-} AIL_TYPE;
+#define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
 
-static int __ail_change_info(int op, const char *appid)
+static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
 {
        void *lib_handle = NULL;
-       int (*ail_desktop_operation) (const char *);
-       char *aop = NULL;
+       int (*appsvc_operation) (const char *, uid_t);
        int ret = 0;
+       GList *tmp;
+       application_x *application;
 
-       if ((lib_handle = dlopen(LIBAIL_PATH, RTLD_LAZY)) == NULL) {
-               DBGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAIL_PATH);
+       if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
+               _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
                goto END;
        }
 
-
-       switch (op) {
-               case 0:
-                       aop  = "ail_desktop_add";
-                       break;
-               case 1:
-                       aop  = "ail_desktop_update";
-                       break;
-               case 2:
-                       aop  = "ail_desktop_remove";
-                       break;
-               default:
-                       goto END;
-                       break;
-       }
-
-       if ((ail_desktop_operation =
-            dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol \n");
+       if ((appsvc_operation =
+                dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
+               _LOGE("can not find symbol \n");
                goto END;
        }
 
-       ret = ail_desktop_operation(appid);
+       for (tmp = mfx->application; tmp; tmp = tmp->next) {
+               application = (application_x *)tmp->data;
+               if (application == NULL)
+                       continue;
+               ret = appsvc_operation(application->appid, uid);
+               if (ret <0)
+                       _LOGE("can not operation  symbol \n");
+       }
 
 END:
        if (lib_handle)
@@ -3257,842 +1957,590 @@ END:
        return ret;
 }
 
-
-/* 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, bool is_update)
+static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
 {
-        FILE* file = NULL;
-        int fd = 0;
-        char filepath[PKG_STRING_LEN_MAX] = "";
-        char *buf = NULL;
-       char *buftemp = NULL;
-       char *locale = NULL;
-
-       buf = (char *)calloc(1, BUFMAX);
-       if (!buf) {
-               DBGE("Malloc Failed\n");
-               return -1;
+       if (!strstr(manifest, getUserManifestPath(uid))) {
+               /* if downloaded app is updated, then update tag set true*/
+               if (mfx->update)
+                       free((void *)mfx->update);
+               mfx->update = strdup("true");
        }
 
-       buftemp = (char *)calloc(1, BUFMAX);
-       if (!buftemp) {
-               DBGE("Malloc Failed\n");
-               free(buf);
-               return -1;
-       }
+       return 0;
+}
+
+API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
+{
+       /* desktop file is no longer used */
+        return 0;
+}
+
+API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
+{
+       /* desktop file is no longer used */
+        return 0;
+}
 
-       for(; mfx->uiapplication; mfx->uiapplication=mfx->uiapplication->next) {
 
-               if(mfx->readonly && !strcasecmp(mfx->readonly, "True"))
-                       snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RO_PATH, mfx->uiapplication->appid);
-               else
-                       snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, mfx->uiapplication->appid);
+API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
+{
+       pkgmgrinfo_basic_free_package((package_x *)mfx);
+}
 
-               /* skip if desktop exists
-               if (access(filepath, R_OK) == 0)
-                       continue;
-               */
-
-               file = fopen(filepath, "w");
-               if(file == NULL)
-               {
-                   DBGE("Can't open %s", filepath);
-                   free(buf);
-                   free(buftemp);
-                   return -1;
-               }
-
-               snprintf(buf, BUFMAX, "[Desktop Entry]\n");
-               fwrite(buf, 1, strlen(buf), file);
-
-               for( ; mfx->uiapplication->label ; mfx->uiapplication->label = mfx->uiapplication->label->next) {
-                       if(!strcmp(mfx->uiapplication->label->lang, DEFAULT_LOCALE)) {
-                               snprintf(buf, BUFMAX, "Name=%s\n",      mfx->uiapplication->label->text);
-                       } else {
-                               locale = __convert_to_system_locale(mfx->uiapplication->label->lang);
-                               snprintf(buf, BUFMAX, "Name[%s]=%s\n", locale,
-                                       mfx->uiapplication->label->text);
-                               free(locale);
-                       }
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
+{
+       _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
+       xmlTextReaderPtr reader;
+       manifest_x *mfx = NULL;
 
-               if(mfx->uiapplication->label && mfx->uiapplication->label->text) {
-                       snprintf(buf, BUFMAX, "Name=%s\n", mfx->uiapplication->label->text);
-                       fwrite(buf, 1, strlen(buf), file);
-               }
-/*
-               else if(mfx->label && mfx->label->text) {
-                       snprintf(buf, BUFMAX, "Name=%s\n", mfx->label->text);
-                       fwrite(buf, 1, strlen(buf), file);
+       reader = xmlReaderForFile(manifest, NULL, 0);
+       if (reader) {
+               mfx = malloc(sizeof(manifest_x));
+               if (mfx) {
+                       memset(mfx, '\0', sizeof(manifest_x));
+                       if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
+                               _LOGD("Parsing Failed\n");
+                               pkgmgr_parser_free_manifest_xml(mfx);
+                               mfx = NULL;
+                       } else
+                               _LOGD("Parsing Success\n");
                } else {
-                       snprintf(buf, BUFMAX, "Name=%s\n", mfx->package);
-                       fwrite(buf, 1, strlen(buf), file);
+                       _LOGD("Memory allocation error\n");
                }
-*/
+               xmlFreeTextReader(reader);
+       } else {
+               _LOGD("Unable to create xml reader\n");
+       }
+       return mfx;
+}
 
 
-               snprintf(buf, BUFMAX, "Type=Application\n");
-               fwrite(buf, 1, strlen(buf), file);
+API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
+{
+       _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
+       xmlTextReaderPtr reader;
+       manifest_x *mfx = NULL;
 
-               if(mfx->uiapplication->exec) {
-                       snprintf(buf, BUFMAX, "Exec=%s\n", mfx->uiapplication->exec);
-                       fwrite(buf, 1, strlen(buf), file);
+       reader = xmlReaderForFile(manifest, NULL, 0);
+       if (reader) {
+               mfx = malloc(sizeof(manifest_x));
+               if (mfx) {
+                       memset(mfx, '\0', sizeof(manifest_x));
+                       if (__process_manifest(reader, mfx, uid) < 0) {
+                               _LOGD("Parsing Failed\n");
+                               pkgmgr_parser_free_manifest_xml(mfx);
+                               mfx = NULL;
+                       } else
+                               _LOGD("Parsing Success\n");
+               } else {
+                       _LOGD("Memory allocation error\n");
                }
+               xmlFreeTextReader(reader);
+       } else {
+               _LOGD("Unable to create xml reader\n");
+       }
+       return mfx;
+}
 
-               if(mfx->uiapplication->icon && mfx->uiapplication->icon->text) {
-                       snprintf(buf, BUFMAX, "Icon=%s\n", mfx->uiapplication->icon->text);
-                       fwrite(buf, 1, strlen(buf), file);
-               } else if(mfx->icon && mfx->icon->text) {
-                       snprintf(buf, BUFMAX, "Icon=%s\n", mfx->icon->text);
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid)
+{
+       return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid);
+}
 
-               if(mfx->version) {
-                       snprintf(buf, BUFMAX, "Version=%s\n", mfx->version);
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path)
+{
+       return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path);
+}
 
-               if(mfx->uiapplication->nodisplay) {
-                       snprintf(buf, BUFMAX, "NoDisplay=%s\n", mfx->uiapplication->nodisplay);
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
+{
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("parsing manifest for installation: %s\n", manifest);
 
-               if(mfx->uiapplication->categories) {
-                       snprintf(buf, BUFMAX, "Categories=%s\n", mfx->uiapplication->categories);
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+       manifest_x *mfx = NULL;
+       int ret = -1;
 
-               if(mfx->uiapplication->taskmanage && !strcasecmp(mfx->uiapplication->taskmanage, "False")) {
-                       snprintf(buf, BUFMAX, "X-TIZEN-TaskManage=False\n");
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+       xmlInitParser();
+       mfx = pkgmgr_parser_process_manifest_xml(manifest);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
 
-               if(mfx->uiapplication->enabled && !strcasecmp(mfx->uiapplication->enabled, "False")) {
-                       snprintf(buf, BUFMAX, "X-TIZEN-Enabled=False\n");
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+       _LOGD("Parsing Finished\n");
 
-               if(mfx->uiapplication->hwacceleration) {
-                       snprintf(buf, BUFMAX, "Hw-Acceleration=%s\n", mfx->uiapplication->hwacceleration);
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+       __ps_process_tag(mfx, tagv);
 
-               if(mfx->uiapplication->multiple && !strcasecmp(mfx->uiapplication->multiple, "True")) {
-                       snprintf(buf, BUFMAX, "X-TIZEN-Multiple=True\n");
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+       ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
 
-               if(mfx->uiapplication->extraid) {
-                       snprintf(buf, BUFMAX, "X-TIZEN-PackageID=%s\n", mfx->uiapplication->extraid);
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+       _LOGD("DB Insert Success\n");
 
-               if(mfx->removable && !strcasecmp(mfx->removable, "False")) {
-                       snprintf(buf, BUFMAX, "X-TIZEN-Removable=False\n");
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+       __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
+       ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating metadata parser failed\n");
+
+       ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+
+       pkgmgr_parser_free_manifest_xml(mfx);
+       _LOGD("Free Done\n");
+       xmlCleanupParser();
+
+       return PMINFO_R_OK;
+}
+API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
+{
+       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;
+
+       xmlInitParser();
+       mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+
+       _LOGD("Parsing Finished\n");
 
-               if(mfx->type) {
-                       snprintf(buf, BUFMAX, "X-TIZEN-PackageType=%s\n", mfx->type);
-                       fwrite(buf, 1, strlen(buf), file);
-               }
+       __ps_process_tag(mfx, tagv);
 
-               snprintf(buf, BUFMAX, "X-TIZEN-PkgID=%s\n", mfx->package);
-               fwrite(buf, 1, strlen(buf), file);
-
-
-//             snprintf(buf, BUFMAX, "X-TIZEN-PackageType=rpm\n");
-//             fwrite(buf, 1, strlen(buf), file);
-
-
-               if(mfx->uiapplication->appsvc) {
-                       snprintf(buf, BUFMAX, "X-TIZEN-Svc=");
-                       DBG("buf[%s]\n", buf);
-
-
-                       uiapplication_x *up = mfx->uiapplication;
-                       appsvc_x *asvc = NULL;
-                       operation_x *op = NULL;
-                       mime_x *mi = NULL;
-                       uri_x *ui = NULL;
-                       subapp_x *sub = NULL;
-                       const char *operation = NULL;
-                       const char *mime = NULL;
-                       const char *uri = NULL;
-                       const char *subapp = NULL;
-                       int i = 0;
-
-
-                       asvc = up->appsvc;
-                       while(asvc != NULL) {
-                               op = asvc->operation;
-                               while(op != NULL) {
-                                       if (op)
-                                               operation = op->name;
-                                       mi = asvc->mime;
-
-                                       do
-                                       {
-                                               if (mi)
-                                                       mime = mi->name;
-                                               sub = asvc->subapp;
-                                               do
-                                               {
-                                                       if (sub)
-                                                               subapp = sub->name;
-                                                       ui = asvc->uri;
-                                                       do
-                                                       {
-                                                               if (ui)
-                                                                       uri = ui->name;
-
-                                                               if(i++ > 0) {
-                                                                       strncpy(buftemp, buf, BUFMAX);
-                                                                       snprintf(buf, BUFMAX, "%s;", buftemp);
-                                                               }
-
-
-                                                               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);
-
-                                                               if (ui)
-                                                                       ui = ui->next;
-                                                               uri = NULL;
-                                                       } while(ui != NULL);
-                                               if (sub)
-                                                               sub = sub->next;
-                                                       subapp = NULL;
-                                               }while(sub != NULL);
-                                               if (mi)
-                                                       mi = mi->next;
-                                               mime = NULL;
-                                       }while(mi != NULL);
-                                       if (op)
-                                               op = op->next;
-                                       operation = NULL;
-                               }
-                               asvc = asvc->next;
-                       }
+       ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
 
+       _LOGD("DB Insert Success\n");
 
-                       fwrite(buf, 1, strlen(buf), file);
+       __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
+       ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating metadata parser failed\n");
+       ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
 
-//                     strncpy(buftemp, buf, BUFMAX);
-//                     snprintf(buf, BUFMAX, "%s\n", buftemp);
-//                     fwrite(buf, 1, strlen(buf), file);
-               }
+       pkgmgr_parser_free_manifest_xml(mfx);
+       _LOGD("Free Done\n");
+       xmlCleanupParser();
 
-               if(mfx->uiapplication->appcontrol) {
-                       snprintf(buf, BUFMAX, "X-TIZEN-Svc=");
-                       DBG("buf[%s]\n", buf);
-
-                       uiapplication_x *up = mfx->uiapplication;
-                       appcontrol_x *acontrol = NULL;
-                       operation_x *op = NULL;
-                       mime_x *mi = NULL;
-                       uri_x *ui = NULL;
-                       subapp_x *sub = NULL;
-                       const char *operation = NULL;
-                       const char *mime = NULL;
-                       const char *uri = NULL;
-                       const char *subapp = NULL;
-                       int i = 0;
-
-                       acontrol = up->appcontrol;
-                       while(acontrol != NULL) {
-                               op = acontrol->operation;
-                               while(op != NULL) {
-                                       if (op)
-                                               operation = op->name;
-                                       mi = acontrol->mime;
-
-                                       do
-                                       {
-                                               if (mi)
-                                                       mime = mi->name;
-                                               sub = acontrol->subapp;
-                                               do
-                                               {
-                                                       if (sub)
-                                                               subapp = sub->name;
-                                                       ui = acontrol->uri;
-                                                       do
-                                                       {
-                                                               if (ui)
-                                                                       uri = ui->name;
-
-                                                               if(i++ > 0) {
-                                                                       strncpy(buftemp, buf, BUFMAX);
-                                                                       snprintf(buf, BUFMAX, "%s;", buftemp);
-                                                               }
-
-                                                               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);
-
-                                                               if (ui)
-                                                                       ui = ui->next;
-                                                               uri = NULL;
-                                                       } while(ui != NULL);
-                                               if (sub)
-                                                               sub = sub->next;
-                                                       subapp = NULL;
-                                               }while(sub != NULL);
-                                               if (mi)
-                                                       mi = mi->next;
-                                               mime = NULL;
-                                       }while(mi != NULL);
-                                       if (op)
-                                               op = op->next;
-                                       operation = NULL;
-                               }
-                               acontrol = acontrol->next;
-                       }
+       return PMINFO_R_OK;
+}
 
+API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest) {
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("processing manifest_x for installation: %s\n", manifest);
+       int ret = -1;
 
-                       fwrite(buf, 1, strlen(buf), file);
+       xmlInitParser();
 
-//                     strncpy(buftemp, buf, BUFMAX);
-//                     snprintf(buf, BUFMAX, "%s\n", buftemp);
-//                     fwrite(buf, 1, strlen(buf), file);
-               }
+       _LOGD("Added preload infomation\n");
 
-               fflush(file);
-               fd = fileno(file);
-               fsync(fd);
-               fclose(file);
+       ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
+       _LOGD("DB Insert Success\n");
 
-               if (!is_update)
-                       __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
-               else
-                       __ail_change_info(AIL_UPDATE, mfx->uiapplication->appid);
-       }
+       ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating metadata parser failed\n");
 
-       free(buf);
-       free(buftemp);
+       ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+       xmlCleanupParser();
 
-        return 0;
+       return PMINFO_R_OK;
 }
 
-static int __ps_remove_nativeapp_desktop(manifest_x *mfx)
-{
-       char filepath[PKG_STRING_LEN_MAX] = "";
-       int ret = 0;
-       uiapplication_x *uiapplication = mfx->uiapplication;
+API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid) {
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("processing manifest_x for installation: %s\n", manifest);
+       int ret = -1;
 
-       for(; uiapplication; uiapplication=uiapplication->next) {
-               snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
+       xmlInitParser();
+       ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
+       _LOGD("DB Insert Success\n");
 
-               __ail_change_info(AIL_REMOVE, uiapplication->appid);
+       ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating metadata parser failed\n");
+       ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+       xmlCleanupParser();
+       return PMINFO_R_OK;
+}
 
-               ret = remove(filepath);
-               if (ret <0)
-                       return -1;
-       }
+API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
+{
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("pkgmgr_parser_parse_manifest_for_upgrade  parsing manifest for upgradation: %s\n", manifest);
+       manifest_x *mfx = NULL;
+       int ret = -1;
+       bool preload = false;
+       bool system = false;
+       char *csc_path = NULL;
+       pkgmgrinfo_pkginfo_h handle = NULL;
 
-        return 0;
-}
+       xmlInitParser();
+       mfx = pkgmgr_parser_process_manifest_xml(manifest);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
 
-#define LIBAPPSVC_PATH "/usr/lib/libappsvc.so.0"
+       _LOGD("Parsing Finished\n");
+       __check_preload_updated(mfx, manifest, GLOBAL_USER);
 
-static int __ps_remove_appsvc_db(manifest_x *mfx)
-{
-       void *lib_handle = NULL;
-       int (*appsvc_operation) (const char *);
-       int ret = 0;
-       uiapplication_x *uiapplication = mfx->uiapplication;
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
+       ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
 
-       if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
-               DBGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAPPSVC_PATH);
-               goto END;
+       if (preload) {
+               free((void *)mfx->preload);
+               mfx->preload = strdup("true");
        }
 
-       if ((appsvc_operation =
-                dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol \n");
-               goto END;
+       ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
+       if (system) {
+               free((void *)mfx->system);
+               mfx->system = strdup("true");
        }
 
-       for(; uiapplication; uiapplication=uiapplication->next) {
-               ret = appsvc_operation(uiapplication->appid);
-               if (ret <0)
-                       DBGE("can not operation  symbol \n");
+       ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
+
+       if (csc_path != NULL) {
+               if (mfx->csc_path)
+                       free((void *)mfx->csc_path);
+               mfx->csc_path = strdup(csc_path);
        }
 
-END:
-       if (lib_handle)
-               dlclose(lib_handle);
+       ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
 
-       return ret;
+       _LOGD("DB Update Success\n");
+
+       __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
+       ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1){
+               _LOGD("Upgrade metadata parser failed\n");
+       }
+       ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       pkgmgr_parser_free_manifest_xml(mfx);
+       _LOGD("Free Done\n");
+       xmlCleanupParser();
+
+       return PMINFO_R_OK;
 }
 
-#define MANIFEST_RO_PREFIX "/usr/share/packages/"
-#define PRELOAD_PACKAGE_LIST "/usr/etc/package-manager/preload/preload_list.txt"
-static int __add_preload_info(manifest_x * mfx, const char *manifest)
+API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
 {
-       FILE *fp = NULL;
-       char buffer[1024] = { 0 };
-       int state = 0;
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
+       manifest_x *mfx = NULL;
+       int ret = -1;
+       bool preload = false;
+       bool system = false;
+       char *csc_path = NULL;
+       pkgmgrinfo_pkginfo_h handle = NULL;
 
-       if(strstr(manifest, MANIFEST_RO_PREFIX)) {
-               free((void *)mfx->readonly);
-               mfx->readonly = strdup("True");
+       xmlInitParser();
+       mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
 
-               free((void *)mfx->preload);
-               mfx->preload = strdup("True");
+       _LOGD("Parsing Finished\n");
+       __check_preload_updated(mfx, manifest, uid);
 
-               free((void *)mfx->removable);
-               mfx->removable = strdup("False");
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
+       ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
 
-               return 0;
+       if (preload) {
+               free((void *)mfx->preload);
+               mfx->preload = strdup("true");
        }
 
-       fp = fopen(PRELOAD_PACKAGE_LIST, "r");
-       if (fp == NULL) {
-               DBGE("no preload list\n");
-               return -1;
+       ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
+
+       if (system) {
+               free((void *)mfx->system);
+               mfx->system = strdup("true");
        }
 
-       while (fgets(buffer, sizeof(buffer), fp) != NULL) {
-               if (buffer[0] == '#') {
-                       if(strcasestr(buffer, "RW_NORM"))
-                               state = 2;
-                       else if(strcasestr(buffer, "RW_RM"))
-                               state = 3;
-                       else
-                               continue;
-               }
+       ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
+       if (csc_path != NULL) {
+               if (mfx->csc_path)
+                       free((void *)mfx->csc_path);
+               mfx->csc_path = strdup(csc_path);
+       }
 
-               __str_trim(buffer);
+       ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
+       _LOGD("DB Update Success\n");
 
-               if(!strcmp(mfx->package, buffer)) {
-                       free((void *)mfx->preload);
-                       mfx->preload = strdup("True");
-                       if(state == 2){
-                               free((void *)mfx->readonly);
-                               mfx->readonly = strdup("False");
-                               free((void *)mfx->removable);
-                               mfx->removable = strdup("False");
-                       } else if(state == 3){
-                               free((void *)mfx->readonly);
-                               mfx->readonly = strdup("False");
-                               free((void *)mfx->removable);
-                               mfx->removable = strdup("True");
-                       }
-               }
+       __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
+       ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1)
+               _LOGD("Upgrade metadata parser failed\n");
+       ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       pkgmgr_parser_free_manifest_xml(mfx);
+       _LOGD("Free Done\n");
+       xmlCleanupParser();
 
-               memset(buffer, 0x00, sizeof(buffer));
-       }
+       return PMINFO_R_OK;
+}
 
-       if (fp != NULL)
-               fclose(fp);
+API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest) {
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("pkgmgr_parser_process_manifest_x_for_upgrade  parsing manifest for upgradation: %s\n", manifest);
+       int ret = -1;
+       bool system = false;
+       char *csc_path = NULL;
+       pkgmgrinfo_pkginfo_h handle = NULL;
 
-       return 0;
-}
+       xmlInitParser();
 
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
 
-API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
-{
-       if (mfx == NULL)
-               return;
-       if (mfx->ns) {
-               free((void *)mfx->ns);
-               mfx->ns = NULL;
-       }
-       if (mfx->package) {
-               free((void *)mfx->package);
-               mfx->package = NULL;
-       }
-       if (mfx->version) {
-               free((void *)mfx->version);
-               mfx->version = NULL;
-       }
-       if (mfx->installlocation) {
-               free((void *)mfx->installlocation);
-               mfx->installlocation = NULL;
-       }
-       if (mfx->preload) {
-               free((void *)mfx->preload);
-               mfx->preload = NULL;
-       }
-       if (mfx->readonly) {
-               free((void *)mfx->readonly);
-               mfx->readonly = NULL;
-       }
-       if (mfx->removable) {
-               free((void *)mfx->removable);
-               mfx->removable = NULL;
-       }
-       if (mfx->update) {
-               free((void *)mfx->update);
-               mfx->update = NULL;
-       }
-       if (mfx->type) {
-               free((void *)mfx->type);
-               mfx->type = NULL;
-       }
-       if (mfx->package_size) {
-               free((void *)mfx->package_size);
-               mfx->package_size = NULL;
-       }
-       if (mfx->installed_time) {
-               free((void *)mfx->installed_time);
-               mfx->installed_time = NULL;
-       }
-       if (mfx->installed_storage) {
-               free((void *)mfx->installed_storage);
-               mfx->installed_storage = NULL;
-       }
-       if (mfx->storeclient_id) {
-               free((void *)mfx->storeclient_id);
-               mfx->storeclient_id = NULL;
-       }
-       if (mfx->mainapp_id) {
-               free((void *)mfx->mainapp_id);
-               mfx->mainapp_id = NULL;
-       }
-       if (mfx->package_url) {
-               free((void *)mfx->package_url);
-               mfx->package_url = NULL;
-       }
-       if (mfx->root_path) {
-               free((void *)mfx->root_path);
-               mfx->root_path = NULL;
-       }
-       if (mfx->appsetting) {
-               free((void *)mfx->appsetting);
-               mfx->appsetting = NULL;
+       ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
+       if (system) {
+               free((void *)mfx->system);
+               mfx->system = strdup("true");
        }
 
-       /*Free Icon*/
-       if (mfx->icon) {
-               icon_x *icon = mfx->icon;
-               icon_x *tmp = NULL;
-               while(icon != NULL) {
-                       tmp = icon->next;
-                       __ps_free_icon(icon);
-                       icon = tmp;
-               }
-       }
-       /*Free Label*/
-       if (mfx->label) {
-               label_x *label = mfx->label;
-               label_x *tmp = NULL;
-               while(label != NULL) {
-                       tmp = label->next;
-                       __ps_free_label(label);
-                       label = tmp;
-               }
-       }
-       /*Free Author*/
-       if (mfx->author) {
-               author_x *author = mfx->author;
-               author_x *tmp = NULL;
-               while(author != NULL) {
-                       tmp = author->next;
-                       __ps_free_author(author);
-                       author = tmp;
-               }
-       }
-       /*Free Description*/
-       if (mfx->description) {
-               description_x *description = mfx->description;
-               description_x *tmp = NULL;
-               while(description != NULL) {
-                       tmp = description->next;
-                       __ps_free_description(description);
-                       description = tmp;
-               }
-       }
-       /*Free License*/
-       if (mfx->license) {
-               license_x *license = mfx->license;
-               license_x *tmp = NULL;
-               while(license != NULL) {
-                       tmp = license->next;
-                       __ps_free_license(license);
-                       license = tmp;
-               }
-       }
-       /*Free Privileges*/
-       if (mfx->privileges) {
-               privileges_x *privileges = mfx->privileges;
-               privileges_x *tmp = NULL;
-               while(privileges != NULL) {
-                       tmp = privileges->next;
-                       __ps_free_privileges(privileges);
-                       privileges = tmp;
-               }
-       }
-       /*Free UiApplication*/
-       if (mfx->uiapplication) {
-               uiapplication_x *uiapplication = mfx->uiapplication;
-               uiapplication_x *tmp = NULL;
-               while(uiapplication != NULL) {
-                       tmp = uiapplication->next;
-                       __ps_free_uiapplication(uiapplication);
-                       uiapplication = tmp;
-               }
-       }
-       /*Free ServiceApplication*/
-       if (mfx->serviceapplication) {
-               serviceapplication_x *serviceapplication = mfx->serviceapplication;
-               serviceapplication_x *tmp = NULL;
-               while(serviceapplication != NULL) {
-                       tmp = serviceapplication->next;
-                       __ps_free_serviceapplication(serviceapplication);
-                       serviceapplication = tmp;
-               }
-       }
-       /*Free Daemon*/
-       if (mfx->daemon) {
-               daemon_x *daemon = mfx->daemon;
-               daemon_x *tmp = NULL;
-               while(daemon != NULL) {
-                       tmp = daemon->next;
-                       __ps_free_daemon(daemon);
-                       daemon = tmp;
-               }
-       }
-       /*Free Theme*/
-       if (mfx->theme) {
-               theme_x *theme = mfx->theme;
-               theme_x *tmp = NULL;
-               while(theme != NULL) {
-                       tmp = theme->next;
-                       __ps_free_theme(theme);
-                       theme = tmp;
-               }
-       }
-       /*Free Font*/
-       if (mfx->font) {
-               font_x *font = mfx->font;
-               font_x *tmp = NULL;
-               while(font != NULL) {
-                       tmp = font->next;
-                       __ps_free_font(font);
-                       font = tmp;
-               }
-       }
-       /*Free Ime*/
-       if (mfx->ime) {
-               ime_x *ime = mfx->ime;
-               ime_x *tmp = NULL;
-               while(ime != NULL) {
-                       tmp = ime->next;
-                       __ps_free_ime(ime);
-                       ime = tmp;
-               }
-       }
-       /*Free Compatibility*/
-       if (mfx->compatibility) {
-               compatibility_x *compatibility = mfx->compatibility;
-               compatibility_x *tmp = NULL;
-               while(compatibility != NULL) {
-                       tmp = compatibility->next;
-                       __ps_free_compatibility(compatibility);
-                       compatibility = tmp;
-               }
-       }
-       /*Free DeviceProfile*/
-       if (mfx->deviceprofile) {
-               deviceprofile_x *deviceprofile = mfx->deviceprofile;
-               deviceprofile_x *tmp = NULL;
-               while(deviceprofile != NULL) {
-                       tmp = deviceprofile->next;
-                       __ps_free_deviceprofile(deviceprofile);
-                       deviceprofile = tmp;
-               }
+       ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
+
+       if (csc_path != NULL) {
+               if (mfx->csc_path)
+                       free((void *)mfx->csc_path);
+               mfx->csc_path = strdup(csc_path);
        }
-       free((void*)mfx);
-       mfx = NULL;
-       return;
-}
 
-API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
-{
-       DBG("parsing start\n");
-       xmlTextReaderPtr reader;
-       manifest_x *mfx = NULL;
+       ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
+       _LOGD("DB Update Success\n");
 
-       reader = xmlReaderForFile(manifest, NULL, 0);
-       if (reader) {
-               mfx = malloc(sizeof(manifest_x));
-               if (mfx) {
-                       memset(mfx, '\0', sizeof(manifest_x));
-                       if (__process_manifest(reader, mfx) < 0) {
-                               DBG("Parsing Failed\n");
-                               pkgmgr_parser_free_manifest_xml(mfx);
-                               mfx = NULL;
-                       } else
-                               DBG("Parsing Success\n");
-               } else {
-                       DBG("Memory allocation error\n");
-               }
-               xmlFreeTextReader(reader);
-       } else {
-               DBG("Unable to create xml reader\n");
+       ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1){
+               _LOGD("Upgrade metadata parser failed\n");
        }
-       return mfx;
+       ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       xmlCleanupParser();
+
+       return PMINFO_R_OK;
 }
 
-/* These APIs are intended to call parser directly */
+API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid) {
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD(" pkgmgr_parser_process_usr_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
+       int ret = -1;
+       pkgmgrinfo_pkginfo_h handle = NULL;
+
+       xmlInitParser();
+
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
 
-API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
+       ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
+       _LOGD("DB Update Success\n");
+
+       ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1)
+               _LOGD("Upgrade metadata parser failed\n");
+       ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       xmlCleanupParser();
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", NULL};
-       if (manifest == NULL) {
-               DBG("argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       DBG("parsing manifest for installation: %s\n", manifest);
+       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;
-       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;
-       
-       __streamFile(manifest, ACTION_INSTALL, temp, mfx->package);
-       __add_preload_info(mfx, manifest);
-       DBG("Added preload infomation\n");
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
 
-       snprintf(roxml_check, PKG_STRING_LEN_MAX, MANIFEST_RO_DIRECTORY "/%s.xml", mfx->package);
-       if (access(roxml_check, F_OK) == 0)
-               mfx->update = strdup("true");
-       else
-               mfx->update = strdup("false");
+       _LOGD("Parsing Finished\n");
 
-       ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
+       __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
+
+       ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
        if (ret == -1)
-               DBG("DB Insert failed\n");
-       else
-               DBG("DB Insert Success\n");
+               _LOGD("Removing metadata parser failed\n");
 
-       ret = __ps_make_nativeapp_desktop(mfx, 0);
+       ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
        if (ret == -1)
-               DBG("Creating desktop file failed\n");
+               _LOGD("Creating category parser failed\n");
+
+       ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
+       if (ret == -1)
+               _LOGD("DB Delete failed\n");
        else
-               DBG("Creating desktop file Success\n");
+               _LOGD("DB Delete Success\n");
 
        pkgmgr_parser_free_manifest_xml(mfx);
-       DBG("Free Done\n");
+       _LOGD("Free Done\n");
        xmlCleanupParser();
 
        return PMINFO_R_OK;
 }
 
-API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
-{
-        int ret = 0;
-       if (mfx == NULL) {
-               DBG("Manifest pointer is NULL\n");
-               return -1;
-       }
-        ret = __ps_make_nativeapp_desktop(mfx, 0);
-        if (ret == -1)
-                DBG("Creating desktop file failed\n");
-        else
-                DBG("Creating desktop file Success\n");
-        return ret;
-}
-
 
-API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
+API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", NULL};
-       if (manifest == NULL) {
-               DBG("argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       DBG("parsing manifest for upgradation: %s\n", manifest);
+       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_UPGRADE, temp, mfx->package);
-       __add_preload_info(mfx, manifest);
-       DBG("Added preload infomation\n");
+       mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
 
-       mfx->update = strdup("true");
-       ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
+       _LOGD("Parsing Finished\n");
+
+       __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
+
+       ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
+       if (ret == -1)
+               _LOGD("Removing metadata parser failed\n");
+
+       ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+
+       ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
        if (ret == -1)
-               DBG("DB Update failed\n");
+               _LOGD("DB Delete failed\n");
        else
-               DBG("DB Update Success\n");
+               _LOGD("DB Delete Success\n");
 
-       ret = __ps_make_nativeapp_desktop(mfx, 1);
+       ret = __ps_remove_appsvc_db(mfx, uid);
        if (ret == -1)
-               DBG("Creating desktop file failed\n");
+               _LOGD("Removing appsvc_db failed\n");
        else
-               DBG("Creating desktop file 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;
 }
 
-API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
-{
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", NULL};
-       if (manifest == NULL) {
-               DBG("argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       DBG("parsing manifest for uninstallation: %s\n", manifest);
-       manifest_x *mfx = NULL;
+API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest) {
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
+
        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);
-       __add_preload_info(mfx, manifest);
-       DBG("Added preload infomation\n");
+
+       ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
+       if (ret == -1)
+               _LOGD("Removing metadata parser failed\n");
+
+       ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
+       if (ret == -1)
+               _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");
+       xmlCleanupParser();
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid) {
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
+
+       int ret = -1;
+       xmlInitParser();
 
-       ret = __ps_remove_nativeapp_desktop(mfx);
+       ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
        if (ret == -1)
-               DBG("Removing desktop file failed\n");
-       else
-               DBG("Removing desktop file Success\n");
+               _LOGD("Removing metadata parser failed\n");
+
+       ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
 
-       ret = __ps_remove_appsvc_db(mfx);
+       ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
        if (ret == -1)
-               DBG("Removing appsvc_db failed\n");
+               _LOGD("DB Delete failed\n");
        else
-               DBG("Removing appsvc_db Success\n");
+               _LOGD("DB Delete Success\n");
 
-       pkgmgr_parser_free_manifest_xml(mfx);
-       DBG("Free Done\n");
+       ret = __ps_remove_appsvc_db(mfx, uid);
+       if (ret == -1)
+               _LOGD("Removing appsvc_db failed\n");
+       else
+               _LOGD("Removing appsvc_db Success\n");
        xmlCleanupParser();
 
        return PMINFO_R_OK;
 }
 
+API int pkgmgr_parser_parse_manifest_for_preload()
+{
+       return pkgmgr_parser_update_preload_info_in_db();
+}
+
+API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
+{
+       return pkgmgr_parser_update_preload_info_in_usr_db(uid);
+}
+
+
+API char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid)
+{
+       return __pkgid_to_manifest(pkgid, uid);
+}
+
 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
 {
-       return __pkgid_to_manifest(pkgid);
+       return __pkgid_to_manifest(pkgid, GLOBAL_USER);
 }
 
 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
@@ -4110,12 +2558,12 @@ API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char
        return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
 }
 
-#define SCHEMA_FILE "/usr/etc/package-manager/preload/manifest.xsd"
+#define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
 #if 1
 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;
@@ -4124,29 +2572,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");
+               _LOGD("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;
@@ -4163,7 +2611,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 */
@@ -4178,7 +2626,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);
@@ -4192,7 +2640,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;
                }
        }