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, privilege_x *privilege);
97 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges);
98 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile);
99 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed);
100 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation);
101 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri);
102 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime);
103 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp);
104 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition);
105 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
106 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category);
107 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
108 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
109 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
110 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request);
111 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
112 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc);
113 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions);
114 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
115 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
116 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
117 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
118 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
119 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol);
120 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
121 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid);
122 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font);
123 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme);
124 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon);
125 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime);
126 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid);
127 static int __next_child_element(xmlTextReaderPtr reader, int depth);
128 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
129 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
130 static void __str_trim(char *input);
131 static char *__get_parser_plugin(const char *type);
132 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
133 API int __is_admin();
135 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, const char **xml_attribute, char *default_value)
137 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
139 *xml_attribute = strdup((const char *)attrib_val);
142 if (default_value != NULL) {
143 *xml_attribute = strdup(default_value);
148 static void __save_xml_lang(xmlTextReaderPtr reader, const char **xml_attribute)
150 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
151 if (attrib_val != NULL)
152 *xml_attribute = strdup(ASCII(attrib_val));
154 *xml_attribute = strdup(DEFAULT_LOCALE);
157 static void __save_xml_value(xmlTextReaderPtr reader, const char **xml_attribute)
159 xmlTextReaderRead(reader);
160 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
163 *xml_attribute = strdup((const char *)attrib_val);
166 static void __save_xml_installed_time(manifest_x *mfx)
168 char buf[PKG_STRING_LEN_MAX] = {'\0'};
172 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
173 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
174 mfx->installed_time = val;
177 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
179 char root[PKG_STRING_LEN_MAX] = { '\0' };
185 tzplatform_set_user(uid);
186 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
187 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
189 mfx->root_path = strdup(root);
191 tzplatform_reset_user();
194 static void __save_xml_default_value(manifest_x * mfx)
196 mfx->preload = strdup("False");
197 mfx->removable = strdup("True");
198 mfx->readonly = strdup("False");
199 mfx->update = strdup("False");
200 mfx->system = strdup("False");
201 mfx->installed_storage= strdup("installed_internal");
202 package = mfx->package;
205 void *__open_lib_handle(char *tag)
207 char *lib_path = NULL;
208 void *lib_handle = NULL;
210 lib_path = __get_parser_plugin(tag);
211 retvm_if(!lib_path, NULL, "lib_path get fail");
213 lib_handle = dlopen(lib_path, RTLD_LAZY);
214 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
219 void __close_lib_handle(void *lib_handle)
224 static void __str_trim(char *input)
226 char *trim_str = input;
231 while (*input != 0) {
232 if (!isspace(*input)) {
245 uid_t uid = getuid();
246 if ((uid_t) 0 == uid )
254 static char * __get_tag_by_key(char *md_key)
258 if (md_key == NULL) {
259 _LOGD("md_key is NULL\n");
263 md_tag = strrchr(md_key, 47) + 1;
266 return strdup(md_tag);
269 static char *__get_metadata_parser_plugin(const char *type)
272 char buffer[1024] = { 0 };
273 char temp_path[1024] = { 0 };
277 _LOGE("invalid argument\n");
281 fp = fopen(PKG_PARSER_CONF_PATH, "r");
283 _LOGE("no matching metadata parser\n");
287 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
288 if (buffer[0] == '#')
293 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
294 path = path + strlen(METADATA_PARSER_NAME);
299 memset(buffer, 0x00, 1024);
306 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
310 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
312 return strdup(temp_path);
315 static char *__get_category_parser_plugin(const char *type)
318 char buffer[1024] = { 0 };
319 char temp_path[1024] = { 0 };
323 _LOGE("invalid argument\n");
327 fp = fopen(PKG_PARSER_CONF_PATH, "r");
329 _LOGE("no matching metadata parser\n");
333 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
334 if (buffer[0] == '#')
339 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
340 path = path + strlen(CATEGORY_PARSER_NAME);
345 memset(buffer, 0x00, 1024);
352 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
356 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
358 return strdup(temp_path);
361 static char *__get_parser_plugin(const char *type)
364 char buffer[1024] = { 0 };
365 char temp_path[1024] = { 0 };
369 _LOGE("invalid argument\n");
373 fp = fopen(PKG_PARSER_CONF_PATH, "r");
375 _LOGE("no matching backendlib\n");
379 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
380 if (buffer[0] == '#')
385 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
386 path = path + strlen(PKG_PARSERLIB);
390 memset(buffer, 0x00, 1024);
397 _LOGE("no matching backendlib\n");
401 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
403 return strdup(temp_path);
406 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
407 ACTION_TYPE action, const char *pkgid)
409 int (*plugin_install) (xmlDocPtr, const char *);
415 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
418 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
420 case ACTION_UNINSTALL:
421 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
427 if ((plugin_install =
428 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
429 _LOGE("can not find symbol[%s] \n", ac);
433 ret = plugin_install(docPtr, pkgid);
434 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
440 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
441 ACTION_TYPE action, const char *pkgid, const char *appid)
443 char *lib_path = NULL;
444 void *lib_handle = NULL;
445 int (*metadata_parser_plugin) (const char *, const char *, GList *);
451 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
454 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
456 case ACTION_UNINSTALL:
457 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
463 lib_path = __get_metadata_parser_plugin(tag);
465 _LOGE("get %s parser fail\n", tag);
469 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
470 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
474 if ((metadata_parser_plugin =
475 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
476 _LOGE("can not find symbol[%s] \n",ac);
480 ret = metadata_parser_plugin(pkgid, appid, md_list);
482 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
484 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
494 static int __ps_run_category_parser(GList *category_list, const char *tag,
495 ACTION_TYPE action, const char *pkgid, const char *appid)
497 char *lib_path = NULL;
498 void *lib_handle = NULL;
499 int (*category_parser_plugin) (const char *, const char *, GList *);
505 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
508 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
510 case ACTION_UNINSTALL:
511 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
517 lib_path = __get_category_parser_plugin(tag);
519 _LOGE("get %s parser fail\n", tag);
523 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
524 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
528 if ((category_parser_plugin =
529 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
530 _LOGE("can not find symbol[%s] \n",ac);
534 ret = category_parser_plugin(pkgid, appid, category_list);
536 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
538 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
548 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
549 ACTION_TYPE action, const char *pkgid)
551 char *lib_path = NULL;
552 void *lib_handle = NULL;
553 int (*plugin_install) (xmlDocPtr, const char *);
559 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
562 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
564 case ACTION_UNINSTALL:
565 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
571 lib_path = __get_parser_plugin(tag);
576 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
577 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
580 if ((plugin_install =
581 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
582 _LOGE("can not find symbol[%s] \n", ac);
586 ret = plugin_install(docPtr, pkgid);
588 _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
590 _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
600 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid)
606 _LOGE("pkgid is NULL");
610 size = strlen(getUserManifestPath(uid)) + strlen(pkgid) + 10;
611 manifest = malloc(size);
612 if (manifest == NULL) {
616 memset(manifest, '\0', size);
617 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
619 if (access(manifest, F_OK)) {
620 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
626 static void __metadata_parser_clear_dir_list(GList* dir_list)
629 __metadata_t* detail = NULL;
632 list = g_list_first(dir_list);
634 detail = (__metadata_t *)list->data;
637 free((void *)detail->key);
639 free((void *)detail->value);
642 list = g_list_next(list);
644 g_list_free(dir_list);
648 static void __category_parser_clear_dir_list(GList* dir_list)
651 __category_t* detail = NULL;
654 list = g_list_first(dir_list);
656 detail = (__category_t *)list->data;
659 free((void *)detail->name);
663 list = g_list_next(list);
665 g_list_free(dir_list);
669 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
674 if (xmlTextReaderDepth(reader) != 1) {
675 _LOGE("Node depth is not 1");
679 if (xmlTextReaderNodeType(reader) != 1) {
680 _LOGE("Node type is not 1");
684 const xmlChar *value;
685 name = xmlTextReaderConstName(reader);
687 _LOGE("TEST TEST TES\n");
688 name = BAD_CAST "--";
691 value = xmlTextReaderConstValue(reader);
693 if (xmlStrlen(value) > 40) {
694 _LOGD(" %.40s...", value);
700 name = xmlTextReaderConstName(reader);
702 _LOGE("TEST TEST TES\n");
703 name = BAD_CAST "--";
706 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
707 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
708 if (copyDocPtr == NULL)
710 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
711 if (rootElement == NULL)
713 xmlNode *cur_node = xmlFirstElementChild(rootElement);
714 if (cur_node == NULL)
716 xmlNode *temp = xmlTextReaderExpand(reader);
719 xmlNode *next_node = NULL;
720 while(cur_node != NULL) {
721 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
722 (temp->line == cur_node->line) ) {
726 next_node = xmlNextElementSibling(cur_node);
727 xmlUnlinkNode(cur_node);
728 xmlFreeNode(cur_node);
729 cur_node = next_node;
732 if (cur_node == NULL)
734 next_node = xmlNextElementSibling(cur_node);
736 cur_node->next = NULL;
737 next_node->prev = NULL;
738 xmlFreeNodeList(next_node);
739 xmlSetTreeDoc(cur_node, copyDocPtr);
741 xmlSetTreeDoc(cur_node, copyDocPtr);
744 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
750 static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
754 char buffer[1024] = { 0, };
755 application_x *app = mfx->application;
756 metadata_x *md = NULL;
759 GList *md_list = NULL;
760 __metadata_t *md_detail = NULL;
762 md_tag = __get_tag_by_key(md_key);
763 if (md_tag == NULL) {
764 _LOGD("md_tag is NULL\n");
768 while (app != NULL) {
771 //get glist of metadata key and value combination
772 memset(buffer, 0x00, 1024);
773 snprintf(buffer, 1024, "%s/", md_key);
774 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
775 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
776 if (md_detail == NULL) {
777 _LOGD("Memory allocation failed\n");
781 md_detail->key = strdup(md->key);
782 if (md_detail->key == NULL) {
783 _LOGD("Memory allocation failed\n");
788 md_detail->value = strdup(md->value);
789 if (md_detail->value == NULL) {
790 _LOGD("Memory allocation failed\n");
791 free((void *)md_detail->key);
796 md_list = g_list_append(md_list, (gpointer)md_detail);
802 //send glist to parser when tags for metadata plugin parser exist.
804 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
806 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
809 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
812 __metadata_parser_clear_dir_list(md_list);
820 __metadata_parser_clear_dir_list(md_list);
828 static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
832 char buffer[1024] = { 0, };
833 application_x *app = mfx->application;
834 category_x *category = NULL;
835 char *category_tag = NULL;
837 GList *category_list = NULL;
838 __category_t *category_detail = NULL;
840 category_tag = __get_tag_by_key(category_key);
841 if (category_tag == NULL) {
842 _LOGD("md_tag is NULL\n");
846 while (app != NULL) {
847 category = app->category;
848 while (category != NULL) {
849 //get glist of category key and value combination
850 memset(buffer, 0x00, 1024);
851 snprintf(buffer, 1024, "%s/", category_key);
852 if ((category->name) && (strncmp(category->name, category_key, strlen(category_key)) == 0)) {
853 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
854 if (category_detail == NULL) {
855 _LOGD("Memory allocation failed\n");
859 category_detail->name = strdup(category->name);
860 if (category_detail->name == NULL) {
861 _LOGD("Memory allocation failed\n");
862 free(category_detail);
866 category_list = g_list_append(category_list, (gpointer)category_detail);
869 category = category->next;
872 //send glist to parser when tags for metadata plugin parser exist.
874 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
876 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
878 _LOGD("category_parser success for tag[%s]\n", category_tag);
880 __category_parser_clear_dir_list(category_list);
881 category_list = NULL;
888 __category_parser_clear_dir_list(category_list);
896 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
898 switch (xmlTextReaderNodeType(reader)) {
899 case XML_READER_TYPE_END_ELEMENT:
903 case XML_READER_TYPE_ELEMENT:
905 // Elements without closing tag don't receive
906 const xmlChar *elementName =
907 xmlTextReaderLocalName(reader);
908 if (elementName == NULL) {
912 if (strcmp(tag, ASCII(elementName)) == 0) {
913 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
914 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
925 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
927 int (*plugin_install) (const char *);
931 if (process == PLUGIN_PRE_PROCESS) {
934 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
937 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
939 case ACTION_UNINSTALL:
940 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
945 } else if (process == PLUGIN_POST_PROCESS) {
948 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
951 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
953 case ACTION_UNINSTALL:
954 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
962 if ((plugin_install =
963 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
967 ret = plugin_install(pkgid);
971 static int __next_child_element(xmlTextReaderPtr reader, int depth)
973 int ret = xmlTextReaderRead(reader);
974 int cur = xmlTextReaderDepth(reader);
977 switch (xmlTextReaderNodeType(reader)) {
978 case XML_READER_TYPE_ELEMENT:
979 if (cur == depth + 1)
982 case XML_READER_TYPE_TEXT:
983 /*text is handled by each function separately*/
984 if (cur == depth + 1)
987 case XML_READER_TYPE_END_ELEMENT:
996 ret = xmlTextReaderRead(reader);
997 cur = xmlTextReaderDepth(reader);
1001 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1003 xmlTextReaderPtr reader;
1007 void *lib_handle = NULL;
1008 char tag[PKG_STRING_LEN_MAX] = { 0 };
1010 fp = fopen(TAG_PARSER_LIST, "r");
1011 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1013 while (fgets(tag, sizeof(tag), fp) != NULL) {
1016 lib_handle = __open_lib_handle(tag);
1017 if (lib_handle == NULL)
1020 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1021 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1023 docPtr = xmlReadFile(filename, NULL, 0);
1024 reader = xmlReaderWalker(docPtr);
1025 if (reader != NULL) {
1026 ret = xmlTextReaderRead(reader);
1028 __process_tag(lib_handle, reader, action, tag, mfx->package);
1029 ret = xmlTextReaderRead(reader);
1031 xmlFreeTextReader(reader);
1034 _LOGD("%s : failed to parse", filename);
1037 _LOGD("Unable to open %s", filename);
1040 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1041 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1043 __close_lib_handle(lib_handle);
1045 memset(tag, 0x00, sizeof(tag));
1054 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1056 fprintf(stdout,"__ps_process_metadata_parser\n");
1059 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1061 fp = fopen(METADATA_PARSER_LIST, "r");
1063 _LOGD("no preload list\n");
1067 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1069 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1080 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1084 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1086 fp = fopen(CATEGORY_PARSER_LIST, "r");
1088 _LOGD("no category parser list\n");
1092 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1093 __str_trim(category_key);
1094 ret = __run_category_parser_prestep(mfx, category_key, action);
1105 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed)
1107 __save_xml_value(reader, &allowed->text);
1111 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation)
1113 __save_xml_attribute(reader, "name", &operation->name, NULL);
1117 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri)
1119 __save_xml_attribute(reader, "name", &uri->name, NULL);
1123 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime)
1125 __save_xml_attribute(reader, "name", &mime->name, NULL);
1129 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp)
1131 __save_xml_attribute(reader, "name", &subapp->name, NULL);
1135 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition)
1137 __save_xml_attribute(reader, "name", &condition->name, NULL);
1141 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
1143 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
1144 __save_xml_value(reader, ¬ification->text);
1148 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category)
1150 __save_xml_attribute(reader, "name", &category->name, NULL);
1154 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
1156 __save_xml_value(reader, &privilege->text);
1160 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
1162 __save_xml_attribute(reader, "key", &metadata->key, NULL);
1163 __save_xml_attribute(reader, "value", &metadata->value, NULL);
1167 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
1169 __save_xml_attribute(reader, "type", &permission->type, NULL);
1170 __save_xml_value(reader, &permission->value);
1174 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
1176 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
1177 __save_xml_value(reader, &compatibility->text);
1181 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request)
1183 __save_xml_value(reader, &request->text);
1187 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
1189 const xmlChar *node;
1192 allowed_x *tmp1 = NULL;
1193 request_x *tmp2 = NULL;
1195 __save_xml_attribute(reader, "path", &define->path, NULL);
1197 depth = xmlTextReaderDepth(reader);
1198 while ((ret = __next_child_element(reader, depth))) {
1199 node = xmlTextReaderConstName(reader);
1201 _LOGD("xmlTextReaderConstName value is NULL\n");
1205 if (!strcmp(ASCII(node), "allowed")) {
1206 allowed_x *allowed= malloc(sizeof(allowed_x));
1207 if (allowed == NULL) {
1208 _LOGD("Malloc Failed\n");
1211 memset(allowed, '\0', sizeof(allowed_x));
1212 LISTADD(define->allowed, allowed);
1213 ret = __ps_process_allowed(reader, allowed);
1214 } else if (!strcmp(ASCII(node), "request")) {
1215 request_x *request = malloc(sizeof(request_x));
1216 if (request == NULL) {
1217 _LOGD("Malloc Failed\n");
1220 memset(request, '\0', sizeof(request_x));
1221 LISTADD(define->request, request);
1222 ret = __ps_process_request(reader, request);
1226 _LOGD("Processing define failed\n");
1230 if (define->allowed) {
1231 LISTHEAD(define->allowed, tmp1);
1232 define->allowed = tmp1;
1234 if (define->request) {
1235 LISTHEAD(define->request, tmp2);
1236 define->request = tmp2;
1241 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol)
1243 const xmlChar *node;
1247 depth = xmlTextReaderDepth(reader);
1248 while ((ret = __next_child_element(reader, depth))) {
1249 node = xmlTextReaderConstName(reader);
1251 _LOGD("xmlTextReaderConstName value is NULL\n");
1255 if (!strcmp(ASCII(node), "operation")) {
1256 __save_xml_attribute(reader, "name", &appcontrol->operation, NULL);
1257 _LOGD("operation processing\n");
1258 } else if (!strcmp(ASCII(node), "uri")) {
1259 __save_xml_attribute(reader, "name", &appcontrol->uri, NULL);
1260 _LOGD("uri processing\n");
1261 } else if (!strcmp(ASCII(node), "mime")) {
1262 __save_xml_attribute(reader, "name", &appcontrol->mime, NULL);
1263 _LOGD("mime processing\n");
1267 _LOGD("Processing appcontrol failed\n");
1275 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
1277 const xmlChar *node;
1280 operation_x *tmp1 = NULL;
1282 mime_x *tmp3 = NULL;
1283 subapp_x *tmp4 = NULL;
1285 depth = xmlTextReaderDepth(reader);
1286 while ((ret = __next_child_element(reader, depth))) {
1287 node = xmlTextReaderConstName(reader);
1289 _LOGD("xmlTextReaderConstName value is NULL\n");
1293 if (!strcmp(ASCII(node), "operation")) {
1294 operation_x *operation = malloc(sizeof(operation_x));
1295 if (operation == NULL) {
1296 _LOGD("Malloc Failed\n");
1299 memset(operation, '\0', sizeof(operation_x));
1300 LISTADD(appsvc->operation, operation);
1301 ret = __ps_process_operation(reader, operation);
1302 _LOGD("operation processing\n");
1303 } else if (!strcmp(ASCII(node), "uri")) {
1304 uri_x *uri= malloc(sizeof(uri_x));
1306 _LOGD("Malloc Failed\n");
1309 memset(uri, '\0', sizeof(uri_x));
1310 LISTADD(appsvc->uri, uri);
1311 ret = __ps_process_uri(reader, uri);
1312 _LOGD("uri processing\n");
1313 } else if (!strcmp(ASCII(node), "mime")) {
1314 mime_x *mime = malloc(sizeof(mime_x));
1316 _LOGD("Malloc Failed\n");
1319 memset(mime, '\0', sizeof(mime_x));
1320 LISTADD(appsvc->mime, mime);
1321 ret = __ps_process_mime(reader, mime);
1322 _LOGD("mime processing\n");
1323 } else if (!strcmp(ASCII(node), "subapp")) {
1324 subapp_x *subapp = malloc(sizeof(subapp_x));
1325 if (subapp == NULL) {
1326 _LOGD("Malloc Failed\n");
1329 memset(subapp, '\0', sizeof(subapp_x));
1330 LISTADD(appsvc->subapp, subapp);
1331 ret = __ps_process_subapp(reader, subapp);
1332 _LOGD("subapp processing\n");
1336 _LOGD("Processing appsvc failed\n");
1340 if (appsvc->operation) {
1341 LISTHEAD(appsvc->operation, tmp1);
1342 appsvc->operation = tmp1;
1345 LISTHEAD(appsvc->uri, tmp2);
1349 LISTHEAD(appsvc->mime, tmp3);
1350 appsvc->mime = tmp3;
1352 if (appsvc->subapp) {
1353 LISTHEAD(appsvc->subapp, tmp4);
1354 appsvc->subapp = tmp4;
1357 xmlTextReaderRead(reader);
1358 if (xmlTextReaderValue(reader))
1359 appsvc->text = ASCII(xmlTextReaderValue(reader));
1365 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges)
1367 const xmlChar *node;
1370 privilege_x *tmp1 = NULL;
1372 depth = xmlTextReaderDepth(reader);
1373 while ((ret = __next_child_element(reader, depth))) {
1374 node = xmlTextReaderConstName(reader);
1376 _LOGD("xmlTextReaderConstName value is NULL\n");
1380 if (strcmp(ASCII(node), "privilege") == 0) {
1381 privilege_x *privilege = malloc(sizeof(privilege_x));
1382 if (privilege == NULL) {
1383 _LOGD("Malloc Failed\n");
1386 memset(privilege, '\0', sizeof(privilege_x));
1387 LISTADD(privileges->privilege, privilege);
1388 ret = __ps_process_privilege(reader, privilege);
1392 _LOGD("Processing privileges failed\n");
1396 if (privileges->privilege) {
1397 LISTHEAD(privileges->privilege, tmp1);
1398 privileges->privilege = tmp1;
1403 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions)
1405 const xmlChar *node;
1408 condition_x *tmp1 = NULL;
1410 depth = xmlTextReaderDepth(reader);
1411 while ((ret = __next_child_element(reader, depth))) {
1412 node = xmlTextReaderConstName(reader);
1414 _LOGD("xmlTextReaderConstName value is NULL\n");
1418 if (strcmp(ASCII(node), "condition") == 0) {
1419 condition_x *condition = malloc(sizeof(condition_x));
1420 if (condition == NULL) {
1421 _LOGD("Malloc Failed\n");
1424 memset(condition, '\0', sizeof(condition_x));
1425 LISTADD(launchconditions->condition, condition);
1426 ret = __ps_process_condition(reader, condition);
1430 _LOGD("Processing launchconditions failed\n");
1434 if (launchconditions->condition) {
1435 LISTHEAD(launchconditions->condition, tmp1);
1436 launchconditions->condition = tmp1;
1439 __save_xml_value(reader, &launchconditions->text);
1444 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
1446 const xmlChar *node;
1449 define_x *tmp1 = NULL;
1450 request_x *tmp2 = NULL;
1451 depth = xmlTextReaderDepth(reader);
1452 while ((ret = __next_child_element(reader, depth))) {
1453 node = xmlTextReaderConstName(reader);
1455 _LOGD("xmlTextReaderConstName value is NULL\n");
1459 if (!strcmp(ASCII(node), "define")) {
1460 define_x *define= malloc(sizeof(define_x));
1461 if (define == NULL) {
1462 _LOGD("Malloc Failed\n");
1465 memset(define, '\0', sizeof(define_x));
1466 LISTADD(datashare->define, define);
1467 ret = __ps_process_define(reader, define);
1468 } else if (!strcmp(ASCII(node), "request")) {
1469 request_x *request= malloc(sizeof(request_x));
1470 if (request == NULL) {
1471 _LOGD("Malloc Failed\n");
1474 memset(request, '\0', sizeof(request_x));
1475 LISTADD(datashare->request, request);
1476 ret = __ps_process_request(reader, request);
1480 _LOGD("Processing data-share failed\n");
1484 if (datashare->define) {
1485 LISTHEAD(datashare->define, tmp1);
1486 datashare->define = tmp1;
1488 if (datashare->request) {
1489 LISTHEAD(datashare->request, tmp2);
1490 datashare->request = tmp2;
1495 static char *__get_icon_with_path(const char *icon, uid_t uid)
1497 char icon_with_path[BUFSIZE];
1498 const char *app_path;
1500 if (!icon || !package)
1503 /* just use absolute path */
1504 if (index(icon, '/'))
1505 return strdup(icon);
1508 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1509 getIconPath(uid), icon);
1510 if (access(icon_with_path, F_OK) == 0)
1513 /* for backward compatibility (.../default/small/...)
1514 * this should be removed
1516 snprintf(icon_with_path, sizeof(icon_with_path),
1517 "%sdefault/small/%s",
1518 getIconPath(uid), icon);
1519 if (access(icon_with_path, F_OK) == 0)
1522 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
1523 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
1525 tzplatform_set_user(uid);
1526 app_path = tzplatform_getenv(TZ_USER_APP);
1527 tzplatform_reset_user();
1530 /* If doesn't exist in case of Global app,
1531 * try to get icon directly into app's directory
1533 snprintf(icon_with_path, sizeof(icon_with_path),
1534 "%s/%s/%s", app_path, package, icon);
1535 if (access(icon_with_path, F_OK) == 0)
1538 /* some preload package has icons at below path */
1539 snprintf(icon_with_path, sizeof(icon_with_path),
1540 "%s/%s/res/icons/%s", app_path, package, icon);
1541 if (access(icon_with_path, F_OK) == 0)
1544 /* since 2.3 tpk package */
1545 snprintf(icon_with_path, sizeof(icon_with_path),
1546 "%s/%s/shared/res/%s", app_path, package, icon);
1547 if (access(icon_with_path, F_OK) == 0)
1550 _LOGE("cannot find icon path for [%s]", icon);
1554 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1556 return strdup(icon_with_path);
1559 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1562 char delims[] = "=";
1563 char *ret_result = NULL;
1569 for (tag = strdup(tagv[0]); tag != NULL; ) {
1570 ret_result = strtok(tag, delims);
1572 /*check tag : preload */
1573 if (strcmp(ret_result, "preload") == 0) {
1574 ret_result = strtok(NULL, delims);
1575 if (strcmp(ret_result, "true") == 0) {
1576 free((void *)mfx->preload);
1577 mfx->preload = strdup("true");
1578 } else if (strcmp(ret_result, "false") == 0) {
1579 free((void *)mfx->preload);
1580 mfx->preload = strdup("false");
1582 /*check tag : removable*/
1583 } else if (strcmp(ret_result, "removable") == 0) {
1584 ret_result = strtok(NULL, delims);
1585 if (strcmp(ret_result, "true") == 0){
1586 free((void *)mfx->removable);
1587 mfx->removable = strdup("true");
1588 } else if (strcmp(ret_result, "false") == 0) {
1589 free((void *)mfx->removable);
1590 mfx->removable = strdup("false");
1592 /*check tag : not matched*/
1594 _LOGD("tag process [%s]is not defined\n", ret_result);
1598 /*check next value*/
1599 if (tagv[++i] != NULL)
1600 tag = strdup(tagv[i]);
1602 _LOGD("tag process success...\n");
1608 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1610 __save_xml_attribute(reader, "name", &icon->name, NULL);
1611 __save_xml_attribute(reader, "section", &icon->section, NULL);
1612 __save_xml_attribute(reader, "size", &icon->size, NULL);
1613 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1614 __save_xml_lang(reader, &icon->lang);
1616 xmlTextReaderRead(reader);
1617 const char *text = ASCII(xmlTextReaderValue(reader));
1619 icon->text = (const char *)__get_icon_with_path(text, uid);
1626 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1628 __save_xml_attribute(reader, "name", &image->name, NULL);
1629 __save_xml_attribute(reader, "section", &image->section, NULL);
1630 __save_xml_lang(reader, &image->lang);
1631 __save_xml_value(reader, &image->text);
1635 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1637 __save_xml_attribute(reader, "name", &label->name, NULL);
1638 __save_xml_lang(reader, &label->lang);
1639 __save_xml_value(reader, &label->text);
1644 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1646 __save_xml_attribute(reader, "email", &author->email, NULL);
1647 __save_xml_attribute(reader, "href", &author->href, NULL);
1648 __save_xml_value(reader, &author->text);
1652 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1654 __save_xml_lang(reader, &description->lang);
1655 __save_xml_value(reader, &description->text);
1659 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1661 __save_xml_lang(reader, &license->lang);
1662 __save_xml_value(reader, &license->text);
1666 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1668 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1669 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1670 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1674 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
1676 const xmlChar *node;
1679 label_x *tmp1 = NULL;
1680 icon_x *tmp2 = NULL;
1681 appsvc_x *tmp3 = NULL;
1682 appcontrol_x *tmp4 = NULL;
1683 launchconditions_x *tmp5 = NULL;
1684 notification_x *tmp6 = NULL;
1685 datashare_x *tmp7 = NULL;
1686 category_x *tmp8 = NULL;
1687 metadata_x *tmp9 = NULL;
1688 image_x *tmp10 = NULL;
1689 permission_x *tmp11 = NULL;
1690 datacontrol_x *tmp12 = NULL;
1692 __save_xml_attribute(reader, "appid", &application->appid, NULL);
1693 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1694 __save_xml_attribute(reader, "exec", &application->exec, NULL);
1695 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
1696 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
1697 __save_xml_attribute(reader, "type", &application->type, NULL);
1698 __save_xml_attribute(reader, "categories", &application->categories, NULL);
1699 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
1700 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
1701 __save_xml_attribute(reader, "enabled", &application->enabled, "true");
1702 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
1703 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
1704 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
1705 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
1706 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
1707 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
1708 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
1709 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
1710 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
1711 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
1712 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : "svcapp");
1713 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1714 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);
1715 __save_xml_attribute(reader, "submode", &application->submode, "false");
1716 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
1717 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
1718 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
1719 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
1720 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
1722 application->package= strdup(package);
1724 depth = xmlTextReaderDepth(reader);
1725 while ((ret = __next_child_element(reader, depth))) {
1726 node = xmlTextReaderConstName(reader);
1728 _LOGD("xmlTextReaderConstName value is NULL\n");
1731 if (!strcmp(ASCII(node), "label")) {
1732 label_x *label = malloc(sizeof(label_x));
1733 if (label == NULL) {
1734 _LOGD("Malloc Failed\n");
1737 memset(label, '\0', sizeof(label_x));
1738 LISTADD(application->label, label);
1739 ret = __ps_process_label(reader, label);
1740 } else if (!strcmp(ASCII(node), "icon")) {
1741 icon_x *icon = malloc(sizeof(icon_x));
1743 _LOGD("Malloc Failed\n");
1746 memset(icon, '\0', sizeof(icon_x));
1747 LISTADD(application->icon, icon);
1748 ret = __ps_process_icon(reader, icon, uid);
1749 } else if (!strcmp(ASCII(node), "image")) {
1750 image_x *image = malloc(sizeof(image_x));
1751 if (image == NULL) {
1752 _LOGD("Malloc Failed\n");
1755 memset(image, '\0', sizeof(image_x));
1756 LISTADD(application->image, image);
1757 ret = __ps_process_image(reader, image);
1758 } else if (!strcmp(ASCII(node), "category")) {
1759 category_x *category = malloc(sizeof(category_x));
1760 if (category == NULL) {
1761 _LOGD("Malloc Failed\n");
1764 memset(category, '\0', sizeof(category_x));
1765 LISTADD(application->category, category);
1766 ret = __ps_process_category(reader, category);
1767 } else if (!strcmp(ASCII(node), "metadata")) {
1768 metadata_x *metadata = malloc(sizeof(metadata_x));
1769 if (metadata == NULL) {
1770 _LOGD("Malloc Failed\n");
1773 memset(metadata, '\0', sizeof(metadata_x));
1774 LISTADD(application->metadata, metadata);
1775 ret = __ps_process_metadata(reader, metadata);
1776 } else if (!strcmp(ASCII(node), "permission")) {
1777 permission_x *permission = malloc(sizeof(permission_x));
1778 if (permission == NULL) {
1779 _LOGD("Malloc Failed\n");
1782 memset(permission, '\0', sizeof(permission_x));
1783 LISTADD(application->permission, permission);
1784 ret = __ps_process_permission(reader, permission);
1785 } else if (!strcmp(ASCII(node), "app-control")) {
1786 appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
1787 if (appcontrol == NULL) {
1788 _LOGD("Malloc Failed\n");
1791 memset(appcontrol, '\0', sizeof(appcontrol_x));
1792 LISTADD(application->appcontrol, appcontrol);
1793 ret = __ps_process_appcontrol(reader, appcontrol);
1794 } else if (!strcmp(ASCII(node), "application-service")) {
1795 appsvc_x *appsvc = malloc(sizeof(appsvc_x));
1796 if (appsvc == NULL) {
1797 _LOGD("Malloc Failed\n");
1800 memset(appsvc, '\0', sizeof(appsvc_x));
1801 LISTADD(application->appsvc, appsvc);
1802 ret = __ps_process_appsvc(reader, appsvc);
1803 } else if (!strcmp(ASCII(node), "data-share")) {
1804 datashare_x *datashare = malloc(sizeof(datashare_x));
1805 if (datashare == NULL) {
1806 _LOGD("Malloc Failed\n");
1809 memset(datashare, '\0', sizeof(datashare_x));
1810 LISTADD(application->datashare, datashare);
1811 ret = __ps_process_datashare(reader, datashare);
1812 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1813 launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
1814 if (launchconditions == NULL) {
1815 _LOGD("Malloc Failed\n");
1818 memset(launchconditions, '\0', sizeof(launchconditions_x));
1819 LISTADD(application->launchconditions, launchconditions);
1820 ret = __ps_process_launchconditions(reader, launchconditions);
1821 } else if (!strcmp(ASCII(node), "notification")) {
1822 notification_x *notification = malloc(sizeof(notification_x));
1823 if (notification == NULL) {
1824 _LOGD("Malloc Failed\n");
1827 memset(notification, '\0', sizeof(notification_x));
1828 LISTADD(application->notification, notification);
1829 ret = __ps_process_notification(reader, notification);
1830 } else if (!strcmp(ASCII(node), "datacontrol")) {
1831 datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
1832 if (datacontrol == NULL) {
1833 _LOGD("Malloc Failed\n");
1836 memset(datacontrol, '\0', sizeof(datacontrol_x));
1837 LISTADD(application->datacontrol, datacontrol);
1838 ret = __ps_process_datacontrol(reader, datacontrol);
1842 _LOGD("Processing application failed\n");
1847 if (application->label) {
1848 LISTHEAD(application->label, tmp1);
1849 application->label = tmp1;
1851 if (application->icon) {
1852 LISTHEAD(application->icon, tmp2);
1853 application->icon = tmp2;
1855 if (application->appsvc) {
1856 LISTHEAD(application->appsvc, tmp3);
1857 application->appsvc = tmp3;
1859 if (application->appcontrol) {
1860 LISTHEAD(application->appcontrol, tmp4);
1861 application->appcontrol = tmp4;
1863 if (application->launchconditions) {
1864 LISTHEAD(application->launchconditions, tmp5);
1865 application->launchconditions = tmp5;
1867 if (application->notification) {
1868 LISTHEAD(application->notification, tmp6);
1869 application->notification = tmp6;
1871 if (application->datashare) {
1872 LISTHEAD(application->datashare, tmp7);
1873 application->datashare = tmp7;
1875 if (application->category) {
1876 LISTHEAD(application->category, tmp8);
1877 application->category = tmp8;
1879 if (application->metadata) {
1880 LISTHEAD(application->metadata, tmp9);
1881 application->metadata = tmp9;
1883 if (application->image) {
1884 LISTHEAD(application->image, tmp10);
1885 application->image = tmp10;
1887 if (application->permission) {
1888 LISTHEAD(application->permission, tmp11);
1889 application->permission = tmp11;
1891 if (application->datacontrol) {
1892 LISTHEAD(application->datacontrol, tmp12);
1893 application->datacontrol = tmp12;
1899 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile)
1901 /*TODO: once policy is set*/
1905 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font)
1907 /*TODO: once policy is set*/
1911 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme)
1913 /*TODO: once policy is set*/
1917 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon)
1919 /*TODO: once policy is set*/
1923 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
1925 /*TODO: once policy is set*/
1929 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1931 _LOGD("__start_process\n");
1932 const xmlChar *node;
1935 label_x *tmp1 = NULL;
1936 author_x *tmp2 = NULL;
1937 description_x *tmp3 = NULL;
1938 license_x *tmp4 = NULL;
1939 application_x *tmp5 = NULL;
1940 daemon_x *tmp7 = NULL;
1941 theme_x *tmp8 = NULL;
1942 font_x *tmp9 = NULL;
1943 ime_x *tmp10 = NULL;
1944 icon_x *tmp11 = NULL;
1945 compatibility_x *tmp12 = NULL;
1946 deviceprofile_x *tmp13 = NULL;
1947 privileges_x *tmp14 = NULL;
1949 depth = xmlTextReaderDepth(reader);
1950 while ((ret = __next_child_element(reader, depth))) {
1951 node = xmlTextReaderConstName(reader);
1953 _LOGD("xmlTextReaderConstName value is NULL\n");
1957 if (!strcmp(ASCII(node), "label")) {
1958 label_x *label = malloc(sizeof(label_x));
1959 if (label == NULL) {
1960 _LOGD("Malloc Failed\n");
1963 memset(label, '\0', sizeof(label_x));
1964 LISTADD(mfx->label, label);
1965 ret = __ps_process_label(reader, label);
1966 } else if (!strcmp(ASCII(node), "author")) {
1967 author_x *author = malloc(sizeof(author_x));
1968 if (author == NULL) {
1969 _LOGD("Malloc Failed\n");
1972 memset(author, '\0', sizeof(author_x));
1973 LISTADD(mfx->author, author);
1974 ret = __ps_process_author(reader, author);
1975 } else if (!strcmp(ASCII(node), "description")) {
1976 description_x *description = malloc(sizeof(description_x));
1977 if (description == NULL) {
1978 _LOGD("Malloc Failed\n");
1981 memset(description, '\0', sizeof(description_x));
1982 LISTADD(mfx->description, description);
1983 ret = __ps_process_description(reader, description);
1984 } else if (!strcmp(ASCII(node), "license")) {
1985 license_x *license = malloc(sizeof(license_x));
1986 if (license == NULL) {
1987 _LOGD("Malloc Failed\n");
1990 memset(license, '\0', sizeof(license_x));
1991 LISTADD(mfx->license, license);
1992 ret = __ps_process_license(reader, license);
1993 } else if (!strcmp(ASCII(node), "privileges")) {
1994 privileges_x *privileges = malloc(sizeof(privileges_x));
1995 if (privileges == NULL) {
1996 _LOGD("Malloc Failed\n");
1999 memset(privileges, '\0', sizeof(privileges_x));
2000 LISTADD(mfx->privileges, privileges);
2001 ret = __ps_process_privileges(reader, privileges);
2002 } else if (!strcmp(ASCII(node), "ui-application")) {
2003 application_x *application = malloc(sizeof(application_x));
2004 if (application == NULL) {
2005 _LOGD("Malloc Failed\n");
2008 memset(application, '\0', sizeof(application_x));
2009 LISTADD(mfx->application, application);
2010 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
2011 } else if (!strcmp(ASCII(node), "service-application")) {
2012 application_x *application = malloc(sizeof(application_x));
2013 if (application == NULL) {
2014 _LOGD("Malloc Failed\n");
2017 memset(application, '\0', sizeof(application_x));
2018 LISTADD(mfx->application, application);
2019 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
2020 } else if (!strcmp(ASCII(node), "daemon")) {
2021 daemon_x *daemon = malloc(sizeof(daemon_x));
2022 if (daemon == NULL) {
2023 _LOGD("Malloc Failed\n");
2026 memset(daemon, '\0', sizeof(daemon_x));
2027 LISTADD(mfx->daemon, daemon);
2028 ret = __ps_process_daemon(reader, daemon);
2029 } else if (!strcmp(ASCII(node), "theme")) {
2030 theme_x *theme = malloc(sizeof(theme_x));
2031 if (theme == NULL) {
2032 _LOGD("Malloc Failed\n");
2035 memset(theme, '\0', sizeof(theme_x));
2036 LISTADD(mfx->theme, theme);
2037 ret = __ps_process_theme(reader, theme);
2038 } else if (!strcmp(ASCII(node), "font")) {
2039 font_x *font = malloc(sizeof(font_x));
2041 _LOGD("Malloc Failed\n");
2044 memset(font, '\0', sizeof(font_x));
2045 LISTADD(mfx->font, font);
2046 ret = __ps_process_font(reader, font);
2047 } else if (!strcmp(ASCII(node), "ime")) {
2048 ime_x *ime = malloc(sizeof(ime_x));
2050 _LOGD("Malloc Failed\n");
2053 memset(ime, '\0', sizeof(ime_x));
2054 LISTADD(mfx->ime, ime);
2055 ret = __ps_process_ime(reader, ime);
2056 } else if (!strcmp(ASCII(node), "icon")) {
2057 icon_x *icon = malloc(sizeof(icon_x));
2059 _LOGD("Malloc Failed\n");
2062 memset(icon, '\0', sizeof(icon_x));
2063 LISTADD(mfx->icon, icon);
2064 ret = __ps_process_icon(reader, icon, uid);
2065 } else if (!strcmp(ASCII(node), "profile")) {
2066 deviceprofile_x *deviceprofile = malloc(sizeof(deviceprofile_x));
2067 if (deviceprofile == NULL) {
2068 _LOGD("Malloc Failed\n");
2071 memset(deviceprofile, '\0', sizeof(deviceprofile_x));
2072 LISTADD(mfx->deviceprofile, deviceprofile);
2073 ret = __ps_process_deviceprofile(reader, deviceprofile);
2074 } else if (!strcmp(ASCII(node), "compatibility")) {
2075 compatibility_x *compatibility = malloc(sizeof(compatibility_x));
2076 if (compatibility == NULL) {
2077 _LOGD("Malloc Failed\n");
2080 memset(compatibility, '\0', sizeof(compatibility_x));
2081 LISTADD(mfx->compatibility, compatibility);
2082 ret = __ps_process_compatibility(reader, compatibility);
2083 } else if (!strcmp(ASCII(node), "shortcut-list")) {
2085 } else if (!strcmp(ASCII(node), "livebox")) {
2087 } else if (!strcmp(ASCII(node), "account")) {
2089 } else if (!strcmp(ASCII(node), "notifications")) {
2091 } else if (!strcmp(ASCII(node), "ime")) {
2093 } else if (!strcmp(ASCII(node), "feature")) {
2096 _LOGE("Unknown element: %s", ASCII(node));
2101 _LOGD("Processing manifest failed\n");
2106 LISTHEAD(mfx->label, tmp1);
2110 LISTHEAD(mfx->author, tmp2);
2113 if (mfx->description) {
2114 LISTHEAD(mfx->description, tmp3);
2115 mfx->description= tmp3;
2118 LISTHEAD(mfx->license, tmp4);
2121 if (mfx->application) {
2122 LISTHEAD(mfx->application, tmp5);
2123 mfx->application = tmp5;
2126 LISTHEAD(mfx->daemon, tmp7);
2130 LISTHEAD(mfx->theme, tmp8);
2134 LISTHEAD(mfx->font, tmp9);
2138 LISTHEAD(mfx->ime, tmp10);
2142 LISTHEAD(mfx->icon, tmp11);
2145 if (mfx->compatibility) {
2146 LISTHEAD(mfx->compatibility, tmp12);
2147 mfx->compatibility= tmp12;
2149 if (mfx->deviceprofile) {
2150 LISTHEAD(mfx->deviceprofile, tmp13);
2151 mfx->deviceprofile= tmp13;
2153 if (mfx->privileges) {
2154 LISTHEAD(mfx->privileges, tmp14);
2155 mfx->privileges = tmp14;
2160 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
2162 const xmlChar *node;
2165 if ((ret = __next_child_element(reader, -1))) {
2166 node = xmlTextReaderConstName(reader);
2168 _LOGD("xmlTextReaderConstName value is NULL\n");
2172 if (!strcmp(ASCII(node), "manifest")) {
2173 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
2174 __save_xml_attribute(reader, "package", &mfx->package, NULL);
2175 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
2176 __save_xml_attribute(reader, "version", &mfx->version, NULL);
2177 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
2178 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
2179 __save_xml_attribute(reader, "type", &mfx->type, "rpm");
2180 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
2181 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
2182 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
2183 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
2184 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
2185 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
2186 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
2187 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
2189 __save_xml_installed_time(mfx);
2190 __save_xml_root_path(mfx, uid);
2191 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
2192 __save_xml_default_value(mfx);
2194 ret = __start_process(reader, mfx, uid);
2196 _LOGD("No Manifest element found\n");
2203 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
2205 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
2207 void *lib_handle = NULL;
2208 int (*appsvc_operation) (const char *, uid_t);
2210 application_x *application = mfx->application;
2212 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
2213 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
2217 if ((appsvc_operation =
2218 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
2219 _LOGE("can not find symbol \n");
2223 for (; application; application = application->next) {
2224 ret = appsvc_operation(application->appid, uid);
2226 _LOGE("can not operation symbol \n");
2231 dlclose(lib_handle);
2236 #define PRELOAD_PACKAGE_LIST SYSCONFDIR "/package-manager/preload/preload_list.txt"
2237 static int __add_preload_info(manifest_x * mfx, const char *manifest, uid_t uid)
2240 char buffer[1024] = { 0 };
2243 if(strstr(manifest, getUserManifestPath(uid))) {
2244 free((void *)mfx->readonly);
2245 mfx->readonly = strdup("True");
2247 free((void *)mfx->preload);
2248 mfx->preload = strdup("True");
2250 free((void *)mfx->removable);
2251 mfx->removable = strdup("False");
2253 free((void *)mfx->system);
2254 mfx->system = strdup("True");
2259 fp = fopen(PRELOAD_PACKAGE_LIST, "r");
2261 _LOGE("no preload list\n");
2265 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
2266 if (buffer[0] == '#') {
2267 if(strcasestr(buffer, "RW_NORM"))
2269 else if(strcasestr(buffer, "RW_RM"))
2277 if(!strcmp(mfx->package, buffer)) {
2278 free((void *)mfx->preload);
2279 mfx->preload = strdup("True");
2281 free((void *)mfx->readonly);
2282 mfx->readonly = strdup("False");
2283 free((void *)mfx->removable);
2284 mfx->removable = strdup("False");
2285 } else if(state == 3){
2286 free((void *)mfx->readonly);
2287 mfx->readonly = strdup("False");
2288 free((void *)mfx->removable);
2289 mfx->removable = strdup("True");
2293 memset(buffer, 0x00, sizeof(buffer));
2302 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
2304 if (!strstr(manifest, getUserManifestPath(uid))) {
2305 /* if downloaded app is updated, then update tag set true*/
2307 free((void *)mfx->update);
2308 mfx->update = strdup("true");
2315 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
2317 /* desktop file is no longer used */
2321 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
2323 /* desktop file is no longer used */
2328 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
2330 pkgmgrinfo_basic_free_package((package_x *)mfx);
2333 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
2335 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
2336 xmlTextReaderPtr reader;
2337 manifest_x *mfx = NULL;
2339 reader = xmlReaderForFile(manifest, NULL, 0);
2341 mfx = malloc(sizeof(manifest_x));
2343 memset(mfx, '\0', sizeof(manifest_x));
2344 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
2345 _LOGD("Parsing Failed\n");
2346 pkgmgr_parser_free_manifest_xml(mfx);
2349 _LOGD("Parsing Success\n");
2351 _LOGD("Memory allocation error\n");
2353 xmlFreeTextReader(reader);
2355 _LOGD("Unable to create xml reader\n");
2361 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
2363 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
2364 xmlTextReaderPtr reader;
2365 manifest_x *mfx = NULL;
2367 reader = xmlReaderForFile(manifest, NULL, 0);
2369 mfx = malloc(sizeof(manifest_x));
2371 memset(mfx, '\0', sizeof(manifest_x));
2372 if (__process_manifest(reader, mfx, uid) < 0) {
2373 _LOGD("Parsing Failed\n");
2374 pkgmgr_parser_free_manifest_xml(mfx);
2377 _LOGD("Parsing Success\n");
2379 _LOGD("Memory allocation error\n");
2381 xmlFreeTextReader(reader);
2383 _LOGD("Unable to create xml reader\n");
2388 /* These APIs are intended to call parser directly */
2390 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2392 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2393 _LOGD("parsing manifest for installation: %s\n", manifest);
2395 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 __add_preload_info(mfx, manifest, GLOBAL_USER);
2406 _LOGD("Added preload infomation\n");
2408 __ps_process_tag(mfx, tagv);
2410 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2411 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2413 _LOGD("DB Insert Success\n");
2415 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2416 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2418 _LOGD("Creating metadata parser failed\n");
2420 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2422 _LOGD("Creating category parser failed\n");
2424 pkgmgr_parser_free_manifest_xml(mfx);
2425 _LOGD("Free Done\n");
2430 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2432 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2433 _LOGD("parsing manifest for installation: %s\n", manifest);
2434 manifest_x *mfx = NULL;
2438 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2439 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2441 _LOGD("Parsing Finished\n");
2443 __ps_process_tag(mfx, tagv);
2445 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2446 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2448 _LOGD("DB Insert Success\n");
2450 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2451 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2453 _LOGD("Creating metadata parser failed\n");
2454 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2456 _LOGD("Creating category parser failed\n");
2458 pkgmgr_parser_free_manifest_xml(mfx);
2459 _LOGD("Free Done\n");
2465 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2467 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2468 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2469 manifest_x *mfx = NULL;
2471 bool preload = false;
2472 bool system = false;
2473 char *csc_path = NULL;
2474 pkgmgrinfo_pkginfo_h handle = NULL;
2477 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2478 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2480 _LOGD("Parsing Finished\n");
2481 __add_preload_info(mfx, manifest, GLOBAL_USER);
2482 _LOGD("Added preload infomation\n");
2483 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2485 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2486 if (ret != PMINFO_R_OK)
2487 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2488 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2489 if (ret != PMINFO_R_OK)
2490 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2493 free((void *)mfx->preload);
2494 mfx->preload = strdup("true");
2497 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2498 if (ret != PMINFO_R_OK)
2499 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2501 free((void *)mfx->system);
2502 mfx->system = strdup("true");
2505 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2506 if (ret != PMINFO_R_OK)
2507 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2509 if (csc_path != NULL) {
2511 free((void *)mfx->csc_path);
2512 mfx->csc_path = strdup(csc_path);
2515 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2516 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2518 _LOGD("DB Update Success\n");
2520 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2521 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2523 _LOGD("Upgrade metadata parser failed\n");
2525 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2527 _LOGD("Creating category parser failed\n");
2528 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2529 pkgmgr_parser_free_manifest_xml(mfx);
2530 _LOGD("Free Done\n");
2536 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2538 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2539 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2540 manifest_x *mfx = NULL;
2542 bool preload = false;
2543 bool system = false;
2544 char *csc_path = NULL;
2545 pkgmgrinfo_pkginfo_h handle = NULL;
2548 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2549 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2551 _LOGD("Parsing Finished\n");
2552 __check_preload_updated(mfx, manifest, uid);
2554 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2555 if (ret != PMINFO_R_OK)
2556 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2557 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2558 if (ret != PMINFO_R_OK)
2559 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2562 free((void *)mfx->preload);
2563 mfx->preload = strdup("true");
2566 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2567 if (ret != PMINFO_R_OK)
2568 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2571 free((void *)mfx->system);
2572 mfx->system = strdup("true");
2575 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2576 if (ret != PMINFO_R_OK)
2577 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2578 if (csc_path != NULL) {
2580 free((void *)mfx->csc_path);
2581 mfx->csc_path = strdup(csc_path);
2584 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2585 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2586 _LOGD("DB Update Success\n");
2588 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2589 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2591 _LOGD("Upgrade metadata parser failed\n");
2592 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2594 _LOGD("Creating category parser failed\n");
2595 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2596 pkgmgr_parser_free_manifest_xml(mfx);
2597 _LOGD("Free Done\n");
2603 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2605 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2606 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2608 manifest_x *mfx = NULL;
2611 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2612 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2614 _LOGD("Parsing Finished\n");
2616 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2618 __add_preload_info(mfx, manifest, GLOBAL_USER);
2619 _LOGD("Added preload infomation\n");
2621 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2623 _LOGD("Removing metadata parser failed\n");
2625 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2627 _LOGD("Creating category parser failed\n");
2629 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2631 _LOGD("DB Delete failed\n");
2633 _LOGD("DB Delete Success\n");
2635 pkgmgr_parser_free_manifest_xml(mfx);
2636 _LOGD("Free Done\n");
2643 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2645 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2646 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2648 manifest_x *mfx = NULL;
2651 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2652 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2654 _LOGD("Parsing Finished\n");
2656 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2658 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2660 _LOGD("Removing metadata parser failed\n");
2662 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2664 _LOGD("Creating category parser failed\n");
2666 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2668 _LOGD("DB Delete failed\n");
2670 _LOGD("DB Delete Success\n");
2672 ret = __ps_remove_appsvc_db(mfx, uid);
2674 _LOGD("Removing appsvc_db failed\n");
2676 _LOGD("Removing appsvc_db Success\n");
2678 pkgmgr_parser_free_manifest_xml(mfx);
2679 _LOGD("Free Done\n");
2685 API int pkgmgr_parser_parse_manifest_for_preload()
2687 return pkgmgr_parser_update_preload_info_in_db();
2690 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
2692 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
2696 API char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid)
2698 return __pkgid_to_manifest(pkgid, uid);
2701 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
2703 return __pkgid_to_manifest(pkgid, GLOBAL_USER);
2706 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2708 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
2711 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2713 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
2716 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2718 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
2721 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2723 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2725 if (manifest == NULL) {
2726 _LOGE("manifest file is NULL\n");
2727 return PMINFO_R_EINVAL;
2730 xmlSchemaParserCtxtPtr ctx;
2731 xmlSchemaValidCtxtPtr vctx;
2732 xmlSchemaPtr xschema;
2733 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2735 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2736 return PMINFO_R_ERROR;
2738 xschema = xmlSchemaParse(ctx);
2739 if (xschema == NULL) {
2740 _LOGE("xmlSchemaParse() Failed\n");
2741 return PMINFO_R_ERROR;
2743 vctx = xmlSchemaNewValidCtxt(xschema);
2745 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2746 return PMINFO_R_ERROR;
2748 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2749 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2751 _LOGE("xmlSchemaValidateFile() failed\n");
2752 return PMINFO_R_ERROR;
2753 } else if (ret == 0) {
2754 _LOGE("Manifest is Valid\n");
2757 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2758 return PMINFO_R_ERROR;
2764 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2774 _LOGE("fork failed\n");
2779 int dev_null_fd = open ("/dev/null", O_RDWR);
2780 if (dev_null_fd >= 0)
2782 dup2 (dev_null_fd, 0);/*stdin*/
2783 dup2 (dev_null_fd, 1);/*stdout*/
2784 dup2 (dev_null_fd, 2);/*stderr*/
2787 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
2788 SCHEMA_FILE, NULL) < 0) {
2789 _LOGE("execl error\n");
2799 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
2803 _LOGE("waitpid failed\n");
2809 if(WIFEXITED(status) && !WEXITSTATUS(status))