4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
31 #include <libxml/parser.h>
32 #include <libxml/xmlreader.h>
33 #include <libxml/xmlschemas.h>
38 #include "pkgmgr-info.h"
39 #include "pkgmgrinfo_basic.h"
40 #include "pkgmgrinfo_debug.h"
42 #include "pkgmgr_parser.h"
43 #include "pkgmgr_parser_internal.h"
44 #include "pkgmgr_parser_db.h"
49 #define LOG_TAG "PKGMGR_PARSER"
51 #define ASCII(s) (char *)s
52 #define XMLCHAR(s) (const xmlChar *)s
54 //#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/metadata_parser_list.txt"
55 #define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/mdparser_list.txt"
56 #define METADATA_PARSER_NAME "metadataparser:"
58 #define CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
59 #define CATEGORY_PARSER_NAME "categoryparser:"
61 #define TAG_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/tag_parser_list.txt"
62 #define TAG_PARSER_NAME "parserlib:"
64 #define PKG_TAG_LEN_MAX 128
67 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
69 /* plugin process_type */
71 PLUGIN_PRE_PROCESS = 0,
73 } PLUGIN_PROCESS_TYPE;
77 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label);
78 static int __ps_process_privilege(xmlTextReaderPtr reader, char **privilege);
79 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges);
80 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed);
81 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition);
82 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
83 static int __ps_process_category(xmlTextReaderPtr reader, char **category);
84 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
85 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
86 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
87 static int __ps_process_request(xmlTextReaderPtr reader, char **request);
88 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
89 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions);
90 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
91 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
92 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
93 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
94 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
95 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol);
96 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
97 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid);
98 static int __next_child_element(xmlTextReaderPtr reader, int depth);
99 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
100 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
101 static void __str_trim(char *input);
102 static char *__get_parser_plugin(const char *type);
103 API int __is_admin();
105 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, char **xml_attribute, char *default_value)
107 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
109 *xml_attribute = strdup((const char *)attrib_val);
112 if (default_value != NULL) {
113 *xml_attribute = strdup(default_value);
118 static void __save_xml_lang(xmlTextReaderPtr reader, char **xml_attribute)
120 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
121 if (attrib_val != NULL)
122 *xml_attribute = strdup(ASCII(attrib_val));
124 *xml_attribute = strdup(DEFAULT_LOCALE);
127 static void __save_xml_value(xmlTextReaderPtr reader, char **xml_attribute)
129 xmlTextReaderRead(reader);
130 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
133 *xml_attribute = strdup((const char *)attrib_val);
136 static void __save_xml_installed_time(manifest_x *mfx)
138 char buf[PKG_STRING_LEN_MAX] = {'\0'};
142 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
143 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
144 mfx->installed_time = val;
147 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
149 char root[PKG_STRING_LEN_MAX] = { '\0' };
155 tzplatform_set_user(uid);
156 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
157 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
159 mfx->root_path = strdup(root);
161 tzplatform_reset_user();
164 static void __save_xml_default_value(manifest_x * mfx)
166 mfx->preload = strdup("False");
167 mfx->removable = strdup("True");
168 mfx->readonly = strdup("False");
169 mfx->update = strdup("False");
170 mfx->system = strdup("False");
171 mfx->installed_storage= strdup("installed_internal");
172 package = mfx->package;
175 void *__open_lib_handle(char *tag)
177 char *lib_path = NULL;
178 void *lib_handle = NULL;
180 lib_path = __get_parser_plugin(tag);
181 retvm_if(!lib_path, NULL, "lib_path get fail");
183 lib_handle = dlopen(lib_path, RTLD_LAZY);
184 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
189 void __close_lib_handle(void *lib_handle)
194 static void __str_trim(char *input)
196 char *trim_str = input;
201 while (*input != 0) {
202 if (!isspace(*input)) {
215 uid_t uid = getuid();
216 if ((uid_t) 0 == uid )
224 static char * __get_tag_by_key(char *md_key)
228 if (md_key == NULL) {
229 _LOGD("md_key is NULL\n");
233 md_tag = strrchr(md_key, 47) + 1;
236 return strdup(md_tag);
239 static char *__get_metadata_parser_plugin(const char *type)
242 char buffer[1024] = { 0 };
243 char temp_path[1024] = { 0 };
247 _LOGE("invalid argument\n");
251 fp = fopen(PKG_PARSER_CONF_PATH, "r");
253 _LOGE("no matching metadata parser\n");
257 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
258 if (buffer[0] == '#')
263 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
264 path = path + strlen(METADATA_PARSER_NAME);
269 memset(buffer, 0x00, 1024);
276 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
280 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
282 return strdup(temp_path);
285 static char *__get_category_parser_plugin(const char *type)
288 char buffer[1024] = { 0 };
289 char temp_path[1024] = { 0 };
293 _LOGE("invalid argument\n");
297 fp = fopen(PKG_PARSER_CONF_PATH, "r");
299 _LOGE("no matching metadata parser\n");
303 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
304 if (buffer[0] == '#')
309 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
310 path = path + strlen(CATEGORY_PARSER_NAME);
315 memset(buffer, 0x00, 1024);
322 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
326 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
328 return strdup(temp_path);
331 static char *__get_parser_plugin(const char *type)
334 char buffer[1024] = { 0 };
335 char temp_path[1024] = { 0 };
339 _LOGE("invalid argument\n");
343 fp = fopen(PKG_PARSER_CONF_PATH, "r");
345 _LOGE("no matching backendlib\n");
349 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
350 if (buffer[0] == '#')
355 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
356 path = path + strlen(PKG_PARSERLIB);
360 memset(buffer, 0x00, 1024);
367 _LOGE("no matching backendlib\n");
371 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
373 return strdup(temp_path);
376 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
377 ACTION_TYPE action, const char *pkgid)
379 int (*plugin_install) (xmlDocPtr, const char *);
385 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
388 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
390 case ACTION_UNINSTALL:
391 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
397 if ((plugin_install =
398 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
399 _LOGE("can not find symbol[%s] \n", ac);
403 ret = plugin_install(docPtr, pkgid);
404 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
410 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
411 ACTION_TYPE action, const char *pkgid, const char *appid)
413 char *lib_path = NULL;
414 void *lib_handle = NULL;
415 int (*metadata_parser_plugin) (const char *, const char *, GList *);
421 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
424 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
426 case ACTION_UNINSTALL:
427 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
433 lib_path = __get_metadata_parser_plugin(tag);
435 _LOGE("get %s parser fail\n", tag);
439 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
440 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
444 if ((metadata_parser_plugin =
445 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
446 _LOGE("can not find symbol[%s] \n",ac);
450 ret = metadata_parser_plugin(pkgid, appid, md_list);
452 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
454 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
464 static int __ps_run_category_parser(GList *category_list, const char *tag,
465 ACTION_TYPE action, const char *pkgid, const char *appid)
467 char *lib_path = NULL;
468 void *lib_handle = NULL;
469 int (*category_parser_plugin) (const char *, const char *, GList *);
475 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
478 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
480 case ACTION_UNINSTALL:
481 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
487 lib_path = __get_category_parser_plugin(tag);
489 _LOGE("get %s parser fail\n", tag);
493 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
494 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
498 if ((category_parser_plugin =
499 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
500 _LOGE("can not find symbol[%s] \n",ac);
504 ret = category_parser_plugin(pkgid, appid, category_list);
506 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
508 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
518 static void __metadata_parser_clear_dir_list(GList* dir_list)
521 __metadata_t* detail = NULL;
524 list = g_list_first(dir_list);
526 detail = (__metadata_t *)list->data;
529 free((void *)detail->key);
531 free((void *)detail->value);
534 list = g_list_next(list);
536 g_list_free(dir_list);
540 static void __category_parser_clear_dir_list(GList* dir_list)
543 __category_t* detail = NULL;
546 list = g_list_first(dir_list);
548 detail = (__category_t *)list->data;
551 free((void *)detail->name);
555 list = g_list_next(list);
557 g_list_free(dir_list);
561 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
566 if (xmlTextReaderDepth(reader) != 1) {
567 _LOGE("Node depth is not 1");
571 if (xmlTextReaderNodeType(reader) != 1) {
572 _LOGE("Node type is not 1");
576 const xmlChar *value;
577 name = xmlTextReaderConstName(reader);
579 _LOGE("TEST TEST TES\n");
580 name = BAD_CAST "--";
583 value = xmlTextReaderConstValue(reader);
585 if (xmlStrlen(value) > 40) {
586 _LOGD(" %.40s...", value);
592 name = xmlTextReaderConstName(reader);
594 _LOGE("TEST TEST TES\n");
595 name = BAD_CAST "--";
598 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
599 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
600 if (copyDocPtr == NULL)
602 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
603 if (rootElement == NULL)
605 xmlNode *cur_node = xmlFirstElementChild(rootElement);
606 if (cur_node == NULL)
608 xmlNode *temp = xmlTextReaderExpand(reader);
611 xmlNode *next_node = NULL;
612 while(cur_node != NULL) {
613 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
614 (temp->line == cur_node->line) ) {
618 next_node = xmlNextElementSibling(cur_node);
619 xmlUnlinkNode(cur_node);
620 xmlFreeNode(cur_node);
621 cur_node = next_node;
624 if (cur_node == NULL)
626 next_node = xmlNextElementSibling(cur_node);
628 cur_node->next = NULL;
629 next_node->prev = NULL;
630 xmlFreeNodeList(next_node);
631 xmlSetTreeDoc(cur_node, copyDocPtr);
633 xmlSetTreeDoc(cur_node, copyDocPtr);
636 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
642 static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
646 char buffer[1024] = { 0, };
649 GList *md_tmp = NULL;
653 GList *md_list = NULL;
654 __metadata_t *md_detail = NULL;
656 md_tag = __get_tag_by_key(md_key);
657 if (md_tag == NULL) {
658 _LOGD("md_tag is NULL\n");
662 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
663 app = (application_x *)app_tmp->data;
666 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
667 md = (metadata_x *)md_tmp->data;
670 //get glist of metadata key and value combination
671 memset(buffer, 0x00, 1024);
672 snprintf(buffer, 1024, "%s/", md_key);
673 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
674 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
675 if (md_detail == NULL) {
676 _LOGD("Memory allocation failed\n");
680 md_detail->key = strdup(md->key);
681 if (md_detail->key == NULL) {
682 _LOGD("Memory allocation failed\n");
687 md_detail->value = strdup(md->value);
688 if (md_detail->value == NULL) {
689 _LOGD("Memory allocation failed\n");
690 free((void *)md_detail->key);
695 md_list = g_list_append(md_list, (gpointer)md_detail);
700 //send glist to parser when tags for metadata plugin parser exist.
702 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
704 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
707 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
710 __metadata_parser_clear_dir_list(md_list);
717 __metadata_parser_clear_dir_list(md_list);
725 static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
729 char buffer[1024] = { 0, };
733 const char *category;
734 char *category_tag = NULL;
736 GList *category_list = NULL;
737 __category_t *category_detail = NULL;
739 category_tag = __get_tag_by_key(category_key);
740 if (category_tag == NULL) {
741 _LOGD("md_tag is NULL\n");
745 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
746 app = (application_x *)app_tmp->data;
749 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
750 category = (const char *)category_tmp->data;
751 //get glist of category key and value combination
752 memset(buffer, 0x00, 1024);
753 snprintf(buffer, 1024, "%s/", category_key);
754 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
755 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
756 if (category_detail == NULL) {
757 _LOGD("Memory allocation failed\n");
761 category_detail->name = strdup(category);
762 if (category_detail->name == NULL) {
763 _LOGD("Memory allocation failed\n");
764 free(category_detail);
768 category_list = g_list_append(category_list, (gpointer)category_detail);
773 //send glist to parser when tags for metadata plugin parser exist.
775 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
777 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
779 _LOGD("category_parser success for tag[%s]\n", category_tag);
781 __category_parser_clear_dir_list(category_list);
782 category_list = NULL;
788 __category_parser_clear_dir_list(category_list);
796 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
798 switch (xmlTextReaderNodeType(reader)) {
799 case XML_READER_TYPE_END_ELEMENT:
803 case XML_READER_TYPE_ELEMENT:
805 // Elements without closing tag don't receive
806 const xmlChar *elementName =
807 xmlTextReaderLocalName(reader);
808 if (elementName == NULL) {
812 if (strcmp(tag, ASCII(elementName)) == 0) {
813 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
814 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
825 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
827 int (*plugin_install) (const char *);
831 if (process == PLUGIN_PRE_PROCESS) {
834 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
837 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
839 case ACTION_UNINSTALL:
840 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
845 } else if (process == PLUGIN_POST_PROCESS) {
848 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
851 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
853 case ACTION_UNINSTALL:
854 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
862 if ((plugin_install =
863 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
867 ret = plugin_install(pkgid);
871 static int __next_child_element(xmlTextReaderPtr reader, int depth)
873 int ret = xmlTextReaderRead(reader);
874 int cur = xmlTextReaderDepth(reader);
877 switch (xmlTextReaderNodeType(reader)) {
878 case XML_READER_TYPE_ELEMENT:
879 if (cur == depth + 1)
882 case XML_READER_TYPE_TEXT:
883 /*text is handled by each function separately*/
884 if (cur == depth + 1)
887 case XML_READER_TYPE_END_ELEMENT:
896 ret = xmlTextReaderRead(reader);
897 cur = xmlTextReaderDepth(reader);
901 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
903 xmlTextReaderPtr reader;
907 void *lib_handle = NULL;
908 char tag[PKG_STRING_LEN_MAX] = { 0 };
910 fp = fopen(TAG_PARSER_LIST, "r");
911 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
913 while (fgets(tag, sizeof(tag), fp) != NULL) {
916 lib_handle = __open_lib_handle(tag);
917 if (lib_handle == NULL)
920 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
921 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
923 docPtr = xmlReadFile(filename, NULL, 0);
924 reader = xmlReaderWalker(docPtr);
925 if (reader != NULL) {
926 ret = xmlTextReaderRead(reader);
928 __process_tag(lib_handle, reader, action, tag, mfx->package);
929 ret = xmlTextReaderRead(reader);
931 xmlFreeTextReader(reader);
934 _LOGD("%s : failed to parse", filename);
937 _LOGD("Unable to open %s", filename);
940 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
941 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
943 __close_lib_handle(lib_handle);
945 memset(tag, 0x00, sizeof(tag));
954 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
956 fprintf(stdout,"__ps_process_metadata_parser\n");
959 char md_key[PKG_STRING_LEN_MAX] = { 0 };
961 fp = fopen(METADATA_PARSER_LIST, "r");
963 _LOGD("no preload list\n");
967 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
969 ret = __run_metadata_parser_prestep(mfx, md_key, action);
980 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
984 char category_key[PKG_STRING_LEN_MAX] = { 0 };
986 fp = fopen(CATEGORY_PARSER_LIST, "r");
988 _LOGD("no category parser list\n");
992 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
993 __str_trim(category_key);
994 ret = __run_category_parser_prestep(mfx, category_key, action);
1005 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed)
1007 __save_xml_value(reader, allowed);
1011 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition)
1013 __save_xml_attribute(reader, "name", condition, NULL);
1017 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
1019 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
1020 __save_xml_value(reader, ¬ification->text);
1024 static int __ps_process_category(xmlTextReaderPtr reader, char **category)
1026 __save_xml_attribute(reader, "name", category, NULL);
1030 static int __ps_process_privilege(xmlTextReaderPtr reader, char **privilege)
1032 __save_xml_value(reader, privilege);
1036 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
1038 __save_xml_attribute(reader, "key", &metadata->key, NULL);
1039 __save_xml_attribute(reader, "value", &metadata->value, NULL);
1043 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
1045 __save_xml_attribute(reader, "type", &permission->type, NULL);
1046 __save_xml_value(reader, &permission->value);
1050 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
1052 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
1053 __save_xml_value(reader, &compatibility->text);
1057 static int __ps_process_request(xmlTextReaderPtr reader, char **request)
1059 __save_xml_value(reader, request);
1063 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
1065 const xmlChar *node;
1070 __save_xml_attribute(reader, "path", &define->path, NULL);
1072 depth = xmlTextReaderDepth(reader);
1073 while ((ret = __next_child_element(reader, depth))) {
1074 node = xmlTextReaderConstName(reader);
1076 _LOGD("xmlTextReaderConstName value is NULL\n");
1080 if (!strcmp(ASCII(node), "allowed")) {
1082 ret = __ps_process_allowed(reader, &val);
1084 define->allowed = g_list_append(define->allowed, (gpointer)val);
1085 } else if (!strcmp(ASCII(node), "request")) {
1087 ret = __ps_process_request(reader, &val);
1089 define->request = g_list_append(define->request, (gpointer)val);
1094 _LOGD("Processing define failed\n");
1101 struct appcontrol_data {
1106 char operation[BUFSIZE];
1111 static void __ps_process_mime(gpointer data, gpointer user_data)
1113 char *mime = (char *)data;
1114 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1115 appcontrol_x *appcontrol;
1117 snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
1119 appcontrol = calloc(1, sizeof(appcontrol_x));
1120 if (strlen(ad->operation))
1121 appcontrol->operation = strdup(ad->operation);
1122 if (strlen(ad->uri))
1123 appcontrol->uri = strdup(ad->uri);
1124 appcontrol->mime = strdup(ad->mime);
1125 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1128 static void __ps_process_uri(gpointer data, gpointer user_data)
1130 char *uri = (char *)data;
1131 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1132 appcontrol_x *appcontrol;
1134 snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
1136 if (ad->mimes != NULL) {
1137 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1139 appcontrol = calloc(1, sizeof(appcontrol_x));
1140 if (strlen(ad->operation))
1141 appcontrol->operation = strdup(ad->operation);
1142 appcontrol->uri = strdup(ad->uri);
1143 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1147 static void __ps_process_operation(gpointer data, gpointer user_data)
1149 char *operation = (char *)data;
1150 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1151 appcontrol_x *appcontrol;
1153 snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
1155 if (ad->uris != NULL) {
1156 g_list_foreach(ad->uris, __ps_process_uri, user_data);
1157 } else if (ad->mimes != NULL) {
1158 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1160 appcontrol = calloc(1, sizeof(appcontrol_x));
1161 appcontrol->operation = strdup(ad->operation);
1162 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1166 static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
1168 struct appcontrol_data ad = {0, };
1170 ad.operations = operations;
1174 if (ad.operations == NULL)
1177 g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
1179 return ad.appcontrols;
1182 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
1184 const xmlChar *node;
1188 GList *operations = NULL;
1190 GList *mimes = NULL;
1193 depth = xmlTextReaderDepth(reader);
1194 while ((ret = __next_child_element(reader, depth)) > 0) {
1195 node = xmlTextReaderConstName(reader);
1197 _LOGD("xmlTextReaderConstName value is NULL\n");
1202 if (!strcmp(ASCII(node), "operation")) {
1203 __save_xml_attribute(reader, "name", &val, NULL);
1205 operations = g_list_append(operations, (gpointer)val);
1206 _LOGD("operation processing\n");
1207 } else if (!strcmp(ASCII(node), "uri")) {
1208 __save_xml_attribute(reader, "name", &val, NULL);
1210 uris = g_list_append(uris, (gpointer)val);
1211 _LOGD("uri processing\n");
1212 } else if (!strcmp(ASCII(node), "mime")) {
1213 __save_xml_attribute(reader, "name", &val, NULL);
1215 mimes = g_list_append(mimes, (gpointer)val);
1216 _LOGD("mime processing\n");
1217 } else if (!strcmp(ASCII(node), "subapp")) {
1225 _LOGD("Processing appcontrol failed\n");
1226 g_list_free_full(operations, free);
1227 g_list_free_full(uris, free);
1228 g_list_free_full(mimes, free);
1232 result = __make_appcontrol_list(operations, uris, mimes);
1234 *appcontrol = g_list_concat(*appcontrol, result);
1238 g_list_free_full(operations, free);
1239 g_list_free_full(uris, free);
1240 g_list_free_full(mimes, free);
1245 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
1247 const xmlChar *node;
1252 depth = xmlTextReaderDepth(reader);
1253 while ((ret = __next_child_element(reader, depth))) {
1254 node = xmlTextReaderConstName(reader);
1256 _LOGD("xmlTextReaderConstName value is NULL\n");
1260 if (strcmp(ASCII(node), "privilege") == 0) {
1262 ret = __ps_process_privilege(reader, &val);
1264 *privileges = g_list_append(*privileges, (gpointer)val);
1268 _LOGD("Processing privileges failed\n");
1275 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
1277 const xmlChar *node;
1282 depth = xmlTextReaderDepth(reader);
1283 while ((ret = __next_child_element(reader, depth))) {
1284 node = xmlTextReaderConstName(reader);
1286 _LOGD("xmlTextReaderConstName value is NULL\n");
1290 if (strcmp(ASCII(node), "condition") == 0) {
1292 ret = __ps_process_condition(reader, &val);
1294 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
1298 _LOGD("Processing launchconditions failed\n");
1306 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
1308 const xmlChar *node;
1312 depth = xmlTextReaderDepth(reader);
1313 while ((ret = __next_child_element(reader, depth))) {
1314 node = xmlTextReaderConstName(reader);
1316 _LOGD("xmlTextReaderConstName value is NULL\n");
1320 if (!strcmp(ASCII(node), "define")) {
1321 define_x *define = calloc(1, sizeof(define_x));
1322 if (define == NULL) {
1323 _LOGD("Malloc Failed\n");
1326 datashare->define = g_list_append(datashare->define, define);
1327 ret = __ps_process_define(reader, define);
1328 } else if (!strcmp(ASCII(node), "request")) {
1330 ret = __ps_process_request(reader, &val);
1332 datashare->request = g_list_append(datashare->request, (gpointer)val);
1336 _LOGD("Processing data-share failed\n");
1343 static char *__get_icon_with_path(const char *icon, uid_t uid)
1345 char icon_with_path[BUFSIZE];
1346 const char *app_path;
1348 if (!icon || !package)
1351 /* just use absolute path */
1352 if (index(icon, '/'))
1353 return strdup(icon);
1356 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1357 getIconPath(uid, true), icon);
1358 if (access(icon_with_path, F_OK) == 0)
1361 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1362 getIconPath(uid, false), icon);
1363 if (access(icon_with_path, F_OK) == 0)
1366 /* for backward compatibility (.../default/small/...)
1367 * this should be removed
1369 snprintf(icon_with_path, sizeof(icon_with_path),
1370 "%sdefault/small/%s",
1371 getIconPath(uid, true), icon);
1372 if (access(icon_with_path, F_OK) == 0)
1375 snprintf(icon_with_path, sizeof(icon_with_path),
1376 "%sdefault/small/%s",
1377 getIconPath(uid, false), icon);
1378 if (access(icon_with_path, F_OK) == 0)
1381 /* If doesn't exist in case of Global app,
1382 * try to get icon directly into app's directory
1384 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
1385 app_path = tzplatform_getenv(TZ_SYS_RO_APP);
1387 snprintf(icon_with_path, sizeof(icon_with_path),
1388 "%s/%s/%s", app_path, package, icon);
1389 if (access(icon_with_path, F_OK) == 0)
1392 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
1394 snprintf(icon_with_path, sizeof(icon_with_path),
1395 "%s/%s/%s", app_path, package, icon);
1396 if (access(icon_with_path, F_OK) == 0)
1399 tzplatform_set_user(uid);
1400 app_path = tzplatform_getenv(TZ_USER_APP);
1401 tzplatform_reset_user();
1403 snprintf(icon_with_path, sizeof(icon_with_path),
1404 "%s/%s/%s", app_path, package, icon);
1405 if (access(icon_with_path, F_OK) == 0)
1409 /* some preload package has icons at below path */
1410 snprintf(icon_with_path, sizeof(icon_with_path),
1411 "%s/%s/res/icons/%s", app_path, package, icon);
1412 if (access(icon_with_path, F_OK) == 0)
1415 /* since 2.3 tpk package */
1416 snprintf(icon_with_path, sizeof(icon_with_path),
1417 "%s/%s/shared/res/%s", app_path, package, icon);
1418 if (access(icon_with_path, F_OK) == 0)
1421 _LOGE("cannot find icon path for [%s]", icon);
1425 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1427 return strdup(icon_with_path);
1430 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1433 char delims[] = "=";
1434 char *ret_result = NULL;
1441 for (tag = strdup(tagv[0]); tag != NULL; ) {
1442 ret_result = strtok_r(tag, delims, &ptr);
1444 /*check tag : preload */
1445 if (strcmp(ret_result, "preload") == 0) {
1446 ret_result = strtok_r(NULL, delims, &ptr);
1447 if (strcmp(ret_result, "true") == 0) {
1448 free((void *)mfx->preload);
1449 mfx->preload = strdup("true");
1450 } else if (strcmp(ret_result, "false") == 0) {
1451 free((void *)mfx->preload);
1452 mfx->preload = strdup("false");
1454 /*check tag : removable*/
1455 } else if (strcmp(ret_result, "removable") == 0) {
1456 ret_result = strtok_r(NULL, delims, &ptr);
1457 if (strcmp(ret_result, "true") == 0){
1458 free((void *)mfx->removable);
1459 mfx->removable = strdup("true");
1460 } else if (strcmp(ret_result, "false") == 0) {
1461 free((void *)mfx->removable);
1462 mfx->removable = strdup("false");
1464 /*check tag : not matched*/
1466 _LOGD("tag process [%s]is not defined\n", ret_result);
1470 /*check next value*/
1471 if (tagv[++i] != NULL)
1472 tag = strdup(tagv[i]);
1474 _LOGD("tag process success...\n");
1480 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1482 __save_xml_attribute(reader, "section", &icon->section, NULL);
1483 __save_xml_attribute(reader, "size", &icon->size, NULL);
1484 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1485 __save_xml_lang(reader, &icon->lang);
1487 xmlTextReaderRead(reader);
1488 char *text = ASCII(xmlTextReaderValue(reader));
1490 icon->text = __get_icon_with_path(text, uid);
1497 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1499 __save_xml_attribute(reader, "section", &image->section, NULL);
1500 __save_xml_lang(reader, &image->lang);
1501 __save_xml_value(reader, &image->text);
1505 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1507 __save_xml_attribute(reader, "name", &label->name, NULL);
1508 __save_xml_lang(reader, &label->lang);
1509 __save_xml_value(reader, &label->text);
1514 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1516 __save_xml_attribute(reader, "email", &author->email, NULL);
1517 __save_xml_attribute(reader, "href", &author->href, NULL);
1518 __save_xml_value(reader, &author->text);
1522 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1524 __save_xml_lang(reader, &description->lang);
1525 __save_xml_value(reader, &description->text);
1529 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1531 __save_xml_lang(reader, &license->lang);
1532 __save_xml_value(reader, &license->text);
1536 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1538 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1539 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1540 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1544 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
1546 __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
1547 __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
1548 __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
1549 __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
1550 __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
1551 __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
1552 __save_xml_attribute(reader, "color-depth", &splashscreen->color_depth, NULL);
1556 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
1558 const xmlChar *node;
1561 splashscreen_x *splashscreen;
1563 depth = xmlTextReaderDepth(reader);
1564 while ((ret = __next_child_element(reader, depth))) {
1565 node = xmlTextReaderConstName(reader);
1567 _LOGD("xmlTextReaderConstName value is NULL\n");
1571 if (strcmp(ASCII(node), "splash-screen") == 0) {
1572 splashscreen = calloc(1, sizeof(splashscreen_x));
1573 if (splashscreen == NULL) {
1574 _LOGD("Malloc Failed\n");
1577 *splashscreens = g_list_append(*splashscreens, splashscreen);
1578 ret = __ps_process_splashscreen(reader, splashscreen);
1584 _LOGD("Processing splash-screen failed\n");
1591 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
1593 const xmlChar *node;
1598 __save_xml_attribute(reader, "appid", &application->appid, NULL);
1599 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1600 __save_xml_attribute(reader, "exec", &application->exec, NULL);
1601 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
1602 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
1603 __save_xml_attribute(reader, "type", &application->type, NULL);
1604 __save_xml_attribute(reader, "categories", &application->categories, NULL);
1605 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
1606 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
1607 __save_xml_attribute(reader, "enabled", &application->enabled, "true");
1608 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
1609 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
1610 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
1611 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
1612 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
1613 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
1614 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
1615 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
1616 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
1617 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
1618 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
1619 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1620 retvm_if(((strcmp(application->component_type, "svcapp") != 0) && (strcmp(application->component_type, "uiapp") != 0) && (strcmp(application->component_type, "widgetapp") != 0)), PM_PARSER_R_ERROR, "invalid component_type[%s]", application->component_type);
1621 __save_xml_attribute(reader, "submode", &application->submode, "false");
1622 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
1623 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
1624 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
1625 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
1626 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
1627 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
1628 __save_xml_attribute(reader, "splash-screen-display", &application->splash_screen_display, "true");
1630 application->package= strdup(package);
1631 /* overwrite some attributes if the app is widgetapp */
1632 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
1633 free((void *)application->nodisplay);
1634 application->nodisplay = strdup("true");
1635 free((void *)application->multiple);
1636 application->multiple = strdup("true");
1637 free((void *)application->type);
1638 application->type = strdup("capp");
1639 free((void *)application->taskmanage);
1640 application->taskmanage = strdup("false");
1641 free((void *)application->indicatordisplay);
1642 application->indicatordisplay = strdup("false");
1645 /* hw-acceleration values are changed from use-GL/not-use-GL/use-system-setting to on/off/default */
1646 if (strcmp(application->hwacceleration, "use-GL") == 0) {
1647 free((void *)application->hwacceleration);
1648 application->hwacceleration = strdup("on");
1649 } else if (strcmp(application->hwacceleration, "not-use-GL") == 0) {
1650 free((void *)application->hwacceleration);
1651 application->hwacceleration = strdup("off");
1652 } else if (strcmp(application->hwacceleration, "use-system-setting") == 0) {
1653 free((void *)application->hwacceleration);
1654 application->hwacceleration = strdup("default");
1657 depth = xmlTextReaderDepth(reader);
1658 while ((ret = __next_child_element(reader, depth))) {
1659 node = xmlTextReaderConstName(reader);
1661 _LOGD("xmlTextReaderConstName value is NULL\n");
1664 if (!strcmp(ASCII(node), "label")) {
1665 label_x *label = calloc(1, sizeof(label_x));
1666 if (label == NULL) {
1667 _LOGD("Malloc Failed\n");
1670 application->label = g_list_append(application->label, label);
1671 ret = __ps_process_label(reader, label);
1672 } else if (!strcmp(ASCII(node), "icon")) {
1673 icon_x *icon = calloc(1, sizeof(icon_x));
1675 _LOGD("Malloc Failed\n");
1678 application->icon = g_list_append(application->icon, icon);
1679 ret = __ps_process_icon(reader, icon, uid);
1680 } else if (!strcmp(ASCII(node), "image")) {
1681 image_x *image = calloc(1, sizeof(image_x));
1682 if (image == NULL) {
1683 _LOGD("Malloc Failed\n");
1686 application->image = g_list_append(application->image, image);
1687 ret = __ps_process_image(reader, image);
1688 } else if (!strcmp(ASCII(node), "category")) {
1690 ret = __ps_process_category(reader, &val);
1692 application->category = g_list_append(application->category, (gpointer)val);
1693 } else if (!strcmp(ASCII(node), "metadata")) {
1694 metadata_x *metadata = calloc(1, sizeof(metadata_x));
1695 if (metadata == NULL) {
1696 _LOGD("Malloc Failed\n");
1699 application->metadata = g_list_append(application->metadata, metadata);
1700 ret = __ps_process_metadata(reader, metadata);
1701 } else if (!strcmp(ASCII(node), "permission")) {
1702 permission_x *permission = calloc(1, sizeof(permission_x));
1703 if (permission == NULL) {
1704 _LOGD("Malloc Failed\n");
1707 application->permission = g_list_append(application->permission, permission);
1708 ret = __ps_process_permission(reader, permission);
1709 } else if (!strcmp(ASCII(node), "app-control")) {
1710 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1711 } else if (!strcmp(ASCII(node), "application-service")) {
1712 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1713 } else if (!strcmp(ASCII(node), "data-share")) {
1714 datashare_x *datashare = calloc(1, sizeof(datashare_x));
1715 if (datashare == NULL) {
1716 _LOGD("Malloc Failed\n");
1719 application->datashare = g_list_append(application->datashare, datashare);
1720 ret = __ps_process_datashare(reader, datashare);
1721 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1722 ret = __ps_process_launchconditions(reader, &application->launchconditions);
1723 } else if (!strcmp(ASCII(node), "notification")) {
1724 notification_x *notification = calloc(1, sizeof(notification_x));
1725 if (notification == NULL) {
1726 _LOGD("Malloc Failed\n");
1729 application->notification = g_list_append(application->notification, notification);
1730 ret = __ps_process_notification(reader, notification);
1731 } else if (!strcmp(ASCII(node), "datacontrol")) {
1732 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
1733 if (datacontrol == NULL) {
1734 _LOGD("Malloc Failed\n");
1737 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
1738 ret = __ps_process_datacontrol(reader, datacontrol);
1739 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
1740 ret = __ps_process_splashscreens(reader, &application->splashscreens);
1744 _LOGD("Processing application failed\n");
1752 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1754 _LOGD("__start_process\n");
1755 const xmlChar *node;
1759 depth = xmlTextReaderDepth(reader);
1760 while ((ret = __next_child_element(reader, depth))) {
1761 node = xmlTextReaderConstName(reader);
1763 _LOGD("xmlTextReaderConstName value is NULL\n");
1767 if (!strcmp(ASCII(node), "label")) {
1768 label_x *label = calloc(1, sizeof(label_x));
1769 if (label == NULL) {
1770 _LOGD("Malloc Failed\n");
1773 mfx->label = g_list_append(mfx->label, label);
1774 ret = __ps_process_label(reader, label);
1775 } else if (!strcmp(ASCII(node), "author")) {
1776 author_x *author = calloc(1, sizeof(author_x));
1777 if (author == NULL) {
1778 _LOGD("Malloc Failed\n");
1781 mfx->author = g_list_append(mfx->author, author);
1782 ret = __ps_process_author(reader, author);
1783 } else if (!strcmp(ASCII(node), "description")) {
1784 description_x *description = calloc(1, sizeof(description_x));
1785 if (description == NULL) {
1786 _LOGD("Malloc Failed\n");
1789 mfx->description = g_list_append(mfx->description, description);
1790 ret = __ps_process_description(reader, description);
1791 } else if (!strcmp(ASCII(node), "license")) {
1792 license_x *license = calloc(1, sizeof(license_x));
1793 if (license == NULL) {
1794 _LOGD("Malloc Failed\n");
1797 mfx->license = g_list_append(mfx->license, license);
1798 ret = __ps_process_license(reader, license);
1799 } else if (!strcmp(ASCII(node), "privileges")) {
1800 ret = __ps_process_privileges(reader, &mfx->privileges);
1801 } else if (!strcmp(ASCII(node), "ui-application")) {
1802 application_x *application = calloc(1, sizeof(application_x));
1803 if (application == NULL) {
1804 _LOGD("Malloc Failed\n");
1807 mfx->application = g_list_append(mfx->application, application);
1808 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1809 } else if (!strcmp(ASCII(node), "service-application")) {
1810 application_x *application = calloc(1, sizeof(application_x));
1811 if (application == NULL) {
1812 _LOGD("Malloc Failed\n");
1815 mfx->application = g_list_append(mfx->application, application);
1816 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
1817 } else if (!strcmp(ASCII(node), "widget-application")) {
1818 application_x *application = calloc(1, sizeof(application_x));
1819 if (application == NULL) {
1820 _LOGD("Malloc Failed\n");
1823 mfx->application = g_list_append(mfx->application, application);
1824 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
1825 } else if (!strcmp(ASCII(node), "watch-application")) {
1826 application_x *application = calloc(1, sizeof(application_x));
1827 if (application == NULL) {
1828 _LOGD("Malloc Failed\n");
1831 mfx->application = g_list_append(mfx->application, application);
1832 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
1833 } else if (!strcmp(ASCII(node), "icon")) {
1834 icon_x *icon = calloc(1, sizeof(icon_x));
1836 _LOGD("Malloc Failed\n");
1839 mfx->icon = g_list_append(mfx->icon, icon);
1840 ret = __ps_process_icon(reader, icon, uid);
1841 } else if (!strcmp(ASCII(node), "compatibility")) {
1842 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
1843 if (compatibility == NULL) {
1844 _LOGD("Malloc Failed\n");
1847 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
1848 ret = __ps_process_compatibility(reader, compatibility);
1849 } else if (!strcmp(ASCII(node), "shortcut-list")) {
1851 } else if (!strcmp(ASCII(node), "livebox")) {
1853 } else if (!strcmp(ASCII(node), "account")) {
1855 } else if (!strcmp(ASCII(node), "notifications")) {
1857 } else if (!strcmp(ASCII(node), "ime")) {
1859 } else if (!strcmp(ASCII(node), "feature")) {
1862 _LOGI("Unknown element: %s", ASCII(node));
1867 _LOGD("Processing manifest failed\n");
1874 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1876 const xmlChar *node;
1879 if ((ret = __next_child_element(reader, -1))) {
1880 node = xmlTextReaderConstName(reader);
1882 _LOGD("xmlTextReaderConstName value is NULL\n");
1886 if (!strcmp(ASCII(node), "manifest")) {
1887 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1888 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1889 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1890 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1891 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1892 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1893 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1894 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1895 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1896 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1897 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1898 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1899 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1900 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1901 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1903 __save_xml_installed_time(mfx);
1904 __save_xml_root_path(mfx, uid);
1905 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1906 __save_xml_default_value(mfx);
1908 ret = __start_process(reader, mfx, uid);
1910 _LOGD("No Manifest element found\n");
1917 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
1919 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
1921 void *lib_handle = NULL;
1922 int (*appsvc_operation) (const char *, uid_t);
1925 application_x *application;
1927 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1928 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
1932 if ((appsvc_operation =
1933 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1934 _LOGE("can not find symbol \n");
1938 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1939 application = (application_x *)tmp->data;
1940 if (application == NULL)
1942 ret = appsvc_operation(application->appid, uid);
1944 _LOGE("can not operation symbol \n");
1949 dlclose(lib_handle);
1954 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1956 if (!strstr(manifest, getUserManifestPath(uid,
1957 strcmp(mfx->preload, "true") == 0))) {
1958 /* if downloaded app is updated, then update tag set true*/
1960 free((void *)mfx->update);
1961 mfx->update = strdup("true");
1967 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
1969 pkgmgrinfo_basic_free_package((package_x *)mfx);
1972 DEPRECATED API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
1974 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
1975 xmlTextReaderPtr reader;
1976 manifest_x *mfx = NULL;
1978 reader = xmlReaderForFile(manifest, NULL, 0);
1980 mfx = malloc(sizeof(manifest_x));
1982 memset(mfx, '\0', sizeof(manifest_x));
1983 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
1984 _LOGD("Parsing Failed\n");
1985 pkgmgr_parser_free_manifest_xml(mfx);
1988 _LOGD("Parsing Success\n");
1990 _LOGD("Memory allocation error\n");
1992 xmlFreeTextReader(reader);
1994 _LOGD("Unable to create xml reader\n");
2000 DEPRECATED API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
2002 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
2003 xmlTextReaderPtr reader;
2004 manifest_x *mfx = NULL;
2006 reader = xmlReaderForFile(manifest, NULL, 0);
2008 mfx = malloc(sizeof(manifest_x));
2010 memset(mfx, '\0', sizeof(manifest_x));
2011 if (__process_manifest(reader, mfx, uid) < 0) {
2012 _LOGD("Parsing Failed\n");
2013 pkgmgr_parser_free_manifest_xml(mfx);
2016 _LOGD("Parsing Success\n");
2018 _LOGD("Memory allocation error\n");
2020 xmlFreeTextReader(reader);
2022 _LOGD("Unable to create xml reader\n");
2027 API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid)
2029 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid);
2032 API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path)
2034 return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path);
2037 DEPRECATED API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2039 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2040 _LOGD("parsing manifest for installation: %s\n", manifest);
2042 manifest_x *mfx = NULL;
2046 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2047 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2049 _LOGD("Parsing Finished\n");
2051 __ps_process_tag(mfx, tagv);
2053 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2054 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2056 _LOGD("DB Insert Success\n");
2058 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2059 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2061 _LOGD("Creating metadata parser failed\n");
2063 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2065 _LOGD("Creating category parser failed\n");
2067 pkgmgr_parser_free_manifest_xml(mfx);
2068 _LOGD("Free Done\n");
2074 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2076 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2077 _LOGD("parsing manifest for installation: %s\n", manifest);
2078 manifest_x *mfx = NULL;
2082 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2083 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2085 _LOGD("Parsing Finished\n");
2087 __ps_process_tag(mfx, tagv);
2089 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2090 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2092 _LOGD("DB Insert Success\n");
2094 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2095 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2097 _LOGD("Creating metadata parser failed\n");
2098 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2100 _LOGD("Creating category parser failed\n");
2102 pkgmgr_parser_free_manifest_xml(mfx);
2103 _LOGD("Free Done\n");
2109 API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest) {
2110 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2111 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2112 _LOGD("processing manifest_x for installation: %s\n", manifest);
2115 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2116 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2117 _LOGD("DB Insert Success\n");
2122 API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid) {
2123 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2124 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2125 _LOGD("processing manifest_x for installation: %s\n", manifest);
2128 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2129 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2130 _LOGD("DB Insert Success\n");
2135 DEPRECATED API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2137 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2138 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2139 manifest_x *mfx = NULL;
2141 bool preload = false;
2142 bool system = false;
2143 char *csc_path = NULL;
2144 pkgmgrinfo_pkginfo_h handle = NULL;
2147 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2148 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2150 _LOGD("Parsing Finished\n");
2151 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2153 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2154 if (ret != PMINFO_R_OK)
2155 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2156 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2157 if (ret != PMINFO_R_OK)
2158 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2161 free((void *)mfx->preload);
2162 mfx->preload = strdup("true");
2165 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2166 if (ret != PMINFO_R_OK)
2167 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2169 free((void *)mfx->system);
2170 mfx->system = strdup("true");
2173 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2174 if (ret != PMINFO_R_OK)
2175 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2177 if (csc_path != NULL) {
2179 free((void *)mfx->csc_path);
2180 mfx->csc_path = strdup(csc_path);
2183 /*Delete from cert table*/
2184 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2186 _LOGD("Cert Info DB Delete Failed\n");
2190 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2191 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2193 _LOGD("DB Update Success\n");
2195 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2196 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2198 _LOGD("Upgrade metadata parser failed\n");
2200 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2202 _LOGD("Creating category parser failed\n");
2203 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2204 pkgmgr_parser_free_manifest_xml(mfx);
2205 _LOGD("Free Done\n");
2211 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2213 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2214 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2215 manifest_x *mfx = NULL;
2217 bool preload = false;
2218 bool system = false;
2219 char *csc_path = NULL;
2220 pkgmgrinfo_pkginfo_h handle = NULL;
2223 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2224 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2226 _LOGD("Parsing Finished\n");
2227 __check_preload_updated(mfx, manifest, uid);
2229 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2230 if (ret != PMINFO_R_OK)
2231 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2232 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2233 if (ret != PMINFO_R_OK)
2234 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2237 free((void *)mfx->preload);
2238 mfx->preload = strdup("true");
2241 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2242 if (ret != PMINFO_R_OK)
2243 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2246 free((void *)mfx->system);
2247 mfx->system = strdup("true");
2250 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2251 if (ret != PMINFO_R_OK)
2252 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2253 if (csc_path != NULL) {
2255 free((void *)mfx->csc_path);
2256 mfx->csc_path = strdup(csc_path);
2259 /*Delete from cert table*/
2260 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2262 _LOGD("Cert Info DB Delete Failed\n");
2266 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2267 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2268 _LOGD("DB Update Success\n");
2270 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2271 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2273 _LOGD("Upgrade metadata parser failed\n");
2274 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2276 _LOGD("Creating category parser failed\n");
2277 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2278 pkgmgr_parser_free_manifest_xml(mfx);
2279 _LOGD("Free Done\n");
2285 API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest) {
2286 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2287 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2288 _LOGD("pkgmgr_parser_process_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2291 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2292 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2293 _LOGD("DB Update Success\n");
2298 API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid) {
2299 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2300 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2301 _LOGD(" pkgmgr_parser_process_usr_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2304 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2305 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2306 _LOGD("DB Update Success\n");
2311 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2313 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2314 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2316 manifest_x *mfx = NULL;
2319 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2320 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2322 _LOGD("Parsing Finished\n");
2324 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2326 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2328 _LOGD("Removing metadata parser failed\n");
2330 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2332 _LOGD("Creating category parser failed\n");
2334 /*Delete from cert table*/
2335 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2337 _LOGD("Cert Info DB Delete Failed\n");
2341 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2343 _LOGD("DB Delete failed\n");
2345 _LOGD("DB Delete Success\n");
2347 pkgmgr_parser_free_manifest_xml(mfx);
2348 _LOGD("Free Done\n");
2355 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2357 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2358 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2360 manifest_x *mfx = NULL;
2363 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2364 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2366 _LOGD("Parsing Finished\n");
2368 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2370 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2372 _LOGD("Removing metadata parser failed\n");
2374 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2376 _LOGD("Creating category parser failed\n");
2378 /*Delete from cert table*/
2379 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2381 _LOGD("Cert Info DB Delete Failed\n");
2385 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2387 _LOGD("DB Delete failed\n");
2389 _LOGD("DB Delete Success\n");
2391 ret = __ps_remove_appsvc_db(mfx, uid);
2393 _LOGD("Removing appsvc_db failed\n");
2395 _LOGD("Removing appsvc_db Success\n");
2397 pkgmgr_parser_free_manifest_xml(mfx);
2398 _LOGD("Free Done\n");
2404 API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest) {
2405 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2406 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2407 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2410 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2412 _LOGD("DB Delete failed\n");
2414 _LOGD("DB Delete Success\n");
2419 API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid) {
2420 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2421 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2422 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2426 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2428 _LOGD("DB Delete failed\n");
2430 _LOGD("DB Delete Success\n");
2432 ret = __ps_remove_appsvc_db(mfx, uid);
2434 _LOGD("Removing appsvc_db failed\n");
2436 _LOGD("Removing appsvc_db Success\n");
2441 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2442 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2444 if (manifest == NULL) {
2445 _LOGE("manifest file is NULL\n");
2446 return PMINFO_R_EINVAL;
2449 xmlSchemaParserCtxtPtr ctx;
2450 xmlSchemaValidCtxtPtr vctx;
2451 xmlSchemaPtr xschema;
2452 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2454 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2455 return PMINFO_R_ERROR;
2457 xschema = xmlSchemaParse(ctx);
2458 if (xschema == NULL) {
2459 _LOGE("xmlSchemaParse() Failed\n");
2460 return PMINFO_R_ERROR;
2462 vctx = xmlSchemaNewValidCtxt(xschema);
2464 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2465 return PMINFO_R_ERROR;
2467 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2468 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2470 _LOGE("xmlSchemaValidateFile() failed\n");
2471 return PMINFO_R_ERROR;
2472 } else if (ret == 0) {
2473 _LOGD("Manifest is Valid\n");
2476 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2477 return PMINFO_R_ERROR;