Sync to the latest code
[platform/core/appfw/pkgmgr-info.git] / parser / pkgmgr_parser.c
index a2e5835..7f875d0 100755 (executable)
  * limitations under the License.
  *
  */
-
+#define _GNU_SOURCE
 #include <dlfcn.h>
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <time.h>
+#include <string.h>
 #include <libxml/parser.h>
 #include <libxml/xmlreader.h>
 #include <libxml/xmlschemas.h>
 #include <vconf.h>
-
+#include <glib.h>
 
 #include "pkgmgr_parser.h"
 #include "pkgmgr_parser_internal.h"
 #define ASCII(s) (const char *)s
 #define XMLCHAR(s) (const xmlChar *)s
 
+#define MDPARSER_LIST "/usr/etc/package-manager/parserlib/metadata/mdparser_list.txt"
+#define MDPARSER_NAME  "mdparser:"
+
+#define CATEGORY_PARSER_LIST "/usr/etc/package-manager/parserlib/category/category_parser_list.txt"
+#define CATEGORY_PARSER_NAME   "categoryparser:"
+
+#define PKG_TAG_LEN_MAX 128
+
 /* operation_type */
 typedef enum {
        ACTION_INSTALL = 0,
@@ -48,9 +60,26 @@ typedef enum {
        ACTION_MAX
 } ACTION_TYPE;
 
-char *package;
+/* 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);
@@ -66,12 +95,9 @@ static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *
 static int __ps_process_resolution(xmlTextReaderPtr reader, resolution_x *resolution);
 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request);
 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
-static int __ps_process_registry(xmlTextReaderPtr reader, registry_x *registry);
-static int __ps_process_database(xmlTextReaderPtr reader, database_x *database);
 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc);
 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions);
 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
-static int __ps_process_layout(xmlTextReaderPtr reader, layout_x *layout);
 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon);
 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
@@ -86,6 +112,8 @@ 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);
@@ -101,12 +129,9 @@ 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_registry(registry_x *registry);
-static void __ps_free_database(database_x *database);
 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_layout(layout_x *layout);
 static void __ps_free_icon(icon_x *icon);
 static void __ps_free_author(author_x *author);
 static void __ps_free_description(description_x *description);
@@ -218,6 +243,112 @@ static int __validate_appid(const char *pkgid, const char *appid, char **newappi
        return 0;
 }
 
+static char * __get_tag_by_key(char *md_key)
+{
+       char *md_tag = NULL;
+
+       if (md_key == NULL) {
+               DBG("md_key is NULL\n");
+               return NULL;
+       }
+
+       md_tag = strrchr(md_key, 47) + 1;
+
+
+       return strdup(md_tag);
+}
+
+static char *__get_mdparser_plugin(const char *type)
+{
+       FILE *fp = NULL;
+       char buffer[1024] = { 0 };
+       char temp_path[1024] = { 0 };
+       char *path = NULL;
+
+       if (type == NULL) {
+               DBGE("invalid argument\n");
+               return NULL;
+       }
+
+       fp = fopen(PKG_PARSER_CONF_PATH, "r");
+       if (fp == NULL) {
+               DBGE("no matching mdparser\n");
+               return NULL;
+       }
+
+       while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+               if (buffer[0] == '#')
+                       continue;
+
+               __str_trim(buffer);
+
+               if ((path = strstr(buffer, MDPARSER_NAME)) != NULL) {
+                       path = path + strlen(MDPARSER_NAME);
+
+                       break;
+               }
+
+               memset(buffer, 0x00, 1024);
+       }
+
+       if (fp != NULL)
+               fclose(fp);
+
+       if (path == NULL) {
+               DBGE("no matching [%s] [%s]\n", MDPARSER_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) {
+               DBGE("invalid argument\n");
+               return NULL;
+       }
+
+       fp = fopen(PKG_PARSER_CONF_PATH, "r");
+       if (fp == NULL) {
+               DBGE("no matching mdparser\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) {
+               DBGE("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)
 {
@@ -244,10 +375,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;
                }
 
@@ -267,6 +395,114 @@ static char *__get_parser_plugin(const char *type)
        return strdup(temp_path);
 }
 
+static int __ps_run_mdparser(GList *md_list, const char *tag,
+                               ACTION_TYPE action, const char *pkgid, const char *appid)
+{
+       char *lib_path = NULL;
+       void *lib_handle = NULL;
+       int (*mdparser_plugin) (const char *, const char *, GList *);
+       int 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_mdparser_plugin(tag);
+       if (!lib_path) {
+               DBGE("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);
+               goto END;
+       }
+
+       if ((mdparser_plugin =
+               dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
+               DBGE("can not find symbol[%s] \n",ac);
+               goto END;
+       }
+
+       ret = mdparser_plugin(pkgid, appid, md_list);
+       if (ret < 0)
+               DBG("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
+       else
+               DBG("[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 __ps_run_category_parser(GList *category_list, const char *tag,
+                               ACTION_TYPE action, const char *pkgid, const char *appid)
+{
+       char *lib_path = NULL;
+       void *lib_handle = NULL;
+       int (*category_parser_plugin) (const char *, const char *, GList *);
+       int ret = -1;
+       char *ac = 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;
+       }
+
+       lib_path = __get_category_parser_plugin(tag);
+       if (!lib_path) {
+               DBGE("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);
+               goto END;
+       }
+
+       if ((category_parser_plugin =
+               dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
+               DBGE("can not find symbol[%s] \n",ac);
+               goto END;
+       }
+
+       ret = category_parser_plugin(pkgid, appid, category_list);
+       if (ret < 0)
+               DBG("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
+       else
+               DBG("[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 __ps_run_parser(xmlDocPtr docPtr, const char *tag,
                           ACTION_TYPE action, const char *pkgid)
 {
@@ -274,7 +510,7 @@ static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
        void *lib_handle = NULL;
        int (*plugin_install) (xmlDocPtr, const char *);
        int ret = -1;
-       char *ac;
+       char *ac = NULL;
 
        switch (action) {
        case ACTION_INSTALL:
@@ -299,16 +535,19 @@ static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
                DBGE("dlopen is failed lib_path[%s]\n", lib_path);
                goto END;
        }
-
        if ((plugin_install =
-            dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
-               DBGE("can not find symbol \n");
+               dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
+               DBGE("can not find symbol[%s] \n", ac);
                goto END;
        }
 
        ret = plugin_install(docPtr, pkgid);
+       if (ret < 0)
+               DBG("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
+       else
+               DBG("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
 
- END:
+END:
        if (lib_path)
                free(lib_path);
        if (lib_handle)
@@ -342,6 +581,200 @@ static char *__pkgid_to_manifest(const char *pkgid)
        return manifest;
 }
 
+static void __mdparser_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(detail->key);
+                               if (detail->value)
+                                       free(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(detail->name);
+
+                               free(detail);
+                       }
+                       list = g_list_next(list);
+               }
+               g_list_free(dir_list);
+       }
+}
+
+static int __run_mdparser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
+{
+       int ret = -1;
+       int tag_exist = 0;
+       char buffer[1024] = { 0, };
+       uiapplication_x *up = mfx->uiapplication;
+       metadata_x *md = NULL;
+       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) {
+               DBG("md_tag is NULL\n");
+               return -1;
+       }
+
+       while(up != NULL)
+       {
+               md = up->metadata;
+               while (md != NULL)
+               {
+                       //get glist of meatdata key and value combination
+                       memset(buffer, 0x00, 1024);
+                       snprintf(buffer, 1024, "%s/", md_key);
+                       if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
+                               md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
+                               if (md_detail == NULL) {
+                                       DBG("Memory allocation failed\n");
+                                       goto END;
+                               }
+
+                               md_detail->key = (char*) calloc(1, sizeof(char)*(strlen(md->key)+2));
+                               if (md_detail->key == NULL) {
+                                       DBG("Memory allocation failed\n");
+                                       free(md_detail);
+                                       goto END;
+                               }
+                               snprintf(md_detail->key, (strlen(md->key)+1), "%s", md->key);
+
+                               md_detail->value = (char*) calloc(1, sizeof(char)*(strlen(md->value)+2));
+                               if (md_detail->value == NULL) {
+                                       DBG("Memory allocation failed\n");
+                                       free(md_detail->key);
+                                       free(md_detail);
+                                       goto END;
+                               }
+                               snprintf(md_detail->value, (strlen(md->value)+1), "%s", md->value);
+
+                               md_list = g_list_append(md_list, (gpointer)md_detail);
+                               tag_exist = 1;
+                       }
+                       md = md->next;
+               }
+
+               //send glist to parser when tags for metadata plugin parser exist.
+               if (tag_exist) {
+                       ret = __ps_run_mdparser(md_list, md_tag, action, mfx->package, up->appid);
+                       if (ret < 0)
+                               DBG("mdparser failed[%d] for tag[%s]\n", ret, md_tag);
+                       else
+                               DBG("mdparser success for tag[%s]\n", md_tag);
+               }
+               __mdparser_clear_dir_list(md_list);
+               md_list = NULL;
+               tag_exist = 0;
+               up = up->next;
+       }
+
+       return 0;
+END:
+       __mdparser_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, };
+       uiapplication_x *up = mfx->uiapplication;
+       category_x *category = NULL;
+       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) {
+               DBG("md_tag is NULL\n");
+               return -1;
+       }
+
+       while(up != NULL)
+       {
+               category = up->category;
+               while (category != NULL)
+               {
+                       //get glist of meatdata key and value combination
+                       memset(buffer, 0x00, 1024);
+                       snprintf(buffer, 1024, "%s/", category_key);
+                       if ((category->name) && (strncmp(category->name, category_key, strlen(category_key)) == 0)) {
+                               category_detail = (__category_t*) calloc(1, sizeof(__category_t));
+                               if (category_detail == NULL) {
+                                       DBG("Memory allocation failed\n");
+                                       goto END;
+                               }
+
+                               category_detail->name = (char*) calloc(1, sizeof(char)*(strlen(category->name)+2));
+                               if (category_detail->name == NULL) {
+                                       DBG("Memory allocation failed\n");
+                                       free(category_detail);
+                                       goto END;
+                               }
+                               snprintf(category_detail->name, (strlen(category->name)+1), "%s", category->name);
+
+                               category_list = g_list_append(category_list, (gpointer)category_detail);
+                               tag_exist = 1;
+                       }
+                       category = category->next;
+               }
+
+               //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, up->appid);
+                       if (ret < 0)
+                               DBG("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
+                       else
+                               DBG("category_parser success for tag[%s]\n", category_tag);
+               }
+               __category_parser_clear_dir_list(category_list);
+               category_list = NULL;
+               tag_exist = 0;
+               up = up->next;
+       }
+
+       return 0;
+END:
+       __category_parser_clear_dir_list(category_list);
+
+       if (category_tag)
+               free(category_tag);
+
+       return ret;
+}
+
 static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
 {
        int ret = -1;
@@ -404,9 +837,8 @@ static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, con
        if (temp == NULL)
                return -1;
        xmlNode *next_node = NULL;
-       while(cur_node != NULL)
-       {
-               if ( (strcmp(temp->name, cur_node->name) == 0) &&
+       while(cur_node != NULL) {
+               if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
                        (temp->line == cur_node->line) ) {
                        break;
                }
@@ -447,7 +879,7 @@ static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, con
        fclose(fp);
 #endif
 
-       ret = __ps_run_parser(copyDocPtr, name, action, pkgid);
+       ret = __ps_run_parser(copyDocPtr, ASCII(name), action, pkgid);
  END:
 
        return ret;
@@ -495,7 +927,7 @@ __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], c
                        else {
                                i = 0;
                                for (tag = tagv[0]; tag; tag = tagv[++i])
-                                       if (strcmp(tag, elementName) == 0) {
+                                       if (strcmp(tag, ASCII(elementName)) == 0) {
                                                DBG("__run_parser_prestep tag[%s] pkgid[%s]\n", tag, pkgid);
                                                __run_parser_prestep(reader,
                                                                     action, pkgid);
@@ -529,12 +961,152 @@ __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], c
        }
 }
 
+static void __plugin_send_tag(const char *tag, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
+{
+       char *lib_path = NULL;
+       void *lib_handle = NULL;
+       int (*plugin_install) (const char *);
+       int ret = -1;
+       char *ac = NULL;
+
+       if (process == PLUGIN_PRE_PROCESS) {
+               switch (action) {
+               case ACTION_INSTALL:
+                       ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
+                       break;
+               case ACTION_UPGRADE:
+                       ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
+                       break;
+               case ACTION_UNINSTALL:
+                       ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
+                       break;
+               default:
+                       goto END;
+               }
+       } 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:
+                       goto END;
+               }
+       } else
+               goto END;
+
+       lib_path = __get_parser_plugin(tag);
+       if (!lib_path) {
+               goto END;
+       }
+
+       if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
+               DBGE("dlopen is failed lib_path[%s] for tag[%s]\n", lib_path, tag);
+               goto END;
+       }
+       if ((plugin_install =
+               dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
+               DBGE("can not find symbol[%s] for tag[%s] \n", ac, tag);
+               goto END;
+       }
+
+       ret = plugin_install(pkgid);
+       if (ret < 0)
+               DBG("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin fail\n", process, pkgid, tag);
+       else
+               DBG("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin success\n", process, pkgid, tag);
+
+END:
+       if (lib_path)
+               free(lib_path);
+       if (lib_handle)
+               dlclose(lib_handle);
+}
+
+static void
+__plugin_process_tag(char *const tag_list[], ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
+{
+       char *tag = NULL;
+       int i = 0;
+
+       for (tag = tag_list[0]; tag; tag = tag_list[++i])
+               __plugin_send_tag(tag, action, process, pkgid);
+
+}
+
+static void
+__plugin_save_tag(xmlTextReaderPtr reader, char *const tagv[], char *tag_list[])
+{
+       char *tag = NULL;
+       int i = 0;
+       static int pre_cnt=0;
+
+       switch (xmlTextReaderNodeType(reader)) {
+       case XML_READER_TYPE_ELEMENT:
+               {
+                       const xmlChar *elementName = xmlTextReaderLocalName(reader);
+                       if (elementName == NULL) {
+                               break;
+                       }
+                       i = 0;
+                       for (tag = tag_list[0]; tag; tag = tag_list[++i])
+                               if (strcmp(ASCII(elementName), tag) == 0) {
+                                       return;
+                               }
+                       i = 0;
+                       for (tag = tagv[0]; tag; tag = tagv[++i])
+                               if (strcmp(tag, ASCII(elementName)) == 0) {
+                                       tag_list[pre_cnt++] = tag;
+                                       break;
+                               }
+                       break;
+               }
+       default:
+//             DBG("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
+               break;
+       }
+}
+
+static void
+__plugin_find_tag(const char *filename, char *const tagv[], char *tag_list[])
+{
+       xmlTextReaderPtr reader;
+       xmlDocPtr docPtr;
+       int ret;
+
+       docPtr = xmlReadFile(filename, NULL, 0);
+       reader = xmlReaderWalker(docPtr);
+       if (reader != NULL) {
+               ret = xmlTextReaderRead(reader);
+               while (ret == 1) {
+                       __plugin_save_tag(reader, tagv, tag_list);
+                       ret = xmlTextReaderRead(reader);
+               }
+               xmlFreeTextReader(reader);
+
+               if (ret != 0) {
+                       DBG("xmlReaderWalker fail");
+               }
+       } else {
+               DBG("xmlReaderWalker fail");
+       }
+}
+
 static void
 __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid)
 {
        xmlTextReaderPtr reader;
        xmlDocPtr docPtr;
        int ret;
+       char *tag_list[PKG_TAG_LEN_MAX] = {'\0'};
+
+       __plugin_find_tag(filename, tagv, tag_list);
+       __plugin_process_tag(tag_list, action, PLUGIN_PRE_PROCESS, pkgid);
 
        docPtr = xmlReadFile(filename, NULL, 0);
        reader = xmlReaderWalker(docPtr);
@@ -552,6 +1124,8 @@ __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const
        } else {
                DBGE("Unable to open %s", filename);
        }
+
+       __plugin_process_tag(tag_list, action, PLUGIN_POST_PROCESS, pkgid);
 }
 
 static int __next_child_element(xmlTextReaderPtr reader, int depth)
@@ -597,13 +1171,43 @@ static void __ps_free_category(category_x *category)
        category = NULL;
 }
 
+static void __ps_free_privilege(privilege_x *privilege)
+{
+       if (privilege == NULL)
+               return;
+       if (privilege->text) {
+               free((void *)privilege->text);
+               privilege->text = NULL;
+       }
+       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;
+               }
+       }
+       free((void*)privileges);
+       privileges = NULL;
+}
+
 static void __ps_free_metadata(metadata_x *metadata)
 {
        if (metadata == NULL)
                return;
-       if (metadata->name) {
-               free((void *)metadata->name);
-               metadata->name = NULL;
+       if (metadata->key) {
+               free((void *)metadata->key);
+               metadata->key = NULL;
        }
        if (metadata->value) {
                free((void *)metadata->value);
@@ -809,8 +1413,7 @@ static void __ps_free_capability(capability_x *capability)
        if (capability->resolution) {
                resolution_x *resolution = capability->resolution;
                resolution_x *tmp = NULL;
-               while(resolution != NULL)
-               {
+               while(resolution != NULL) {
                        tmp = resolution->next;
                        __ps_free_resolution(resolution);
                        resolution = tmp;
@@ -860,8 +1463,7 @@ static void __ps_free_datacontrol(datacontrol_x *datacontrol)
        if (datacontrol->capability) {
                capability_x *capability = datacontrol->capability;
                capability_x *tmp = NULL;
-               while(capability != NULL)
-               {
+               while(capability != NULL) {
                        tmp = capability->next;
                        __ps_free_capability(capability);
                        capability = tmp;
@@ -883,8 +1485,7 @@ static void __ps_free_launchconditions(launchconditions_x *launchconditions)
        if (launchconditions->condition) {
                condition_x *condition = launchconditions->condition;
                condition_x *tmp = NULL;
-               while(condition != NULL)
-               {
+               while(condition != NULL) {
                        tmp = condition->next;
                        __ps_free_condition(condition);
                        condition = tmp;
@@ -906,8 +1507,7 @@ static void __ps_free_appcontrol(appcontrol_x *appcontrol)
        if (appcontrol->operation) {
                operation_x *operation = appcontrol->operation;
                operation_x *tmp = NULL;
-               while(operation != NULL)
-               {
+               while(operation != NULL) {
                        tmp = operation->next;
                        __ps_free_operation(operation);
                        operation = tmp;
@@ -917,8 +1517,7 @@ static void __ps_free_appcontrol(appcontrol_x *appcontrol)
        if (appcontrol->uri) {
                uri_x *uri = appcontrol->uri;
                uri_x *tmp = NULL;
-               while(uri != NULL)
-               {
+               while(uri != NULL) {
                        tmp = uri->next;
                        __ps_free_uri(uri);
                        uri = tmp;
@@ -928,8 +1527,7 @@ static void __ps_free_appcontrol(appcontrol_x *appcontrol)
        if (appcontrol->mime) {
                mime_x *mime = appcontrol->mime;
                mime_x *tmp = NULL;
-               while(mime != NULL)
-               {
+               while(mime != NULL) {
                        tmp = mime->next;
                        __ps_free_mime(mime);
                        mime = tmp;
@@ -939,8 +1537,7 @@ static void __ps_free_appcontrol(appcontrol_x *appcontrol)
        if (appcontrol->subapp) {
                subapp_x *subapp = appcontrol->subapp;
                subapp_x *tmp = NULL;
-               while(subapp != NULL)
-               {
+               while(subapp != NULL) {
                        tmp = subapp->next;
                        __ps_free_subapp(subapp);
                        subapp = tmp;
@@ -962,8 +1559,7 @@ static void __ps_free_appsvc(appsvc_x *appsvc)
        if (appsvc->operation) {
                operation_x *operation = appsvc->operation;
                operation_x *tmp = NULL;
-               while(operation != NULL)
-               {
+               while(operation != NULL) {
                        tmp = operation->next;
                        __ps_free_operation(operation);
                        operation = tmp;
@@ -973,8 +1569,7 @@ static void __ps_free_appsvc(appsvc_x *appsvc)
        if (appsvc->uri) {
                uri_x *uri = appsvc->uri;
                uri_x *tmp = NULL;
-               while(uri != NULL)
-               {
+               while(uri != NULL) {
                        tmp = uri->next;
                        __ps_free_uri(uri);
                        uri = tmp;
@@ -984,8 +1579,7 @@ static void __ps_free_appsvc(appsvc_x *appsvc)
        if (appsvc->mime) {
                mime_x *mime = appsvc->mime;
                mime_x *tmp = NULL;
-               while(mime != NULL)
-               {
+               while(mime != NULL) {
                        tmp = mime->next;
                        __ps_free_mime(mime);
                        mime = tmp;
@@ -995,8 +1589,7 @@ static void __ps_free_appsvc(appsvc_x *appsvc)
        if (appsvc->subapp) {
                subapp_x *subapp = appsvc->subapp;
                subapp_x *tmp = NULL;
-               while(subapp != NULL)
-               {
+               while(subapp != NULL) {
                        tmp = subapp->next;
                        __ps_free_subapp(subapp);
                        subapp = tmp;
@@ -1023,8 +1616,7 @@ static void __ps_free_define(define_x *define)
        if (define->request) {
                request_x *request = define->request;
                request_x *tmp = NULL;
-               while(request != NULL)
-               {
+               while(request != NULL) {
                        tmp = request->next;
                        __ps_free_request(request);
                        request = tmp;
@@ -1034,8 +1626,7 @@ static void __ps_free_define(define_x *define)
        if (define->allowed) {
                allowed_x *allowed = define->allowed;
                allowed_x *tmp = NULL;
-               while(allowed != NULL)
-               {
+               while(allowed != NULL) {
                        tmp = allowed->next;
                        __ps_free_allowed(allowed);
                        allowed = tmp;
@@ -1045,38 +1636,6 @@ static void __ps_free_define(define_x *define)
        define = NULL;
 }
 
-static void __ps_free_registry(registry_x *registry)
-{
-       if (registry == NULL)
-               return;
-       if (registry->name) {
-               free((void *)registry->name);
-               registry->name = NULL;
-       }
-       if (registry->text) {
-               free((void *)registry->text);
-               registry->text = NULL;
-       }
-       free((void*)registry);
-       registry = NULL;
-}
-
-static void __ps_free_database(database_x *database)
-{
-       if (database == NULL)
-               return;
-       if (database->name) {
-               free((void *)database->name);
-               database->name = NULL;
-       }
-       if (database->text) {
-               free((void *)database->text);
-               database->text = NULL;
-       }
-       free((void*)database);
-       database = NULL;
-}
-
 static void __ps_free_datashare(datashare_x *datashare)
 {
        if (datashare == NULL)
@@ -1085,8 +1644,7 @@ static void __ps_free_datashare(datashare_x *datashare)
        if (datashare->define) {
                define_x *define =  datashare->define;
                define_x *tmp = NULL;
-               while(define != NULL)
-               {
+               while(define != NULL) {
                        tmp = define->next;
                        __ps_free_define(define);
                        define = tmp;
@@ -1096,8 +1654,7 @@ static void __ps_free_datashare(datashare_x *datashare)
        if (datashare->request) {
                request_x *request = datashare->request;
                request_x *tmp = NULL;
-               while(request != NULL)
-               {
+               while(request != NULL) {
                        tmp = request->next;
                        __ps_free_request(request);
                        request = tmp;
@@ -1107,22 +1664,6 @@ static void __ps_free_datashare(datashare_x *datashare)
        datashare = NULL;
 }
 
-static void __ps_free_layout(layout_x *layout)
-{
-       if (layout == NULL)
-               return;
-       if (layout->name) {
-               free((void *)layout->name);
-               layout->name = NULL;
-       }
-       if (layout->text) {
-               free((void *)layout->text);
-               layout->text = NULL;
-       }
-       free((void*)layout);
-       layout = NULL;
-}
-
 static void __ps_free_label(label_x *label)
 {
        if (label == NULL)
@@ -1247,6 +1788,10 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
                free((void *)uiapplication->hwacceleration);
                uiapplication->hwacceleration = NULL;
        }
+       if (uiapplication->screenreader) {
+               free((void *)uiapplication->screenreader);
+               uiapplication->screenreader = NULL;
+       }
        if (uiapplication->mainapp) {
                free((void *)uiapplication->mainapp);
                uiapplication->mainapp = NULL;
@@ -1255,12 +1800,19 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
                free((void *)uiapplication->recentimage);
                uiapplication->recentimage = NULL;
        }
+       if (uiapplication->package) {
+               free((void *)uiapplication->package);
+               uiapplication->package = NULL;
+       }
+       if (uiapplication->launchcondition) {
+               free((void *)uiapplication->launchcondition);
+               uiapplication->launchcondition = NULL;
+       }
        /*Free Label*/
        if (uiapplication->label) {
                label_x *label = uiapplication->label;
                label_x *tmp = NULL;
-               while(label != NULL)
-               {
+               while(label != NULL) {
                        tmp = label->next;
                        __ps_free_label(label);
                        label = tmp;
@@ -1270,8 +1822,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->icon) {
                icon_x *icon = uiapplication->icon;
                icon_x *tmp = NULL;
-               while(icon != NULL)
-               {
+               while(icon != NULL) {
                        tmp = icon->next;
                        __ps_free_icon(icon);
                        icon = tmp;
@@ -1281,8 +1832,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->image) {
                image_x *image = uiapplication->image;
                image_x *tmp = NULL;
-               while(image != NULL)
-               {
+               while(image != NULL) {
                        tmp = image->next;
                        __ps_free_image(image);
                        image = tmp;
@@ -1292,8 +1842,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->appcontrol) {
                appcontrol_x *appcontrol = uiapplication->appcontrol;
                appcontrol_x *tmp = NULL;
-               while(appcontrol != NULL)
-               {
+               while(appcontrol != NULL) {
                        tmp = appcontrol->next;
                        __ps_free_appcontrol(appcontrol);
                        appcontrol = tmp;
@@ -1303,8 +1852,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->launchconditions) {
                launchconditions_x *launchconditions = uiapplication->launchconditions;
                launchconditions_x *tmp = NULL;
-               while(launchconditions != NULL)
-               {
+               while(launchconditions != NULL) {
                        tmp = launchconditions->next;
                        __ps_free_launchconditions(launchconditions);
                        launchconditions = tmp;
@@ -1314,8 +1862,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->notification) {
                notification_x *notification = uiapplication->notification;
                notification_x *tmp = NULL;
-               while(notification != NULL)
-               {
+               while(notification != NULL) {
                        tmp = notification->next;
                        __ps_free_notification(notification);
                        notification = tmp;
@@ -1325,8 +1872,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->datashare) {
                datashare_x *datashare = uiapplication->datashare;
                datashare_x *tmp = NULL;
-               while(datashare != NULL)
-               {
+               while(datashare != NULL) {
                        tmp = datashare->next;
                        __ps_free_datashare(datashare);
                        datashare = tmp;
@@ -1336,8 +1882,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->appsvc) {
                appsvc_x *appsvc = uiapplication->appsvc;
                appsvc_x *tmp = NULL;
-               while(appsvc != NULL)
-               {
+               while(appsvc != NULL) {
                        tmp = appsvc->next;
                        __ps_free_appsvc(appsvc);
                        appsvc = tmp;
@@ -1347,8 +1892,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->category) {
                category_x *category = uiapplication->category;
                category_x *tmp = NULL;
-               while(category != NULL)
-               {
+               while(category != NULL) {
                        tmp = category->next;
                        __ps_free_category(category);
                        category = tmp;
@@ -1358,8 +1902,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->metadata) {
                metadata_x *metadata = uiapplication->metadata;
                metadata_x *tmp = NULL;
-               while(metadata != NULL)
-               {
+               while(metadata != NULL) {
                        tmp = metadata->next;
                        __ps_free_metadata(metadata);
                        metadata = tmp;
@@ -1369,8 +1912,7 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
        if (uiapplication->permission) {
                permission_x *permission = uiapplication->permission;
                permission_x *tmp = NULL;
-               while(permission != NULL)
-               {
+               while(permission != NULL) {
                        tmp = permission->next;
                        __ps_free_permission(permission);
                        permission = tmp;
@@ -1394,6 +1936,31 @@ static void __ps_free_uiapplication(uiapplication_x *uiapplication)
                free((void *)uiapplication->guestmode_visibility);
                uiapplication->guestmode_visibility = NULL;
        }
+       if (uiapplication->app_component) {
+               free((void *)uiapplication->app_component);
+               uiapplication->app_component = NULL;
+       }
+       if (uiapplication->permission_type) {
+               free((void *)uiapplication->permission_type);
+               uiapplication->permission_type = NULL;
+       }
+       if (uiapplication->component_type) {
+               free((void *)uiapplication->component_type);
+               uiapplication->component_type = NULL;
+       }
+       if (uiapplication->preload) {
+               free((void *)uiapplication->preload);
+               uiapplication->preload = NULL;
+       }
+       if (uiapplication->submode) {
+               free((void *)uiapplication->submode);
+               uiapplication->submode = NULL;
+       }
+       if (uiapplication->submode_mainid) {
+               free((void *)uiapplication->submode_mainid);
+               uiapplication->submode_mainid = NULL;
+       }
+
        free((void*)uiapplication);
        uiapplication = NULL;
 }
@@ -1422,12 +1989,23 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
                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;
+       }
+       if (serviceapplication->permission_type) {
+               free((void *)serviceapplication->permission_type);
+               serviceapplication->permission_type = NULL;
+       }
        /*Free Label*/
        if (serviceapplication->label) {
                label_x *label = serviceapplication->label;
                label_x *tmp = NULL;
-               while(label != NULL)
-               {
+               while(label != NULL) {
                        tmp = label->next;
                        __ps_free_label(label);
                        label = tmp;
@@ -1437,8 +2015,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->icon) {
                icon_x *icon = serviceapplication->icon;
                icon_x *tmp = NULL;
-               while(icon != NULL)
-               {
+               while(icon != NULL) {
                        tmp = icon->next;
                        __ps_free_icon(icon);
                        icon = tmp;
@@ -1448,8 +2025,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->appcontrol) {
                appcontrol_x *appcontrol = serviceapplication->appcontrol;
                appcontrol_x *tmp = NULL;
-               while(appcontrol != NULL)
-               {
+               while(appcontrol != NULL) {
                        tmp = appcontrol->next;
                        __ps_free_appcontrol(appcontrol);
                        appcontrol = tmp;
@@ -1459,8 +2035,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->datacontrol) {
                datacontrol_x *datacontrol = serviceapplication->datacontrol;
                datacontrol_x *tmp = NULL;
-               while(datacontrol != NULL)
-               {
+               while(datacontrol != NULL) {
                        tmp = datacontrol->next;
                        __ps_free_datacontrol(datacontrol);
                        datacontrol = tmp;
@@ -1470,8 +2045,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->launchconditions) {
                launchconditions_x *launchconditions = serviceapplication->launchconditions;
                launchconditions_x *tmp = NULL;
-               while(launchconditions != NULL)
-               {
+               while(launchconditions != NULL) {
                        tmp = launchconditions->next;
                        __ps_free_launchconditions(launchconditions);
                        launchconditions = tmp;
@@ -1481,8 +2055,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->notification) {
                notification_x *notification = serviceapplication->notification;
                notification_x *tmp = NULL;
-               while(notification != NULL)
-               {
+               while(notification != NULL) {
                        tmp = notification->next;
                        __ps_free_notification(notification);
                        notification = tmp;
@@ -1492,8 +2065,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->datashare) {
                datashare_x *datashare = serviceapplication->datashare;
                datashare_x *tmp = NULL;
-               while(datashare != NULL)
-               {
+               while(datashare != NULL) {
                        tmp = datashare->next;
                        __ps_free_datashare(datashare);
                        datashare = tmp;
@@ -1503,8 +2075,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->appsvc) {
                appsvc_x *appsvc = serviceapplication->appsvc;
                appsvc_x *tmp = NULL;
-               while(appsvc != NULL)
-               {
+               while(appsvc != NULL) {
                        tmp = appsvc->next;
                        __ps_free_appsvc(appsvc);
                        appsvc = tmp;
@@ -1514,8 +2085,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->category) {
                category_x *category = serviceapplication->category;
                category_x *tmp = NULL;
-               while(category != NULL)
-               {
+               while(category != NULL) {
                        tmp = category->next;
                        __ps_free_category(category);
                        category = tmp;
@@ -1525,8 +2095,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->metadata) {
                metadata_x *metadata = serviceapplication->metadata;
                metadata_x *tmp = NULL;
-               while(metadata != NULL)
-               {
+               while(metadata != NULL) {
                        tmp = metadata->next;
                        __ps_free_metadata(metadata);
                        metadata = tmp;
@@ -1536,8 +2105,7 @@ static void __ps_free_serviceapplication(serviceapplication_x *serviceapplicatio
        if (serviceapplication->permission) {
                permission_x *permission = serviceapplication->permission;
                permission_x *tmp = NULL;
-               while(permission != NULL)
-               {
+               while(permission != NULL) {
                        tmp = permission->next;
                        __ps_free_permission(permission);
                        permission = tmp;
@@ -1603,14 +2171,63 @@ static void __ps_free_ime(ime_x *ime)
                free((void *)ime->name);
                ime->name = NULL;
        }
-       if (ime->text) {
-               free((void *)ime->text);
-               ime->text = NULL;
+       if (ime->text) {
+               free((void *)ime->text);
+               ime->text = NULL;
+       }
+       free((void*)ime);
+       ime = NULL;
+}
+
+int __ps_process_mdparser(manifest_x *mfx, ACTION_TYPE action)
+{
+       int ret = -1;
+       FILE *fp = NULL;
+       char md_key[PKG_STRING_LEN_MAX] = { 0 };
+
+       fp = fopen(MDPARSER_LIST, "r");
+       if (fp == NULL) {
+               DBG("no preload list\n");
+               return -1;
+       }
+
+       while (fgets(md_key, sizeof(md_key), fp) != NULL) {
+               __str_trim(md_key);
+               ret = __run_mdparser_prestep(mfx, md_key, action);
+
+               memset(md_key, 0x00, sizeof(md_key));
+       }
+
+       if (fp != NULL)
+               fclose(fp);
+
+       return 0;
+}
+
+int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
+{
+       int ret = -1;
+       FILE *fp = NULL;
+       char category_key[PKG_STRING_LEN_MAX] = { 0 };
+
+       fp = fopen(CATEGORY_PARSER_LIST, "r");
+       if (fp == NULL) {
+               DBG("no category parser list\n");
+               return -1;
+       }
+
+       while (fgets(category_key, sizeof(category_key), fp) != NULL) {
+               __str_trim(category_key);
+               ret = __run_category_parser_prestep(mfx, category_key, action);
+
+               memset(category_key, 0x00, sizeof(category_key));
        }
-       free((void*)ime);
-       ime = NULL;
-}
 
+       if (fp != NULL)
+               fclose(fp);
+
+       return 0;
+}
 
 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed)
 {
@@ -1695,13 +2312,21 @@ static int __ps_process_category(xmlTextReaderPtr reader, category_x *category)
        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)
 {
-       /*name and value both should exist. If any one attribute is missing then dont parse*/
-       if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")) && xmlTextReaderGetAttribute(reader, XMLCHAR("value"))) {
-               metadata->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
+       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;
 }
 
@@ -1713,7 +2338,7 @@ static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permis
        xmlTextReaderRead(reader);
        if (xmlTextReaderValue(reader))
                permission->value = ASCII(xmlTextReaderValue(reader));
-
+       return 0;
 }
 
 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
@@ -1798,18 +2423,6 @@ static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
        return ret;
 }
 
-static int __ps_process_registry(xmlTextReaderPtr reader, registry_x *registry)
-{
-       /*TODO: once policy is set*/
-       return 0;
-}
-
-static int __ps_process_database(xmlTextReaderPtr reader, database_x *database)
-{
-       /*TODO: once policy is set*/
-       return 0;
-}
-
 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol)
 {
        const xmlChar *node;
@@ -1988,6 +2601,45 @@ static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
        return ret;
 }
 
+
+static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges)
+{
+       const xmlChar *node;
+       int ret = -1;
+       int depth = -1;
+       privilege_x *tmp1 = NULL;
+
+       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), "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);
+               } else
+                       return -1;
+               if (ret < 0) {
+                       DBG("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)
 {
        const xmlChar *node;
@@ -2082,14 +2734,8 @@ static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashar
        return ret;
 }
 
-static int __ps_process_layout(xmlTextReaderPtr reader, layout_x *layout)
-{
-       /*TODO: once policy is set*/
-       return 0;
-}
-
 static char*
-__get_icon_with_path(char* icon)
+__get_icon_with_path(const char* icon)
 {
        if (!icon)
                return NULL;
@@ -2142,6 +2788,8 @@ __get_icon_with_path(char* 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;
+                       snprintf(icon_with_path, len, "/usr/ug/res/images/%s/%s", package, icon);
+                       if (access(icon_with_path, R_OK) == 0) break;
                } while (0);
 
                free(theme);
@@ -2159,6 +2807,54 @@ __get_icon_with_path(char* icon)
        }
 }
 
+static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
+{
+       int i = 0;
+       char delims[] = "=";
+       char *ret_result = NULL;
+       char *tag = NULL;
+
+       if (tagv == NULL)
+               return;
+
+       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");
+                       }
+               /*check tag :  not matched*/
+               } else
+                       DBG("tag process [%s]is not defined\n", ret_result);
+
+               free(tag);
+
+               /*check next value*/
+               if (tagv[++i] != NULL)
+                       tag = strdup(tagv[i]);
+               else {
+                       DBG("tag process success...\n");
+                       return;
+               }
+       }
+}
 
 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon)
 {
@@ -2179,10 +2875,10 @@ static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon)
                icon->resolution = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("resolution")));
        xmlTextReaderRead(reader);
        if (xmlTextReaderValue(reader)) {
-               char *text  = ASCII(xmlTextReaderValue(reader));
+               const char *text  = ASCII(xmlTextReaderValue(reader));
                if(text) {
-                       icon->text = __get_icon_with_path(text);
-                       free(text);
+                       icon->text = (const char *)__get_icon_with_path(text);
+                       free((void *)text);
                }
        }
 
@@ -2246,8 +2942,15 @@ static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
                author->lang = strdup(DEFAULT_LOCALE);
        }
        xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
+       if (xmlTextReaderValue(reader)) {
+               const char *text  = ASCII(xmlTextReaderValue(reader));
+               if (*text == '\n') {
+                       author->text = NULL;
+                       free((void *)text);
+                       return 0;
+               }
                author->text = ASCII(xmlTextReaderValue(reader));
+       }
        return 0;
 }
 
@@ -2261,8 +2964,15 @@ static int __ps_process_description(xmlTextReaderPtr reader, description_x *desc
                description->lang = strdup(DEFAULT_LOCALE);
        }
        xmlTextReaderRead(reader);
-       if (xmlTextReaderValue(reader))
+       if (xmlTextReaderValue(reader)) {
+               const char *text  = ASCII(xmlTextReaderValue(reader));
+               if (*text == '\n') {
+                       description->text = NULL;
+                       free((void *)text);
+                       return 0;
+               }
                description->text = ASCII(xmlTextReaderValue(reader));
+       }
        return 0;
 }
 
@@ -2406,6 +3116,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                                free((void *)uiapplication->appid);
                        uiapplication->appid = newappid;
                }
+               uiapplication->package= strdup(package);
        }
        if (xmlTextReaderGetAttribute(reader, XMLCHAR("exec")))
                uiapplication->exec = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("exec")));
@@ -2450,6 +3161,13 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
        } else {
                uiapplication->hwacceleration = strdup("use-system-setting");
        }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("screen-reader"))) {
+               uiapplication->screenreader = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("screen-reader")));
+               if (uiapplication->screenreader == NULL)
+                       uiapplication->screenreader = strdup("use-system-setting");
+       } else {
+               uiapplication->screenreader = strdup("use-system-setting");
+       }
        if (xmlTextReaderGetAttribute(reader, XMLCHAR("recentimage")))
                uiapplication->recentimage = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("recentimage")));
        if (xmlTextReaderGetAttribute(reader, XMLCHAR("mainapp"))) {
@@ -2459,6 +3177,14 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
        } else {
                uiapplication->mainapp = strdup("false");
        }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("launchcondition"))) {
+               uiapplication->launchcondition = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("launchcondition")));
+               if (uiapplication->launchcondition == NULL)
+                       uiapplication->launchcondition = strdup("false");
+       } else {
+               uiapplication->launchcondition = strdup("false");
+       }
+
        if (xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay"))) {
                uiapplication->indicatordisplay = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay")));
                if (uiapplication->indicatordisplay == NULL)
@@ -2481,6 +3207,29 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
        } else {
                uiapplication->guestmode_visibility = strdup("true");
        }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type"))) {
+               uiapplication->permission_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type")));
+               if (uiapplication->permission_type == NULL)
+                       uiapplication->permission_type = strdup("normal");
+       } else {
+               uiapplication->permission_type = strdup("normal");
+       }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("component-type"))) {
+               uiapplication->component_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("component-type")));
+               if (uiapplication->component_type == NULL)
+                       uiapplication->component_type = strdup("uiapp");
+       } else {
+               uiapplication->component_type = strdup("uiapp");
+       }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("submode"))) {
+               uiapplication->submode = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("submode")));
+               if (uiapplication->submode == NULL)
+                       uiapplication->submode = strdup("false");
+       } else {
+               uiapplication->submode = strdup("false");
+       }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("submode-mainid")))
+               uiapplication->submode_mainid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("submode-mainid")));
 
        depth = xmlTextReaderDepth(reader);
        while ((ret = __next_child_element(reader, depth))) {
@@ -2702,6 +3451,13 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
        } else {
                serviceapplication->autorestart = strdup("false");
        }
+       if (xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type"))) {
+               serviceapplication->permission_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type")));
+               if (serviceapplication->permission_type == NULL)
+                       serviceapplication->permission_type = strdup("normal");
+       } else {
+               serviceapplication->permission_type = strdup("normal");
+       }
 
        depth = xmlTextReaderDepth(reader);
        while ((ret = __next_child_element(reader, depth))) {
@@ -2915,6 +3671,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
        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))) {
@@ -2960,6 +3717,15 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                        memset(license, '\0', sizeof(license_x));
                        LISTADD(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);
                } else if (!strcmp(ASCII(node), "ui-application")) {
                        uiapplication_x *uiapplication = malloc(sizeof(uiapplication_x));
                        if (uiapplication == NULL) {
@@ -3049,6 +3815,8 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                        continue;
                } else if (!strcmp(ASCII(node), "notifications")) {
                        continue;
+               } else if (!strcmp(ASCII(node), "ime")) {
+                       continue;
                } else
                        return -1;
 
@@ -3109,7 +3877,10 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                LISTHEAD(mfx->deviceprofile, tmp13);
                mfx->deviceprofile= tmp13;
        }
-
+       if (mfx->privileges) {
+               LISTHEAD(mfx->privileges, tmp14);
+               mfx->privileges = tmp14;
+       }
        return ret;
 }
 
