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) (const 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, const char **privilege);
79 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges);
80 static int __ps_process_allowed(xmlTextReaderPtr reader, const char **allowed);
81 static int __ps_process_condition(xmlTextReaderPtr reader, const char **condition);
82 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
83 static int __ps_process_category(xmlTextReaderPtr reader, const 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, const 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, const 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, const 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, const 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, const char **allowed)
1060 __save_xml_value(reader, allowed);
1064 static int __ps_process_condition(xmlTextReaderPtr reader, const 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, const char **category)
1079 __save_xml_attribute(reader, "name", category, NULL);
1083 static int __ps_process_privilege(xmlTextReaderPtr reader, const 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, const 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;
1493 for (tag = strdup(tagv[0]); tag != NULL; ) {
1494 ret_result = strtok(tag, delims);
1496 /*check tag : preload */
1497 if (strcmp(ret_result, "preload") == 0) {
1498 ret_result = strtok(NULL, delims);
1499 if (strcmp(ret_result, "true") == 0) {
1500 free((void *)mfx->preload);
1501 mfx->preload = strdup("true");
1502 } else if (strcmp(ret_result, "false") == 0) {
1503 free((void *)mfx->preload);
1504 mfx->preload = strdup("false");
1506 /*check tag : removable*/
1507 } else if (strcmp(ret_result, "removable") == 0) {
1508 ret_result = strtok(NULL, delims);
1509 if (strcmp(ret_result, "true") == 0){
1510 free((void *)mfx->removable);
1511 mfx->removable = strdup("true");
1512 } else if (strcmp(ret_result, "false") == 0) {
1513 free((void *)mfx->removable);
1514 mfx->removable = strdup("false");
1516 /*check tag : not matched*/
1518 _LOGD("tag process [%s]is not defined\n", ret_result);
1522 /*check next value*/
1523 if (tagv[++i] != NULL)
1524 tag = strdup(tagv[i]);
1526 _LOGD("tag process success...\n");
1532 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1534 __save_xml_attribute(reader, "section", &icon->section, NULL);
1535 __save_xml_attribute(reader, "size", &icon->size, NULL);
1536 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1537 __save_xml_lang(reader, &icon->lang);
1539 xmlTextReaderRead(reader);
1540 const char *text = ASCII(xmlTextReaderValue(reader));
1542 icon->text = (const char *)__get_icon_with_path(text, uid);
1549 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1551 __save_xml_attribute(reader, "section", &image->section, NULL);
1552 __save_xml_lang(reader, &image->lang);
1553 __save_xml_value(reader, &image->text);
1557 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1559 __save_xml_attribute(reader, "name", &label->name, NULL);
1560 __save_xml_lang(reader, &label->lang);
1561 __save_xml_value(reader, &label->text);
1566 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1568 __save_xml_attribute(reader, "email", &author->email, NULL);
1569 __save_xml_attribute(reader, "href", &author->href, NULL);
1570 __save_xml_value(reader, &author->text);
1574 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1576 __save_xml_lang(reader, &description->lang);
1577 __save_xml_value(reader, &description->text);
1581 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1583 __save_xml_lang(reader, &license->lang);
1584 __save_xml_value(reader, &license->text);
1588 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1590 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1591 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1592 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1596 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
1598 __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
1599 __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
1600 __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
1601 __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
1602 __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
1603 __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
1607 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
1609 const xmlChar *node;
1612 splashscreen_x *splashscreen;
1614 depth = xmlTextReaderDepth(reader);
1615 while ((ret = __next_child_element(reader, depth))) {
1616 node = xmlTextReaderConstName(reader);
1618 _LOGD("xmlTextReaderConstName value is NULL\n");
1622 if (strcmp(ASCII(node), "splash-screen") == 0) {
1623 splashscreen = calloc(1, sizeof(splashscreen_x));
1624 if (splashscreen == NULL) {
1625 _LOGD("Malloc Failed\n");
1628 *splashscreens = g_list_append(*splashscreens, splashscreen);
1629 ret = __ps_process_splashscreen(reader, splashscreen);
1635 _LOGD("Processing splash-screen failed\n");
1642 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
1644 const xmlChar *node;
1649 __save_xml_attribute(reader, "appid", &application->appid, NULL);
1650 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1651 __save_xml_attribute(reader, "exec", &application->exec, NULL);
1652 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
1653 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
1654 __save_xml_attribute(reader, "type", &application->type, NULL);
1655 __save_xml_attribute(reader, "categories", &application->categories, NULL);
1656 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
1657 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
1658 __save_xml_attribute(reader, "enabled", &application->enabled, "true");
1659 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
1660 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
1661 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
1662 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
1663 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
1664 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
1665 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
1666 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
1667 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
1668 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
1669 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
1670 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1671 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);
1672 __save_xml_attribute(reader, "submode", &application->submode, "false");
1673 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
1674 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
1675 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
1676 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
1677 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
1678 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
1680 application->package= strdup(package);
1681 /* overwrite some attributes if the app is widgetapp */
1682 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
1683 free((void *)application->nodisplay);
1684 application->nodisplay = strdup("true");
1685 free((void *)application->multiple);
1686 application->multiple = strdup("true");
1687 free((void *)application->type);
1688 application->type = strdup("capp");
1689 free((void *)application->taskmanage);
1690 application->taskmanage = strdup("false");
1691 free((void *)application->indicatordisplay);
1692 application->indicatordisplay = strdup("false");
1695 depth = xmlTextReaderDepth(reader);
1696 while ((ret = __next_child_element(reader, depth))) {
1697 node = xmlTextReaderConstName(reader);
1699 _LOGD("xmlTextReaderConstName value is NULL\n");
1702 if (!strcmp(ASCII(node), "label")) {
1703 label_x *label = calloc(1, sizeof(label_x));
1704 if (label == NULL) {
1705 _LOGD("Malloc Failed\n");
1708 application->label = g_list_append(application->label, label);
1709 ret = __ps_process_label(reader, label);
1710 } else if (!strcmp(ASCII(node), "icon")) {
1711 icon_x *icon = calloc(1, sizeof(icon_x));
1713 _LOGD("Malloc Failed\n");
1716 application->icon = g_list_append(application->icon, icon);
1717 ret = __ps_process_icon(reader, icon, uid);
1718 } else if (!strcmp(ASCII(node), "image")) {
1719 image_x *image = calloc(1, sizeof(image_x));
1720 if (image == NULL) {
1721 _LOGD("Malloc Failed\n");
1724 application->image = g_list_append(application->image, image);
1725 ret = __ps_process_image(reader, image);
1726 } else if (!strcmp(ASCII(node), "category")) {
1728 ret = __ps_process_category(reader, &val);
1730 application->category = g_list_append(application->category, (gpointer)val);
1731 } else if (!strcmp(ASCII(node), "metadata")) {
1732 metadata_x *metadata = calloc(1, sizeof(metadata_x));
1733 if (metadata == NULL) {
1734 _LOGD("Malloc Failed\n");
1737 application->metadata = g_list_append(application->metadata, metadata);
1738 ret = __ps_process_metadata(reader, metadata);
1739 } else if (!strcmp(ASCII(node), "permission")) {
1740 permission_x *permission = calloc(1, sizeof(permission_x));
1741 if (permission == NULL) {
1742 _LOGD("Malloc Failed\n");
1745 application->permission = g_list_append(application->permission, permission);
1746 ret = __ps_process_permission(reader, permission);
1747 } else if (!strcmp(ASCII(node), "app-control")) {
1748 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1749 } else if (!strcmp(ASCII(node), "application-service")) {
1750 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1751 } else if (!strcmp(ASCII(node), "data-share")) {
1752 datashare_x *datashare = calloc(1, sizeof(datashare_x));
1753 if (datashare == NULL) {
1754 _LOGD("Malloc Failed\n");
1757 application->datashare = g_list_append(application->datashare, datashare);
1758 ret = __ps_process_datashare(reader, datashare);
1759 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1760 ret = __ps_process_launchconditions(reader, &application->launchconditions);
1761 } else if (!strcmp(ASCII(node), "notification")) {
1762 notification_x *notification = calloc(1, sizeof(notification_x));
1763 if (notification == NULL) {
1764 _LOGD("Malloc Failed\n");
1767 application->notification = g_list_append(application->notification, notification);
1768 ret = __ps_process_notification(reader, notification);
1769 } else if (!strcmp(ASCII(node), "datacontrol")) {
1770 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
1771 if (datacontrol == NULL) {
1772 _LOGD("Malloc Failed\n");
1775 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
1776 ret = __ps_process_datacontrol(reader, datacontrol);
1777 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
1778 ret = __ps_process_splashscreens(reader, &application->splashscreens);
1782 _LOGD("Processing application failed\n");
1790 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1792 _LOGD("__start_process\n");
1793 const xmlChar *node;
1797 depth = xmlTextReaderDepth(reader);
1798 while ((ret = __next_child_element(reader, depth))) {
1799 node = xmlTextReaderConstName(reader);
1801 _LOGD("xmlTextReaderConstName value is NULL\n");
1805 if (!strcmp(ASCII(node), "label")) {
1806 label_x *label = calloc(1, sizeof(label_x));
1807 if (label == NULL) {
1808 _LOGD("Malloc Failed\n");
1811 mfx->label = g_list_append(mfx->label, label);
1812 ret = __ps_process_label(reader, label);
1813 } else if (!strcmp(ASCII(node), "author")) {
1814 author_x *author = calloc(1, sizeof(author_x));
1815 if (author == NULL) {
1816 _LOGD("Malloc Failed\n");
1819 mfx->author = g_list_append(mfx->author, author);
1820 ret = __ps_process_author(reader, author);
1821 } else if (!strcmp(ASCII(node), "description")) {
1822 description_x *description = calloc(1, sizeof(description_x));
1823 if (description == NULL) {
1824 _LOGD("Malloc Failed\n");
1827 mfx->description = g_list_append(mfx->description, description);
1828 ret = __ps_process_description(reader, description);
1829 } else if (!strcmp(ASCII(node), "license")) {
1830 license_x *license = calloc(1, sizeof(license_x));
1831 if (license == NULL) {
1832 _LOGD("Malloc Failed\n");
1835 mfx->license = g_list_append(mfx->license, license);
1836 ret = __ps_process_license(reader, license);
1837 } else if (!strcmp(ASCII(node), "privileges")) {
1838 ret = __ps_process_privileges(reader, &mfx->privileges);
1839 } else if (!strcmp(ASCII(node), "ui-application")) {
1840 application_x *application = calloc(1, sizeof(application_x));
1841 if (application == NULL) {
1842 _LOGD("Malloc Failed\n");
1845 mfx->application = g_list_append(mfx->application, application);
1846 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1847 } else if (!strcmp(ASCII(node), "service-application")) {
1848 application_x *application = calloc(1, sizeof(application_x));
1849 if (application == NULL) {
1850 _LOGD("Malloc Failed\n");
1853 mfx->application = g_list_append(mfx->application, application);
1854 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
1855 } else if (!strcmp(ASCII(node), "widget-application")) {
1856 application_x *application = calloc(1, sizeof(application_x));
1857 if (application == NULL) {
1858 _LOGD("Malloc Failed\n");
1861 mfx->application = g_list_append(mfx->application, application);
1862 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
1863 } else if (!strcmp(ASCII(node), "watch-application")) {
1864 application_x *application = calloc(1, sizeof(application_x));
1865 if (application == NULL) {
1866 _LOGD("Malloc Failed\n");
1869 mfx->application = g_list_append(mfx->application, application);
1870 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
1871 } else if (!strcmp(ASCII(node), "icon")) {
1872 icon_x *icon = calloc(1, sizeof(icon_x));
1874 _LOGD("Malloc Failed\n");
1877 mfx->icon = g_list_append(mfx->icon, icon);
1878 ret = __ps_process_icon(reader, icon, uid);
1879 } else if (!strcmp(ASCII(node), "compatibility")) {
1880 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
1881 if (compatibility == NULL) {
1882 _LOGD("Malloc Failed\n");
1885 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
1886 ret = __ps_process_compatibility(reader, compatibility);
1887 } else if (!strcmp(ASCII(node), "shortcut-list")) {
1889 } else if (!strcmp(ASCII(node), "livebox")) {
1891 } else if (!strcmp(ASCII(node), "account")) {
1893 } else if (!strcmp(ASCII(node), "notifications")) {
1895 } else if (!strcmp(ASCII(node), "ime")) {
1897 } else if (!strcmp(ASCII(node), "feature")) {
1900 _LOGI("Unknown element: %s", ASCII(node));
1905 _LOGD("Processing manifest failed\n");
1912 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1914 const xmlChar *node;
1917 if ((ret = __next_child_element(reader, -1))) {
1918 node = xmlTextReaderConstName(reader);
1920 _LOGD("xmlTextReaderConstName value is NULL\n");
1924 if (!strcmp(ASCII(node), "manifest")) {
1925 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1926 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1927 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1928 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1929 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1930 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1931 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1932 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1933 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1934 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1935 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1936 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1937 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1938 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1939 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1941 __save_xml_installed_time(mfx);
1942 __save_xml_root_path(mfx, uid);
1943 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1944 __save_xml_default_value(mfx);
1946 ret = __start_process(reader, mfx, uid);
1948 _LOGD("No Manifest element found\n");
1955 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
1957 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
1959 void *lib_handle = NULL;
1960 int (*appsvc_operation) (const char *, uid_t);
1963 application_x *application;
1965 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1966 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
1970 if ((appsvc_operation =
1971 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1972 _LOGE("can not find symbol \n");
1976 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1977 application = (application_x *)tmp->data;
1978 if (application == NULL)
1980 ret = appsvc_operation(application->appid, uid);
1982 _LOGE("can not operation symbol \n");
1987 dlclose(lib_handle);
1992 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1994 if (!strstr(manifest, getUserManifestPath(uid,
1995 strcmp(mfx->preload, "true") == 0))) {
1996 /* if downloaded app is updated, then update tag set true*/
1998 free((void *)mfx->update);
1999 mfx->update = strdup("true");
2005 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
2007 /* desktop file is no longer used */
2011 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
2013 /* desktop file is no longer used */
2018 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
2020 pkgmgrinfo_basic_free_package((package_x *)mfx);
2023 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
2025 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
2026 xmlTextReaderPtr reader;
2027 manifest_x *mfx = NULL;
2029 reader = xmlReaderForFile(manifest, NULL, 0);
2031 mfx = malloc(sizeof(manifest_x));
2033 memset(mfx, '\0', sizeof(manifest_x));
2034 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
2035 _LOGD("Parsing Failed\n");
2036 pkgmgr_parser_free_manifest_xml(mfx);
2039 _LOGD("Parsing Success\n");
2041 _LOGD("Memory allocation error\n");
2043 xmlFreeTextReader(reader);
2045 _LOGD("Unable to create xml reader\n");
2051 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
2053 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
2054 xmlTextReaderPtr reader;
2055 manifest_x *mfx = NULL;
2057 reader = xmlReaderForFile(manifest, NULL, 0);
2059 mfx = malloc(sizeof(manifest_x));
2061 memset(mfx, '\0', sizeof(manifest_x));
2062 if (__process_manifest(reader, mfx, uid) < 0) {
2063 _LOGD("Parsing Failed\n");
2064 pkgmgr_parser_free_manifest_xml(mfx);
2067 _LOGD("Parsing Success\n");
2069 _LOGD("Memory allocation error\n");
2071 xmlFreeTextReader(reader);
2073 _LOGD("Unable to create xml reader\n");
2078 API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid)
2080 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid);
2083 API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path)
2085 return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path);
2088 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2090 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2091 _LOGD("parsing manifest for installation: %s\n", manifest);
2093 manifest_x *mfx = NULL;
2097 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2098 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2100 _LOGD("Parsing Finished\n");
2102 __ps_process_tag(mfx, tagv);
2104 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2105 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2107 _LOGD("DB Insert Success\n");
2109 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2110 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2112 _LOGD("Creating metadata parser failed\n");
2114 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2116 _LOGD("Creating category parser failed\n");
2118 pkgmgr_parser_free_manifest_xml(mfx);
2119 _LOGD("Free Done\n");
2124 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2126 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2127 _LOGD("parsing manifest for installation: %s\n", manifest);
2128 manifest_x *mfx = NULL;
2132 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2133 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2135 _LOGD("Parsing Finished\n");
2137 __ps_process_tag(mfx, tagv);
2139 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2140 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2142 _LOGD("DB Insert Success\n");
2144 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2145 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2147 _LOGD("Creating metadata parser failed\n");
2148 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2150 _LOGD("Creating category parser failed\n");
2152 pkgmgr_parser_free_manifest_xml(mfx);
2153 _LOGD("Free Done\n");
2159 API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest) {
2160 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2161 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2162 _LOGD("processing manifest_x for installation: %s\n", manifest);
2167 _LOGD("Added preload infomation\n");
2169 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2170 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2171 _LOGD("DB Insert Success\n");
2177 API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid) {
2178 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2179 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2180 _LOGD("processing manifest_x for installation: %s\n", manifest);
2184 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2185 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2186 _LOGD("DB Insert Success\n");
2191 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2193 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2194 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2195 manifest_x *mfx = NULL;
2197 bool preload = false;
2198 bool system = false;
2199 char *csc_path = NULL;
2200 pkgmgrinfo_pkginfo_h handle = NULL;
2203 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2204 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2206 _LOGD("Parsing Finished\n");
2207 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2209 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2210 if (ret != PMINFO_R_OK)
2211 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2212 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2213 if (ret != PMINFO_R_OK)
2214 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2217 free((void *)mfx->preload);
2218 mfx->preload = strdup("true");
2221 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2222 if (ret != PMINFO_R_OK)
2223 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2225 free((void *)mfx->system);
2226 mfx->system = strdup("true");
2229 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2230 if (ret != PMINFO_R_OK)
2231 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2233 if (csc_path != NULL) {
2235 free((void *)mfx->csc_path);
2236 mfx->csc_path = strdup(csc_path);
2239 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2240 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2242 _LOGD("DB Update Success\n");
2244 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2245 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2247 _LOGD("Upgrade metadata parser failed\n");
2249 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2251 _LOGD("Creating category parser failed\n");
2252 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2253 pkgmgr_parser_free_manifest_xml(mfx);
2254 _LOGD("Free Done\n");
2260 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2262 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2263 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2264 manifest_x *mfx = NULL;
2266 bool preload = false;
2267 bool system = false;
2268 char *csc_path = NULL;
2269 pkgmgrinfo_pkginfo_h handle = NULL;
2272 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2273 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2275 _LOGD("Parsing Finished\n");
2276 __check_preload_updated(mfx, manifest, uid);
2278 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2279 if (ret != PMINFO_R_OK)
2280 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2281 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2282 if (ret != PMINFO_R_OK)
2283 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2286 free((void *)mfx->preload);
2287 mfx->preload = strdup("true");
2290 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2291 if (ret != PMINFO_R_OK)
2292 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2295 free((void *)mfx->system);
2296 mfx->system = strdup("true");
2299 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2300 if (ret != PMINFO_R_OK)
2301 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2302 if (csc_path != NULL) {
2304 free((void *)mfx->csc_path);
2305 mfx->csc_path = strdup(csc_path);
2308 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2309 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2310 _LOGD("DB Update Success\n");
2312 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2313 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2315 _LOGD("Upgrade metadata parser failed\n");
2316 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2318 _LOGD("Creating category parser failed\n");
2319 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2320 pkgmgr_parser_free_manifest_xml(mfx);
2321 _LOGD("Free Done\n");
2327 API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest) {
2328 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2329 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2330 _LOGD("pkgmgr_parser_process_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2332 bool system = false;
2333 char *csc_path = NULL;
2334 pkgmgrinfo_pkginfo_h handle = NULL;
2338 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2339 if (ret != PMINFO_R_OK)
2340 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2342 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2343 if (ret != PMINFO_R_OK)
2344 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2346 free((void *)mfx->system);
2347 mfx->system = strdup("true");
2350 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2351 if (ret != PMINFO_R_OK)
2352 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2354 if (csc_path != NULL) {
2356 free((void *)mfx->csc_path);
2357 mfx->csc_path = strdup(csc_path);
2360 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2361 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2362 _LOGD("DB Update Success\n");
2363 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2369 API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(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(" pkgmgr_parser_process_usr_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2374 pkgmgrinfo_pkginfo_h handle = NULL;
2378 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2379 if (ret != PMINFO_R_OK)
2380 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2382 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2383 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2384 _LOGD("DB Update Success\n");
2385 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2391 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2393 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2394 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2396 manifest_x *mfx = NULL;
2399 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2400 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2402 _LOGD("Parsing Finished\n");
2404 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2406 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2408 _LOGD("Removing metadata parser failed\n");
2410 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2412 _LOGD("Creating category parser failed\n");
2414 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2416 _LOGD("DB Delete failed\n");
2418 _LOGD("DB Delete Success\n");
2420 pkgmgr_parser_free_manifest_xml(mfx);
2421 _LOGD("Free Done\n");
2428 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2430 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2431 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2433 manifest_x *mfx = NULL;
2436 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2437 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2439 _LOGD("Parsing Finished\n");
2441 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2443 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2445 _LOGD("Removing metadata parser failed\n");
2447 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2449 _LOGD("Creating category parser failed\n");
2451 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2453 _LOGD("DB Delete failed\n");
2455 _LOGD("DB Delete Success\n");
2457 ret = __ps_remove_appsvc_db(mfx, uid);
2459 _LOGD("Removing appsvc_db failed\n");
2461 _LOGD("Removing appsvc_db Success\n");
2463 pkgmgr_parser_free_manifest_xml(mfx);
2464 _LOGD("Free Done\n");
2470 API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest) {
2471 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2472 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2473 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2477 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2479 _LOGD("DB Delete failed\n");
2481 _LOGD("DB Delete Success\n");
2487 API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid) {
2488 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2489 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2490 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2495 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2497 _LOGD("DB Delete failed\n");
2499 _LOGD("DB Delete Success\n");
2501 ret = __ps_remove_appsvc_db(mfx, uid);
2503 _LOGD("Removing appsvc_db failed\n");
2505 _LOGD("Removing appsvc_db Success\n");
2511 API int pkgmgr_parser_parse_manifest_for_preload()
2513 return pkgmgr_parser_update_preload_info_in_db();
2516 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
2518 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
2521 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2523 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
2526 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2528 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
2531 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2533 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
2536 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2538 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2540 if (manifest == NULL) {
2541 _LOGE("manifest file is NULL\n");
2542 return PMINFO_R_EINVAL;
2545 xmlSchemaParserCtxtPtr ctx;
2546 xmlSchemaValidCtxtPtr vctx;
2547 xmlSchemaPtr xschema;
2548 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2550 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2551 return PMINFO_R_ERROR;
2553 xschema = xmlSchemaParse(ctx);
2554 if (xschema == NULL) {
2555 _LOGE("xmlSchemaParse() Failed\n");
2556 return PMINFO_R_ERROR;
2558 vctx = xmlSchemaNewValidCtxt(xschema);
2560 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2561 return PMINFO_R_ERROR;
2563 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2564 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2566 _LOGE("xmlSchemaValidateFile() failed\n");
2567 return PMINFO_R_ERROR;
2568 } else if (ret == 0) {
2569 _LOGD("Manifest is Valid\n");
2572 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2573 return PMINFO_R_ERROR;
2579 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2589 _LOGE("fork failed\n");
2594 int dev_null_fd = open ("/dev/null", O_RDWR);
2595 if (dev_null_fd >= 0)
2597 dup2 (dev_null_fd, 0);/*stdin*/
2598 dup2 (dev_null_fd, 1);/*stdout*/
2599 dup2 (dev_null_fd, 2);/*stderr*/
2602 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
2603 SCHEMA_FILE, NULL) < 0) {
2604 _LOGE("execl error\n");
2614 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
2618 _LOGE("waitpid failed\n");
2624 if(WIFEXITED(status) && !WEXITSTATUS(status))