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 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
104 API int __is_admin();
106 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, char **xml_attribute, char *default_value)
108 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
110 *xml_attribute = strdup((const char *)attrib_val);
113 if (default_value != NULL) {
114 *xml_attribute = strdup(default_value);
119 static void __save_xml_lang(xmlTextReaderPtr reader, char **xml_attribute)
121 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
122 if (attrib_val != NULL)
123 *xml_attribute = strdup(ASCII(attrib_val));
125 *xml_attribute = strdup(DEFAULT_LOCALE);
128 static void __save_xml_value(xmlTextReaderPtr reader, char **xml_attribute)
130 xmlTextReaderRead(reader);
131 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
134 *xml_attribute = strdup((const char *)attrib_val);
137 static void __save_xml_installed_time(manifest_x *mfx)
139 char buf[PKG_STRING_LEN_MAX] = {'\0'};
143 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
144 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
145 mfx->installed_time = val;
148 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
150 char root[PKG_STRING_LEN_MAX] = { '\0' };
156 tzplatform_set_user(uid);
157 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
158 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
160 mfx->root_path = strdup(root);
162 tzplatform_reset_user();
165 static void __save_xml_default_value(manifest_x * mfx)
167 mfx->preload = strdup("False");
168 mfx->removable = strdup("True");
169 mfx->readonly = strdup("False");
170 mfx->update = strdup("False");
171 mfx->system = strdup("False");
172 mfx->installed_storage= strdup("installed_internal");
173 package = mfx->package;
176 void *__open_lib_handle(char *tag)
178 char *lib_path = NULL;
179 void *lib_handle = NULL;
181 lib_path = __get_parser_plugin(tag);
182 retvm_if(!lib_path, NULL, "lib_path get fail");
184 lib_handle = dlopen(lib_path, RTLD_LAZY);
185 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
190 void __close_lib_handle(void *lib_handle)
195 static void __str_trim(char *input)
197 char *trim_str = input;
202 while (*input != 0) {
203 if (!isspace(*input)) {
216 uid_t uid = getuid();
217 if ((uid_t) 0 == uid )
225 static char * __get_tag_by_key(char *md_key)
229 if (md_key == NULL) {
230 _LOGD("md_key is NULL\n");
234 md_tag = strrchr(md_key, 47) + 1;
237 return strdup(md_tag);
240 static char *__get_metadata_parser_plugin(const char *type)
243 char buffer[1024] = { 0 };
244 char temp_path[1024] = { 0 };
248 _LOGE("invalid argument\n");
252 fp = fopen(PKG_PARSER_CONF_PATH, "r");
254 _LOGE("no matching metadata parser\n");
258 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
259 if (buffer[0] == '#')
264 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
265 path = path + strlen(METADATA_PARSER_NAME);
270 memset(buffer, 0x00, 1024);
277 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
281 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
283 return strdup(temp_path);
286 static char *__get_category_parser_plugin(const char *type)
289 char buffer[1024] = { 0 };
290 char temp_path[1024] = { 0 };
294 _LOGE("invalid argument\n");
298 fp = fopen(PKG_PARSER_CONF_PATH, "r");
300 _LOGE("no matching metadata parser\n");
304 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
305 if (buffer[0] == '#')
310 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
311 path = path + strlen(CATEGORY_PARSER_NAME);
316 memset(buffer, 0x00, 1024);
323 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
327 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
329 return strdup(temp_path);
332 static char *__get_parser_plugin(const char *type)
335 char buffer[1024] = { 0 };
336 char temp_path[1024] = { 0 };
340 _LOGE("invalid argument\n");
344 fp = fopen(PKG_PARSER_CONF_PATH, "r");
346 _LOGE("no matching backendlib\n");
350 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
351 if (buffer[0] == '#')
356 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
357 path = path + strlen(PKG_PARSERLIB);
361 memset(buffer, 0x00, 1024);
368 _LOGE("no matching backendlib\n");
372 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
374 return strdup(temp_path);
377 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
378 ACTION_TYPE action, const char *pkgid)
380 int (*plugin_install) (xmlDocPtr, const char *);
386 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
389 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
391 case ACTION_UNINSTALL:
392 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
398 if ((plugin_install =
399 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
400 _LOGE("can not find symbol[%s] \n", ac);
404 ret = plugin_install(docPtr, pkgid);
405 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
411 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
412 ACTION_TYPE action, const char *pkgid, const char *appid)
414 char *lib_path = NULL;
415 void *lib_handle = NULL;
416 int (*metadata_parser_plugin) (const char *, const char *, GList *);
422 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
425 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
427 case ACTION_UNINSTALL:
428 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
434 lib_path = __get_metadata_parser_plugin(tag);
436 _LOGE("get %s parser fail\n", tag);
440 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
441 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
445 if ((metadata_parser_plugin =
446 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
447 _LOGE("can not find symbol[%s] \n",ac);
451 ret = metadata_parser_plugin(pkgid, appid, md_list);
453 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
455 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
465 static int __ps_run_category_parser(GList *category_list, const char *tag,
466 ACTION_TYPE action, const char *pkgid, const char *appid)
468 char *lib_path = NULL;
469 void *lib_handle = NULL;
470 int (*category_parser_plugin) (const char *, const char *, GList *);
476 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
479 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
481 case ACTION_UNINSTALL:
482 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
488 lib_path = __get_category_parser_plugin(tag);
490 _LOGE("get %s parser fail\n", tag);
494 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
495 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
499 if ((category_parser_plugin =
500 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
501 _LOGE("can not find symbol[%s] \n",ac);
505 ret = category_parser_plugin(pkgid, appid, category_list);
507 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
509 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
519 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
520 ACTION_TYPE action, const char *pkgid)
522 char *lib_path = NULL;
523 void *lib_handle = NULL;
524 int (*plugin_install) (xmlDocPtr, const char *);
530 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
533 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
535 case ACTION_UNINSTALL:
536 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
542 lib_path = __get_parser_plugin(tag);
547 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
548 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
551 if ((plugin_install =
552 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
553 _LOGE("can not find symbol[%s] \n", ac);
557 ret = plugin_install(docPtr, pkgid);
559 _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
561 _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
571 static void __metadata_parser_clear_dir_list(GList* dir_list)
574 __metadata_t* detail = NULL;
577 list = g_list_first(dir_list);
579 detail = (__metadata_t *)list->data;
582 free((void *)detail->key);
584 free((void *)detail->value);
587 list = g_list_next(list);
589 g_list_free(dir_list);
593 static void __category_parser_clear_dir_list(GList* dir_list)
596 __category_t* detail = NULL;
599 list = g_list_first(dir_list);
601 detail = (__category_t *)list->data;
604 free((void *)detail->name);
608 list = g_list_next(list);
610 g_list_free(dir_list);
614 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
619 if (xmlTextReaderDepth(reader) != 1) {
620 _LOGE("Node depth is not 1");
624 if (xmlTextReaderNodeType(reader) != 1) {
625 _LOGE("Node type is not 1");
629 const xmlChar *value;
630 name = xmlTextReaderConstName(reader);
632 _LOGE("TEST TEST TES\n");
633 name = BAD_CAST "--";
636 value = xmlTextReaderConstValue(reader);
638 if (xmlStrlen(value) > 40) {
639 _LOGD(" %.40s...", value);
645 name = xmlTextReaderConstName(reader);
647 _LOGE("TEST TEST TES\n");
648 name = BAD_CAST "--";
651 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
652 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
653 if (copyDocPtr == NULL)
655 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
656 if (rootElement == NULL)
658 xmlNode *cur_node = xmlFirstElementChild(rootElement);
659 if (cur_node == NULL)
661 xmlNode *temp = xmlTextReaderExpand(reader);
664 xmlNode *next_node = NULL;
665 while(cur_node != NULL) {
666 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
667 (temp->line == cur_node->line) ) {
671 next_node = xmlNextElementSibling(cur_node);
672 xmlUnlinkNode(cur_node);
673 xmlFreeNode(cur_node);
674 cur_node = next_node;
677 if (cur_node == NULL)
679 next_node = xmlNextElementSibling(cur_node);
681 cur_node->next = NULL;
682 next_node->prev = NULL;
683 xmlFreeNodeList(next_node);
684 xmlSetTreeDoc(cur_node, copyDocPtr);
686 xmlSetTreeDoc(cur_node, copyDocPtr);
689 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
695 static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
699 char buffer[1024] = { 0, };
702 GList *md_tmp = NULL;
706 GList *md_list = NULL;
707 __metadata_t *md_detail = NULL;
709 md_tag = __get_tag_by_key(md_key);
710 if (md_tag == NULL) {
711 _LOGD("md_tag is NULL\n");
715 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
716 app = (application_x *)app_tmp->data;
719 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
720 md = (metadata_x *)md_tmp->data;
723 //get glist of metadata key and value combination
724 memset(buffer, 0x00, 1024);
725 snprintf(buffer, 1024, "%s/", md_key);
726 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
727 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
728 if (md_detail == NULL) {
729 _LOGD("Memory allocation failed\n");
733 md_detail->key = strdup(md->key);
734 if (md_detail->key == NULL) {
735 _LOGD("Memory allocation failed\n");
740 md_detail->value = strdup(md->value);
741 if (md_detail->value == NULL) {
742 _LOGD("Memory allocation failed\n");
743 free((void *)md_detail->key);
748 md_list = g_list_append(md_list, (gpointer)md_detail);
753 //send glist to parser when tags for metadata plugin parser exist.
755 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
757 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
760 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
763 __metadata_parser_clear_dir_list(md_list);
770 __metadata_parser_clear_dir_list(md_list);
778 static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
782 char buffer[1024] = { 0, };
786 const char *category;
787 char *category_tag = NULL;
789 GList *category_list = NULL;
790 __category_t *category_detail = NULL;
792 category_tag = __get_tag_by_key(category_key);
793 if (category_tag == NULL) {
794 _LOGD("md_tag is NULL\n");
798 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
799 app = (application_x *)app_tmp->data;
802 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
803 category = (const char *)category_tmp->data;
804 //get glist of category key and value combination
805 memset(buffer, 0x00, 1024);
806 snprintf(buffer, 1024, "%s/", category_key);
807 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
808 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
809 if (category_detail == NULL) {
810 _LOGD("Memory allocation failed\n");
814 category_detail->name = strdup(category);
815 if (category_detail->name == NULL) {
816 _LOGD("Memory allocation failed\n");
817 free(category_detail);
821 category_list = g_list_append(category_list, (gpointer)category_detail);
826 //send glist to parser when tags for metadata plugin parser exist.
828 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
830 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
832 _LOGD("category_parser success for tag[%s]\n", category_tag);
834 __category_parser_clear_dir_list(category_list);
835 category_list = NULL;
841 __category_parser_clear_dir_list(category_list);
849 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
851 switch (xmlTextReaderNodeType(reader)) {
852 case XML_READER_TYPE_END_ELEMENT:
856 case XML_READER_TYPE_ELEMENT:
858 // Elements without closing tag don't receive
859 const xmlChar *elementName =
860 xmlTextReaderLocalName(reader);
861 if (elementName == NULL) {
865 if (strcmp(tag, ASCII(elementName)) == 0) {
866 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
867 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
878 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
880 int (*plugin_install) (const char *);
884 if (process == PLUGIN_PRE_PROCESS) {
887 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
890 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
892 case ACTION_UNINSTALL:
893 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
898 } else if (process == PLUGIN_POST_PROCESS) {
901 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
904 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
906 case ACTION_UNINSTALL:
907 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
915 if ((plugin_install =
916 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
920 ret = plugin_install(pkgid);
924 static int __next_child_element(xmlTextReaderPtr reader, int depth)
926 int ret = xmlTextReaderRead(reader);
927 int cur = xmlTextReaderDepth(reader);
930 switch (xmlTextReaderNodeType(reader)) {
931 case XML_READER_TYPE_ELEMENT:
932 if (cur == depth + 1)
935 case XML_READER_TYPE_TEXT:
936 /*text is handled by each function separately*/
937 if (cur == depth + 1)
940 case XML_READER_TYPE_END_ELEMENT:
949 ret = xmlTextReaderRead(reader);
950 cur = xmlTextReaderDepth(reader);
954 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
956 xmlTextReaderPtr reader;
960 void *lib_handle = NULL;
961 char tag[PKG_STRING_LEN_MAX] = { 0 };
963 fp = fopen(TAG_PARSER_LIST, "r");
964 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
966 while (fgets(tag, sizeof(tag), fp) != NULL) {
969 lib_handle = __open_lib_handle(tag);
970 if (lib_handle == NULL)
973 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
974 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
976 docPtr = xmlReadFile(filename, NULL, 0);
977 reader = xmlReaderWalker(docPtr);
978 if (reader != NULL) {
979 ret = xmlTextReaderRead(reader);
981 __process_tag(lib_handle, reader, action, tag, mfx->package);
982 ret = xmlTextReaderRead(reader);
984 xmlFreeTextReader(reader);
987 _LOGD("%s : failed to parse", filename);
990 _LOGD("Unable to open %s", filename);
993 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
994 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
996 __close_lib_handle(lib_handle);
998 memset(tag, 0x00, sizeof(tag));
1007 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1009 fprintf(stdout,"__ps_process_metadata_parser\n");
1012 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1014 fp = fopen(METADATA_PARSER_LIST, "r");
1016 _LOGD("no preload list\n");
1020 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1022 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1033 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1037 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1039 fp = fopen(CATEGORY_PARSER_LIST, "r");
1041 _LOGD("no category parser list\n");
1045 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1046 __str_trim(category_key);
1047 ret = __run_category_parser_prestep(mfx, category_key, action);
1058 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed)
1060 __save_xml_value(reader, allowed);
1064 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition)
1066 __save_xml_attribute(reader, "name", condition, NULL);
1070 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
1072 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
1073 __save_xml_value(reader, ¬ification->text);
1077 static int __ps_process_category(xmlTextReaderPtr reader, char **category)
1079 __save_xml_attribute(reader, "name", category, NULL);
1083 static int __ps_process_privilege(xmlTextReaderPtr reader, char **privilege)
1085 __save_xml_value(reader, privilege);
1089 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
1091 __save_xml_attribute(reader, "key", &metadata->key, NULL);
1092 __save_xml_attribute(reader, "value", &metadata->value, NULL);
1096 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
1098 __save_xml_attribute(reader, "type", &permission->type, NULL);
1099 __save_xml_value(reader, &permission->value);
1103 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
1105 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
1106 __save_xml_value(reader, &compatibility->text);
1110 static int __ps_process_request(xmlTextReaderPtr reader, char **request)
1112 __save_xml_value(reader, request);
1116 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
1118 const xmlChar *node;
1123 __save_xml_attribute(reader, "path", &define->path, NULL);
1125 depth = xmlTextReaderDepth(reader);
1126 while ((ret = __next_child_element(reader, depth))) {
1127 node = xmlTextReaderConstName(reader);
1129 _LOGD("xmlTextReaderConstName value is NULL\n");
1133 if (!strcmp(ASCII(node), "allowed")) {
1135 ret = __ps_process_allowed(reader, &val);
1137 define->allowed = g_list_append(define->allowed, (gpointer)val);
1138 } else if (!strcmp(ASCII(node), "request")) {
1140 ret = __ps_process_request(reader, &val);
1142 define->request = g_list_append(define->request, (gpointer)val);
1147 _LOGD("Processing define failed\n");
1154 struct appcontrol_data {
1159 char operation[BUFSIZE];
1164 static void __ps_process_mime(gpointer data, gpointer user_data)
1166 char *mime = (char *)data;
1167 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1168 appcontrol_x *appcontrol;
1170 snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
1172 appcontrol = calloc(1, sizeof(appcontrol_x));
1173 if (strlen(ad->operation))
1174 appcontrol->operation = strdup(ad->operation);
1175 if (strlen(ad->uri))
1176 appcontrol->uri = strdup(ad->uri);
1177 appcontrol->mime = strdup(ad->mime);
1178 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1181 static void __ps_process_uri(gpointer data, gpointer user_data)
1183 char *uri = (char *)data;
1184 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1185 appcontrol_x *appcontrol;
1187 snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
1189 if (ad->mimes != NULL) {
1190 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1192 appcontrol = calloc(1, sizeof(appcontrol_x));
1193 if (strlen(ad->operation))
1194 appcontrol->operation = strdup(ad->operation);
1195 appcontrol->uri = strdup(ad->uri);
1196 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1200 static void __ps_process_operation(gpointer data, gpointer user_data)
1202 char *operation = (char *)data;
1203 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1204 appcontrol_x *appcontrol;
1206 snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
1208 if (ad->uris != NULL) {
1209 g_list_foreach(ad->uris, __ps_process_uri, user_data);
1210 } else if (ad->mimes != NULL) {
1211 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1213 appcontrol = calloc(1, sizeof(appcontrol_x));
1214 appcontrol->operation = strdup(ad->operation);
1215 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1219 static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
1221 struct appcontrol_data ad = {0, };
1223 ad.operations = operations;
1227 if (ad.operations == NULL)
1230 g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
1232 return ad.appcontrols;
1235 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
1237 const xmlChar *node;
1241 GList *operations = NULL;
1243 GList *mimes = NULL;
1246 depth = xmlTextReaderDepth(reader);
1247 while ((ret = __next_child_element(reader, depth)) > 0) {
1248 node = xmlTextReaderConstName(reader);
1250 _LOGD("xmlTextReaderConstName value is NULL\n");
1255 if (!strcmp(ASCII(node), "operation")) {
1256 __save_xml_attribute(reader, "name", &val, NULL);
1258 operations = g_list_append(operations, (gpointer)val);
1259 _LOGD("operation processing\n");
1260 } else if (!strcmp(ASCII(node), "uri")) {
1261 __save_xml_attribute(reader, "name", &val, NULL);
1263 uris = g_list_append(uris, (gpointer)val);
1264 _LOGD("uri processing\n");
1265 } else if (!strcmp(ASCII(node), "mime")) {
1266 __save_xml_attribute(reader, "name", &val, NULL);
1268 mimes = g_list_append(mimes, (gpointer)val);
1269 _LOGD("mime processing\n");
1270 } else if (!strcmp(ASCII(node), "subapp")) {
1278 _LOGD("Processing appcontrol failed\n");
1279 g_list_free_full(operations, free);
1280 g_list_free_full(uris, free);
1281 g_list_free_full(mimes, free);
1285 result = __make_appcontrol_list(operations, uris, mimes);
1287 *appcontrol = g_list_concat(*appcontrol, result);
1291 g_list_free_full(operations, free);
1292 g_list_free_full(uris, free);
1293 g_list_free_full(mimes, free);
1298 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
1300 const xmlChar *node;
1305 depth = xmlTextReaderDepth(reader);
1306 while ((ret = __next_child_element(reader, depth))) {
1307 node = xmlTextReaderConstName(reader);
1309 _LOGD("xmlTextReaderConstName value is NULL\n");
1313 if (strcmp(ASCII(node), "privilege") == 0) {
1315 ret = __ps_process_privilege(reader, &val);
1317 *privileges = g_list_append(*privileges, (gpointer)val);
1321 _LOGD("Processing privileges failed\n");
1328 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
1330 const xmlChar *node;
1335 depth = xmlTextReaderDepth(reader);
1336 while ((ret = __next_child_element(reader, depth))) {
1337 node = xmlTextReaderConstName(reader);
1339 _LOGD("xmlTextReaderConstName value is NULL\n");
1343 if (strcmp(ASCII(node), "condition") == 0) {
1345 ret = __ps_process_condition(reader, &val);
1347 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
1351 _LOGD("Processing launchconditions failed\n");
1359 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
1361 const xmlChar *node;
1365 depth = xmlTextReaderDepth(reader);
1366 while ((ret = __next_child_element(reader, depth))) {
1367 node = xmlTextReaderConstName(reader);
1369 _LOGD("xmlTextReaderConstName value is NULL\n");
1373 if (!strcmp(ASCII(node), "define")) {
1374 define_x *define = calloc(1, sizeof(define_x));
1375 if (define == NULL) {
1376 _LOGD("Malloc Failed\n");
1379 datashare->define = g_list_append(datashare->define, define);
1380 ret = __ps_process_define(reader, define);
1381 } else if (!strcmp(ASCII(node), "request")) {
1383 ret = __ps_process_request(reader, &val);
1385 datashare->request = g_list_append(datashare->request, (gpointer)val);
1389 _LOGD("Processing data-share failed\n");
1396 static char *__get_icon_with_path(const char *icon, uid_t uid)
1398 char icon_with_path[BUFSIZE];
1399 const char *app_path;
1401 if (!icon || !package)
1404 /* just use absolute path */
1405 if (index(icon, '/'))
1406 return strdup(icon);
1409 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1410 getIconPath(uid, true), icon);
1411 if (access(icon_with_path, F_OK) == 0)
1414 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1415 getIconPath(uid, false), icon);
1416 if (access(icon_with_path, F_OK) == 0)
1419 /* for backward compatibility (.../default/small/...)
1420 * this should be removed
1422 snprintf(icon_with_path, sizeof(icon_with_path),
1423 "%sdefault/small/%s",
1424 getIconPath(uid, true), icon);
1425 if (access(icon_with_path, F_OK) == 0)
1428 snprintf(icon_with_path, sizeof(icon_with_path),
1429 "%sdefault/small/%s",
1430 getIconPath(uid, false), icon);
1431 if (access(icon_with_path, F_OK) == 0)
1434 /* If doesn't exist in case of Global app,
1435 * try to get icon directly into app's directory
1437 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
1438 app_path = tzplatform_getenv(TZ_SYS_RO_APP);
1440 snprintf(icon_with_path, sizeof(icon_with_path),
1441 "%s/%s/%s", app_path, package, icon);
1442 if (access(icon_with_path, F_OK) == 0)
1445 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
1447 snprintf(icon_with_path, sizeof(icon_with_path),
1448 "%s/%s/%s", app_path, package, icon);
1449 if (access(icon_with_path, F_OK) == 0)
1452 tzplatform_set_user(uid);
1453 app_path = tzplatform_getenv(TZ_USER_APP);
1454 tzplatform_reset_user();
1456 snprintf(icon_with_path, sizeof(icon_with_path),
1457 "%s/%s/%s", app_path, package, icon);
1458 if (access(icon_with_path, F_OK) == 0)
1462 /* some preload package has icons at below path */
1463 snprintf(icon_with_path, sizeof(icon_with_path),
1464 "%s/%s/res/icons/%s", app_path, package, icon);
1465 if (access(icon_with_path, F_OK) == 0)
1468 /* since 2.3 tpk package */
1469 snprintf(icon_with_path, sizeof(icon_with_path),
1470 "%s/%s/shared/res/%s", app_path, package, icon);
1471 if (access(icon_with_path, F_OK) == 0)
1474 _LOGE("cannot find icon path for [%s]", icon);
1478 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1480 return strdup(icon_with_path);
1483 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1486 char delims[] = "=";
1487 char *ret_result = NULL;
1494 for (tag = strdup(tagv[0]); tag != NULL; ) {
1495 ret_result = strtok_r(tag, delims, &ptr);
1497 /*check tag : preload */
1498 if (strcmp(ret_result, "preload") == 0) {
1499 ret_result = strtok_r(NULL, delims, &ptr);
1500 if (strcmp(ret_result, "true") == 0) {
1501 free((void *)mfx->preload);
1502 mfx->preload = strdup("true");
1503 } else if (strcmp(ret_result, "false") == 0) {
1504 free((void *)mfx->preload);
1505 mfx->preload = strdup("false");
1507 /*check tag : removable*/
1508 } else if (strcmp(ret_result, "removable") == 0) {
1509 ret_result = strtok_r(NULL, delims, &ptr);
1510 if (strcmp(ret_result, "true") == 0){
1511 free((void *)mfx->removable);
1512 mfx->removable = strdup("true");
1513 } else if (strcmp(ret_result, "false") == 0) {
1514 free((void *)mfx->removable);
1515 mfx->removable = strdup("false");
1517 /*check tag : not matched*/
1519 _LOGD("tag process [%s]is not defined\n", ret_result);
1523 /*check next value*/
1524 if (tagv[++i] != NULL)
1525 tag = strdup(tagv[i]);
1527 _LOGD("tag process success...\n");
1533 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1535 __save_xml_attribute(reader, "section", &icon->section, NULL);
1536 __save_xml_attribute(reader, "size", &icon->size, NULL);
1537 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1538 __save_xml_lang(reader, &icon->lang);
1540 xmlTextReaderRead(reader);
1541 char *text = ASCII(xmlTextReaderValue(reader));
1543 icon->text = __get_icon_with_path(text, uid);
1550 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1552 __save_xml_attribute(reader, "section", &image->section, NULL);
1553 __save_xml_lang(reader, &image->lang);
1554 __save_xml_value(reader, &image->text);
1558 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1560 __save_xml_attribute(reader, "name", &label->name, NULL);
1561 __save_xml_lang(reader, &label->lang);
1562 __save_xml_value(reader, &label->text);
1567 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1569 __save_xml_attribute(reader, "email", &author->email, NULL);
1570 __save_xml_attribute(reader, "href", &author->href, NULL);
1571 __save_xml_value(reader, &author->text);
1575 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1577 __save_xml_lang(reader, &description->lang);
1578 __save_xml_value(reader, &description->text);
1582 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1584 __save_xml_lang(reader, &license->lang);
1585 __save_xml_value(reader, &license->text);
1589 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1591 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1592 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1593 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1597 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
1599 __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
1600 __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
1601 __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
1602 __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
1603 __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
1604 __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
1608 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
1610 const xmlChar *node;
1613 splashscreen_x *splashscreen;
1615 depth = xmlTextReaderDepth(reader);
1616 while ((ret = __next_child_element(reader, depth))) {
1617 node = xmlTextReaderConstName(reader);
1619 _LOGD("xmlTextReaderConstName value is NULL\n");
1623 if (strcmp(ASCII(node), "splash-screen") == 0) {
1624 splashscreen = calloc(1, sizeof(splashscreen_x));
1625 if (splashscreen == NULL) {
1626 _LOGD("Malloc Failed\n");
1629 *splashscreens = g_list_append(*splashscreens, splashscreen);
1630 ret = __ps_process_splashscreen(reader, splashscreen);
1636 _LOGD("Processing splash-screen failed\n");
1643 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
1645 const xmlChar *node;
1650 __save_xml_attribute(reader, "appid", &application->appid, NULL);
1651 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1652 __save_xml_attribute(reader, "exec", &application->exec, NULL);
1653 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
1654 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
1655 __save_xml_attribute(reader, "type", &application->type, NULL);
1656 __save_xml_attribute(reader, "categories", &application->categories, NULL);
1657 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
1658 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
1659 __save_xml_attribute(reader, "enabled", &application->enabled, "true");
1660 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
1661 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
1662 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
1663 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
1664 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
1665 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
1666 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
1667 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
1668 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
1669 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
1670 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
1671 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1672 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);
1673 __save_xml_attribute(reader, "submode", &application->submode, "false");
1674 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
1675 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
1676 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
1677 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
1678 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
1679 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
1681 application->package= strdup(package);
1682 /* overwrite some attributes if the app is widgetapp */
1683 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
1684 free((void *)application->nodisplay);
1685 application->nodisplay = strdup("true");
1686 free((void *)application->multiple);
1687 application->multiple = strdup("true");
1688 free((void *)application->type);
1689 application->type = strdup("capp");
1690 free((void *)application->taskmanage);
1691 application->taskmanage = strdup("false");
1692 free((void *)application->indicatordisplay);
1693 application->indicatordisplay = strdup("false");
1696 depth = xmlTextReaderDepth(reader);
1697 while ((ret = __next_child_element(reader, depth))) {
1698 node = xmlTextReaderConstName(reader);
1700 _LOGD("xmlTextReaderConstName value is NULL\n");
1703 if (!strcmp(ASCII(node), "label")) {
1704 label_x *label = calloc(1, sizeof(label_x));
1705 if (label == NULL) {
1706 _LOGD("Malloc Failed\n");
1709 application->label = g_list_append(application->label, label);
1710 ret = __ps_process_label(reader, label);
1711 } else if (!strcmp(ASCII(node), "icon")) {
1712 icon_x *icon = calloc(1, sizeof(icon_x));
1714 _LOGD("Malloc Failed\n");
1717 application->icon = g_list_append(application->icon, icon);
1718 ret = __ps_process_icon(reader, icon, uid);
1719 } else if (!strcmp(ASCII(node), "image")) {
1720 image_x *image = calloc(1, sizeof(image_x));
1721 if (image == NULL) {
1722 _LOGD("Malloc Failed\n");
1725 application->image = g_list_append(application->image, image);
1726 ret = __ps_process_image(reader, image);
1727 } else if (!strcmp(ASCII(node), "category")) {
1729 ret = __ps_process_category(reader, &val);
1731 application->category = g_list_append(application->category, (gpointer)val);
1732 } else if (!strcmp(ASCII(node), "metadata")) {
1733 metadata_x *metadata = calloc(1, sizeof(metadata_x));
1734 if (metadata == NULL) {
1735 _LOGD("Malloc Failed\n");
1738 application->metadata = g_list_append(application->metadata, metadata);
1739 ret = __ps_process_metadata(reader, metadata);
1740 } else if (!strcmp(ASCII(node), "permission")) {
1741 permission_x *permission = calloc(1, sizeof(permission_x));
1742 if (permission == NULL) {
1743 _LOGD("Malloc Failed\n");
1746 application->permission = g_list_append(application->permission, permission);
1747 ret = __ps_process_permission(reader, permission);
1748 } else if (!strcmp(ASCII(node), "app-control")) {
1749 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1750 } else if (!strcmp(ASCII(node), "application-service")) {
1751 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1752 } else if (!strcmp(ASCII(node), "data-share")) {
1753 datashare_x *datashare = calloc(1, sizeof(datashare_x));
1754 if (datashare == NULL) {
1755 _LOGD("Malloc Failed\n");
1758 application->datashare = g_list_append(application->datashare, datashare);
1759 ret = __ps_process_datashare(reader, datashare);
1760 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1761 ret = __ps_process_launchconditions(reader, &application->launchconditions);
1762 } else if (!strcmp(ASCII(node), "notification")) {
1763 notification_x *notification = calloc(1, sizeof(notification_x));
1764 if (notification == NULL) {
1765 _LOGD("Malloc Failed\n");
1768 application->notification = g_list_append(application->notification, notification);
1769 ret = __ps_process_notification(reader, notification);
1770 } else if (!strcmp(ASCII(node), "datacontrol")) {
1771 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
1772 if (datacontrol == NULL) {
1773 _LOGD("Malloc Failed\n");
1776 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
1777 ret = __ps_process_datacontrol(reader, datacontrol);
1778 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
1779 ret = __ps_process_splashscreens(reader, &application->splashscreens);
1783 _LOGD("Processing application failed\n");
1791 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1793 _LOGD("__start_process\n");
1794 const xmlChar *node;
1798 depth = xmlTextReaderDepth(reader);
1799 while ((ret = __next_child_element(reader, depth))) {
1800 node = xmlTextReaderConstName(reader);
1802 _LOGD("xmlTextReaderConstName value is NULL\n");
1806 if (!strcmp(ASCII(node), "label")) {
1807 label_x *label = calloc(1, sizeof(label_x));
1808 if (label == NULL) {
1809 _LOGD("Malloc Failed\n");
1812 mfx->label = g_list_append(mfx->label, label);
1813 ret = __ps_process_label(reader, label);
1814 } else if (!strcmp(ASCII(node), "author")) {
1815 author_x *author = calloc(1, sizeof(author_x));
1816 if (author == NULL) {
1817 _LOGD("Malloc Failed\n");
1820 mfx->author = g_list_append(mfx->author, author);
1821 ret = __ps_process_author(reader, author);
1822 } else if (!strcmp(ASCII(node), "description")) {
1823 description_x *description = calloc(1, sizeof(description_x));
1824 if (description == NULL) {
1825 _LOGD("Malloc Failed\n");
1828 mfx->description = g_list_append(mfx->description, description);
1829 ret = __ps_process_description(reader, description);
1830 } else if (!strcmp(ASCII(node), "license")) {
1831 license_x *license = calloc(1, sizeof(license_x));
1832 if (license == NULL) {
1833 _LOGD("Malloc Failed\n");
1836 mfx->license = g_list_append(mfx->license, license);
1837 ret = __ps_process_license(reader, license);
1838 } else if (!strcmp(ASCII(node), "privileges")) {
1839 ret = __ps_process_privileges(reader, &mfx->privileges);
1840 } else if (!strcmp(ASCII(node), "ui-application")) {
1841 application_x *application = calloc(1, sizeof(application_x));
1842 if (application == NULL) {
1843 _LOGD("Malloc Failed\n");
1846 mfx->application = g_list_append(mfx->application, application);
1847 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1848 } else if (!strcmp(ASCII(node), "service-application")) {
1849 application_x *application = calloc(1, sizeof(application_x));
1850 if (application == NULL) {
1851 _LOGD("Malloc Failed\n");
1854 mfx->application = g_list_append(mfx->application, application);
1855 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
1856 } else if (!strcmp(ASCII(node), "widget-application")) {
1857 application_x *application = calloc(1, sizeof(application_x));
1858 if (application == NULL) {
1859 _LOGD("Malloc Failed\n");
1862 mfx->application = g_list_append(mfx->application, application);
1863 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
1864 } else if (!strcmp(ASCII(node), "watch-application")) {
1865 application_x *application = calloc(1, sizeof(application_x));
1866 if (application == NULL) {
1867 _LOGD("Malloc Failed\n");
1870 mfx->application = g_list_append(mfx->application, application);
1871 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
1872 } else if (!strcmp(ASCII(node), "icon")) {
1873 icon_x *icon = calloc(1, sizeof(icon_x));
1875 _LOGD("Malloc Failed\n");
1878 mfx->icon = g_list_append(mfx->icon, icon);
1879 ret = __ps_process_icon(reader, icon, uid);
1880 } else if (!strcmp(ASCII(node), "compatibility")) {
1881 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
1882 if (compatibility == NULL) {
1883 _LOGD("Malloc Failed\n");
1886 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
1887 ret = __ps_process_compatibility(reader, compatibility);
1888 } else if (!strcmp(ASCII(node), "shortcut-list")) {
1890 } else if (!strcmp(ASCII(node), "livebox")) {
1892 } else if (!strcmp(ASCII(node), "account")) {
1894 } else if (!strcmp(ASCII(node), "notifications")) {
1896 } else if (!strcmp(ASCII(node), "ime")) {
1898 } else if (!strcmp(ASCII(node), "feature")) {
1901 _LOGI("Unknown element: %s", ASCII(node));
1906 _LOGD("Processing manifest failed\n");
1913 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1915 const xmlChar *node;
1918 if ((ret = __next_child_element(reader, -1))) {
1919 node = xmlTextReaderConstName(reader);
1921 _LOGD("xmlTextReaderConstName value is NULL\n");
1925 if (!strcmp(ASCII(node), "manifest")) {
1926 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1927 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1928 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1929 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1930 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1931 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1932 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1933 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1934 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1935 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1936 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1937 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1938 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1939 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1940 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1942 __save_xml_installed_time(mfx);
1943 __save_xml_root_path(mfx, uid);
1944 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1945 __save_xml_default_value(mfx);
1947 ret = __start_process(reader, mfx, uid);
1949 _LOGD("No Manifest element found\n");
1956 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
1958 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
1960 void *lib_handle = NULL;
1961 int (*appsvc_operation) (const char *, uid_t);
1964 application_x *application;
1966 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1967 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
1971 if ((appsvc_operation =
1972 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1973 _LOGE("can not find symbol \n");
1977 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1978 application = (application_x *)tmp->data;
1979 if (application == NULL)
1981 ret = appsvc_operation(application->appid, uid);
1983 _LOGE("can not operation symbol \n");
1988 dlclose(lib_handle);
1993 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1995 if (!strstr(manifest, getUserManifestPath(uid,
1996 strcmp(mfx->preload, "true") == 0))) {
1997 /* if downloaded app is updated, then update tag set true*/
1999 free((void *)mfx->update);
2000 mfx->update = strdup("true");
2006 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
2008 /* desktop file is no longer used */
2012 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
2014 /* desktop file is no longer used */
2019 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
2021 pkgmgrinfo_basic_free_package((package_x *)mfx);
2024 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
2026 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
2027 xmlTextReaderPtr reader;
2028 manifest_x *mfx = NULL;
2030 reader = xmlReaderForFile(manifest, NULL, 0);
2032 mfx = malloc(sizeof(manifest_x));
2034 memset(mfx, '\0', sizeof(manifest_x));
2035 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
2036 _LOGD("Parsing Failed\n");
2037 pkgmgr_parser_free_manifest_xml(mfx);
2040 _LOGD("Parsing Success\n");
2042 _LOGD("Memory allocation error\n");
2044 xmlFreeTextReader(reader);
2046 _LOGD("Unable to create xml reader\n");
2052 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
2054 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
2055 xmlTextReaderPtr reader;
2056 manifest_x *mfx = NULL;
2058 reader = xmlReaderForFile(manifest, NULL, 0);
2060 mfx = malloc(sizeof(manifest_x));
2062 memset(mfx, '\0', sizeof(manifest_x));
2063 if (__process_manifest(reader, mfx, uid) < 0) {
2064 _LOGD("Parsing Failed\n");
2065 pkgmgr_parser_free_manifest_xml(mfx);
2068 _LOGD("Parsing Success\n");
2070 _LOGD("Memory allocation error\n");
2072 xmlFreeTextReader(reader);
2074 _LOGD("Unable to create xml reader\n");
2079 API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid)
2081 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid);
2084 API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path)
2086 return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path);
2089 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2091 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2092 _LOGD("parsing manifest for installation: %s\n", manifest);
2094 manifest_x *mfx = NULL;
2098 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2099 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2101 _LOGD("Parsing Finished\n");
2103 __ps_process_tag(mfx, tagv);
2105 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2106 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2108 _LOGD("DB Insert Success\n");
2110 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2111 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2113 _LOGD("Creating metadata parser failed\n");
2115 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2117 _LOGD("Creating category parser failed\n");
2119 pkgmgr_parser_free_manifest_xml(mfx);
2120 _LOGD("Free Done\n");
2125 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2127 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2128 _LOGD("parsing manifest for installation: %s\n", manifest);
2129 manifest_x *mfx = NULL;
2133 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2134 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2136 _LOGD("Parsing Finished\n");
2138 __ps_process_tag(mfx, tagv);
2140 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2141 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2143 _LOGD("DB Insert Success\n");
2145 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2146 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2148 _LOGD("Creating metadata parser failed\n");
2149 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2151 _LOGD("Creating category parser failed\n");
2153 pkgmgr_parser_free_manifest_xml(mfx);
2154 _LOGD("Free Done\n");
2160 API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest) {
2161 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2162 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2163 _LOGD("processing manifest_x for installation: %s\n", manifest);
2168 _LOGD("Added preload infomation\n");
2170 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2171 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2172 _LOGD("DB Insert Success\n");
2178 API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid) {
2179 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2180 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2181 _LOGD("processing manifest_x for installation: %s\n", manifest);
2185 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2186 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2187 _LOGD("DB Insert Success\n");
2192 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2194 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2195 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2196 manifest_x *mfx = NULL;
2198 bool preload = false;
2199 bool system = false;
2200 char *csc_path = NULL;
2201 pkgmgrinfo_pkginfo_h handle = NULL;
2204 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2205 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2207 _LOGD("Parsing Finished\n");
2208 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2210 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2211 if (ret != PMINFO_R_OK)
2212 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2213 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2214 if (ret != PMINFO_R_OK)
2215 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2218 free((void *)mfx->preload);
2219 mfx->preload = strdup("true");
2222 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2223 if (ret != PMINFO_R_OK)
2224 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2226 free((void *)mfx->system);
2227 mfx->system = strdup("true");
2230 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2231 if (ret != PMINFO_R_OK)
2232 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2234 if (csc_path != NULL) {
2236 free((void *)mfx->csc_path);
2237 mfx->csc_path = strdup(csc_path);
2240 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2241 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2243 _LOGD("DB Update Success\n");
2245 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2246 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2248 _LOGD("Upgrade metadata parser failed\n");
2250 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2252 _LOGD("Creating category parser failed\n");
2253 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2254 pkgmgr_parser_free_manifest_xml(mfx);
2255 _LOGD("Free Done\n");
2261 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2263 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2264 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2265 manifest_x *mfx = NULL;
2267 bool preload = false;
2268 bool system = false;
2269 char *csc_path = NULL;
2270 pkgmgrinfo_pkginfo_h handle = NULL;
2273 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2274 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2276 _LOGD("Parsing Finished\n");
2277 __check_preload_updated(mfx, manifest, uid);
2279 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2280 if (ret != PMINFO_R_OK)
2281 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2282 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2283 if (ret != PMINFO_R_OK)
2284 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2287 free((void *)mfx->preload);
2288 mfx->preload = strdup("true");
2291 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2292 if (ret != PMINFO_R_OK)
2293 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2296 free((void *)mfx->system);
2297 mfx->system = strdup("true");
2300 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2301 if (ret != PMINFO_R_OK)
2302 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2303 if (csc_path != NULL) {
2305 free((void *)mfx->csc_path);
2306 mfx->csc_path = strdup(csc_path);
2309 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2310 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2311 _LOGD("DB Update Success\n");
2313 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2314 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2316 _LOGD("Upgrade metadata parser failed\n");
2317 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2319 _LOGD("Creating category parser failed\n");
2320 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2321 pkgmgr_parser_free_manifest_xml(mfx);
2322 _LOGD("Free Done\n");
2328 API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest) {
2329 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2330 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2331 _LOGD("pkgmgr_parser_process_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2333 bool system = false;
2334 char *csc_path = NULL;
2335 pkgmgrinfo_pkginfo_h handle = NULL;
2339 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2340 if (ret != PMINFO_R_OK)
2341 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2343 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2344 if (ret != PMINFO_R_OK)
2345 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2347 free((void *)mfx->system);
2348 mfx->system = strdup("true");
2351 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2352 if (ret != PMINFO_R_OK)
2353 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2355 if (csc_path != NULL) {
2357 free((void *)mfx->csc_path);
2358 mfx->csc_path = strdup(csc_path);
2361 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2362 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2363 _LOGD("DB Update Success\n");
2364 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2370 API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid) {
2371 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2372 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2373 _LOGD(" pkgmgr_parser_process_usr_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2375 pkgmgrinfo_pkginfo_h handle = NULL;
2379 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2380 if (ret != PMINFO_R_OK)
2381 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2383 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2384 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2385 _LOGD("DB Update Success\n");
2386 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2392 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2394 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2395 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2397 manifest_x *mfx = NULL;
2400 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2401 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2403 _LOGD("Parsing Finished\n");
2405 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2407 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2409 _LOGD("Removing metadata parser failed\n");
2411 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2413 _LOGD("Creating category parser failed\n");
2415 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2417 _LOGD("DB Delete failed\n");
2419 _LOGD("DB Delete Success\n");
2421 pkgmgr_parser_free_manifest_xml(mfx);
2422 _LOGD("Free Done\n");
2429 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2431 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2432 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2434 manifest_x *mfx = NULL;
2437 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2438 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2440 _LOGD("Parsing Finished\n");
2442 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2444 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2446 _LOGD("Removing metadata parser failed\n");
2448 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2450 _LOGD("Creating category parser failed\n");
2452 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2454 _LOGD("DB Delete failed\n");
2456 _LOGD("DB Delete Success\n");
2458 ret = __ps_remove_appsvc_db(mfx, uid);
2460 _LOGD("Removing appsvc_db failed\n");
2462 _LOGD("Removing appsvc_db Success\n");
2464 pkgmgr_parser_free_manifest_xml(mfx);
2465 _LOGD("Free Done\n");
2471 API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest) {
2472 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2473 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2474 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2478 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2480 _LOGD("DB Delete failed\n");
2482 _LOGD("DB Delete Success\n");
2488 API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid) {
2489 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2490 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2491 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2496 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2498 _LOGD("DB Delete failed\n");
2500 _LOGD("DB Delete Success\n");
2502 ret = __ps_remove_appsvc_db(mfx, uid);
2504 _LOGD("Removing appsvc_db failed\n");
2506 _LOGD("Removing appsvc_db Success\n");
2512 API int pkgmgr_parser_parse_manifest_for_preload()
2514 return pkgmgr_parser_update_preload_info_in_db();
2517 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
2519 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
2522 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2524 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
2527 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2529 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
2532 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2534 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
2537 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2539 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2541 if (manifest == NULL) {
2542 _LOGE("manifest file is NULL\n");
2543 return PMINFO_R_EINVAL;
2546 xmlSchemaParserCtxtPtr ctx;
2547 xmlSchemaValidCtxtPtr vctx;
2548 xmlSchemaPtr xschema;
2549 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2551 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2552 return PMINFO_R_ERROR;
2554 xschema = xmlSchemaParse(ctx);
2555 if (xschema == NULL) {
2556 _LOGE("xmlSchemaParse() Failed\n");
2557 return PMINFO_R_ERROR;
2559 vctx = xmlSchemaNewValidCtxt(xschema);
2561 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2562 return PMINFO_R_ERROR;
2564 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2565 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2567 _LOGE("xmlSchemaValidateFile() failed\n");
2568 return PMINFO_R_ERROR;
2569 } else if (ret == 0) {
2570 _LOGD("Manifest is Valid\n");
2573 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2574 return PMINFO_R_ERROR;
2580 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2590 _LOGE("fork failed\n");
2595 int dev_null_fd = open ("/dev/null", O_RDWR);
2596 if (dev_null_fd >= 0)
2598 dup2 (dev_null_fd, 0);/*stdin*/
2599 dup2 (dev_null_fd, 1);/*stdout*/
2600 dup2 (dev_null_fd, 2);/*stderr*/
2603 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
2604 SCHEMA_FILE, NULL) < 0) {
2605 _LOGE("execl error\n");
2615 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
2619 _LOGE("waitpid failed\n");
2625 if(WIFEXITED(status) && !WEXITSTATUS(status))