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"
45 #include "pkgmgr_parser_signature.h"
50 #define LOG_TAG "PKGMGR_PARSER"
52 #define ASCII(s) (const char *)s
53 #define XMLCHAR(s) (const xmlChar *)s
55 //#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/metadata_parser_list.txt"
56 #define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/mdparser_list.txt"
57 #define METADATA_PARSER_NAME "metadataparser:"
59 #define CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
60 #define CATEGORY_PARSER_NAME "categoryparser:"
62 #define TAG_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/tag_parser_list.txt"
63 #define TAG_PARSER_NAME "parserlib:"
65 #define PKG_TAG_LEN_MAX 128
68 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
79 /* plugin process_type */
81 PLUGIN_PRE_PROCESS = 0,
83 } PLUGIN_PROCESS_TYPE;
96 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label);
97 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege);
98 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges);
99 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile);
100 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed);
101 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation);
102 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri);
103 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime);
104 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp);
105 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition);
106 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
107 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category);
108 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
109 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
110 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
111 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request);
112 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
113 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc);
114 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions);
115 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
116 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
117 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
118 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
119 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
120 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol);
121 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
122 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication, uid_t uid);
123 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication, uid_t uid);
124 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font);
125 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme);
126 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon);
127 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime);
128 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid);
129 static int __next_child_element(xmlTextReaderPtr reader, int depth);
130 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
131 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
132 static void __str_trim(char *input);
133 static char *__get_parser_plugin(const char *type);
134 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
135 API int __is_admin();
137 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, const char **xml_attribute, char *default_value)
139 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
141 *xml_attribute = strdup((const char *)attrib_val);
144 if (default_value != NULL) {
145 *xml_attribute = strdup(default_value);
150 static void __save_xml_lang(xmlTextReaderPtr reader, const char **xml_attribute)
152 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
153 if (attrib_val != NULL)
154 *xml_attribute = strdup(ASCII(attrib_val));
156 *xml_attribute = strdup(DEFAULT_LOCALE);
159 static void __save_xml_value(xmlTextReaderPtr reader, const char **xml_attribute)
161 xmlTextReaderRead(reader);
162 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
165 *xml_attribute = strdup((const char *)attrib_val);
168 static void __save_xml_installed_time(manifest_x *mfx)
170 char buf[PKG_STRING_LEN_MAX] = {'\0'};
174 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
175 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
176 mfx->installed_time = val;
179 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
181 char root[PKG_STRING_LEN_MAX] = { '\0' };
187 tzplatform_set_user(uid);
188 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
189 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
191 mfx->root_path = strdup(root);
193 tzplatform_reset_user();
196 static void __save_xml_default_value(manifest_x * mfx)
198 mfx->preload = strdup("False");
199 mfx->removable = strdup("True");
200 mfx->readonly = strdup("False");
201 mfx->update = strdup("False");
202 mfx->system = strdup("False");
203 mfx->installed_storage= strdup("installed_internal");
204 package = mfx->package;
207 void *__open_lib_handle(char *tag)
209 char *lib_path = NULL;
210 void *lib_handle = NULL;
212 lib_path = __get_parser_plugin(tag);
213 retvm_if(!lib_path, NULL, "lib_path get fail");
215 lib_handle = dlopen(lib_path, RTLD_LAZY);
216 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
221 void __close_lib_handle(void *lib_handle)
226 static void __str_trim(char *input)
228 char *trim_str = input;
233 while (*input != 0) {
234 if (!isspace(*input)) {
247 uid_t uid = getuid();
248 if ((uid_t) 0 == uid )
256 static char * __get_tag_by_key(char *md_key)
260 if (md_key == NULL) {
261 _LOGD("md_key is NULL\n");
265 md_tag = strrchr(md_key, 47) + 1;
268 return strdup(md_tag);
271 static char *__get_metadata_parser_plugin(const char *type)
274 char buffer[1024] = { 0 };
275 char temp_path[1024] = { 0 };
279 _LOGE("invalid argument\n");
283 fp = fopen(PKG_PARSER_CONF_PATH, "r");
285 _LOGE("no matching metadata parser\n");
289 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
290 if (buffer[0] == '#')
295 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
296 path = path + strlen(METADATA_PARSER_NAME);
301 memset(buffer, 0x00, 1024);
308 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
312 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
314 return strdup(temp_path);
317 static char *__get_category_parser_plugin(const char *type)
320 char buffer[1024] = { 0 };
321 char temp_path[1024] = { 0 };
325 _LOGE("invalid argument\n");
329 fp = fopen(PKG_PARSER_CONF_PATH, "r");
331 _LOGE("no matching metadata parser\n");
335 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
336 if (buffer[0] == '#')
341 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
342 path = path + strlen(CATEGORY_PARSER_NAME);
347 memset(buffer, 0x00, 1024);
354 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
358 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
360 return strdup(temp_path);
363 static char *__get_parser_plugin(const char *type)
366 char buffer[1024] = { 0 };
367 char temp_path[1024] = { 0 };
371 _LOGE("invalid argument\n");
375 fp = fopen(PKG_PARSER_CONF_PATH, "r");
377 _LOGE("no matching backendlib\n");
381 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
382 if (buffer[0] == '#')
387 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
388 path = path + strlen(PKG_PARSERLIB);
392 memset(buffer, 0x00, 1024);
399 _LOGE("no matching backendlib\n");
403 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
405 return strdup(temp_path);
408 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
409 ACTION_TYPE action, const char *pkgid)
411 int (*plugin_install) (xmlDocPtr, const char *);
417 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
420 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
422 case ACTION_UNINSTALL:
423 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
429 if ((plugin_install =
430 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
431 _LOGE("can not find symbol[%s] \n", ac);
435 ret = plugin_install(docPtr, pkgid);
436 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
442 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
443 ACTION_TYPE action, const char *pkgid, const char *appid)
445 char *lib_path = NULL;
446 void *lib_handle = NULL;
447 int (*metadata_parser_plugin) (const char *, const char *, GList *);
453 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
456 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
458 case ACTION_UNINSTALL:
459 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
465 lib_path = __get_metadata_parser_plugin(tag);
467 _LOGE("get %s parser fail\n", tag);
471 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
472 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
476 if ((metadata_parser_plugin =
477 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
478 _LOGE("can not find symbol[%s] \n",ac);
482 ret = metadata_parser_plugin(pkgid, appid, md_list);
484 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
486 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
496 static int __ps_run_category_parser(GList *category_list, const char *tag,
497 ACTION_TYPE action, const char *pkgid, const char *appid)
499 char *lib_path = NULL;
500 void *lib_handle = NULL;
501 int (*category_parser_plugin) (const char *, const char *, GList *);
507 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
510 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
512 case ACTION_UNINSTALL:
513 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
519 lib_path = __get_category_parser_plugin(tag);
521 _LOGE("get %s parser fail\n", tag);
525 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
526 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
530 if ((category_parser_plugin =
531 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
532 _LOGE("can not find symbol[%s] \n",ac);
536 ret = category_parser_plugin(pkgid, appid, category_list);
538 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
540 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
550 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
551 ACTION_TYPE action, const char *pkgid)
553 char *lib_path = NULL;
554 void *lib_handle = NULL;
555 int (*plugin_install) (xmlDocPtr, const char *);
561 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
564 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
566 case ACTION_UNINSTALL:
567 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
573 lib_path = __get_parser_plugin(tag);
578 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
579 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
582 if ((plugin_install =
583 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
584 _LOGE("can not find symbol[%s] \n", ac);
588 ret = plugin_install(docPtr, pkgid);
590 _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
592 _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
602 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid)
608 _LOGE("pkgid is NULL");
612 size = strlen(getUserManifestPath(uid)) + strlen(pkgid) + 10;
613 manifest = malloc(size);
614 if (manifest == NULL) {
618 memset(manifest, '\0', size);
619 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
621 if (access(manifest, F_OK)) {
622 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
628 static void __metadata_parser_clear_dir_list(GList* dir_list)
631 __metadata_t* detail = NULL;
634 list = g_list_first(dir_list);
636 detail = (__metadata_t *)list->data;
639 free((void *)detail->key);
641 free((void *)detail->value);
644 list = g_list_next(list);
646 g_list_free(dir_list);
650 static void __category_parser_clear_dir_list(GList* dir_list)
653 __category_t* detail = NULL;
656 list = g_list_first(dir_list);
658 detail = (__category_t *)list->data;
661 free((void *)detail->name);
665 list = g_list_next(list);
667 g_list_free(dir_list);
671 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
676 if (xmlTextReaderDepth(reader) != 1) {
677 _LOGE("Node depth is not 1");
681 if (xmlTextReaderNodeType(reader) != 1) {
682 _LOGE("Node type is not 1");
686 const xmlChar *value;
687 name = xmlTextReaderConstName(reader);
689 _LOGE("TEST TEST TES\n");
690 name = BAD_CAST "--";
693 value = xmlTextReaderConstValue(reader);
695 if (xmlStrlen(value) > 40) {
696 _LOGD(" %.40s...", value);
702 name = xmlTextReaderConstName(reader);
704 _LOGE("TEST TEST TES\n");
705 name = BAD_CAST "--";
708 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
709 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
710 if (copyDocPtr == NULL)
712 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
713 if (rootElement == NULL)
715 xmlNode *cur_node = xmlFirstElementChild(rootElement);
716 if (cur_node == NULL)
718 xmlNode *temp = xmlTextReaderExpand(reader);
721 xmlNode *next_node = NULL;
722 while(cur_node != NULL) {
723 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
724 (temp->line == cur_node->line) ) {
728 next_node = xmlNextElementSibling(cur_node);
729 xmlUnlinkNode(cur_node);
730 xmlFreeNode(cur_node);
731 cur_node = next_node;
734 if (cur_node == NULL)
736 next_node = xmlNextElementSibling(cur_node);
738 cur_node->next = NULL;
739 next_node->prev = NULL;
740 xmlFreeNodeList(next_node);
741 xmlSetTreeDoc(cur_node, copyDocPtr);
743 xmlSetTreeDoc(cur_node, copyDocPtr);
746 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
752 static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
756 char buffer[1024] = { 0, };
757 uiapplication_x *up = mfx->uiapplication;
758 metadata_x *md = NULL;
761 GList *md_list = NULL;
762 __metadata_t *md_detail = NULL;
764 md_tag = __get_tag_by_key(md_key);
765 if (md_tag == NULL) {
766 _LOGD("md_tag is NULL\n");
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);
804 //send glist to parser when tags for metadata plugin parser exist.
806 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, up->appid);
808 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
811 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
814 __metadata_parser_clear_dir_list(md_list);
822 __metadata_parser_clear_dir_list(md_list);
830 static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
834 char buffer[1024] = { 0, };
835 uiapplication_x *up = mfx->uiapplication;
836 category_x *category = NULL;
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");
849 category = up->category;
850 while (category != NULL) {
851 //get glist of category key and value combination
852 memset(buffer, 0x00, 1024);
853 snprintf(buffer, 1024, "%s/", category_key);
854 if ((category->name) && (strncmp(category->name, category_key, strlen(category_key)) == 0)) {
855 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
856 if (category_detail == NULL) {
857 _LOGD("Memory allocation failed\n");
861 category_detail->name = strdup(category->name);
862 if (category_detail->name == NULL) {
863 _LOGD("Memory allocation failed\n");
864 free(category_detail);
868 category_list = g_list_append(category_list, (gpointer)category_detail);
871 category = category->next;
874 //send glist to parser when tags for metadata plugin parser exist.
876 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, up->appid);
878 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
880 _LOGD("category_parser success for tag[%s]\n", category_tag);
882 __category_parser_clear_dir_list(category_list);
883 category_list = NULL;
890 __category_parser_clear_dir_list(category_list);
898 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
900 switch (xmlTextReaderNodeType(reader)) {
901 case XML_READER_TYPE_END_ELEMENT:
905 case XML_READER_TYPE_ELEMENT:
907 // Elements without closing tag don't receive
908 const xmlChar *elementName =
909 xmlTextReaderLocalName(reader);
910 if (elementName == NULL) {
914 if (strcmp(tag, ASCII(elementName)) == 0) {
915 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
916 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
927 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
929 int (*plugin_install) (const char *);
933 if (process == PLUGIN_PRE_PROCESS) {
936 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
939 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
941 case ACTION_UNINSTALL:
942 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
947 } else if (process == PLUGIN_POST_PROCESS) {
950 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
953 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
955 case ACTION_UNINSTALL:
956 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
964 if ((plugin_install =
965 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
969 ret = plugin_install(pkgid);
973 static int __next_child_element(xmlTextReaderPtr reader, int depth)
975 int ret = xmlTextReaderRead(reader);
976 int cur = xmlTextReaderDepth(reader);
979 switch (xmlTextReaderNodeType(reader)) {
980 case XML_READER_TYPE_ELEMENT:
981 if (cur == depth + 1)
984 case XML_READER_TYPE_TEXT:
985 /*text is handled by each function separately*/
986 if (cur == depth + 1)
989 case XML_READER_TYPE_END_ELEMENT:
998 ret = xmlTextReaderRead(reader);
999 cur = xmlTextReaderDepth(reader);
1003 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1005 xmlTextReaderPtr reader;
1009 void *lib_handle = NULL;
1010 char tag[PKG_STRING_LEN_MAX] = { 0 };
1012 fp = fopen(TAG_PARSER_LIST, "r");
1013 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1015 while (fgets(tag, sizeof(tag), fp) != NULL) {
1018 lib_handle = __open_lib_handle(tag);
1019 if (lib_handle == NULL)
1022 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1023 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1025 docPtr = xmlReadFile(filename, NULL, 0);
1026 reader = xmlReaderWalker(docPtr);
1027 if (reader != NULL) {
1028 ret = xmlTextReaderRead(reader);
1030 __process_tag(lib_handle, reader, action, tag, mfx->package);
1031 ret = xmlTextReaderRead(reader);
1033 xmlFreeTextReader(reader);
1036 _LOGD("%s : failed to parse", filename);
1039 _LOGD("Unable to open %s", filename);
1042 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1043 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1045 __close_lib_handle(lib_handle);
1047 memset(tag, 0x00, sizeof(tag));
1056 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1058 fprintf(stdout,"__ps_process_metadata_parser\n");
1061 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1063 fp = fopen(METADATA_PARSER_LIST, "r");
1065 _LOGD("no preload list\n");
1069 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1071 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1082 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1086 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1088 fp = fopen(CATEGORY_PARSER_LIST, "r");
1090 _LOGD("no category parser list\n");
1094 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1095 __str_trim(category_key);
1096 ret = __run_category_parser_prestep(mfx, category_key, action);
1107 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed)
1109 __save_xml_value(reader, &allowed->text);
1113 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation)
1115 __save_xml_attribute(reader, "name", &operation->name, NULL);
1119 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri)
1121 __save_xml_attribute(reader, "name", &uri->name, NULL);
1125 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime)
1127 __save_xml_attribute(reader, "name", &mime->name, NULL);
1131 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp)
1133 __save_xml_attribute(reader, "name", &subapp->name, NULL);
1137 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition)
1139 __save_xml_attribute(reader, "name", &condition->name, NULL);
1143 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
1145 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
1146 __save_xml_value(reader, ¬ification->text);
1150 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category)
1152 __save_xml_attribute(reader, "name", &category->name, NULL);
1156 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
1158 __save_xml_value(reader, &privilege->text);
1162 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
1164 __save_xml_attribute(reader, "key", &metadata->key, NULL);
1165 __save_xml_attribute(reader, "value", &metadata->value, NULL);
1169 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
1171 __save_xml_attribute(reader, "type", &permission->type, NULL);
1172 __save_xml_value(reader, &permission->value);
1176 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
1178 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
1179 __save_xml_value(reader, &compatibility->text);
1183 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request)
1185 __save_xml_value(reader, &request->text);
1189 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
1191 const xmlChar *node;
1194 allowed_x *tmp1 = NULL;
1195 request_x *tmp2 = NULL;
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")) {
1208 allowed_x *allowed= malloc(sizeof(allowed_x));
1209 if (allowed == NULL) {
1210 _LOGD("Malloc Failed\n");
1213 memset(allowed, '\0', sizeof(allowed_x));
1214 LISTADD(define->allowed, allowed);
1215 ret = __ps_process_allowed(reader, allowed);
1216 } else if (!strcmp(ASCII(node), "request")) {
1217 request_x *request = malloc(sizeof(request_x));
1218 if (request == NULL) {
1219 _LOGD("Malloc Failed\n");
1222 memset(request, '\0', sizeof(request_x));
1223 LISTADD(define->request, request);
1224 ret = __ps_process_request(reader, request);
1228 _LOGD("Processing define failed\n");
1232 if (define->allowed) {
1233 LISTHEAD(define->allowed, tmp1);
1234 define->allowed = tmp1;
1236 if (define->request) {
1237 LISTHEAD(define->request, tmp2);
1238 define->request = tmp2;
1243 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol)
1245 const xmlChar *node;
1249 depth = xmlTextReaderDepth(reader);
1250 while ((ret = __next_child_element(reader, depth))) {
1251 node = xmlTextReaderConstName(reader);
1253 _LOGD("xmlTextReaderConstName value is NULL\n");
1257 if (!strcmp(ASCII(node), "operation")) {
1258 __save_xml_attribute(reader, "name", &appcontrol->operation, NULL);
1259 _LOGD("operation processing\n");
1260 } else if (!strcmp(ASCII(node), "uri")) {
1261 __save_xml_attribute(reader, "name", &appcontrol->uri, NULL);
1262 _LOGD("uri processing\n");
1263 } else if (!strcmp(ASCII(node), "mime")) {
1264 __save_xml_attribute(reader, "name", &appcontrol->mime, NULL);
1265 _LOGD("mime processing\n");
1269 _LOGD("Processing appcontrol failed\n");
1277 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
1279 const xmlChar *node;
1282 operation_x *tmp1 = NULL;
1284 mime_x *tmp3 = NULL;
1285 subapp_x *tmp4 = NULL;
1287 depth = xmlTextReaderDepth(reader);
1288 while ((ret = __next_child_element(reader, depth))) {
1289 node = xmlTextReaderConstName(reader);
1291 _LOGD("xmlTextReaderConstName value is NULL\n");
1295 if (!strcmp(ASCII(node), "operation")) {
1296 operation_x *operation = malloc(sizeof(operation_x));
1297 if (operation == NULL) {
1298 _LOGD("Malloc Failed\n");
1301 memset(operation, '\0', sizeof(operation_x));
1302 LISTADD(appsvc->operation, operation);
1303 ret = __ps_process_operation(reader, operation);
1304 _LOGD("operation processing\n");
1305 } else if (!strcmp(ASCII(node), "uri")) {
1306 uri_x *uri= malloc(sizeof(uri_x));
1308 _LOGD("Malloc Failed\n");
1311 memset(uri, '\0', sizeof(uri_x));
1312 LISTADD(appsvc->uri, uri);
1313 ret = __ps_process_uri(reader, uri);
1314 _LOGD("uri processing\n");
1315 } else if (!strcmp(ASCII(node), "mime")) {
1316 mime_x *mime = malloc(sizeof(mime_x));
1318 _LOGD("Malloc Failed\n");
1321 memset(mime, '\0', sizeof(mime_x));
1322 LISTADD(appsvc->mime, mime);
1323 ret = __ps_process_mime(reader, mime);
1324 _LOGD("mime processing\n");
1325 } else if (!strcmp(ASCII(node), "subapp")) {
1326 subapp_x *subapp = malloc(sizeof(subapp_x));
1327 if (subapp == NULL) {
1328 _LOGD("Malloc Failed\n");
1331 memset(subapp, '\0', sizeof(subapp_x));
1332 LISTADD(appsvc->subapp, subapp);
1333 ret = __ps_process_subapp(reader, subapp);
1334 _LOGD("subapp processing\n");
1338 _LOGD("Processing appsvc failed\n");
1342 if (appsvc->operation) {
1343 LISTHEAD(appsvc->operation, tmp1);
1344 appsvc->operation = tmp1;
1347 LISTHEAD(appsvc->uri, tmp2);
1351 LISTHEAD(appsvc->mime, tmp3);
1352 appsvc->mime = tmp3;
1354 if (appsvc->subapp) {
1355 LISTHEAD(appsvc->subapp, tmp4);
1356 appsvc->subapp = tmp4;
1359 xmlTextReaderRead(reader);
1360 if (xmlTextReaderValue(reader))
1361 appsvc->text = ASCII(xmlTextReaderValue(reader));
1367 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges)
1369 const xmlChar *node;
1372 privilege_x *tmp1 = NULL;
1374 depth = xmlTextReaderDepth(reader);
1375 while ((ret = __next_child_element(reader, depth))) {
1376 node = xmlTextReaderConstName(reader);
1378 _LOGD("xmlTextReaderConstName value is NULL\n");
1382 if (strcmp(ASCII(node), "privilege") == 0) {
1383 privilege_x *privilege = malloc(sizeof(privilege_x));
1384 if (privilege == NULL) {
1385 _LOGD("Malloc Failed\n");
1388 memset(privilege, '\0', sizeof(privilege_x));
1389 LISTADD(privileges->privilege, privilege);
1390 ret = __ps_process_privilege(reader, privilege);
1394 _LOGD("Processing privileges failed\n");
1398 if (privileges->privilege) {
1399 LISTHEAD(privileges->privilege, tmp1);
1400 privileges->privilege = tmp1;
1405 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions)
1407 const xmlChar *node;
1410 condition_x *tmp1 = NULL;
1412 depth = xmlTextReaderDepth(reader);
1413 while ((ret = __next_child_element(reader, depth))) {
1414 node = xmlTextReaderConstName(reader);
1416 _LOGD("xmlTextReaderConstName value is NULL\n");
1420 if (strcmp(ASCII(node), "condition") == 0) {
1421 condition_x *condition = malloc(sizeof(condition_x));
1422 if (condition == NULL) {
1423 _LOGD("Malloc Failed\n");
1426 memset(condition, '\0', sizeof(condition_x));
1427 LISTADD(launchconditions->condition, condition);
1428 ret = __ps_process_condition(reader, condition);
1432 _LOGD("Processing launchconditions failed\n");
1436 if (launchconditions->condition) {
1437 LISTHEAD(launchconditions->condition, tmp1);
1438 launchconditions->condition = tmp1;
1441 __save_xml_value(reader, &launchconditions->text);
1446 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
1448 const xmlChar *node;
1451 define_x *tmp1 = NULL;
1452 request_x *tmp2 = NULL;
1453 depth = xmlTextReaderDepth(reader);
1454 while ((ret = __next_child_element(reader, depth))) {
1455 node = xmlTextReaderConstName(reader);
1457 _LOGD("xmlTextReaderConstName value is NULL\n");
1461 if (!strcmp(ASCII(node), "define")) {
1462 define_x *define= malloc(sizeof(define_x));
1463 if (define == NULL) {
1464 _LOGD("Malloc Failed\n");
1467 memset(define, '\0', sizeof(define_x));
1468 LISTADD(datashare->define, define);
1469 ret = __ps_process_define(reader, define);
1470 } else if (!strcmp(ASCII(node), "request")) {
1471 request_x *request= malloc(sizeof(request_x));
1472 if (request == NULL) {
1473 _LOGD("Malloc Failed\n");
1476 memset(request, '\0', sizeof(request_x));
1477 LISTADD(datashare->request, request);
1478 ret = __ps_process_request(reader, request);
1482 _LOGD("Processing data-share failed\n");
1486 if (datashare->define) {
1487 LISTHEAD(datashare->define, tmp1);
1488 datashare->define = tmp1;
1490 if (datashare->request) {
1491 LISTHEAD(datashare->request, tmp2);
1492 datashare->request = tmp2;
1497 static char *__get_icon_with_path(const char *icon, uid_t uid)
1499 char icon_with_path[BUFSIZE];
1500 const char *app_path;
1502 if (!icon || !package)
1505 /* just use absolute path */
1506 if (index(icon, '/'))
1507 return strdup(icon);
1510 snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
1511 getIconPath(uid), icon);
1512 if (access(icon_with_path, F_OK) == 0)
1515 /* for backward compatibility (.../default/small/...)
1516 * this should be removed
1518 snprintf(icon_with_path, sizeof(icon_with_path),
1519 "%sdefault/small/%s",
1520 getIconPath(uid), icon);
1521 if (access(icon_with_path, F_OK) == 0)
1524 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
1525 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
1527 tzplatform_set_user(uid);
1528 app_path = tzplatform_getenv(TZ_USER_APP);
1529 tzplatform_reset_user();
1532 /* If doesn't exist in case of Global app,
1533 * try to get icon directly into app's directory
1535 snprintf(icon_with_path, sizeof(icon_with_path),
1536 "%s/%s/%s", app_path, package, icon);
1537 if (access(icon_with_path, F_OK) == 0)
1540 /* some preload package has icons at below path */
1541 snprintf(icon_with_path, sizeof(icon_with_path),
1542 "%s/%s/res/icons/%s", app_path, package, icon);
1543 if (access(icon_with_path, F_OK) == 0)
1546 /* since 2.3 tpk package */
1547 snprintf(icon_with_path, sizeof(icon_with_path),
1548 "%s/%s/shared/res/%s", app_path, package, icon);
1549 if (access(icon_with_path, F_OK) == 0)
1552 _LOGE("cannot find icon path for [%s]", icon);
1556 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1558 return strdup(icon_with_path);
1561 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1564 char delims[] = "=";
1565 char *ret_result = NULL;
1571 for (tag = strdup(tagv[0]); tag != NULL; ) {
1572 ret_result = strtok(tag, delims);
1574 /*check tag : preload */
1575 if (strcmp(ret_result, "preload") == 0) {
1576 ret_result = strtok(NULL, delims);
1577 if (strcmp(ret_result, "true") == 0) {
1578 free((void *)mfx->preload);
1579 mfx->preload = strdup("true");
1580 } else if (strcmp(ret_result, "false") == 0) {
1581 free((void *)mfx->preload);
1582 mfx->preload = strdup("false");
1584 /*check tag : removable*/
1585 } else if (strcmp(ret_result, "removable") == 0) {
1586 ret_result = strtok(NULL, delims);
1587 if (strcmp(ret_result, "true") == 0){
1588 free((void *)mfx->removable);
1589 mfx->removable = strdup("true");
1590 } else if (strcmp(ret_result, "false") == 0) {
1591 free((void *)mfx->removable);
1592 mfx->removable = strdup("false");
1594 /*check tag : not matched*/
1596 _LOGD("tag process [%s]is not defined\n", ret_result);
1600 /*check next value*/
1601 if (tagv[++i] != NULL)
1602 tag = strdup(tagv[i]);
1604 _LOGD("tag process success...\n");
1610 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1612 __save_xml_attribute(reader, "name", &icon->name, NULL);
1613 __save_xml_attribute(reader, "section", &icon->section, NULL);
1614 __save_xml_attribute(reader, "size", &icon->size, NULL);
1615 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1616 __save_xml_lang(reader, &icon->lang);
1618 xmlTextReaderRead(reader);
1619 const char *text = ASCII(xmlTextReaderValue(reader));
1621 icon->text = (const char *)__get_icon_with_path(text, uid);
1628 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1630 __save_xml_attribute(reader, "name", &image->name, NULL);
1631 __save_xml_attribute(reader, "section", &image->section, NULL);
1632 __save_xml_lang(reader, &image->lang);
1633 __save_xml_value(reader, &image->text);
1637 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1639 __save_xml_attribute(reader, "name", &label->name, NULL);
1640 __save_xml_lang(reader, &label->lang);
1641 __save_xml_value(reader, &label->text);
1646 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1648 __save_xml_attribute(reader, "email", &author->email, NULL);
1649 __save_xml_attribute(reader, "href", &author->href, NULL);
1650 __save_xml_value(reader, &author->text);
1654 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1656 __save_xml_lang(reader, &description->lang);
1657 __save_xml_value(reader, &description->text);
1661 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1663 __save_xml_lang(reader, &license->lang);
1664 __save_xml_value(reader, &license->text);
1668 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1670 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1671 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1672 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1676 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication, uid_t uid)
1678 const xmlChar *node;
1681 label_x *tmp1 = NULL;
1682 icon_x *tmp2 = NULL;
1683 appsvc_x *tmp3 = NULL;
1684 appcontrol_x *tmp4 = NULL;
1685 launchconditions_x *tmp5 = NULL;
1686 notification_x *tmp6 = NULL;
1687 datashare_x *tmp7 = NULL;
1688 category_x *tmp8 = NULL;
1689 metadata_x *tmp9 = NULL;
1690 image_x *tmp10 = NULL;
1691 permission_x *tmp11 = NULL;
1692 datacontrol_x *tmp12 = NULL;
1694 __save_xml_attribute(reader, "appid", &uiapplication->appid, NULL);
1695 retvm_if(uiapplication->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1696 __save_xml_attribute(reader, "exec", &uiapplication->exec, NULL);
1697 __save_xml_attribute(reader, "nodisplay", &uiapplication->nodisplay, "false");
1698 __save_xml_attribute(reader, "multiple", &uiapplication->multiple, "false");
1699 __save_xml_attribute(reader, "type", &uiapplication->type, NULL);
1700 __save_xml_attribute(reader, "categories", &uiapplication->categories, NULL);
1701 __save_xml_attribute(reader, "extraid", &uiapplication->extraid, NULL);
1702 __save_xml_attribute(reader, "taskmanage", &uiapplication->taskmanage, "true");
1703 __save_xml_attribute(reader, "enabled", &uiapplication->enabled, "true");
1704 __save_xml_attribute(reader, "hw-acceleration", &uiapplication->hwacceleration, "default");
1705 __save_xml_attribute(reader, "screen-reader", &uiapplication->screenreader, "use-system-setting");
1706 __save_xml_attribute(reader, "mainapp", &uiapplication->mainapp, "false");
1707 __save_xml_attribute(reader, "recentimage", &uiapplication->recentimage, "false");
1708 __save_xml_attribute(reader, "launchcondition", &uiapplication->launchcondition, "false");
1709 __save_xml_attribute(reader, "indicatordisplay", &uiapplication->indicatordisplay, "true");
1710 __save_xml_attribute(reader, "portrait-effectimage", &uiapplication->portraitimg, NULL);
1711 __save_xml_attribute(reader, "landscape-effectimage", &uiapplication->landscapeimg, NULL);
1712 __save_xml_attribute(reader, "guestmode-visibility", &uiapplication->guestmode_visibility, "true");
1713 __save_xml_attribute(reader, "permission-type", &uiapplication->permission_type, "normal");
1714 __save_xml_attribute(reader, "component-type", &uiapplication->component_type, "uiapp");
1715 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1716 retvm_if(((strcmp(uiapplication->component_type, "svcapp") != 0) && (strcmp(uiapplication->component_type, "uiapp") != 0) && (strcmp(uiapplication->component_type, "widgetapp") != 0)), PM_PARSER_R_ERROR, "invalid component_type[%s]\n", uiapplication->component_type);
1717 __save_xml_attribute(reader, "submode", &uiapplication->submode, "false");
1718 __save_xml_attribute(reader, "submode-mainid", &uiapplication->submode_mainid, NULL);
1719 __save_xml_attribute(reader, "launch_mode", &uiapplication->launch_mode, "caller");
1720 __save_xml_attribute(reader, "ui-gadget", &uiapplication->ui_gadget, "false");
1722 uiapplication->package= strdup(package);
1724 depth = xmlTextReaderDepth(reader);
1725 while ((ret = __next_child_element(reader, depth))) {
1726 node = xmlTextReaderConstName(reader);
1728 _LOGD("xmlTextReaderConstName value is NULL\n");
1731 if (!strcmp(ASCII(node), "label")) {
1732 label_x *label = malloc(sizeof(label_x));
1733 if (label == NULL) {
1734 _LOGD("Malloc Failed\n");
1737 memset(label, '\0', sizeof(label_x));
1738 LISTADD(uiapplication->label, label);
1739 ret = __ps_process_label(reader, label);
1740 } else if (!strcmp(ASCII(node), "icon")) {
1741 icon_x *icon = malloc(sizeof(icon_x));
1743 _LOGD("Malloc Failed\n");
1746 memset(icon, '\0', sizeof(icon_x));
1747 LISTADD(uiapplication->icon, icon);
1748 ret = __ps_process_icon(reader, icon, uid);
1749 } else if (!strcmp(ASCII(node), "image")) {
1750 image_x *image = malloc(sizeof(image_x));
1751 if (image == NULL) {
1752 _LOGD("Malloc Failed\n");
1755 memset(image, '\0', sizeof(image_x));
1756 LISTADD(uiapplication->image, image);
1757 ret = __ps_process_image(reader, image);
1758 } else if (!strcmp(ASCII(node), "category")) {
1759 category_x *category = malloc(sizeof(category_x));
1760 if (category == NULL) {
1761 _LOGD("Malloc Failed\n");
1764 memset(category, '\0', sizeof(category_x));
1765 LISTADD(uiapplication->category, category);
1766 ret = __ps_process_category(reader, category);
1767 } else if (!strcmp(ASCII(node), "metadata")) {
1768 metadata_x *metadata = malloc(sizeof(metadata_x));
1769 if (metadata == NULL) {
1770 _LOGD("Malloc Failed\n");
1773 memset(metadata, '\0', sizeof(metadata_x));
1774 LISTADD(uiapplication->metadata, metadata);
1775 ret = __ps_process_metadata(reader, metadata);
1776 } else if (!strcmp(ASCII(node), "permission")) {
1777 permission_x *permission = malloc(sizeof(permission_x));
1778 if (permission == NULL) {
1779 _LOGD("Malloc Failed\n");
1782 memset(permission, '\0', sizeof(permission_x));
1783 LISTADD(uiapplication->permission, permission);
1784 ret = __ps_process_permission(reader, permission);
1785 } else if (!strcmp(ASCII(node), "app-control")) {
1786 appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
1787 if (appcontrol == NULL) {
1788 _LOGD("Malloc Failed\n");
1791 memset(appcontrol, '\0', sizeof(appcontrol_x));
1792 LISTADD(uiapplication->appcontrol, appcontrol);
1793 ret = __ps_process_appcontrol(reader, appcontrol);
1794 } else if (!strcmp(ASCII(node), "application-service")) {
1795 appsvc_x *appsvc = malloc(sizeof(appsvc_x));
1796 if (appsvc == NULL) {
1797 _LOGD("Malloc Failed\n");
1800 memset(appsvc, '\0', sizeof(appsvc_x));
1801 LISTADD(uiapplication->appsvc, appsvc);
1802 ret = __ps_process_appsvc(reader, appsvc);
1803 } else if (!strcmp(ASCII(node), "data-share")) {
1804 datashare_x *datashare = malloc(sizeof(datashare_x));
1805 if (datashare == NULL) {
1806 _LOGD("Malloc Failed\n");
1809 memset(datashare, '\0', sizeof(datashare_x));
1810 LISTADD(uiapplication->datashare, datashare);
1811 ret = __ps_process_datashare(reader, datashare);
1812 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1813 launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
1814 if (launchconditions == NULL) {
1815 _LOGD("Malloc Failed\n");
1818 memset(launchconditions, '\0', sizeof(launchconditions_x));
1819 LISTADD(uiapplication->launchconditions, launchconditions);
1820 ret = __ps_process_launchconditions(reader, launchconditions);
1821 } else if (!strcmp(ASCII(node), "notification")) {
1822 notification_x *notification = malloc(sizeof(notification_x));
1823 if (notification == NULL) {
1824 _LOGD("Malloc Failed\n");
1827 memset(notification, '\0', sizeof(notification_x));
1828 LISTADD(uiapplication->notification, notification);
1829 ret = __ps_process_notification(reader, notification);
1830 } else if (!strcmp(ASCII(node), "datacontrol")) {
1831 datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
1832 if (datacontrol == NULL) {
1833 _LOGD("Malloc Failed\n");
1836 memset(datacontrol, '\0', sizeof(datacontrol_x));
1837 LISTADD(uiapplication->datacontrol, datacontrol);
1838 ret = __ps_process_datacontrol(reader, datacontrol);
1842 _LOGD("Processing uiapplication failed\n");
1847 if (uiapplication->label) {
1848 LISTHEAD(uiapplication->label, tmp1);
1849 uiapplication->label = tmp1;
1851 if (uiapplication->icon) {
1852 LISTHEAD(uiapplication->icon, tmp2);
1853 uiapplication->icon = tmp2;
1855 if (uiapplication->appsvc) {
1856 LISTHEAD(uiapplication->appsvc, tmp3);
1857 uiapplication->appsvc = tmp3;
1859 if (uiapplication->appcontrol) {
1860 LISTHEAD(uiapplication->appcontrol, tmp4);
1861 uiapplication->appcontrol = tmp4;
1863 if (uiapplication->launchconditions) {
1864 LISTHEAD(uiapplication->launchconditions, tmp5);
1865 uiapplication->launchconditions = tmp5;
1867 if (uiapplication->notification) {
1868 LISTHEAD(uiapplication->notification, tmp6);
1869 uiapplication->notification = tmp6;
1871 if (uiapplication->datashare) {
1872 LISTHEAD(uiapplication->datashare, tmp7);
1873 uiapplication->datashare = tmp7;
1875 if (uiapplication->category) {
1876 LISTHEAD(uiapplication->category, tmp8);
1877 uiapplication->category = tmp8;
1879 if (uiapplication->metadata) {
1880 LISTHEAD(uiapplication->metadata, tmp9);
1881 uiapplication->metadata = tmp9;
1883 if (uiapplication->image) {
1884 LISTHEAD(uiapplication->image, tmp10);
1885 uiapplication->image = tmp10;
1887 if (uiapplication->permission) {
1888 LISTHEAD(uiapplication->permission, tmp11);
1889 uiapplication->permission = tmp11;
1891 if (uiapplication->datacontrol) {
1892 LISTHEAD(uiapplication->datacontrol, tmp12);
1893 uiapplication->datacontrol = tmp12;
1899 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication, uid_t uid)
1901 const xmlChar *node;
1904 label_x *tmp1 = NULL;
1905 icon_x *tmp2 = NULL;
1906 appsvc_x *tmp3 = NULL;
1907 appcontrol_x *tmp4 = NULL;
1908 datacontrol_x *tmp5 = NULL;
1909 launchconditions_x *tmp6 = NULL;
1910 notification_x *tmp7 = NULL;
1911 datashare_x *tmp8 = NULL;
1912 category_x *tmp9 = NULL;
1913 metadata_x *tmp10 = NULL;
1914 permission_x *tmp11 = NULL;
1916 __save_xml_attribute(reader, "appid", &serviceapplication->appid, NULL);
1917 retvm_if(serviceapplication->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1918 __save_xml_attribute(reader, "exec", &serviceapplication->exec, NULL);
1919 __save_xml_attribute(reader, "type", &serviceapplication->type, NULL);
1920 __save_xml_attribute(reader, "enabled", &serviceapplication->enabled, "true");
1921 __save_xml_attribute(reader, "permission-type", &serviceapplication->permission_type, "normal");
1922 __save_xml_attribute(reader, "auto-restart", &serviceapplication->autorestart, "false");
1923 __save_xml_attribute(reader, "on-boot", &serviceapplication->onboot, "false");
1925 serviceapplication->package= strdup(package);
1927 depth = xmlTextReaderDepth(reader);
1928 while ((ret = __next_child_element(reader, depth))) {
1929 node = xmlTextReaderConstName(reader);
1931 _LOGD("xmlTextReaderConstName value is NULL\n");
1935 if (!strcmp(ASCII(node), "label")) {
1936 label_x *label = malloc(sizeof(label_x));
1937 if (label == NULL) {
1938 _LOGD("Malloc Failed\n");
1941 memset(label, '\0', sizeof(label_x));
1942 LISTADD(serviceapplication->label, label);
1943 ret = __ps_process_label(reader, label);
1944 } else if (!strcmp(ASCII(node), "icon")) {
1945 icon_x *icon = malloc(sizeof(icon_x));
1947 _LOGD("Malloc Failed\n");
1950 memset(icon, '\0', sizeof(icon_x));
1951 LISTADD(serviceapplication->icon, icon);
1952 ret = __ps_process_icon(reader, icon, uid);
1953 } else if (!strcmp(ASCII(node), "category")) {
1954 category_x *category = malloc(sizeof(category_x));
1955 if (category == NULL) {
1956 _LOGD("Malloc Failed\n");
1959 memset(category, '\0', sizeof(category_x));
1960 LISTADD(serviceapplication->category, category);
1961 ret = __ps_process_category(reader, category);
1962 } else if (!strcmp(ASCII(node), "metadata")) {
1963 metadata_x *metadata = malloc(sizeof(metadata_x));
1964 if (metadata == NULL) {
1965 _LOGD("Malloc Failed\n");
1968 memset(metadata, '\0', sizeof(metadata_x));
1969 LISTADD(serviceapplication->metadata, metadata);
1970 ret = __ps_process_metadata(reader, metadata);
1971 } else if (!strcmp(ASCII(node), "permission")) {
1972 permission_x *permission = malloc(sizeof(permission_x));
1973 if (permission == NULL) {
1974 _LOGD("Malloc Failed\n");
1977 memset(permission, '\0', sizeof(permission_x));
1978 LISTADD(serviceapplication->permission, permission);
1979 ret = __ps_process_permission(reader, permission);
1980 } else if (!strcmp(ASCII(node), "app-control")) {
1981 appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
1982 if (appcontrol == NULL) {
1983 _LOGD("Malloc Failed\n");
1986 memset(appcontrol, '\0', sizeof(appcontrol_x));
1987 LISTADD(serviceapplication->appcontrol, appcontrol);
1988 ret = __ps_process_appcontrol(reader, appcontrol);
1989 } else if (!strcmp(ASCII(node), "application-service")) {
1990 appsvc_x *appsvc = malloc(sizeof(appsvc_x));
1991 if (appsvc == NULL) {
1992 _LOGD("Malloc Failed\n");
1995 memset(appsvc, '\0', sizeof(appsvc_x));
1996 LISTADD(serviceapplication->appsvc, appsvc);
1997 ret = __ps_process_appsvc(reader, appsvc);
1998 } else if (!strcmp(ASCII(node), "data-share")) {
1999 datashare_x *datashare = malloc(sizeof(datashare_x));
2000 if (datashare == NULL) {
2001 _LOGD("Malloc Failed\n");
2004 memset(datashare, '\0', sizeof(datashare_x));
2005 LISTADD(serviceapplication->datashare, datashare);
2006 ret = __ps_process_datashare(reader, datashare);
2007 } else if (!strcmp(ASCII(node), "launch-conditions")) {
2008 launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
2009 if (launchconditions == NULL) {
2010 _LOGD("Malloc Failed\n");
2013 memset(launchconditions, '\0', sizeof(launchconditions_x));
2014 LISTADD(serviceapplication->launchconditions, launchconditions);
2015 ret = __ps_process_launchconditions(reader, launchconditions);
2016 } else if (!strcmp(ASCII(node), "notification")) {
2017 notification_x *notification = malloc(sizeof(notification_x));
2018 if (notification == NULL) {
2019 _LOGD("Malloc Failed\n");
2022 memset(notification, '\0', sizeof(notification_x));
2023 LISTADD(serviceapplication->notification, notification);
2024 ret = __ps_process_notification(reader, notification);
2025 } else if (!strcmp(ASCII(node), "datacontrol")) {
2026 datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
2027 if (datacontrol == NULL) {
2028 _LOGD("Malloc Failed\n");
2031 memset(datacontrol, '\0', sizeof(datacontrol_x));
2032 LISTADD(serviceapplication->datacontrol, datacontrol);
2033 ret = __ps_process_datacontrol(reader, datacontrol);
2037 _LOGD("Processing serviceapplication failed\n");
2042 if (serviceapplication->label) {
2043 LISTHEAD(serviceapplication->label, tmp1);
2044 serviceapplication->label = tmp1;
2046 if (serviceapplication->icon) {
2047 LISTHEAD(serviceapplication->icon, tmp2);
2048 serviceapplication->icon = tmp2;
2050 if (serviceapplication->appsvc) {
2051 LISTHEAD(serviceapplication->appsvc, tmp3);
2052 serviceapplication->appsvc = tmp3;
2054 if (serviceapplication->appcontrol) {
2055 LISTHEAD(serviceapplication->appcontrol, tmp4);
2056 serviceapplication->appcontrol = tmp4;
2058 if (serviceapplication->datacontrol) {
2059 LISTHEAD(serviceapplication->datacontrol, tmp5);
2060 serviceapplication->datacontrol = tmp5;
2062 if (serviceapplication->launchconditions) {
2063 LISTHEAD(serviceapplication->launchconditions, tmp6);
2064 serviceapplication->launchconditions = tmp6;
2066 if (serviceapplication->notification) {
2067 LISTHEAD(serviceapplication->notification, tmp7);
2068 serviceapplication->notification = tmp7;
2070 if (serviceapplication->datashare) {
2071 LISTHEAD(serviceapplication->datashare, tmp8);
2072 serviceapplication->datashare = tmp8;
2074 if (serviceapplication->category) {
2075 LISTHEAD(serviceapplication->category, tmp9);
2076 serviceapplication->category = tmp9;
2078 if (serviceapplication->metadata) {
2079 LISTHEAD(serviceapplication->metadata, tmp10);
2080 serviceapplication->metadata = tmp10;
2082 if (serviceapplication->permission) {
2083 LISTHEAD(serviceapplication->permission, tmp11);
2084 serviceapplication->permission = tmp11;
2090 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile)
2092 /*TODO: once policy is set*/
2096 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font)
2098 /*TODO: once policy is set*/
2102 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme)
2104 /*TODO: once policy is set*/
2108 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon)
2110 /*TODO: once policy is set*/
2114 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
2116 /*TODO: once policy is set*/
2120 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
2122 _LOGD("__start_process\n");
2123 const xmlChar *node;
2126 label_x *tmp1 = NULL;
2127 author_x *tmp2 = NULL;
2128 description_x *tmp3 = NULL;
2129 license_x *tmp4 = NULL;
2130 uiapplication_x *tmp5 = NULL;
2131 serviceapplication_x *tmp6 = NULL;
2132 daemon_x *tmp7 = NULL;
2133 theme_x *tmp8 = NULL;
2134 font_x *tmp9 = NULL;
2135 ime_x *tmp10 = NULL;
2136 icon_x *tmp11 = NULL;
2137 compatibility_x *tmp12 = NULL;
2138 deviceprofile_x *tmp13 = NULL;
2139 privileges_x *tmp14 = NULL;
2141 depth = xmlTextReaderDepth(reader);
2142 while ((ret = __next_child_element(reader, depth))) {
2143 node = xmlTextReaderConstName(reader);
2145 _LOGD("xmlTextReaderConstName value is NULL\n");
2149 if (!strcmp(ASCII(node), "label")) {
2150 label_x *label = malloc(sizeof(label_x));
2151 if (label == NULL) {
2152 _LOGD("Malloc Failed\n");
2155 memset(label, '\0', sizeof(label_x));
2156 LISTADD(mfx->label, label);
2157 ret = __ps_process_label(reader, label);
2158 } else if (!strcmp(ASCII(node), "author")) {
2159 author_x *author = malloc(sizeof(author_x));
2160 if (author == NULL) {
2161 _LOGD("Malloc Failed\n");
2164 memset(author, '\0', sizeof(author_x));
2165 LISTADD(mfx->author, author);
2166 ret = __ps_process_author(reader, author);
2167 } else if (!strcmp(ASCII(node), "description")) {
2168 description_x *description = malloc(sizeof(description_x));
2169 if (description == NULL) {
2170 _LOGD("Malloc Failed\n");
2173 memset(description, '\0', sizeof(description_x));
2174 LISTADD(mfx->description, description);
2175 ret = __ps_process_description(reader, description);
2176 } else if (!strcmp(ASCII(node), "license")) {
2177 license_x *license = malloc(sizeof(license_x));
2178 if (license == NULL) {
2179 _LOGD("Malloc Failed\n");
2182 memset(license, '\0', sizeof(license_x));
2183 LISTADD(mfx->license, license);
2184 ret = __ps_process_license(reader, license);
2185 } else if (!strcmp(ASCII(node), "privileges")) {
2186 privileges_x *privileges = malloc(sizeof(privileges_x));
2187 if (privileges == NULL) {
2188 _LOGD("Malloc Failed\n");
2191 memset(privileges, '\0', sizeof(privileges_x));
2192 LISTADD(mfx->privileges, privileges);
2193 ret = __ps_process_privileges(reader, privileges);
2194 } else if (!strcmp(ASCII(node), "ui-application")) {
2195 uiapplication_x *uiapplication = malloc(sizeof(uiapplication_x));
2196 if (uiapplication == NULL) {
2197 _LOGD("Malloc Failed\n");
2200 memset(uiapplication, '\0', sizeof(uiapplication_x));
2201 LISTADD(mfx->uiapplication, uiapplication);
2202 ret = __ps_process_uiapplication(reader, uiapplication, uid);
2203 } else if (!strcmp(ASCII(node), "service-application")) {
2204 serviceapplication_x *serviceapplication = malloc(sizeof(serviceapplication_x));
2205 if (serviceapplication == NULL) {
2206 _LOGD("Malloc Failed\n");
2209 memset(serviceapplication, '\0', sizeof(serviceapplication_x));
2210 LISTADD(mfx->serviceapplication, serviceapplication);
2211 ret = __ps_process_serviceapplication(reader, serviceapplication, uid);
2212 } else if (!strcmp(ASCII(node), "daemon")) {
2213 daemon_x *daemon = malloc(sizeof(daemon_x));
2214 if (daemon == NULL) {
2215 _LOGD("Malloc Failed\n");
2218 memset(daemon, '\0', sizeof(daemon_x));
2219 LISTADD(mfx->daemon, daemon);
2220 ret = __ps_process_daemon(reader, daemon);
2221 } else if (!strcmp(ASCII(node), "theme")) {
2222 theme_x *theme = malloc(sizeof(theme_x));
2223 if (theme == NULL) {
2224 _LOGD("Malloc Failed\n");
2227 memset(theme, '\0', sizeof(theme_x));
2228 LISTADD(mfx->theme, theme);
2229 ret = __ps_process_theme(reader, theme);
2230 } else if (!strcmp(ASCII(node), "font")) {
2231 font_x *font = malloc(sizeof(font_x));
2233 _LOGD("Malloc Failed\n");
2236 memset(font, '\0', sizeof(font_x));
2237 LISTADD(mfx->font, font);
2238 ret = __ps_process_font(reader, font);
2239 } else if (!strcmp(ASCII(node), "ime")) {
2240 ime_x *ime = malloc(sizeof(ime_x));
2242 _LOGD("Malloc Failed\n");
2245 memset(ime, '\0', sizeof(ime_x));
2246 LISTADD(mfx->ime, ime);
2247 ret = __ps_process_ime(reader, ime);
2248 } else if (!strcmp(ASCII(node), "icon")) {
2249 icon_x *icon = malloc(sizeof(icon_x));
2251 _LOGD("Malloc Failed\n");
2254 memset(icon, '\0', sizeof(icon_x));
2255 LISTADD(mfx->icon, icon);
2256 ret = __ps_process_icon(reader, icon, uid);
2257 } else if (!strcmp(ASCII(node), "profile")) {
2258 deviceprofile_x *deviceprofile = malloc(sizeof(deviceprofile_x));
2259 if (deviceprofile == NULL) {
2260 _LOGD("Malloc Failed\n");
2263 memset(deviceprofile, '\0', sizeof(deviceprofile_x));
2264 LISTADD(mfx->deviceprofile, deviceprofile);
2265 ret = __ps_process_deviceprofile(reader, deviceprofile);
2266 } else if (!strcmp(ASCII(node), "compatibility")) {
2267 compatibility_x *compatibility = malloc(sizeof(compatibility_x));
2268 if (compatibility == NULL) {
2269 _LOGD("Malloc Failed\n");
2272 memset(compatibility, '\0', sizeof(compatibility_x));
2273 LISTADD(mfx->compatibility, compatibility);
2274 ret = __ps_process_compatibility(reader, compatibility);
2275 } else if (!strcmp(ASCII(node), "shortcut-list")) {
2277 } else if (!strcmp(ASCII(node), "livebox")) {
2279 } else if (!strcmp(ASCII(node), "account")) {
2281 } else if (!strcmp(ASCII(node), "notifications")) {
2283 } else if (!strcmp(ASCII(node), "ime")) {
2285 } else if (!strcmp(ASCII(node), "feature")) {
2288 _LOGE("Unknown element: %s", ASCII(node));
2293 _LOGD("Processing manifest failed\n");
2298 LISTHEAD(mfx->label, tmp1);
2302 LISTHEAD(mfx->author, tmp2);
2305 if (mfx->description) {
2306 LISTHEAD(mfx->description, tmp3);
2307 mfx->description= tmp3;
2310 LISTHEAD(mfx->license, tmp4);
2313 if (mfx->uiapplication) {
2314 LISTHEAD(mfx->uiapplication, tmp5);
2315 mfx->uiapplication = tmp5;
2317 if (mfx->serviceapplication) {
2318 LISTHEAD(mfx->serviceapplication, tmp6);
2319 mfx->serviceapplication = tmp6;
2322 LISTHEAD(mfx->daemon, tmp7);
2326 LISTHEAD(mfx->theme, tmp8);
2330 LISTHEAD(mfx->font, tmp9);
2334 LISTHEAD(mfx->ime, tmp10);
2338 LISTHEAD(mfx->icon, tmp11);
2341 if (mfx->compatibility) {
2342 LISTHEAD(mfx->compatibility, tmp12);
2343 mfx->compatibility= tmp12;
2345 if (mfx->deviceprofile) {
2346 LISTHEAD(mfx->deviceprofile, tmp13);
2347 mfx->deviceprofile= tmp13;
2349 if (mfx->privileges) {
2350 LISTHEAD(mfx->privileges, tmp14);
2351 mfx->privileges = tmp14;
2356 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
2358 const xmlChar *node;
2361 if ((ret = __next_child_element(reader, -1))) {
2362 node = xmlTextReaderConstName(reader);
2364 _LOGD("xmlTextReaderConstName value is NULL\n");
2368 if (!strcmp(ASCII(node), "manifest")) {
2369 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
2370 __save_xml_attribute(reader, "package", &mfx->package, NULL);
2371 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
2372 __save_xml_attribute(reader, "version", &mfx->version, NULL);
2373 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
2374 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
2375 __save_xml_attribute(reader, "type", &mfx->type, "rpm");
2376 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
2377 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
2378 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
2379 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
2380 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
2381 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
2382 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
2384 __save_xml_installed_time(mfx);
2385 __save_xml_root_path(mfx, uid);
2386 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
2387 __save_xml_default_value(mfx);
2389 ret = __start_process(reader, mfx, uid);
2391 _LOGD("No Manifest element found\n");
2398 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
2400 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
2402 void *lib_handle = NULL;
2403 int (*appsvc_operation) (const char *, uid_t);
2405 uiapplication_x *uiapplication = mfx->uiapplication;
2407 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
2408 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
2412 if ((appsvc_operation =
2413 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
2414 _LOGE("can not find symbol \n");
2418 for(; uiapplication; uiapplication=uiapplication->next) {
2419 ret = appsvc_operation(uiapplication->appid, uid);
2421 _LOGE("can not operation symbol \n");
2426 dlclose(lib_handle);
2431 #define PRELOAD_PACKAGE_LIST SYSCONFDIR "/package-manager/preload/preload_list.txt"
2432 static int __add_preload_info(manifest_x * mfx, const char *manifest, uid_t uid)
2435 char buffer[1024] = { 0 };
2438 if(strstr(manifest, getUserManifestPath(uid))) {
2439 free((void *)mfx->readonly);
2440 mfx->readonly = strdup("True");
2442 free((void *)mfx->preload);
2443 mfx->preload = strdup("True");
2445 free((void *)mfx->removable);
2446 mfx->removable = strdup("False");
2448 free((void *)mfx->system);
2449 mfx->system = strdup("True");
2454 fp = fopen(PRELOAD_PACKAGE_LIST, "r");
2456 _LOGE("no preload list\n");
2460 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
2461 if (buffer[0] == '#') {
2462 if(strcasestr(buffer, "RW_NORM"))
2464 else if(strcasestr(buffer, "RW_RM"))
2472 if(!strcmp(mfx->package, buffer)) {
2473 free((void *)mfx->preload);
2474 mfx->preload = strdup("True");
2476 free((void *)mfx->readonly);
2477 mfx->readonly = strdup("False");
2478 free((void *)mfx->removable);
2479 mfx->removable = strdup("False");
2480 } else if(state == 3){
2481 free((void *)mfx->readonly);
2482 mfx->readonly = strdup("False");
2483 free((void *)mfx->removable);
2484 mfx->removable = strdup("True");
2488 memset(buffer, 0x00, sizeof(buffer));
2497 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
2499 if (!strstr(manifest, getUserManifestPath(uid))) {
2500 /* if downloaded app is updated, then update tag set true*/
2502 free((void *)mfx->update);
2503 mfx->update = strdup("true");
2510 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
2512 /* desktop file is no longer used */
2516 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
2518 /* desktop file is no longer used */
2523 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
2525 pkgmgrinfo_basic_free_package((package_x *)mfx);
2528 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
2530 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
2531 xmlTextReaderPtr reader;
2532 manifest_x *mfx = NULL;
2534 reader = xmlReaderForFile(manifest, NULL, 0);
2536 mfx = malloc(sizeof(manifest_x));
2538 memset(mfx, '\0', sizeof(manifest_x));
2539 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
2540 _LOGD("Parsing Failed\n");
2541 pkgmgr_parser_free_manifest_xml(mfx);
2544 _LOGD("Parsing Success\n");
2546 _LOGD("Memory allocation error\n");
2548 xmlFreeTextReader(reader);
2550 _LOGD("Unable to create xml reader\n");
2556 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
2558 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
2559 xmlTextReaderPtr reader;
2560 manifest_x *mfx = NULL;
2562 reader = xmlReaderForFile(manifest, NULL, 0);
2564 mfx = malloc(sizeof(manifest_x));
2566 memset(mfx, '\0', sizeof(manifest_x));
2567 if (__process_manifest(reader, mfx, uid) < 0) {
2568 _LOGD("Parsing Failed\n");
2569 pkgmgr_parser_free_manifest_xml(mfx);
2572 _LOGD("Parsing Success\n");
2574 _LOGD("Memory allocation error\n");
2576 xmlFreeTextReader(reader);
2578 _LOGD("Unable to create xml reader\n");
2583 /* These APIs are intended to call parser directly */
2585 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2587 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2588 _LOGD("parsing manifest for installation: %s\n", manifest);
2590 manifest_x *mfx = NULL;
2594 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2595 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2597 _LOGD("Parsing Finished\n");
2599 __add_preload_info(mfx, manifest, GLOBAL_USER);
2601 _LOGD("Added preload infomation\n");
2603 __ps_process_tag(mfx, tagv);
2605 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2606 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2608 _LOGD("DB Insert Success\n");
2610 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2611 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2613 _LOGD("Creating metadata parser failed\n");
2615 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2617 _LOGD("Creating category parser failed\n");
2619 pkgmgr_parser_free_manifest_xml(mfx);
2620 _LOGD("Free Done\n");
2625 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2627 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2628 _LOGD("parsing manifest for installation: %s\n", manifest);
2629 manifest_x *mfx = NULL;
2633 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2634 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2636 _LOGD("Parsing Finished\n");
2638 __ps_process_tag(mfx, tagv);
2640 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2641 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2643 _LOGD("DB Insert Success\n");
2645 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2646 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2648 _LOGD("Creating metadata parser failed\n");
2649 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2651 _LOGD("Creating category parser failed\n");
2653 pkgmgr_parser_free_manifest_xml(mfx);
2654 _LOGD("Free Done\n");
2660 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2662 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2663 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2664 manifest_x *mfx = NULL;
2666 bool preload = false;
2667 bool system = false;
2668 char *csc_path = NULL;
2669 pkgmgrinfo_pkginfo_h handle = NULL;
2672 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2673 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2675 _LOGD("Parsing Finished\n");
2676 __add_preload_info(mfx, manifest, GLOBAL_USER);
2677 _LOGD("Added preload infomation\n");
2678 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2680 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2681 if (ret != PMINFO_R_OK)
2682 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2683 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2684 if (ret != PMINFO_R_OK)
2685 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2688 free((void *)mfx->preload);
2689 mfx->preload = strdup("true");
2692 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2693 if (ret != PMINFO_R_OK)
2694 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2696 free((void *)mfx->system);
2697 mfx->system = strdup("true");
2700 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2701 if (ret != PMINFO_R_OK)
2702 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2704 if (csc_path != NULL) {
2706 free((void *)mfx->csc_path);
2707 mfx->csc_path = strdup(csc_path);
2710 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2711 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2713 _LOGD("DB Update Success\n");
2715 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2716 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2718 _LOGD("Upgrade metadata parser failed\n");
2720 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2722 _LOGD("Creating category parser failed\n");
2723 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2724 pkgmgr_parser_free_manifest_xml(mfx);
2725 _LOGD("Free Done\n");
2731 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2733 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2734 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2735 manifest_x *mfx = NULL;
2737 bool preload = false;
2738 bool system = false;
2739 char *csc_path = NULL;
2740 pkgmgrinfo_pkginfo_h handle = NULL;
2743 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2744 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2746 _LOGD("Parsing Finished\n");
2747 __check_preload_updated(mfx, manifest, uid);
2749 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2750 if (ret != PMINFO_R_OK)
2751 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2752 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2753 if (ret != PMINFO_R_OK)
2754 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2757 free((void *)mfx->preload);
2758 mfx->preload = strdup("true");
2761 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2762 if (ret != PMINFO_R_OK)
2763 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2766 free((void *)mfx->system);
2767 mfx->system = strdup("true");
2770 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2771 if (ret != PMINFO_R_OK)
2772 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2773 if (csc_path != NULL) {
2775 free((void *)mfx->csc_path);
2776 mfx->csc_path = strdup(csc_path);
2779 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2780 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2781 _LOGD("DB Update Success\n");
2783 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2784 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2786 _LOGD("Upgrade metadata parser failed\n");
2787 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2789 _LOGD("Creating category parser failed\n");
2790 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2791 pkgmgr_parser_free_manifest_xml(mfx);
2792 _LOGD("Free Done\n");
2798 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2800 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2801 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2803 manifest_x *mfx = NULL;
2806 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2807 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2809 _LOGD("Parsing Finished\n");
2811 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2813 __add_preload_info(mfx, manifest, GLOBAL_USER);
2814 _LOGD("Added preload infomation\n");
2816 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2818 _LOGD("Removing metadata parser failed\n");
2820 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2822 _LOGD("Creating category parser failed\n");
2824 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2826 _LOGD("DB Delete failed\n");
2828 _LOGD("DB Delete Success\n");
2830 pkgmgr_parser_free_manifest_xml(mfx);
2831 _LOGD("Free Done\n");
2838 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2840 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2841 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2843 manifest_x *mfx = NULL;
2846 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2847 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2849 _LOGD("Parsing Finished\n");
2851 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2853 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2855 _LOGD("Removing metadata parser failed\n");
2857 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2859 _LOGD("Creating category parser failed\n");
2861 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2863 _LOGD("DB Delete failed\n");
2865 _LOGD("DB Delete Success\n");
2867 ret = __ps_remove_appsvc_db(mfx, uid);
2869 _LOGD("Removing appsvc_db failed\n");
2871 _LOGD("Removing appsvc_db Success\n");
2873 pkgmgr_parser_free_manifest_xml(mfx);
2874 _LOGD("Free Done\n");
2880 API int pkgmgr_parser_parse_manifest_for_preload()
2882 return pkgmgr_parser_update_preload_info_in_db();
2885 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
2887 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
2891 API char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid)
2893 return __pkgid_to_manifest(pkgid, uid);
2896 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
2898 return __pkgid_to_manifest(pkgid, GLOBAL_USER);
2901 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2903 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
2906 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2908 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
2911 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2913 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
2916 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2918 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2920 if (manifest == NULL) {
2921 _LOGE("manifest file is NULL\n");
2922 return PMINFO_R_EINVAL;
2925 xmlSchemaParserCtxtPtr ctx;
2926 xmlSchemaValidCtxtPtr vctx;
2927 xmlSchemaPtr xschema;
2928 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2930 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2931 return PMINFO_R_ERROR;
2933 xschema = xmlSchemaParse(ctx);
2934 if (xschema == NULL) {
2935 _LOGE("xmlSchemaParse() Failed\n");
2936 return PMINFO_R_ERROR;
2938 vctx = xmlSchemaNewValidCtxt(xschema);
2940 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2941 return PMINFO_R_ERROR;
2943 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2944 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2946 _LOGE("xmlSchemaValidateFile() failed\n");
2947 return PMINFO_R_ERROR;
2948 } else if (ret == 0) {
2949 _LOGE("Manifest is Valid\n");
2952 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2953 return PMINFO_R_ERROR;
2959 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2969 _LOGE("fork failed\n");
2974 int dev_null_fd = open ("/dev/null", O_RDWR);
2975 if (dev_null_fd >= 0)
2977 dup2 (dev_null_fd, 0);/*stdin*/
2978 dup2 (dev_null_fd, 1);/*stdout*/
2979 dup2 (dev_null_fd, 2);/*stderr*/
2982 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
2983 SCHEMA_FILE, NULL) < 0) {
2984 _LOGE("execl error\n");
2994 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
2998 _LOGE("waitpid failed\n");
3004 if(WIFEXITED(status) && !WEXITSTATUS(status))