4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
31 #include <libxml/parser.h>
32 #include <libxml/xmlreader.h>
33 #include <libxml/xmlschemas.h>
38 #include "pkgmgr-info.h"
39 #include "pkgmgrinfo_basic.h"
40 #include "pkgmgrinfo_debug.h"
42 #include "pkgmgr_parser.h"
43 #include "pkgmgr_parser_internal.h"
44 #include "pkgmgr_parser_db.h"
49 #define LOG_TAG "PKGMGR_PARSER"
51 #define ASCII(s) (const char *)s
52 #define XMLCHAR(s) (const xmlChar *)s
54 //#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/metadata_parser_list.txt"
55 #define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/mdparser_list.txt"
56 #define METADATA_PARSER_NAME "metadataparser:"
58 #define CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
59 #define CATEGORY_PARSER_NAME "categoryparser:"
61 #define TAG_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/tag_parser_list.txt"
62 #define TAG_PARSER_NAME "parserlib:"
64 #define PKG_TAG_LEN_MAX 128
67 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
78 /* plugin process_type */
80 PLUGIN_PRE_PROCESS = 0,
82 } PLUGIN_PROCESS_TYPE;
95 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label);
96 static int __ps_process_privilege(xmlTextReaderPtr reader, const char **privilege);
97 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges);
98 static int __ps_process_allowed(xmlTextReaderPtr reader, const char **allowed);
99 static int __ps_process_condition(xmlTextReaderPtr reader, const char **condition);
100 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
101 static int __ps_process_category(xmlTextReaderPtr reader, const char **category);
102 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
103 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
104 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
105 static int __ps_process_request(xmlTextReaderPtr reader, const char **request);
106 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
107 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions);
108 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
109 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
110 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
111 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
112 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
113 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol);
114 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
115 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid);
116 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid);
117 static int __next_child_element(xmlTextReaderPtr reader, int depth);
118 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
119 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
120 static void __str_trim(char *input);
121 static char *__get_parser_plugin(const char *type);
122 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
123 API int __is_admin();
125 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, const char **xml_attribute, char *default_value)
127 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
129 *xml_attribute = strdup((const char *)attrib_val);
132 if (default_value != NULL) {
133 *xml_attribute = strdup(default_value);
138 static void __save_xml_lang(xmlTextReaderPtr reader, const char **xml_attribute)
140 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
141 if (attrib_val != NULL)
142 *xml_attribute = strdup(ASCII(attrib_val));
144 *xml_attribute = strdup(DEFAULT_LOCALE);
147 static void __save_xml_value(xmlTextReaderPtr reader, const char **xml_attribute)
149 xmlTextReaderRead(reader);
150 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
153 *xml_attribute = strdup((const char *)attrib_val);
156 static void __save_xml_installed_time(manifest_x *mfx)
158 char buf[PKG_STRING_LEN_MAX] = {'\0'};
162 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
163 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
164 mfx->installed_time = val;
167 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
169 char root[PKG_STRING_LEN_MAX] = { '\0' };
175 tzplatform_set_user(uid);
176 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
177 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
179 mfx->root_path = strdup(root);
181 tzplatform_reset_user();
184 static void __save_xml_default_value(manifest_x * mfx)
186 mfx->preload = strdup("False");
187 mfx->removable = strdup("True");
188 mfx->readonly = strdup("False");
189 mfx->update = strdup("False");
190 mfx->system = strdup("False");
191 mfx->installed_storage= strdup("installed_internal");
192 package = mfx->package;
195 void *__open_lib_handle(char *tag)
197 char *lib_path = NULL;
198 void *lib_handle = NULL;
200 lib_path = __get_parser_plugin(tag);
201 retvm_if(!lib_path, NULL, "lib_path get fail");
203 lib_handle = dlopen(lib_path, RTLD_LAZY);
204 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
209 void __close_lib_handle(void *lib_handle)
214 static void __str_trim(char *input)
216 char *trim_str = input;
221 while (*input != 0) {
222 if (!isspace(*input)) {
235 uid_t uid = getuid();
236 if ((uid_t) 0 == uid )
244 static char * __get_tag_by_key(char *md_key)
248 if (md_key == NULL) {
249 _LOGD("md_key is NULL\n");
253 md_tag = strrchr(md_key, 47) + 1;
256 return strdup(md_tag);
259 static char *__get_metadata_parser_plugin(const char *type)
262 char buffer[1024] = { 0 };
263 char temp_path[1024] = { 0 };
267 _LOGE("invalid argument\n");
271 fp = fopen(PKG_PARSER_CONF_PATH, "r");
273 _LOGE("no matching metadata parser\n");
277 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
278 if (buffer[0] == '#')
283 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
284 path = path + strlen(METADATA_PARSER_NAME);
289 memset(buffer, 0x00, 1024);
296 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
300 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
302 return strdup(temp_path);
305 static char *__get_category_parser_plugin(const char *type)
308 char buffer[1024] = { 0 };
309 char temp_path[1024] = { 0 };
313 _LOGE("invalid argument\n");
317 fp = fopen(PKG_PARSER_CONF_PATH, "r");
319 _LOGE("no matching metadata parser\n");
323 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
324 if (buffer[0] == '#')
329 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
330 path = path + strlen(CATEGORY_PARSER_NAME);
335 memset(buffer, 0x00, 1024);
342 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
346 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
348 return strdup(temp_path);
351 static char *__get_parser_plugin(const char *type)
354 char buffer[1024] = { 0 };
355 char temp_path[1024] = { 0 };
359 _LOGE("invalid argument\n");
363 fp = fopen(PKG_PARSER_CONF_PATH, "r");
365 _LOGE("no matching backendlib\n");
369 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
370 if (buffer[0] == '#')
375 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
376 path = path + strlen(PKG_PARSERLIB);
380 memset(buffer, 0x00, 1024);
387 _LOGE("no matching backendlib\n");
391 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
393 return strdup(temp_path);
396 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
397 ACTION_TYPE action, const char *pkgid)
399 int (*plugin_install) (xmlDocPtr, const char *);
405 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
408 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
410 case ACTION_UNINSTALL:
411 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
417 if ((plugin_install =
418 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
419 _LOGE("can not find symbol[%s] \n", ac);
423 ret = plugin_install(docPtr, pkgid);
424 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
430 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
431 ACTION_TYPE action, const char *pkgid, const char *appid)
433 char *lib_path = NULL;
434 void *lib_handle = NULL;
435 int (*metadata_parser_plugin) (const char *, const char *, GList *);
441 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
444 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
446 case ACTION_UNINSTALL:
447 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
453 lib_path = __get_metadata_parser_plugin(tag);
455 _LOGE("get %s parser fail\n", tag);
459 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
460 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
464 if ((metadata_parser_plugin =
465 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
466 _LOGE("can not find symbol[%s] \n",ac);
470 ret = metadata_parser_plugin(pkgid, appid, md_list);
472 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
474 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
484 static int __ps_run_category_parser(GList *category_list, const char *tag,
485 ACTION_TYPE action, const char *pkgid, const char *appid)
487 char *lib_path = NULL;
488 void *lib_handle = NULL;
489 int (*category_parser_plugin) (const char *, const char *, GList *);
495 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
498 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
500 case ACTION_UNINSTALL:
501 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
507 lib_path = __get_category_parser_plugin(tag);
509 _LOGE("get %s parser fail\n", tag);
513 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
514 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
518 if ((category_parser_plugin =
519 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
520 _LOGE("can not find symbol[%s] \n",ac);
524 ret = category_parser_plugin(pkgid, appid, category_list);
526 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
528 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
538 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
539 ACTION_TYPE action, const char *pkgid)
541 char *lib_path = NULL;
542 void *lib_handle = NULL;
543 int (*plugin_install) (xmlDocPtr, const char *);
549 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
552 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
554 case ACTION_UNINSTALL:
555 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
561 lib_path = __get_parser_plugin(tag);
566 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
567 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
570 if ((plugin_install =
571 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
572 _LOGE("can not find symbol[%s] \n", ac);
576 ret = plugin_install(docPtr, pkgid);
578 _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
580 _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
590 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid)
596 _LOGE("pkgid is NULL");
600 size = strlen(getUserManifestPath(uid)) + strlen(pkgid) + 10;
601 manifest = malloc(size);
602 if (manifest == NULL) {
606 memset(manifest, '\0', size);
607 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
609 if (access(manifest, F_OK)) {
610 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
616 static void __metadata_parser_clear_dir_list(GList* dir_list)
619 __metadata_t* detail = NULL;
622 list = g_list_first(dir_list);
624 detail = (__metadata_t *)list->data;
627 free((void *)detail->key);
629 free((void *)detail->value);
632 list = g_list_next(list);
634 g_list_free(dir_list);
638 static void __category_parser_clear_dir_list(GList* dir_list)
641 __category_t* detail = NULL;
644 list = g_list_first(dir_list);
646 detail = (__category_t *)list->data;
649 free((void *)detail->name);
653 list = g_list_next(list);
655 g_list_free(dir_list);
659 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
664 if (xmlTextReaderDepth(reader) != 1) {
665 _LOGE("Node depth is not 1");
669 if (xmlTextReaderNodeType(reader) != 1) {
670 _LOGE("Node type is not 1");
674 const xmlChar *value;
675 name = xmlTextReaderConstName(reader);
677 _LOGE("TEST TEST TES\n");
678 name = BAD_CAST "--";
681 value = xmlTextReaderConstValue(reader);
683 if (xmlStrlen(value) > 40) {
684 _LOGD(" %.40s...", value);
690 name = xmlTextReaderConstName(reader);
692 _LOGE("TEST TEST TES\n");
693 name = BAD_CAST "--";
696 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
697 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
698 if (copyDocPtr == NULL)
700 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
701 if (rootElement == NULL)
703 xmlNode *cur_node = xmlFirstElementChild(rootElement);
704 if (cur_node == NULL)
706 xmlNode *temp = xmlTextReaderExpand(reader);
709 xmlNode *next_node = NULL;
710 while(cur_node != NULL) {
711 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
712 (temp->line == cur_node->line) ) {
716 next_node = xmlNextElementSibling(cur_node);
717 xmlUnlinkNode(cur_node);
718 xmlFreeNode(cur_node);
719 cur_node = next_node;
722 if (cur_node == NULL)
724 next_node = xmlNextElementSibling(cur_node);
726 cur_node->next = NULL;
727 next_node->prev = NULL;
728 xmlFreeNodeList(next_node);
729 xmlSetTreeDoc(cur_node, copyDocPtr);
731 xmlSetTreeDoc(cur_node, copyDocPtr);
734 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
740 static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
744 char buffer[1024] = { 0, };
747 GList *md_tmp = NULL;
751 GList *md_list = NULL;
752 __metadata_t *md_detail = NULL;
754 md_tag = __get_tag_by_key(md_key);
755 if (md_tag == NULL) {
756 _LOGD("md_tag is NULL\n");
760 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
761 app = (application_x *)app_tmp->data;
764 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
765 md = (metadata_x *)md_tmp->data;
768 //get glist of metadata key and value combination
769 memset(buffer, 0x00, 1024);
770 snprintf(buffer, 1024, "%s/", md_key);
771 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
772 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
773 if (md_detail == NULL) {
774 _LOGD("Memory allocation failed\n");
778 md_detail->key = strdup(md->key);
779 if (md_detail->key == NULL) {
780 _LOGD("Memory allocation failed\n");
785 md_detail->value = strdup(md->value);
786 if (md_detail->value == NULL) {
787 _LOGD("Memory allocation failed\n");
788 free((void *)md_detail->key);
793 md_list = g_list_append(md_list, (gpointer)md_detail);
798 //send glist to parser when tags for metadata plugin parser exist.
800 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
802 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
805 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
808 __metadata_parser_clear_dir_list(md_list);
815 __metadata_parser_clear_dir_list(md_list);
823 static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
827 char buffer[1024] = { 0, };
831 const char *category;
832 char *category_tag = NULL;
834 GList *category_list = NULL;
835 __category_t *category_detail = NULL;
837 category_tag = __get_tag_by_key(category_key);
838 if (category_tag == NULL) {
839 _LOGD("md_tag is NULL\n");
843 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
844 app = (application_x *)app_tmp->data;
847 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
848 category = (const char *)category_tmp->data;
849 //get glist of category key and value combination
850 memset(buffer, 0x00, 1024);
851 snprintf(buffer, 1024, "%s/", category_key);
852 if ((category) && (strncmp(category, 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);
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);
871 //send glist to parser when tags for metadata plugin parser exist.
873 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
875 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
877 _LOGD("category_parser success for tag[%s]\n", category_tag);
879 __category_parser_clear_dir_list(category_list);
880 category_list = NULL;
886 __category_parser_clear_dir_list(category_list);
894 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
896 switch (xmlTextReaderNodeType(reader)) {
897 case XML_READER_TYPE_END_ELEMENT:
901 case XML_READER_TYPE_ELEMENT:
903 // Elements without closing tag don't receive
904 const xmlChar *elementName =
905 xmlTextReaderLocalName(reader);
906 if (elementName == NULL) {
910 if (strcmp(tag, ASCII(elementName)) == 0) {
911 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
912 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
923 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
925 int (*plugin_install) (const char *);
929 if (process == PLUGIN_PRE_PROCESS) {
932 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
935 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
937 case ACTION_UNINSTALL:
938 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
943 } else if (process == PLUGIN_POST_PROCESS) {
946 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
949 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
951 case ACTION_UNINSTALL:
952 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
960 if ((plugin_install =
961 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
965 ret = plugin_install(pkgid);
969 static int __next_child_element(xmlTextReaderPtr reader, int depth)
971 int ret = xmlTextReaderRead(reader);
972 int cur = xmlTextReaderDepth(reader);
975 switch (xmlTextReaderNodeType(reader)) {
976 case XML_READER_TYPE_ELEMENT:
977 if (cur == depth + 1)
980 case XML_READER_TYPE_TEXT:
981 /*text is handled by each function separately*/
982 if (cur == depth + 1)
985 case XML_READER_TYPE_END_ELEMENT:
994 ret = xmlTextReaderRead(reader);
995 cur = xmlTextReaderDepth(reader);
999 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1001 xmlTextReaderPtr reader;
1005 void *lib_handle = NULL;
1006 char tag[PKG_STRING_LEN_MAX] = { 0 };
1008 fp = fopen(TAG_PARSER_LIST, "r");
1009 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1011 while (fgets(tag, sizeof(tag), fp) != NULL) {
1014 lib_handle = __open_lib_handle(tag);
1015 if (lib_handle == NULL)
1018 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1019 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1021 docPtr = xmlReadFile(filename, NULL, 0);
1022 reader = xmlReaderWalker(docPtr);
1023 if (reader != NULL) {
1024 ret = xmlTextReaderRead(reader);
1026 __process_tag(lib_handle, reader, action, tag, mfx->package);
1027 ret = xmlTextReaderRead(reader);
1029 xmlFreeTextReader(reader);
1032 _LOGD("%s : failed to parse", filename);
1035 _LOGD("Unable to open %s", filename);
1038 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1039 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1041 __close_lib_handle(lib_handle);
1043 memset(tag, 0x00, sizeof(tag));
1052 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1054 fprintf(stdout,"__ps_process_metadata_parser\n");
1057 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1059 fp = fopen(METADATA_PARSER_LIST, "r");
1061 _LOGD("no preload list\n");
1065 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1067 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1078 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1082 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1084 fp = fopen(CATEGORY_PARSER_LIST, "r");
1086 _LOGD("no category parser list\n");
1090 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1091 __str_trim(category_key);
1092 ret = __run_category_parser_prestep(mfx, category_key, action);
1103 static int __ps_process_allowed(xmlTextReaderPtr reader, const char **allowed)
1105 __save_xml_value(reader, allowed);
1109 static int __ps_process_condition(xmlTextReaderPtr reader, const char **condition)
1111 __save_xml_attribute(reader, "name", condition, NULL);
1115 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
1117 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
1118 __save_xml_value(reader, ¬ification->text);
1122 static int __ps_process_category(xmlTextReaderPtr reader, const char **category)
1124 __save_xml_attribute(reader, "name", category, NULL);
1128 static int __ps_process_privilege(xmlTextReaderPtr reader, const char **privilege)
1130 __save_xml_value(reader, privilege);
1134 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
1136 __save_xml_attribute(reader, "key", &metadata->key, NULL);
1137 __save_xml_attribute(reader, "value", &metadata->value, NULL);
1141 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
1143 __save_xml_attribute(reader, "type", &permission->type, NULL);
1144 __save_xml_value(reader, &permission->value);
1148 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
1150 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
1151 __save_xml_value(reader, &compatibility->text);
1155 static int __ps_process_request(xmlTextReaderPtr reader, const char **request)
1157 __save_xml_value(reader, request);
1161 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
1163 const xmlChar *node;
1168 __save_xml_attribute(reader, "path", &define->path, NULL);
1170 depth = xmlTextReaderDepth(reader);
1171 while ((ret = __next_child_element(reader, depth))) {
1172 node = xmlTextReaderConstName(reader);
1174 _LOGD("xmlTextReaderConstName value is NULL\n");
1178 if (!strcmp(ASCII(node), "allowed")) {
1180 ret = __ps_process_allowed(reader, &val);
1182 define->allowed = g_list_append(define->allowed, (gpointer)val);
1183 } else if (!strcmp(ASCII(node), "request")) {
1185 ret = __ps_process_request(reader, &val);
1187 define->request = g_list_append(define->request, (gpointer)val);
1192 _LOGD("Processing define failed\n");
1199 struct appcontrol_data {
1204 char operation[BUFSIZE];
1209 static void __ps_process_mime(gpointer data, gpointer user_data)
1211 char *mime = (char *)data;
1212 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1213 appcontrol_x *appcontrol;
1215 snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
1217 appcontrol = calloc(1, sizeof(appcontrol_x));
1218 if (strlen(ad->operation))
1219 appcontrol->operation = strdup(ad->operation);
1220 if (strlen(ad->uri))
1221 appcontrol->uri = strdup(ad->uri);
1222 appcontrol->mime = strdup(ad->mime);
1223 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1226 static void __ps_process_uri(gpointer data, gpointer user_data)
1228 char *uri = (char *)data;
1229 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1230 appcontrol_x *appcontrol;
1232 snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
1234 if (ad->mimes != NULL) {
1235 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1237 appcontrol = calloc(1, sizeof(appcontrol_x));
1238 if (strlen(ad->operation))
1239 appcontrol->operation = strdup(ad->operation);
1240 appcontrol->uri = strdup(ad->uri);
1241 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1245 static void __ps_process_operation(gpointer data, gpointer user_data)
1247 char *operation = (char *)data;
1248 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1249 appcontrol_x *appcontrol;
1251 snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
1253 if (ad->uris != NULL) {
1254 g_list_foreach(ad->uris, __ps_process_uri, user_data);
1255 } else if (ad->mimes != NULL) {
1256 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1258 appcontrol = calloc(1, sizeof(appcontrol_x));
1259 appcontrol->operation = strdup(ad->operation);
1260 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1264 static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
1266 struct appcontrol_data ad = {0, };
1268 ad.operations = operations;
1272 if (ad.operations == NULL)
1275 g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
1277 return ad.appcontrols;
1280 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
1282 const xmlChar *node;
1286 GList *operations = NULL;
1288 GList *mimes = NULL;
1291 depth = xmlTextReaderDepth(reader);
1292 while ((ret = __next_child_element(reader, depth)) > 0) {
1293 node = xmlTextReaderConstName(reader);
1295 _LOGD("xmlTextReaderConstName value is NULL\n");
1300 if (!strcmp(ASCII(node), "operation")) {
1301 __save_xml_attribute(reader, "name", &val, NULL);
1303 operations = g_list_append(operations, (gpointer)val);
1304 _LOGD("operation processing\n");
1305 } else if (!strcmp(ASCII(node), "uri")) {
1306 __save_xml_attribute(reader, "name", &val, NULL);
1308 uris = g_list_append(uris, (gpointer)val);
1309 _LOGD("uri processing\n");
1310 } else if (!strcmp(ASCII(node), "mime")) {
1311 __save_xml_attribute(reader, "name", &val, NULL);
1313 mimes = g_list_append(mimes, (gpointer)val);
1314 _LOGD("mime processing\n");
1315 } else if (!strcmp(ASCII(node), "subapp")) {
1323 _LOGD("Processing appcontrol failed\n");
1324 g_list_free_full(operations, free);
1325 g_list_free_full(uris, free);
1326 g_list_free_full(mimes, free);
1330 result = __make_appcontrol_list(operations, uris, mimes);
1332 *appcontrol = g_list_concat(*appcontrol, result);
1336 g_list_free_full(operations, free);
1337 g_list_free_full(uris, free);
1338 g_list_free_full(mimes, free);
1343 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
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), "privilege") == 0) {
1360 ret = __ps_process_privilege(reader, &val);
1362 *privileges = g_list_append(*privileges, (gpointer)val);
1366 _LOGD("Processing privileges failed\n");
1373 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
1375 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), "condition") == 0) {
1390 ret = __ps_process_condition(reader, &val);
1392 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
1396 _LOGD("Processing launchconditions failed\n");
1404 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
1406 const xmlChar *node;
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), "define")) {
1419 define_x *define = calloc(1, sizeof(define_x));
1420 if (define == NULL) {
1421 _LOGD("Malloc Failed\n");
1424 datashare->define = g_list_append(datashare->define, define);
1425 ret = __ps_process_define(reader, define);
1426 } else if (!strcmp(ASCII(node), "request")) {
1428 ret = __ps_process_request(reader, &val);
1430 datashare->request = g_list_append(datashare->request, (gpointer)val);
1434 _LOGD("Processing data-share failed\n");
1441 static char *__get_icon_with_path(const char *icon, uid_t uid)
1443 char icon_with_path[BUFSIZE];
1444 const char *app_path;
1446 if (!icon || !package)
1449 /* just use absolute path */
1450 if (index(icon, '/'))
1451 return strdup(icon);
1454 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1455 getIconPath(uid), icon);
1456 if (access(icon_with_path, F_OK) == 0)
1459 /* for backward compatibility (.../default/small/...)
1460 * this should be removed
1462 snprintf(icon_with_path, sizeof(icon_with_path),
1463 "%sdefault/small/%s",
1464 getIconPath(uid), icon);
1465 if (access(icon_with_path, F_OK) == 0)
1468 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
1469 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
1471 tzplatform_set_user(uid);
1472 app_path = tzplatform_getenv(TZ_USER_APP);
1473 tzplatform_reset_user();
1476 /* If doesn't exist in case of Global app,
1477 * try to get icon directly into app's directory
1479 snprintf(icon_with_path, sizeof(icon_with_path),
1480 "%s/%s/%s", app_path, package, icon);
1481 if (access(icon_with_path, F_OK) == 0)
1484 /* some preload package has icons at below path */
1485 snprintf(icon_with_path, sizeof(icon_with_path),
1486 "%s/%s/res/icons/%s", app_path, package, icon);
1487 if (access(icon_with_path, F_OK) == 0)
1490 /* since 2.3 tpk package */
1491 snprintf(icon_with_path, sizeof(icon_with_path),
1492 "%s/%s/shared/res/%s", app_path, package, icon);
1493 if (access(icon_with_path, F_OK) == 0)
1496 _LOGE("cannot find icon path for [%s]", icon);
1500 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1502 return strdup(icon_with_path);
1505 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1508 char delims[] = "=";
1509 char *ret_result = NULL;
1515 for (tag = strdup(tagv[0]); tag != NULL; ) {
1516 ret_result = strtok(tag, delims);
1518 /*check tag : preload */
1519 if (strcmp(ret_result, "preload") == 0) {
1520 ret_result = strtok(NULL, delims);
1521 if (strcmp(ret_result, "true") == 0) {
1522 free((void *)mfx->preload);
1523 mfx->preload = strdup("true");
1524 } else if (strcmp(ret_result, "false") == 0) {
1525 free((void *)mfx->preload);
1526 mfx->preload = strdup("false");
1528 /*check tag : removable*/
1529 } else if (strcmp(ret_result, "removable") == 0) {
1530 ret_result = strtok(NULL, delims);
1531 if (strcmp(ret_result, "true") == 0){
1532 free((void *)mfx->removable);
1533 mfx->removable = strdup("true");
1534 } else if (strcmp(ret_result, "false") == 0) {
1535 free((void *)mfx->removable);
1536 mfx->removable = strdup("false");
1538 /*check tag : not matched*/
1540 _LOGD("tag process [%s]is not defined\n", ret_result);
1544 /*check next value*/
1545 if (tagv[++i] != NULL)
1546 tag = strdup(tagv[i]);
1548 _LOGD("tag process success...\n");
1554 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1556 __save_xml_attribute(reader, "name", &icon->name, NULL);
1557 __save_xml_attribute(reader, "section", &icon->section, NULL);
1558 __save_xml_attribute(reader, "size", &icon->size, NULL);
1559 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1560 __save_xml_lang(reader, &icon->lang);
1562 xmlTextReaderRead(reader);
1563 const char *text = ASCII(xmlTextReaderValue(reader));
1565 icon->text = (const char *)__get_icon_with_path(text, uid);
1572 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1574 __save_xml_attribute(reader, "name", &image->name, NULL);
1575 __save_xml_attribute(reader, "section", &image->section, NULL);
1576 __save_xml_lang(reader, &image->lang);
1577 __save_xml_value(reader, &image->text);
1581 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1583 __save_xml_attribute(reader, "name", &label->name, NULL);
1584 __save_xml_lang(reader, &label->lang);
1585 __save_xml_value(reader, &label->text);
1590 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1592 __save_xml_attribute(reader, "email", &author->email, NULL);
1593 __save_xml_attribute(reader, "href", &author->href, NULL);
1594 __save_xml_value(reader, &author->text);
1598 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1600 __save_xml_lang(reader, &description->lang);
1601 __save_xml_value(reader, &description->text);
1605 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1607 __save_xml_lang(reader, &license->lang);
1608 __save_xml_value(reader, &license->text);
1612 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1614 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1615 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1616 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1620 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
1622 const xmlChar *node;
1627 __save_xml_attribute(reader, "appid", &application->appid, NULL);
1628 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1629 __save_xml_attribute(reader, "exec", &application->exec, NULL);
1630 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
1631 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
1632 __save_xml_attribute(reader, "type", &application->type, NULL);
1633 __save_xml_attribute(reader, "categories", &application->categories, NULL);
1634 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
1635 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
1636 __save_xml_attribute(reader, "enabled", &application->enabled, "true");
1637 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
1638 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
1639 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
1640 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
1641 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
1642 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
1643 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
1644 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
1645 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
1646 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
1647 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : "svcapp");
1648 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1649 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);
1650 __save_xml_attribute(reader, "submode", &application->submode, "false");
1651 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
1652 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
1653 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
1654 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
1655 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
1656 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
1658 application->package= strdup(package);
1660 depth = xmlTextReaderDepth(reader);
1661 while ((ret = __next_child_element(reader, depth))) {
1662 node = xmlTextReaderConstName(reader);
1664 _LOGD("xmlTextReaderConstName value is NULL\n");
1667 if (!strcmp(ASCII(node), "label")) {
1668 label_x *label = calloc(1, sizeof(label_x));
1669 if (label == NULL) {
1670 _LOGD("Malloc Failed\n");
1673 application->label = g_list_append(application->label, label);
1674 ret = __ps_process_label(reader, label);
1675 } else if (!strcmp(ASCII(node), "icon")) {
1676 icon_x *icon = calloc(1, sizeof(icon_x));
1678 _LOGD("Malloc Failed\n");
1681 application->icon = g_list_append(application->icon, icon);
1682 ret = __ps_process_icon(reader, icon, uid);
1683 } else if (!strcmp(ASCII(node), "image")) {
1684 image_x *image = calloc(1, sizeof(image_x));
1685 if (image == NULL) {
1686 _LOGD("Malloc Failed\n");
1689 application->image = g_list_append(application->image, image);
1690 ret = __ps_process_image(reader, image);
1691 } else if (!strcmp(ASCII(node), "category")) {
1693 ret = __ps_process_category(reader, &val);
1695 application->category = g_list_append(application->category, (gpointer)val);
1696 } else if (!strcmp(ASCII(node), "metadata")) {
1697 metadata_x *metadata = calloc(1, sizeof(metadata_x));
1698 if (metadata == NULL) {
1699 _LOGD("Malloc Failed\n");
1702 application->metadata = g_list_append(application->metadata, metadata);
1703 ret = __ps_process_metadata(reader, metadata);
1704 } else if (!strcmp(ASCII(node), "permission")) {
1705 permission_x *permission = calloc(1, sizeof(permission_x));
1706 if (permission == NULL) {
1707 _LOGD("Malloc Failed\n");
1710 application->permission = g_list_append(application->permission, permission);
1711 ret = __ps_process_permission(reader, permission);
1712 } else if (!strcmp(ASCII(node), "app-control")) {
1713 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1714 } else if (!strcmp(ASCII(node), "application-service")) {
1715 ret = __ps_process_appcontrol(reader, &application->appcontrol);
1716 } else if (!strcmp(ASCII(node), "data-share")) {
1717 datashare_x *datashare = calloc(1, sizeof(datashare_x));
1718 if (datashare == NULL) {
1719 _LOGD("Malloc Failed\n");
1722 application->datashare = g_list_append(application->datashare, datashare);
1723 ret = __ps_process_datashare(reader, datashare);
1724 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1725 ret = __ps_process_launchconditions(reader, &application->launchconditions);
1726 } else if (!strcmp(ASCII(node), "notification")) {
1727 notification_x *notification = calloc(1, sizeof(notification_x));
1728 if (notification == NULL) {
1729 _LOGD("Malloc Failed\n");
1732 application->notification = g_list_append(application->notification, notification);
1733 ret = __ps_process_notification(reader, notification);
1734 } else if (!strcmp(ASCII(node), "datacontrol")) {
1735 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
1736 if (datacontrol == NULL) {
1737 _LOGD("Malloc Failed\n");
1740 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
1741 ret = __ps_process_datacontrol(reader, datacontrol);
1745 _LOGD("Processing application failed\n");
1753 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1755 _LOGD("__start_process\n");
1756 const xmlChar *node;
1760 depth = xmlTextReaderDepth(reader);
1761 while ((ret = __next_child_element(reader, depth))) {
1762 node = xmlTextReaderConstName(reader);
1764 _LOGD("xmlTextReaderConstName value is NULL\n");
1768 if (!strcmp(ASCII(node), "label")) {
1769 label_x *label = calloc(1, sizeof(label_x));
1770 if (label == NULL) {
1771 _LOGD("Malloc Failed\n");
1774 mfx->label = g_list_append(mfx->label, label);
1775 ret = __ps_process_label(reader, label);
1776 } else if (!strcmp(ASCII(node), "author")) {
1777 author_x *author = calloc(1, sizeof(author_x));
1778 if (author == NULL) {
1779 _LOGD("Malloc Failed\n");
1782 mfx->author = g_list_append(mfx->author, author);
1783 ret = __ps_process_author(reader, author);
1784 } else if (!strcmp(ASCII(node), "description")) {
1785 description_x *description = calloc(1, sizeof(description_x));
1786 if (description == NULL) {
1787 _LOGD("Malloc Failed\n");
1790 mfx->description = g_list_append(mfx->description, description);
1791 ret = __ps_process_description(reader, description);
1792 } else if (!strcmp(ASCII(node), "license")) {
1793 license_x *license = calloc(1, sizeof(license_x));
1794 if (license == NULL) {
1795 _LOGD("Malloc Failed\n");
1798 mfx->license = g_list_append(mfx->license, license);
1799 ret = __ps_process_license(reader, license);
1800 } else if (!strcmp(ASCII(node), "privileges")) {
1801 ret = __ps_process_privileges(reader, &mfx->privileges);
1802 } else if (!strcmp(ASCII(node), "ui-application")) {
1803 application_x *application = calloc(1, sizeof(application_x));
1804 if (application == NULL) {
1805 _LOGD("Malloc Failed\n");
1808 mfx->application = g_list_append(mfx->application, application);
1809 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1810 } else if (!strcmp(ASCII(node), "service-application")) {
1811 application_x *application = calloc(1, sizeof(application_x));
1812 if (application == NULL) {
1813 _LOGD("Malloc Failed\n");
1816 mfx->application = g_list_append(mfx->application, application);
1817 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
1818 } else if (!strcmp(ASCII(node), "widget-application")) {
1819 application_x *application = calloc(1, sizeof(application_x));
1820 if (application == NULL) {
1821 _LOGD("Malloc Failed\n");
1824 mfx->application = g_list_append(mfx->application, application);
1825 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1826 } else if (!strcmp(ASCII(node), "icon")) {
1827 icon_x *icon = calloc(1, sizeof(icon_x));
1829 _LOGD("Malloc Failed\n");
1832 mfx->icon = g_list_append(mfx->icon, icon);
1833 ret = __ps_process_icon(reader, icon, uid);
1834 } else if (!strcmp(ASCII(node), "compatibility")) {
1835 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
1836 if (compatibility == NULL) {
1837 _LOGD("Malloc Failed\n");
1840 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
1841 ret = __ps_process_compatibility(reader, compatibility);
1842 } else if (!strcmp(ASCII(node), "shortcut-list")) {
1844 } else if (!strcmp(ASCII(node), "livebox")) {
1846 } else if (!strcmp(ASCII(node), "account")) {
1848 } else if (!strcmp(ASCII(node), "notifications")) {
1850 } else if (!strcmp(ASCII(node), "ime")) {
1852 } else if (!strcmp(ASCII(node), "feature")) {
1855 _LOGI("Unknown element: %s", ASCII(node));
1860 _LOGD("Processing manifest failed\n");
1867 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1869 const xmlChar *node;
1872 if ((ret = __next_child_element(reader, -1))) {
1873 node = xmlTextReaderConstName(reader);
1875 _LOGD("xmlTextReaderConstName value is NULL\n");
1879 if (!strcmp(ASCII(node), "manifest")) {
1880 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1881 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1882 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1883 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1884 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1885 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1886 __save_xml_attribute(reader, "type", &mfx->type, "rpm");
1887 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1888 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1889 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1890 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1891 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1892 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1893 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1894 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1896 __save_xml_installed_time(mfx);
1897 __save_xml_root_path(mfx, uid);
1898 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1899 __save_xml_default_value(mfx);
1901 ret = __start_process(reader, mfx, uid);
1903 _LOGD("No Manifest element found\n");
1910 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
1912 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
1914 void *lib_handle = NULL;
1915 int (*appsvc_operation) (const char *, uid_t);
1918 application_x *application;
1920 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1921 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
1925 if ((appsvc_operation =
1926 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1927 _LOGE("can not find symbol \n");
1931 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1932 application = (application_x *)tmp->data;
1933 if (application == NULL)
1935 ret = appsvc_operation(application->appid, uid);
1937 _LOGE("can not operation symbol \n");
1942 dlclose(lib_handle);
1947 #define PRELOAD_PACKAGE_LIST SYSCONFDIR "/package-manager/preload/preload_list.txt"
1948 static int __add_preload_info(manifest_x * mfx, const char *manifest, uid_t uid)
1951 char buffer[1024] = { 0 };
1954 if(strstr(manifest, getUserManifestPath(uid))) {
1955 free((void *)mfx->readonly);
1956 mfx->readonly = strdup("True");
1958 free((void *)mfx->preload);
1959 mfx->preload = strdup("True");
1961 free((void *)mfx->removable);
1962 mfx->removable = strdup("False");
1964 free((void *)mfx->system);
1965 mfx->system = strdup("True");
1970 fp = fopen(PRELOAD_PACKAGE_LIST, "r");
1972 _LOGE("no preload list\n");
1976 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1977 if (buffer[0] == '#') {
1978 if(strcasestr(buffer, "RW_NORM"))
1980 else if(strcasestr(buffer, "RW_RM"))
1988 if(!strcmp(mfx->package, buffer)) {
1989 free((void *)mfx->preload);
1990 mfx->preload = strdup("True");
1992 free((void *)mfx->readonly);
1993 mfx->readonly = strdup("False");
1994 free((void *)mfx->removable);
1995 mfx->removable = strdup("False");
1996 } else if(state == 3){
1997 free((void *)mfx->readonly);
1998 mfx->readonly = strdup("False");
1999 free((void *)mfx->removable);
2000 mfx->removable = strdup("True");
2004 memset(buffer, 0x00, sizeof(buffer));
2013 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
2015 if (!strstr(manifest, getUserManifestPath(uid))) {
2016 /* if downloaded app is updated, then update tag set true*/
2018 free((void *)mfx->update);
2019 mfx->update = strdup("true");
2026 API int pkgmgr_parser_preload_package_type(const char *package)
2029 char buffer[1024] = { 0 };
2031 int ret = PM_PRELOAD_NONE;
2033 fp = fopen(PRELOAD_PACKAGE_LIST, "r");
2035 _LOGE("no preload list\n");
2039 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
2040 if (buffer[0] == '#') {
2041 if(strcasestr(buffer, "RW_NORM"))
2043 else if(strcasestr(buffer, "RW_RM"))
2051 if(!strcmp(package, buffer)) {
2053 ret = PM_PRELOAD_RW_NORM;
2055 } else if(state == 3){
2056 ret = PM_PRELOAD_RW_RM;
2061 memset(buffer, 0x00, sizeof(buffer));
2070 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
2072 /* desktop file is no longer used */
2076 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
2078 /* desktop file is no longer used */
2083 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
2085 pkgmgrinfo_basic_free_package((package_x *)mfx);
2088 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
2090 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
2091 xmlTextReaderPtr reader;
2092 manifest_x *mfx = NULL;
2094 reader = xmlReaderForFile(manifest, NULL, 0);
2096 mfx = malloc(sizeof(manifest_x));
2098 memset(mfx, '\0', sizeof(manifest_x));
2099 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
2100 _LOGD("Parsing Failed\n");
2101 pkgmgr_parser_free_manifest_xml(mfx);
2104 _LOGD("Parsing Success\n");
2106 _LOGD("Memory allocation error\n");
2108 xmlFreeTextReader(reader);
2110 _LOGD("Unable to create xml reader\n");
2116 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
2118 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
2119 xmlTextReaderPtr reader;
2120 manifest_x *mfx = NULL;
2122 reader = xmlReaderForFile(manifest, NULL, 0);
2124 mfx = malloc(sizeof(manifest_x));
2126 memset(mfx, '\0', sizeof(manifest_x));
2127 if (__process_manifest(reader, mfx, uid) < 0) {
2128 _LOGD("Parsing Failed\n");
2129 pkgmgr_parser_free_manifest_xml(mfx);
2132 _LOGD("Parsing Success\n");
2134 _LOGD("Memory allocation error\n");
2136 xmlFreeTextReader(reader);
2138 _LOGD("Unable to create xml reader\n");
2143 API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid)
2145 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid);
2148 API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path)
2150 return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path);
2153 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2155 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2156 _LOGD("parsing manifest for installation: %s\n", manifest);
2158 manifest_x *mfx = NULL;
2162 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2163 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2165 _LOGD("Parsing Finished\n");
2167 __ps_process_tag(mfx, tagv);
2169 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2170 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2172 _LOGD("DB Insert Success\n");
2174 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2175 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2177 _LOGD("Creating metadata parser failed\n");
2179 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2181 _LOGD("Creating category parser failed\n");
2183 pkgmgr_parser_free_manifest_xml(mfx);
2184 _LOGD("Free Done\n");
2189 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2191 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2192 _LOGD("parsing manifest for installation: %s\n", manifest);
2193 manifest_x *mfx = NULL;
2197 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2198 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2200 _LOGD("Parsing Finished\n");
2202 __ps_process_tag(mfx, tagv);
2204 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2205 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2207 _LOGD("DB Insert Success\n");
2209 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2210 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2212 _LOGD("Creating metadata parser failed\n");
2213 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2215 _LOGD("Creating category parser failed\n");
2217 pkgmgr_parser_free_manifest_xml(mfx);
2218 _LOGD("Free Done\n");
2224 API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest) {
2225 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2226 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2227 _LOGD("processing manifest_x for installation: %s\n", manifest);
2232 _LOGD("Added preload infomation\n");
2234 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2235 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2236 _LOGD("DB Insert Success\n");
2238 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2239 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2241 _LOGD("Creating metadata parser failed\n");
2243 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2245 _LOGD("Creating category parser failed\n");
2251 API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid) {
2252 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2253 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2254 _LOGD("processing manifest_x for installation: %s\n", manifest);
2258 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2259 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2260 _LOGD("DB Insert Success\n");
2262 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2263 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2265 _LOGD("Creating metadata parser failed\n");
2266 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2268 _LOGD("Creating category parser failed\n");
2273 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2275 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2276 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2277 manifest_x *mfx = NULL;
2279 bool preload = false;
2280 bool system = false;
2281 char *csc_path = NULL;
2282 pkgmgrinfo_pkginfo_h handle = NULL;
2285 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2286 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2288 _LOGD("Parsing Finished\n");
2289 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2291 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2292 if (ret != PMINFO_R_OK)
2293 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2294 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2295 if (ret != PMINFO_R_OK)
2296 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2299 free((void *)mfx->preload);
2300 mfx->preload = strdup("true");
2303 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2304 if (ret != PMINFO_R_OK)
2305 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2307 free((void *)mfx->system);
2308 mfx->system = strdup("true");
2311 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2312 if (ret != PMINFO_R_OK)
2313 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2315 if (csc_path != NULL) {
2317 free((void *)mfx->csc_path);
2318 mfx->csc_path = strdup(csc_path);
2321 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2322 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2324 _LOGD("DB Update Success\n");
2326 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2327 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2329 _LOGD("Upgrade metadata parser failed\n");
2331 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2333 _LOGD("Creating category parser failed\n");
2334 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2335 pkgmgr_parser_free_manifest_xml(mfx);
2336 _LOGD("Free Done\n");
2342 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2344 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2345 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2346 manifest_x *mfx = NULL;
2348 bool preload = false;
2349 bool system = false;
2350 char *csc_path = NULL;
2351 pkgmgrinfo_pkginfo_h handle = NULL;
2354 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2355 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2357 _LOGD("Parsing Finished\n");
2358 __check_preload_updated(mfx, manifest, uid);
2360 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2361 if (ret != PMINFO_R_OK)
2362 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2363 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2364 if (ret != PMINFO_R_OK)
2365 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2368 free((void *)mfx->preload);
2369 mfx->preload = strdup("true");
2372 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2373 if (ret != PMINFO_R_OK)
2374 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2377 free((void *)mfx->system);
2378 mfx->system = strdup("true");
2381 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2382 if (ret != PMINFO_R_OK)
2383 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2384 if (csc_path != NULL) {
2386 free((void *)mfx->csc_path);
2387 mfx->csc_path = strdup(csc_path);
2390 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2391 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2392 _LOGD("DB Update Success\n");
2394 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2395 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2397 _LOGD("Upgrade metadata parser failed\n");
2398 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2400 _LOGD("Creating category parser failed\n");
2401 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2402 pkgmgr_parser_free_manifest_xml(mfx);
2403 _LOGD("Free Done\n");
2409 API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest) {
2410 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2411 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2412 _LOGD("pkgmgr_parser_process_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2414 bool preload = false;
2415 bool system = false;
2416 char *csc_path = NULL;
2417 pkgmgrinfo_pkginfo_h handle = NULL;
2421 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2422 if (ret != PMINFO_R_OK)
2423 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2425 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2426 if (ret != PMINFO_R_OK)
2427 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2429 free((void *)mfx->system);
2430 mfx->system = strdup("true");
2433 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2434 if (ret != PMINFO_R_OK)
2435 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2437 if (csc_path != NULL) {
2439 free((void *)mfx->csc_path);
2440 mfx->csc_path = strdup(csc_path);
2443 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2444 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2445 _LOGD("DB Update Success\n");
2447 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2448 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2450 _LOGD("Upgrade metadata parser failed\n");
2452 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2454 _LOGD("Creating category parser failed\n");
2455 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2461 API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid) {
2462 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2463 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2464 _LOGD(" pkgmgr_parser_process_usr_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2466 pkgmgrinfo_pkginfo_h handle = NULL;
2470 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2471 if (ret != PMINFO_R_OK)
2472 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2474 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2475 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2476 _LOGD("DB Update Success\n");
2478 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2479 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2481 _LOGD("Upgrade metadata parser failed\n");
2482 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2484 _LOGD("Creating category parser failed\n");
2485 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2491 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2493 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2494 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2496 manifest_x *mfx = NULL;
2499 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2500 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2502 _LOGD("Parsing Finished\n");
2504 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2506 __add_preload_info(mfx, manifest, GLOBAL_USER);
2507 _LOGD("Added preload infomation\n");
2509 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2511 _LOGD("Removing metadata parser failed\n");
2513 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2515 _LOGD("Creating category parser failed\n");
2517 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2519 _LOGD("DB Delete failed\n");
2521 _LOGD("DB Delete Success\n");
2523 pkgmgr_parser_free_manifest_xml(mfx);
2524 _LOGD("Free Done\n");
2531 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2533 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2534 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2536 manifest_x *mfx = NULL;
2539 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2540 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2542 _LOGD("Parsing Finished\n");
2544 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2546 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2548 _LOGD("Removing metadata parser failed\n");
2550 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2552 _LOGD("Creating category parser failed\n");
2554 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2556 _LOGD("DB Delete failed\n");
2558 _LOGD("DB Delete Success\n");
2560 ret = __ps_remove_appsvc_db(mfx, uid);
2562 _LOGD("Removing appsvc_db failed\n");
2564 _LOGD("Removing appsvc_db Success\n");
2566 pkgmgr_parser_free_manifest_xml(mfx);
2567 _LOGD("Free Done\n");
2573 API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest) {
2574 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2575 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2576 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2580 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2582 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2584 _LOGD("Removing metadata parser failed\n");
2586 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2588 _LOGD("Creating category parser failed\n");
2590 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2592 _LOGD("DB Delete failed\n");
2594 _LOGD("DB Delete Success\n");
2600 API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid) {
2601 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2602 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2603 _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2608 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2610 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2612 _LOGD("Removing metadata parser failed\n");
2614 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2616 _LOGD("Creating category parser failed\n");
2618 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2620 _LOGD("DB Delete failed\n");
2622 _LOGD("DB Delete Success\n");
2624 ret = __ps_remove_appsvc_db(mfx, uid);
2626 _LOGD("Removing appsvc_db failed\n");
2628 _LOGD("Removing appsvc_db Success\n");
2634 API int pkgmgr_parser_parse_manifest_for_preload()
2636 return pkgmgr_parser_update_preload_info_in_db();
2639 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
2641 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
2645 API char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid)
2647 return __pkgid_to_manifest(pkgid, uid);
2650 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
2652 return __pkgid_to_manifest(pkgid, GLOBAL_USER);
2655 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2657 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
2660 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2662 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
2665 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2667 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
2670 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2672 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2674 if (manifest == NULL) {
2675 _LOGE("manifest file is NULL\n");
2676 return PMINFO_R_EINVAL;
2679 xmlSchemaParserCtxtPtr ctx;
2680 xmlSchemaValidCtxtPtr vctx;
2681 xmlSchemaPtr xschema;
2682 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2684 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2685 return PMINFO_R_ERROR;
2687 xschema = xmlSchemaParse(ctx);
2688 if (xschema == NULL) {
2689 _LOGE("xmlSchemaParse() Failed\n");
2690 return PMINFO_R_ERROR;
2692 vctx = xmlSchemaNewValidCtxt(xschema);
2694 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2695 return PMINFO_R_ERROR;
2697 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2698 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2700 _LOGE("xmlSchemaValidateFile() failed\n");
2701 return PMINFO_R_ERROR;
2702 } else if (ret == 0) {
2703 _LOGD("Manifest is Valid\n");
2706 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2707 return PMINFO_R_ERROR;
2713 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2723 _LOGE("fork failed\n");
2728 int dev_null_fd = open ("/dev/null", O_RDWR);
2729 if (dev_null_fd >= 0)
2731 dup2 (dev_null_fd, 0);/*stdin*/
2732 dup2 (dev_null_fd, 1);/*stdout*/
2733 dup2 (dev_null_fd, 2);/*stderr*/
2736 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
2737 SCHEMA_FILE, NULL) < 0) {
2738 _LOGE("execl error\n");
2748 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
2752 _LOGE("waitpid failed\n");
2758 if(WIFEXITED(status) && !WEXITSTATUS(status))