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)
78 /* plugin process_type */
80 PLUGIN_PRE_PROCESS = 0,
82 } PLUGIN_PROCESS_TYPE;
95 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label);
96 static int __ps_process_privilege(xmlTextReaderPtr reader, const char **privilege);
97 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges);
98 static int __ps_process_allowed(xmlTextReaderPtr reader, const char **allowed);
99 static int __ps_process_condition(xmlTextReaderPtr reader, const char **condition);
100 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
101 static int __ps_process_category(xmlTextReaderPtr reader, const char **category);
102 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
103 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
104 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
105 static int __ps_process_request(xmlTextReaderPtr reader, const char **request);
106 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
107 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions);
108 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
109 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
110 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
111 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
112 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
113 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol);
114 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
115 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid);
116 static int __next_child_element(xmlTextReaderPtr reader, int depth);
117 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
118 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
119 static void __str_trim(char *input);
120 static char *__get_parser_plugin(const char *type);
121 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
122 API int __is_admin();
124 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, const char **xml_attribute, char *default_value)
126 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
128 *xml_attribute = strdup((const char *)attrib_val);
131 if (default_value != NULL) {
132 *xml_attribute = strdup(default_value);
137 static void __save_xml_lang(xmlTextReaderPtr reader, const char **xml_attribute)
139 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
140 if (attrib_val != NULL)
141 *xml_attribute = strdup(ASCII(attrib_val));
143 *xml_attribute = strdup(DEFAULT_LOCALE);
146 static void __save_xml_value(xmlTextReaderPtr reader, const char **xml_attribute)
148 xmlTextReaderRead(reader);
149 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
152 *xml_attribute = strdup((const char *)attrib_val);
155 static void __save_xml_installed_time(manifest_x *mfx)
157 char buf[PKG_STRING_LEN_MAX] = {'\0'};
161 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
162 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
163 mfx->installed_time = val;
166 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
168 char root[PKG_STRING_LEN_MAX] = { '\0' };
174 tzplatform_set_user(uid);
175 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
176 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
178 mfx->root_path = strdup(root);
180 tzplatform_reset_user();
183 static void __save_xml_default_value(manifest_x * mfx)
185 mfx->preload = strdup("False");
186 mfx->removable = strdup("True");
187 mfx->readonly = strdup("False");
188 mfx->update = strdup("False");
189 mfx->system = strdup("False");
190 mfx->installed_storage= strdup("installed_internal");
191 package = mfx->package;
194 void *__open_lib_handle(char *tag)
196 char *lib_path = NULL;
197 void *lib_handle = NULL;
199 lib_path = __get_parser_plugin(tag);
200 retvm_if(!lib_path, NULL, "lib_path get fail");
202 lib_handle = dlopen(lib_path, RTLD_LAZY);
203 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
208 void __close_lib_handle(void *lib_handle)
213 static void __str_trim(char *input)
215 char *trim_str = input;
220 while (*input != 0) {
221 if (!isspace(*input)) {
234 uid_t uid = getuid();
235 if ((uid_t) 0 == uid )
243 static char * __get_tag_by_key(char *md_key)
247 if (md_key == NULL) {
248 _LOGD("md_key is NULL\n");
252 md_tag = strrchr(md_key, 47) + 1;
255 return strdup(md_tag);
258 static char *__get_metadata_parser_plugin(const char *type)
261 char buffer[1024] = { 0 };
262 char temp_path[1024] = { 0 };
266 _LOGE("invalid argument\n");
270 fp = fopen(PKG_PARSER_CONF_PATH, "r");
272 _LOGE("no matching metadata parser\n");
276 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
277 if (buffer[0] == '#')
282 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
283 path = path + strlen(METADATA_PARSER_NAME);
288 memset(buffer, 0x00, 1024);
295 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
299 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
301 return strdup(temp_path);
304 static char *__get_category_parser_plugin(const char *type)
307 char buffer[1024] = { 0 };
308 char temp_path[1024] = { 0 };
312 _LOGE("invalid argument\n");
316 fp = fopen(PKG_PARSER_CONF_PATH, "r");
318 _LOGE("no matching metadata parser\n");
322 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
323 if (buffer[0] == '#')
328 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
329 path = path + strlen(CATEGORY_PARSER_NAME);
334 memset(buffer, 0x00, 1024);
341 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
345 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
347 return strdup(temp_path);
350 static char *__get_parser_plugin(const char *type)
353 char buffer[1024] = { 0 };
354 char temp_path[1024] = { 0 };
358 _LOGE("invalid argument\n");
362 fp = fopen(PKG_PARSER_CONF_PATH, "r");
364 _LOGE("no matching backendlib\n");
368 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
369 if (buffer[0] == '#')
374 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
375 path = path + strlen(PKG_PARSERLIB);
379 memset(buffer, 0x00, 1024);
386 _LOGE("no matching backendlib\n");
390 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
392 return strdup(temp_path);
395 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
396 ACTION_TYPE action, const char *pkgid)
398 int (*plugin_install) (xmlDocPtr, const char *);
404 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
407 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
409 case ACTION_UNINSTALL:
410 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
416 if ((plugin_install =
417 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
418 _LOGE("can not find symbol[%s] \n", ac);
422 ret = plugin_install(docPtr, pkgid);
423 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
429 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
430 ACTION_TYPE action, const char *pkgid, const char *appid)
432 char *lib_path = NULL;
433 void *lib_handle = NULL;
434 int (*metadata_parser_plugin) (const char *, const char *, GList *);
440 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
443 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
445 case ACTION_UNINSTALL:
446 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
452 lib_path = __get_metadata_parser_plugin(tag);
454 _LOGE("get %s parser fail\n", tag);
458 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
459 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
463 if ((metadata_parser_plugin =
464 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
465 _LOGE("can not find symbol[%s] \n",ac);
469 ret = metadata_parser_plugin(pkgid, appid, md_list);
471 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
473 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
483 static int __ps_run_category_parser(GList *category_list, const char *tag,
484 ACTION_TYPE action, const char *pkgid, const char *appid)
486 char *lib_path = NULL;
487 void *lib_handle = NULL;
488 int (*category_parser_plugin) (const char *, const char *, GList *);
494 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
497 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
499 case ACTION_UNINSTALL:
500 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
506 lib_path = __get_category_parser_plugin(tag);
508 _LOGE("get %s parser fail\n", tag);
512 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
513 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
517 if ((category_parser_plugin =
518 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
519 _LOGE("can not find symbol[%s] \n",ac);
523 ret = category_parser_plugin(pkgid, appid, category_list);
525 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
527 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
537 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
538 ACTION_TYPE action, const char *pkgid)
540 char *lib_path = NULL;
541 void *lib_handle = NULL;
542 int (*plugin_install) (xmlDocPtr, const char *);
548 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
551 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
553 case ACTION_UNINSTALL:
554 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
560 lib_path = __get_parser_plugin(tag);
565 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
566 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
569 if ((plugin_install =
570 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
571 _LOGE("can not find symbol[%s] \n", ac);
575 ret = plugin_install(docPtr, pkgid);
577 _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
579 _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
589 static void __metadata_parser_clear_dir_list(GList* dir_list)
592 __metadata_t* detail = NULL;
595 list = g_list_first(dir_list);
597 detail = (__metadata_t *)list->data;
600 free((void *)detail->key);
602 free((void *)detail->value);
605 list = g_list_next(list);
607 g_list_free(dir_list);
611 static void __category_parser_clear_dir_list(GList* dir_list)
614 __category_t* detail = NULL;
617 list = g_list_first(dir_list);
619 detail = (__category_t *)list->data;
622 free((void *)detail->name);
626 list = g_list_next(list);
628 g_list_free(dir_list);
632 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
637 if (xmlTextReaderDepth(reader) != 1) {
638 _LOGE("Node depth is not 1");
642 if (xmlTextReaderNodeType(reader) != 1) {
643 _LOGE("Node type is not 1");
647 const xmlChar *value;
648 name = xmlTextReaderConstName(reader);
650 _LOGE("TEST TEST TES\n");
651 name = BAD_CAST "--";
654 value = xmlTextReaderConstValue(reader);
656 if (xmlStrlen(value) > 40) {
657 _LOGD(" %.40s...", value);
663 name = xmlTextReaderConstName(reader);
665 _LOGE("TEST TEST TES\n");
666 name = BAD_CAST "--";
669 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
670 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
671 if (copyDocPtr == NULL)
673 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
674 if (rootElement == NULL)
676 xmlNode *cur_node = xmlFirstElementChild(rootElement);
677 if (cur_node == NULL)
679 xmlNode *temp = xmlTextReaderExpand(reader);
682 xmlNode *next_node = NULL;
683 while(cur_node != NULL) {
684 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
685 (temp->line == cur_node->line) ) {
689 next_node = xmlNextElementSibling(cur_node);
690 xmlUnlinkNode(cur_node);
691 xmlFreeNode(cur_node);
692 cur_node = next_node;
695 if (cur_node == NULL)
697 next_node = xmlNextElementSibling(cur_node);
699 cur_node->next = NULL;
700 next_node->prev = NULL;
701 xmlFreeNodeList(next_node);
702 xmlSetTreeDoc(cur_node, copyDocPtr);
704 xmlSetTreeDoc(cur_node, copyDocPtr);
707 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
713 static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
717 char buffer[1024] = { 0, };
720 GList *md_tmp = NULL;
724 GList *md_list = NULL;
725 __metadata_t *md_detail = NULL;
727 md_tag = __get_tag_by_key(md_key);
728 if (md_tag == NULL) {
729 _LOGD("md_tag is NULL\n");
733 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
734 app = (application_x *)app_tmp->data;
737 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
738 md = (metadata_x *)md_tmp->data;
741 //get glist of metadata key and value combination
742 memset(buffer, 0x00, 1024);
743 snprintf(buffer, 1024, "%s/", md_key);
744 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
745 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
746 if (md_detail == NULL) {
747 _LOGD("Memory allocation failed\n");
751 md_detail->key = strdup(md->key);
752 if (md_detail->key == NULL) {
753 _LOGD("Memory allocation failed\n");
758 md_detail->value = strdup(md->value);
759 if (md_detail->value == NULL) {
760 _LOGD("Memory allocation failed\n");
761 free((void *)md_detail->key);
766 md_list = g_list_append(md_list, (gpointer)md_detail);
771 //send glist to parser when tags for metadata plugin parser exist.
773 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
775 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
778 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
781 __metadata_parser_clear_dir_list(md_list);
788 __metadata_parser_clear_dir_list(md_list);
796 static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
800 char buffer[1024] = { 0, };
804 const char *category;
805 char *category_tag = NULL;
807 GList *category_list = NULL;
808 __category_t *category_detail = NULL;
810 category_tag = __get_tag_by_key(category_key);
811 if (category_tag == NULL) {
812 _LOGD("md_tag is NULL\n");
816 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
817 app = (application_x *)app_tmp->data;
820 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
821 category = (const char *)category_tmp->data;
822 //get glist of category key and value combination
823 memset(buffer, 0x00, 1024);
824 snprintf(buffer, 1024, "%s/", category_key);
825 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
826 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
827 if (category_detail == NULL) {
828 _LOGD("Memory allocation failed\n");
832 category_detail->name = strdup(category);
833 if (category_detail->name == NULL) {
834 _LOGD("Memory allocation failed\n");
835 free(category_detail);
839 category_list = g_list_append(category_list, (gpointer)category_detail);
844 //send glist to parser when tags for metadata plugin parser exist.
846 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
848 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
850 _LOGD("category_parser success for tag[%s]\n", category_tag);
852 __category_parser_clear_dir_list(category_list);
853 category_list = NULL;
859 __category_parser_clear_dir_list(category_list);
867 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
869 switch (xmlTextReaderNodeType(reader)) {
870 case XML_READER_TYPE_END_ELEMENT:
874 case XML_READER_TYPE_ELEMENT:
876 // Elements without closing tag don't receive
877 const xmlChar *elementName =
878 xmlTextReaderLocalName(reader);
879 if (elementName == NULL) {
883 if (strcmp(tag, ASCII(elementName)) == 0) {
884 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
885 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
896 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
898 int (*plugin_install) (const char *);
902 if (process == PLUGIN_PRE_PROCESS) {
905 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
908 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
910 case ACTION_UNINSTALL:
911 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
916 } else if (process == PLUGIN_POST_PROCESS) {
919 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
922 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
924 case ACTION_UNINSTALL:
925 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
933 if ((plugin_install =
934 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
938 ret = plugin_install(pkgid);
942 static int __next_child_element(xmlTextReaderPtr reader, int depth)
944 int ret = xmlTextReaderRead(reader);
945 int cur = xmlTextReaderDepth(reader);
948 switch (xmlTextReaderNodeType(reader)) {
949 case XML_READER_TYPE_ELEMENT:
950 if (cur == depth + 1)
953 case XML_READER_TYPE_TEXT:
954 /*text is handled by each function separately*/
955 if (cur == depth + 1)
958 case XML_READER_TYPE_END_ELEMENT:
967 ret = xmlTextReaderRead(reader);
968 cur = xmlTextReaderDepth(reader);
972 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
974 xmlTextReaderPtr reader;
978 void *lib_handle = NULL;
979 char tag[PKG_STRING_LEN_MAX] = { 0 };
981 fp = fopen(TAG_PARSER_LIST, "r");
982 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
984 while (fgets(tag, sizeof(tag), fp) != NULL) {
987 lib_handle = __open_lib_handle(tag);
988 if (lib_handle == NULL)
991 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
992 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
994 docPtr = xmlReadFile(filename, NULL, 0);
995 reader = xmlReaderWalker(docPtr);
996 if (reader != NULL) {
997 ret = xmlTextReaderRead(reader);
999 __process_tag(lib_handle, reader, action, tag, mfx->package);
1000 ret = xmlTextReaderRead(reader);
1002 xmlFreeTextReader(reader);
1005 _LOGD("%s : failed to parse", filename);
1008 _LOGD("Unable to open %s", filename);
1011 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1012 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1014 __close_lib_handle(lib_handle);
1016 memset(tag, 0x00, sizeof(tag));
1025 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1027 fprintf(stdout,"__ps_process_metadata_parser\n");
1030 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1032 fp = fopen(METADATA_PARSER_LIST, "r");
1034 _LOGD("no preload list\n");
1038 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1040 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1051 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1055 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1057 fp = fopen(CATEGORY_PARSER_LIST, "r");
1059 _LOGD("no category parser list\n");
1063 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1064 __str_trim(category_key);
1065 ret = __run_category_parser_prestep(mfx, category_key, action);
1076 static int __ps_process_allowed(xmlTextReaderPtr reader, const char **allowed)
1078 __save_xml_value(reader, allowed);
1082 static int __ps_process_condition(xmlTextReaderPtr reader, const char **condition)
1084 __save_xml_attribute(reader, "name", condition, NULL);
1088 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
1090 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
1091 __save_xml_value(reader, ¬ification->text);
1095 static int __ps_process_category(xmlTextReaderPtr reader, const char **category)
1097 __save_xml_attribute(reader, "name", category, NULL);
1101 static int __ps_process_privilege(xmlTextReaderPtr reader, const char **privilege)
1103 __save_xml_value(reader, privilege);
1107 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
1109 __save_xml_attribute(reader, "key", &metadata->key, NULL);
1110 __save_xml_attribute(reader, "value", &metadata->value, NULL);
1114 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
1116 __save_xml_attribute(reader, "type", &permission->type, NULL);
1117 __save_xml_value(reader, &permission->value);
1121 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
1123 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
1124 __save_xml_value(reader, &compatibility->text);
1128 static int __ps_process_request(xmlTextReaderPtr reader, const char **request)
1130 __save_xml_value(reader, request);
1134 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
1136 const xmlChar *node;
1141 __save_xml_attribute(reader, "path", &define->path, NULL);
1143 depth = xmlTextReaderDepth(reader);
1144 while ((ret = __next_child_element(reader, depth))) {
1145 node = xmlTextReaderConstName(reader);
1147 _LOGD("xmlTextReaderConstName value is NULL\n");
1151 if (!strcmp(ASCII(node), "allowed")) {
1153 ret = __ps_process_allowed(reader, &val);
1155 define->allowed = g_list_append(define->allowed, (gpointer)val);
1156 } else if (!strcmp(ASCII(node), "request")) {
1158 ret = __ps_process_request(reader, &val);
1160 define->request = g_list_append(define->request, (gpointer)val);
1165 _LOGD("Processing define failed\n");
1172 struct appcontrol_data {
1177 char operation[BUFSIZE];
1182 static void __ps_process_mime(gpointer data, gpointer user_data)
1184 char *mime = (char *)data;
1185 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1186 appcontrol_x *appcontrol;
1188 snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
1190 appcontrol = calloc(1, sizeof(appcontrol_x));
1191 if (strlen(ad->operation))
1192 appcontrol->operation = strdup(ad->operation);
1193 if (strlen(ad->uri))
1194 appcontrol->uri = strdup(ad->uri);
1195 appcontrol->mime = strdup(ad->mime);
1196 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1199 static void __ps_process_uri(gpointer data, gpointer user_data)
1201 char *uri = (char *)data;
1202 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1203 appcontrol_x *appcontrol;
1205 snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
1207 if (ad->mimes != NULL) {
1208 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1210 appcontrol = calloc(1, sizeof(appcontrol_x));
1211 if (strlen(ad->operation))
1212 appcontrol->operation = strdup(ad->operation);
1213 appcontrol->uri = strdup(ad->uri);
1214 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1218 static void __ps_process_operation(gpointer data, gpointer user_data)
1220 char *operation = (char *)data;
1221 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1222 appcontrol_x *appcontrol;
1224 snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
1226 if (ad->uris != NULL) {
1227 g_list_foreach(ad->uris, __ps_process_uri, user_data);
1228 } else if (ad->mimes != NULL) {
1229 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1231 appcontrol = calloc(1, sizeof(appcontrol_x));
1232 appcontrol->operation = strdup(ad->operation);
1233 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1237 static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
1239 struct appcontrol_data ad = {0, };
1241 ad.operations = operations;
1245 if (ad.operations == NULL)
1248 g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
1250 return ad.appcontrols;
1253 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
1255 const xmlChar *node;
1259 GList *operations = NULL;
1261 GList *mimes = NULL;
1264 depth = xmlTextReaderDepth(reader);
1265 while ((ret = __next_child_element(reader, depth)) > 0) {
1266 node = xmlTextReaderConstName(reader);
1268 _LOGD("xmlTextReaderConstName value is NULL\n");
1273 if (!strcmp(ASCII(node), "operation")) {
1274 __save_xml_attribute(reader, "name", &val, NULL);
1276 operations = g_list_append(operations, (gpointer)val);
1277 _LOGD("operation processing\n");
1278 } else if (!strcmp(ASCII(node), "uri")) {
1279 __save_xml_attribute(reader, "name", &val, NULL);
1281 uris = g_list_append(uris, (gpointer)val);
1282 _LOGD("uri processing\n");
1283 } else if (!strcmp(ASCII(node), "mime")) {
1284 __save_xml_attribute(reader, "name", &val, NULL);
1286 mimes = g_list_append(mimes, (gpointer)val);
1287 _LOGD("mime processing\n");
1288 } else if (!strcmp(ASCII(node), "subapp")) {
1296 _LOGD("Processing appcontrol failed\n");
1297 g_list_free_full(operations, free);
1298 g_list_free_full(uris, free);
1299 g_list_free_full(mimes, free);
1303 result = __make_appcontrol_list(operations, uris, mimes);
1305 *appcontrol = g_list_concat(*appcontrol, result);
1309 g_list_free_full(operations, free);
1310 g_list_free_full(uris, free);
1311 g_list_free_full(mimes, free);
1316 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
1318 const xmlChar *node;
1323 depth = xmlTextReaderDepth(reader);
1324 while ((ret = __next_child_element(reader, depth))) {
1325 node = xmlTextReaderConstName(reader);
1327 _LOGD("xmlTextReaderConstName value is NULL\n");
1331 if (strcmp(ASCII(node), "privilege") == 0) {
1333 ret = __ps_process_privilege(reader, &val);
1335 *privileges = g_list_append(*privileges, (gpointer)val);
1339 _LOGD("Processing privileges failed\n");
1346 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
1348 const xmlChar *node;
1353 depth = xmlTextReaderDepth(reader);
1354 while ((ret = __next_child_element(reader, depth))) {
1355 node = xmlTextReaderConstName(reader);
1357 _LOGD("xmlTextReaderConstName value is NULL\n");
1361 if (strcmp(ASCII(node), "condition") == 0) {
1363 ret = __ps_process_condition(reader, &val);
1365 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
1369 _LOGD("Processing launchconditions failed\n");
1377 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
1379 const xmlChar *node;
1383 depth = xmlTextReaderDepth(reader);
1384 while ((ret = __next_child_element(reader, depth))) {
1385 node = xmlTextReaderConstName(reader);
1387 _LOGD("xmlTextReaderConstName value is NULL\n");
1391 if (!strcmp(ASCII(node), "define")) {
1392 define_x *define = calloc(1, sizeof(define_x));
1393 if (define == NULL) {
1394 _LOGD("Malloc Failed\n");
1397 datashare->define = g_list_append(datashare->define, define);
1398 ret = __ps_process_define(reader, define);
1399 } else if (!strcmp(ASCII(node), "request")) {
1401 ret = __ps_process_request(reader, &val);
1403 datashare->request = g_list_append(datashare->request, (gpointer)val);
1407 _LOGD("Processing data-share failed\n");
1414 static char *__get_icon_with_path(const char *icon, uid_t uid)
1416 char icon_with_path[BUFSIZE];
1417 const char *app_path;
1419 if (!icon || !package)
1422 /* just use absolute path */
1423 if (index(icon, '/'))
1424 return strdup(icon);
1427 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1428 getIconPath(uid, true), icon);
1429 if (access(icon_with_path, F_OK) == 0)
1432 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1433 getIconPath(uid, false), icon);
1434 if (access(icon_with_path, F_OK) == 0)
1437 /* for backward compatibility (.../default/small/...)
1438 * this should be removed
1440 snprintf(icon_with_path, sizeof(icon_with_path),
1441 "%sdefault/small/%s",
1442 getIconPath(uid, true), icon);
1443 if (access(icon_with_path, F_OK) == 0)
1446 snprintf(icon_with_path, sizeof(icon_with_path),
1447 "%sdefault/small/%s",
1448 getIconPath(uid, false), icon);
1449 if (access(icon_with_path, F_OK) == 0)
1452 /* If doesn't exist in case of Global app,
1453 * try to get icon directly into app's directory
1455 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
1456 app_path = tzplatform_getenv(TZ_SYS_RO_APP);
1458 snprintf(icon_with_path, sizeof(icon_with_path),
1459 "%s/%s/%s", app_path, package, icon);
1460 if (access(icon_with_path, F_OK) == 0)
1463 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
1465 snprintf(icon_with_path, sizeof(icon_with_path),
1466 "%s/%s/%s", app_path, package, icon);
1467 if (access(icon_with_path, F_OK) == 0)
1470 tzplatform_set_user(uid);
1471 app_path = tzplatform_getenv(TZ_USER_APP);
1472 tzplatform_reset_user();
1474 snprintf(icon_with_path, sizeof(icon_with_path),
1475 "%s/%s/%s", app_path, package, icon);
1476 if (access(icon_with_path, F_OK) == 0)
1480 /* some preload package has icons at below path */
1481 snprintf(icon_with_path, sizeof(icon_with_path),
1482 "%s/%s/res/icons/%s", app_path, package, icon);
1483 if (access(icon_with_path, F_OK) == 0)
1486 /* since 2.3 tpk package */
1487 snprintf(icon_with_path, sizeof(icon_with_path),
1488 "%s/%s/shared/res/%s", app_path, package, icon);
1489 if (access(icon_with_path, F_OK) == 0)
1492 _LOGE("cannot find icon path for [%s]", icon);
1496 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1498 return strdup(icon_with_path);
1501 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1504 char delims[] = "=";
1505 char *ret_result = NULL;
1511 for (tag = strdup(tagv[0]); tag != NULL; ) {
1512 ret_result = strtok(tag, delims);
1514 /*check tag : preload */
1515 if (strcmp(ret_result, "preload") == 0) {
1516 ret_result = strtok(NULL, delims);
1517 if (strcmp(ret_result, "true") == 0) {
1518 free((void *)mfx->preload);
1519 mfx->preload = strdup("true");
1520 } else if (strcmp(ret_result, "false") == 0) {
1521 free((void *)mfx->preload);
1522 mfx->preload = strdup("false");
1524 /*check tag : removable*/
1525 } else if (strcmp(ret_result, "removable") == 0) {
1526 ret_result = strtok(NULL, delims);
1527 if (strcmp(ret_result, "true") == 0){
1528 free((void *)mfx->removable);
1529 mfx->removable = strdup("true");
1530 } else if (strcmp(ret_result, "false") == 0) {
1531 free((void *)mfx->removable);
1532 mfx->removable = strdup("false");
1534 /*check tag : not matched*/
1536 _LOGD("tag process [%s]is not defined\n", ret_result);
1540 /*check next value*/
1541 if (tagv[++i] != NULL)
1542 tag = strdup(tagv[i]);
1544 _LOGD("tag process success...\n");
1550 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1552 __save_xml_attribute(reader, "section", &icon->section, NULL);
1553 __save_xml_attribute(reader, "size", &icon->size, NULL);
1554 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1555 __save_xml_lang(reader, &icon->lang);
1557 xmlTextReaderRead(reader);
1558 const char *text = ASCII(xmlTextReaderValue(reader));
1560 icon->text = (const char *)__get_icon_with_path(text, uid);
1567 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1569 __save_xml_attribute(reader, "section", &image->section, NULL);
1570 __save_xml_lang(reader, &image->lang);
1571 __save_xml_value(reader, &image->text);
1575 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1577 __save_xml_attribute(reader, "name", &label->name, NULL);
1578 __save_xml_lang(reader, &label->lang);
1579 __save_xml_value(reader, &label->text);
1584 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1586 __save_xml_attribute(reader, "email", &author->email, NULL);
1587 __save_xml_attribute(reader, "href", &author->href, NULL);
1588 __save_xml_value(reader, &author->text);
1592 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1594 __save_xml_lang(reader, &description->lang);
1595 __save_xml_value(reader, &description->text);
1599 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1601 __save_xml_lang(reader, &license->lang);
1602 __save_xml_value(reader, &license->text);
1606 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1608 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1609 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1610 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1614 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
1616 __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
1617 __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
1618 __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
1619 __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
1620 __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
1621 __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
1625 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
1627 const xmlChar *node;
1630 splashscreen_x *splashscreen;
1632 depth = xmlTextReaderDepth(reader);
1633 while ((ret = __next_child_element(reader, depth))) {
1634 node = xmlTextReaderConstName(reader);
1636 _LOGD("xmlTextReaderConstName value is NULL\n");
1640 if (strcmp(ASCII(node), "splash-screen") == 0) {
1641 splashscreen = calloc(1, sizeof(splashscreen_x));
1642 if (splashscreen == NULL) {
1643 _LOGD("Malloc Failed\n");
1646 *splashscreens = g_list_append(*splashscreens, splashscreen);
1647 ret = __ps_process_splashscreen(reader, splashscreen);
1653 _LOGD("Processing splash-screen failed\n");
1660 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
1662 const xmlChar *node;
1667 __save_xml_attribute(reader, "appid", &application->appid, NULL);
1668 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1669 __save_xml_attribute(reader, "exec", &application->exec, NULL);
1670 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
1671 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
1672 __save_xml_attribute(reader, "type", &application->type, NULL);
1673 __save_xml_attribute(reader, "categories", &application->categories, NULL);
1674 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
1675 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
1676 __save_xml_attribute(reader, "enabled", &application->enabled, "true");
1677 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
1678 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
1679 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
1680 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
1681 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
1682 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
1683 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
1684 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
1685 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
1686 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
1687 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
1688 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1689 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);
1690 __save_xml_attribute(reader, "submode", &application->submode, "false");
1691 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
1692 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
1693 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
1694 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
1695 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
1696 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
1698 application->package= strdup(package);
1699 /* overwrite some attributes if the app is widgetapp */
1700 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
1701 free((void *)application->nodisplay);
1702 application->nodisplay = strdup("true");
1703 free((void *)application->multiple);
1704 application->multiple = strdup("true");
1705 free((void *)application->type);
1706 application->type = strdup("capp");
1707 free((void *)application->taskmanage);
1708 application->taskmanage = strdup("false");
1709 free((void *)application->indicatordisplay);
1710 application->indicatordisplay = strdup("false");
1713 depth = xmlTextReaderDepth(reader);
1714 while ((ret = __next_child_element(reader, depth))) {
1715 node = xmlTextReaderConstName(reader);
1717 _LOGD("xmlTextReaderConstName value is NULL\n");
1720 if (!strcmp(ASCII(node), "label")) {
1721 label_x *label = calloc(1, sizeof(label_x));
1722 if (label == NULL) {
1723 _LOGD("Malloc Failed\n");
1726 application->label = g_list_append(application->label, label);
1727 ret = __ps_process_label(reader, label);
1728 } else if (!strcmp(ASCII(node), "icon")) {
1729 icon_x *icon = calloc(1, sizeof(icon_x));
1731 _LOGD("Malloc Failed\n");
1734 application->icon = g_list_append(application->icon, icon);
1735 ret = __ps_process_icon(reader, icon, uid);
1736 } else if (!strcmp(ASCII(node), "image")) {
1737 image_x *image = calloc(1, sizeof(image_x));
1738 if (image == NULL) {
1739 _LOGD("Malloc Failed\n");
1742 application->image = g_list_append(application->image, image);
1743 ret = __ps_process_image(reader, image);
1744 } else if (!strcmp(ASCII(node), "category")) {
1746 ret = __ps_process_category(reader, &val);
1748 application->category = g_list_append(application->category, (gpointer)val);
1749 } else if (!strcmp(ASCII(node), "metadata")) {
1750 metadata_x *metadata = calloc(1, sizeof(metadata_x));
1751 if (metadata == NULL) {
1752 _LOGD("Malloc Failed\n");
1755 application->metadata = g_list_append(application->metadata, metadata);
1756 ret = __ps_process_metadata(reader, metadata);
1757 } else if (!strcmp(ASCII(node), "permission")) {
1758 permission_x *permission = calloc(1, sizeof(permission_x));
1759 if (permission == NULL) {
1760 _LOGD("Malloc Failed\n");
1763 application->permission = g_list_append(application->permission, permission);
1764 ret = __ps_process_permission(reader, permission);
1765 } else if (!strcmp(ASCII(node), "app-control")) {
1766 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1767 } else if (!strcmp(ASCII(node), "application-service")) {
1768 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1769 } else if (!strcmp(ASCII(node), "data-share")) {
1770 datashare_x *datashare = calloc(1, sizeof(datashare_x));
1771 if (datashare == NULL) {
1772 _LOGD("Malloc Failed\n");
1775 application->datashare = g_list_append(application->datashare, datashare);
1776 ret = __ps_process_datashare(reader, datashare);
1777 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1778 ret = __ps_process_launchconditions(reader, &application->launchconditions);
1779 } else if (!strcmp(ASCII(node), "notification")) {
1780 notification_x *notification = calloc(1, sizeof(notification_x));
1781 if (notification == NULL) {
1782 _LOGD("Malloc Failed\n");
1785 application->notification = g_list_append(application->notification, notification);
1786 ret = __ps_process_notification(reader, notification);
1787 } else if (!strcmp(ASCII(node), "datacontrol")) {
1788 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
1789 if (datacontrol == NULL) {
1790 _LOGD("Malloc Failed\n");
1793 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
1794 ret = __ps_process_datacontrol(reader, datacontrol);
1795 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
1796 ret = __ps_process_splashscreens(reader, &application->splashscreens);
1800 _LOGD("Processing application failed\n");
1808 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1810 _LOGD("__start_process\n");
1811 const xmlChar *node;
1815 depth = xmlTextReaderDepth(reader);
1816 while ((ret = __next_child_element(reader, depth))) {
1817 node = xmlTextReaderConstName(reader);
1819 _LOGD("xmlTextReaderConstName value is NULL\n");
1823 if (!strcmp(ASCII(node), "label")) {
1824 label_x *label = calloc(1, sizeof(label_x));
1825 if (label == NULL) {
1826 _LOGD("Malloc Failed\n");
1829 mfx->label = g_list_append(mfx->label, label);
1830 ret = __ps_process_label(reader, label);
1831 } else if (!strcmp(ASCII(node), "author")) {
1832 author_x *author = calloc(1, sizeof(author_x));
1833 if (author == NULL) {
1834 _LOGD("Malloc Failed\n");
1837 mfx->author = g_list_append(mfx->author, author);
1838 ret = __ps_process_author(reader, author);
1839 } else if (!strcmp(ASCII(node), "description")) {
1840 description_x *description = calloc(1, sizeof(description_x));
1841 if (description == NULL) {
1842 _LOGD("Malloc Failed\n");
1845 mfx->description = g_list_append(mfx->description, description);
1846 ret = __ps_process_description(reader, description);
1847 } else if (!strcmp(ASCII(node), "license")) {
1848 license_x *license = calloc(1, sizeof(license_x));
1849 if (license == NULL) {
1850 _LOGD("Malloc Failed\n");
1853 mfx->license = g_list_append(mfx->license, license);
1854 ret = __ps_process_license(reader, license);
1855 } else if (!strcmp(ASCII(node), "privileges")) {
1856 ret = __ps_process_privileges(reader, &mfx->privileges);
1857 } else if (!strcmp(ASCII(node), "ui-application")) {
1858 application_x *application = calloc(1, sizeof(application_x));
1859 if (application == NULL) {
1860 _LOGD("Malloc Failed\n");
1863 mfx->application = g_list_append(mfx->application, application);
1864 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1865 } else if (!strcmp(ASCII(node), "service-application")) {
1866 application_x *application = calloc(1, sizeof(application_x));
1867 if (application == NULL) {
1868 _LOGD("Malloc Failed\n");
1871 mfx->application = g_list_append(mfx->application, application);
1872 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
1873 } else if (!strcmp(ASCII(node), "widget-application")) {
1874 application_x *application = calloc(1, sizeof(application_x));
1875 if (application == NULL) {
1876 _LOGD("Malloc Failed\n");
1879 mfx->application = g_list_append(mfx->application, application);
1880 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
1881 } else if (!strcmp(ASCII(node), "watch-application")) {
1882 application_x *application = calloc(1, sizeof(application_x));
1883 if (application == NULL) {
1884 _LOGD("Malloc Failed\n");
1887 mfx->application = g_list_append(mfx->application, application);
1888 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
1889 } else if (!strcmp(ASCII(node), "icon")) {
1890 icon_x *icon = calloc(1, sizeof(icon_x));
1892 _LOGD("Malloc Failed\n");
1895 mfx->icon = g_list_append(mfx->icon, icon);
1896 ret = __ps_process_icon(reader, icon, uid);
1897 } else if (!strcmp(ASCII(node), "compatibility")) {
1898 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
1899 if (compatibility == NULL) {
1900 _LOGD("Malloc Failed\n");
1903 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
1904 ret = __ps_process_compatibility(reader, compatibility);
1905 } else if (!strcmp(ASCII(node), "shortcut-list")) {
1907 } else if (!strcmp(ASCII(node), "livebox")) {
1909 } else if (!strcmp(ASCII(node), "account")) {
1911 } else if (!strcmp(ASCII(node), "notifications")) {
1913 } else if (!strcmp(ASCII(node), "ime")) {
1915 } else if (!strcmp(ASCII(node), "feature")) {
1918 _LOGI("Unknown element: %s", ASCII(node));
1923 _LOGD("Processing manifest failed\n");
1930 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1932 const xmlChar *node;
1935 if ((ret = __next_child_element(reader, -1))) {
1936 node = xmlTextReaderConstName(reader);
1938 _LOGD("xmlTextReaderConstName value is NULL\n");
1942 if (!strcmp(ASCII(node), "manifest")) {
1943 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1944 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1945 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1946 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1947 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1948 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1949 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1950 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1951 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1952 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1953 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1954 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1955 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1956 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1957 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1959 __save_xml_installed_time(mfx);
1960 __save_xml_root_path(mfx, uid);
1961 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1962 __save_xml_default_value(mfx);
1964 ret = __start_process(reader, mfx, uid);
1966 _LOGD("No Manifest element found\n");
1973 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
1975 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
1977 void *lib_handle = NULL;
1978 int (*appsvc_operation) (const char *, uid_t);
1981 application_x *application;
1983 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1984 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
1988 if ((appsvc_operation =
1989 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1990 _LOGE("can not find symbol \n");
1994 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1995 application = (application_x *)tmp->data;
1996 if (application == NULL)
1998 ret = appsvc_operation(application->appid, uid);
2000 _LOGE("can not operation symbol \n");
2005 dlclose(lib_handle);
2010 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
2012 if (!strstr(manifest, getUserManifestPath(uid,
2013 strcmp(mfx->preload, "true") == 0))) {
2014 /* if downloaded app is updated, then update tag set true*/
2016 free((void *)mfx->update);
2017 mfx->update = strdup("true");
2023 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
2025 /* desktop file is no longer used */
2029 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
2031 /* desktop file is no longer used */
2036 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
2038 pkgmgrinfo_basic_free_package((package_x *)mfx);
2041 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
2043 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
2044 xmlTextReaderPtr reader;
2045 manifest_x *mfx = NULL;
2047 reader = xmlReaderForFile(manifest, NULL, 0);
2049 mfx = malloc(sizeof(manifest_x));
2051 memset(mfx, '\0', sizeof(manifest_x));
2052 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
2053 _LOGD("Parsing Failed\n");
2054 pkgmgr_parser_free_manifest_xml(mfx);
2057 _LOGD("Parsing Success\n");
2059 _LOGD("Memory allocation error\n");
2061 xmlFreeTextReader(reader);
2063 _LOGD("Unable to create xml reader\n");
2069 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
2071 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
2072 xmlTextReaderPtr reader;
2073 manifest_x *mfx = NULL;
2075 reader = xmlReaderForFile(manifest, NULL, 0);
2077 mfx = malloc(sizeof(manifest_x));
2079 memset(mfx, '\0', sizeof(manifest_x));
2080 if (__process_manifest(reader, mfx, uid) < 0) {
2081 _LOGD("Parsing Failed\n");
2082 pkgmgr_parser_free_manifest_xml(mfx);
2085 _LOGD("Parsing Success\n");
2087 _LOGD("Memory allocation error\n");
2089 xmlFreeTextReader(reader);
2091 _LOGD("Unable to create xml reader\n");
2096 API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid)
2098 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid);
2101 API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path)
2103 return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path);
2106 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2108 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2109 _LOGD("parsing manifest for installation: %s\n", manifest);
2111 manifest_x *mfx = NULL;
2115 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2116 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2118 _LOGD("Parsing Finished\n");
2120 __ps_process_tag(mfx, tagv);
2122 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2123 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2125 _LOGD("DB Insert Success\n");
2127 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2128 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2130 _LOGD("Creating metadata parser failed\n");
2132 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2134 _LOGD("Creating category parser failed\n");
2136 pkgmgr_parser_free_manifest_xml(mfx);
2137 _LOGD("Free Done\n");
2142 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2144 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2145 _LOGD("parsing manifest for installation: %s\n", manifest);
2146 manifest_x *mfx = NULL;
2150 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2151 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2153 _LOGD("Parsing Finished\n");
2155 __ps_process_tag(mfx, tagv);
2157 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2158 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2160 _LOGD("DB Insert Success\n");
2162 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2163 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2165 _LOGD("Creating metadata parser failed\n");
2166 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2168 _LOGD("Creating category parser failed\n");
2170 pkgmgr_parser_free_manifest_xml(mfx);
2171 _LOGD("Free Done\n");
2177 API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest) {
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);
2185 _LOGD("Added preload infomation\n");
2187 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2188 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2189 _LOGD("DB Insert Success\n");
2191 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2193 _LOGD("Creating metadata parser failed\n");
2195 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2197 _LOGD("Creating category parser failed\n");
2203 API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid) {
2204 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2205 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2206 _LOGD("processing manifest_x for installation: %s\n", manifest);
2210 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2211 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2212 _LOGD("DB Insert Success\n");
2214 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2216 _LOGD("Creating metadata parser failed\n");
2217 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2219 _LOGD("Creating category parser failed\n");
2224 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2226 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2227 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2228 manifest_x *mfx = NULL;
2230 bool preload = false;
2231 bool system = false;
2232 char *csc_path = NULL;
2233 pkgmgrinfo_pkginfo_h handle = NULL;
2236 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2237 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2239 _LOGD("Parsing Finished\n");
2240 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2242 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2243 if (ret != PMINFO_R_OK)
2244 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2245 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2246 if (ret != PMINFO_R_OK)
2247 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2250 free((void *)mfx->preload);
2251 mfx->preload = strdup("true");
2254 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2255 if (ret != PMINFO_R_OK)
2256 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2258 free((void *)mfx->system);
2259 mfx->system = strdup("true");
2262 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2263 if (ret != PMINFO_R_OK)
2264 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2266 if (csc_path != NULL) {
2268 free((void *)mfx->csc_path);
2269 mfx->csc_path = strdup(csc_path);
2272 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2273 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2275 _LOGD("DB Update Success\n");
2277 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2278 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2280 _LOGD("Upgrade metadata parser failed\n");
2282 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2284 _LOGD("Creating category parser failed\n");
2285 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2286 pkgmgr_parser_free_manifest_xml(mfx);
2287 _LOGD("Free Done\n");
2293 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2295 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2296 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2297 manifest_x *mfx = NULL;
2299 bool preload = false;
2300 bool system = false;
2301 char *csc_path = NULL;
2302 pkgmgrinfo_pkginfo_h handle = NULL;
2305 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2306 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2308 _LOGD("Parsing Finished\n");
2309 __check_preload_updated(mfx, manifest, uid);
2311 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2312 if (ret != PMINFO_R_OK)
2313 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2314 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2315 if (ret != PMINFO_R_OK)
2316 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2319 free((void *)mfx->preload);
2320 mfx->preload = strdup("true");
2323 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2324 if (ret != PMINFO_R_OK)
2325 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2328 free((void *)mfx->system);
2329 mfx->system = strdup("true");
2332 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2333 if (ret != PMINFO_R_OK)
2334 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2335 if (csc_path != NULL) {
2337 free((void *)mfx->csc_path);
2338 mfx->csc_path = strdup(csc_path);
2341 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2342 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2343 _LOGD("DB Update Success\n");
2345 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2346 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2348 _LOGD("Upgrade metadata parser failed\n");
2349 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2351 _LOGD("Creating category parser failed\n");
2352 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2353 pkgmgr_parser_free_manifest_xml(mfx);
2354 _LOGD("Free Done\n");
2360 API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest) {
2361 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2362 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2363 _LOGD("pkgmgr_parser_process_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2365 bool system = false;
2366 char *csc_path = NULL;
2367 pkgmgrinfo_pkginfo_h handle = NULL;
2371 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2372 if (ret != PMINFO_R_OK)
2373 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2375 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2376 if (ret != PMINFO_R_OK)
2377 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2379 free((void *)mfx->system);
2380 mfx->system = strdup("true");
2383 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2384 if (ret != PMINFO_R_OK)
2385 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2387 if (csc_path != NULL) {
2389 free((void *)mfx->csc_path);
2390 mfx->csc_path = strdup(csc_path);
2393 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2394 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2395 _LOGD("DB Update Success\n");
2397 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2399 _LOGD("Upgrade metadata parser failed\n");
2401 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2403 _LOGD("Creating category parser failed\n");
2404 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2410 API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid) {
2411 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2412 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2413 _LOGD(" pkgmgr_parser_process_usr_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2415 pkgmgrinfo_pkginfo_h handle = NULL;
2419 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2420 if (ret != PMINFO_R_OK)
2421 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2423 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2424 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2425 _LOGD("DB Update Success\n");
2427 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2429 _LOGD("Upgrade metadata parser failed\n");
2430 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2432 _LOGD("Creating category parser failed\n");
2433 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2439 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2441 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2442 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2444 manifest_x *mfx = NULL;
2447 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2448 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2450 _LOGD("Parsing Finished\n");
2452 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2454 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2456 _LOGD("Removing metadata parser failed\n");
2458 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2460 _LOGD("Creating category parser failed\n");
2462 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2464 _LOGD("DB Delete failed\n");
2466 _LOGD("DB Delete Success\n");
2468 pkgmgr_parser_free_manifest_xml(mfx);
2469 _LOGD("Free Done\n");
2476 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2478 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2479 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2481 manifest_x *mfx = NULL;
2484 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2485 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2487 _LOGD("Parsing Finished\n");
2489 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2491 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2493 _LOGD("Removing metadata parser failed\n");
2495 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2497 _LOGD("Creating category parser failed\n");
2499 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2501 _LOGD("DB Delete failed\n");
2503 _LOGD("DB Delete Success\n");
2505 ret = __ps_remove_appsvc_db(mfx, uid);
2507 _LOGD("Removing appsvc_db failed\n");
2509 _LOGD("Removing appsvc_db Success\n");
2511 pkgmgr_parser_free_manifest_xml(mfx);
2512 _LOGD("Free Done\n");
2518 API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest) {
2519 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2520 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2521 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2526 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2528 _LOGD("Removing metadata parser failed\n");
2530 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2532 _LOGD("Creating category parser failed\n");
2534 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2536 _LOGD("DB Delete failed\n");
2538 _LOGD("DB Delete Success\n");
2544 API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid) {
2545 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2546 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2547 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2552 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2554 _LOGD("Removing metadata parser failed\n");
2556 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2558 _LOGD("Creating category parser failed\n");
2560 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2562 _LOGD("DB Delete failed\n");
2564 _LOGD("DB Delete Success\n");
2566 ret = __ps_remove_appsvc_db(mfx, uid);
2568 _LOGD("Removing appsvc_db failed\n");
2570 _LOGD("Removing appsvc_db Success\n");
2576 API int pkgmgr_parser_parse_manifest_for_preload()
2578 return pkgmgr_parser_update_preload_info_in_db();
2581 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
2583 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
2586 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2588 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
2591 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2593 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
2596 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2598 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
2601 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2603 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2605 if (manifest == NULL) {
2606 _LOGE("manifest file is NULL\n");
2607 return PMINFO_R_EINVAL;
2610 xmlSchemaParserCtxtPtr ctx;
2611 xmlSchemaValidCtxtPtr vctx;
2612 xmlSchemaPtr xschema;
2613 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2615 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2616 return PMINFO_R_ERROR;
2618 xschema = xmlSchemaParse(ctx);
2619 if (xschema == NULL) {
2620 _LOGE("xmlSchemaParse() Failed\n");
2621 return PMINFO_R_ERROR;
2623 vctx = xmlSchemaNewValidCtxt(xschema);
2625 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2626 return PMINFO_R_ERROR;
2628 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2629 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2631 _LOGE("xmlSchemaValidateFile() failed\n");
2632 return PMINFO_R_ERROR;
2633 } else if (ret == 0) {
2634 _LOGD("Manifest is Valid\n");
2637 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2638 return PMINFO_R_ERROR;
2644 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2654 _LOGE("fork failed\n");
2659 int dev_null_fd = open ("/dev/null", O_RDWR);
2660 if (dev_null_fd >= 0)
2662 dup2 (dev_null_fd, 0);/*stdin*/
2663 dup2 (dev_null_fd, 1);/*stdout*/
2664 dup2 (dev_null_fd, 2);/*stderr*/
2667 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
2668 SCHEMA_FILE, NULL) < 0) {
2669 _LOGE("execl error\n");
2679 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
2683 _LOGE("waitpid failed\n");
2689 if(WIFEXITED(status) && !WEXITSTATUS(status))