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 depth = xmlTextReaderDepth(reader);
1646 while ((ret = __next_child_element(reader, depth))) {
1647 node = xmlTextReaderConstName(reader);
1649 _LOGD("xmlTextReaderConstName value is NULL\n");
1652 if (!strcmp(ASCII(node), "label")) {
1653 label_x *label = calloc(1, sizeof(label_x));
1654 if (label == NULL) {
1655 _LOGD("Malloc Failed\n");
1658 application->label = g_list_append(application->label, label);
1659 ret = __ps_process_label(reader, label);
1660 } else if (!strcmp(ASCII(node), "icon")) {
1661 icon_x *icon = calloc(1, sizeof(icon_x));
1663 _LOGD("Malloc Failed\n");
1666 application->icon = g_list_append(application->icon, icon);
1667 ret = __ps_process_icon(reader, icon, uid);
1668 } else if (!strcmp(ASCII(node), "image")) {
1669 image_x *image = calloc(1, sizeof(image_x));
1670 if (image == NULL) {
1671 _LOGD("Malloc Failed\n");
1674 application->image = g_list_append(application->image, image);
1675 ret = __ps_process_image(reader, image);
1676 } else if (!strcmp(ASCII(node), "category")) {
1678 ret = __ps_process_category(reader, &val);
1680 application->category = g_list_append(application->category, (gpointer)val);
1681 } else if (!strcmp(ASCII(node), "metadata")) {
1682 metadata_x *metadata = calloc(1, sizeof(metadata_x));
1683 if (metadata == NULL) {
1684 _LOGD("Malloc Failed\n");
1687 application->metadata = g_list_append(application->metadata, metadata);
1688 ret = __ps_process_metadata(reader, metadata);
1689 } else if (!strcmp(ASCII(node), "permission")) {
1690 permission_x *permission = calloc(1, sizeof(permission_x));
1691 if (permission == NULL) {
1692 _LOGD("Malloc Failed\n");
1695 application->permission = g_list_append(application->permission, permission);
1696 ret = __ps_process_permission(reader, permission);
1697 } else if (!strcmp(ASCII(node), "app-control")) {
1698 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1699 } else if (!strcmp(ASCII(node), "application-service")) {
1700 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1701 } else if (!strcmp(ASCII(node), "data-share")) {
1702 datashare_x *datashare = calloc(1, sizeof(datashare_x));
1703 if (datashare == NULL) {
1704 _LOGD("Malloc Failed\n");
1707 application->datashare = g_list_append(application->datashare, datashare);
1708 ret = __ps_process_datashare(reader, datashare);
1709 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1710 ret = __ps_process_launchconditions(reader, &application->launchconditions);
1711 } else if (!strcmp(ASCII(node), "notification")) {
1712 notification_x *notification = calloc(1, sizeof(notification_x));
1713 if (notification == NULL) {
1714 _LOGD("Malloc Failed\n");
1717 application->notification = g_list_append(application->notification, notification);
1718 ret = __ps_process_notification(reader, notification);
1719 } else if (!strcmp(ASCII(node), "datacontrol")) {
1720 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
1721 if (datacontrol == NULL) {
1722 _LOGD("Malloc Failed\n");
1725 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
1726 ret = __ps_process_datacontrol(reader, datacontrol);
1727 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
1728 ret = __ps_process_splashscreens(reader, &application->splashscreens);
1732 _LOGD("Processing application failed\n");
1740 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1742 _LOGD("__start_process\n");
1743 const xmlChar *node;
1747 depth = xmlTextReaderDepth(reader);
1748 while ((ret = __next_child_element(reader, depth))) {
1749 node = xmlTextReaderConstName(reader);
1751 _LOGD("xmlTextReaderConstName value is NULL\n");
1755 if (!strcmp(ASCII(node), "label")) {
1756 label_x *label = calloc(1, sizeof(label_x));
1757 if (label == NULL) {
1758 _LOGD("Malloc Failed\n");
1761 mfx->label = g_list_append(mfx->label, label);
1762 ret = __ps_process_label(reader, label);
1763 } else if (!strcmp(ASCII(node), "author")) {
1764 author_x *author = calloc(1, sizeof(author_x));
1765 if (author == NULL) {
1766 _LOGD("Malloc Failed\n");
1769 mfx->author = g_list_append(mfx->author, author);
1770 ret = __ps_process_author(reader, author);
1771 } else if (!strcmp(ASCII(node), "description")) {
1772 description_x *description = calloc(1, sizeof(description_x));
1773 if (description == NULL) {
1774 _LOGD("Malloc Failed\n");
1777 mfx->description = g_list_append(mfx->description, description);
1778 ret = __ps_process_description(reader, description);
1779 } else if (!strcmp(ASCII(node), "license")) {
1780 license_x *license = calloc(1, sizeof(license_x));
1781 if (license == NULL) {
1782 _LOGD("Malloc Failed\n");
1785 mfx->license = g_list_append(mfx->license, license);
1786 ret = __ps_process_license(reader, license);
1787 } else if (!strcmp(ASCII(node), "privileges")) {
1788 ret = __ps_process_privileges(reader, &mfx->privileges);
1789 } else if (!strcmp(ASCII(node), "ui-application")) {
1790 application_x *application = calloc(1, sizeof(application_x));
1791 if (application == NULL) {
1792 _LOGD("Malloc Failed\n");
1795 mfx->application = g_list_append(mfx->application, application);
1796 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1797 } else if (!strcmp(ASCII(node), "service-application")) {
1798 application_x *application = calloc(1, sizeof(application_x));
1799 if (application == NULL) {
1800 _LOGD("Malloc Failed\n");
1803 mfx->application = g_list_append(mfx->application, application);
1804 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
1805 } else if (!strcmp(ASCII(node), "widget-application")) {
1806 application_x *application = calloc(1, sizeof(application_x));
1807 if (application == NULL) {
1808 _LOGD("Malloc Failed\n");
1811 mfx->application = g_list_append(mfx->application, application);
1812 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
1813 } else if (!strcmp(ASCII(node), "watch-application")) {
1814 application_x *application = calloc(1, sizeof(application_x));
1815 if (application == NULL) {
1816 _LOGD("Malloc Failed\n");
1819 mfx->application = g_list_append(mfx->application, application);
1820 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
1821 } else if (!strcmp(ASCII(node), "icon")) {
1822 icon_x *icon = calloc(1, sizeof(icon_x));
1824 _LOGD("Malloc Failed\n");
1827 mfx->icon = g_list_append(mfx->icon, icon);
1828 ret = __ps_process_icon(reader, icon, uid);
1829 } else if (!strcmp(ASCII(node), "compatibility")) {
1830 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
1831 if (compatibility == NULL) {
1832 _LOGD("Malloc Failed\n");
1835 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
1836 ret = __ps_process_compatibility(reader, compatibility);
1837 } else if (!strcmp(ASCII(node), "shortcut-list")) {
1839 } else if (!strcmp(ASCII(node), "livebox")) {
1841 } else if (!strcmp(ASCII(node), "account")) {
1843 } else if (!strcmp(ASCII(node), "notifications")) {
1845 } else if (!strcmp(ASCII(node), "ime")) {
1847 } else if (!strcmp(ASCII(node), "feature")) {
1850 _LOGI("Unknown element: %s", ASCII(node));
1855 _LOGD("Processing manifest failed\n");
1862 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1864 const xmlChar *node;
1867 if ((ret = __next_child_element(reader, -1))) {
1868 node = xmlTextReaderConstName(reader);
1870 _LOGD("xmlTextReaderConstName value is NULL\n");
1874 if (!strcmp(ASCII(node), "manifest")) {
1875 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1876 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1877 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1878 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1879 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1880 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1881 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1882 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1883 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1884 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1885 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1886 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1887 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1888 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1889 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1891 __save_xml_installed_time(mfx);
1892 __save_xml_root_path(mfx, uid);
1893 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1894 __save_xml_default_value(mfx);
1896 ret = __start_process(reader, mfx, uid);
1898 _LOGD("No Manifest element found\n");
1905 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
1907 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
1909 void *lib_handle = NULL;
1910 int (*appsvc_operation) (const char *, uid_t);
1913 application_x *application;
1915 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1916 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
1920 if ((appsvc_operation =
1921 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1922 _LOGE("can not find symbol \n");
1926 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1927 application = (application_x *)tmp->data;
1928 if (application == NULL)
1930 ret = appsvc_operation(application->appid, uid);
1932 _LOGE("can not operation symbol \n");
1937 dlclose(lib_handle);
1942 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1944 if (!strstr(manifest, getUserManifestPath(uid,
1945 strcmp(mfx->preload, "true") == 0))) {
1946 /* if downloaded app is updated, then update tag set true*/
1948 free((void *)mfx->update);
1949 mfx->update = strdup("true");
1955 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
1957 pkgmgrinfo_basic_free_package((package_x *)mfx);
1960 DEPRECATED API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
1962 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
1963 xmlTextReaderPtr reader;
1964 manifest_x *mfx = NULL;
1966 reader = xmlReaderForFile(manifest, NULL, 0);
1968 mfx = malloc(sizeof(manifest_x));
1970 memset(mfx, '\0', sizeof(manifest_x));
1971 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
1972 _LOGD("Parsing Failed\n");
1973 pkgmgr_parser_free_manifest_xml(mfx);
1976 _LOGD("Parsing Success\n");
1978 _LOGD("Memory allocation error\n");
1980 xmlFreeTextReader(reader);
1982 _LOGD("Unable to create xml reader\n");
1988 DEPRECATED API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
1990 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
1991 xmlTextReaderPtr reader;
1992 manifest_x *mfx = NULL;
1994 reader = xmlReaderForFile(manifest, NULL, 0);
1996 mfx = malloc(sizeof(manifest_x));
1998 memset(mfx, '\0', sizeof(manifest_x));
1999 if (__process_manifest(reader, mfx, uid) < 0) {
2000 _LOGD("Parsing Failed\n");
2001 pkgmgr_parser_free_manifest_xml(mfx);
2004 _LOGD("Parsing Success\n");
2006 _LOGD("Memory allocation error\n");
2008 xmlFreeTextReader(reader);
2010 _LOGD("Unable to create xml reader\n");
2015 DEPRECATED API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2017 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2018 _LOGD("parsing manifest for installation: %s\n", manifest);
2020 manifest_x *mfx = NULL;
2024 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2025 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2027 _LOGD("Parsing Finished\n");
2029 __ps_process_tag(mfx, tagv);
2031 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2032 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2034 _LOGD("DB Insert Success\n");
2036 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2037 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2039 _LOGD("Creating metadata parser failed\n");
2041 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2043 _LOGD("Creating category parser failed\n");
2045 pkgmgr_parser_free_manifest_xml(mfx);
2046 _LOGD("Free Done\n");
2052 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2054 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2055 _LOGD("parsing manifest for installation: %s\n", manifest);
2056 manifest_x *mfx = NULL;
2060 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2061 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2063 _LOGD("Parsing Finished\n");
2065 __ps_process_tag(mfx, tagv);
2067 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2068 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2070 _LOGD("DB Insert Success\n");
2072 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2073 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2075 _LOGD("Creating metadata parser failed\n");
2076 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2078 _LOGD("Creating category parser failed\n");
2080 pkgmgr_parser_free_manifest_xml(mfx);
2081 _LOGD("Free Done\n");
2087 API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest) {
2088 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2089 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2090 _LOGD("processing manifest_x for installation: %s\n", manifest);
2093 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2094 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2095 _LOGD("DB Insert Success\n");
2100 API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid) {
2101 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2102 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2103 _LOGD("processing manifest_x for installation: %s\n", manifest);
2106 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2107 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2108 _LOGD("DB Insert Success\n");
2113 DEPRECATED API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2115 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2116 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2117 manifest_x *mfx = NULL;
2119 bool preload = false;
2120 bool system = false;
2121 char *csc_path = NULL;
2122 pkgmgrinfo_pkginfo_h handle = NULL;
2125 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2126 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2128 _LOGD("Parsing Finished\n");
2129 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2131 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2132 if (ret != PMINFO_R_OK)
2133 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2134 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2135 if (ret != PMINFO_R_OK)
2136 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2139 free((void *)mfx->preload);
2140 mfx->preload = strdup("true");
2143 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2144 if (ret != PMINFO_R_OK)
2145 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2147 free((void *)mfx->system);
2148 mfx->system = strdup("true");
2151 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2152 if (ret != PMINFO_R_OK)
2153 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2155 if (csc_path != NULL) {
2157 free((void *)mfx->csc_path);
2158 mfx->csc_path = strdup(csc_path);
2161 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2162 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2164 _LOGD("DB Update Success\n");
2166 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2167 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2169 _LOGD("Upgrade metadata parser failed\n");
2171 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2173 _LOGD("Creating category parser failed\n");
2174 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2175 pkgmgr_parser_free_manifest_xml(mfx);
2176 _LOGD("Free Done\n");
2182 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2184 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2185 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2186 manifest_x *mfx = NULL;
2188 bool preload = false;
2189 bool system = false;
2190 char *csc_path = NULL;
2191 pkgmgrinfo_pkginfo_h handle = NULL;
2194 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2195 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2197 _LOGD("Parsing Finished\n");
2198 __check_preload_updated(mfx, manifest, uid);
2200 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2201 if (ret != PMINFO_R_OK)
2202 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2203 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2204 if (ret != PMINFO_R_OK)
2205 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2208 free((void *)mfx->preload);
2209 mfx->preload = strdup("true");
2212 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2213 if (ret != PMINFO_R_OK)
2214 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2217 free((void *)mfx->system);
2218 mfx->system = strdup("true");
2221 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2222 if (ret != PMINFO_R_OK)
2223 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2224 if (csc_path != NULL) {
2226 free((void *)mfx->csc_path);
2227 mfx->csc_path = strdup(csc_path);
2230 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2231 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2232 _LOGD("DB Update Success\n");
2234 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2235 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2237 _LOGD("Upgrade metadata parser failed\n");
2238 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2240 _LOGD("Creating category parser failed\n");
2241 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2242 pkgmgr_parser_free_manifest_xml(mfx);
2243 _LOGD("Free Done\n");
2249 API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest) {
2250 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2251 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2252 _LOGD("pkgmgr_parser_process_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2255 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2256 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2257 _LOGD("DB Update Success\n");
2262 API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid) {
2263 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2264 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2265 _LOGD(" pkgmgr_parser_process_usr_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2268 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2269 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2270 _LOGD("DB Update Success\n");
2275 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2277 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2278 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2280 manifest_x *mfx = NULL;
2283 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2284 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2286 _LOGD("Parsing Finished\n");
2288 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2290 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2292 _LOGD("Removing metadata parser failed\n");
2294 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2296 _LOGD("Creating category parser failed\n");
2298 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2300 _LOGD("DB Delete failed\n");
2302 _LOGD("DB Delete Success\n");
2304 pkgmgr_parser_free_manifest_xml(mfx);
2305 _LOGD("Free Done\n");
2312 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2314 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2315 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2317 manifest_x *mfx = NULL;
2320 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2321 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2323 _LOGD("Parsing Finished\n");
2325 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2327 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2329 _LOGD("Removing metadata parser failed\n");
2331 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2333 _LOGD("Creating category parser failed\n");
2335 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2337 _LOGD("DB Delete failed\n");
2339 _LOGD("DB Delete Success\n");
2341 ret = __ps_remove_appsvc_db(mfx, uid);
2343 _LOGD("Removing appsvc_db failed\n");
2345 _LOGD("Removing appsvc_db Success\n");
2347 pkgmgr_parser_free_manifest_xml(mfx);
2348 _LOGD("Free Done\n");
2354 API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest) {
2355 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2356 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2357 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2360 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2362 _LOGD("DB Delete failed\n");
2364 _LOGD("DB Delete Success\n");
2369 API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid) {
2370 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2371 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2372 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2376 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2378 _LOGD("DB Delete failed\n");
2380 _LOGD("DB Delete Success\n");
2382 ret = __ps_remove_appsvc_db(mfx, uid);
2384 _LOGD("Removing appsvc_db failed\n");
2386 _LOGD("Removing appsvc_db Success\n");
2391 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2392 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2394 if (manifest == NULL) {
2395 _LOGE("manifest file is NULL\n");
2396 return PMINFO_R_EINVAL;
2399 xmlSchemaParserCtxtPtr ctx;
2400 xmlSchemaValidCtxtPtr vctx;
2401 xmlSchemaPtr xschema;
2402 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2404 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2405 return PMINFO_R_ERROR;
2407 xschema = xmlSchemaParse(ctx);
2408 if (xschema == NULL) {
2409 _LOGE("xmlSchemaParse() Failed\n");
2410 return PMINFO_R_ERROR;
2412 vctx = xmlSchemaNewValidCtxt(xschema);
2414 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2415 return PMINFO_R_ERROR;
2417 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2418 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2420 _LOGE("xmlSchemaValidateFile() failed\n");
2421 return PMINFO_R_ERROR;
2422 } else if (ret == 0) {
2423 _LOGD("Manifest is Valid\n");
2426 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2427 return PMINFO_R_ERROR;