@@ -3150,6 +3921,8 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
                                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("csc_path")))
+                               mfx->csc_path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("csc_path")));
                        if (xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting"))) {
                                mfx->appsetting = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting")));
                                if (mfx->appsetting == NULL)
@@ -3157,11 +3930,24 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
                        } else {
                                mfx->appsetting = strdup("false");
                        }
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")))
+                               mfx->storeclient_id= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")));
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay-setting"))) {
+                               mfx->nodisplay_setting = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay-setting")));
+                               if (mfx->nodisplay_setting == NULL)
+                                       mfx->nodisplay_setting = strdup("false");
+                       } else {
+                               mfx->nodisplay_setting = strdup("false");
+                       }
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("url")))
+                               mfx->package_url= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("url")));
 
                        /*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");
+                       mfx->update = strdup("False");
+                       mfx->system = strdup("False");
                        char buf[PKG_STRING_LEN_MAX] = {'\0'};
                        char *val = NULL;
                        time_t current_time;
@@ -3183,6 +3969,7 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
 
 #define DESKTOP_RW_PATH "/opt/share/applications/"
 #define DESKTOP_RO_PATH "/usr/share/applications/"
+#define MANIFEST_RO_PREFIX "/usr/share/packages/"
 
 static char* __convert_to_system_locale(const char *mlocale)
 {
@@ -3209,6 +3996,7 @@ typedef enum {
        AIL_INSTALL = 0,
        AIL_UPDATE,
        AIL_REMOVE,
+       AIL_CLEAN,
        AIL_MAX
 } AIL_TYPE;
 
@@ -3235,6 +4023,9 @@ static int __ail_change_info(int op, const char *appid)
                case 2:
                        aop  = "ail_desktop_remove";
                        break;
+               case 3:
+                       aop  = "ail_desktop_clean";
+                       break;
                default:
                        goto END;
                        break;
@@ -3259,7 +4050,7 @@ END:
 /* desktop shoud be generated automatically based on manifest */
 /* Currently removable, taskmanage, etc fields are not considerd. it will be decided soon.*/
 #define BUFMAX 1024*128
