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)
1500 char *icon_with_path;
1501 char *confirmed_icon;
1502 const char *app_path;
1505 if (!icon || !package)
1508 if (index(icon, '/') == NULL) {
1509 /* "db/setting/theme" is not exist */
1511 theme = vconf_get_str("db/setting/theme");
1513 theme = strdup("default");
1519 theme = strdup("default");
1522 len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
1523 icon_with_path = malloc(len);
1524 if(icon_with_path == NULL) {
1525 _LOGD("(icon_with_path == NULL) return\n");
1530 memset(icon_with_path, 0, len);
1531 if (uid != GLOBAL_USER && uid != OWNER_ROOT)
1532 snprintf(icon_with_path, len, "%s%s", getIconPath(uid), icon);
1534 snprintf(icon_with_path, len, "%s%s/small/%s", getIconPath(GLOBAL_USER), theme, icon);
1535 if (access (icon_with_path, F_OK)) { //If doesn't exist in case of Global app, try to get icon directly into app's directory
1536 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
1538 snprintf(icon_with_path, len, "%s/%s/res/icons/%s/small/%s", app_path, package, theme, icon);
1539 if (access(icon_with_path, F_OK))
1540 _LOGE("Cannot find icon path");
1544 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1545 return icon_with_path;
1547 confirmed_icon = strdup(icon);
1548 if (!confirmed_icon)
1550 return confirmed_icon;
1554 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1557 char delims[] = "=";
1558 char *ret_result = NULL;
1564 for (tag = strdup(tagv[0]); tag != NULL; ) {
1565 ret_result = strtok(tag, delims);
1567 /*check tag : preload */
1568 if (strcmp(ret_result, "preload") == 0) {
1569 ret_result = strtok(NULL, delims);
1570 if (strcmp(ret_result, "true") == 0) {
1571 free((void *)mfx->preload);
1572 mfx->preload = strdup("true");
1573 } else if (strcmp(ret_result, "false") == 0) {
1574 free((void *)mfx->preload);
1575 mfx->preload = strdup("false");
1577 /*check tag : removable*/
1578 } else if (strcmp(ret_result, "removable") == 0) {
1579 ret_result = strtok(NULL, delims);
1580 if (strcmp(ret_result, "true") == 0){
1581 free((void *)mfx->removable);
1582 mfx->removable = strdup("true");
1583 } else if (strcmp(ret_result, "false") == 0) {
1584 free((void *)mfx->removable);
1585 mfx->removable = strdup("false");
1587 /*check tag : not matched*/
1589 _LOGD("tag process [%s]is not defined\n", ret_result);
1593 /*check next value*/
1594 if (tagv[++i] != NULL)
1595 tag = strdup(tagv[i]);
1597 _LOGD("tag process success...\n");
1603 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1605 __save_xml_attribute(reader, "name", &icon->name, NULL);
1606 __save_xml_attribute(reader, "section", &icon->section, NULL);
1607 __save_xml_attribute(reader, "size", &icon->size, NULL);
1608 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1609 __save_xml_lang(reader, &icon->lang);
1611 xmlTextReaderRead(reader);
1612 const char *text = ASCII(xmlTextReaderValue(reader));
1614 icon->text = (const char *)__get_icon_with_path(text, uid);
1621 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1623 __save_xml_attribute(reader, "name", &image->name, NULL);
1624 __save_xml_attribute(reader, "section", &image->section, NULL);
1625 __save_xml_lang(reader, &image->lang);
1626 __save_xml_value(reader, &image->text);
1630 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1632 __save_xml_attribute(reader, "name", &label->name, NULL);
1633 __save_xml_lang(reader, &label->lang);
1634 __save_xml_value(reader, &label->text);
1639 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1641 __save_xml_attribute(reader, "email", &author->email, NULL);
1642 __save_xml_attribute(reader, "href", &author->href, NULL);
1643 __save_xml_lang(reader, &author->lang);
1644 __save_xml_value(reader, &author->text);
1648 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1650 __save_xml_lang(reader, &description->lang);
1651 __save_xml_value(reader, &description->text);
1655 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1657 __save_xml_lang(reader, &license->lang);
1658 __save_xml_value(reader, &license->text);
1662 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1664 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1665 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1666 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1670 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication, uid_t uid)
1672 const xmlChar *node;
1675 label_x *tmp1 = NULL;
1676 icon_x *tmp2 = NULL;
1677 appsvc_x *tmp3 = NULL;
1678 appcontrol_x *tmp4 = NULL;
1679 launchconditions_x *tmp5 = NULL;
1680 notification_x *tmp6 = NULL;
1681 datashare_x *tmp7 = NULL;
1682 category_x *tmp8 = NULL;
1683 metadata_x *tmp9 = NULL;
1684 image_x *tmp10 = NULL;
1685 permission_x *tmp11 = NULL;
1686 datacontrol_x *tmp12 = NULL;
1688 __save_xml_attribute(reader, "appid", &uiapplication->appid, NULL);
1689 retvm_if(uiapplication->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1690 __save_xml_attribute(reader, "exec", &uiapplication->exec, NULL);
1691 __save_xml_attribute(reader, "nodisplay", &uiapplication->nodisplay, "false");
1692 __save_xml_attribute(reader, "multiple", &uiapplication->multiple, "false");
1693 __save_xml_attribute(reader, "type", &uiapplication->type, NULL);
1694 __save_xml_attribute(reader, "categories", &uiapplication->categories, NULL);
1695 __save_xml_attribute(reader, "extraid", &uiapplication->extraid, NULL);
1696 __save_xml_attribute(reader, "taskmanage", &uiapplication->taskmanage, "true");
1697 __save_xml_attribute(reader, "enabled", &uiapplication->enabled, "true");
1698 __save_xml_attribute(reader, "hw-acceleration", &uiapplication->hwacceleration, "default");
1699 __save_xml_attribute(reader, "screen-reader", &uiapplication->screenreader, "use-system-setting");
1700 __save_xml_attribute(reader, "mainapp", &uiapplication->mainapp, "false");
1701 __save_xml_attribute(reader, "recentimage", &uiapplication->recentimage, "false");
1702 __save_xml_attribute(reader, "launchcondition", &uiapplication->launchcondition, "false");
1703 __save_xml_attribute(reader, "indicatordisplay", &uiapplication->indicatordisplay, "true");
1704 __save_xml_attribute(reader, "portrait-effectimage", &uiapplication->portraitimg, NULL);
1705 __save_xml_attribute(reader, "landscape-effectimage", &uiapplication->landscapeimg, NULL);
1706 __save_xml_attribute(reader, "guestmode-visibility", &uiapplication->guestmode_visibility, "true");
1707 __save_xml_attribute(reader, "permission-type", &uiapplication->permission_type, "normal");
1708 __save_xml_attribute(reader, "component-type", &uiapplication->component_type, "uiapp");
1709 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1710 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);
1711 __save_xml_attribute(reader, "submode", &uiapplication->submode, "false");
1712 __save_xml_attribute(reader, "submode-mainid", &uiapplication->submode_mainid, NULL);
1713 __save_xml_attribute(reader, "launch_mode", &uiapplication->launch_mode, "caller");
1715 uiapplication->package= strdup(package);
1717 depth = xmlTextReaderDepth(reader);
1718 while ((ret = __next_child_element(reader, depth))) {
1719 node = xmlTextReaderConstName(reader);
1721 _LOGD("xmlTextReaderConstName value is NULL\n");
1724 if (!strcmp(ASCII(node), "label")) {
1725 label_x *label = malloc(sizeof(label_x));
1726 if (label == NULL) {
1727 _LOGD("Malloc Failed\n");
1730 memset(label, '\0', sizeof(label_x));
1731 LISTADD(uiapplication->label, label);
1732 ret = __ps_process_label(reader, label);
1733 } else if (!strcmp(ASCII(node), "icon")) {
1734 icon_x *icon = malloc(sizeof(icon_x));
1736 _LOGD("Malloc Failed\n");
1739 memset(icon, '\0', sizeof(icon_x));
1740 LISTADD(uiapplication->icon, icon);
1741 ret = __ps_process_icon(reader, icon, uid);
1742 } else if (!strcmp(ASCII(node), "image")) {
1743 image_x *image = malloc(sizeof(image_x));
1744 if (image == NULL) {
1745 _LOGD("Malloc Failed\n");
1748 memset(image, '\0', sizeof(image_x));
1749 LISTADD(uiapplication->image, image);
1750 ret = __ps_process_image(reader, image);
1751 } else if (!strcmp(ASCII(node), "category")) {
1752 category_x *category = malloc(sizeof(category_x));
1753 if (category == NULL) {
1754 _LOGD("Malloc Failed\n");
1757 memset(category, '\0', sizeof(category_x));
1758 LISTADD(uiapplication->category, category);
1759 ret = __ps_process_category(reader, category);
1760 } else if (!strcmp(ASCII(node), "metadata")) {
1761 metadata_x *metadata = malloc(sizeof(metadata_x));
1762 if (metadata == NULL) {
1763 _LOGD("Malloc Failed\n");
1766 memset(metadata, '\0', sizeof(metadata_x));
1767 LISTADD(uiapplication->metadata, metadata);
1768 ret = __ps_process_metadata(reader, metadata);
1769 } else if (!strcmp(ASCII(node), "permission")) {
1770 permission_x *permission = malloc(sizeof(permission_x));
1771 if (permission == NULL) {
1772 _LOGD("Malloc Failed\n");
1775 memset(permission, '\0', sizeof(permission_x));
1776 LISTADD(uiapplication->permission, permission);
1777 ret = __ps_process_permission(reader, permission);
1778 } else if (!strcmp(ASCII(node), "app-control")) {
1779 appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
1780 if (appcontrol == NULL) {
1781 _LOGD("Malloc Failed\n");
1784 memset(appcontrol, '\0', sizeof(appcontrol_x));
1785 LISTADD(uiapplication->appcontrol, appcontrol);
1786 ret = __ps_process_appcontrol(reader, appcontrol);
1787 } else if (!strcmp(ASCII(node), "application-service")) {
1788 appsvc_x *appsvc = malloc(sizeof(appsvc_x));
1789 if (appsvc == NULL) {
1790 _LOGD("Malloc Failed\n");
1793 memset(appsvc, '\0', sizeof(appsvc_x));
1794 LISTADD(uiapplication->appsvc, appsvc);
1795 ret = __ps_process_appsvc(reader, appsvc);
1796 } else if (!strcmp(ASCII(node), "data-share")) {
1797 datashare_x *datashare = malloc(sizeof(datashare_x));
1798 if (datashare == NULL) {
1799 _LOGD("Malloc Failed\n");
1802 memset(datashare, '\0', sizeof(datashare_x));
1803 LISTADD(uiapplication->datashare, datashare);
1804 ret = __ps_process_datashare(reader, datashare);
1805 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1806 launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
1807 if (launchconditions == NULL) {
1808 _LOGD("Malloc Failed\n");
1811 memset(launchconditions, '\0', sizeof(launchconditions_x));
1812 LISTADD(uiapplication->launchconditions, launchconditions);
1813 ret = __ps_process_launchconditions(reader, launchconditions);
1814 } else if (!strcmp(ASCII(node), "notification")) {
1815 notification_x *notification = malloc(sizeof(notification_x));
1816 if (notification == NULL) {
1817 _LOGD("Malloc Failed\n");
1820 memset(notification, '\0', sizeof(notification_x));
1821 LISTADD(uiapplication->notification, notification);
1822 ret = __ps_process_notification(reader, notification);
1823 } else if (!strcmp(ASCII(node), "datacontrol")) {
1824 datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
1825 if (datacontrol == NULL) {
1826 _LOGD("Malloc Failed\n");
1829 memset(datacontrol, '\0', sizeof(datacontrol_x));
1830 LISTADD(uiapplication->datacontrol, datacontrol);
1831 ret = __ps_process_datacontrol(reader, datacontrol);
1835 _LOGD("Processing uiapplication failed\n");
1840 if (uiapplication->label) {
1841 LISTHEAD(uiapplication->label, tmp1);
1842 uiapplication->label = tmp1;
1844 if (uiapplication->icon) {
1845 LISTHEAD(uiapplication->icon, tmp2);
1846 uiapplication->icon = tmp2;
1848 if (uiapplication->appsvc) {
1849 LISTHEAD(uiapplication->appsvc, tmp3);
1850 uiapplication->appsvc = tmp3;
1852 if (uiapplication->appcontrol) {
1853 LISTHEAD(uiapplication->appcontrol, tmp4);
1854 uiapplication->appcontrol = tmp4;
1856 if (uiapplication->launchconditions) {
1857 LISTHEAD(uiapplication->launchconditions, tmp5);
1858 uiapplication->launchconditions = tmp5;
1860 if (uiapplication->notification) {
1861 LISTHEAD(uiapplication->notification, tmp6);
1862 uiapplication->notification = tmp6;
1864 if (uiapplication->datashare) {
1865 LISTHEAD(uiapplication->datashare, tmp7);
1866 uiapplication->datashare = tmp7;
1868 if (uiapplication->category) {
1869 LISTHEAD(uiapplication->category, tmp8);
1870 uiapplication->category = tmp8;
1872 if (uiapplication->metadata) {
1873 LISTHEAD(uiapplication->metadata, tmp9);
1874 uiapplication->metadata = tmp9;
1876 if (uiapplication->image) {
1877 LISTHEAD(uiapplication->image, tmp10);
1878 uiapplication->image = tmp10;
1880 if (uiapplication->permission) {
1881 LISTHEAD(uiapplication->permission, tmp11);
1882 uiapplication->permission = tmp11;
1884 if (uiapplication->datacontrol) {
1885 LISTHEAD(uiapplication->datacontrol, tmp12);
1886 uiapplication->datacontrol = tmp12;
1892 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication, uid_t uid)
1894 const xmlChar *node;
1897 label_x *tmp1 = NULL;
1898 icon_x *tmp2 = NULL;
1899 appsvc_x *tmp3 = NULL;
1900 appcontrol_x *tmp4 = NULL;
1901 datacontrol_x *tmp5 = NULL;
1902 launchconditions_x *tmp6 = NULL;
1903 notification_x *tmp7 = NULL;
1904 datashare_x *tmp8 = NULL;
1905 category_x *tmp9 = NULL;
1906 metadata_x *tmp10 = NULL;
1907 permission_x *tmp11 = NULL;
1909 __save_xml_attribute(reader, "appid", &serviceapplication->appid, NULL);
1910 retvm_if(serviceapplication->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1911 __save_xml_attribute(reader, "exec", &serviceapplication->exec, NULL);
1912 __save_xml_attribute(reader, "type", &serviceapplication->type, NULL);
1913 __save_xml_attribute(reader, "enabled", &serviceapplication->enabled, "true");
1914 __save_xml_attribute(reader, "permission-type", &serviceapplication->permission_type, "normal");
1915 __save_xml_attribute(reader, "auto-restart", &serviceapplication->autorestart, "false");
1916 __save_xml_attribute(reader, "on-boot", &serviceapplication->onboot, "false");
1918 serviceapplication->package= strdup(package);
1920 depth = xmlTextReaderDepth(reader);
1921 while ((ret = __next_child_element(reader, depth))) {
1922 node = xmlTextReaderConstName(reader);
1924 _LOGD("xmlTextReaderConstName value is NULL\n");
1928 if (!strcmp(ASCII(node), "label")) {
1929 label_x *label = malloc(sizeof(label_x));
1930 if (label == NULL) {
1931 _LOGD("Malloc Failed\n");
1934 memset(label, '\0', sizeof(label_x));
1935 LISTADD(serviceapplication->label, label);
1936 ret = __ps_process_label(reader, label);
1937 } else if (!strcmp(ASCII(node), "icon")) {
1938 icon_x *icon = malloc(sizeof(icon_x));
1940 _LOGD("Malloc Failed\n");
1943 memset(icon, '\0', sizeof(icon_x));
1944 LISTADD(serviceapplication->icon, icon);
1945 ret = __ps_process_icon(reader, icon, uid);
1946 } else if (!strcmp(ASCII(node), "category")) {
1947 category_x *category = malloc(sizeof(category_x));
1948 if (category == NULL) {
1949 _LOGD("Malloc Failed\n");
1952 memset(category, '\0', sizeof(category_x));
1953 LISTADD(serviceapplication->category, category);
1954 ret = __ps_process_category(reader, category);
1955 } else if (!strcmp(ASCII(node), "metadata")) {
1956 metadata_x *metadata = malloc(sizeof(metadata_x));
1957 if (metadata == NULL) {
1958 _LOGD("Malloc Failed\n");
1961 memset(metadata, '\0', sizeof(metadata_x));
1962 LISTADD(serviceapplication->metadata, metadata);
1963 ret = __ps_process_metadata(reader, metadata);
1964 } else if (!strcmp(ASCII(node), "permission")) {
1965 permission_x *permission = malloc(sizeof(permission_x));
1966 if (permission == NULL) {
1967 _LOGD("Malloc Failed\n");
1970 memset(permission, '\0', sizeof(permission_x));
1971 LISTADD(serviceapplication->permission, permission);
1972 ret = __ps_process_permission(reader, permission);
1973 } else if (!strcmp(ASCII(node), "app-control")) {
1974 appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
1975 if (appcontrol == NULL) {
1976 _LOGD("Malloc Failed\n");
1979 memset(appcontrol, '\0', sizeof(appcontrol_x));
1980 LISTADD(serviceapplication->appcontrol, appcontrol);
1981 ret = __ps_process_appcontrol(reader, appcontrol);
1982 } else if (!strcmp(ASCII(node), "application-service")) {
1983 appsvc_x *appsvc = malloc(sizeof(appsvc_x));
1984 if (appsvc == NULL) {
1985 _LOGD("Malloc Failed\n");
1988 memset(appsvc, '\0', sizeof(appsvc_x));
1989 LISTADD(serviceapplication->appsvc, appsvc);
1990 ret = __ps_process_appsvc(reader, appsvc);
1991 } else if (!strcmp(ASCII(node), "data-share")) {
1992 datashare_x *datashare = malloc(sizeof(datashare_x));
1993 if (datashare == NULL) {
1994 _LOGD("Malloc Failed\n");
1997 memset(datashare, '\0', sizeof(datashare_x));
1998 LISTADD(serviceapplication->datashare, datashare);
1999 ret = __ps_process_datashare(reader, datashare);
2000 } else if (!strcmp(ASCII(node), "launch-conditions")) {
2001 launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
2002 if (launchconditions == NULL) {
2003 _LOGD("Malloc Failed\n");
2006 memset(launchconditions, '\0', sizeof(launchconditions_x));
2007 LISTADD(serviceapplication->launchconditions, launchconditions);
2008 ret = __ps_process_launchconditions(reader, launchconditions);
2009 } else if (!strcmp(ASCII(node), "notification")) {
2010 notification_x *notification = malloc(sizeof(notification_x));
2011 if (notification == NULL) {
2012 _LOGD("Malloc Failed\n");
2015 memset(notification, '\0', sizeof(notification_x));
2016 LISTADD(serviceapplication->notification, notification);
2017 ret = __ps_process_notification(reader, notification);
2018 } else if (!strcmp(ASCII(node), "datacontrol")) {
2019 datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
2020 if (datacontrol == NULL) {
2021 _LOGD("Malloc Failed\n");
2024 memset(datacontrol, '\0', sizeof(datacontrol_x));
2025 LISTADD(serviceapplication->datacontrol, datacontrol);
2026 ret = __ps_process_datacontrol(reader, datacontrol);
2030 _LOGD("Processing serviceapplication failed\n");
2035 if (serviceapplication->label) {
2036 LISTHEAD(serviceapplication->label, tmp1);
2037 serviceapplication->label = tmp1;
2039 if (serviceapplication->icon) {
2040 LISTHEAD(serviceapplication->icon, tmp2);
2041 serviceapplication->icon = tmp2;
2043 if (serviceapplication->appsvc) {
2044 LISTHEAD(serviceapplication->appsvc, tmp3);
2045 serviceapplication->appsvc = tmp3;
2047 if (serviceapplication->appcontrol) {
2048 LISTHEAD(serviceapplication->appcontrol, tmp4);
2049 serviceapplication->appcontrol = tmp4;
2051 if (serviceapplication->datacontrol) {
2052 LISTHEAD(serviceapplication->datacontrol, tmp5);
2053 serviceapplication->datacontrol = tmp5;
2055 if (serviceapplication->launchconditions) {
2056 LISTHEAD(serviceapplication->launchconditions, tmp6);
2057 serviceapplication->launchconditions = tmp6;
2059 if (serviceapplication->notification) {
2060 LISTHEAD(serviceapplication->notification, tmp7);
2061 serviceapplication->notification = tmp7;
2063 if (serviceapplication->datashare) {
2064 LISTHEAD(serviceapplication->datashare, tmp8);
2065 serviceapplication->datashare = tmp8;
2067 if (serviceapplication->category) {
2068 LISTHEAD(serviceapplication->category, tmp9);
2069 serviceapplication->category = tmp9;
2071 if (serviceapplication->metadata) {
2072 LISTHEAD(serviceapplication->metadata, tmp10);
2073 serviceapplication->metadata = tmp10;
2075 if (serviceapplication->permission) {
2076 LISTHEAD(serviceapplication->permission, tmp11);
2077 serviceapplication->permission = tmp11;
2083 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile)
2085 /*TODO: once policy is set*/
2089 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font)
2091 /*TODO: once policy is set*/
2095 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme)
2097 /*TODO: once policy is set*/
2101 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon)
2103 /*TODO: once policy is set*/
2107 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
2109 /*TODO: once policy is set*/
2113 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
2115 _LOGD("__start_process\n");
2116 const xmlChar *node;
2119 label_x *tmp1 = NULL;
2120 author_x *tmp2 = NULL;
2121 description_x *tmp3 = NULL;
2122 license_x *tmp4 = NULL;
2123 uiapplication_x *tmp5 = NULL;
2124 serviceapplication_x *tmp6 = NULL;
2125 daemon_x *tmp7 = NULL;
2126 theme_x *tmp8 = NULL;
2127 font_x *tmp9 = NULL;
2128 ime_x *tmp10 = NULL;
2129 icon_x *tmp11 = NULL;
2130 compatibility_x *tmp12 = NULL;
2131 deviceprofile_x *tmp13 = NULL;
2132 privileges_x *tmp14 = NULL;
2134 depth = xmlTextReaderDepth(reader);
2135 while ((ret = __next_child_element(reader, depth))) {
2136 node = xmlTextReaderConstName(reader);
2138 _LOGD("xmlTextReaderConstName value is NULL\n");
2142 if (!strcmp(ASCII(node), "label")) {
2143 label_x *label = malloc(sizeof(label_x));
2144 if (label == NULL) {
2145 _LOGD("Malloc Failed\n");
2148 memset(label, '\0', sizeof(label_x));
2149 LISTADD(mfx->label, label);
2150 ret = __ps_process_label(reader, label);
2151 } else if (!strcmp(ASCII(node), "author")) {
2152 author_x *author = malloc(sizeof(author_x));
2153 if (author == NULL) {
2154 _LOGD("Malloc Failed\n");
2157 memset(author, '\0', sizeof(author_x));
2158 LISTADD(mfx->author, author);
2159 ret = __ps_process_author(reader, author);
2160 } else if (!strcmp(ASCII(node), "description")) {
2161 description_x *description = malloc(sizeof(description_x));
2162 if (description == NULL) {
2163 _LOGD("Malloc Failed\n");
2166 memset(description, '\0', sizeof(description_x));
2167 LISTADD(mfx->description, description);
2168 ret = __ps_process_description(reader, description);
2169 } else if (!strcmp(ASCII(node), "license")) {
2170 license_x *license = malloc(sizeof(license_x));
2171 if (license == NULL) {
2172 _LOGD("Malloc Failed\n");
2175 memset(license, '\0', sizeof(license_x));
2176 LISTADD(mfx->license, license);
2177 ret = __ps_process_license(reader, license);
2178 } else if (!strcmp(ASCII(node), "privileges")) {
2179 privileges_x *privileges = malloc(sizeof(privileges_x));
2180 if (privileges == NULL) {
2181 _LOGD("Malloc Failed\n");
2184 memset(privileges, '\0', sizeof(privileges_x));
2185 LISTADD(mfx->privileges, privileges);
2186 ret = __ps_process_privileges(reader, privileges);
2187 } else if (!strcmp(ASCII(node), "ui-application")) {
2188 uiapplication_x *uiapplication = malloc(sizeof(uiapplication_x));
2189 if (uiapplication == NULL) {
2190 _LOGD("Malloc Failed\n");
2193 memset(uiapplication, '\0', sizeof(uiapplication_x));
2194 LISTADD(mfx->uiapplication, uiapplication);
2195 ret = __ps_process_uiapplication(reader, uiapplication, uid);
2196 } else if (!strcmp(ASCII(node), "service-application")) {
2197 serviceapplication_x *serviceapplication = malloc(sizeof(serviceapplication_x));
2198 if (serviceapplication == NULL) {
2199 _LOGD("Malloc Failed\n");
2202 memset(serviceapplication, '\0', sizeof(serviceapplication_x));
2203 LISTADD(mfx->serviceapplication, serviceapplication);
2204 ret = __ps_process_serviceapplication(reader, serviceapplication, uid);
2205 } else if (!strcmp(ASCII(node), "daemon")) {
2206 daemon_x *daemon = malloc(sizeof(daemon_x));
2207 if (daemon == NULL) {
2208 _LOGD("Malloc Failed\n");
2211 memset(daemon, '\0', sizeof(daemon_x));
2212 LISTADD(mfx->daemon, daemon);
2213 ret = __ps_process_daemon(reader, daemon);
2214 } else if (!strcmp(ASCII(node), "theme")) {
2215 theme_x *theme = malloc(sizeof(theme_x));
2216 if (theme == NULL) {
2217 _LOGD("Malloc Failed\n");
2220 memset(theme, '\0', sizeof(theme_x));
2221 LISTADD(mfx->theme, theme);
2222 ret = __ps_process_theme(reader, theme);
2223 } else if (!strcmp(ASCII(node), "font")) {
2224 font_x *font = malloc(sizeof(font_x));
2226 _LOGD("Malloc Failed\n");
2229 memset(font, '\0', sizeof(font_x));
2230 LISTADD(mfx->font, font);
2231 ret = __ps_process_font(reader, font);
2232 } else if (!strcmp(ASCII(node), "ime")) {
2233 ime_x *ime = malloc(sizeof(ime_x));
2235 _LOGD("Malloc Failed\n");
2238 memset(ime, '\0', sizeof(ime_x));
2239 LISTADD(mfx->ime, ime);
2240 ret = __ps_process_ime(reader, ime);
2241 } else if (!strcmp(ASCII(node), "icon")) {
2242 icon_x *icon = malloc(sizeof(icon_x));
2244 _LOGD("Malloc Failed\n");
2247 memset(icon, '\0', sizeof(icon_x));
2248 LISTADD(mfx->icon, icon);
2249 ret = __ps_process_icon(reader, icon, uid);
2250 } else if (!strcmp(ASCII(node), "profile")) {
2251 deviceprofile_x *deviceprofile = malloc(sizeof(deviceprofile_x));
2252 if (deviceprofile == NULL) {
2253 _LOGD("Malloc Failed\n");
2256 memset(deviceprofile, '\0', sizeof(deviceprofile_x));
2257 LISTADD(mfx->deviceprofile, deviceprofile);
2258 ret = __ps_process_deviceprofile(reader, deviceprofile);
2259 } else if (!strcmp(ASCII(node), "compatibility")) {
2260 compatibility_x *compatibility = malloc(sizeof(compatibility_x));
2261 if (compatibility == NULL) {
2262 _LOGD("Malloc Failed\n");
2265 memset(compatibility, '\0', sizeof(compatibility_x));
2266 LISTADD(mfx->compatibility, compatibility);
2267 ret = __ps_process_compatibility(reader, compatibility);
2268 } else if (!strcmp(ASCII(node), "shortcut-list")) {
2270 } else if (!strcmp(ASCII(node), "livebox")) {
2272 } else if (!strcmp(ASCII(node), "account")) {
2274 } else if (!strcmp(ASCII(node), "notifications")) {
2276 } else if (!strcmp(ASCII(node), "ime")) {
2278 } else if (!strcmp(ASCII(node), "feature")) {
2281 _LOGE("Unknown element: %s", ASCII(node));
2286 _LOGD("Processing manifest failed\n");
2291 LISTHEAD(mfx->label, tmp1);
2295 LISTHEAD(mfx->author, tmp2);
2298 if (mfx->description) {
2299 LISTHEAD(mfx->description, tmp3);
2300 mfx->description= tmp3;
2303 LISTHEAD(mfx->license, tmp4);
2306 if (mfx->uiapplication) {
2307 LISTHEAD(mfx->uiapplication, tmp5);
2308 mfx->uiapplication = tmp5;
2310 if (mfx->serviceapplication) {
2311 LISTHEAD(mfx->serviceapplication, tmp6);
2312 mfx->serviceapplication = tmp6;
2315 LISTHEAD(mfx->daemon, tmp7);
2319 LISTHEAD(mfx->theme, tmp8);
2323 LISTHEAD(mfx->font, tmp9);
2327 LISTHEAD(mfx->ime, tmp10);
2331 LISTHEAD(mfx->icon, tmp11);
2334 if (mfx->compatibility) {
2335 LISTHEAD(mfx->compatibility, tmp12);
2336 mfx->compatibility= tmp12;
2338 if (mfx->deviceprofile) {
2339 LISTHEAD(mfx->deviceprofile, tmp13);
2340 mfx->deviceprofile= tmp13;
2342 if (mfx->privileges) {
2343 LISTHEAD(mfx->privileges, tmp14);
2344 mfx->privileges = tmp14;
2349 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
2351 const xmlChar *node;
2354 if ((ret = __next_child_element(reader, -1))) {
2355 node = xmlTextReaderConstName(reader);
2357 _LOGD("xmlTextReaderConstName value is NULL\n");
2361 if (!strcmp(ASCII(node), "manifest")) {
2362 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
2363 __save_xml_attribute(reader, "package", &mfx->package, NULL);
2364 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
2365 __save_xml_attribute(reader, "version", &mfx->version, NULL);
2366 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
2367 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
2368 __save_xml_attribute(reader, "type", &mfx->type, "rpm");
2369 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
2370 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
2371 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
2372 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
2373 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
2374 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
2375 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
2377 __save_xml_installed_time(mfx);
2378 __save_xml_root_path(mfx, uid);
2379 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
2380 __save_xml_default_value(mfx);
2382 ret = __start_process(reader, mfx, uid);
2384 _LOGD("No Manifest element found\n");
2391 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
2393 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
2395 void *lib_handle = NULL;
2396 int (*appsvc_operation) (const char *, uid_t);
2398 uiapplication_x *uiapplication = mfx->uiapplication;
2400 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
2401 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
2405 if ((appsvc_operation =
2406 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
2407 _LOGE("can not find symbol \n");
2411 for(; uiapplication; uiapplication=uiapplication->next) {
2412 ret = appsvc_operation(uiapplication->appid, uid);
2414 _LOGE("can not operation symbol \n");
2419 dlclose(lib_handle);
2424 #define PRELOAD_PACKAGE_LIST SYSCONFDIR "/package-manager/preload/preload_list.txt"
2425 static int __add_preload_info(manifest_x * mfx, const char *manifest, uid_t uid)
2428 char buffer[1024] = { 0 };
2431 if(strstr(manifest, getUserManifestPath(uid))) {
2432 free((void *)mfx->readonly);
2433 mfx->readonly = strdup("True");
2435 free((void *)mfx->preload);
2436 mfx->preload = strdup("True");
2438 free((void *)mfx->removable);
2439 mfx->removable = strdup("False");
2441 free((void *)mfx->system);
2442 mfx->system = strdup("True");
2447 fp = fopen(PRELOAD_PACKAGE_LIST, "r");
2449 _LOGE("no preload list\n");
2453 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
2454 if (buffer[0] == '#') {
2455 if(strcasestr(buffer, "RW_NORM"))
2457 else if(strcasestr(buffer, "RW_RM"))
2465 if(!strcmp(mfx->package, buffer)) {
2466 free((void *)mfx->preload);
2467 mfx->preload = strdup("True");
2469 free((void *)mfx->readonly);
2470 mfx->readonly = strdup("False");
2471 free((void *)mfx->removable);
2472 mfx->removable = strdup("False");
2473 } else if(state == 3){
2474 free((void *)mfx->readonly);
2475 mfx->readonly = strdup("False");
2476 free((void *)mfx->removable);
2477 mfx->removable = strdup("True");
2481 memset(buffer, 0x00, sizeof(buffer));
2490 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
2492 if (!strstr(manifest, getUserManifestPath(uid))) {
2493 /* if downloaded app is updated, then update tag set true*/
2495 free((void *)mfx->update);
2496 mfx->update = strdup("true");
2503 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
2505 /* desktop file is no longer used */
2509 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
2511 /* desktop file is no longer used */
2516 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
2518 pkgmgrinfo_basic_free_package((package_x *)mfx);
2521 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
2523 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
2524 xmlTextReaderPtr reader;
2525 manifest_x *mfx = NULL;
2527 reader = xmlReaderForFile(manifest, NULL, 0);
2529 mfx = malloc(sizeof(manifest_x));
2531 memset(mfx, '\0', sizeof(manifest_x));
2532 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
2533 _LOGD("Parsing Failed\n");
2534 pkgmgr_parser_free_manifest_xml(mfx);
2537 _LOGD("Parsing Success\n");
2539 _LOGD("Memory allocation error\n");
2541 xmlFreeTextReader(reader);
2543 _LOGD("Unable to create xml reader\n");
2549 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
2551 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
2552 xmlTextReaderPtr reader;
2553 manifest_x *mfx = NULL;
2555 reader = xmlReaderForFile(manifest, NULL, 0);
2557 mfx = malloc(sizeof(manifest_x));
2559 memset(mfx, '\0', sizeof(manifest_x));
2560 if (__process_manifest(reader, mfx, uid) < 0) {
2561 _LOGD("Parsing Failed\n");
2562 pkgmgr_parser_free_manifest_xml(mfx);
2565 _LOGD("Parsing Success\n");
2567 _LOGD("Memory allocation error\n");
2569 xmlFreeTextReader(reader);
2571 _LOGD("Unable to create xml reader\n");
2576 /* These APIs are intended to call parser directly */
2578 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2580 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2581 _LOGD("parsing manifest for installation: %s\n", manifest);
2583 manifest_x *mfx = NULL;
2587 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2588 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2590 _LOGD("Parsing Finished\n");
2592 __add_preload_info(mfx, manifest, GLOBAL_USER);
2594 _LOGD("Added preload infomation\n");
2596 __ps_process_tag(mfx, tagv);
2598 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2599 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2601 _LOGD("DB Insert Success\n");
2603 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2604 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2606 _LOGD("Creating metadata parser failed\n");
2608 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2610 _LOGD("Creating category parser failed\n");
2612 pkgmgr_parser_free_manifest_xml(mfx);
2613 _LOGD("Free Done\n");
2618 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2620 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2621 _LOGD("parsing manifest for installation: %s\n", manifest);
2622 manifest_x *mfx = NULL;
2626 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2627 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2629 _LOGD("Parsing Finished\n");
2631 __ps_process_tag(mfx, tagv);
2633 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2634 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2636 _LOGD("DB Insert Success\n");
2638 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2639 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2641 _LOGD("Creating metadata parser failed\n");
2642 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2644 _LOGD("Creating category parser failed\n");
2646 pkgmgr_parser_free_manifest_xml(mfx);
2647 _LOGD("Free Done\n");
2653 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2655 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2656 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2657 manifest_x *mfx = NULL;
2659 bool preload = false;
2660 bool system = false;
2661 char *csc_path = NULL;
2662 pkgmgrinfo_pkginfo_h handle = NULL;
2665 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2666 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2668 _LOGD("Parsing Finished\n");
2669 __add_preload_info(mfx, manifest, GLOBAL_USER);
2670 _LOGD("Added preload infomation\n");
2671 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2673 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2674 if (ret != PMINFO_R_OK)
2675 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2676 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2677 if (ret != PMINFO_R_OK)
2678 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2681 free((void *)mfx->preload);
2682 mfx->preload = strdup("true");
2685 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2686 if (ret != PMINFO_R_OK)
2687 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2689 free((void *)mfx->system);
2690 mfx->system = strdup("true");
2693 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2694 if (ret != PMINFO_R_OK)
2695 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2697 if (csc_path != NULL) {
2699 free((void *)mfx->csc_path);
2700 mfx->csc_path = strdup(csc_path);
2703 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2704 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2706 _LOGD("DB Update Success\n");
2708 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2709 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2711 _LOGD("Upgrade metadata parser failed\n");
2713 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2715 _LOGD("Creating category parser failed\n");
2716 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2717 pkgmgr_parser_free_manifest_xml(mfx);
2718 _LOGD("Free Done\n");
2724 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2726 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2727 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2728 manifest_x *mfx = NULL;
2730 bool preload = false;
2731 bool system = false;
2732 char *csc_path = NULL;
2733 pkgmgrinfo_pkginfo_h handle = NULL;
2736 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2737 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2739 _LOGD("Parsing Finished\n");
2740 __check_preload_updated(mfx, manifest, uid);
2742 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2743 if (ret != PMINFO_R_OK)
2744 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2745 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2746 if (ret != PMINFO_R_OK)
2747 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2750 free((void *)mfx->preload);
2751 mfx->preload = strdup("true");
2754 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2755 if (ret != PMINFO_R_OK)
2756 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2759 free((void *)mfx->system);
2760 mfx->system = strdup("true");
2763 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2764 if (ret != PMINFO_R_OK)
2765 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2766 if (csc_path != NULL) {
2768 free((void *)mfx->csc_path);
2769 mfx->csc_path = strdup(csc_path);
2772 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2773 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2774 _LOGD("DB Update Success\n");
2776 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2777 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2779 _LOGD("Upgrade metadata parser failed\n");
2780 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2782 _LOGD("Creating category parser failed\n");
2783 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2784 pkgmgr_parser_free_manifest_xml(mfx);
2785 _LOGD("Free Done\n");
2791 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2793 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2794 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2796 manifest_x *mfx = NULL;
2799 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2800 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2802 _LOGD("Parsing Finished\n");
2804 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2806 __add_preload_info(mfx, manifest, GLOBAL_USER);
2807 _LOGD("Added preload infomation\n");
2809 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2811 _LOGD("Removing metadata parser failed\n");
2813 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2815 _LOGD("Creating category parser failed\n");
2817 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2819 _LOGD("DB Delete failed\n");
2821 _LOGD("DB Delete Success\n");
2823 pkgmgr_parser_free_manifest_xml(mfx);
2824 _LOGD("Free Done\n");
2831 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2833 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2834 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2836 manifest_x *mfx = NULL;
2839 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2840 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2842 _LOGD("Parsing Finished\n");
2844 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2846 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2848 _LOGD("Removing metadata parser failed\n");
2850 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2852 _LOGD("Creating category parser failed\n");
2854 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2856 _LOGD("DB Delete failed\n");
2858 _LOGD("DB Delete Success\n");
2860 ret = __ps_remove_appsvc_db(mfx, uid);
2862 _LOGD("Removing appsvc_db failed\n");
2864 _LOGD("Removing appsvc_db Success\n");
2866 pkgmgr_parser_free_manifest_xml(mfx);
2867 _LOGD("Free Done\n");
2873 API int pkgmgr_parser_parse_manifest_for_preload()
2875 return pkgmgr_parser_update_preload_info_in_db();
2878 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
2880 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
2884 API char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid)
2886 return __pkgid_to_manifest(pkgid, uid);
2889 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
2891 return __pkgid_to_manifest(pkgid, GLOBAL_USER);
2894 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2896 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
2899 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2901 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
2904 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
2906 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
2909 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2911 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2913 if (manifest == NULL) {
2914 _LOGE("manifest file is NULL\n");
2915 return PMINFO_R_EINVAL;
2918 xmlSchemaParserCtxtPtr ctx;
2919 xmlSchemaValidCtxtPtr vctx;
2920 xmlSchemaPtr xschema;
2921 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2923 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2924 return PMINFO_R_ERROR;
2926 xschema = xmlSchemaParse(ctx);
2927 if (xschema == NULL) {
2928 _LOGE("xmlSchemaParse() Failed\n");
2929 return PMINFO_R_ERROR;
2931 vctx = xmlSchemaNewValidCtxt(xschema);
2933 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2934 return PMINFO_R_ERROR;
2936 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2937 ret = xmlSchemaValidateFile(vctx, manifest, 0);
2939 _LOGE("xmlSchemaValidateFile() failed\n");
2940 return PMINFO_R_ERROR;
2941 } else if (ret == 0) {
2942 _LOGE("Manifest is Valid\n");
2945 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2946 return PMINFO_R_ERROR;
2952 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2962 _LOGE("fork failed\n");
2967 int dev_null_fd = open ("/dev/null", O_RDWR);
2968 if (dev_null_fd >= 0)
2970 dup2 (dev_null_fd, 0);/*stdin*/
2971 dup2 (dev_null_fd, 1);/*stdout*/
2972 dup2 (dev_null_fd, 2);/*stderr*/
2975 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
2976 SCHEMA_FILE, NULL) < 0) {
2977 _LOGE("execl error\n");
2987 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
2991 _LOGE("waitpid failed\n");
2997 if(WIFEXITED(status) && !WEXITSTATUS(status))