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_operation(xmlTextReaderPtr reader, const char **operation);
100 static int __ps_process_uri(xmlTextReaderPtr reader, const char **uri);
101 static int __ps_process_mime(xmlTextReaderPtr reader, const char **mime);
102 static int __ps_process_subapp(xmlTextReaderPtr reader, const char **subapp);
103 static int __ps_process_condition(xmlTextReaderPtr reader, const char **condition);
104 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
105 static int __ps_process_category(xmlTextReaderPtr reader, const char **category);
106 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
107 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
108 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
109 static int __ps_process_request(xmlTextReaderPtr reader, const char **request);
110 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
111 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc);
112 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions);
113 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
114 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
115 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
116 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
117 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
118 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol);
119 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
120 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid);
121 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid);
122 static int __next_child_element(xmlTextReaderPtr reader, int depth);
123 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
124 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
125 static void __str_trim(char *input);
126 static char *__get_parser_plugin(const char *type);
127 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
128 API int __is_admin();
130 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, const char **xml_attribute, char *default_value)
132 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
134 *xml_attribute = strdup((const char *)attrib_val);
137 if (default_value != NULL) {
138 *xml_attribute = strdup(default_value);
143 static void __save_xml_lang(xmlTextReaderPtr reader, const char **xml_attribute)
145 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
146 if (attrib_val != NULL)
147 *xml_attribute = strdup(ASCII(attrib_val));
149 *xml_attribute = strdup(DEFAULT_LOCALE);
152 static void __save_xml_value(xmlTextReaderPtr reader, const char **xml_attribute)
154 xmlTextReaderRead(reader);
155 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
158 *xml_attribute = strdup((const char *)attrib_val);
161 static void __save_xml_installed_time(manifest_x *mfx)
163 char buf[PKG_STRING_LEN_MAX] = {'\0'};
167 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
168 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
169 mfx->installed_time = val;
172 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
174 char root[PKG_STRING_LEN_MAX] = { '\0' };
180 tzplatform_set_user(uid);
181 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
182 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
184 mfx->root_path = strdup(root);
186 tzplatform_reset_user();
189 static void __save_xml_default_value(manifest_x * mfx)
191 mfx->preload = strdup("False");
192 mfx->removable = strdup("True");
193 mfx->readonly = strdup("False");
194 mfx->update = strdup("False");
195 mfx->system = strdup("False");
196 mfx->installed_storage= strdup("installed_internal");
197 package = mfx->package;
200 void *__open_lib_handle(char *tag)
202 char *lib_path = NULL;
203 void *lib_handle = NULL;
205 lib_path = __get_parser_plugin(tag);
206 retvm_if(!lib_path, NULL, "lib_path get fail");
208 lib_handle = dlopen(lib_path, RTLD_LAZY);
209 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
214 void __close_lib_handle(void *lib_handle)
219 static void __str_trim(char *input)
221 char *trim_str = input;
226 while (*input != 0) {
227 if (!isspace(*input)) {
240 uid_t uid = getuid();
241 if ((uid_t) 0 == uid )
249 static char * __get_tag_by_key(char *md_key)
253 if (md_key == NULL) {
254 _LOGD("md_key is NULL\n");
258 md_tag = strrchr(md_key, 47) + 1;
261 return strdup(md_tag);
264 static char *__get_metadata_parser_plugin(const char *type)
267 char buffer[1024] = { 0 };
268 char temp_path[1024] = { 0 };
272 _LOGE("invalid argument\n");
276 fp = fopen(PKG_PARSER_CONF_PATH, "r");
278 _LOGE("no matching metadata parser\n");
282 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
283 if (buffer[0] == '#')
288 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
289 path = path + strlen(METADATA_PARSER_NAME);
294 memset(buffer, 0x00, 1024);
301 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
305 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
307 return strdup(temp_path);
310 static char *__get_category_parser_plugin(const char *type)
313 char buffer[1024] = { 0 };
314 char temp_path[1024] = { 0 };
318 _LOGE("invalid argument\n");
322 fp = fopen(PKG_PARSER_CONF_PATH, "r");
324 _LOGE("no matching metadata parser\n");
328 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
329 if (buffer[0] == '#')
334 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
335 path = path + strlen(CATEGORY_PARSER_NAME);
340 memset(buffer, 0x00, 1024);
347 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
351 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
353 return strdup(temp_path);
356 static char *__get_parser_plugin(const char *type)
359 char buffer[1024] = { 0 };
360 char temp_path[1024] = { 0 };
364 _LOGE("invalid argument\n");
368 fp = fopen(PKG_PARSER_CONF_PATH, "r");
370 _LOGE("no matching backendlib\n");
374 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
375 if (buffer[0] == '#')
380 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
381 path = path + strlen(PKG_PARSERLIB);
385 memset(buffer, 0x00, 1024);
392 _LOGE("no matching backendlib\n");
396 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
398 return strdup(temp_path);
401 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
402 ACTION_TYPE action, const char *pkgid)
404 int (*plugin_install) (xmlDocPtr, const char *);
410 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
413 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
415 case ACTION_UNINSTALL:
416 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
422 if ((plugin_install =
423 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
424 _LOGE("can not find symbol[%s] \n", ac);
428 ret = plugin_install(docPtr, pkgid);
429 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
435 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
436 ACTION_TYPE action, const char *pkgid, const char *appid)
438 char *lib_path = NULL;
439 void *lib_handle = NULL;
440 int (*metadata_parser_plugin) (const char *, const char *, GList *);
446 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
449 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
451 case ACTION_UNINSTALL:
452 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
458 lib_path = __get_metadata_parser_plugin(tag);
460 _LOGE("get %s parser fail\n", tag);
464 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
465 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
469 if ((metadata_parser_plugin =
470 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
471 _LOGE("can not find symbol[%s] \n",ac);
475 ret = metadata_parser_plugin(pkgid, appid, md_list);
477 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
479 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
489 static int __ps_run_category_parser(GList *category_list, const char *tag,
490 ACTION_TYPE action, const char *pkgid, const char *appid)
492 char *lib_path = NULL;
493 void *lib_handle = NULL;
494 int (*category_parser_plugin) (const char *, const char *, GList *);
500 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
503 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
505 case ACTION_UNINSTALL:
506 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
512 lib_path = __get_category_parser_plugin(tag);
514 _LOGE("get %s parser fail\n", tag);
518 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
519 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
523 if ((category_parser_plugin =
524 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
525 _LOGE("can not find symbol[%s] \n",ac);
529 ret = category_parser_plugin(pkgid, appid, category_list);
531 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
533 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
543 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
544 ACTION_TYPE action, const char *pkgid)
546 char *lib_path = NULL;
547 void *lib_handle = NULL;
548 int (*plugin_install) (xmlDocPtr, const char *);
554 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
557 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
559 case ACTION_UNINSTALL:
560 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
566 lib_path = __get_parser_plugin(tag);
571 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
572 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
575 if ((plugin_install =
576 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
577 _LOGE("can not find symbol[%s] \n", ac);
581 ret = plugin_install(docPtr, pkgid);
583 _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
585 _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
595 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid)
601 _LOGE("pkgid is NULL");
605 size = strlen(getUserManifestPath(uid)) + strlen(pkgid) + 10;
606 manifest = malloc(size);
607 if (manifest == NULL) {
611 memset(manifest, '\0', size);
612 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
614 if (access(manifest, F_OK)) {
615 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
621 static void __metadata_parser_clear_dir_list(GList* dir_list)
624 __metadata_t* detail = NULL;
627 list = g_list_first(dir_list);
629 detail = (__metadata_t *)list->data;
632 free((void *)detail->key);
634 free((void *)detail->value);
637 list = g_list_next(list);
639 g_list_free(dir_list);
643 static void __category_parser_clear_dir_list(GList* dir_list)
646 __category_t* detail = NULL;
649 list = g_list_first(dir_list);
651 detail = (__category_t *)list->data;
654 free((void *)detail->name);
658 list = g_list_next(list);
660 g_list_free(dir_list);
664 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
669 if (xmlTextReaderDepth(reader) != 1) {
670 _LOGE("Node depth is not 1");
674 if (xmlTextReaderNodeType(reader) != 1) {
675 _LOGE("Node type is not 1");
679 const xmlChar *value;
680 name = xmlTextReaderConstName(reader);
682 _LOGE("TEST TEST TES\n");
683 name = BAD_CAST "--";
686 value = xmlTextReaderConstValue(reader);
688 if (xmlStrlen(value) > 40) {
689 _LOGD(" %.40s...", value);
695 name = xmlTextReaderConstName(reader);
697 _LOGE("TEST TEST TES\n");
698 name = BAD_CAST "--";
701 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
702 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
703 if (copyDocPtr == NULL)
705 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
706 if (rootElement == NULL)
708 xmlNode *cur_node = xmlFirstElementChild(rootElement);
709 if (cur_node == NULL)
711 xmlNode *temp = xmlTextReaderExpand(reader);
714 xmlNode *next_node = NULL;
715 while(cur_node != NULL) {
716 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
717 (temp->line == cur_node->line) ) {
721 next_node = xmlNextElementSibling(cur_node);
722 xmlUnlinkNode(cur_node);
723 xmlFreeNode(cur_node);
724 cur_node = next_node;
727 if (cur_node == NULL)
729 next_node = xmlNextElementSibling(cur_node);
731 cur_node->next = NULL;
732 next_node->prev = NULL;
733 xmlFreeNodeList(next_node);
734 xmlSetTreeDoc(cur_node, copyDocPtr);
736 xmlSetTreeDoc(cur_node, copyDocPtr);
739 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
745 static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
749 char buffer[1024] = { 0, };
752 GList *md_tmp = NULL;
756 GList *md_list = NULL;
757 __metadata_t *md_detail = NULL;
759 md_tag = __get_tag_by_key(md_key);
760 if (md_tag == NULL) {
761 _LOGD("md_tag is NULL\n");
765 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
766 app = (application_x *)app_tmp->data;
769 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
770 md = (metadata_x *)md_tmp->data;
773 //get glist of metadata key and value combination
774 memset(buffer, 0x00, 1024);
775 snprintf(buffer, 1024, "%s/", md_key);
776 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
777 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
778 if (md_detail == NULL) {
779 _LOGD("Memory allocation failed\n");
783 md_detail->key = strdup(md->key);
784 if (md_detail->key == NULL) {
785 _LOGD("Memory allocation failed\n");
790 md_detail->value = strdup(md->value);
791 if (md_detail->value == NULL) {
792 _LOGD("Memory allocation failed\n");
793 free((void *)md_detail->key);
798 md_list = g_list_append(md_list, (gpointer)md_detail);
803 //send glist to parser when tags for metadata plugin parser exist.
805 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
807 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
810 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
813 __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, };
836 const char *category;
837 char *category_tag = NULL;
839 GList *category_list = NULL;
840 __category_t *category_detail = NULL;
842 category_tag = __get_tag_by_key(category_key);
843 if (category_tag == NULL) {
844 _LOGD("md_tag is NULL\n");
848 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
849 app = (application_x *)app_tmp->data;
852 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
853 category = (const char *)category_tmp->data;
854 //get glist of category key and value combination
855 memset(buffer, 0x00, 1024);
856 snprintf(buffer, 1024, "%s/", category_key);
857 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
858 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
859 if (category_detail == NULL) {
860 _LOGD("Memory allocation failed\n");
864 category_detail->name = strdup(category);
865 if (category_detail->name == NULL) {
866 _LOGD("Memory allocation failed\n");
867 free(category_detail);
871 category_list = g_list_append(category_list, (gpointer)category_detail);
876 //send glist to parser when tags for metadata plugin parser exist.
878 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
880 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
882 _LOGD("category_parser success for tag[%s]\n", category_tag);
884 __category_parser_clear_dir_list(category_list);
885 category_list = NULL;
891 __category_parser_clear_dir_list(category_list);
899 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
901 switch (xmlTextReaderNodeType(reader)) {
902 case XML_READER_TYPE_END_ELEMENT:
906 case XML_READER_TYPE_ELEMENT:
908 // Elements without closing tag don't receive
909 const xmlChar *elementName =
910 xmlTextReaderLocalName(reader);
911 if (elementName == NULL) {
915 if (strcmp(tag, ASCII(elementName)) == 0) {
916 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
917 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
928 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
930 int (*plugin_install) (const char *);
934 if (process == PLUGIN_PRE_PROCESS) {
937 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
940 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
942 case ACTION_UNINSTALL:
943 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
948 } else if (process == PLUGIN_POST_PROCESS) {
951 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
954 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
956 case ACTION_UNINSTALL:
957 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
965 if ((plugin_install =
966 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
970 ret = plugin_install(pkgid);
974 static int __next_child_element(xmlTextReaderPtr reader, int depth)
976 int ret = xmlTextReaderRead(reader);
977 int cur = xmlTextReaderDepth(reader);
980 switch (xmlTextReaderNodeType(reader)) {
981 case XML_READER_TYPE_ELEMENT:
982 if (cur == depth + 1)
985 case XML_READER_TYPE_TEXT:
986 /*text is handled by each function separately*/
987 if (cur == depth + 1)
990 case XML_READER_TYPE_END_ELEMENT:
999 ret = xmlTextReaderRead(reader);
1000 cur = xmlTextReaderDepth(reader);
1004 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1006 xmlTextReaderPtr reader;
1010 void *lib_handle = NULL;
1011 char tag[PKG_STRING_LEN_MAX] = { 0 };
1013 fp = fopen(TAG_PARSER_LIST, "r");
1014 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1016 while (fgets(tag, sizeof(tag), fp) != NULL) {
1019 lib_handle = __open_lib_handle(tag);
1020 if (lib_handle == NULL)
1023 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1024 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1026 docPtr = xmlReadFile(filename, NULL, 0);
1027 reader = xmlReaderWalker(docPtr);
1028 if (reader != NULL) {
1029 ret = xmlTextReaderRead(reader);
1031 __process_tag(lib_handle, reader, action, tag, mfx->package);
1032 ret = xmlTextReaderRead(reader);
1034 xmlFreeTextReader(reader);
1037 _LOGD("%s : failed to parse", filename);
1040 _LOGD("Unable to open %s", filename);
1043 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1044 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1046 __close_lib_handle(lib_handle);
1048 memset(tag, 0x00, sizeof(tag));
1057 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1059 fprintf(stdout,"__ps_process_metadata_parser\n");
1062 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1064 fp = fopen(METADATA_PARSER_LIST, "r");
1066 _LOGD("no preload list\n");
1070 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1072 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1083 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1087 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1089 fp = fopen(CATEGORY_PARSER_LIST, "r");
1091 _LOGD("no category parser list\n");
1095 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1096 __str_trim(category_key);
1097 ret = __run_category_parser_prestep(mfx, category_key, action);
1108 static int __ps_process_allowed(xmlTextReaderPtr reader, const char **allowed)
1110 __save_xml_value(reader, allowed);
1114 static int __ps_process_operation(xmlTextReaderPtr reader, const char **operation)
1116 __save_xml_attribute(reader, "name", operation, NULL);
1120 static int __ps_process_uri(xmlTextReaderPtr reader, const char **uri)
1122 __save_xml_attribute(reader, "name", uri, NULL);
1126 static int __ps_process_mime(xmlTextReaderPtr reader, const char **mime)
1128 __save_xml_attribute(reader, "name", mime, NULL);
1132 static int __ps_process_subapp(xmlTextReaderPtr reader, const char **subapp)
1134 __save_xml_attribute(reader, "name", subapp, NULL);
1138 static int __ps_process_condition(xmlTextReaderPtr reader, const char **condition)
1140 __save_xml_attribute(reader, "name", condition, NULL);
1144 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
1146 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
1147 __save_xml_value(reader, ¬ification->text);
1151 static int __ps_process_category(xmlTextReaderPtr reader, const char **category)
1153 __save_xml_attribute(reader, "name", category, NULL);
1157 static int __ps_process_privilege(xmlTextReaderPtr reader, const char **privilege)
1159 __save_xml_value(reader, privilege);
1163 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
1165 __save_xml_attribute(reader, "key", &metadata->key, NULL);
1166 __save_xml_attribute(reader, "value", &metadata->value, NULL);
1170 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
1172 __save_xml_attribute(reader, "type", &permission->type, NULL);
1173 __save_xml_value(reader, &permission->value);
1177 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
1179 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
1180 __save_xml_value(reader, &compatibility->text);
1184 static int __ps_process_request(xmlTextReaderPtr reader, const char **request)
1186 __save_xml_value(reader, request);
1190 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
1192 const xmlChar *node;
1197 __save_xml_attribute(reader, "path", &define->path, NULL);
1199 depth = xmlTextReaderDepth(reader);
1200 while ((ret = __next_child_element(reader, depth))) {
1201 node = xmlTextReaderConstName(reader);
1203 _LOGD("xmlTextReaderConstName value is NULL\n");
1207 if (!strcmp(ASCII(node), "allowed")) {
1209 ret = __ps_process_allowed(reader, &val);
1211 define->allowed = g_list_append(define->allowed, (gpointer)val);
1212 } else if (!strcmp(ASCII(node), "request")) {
1214 ret = __ps_process_request(reader, &val);
1216 define->request = g_list_append(define->request, (gpointer)val);
1221 _LOGD("Processing define failed\n");
1228 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol)
1230 const xmlChar *node;
1234 depth = xmlTextReaderDepth(reader);
1235 while ((ret = __next_child_element(reader, depth))) {
1236 node = xmlTextReaderConstName(reader);
1238 _LOGD("xmlTextReaderConstName value is NULL\n");
1242 if (!strcmp(ASCII(node), "operation")) {
1243 __save_xml_attribute(reader, "name", &appcontrol->operation, NULL);
1244 _LOGD("operation processing\n");
1245 } else if (!strcmp(ASCII(node), "uri")) {
1246 __save_xml_attribute(reader, "name", &appcontrol->uri, NULL);
1247 _LOGD("uri processing\n");
1248 } else if (!strcmp(ASCII(node), "mime")) {
1249 __save_xml_attribute(reader, "name", &appcontrol->mime, NULL);
1250 _LOGD("mime processing\n");
1254 _LOGD("Processing appcontrol failed\n");
1262 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
1264 const xmlChar *node;
1269 depth = xmlTextReaderDepth(reader);
1270 while ((ret = __next_child_element(reader, depth))) {
1271 node = xmlTextReaderConstName(reader);
1273 _LOGD("xmlTextReaderConstName value is NULL\n");
1277 if (!strcmp(ASCII(node), "operation")) {
1279 ret = __ps_process_operation(reader, &val);
1280 appsvc->operation = val;
1281 _LOGD("operation processing\n");
1282 } else if (!strcmp(ASCII(node), "uri")) {
1284 ret = __ps_process_uri(reader, &val);
1286 _LOGD("uri processing\n");
1287 } else if (!strcmp(ASCII(node), "mime")) {
1289 ret = __ps_process_mime(reader, &val);
1291 _LOGD("mime processing\n");
1292 } else if (!strcmp(ASCII(node), "subapp")) {
1294 ret = __ps_process_subapp(reader, &val);
1295 appsvc->subapp = val;
1296 _LOGD("subapp processing\n");
1300 _LOGD("Processing appsvc failed\n");
1305 xmlTextReaderRead(reader);
1306 if (xmlTextReaderValue(reader))
1307 appsvc->text = ASCII(xmlTextReaderValue(reader));
1313 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
1315 const xmlChar *node;
1320 depth = xmlTextReaderDepth(reader);
1321 while ((ret = __next_child_element(reader, depth))) {
1322 node = xmlTextReaderConstName(reader);
1324 _LOGD("xmlTextReaderConstName value is NULL\n");
1328 if (strcmp(ASCII(node), "privilege") == 0) {
1330 ret = __ps_process_privilege(reader, &val);
1332 *privileges = g_list_append(*privileges, (gpointer)val);
1336 _LOGD("Processing privileges failed\n");
1343 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
1345 const xmlChar *node;
1350 depth = xmlTextReaderDepth(reader);
1351 while ((ret = __next_child_element(reader, depth))) {
1352 node = xmlTextReaderConstName(reader);
1354 _LOGD("xmlTextReaderConstName value is NULL\n");
1358 if (strcmp(ASCII(node), "condition") == 0) {
1360 ret = __ps_process_condition(reader, &val);
1362 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
1366 _LOGD("Processing launchconditions failed\n");
1374 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
1376 const xmlChar *node;
1380 depth = xmlTextReaderDepth(reader);
1381 while ((ret = __next_child_element(reader, depth))) {
1382 node = xmlTextReaderConstName(reader);
1384 _LOGD("xmlTextReaderConstName value is NULL\n");
1388 if (!strcmp(ASCII(node), "define")) {
1389 define_x *define = calloc(1, sizeof(define_x));
1390 if (define == NULL) {
1391 _LOGD("Malloc Failed\n");
1394 datashare->define = g_list_append(datashare->define, define);
1395 ret = __ps_process_define(reader, define);
1396 } else if (!strcmp(ASCII(node), "request")) {
1398 ret = __ps_process_request(reader, &val);
1400 datashare->request = g_list_append(datashare->request, (gpointer)val);
1404 _LOGD("Processing data-share failed\n");
1411 static char *__get_icon_with_path(const char *icon, uid_t uid)
1413 char icon_with_path[BUFSIZE];
1414 const char *app_path;
1416 if (!icon || !package)
1419 /* just use absolute path */
1420 if (index(icon, '/'))
1421 return strdup(icon);
1424 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1425 getIconPath(uid), icon);
1426 if (access(icon_with_path, F_OK) == 0)
1429 /* for backward compatibility (.../default/small/...)
1430 * this should be removed
1432 snprintf(icon_with_path, sizeof(icon_with_path),
1433 "%sdefault/small/%s",
1434 getIconPath(uid), icon);
1435 if (access(icon_with_path, F_OK) == 0)
1438 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
1439 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
1441 tzplatform_set_user(uid);
1442 app_path = tzplatform_getenv(TZ_USER_APP);
1443 tzplatform_reset_user();
1446 /* If doesn't exist in case of Global app,
1447 * try to get icon directly into app's directory
1449 snprintf(icon_with_path, sizeof(icon_with_path),
1450 "%s/%s/%s", app_path, package, icon);
1451 if (access(icon_with_path, F_OK) == 0)
1454 /* some preload package has icons at below path */
1455 snprintf(icon_with_path, sizeof(icon_with_path),
1456 "%s/%s/res/icons/%s", app_path, package, icon);
1457 if (access(icon_with_path, F_OK) == 0)
1460 /* since 2.3 tpk package */
1461 snprintf(icon_with_path, sizeof(icon_with_path),
1462 "%s/%s/shared/res/%s", app_path, package, icon);
1463 if (access(icon_with_path, F_OK) == 0)
1466 _LOGE("cannot find icon path for [%s]", icon);
1470 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1472 return strdup(icon_with_path);
1475 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1478 char delims[] = "=";
1479 char *ret_result = NULL;
1485 for (tag = strdup(tagv[0]); tag != NULL; ) {
1486 ret_result = strtok(tag, delims);
1488 /*check tag : preload */
1489 if (strcmp(ret_result, "preload") == 0) {
1490 ret_result = strtok(NULL, delims);
1491 if (strcmp(ret_result, "true") == 0) {
1492 free((void *)mfx->preload);
1493 mfx->preload = strdup("true");
1494 } else if (strcmp(ret_result, "false") == 0) {
1495 free((void *)mfx->preload);
1496 mfx->preload = strdup("false");
1498 /*check tag : removable*/
1499 } else if (strcmp(ret_result, "removable") == 0) {
1500 ret_result = strtok(NULL, delims);
1501 if (strcmp(ret_result, "true") == 0){
1502 free((void *)mfx->removable);
1503 mfx->removable = strdup("true");
1504 } else if (strcmp(ret_result, "false") == 0) {
1505 free((void *)mfx->removable);
1506 mfx->removable = strdup("false");
1508 /*check tag : not matched*/
1510 _LOGD("tag process [%s]is not defined\n", ret_result);
1514 /*check next value*/
1515 if (tagv[++i] != NULL)
1516 tag = strdup(tagv[i]);
1518 _LOGD("tag process success...\n");
1524 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1526 __save_xml_attribute(reader, "name", &icon->name, NULL);
1527 __save_xml_attribute(reader, "section", &icon->section, NULL);
1528 __save_xml_attribute(reader, "size", &icon->size, NULL);
1529 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1530 __save_xml_lang(reader, &icon->lang);
1532 xmlTextReaderRead(reader);
1533 const char *text = ASCII(xmlTextReaderValue(reader));
1535 icon->text = (const char *)__get_icon_with_path(text, uid);
1542 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1544 __save_xml_attribute(reader, "name", &image->name, NULL);
1545 __save_xml_attribute(reader, "section", &image->section, NULL);
1546 __save_xml_lang(reader, &image->lang);
1547 __save_xml_value(reader, &image->text);
1551 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1553 __save_xml_attribute(reader, "name", &label->name, NULL);
1554 __save_xml_lang(reader, &label->lang);
1555 __save_xml_value(reader, &label->text);
1560 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1562 __save_xml_attribute(reader, "email", &author->email, NULL);
1563 __save_xml_attribute(reader, "href", &author->href, NULL);
1564 __save_xml_value(reader, &author->text);
1568 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1570 __save_xml_lang(reader, &description->lang);
1571 __save_xml_value(reader, &description->text);
1575 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1577 __save_xml_lang(reader, &license->lang);
1578 __save_xml_value(reader, &license->text);
1582 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1584 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1585 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1586 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1590 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
1592 const xmlChar *node;
1597 __save_xml_attribute(reader, "appid", &application->appid, NULL);
1598 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1599 __save_xml_attribute(reader, "exec", &application->exec, NULL);
1600 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
1601 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
1602 __save_xml_attribute(reader, "type", &application->type, NULL);
1603 __save_xml_attribute(reader, "categories", &application->categories, NULL);
1604 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
1605 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
1606 __save_xml_attribute(reader, "enabled", &application->enabled, "true");
1607 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
1608 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
1609 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
1610 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
1611 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
1612 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
1613 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
1614 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
1615 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
1616 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
1617 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : "svcapp");
1618 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1619 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);
1620 __save_xml_attribute(reader, "submode", &application->submode, "false");
1621 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
1622 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
1623 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
1624 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
1625 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
1627 application->package= strdup(package);
1629 depth = xmlTextReaderDepth(reader);
1630 while ((ret = __next_child_element(reader, depth))) {
1631 node = xmlTextReaderConstName(reader);
1633 _LOGD("xmlTextReaderConstName value is NULL\n");
1636 if (!strcmp(ASCII(node), "label")) {
1637 label_x *label = calloc(1, sizeof(label_x));
1638 if (label == NULL) {
1639 _LOGD("Malloc Failed\n");
1642 application->label = g_list_append(application->label, label);
1643 ret = __ps_process_label(reader, label);
1644 } else if (!strcmp(ASCII(node), "icon")) {
1645 icon_x *icon = calloc(1, sizeof(icon_x));
1647 _LOGD("Malloc Failed\n");
1650 application->icon = g_list_append(application->icon, icon);
1651 ret = __ps_process_icon(reader, icon, uid);
1652 } else if (!strcmp(ASCII(node), "image")) {
1653 image_x *image = calloc(1, sizeof(image_x));
1654 if (image == NULL) {
1655 _LOGD("Malloc Failed\n");
1658 application->image = g_list_append(application->image, image);
1659 ret = __ps_process_image(reader, image);
1660 } else if (!strcmp(ASCII(node), "category")) {
1662 ret = __ps_process_category(reader, &val);
1664 application->category = g_list_append(application->category, (gpointer)val);
1665 } else if (!strcmp(ASCII(node), "metadata")) {
1666 metadata_x *metadata = calloc(1, sizeof(metadata_x));
1667 if (metadata == NULL) {
1668 _LOGD("Malloc Failed\n");
1671 application->metadata = g_list_append(application->metadata, metadata);
1672 ret = __ps_process_metadata(reader, metadata);
1673 } else if (!strcmp(ASCII(node), "permission")) {
1674 permission_x *permission = calloc(1, sizeof(permission_x));
1675 if (permission == NULL) {
1676 _LOGD("Malloc Failed\n");
1679 application->permission = g_list_append(application->permission, permission);
1680 ret = __ps_process_permission(reader, permission);
1681 } else if (!strcmp(ASCII(node), "app-control")) {
1682 appcontrol_x *appcontrol = calloc(1, sizeof(appcontrol_x));
1683 if (appcontrol == NULL) {
1684 _LOGD("Malloc Failed\n");
1687 application->appcontrol = g_list_append(application->appcontrol, appcontrol);
1688 ret = __ps_process_appcontrol(reader, appcontrol);
1689 } else if (!strcmp(ASCII(node), "application-service")) {
1690 appsvc_x *appsvc = calloc(1, sizeof(appsvc_x));
1691 if (appsvc == NULL) {
1692 _LOGD("Malloc Failed\n");
1695 application->appsvc = g_list_append(application->appsvc, appsvc);
1696 ret = __ps_process_appsvc(reader, appsvc);
1697 } else if (!strcmp(ASCII(node), "data-share")) {
1698 datashare_x *datashare = calloc(1, sizeof(datashare_x));
1699 if (datashare == NULL) {
1700 _LOGD("Malloc Failed\n");
1703 application->datashare = g_list_append(application->datashare, datashare);
1704 ret = __ps_process_datashare(reader, datashare);
1705 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1706 ret = __ps_process_launchconditions(reader, &application->launchconditions);
1707 } else if (!strcmp(ASCII(node), "notification")) {
1708 notification_x *notification = calloc(1, sizeof(notification_x));
1709 if (notification == NULL) {
1710 _LOGD("Malloc Failed\n");
1713 application->notification = g_list_append(application->notification, notification);
1714 ret = __ps_process_notification(reader, notification);
1715 } else if (!strcmp(ASCII(node), "datacontrol")) {
1716 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
1717 if (datacontrol == NULL) {
1718 _LOGD("Malloc Failed\n");
1721 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
1722 ret = __ps_process_datacontrol(reader, datacontrol);
1726 _LOGD("Processing application failed\n");
1734 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1736 _LOGD("__start_process\n");
1737 const xmlChar *node;
1741 depth = xmlTextReaderDepth(reader);
1742 while ((ret = __next_child_element(reader, depth))) {
1743 node = xmlTextReaderConstName(reader);
1745 _LOGD("xmlTextReaderConstName value is NULL\n");
1749 if (!strcmp(ASCII(node), "label")) {
1750 label_x *label = calloc(1, sizeof(label_x));
1751 if (label == NULL) {
1752 _LOGD("Malloc Failed\n");
1755 mfx->label = g_list_append(mfx->label, label);
1756 ret = __ps_process_label(reader, label);
1757 } else if (!strcmp(ASCII(node), "author")) {
1758 author_x *author = calloc(1, sizeof(author_x));
1759 if (author == NULL) {
1760 _LOGD("Malloc Failed\n");
1763 mfx->author = g_list_append(mfx->author, author);
1764 ret = __ps_process_author(reader, author);
1765 } else if (!strcmp(ASCII(node), "description")) {
1766 description_x *description = calloc(1, sizeof(description_x));
1767 if (description == NULL) {
1768 _LOGD("Malloc Failed\n");
1771 mfx->description = g_list_append(mfx->description, description);
1772 ret = __ps_process_description(reader, description);
1773 } else if (!strcmp(ASCII(node), "license")) {
1774 license_x *license = calloc(1, sizeof(license_x));
1775 if (license == NULL) {
1776 _LOGD("Malloc Failed\n");
1779 mfx->license = g_list_append(mfx->license, license);
1780 ret = __ps_process_license(reader, license);
1781 } else if (!strcmp(ASCII(node), "privileges")) {
1782 ret = __ps_process_privileges(reader, &mfx->privileges);
1783 } else if (!strcmp(ASCII(node), "ui-application")) {
1784 application_x *application = calloc(1, sizeof(application_x));
1785 if (application == NULL) {
1786 _LOGD("Malloc Failed\n");
1789 mfx->application = g_list_append(mfx->application, application);
1790 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1791 } else if (!strcmp(ASCII(node), "service-application")) {
1792 application_x *application = calloc(1, sizeof(application_x));
1793 if (application == NULL) {
1794 _LOGD("Malloc Failed\n");
1797 mfx->application = g_list_append(mfx->application, application);
1798 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
1799 } else if (!strcmp(ASCII(node), "icon")) {
1800 icon_x *icon = calloc(1, sizeof(icon_x));
1802 _LOGD("Malloc Failed\n");
1805 mfx->icon = g_list_append(mfx->icon, icon);
1806 ret = __ps_process_icon(reader, icon, uid);
1807 } else if (!strcmp(ASCII(node), "compatibility")) {
1808 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
1809 if (compatibility == NULL) {
1810 _LOGD("Malloc Failed\n");
1813 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
1814 ret = __ps_process_compatibility(reader, compatibility);
1815 } else if (!strcmp(ASCII(node), "shortcut-list")) {
1817 } else if (!strcmp(ASCII(node), "livebox")) {
1819 } else if (!strcmp(ASCII(node), "account")) {
1821 } else if (!strcmp(ASCII(node), "notifications")) {
1823 } else if (!strcmp(ASCII(node), "ime")) {
1825 } else if (!strcmp(ASCII(node), "feature")) {
1828 _LOGE("Unknown element: %s", ASCII(node));
1833 _LOGD("Processing manifest failed\n");
1840 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1842 const xmlChar *node;
1845 if ((ret = __next_child_element(reader, -1))) {
1846 node = xmlTextReaderConstName(reader);
1848 _LOGD("xmlTextReaderConstName value is NULL\n");
1852 if (!strcmp(ASCII(node), "manifest")) {
1853 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1854 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1855 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1856 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1857 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1858 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1859 __save_xml_attribute(reader, "type", &mfx->type, "rpm");
1860 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1861 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1862 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1863 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1864 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1865 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1866 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1867 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1869 __save_xml_installed_time(mfx);
1870 __save_xml_root_path(mfx, uid);
1871 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1872 __save_xml_default_value(mfx);
1874 ret = __start_process(reader, mfx, uid);
1876 _LOGD("No Manifest element found\n");
1883 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
1885 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
1887 void *lib_handle = NULL;
1888 int (*appsvc_operation) (const char *, uid_t);
1891 application_x *application;
1893 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1894 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
1898 if ((appsvc_operation =
1899 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1900 _LOGE("can not find symbol \n");
1904 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1905 application = (application_x *)tmp->data;
1906 if (application == NULL)
1908 ret = appsvc_operation(application->appid, uid);
1910 _LOGE("can not operation symbol \n");
1915 dlclose(lib_handle);
1920 #define PRELOAD_PACKAGE_LIST SYSCONFDIR "/package-manager/preload/preload_list.txt"
1921 static int __add_preload_info(manifest_x * mfx, const char *manifest, uid_t uid)
1924 char buffer[1024] = { 0 };
1927 if(strstr(manifest, getUserManifestPath(uid))) {
1928 free((void *)mfx->readonly);
1929 mfx->readonly = strdup("True");
1931 free((void *)mfx->preload);
1932 mfx->preload = strdup("True");
1934 free((void *)mfx->removable);
1935 mfx->removable = strdup("False");
1937 free((void *)mfx->system);
1938 mfx->system = strdup("True");
1943 fp = fopen(PRELOAD_PACKAGE_LIST, "r");
1945 _LOGE("no preload list\n");
1949 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1950 if (buffer[0] == '#') {
1951 if(strcasestr(buffer, "RW_NORM"))
1953 else if(strcasestr(buffer, "RW_RM"))
1961 if(!strcmp(mfx->package, buffer)) {
1962 free((void *)mfx->preload);
1963 mfx->preload = strdup("True");
1965 free((void *)mfx->readonly);
1966 mfx->readonly = strdup("False");
1967 free((void *)mfx->removable);
1968 mfx->removable = strdup("False");
1969 } else if(state == 3){
1970 free((void *)mfx->readonly);
1971 mfx->readonly = strdup("False");
1972 free((void *)mfx->removable);
1973 mfx->removable = strdup("True");
1977 memset(buffer, 0x00, sizeof(buffer));
1986 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1988 if (!strstr(manifest, getUserManifestPath(uid))) {
1989 /* if downloaded app is updated, then update tag set true*/
1991 free((void *)mfx->update);
1992 mfx->update = strdup("true");
1999 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
2001 /* desktop file is no longer used */
2005 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
2007 /* desktop file is no longer used */
2012 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
2014 pkgmgrinfo_basic_free_package((package_x *)mfx);
2017 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
2019 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
2020 xmlTextReaderPtr reader;
2021 manifest_x *mfx = NULL;
2023 reader = xmlReaderForFile(manifest, NULL, 0);
2025 mfx = malloc(sizeof(manifest_x));
2027 memset(mfx, '\0', sizeof(manifest_x));
2028 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
2029 _LOGD("Parsing Failed\n");
2030 pkgmgr_parser_free_manifest_xml(mfx);
2033 _LOGD("Parsing Success\n");
2035 _LOGD("Memory allocation error\n");
2037 xmlFreeTextReader(reader);
2039 _LOGD("Unable to create xml reader\n");
2045 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
2047 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
2048 xmlTextReaderPtr reader;
2049 manifest_x *mfx = NULL;
2051 reader = xmlReaderForFile(manifest, NULL, 0);
2053 mfx = malloc(sizeof(manifest_x));
2055 memset(mfx, '\0', sizeof(manifest_x));
2056 if (__process_manifest(reader, mfx, uid) < 0) {
2057 _LOGD("Parsing Failed\n");
2058 pkgmgr_parser_free_manifest_xml(mfx);
2061 _LOGD("Parsing Success\n");
2063 _LOGD("Memory allocation error\n");
2065 xmlFreeTextReader(reader);
2067 _LOGD("Unable to create xml reader\n");
2072 /* These APIs are intended to call parser directly */
2074 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2076 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2077 _LOGD("parsing manifest for installation: %s\n", manifest);
2079 manifest_x *mfx = NULL;
2083 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2084 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2086 _LOGD("Parsing Finished\n");
2088 __add_preload_info(mfx, manifest, GLOBAL_USER);
2090 _LOGD("Added preload infomation\n");
2092 __ps_process_tag(mfx, tagv);
2094 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2095 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2097 _LOGD("DB Insert Success\n");
2099 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2100 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2102 _LOGD("Creating metadata parser failed\n");
2104 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2106 _LOGD("Creating category parser failed\n");
2108 pkgmgr_parser_free_manifest_xml(mfx);
2109 _LOGD("Free Done\n");
2114 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2116 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2117 _LOGD("parsing manifest for installation: %s\n", manifest);
2118 manifest_x *mfx = NULL;
2122 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2123 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2125 _LOGD("Parsing Finished\n");
2127 __ps_process_tag(mfx, tagv);
2129 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2130 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2132 _LOGD("DB Insert Success\n");
2134 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2135 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2137 _LOGD("Creating metadata parser failed\n");
2138 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2140 _LOGD("Creating category parser failed\n");
2142 pkgmgr_parser_free_manifest_xml(mfx);
2143 _LOGD("Free Done\n");
2149 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2151 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2152 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2153 manifest_x *mfx = NULL;
2155 bool preload = false;
2156 bool system = false;
2157 char *csc_path = NULL;
2158 pkgmgrinfo_pkginfo_h handle = NULL;
2161 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2162 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2164 _LOGD("Parsing Finished\n");
2165 __add_preload_info(mfx, manifest, GLOBAL_USER);
2166 _LOGD("Added preload infomation\n");
2167 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2169 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2170 if (ret != PMINFO_R_OK)
2171 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2172 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2173 if (ret != PMINFO_R_OK)
2174 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2177 free((void *)mfx->preload);
2178 mfx->preload = strdup("true");
2181 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2182 if (ret != PMINFO_R_OK)
2183 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2185 free((void *)mfx->system);
2186 mfx->system = strdup("true");
2189 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2190 if (ret != PMINFO_R_OK)
2191 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2193 if (csc_path != NULL) {
2195 free((void *)mfx->csc_path);
2196 mfx->csc_path = strdup(csc_path);
2199 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2200 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2202 _LOGD("DB Update Success\n");
2204 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2205 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2207 _LOGD("Upgrade metadata parser failed\n");
2209 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2211 _LOGD("Creating category parser failed\n");
2212 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2213 pkgmgr_parser_free_manifest_xml(mfx);
2214 _LOGD("Free Done\n");
2220 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2222 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2223 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2224 manifest_x *mfx = NULL;
2226 bool preload = false;
2227 bool system = false;
2228 char *csc_path = NULL;
2229 pkgmgrinfo_pkginfo_h handle = NULL;
2232 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2233 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2235 _LOGD("Parsing Finished\n");
2236 __check_preload_updated(mfx, manifest, uid);
2238 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2239 if (ret != PMINFO_R_OK)
2240 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2241 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2242 if (ret != PMINFO_R_OK)
2243 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2246 free((void *)mfx->preload);
2247 mfx->preload = strdup("true");
2250 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2251 if (ret != PMINFO_R_OK)
2252 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2255 free((void *)mfx->system);
2256 mfx->system = strdup("true");
2259 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2260 if (ret != PMINFO_R_OK)
2261 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2262 if (csc_path != NULL) {
2264 free((void *)mfx->csc_path);
2265 mfx->csc_path = strdup(csc_path);
2268 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2269 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2270 _LOGD("DB Update Success\n");
2272 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2273 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2275 _LOGD("Upgrade metadata parser failed\n");
2276 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2278 _LOGD("Creating category parser failed\n");
2279 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2280 pkgmgr_parser_free_manifest_xml(mfx);
2281 _LOGD("Free Done\n");
2287 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2289 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2290 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2292 manifest_x *mfx = NULL;
2295 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2296 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2298 _LOGD("Parsing Finished\n");
2300 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2302 __add_preload_info(mfx, manifest, GLOBAL_USER);
2303 _LOGD("Added preload infomation\n");
2305 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2307 _LOGD("Removing metadata parser failed\n");
2309 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2311 _LOGD("Creating category parser failed\n");
2313 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2315 _LOGD("DB Delete failed\n");
2317 _LOGD("DB Delete Success\n");
2319 pkgmgr_parser_free_manifest_xml(mfx);
2320 _LOGD("Free Done\n");
2327 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2329 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2330 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2332 manifest_x *mfx = NULL;
2335 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2336 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2338 _LOGD("Parsing Finished\n");
2340 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2342 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2344 _LOGD("Removing metadata parser failed\n");
2346 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2348 _LOGD("Creating category parser failed\n");
2350 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2352 _LOGD("DB Delete failed\n");
2354 _LOGD("DB Delete Success\n");
2356 ret = __ps_remove_appsvc_db(mfx, uid);
2358 _LOGD("Removing appsvc_db failed\n");
2360 _LOGD("Removing appsvc_db Success\n");
2362 pkgmgr_parser_free_manifest_xml(mfx);
2363 _LOGD("Free Done\n");
2369 API int pkgmgr_parser_parse_manifest_for_preload()
2371 return pkgmgr_parser_update_preload_info_in_db();
2374 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
2376 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
2380 API char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid)
2382 return __pkgid_to_manifest(pkgid, uid);
2385 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
2387 return __pkgid_to_manifest(pkgid, GLOBAL_USER);
2390 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2392 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
2395 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2397 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
2400 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2402 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
2405 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2407 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2409 if (manifest == NULL) {
2410 _LOGE("manifest file is NULL\n");
2411 return PMINFO_R_EINVAL;
2414 xmlSchemaParserCtxtPtr ctx;
2415 xmlSchemaValidCtxtPtr vctx;
2416 xmlSchemaPtr xschema;
2417 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2419 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2420 return PMINFO_R_ERROR;
2422 xschema = xmlSchemaParse(ctx);
2423 if (xschema == NULL) {
2424 _LOGE("xmlSchemaParse() Failed\n");
2425 return PMINFO_R_ERROR;
2427 vctx = xmlSchemaNewValidCtxt(xschema);
2429 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2430 return PMINFO_R_ERROR;
2432 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2433 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2435 _LOGE("xmlSchemaValidateFile() failed\n");
2436 return PMINFO_R_ERROR;
2437 } else if (ret == 0) {
2438 _LOGE("Manifest is Valid\n");
2441 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2442 return PMINFO_R_ERROR;
2448 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2458 _LOGE("fork failed\n");
2463 int dev_null_fd = open ("/dev/null", O_RDWR);
2464 if (dev_null_fd >= 0)
2466 dup2 (dev_null_fd, 0);/*stdin*/
2467 dup2 (dev_null_fd, 1);/*stdout*/
2468 dup2 (dev_null_fd, 2);/*stderr*/
2471 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
2472 SCHEMA_FILE, NULL) < 0) {
2473 _LOGE("execl error\n");
2483 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
2487 _LOGE("waitpid failed\n");
2493 if(WIFEXITED(status) && !WEXITSTATUS(status))