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);
1555 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
1557 const xmlChar *node;
1560 splashscreen_x *splashscreen;
1562 depth = xmlTextReaderDepth(reader);
1563 while ((ret = __next_child_element(reader, depth))) {
1564 node = xmlTextReaderConstName(reader);
1566 _LOGD("xmlTextReaderConstName value is NULL\n");
1570 if (strcmp(ASCII(node), "splash-screen") == 0) {
1571 splashscreen = calloc(1, sizeof(splashscreen_x));
1572 if (splashscreen == NULL) {
1573 _LOGD("Malloc Failed\n");
1576 *splashscreens = g_list_append(*splashscreens, splashscreen);
1577 ret = __ps_process_splashscreen(reader, splashscreen);
1583 _LOGD("Processing splash-screen failed\n");
1590 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
1592 const xmlChar *node;
1597 __save_xml_attribute(reader, "appid", &application->appid, NULL);
1598 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1599 __save_xml_attribute(reader, "exec", &application->exec, NULL);
1600 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
1601 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
1602 __save_xml_attribute(reader, "type", &application->type, NULL);
1603 __save_xml_attribute(reader, "categories", &application->categories, NULL);
1604 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
1605 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
1606 __save_xml_attribute(reader, "enabled", &application->enabled, "true");
1607 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
1608 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
1609 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
1610 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
1611 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
1612 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
1613 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
1614 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
1615 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
1616 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
1617 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
1618 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1619 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);
1620 __save_xml_attribute(reader, "submode", &application->submode, "false");
1621 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
1622 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
1623 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
1624 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
1625 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
1626 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
1628 application->package= strdup(package);
1629 /* overwrite some attributes if the app is widgetapp */
1630 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
1631 free((void *)application->nodisplay);
1632 application->nodisplay = strdup("true");
1633 free((void *)application->multiple);
1634 application->multiple = strdup("true");
1635 free((void *)application->type);
1636 application->type = strdup("capp");
1637 free((void *)application->taskmanage);
1638 application->taskmanage = strdup("false");
1639 free((void *)application->indicatordisplay);
1640 application->indicatordisplay = strdup("false");
1643 depth = xmlTextReaderDepth(reader);
1644 while ((ret = __next_child_element(reader, depth))) {
1645 node = xmlTextReaderConstName(reader);
1647 _LOGD("xmlTextReaderConstName value is NULL\n");
1650 if (!strcmp(ASCII(node), "label")) {
1651 label_x *label = calloc(1, sizeof(label_x));
1652 if (label == NULL) {
1653 _LOGD("Malloc Failed\n");
1656 application->label = g_list_append(application->label, label);
1657 ret = __ps_process_label(reader, label);
1658 } else if (!strcmp(ASCII(node), "icon")) {
1659 icon_x *icon = calloc(1, sizeof(icon_x));
1661 _LOGD("Malloc Failed\n");
1664 application->icon = g_list_append(application->icon, icon);
1665 ret = __ps_process_icon(reader, icon, uid);
1666 } else if (!strcmp(ASCII(node), "image")) {
1667 image_x *image = calloc(1, sizeof(image_x));
1668 if (image == NULL) {
1669 _LOGD("Malloc Failed\n");
1672 application->image = g_list_append(application->image, image);
1673 ret = __ps_process_image(reader, image);
1674 } else if (!strcmp(ASCII(node), "category")) {
1676 ret = __ps_process_category(reader, &val);
1678 application->category = g_list_append(application->category, (gpointer)val);
1679 } else if (!strcmp(ASCII(node), "metadata")) {
1680 metadata_x *metadata = calloc(1, sizeof(metadata_x));
1681 if (metadata == NULL) {
1682 _LOGD("Malloc Failed\n");
1685 application->metadata = g_list_append(application->metadata, metadata);
1686 ret = __ps_process_metadata(reader, metadata);
1687 } else if (!strcmp(ASCII(node), "permission")) {
1688 permission_x *permission = calloc(1, sizeof(permission_x));
1689 if (permission == NULL) {
1690 _LOGD("Malloc Failed\n");
1693 application->permission = g_list_append(application->permission, permission);
1694 ret = __ps_process_permission(reader, permission);
1695 } else if (!strcmp(ASCII(node), "app-control")) {
1696 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1697 } else if (!strcmp(ASCII(node), "application-service")) {
1698 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1699 } else if (!strcmp(ASCII(node), "data-share")) {
1700 datashare_x *datashare = calloc(1, sizeof(datashare_x));
1701 if (datashare == NULL) {
1702 _LOGD("Malloc Failed\n");
1705 application->datashare = g_list_append(application->datashare, datashare);
1706 ret = __ps_process_datashare(reader, datashare);
1707 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1708 ret = __ps_process_launchconditions(reader, &application->launchconditions);
1709 } else if (!strcmp(ASCII(node), "notification")) {
1710 notification_x *notification = calloc(1, sizeof(notification_x));
1711 if (notification == NULL) {
1712 _LOGD("Malloc Failed\n");
1715 application->notification = g_list_append(application->notification, notification);
1716 ret = __ps_process_notification(reader, notification);
1717 } else if (!strcmp(ASCII(node), "datacontrol")) {
1718 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
1719 if (datacontrol == NULL) {
1720 _LOGD("Malloc Failed\n");
1723 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
1724 ret = __ps_process_datacontrol(reader, datacontrol);
1725 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
1726 ret = __ps_process_splashscreens(reader, &application->splashscreens);
1730 _LOGD("Processing application failed\n");
1738 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1740 _LOGD("__start_process\n");
1741 const xmlChar *node;
1745 depth = xmlTextReaderDepth(reader);
1746 while ((ret = __next_child_element(reader, depth))) {
1747 node = xmlTextReaderConstName(reader);
1749 _LOGD("xmlTextReaderConstName value is NULL\n");
1753 if (!strcmp(ASCII(node), "label")) {
1754 label_x *label = calloc(1, sizeof(label_x));
1755 if (label == NULL) {
1756 _LOGD("Malloc Failed\n");
1759 mfx->label = g_list_append(mfx->label, label);
1760 ret = __ps_process_label(reader, label);
1761 } else if (!strcmp(ASCII(node), "author")) {
1762 author_x *author = calloc(1, sizeof(author_x));
1763 if (author == NULL) {
1764 _LOGD("Malloc Failed\n");
1767 mfx->author = g_list_append(mfx->author, author);
1768 ret = __ps_process_author(reader, author);
1769 } else if (!strcmp(ASCII(node), "description")) {
1770 description_x *description = calloc(1, sizeof(description_x));
1771 if (description == NULL) {
1772 _LOGD("Malloc Failed\n");
1775 mfx->description = g_list_append(mfx->description, description);
1776 ret = __ps_process_description(reader, description);
1777 } else if (!strcmp(ASCII(node), "license")) {
1778 license_x *license = calloc(1, sizeof(license_x));
1779 if (license == NULL) {
1780 _LOGD("Malloc Failed\n");
1783 mfx->license = g_list_append(mfx->license, license);
1784 ret = __ps_process_license(reader, license);
1785 } else if (!strcmp(ASCII(node), "privileges")) {
1786 ret = __ps_process_privileges(reader, &mfx->privileges);
1787 } else if (!strcmp(ASCII(node), "ui-application")) {
1788 application_x *application = calloc(1, sizeof(application_x));
1789 if (application == NULL) {
1790 _LOGD("Malloc Failed\n");
1793 mfx->application = g_list_append(mfx->application, application);
1794 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1795 } else if (!strcmp(ASCII(node), "service-application")) {
1796 application_x *application = calloc(1, sizeof(application_x));
1797 if (application == NULL) {
1798 _LOGD("Malloc Failed\n");
1801 mfx->application = g_list_append(mfx->application, application);
1802 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
1803 } else if (!strcmp(ASCII(node), "widget-application")) {
1804 application_x *application = calloc(1, sizeof(application_x));
1805 if (application == NULL) {
1806 _LOGD("Malloc Failed\n");
1809 mfx->application = g_list_append(mfx->application, application);
1810 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
1811 } else if (!strcmp(ASCII(node), "watch-application")) {
1812 application_x *application = calloc(1, sizeof(application_x));
1813 if (application == NULL) {
1814 _LOGD("Malloc Failed\n");
1817 mfx->application = g_list_append(mfx->application, application);
1818 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
1819 } else if (!strcmp(ASCII(node), "icon")) {
1820 icon_x *icon = calloc(1, sizeof(icon_x));
1822 _LOGD("Malloc Failed\n");
1825 mfx->icon = g_list_append(mfx->icon, icon);
1826 ret = __ps_process_icon(reader, icon, uid);
1827 } else if (!strcmp(ASCII(node), "compatibility")) {
1828 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
1829 if (compatibility == NULL) {
1830 _LOGD("Malloc Failed\n");
1833 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
1834 ret = __ps_process_compatibility(reader, compatibility);
1835 } else if (!strcmp(ASCII(node), "shortcut-list")) {
1837 } else if (!strcmp(ASCII(node), "livebox")) {
1839 } else if (!strcmp(ASCII(node), "account")) {
1841 } else if (!strcmp(ASCII(node), "notifications")) {
1843 } else if (!strcmp(ASCII(node), "ime")) {
1845 } else if (!strcmp(ASCII(node), "feature")) {
1848 _LOGI("Unknown element: %s", ASCII(node));
1853 _LOGD("Processing manifest failed\n");
1860 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1862 const xmlChar *node;
1865 if ((ret = __next_child_element(reader, -1))) {
1866 node = xmlTextReaderConstName(reader);
1868 _LOGD("xmlTextReaderConstName value is NULL\n");
1872 if (!strcmp(ASCII(node), "manifest")) {
1873 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1874 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1875 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1876 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1877 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1878 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1879 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1880 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1881 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1882 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1883 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1884 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1885 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1886 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1887 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1889 __save_xml_installed_time(mfx);
1890 __save_xml_root_path(mfx, uid);
1891 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1892 __save_xml_default_value(mfx);
1894 ret = __start_process(reader, mfx, uid);
1896 _LOGD("No Manifest element found\n");
1903 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
1905 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
1907 void *lib_handle = NULL;
1908 int (*appsvc_operation) (const char *, uid_t);
1911 application_x *application;
1913 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1914 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
1918 if ((appsvc_operation =
1919 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1920 _LOGE("can not find symbol \n");
1924 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1925 application = (application_x *)tmp->data;
1926 if (application == NULL)
1928 ret = appsvc_operation(application->appid, uid);
1930 _LOGE("can not operation symbol \n");
1935 dlclose(lib_handle);
1940 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1942 if (!strstr(manifest, getUserManifestPath(uid,
1943 strcmp(mfx->preload, "true") == 0))) {
1944 /* if downloaded app is updated, then update tag set true*/
1946 free((void *)mfx->update);
1947 mfx->update = strdup("true");
1953 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
1955 pkgmgrinfo_basic_free_package((package_x *)mfx);
1958 DEPRECATED manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
1960 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
1961 xmlTextReaderPtr reader;
1962 manifest_x *mfx = NULL;
1964 reader = xmlReaderForFile(manifest, NULL, 0);
1966 mfx = malloc(sizeof(manifest_x));
1968 memset(mfx, '\0', sizeof(manifest_x));
1969 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
1970 _LOGD("Parsing Failed\n");
1971 pkgmgr_parser_free_manifest_xml(mfx);
1974 _LOGD("Parsing Success\n");
1976 _LOGD("Memory allocation error\n");
1978 xmlFreeTextReader(reader);
1980 _LOGD("Unable to create xml reader\n");
1986 DEPRECATED manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
1988 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
1989 xmlTextReaderPtr reader;
1990 manifest_x *mfx = NULL;
1992 reader = xmlReaderForFile(manifest, NULL, 0);
1994 mfx = malloc(sizeof(manifest_x));
1996 memset(mfx, '\0', sizeof(manifest_x));
1997 if (__process_manifest(reader, mfx, uid) < 0) {
1998 _LOGD("Parsing Failed\n");
1999 pkgmgr_parser_free_manifest_xml(mfx);
2002 _LOGD("Parsing Success\n");
2004 _LOGD("Memory allocation error\n");
2006 xmlFreeTextReader(reader);
2008 _LOGD("Unable to create xml reader\n");
2013 API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid)
2015 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid);
2018 API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path)
2020 return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path);
2023 DEPRECATED int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2025 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2026 _LOGD("parsing manifest for installation: %s\n", manifest);
2028 manifest_x *mfx = NULL;
2032 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2033 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2035 _LOGD("Parsing Finished\n");
2037 __ps_process_tag(mfx, tagv);
2039 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2040 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2042 _LOGD("DB Insert Success\n");
2044 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2045 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2047 _LOGD("Creating metadata parser failed\n");
2049 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2051 _LOGD("Creating category parser failed\n");
2053 pkgmgr_parser_free_manifest_xml(mfx);
2054 _LOGD("Free Done\n");
2060 DEPRECATED int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2062 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2063 _LOGD("parsing manifest for installation: %s\n", manifest);
2064 manifest_x *mfx = NULL;
2068 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2069 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2071 _LOGD("Parsing Finished\n");
2073 __ps_process_tag(mfx, tagv);
2075 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2076 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2078 _LOGD("DB Insert Success\n");
2080 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2081 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2083 _LOGD("Creating metadata parser failed\n");
2084 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2086 _LOGD("Creating category parser failed\n");
2088 pkgmgr_parser_free_manifest_xml(mfx);
2089 _LOGD("Free Done\n");
2095 API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest) {
2096 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2097 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2098 _LOGD("processing manifest_x for installation: %s\n", manifest);
2101 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2102 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2103 _LOGD("DB Insert Success\n");
2108 API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid) {
2109 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2110 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2111 _LOGD("processing manifest_x for installation: %s\n", manifest);
2114 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2115 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2116 _LOGD("DB Insert Success\n");
2121 DEPRECATED int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2123 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2124 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2125 manifest_x *mfx = NULL;
2127 bool preload = false;
2128 bool system = false;
2129 char *csc_path = NULL;
2130 pkgmgrinfo_pkginfo_h handle = NULL;
2133 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2134 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2136 _LOGD("Parsing Finished\n");
2137 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2139 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2140 if (ret != PMINFO_R_OK)
2141 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2142 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2143 if (ret != PMINFO_R_OK)
2144 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2147 free((void *)mfx->preload);
2148 mfx->preload = strdup("true");
2151 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2152 if (ret != PMINFO_R_OK)
2153 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2155 free((void *)mfx->system);
2156 mfx->system = strdup("true");
2159 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2160 if (ret != PMINFO_R_OK)
2161 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2163 if (csc_path != NULL) {
2165 free((void *)mfx->csc_path);
2166 mfx->csc_path = strdup(csc_path);
2169 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2170 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2172 _LOGD("DB Update Success\n");
2174 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2175 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2177 _LOGD("Upgrade metadata parser failed\n");
2179 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2181 _LOGD("Creating category parser failed\n");
2182 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2183 pkgmgr_parser_free_manifest_xml(mfx);
2184 _LOGD("Free Done\n");
2190 DEPRECATED int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2192 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2193 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2194 manifest_x *mfx = NULL;
2196 bool preload = false;
2197 bool system = false;
2198 char *csc_path = NULL;
2199 pkgmgrinfo_pkginfo_h handle = NULL;
2202 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2203 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2205 _LOGD("Parsing Finished\n");
2206 __check_preload_updated(mfx, manifest, uid);
2208 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2209 if (ret != PMINFO_R_OK)
2210 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2211 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2212 if (ret != PMINFO_R_OK)
2213 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2216 free((void *)mfx->preload);
2217 mfx->preload = strdup("true");
2220 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2221 if (ret != PMINFO_R_OK)
2222 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2225 free((void *)mfx->system);
2226 mfx->system = strdup("true");
2229 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2230 if (ret != PMINFO_R_OK)
2231 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2232 if (csc_path != NULL) {
2234 free((void *)mfx->csc_path);
2235 mfx->csc_path = strdup(csc_path);
2238 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2239 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2240 _LOGD("DB Update Success\n");
2242 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2243 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2245 _LOGD("Upgrade metadata parser failed\n");
2246 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2248 _LOGD("Creating category parser failed\n");
2249 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2250 pkgmgr_parser_free_manifest_xml(mfx);
2251 _LOGD("Free Done\n");
2257 API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest) {
2258 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2259 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2260 _LOGD("pkgmgr_parser_process_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2263 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2264 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2265 _LOGD("DB Update Success\n");
2270 API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid) {
2271 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2272 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2273 _LOGD(" pkgmgr_parser_process_usr_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2276 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2277 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2278 _LOGD("DB Update Success\n");
2283 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2285 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2286 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2288 manifest_x *mfx = NULL;
2291 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2292 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2294 _LOGD("Parsing Finished\n");
2296 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2298 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2300 _LOGD("Removing metadata parser failed\n");
2302 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2304 _LOGD("Creating category parser failed\n");
2306 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2308 _LOGD("DB Delete failed\n");
2310 _LOGD("DB Delete Success\n");
2312 pkgmgr_parser_free_manifest_xml(mfx);
2313 _LOGD("Free Done\n");
2320 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2322 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2323 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2325 manifest_x *mfx = NULL;
2328 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2329 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2331 _LOGD("Parsing Finished\n");
2333 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2335 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2337 _LOGD("Removing metadata parser failed\n");
2339 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2341 _LOGD("Creating category parser failed\n");
2343 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2345 _LOGD("DB Delete failed\n");
2347 _LOGD("DB Delete Success\n");
2349 ret = __ps_remove_appsvc_db(mfx, uid);
2351 _LOGD("Removing appsvc_db failed\n");
2353 _LOGD("Removing appsvc_db Success\n");
2355 pkgmgr_parser_free_manifest_xml(mfx);
2356 _LOGD("Free Done\n");
2362 API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest) {
2363 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2364 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2365 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2368 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2370 _LOGD("DB Delete failed\n");
2372 _LOGD("DB Delete Success\n");
2377 API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid) {
2378 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2379 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2380 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2384 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2386 _LOGD("DB Delete failed\n");
2388 _LOGD("DB Delete Success\n");
2390 ret = __ps_remove_appsvc_db(mfx, uid);
2392 _LOGD("Removing appsvc_db failed\n");
2394 _LOGD("Removing appsvc_db Success\n");
2399 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2400 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2402 if (manifest == NULL) {
2403 _LOGE("manifest file is NULL\n");
2404 return PMINFO_R_EINVAL;
2407 xmlSchemaParserCtxtPtr ctx;
2408 xmlSchemaValidCtxtPtr vctx;
2409 xmlSchemaPtr xschema;
2410 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2412 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2413 return PMINFO_R_ERROR;
2415 xschema = xmlSchemaParse(ctx);
2416 if (xschema == NULL) {
2417 _LOGE("xmlSchemaParse() Failed\n");
2418 return PMINFO_R_ERROR;
2420 vctx = xmlSchemaNewValidCtxt(xschema);
2422 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2423 return PMINFO_R_ERROR;
2425 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2426 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2428 _LOGE("xmlSchemaValidateFile() failed\n");
2429 return PMINFO_R_ERROR;
2430 } else if (ret == 0) {
2431 _LOGD("Manifest is Valid\n");
2434 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2435 return PMINFO_R_ERROR;