-static int __ps_make_nativeapp_desktop(manifest_x * mfx, bool is_update)
+static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, bool is_update)
 {
         FILE* file = NULL;
         int fd = 0;
@@ -3281,10 +4072,22 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, bool is_update)
                return -1;
        }
 
+       if (is_update)
+               __ail_change_info(AIL_CLEAN, mfx->package);
+
        for(; mfx->uiapplication; mfx->uiapplication=mfx->uiapplication->next) {
 
+               if (manifest != NULL) {
+                       /* skip making a deskfile and update ail, if preload app is updated */
+                       if(strstr(manifest, MANIFEST_RO_PREFIX)) {
+                               __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
+                   DBGE("preload app is update : skip and update ail : %s", manifest);
+                               continue;
+                       }
+               }
+
                if(mfx->readonly && !strcasecmp(mfx->readonly, "True"))
-                       snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RO_PATH, mfx->uiapplication->appid);
+                       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);
 
@@ -3348,6 +4151,37 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, bool is_update)
                        fwrite(buf, 1, strlen(buf), file);
                }
 
+               // MIME types
+               if(mfx->uiapplication && mfx->uiapplication->appsvc) {
+                       appsvc_x *asvc = mfx->uiapplication->appsvc;
+                       mime_x *mi = NULL;
+                       const char *mime = NULL;
+                       const char *mime_delim = "; ";
+                       int mime_count = 0;
+
+                       strncpy(buf, "MimeType=", BUFMAX-1);
+                       while (asvc) {
+                               mi = asvc->mime;
+                               while (mi) {
+                                       mime_count++;
+                                       mime = mi->name;
+                                       DBG("MIME type: %s\n", mime);
+                                       strncat(buf, mime, BUFMAX-strlen(buf)-1);
+                                       if(mi->next) {
+                                               strncat(buf, mime_delim, BUFMAX-strlen(buf)-1);
+                                       }
+
+                                       mi = mi->next;
+                                       mime = NULL;
+                               }
+                               asvc = asvc->next;
+                       }
+                       DBG("MIME types: buf[%s]\n", buf);
+                       DBG("MIME count: %d\n", mime_count);
+                       if(mime_count)
+                               fwrite(buf, 1, strlen(buf), file);
+               }
+
                if(mfx->version) {
                        snprintf(buf, BUFMAX, "Version=%s\n", mfx->version);
                        fwrite(buf, 1, strlen(buf), file);
@@ -3417,19 +4251,17 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, bool is_update)
                        mime_x *mi = NULL;
                        uri_x *ui = NULL;
                        subapp_x *sub = NULL;
