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_resolution(resolution_x *resolution);
142 static void __ps_free_request(request_x *request);
143 static void __ps_free_define(define_x *define);
144 static void __ps_free_appsvc(appsvc_x *appsvc);
145 static void __ps_free_launchconditions(launchconditions_x *launchconditions);
146 static void __ps_free_datashare(datashare_x *datashare);
147 static void __ps_free_icon(icon_x *icon);
148 static void __ps_free_author(author_x *author);
149 static void __ps_free_description(description_x *description);
150 static void __ps_free_capability(capability_x *capability);
151 static void __ps_free_license(license_x *license);
152 static void __ps_free_appcontrol(appcontrol_x *appcontrol);
153 static void __ps_free_datacontrol(datacontrol_x *datacontrol);
154 static void __ps_free_uiapplication(uiapplication_x *uiapplication);
155 static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication);
156 static void __ps_free_font(font_x *font);
157 static void __ps_free_theme(theme_x *theme);
158 static void __ps_free_daemon(daemon_x *daemon);
159 static void __ps_free_ime(ime_x *ime);
160 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid);
161 static int __next_child_element(xmlTextReaderPtr reader, int depth);
162 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
163 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
164 static void __str_trim(char *input);
165 static char *__get_parser_plugin(const char *type);
166 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
167 static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid);
168 static void __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], const char *pkgid);
169 static void __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid);
170 API int __is_admin();
172 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, const char **xml_attribute, char *default_value)
174 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
176 *xml_attribute = strdup((const char *)attrib_val);
179 if (default_value != NULL) {
180 *xml_attribute = strdup(default_value);
185 static void __save_xml_lang(xmlTextReaderPtr reader, const char **xml_attribute)
187 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
188 if (attrib_val != NULL)
189 *xml_attribute = strdup(ASCII(attrib_val));
191 *xml_attribute = strdup(DEFAULT_LOCALE);
194 static void __save_xml_value(xmlTextReaderPtr reader, const char **xml_attribute)
196 xmlTextReaderRead(reader);
197 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
200 *xml_attribute = strdup((const char *)attrib_val);
203 static void __save_xml_installed_time(manifest_x *mfx)
205 char buf[PKG_STRING_LEN_MAX] = {'\0'};
209 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
210 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
211 mfx->installed_time = val;
214 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
216 char root[PKG_STRING_LEN_MAX] = { '\0' };
222 tzplatform_set_user(uid);
223 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
224 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
226 mfx->root_path = strdup(root);
228 tzplatform_reset_user();
231 static void __save_xml_default_value(manifest_x * mfx)
233 mfx->preload = strdup("False");
234 mfx->removable = strdup("True");
235 mfx->readonly = strdup("False");
236 mfx->update = strdup("False");
237 mfx->system = strdup("False");
238 mfx->installed_storage= strdup("installed_internal");
239 package = mfx->package;
242 void *__open_lib_handle(char *tag)
244 char *lib_path = NULL;
245 void *lib_handle = NULL;
247 lib_path = __get_parser_plugin(tag);
248 retvm_if(!lib_path, NULL, "lib_path get fail");
250 lib_handle = dlopen(lib_path, RTLD_LAZY);
251 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
256 void __close_lib_handle(void *lib_handle)
261 static void __str_trim(char *input)
263 char *trim_str = input;
268 while (*input != 0) {
269 if (!isspace(*input)) {
282 uid_t uid = getuid();
283 if ((uid_t) 0 == uid )
291 static char * __get_tag_by_key(char *md_key)
295 if (md_key == NULL) {
296 _LOGD("md_key is NULL\n");
300 md_tag = strrchr(md_key, 47) + 1;
303 return strdup(md_tag);
306 static char *__get_metadata_parser_plugin(const char *type)
309 char buffer[1024] = { 0 };
310 char temp_path[1024] = { 0 };
314 _LOGE("invalid argument\n");
318 fp = fopen(PKG_PARSER_CONF_PATH, "r");
320 _LOGE("no matching metadata parser\n");
324 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
325 if (buffer[0] == '#')
330 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
331 path = path + strlen(METADATA_PARSER_NAME);
336 memset(buffer, 0x00, 1024);
343 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME,type);
347 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
349 return strdup(temp_path);
352 static char *__get_category_parser_plugin(const char *type)
355 char buffer[1024] = { 0 };
356 char temp_path[1024] = { 0 };
360 _LOGE("invalid argument\n");
364 fp = fopen(PKG_PARSER_CONF_PATH, "r");
366 _LOGE("no matching metadata parser\n");
370 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
371 if (buffer[0] == '#')
376 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
377 path = path + strlen(CATEGORY_PARSER_NAME);
382 memset(buffer, 0x00, 1024);
389 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
393 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
395 return strdup(temp_path);
398 static char *__get_parser_plugin(const char *type)
401 char buffer[1024] = { 0 };
402 char temp_path[1024] = { 0 };
406 _LOGE("invalid argument\n");
410 fp = fopen(PKG_PARSER_CONF_PATH, "r");
412 _LOGE("no matching backendlib\n");
416 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
417 if (buffer[0] == '#')
422 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
423 path = path + strlen(PKG_PARSERLIB);
427 memset(buffer, 0x00, 1024);
434 _LOGE("no matching backendlib\n");
438 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
440 return strdup(temp_path);
443 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
444 ACTION_TYPE action, const char *pkgid)
446 int (*plugin_install) (xmlDocPtr, const char *);
452 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
455 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
457 case ACTION_UNINSTALL:
458 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
464 if ((plugin_install =
465 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
466 _LOGE("can not find symbol[%s] \n", ac);
470 ret = plugin_install(docPtr, pkgid);
471 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
477 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
478 ACTION_TYPE action, const char *pkgid, const char *appid)
480 char *lib_path = NULL;
481 void *lib_handle = NULL;
482 int (*metadata_parser_plugin) (const char *, const char *, GList *);
488 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
491 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
493 case ACTION_UNINSTALL:
494 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
500 lib_path = __get_metadata_parser_plugin(tag);
502 _LOGE("get %s parser fail\n", tag);
506 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
507 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
511 if ((metadata_parser_plugin =
512 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
513 _LOGE("can not find symbol[%s] \n",ac);
517 ret = metadata_parser_plugin(pkgid, appid, md_list);
519 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
521 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
531 static int __ps_run_category_parser(GList *category_list, const char *tag,
532 ACTION_TYPE action, const char *pkgid, const char *appid)
534 char *lib_path = NULL;
535 void *lib_handle = NULL;
536 int (*category_parser_plugin) (const char *, const char *, GList *);
542 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
545 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
547 case ACTION_UNINSTALL:
548 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
554 lib_path = __get_category_parser_plugin(tag);
556 _LOGE("get %s parser fail\n", tag);
560 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
561 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
565 if ((category_parser_plugin =
566 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
567 _LOGE("can not find symbol[%s] \n",ac);
571 ret = category_parser_plugin(pkgid, appid, category_list);
573 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
575 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
585 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
586 ACTION_TYPE action, const char *pkgid)
588 char *lib_path = NULL;
589 void *lib_handle = NULL;
590 int (*plugin_install) (xmlDocPtr, const char *);
596 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
599 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
601 case ACTION_UNINSTALL:
602 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
608 lib_path = __get_parser_plugin(tag);
613 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
614 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
617 if ((plugin_install =
618 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
619 _LOGE("can not find symbol[%s] \n", ac);
623 ret = plugin_install(docPtr, pkgid);
625 _LOGD("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
627 _LOGD("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
637 static char *__pkgid_to_manifest(const char *pkgid, uid_t uid)
643 _LOGE("pkgid is NULL");
647 size = strlen(getUserManifestPath(uid)) + strlen(pkgid) + 10;
648 manifest = malloc(size);
649 if (manifest == NULL) {
653 memset(manifest, '\0', size);
654 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
656 if (access(manifest, F_OK)) {
657 snprintf(manifest, size, "%s%s.xml", getUserManifestPath(uid), pkgid);
663 static void __metadata_parser_clear_dir_list(GList* dir_list)
666 __metadata_t* detail = NULL;
669 list = g_list_first(dir_list);
671 detail = (__metadata_t *)list->data;
679 list = g_list_next(list);
681 g_list_free(dir_list);
685 static void __category_parser_clear_dir_list(GList* dir_list)
688 __category_t* detail = NULL;
691 list = g_list_first(dir_list);
693 detail = (__category_t *)list->data;
700 list = g_list_next(list);
702 g_list_free(dir_list);
706 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
711 if (xmlTextReaderDepth(reader) != 1) {
712 _LOGE("Node depth is not 1");
716 if (xmlTextReaderNodeType(reader) != 1) {
717 _LOGE("Node type is not 1");
721 const xmlChar *value;
722 name = xmlTextReaderConstName(reader);
724 _LOGE("TEST TEST TES\n");
725 name = BAD_CAST "--";
728 value = xmlTextReaderConstValue(reader);
730 if (xmlStrlen(value) > 40) {
731 _LOGD(" %.40s...", value);
737 name = xmlTextReaderConstName(reader);
739 _LOGE("TEST TEST TES\n");
740 name = BAD_CAST "--";
743 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
744 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
745 if (copyDocPtr == NULL)
747 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
748 if (rootElement == NULL)
750 xmlNode *cur_node = xmlFirstElementChild(rootElement);
751 if (cur_node == NULL)
753 xmlNode *temp = xmlTextReaderExpand(reader);
756 xmlNode *next_node = NULL;
757 while(cur_node != NULL) {
758 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
759 (temp->line == cur_node->line) ) {
763 next_node = xmlNextElementSibling(cur_node);
764 xmlUnlinkNode(cur_node);
765 xmlFreeNode(cur_node);
766 cur_node = next_node;
769 if (cur_node == NULL)
771 next_node = xmlNextElementSibling(cur_node);
773 cur_node->next = NULL;
774 next_node->prev = NULL;
775 xmlFreeNodeList(next_node);
776 xmlSetTreeDoc(cur_node, copyDocPtr);
778 xmlSetTreeDoc(cur_node, copyDocPtr);
781 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
787 static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
791 char buffer[1024] = { 0, };
792 uiapplication_x *up = mfx->uiapplication;
793 metadata_x *md = NULL;
796 GList *md_list = NULL;
797 __metadata_t *md_detail = NULL;
799 md_tag = __get_tag_by_key(md_key);
800 if (md_tag == NULL) {
801 _LOGD("md_tag is NULL\n");
810 //get glist of metadata key and value combination
811 memset(buffer, 0x00, 1024);
812 snprintf(buffer, 1024, "%s/", md_key);
813 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
814 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
815 if (md_detail == NULL) {
816 _LOGD("Memory allocation failed\n");
820 md_detail->key = (char*) calloc(1, sizeof(char)*(strlen(md->key)+2));
821 if (md_detail->key == NULL) {
822 _LOGD("Memory allocation failed\n");
826 snprintf(md_detail->key, (strlen(md->key)+1), "%s", md->key);
828 md_detail->value = (char*) calloc(1, sizeof(char)*(strlen(md->value)+2));
829 if (md_detail->value == NULL) {
830 _LOGD("Memory allocation failed\n");
831 free(md_detail->key);
835 snprintf(md_detail->value, (strlen(md->value)+1), "%s", md->value);
837 md_list = g_list_append(md_list, (gpointer)md_detail);
843 //send glist to parser when tags for metadata plugin parser exist.
845 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, up->appid);
847 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
850 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
853 __metadata_parser_clear_dir_list(md_list);
861 __metadata_parser_clear_dir_list(md_list);
869 static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
873 char buffer[1024] = { 0, };
874 uiapplication_x *up = mfx->uiapplication;
875 category_x *category = NULL;
876 char *category_tag = NULL;
878 GList *category_list = NULL;
879 __category_t *category_detail = NULL;
881 category_tag = __get_tag_by_key(category_key);
882 if (category_tag == NULL) {
883 _LOGD("md_tag is NULL\n");
889 category = up->category;
890 while (category != NULL)
892 //get glist of category key and value combination
893 memset(buffer, 0x00, 1024);
894 snprintf(buffer, 1024, "%s/", category_key);
895 if ((category->name) && (strncmp(category->name, category_key, strlen(category_key)) == 0)) {
896 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
897 if (category_detail == NULL) {
898 _LOGD("Memory allocation failed\n");
902 category_detail->name = (char*) calloc(1, sizeof(char)*(strlen(category->name)+2));
903 if (category_detail->name == NULL) {
904 _LOGD("Memory allocation failed\n");
905 free(category_detail);
908 snprintf(category_detail->name, (strlen(category->name)+1), "%s", category->name);
910 category_list = g_list_append(category_list, (gpointer)category_detail);
913 category = category->next;
916 //send glist to parser when tags for metadata plugin parser exist.
918 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, up->appid);
920 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
922 _LOGD("category_parser success for tag[%s]\n", category_tag);
924 __category_parser_clear_dir_list(category_list);
925 category_list = NULL;
932 __category_parser_clear_dir_list(category_list);
940 static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
945 // _LOGD("__run_parser_prestep");
947 if (xmlTextReaderDepth(reader) != 1) {
948 _LOGE("Node depth is not 1");
952 if (xmlTextReaderNodeType(reader) != 1) {
953 _LOGE("Node type is not 1");
957 const xmlChar *value;
958 name = xmlTextReaderConstName(reader);
960 _LOGE("TEST TEST TES\n");
961 name = BAD_CAST "--";
964 value = xmlTextReaderConstValue(reader);
965 _LOGD("%d %d %s %d %d",
966 xmlTextReaderDepth(reader),
967 xmlTextReaderNodeType(reader),
969 xmlTextReaderIsEmptyElement(reader), xmlTextReaderHasValue(reader));
972 if (xmlStrlen(value) > 40) {
973 _LOGD(" %.40s...", value);
979 name = xmlTextReaderConstName(reader);
981 _LOGE("TEST TEST TES\n");
982 name = BAD_CAST "--";
985 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
986 _LOGD("docPtr->URL %s\n", (char *)docPtr->URL);
987 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
988 if (copyDocPtr == NULL)
990 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
991 if (rootElement == NULL)
993 xmlNode *cur_node = xmlFirstElementChild(rootElement);
994 if (cur_node == NULL)
996 xmlNode *temp = xmlTextReaderExpand(reader);
999 xmlNode *next_node = NULL;
1000 while(cur_node != NULL) {
1001 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
1002 (temp->line == cur_node->line) ) {
1006 next_node = xmlNextElementSibling(cur_node);
1007 xmlUnlinkNode(cur_node);
1008 xmlFreeNode(cur_node);
1009 cur_node = next_node;
1012 if (cur_node == NULL)
1014 next_node = xmlNextElementSibling(cur_node);
1016 cur_node->next = NULL;
1017 next_node->prev = NULL;
1018 xmlFreeNodeList(next_node);
1019 xmlSetTreeDoc(cur_node, copyDocPtr);
1021 xmlSetTreeDoc(cur_node, copyDocPtr);
1027 _LOGD("node type: %d, name: %s children->name: %s last->name: %s\n"
1028 "parent->name: %s next->name: %s prev->name: %s\n",
1029 cur_node->type, cur_node->name,
1030 cur_node->children ? cur_node->children->name : "NULL",
1031 cur_node->last ? cur_node->last->name : "NULL",
1032 cur_node->parent ? cur_node->parent->name : "NULL",
1033 cur_node->next ? cur_node->next->name : "NULL",
1034 cur_node->prev ? cur_node->prev->name : "NULL");
1036 FILE *fp = fopen(tzplatform_mkpath(TZ_SYS_SHARE, "test.xml"), "a");
1037 xmlDocDump(fp, copyDocPtr);
1041 ret = __ps_run_parser(copyDocPtr, ASCII(name), action, pkgid);
1048 __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], const char *pkgid)
1053 switch (xmlTextReaderNodeType(reader)) {
1054 case XML_READER_TYPE_END_ELEMENT:
1056 // _LOGD("XML_READER_TYPE_END_ELEMENT");
1060 case XML_READER_TYPE_ELEMENT:
1062 // Elements without closing tag don't receive
1063 // XML_READER_TYPE_END_ELEMENT event.
1065 const xmlChar *elementName =
1066 xmlTextReaderLocalName(reader);
1067 if (elementName == NULL) {
1068 // _LOGD("elementName %s\n", (char *)elementName);
1072 const xmlChar *nameSpace =
1073 xmlTextReaderConstNamespaceUri(reader);
1075 // _LOGD("nameSpace %s\n", (char *)nameSpace);
1078 _LOGD("XML_READER_TYPE_ELEMENT %s, %s\n",
1079 elementName ? elementName : "NULL",
1080 nameSpace ? nameSpace : "NULL");
1083 _LOGD("__run_parser_prestep pkgid[%s]\n", pkgid);
1084 __run_parser_prestep(reader, action, pkgid);
1088 for (tag = tagv[0]; tag; tag = tagv[++i])
1089 if (strcmp(tag, ASCII(elementName)) == 0) {
1090 _LOGD("__run_parser_prestep tag[%s] pkgid[%s]\n", tag, pkgid);
1091 __run_parser_prestep(reader,
1099 case XML_READER_TYPE_TEXT:
1100 case XML_READER_TYPE_CDATA:
1102 const xmlChar *value = xmlTextReaderConstValue(reader);
1104 // _LOGD("value %s\n", value);
1107 const xmlChar *lang = xmlTextReaderConstXmlLang(reader);
1109 // _LOGD("lang\n", lang);
1112 /* _LOGD("XML_READER_TYPE_TEXT %s, %s\n",
1113 value ? value : "NULL", lang ? lang : "NULL");
1118 // _LOGD("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
1124 __processTag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
1126 switch (xmlTextReaderNodeType(reader)) {
1127 case XML_READER_TYPE_END_ELEMENT:
1131 case XML_READER_TYPE_ELEMENT:
1133 // Elements without closing tag don't receive
1134 const xmlChar *elementName =
1135 xmlTextReaderLocalName(reader);
1136 if (elementName == NULL) {
1140 if (strcmp(tag, ASCII(elementName)) == 0) {
1141 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
1142 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
1153 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1155 int (*plugin_install) (const char *);
1159 if (process == PLUGIN_PRE_PROCESS) {
1161 case ACTION_INSTALL:
1162 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
1164 case ACTION_UPGRADE:
1165 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
1167 case ACTION_UNINSTALL:
1168 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
1173 } else if (process == PLUGIN_POST_PROCESS) {
1175 case ACTION_INSTALL:
1176 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
1178 case ACTION_UPGRADE:
1179 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
1181 case ACTION_UNINSTALL:
1182 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
1190 if ((plugin_install =
1191 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1195 ret = plugin_install(pkgid);
1199 static void __plugin_send_tag(const char *tag, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1201 char *lib_path = NULL;
1202 void *lib_handle = NULL;
1203 int (*plugin_install) (const char *);
1207 if (process == PLUGIN_PRE_PROCESS) {
1209 case ACTION_INSTALL:
1210 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
1212 case ACTION_UPGRADE:
1213 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
1215 case ACTION_UNINSTALL:
1216 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
1221 } else if (process == PLUGIN_POST_PROCESS) {
1223 case ACTION_INSTALL:
1224 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
1226 case ACTION_UPGRADE:
1227 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
1229 case ACTION_UNINSTALL:
1230 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
1238 lib_path = __get_parser_plugin(tag);
1243 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1244 _LOGE("dlopen is failed lib_path[%s] for tag[%s]\n", lib_path, tag);
1247 if ((plugin_install =
1248 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1249 // _LOGE("can not find symbol[%s] for tag[%s] \n", ac, tag);
1253 ret = plugin_install(pkgid);
1255 _LOGD("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin fail\n", process, pkgid, tag);
1257 _LOGD("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin success\n", process, pkgid, tag);
1263 dlclose(lib_handle);
1267 __plugin_process_tag(char *const tag_list[], ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1272 for (tag = tag_list[0]; tag; tag = tag_list[++i])
1273 __plugin_send_tag(tag, action, process, pkgid);
1278 __plugin_save_tag(xmlTextReaderPtr reader, char *const tagv[], char *tag_list[])
1282 static int pre_cnt=0;
1284 switch (xmlTextReaderNodeType(reader)) {
1285 case XML_READER_TYPE_ELEMENT:
1287 const xmlChar *elementName = xmlTextReaderLocalName(reader);
1288 if (elementName == NULL) {
1292 for (tag = tag_list[0]; tag; tag = tag_list[++i])
1293 if (strcmp(ASCII(elementName), tag) == 0) {
1297 for (tag = tagv[0]; tag; tag = tagv[++i])
1298 if (strcmp(tag, ASCII(elementName)) == 0) {
1299 tag_list[pre_cnt++] = tag;
1305 // _LOGD("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
1311 __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid)
1313 xmlTextReaderPtr reader;
1316 __plugin_process_tag(tagv, action, PLUGIN_PRE_PROCESS, pkgid);
1318 docPtr = xmlReadFile(filename, NULL, 0);
1319 reader = xmlReaderWalker(docPtr);
1320 if (reader != NULL) {
1321 ret = xmlTextReaderRead(reader);
1323 __processNode(reader, action, tagv, pkgid);
1324 ret = xmlTextReaderRead(reader);
1326 xmlFreeTextReader(reader);
1329 _LOGD("%s : failed to parse", filename);
1332 _LOGD("Unable to open %s", filename);
1335 __plugin_process_tag(tagv, action, PLUGIN_POST_PROCESS, pkgid);
1338 static int __next_child_element(xmlTextReaderPtr reader, int depth)
1340 int ret = xmlTextReaderRead(reader);
1341 int cur = xmlTextReaderDepth(reader);
1344 switch (xmlTextReaderNodeType(reader)) {
1345 case XML_READER_TYPE_ELEMENT:
1346 if (cur == depth + 1)
1349 case XML_READER_TYPE_TEXT:
1350 /*text is handled by each function separately*/
1351 if (cur == depth + 1)
1354 case XML_READER_TYPE_END_ELEMENT:
1363 ret = xmlTextReaderRead(reader);
1364 cur = xmlTextReaderDepth(reader);
1369 static bool __check_action_fota(char *const tagv[])
1372 char delims[] = "=";
1373 char *ret_result = NULL;
1380 for (tag = strdup(tagv[0]); tag != NULL; ) {
1381 ret_result = strtok(tag, delims);
1383 /*check tag : fota is true */
1384 if (strcmp(ret_result, "fota") == 0) {
1385 ret_result = strtok(NULL, delims);
1386 if (strcmp(ret_result, "true") == 0) {
1390 _LOGD("tag process [%s]is not defined\n", ret_result);
1394 /*check next value*/
1395 if (tagv[++i] != NULL)
1396 tag = strdup(tagv[i]);
1398 _LOGD("tag process success...%d\n" , ret);
1406 static void __ps_free_category(category_x *category)
1408 if (category == NULL)
1410 if (category->name) {
1411 free((void *)category->name);
1412 category->name = NULL;
1414 free((void*)category);
1418 static void __ps_free_privilege(privilege_x *privilege)
1420 if (privilege == NULL)
1422 if (privilege->text) {
1423 free((void *)privilege->text);
1424 privilege->text = NULL;
1426 free((void*)privilege);
1430 static void __ps_free_privileges(privileges_x *privileges)
1432 if (privileges == NULL)
1435 if (privileges->privilege) {
1436 privilege_x *privilege = privileges->privilege;
1437 privilege_x *tmp = NULL;
1438 while(privilege != NULL) {
1439 tmp = privilege->next;
1440 __ps_free_privilege(privilege);
1444 free((void*)privileges);
1448 static void __ps_free_metadata(metadata_x *metadata)
1450 if (metadata == NULL)
1452 if (metadata->key) {
1453 free((void *)metadata->key);
1454 metadata->key = NULL;
1456 if (metadata->value) {
1457 free((void *)metadata->value);
1458 metadata->value = NULL;
1460 free((void*)metadata);
1464 static void __ps_free_permission(permission_x *permission)
1466 if (permission == NULL)
1468 if (permission->type) {
1469 free((void *)permission->type);
1470 permission->type = NULL;
1472 if (permission->value) {
1473 free((void *)permission->value);
1474 permission->value = NULL;
1476 free((void*)permission);
1480 static void __ps_free_icon(icon_x *icon)
1485 free((void *)icon->text);
1489 free((void *)icon->lang);
1493 free((void *)icon->name);
1496 if (icon->section) {
1497 free((void *)icon->section);
1498 icon->section = NULL;
1501 free((void *)icon->size);
1504 if (icon->resolution) {
1505 free((void *)icon->resolution);
1506 icon->resolution = NULL;
1512 static void __ps_free_image(image_x *image)
1517 free((void *)image->text);
1521 free((void *)image->lang);
1525 free((void *)image->name);
1528 if (image->section) {
1529 free((void *)image->section);
1530 image->section = NULL;
1536 static void __ps_free_operation(operation_x *operation)
1538 if (operation == NULL)
1540 if (operation->text) {
1541 free((void *)operation->text);
1542 operation->text = NULL;
1544 free((void*)operation);
1548 static void __ps_free_uri(uri_x *uri)
1553 free((void *)uri->text);
1560 static void __ps_free_mime(mime_x *mime)
1565 free((void *)mime->text);
1572 static void __ps_free_subapp(subapp_x *subapp)
1577 free((void *)subapp->text);
1578 subapp->text = NULL;
1580 free((void*)subapp);
1584 static void __ps_free_condition(condition_x *condition)
1586 if (condition == NULL)
1588 if (condition->text) {
1589 free((void *)condition->text);
1590 condition->text = NULL;
1592 if (condition->name) {
1593 free((void *)condition->name);
1594 condition->name = NULL;
1596 free((void*)condition);
1600 static void __ps_free_notification(notification_x *notification)
1602 if (notification == NULL)
1604 if (notification->text) {
1605 free((void *)notification->text);
1606 notification->text = NULL;
1608 if (notification->name) {
1609 free((void *)notification->name);
1610 notification->name = NULL;
1612 free((void*)notification);
1613 notification = NULL;
1616 static void __ps_free_compatibility(compatibility_x *compatibility)
1618 if (compatibility == NULL)
1620 if (compatibility->text) {
1621 free((void *)compatibility->text);
1622 compatibility->text = NULL;
1624 if (compatibility->name) {
1625 free((void *)compatibility->name);
1626 compatibility->name = NULL;
1628 free((void*)compatibility);
1629 compatibility = NULL;
1632 static void __ps_free_resolution(resolution_x *resolution)
1634 if (resolution == NULL)
1636 if (resolution->mimetype) {
1637 free((void *)resolution->mimetype);
1638 resolution->mimetype = NULL;
1640 if (resolution->urischeme) {
1641 free((void *)resolution->urischeme);
1642 resolution->urischeme = NULL;
1644 free((void*)resolution);
1648 static void __ps_free_capability(capability_x *capability)
1650 if (capability == NULL)
1652 if (capability->operationid) {
1653 free((void *)capability->operationid);
1654 capability->operationid = NULL;
1657 if (capability->resolution) {
1658 resolution_x *resolution = capability->resolution;
1659 resolution_x *tmp = NULL;
1660 while(resolution != NULL) {
1661 tmp = resolution->next;
1662 __ps_free_resolution(resolution);
1666 free((void*)capability);
1670 static void __ps_free_allowed(allowed_x *allowed)
1672 if (allowed == NULL)
1674 if (allowed->name) {
1675 free((void *)allowed->name);
1676 allowed->name = NULL;
1678 if (allowed->text) {
1679 free((void *)allowed->text);
1680 allowed->text = NULL;
1682 free((void*)allowed);
1686 static void __ps_free_request(request_x *request)
1688 if (request == NULL)
1690 if (request->text) {
1691 free((void *)request->text);
1692 request->text = NULL;
1694 free((void*)request);
1698 static void __ps_free_datacontrol(datacontrol_x *datacontrol)
1700 if (datacontrol == NULL)
1702 if (datacontrol->providerid) {
1703 free((void *)datacontrol->providerid);
1704 datacontrol->providerid = NULL;
1706 if (datacontrol->access) {
1707 free((void *)datacontrol->access);
1708 datacontrol->access = NULL;
1710 if (datacontrol->type) {
1711 free((void *)datacontrol->type);
1712 datacontrol->type = NULL;
1714 free((void*)datacontrol);
1718 static void __ps_free_launchconditions(launchconditions_x *launchconditions)
1720 if (launchconditions == NULL)
1722 if (launchconditions->text) {
1723 free((void *)launchconditions->text);
1724 launchconditions->text = NULL;
1727 if (launchconditions->condition) {
1728 condition_x *condition = launchconditions->condition;
1729 condition_x *tmp = NULL;
1730 while(condition != NULL) {
1731 tmp = condition->next;
1732 __ps_free_condition(condition);
1736 free((void*)launchconditions);
1737 launchconditions = NULL;
1740 static void __ps_free_appcontrol(appcontrol_x *appcontrol)
1742 if (appcontrol == NULL)
1745 if (appcontrol->operation)
1746 free(appcontrol->operation);
1748 if (appcontrol->uri)
1749 free(appcontrol->uri);
1751 if (appcontrol->mime)
1752 free(appcontrol->mime);
1753 free((void*)appcontrol);
1757 static void __ps_free_appsvc(appsvc_x *appsvc)
1762 free((void *)appsvc->text);
1763 appsvc->text = NULL;
1766 if (appsvc->operation) {
1767 operation_x *operation = appsvc->operation;
1768 operation_x *tmp = NULL;
1769 while(operation != NULL) {
1770 tmp = operation->next;
1771 __ps_free_operation(operation);
1777 uri_x *uri = appsvc->uri;
1779 while(uri != NULL) {
1787 mime_x *mime = appsvc->mime;
1789 while(mime != NULL) {
1791 __ps_free_mime(mime);
1796 if (appsvc->subapp) {
1797 subapp_x *subapp = appsvc->subapp;
1798 subapp_x *tmp = NULL;
1799 while(subapp != NULL) {
1801 __ps_free_subapp(subapp);
1805 free((void*)appsvc);
1809 static void __ps_free_deviceprofile(deviceprofile_x *deviceprofile)
1814 static void __ps_free_define(define_x *define)
1819 free((void *)define->path);
1820 define->path = NULL;
1823 if (define->request) {
1824 request_x *request = define->request;
1825 request_x *tmp = NULL;
1826 while(request != NULL) {
1827 tmp = request->next;
1828 __ps_free_request(request);
1833 if (define->allowed) {
1834 allowed_x *allowed = define->allowed;
1835 allowed_x *tmp = NULL;
1836 while(allowed != NULL) {
1837 tmp = allowed->next;
1838 __ps_free_allowed(allowed);
1842 free((void*)define);
1846 static void __ps_free_datashare(datashare_x *datashare)
1848 if (datashare == NULL)
1851 if (datashare->define) {
1852 define_x *define = datashare->define;
1853 define_x *tmp = NULL;
1854 while(define != NULL) {
1856 __ps_free_define(define);
1861 if (datashare->request) {
1862 request_x *request = datashare->request;
1863 request_x *tmp = NULL;
1864 while(request != NULL) {
1865 tmp = request->next;
1866 __ps_free_request(request);
1870 free((void*)datashare);
1874 static void __ps_free_label(label_x *label)
1879 free((void *)label->name);
1883 free((void *)label->text);
1887 free((void *)label->lang);
1894 static void __ps_free_author(author_x *author)
1898 if (author->email) {
1899 free((void *)author->email);
1900 author->email = NULL;
1903 free((void *)author->text);
1904 author->text = NULL;
1907 free((void *)author->href);
1908 author->href = NULL;
1911 free((void *)author->lang);
1912 author->lang = NULL;
1914 free((void*)author);
1918 static void __ps_free_description(description_x *description)
1920 if (description == NULL)
1922 if (description->name) {
1923 free((void *)description->name);
1924 description->name = NULL;
1926 if (description->text) {
1927 free((void *)description->text);
1928 description->text = NULL;
1930 if (description->lang) {
1931 free((void *)description->lang);
1932 description->lang = NULL;
1934 free((void*)description);
1938 static void __ps_free_license(license_x *license)
1940 if (license == NULL)
1942 if (license->text) {
1943 free((void *)license->text);
1944 license->text = NULL;
1946 if (license->lang) {
1947 free((void *)license->lang);
1948 license->lang = NULL;
1950 free((void*)license);
1954 static void __ps_free_uiapplication(uiapplication_x *uiapplication)
1956 if (uiapplication == NULL)
1958 if (uiapplication->exec) {
1959 free((void *)uiapplication->exec);
1960 uiapplication->exec = NULL;
1962 if (uiapplication->appid) {
1963 free((void *)uiapplication->appid);
1964 uiapplication->appid = NULL;
1966 if (uiapplication->nodisplay) {
1967 free((void *)uiapplication->nodisplay);
1968 uiapplication->nodisplay = NULL;
1970 if (uiapplication->multiple) {
1971 free((void *)uiapplication->multiple);
1972 uiapplication->multiple = NULL;
1974 if (uiapplication->type) {
1975 free((void *)uiapplication->type);
1976 uiapplication->type = NULL;
1978 if (uiapplication->categories) {
1979 free((void *)uiapplication->categories);
1980 uiapplication->categories = NULL;
1982 if (uiapplication->extraid) {
1983 free((void *)uiapplication->extraid);
1984 uiapplication->extraid = NULL;
1986 if (uiapplication->taskmanage) {
1987 free((void *)uiapplication->taskmanage);
1988 uiapplication->taskmanage = NULL;
1990 if (uiapplication->enabled) {
1991 free((void *)uiapplication->enabled);
1992 uiapplication->enabled = NULL;
1994 if (uiapplication->hwacceleration) {
1995 free((void *)uiapplication->hwacceleration);
1996 uiapplication->hwacceleration = NULL;
1998 if (uiapplication->screenreader) {
1999 free((void *)uiapplication->screenreader);
2000 uiapplication->screenreader = NULL;
2002 if (uiapplication->mainapp) {
2003 free((void *)uiapplication->mainapp);
2004 uiapplication->mainapp = NULL;
2006 if (uiapplication->recentimage) {
2007 free((void *)uiapplication->recentimage);
2008 uiapplication->recentimage = NULL;
2010 if (uiapplication->package) {
2011 free((void *)uiapplication->package);
2012 uiapplication->package = NULL;
2014 if (uiapplication->launchcondition) {
2015 free((void *)uiapplication->launchcondition);
2016 uiapplication->launchcondition = NULL;
2019 if (uiapplication->label) {
2020 label_x *label = uiapplication->label;
2021 label_x *tmp = NULL;
2022 while(label != NULL) {
2024 __ps_free_label(label);
2029 if (uiapplication->icon) {
2030 icon_x *icon = uiapplication->icon;
2032 while(icon != NULL) {
2034 __ps_free_icon(icon);
2039 if (uiapplication->image) {
2040 image_x *image = uiapplication->image;
2041 image_x *tmp = NULL;
2042 while(image != NULL) {
2044 __ps_free_image(image);
2049 if (uiapplication->appcontrol) {
2050 appcontrol_x *appcontrol = uiapplication->appcontrol;
2051 appcontrol_x *tmp = NULL;
2052 while(appcontrol != NULL) {
2053 tmp = appcontrol->next;
2054 __ps_free_appcontrol(appcontrol);
2058 /*Free LaunchConditions*/
2059 if (uiapplication->launchconditions) {
2060 launchconditions_x *launchconditions = uiapplication->launchconditions;
2061 launchconditions_x *tmp = NULL;
2062 while(launchconditions != NULL) {
2063 tmp = launchconditions->next;
2064 __ps_free_launchconditions(launchconditions);
2065 launchconditions = tmp;
2068 /*Free Notification*/
2069 if (uiapplication->notification) {
2070 notification_x *notification = uiapplication->notification;
2071 notification_x *tmp = NULL;
2072 while(notification != NULL) {
2073 tmp = notification->next;
2074 __ps_free_notification(notification);
2079 if (uiapplication->datashare) {
2080 datashare_x *datashare = uiapplication->datashare;
2081 datashare_x *tmp = NULL;
2082 while(datashare != NULL) {
2083 tmp = datashare->next;
2084 __ps_free_datashare(datashare);
2089 if (uiapplication->appsvc) {
2090 appsvc_x *appsvc = uiapplication->appsvc;
2091 appsvc_x *tmp = NULL;
2092 while(appsvc != NULL) {
2094 __ps_free_appsvc(appsvc);
2099 if (uiapplication->category) {
2100 category_x *category = uiapplication->category;
2101 category_x *tmp = NULL;
2102 while(category != NULL) {
2103 tmp = category->next;
2104 __ps_free_category(category);
2109 if (uiapplication->metadata) {
2110 metadata_x *metadata = uiapplication->metadata;
2111 metadata_x *tmp = NULL;
2112 while(metadata != NULL) {
2113 tmp = metadata->next;
2114 __ps_free_metadata(metadata);
2119 if (uiapplication->permission) {
2120 permission_x *permission = uiapplication->permission;
2121 permission_x *tmp = NULL;
2122 while(permission != NULL) {
2123 tmp = permission->next;
2124 __ps_free_permission(permission);
2128 /*Free DataControl*/
2129 if (uiapplication->datacontrol) {
2130 datacontrol_x *datacontrol = uiapplication->datacontrol;
2131 datacontrol_x *tmp = NULL;
2132 while(datacontrol != NULL) {
2133 tmp = datacontrol->next;
2134 __ps_free_datacontrol(datacontrol);
2138 /* _PRODUCT_LAUNCHING_ENHANCED_ START */
2139 if (uiapplication->indicatordisplay) {
2140 free((void *)uiapplication->indicatordisplay);
2141 uiapplication->indicatordisplay = NULL;
2143 if (uiapplication->portraitimg) {
2144 free((void *)uiapplication->portraitimg);
2145 uiapplication->portraitimg = NULL;
2147 if (uiapplication->landscapeimg) {
2148 free((void *)uiapplication->landscapeimg);
2149 uiapplication->landscapeimg = NULL;
2151 /* _PRODUCT_LAUNCHING_ENHANCED_ END */
2152 if (uiapplication->guestmode_visibility) {
2153 free((void *)uiapplication->guestmode_visibility);
2154 uiapplication->guestmode_visibility = NULL;
2156 if (uiapplication->app_component) {
2157 free((void *)uiapplication->app_component);
2158 uiapplication->app_component = NULL;
2160 if (uiapplication->permission_type) {
2161 free((void *)uiapplication->permission_type);
2162 uiapplication->permission_type = NULL;
2164 if (uiapplication->component_type) {
2165 free((void *)uiapplication->component_type);
2166 uiapplication->component_type = NULL;
2168 if (uiapplication->preload) {
2169 free((void *)uiapplication->preload);
2170 uiapplication->preload = NULL;
2172 if (uiapplication->submode) {
2173 free((void *)uiapplication->submode);
2174 uiapplication->submode = NULL;
2176 if (uiapplication->submode_mainid) {
2177 free((void *)uiapplication->submode_mainid);
2178 uiapplication->submode_mainid = NULL;
2181 free((void*)uiapplication);
2182 uiapplication = NULL;
2185 static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication)
2187 if (serviceapplication == NULL)
2189 if (serviceapplication->exec) {
2190 free((void *)serviceapplication->exec);
2191 serviceapplication->exec = NULL;
2193 if (serviceapplication->appid) {
2194 free((void *)serviceapplication->appid);
2195 serviceapplication->appid = NULL;
2197 if (serviceapplication->onboot) {
2198 free((void *)serviceapplication->onboot);
2199 serviceapplication->onboot = NULL;
2201 if (serviceapplication->autorestart) {
2202 free((void *)serviceapplication->autorestart);
2203 serviceapplication->autorestart = NULL;
2205 if (serviceapplication->type) {
2206 free((void *)serviceapplication->type);
2207 serviceapplication->type = NULL;
2209 if (serviceapplication->enabled) {
2210 free((void *)serviceapplication->enabled);
2211 serviceapplication->enabled = NULL;
2213 if (serviceapplication->package) {
2214 free((void *)serviceapplication->package);
2215 serviceapplication->package = NULL;
2217 if (serviceapplication->permission_type) {
2218 free((void *)serviceapplication->permission_type);
2219 serviceapplication->permission_type = NULL;
2222 if (serviceapplication->label) {
2223 label_x *label = serviceapplication->label;
2224 label_x *tmp = NULL;
2225 while(label != NULL) {
2227 __ps_free_label(label);
2232 if (serviceapplication->icon) {
2233 icon_x *icon = serviceapplication->icon;
2235 while(icon != NULL) {
2237 __ps_free_icon(icon);
2242 if (serviceapplication->appcontrol) {
2243 appcontrol_x *appcontrol = serviceapplication->appcontrol;
2244 appcontrol_x *tmp = NULL;
2245 while(appcontrol != NULL) {
2246 tmp = appcontrol->next;
2247 __ps_free_appcontrol(appcontrol);
2251 /*Free DataControl*/
2252 if (serviceapplication->datacontrol) {
2253 datacontrol_x *datacontrol = serviceapplication->datacontrol;
2254 datacontrol_x *tmp = NULL;
2255 while(datacontrol != NULL) {
2256 tmp = datacontrol->next;
2257 __ps_free_datacontrol(datacontrol);
2261 /*Free LaunchConditions*/
2262 if (serviceapplication->launchconditions) {
2263 launchconditions_x *launchconditions = serviceapplication->launchconditions;
2264 launchconditions_x *tmp = NULL;
2265 while(launchconditions != NULL) {
2266 tmp = launchconditions->next;
2267 __ps_free_launchconditions(launchconditions);
2268 launchconditions = tmp;
2271 /*Free Notification*/
2272 if (serviceapplication->notification) {
2273 notification_x *notification = serviceapplication->notification;
2274 notification_x *tmp = NULL;
2275 while(notification != NULL) {
2276 tmp = notification->next;
2277 __ps_free_notification(notification);
2282 if (serviceapplication->datashare) {
2283 datashare_x *datashare = serviceapplication->datashare;
2284 datashare_x *tmp = NULL;
2285 while(datashare != NULL) {
2286 tmp = datashare->next;
2287 __ps_free_datashare(datashare);
2292 if (serviceapplication->appsvc) {
2293 appsvc_x *appsvc = serviceapplication->appsvc;
2294 appsvc_x *tmp = NULL;
2295 while(appsvc != NULL) {
2297 __ps_free_appsvc(appsvc);
2302 if (serviceapplication->category) {
2303 category_x *category = serviceapplication->category;
2304 category_x *tmp = NULL;
2305 while(category != NULL) {
2306 tmp = category->next;
2307 __ps_free_category(category);
2312 if (serviceapplication->metadata) {
2313 metadata_x *metadata = serviceapplication->metadata;
2314 metadata_x *tmp = NULL;
2315 while(metadata != NULL) {
2316 tmp = metadata->next;
2317 __ps_free_metadata(metadata);
2322 if (serviceapplication->permission) {
2323 permission_x *permission = serviceapplication->permission;
2324 permission_x *tmp = NULL;
2325 while(permission != NULL) {
2326 tmp = permission->next;
2327 __ps_free_permission(permission);
2331 free((void*)serviceapplication);
2332 serviceapplication = NULL;
2335 static void __ps_free_font(font_x *font)
2340 free((void *)font->name);
2344 free((void *)font->text);
2351 static void __ps_free_theme(theme_x *theme)
2356 free((void *)theme->name);
2360 free((void *)theme->text);
2367 static void __ps_free_daemon(daemon_x *daemon)
2372 free((void *)daemon->name);
2373 daemon->name = NULL;
2376 free((void *)daemon->text);
2377 daemon->text = NULL;
2379 free((void*)daemon);
2383 static void __ps_free_ime(ime_x *ime)
2388 free((void *)ime->name);
2392 free((void *)ime->text);
2399 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
2401 xmlTextReaderPtr reader;
2405 void *lib_handle = NULL;
2406 char tag[PKG_STRING_LEN_MAX] = { 0 };
2408 fp = fopen(TAG_PARSER_LIST, "r");
2409 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
2411 while (fgets(tag, sizeof(tag), fp) != NULL) {
2414 lib_handle = __open_lib_handle(tag);
2415 if (lib_handle == NULL)
2418 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
2419 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
2421 docPtr = xmlReadFile(filename, NULL, 0);
2422 reader = xmlReaderWalker(docPtr);
2423 if (reader != NULL) {
2424 ret = xmlTextReaderRead(reader);
2426 __processTag(lib_handle, reader, action, tag, mfx->package);
2427 ret = xmlTextReaderRead(reader);
2429 xmlFreeTextReader(reader);
2432 _LOGD("%s : failed to parse", filename);
2435 _LOGD("Unable to open %s", filename);
2438 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
2439 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
2441 __close_lib_handle(lib_handle);
2443 memset(tag, 0x00, sizeof(tag));
2452 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
2454 fprintf(stdout,"__ps_process_metadata_parser\n");
2457 char md_key[PKG_STRING_LEN_MAX] = { 0 };
2459 fp = fopen(METADATA_PARSER_LIST, "r");
2461 _LOGD("no preload list\n");
2465 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
2467 ret = __run_metadata_parser_prestep(mfx, md_key, action);
2469 memset(md_key, 0x00, sizeof(md_key));
2478 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
2482 char category_key[PKG_STRING_LEN_MAX] = { 0 };
2484 fp = fopen(CATEGORY_PARSER_LIST, "r");
2486 _LOGD("no category parser list\n");
2490 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
2491 __str_trim(category_key);
2492 ret = __run_category_parser_prestep(mfx, category_key, action);
2494 memset(category_key, 0x00, sizeof(category_key));
2503 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed)
2505 __save_xml_value(reader, &allowed->text);
2509 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation)
2511 __save_xml_attribute(reader, "name", &operation->name, NULL);
2515 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri)
2517 __save_xml_attribute(reader, "name", &uri->name, NULL);
2521 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime)
2523 __save_xml_attribute(reader, "name", &mime->name, NULL);
2527 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp)
2529 __save_xml_attribute(reader, "name", &subapp->name, NULL);
2533 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition)
2535 __save_xml_attribute(reader, "name", &condition->name, NULL);
2539 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
2541 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
2542 __save_xml_value(reader, ¬ification->text);
2546 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category)
2548 __save_xml_attribute(reader, "name", &category->name, NULL);
2552 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
2554 __save_xml_value(reader, &privilege->text);
2558 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
2560 __save_xml_attribute(reader, "key", &metadata->key, NULL);
2561 __save_xml_attribute(reader, "value", &metadata->value, NULL);
2565 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
2567 __save_xml_attribute(reader, "type", &permission->type, NULL);
2568 __save_xml_value(reader, &permission->value);
2572 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
2574 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
2575 __save_xml_value(reader, &compatibility->text);
2579 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request)
2581 __save_xml_value(reader, &request->text);
2585 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
2587 const xmlChar *node;
2590 allowed_x *tmp1 = NULL;
2591 request_x *tmp2 = NULL;
2593 __save_xml_attribute(reader, "path", &define->path, NULL);
2595 depth = xmlTextReaderDepth(reader);
2596 while ((ret = __next_child_element(reader, depth))) {
2597 node = xmlTextReaderConstName(reader);
2599 _LOGD("xmlTextReaderConstName value is NULL\n");
2603 if (!strcmp(ASCII(node), "allowed")) {
2604 allowed_x *allowed= malloc(sizeof(allowed_x));
2605 if (allowed == NULL) {
2606 _LOGD("Malloc Failed\n");
2609 memset(allowed, '\0', sizeof(allowed_x));
2610 LISTADD(define->allowed, allowed);
2611 ret = __ps_process_allowed(reader, allowed);
2612 } else if (!strcmp(ASCII(node), "request")) {
2613 request_x *request = malloc(sizeof(request_x));
2614 if (request == NULL) {
2615 _LOGD("Malloc Failed\n");
2618 memset(request, '\0', sizeof(request_x));
2619 LISTADD(define->request, request);
2620 ret = __ps_process_request(reader, request);
2624 _LOGD("Processing define failed\n");
2628 if (define->allowed) {
2629 LISTHEAD(define->allowed, tmp1);
2630 define->allowed = tmp1;
2632 if (define->request) {
2633 LISTHEAD(define->request, tmp2);
2634 define->request = tmp2;
2639 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol)
2641 const xmlChar *node;
2645 depth = xmlTextReaderDepth(reader);
2646 while ((ret = __next_child_element(reader, depth))) {
2647 node = xmlTextReaderConstName(reader);
2649 _LOGD("xmlTextReaderConstName value is NULL\n");
2653 if (!strcmp(ASCII(node), "operation")) {
2654 __save_xml_attribute(reader, "name", &appcontrol->operation, NULL);
2655 _LOGD("operation processing\n");
2656 } else if (!strcmp(ASCII(node), "uri")) {
2657 __save_xml_attribute(reader, "name", &appcontrol->uri, NULL);
2658 _LOGD("uri processing\n");
2659 } else if (!strcmp(ASCII(node), "mime")) {
2660 __save_xml_attribute(reader, "name", &appcontrol->mime, NULL);
2661 _LOGD("mime processing\n");
2665 _LOGD("Processing appcontrol failed\n");
2673 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
2675 const xmlChar *node;
2678 operation_x *tmp1 = NULL;
2680 mime_x *tmp3 = NULL;
2681 subapp_x *tmp4 = NULL;
2683 depth = xmlTextReaderDepth(reader);
2684 while ((ret = __next_child_element(reader, depth))) {
2685 node = xmlTextReaderConstName(reader);
2687 _LOGD("xmlTextReaderConstName value is NULL\n");
2691 if (!strcmp(ASCII(node), "operation")) {
2692 operation_x *operation = malloc(sizeof(operation_x));
2693 if (operation == NULL) {
2694 _LOGD("Malloc Failed\n");
2697 memset(operation, '\0', sizeof(operation_x));
2698 LISTADD(appsvc->operation, operation);
2699 ret = __ps_process_operation(reader, operation);
2700 _LOGD("operation processing\n");
2701 } else if (!strcmp(ASCII(node), "uri")) {
2702 uri_x *uri= malloc(sizeof(uri_x));
2704 _LOGD("Malloc Failed\n");
2707 memset(uri, '\0', sizeof(uri_x));
2708 LISTADD(appsvc->uri, uri);
2709 ret = __ps_process_uri(reader, uri);
2710 _LOGD("uri processing\n");
2711 } else if (!strcmp(ASCII(node), "mime")) {
2712 mime_x *mime = malloc(sizeof(mime_x));
2714 _LOGD("Malloc Failed\n");
2717 memset(mime, '\0', sizeof(mime_x));
2718 LISTADD(appsvc->mime, mime);
2719 ret = __ps_process_mime(reader, mime);
2720 _LOGD("mime processing\n");
2721 } else if (!strcmp(ASCII(node), "subapp")) {
2722 subapp_x *subapp = malloc(sizeof(subapp_x));
2723 if (subapp == NULL) {
2724 _LOGD("Malloc Failed\n");
2727 memset(subapp, '\0', sizeof(subapp_x));
2728 LISTADD(appsvc->subapp, subapp);
2729 ret = __ps_process_subapp(reader, subapp);
2730 _LOGD("subapp processing\n");
2734 _LOGD("Processing appsvc failed\n");
2738 if (appsvc->operation) {
2739 LISTHEAD(appsvc->operation, tmp1);
2740 appsvc->operation = tmp1;
2743 LISTHEAD(appsvc->uri, tmp2);
2747 LISTHEAD(appsvc->mime, tmp3);
2748 appsvc->mime = tmp3;
2750 if (appsvc->subapp) {
2751 LISTHEAD(appsvc->subapp, tmp4);
2752 appsvc->subapp = tmp4;
2755 xmlTextReaderRead(reader);
2756 if (xmlTextReaderValue(reader))
2757 appsvc->text = ASCII(xmlTextReaderValue(reader));
2763 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges)
2765 const xmlChar *node;
2768 privilege_x *tmp1 = NULL;
2770 depth = xmlTextReaderDepth(reader);
2771 while ((ret = __next_child_element(reader, depth))) {
2772 node = xmlTextReaderConstName(reader);
2774 _LOGD("xmlTextReaderConstName value is NULL\n");
2778 if (strcmp(ASCII(node), "privilege") == 0) {
2779 privilege_x *privilege = malloc(sizeof(privilege_x));
2780 if (privilege == NULL) {
2781 _LOGD("Malloc Failed\n");
2784 memset(privilege, '\0', sizeof(privilege_x));
2785 LISTADD(privileges->privilege, privilege);
2786 ret = __ps_process_privilege(reader, privilege);
2790 _LOGD("Processing privileges failed\n");
2794 if (privileges->privilege) {
2795 LISTHEAD(privileges->privilege, tmp1);
2796 privileges->privilege = tmp1;
2801 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions)
2803 const xmlChar *node;
2806 condition_x *tmp1 = NULL;
2808 depth = xmlTextReaderDepth(reader);
2809 while ((ret = __next_child_element(reader, depth))) {
2810 node = xmlTextReaderConstName(reader);
2812 _LOGD("xmlTextReaderConstName value is NULL\n");
2816 if (strcmp(ASCII(node), "condition") == 0) {
2817 condition_x *condition = malloc(sizeof(condition_x));
2818 if (condition == NULL) {
2819 _LOGD("Malloc Failed\n");
2822 memset(condition, '\0', sizeof(condition_x));
2823 LISTADD(launchconditions->condition, condition);
2824 ret = __ps_process_condition(reader, condition);
2828 _LOGD("Processing launchconditions failed\n");
2832 if (launchconditions->condition) {
2833 LISTHEAD(launchconditions->condition, tmp1);
2834 launchconditions->condition = tmp1;
2837 __save_xml_value(reader, &launchconditions->text);
2842 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
2844 const xmlChar *node;
2847 define_x *tmp1 = NULL;
2848 request_x *tmp2 = NULL;
2849 depth = xmlTextReaderDepth(reader);
2850 while ((ret = __next_child_element(reader, depth))) {
2851 node = xmlTextReaderConstName(reader);
2853 _LOGD("xmlTextReaderConstName value is NULL\n");
2857 if (!strcmp(ASCII(node), "define")) {
2858 define_x *define= malloc(sizeof(define_x));
2859 if (define == NULL) {
2860 _LOGD("Malloc Failed\n");
2863 memset(define, '\0', sizeof(define_x));
2864 LISTADD(datashare->define, define);
2865 ret = __ps_process_define(reader, define);
2866 } else if (!strcmp(ASCII(node), "request")) {
2867 request_x *request= malloc(sizeof(request_x));
2868 if (request == NULL) {
2869 _LOGD("Malloc Failed\n");
2872 memset(request, '\0', sizeof(request_x));
2873 LISTADD(datashare->request, request);
2874 ret = __ps_process_request(reader, request);
2878 _LOGD("Processing data-share failed\n");
2882 if (datashare->define) {
2883 LISTHEAD(datashare->define, tmp1);
2884 datashare->define = tmp1;
2886 if (datashare->request) {
2887 LISTHEAD(datashare->request, tmp2);
2888 datashare->request = tmp2;
2894 __get_icon_with_path(const char* icon, uid_t uid)
2899 if (index(icon, '/') == NULL) {
2901 char* icon_with_path = NULL;
2902 char *app_path = NULL;
2908 /* "db/setting/theme" is not exist */
2910 theme = vconf_get_str("db/setting/theme");
2912 theme = strdup("default");
2918 theme = strdup("default");
2921 len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
2922 icon_with_path = malloc(len);
2923 if(icon_with_path == NULL) {
2924 _LOGD("(icon_with_path == NULL) return\n");
2929 memset(icon_with_path, 0, len);
2930 if (uid != GLOBAL_USER)
2931 snprintf(icon_with_path, len, "%s%s", getIconPath(uid), icon);
2933 snprintf(icon_with_path, len, "%s%s/small/%s", getIconPath(GLOBAL_USER), theme, icon);
2934 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
2935 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
2937 snprintf(icon_with_path, len, "%s/%q/res/icons/%q/small/%q", app_path, package, theme, icon);
2938 if (access (icon_with_path, F_OK))
2939 _LOGE("Cannot find icon path");
2943 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
2944 return icon_with_path;
2946 char* confirmed_icon = NULL;
2948 confirmed_icon = strdup(icon);
2949 if (!confirmed_icon)
2951 return confirmed_icon;
2955 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
2958 char delims[] = "=";
2959 char *ret_result = NULL;
2965 for (tag = strdup(tagv[0]); tag != NULL; ) {
2966 ret_result = strtok(tag, delims);
2968 /*check tag : preload */
2969 if (strcmp(ret_result, "preload") == 0) {
2970 ret_result = strtok(NULL, delims);
2971 if (strcmp(ret_result, "true") == 0) {
2972 free((void *)mfx->preload);
2973 mfx->preload = strdup("true");
2974 } else if (strcmp(ret_result, "false") == 0) {
2975 free((void *)mfx->preload);
2976 mfx->preload = strdup("false");
2978 /*check tag : removable*/
2979 } else if (strcmp(ret_result, "removable") == 0) {
2980 ret_result = strtok(NULL, delims);
2981 if (strcmp(ret_result, "true") == 0){
2982 free((void *)mfx->removable);
2983 mfx->removable = strdup("true");
2984 } else if (strcmp(ret_result, "false") == 0) {
2985 free((void *)mfx->removable);
2986 mfx->removable = strdup("false");
2988 /*check tag : not matched*/
2990 _LOGD("tag process [%s]is not defined\n", ret_result);
2994 /*check next value*/
2995 if (tagv[++i] != NULL)
2996 tag = strdup(tagv[i]);
2998 _LOGD("tag process success...\n");
3004 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
3006 __save_xml_attribute(reader, "name", &icon->name, NULL);
3007 __save_xml_attribute(reader, "section", &icon->section, NULL);
3008 __save_xml_attribute(reader, "size", &icon->size, NULL);
3009 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
3010 __save_xml_lang(reader, &icon->lang);
3012 xmlTextReaderRead(reader);
3013 const char *text = ASCII(xmlTextReaderValue(reader));
3015 icon->text = (const char *)__get_icon_with_path(text, uid);
3022 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
3024 __save_xml_attribute(reader, "name", &image->name, NULL);
3025 __save_xml_attribute(reader, "section", &image->section, NULL);
3026 __save_xml_lang(reader, &image->lang);
3027 __save_xml_value(reader, &image->text);
3031 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
3033 __save_xml_attribute(reader, "name", &label->name, NULL);
3034 __save_xml_lang(reader, &label->lang);
3035 __save_xml_value(reader, &label->text);
3040 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
3042 __save_xml_attribute(reader, "email", &author->email, NULL);
3043 __save_xml_attribute(reader, "href", &author->href, NULL);
3044 __save_xml_lang(reader, &author->lang);
3045 __save_xml_value(reader, &author->text);
3049 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
3051 __save_xml_lang(reader, &description->lang);
3052 __save_xml_value(reader, &description->text);
3056 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
3058 __save_xml_lang(reader, &license->lang);
3059 __save_xml_value(reader, &license->text);
3063 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
3065 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
3066 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
3067 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
3071 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication, uid_t uid)
3073 const xmlChar *node;
3076 label_x *tmp1 = NULL;
3077 icon_x *tmp2 = NULL;
3078 appsvc_x *tmp3 = NULL;
3079 appcontrol_x *tmp4 = NULL;
3080 launchconditions_x *tmp5 = NULL;
3081 notification_x *tmp6 = NULL;
3082 datashare_x *tmp7 = NULL;
3083 category_x *tmp8 = NULL;
3084 metadata_x *tmp9 = NULL;
3085 image_x *tmp10 = NULL;
3086 permission_x *tmp11 = NULL;
3087 datacontrol_x *tmp12 = NULL;
3089 __save_xml_attribute(reader, "appid", &uiapplication->appid, NULL);
3090 retvm_if(uiapplication->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
3091 __save_xml_attribute(reader, "exec", &uiapplication->exec, NULL);
3092 __save_xml_attribute(reader, "nodisplay", &uiapplication->nodisplay, "false");
3093 __save_xml_attribute(reader, "multiple", &uiapplication->multiple, "false");
3094 __save_xml_attribute(reader, "type", &uiapplication->type, NULL);
3095 __save_xml_attribute(reader, "categories", &uiapplication->categories, NULL);
3096 __save_xml_attribute(reader, "extraid", &uiapplication->extraid, NULL);
3097 __save_xml_attribute(reader, "taskmanage", &uiapplication->taskmanage, "true");
3098 __save_xml_attribute(reader, "enabled", &uiapplication->enabled, "true");
3099 __save_xml_attribute(reader, "hw-acceleration", &uiapplication->hwacceleration, "default");
3100 __save_xml_attribute(reader, "screen-reader", &uiapplication->screenreader, "use-system-setting");
3101 __save_xml_attribute(reader, "mainapp", &uiapplication->mainapp, "false");
3102 __save_xml_attribute(reader, "recentimage", &uiapplication->recentimage, "false");
3103 __save_xml_attribute(reader, "launchcondition", &uiapplication->launchcondition, "false");
3104 __save_xml_attribute(reader, "indicatordisplay", &uiapplication->indicatordisplay, "true");
3105 __save_xml_attribute(reader, "portrait-effectimage", &uiapplication->portraitimg, NULL);
3106 __save_xml_attribute(reader, "landscape-effectimage", &uiapplication->landscapeimg, NULL);
3107 __save_xml_attribute(reader, "guestmode-visibility", &uiapplication->guestmode_visibility, "true");
3108 __save_xml_attribute(reader, "permission-type", &uiapplication->permission_type, "normal");
3109 __save_xml_attribute(reader, "component-type", &uiapplication->component_type, "uiapp");
3110 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
3111 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);
3112 __save_xml_attribute(reader, "submode", &uiapplication->submode, "false");
3113 __save_xml_attribute(reader, "submode-mainid", &uiapplication->submode_mainid, NULL);
3114 __save_xml_attribute(reader, "launch_mode", &uiapplication->launch_mode, "caller");
3116 uiapplication->package= strdup(package);
3118 depth = xmlTextReaderDepth(reader);
3119 while ((ret = __next_child_element(reader, depth))) {
3120 node = xmlTextReaderConstName(reader);
3122 _LOGD("xmlTextReaderConstName value is NULL\n");
3125 if (!strcmp(ASCII(node), "label")) {
3126 label_x *label = malloc(sizeof(label_x));
3127 if (label == NULL) {
3128 _LOGD("Malloc Failed\n");
3131 memset(label, '\0', sizeof(label_x));
3132 LISTADD(uiapplication->label, label);
3133 ret = __ps_process_label(reader, label);
3134 } else if (!strcmp(ASCII(node), "icon")) {
3135 icon_x *icon = malloc(sizeof(icon_x));
3137 _LOGD("Malloc Failed\n");
3140 memset(icon, '\0', sizeof(icon_x));
3141 LISTADD(uiapplication->icon, icon);
3142 ret = __ps_process_icon(reader, icon, uid);
3143 } else if (!strcmp(ASCII(node), "image")) {
3144 image_x *image = malloc(sizeof(image_x));
3145 if (image == NULL) {
3146 _LOGD("Malloc Failed\n");
3149 memset(image, '\0', sizeof(image_x));
3150 LISTADD(uiapplication->image, image);
3151 ret = __ps_process_image(reader, image);
3152 } else if (!strcmp(ASCII(node), "category")) {
3153 category_x *category = malloc(sizeof(category_x));
3154 if (category == NULL) {
3155 _LOGD("Malloc Failed\n");
3158 memset(category, '\0', sizeof(category_x));
3159 LISTADD(uiapplication->category, category);
3160 ret = __ps_process_category(reader, category);
3161 } else if (!strcmp(ASCII(node), "metadata")) {
3162 metadata_x *metadata = malloc(sizeof(metadata_x));
3163 if (metadata == NULL) {
3164 _LOGD("Malloc Failed\n");
3167 memset(metadata, '\0', sizeof(metadata_x));
3168 LISTADD(uiapplication->metadata, metadata);
3169 ret = __ps_process_metadata(reader, metadata);
3170 } else if (!strcmp(ASCII(node), "permission")) {
3171 permission_x *permission = malloc(sizeof(permission_x));
3172 if (permission == NULL) {
3173 _LOGD("Malloc Failed\n");
3176 memset(permission, '\0', sizeof(permission_x));
3177 LISTADD(uiapplication->permission, permission);
3178 ret = __ps_process_permission(reader, permission);
3179 } else if (!strcmp(ASCII(node), "app-control")) {
3180 appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
3181 if (appcontrol == NULL) {
3182 _LOGD("Malloc Failed\n");
3185 memset(appcontrol, '\0', sizeof(appcontrol_x));
3186 LISTADD(uiapplication->appcontrol, appcontrol);
3187 ret = __ps_process_appcontrol(reader, appcontrol);
3188 } else if (!strcmp(ASCII(node), "application-service")) {
3189 appsvc_x *appsvc = malloc(sizeof(appsvc_x));
3190 if (appsvc == NULL) {
3191 _LOGD("Malloc Failed\n");
3194 memset(appsvc, '\0', sizeof(appsvc_x));
3195 LISTADD(uiapplication->appsvc, appsvc);
3196 ret = __ps_process_appsvc(reader, appsvc);
3197 } else if (!strcmp(ASCII(node), "data-share")) {
3198 datashare_x *datashare = malloc(sizeof(datashare_x));
3199 if (datashare == NULL) {
3200 _LOGD("Malloc Failed\n");
3203 memset(datashare, '\0', sizeof(datashare_x));
3204 LISTADD(uiapplication->datashare, datashare);
3205 ret = __ps_process_datashare(reader, datashare);
3206 } else if (!strcmp(ASCII(node), "launch-conditions")) {
3207 launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
3208 if (launchconditions == NULL) {
3209 _LOGD("Malloc Failed\n");
3212 memset(launchconditions, '\0', sizeof(launchconditions_x));
3213 LISTADD(uiapplication->launchconditions, launchconditions);
3214 ret = __ps_process_launchconditions(reader, launchconditions);
3215 } else if (!strcmp(ASCII(node), "notification")) {
3216 notification_x *notification = malloc(sizeof(notification_x));
3217 if (notification == NULL) {
3218 _LOGD("Malloc Failed\n");
3221 memset(notification, '\0', sizeof(notification_x));
3222 LISTADD(uiapplication->notification, notification);
3223 ret = __ps_process_notification(reader, notification);
3224 } else if (!strcmp(ASCII(node), "datacontrol")) {
3225 datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
3226 if (datacontrol == NULL) {
3227 _LOGD("Malloc Failed\n");
3230 memset(datacontrol, '\0', sizeof(datacontrol_x));
3231 LISTADD(uiapplication->datacontrol, datacontrol);
3232 ret = __ps_process_datacontrol(reader, datacontrol);
3236 _LOGD("Processing uiapplication failed\n");
3241 if (uiapplication->label) {
3242 LISTHEAD(uiapplication->label, tmp1);
3243 uiapplication->label = tmp1;
3245 if (uiapplication->icon) {
3246 LISTHEAD(uiapplication->icon, tmp2);
3247 uiapplication->icon = tmp2;
3249 if (uiapplication->appsvc) {
3250 LISTHEAD(uiapplication->appsvc, tmp3);
3251 uiapplication->appsvc = tmp3;
3253 if (uiapplication->appcontrol) {
3254 LISTHEAD(uiapplication->appcontrol, tmp4);
3255 uiapplication->appcontrol = tmp4;
3257 if (uiapplication->launchconditions) {
3258 LISTHEAD(uiapplication->launchconditions, tmp5);
3259 uiapplication->launchconditions = tmp5;
3261 if (uiapplication->notification) {
3262 LISTHEAD(uiapplication->notification, tmp6);
3263 uiapplication->notification = tmp6;
3265 if (uiapplication->datashare) {
3266 LISTHEAD(uiapplication->datashare, tmp7);
3267 uiapplication->datashare = tmp7;
3269 if (uiapplication->category) {
3270 LISTHEAD(uiapplication->category, tmp8);
3271 uiapplication->category = tmp8;
3273 if (uiapplication->metadata) {
3274 LISTHEAD(uiapplication->metadata, tmp9);
3275 uiapplication->metadata = tmp9;
3277 if (uiapplication->image) {
3278 LISTHEAD(uiapplication->image, tmp10);
3279 uiapplication->image = tmp10;
3281 if (uiapplication->permission) {
3282 LISTHEAD(uiapplication->permission, tmp11);
3283 uiapplication->permission = tmp11;
3285 if (uiapplication->datacontrol) {
3286 LISTHEAD(uiapplication->datacontrol, tmp12);
3287 uiapplication->datacontrol = tmp12;
3293 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication, uid_t uid)
3295 const xmlChar *node;
3298 label_x *tmp1 = NULL;
3299 icon_x *tmp2 = NULL;
3300 appsvc_x *tmp3 = NULL;
3301 appcontrol_x *tmp4 = NULL;
3302 datacontrol_x *tmp5 = NULL;
3303 launchconditions_x *tmp6 = NULL;
3304 notification_x *tmp7 = NULL;
3305 datashare_x *tmp8 = NULL;
3306 category_x *tmp9 = NULL;
3307 metadata_x *tmp10 = NULL;
3308 permission_x *tmp11 = NULL;
3310 __save_xml_attribute(reader, "appid", &serviceapplication->appid, NULL);
3311 retvm_if(serviceapplication->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
3312 __save_xml_attribute(reader, "exec", &serviceapplication->exec, NULL);
3313 __save_xml_attribute(reader, "type", &serviceapplication->type, NULL);
3314 __save_xml_attribute(reader, "enabled", &serviceapplication->enabled, "true");
3315 __save_xml_attribute(reader, "permission-type", &serviceapplication->permission_type, "normal");
3316 __save_xml_attribute(reader, "auto-restart", &serviceapplication->autorestart, "false");
3317 __save_xml_attribute(reader, "on-boot", &serviceapplication->onboot, "false");
3319 serviceapplication->package= strdup(package);
3321 depth = xmlTextReaderDepth(reader);
3322 while ((ret = __next_child_element(reader, depth))) {
3323 node = xmlTextReaderConstName(reader);
3325 _LOGD("xmlTextReaderConstName value is NULL\n");
3329 if (!strcmp(ASCII(node), "label")) {
3330 label_x *label = malloc(sizeof(label_x));
3331 if (label == NULL) {
3332 _LOGD("Malloc Failed\n");
3335 memset(label, '\0', sizeof(label_x));
3336 LISTADD(serviceapplication->label, label);
3337 ret = __ps_process_label(reader, label);
3338 } else if (!strcmp(ASCII(node), "icon")) {
3339 icon_x *icon = malloc(sizeof(icon_x));
3341 _LOGD("Malloc Failed\n");
3344 memset(icon, '\0', sizeof(icon_x));
3345 LISTADD(serviceapplication->icon, icon);
3346 ret = __ps_process_icon(reader, icon, uid);
3347 } else if (!strcmp(ASCII(node), "category")) {
3348 category_x *category = malloc(sizeof(category_x));
3349 if (category == NULL) {
3350 _LOGD("Malloc Failed\n");
3353 memset(category, '\0', sizeof(category_x));
3354 LISTADD(serviceapplication->category, category);
3355 ret = __ps_process_category(reader, category);
3356 } else if (!strcmp(ASCII(node), "metadata")) {
3357 metadata_x *metadata = malloc(sizeof(metadata_x));
3358 if (metadata == NULL) {
3359 _LOGD("Malloc Failed\n");
3362 memset(metadata, '\0', sizeof(metadata_x));
3363 LISTADD(serviceapplication->metadata, metadata);
3364 ret = __ps_process_metadata(reader, metadata);
3365 } else if (!strcmp(ASCII(node), "permission")) {
3366 permission_x *permission = malloc(sizeof(permission_x));
3367 if (permission == NULL) {
3368 _LOGD("Malloc Failed\n");
3371 memset(permission, '\0', sizeof(permission_x));
3372 LISTADD(serviceapplication->permission, permission);
3373 ret = __ps_process_permission(reader, permission);
3374 } else if (!strcmp(ASCII(node), "app-control")) {
3375 appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
3376 if (appcontrol == NULL) {
3377 _LOGD("Malloc Failed\n");
3380 memset(appcontrol, '\0', sizeof(appcontrol_x));
3381 LISTADD(serviceapplication->appcontrol, appcontrol);
3382 ret = __ps_process_appcontrol(reader, appcontrol);
3383 } else if (!strcmp(ASCII(node), "application-service")) {
3384 appsvc_x *appsvc = malloc(sizeof(appsvc_x));
3385 if (appsvc == NULL) {
3386 _LOGD("Malloc Failed\n");
3389 memset(appsvc, '\0', sizeof(appsvc_x));
3390 LISTADD(serviceapplication->appsvc, appsvc);
3391 ret = __ps_process_appsvc(reader, appsvc);
3392 } else if (!strcmp(ASCII(node), "data-share")) {
3393 datashare_x *datashare = malloc(sizeof(datashare_x));
3394 if (datashare == NULL) {
3395 _LOGD("Malloc Failed\n");
3398 memset(datashare, '\0', sizeof(datashare_x));
3399 LISTADD(serviceapplication->datashare, datashare);
3400 ret = __ps_process_datashare(reader, datashare);
3401 } else if (!strcmp(ASCII(node), "launch-conditions")) {
3402 launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
3403 if (launchconditions == NULL) {
3404 _LOGD("Malloc Failed\n");
3407 memset(launchconditions, '\0', sizeof(launchconditions_x));
3408 LISTADD(serviceapplication->launchconditions, launchconditions);
3409 ret = __ps_process_launchconditions(reader, launchconditions);
3410 } else if (!strcmp(ASCII(node), "notification")) {
3411 notification_x *notification = malloc(sizeof(notification_x));
3412 if (notification == NULL) {
3413 _LOGD("Malloc Failed\n");
3416 memset(notification, '\0', sizeof(notification_x));
3417 LISTADD(serviceapplication->notification, notification);
3418 ret = __ps_process_notification(reader, notification);
3419 } else if (!strcmp(ASCII(node), "datacontrol")) {
3420 datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
3421 if (datacontrol == NULL) {
3422 _LOGD("Malloc Failed\n");
3425 memset(datacontrol, '\0', sizeof(datacontrol_x));
3426 LISTADD(serviceapplication->datacontrol, datacontrol);
3427 ret = __ps_process_datacontrol(reader, datacontrol);
3431 _LOGD("Processing serviceapplication failed\n");
3436 if (serviceapplication->label) {
3437 LISTHEAD(serviceapplication->label, tmp1);
3438 serviceapplication->label = tmp1;
3440 if (serviceapplication->icon) {
3441 LISTHEAD(serviceapplication->icon, tmp2);
3442 serviceapplication->icon = tmp2;
3444 if (serviceapplication->appsvc) {
3445 LISTHEAD(serviceapplication->appsvc, tmp3);
3446 serviceapplication->appsvc = tmp3;
3448 if (serviceapplication->appcontrol) {
3449 LISTHEAD(serviceapplication->appcontrol, tmp4);
3450 serviceapplication->appcontrol = tmp4;
3452 if (serviceapplication->datacontrol) {
3453 LISTHEAD(serviceapplication->datacontrol, tmp5);
3454 serviceapplication->datacontrol = tmp5;
3456 if (serviceapplication->launchconditions) {
3457 LISTHEAD(serviceapplication->launchconditions, tmp6);
3458 serviceapplication->launchconditions = tmp6;
3460 if (serviceapplication->notification) {
3461 LISTHEAD(serviceapplication->notification, tmp7);
3462 serviceapplication->notification = tmp7;
3464 if (serviceapplication->datashare) {
3465 LISTHEAD(serviceapplication->datashare, tmp8);
3466 serviceapplication->datashare = tmp8;
3468 if (serviceapplication->category) {
3469 LISTHEAD(serviceapplication->category, tmp9);
3470 serviceapplication->category = tmp9;
3472 if (serviceapplication->metadata) {
3473 LISTHEAD(serviceapplication->metadata, tmp10);
3474 serviceapplication->metadata = tmp10;
3476 if (serviceapplication->permission) {
3477 LISTHEAD(serviceapplication->permission, tmp11);
3478 serviceapplication->permission = tmp11;
3484 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile)
3486 /*TODO: once policy is set*/
3490 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font)
3492 /*TODO: once policy is set*/
3496 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme)
3498 /*TODO: once policy is set*/
3502 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon)
3504 /*TODO: once policy is set*/
3508 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
3510 /*TODO: once policy is set*/
3514 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
3516 _LOGD("__start_process\n");
3517 const xmlChar *node;
3520 label_x *tmp1 = NULL;
3521 author_x *tmp2 = NULL;
3522 description_x *tmp3 = NULL;
3523 license_x *tmp4 = NULL;
3524 uiapplication_x *tmp5 = NULL;
3525 serviceapplication_x *tmp6 = NULL;
3526 daemon_x *tmp7 = NULL;
3527 theme_x *tmp8 = NULL;
3528 font_x *tmp9 = NULL;
3529 ime_x *tmp10 = NULL;
3530 icon_x *tmp11 = NULL;
3531 compatibility_x *tmp12 = NULL;
3532 deviceprofile_x *tmp13 = NULL;
3533 privileges_x *tmp14 = NULL;
3535 depth = xmlTextReaderDepth(reader);
3536 while ((ret = __next_child_element(reader, depth))) {
3537 node = xmlTextReaderConstName(reader);
3539 _LOGD("xmlTextReaderConstName value is NULL\n");
3543 if (!strcmp(ASCII(node), "label")) {
3544 label_x *label = malloc(sizeof(label_x));
3545 if (label == NULL) {
3546 _LOGD("Malloc Failed\n");
3549 memset(label, '\0', sizeof(label_x));
3550 LISTADD(mfx->label, label);
3551 ret = __ps_process_label(reader, label);
3552 } else if (!strcmp(ASCII(node), "author")) {
3553 author_x *author = malloc(sizeof(author_x));
3554 if (author == NULL) {
3555 _LOGD("Malloc Failed\n");
3558 memset(author, '\0', sizeof(author_x));
3559 LISTADD(mfx->author, author);
3560 ret = __ps_process_author(reader, author);
3561 } else if (!strcmp(ASCII(node), "description")) {
3562 description_x *description = malloc(sizeof(description_x));
3563 if (description == NULL) {
3564 _LOGD("Malloc Failed\n");
3567 memset(description, '\0', sizeof(description_x));
3568 LISTADD(mfx->description, description);
3569 ret = __ps_process_description(reader, description);
3570 } else if (!strcmp(ASCII(node), "license")) {
3571 license_x *license = malloc(sizeof(license_x));
3572 if (license == NULL) {
3573 _LOGD("Malloc Failed\n");
3576 memset(license, '\0', sizeof(license_x));
3577 LISTADD(mfx->license, license);
3578 ret = __ps_process_license(reader, license);
3579 } else if (!strcmp(ASCII(node), "privileges")) {
3580 privileges_x *privileges = malloc(sizeof(privileges_x));
3581 if (privileges == NULL) {
3582 _LOGD("Malloc Failed\n");
3585 memset(privileges, '\0', sizeof(privileges_x));
3586 LISTADD(mfx->privileges, privileges);
3587 ret = __ps_process_privileges(reader, privileges);
3588 } else if (!strcmp(ASCII(node), "ui-application")) {
3589 uiapplication_x *uiapplication = malloc(sizeof(uiapplication_x));
3590 if (uiapplication == NULL) {
3591 _LOGD("Malloc Failed\n");
3594 memset(uiapplication, '\0', sizeof(uiapplication_x));
3595 LISTADD(mfx->uiapplication, uiapplication);
3596 ret = __ps_process_uiapplication(reader, uiapplication, uid);
3597 } else if (!strcmp(ASCII(node), "service-application")) {
3598 serviceapplication_x *serviceapplication = malloc(sizeof(serviceapplication_x));
3599 if (serviceapplication == NULL) {
3600 _LOGD("Malloc Failed\n");
3603 memset(serviceapplication, '\0', sizeof(serviceapplication_x));
3604 LISTADD(mfx->serviceapplication, serviceapplication);
3605 ret = __ps_process_serviceapplication(reader, serviceapplication, uid);
3606 } else if (!strcmp(ASCII(node), "daemon")) {
3607 daemon_x *daemon = malloc(sizeof(daemon_x));
3608 if (daemon == NULL) {
3609 _LOGD("Malloc Failed\n");
3612 memset(daemon, '\0', sizeof(daemon_x));
3613 LISTADD(mfx->daemon, daemon);
3614 ret = __ps_process_daemon(reader, daemon);
3615 } else if (!strcmp(ASCII(node), "theme")) {
3616 theme_x *theme = malloc(sizeof(theme_x));
3617 if (theme == NULL) {
3618 _LOGD("Malloc Failed\n");
3621 memset(theme, '\0', sizeof(theme_x));
3622 LISTADD(mfx->theme, theme);
3623 ret = __ps_process_theme(reader, theme);
3624 } else if (!strcmp(ASCII(node), "font")) {
3625 font_x *font = malloc(sizeof(font_x));
3627 _LOGD("Malloc Failed\n");
3630 memset(font, '\0', sizeof(font_x));
3631 LISTADD(mfx->font, font);
3632 ret = __ps_process_font(reader, font);
3633 } else if (!strcmp(ASCII(node), "ime")) {
3634 ime_x *ime = malloc(sizeof(ime_x));
3636 _LOGD("Malloc Failed\n");
3639 memset(ime, '\0', sizeof(ime_x));
3640 LISTADD(mfx->ime, ime);
3641 ret = __ps_process_ime(reader, ime);
3642 } else if (!strcmp(ASCII(node), "icon")) {
3643 icon_x *icon = malloc(sizeof(icon_x));
3645 _LOGD("Malloc Failed\n");
3648 memset(icon, '\0', sizeof(icon_x));
3649 LISTADD(mfx->icon, icon);
3650 ret = __ps_process_icon(reader, icon, uid);
3651 } else if (!strcmp(ASCII(node), "profile")) {
3652 deviceprofile_x *deviceprofile = malloc(sizeof(deviceprofile_x));
3653 if (deviceprofile == NULL) {
3654 _LOGD("Malloc Failed\n");
3657 memset(deviceprofile, '\0', sizeof(deviceprofile_x));
3658 LISTADD(mfx->deviceprofile, deviceprofile);
3659 ret = __ps_process_deviceprofile(reader, deviceprofile);
3660 } else if (!strcmp(ASCII(node), "compatibility")) {
3661 compatibility_x *compatibility = malloc(sizeof(compatibility_x));
3662 if (compatibility == NULL) {
3663 _LOGD("Malloc Failed\n");
3666 memset(compatibility, '\0', sizeof(compatibility_x));
3667 LISTADD(mfx->compatibility, compatibility);
3668 ret = __ps_process_compatibility(reader, compatibility);
3669 } else if (!strcmp(ASCII(node), "shortcut-list")) {
3671 } else if (!strcmp(ASCII(node), "livebox")) {
3673 } else if (!strcmp(ASCII(node), "account")) {
3675 } else if (!strcmp(ASCII(node), "notifications")) {
3677 } else if (!strcmp(ASCII(node), "ime")) {
3679 } else if (!strcmp(ASCII(node), "feature")) {
3682 _LOGE("Unknown element: %s", ASCII(node));
3687 _LOGD("Processing manifest failed\n");
3692 LISTHEAD(mfx->label, tmp1);
3696 LISTHEAD(mfx->author, tmp2);
3699 if (mfx->description) {
3700 LISTHEAD(mfx->description, tmp3);
3701 mfx->description= tmp3;
3704 LISTHEAD(mfx->license, tmp4);
3707 if (mfx->uiapplication) {
3708 LISTHEAD(mfx->uiapplication, tmp5);
3709 mfx->uiapplication = tmp5;
3711 if (mfx->serviceapplication) {
3712 LISTHEAD(mfx->serviceapplication, tmp6);
3713 mfx->serviceapplication = tmp6;
3716 LISTHEAD(mfx->daemon, tmp7);
3720 LISTHEAD(mfx->theme, tmp8);
3724 LISTHEAD(mfx->font, tmp9);
3728 LISTHEAD(mfx->ime, tmp10);
3732 LISTHEAD(mfx->icon, tmp11);
3735 if (mfx->compatibility) {
3736 LISTHEAD(mfx->compatibility, tmp12);
3737 mfx->compatibility= tmp12;
3739 if (mfx->deviceprofile) {
3740 LISTHEAD(mfx->deviceprofile, tmp13);
3741 mfx->deviceprofile= tmp13;
3743 if (mfx->privileges) {
3744 LISTHEAD(mfx->privileges, tmp14);
3745 mfx->privileges = tmp14;
3750 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
3752 const xmlChar *node;
3755 if ((ret = __next_child_element(reader, -1))) {
3756 node = xmlTextReaderConstName(reader);
3758 _LOGD("xmlTextReaderConstName value is NULL\n");
3762 if (!strcmp(ASCII(node), "manifest")) {
3763 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
3764 __save_xml_attribute(reader, "package", &mfx->package, NULL);
3765 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
3766 __save_xml_attribute(reader, "version", &mfx->version, NULL);
3767 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
3768 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
3769 __save_xml_attribute(reader, "type", &mfx->type, "rpm");
3770 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
3771 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
3772 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
3773 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
3774 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
3775 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
3776 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
3778 __save_xml_installed_time(mfx);
3779 __save_xml_root_path(mfx, uid);
3780 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
3781 __save_xml_default_value(mfx);
3783 ret = __start_process(reader, mfx, uid);
3785 _LOGD("No Manifest element found\n");
3792 static char* __convert_to_system_locale(const char *mlocale)
3794 if (mlocale == NULL)
3796 char *locale = NULL;
3797 locale = (char *)calloc(1, 6);
3799 _LOGE("Malloc Failed\n");
3803 strncpy(locale, mlocale, 2);
3804 strncat(locale, "_", 1);
3805 locale[3] = toupper(mlocale[3]);
3806 locale[4] = toupper(mlocale[4]);
3810 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
3812 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
3814 void *lib_handle = NULL;
3815 int (*appsvc_operation) (const char *, uid_t);
3817 uiapplication_x *uiapplication = mfx->uiapplication;
3819 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
3820 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
3824 if ((appsvc_operation =
3825 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
3826 _LOGE("can not find symbol \n");
3830 for(; uiapplication; uiapplication=uiapplication->next) {
3831 ret = appsvc_operation(uiapplication->appid, uid);
3833 _LOGE("can not operation symbol \n");
3838 dlclose(lib_handle);
3843 #define PRELOAD_PACKAGE_LIST SYSCONFDIR "/package-manager/preload/preload_list.txt"
3844 static int __add_preload_info(manifest_x * mfx, const char *manifest, uid_t uid)
3847 char buffer[1024] = { 0 };
3850 if(strstr(manifest, getUserManifestPath(uid))) {
3851 free((void *)mfx->readonly);
3852 mfx->readonly = strdup("True");
3854 free((void *)mfx->preload);
3855 mfx->preload = strdup("True");
3857 free((void *)mfx->removable);
3858 mfx->removable = strdup("False");
3860 free((void *)mfx->system);
3861 mfx->system = strdup("True");
3866 fp = fopen(PRELOAD_PACKAGE_LIST, "r");
3868 _LOGE("no preload list\n");
3872 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
3873 if (buffer[0] == '#') {
3874 if(strcasestr(buffer, "RW_NORM"))
3876 else if(strcasestr(buffer, "RW_RM"))
3884 if(!strcmp(mfx->package, buffer)) {
3885 free((void *)mfx->preload);
3886 mfx->preload = strdup("True");
3888 free((void *)mfx->readonly);
3889 mfx->readonly = strdup("False");
3890 free((void *)mfx->removable);
3891 mfx->removable = strdup("False");
3892 } else if(state == 3){
3893 free((void *)mfx->readonly);
3894 mfx->readonly = strdup("False");
3895 free((void *)mfx->removable);
3896 mfx->removable = strdup("True");
3900 memset(buffer, 0x00, sizeof(buffer));
3909 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
3911 if (!strstr(manifest, getUserManifestPath(uid))) {
3912 /* if downloaded app is updated, then update tag set true*/
3914 free((void *)mfx->update);
3915 mfx->update = strdup("true");
3922 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
3924 /* desktop file is no longer used */
3928 API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
3930 /* desktop file is no longer used */
3935 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
3940 free((void *)mfx->ns);
3944 free((void *)mfx->package);
3945 mfx->package = NULL;
3948 free((void *)mfx->version);
3949 mfx->version = NULL;
3951 if (mfx->installlocation) {
3952 free((void *)mfx->installlocation);
3953 mfx->installlocation = NULL;
3956 free((void *)mfx->preload);
3957 mfx->preload = NULL;
3959 if (mfx->readonly) {
3960 free((void *)mfx->readonly);
3961 mfx->readonly = NULL;
3963 if (mfx->removable) {
3964 free((void *)mfx->removable);
3965 mfx->removable = NULL;
3968 free((void *)mfx->update);
3972 free((void *)mfx->system);
3976 free((void *)mfx->type);
3979 if (mfx->package_size) {
3980 free((void *)mfx->package_size);
3981 mfx->package_size = NULL;
3983 if (mfx->installed_time) {
3984 free((void *)mfx->installed_time);
3985 mfx->installed_time = NULL;
3987 if (mfx->installed_storage) {
3988 free((void *)mfx->installed_storage);
3989 mfx->installed_storage = NULL;
3991 if (mfx->storeclient_id) {
3992 free((void *)mfx->storeclient_id);
3993 mfx->storeclient_id = NULL;
3995 if (mfx->mainapp_id) {
3996 free((void *)mfx->mainapp_id);
3997 mfx->mainapp_id = NULL;
3999 if (mfx->package_url) {
4000 free((void *)mfx->package_url);
4001 mfx->package_url = NULL;
4003 if (mfx->root_path) {
4004 free((void *)mfx->root_path);
4005 mfx->root_path = NULL;
4007 if (mfx->csc_path) {
4008 free((void *)mfx->csc_path);
4009 mfx->csc_path = NULL;
4011 if (mfx->appsetting) {
4012 free((void *)mfx->appsetting);
4013 mfx->appsetting = NULL;
4015 if (mfx->nodisplay_setting) {
4016 free((void *)mfx->nodisplay_setting);
4017 mfx->nodisplay_setting = NULL;
4019 if (mfx->api_version) {
4020 free((void *)mfx->api_version);
4021 mfx->api_version = NULL;
4026 icon_x *icon = mfx->icon;
4028 while(icon != NULL) {
4030 __ps_free_icon(icon);
4036 label_x *label = mfx->label;
4037 label_x *tmp = NULL;
4038 while(label != NULL) {
4040 __ps_free_label(label);
4046 author_x *author = mfx->author;
4047 author_x *tmp = NULL;
4048 while(author != NULL) {
4050 __ps_free_author(author);
4054 /*Free Description*/
4055 if (mfx->description) {
4056 description_x *description = mfx->description;
4057 description_x *tmp = NULL;
4058 while(description != NULL) {
4059 tmp = description->next;
4060 __ps_free_description(description);
4066 license_x *license = mfx->license;
4067 license_x *tmp = NULL;
4068 while(license != NULL) {
4069 tmp = license->next;
4070 __ps_free_license(license);
4075 if (mfx->privileges) {
4076 privileges_x *privileges = mfx->privileges;
4077 privileges_x *tmp = NULL;
4078 while(privileges != NULL) {
4079 tmp = privileges->next;
4080 __ps_free_privileges(privileges);
4084 /*Free UiApplication*/
4085 if (mfx->uiapplication) {
4086 uiapplication_x *uiapplication = mfx->uiapplication;
4087 uiapplication_x *tmp = NULL;
4088 while(uiapplication != NULL) {
4089 tmp = uiapplication->next;
4090 __ps_free_uiapplication(uiapplication);
4091 uiapplication = tmp;
4094 /*Free ServiceApplication*/
4095 if (mfx->serviceapplication) {
4096 serviceapplication_x *serviceapplication = mfx->serviceapplication;
4097 serviceapplication_x *tmp = NULL;
4098 while(serviceapplication != NULL) {
4099 tmp = serviceapplication->next;
4100 __ps_free_serviceapplication(serviceapplication);
4101 serviceapplication = tmp;
4106 daemon_x *daemon = mfx->daemon;
4107 daemon_x *tmp = NULL;
4108 while(daemon != NULL) {
4110 __ps_free_daemon(daemon);
4116 theme_x *theme = mfx->theme;
4117 theme_x *tmp = NULL;
4118 while(theme != NULL) {
4120 __ps_free_theme(theme);
4126 font_x *font = mfx->font;
4128 while(font != NULL) {
4130 __ps_free_font(font);
4136 ime_x *ime = mfx->ime;
4138 while(ime != NULL) {
4144 /*Free Compatibility*/
4145 if (mfx->compatibility) {
4146 compatibility_x *compatibility = mfx->compatibility;
4147 compatibility_x *tmp = NULL;
4148 while(compatibility != NULL) {
4149 tmp = compatibility->next;
4150 __ps_free_compatibility(compatibility);
4151 compatibility = tmp;
4154 /*Free DeviceProfile*/
4155 if (mfx->deviceprofile) {
4156 deviceprofile_x *deviceprofile = mfx->deviceprofile;
4157 deviceprofile_x *tmp = NULL;
4158 while(deviceprofile != NULL) {
4159 tmp = deviceprofile->next;
4160 __ps_free_deviceprofile(deviceprofile);
4161 deviceprofile = tmp;
4169 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
4171 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
4172 xmlTextReaderPtr reader;
4173 manifest_x *mfx = NULL;
4175 reader = xmlReaderForFile(manifest, NULL, 0);
4177 mfx = malloc(sizeof(manifest_x));
4179 memset(mfx, '\0', sizeof(manifest_x));
4180 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
4181 _LOGD("Parsing Failed\n");
4182 pkgmgr_parser_free_manifest_xml(mfx);
4185 _LOGD("Parsing Success\n");
4187 _LOGD("Memory allocation error\n");
4189 xmlFreeTextReader(reader);
4191 _LOGD("Unable to create xml reader\n");
4197 API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
4199 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
4200 xmlTextReaderPtr reader;
4201 manifest_x *mfx = NULL;
4203 reader = xmlReaderForFile(manifest, NULL, 0);
4205 mfx = malloc(sizeof(manifest_x));
4207 memset(mfx, '\0', sizeof(manifest_x));
4208 if (__process_manifest(reader, mfx, uid) < 0) {
4209 _LOGD("Parsing Failed\n");
4210 pkgmgr_parser_free_manifest_xml(mfx);
4213 _LOGD("Parsing Success\n");
4215 _LOGD("Memory allocation error\n");
4217 xmlFreeTextReader(reader);
4219 _LOGD("Unable to create xml reader\n");
4224 /* These APIs are intended to call parser directly */
4226 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
4228 // char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
4229 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4230 _LOGD("parsing manifest for installation: %s\n", manifest);
4232 manifest_x *mfx = NULL;
4236 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4237 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4239 _LOGD("Parsing Finished\n");
4241 // __streamFile(manifest, ACTION_INSTALL, temp, mfx->package);
4242 __add_preload_info(mfx, manifest, GLOBAL_USER);
4244 _LOGD("Added preload infomation\n");
4246 __ps_process_tag(mfx, tagv);
4248 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
4249 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
4251 _LOGD("DB Insert Success\n");
4253 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
4254 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
4256 _LOGD("Creating metadata parser failed\n");
4258 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
4260 _LOGD("Creating category parser failed\n");
4262 pkgmgr_parser_free_manifest_xml(mfx);
4263 _LOGD("Free Done\n");
4268 API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
4270 // char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
4271 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4272 _LOGD("parsing manifest for installation: %s\n", manifest);
4273 manifest_x *mfx = NULL;
4277 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
4278 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4280 _LOGD("Parsing Finished\n");
4281 // __streamFile(manifest, ACTION_INSTALL, temp, mfx->package);
4283 __ps_process_tag(mfx, tagv);
4285 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
4286 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
4288 _LOGD("DB Insert Success\n");
4290 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
4291 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
4293 _LOGD("Creating metadata parser failed\n");
4294 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
4296 _LOGD("Creating category parser failed\n");
4298 pkgmgr_parser_free_manifest_xml(mfx);
4299 _LOGD("Free Done\n");
4305 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
4307 // char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
4308 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4309 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
4310 manifest_x *mfx = NULL;
4312 bool preload = false;
4313 bool system = false;
4314 char *csc_path = NULL;
4315 pkgmgrinfo_pkginfo_h handle = NULL;
4318 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4319 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4321 _LOGD("Parsing Finished\n");
4322 // __streamFile(manifest, ACTION_UPGRADE, temp, mfx->package);
4323 __add_preload_info(mfx, manifest, GLOBAL_USER);
4324 _LOGD("Added preload infomation\n");
4325 __check_preload_updated(mfx, manifest, GLOBAL_USER);
4327 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
4328 if (ret != PMINFO_R_OK)
4329 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
4330 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
4331 if (ret != PMINFO_R_OK)
4332 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
4335 free((void *)mfx->preload);
4336 mfx->preload = strdup("true");
4339 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
4340 if (ret != PMINFO_R_OK)
4341 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
4343 free((void *)mfx->system);
4344 mfx->system = strdup("true");
4347 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
4348 if (ret != PMINFO_R_OK)
4349 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
4351 if (csc_path != NULL) {
4353 free((void *)mfx->csc_path);
4354 mfx->csc_path = strdup(csc_path);
4357 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
4358 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
4360 _LOGD("DB Update Success\n");
4362 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
4363 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
4365 _LOGD("Upgrade metadata parser failed\n");
4367 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
4369 _LOGD("Creating category parser failed\n");
4370 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
4371 pkgmgr_parser_free_manifest_xml(mfx);
4372 _LOGD("Free Done\n");
4378 API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
4380 // char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
4381 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4382 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
4383 manifest_x *mfx = NULL;
4385 bool preload = false;
4386 bool system = false;
4387 char *csc_path = NULL;
4388 pkgmgrinfo_pkginfo_h handle = NULL;
4391 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
4392 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4394 _LOGD("Parsing Finished\n");
4395 //__streamFile(manifest, ACTION_UPGRADE, temp, mfx->package);
4396 __check_preload_updated(mfx, manifest, uid);
4398 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
4399 if (ret != PMINFO_R_OK)
4400 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
4401 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
4402 if (ret != PMINFO_R_OK)
4403 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
4406 free((void *)mfx->preload);
4407 mfx->preload = strdup("true");
4410 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
4411 if (ret != PMINFO_R_OK)
4412 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
4415 free((void *)mfx->system);
4416 mfx->system = strdup("true");
4419 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
4420 if (ret != PMINFO_R_OK)
4421 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
4422 if (csc_path != NULL) {
4424 free((void *)mfx->csc_path);
4425 mfx->csc_path = strdup(csc_path);
4428 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
4429 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
4430 _LOGD("DB Update Success\n");
4432 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
4433 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
4435 _LOGD("Upgrade metadata parser failed\n");
4436 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
4438 _LOGD("Creating category parser failed\n");
4439 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
4440 pkgmgr_parser_free_manifest_xml(mfx);
4441 _LOGD("Free Done\n");
4447 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
4449 // char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
4450 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4451 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
4453 manifest_x *mfx = NULL;
4456 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4457 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4459 _LOGD("Parsing Finished\n");
4461 // __streamFile(manifest, ACTION_UNINSTALL, temp, mfx->package);
4462 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
4464 __add_preload_info(mfx, manifest, GLOBAL_USER);
4465 _LOGD("Added preload infomation\n");
4467 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
4469 _LOGD("Removing metadata parser failed\n");
4471 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
4473 _LOGD("Creating category parser failed\n");
4475 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
4477 _LOGD("DB Delete failed\n");
4479 _LOGD("DB Delete Success\n");
4481 pkgmgr_parser_free_manifest_xml(mfx);
4482 _LOGD("Free Done\n");
4489 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
4491 // char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
4492 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4493 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
4495 manifest_x *mfx = NULL;
4498 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
4499 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
4501 _LOGD("Parsing Finished\n");
4503 // __streamFile(manifest, ACTION_UNINSTALL, temp, mfx->package);
4504 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
4506 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
4508 _LOGD("Removing metadata parser failed\n");
4510 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
4512 _LOGD("Creating category parser failed\n");
4514 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
4516 _LOGD("DB Delete failed\n");
4518 _LOGD("DB Delete Success\n");
4520 ret = __ps_remove_appsvc_db(mfx, uid);
4522 _LOGD("Removing appsvc_db failed\n");
4524 _LOGD("Removing appsvc_db Success\n");
4526 pkgmgr_parser_free_manifest_xml(mfx);
4527 _LOGD("Free Done\n");
4533 API int pkgmgr_parser_parse_manifest_for_preload()
4535 return pkgmgr_parser_update_preload_info_in_db();
4538 API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
4540 return pkgmgr_parser_update_preload_info_in_usr_db(uid);
4544 API char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid)
4546 return __pkgid_to_manifest(pkgid, uid);
4549 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
4551 return __pkgid_to_manifest(pkgid, GLOBAL_USER);
4554 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
4556 return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
4559 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
4561 return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
4564 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
4566 return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
4569 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
4571 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
4573 if (manifest == NULL) {
4574 _LOGE("manifest file is NULL\n");
4575 return PMINFO_R_EINVAL;
4578 xmlSchemaParserCtxtPtr ctx;
4579 xmlSchemaValidCtxtPtr vctx;
4580 xmlSchemaPtr xschema;
4581 ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
4583 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
4584 return PMINFO_R_ERROR;
4586 xschema = xmlSchemaParse(ctx);
4587 if (xschema == NULL) {
4588 _LOGE("xmlSchemaParse() Failed\n");
4589 return PMINFO_R_ERROR;
4591 vctx = xmlSchemaNewValidCtxt(xschema);
4593 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
4594 return PMINFO_R_ERROR;
4596 xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
4597 ret = xmlSchemaValidateFile(vctx, manifest, 0);
4599 _LOGE("xmlSchemaValidateFile() failed\n");
4600 return PMINFO_R_ERROR;
4601 } else if (ret == 0) {
4602 _LOGE("Manifest is Valid\n");
4605 _LOGE("Manifest Validation Failed with error code %d\n", ret);
4606 return PMINFO_R_ERROR;
4612 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
4622 _LOGE("fork failed\n");
4627 int dev_null_fd = open ("/dev/null", O_RDWR);
4628 if (dev_null_fd >= 0)
4630 dup2 (dev_null_fd, 0);/*stdin*/
4631 dup2 (dev_null_fd, 1);/*stdout*/
4632 dup2 (dev_null_fd, 2);/*stderr*/
4635 if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
4636 SCHEMA_FILE, NULL) < 0) {
4637 _LOGE("execl error\n");
4647 while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
4651 _LOGE("waitpid failed\n");
4657 if(WIFEXITED(status) && !WEXITSTATUS(status))