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_parser.h"
39 #include "pkgmgr_parser_internal.h"
40 #include "pkgmgr_parser_db.h"
41 #include "pkgmgr-info.h"
42 #include "pkgmgr_parser_signature.h"
43 #include "pkgmgr-info-debug.h"
48 #define LOG_TAG "PKGMGR_PARSER"
50 #define ASCII(s) (const char *)s
51 #define XMLCHAR(s) (const xmlChar *)s
53 //#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/metadata_parser_list.txt"
54 #define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/mdparser_list.txt"
55 #define METADATA_PARSER_NAME "metadataparser:"
57 #define CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
58 #define CATEGORY_PARSER_NAME "categoryparser:"
60 #define TAG_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/tag_parser_list.txt"
61 #define TAG_PARSER_NAME "parserlib:"
63 #define PKG_TAG_LEN_MAX 128
66 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
77 /* plugin process_type */
79 PLUGIN_PRE_PROCESS = 0,
81 } PLUGIN_PROCESS_TYPE;
94 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label);
95 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege);
96 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges);
97 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile);
98 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed);
99 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation);
100 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri);
101 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime);
102 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp);
103 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition);
104 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
105 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category);
106 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
107 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
108 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
109 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request);
110 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
111 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc);
112 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions);
113 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
114 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
115 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
116 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
117 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
118 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol);
119 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
120 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication, uid_t uid);
121 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication, uid_t uid);
122 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font);
123 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme);
124 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon);
125 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime);
126 static void __ps_free_label(label_x *label);
127 static void __ps_free_privilege(privilege_x *privilege);
128 static void __ps_free_privileges(privileges_x *privileges);
129 static void __ps_free_deviceprofile(deviceprofile_x * deviceprofile);
130 static void __ps_free_allowed(allowed_x *allowed);
131 static void __ps_free_operation(operation_x *operation);
132 static void __ps_free_uri(uri_x *uri);
133 static void __ps_free_mime(mime_x *mime);
134 static void __ps_free_subapp(subapp_x *subapp);
135 static void __ps_free_condition(condition_x *condition);
136 static void __ps_free_notification(notification_x *notifiation);
137 static void __ps_free_category(category_x *category);
138 static void __ps_free_metadata(metadata_x *metadata);
139 static void __ps_free_permission(permission_x *permission);
140 static void __ps_free_compatibility(compatibility_x *compatibility);
141 static void __ps_free_request(request_x *request);
142 static void __ps_free_define(define_x *define);
143 static void __ps_free_appsvc(appsvc_x *appsvc);
144 static void __ps_free_launchconditions(launchconditions_x *launchconditions);
145 static void __ps_free_datashare(datashare_x *datashare);
146 static void __ps_free_icon(icon_x *icon);
147 static void __ps_free_author(author_x *author);
148 static void __ps_free_description(description_x *description);
149 static void __ps_free_license(license_x *license);
150 static void __ps_free_appcontrol(appcontrol_x *appcontrol);
151 static void __ps_free_datacontrol(datacontrol_x *datacontrol);
152 static void __ps_free_uiapplication(uiapplication_x *uiapplication);
153 static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication);
154 static void __ps_free_font(font_x *font);
155 static void __ps_free_theme(theme_x *theme);
156 static void __ps_free_daemon(daemon_x *daemon);
157 static void __ps_free_ime(ime_x *ime);
158 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid);
159 static int __next_child_element(xmlTextReaderPtr reader, int depth);
160 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
161 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
162 static void __str_trim(char *input);
163 static char *__get_parser_plugin(const char *type);
164 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
165 API int __is_admin();
167 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, const char **xml_attribute, char *default_value)
169 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
171 *xml_attribute = strdup((const char *)attrib_val);
174 if (default_value != NULL) {
175 *xml_attribute = strdup(default_value);
180 static void __save_xml_lang(xmlTextReaderPtr reader, const char **xml_attribute)
182 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
183 if (attrib_val != NULL)
184 *xml_attribute = strdup(ASCII(attrib_val));
186 *xml_attribute = strdup(DEFAULT_LOCALE);
189 static void __save_xml_value(xmlTextReaderPtr reader, const char **xml_attribute)
191 xmlTextReaderRead(reader);
192 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
195 *xml_attribute = strdup((const char *)attrib_val);
198 static void __save_xml_installed_time(manifest_x *mfx)
200 char buf[PKG_STRING_LEN_MAX] = {'\0'};
204 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
205 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
206 mfx->installed_time = val;
209 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
211 char root[PKG_STRING_LEN_MAX] = { '\0' };
217 tzplatform_set_user(uid);
218 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
219 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
221 mfx->root_path = strdup(root);
223 tzplatform_reset_user();
226 static void __save_xml_default_value(manifest_x * mfx)
228 mfx->preload = strdup("False");
229 mfx->removable = strdup("True");
230 mfx->readonly = strdup("False");
231 mfx->update = strdup("False");
232 mfx->system = strdup("False");
233 mfx->installed_storage= strdup("installed_internal");
234 package = mfx->package;
237 void *__open_lib_handle(char *tag)
239 char *lib_path = NULL;
240 void *lib_handle = NULL;
242 lib_path = __get_parser_plugin(tag);
243 retvm_if(!lib_path, NULL, "lib_path get fail");
245 lib_handle = dlopen(lib_path, RTLD_LAZY);
246 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
251 void __close_lib_handle(void *lib_handle)
256 static void __str_trim(char *input)
258 char *trim_str = input;
263 while (*input != 0) {
264 if (!isspace(*input)) {
277 uid_t uid = getuid();
278 if ((uid_t) 0 == uid )
286 static char * __get_tag_by_key(char *md_key)
290 if (md_key == NULL) {
291 _LOGD("md_key is NULL\n");
295 md_tag = strrchr(md_key, 47) + 1;
298 return strdup(md_tag);
301 static char *__get_metadata_parser_plugin(const char *type)
304 char buffer[1024] = { 0 };
305 char temp_path[1024] = { 0 };
309 _LOGE("invalid argument\n");
313 fp = fopen(PKG_PARSER_CONF_PATH, "r");
315 _LOGE("no matching metadata parser\n");
319 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
320 if (buffer[0] == '#')
325 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
326 path = path + strlen(METADATA_PARSER_NAME);
331 memset(buffer, 0x00, 1024);
338 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
342 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
344 return strdup(temp_path);
347 static char *__get_category_parser_plugin(const char *type)
350 char buffer[1024] = { 0 };
351 char temp_path[1024] = { 0 };
355 _LOGE("invalid argument\n");
359 fp = fopen(PKG_PARSER_CONF_PATH, "r");
361 _LOGE("no matching metadata parser\n");
365 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
366 if (buffer[0] == '#')
371 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
372 path = path + strlen(CATEGORY_PARSER_NAME);
377 memset(buffer, 0x00, 1024);
384 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
388 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
390 return strdup(temp_path);
393 static char *__get_parser_plugin(const char *type)
396 char buffer[1024] = { 0 };
397 char temp_path[1024] = { 0 };
401 _LOGE("invalid argument\n");
405 fp = fopen(PKG_PARSER_CONF_PATH, "r");
407 _LOGE("no matching backendlib\n");
411 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
412 if (buffer[0] == '#')
417 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
418 path = path + strlen(PKG_PARSERLIB);
422 memset(buffer, 0x00, 1024);
429 _LOGE("no matching backendlib\n");
433 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
435 return strdup(temp_path);
438 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
439 ACTION_TYPE action, const char *pkgid)
441 int (*plugin_install) (xmlDocPtr, const char *);
447 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
450 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
452 case ACTION_UNINSTALL:
453 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
459 if ((plugin_install =
460 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
461 _LOGE("can not find symbol[%s] \n", ac);
465 ret = plugin_install(docPtr, pkgid);
466 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
472 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
473 ACTION_TYPE action, const char *pkgid, const char *appid)
475 char *lib_path = NULL;
476 void *lib_handle = NULL;
477 int (*metadata_parser_plugin) (const char *, const char *, GList *);
483 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
486 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
488 case ACTION_UNINSTALL:
489 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
495 lib_path = __get_metadata_parser_plugin(tag);
497 _LOGE("get %s parser fail\n", tag);
501 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
502 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
506 if ((metadata_parser_plugin =
507 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
508 _LOGE("can not find symbol[%s] \n",ac);
512 ret = metadata_parser_plugin(pkgid, appid, md_list);
514 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
516 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
526 static int __ps_run_category_parser(GList *category_list, const char *tag,
527 ACTION_TYPE action, const char *pkgid, const char *appid)
529 char *lib_path = NULL;
530 void *lib_handle = NULL;
531 int (*category_parser_plugin) (const char *, const char *, GList *);
537 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
540 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
542 case ACTION_UNINSTALL:
543 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
549 lib_path = __get_category_parser_plugin(tag);
551 _LOGE("get %s parser fail\n", tag);
555 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
556 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
560 if ((category_parser_plugin =
561 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
562 _LOGE("can not find symbol[%s] \n",ac);
566 ret = category_parser_plugin(pkgid, appid, category_list);
568 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
570 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
580 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
581 ACTION_TYPE action, const char *pkgid)
583 char *lib_path = NULL;
584 void *lib_handle = NULL;
585 int (*plugin_install) (xmlDocPtr, const char *);
591 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
594 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
596 case ACTION_UNINSTALL:
597 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
603 lib_path = __get_parser_plugin(tag);
608 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
609 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
612 if ((plugin_install =
613 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
614 _LOGE("can not find symbol[%s] \n", ac);
618 ret = plugin_install(docPtr, pkgid);
620 _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
622 _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
632 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid)
638 _LOGE("pkgid is NULL");
642 size = strlen(getUserManifestPath(uid)) + strlen(pkgid) + 10;
643 manifest = malloc(size);
644 if (manifest == NULL) {
648 memset(manifest, '\0', size);
649 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
651 if (access(manifest, F_OK)) {
652 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
658 static void __metadata_parser_clear_dir_list(GList* dir_list)
661 __metadata_t* detail = NULL;
664 list = g_list_first(dir_list);
666 detail = (__metadata_t *)list->data;
669 free((void *)detail->key);
671 free((void *)detail->value);
674 list = g_list_next(list);
676 g_list_free(dir_list);
680 static void __category_parser_clear_dir_list(GList* dir_list)
683 __category_t* detail = NULL;
686 list = g_list_first(dir_list);
688 detail = (__category_t *)list->data;
691 free((void *)detail->name);
695 list = g_list_next(list);
697 g_list_free(dir_list);
701 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
706 if (xmlTextReaderDepth(reader) != 1) {
707 _LOGE("Node depth is not 1");
711 if (xmlTextReaderNodeType(reader) != 1) {
712 _LOGE("Node type is not 1");
716 const xmlChar *value;
717 name = xmlTextReaderConstName(reader);
719 _LOGE("TEST TEST TES\n");
720 name = BAD_CAST "--";
723 value = xmlTextReaderConstValue(reader);
725 if (xmlStrlen(value) > 40) {
726 _LOGD(" %.40s...", value);
732 name = xmlTextReaderConstName(reader);
734 _LOGE("TEST TEST TES\n");
735 name = BAD_CAST "--";
738 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
739 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
740 if (copyDocPtr == NULL)
742 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
743 if (rootElement == NULL)
745 xmlNode *cur_node = xmlFirstElementChild(rootElement);
746 if (cur_node == NULL)
748 xmlNode *temp = xmlTextReaderExpand(reader);
751 xmlNode *next_node = NULL;
752 while(cur_node != NULL) {
753 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
754 (temp->line == cur_node->line) ) {
758 next_node = xmlNextElementSibling(cur_node);
759 xmlUnlinkNode(cur_node);
760 xmlFreeNode(cur_node);
761 cur_node = next_node;
764 if (cur_node == NULL)
766 next_node = xmlNextElementSibling(cur_node);
768 cur_node->next = NULL;
769 next_node->prev = NULL;
770 xmlFreeNodeList(next_node);
771 xmlSetTreeDoc(cur_node, copyDocPtr);
773 xmlSetTreeDoc(cur_node, copyDocPtr);
776 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
782 static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
786 char buffer[1024] = { 0, };
787 uiapplication_x *up = mfx->uiapplication;
788 metadata_x *md = NULL;
791 GList *md_list = NULL;
792 __metadata_t *md_detail = NULL;
794 md_tag = __get_tag_by_key(md_key);
795 if (md_tag == NULL) {
796 _LOGD("md_tag is NULL\n");
803 //get glist of metadata key and value combination
804 memset(buffer, 0x00, 1024);
805 snprintf(buffer, 1024, "%s/", md_key);
806 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
807 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
808 if (md_detail == NULL) {
809 _LOGD("Memory allocation failed\n");
813 md_detail->key = strdup(md->key);
814 if (md_detail->key == NULL) {
815 _LOGD("Memory allocation failed\n");
820 md_detail->value = strdup(md->value);
821 if (md_detail->value == NULL) {
822 _LOGD("Memory allocation failed\n");
823 free((void *)md_detail->key);
828 md_list = g_list_append(md_list, (gpointer)md_detail);
834 //send glist to parser when tags for metadata plugin parser exist.
836 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, up->appid);
838 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
841 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
844 __metadata_parser_clear_dir_list(md_list);
852 __metadata_parser_clear_dir_list(md_list);
860 static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
864 char buffer[1024] = { 0, };
865 uiapplication_x *up = mfx->uiapplication;
866 category_x *category = NULL;
867 char *category_tag = NULL;
869 GList *category_list = NULL;
870 __category_t *category_detail = NULL;
872 category_tag = __get_tag_by_key(category_key);
873 if (category_tag == NULL) {
874 _LOGD("md_tag is NULL\n");
879 category = up->category;
880 while (category != NULL) {
881 //get glist of category key and value combination
882 memset(buffer, 0x00, 1024);
883 snprintf(buffer, 1024, "%s/", category_key);
884 if ((category->name) && (strncmp(category->name, category_key, strlen(category_key)) == 0)) {
885 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
886 if (category_detail == NULL) {
887 _LOGD("Memory allocation failed\n");
891 category_detail->name = strdup(category->name);
892 if (category_detail->name == NULL) {
893 _LOGD("Memory allocation failed\n");
894 free(category_detail);
898 category_list = g_list_append(category_list, (gpointer)category_detail);
901 category = category->next;
904 //send glist to parser when tags for metadata plugin parser exist.
906 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, up->appid);
908 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
910 _LOGD("category_parser success for tag[%s]\n", category_tag);
912 __category_parser_clear_dir_list(category_list);
913 category_list = NULL;
920 __category_parser_clear_dir_list(category_list);
928 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
930 switch (xmlTextReaderNodeType(reader)) {
931 case XML_READER_TYPE_END_ELEMENT:
935 case XML_READER_TYPE_ELEMENT:
937 // Elements without closing tag don't receive
938 const xmlChar *elementName =
939 xmlTextReaderLocalName(reader);
940 if (elementName == NULL) {
944 if (strcmp(tag, ASCII(elementName)) == 0) {
945 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
946 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
957 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
959 int (*plugin_install) (const char *);
963 if (process == PLUGIN_PRE_PROCESS) {
966 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
969 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
971 case ACTION_UNINSTALL:
972 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
977 } else if (process == PLUGIN_POST_PROCESS) {
980 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
983 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
985 case ACTION_UNINSTALL:
986 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
994 if ((plugin_install =
995 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
999 ret = plugin_install(pkgid);
1003 static int __next_child_element(xmlTextReaderPtr reader, int depth)
1005 int ret = xmlTextReaderRead(reader);
1006 int cur = xmlTextReaderDepth(reader);
1009 switch (xmlTextReaderNodeType(reader)) {
1010 case XML_READER_TYPE_ELEMENT:
1011 if (cur == depth + 1)
1014 case XML_READER_TYPE_TEXT:
1015 /*text is handled by each function separately*/
1016 if (cur == depth + 1)
1019 case XML_READER_TYPE_END_ELEMENT:
1028 ret = xmlTextReaderRead(reader);
1029 cur = xmlTextReaderDepth(reader);
1034 static void __ps_free_category(category_x *category)
1036 if (category == NULL)
1038 if (category->name) {
1039 free((void *)category->name);
1040 category->name = NULL;
1042 free((void*)category);
1046 static void __ps_free_privilege(privilege_x *privilege)
1048 if (privilege == NULL)
1050 if (privilege->text) {
1051 free((void *)privilege->text);
1052 privilege->text = NULL;
1054 free((void*)privilege);
1058 static void __ps_free_privileges(privileges_x *privileges)
1060 if (privileges == NULL)
1063 if (privileges->privilege) {
1064 privilege_x *privilege = privileges->privilege;
1065 privilege_x *tmp = NULL;
1066 while(privilege != NULL) {
1067 tmp = privilege->next;
1068 __ps_free_privilege(privilege);
1072 free((void*)privileges);
1076 static void __ps_free_metadata(metadata_x *metadata)
1078 if (metadata == NULL)
1080 if (metadata->key) {
1081 free((void *)metadata->key);
1082 metadata->key = NULL;
1084 if (metadata->value) {
1085 free((void *)metadata->value);
1086 metadata->value = NULL;
1088 free((void*)metadata);
1092 static void __ps_free_permission(permission_x *permission)
1094 if (permission == NULL)
1096 if (permission->type) {
1097 free((void *)permission->type);
1098 permission->type = NULL;
1100 if (permission->value) {
1101 free((void *)permission->value);
1102 permission->value = NULL;
1104 free((void*)permission);
1108 static void __ps_free_icon(icon_x *icon)
1113 free((void *)icon->text);
1117 free((void *)icon->lang);
1121 free((void *)icon->name);
1124 if (icon->section) {
1125 free((void *)icon->section);
1126 icon->section = NULL;
1129 free((void *)icon->size);
1132 if (icon->resolution) {
1133 free((void *)icon->resolution);
1134 icon->resolution = NULL;
1140 static void __ps_free_image(image_x *image)
1145 free((void *)image->text);
1149 free((void *)image->lang);
1153 free((void *)image->name);
1156 if (image->section) {
1157 free((void *)image->section);
1158 image->section = NULL;
1164 static void __ps_free_operation(operation_x *operation)
1166 if (operation == NULL)
1168 if (operation->text) {
1169 free((void *)operation->text);
1170 operation->text = NULL;
1172 free((void*)operation);
1176 static void __ps_free_uri(uri_x *uri)
1181 free((void *)uri->text);
1188 static void __ps_free_mime(mime_x *mime)
1193 free((void *)mime->text);
1200 static void __ps_free_subapp(subapp_x *subapp)
1205 free((void *)subapp->text);
1206 subapp->text = NULL;
1208 free((void*)subapp);
1212 static void __ps_free_condition(condition_x *condition)
1214 if (condition == NULL)
1216 if (condition->text) {
1217 free((void *)condition->text);
1218 condition->text = NULL;
1220 if (condition->name) {
1221 free((void *)condition->name);
1222 condition->name = NULL;
1224 free((void*)condition);
1228 static void __ps_free_notification(notification_x *notification)
1230 if (notification == NULL)
1232 if (notification->text) {
1233 free((void *)notification->text);
1234 notification->text = NULL;
1236 if (notification->name) {
1237 free((void *)notification->name);
1238 notification->name = NULL;
1240 free((void*)notification);
1241 notification = NULL;
1244 static void __ps_free_compatibility(compatibility_x *compatibility)
1246 if (compatibility == NULL)
1248 if (compatibility->text) {
1249 free((void *)compatibility->text);
1250 compatibility->text = NULL;
1252 if (compatibility->name) {
1253 free((void *)compatibility->name);
1254 compatibility->name = NULL;
1256 free((void*)compatibility);
1257 compatibility = NULL;
1260 static void __ps_free_allowed(allowed_x *allowed)
1262 if (allowed == NULL)
1264 if (allowed->name) {
1265 free((void *)allowed->name);
1266 allowed->name = NULL;
1268 if (allowed->text) {
1269 free((void *)allowed->text);
1270 allowed->text = NULL;
1272 free((void*)allowed);
1276 static void __ps_free_request(request_x *request)
1278 if (request == NULL)
1280 if (request->text) {
1281 free((void *)request->text);
1282 request->text = NULL;
1284 free((void*)request);
1288 static void __ps_free_datacontrol(datacontrol_x *datacontrol)
1290 if (datacontrol == NULL)
1292 if (datacontrol->providerid) {
1293 free((void *)datacontrol->providerid);
1294 datacontrol->providerid = NULL;
1296 if (datacontrol->access) {
1297 free((void *)datacontrol->access);
1298 datacontrol->access = NULL;
1300 if (datacontrol->type) {
1301 free((void *)datacontrol->type);
1302 datacontrol->type = NULL;
1304 free((void*)datacontrol);
1308 static void __ps_free_launchconditions(launchconditions_x *launchconditions)
1310 if (launchconditions == NULL)
1312 if (launchconditions->text) {
1313 free((void *)launchconditions->text);
1314 launchconditions->text = NULL;
1317 if (launchconditions->condition) {
1318 condition_x *condition = launchconditions->condition;
1319 condition_x *tmp = NULL;
1320 while(condition != NULL) {
1321 tmp = condition->next;
1322 __ps_free_condition(condition);
1326 free((void*)launchconditions);
1327 launchconditions = NULL;
1330 static void __ps_free_appcontrol(appcontrol_x *appcontrol)
1332 if (appcontrol == NULL)
1335 if (appcontrol->operation)
1336 free((void *)appcontrol->operation);
1338 if (appcontrol->uri)
1339 free((void *)appcontrol->uri);
1341 if (appcontrol->mime)
1342 free((void *)appcontrol->mime);
1343 free((void*)appcontrol);
1347 static void __ps_free_appsvc(appsvc_x *appsvc)
1352 free((void *)appsvc->text);
1353 appsvc->text = NULL;
1356 if (appsvc->operation) {
1357 operation_x *operation = appsvc->operation;
1358 operation_x *tmp = NULL;
1359 while(operation != NULL) {
1360 tmp = operation->next;
1361 __ps_free_operation(operation);
1367 uri_x *uri = appsvc->uri;
1369 while(uri != NULL) {
1377 mime_x *mime = appsvc->mime;
1379 while(mime != NULL) {
1381 __ps_free_mime(mime);
1386 if (appsvc->subapp) {
1387 subapp_x *subapp = appsvc->subapp;
1388 subapp_x *tmp = NULL;
1389 while(subapp != NULL) {
1391 __ps_free_subapp(subapp);
1395 free((void*)appsvc);
1399 static void __ps_free_deviceprofile(deviceprofile_x *deviceprofile)
1404 static void __ps_free_define(define_x *define)
1409 free((void *)define->path);
1410 define->path = NULL;
1413 if (define->request) {
1414 request_x *request = define->request;
1415 request_x *tmp = NULL;
1416 while(request != NULL) {
1417 tmp = request->next;
1418 __ps_free_request(request);
1423 if (define->allowed) {
1424 allowed_x *allowed = define->allowed;
1425 allowed_x *tmp = NULL;
1426 while(allowed != NULL) {
1427 tmp = allowed->next;
1428 __ps_free_allowed(allowed);
1432 free((void*)define);
1436 static void __ps_free_datashare(datashare_x *datashare)
1438 if (datashare == NULL)
1441 if (datashare->define) {
1442 define_x *define = datashare->define;
1443 define_x *tmp = NULL;
1444 while(define != NULL) {
1446 __ps_free_define(define);
1451 if (datashare->request) {
1452 request_x *request = datashare->request;
1453 request_x *tmp = NULL;
1454 while(request != NULL) {
1455 tmp = request->next;
1456 __ps_free_request(request);
1460 free((void*)datashare);
1464 static void __ps_free_label(label_x *label)
1469 free((void *)label->name);
1473 free((void *)label->text);
1477 free((void *)label->lang);
1484 static void __ps_free_author(author_x *author)
1488 if (author->email) {
1489 free((void *)author->email);
1490 author->email = NULL;
1493 free((void *)author->text);
1494 author->text = NULL;
1497 free((void *)author->href);
1498 author->href = NULL;
1501 free((void *)author->lang);
1502 author->lang = NULL;
1504 free((void*)author);
1508 static void __ps_free_description(description_x *description)
1510 if (description == NULL)
1512 if (description->name) {
1513 free((void *)description->name);
1514 description->name = NULL;
1516 if (description->text) {
1517 free((void *)description->text);
1518 description->text = NULL;
1520 if (description->lang) {
1521 free((void *)description->lang);
1522 description->lang = NULL;
1524 free((void*)description);
1528 static void __ps_free_license(license_x *license)
1530 if (license == NULL)
1532 if (license->text) {
1533 free((void *)license->text);
1534 license->text = NULL;
1536 if (license->lang) {
1537 free((void *)license->lang);
1538 license->lang = NULL;
1540 free((void*)license);
1544 static void __ps_free_uiapplication(uiapplication_x *uiapplication)
1546 if (uiapplication == NULL)
1548 if (uiapplication->exec) {
1549 free((void *)uiapplication->exec);
1550 uiapplication->exec = NULL;
1552 if (uiapplication->appid) {
1553 free((void *)uiapplication->appid);
1554 uiapplication->appid = NULL;
1556 if (uiapplication->nodisplay) {
1557 free((void *)uiapplication->nodisplay);
1558 uiapplication->nodisplay = NULL;
1560 if (uiapplication->multiple) {
1561 free((void *)uiapplication->multiple);
1562 uiapplication->multiple = NULL;
1564 if (uiapplication->type) {
1565 free((void *)uiapplication->type);
1566 uiapplication->type = NULL;
1568 if (uiapplication->categories) {
1569 free((void *)uiapplication->categories);
1570 uiapplication->categories = NULL;
1572 if (uiapplication->extraid) {
1573 free((void *)uiapplication->extraid);
1574 uiapplication->extraid = NULL;
1576 if (uiapplication->taskmanage) {
1577 free((void *)uiapplication->taskmanage);
1578 uiapplication->taskmanage = NULL;
1580 if (uiapplication->enabled) {
1581 free((void *)uiapplication->enabled);
1582 uiapplication->enabled = NULL;
1584 if (uiapplication->hwacceleration) {
1585 free((void *)uiapplication->hwacceleration);
1586 uiapplication->hwacceleration = NULL;
1588 if (uiapplication->screenreader) {
1589 free((void *)uiapplication->screenreader);
1590 uiapplication->screenreader = NULL;
1592 if (uiapplication->mainapp) {
1593 free((void *)uiapplication->mainapp);
1594 uiapplication->mainapp = NULL;
1596 if (uiapplication->recentimage) {
1597 free((void *)uiapplication->recentimage);
1598 uiapplication->recentimage = NULL;
1600 if (uiapplication->package) {
1601 free((void *)uiapplication->package);
1602 uiapplication->package = NULL;
1604 if (uiapplication->launchcondition) {
1605 free((void *)uiapplication->launchcondition);
1606 uiapplication->launchcondition = NULL;
1609 if (uiapplication->label) {
1610 label_x *label = uiapplication->label;
1611 label_x *tmp = NULL;
1612 while(label != NULL) {
1614 __ps_free_label(label);
1619 if (uiapplication->icon) {
1620 icon_x *icon = uiapplication->icon;
1622 while(icon != NULL) {
1624 __ps_free_icon(icon);
1629 if (uiapplication->image) {
1630 image_x *image = uiapplication->image;
1631 image_x *tmp = NULL;
1632 while(image != NULL) {
1634 __ps_free_image(image);
1639 if (uiapplication->appcontrol) {
1640 appcontrol_x *appcontrol = uiapplication->appcontrol;
1641 appcontrol_x *tmp = NULL;
1642 while(appcontrol != NULL) {
1643 tmp = appcontrol->next;
1644 __ps_free_appcontrol(appcontrol);
1648 /*Free LaunchConditions*/
1649 if (uiapplication->launchconditions) {
1650 launchconditions_x *launchconditions = uiapplication->launchconditions;
1651 launchconditions_x *tmp = NULL;
1652 while(launchconditions != NULL) {
1653 tmp = launchconditions->next;
1654 __ps_free_launchconditions(launchconditions);
1655 launchconditions = tmp;
1658 /*Free Notification*/
1659 if (uiapplication->notification) {
1660 notification_x *notification = uiapplication->notification;
1661 notification_x *tmp = NULL;
1662 while(notification != NULL) {
1663 tmp = notification->next;
1664 __ps_free_notification(notification);
1669 if (uiapplication->datashare) {
1670 datashare_x *datashare = uiapplication->datashare;
1671 datashare_x *tmp = NULL;
1672 while(datashare != NULL) {
1673 tmp = datashare->next;
1674 __ps_free_datashare(datashare);
1679 if (uiapplication->appsvc) {
1680 appsvc_x *appsvc = uiapplication->appsvc;
1681 appsvc_x *tmp = NULL;
1682 while(appsvc != NULL) {
1684 __ps_free_appsvc(appsvc);
1689 if (uiapplication->category) {
1690 category_x *category = uiapplication->category;
1691 category_x *tmp = NULL;
1692 while(category != NULL) {
1693 tmp = category->next;
1694 __ps_free_category(category);
1699 if (uiapplication->metadata) {
1700 metadata_x *metadata = uiapplication->metadata;
1701 metadata_x *tmp = NULL;
1702 while(metadata != NULL) {
1703 tmp = metadata->next;
1704 __ps_free_metadata(metadata);
1709 if (uiapplication->permission) {
1710 permission_x *permission = uiapplication->permission;
1711 permission_x *tmp = NULL;
1712 while(permission != NULL) {
1713 tmp = permission->next;
1714 __ps_free_permission(permission);
1718 /*Free DataControl*/
1719 if (uiapplication->datacontrol) {
1720 datacontrol_x *datacontrol = uiapplication->datacontrol;
1721 datacontrol_x *tmp = NULL;
1722 while(datacontrol != NULL) {
1723 tmp = datacontrol->next;
1724 __ps_free_datacontrol(datacontrol);
1728 /* _PRODUCT_LAUNCHING_ENHANCED_ START */
1729 if (uiapplication->indicatordisplay) {
1730 free((void *)uiapplication->indicatordisplay);
1731 uiapplication->indicatordisplay = NULL;
1733 if (uiapplication->portraitimg) {
1734 free((void *)uiapplication->portraitimg);
1735 uiapplication->portraitimg = NULL;
1737 if (uiapplication->landscapeimg) {
1738 free((void *)uiapplication->landscapeimg);
1739 uiapplication->landscapeimg = NULL;
1741 /* _PRODUCT_LAUNCHING_ENHANCED_ END */
1742 if (uiapplication->guestmode_visibility) {
1743 free((void *)uiapplication->guestmode_visibility);
1744 uiapplication->guestmode_visibility = NULL;
1746 if (uiapplication->app_component) {
1747 free((void *)uiapplication->app_component);
1748 uiapplication->app_component = NULL;
1750 if (uiapplication->permission_type) {
1751 free((void *)uiapplication->permission_type);
1752 uiapplication->permission_type = NULL;
1754 if (uiapplication->component_type) {
1755 free((void *)uiapplication->component_type);
1756 uiapplication->component_type = NULL;
1758 if (uiapplication->preload) {
1759 free((void *)uiapplication->preload);
1760 uiapplication->preload = NULL;
1762 if (uiapplication->submode) {
1763 free((void *)uiapplication->submode);
1764 uiapplication->submode = NULL;
1766 if (uiapplication->submode_mainid) {
1767 free((void *)uiapplication->submode_mainid);
1768 uiapplication->submode_mainid = NULL;
1771 free((void*)uiapplication);
1772 uiapplication = NULL;
1775 static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication)
1777 if (serviceapplication == NULL)
1779 if (serviceapplication->exec) {
1780 free((void *)serviceapplication->exec);
1781 serviceapplication->exec = NULL;
1783 if (serviceapplication->appid) {
1784 free((void *)serviceapplication->appid);
1785 serviceapplication->appid = NULL;
1787 if (serviceapplication->onboot) {
1788 free((void *)serviceapplication->onboot);
1789 serviceapplication->onboot = NULL;
1791 if (serviceapplication->autorestart) {
1792 free((void *)serviceapplication->autorestart);
1793 serviceapplication->autorestart = NULL;
1795 if (serviceapplication->type) {
1796 free((void *)serviceapplication->type);
1797 serviceapplication->type = NULL;
1799 if (serviceapplication->enabled) {
1800 free((void *)serviceapplication->enabled);
1801 serviceapplication->enabled = NULL;
1803 if (serviceapplication->package) {
1804 free((void *)serviceapplication->package);
1805 serviceapplication->package = NULL;
1807 if (serviceapplication->permission_type) {
1808 free((void *)serviceapplication->permission_type);
1809 serviceapplication->permission_type = NULL;
1812 if (serviceapplication->label) {
1813 label_x *label = serviceapplication->label;
1814 label_x *tmp = NULL;
1815 while(label != NULL) {
1817 __ps_free_label(label);
1822 if (serviceapplication->icon) {
1823 icon_x *icon = serviceapplication->icon;
1825 while(icon != NULL) {
1827 __ps_free_icon(icon);
1832 if (serviceapplication->appcontrol) {
1833 appcontrol_x *appcontrol = serviceapplication->appcontrol;
1834 appcontrol_x *tmp = NULL;
1835 while(appcontrol != NULL) {
1836 tmp = appcontrol->next;
1837 __ps_free_appcontrol(appcontrol);
1841 /*Free DataControl*/
1842 if (serviceapplication->datacontrol) {
1843 datacontrol_x *datacontrol = serviceapplication->datacontrol;
1844 datacontrol_x *tmp = NULL;
1845 while(datacontrol != NULL) {
1846 tmp = datacontrol->next;
1847 __ps_free_datacontrol(datacontrol);
1851 /*Free LaunchConditions*/
1852 if (serviceapplication->launchconditions) {
1853 launchconditions_x *launchconditions = serviceapplication->launchconditions;
1854 launchconditions_x *tmp = NULL;
1855 while(launchconditions != NULL) {
1856 tmp = launchconditions->next;
1857 __ps_free_launchconditions(launchconditions);
1858 launchconditions = tmp;
1861 /*Free Notification*/
1862 if (serviceapplication->notification) {
1863 notification_x *notification = serviceapplication->notification;
1864 notification_x *tmp = NULL;
1865 while(notification != NULL) {
1866 tmp = notification->next;
1867 __ps_free_notification(notification);
1872 if (serviceapplication->datashare) {
1873 datashare_x *datashare = serviceapplication->datashare;
1874 datashare_x *tmp = NULL;
1875 while(datashare != NULL) {
1876 tmp = datashare->next;
1877 __ps_free_datashare(datashare);
1882 if (serviceapplication->appsvc) {
1883 appsvc_x *appsvc = serviceapplication->appsvc;
1884 appsvc_x *tmp = NULL;
1885 while(appsvc != NULL) {
1887 __ps_free_appsvc(appsvc);
1892 if (serviceapplication->category) {
1893 category_x *category = serviceapplication->category;
1894 category_x *tmp = NULL;
1895 while(category != NULL) {
1896 tmp = category->next;
1897 __ps_free_category(category);
1902 if (serviceapplication->metadata) {
1903 metadata_x *metadata = serviceapplication->metadata;
1904 metadata_x *tmp = NULL;
1905 while(metadata != NULL) {
1906 tmp = metadata->next;
1907 __ps_free_metadata(metadata);
1912 if (serviceapplication->permission) {
1913 permission_x *permission = serviceapplication->permission;
1914 permission_x *tmp = NULL;
1915 while(permission != NULL) {
1916 tmp = permission->next;
1917 __ps_free_permission(permission);
1921 free((void*)serviceapplication);
1922 serviceapplication = NULL;
1925 static void __ps_free_font(font_x *font)
1930 free((void *)font->name);
1934 free((void *)font->text);
1941 static void __ps_free_theme(theme_x *theme)
1946 free((void *)theme->name);
1950 free((void *)theme->text);
1957 static void __ps_free_daemon(daemon_x *daemon)
1962 free((void *)daemon->name);
1963 daemon->name = NULL;
1966 free((void *)daemon->text);
1967 daemon->text = NULL;
1969 free((void*)daemon);
1973 static void __ps_free_ime(ime_x *ime)
1978 free((void *)ime->name);
1982 free((void *)ime->text);
1989 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1991 xmlTextReaderPtr reader;
1995 void *lib_handle = NULL;
1996 char tag[PKG_STRING_LEN_MAX] = { 0 };
1998 fp = fopen(TAG_PARSER_LIST, "r");
1999 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
2001 while (fgets(tag, sizeof(tag), fp) != NULL) {
2004 lib_handle = __open_lib_handle(tag);
2005 if (lib_handle == NULL)
2008 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
2009 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
2011 docPtr = xmlReadFile(filename, NULL, 0);
2012 reader = xmlReaderWalker(docPtr);
2013 if (reader != NULL) {
2014 ret = xmlTextReaderRead(reader);
2016 __process_tag(lib_handle, reader, action, tag, mfx->package);
2017 ret = xmlTextReaderRead(reader);
2019 xmlFreeTextReader(reader);
2022 _LOGD("%s : failed to parse", filename);
2025 _LOGD("Unable to open %s", filename);
2028 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
2029 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
2031 __close_lib_handle(lib_handle);
2033 memset(tag, 0x00, sizeof(tag));
2042 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
2044 fprintf(stdout,"__ps_process_metadata_parser\n");
2047 char md_key[PKG_STRING_LEN_MAX] = { 0 };
2049 fp = fopen(METADATA_PARSER_LIST, "r");
2051 _LOGD("no preload list\n");
2055 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
2057 ret = __run_metadata_parser_prestep(mfx, md_key, action);
2068 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
2072 char category_key[PKG_STRING_LEN_MAX] = { 0 };
2074 fp = fopen(CATEGORY_PARSER_LIST, "r");
2076 _LOGD("no category parser list\n");
2080 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
2081 __str_trim(category_key);
2082 ret = __run_category_parser_prestep(mfx, category_key, action);
2093 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed)
2095 __save_xml_value(reader, &allowed->text);
2099 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation)
2101 __save_xml_attribute(reader, "name", &operation->name, NULL);
2105 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri)
2107 __save_xml_attribute(reader, "name", &uri->name, NULL);
2111 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime)
2113 __save_xml_attribute(reader, "name", &mime->name, NULL);
2117 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp)
2119 __save_xml_attribute(reader, "name", &subapp->name, NULL);
2123 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition)
2125 __save_xml_attribute(reader, "name", &condition->name, NULL);
2129 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
2131 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
2132 __save_xml_value(reader, ¬ification->text);
2136 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category)
2138 __save_xml_attribute(reader, "name", &category->name, NULL);
2142 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
2144 __save_xml_value(reader, &privilege->text);
2148 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
2150 __save_xml_attribute(reader, "key", &metadata->key, NULL);
2151 __save_xml_attribute(reader, "value", &metadata->value, NULL);
2155 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
2157 __save_xml_attribute(reader, "type", &permission->type, NULL);
2158 __save_xml_value(reader, &permission->value);
2162 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
2164 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
2165 __save_xml_value(reader, &compatibility->text);
2169 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request)
2171 __save_xml_value(reader, &request->text);
2175 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
2177 const xmlChar *node;
2180 allowed_x *tmp1 = NULL;
2181 request_x *tmp2 = NULL;
2183 __save_xml_attribute(reader, "path", &define->path, NULL);
2185 depth = xmlTextReaderDepth(reader);
2186 while ((ret = __next_child_element(reader, depth))) {
2187 node = xmlTextReaderConstName(reader);
2189 _LOGD("xmlTextReaderConstName value is NULL\n");
2193 if (!strcmp(ASCII(node), "allowed")) {
2194 allowed_x *allowed= malloc(sizeof(allowed_x));
2195 if (allowed == NULL) {
2196 _LOGD("Malloc Failed\n");
2199 memset(allowed, '\0', sizeof(allowed_x));
2200 LISTADD(define->allowed, allowed);
2201 ret = __ps_process_allowed(reader, allowed);
2202 } else if (!strcmp(ASCII(node), "request")) {
2203 request_x *request = malloc(sizeof(request_x));
2204 if (request == NULL) {
2205 _LOGD("Malloc Failed\n");
2208 memset(request, '\0', sizeof(request_x));
2209 LISTADD(define->request, request);
2210 ret = __ps_process_request(reader, request);
2214 _LOGD("Processing define failed\n");
2218 if (define->allowed) {
2219 LISTHEAD(define->allowed, tmp1);
2220 define->allowed = tmp1;
2222 if (define->request) {
2223 LISTHEAD(define->request, tmp2);
2224 define->request = tmp2;
2229 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol)
2231 const xmlChar *node;
2235 depth = xmlTextReaderDepth(reader);
2236 while ((ret = __next_child_element(reader, depth))) {
2237 node = xmlTextReaderConstName(reader);
2239 _LOGD("xmlTextReaderConstName value is NULL\n");
2243 if (!strcmp(ASCII(node), "operation")) {
2244 __save_xml_attribute(reader, "name", &appcontrol->operation, NULL);
2245 _LOGD("operation processing\n");
2246 } else if (!strcmp(ASCII(node), "uri")) {
2247 __save_xml_attribute(reader, "name", &appcontrol->uri, NULL);
2248 _LOGD("uri processing\n");
2249 } else if (!strcmp(ASCII(node), "mime")) {
2250 __save_xml_attribute(reader, "name", &appcontrol->mime, NULL);
2251 _LOGD("mime processing\n");
2255 _LOGD("Processing appcontrol failed\n");
2263 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
2265 const xmlChar *node;
2268 operation_x *tmp1 = NULL;
2270 mime_x *tmp3 = NULL;
2271 subapp_x *tmp4 = NULL;
2273 depth = xmlTextReaderDepth(reader);
2274 while ((ret = __next_child_element(reader, depth))) {
2275 node = xmlTextReaderConstName(reader);
2277 _LOGD("xmlTextReaderConstName value is NULL\n");
2281 if (!strcmp(ASCII(node), "operation")) {
2282 operation_x *operation = malloc(sizeof(operation_x));
2283 if (operation == NULL) {
2284 _LOGD("Malloc Failed\n");
2287 memset(operation, '\0', sizeof(operation_x));
2288 LISTADD(appsvc->operation, operation);
2289 ret = __ps_process_operation(reader, operation);
2290 _LOGD("operation processing\n");
2291 } else if (!strcmp(ASCII(node), "uri")) {
2292 uri_x *uri= malloc(sizeof(uri_x));
2294 _LOGD("Malloc Failed\n");
2297 memset(uri, '\0', sizeof(uri_x));
2298 LISTADD(appsvc->uri, uri);
2299 ret = __ps_process_uri(reader, uri);
2300 _LOGD("uri processing\n");
2301 } else if (!strcmp(ASCII(node), "mime")) {
2302 mime_x *mime = malloc(sizeof(mime_x));
2304 _LOGD("Malloc Failed\n");
2307 memset(mime, '\0', sizeof(mime_x));
2308 LISTADD(appsvc->mime, mime);
2309 ret = __ps_process_mime(reader, mime);
2310 _LOGD("mime processing\n");
2311 } else if (!strcmp(ASCII(node), "subapp")) {
2312 subapp_x *subapp = malloc(sizeof(subapp_x));
2313 if (subapp == NULL) {
2314 _LOGD("Malloc Failed\n");
2317 memset(subapp, '\0', sizeof(subapp_x));
2318 LISTADD(appsvc->subapp, subapp);
2319 ret = __ps_process_subapp(reader, subapp);
2320 _LOGD("subapp processing\n");
2324 _LOGD("Processing appsvc failed\n");
2328 if (appsvc->operation) {
2329 LISTHEAD(appsvc->operation, tmp1);
2330 appsvc->operation = tmp1;
2333 LISTHEAD(appsvc->uri, tmp2);
2337 LISTHEAD(appsvc->mime, tmp3);
2338 appsvc->mime = tmp3;
2340 if (appsvc->subapp) {
2341 LISTHEAD(appsvc->subapp, tmp4);
2342 appsvc->subapp = tmp4;
2345 xmlTextReaderRead(reader);
2346 if (xmlTextReaderValue(reader))
2347 appsvc->text = ASCII(xmlTextReaderValue(reader));
2353 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges)
2355 const xmlChar *node;
2358 privilege_x *tmp1 = NULL;
2360 depth = xmlTextReaderDepth(reader);
2361 while ((ret = __next_child_element(reader, depth))) {
2362 node = xmlTextReaderConstName(reader);
2364 _LOGD("xmlTextReaderConstName value is NULL\n");
2368 if (strcmp(ASCII(node), "privilege") == 0) {
2369 privilege_x *privilege = malloc(sizeof(privilege_x));
2370 if (privilege == NULL) {
2371 _LOGD("Malloc Failed\n");
2374 memset(privilege, '\0', sizeof(privilege_x));
2375 LISTADD(privileges->privilege, privilege);
2376 ret = __ps_process_privilege(reader, privilege);
2380 _LOGD("Processing privileges failed\n");
2384 if (privileges->privilege) {
2385 LISTHEAD(privileges->privilege, tmp1);
2386 privileges->privilege = tmp1;
2391 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions)
2393 const xmlChar *node;
2396 condition_x *tmp1 = NULL;
2398 depth = xmlTextReaderDepth(reader);
2399 while ((ret = __next_child_element(reader, depth))) {
2400 node = xmlTextReaderConstName(reader);
2402 _LOGD("xmlTextReaderConstName value is NULL\n");
2406 if (strcmp(ASCII(node), "condition") == 0) {
2407 condition_x *condition = malloc(sizeof(condition_x));
2408 if (condition == NULL) {
2409 _LOGD("Malloc Failed\n");
2412 memset(condition, '\0', sizeof(condition_x));
2413 LISTADD(launchconditions->condition, condition);
2414 ret = __ps_process_condition(reader, condition);
2418 _LOGD("Processing launchconditions failed\n");
2422 if (launchconditions->condition) {
2423 LISTHEAD(launchconditions->condition, tmp1);
2424 launchconditions->condition = tmp1;
2427 __save_xml_value(reader, &launchconditions->text);
2432 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
2434 const xmlChar *node;
2437 define_x *tmp1 = NULL;
2438 request_x *tmp2 = NULL;
2439 depth = xmlTextReaderDepth(reader);
2440 while ((ret = __next_child_element(reader, depth))) {
2441 node = xmlTextReaderConstName(reader);
2443 _LOGD("xmlTextReaderConstName value is NULL\n");
2447 if (!strcmp(ASCII(node), "define")) {
2448 define_x *define= malloc(sizeof(define_x));
2449 if (define == NULL) {
2450 _LOGD("Malloc Failed\n");
2453 memset(define, '\0', sizeof(define_x));
2454 LISTADD(datashare->define, define);
2455 ret = __ps_process_define(reader, define);
2456 } else if (!strcmp(ASCII(node), "request")) {
2457 request_x *request= malloc(sizeof(request_x));
2458 if (request == NULL) {
2459 _LOGD("Malloc Failed\n");
2462 memset(request, '\0', sizeof(request_x));
2463 LISTADD(datashare->request, request);
2464 ret = __ps_process_request(reader, request);
2468 _LOGD("Processing data-share failed\n");
2472 if (datashare->define) {
2473 LISTHEAD(datashare->define, tmp1);
2474 datashare->define = tmp1;
2476 if (datashare->request) {
2477 LISTHEAD(datashare->request, tmp2);
2478 datashare->request = tmp2;
2483 static char *__get_icon_with_path(const char * icon, uid_t uid)
2486 char *icon_with_path;
2487 char *confirmed_icon;
2488 const char *app_path;
2491 if (!icon || !package)
2494 if (index(icon, '/') == NULL) {
2495 /* "db/setting/theme" is not exist */
2497 theme = vconf_get_str("db/setting/theme");
2499 theme = strdup("default");
2505 theme = strdup("default");
2508 len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
2509 icon_with_path = malloc(len);
2510 if(icon_with_path == NULL) {
2511 _LOGD("(icon_with_path == NULL) return\n");
2516 memset(icon_with_path, 0, len);
2517 if (uid != GLOBAL_USER && uid != OWNER_ROOT)
2518 snprintf(icon_with_path, len, "%s%s", getIconPath(uid), icon);
2520 snprintf(icon_with_path, len, "%s%s/small/%s", getIconPath(GLOBAL_USER), theme, icon);
2521 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
2522 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
2524 snprintf(icon_with_path, len, "%s/%s/res/icons/%s/small/%s", app_path, package, theme, icon);
2525 if (access(icon_with_path, F_OK))
2526 _LOGE("Cannot find icon path");
2530 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
2531 return icon_with_path;
2533 confirmed_icon = strdup(icon);
2534 if (!confirmed_icon)
2536 return confirmed_icon;
2540 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
2543 char delims[] = "=";
2544 char *ret_result = NULL;
2550 for (tag = strdup(tagv[0]); tag != NULL; ) {
2551 ret_result = strtok(tag, delims);
2553 /*check tag : preload */
2554 if (strcmp(ret_result, "preload") == 0) {
2555 ret_result = strtok(NULL, delims);
2556 if (strcmp(ret_result, "true") == 0) {
2557 free((void *)mfx->preload);
2558 mfx->preload = strdup("true");
2559 } else if (strcmp(ret_result, "false") == 0) {
2560 free((void *)mfx->preload);
2561 mfx->preload = strdup("false");
2563 /*check tag : removable*/
2564 } else if (strcmp(ret_result, "removable") == 0) {
2565 ret_result = strtok(NULL, delims);
2566 if (strcmp(ret_result, "true") == 0){
2567 free((void *)mfx->removable);
2568 mfx->removable = strdup("true");
2569 } else if (strcmp(ret_result, "false") == 0) {
2570 free((void *)mfx->removable);
2571 mfx->removable = strdup("false");
2573 /*check tag : not matched*/
2575 _LOGD("tag process [%s]is not defined\n", ret_result);
2579 /*check next value*/
2580 if (tagv[++i] != NULL)
2581 tag = strdup(tagv[i]);
2583 _LOGD("tag process success...\n");
2589 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
2591 __save_xml_attribute(reader, "name", &icon->name, NULL);
2592 __save_xml_attribute(reader, "section", &icon->section, NULL);
2593 __save_xml_attribute(reader, "size", &icon->size, NULL);
2594 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
2595 __save_xml_lang(reader, &icon->lang);
2597 xmlTextReaderRead(reader);
2598 const char *text = ASCII(xmlTextReaderValue(reader));
2600 icon->text = (const char *)__get_icon_with_path(text, uid);
2607 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
2609 __save_xml_attribute(reader, "name", &image->name, NULL);
2610 __save_xml_attribute(reader, "section", &image->section, NULL);
2611 __save_xml_lang(reader, &image->lang);
2612 __save_xml_value(reader, &image->text);
2616 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
2618 __save_xml_attribute(reader, "name", &label->name, NULL);
2619 __save_xml_lang(reader, &label->lang);
2620 __save_xml_value(reader, &label->text);
2625 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
2627 __save_xml_attribute(reader, "email", &author->email, NULL);
2628 __save_xml_attribute(reader, "href", &author->href, NULL);
2629 __save_xml_lang(reader, &author->lang);
2630 __save_xml_value(reader, &author->text);
2634 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
2636 __save_xml_lang(reader, &description->lang);
2637 __save_xml_value(reader, &description->text);
2641 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
2643 __save_xml_lang(reader, &license->lang);
2644 __save_xml_value(reader, &license->text);
2648 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
2650 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
2651 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
2652 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
2656 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication, uid_t uid)
2658 const xmlChar *node;
2661 label_x *tmp1 = NULL;
2662 icon_x *tmp2 = NULL;
2663 appsvc_x *tmp3 = NULL;
2664 appcontrol_x *tmp4 = NULL;
2665 launchconditions_x *tmp5 = NULL;
2666 notification_x *tmp6 = NULL;
2667 datashare_x *tmp7 = NULL;
2668 category_x *tmp8 = NULL;
2669 metadata_x *tmp9 = NULL;
2670 image_x *tmp10 = NULL;
2671 permission_x *tmp11 = NULL;
2672 datacontrol_x *tmp12 = NULL;
2674 __save_xml_attribute(reader, "appid", &uiapplication->appid, NULL);
2675 retvm_if(uiapplication->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
2676 __save_xml_attribute(reader, "exec", &uiapplication->exec, NULL);
2677 __save_xml_attribute(reader, "nodisplay", &uiapplication->nodisplay, "false");
2678 __save_xml_attribute(reader, "multiple", &uiapplication->multiple, "false");
2679 __save_xml_attribute(reader, "type", &uiapplication->type, NULL);
2680 __save_xml_attribute(reader, "categories", &uiapplication->categories, NULL);
2681 __save_xml_attribute(reader, "extraid", &uiapplication->extraid, NULL);
2682 __save_xml_attribute(reader, "taskmanage", &uiapplication->taskmanage, "true");
2683 __save_xml_attribute(reader, "enabled", &uiapplication->enabled, "true");
2684 __save_xml_attribute(reader, "hw-acceleration", &uiapplication->hwacceleration, "default");
2685 __save_xml_attribute(reader, "screen-reader", &uiapplication->screenreader, "use-system-setting");
2686 __save_xml_attribute(reader, "mainapp", &uiapplication->mainapp, "false");
2687 __save_xml_attribute(reader, "recentimage", &uiapplication->recentimage, "false");
2688 __save_xml_attribute(reader, "launchcondition", &uiapplication->launchcondition, "false");
2689 __save_xml_attribute(reader, "indicatordisplay", &uiapplication->indicatordisplay, "true");
2690 __save_xml_attribute(reader, "portrait-effectimage", &uiapplication->portraitimg, NULL);
2691 __save_xml_attribute(reader, "landscape-effectimage", &uiapplication->landscapeimg, NULL);
2692 __save_xml_attribute(reader, "guestmode-visibility", &uiapplication->guestmode_visibility, "true");
2693 __save_xml_attribute(reader, "permission-type", &uiapplication->permission_type, "normal");
2694 __save_xml_attribute(reader, "component-type", &uiapplication->component_type, "uiapp");
2695 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
2696 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);
2697 __save_xml_attribute(reader, "submode", &uiapplication->submode, "false");
2698 __save_xml_attribute(reader, "submode-mainid", &uiapplication->submode_mainid, NULL);
2699 __save_xml_attribute(reader, "launch_mode", &uiapplication->launch_mode, "caller");
2701 uiapplication->package= strdup(package);
2703 depth = xmlTextReaderDepth(reader);
2704 while ((ret = __next_child_element(reader, depth))) {
2705 node = xmlTextReaderConstName(reader);
2707 _LOGD("xmlTextReaderConstName value is NULL\n");
2710 if (!strcmp(ASCII(node), "label")) {
2711 label_x *label = malloc(sizeof(label_x));
2712 if (label == NULL) {
2713 _LOGD("Malloc Failed\n");
2716 memset(label, '\0', sizeof(label_x));
2717 LISTADD(uiapplication->label, label);
2718 ret = __ps_process_label(reader, label);
2719 } else if (!strcmp(ASCII(node), "icon")) {
2720 icon_x *icon = malloc(sizeof(icon_x));
2722 _LOGD("Malloc Failed\n");
2725 memset(icon, '\0', sizeof(icon_x));
2726 LISTADD(uiapplication->icon, icon);
2727 ret = __ps_process_icon(reader, icon, uid);
2728 } else if (!strcmp(ASCII(node), "image")) {
2729 image_x *image = malloc(sizeof(image_x));
2730 if (image == NULL) {
2731 _LOGD("Malloc Failed\n");
2734 memset(image, '\0', sizeof(image_x));
2735 LISTADD(uiapplication->image, image);
2736 ret = __ps_process_image(reader, image);
2737 } else if (!strcmp(ASCII(node), "category")) {
2738 category_x *category = malloc(sizeof(category_x));
2739 if (category == NULL) {
2740 _LOGD("Malloc Failed\n");
2743 memset(category, '\0', sizeof(category_x));
2744 LISTADD(uiapplication->category, category);
2745 ret = __ps_process_category(reader, category);
2746 } else if (!strcmp(ASCII(node), "metadata")) {
2747 metadata_x *metadata = malloc(sizeof(metadata_x));
2748 if (metadata == NULL) {
2749 _LOGD("Malloc Failed\n");
2752 memset(metadata, '\0', sizeof(metadata_x));
2753 LISTADD(uiapplication->metadata, metadata);
2754 ret = __ps_process_metadata(reader, metadata);
2755 } else if (!strcmp(ASCII(node), "permission")) {
2756 permission_x *permission = malloc(sizeof(permission_x));
2757 if (permission == NULL) {
2758 _LOGD("Malloc Failed\n");
2761 memset(permission, '\0', sizeof(permission_x));
2762 LISTADD(uiapplication->permission, permission);
2763 ret = __ps_process_permission(reader, permission);
2764 } else if (!strcmp(ASCII(node), "app-control")) {
2765 appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
2766 if (appcontrol == NULL) {
2767 _LOGD("Malloc Failed\n");
2770 memset(appcontrol, '\0', sizeof(appcontrol_x));
2771 LISTADD(uiapplication->appcontrol, appcontrol);
2772 ret = __ps_process_appcontrol(reader, appcontrol);
2773 } else if (!strcmp(ASCII(node), "application-service")) {
2774 appsvc_x *appsvc = malloc(sizeof(appsvc_x));
2775 if (appsvc == NULL) {
2776 _LOGD("Malloc Failed\n");
2779 memset(appsvc, '\0', sizeof(appsvc_x));
2780 LISTADD(uiapplication->appsvc, appsvc);
2781 ret = __ps_process_appsvc(reader, appsvc);
2782 } else if (!strcmp(ASCII(node), "data-share")) {
2783 datashare_x *datashare = malloc(sizeof(datashare_x));
2784 if (datashare == NULL) {
2785 _LOGD("Malloc Failed\n");
2788 memset(datashare, '\0', sizeof(datashare_x));
2789 LISTADD(uiapplication->datashare, datashare);
2790 ret = __ps_process_datashare(reader, datashare);
2791 } else if (!strcmp(ASCII(node), "launch-conditions")) {
2792 launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
2793 if (launchconditions == NULL) {
2794 _LOGD("Malloc Failed\n");
2797 memset(launchconditions, '\0', sizeof(launchconditions_x));
2798 LISTADD(uiapplication->launchconditions, launchconditions);
2799 ret = __ps_process_launchconditions(reader, launchconditions);
2800 } else if (!strcmp(ASCII(node), "notification")) {
2801 notification_x *notification = malloc(sizeof(notification_x));
2802 if (notification == NULL) {
2803 _LOGD("Malloc Failed\n");
2806 memset(notification, '\0', sizeof(notification_x));
2807 LISTADD(uiapplication->notification, notification);
2808 ret = __ps_process_notification(reader, notification);
2809 } else if (!strcmp(ASCII(node), "datacontrol")) {
2810 datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
2811 if (datacontrol == NULL) {
2812 _LOGD("Malloc Failed\n");
2815 memset(datacontrol, '\0', sizeof(datacontrol_x));
2816 LISTADD(uiapplication->datacontrol, datacontrol);
2817 ret = __ps_process_datacontrol(reader, datacontrol);
2821 _LOGD("Processing uiapplication failed\n");
2826 if (uiapplication->label) {
2827 LISTHEAD(uiapplication->label, tmp1);
2828 uiapplication->label = tmp1;
2830 if (uiapplication->icon) {
2831 LISTHEAD(uiapplication->icon, tmp2);
2832 uiapplication->icon = tmp2;
2834 if (uiapplication->appsvc) {
2835 LISTHEAD(uiapplication->appsvc, tmp3);
2836 uiapplication->appsvc = tmp3;
2838 if (uiapplication->appcontrol) {
2839 LISTHEAD(uiapplication->appcontrol, tmp4);
2840 uiapplication->appcontrol = tmp4;
2842 if (uiapplication->launchconditions) {
2843 LISTHEAD(uiapplication->launchconditions, tmp5);
2844 uiapplication->launchconditions = tmp5;
2846 if (uiapplication->notification) {
2847 LISTHEAD(uiapplication->notification, tmp6);
2848 uiapplication->notification = tmp6;
2850 if (uiapplication->datashare) {
2851 LISTHEAD(uiapplication->datashare, tmp7);
2852 uiapplication->datashare = tmp7;
2854 if (uiapplication->category) {
2855 LISTHEAD(uiapplication->category, tmp8);
2856 uiapplication->category = tmp8;
2858 if (uiapplication->metadata) {
2859 LISTHEAD(uiapplication->metadata, tmp9);
2860 uiapplication->metadata = tmp9;
2862 if (uiapplication->image) {
2863 LISTHEAD(uiapplication->image, tmp10);
2864 uiapplication->image = tmp10;
2866 if (uiapplication->permission) {
2867 LISTHEAD(uiapplication->permission, tmp11);
2868 uiapplication->permission = tmp11;
2870 if (uiapplication->datacontrol) {
2871 LISTHEAD(uiapplication->datacontrol, tmp12);
2872 uiapplication->datacontrol = tmp12;
2878 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication, uid_t uid)
2880 const xmlChar *node;
2883 label_x *tmp1 = NULL;
2884 icon_x *tmp2 = NULL;
2885 appsvc_x *tmp3 = NULL;
2886 appcontrol_x *tmp4 = NULL;
2887 datacontrol_x *tmp5 = NULL;
2888 launchconditions_x *tmp6 = NULL;
2889 notification_x *tmp7 = NULL;
2890 datashare_x *tmp8 = NULL;
2891 category_x *tmp9 = NULL;
2892 metadata_x *tmp10 = NULL;
2893 permission_x *tmp11 = NULL;
2895 __save_xml_attribute(reader, "appid", &serviceapplication->appid, NULL);
2896 retvm_if(serviceapplication->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
2897 __save_xml_attribute(reader, "exec", &serviceapplication->exec, NULL);
2898 __save_xml_attribute(reader, "type", &serviceapplication->type, NULL);
2899 __save_xml_attribute(reader, "enabled", &serviceapplication->enabled, "true");
2900 __save_xml_attribute(reader, "permission-type", &serviceapplication->permission_type, "normal");
2901 __save_xml_attribute(reader, "auto-restart", &serviceapplication->autorestart, "false");
2902 __save_xml_attribute(reader, "on-boot", &serviceapplication->onboot, "false");
2904 serviceapplication->package= strdup(package);
2906 depth = xmlTextReaderDepth(reader);
2907 while ((ret = __next_child_element(reader, depth))) {
2908 node = xmlTextReaderConstName(reader);
2910 _LOGD("xmlTextReaderConstName value is NULL\n");
2914 if (!strcmp(ASCII(node), "label")) {
2915 label_x *label = malloc(sizeof(label_x));
2916 if (label == NULL) {
2917 _LOGD("Malloc Failed\n");
2920 memset(label, '\0', sizeof(label_x));
2921 LISTADD(serviceapplication->label, label);
2922 ret = __ps_process_label(reader, label);
2923 } else if (!strcmp(ASCII(node), "icon")) {
2924 icon_x *icon = malloc(sizeof(icon_x));
2926 _LOGD("Malloc Failed\n");
2929 memset(icon, '\0', sizeof(icon_x));
2930 LISTADD(serviceapplication->icon, icon);
2931 ret = __ps_process_icon(reader, icon, uid);
2932 } else if (!strcmp(ASCII(node), "category")) {
2933 category_x *category = malloc(sizeof(category_x));
2934 if (category == NULL) {
2935 _LOGD("Malloc Failed\n");
2938 memset(category, '\0', sizeof(category_x));
2939 LISTADD(serviceapplication->category, category);
2940 ret = __ps_process_category(reader, category);
2941 } else if (!strcmp(ASCII(node), "metadata")) {
2942 metadata_x *metadata = malloc(sizeof(metadata_x));
2943 if (metadata == NULL) {
2944 _LOGD("Malloc Failed\n");
2947 memset(metadata, '\0', sizeof(metadata_x));
2948 LISTADD(serviceapplication->metadata, metadata);
2949 ret = __ps_process_metadata(reader, metadata);
2950 } else if (!strcmp(ASCII(node), "permission")) {
2951 permission_x *permission = malloc(sizeof(permission_x));
2952 if (permission == NULL) {
2953 _LOGD("Malloc Failed\n");
2956 memset(permission, '\0', sizeof(permission_x));
2957 LISTADD(serviceapplication->permission, permission);
2958 ret = __ps_process_permission(reader, permission);
2959 } else if (!strcmp(ASCII(node), "app-control")) {
2960 appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
2961 if (appcontrol == NULL) {
2962 _LOGD("Malloc Failed\n");
2965 memset(appcontrol, '\0', sizeof(appcontrol_x));
2966 LISTADD(serviceapplication->appcontrol, appcontrol);
2967 ret = __ps_process_appcontrol(reader, appcontrol);
2968 } else if (!strcmp(ASCII(node), "application-service")) {
2969 appsvc_x *appsvc = malloc(sizeof(appsvc_x));
2970 if (appsvc == NULL) {
2971 _LOGD("Malloc Failed\n");
2974 memset(appsvc, '\0', sizeof(appsvc_x));
2975 LISTADD(serviceapplication->appsvc, appsvc);
2976 ret = __ps_process_appsvc(reader, appsvc);
2977 } else if (!strcmp(ASCII(node), "data-share")) {
2978 datashare_x *datashare = malloc(sizeof(datashare_x));
2979 if (datashare == NULL) {
2980 _LOGD("Malloc Failed\n");
2983 memset(datashare, '\0', sizeof(datashare_x));
2984 LISTADD(serviceapplication->datashare, datashare);
2985 ret = __ps_process_datashare(reader, datashare);
2986 } else if (!strcmp(ASCII(node), "launch-conditions")) {
2987 launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
2988 if (launchconditions == NULL) {
2989 _LOGD("Malloc Failed\n");
2992 memset(launchconditions, '\0', sizeof(launchconditions_x));
2993 LISTADD(serviceapplication->launchconditions, launchconditions);
2994 ret = __ps_process_launchconditions(reader, launchconditions);
2995 } else if (!strcmp(ASCII(node), "notification")) {
2996 notification_x *notification = malloc(sizeof(notification_x));
2997 if (notification == NULL) {
2998 _LOGD("Malloc Failed\n");
3001 memset(notification, '\0', sizeof(notification_x));
3002 LISTADD(serviceapplication->notification, notification);
3003 ret = __ps_process_notification(reader, notification);
3004 } else if (!strcmp(ASCII(node), "datacontrol")) {
3005 datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
3006 if (datacontrol == NULL) {
3007 _LOGD("Malloc Failed\n");
3010 memset(datacontrol, '\0', sizeof(datacontrol_x));
3011 LISTADD(serviceapplication->datacontrol, datacontrol);
3012 ret = __ps_process_datacontrol(reader, datacontrol);
3016 _LOGD("Processing serviceapplication failed\n");
3021 if (serviceapplication->label) {
3022 LISTHEAD(serviceapplication->label, tmp1);
3023 serviceapplication->label = tmp1;
3025 if (serviceapplication->icon) {
3026 LISTHEAD(serviceapplication->icon, tmp2);
3027 serviceapplication->icon = tmp2;
3029 if (serviceapplication->appsvc) {
3030 LISTHEAD(serviceapplication->appsvc, tmp3);
3031 serviceapplication->appsvc = tmp3;
3033 if (serviceapplication->appcontrol) {
3034 LISTHEAD(serviceapplication->appcontrol, tmp4);
3035 serviceapplication->appcontrol = tmp4;
3037 if (serviceapplication->datacontrol) {
3038 LISTHEAD(serviceapplication->datacontrol, tmp5);
3039 serviceapplication->datacontrol = tmp5;
3041 if (serviceapplication->launchconditions) {
3042 LISTHEAD(serviceapplication->launchconditions, tmp6);
3043 serviceapplication->launchconditions = tmp6;
3045 if (serviceapplication->notification) {
3046 LISTHEAD(serviceapplication->notification, tmp7);
3047 serviceapplication->notification = tmp7;
3049 if (serviceapplication->datashare) {
3050 LISTHEAD(serviceapplication->datashare, tmp8);
3051 serviceapplication->datashare = tmp8;
3053 if (serviceapplication->category) {
3054 LISTHEAD(serviceapplication->category, tmp9);
3055 serviceapplication->category = tmp9;
3057 if (serviceapplication->metadata) {
3058 LISTHEAD(serviceapplication->metadata, tmp10);
3059 serviceapplication->metadata = tmp10;
3061 if (serviceapplication->permission) {
3062 LISTHEAD(serviceapplication->permission, tmp11);
3063 serviceapplication->permission = tmp11;
3069 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile)
3071 /*TODO: once policy is set*/
3075 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font)
3077 /*TODO: once policy is set*/
3081 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme)
3083 /*TODO: once policy is set*/
3087 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon)
3089 /*TODO: once policy is set*/
3093 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
3095 /*TODO: once policy is set*/
3099 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
3101 _LOGD("__start_process\n");
3102 const xmlChar *node;
3105 label_x *tmp1 = NULL;
3106 author_x *tmp2 = NULL;
3107 description_x *tmp3 = NULL;
3108 license_x *tmp4 = NULL;
3109 uiapplication_x *tmp5 = NULL;
3110 serviceapplication_x *tmp6 = NULL;
3111 daemon_x *tmp7 = NULL;
3112 theme_x *tmp8 = NULL;
3113 font_x *tmp9 = NULL;
3114 ime_x *tmp10 = NULL;
3115 icon_x *tmp11 = NULL;
3116 compatibility_x *tmp12 = NULL;
3117 deviceprofile_x *tmp13 = NULL;
3118 privileges_x *tmp14 = NULL;
3120 depth = xmlTextReaderDepth(reader);
3121 while ((ret = __next_child_element(reader, depth))) {
3122 node = xmlTextReaderConstName(reader);
3124 _LOGD("xmlTextReaderConstName value is NULL\n");
3128 if (!strcmp(ASCII(node), "label")) {
3129 label_x *label = malloc(sizeof(label_x));
3130 if (label == NULL) {
3131 _LOGD("Malloc Failed\n");
3134 memset(label, '\0', sizeof(label_x));
3135 LISTADD(mfx->label, label);
3136 ret = __ps_process_label(reader, label);
3137 } else if (!strcmp(ASCII(node), "author")) {
3138 author_x *author = malloc(sizeof(author_x));
3139 if (author == NULL) {
3140 _LOGD("Malloc Failed\n");
3143 memset(author, '\0', sizeof(author_x));
3144 LISTADD(mfx->author, author);
3145 ret = __ps_process_author(reader, author);
3146 } else if (!strcmp(ASCII(node), "description")) {
3147 description_x *description = malloc(sizeof(description_x));
3148 if (description == NULL) {
3149 _LOGD("Malloc Failed\n");
3152 memset(description, '\0', sizeof(description_x));
3153 LISTADD(mfx->description, description);
3154 ret = __ps_process_description(reader, description);
3155 } else if (!strcmp(ASCII(node), "license")) {
3156 license_x *license = malloc(sizeof(license_x));
3157 if (license == NULL) {
3158 _LOGD("Malloc Failed\n");
3161 memset(license, '\0', sizeof(license_x));
3162 LISTADD(mfx->license, license);
3163 ret = __ps_process_license(reader, license);
3164 } else if (!strcmp(ASCII(node), "privileges")) {
3165 privileges_x *privileges = malloc(sizeof(privileges_x));
3166 if (privileges == NULL) {
3167 _LOGD("Malloc Failed\n");
3170 memset(privileges, '\0', sizeof(privileges_x));
3171 LISTADD(mfx->privileges, privileges);
3172 ret = __ps_process_privileges(reader, privileges);
3173 } else if (!strcmp(ASCII(node), "ui-application")) {
3174 uiapplication_x *uiapplication = malloc(sizeof(uiapplication_x));
3175 if (uiapplication == NULL) {
3176 _LOGD("Malloc Failed\n");
3179 memset(uiapplication, '\0', sizeof(uiapplication_x));
3180 LISTADD(mfx->uiapplication, uiapplication);
3181 ret = __ps_process_uiapplication(reader, uiapplication, uid);
3182 } else if (!strcmp(ASCII(node), "service-application")) {
3183 serviceapplication_x *serviceapplication = malloc(sizeof(serviceapplication_x));
3184 if (serviceapplication == NULL) {
3185 _LOGD("Malloc Failed\n");
3188 memset(serviceapplication, '\0', sizeof(serviceapplication_x));
3189 LISTADD(mfx->serviceapplication, serviceapplication);
3190 ret = __ps_process_serviceapplication(reader, serviceapplication, uid);
3191 } else if (!strcmp(ASCII(node), "daemon")) {
3192 daemon_x *daemon = malloc(sizeof(daemon_x));
3193 if (daemon == NULL) {
3194 _LOGD("Malloc Failed\n");
3197 memset(daemon, '\0', sizeof(daemon_x));
3198 LISTADD(mfx->daemon, daemon);
3199 ret = __ps_process_daemon(reader, daemon);
3200 } else if (!strcmp(ASCII(node), "theme")) {
3201 theme_x *theme = malloc(sizeof(theme_x));
3202 if (theme == NULL) {
3203 _LOGD("Malloc Failed\n");
3206 memset(theme, '\0', sizeof(theme_x));
3207 LISTADD(mfx->theme, theme);
3208 ret = __ps_process_theme(reader, theme);
3209 } else if (!strcmp(ASCII(node), "font")) {
3210 font_x *font = malloc(sizeof(font_x));
3212 _LOGD("Malloc Failed\n");
3215 memset(font, '\0', sizeof(font_x));
3216 LISTADD(mfx->font, font);
3217 ret = __ps_process_font(reader, font);
3218 } else if (!strcmp(ASCII(node), "ime")) {
3219 ime_x *ime = malloc(sizeof(ime_x));
3221 _LOGD("Malloc Failed\n");
3224 memset(ime, '\0', sizeof(ime_x));
3225 LISTADD(mfx->ime, ime);
3226 ret = __ps_process_ime(reader, ime);
3227 } else if (!strcmp(ASCII(node), "icon")) {
3228 icon_x *icon = malloc(sizeof(icon_x));
3230 _LOGD("Malloc Failed\n");
3233 memset(icon, '\0', sizeof(icon_x));
3234 LISTADD(mfx->icon, icon);
3235 ret = __ps_process_icon(reader, icon, uid);
3236 } else if (!strcmp(ASCII(node), "profile")) {
3237 deviceprofile_x *deviceprofile = malloc(sizeof(deviceprofile_x));
3238 if (deviceprofile == NULL) {
3239 _LOGD("Malloc Failed\n");
3242 memset(deviceprofile, '\0', sizeof(deviceprofile_x));
3243 LISTADD(mfx->deviceprofile, deviceprofile);
3244 ret = __ps_process_deviceprofile(reader, deviceprofile);
3245 } else if (!strcmp(ASCII(node), "compatibility")) {
3246 compatibility_x *compatibility = malloc(sizeof(compatibility_x));
3247 if (compatibility == NULL) {
3248 _LOGD("Malloc Failed\n");
3251 memset(compatibility, '\0', sizeof(compatibility_x));
3252 LISTADD(mfx->compatibility, compatibility);
3253 ret = __ps_process_compatibility(reader, compatibility);
3254 } else if (!strcmp(ASCII(node), "shortcut-list")) {
3256 } else if (!strcmp(ASCII(node), "livebox")) {
3258 } else if (!strcmp(ASCII(node), "account")) {
3260 } else if (!strcmp(ASCII(node), "notifications")) {
3262 } else if (!strcmp(ASCII(node), "ime")) {
3264 } else if (!strcmp(ASCII(node), "feature")) {
3267 _LOGE("Unknown element: %s", ASCII(node));
3272 _LOGD("Processing manifest failed\n");
3277 LISTHEAD(mfx->label, tmp1);
3281 LISTHEAD(mfx->author, tmp2);
3284 if (mfx->description) {
3285 LISTHEAD(mfx->description, tmp3);
3286 mfx->description= tmp3;
3289 LISTHEAD(mfx->license, tmp4);
3292 if (mfx->uiapplication) {
3293 LISTHEAD(mfx->uiapplication, tmp5);
3294 mfx->uiapplication = tmp5;
3296 if (mfx->serviceapplication) {
3297 LISTHEAD(mfx->serviceapplication, tmp6);
3298 mfx->serviceapplication = tmp6;
3301 LISTHEAD(mfx->daemon, tmp7);
3305 LISTHEAD(mfx->theme, tmp8);
3309 LISTHEAD(mfx->font, tmp9);
3313 LISTHEAD(mfx->ime, tmp10);
3317 LISTHEAD(mfx->icon, tmp11);
3320 if (mfx->compatibility) {
3321 LISTHEAD(mfx->compatibility, tmp12);
3322 mfx->compatibility= tmp12;
3324 if (mfx->deviceprofile) {
3325 LISTHEAD(mfx->deviceprofile, tmp13);
3326 mfx->deviceprofile= tmp13;
3328 if (mfx->privileges) {
3329 LISTHEAD(mfx->privileges, tmp14);
3330 mfx->privileges = tmp14;
3335 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
3337 const xmlChar *node;
3340 if ((ret = __next_child_element(reader, -1))) {
3341 node = xmlTextReaderConstName(reader);
3343 _LOGD("xmlTextReaderConstName value is NULL\n");
3347 if (!strcmp(ASCII(node), "manifest")) {
3348 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
3349 __save_xml_attribute(reader, "package", &mfx->package, NULL);
3350 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
3351 __save_xml_attribute(reader, "version", &mfx->version, NULL);
3352 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
3353 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
3354 __save_xml_attribute(reader, "type", &mfx->type, "rpm");
3355 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
3356 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
3357 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
3358 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
3359 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
3360 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
3361 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
3363 __save_xml_installed_time(mfx);
3364 __save_xml_root_path(mfx, uid);
3365 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
3366 __save_xml_default_value(mfx);
3368 ret = __start_process(reader, mfx, uid);
3370 _LOGD("No Manifest element found\n");
3377 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
3379 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
3381 void *lib_handle = NULL;
3382 int (*appsvc_operation) (const char *, uid_t);
3384 uiapplication_x *uiapplication = mfx->uiapplication;
3386 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
3387 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
3391 if ((appsvc_operation =
3392 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
3393 _LOGE("can not find symbol \n");
3397 for(; uiapplication; uiapplication=uiapplication->next) {
3398 ret = appsvc_operation(uiapplication->appid, uid);
3400 _LOGE("can not operation symbol \n");
3405 dlclose(lib_handle);
3410 #define PRELOAD_PACKAGE_LIST SYSCONFDIR "/package-manager/preload/preload_list.txt"
3411 static int __add_preload_info(manifest_x * mfx, const char *manifest, uid_t uid)
3414 char buffer[1024] = { 0 };
3417 if(strstr(manifest, getUserManifestPath(uid))) {
3418 free((void *)mfx->readonly);
3419 mfx->readonly = strdup("True");
3421 free((void *)mfx->preload);
3422 mfx->preload = strdup("True");
3424 free((void *)mfx->removable);
3425 mfx->removable = strdup("False");
3427 free((void *)mfx->system);
3428 mfx->system = strdup("True");
3433 fp = fopen(PRELOAD_PACKAGE_LIST, "r");
3435 _LOGE("no preload list\n");
3439 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
3440 if (buffer[0] == '#') {
3441 if(strcasestr(buffer, "RW_NORM"))
3443 else if(strcasestr(buffer, "RW_RM"))
3451 if(!strcmp(mfx->package, buffer)) {
3452 free((void *)mfx->preload);
3453 mfx->preload = strdup("True");
3455 free((void *)mfx->readonly);
3456 mfx->readonly = strdup("False");
3457 free((void *)mfx->removable);
3458 mfx->removable = strdup("False");
3459 } else if(state == 3){
3460 free((void *)mfx->readonly);
3461 mfx->readonly = strdup("False");
3462 free((void *)mfx->removable);
3463 mfx->removable = strdup("True");
3467 memset(buffer, 0x00, sizeof(buffer));
3476 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
3478 if (!strstr(manifest, getUserManifestPath(uid))) {
3479 /* if downloaded app is updated, then update tag set true*/
3481 free((void *)mfx->update);
3482 mfx->update = strdup("true");
3489 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
3491 /* desktop file is no longer used */
3495 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
3497 /* desktop file is no longer used */
3502 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
3507 free((void *)mfx->ns);
3511 free((void *)mfx->package);
3512 mfx->package = NULL;
3515 free((void *)mfx->version);
3516 mfx->version = NULL;
3518 if (mfx->installlocation) {
3519 free((void *)mfx->installlocation);
3520 mfx->installlocation = NULL;
3523 free((void *)mfx->preload);
3524 mfx->preload = NULL;
3526 if (mfx->readonly) {
3527 free((void *)mfx->readonly);
3528 mfx->readonly = NULL;
3530 if (mfx->removable) {
3531 free((void *)mfx->removable);
3532 mfx->removable = NULL;
3535 free((void *)mfx->update);
3539 free((void *)mfx->system);
3543 free((void *)mfx->type);
3546 if (mfx->package_size) {
3547 free((void *)mfx->package_size);
3548 mfx->package_size = NULL;
3550 if (mfx->installed_time) {
3551 free((void *)mfx->installed_time);
3552 mfx->installed_time = NULL;
3554 if (mfx->installed_storage) {
3555 free((void *)mfx->installed_storage);
3556 mfx->installed_storage = NULL;
3558 if (mfx->storeclient_id) {
3559 free((void *)mfx->storeclient_id);
3560 mfx->storeclient_id = NULL;
3562 if (mfx->mainapp_id) {
3563 free((void *)mfx->mainapp_id);
3564 mfx->mainapp_id = NULL;
3566 if (mfx->package_url) {
3567 free((void *)mfx->package_url);
3568 mfx->package_url = NULL;
3570 if (mfx->root_path) {
3571 free((void *)mfx->root_path);
3572 mfx->root_path = NULL;
3574 if (mfx->csc_path) {
3575 free((void *)mfx->csc_path);
3576 mfx->csc_path = NULL;
3578 if (mfx->appsetting) {
3579 free((void *)mfx->appsetting);
3580 mfx->appsetting = NULL;
3582 if (mfx->nodisplay_setting) {
3583 free((void *)mfx->nodisplay_setting);
3584 mfx->nodisplay_setting = NULL;
3586 if (mfx->api_version) {
3587 free((void *)mfx->api_version);
3588 mfx->api_version = NULL;
3593 icon_x *icon = mfx->icon;
3595 while(icon != NULL) {
3597 __ps_free_icon(icon);
3603 label_x *label = mfx->label;
3604 label_x *tmp = NULL;
3605 while(label != NULL) {
3607 __ps_free_label(label);
3613 author_x *author = mfx->author;
3614 author_x *tmp = NULL;
3615 while(author != NULL) {
3617 __ps_free_author(author);
3621 /*Free Description*/
3622 if (mfx->description) {
3623 description_x *description = mfx->description;
3624 description_x *tmp = NULL;
3625 while(description != NULL) {
3626 tmp = description->next;
3627 __ps_free_description(description);
3633 license_x *license = mfx->license;
3634 license_x *tmp = NULL;
3635 while(license != NULL) {
3636 tmp = license->next;
3637 __ps_free_license(license);
3642 if (mfx->privileges) {
3643 privileges_x *privileges = mfx->privileges;
3644 privileges_x *tmp = NULL;
3645 while(privileges != NULL) {
3646 tmp = privileges->next;
3647 __ps_free_privileges(privileges);
3651 /*Free UiApplication*/
3652 if (mfx->uiapplication) {
3653 uiapplication_x *uiapplication = mfx->uiapplication;
3654 uiapplication_x *tmp = NULL;
3655 while(uiapplication != NULL) {
3656 tmp = uiapplication->next;
3657 __ps_free_uiapplication(uiapplication);
3658 uiapplication = tmp;
3661 /*Free ServiceApplication*/
3662 if (mfx->serviceapplication) {
3663 serviceapplication_x *serviceapplication = mfx->serviceapplication;
3664 serviceapplication_x *tmp = NULL;
3665 while(serviceapplication != NULL) {
3666 tmp = serviceapplication->next;
3667 __ps_free_serviceapplication(serviceapplication);
3668 serviceapplication = tmp;
3673 daemon_x *daemon = mfx->daemon;
3674 daemon_x *tmp = NULL;
3675 while(daemon != NULL) {
3677 __ps_free_daemon(daemon);
3683 theme_x *theme = mfx->theme;
3684 theme_x *tmp = NULL;
3685 while(theme != NULL) {
3687 __ps_free_theme(theme);
3693 font_x *font = mfx->font;
3695 while(font != NULL) {
3697 __ps_free_font(font);
3703 ime_x *ime = mfx->ime;
3705 while(ime != NULL) {
3711 /*Free Compatibility*/
3712 if (mfx->compatibility) {
3713 compatibility_x *compatibility = mfx->compatibility;
3714 compatibility_x *tmp = NULL;
3715 while(compatibility != NULL) {
3716 tmp = compatibility->next;
3717 __ps_free_compatibility(compatibility);
3718 compatibility = tmp;
3721 /*Free DeviceProfile*/
3722 if (mfx->deviceprofile) {
3723 deviceprofile_x *deviceprofile = mfx->deviceprofile;
3724 deviceprofile_x *tmp = NULL;
3725 while(deviceprofile != NULL) {
3726 tmp = deviceprofile->next;
3727 __ps_free_deviceprofile(deviceprofile);
3728 deviceprofile = tmp;
3736 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
3738 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
3739 xmlTextReaderPtr reader;
3740 manifest_x *mfx = NULL;
3742 reader = xmlReaderForFile(manifest, NULL, 0);
3744 mfx = malloc(sizeof(manifest_x));
3746 memset(mfx, '\0', sizeof(manifest_x));
3747 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
3748 _LOGD("Parsing Failed\n");
3749 pkgmgr_parser_free_manifest_xml(mfx);
3752 _LOGD("Parsing Success\n");
3754 _LOGD("Memory allocation error\n");
3756 xmlFreeTextReader(reader);
3758 _LOGD("Unable to create xml reader\n");
3764 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
3766 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
3767 xmlTextReaderPtr reader;
3768 manifest_x *mfx = NULL;
3770 reader = xmlReaderForFile(manifest, NULL, 0);
3772 mfx = malloc(sizeof(manifest_x));
3774 memset(mfx, '\0', sizeof(manifest_x));
3775 if (__process_manifest(reader, mfx, uid) < 0) {
3776 _LOGD("Parsing Failed\n");
3777 pkgmgr_parser_free_manifest_xml(mfx);
3780 _LOGD("Parsing Success\n");
3782 _LOGD("Memory allocation error\n");
3784 xmlFreeTextReader(reader);
3786 _LOGD("Unable to create xml reader\n");
3791 /* These APIs are intended to call parser directly */
3793 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
3795 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
3796 _LOGD("parsing manifest for installation: %s\n", manifest);
3798 manifest_x *mfx = NULL;
3802 mfx = pkgmgr_parser_process_manifest_xml(manifest);
3803 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
3805 _LOGD("Parsing Finished\n");
3807 __add_preload_info(mfx, manifest, GLOBAL_USER);
3809 _LOGD("Added preload infomation\n");
3811 __ps_process_tag(mfx, tagv);
3813 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
3814 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
3816 _LOGD("DB Insert Success\n");
3818 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
3819 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
3821 _LOGD("Creating metadata parser failed\n");
3823 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
3825 _LOGD("Creating category parser failed\n");
3827 pkgmgr_parser_free_manifest_xml(mfx);
3828 _LOGD("Free Done\n");
3833 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
3835 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
3836 _LOGD("parsing manifest for installation: %s\n", manifest);
3837 manifest_x *mfx = NULL;
3841 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
3842 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
3844 _LOGD("Parsing Finished\n");
3846 __ps_process_tag(mfx, tagv);
3848 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
3849 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
3851 _LOGD("DB Insert Success\n");
3853 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
3854 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
3856 _LOGD("Creating metadata parser failed\n");
3857 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
3859 _LOGD("Creating category parser failed\n");
3861 pkgmgr_parser_free_manifest_xml(mfx);
3862 _LOGD("Free Done\n");
3868 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
3870 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
3871 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
3872 manifest_x *mfx = NULL;
3874 bool preload = false;
3875 bool system = false;
3876 char *csc_path = NULL;
3877 pkgmgrinfo_pkginfo_h handle = NULL;
3880 mfx = pkgmgr_parser_process_manifest_xml(manifest);
3881 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
3883 _LOGD("Parsing Finished\n");
3884 __add_preload_info(mfx, manifest, GLOBAL_USER);
3885 _LOGD("Added preload infomation\n");
3886 __check_preload_updated(mfx, manifest, GLOBAL_USER);
3888 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
3889 if (ret != PMINFO_R_OK)
3890 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
3891 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
3892 if (ret != PMINFO_R_OK)
3893 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
3896 free((void *)mfx->preload);
3897 mfx->preload = strdup("true");
3900 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
3901 if (ret != PMINFO_R_OK)
3902 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
3904 free((void *)mfx->system);
3905 mfx->system = strdup("true");
3908 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
3909 if (ret != PMINFO_R_OK)
3910 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
3912 if (csc_path != NULL) {
3914 free((void *)mfx->csc_path);
3915 mfx->csc_path = strdup(csc_path);
3918 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
3919 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
3921 _LOGD("DB Update Success\n");
3923 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
3924 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
3926 _LOGD("Upgrade metadata parser failed\n");
3928 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
3930 _LOGD("Creating category parser failed\n");
3931 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
3932 pkgmgr_parser_free_manifest_xml(mfx);
3933 _LOGD("Free Done\n");
3939 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
3941 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
3942 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
3943 manifest_x *mfx = NULL;
3945 bool preload = false;
3946 bool system = false;
3947 char *csc_path = NULL;
3948 pkgmgrinfo_pkginfo_h handle = NULL;
3951 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
3952 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
3954 _LOGD("Parsing Finished\n");
3955 __check_preload_updated(mfx, manifest, uid);
3957 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
3958 if (ret != PMINFO_R_OK)
3959 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
3960 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
3961 if (ret != PMINFO_R_OK)
3962 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
3965 free((void *)mfx->preload);
3966 mfx->preload = strdup("true");
3969 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
3970 if (ret != PMINFO_R_OK)
3971 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
3974 free((void *)mfx->system);
3975 mfx->system = strdup("true");
3978 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
3979 if (ret != PMINFO_R_OK)
3980 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
3981 if (csc_path != NULL) {
3983 free((void *)mfx->csc_path);
3984 mfx->csc_path = strdup(csc_path);
3987 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
3988 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
3989 _LOGD("DB Update Success\n");
3991 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
3992 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
3994 _LOGD("Upgrade metadata parser failed\n");
3995 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
3997 _LOGD("Creating category parser failed\n");
3998 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
3999 pkgmgr_parser_free_manifest_xml(mfx);
4000 _LOGD("Free Done\n");
4006 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
4008 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4009 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
4011 manifest_x *mfx = NULL;
4014 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4015 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4017 _LOGD("Parsing Finished\n");
4019 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
4021 __add_preload_info(mfx, manifest, GLOBAL_USER);
4022 _LOGD("Added preload infomation\n");
4024 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
4026 _LOGD("Removing metadata parser failed\n");
4028 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
4030 _LOGD("Creating category parser failed\n");
4032 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
4034 _LOGD("DB Delete failed\n");
4036 _LOGD("DB Delete Success\n");
4038 pkgmgr_parser_free_manifest_xml(mfx);
4039 _LOGD("Free Done\n");
4046 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
4048 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4049 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
4051 manifest_x *mfx = NULL;
4054 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
4055 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4057 _LOGD("Parsing Finished\n");
4059 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
4061 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
4063 _LOGD("Removing metadata parser failed\n");
4065 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
4067 _LOGD("Creating category parser failed\n");
4069 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
4071 _LOGD("DB Delete failed\n");
4073 _LOGD("DB Delete Success\n");
4075 ret = __ps_remove_appsvc_db(mfx, uid);
4077 _LOGD("Removing appsvc_db failed\n");
4079 _LOGD("Removing appsvc_db Success\n");
4081 pkgmgr_parser_free_manifest_xml(mfx);
4082 _LOGD("Free Done\n");
4088 API int pkgmgr_parser_parse_manifest_for_preload()
4090 return pkgmgr_parser_update_preload_info_in_db();
4093 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
4095 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
4099 API char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid)
4101 return __pkgid_to_manifest(pkgid, uid);
4104 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
4106 return __pkgid_to_manifest(pkgid, GLOBAL_USER);
4109 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
4111 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
4114 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
4116 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
4119 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
4121 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
4124 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
4126 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
4128 if (manifest == NULL) {
4129 _LOGE("manifest file is NULL\n");
4130 return PMINFO_R_EINVAL;
4133 xmlSchemaParserCtxtPtr ctx;
4134 xmlSchemaValidCtxtPtr vctx;
4135 xmlSchemaPtr xschema;
4136 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
4138 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
4139 return PMINFO_R_ERROR;
4141 xschema = xmlSchemaParse(ctx);
4142 if (xschema == NULL) {
4143 _LOGE("xmlSchemaParse() Failed\n");
4144 return PMINFO_R_ERROR;
4146 vctx = xmlSchemaNewValidCtxt(xschema);
4148 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
4149 return PMINFO_R_ERROR;
4151 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
4152 ret = xmlSchemaValidateFile(vctx, manifest, 0);
4154 _LOGE("xmlSchemaValidateFile() failed\n");
4155 return PMINFO_R_ERROR;
4156 } else if (ret == 0) {
4157 _LOGE("Manifest is Valid\n");
4160 _LOGE("Manifest Validation Failed with error code %d\n", ret);
4161 return PMINFO_R_ERROR;
4167 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
4177 _LOGE("fork failed\n");
4182 int dev_null_fd = open ("/dev/null", O_RDWR);
4183 if (dev_null_fd >= 0)
4185 dup2 (dev_null_fd, 0);/*stdin*/
4186 dup2 (dev_null_fd, 1);/*stdout*/
4187 dup2 (dev_null_fd, 2);/*stderr*/
4190 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
4191 SCHEMA_FILE, NULL) < 0) {
4192 _LOGE("execl error\n");
4202 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
4206 _LOGE("waitpid failed\n");
4212 if(WIFEXITED(status) && !WEXITSTATUS(status))