-                       char *operation = NULL;
-                       char *mime = NULL;
-                       char *uri = NULL;
-                       char *subapp = 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)
-                       {
+                       while(asvc != NULL) {
                                op = asvc->operation;
-                               while(op != NULL)
-                               {
+                               while(op != NULL) {
                                        if (op)
                                                operation = op->name;
                                        mi = asvc->mime;
@@ -3496,18 +4328,16 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, bool is_update)
                        mime_x *mi = NULL;
                        uri_x *ui = NULL;
                        subapp_x *sub = NULL;
-                       char *operation = NULL;
-                       char *mime = NULL;
-                       char *uri = NULL;
-                       char *subapp = 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)
-                       {
+                       while(acontrol != NULL) {
                                op = acontrol->operation;
-                               while(op != NULL)
-                               {
+                               while(op != NULL) {
                                        if (op)
                                                operation = op->name;
                                        mi = acontrol->mime;
@@ -3568,10 +4398,7 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, bool is_update)
                fsync(fd);
                fclose(file);
 
-               if (!is_update)
-                       __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
-               else
-                       __ail_change_info(AIL_UPDATE, mfx->uiapplication->appid);
+               __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
        }
 
        free(buf);
@@ -3584,11 +4411,12 @@ static int __ps_remove_nativeapp_desktop(manifest_x *mfx)
 {
        char filepath[PKG_STRING_LEN_MAX] = "";
        int ret = 0;
+       uiapplication_x *uiapplication = mfx->uiapplication;
 
-       for(; mfx->uiapplication; mfx->uiapplication=mfx->uiapplication->next) {
-               snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, mfx->uiapplication->appid);
+       for(; uiapplication; uiapplication=uiapplication->next) {
+               snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
 
-               __ail_change_info(AIL_REMOVE, mfx->uiapplication->appid);
+               __ail_change_info(AIL_REMOVE, uiapplication->appid);
 
                ret = remove(filepath);
                if (ret <0)
@@ -3598,7 +4426,39 @@ static int __ps_remove_nativeapp_desktop(manifest_x *mfx)
         return 0;
 }
 
-#define MANIFEST_RO_PREFIX "/usr/share/packages/"
+#define LIBAPPSVC_PATH "/usr/lib/libappsvc.so.0"
+
+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;
+
+       if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
+               DBGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAPPSVC_PATH);
+               goto END;
+       }
+
+       if ((appsvc_operation =
+                dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
+               DBGE("can not find symbol \n");
+               goto END;
+       }
+
+       for(; uiapplication; uiapplication=uiapplication->next) {
+               ret = appsvc_operation(uiapplication->appid);
+               if (ret <0)
+                       DBGE("can not operation  symbol \n");
+       }
+
+END:
+       if (lib_handle)
+               dlclose(lib_handle);
+
+       return ret;
+}
+
 #define PRELOAD_PACKAGE_LIST "/usr/etc/package-manager/preload/preload_list.txt"
 static int __add_preload_info(manifest_x * mfx, const char *manifest)
 {
@@ -3607,15 +4467,18 @@ static int __add_preload_info(manifest_x * mfx, const char *manifest)
        int state = 0;
 
        if(strstr(manifest, MANIFEST_RO_PREFIX)) {
-               free(mfx->readonly);
+               free((void *)mfx->readonly);
                mfx->readonly = strdup("True");
 
-               free(mfx->preload);
+               free((void *)mfx->preload);
                mfx->preload = strdup("True");
 
-               free(mfx->removable);
+               free((void *)mfx->removable);
                mfx->removable = strdup("False");
 
+               free((void *)mfx->system);
+               mfx->system = strdup("True");
+
                return 0;
        }
 
@@ -3638,17 +4501,17 @@ static int __add_preload_info(manifest_x * mfx, const char *manifest)
                __str_trim(buffer);
 
                if(!strcmp(mfx->package, buffer)) {
-                       free(mfx->preload);
+                       free((void *)mfx->preload);
                        mfx->preload = strdup("True");
                        if(state == 2){
-                               free(mfx->readonly);
+                               free((void *)mfx->readonly);
                                mfx->readonly = strdup("False");
-                               free(mfx->removable);
+                               free((void *)mfx->removable);
                                mfx->removable = strdup("False");
                        } else if(state == 3){
-                               free(mfx->readonly);
+                               free((void *)mfx->readonly);
                                mfx->readonly = strdup("False");
-                               free(mfx->removable);
+                               free((void *)mfx->removable);
                                mfx->removable = strdup("True");
                        }
                }
@@ -3662,6 +4525,44 @@ static int __add_preload_info(manifest_x * mfx, const char *manifest)
        return 0;
 }
 
+static int __check_preload_updated(manifest_x * mfx, const char *manifest)
+{
+       char filepath[PKG_STRING_LEN_MAX] = "";
+       int ret = 0;
+       uiapplication_x *uiapplication = mfx->uiapplication;
+
+       if(strstr(manifest, MANIFEST_RO_PREFIX)) {
+               /* if preload app is updated, then remove previous desktop file on RW*/
+               for(; uiapplication; uiapplication=uiapplication->next) {
+                               snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
+                       ret = remove(filepath);
+                       if (ret <0)
+                               return -1;
+               }
+       } else {
+               /* if downloaded app is updated, then update tag set true*/
+               free((void *)mfx->update);
+               mfx->update = strdup("true");
+       }
+
+       return 0;
+}
+
+
+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, NULL, 0);
+        if (ret == -1)
+                DBG("Creating desktop file failed\n");
+        else
+                DBG("Creating desktop file Success\n");
+        return ret;
+}
 
 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
 {
@@ -3699,6 +4600,10 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
                free((void *)mfx->update);
                mfx->update = NULL;
        }
+       if (mfx->system) {
+               free((void *)mfx->system);
+               mfx->system = NULL;
+       }
        if (mfx->type) {
                free((void *)mfx->type);
                mfx->type = NULL;
@@ -3731,17 +4636,24 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
                free((void *)mfx->root_path);
                mfx->root_path = NULL;
        }
+       if (mfx->csc_path) {
+               free((void *)mfx->csc_path);
+               mfx->csc_path = NULL;
+       }
        if (mfx->appsetting) {
                free((void *)mfx->appsetting);
                mfx->appsetting = NULL;
        }
+       if (mfx->nodisplay_setting) {
+               free((void *)mfx->nodisplay_setting);
+               mfx->nodisplay_setting = NULL;
+       }
 
        /*Free Icon*/
        if (mfx->icon) {
                icon_x *icon = mfx->icon;
                icon_x *tmp = NULL;
-               while(icon != NULL)
-               {
+               while(icon != NULL) {
                        tmp = icon->next;
                        __ps_free_icon(icon);
                        icon = tmp;
@@ -3751,8 +4663,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->label) {
                label_x *label = mfx->label;
                label_x *tmp = NULL;
-               while(label != NULL)
-               {
+               while(label != NULL) {
                        tmp = label->next;
                        __ps_free_label(label);
                        label = tmp;
@@ -3762,8 +4673,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->author) {
                author_x *author = mfx->author;
                author_x *tmp = NULL;
-               while(author != NULL)
-               {
+               while(author != NULL) {
                        tmp = author->next;
                        __ps_free_author(author);
                        author = tmp;
@@ -3773,8 +4683,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->description) {
                description_x *description = mfx->description;
                description_x *tmp = NULL;
-               while(description != NULL)
-               {
+               while(description != NULL) {
                        tmp = description->next;
                        __ps_free_description(description);
                        description = tmp;
@@ -3784,19 +4693,27 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->license) {
                license_x *license = mfx->license;
                license_x *tmp = NULL;
-               while(license != 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)
-               {
+               while(uiapplication != NULL) {
                        tmp = uiapplication->next;
                        __ps_free_uiapplication(uiapplication);
                        uiapplication = tmp;
@@ -3806,8 +4723,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->serviceapplication) {
                serviceapplication_x *serviceapplication = mfx->serviceapplication;
                serviceapplication_x *tmp = NULL;
-               while(serviceapplication != NULL)
-               {
+               while(serviceapplication != NULL) {
                        tmp = serviceapplication->next;
                        __ps_free_serviceapplication(serviceapplication);
                        serviceapplication = tmp;
@@ -3817,8 +4733,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->daemon) {
                daemon_x *daemon = mfx->daemon;
                daemon_x *tmp = NULL;
-               while(daemon != NULL)
-               {
+               while(daemon != NULL) {
                        tmp = daemon->next;
                        __ps_free_daemon(daemon);
                        daemon = tmp;
@@ -3828,8 +4743,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->theme) {
                theme_x *theme = mfx->theme;
                theme_x *tmp = NULL;
-               while(theme != NULL)
-               {
+               while(theme != NULL) {
                        tmp = theme->next;
                        __ps_free_theme(theme);
                        theme = tmp;
@@ -3839,8 +4753,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->font) {
                font_x *font = mfx->font;
                font_x *tmp = NULL;
-               while(font != NULL)
-               {
+               while(font != NULL) {
                        tmp = font->next;
                        __ps_free_font(font);
                        font = tmp;
@@ -3850,8 +4763,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->ime) {
                ime_x *ime = mfx->ime;
                ime_x *tmp = NULL;
-               while(ime != NULL)
-               {
+               while(ime != NULL) {
                        tmp = ime->next;
                        __ps_free_ime(ime);
                        ime = tmp;
@@ -3861,8 +4773,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->compatibility) {
                compatibility_x *compatibility = mfx->compatibility;
                compatibility_x *tmp = NULL;
-               while(compatibility != NULL)
-               {
+               while(compatibility != NULL) {
                        tmp = compatibility->next;
                        __ps_free_compatibility(compatibility);
                        compatibility = tmp;
@@ -3872,8 +4783,7 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
        if (mfx->deviceprofile) {
                deviceprofile_x *deviceprofile = mfx->deviceprofile;
                deviceprofile_x *tmp = NULL;
-               while(deviceprofile != NULL)
-               {
+               while(deviceprofile != NULL) {
                        tmp = deviceprofile->next;
                        __ps_free_deviceprofile(deviceprofile);
                        deviceprofile = tmp;
@@ -3915,7 +4825,7 @@ API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
 
 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", NULL};
+       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
        if (manifest == NULL) {
                DBG("argument supplied is NULL\n");
                return PMINFO_R_EINVAL;
@@ -3930,16 +4840,12 @@ API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char
        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");
 
-       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");
+       __ps_process_tag(mfx, tagv);
 
        ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
        if (ret == -1)
@@ -3947,7 +4853,15 @@ API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char
        else
                DBG("DB Insert Success\n");
 
-       ret = __ps_make_nativeapp_desktop(mfx, 0);
+       ret = __ps_process_mdparser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               DBG("Creating metadata parser failed\n");
+
+       ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               DBG("Creating category parser failed\n");
+
+       ret = __ps_make_nativeapp_desktop(mfx, NULL, 0);
        if (ret == -1)
                DBG("Creating desktop file failed\n");
        else
@@ -3960,25 +4874,9 @@ API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char
        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[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", NULL};
+       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
        if (manifest == NULL) {
                DBG("argument supplied is NULL\n");
                return PMINFO_R_EINVAL;
@@ -3986,6 +4884,11 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        DBG("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;
+
        xmlInitParser();
        mfx = pkgmgr_parser_process_manifest_xml(manifest);
        DBG("Parsing Finished\n");
@@ -3995,20 +4898,61 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        __streamFile(manifest, ACTION_UPGRADE, temp, mfx->package);
        __add_preload_info(mfx, manifest);
        DBG("Added preload infomation\n");
+       __check_preload_updated(mfx, manifest);
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
+       if (ret != PMINFO_R_OK)
+               DBG("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
+
+       ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
+       if (ret != PMINFO_R_OK)
+               DBG("pkgmgrinfo_pkginfo_is_preload failed\n");
+
+       if (preload) {
+               free((void *)mfx->preload);
+               mfx->preload = strdup("true");
+       }
+
+       ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
+       if (ret != PMINFO_R_OK)
+               DBG("pkgmgrinfo_pkginfo_is_system failed\n");
+
+       if (system) {
+               free((void *)mfx->system);
+               mfx->system = strdup("true");
+       }
+
+       ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
+       if (ret != PMINFO_R_OK)
+               DBG("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);
+       }
 
-       mfx->update = strdup("true");
        ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
        if (ret == -1)
                DBG("DB Update failed\n");
        else
                DBG("DB Update Success\n");
 
-       ret = __ps_make_nativeapp_desktop(mfx, 1);
+       ret = __ps_process_mdparser(mfx, ACTION_UPGRADE);
+       if (ret == -1)
+               DBG("Upgrade metadata parser failed\n");
+
+       ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1)
+               DBG("Creating category parser failed\n");
+
+       ret = __ps_make_nativeapp_desktop(mfx, manifest, 1);
        if (ret == -1)
                DBG("Creating desktop file failed\n");
        else
                DBG("Creating desktop file Success\n");
 
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
        pkgmgr_parser_free_manifest_xml(mfx);
        DBG("Free Done\n");
        xmlCleanupParser();
@@ -4018,7 +4962,7 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
 
 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
 {
-       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", NULL};
+       char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
        if (manifest == NULL) {
                DBG("argument supplied is NULL\n");
                return PMINFO_R_EINVAL;
@@ -4036,6 +4980,14 @@ API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, ch
        __add_preload_info(mfx, manifest);
        DBG("Added preload infomation\n");
 
+       ret = __ps_process_mdparser(mfx, ACTION_UNINSTALL);
+       if (ret == -1)
+               DBG("Removing metadata parser failed\n");
+
+       ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
+       if (ret == -1)
+               DBG("Creating category parser failed\n");
+
        ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
        if (ret == -1)
                DBG("DB Delete failed\n");
@@ -4048,6 +5000,12 @@ API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, ch
        else
                DBG("Removing desktop file Success\n");
 
+       ret = __ps_remove_appsvc_db(mfx);
+       if (ret == -1)
+               DBG("Removing appsvc_db failed\n");
+       else
+               DBG("Removing appsvc_db Success\n");
+
        pkgmgr_parser_free_manifest_xml(mfx);
        DBG("Free Done\n");
        xmlCleanupParser();
@@ -4055,6 +5013,11 @@ API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, ch
        return PMINFO_R_OK;
 }
 
+API int pkgmgr_parser_parse_manifest_for_preload()
+{
+       return pkgmgr_parser_update_preload_info_in_db();
+}
+
 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
 {
        return __pkgid_to_manifest(pkgid);