2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
28 #include <libxml/parser.h>
29 #include <libxml/xmlreader.h>
30 #include <libxml/xmlschemas.h>
32 #include <tzplatform_config.h>
34 #include "pkgmgrinfo_basic.h"
35 #include "pkgmgr-info.h"
36 #include "pkgmgr_parser.h"
37 #include "pkgmgr_parser_db.h"
38 #include "pkgmgr_parser_debug.h"
39 #include "pkgmgr_parser_internal.h"
41 #define ASCII(s) (char *)s
42 #define XMLCHAR(s) (const xmlChar *)s
44 #define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/mdparser_list.txt"
45 #define METADATA_PARSER_NAME "metadataparser:"
47 #define CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
48 #define CATEGORY_PARSER_NAME "categoryparser:"
50 #define TAG_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/tag_parser_list.txt"
51 #define TAG_PARSER_NAME "parserlib:"
56 /* plugin process_type */
58 PLUGIN_PRE_PROCESS = 0,
60 } PLUGIN_PROCESS_TYPE;
64 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, char **xml_attribute, char *default_value)
66 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
68 *xml_attribute = strdup((const char *)attrib_val);
71 if (default_value != NULL)
72 *xml_attribute = strdup(default_value);
76 static void __save_xml_value(xmlTextReaderPtr reader, char **xml_attribute)
78 xmlTextReaderRead(reader);
79 const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
82 *xml_attribute = strdup((const char *)attrib_val);
85 static void __save_xml_lang(xmlTextReaderPtr reader, char **xml_attribute)
87 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
88 if (attrib_val != NULL)
89 *xml_attribute = strdup(ASCII(attrib_val));
91 *xml_attribute = strdup(DEFAULT_LOCALE);
94 static void __save_xml_installed_time(manifest_x *mfx)
96 char buf[PKG_STRING_LEN_MAX] = {'\0'};
100 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
101 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
102 mfx->installed_time = val;
105 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
107 char root[PKG_STRING_LEN_MAX] = { '\0' };
113 tzplatform_set_user(uid);
114 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
115 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
117 mfx->root_path = strdup(root);
119 tzplatform_reset_user();
122 static void __save_xml_default_value(manifest_x * mfx)
124 mfx->preload = strdup("False");
125 mfx->removable = strdup("True");
126 mfx->readonly = strdup("False");
127 mfx->update = strdup("False");
128 mfx->system = strdup("False");
129 mfx->installed_storage = strdup("installed_internal");
130 package = mfx->package;
133 static int __next_child_element(xmlTextReaderPtr reader, int depth)
135 int ret = xmlTextReaderRead(reader);
136 int cur = xmlTextReaderDepth(reader);
139 switch (xmlTextReaderNodeType(reader)) {
140 case XML_READER_TYPE_ELEMENT:
141 if (cur == depth + 1)
144 case XML_READER_TYPE_TEXT:
145 /*text is handled by each function separately*/
146 if (cur == depth + 1)
149 case XML_READER_TYPE_END_ELEMENT:
158 ret = xmlTextReaderRead(reader);
159 cur = xmlTextReaderDepth(reader);
164 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
166 __save_xml_attribute(reader, "name", &label->name, NULL);
167 __save_xml_lang(reader, &label->lang);
168 __save_xml_value(reader, &label->text);
173 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
175 __save_xml_attribute(reader, "email", &author->email, NULL);
176 __save_xml_attribute(reader, "href", &author->href, NULL);
177 __save_xml_value(reader, &author->text);
181 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
183 __save_xml_lang(reader, &description->lang);
184 __save_xml_value(reader, &description->text);
188 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
190 __save_xml_lang(reader, &license->lang);
191 __save_xml_value(reader, &license->text);
195 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
197 __save_xml_attribute(reader, "type", &privilege->type, "tpk");
198 __save_xml_value(reader, &privilege->value);
201 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
207 depth = xmlTextReaderDepth(reader);
208 while ((ret = __next_child_element(reader, depth))) {
209 node = xmlTextReaderConstName(reader);
211 _LOGD("xmlTextReaderConstName value is NULL\n");
215 if (strcmp(ASCII(node), "privilege") == 0) {
216 privilege_x *privilege = calloc(1, sizeof(privilege_x));
217 if (privilege == NULL) {
218 _LOGD("Malloc Failed\n");
221 ret = __ps_process_privilege(reader, privilege);
225 *privileges = g_list_append(*privileges, (gpointer)privilege);
230 _LOGD("Processing privileges failed\n");
237 static char *__get_icon_with_path(const char *icon, uid_t uid)
239 char icon_with_path[BUFSIZE];
240 const char *app_path;
242 if (!icon || !package)
245 /* just use absolute path */
246 if (index(icon, '/'))
250 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
251 snprintf(icon_with_path, sizeof(icon_with_path),
252 "%s%s", getIconPath(uid, true), icon);
253 if (access(icon_with_path, F_OK) == 0)
256 snprintf(icon_with_path, sizeof(icon_with_path),
257 "%s%s", getIconPath(uid, false), icon);
258 if (access(icon_with_path, F_OK) == 0)
261 /* for backward compatibility (.../default/small/...)
262 * this should be removed
264 snprintf(icon_with_path, sizeof(icon_with_path),
265 "%sdefault/small/%s",
266 getIconPath(uid, true), icon);
267 if (access(icon_with_path, F_OK) == 0)
270 snprintf(icon_with_path, sizeof(icon_with_path),
271 "%sdefault/small/%s",
272 getIconPath(uid, false), icon);
273 if (access(icon_with_path, F_OK) == 0)
276 /* If doesn't exist in case of Global app,
277 * try to get icon directly into app's directory
279 app_path = tzplatform_getenv(TZ_SYS_RO_APP);
281 snprintf(icon_with_path, sizeof(icon_with_path),
282 "%s/%s/%s", app_path, package, icon);
283 if (access(icon_with_path, F_OK) == 0)
286 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
288 snprintf(icon_with_path, sizeof(icon_with_path),
289 "%s/%s/%s", app_path, package, icon);
290 if (access(icon_with_path, F_OK) == 0)
293 tzplatform_set_user(uid);
294 app_path = tzplatform_getenv(TZ_USER_APP);
295 tzplatform_reset_user();
297 snprintf(icon_with_path, sizeof(icon_with_path),
298 "%s/%s/%s", app_path, package, icon);
299 if (access(icon_with_path, F_OK) == 0)
303 /* some preload package has icons at below path */
304 snprintf(icon_with_path, sizeof(icon_with_path),
305 "%s/%s/res/icons/%s", app_path, package, icon);
306 if (access(icon_with_path, F_OK) == 0)
309 /* since 2.3 tpk package */
310 snprintf(icon_with_path, sizeof(icon_with_path),
311 "%s/%s/shared/res/%s", app_path, package, icon);
312 if (access(icon_with_path, F_OK) == 0)
315 _LOGE("cannot find icon path for [%s]", icon);
319 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
321 return strdup(icon_with_path);
324 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
326 __save_xml_attribute(reader, "section", &icon->section, NULL);
327 __save_xml_attribute(reader, "size", &icon->size, NULL);
328 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
329 __save_xml_lang(reader, &icon->lang);
331 xmlTextReaderRead(reader);
332 char *text = ASCII(xmlTextReaderValue(reader));
334 icon->text = __get_icon_with_path(text, uid);
341 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
343 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
344 __save_xml_value(reader, &compatibility->text);
348 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
350 __save_xml_attribute(reader, "section", &image->section, NULL);
351 __save_xml_lang(reader, &image->lang);
352 __save_xml_value(reader, &image->text);
356 static int __ps_process_category(xmlTextReaderPtr reader, char **category)
358 __save_xml_attribute(reader, "name", category, NULL);
362 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
364 __save_xml_attribute(reader, "key", &metadata->key, NULL);
365 __save_xml_attribute(reader, "value", &metadata->value, NULL);
369 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
371 __save_xml_attribute(reader, "type", &permission->type, NULL);
372 __save_xml_value(reader, &permission->value);
376 struct appcontrol_data {
381 char operation[BUFSIZE];
386 static void __ps_process_mime(gpointer data, gpointer user_data)
388 char *mime = (char *)data;
389 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
390 appcontrol_x *appcontrol;
392 snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
394 appcontrol = calloc(1, sizeof(appcontrol_x));
395 if (strlen(ad->operation))
396 appcontrol->operation = strdup(ad->operation);
398 appcontrol->uri = strdup(ad->uri);
399 appcontrol->mime = strdup(ad->mime);
400 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
403 static void __ps_process_uri(gpointer data, gpointer user_data)
405 char *uri = (char *)data;
406 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
407 appcontrol_x *appcontrol;
409 snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
411 if (ad->mimes != NULL) {
412 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
414 appcontrol = calloc(1, sizeof(appcontrol_x));
415 if (strlen(ad->operation))
416 appcontrol->operation = strdup(ad->operation);
417 appcontrol->uri = strdup(ad->uri);
418 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
422 static void __ps_process_operation(gpointer data, gpointer user_data)
424 char *operation = (char *)data;
425 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
426 appcontrol_x *appcontrol;
428 snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
430 if (ad->uris != NULL) {
431 g_list_foreach(ad->uris, __ps_process_uri, user_data);
432 } else if (ad->mimes != NULL) {
433 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
435 appcontrol = calloc(1, sizeof(appcontrol_x));
436 appcontrol->operation = strdup(ad->operation);
437 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
441 static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
443 struct appcontrol_data ad = {0, };
445 ad.operations = operations;
449 if (ad.operations == NULL)
452 g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
454 return ad.appcontrols;
457 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
463 GList *operations = NULL;
468 depth = xmlTextReaderDepth(reader);
469 while ((ret = __next_child_element(reader, depth)) > 0) {
470 node = xmlTextReaderConstName(reader);
472 _LOGD("xmlTextReaderConstName value is NULL\n");
477 if (!strcmp(ASCII(node), "operation")) {
478 __save_xml_attribute(reader, "name", &val, NULL);
480 operations = g_list_append(operations, (gpointer)val);
481 _LOGD("operation processing\n");
482 } else if (!strcmp(ASCII(node), "uri")) {
483 __save_xml_attribute(reader, "name", &val, NULL);
485 uris = g_list_append(uris, (gpointer)val);
486 _LOGD("uri processing\n");
487 } else if (!strcmp(ASCII(node), "mime")) {
488 __save_xml_attribute(reader, "name", &val, NULL);
490 mimes = g_list_append(mimes, (gpointer)val);
491 _LOGD("mime processing\n");
492 } else if (!strcmp(ASCII(node), "subapp")) {
500 _LOGD("Processing appcontrol failed\n");
501 g_list_free_full(operations, free);
502 g_list_free_full(uris, free);
503 g_list_free_full(mimes, free);
507 result = __make_appcontrol_list(operations, uris, mimes);
509 *appcontrol = g_list_concat(*appcontrol, result);
513 g_list_free_full(operations, free);
514 g_list_free_full(uris, free);
515 g_list_free_full(mimes, free);
520 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed)
522 __save_xml_value(reader, allowed);
526 static int __ps_process_request(xmlTextReaderPtr reader, char **request)
528 __save_xml_value(reader, request);
532 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
539 __save_xml_attribute(reader, "path", &define->path, NULL);
541 depth = xmlTextReaderDepth(reader);
542 while ((ret = __next_child_element(reader, depth))) {
543 node = xmlTextReaderConstName(reader);
545 _LOGD("xmlTextReaderConstName value is NULL\n");
549 if (!strcmp(ASCII(node), "allowed")) {
551 ret = __ps_process_allowed(reader, &val);
553 define->allowed = g_list_append(define->allowed, (gpointer)val);
554 } else if (!strcmp(ASCII(node), "request")) {
556 ret = __ps_process_request(reader, &val);
558 define->request = g_list_append(define->request, (gpointer)val);
563 _LOGD("Processing define failed\n");
570 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
576 depth = xmlTextReaderDepth(reader);
577 while ((ret = __next_child_element(reader, depth))) {
578 node = xmlTextReaderConstName(reader);
580 _LOGD("xmlTextReaderConstName value is NULL\n");
584 if (!strcmp(ASCII(node), "define")) {
585 define_x *define = calloc(1, sizeof(define_x));
586 if (define == NULL) {
587 _LOGD("Malloc Failed\n");
590 datashare->define = g_list_append(datashare->define, define);
591 ret = __ps_process_define(reader, define);
592 } else if (!strcmp(ASCII(node), "request")) {
594 ret = __ps_process_request(reader, &val);
596 datashare->request = g_list_append(datashare->request, (gpointer)val);
600 _LOGD("Processing data-share failed\n");
607 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition)
609 __save_xml_attribute(reader, "name", condition, NULL);
613 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
620 depth = xmlTextReaderDepth(reader);
621 while ((ret = __next_child_element(reader, depth))) {
622 node = xmlTextReaderConstName(reader);
624 _LOGD("xmlTextReaderConstName value is NULL\n");
628 if (strcmp(ASCII(node), "condition") == 0) {
630 ret = __ps_process_condition(reader, &val);
632 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
636 _LOGD("Processing launchconditions failed\n");
644 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
646 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
647 __save_xml_value(reader, ¬ification->text);
651 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
653 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
654 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
655 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
659 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
661 __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
662 __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
663 __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
664 __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
665 __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
666 __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
667 __save_xml_attribute(reader, "color-depth", &splashscreen->color_depth, NULL);
671 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
676 splashscreen_x *splashscreen;
678 depth = xmlTextReaderDepth(reader);
679 while ((ret = __next_child_element(reader, depth))) {
680 node = xmlTextReaderConstName(reader);
682 _LOGD("xmlTextReaderConstName value is NULL\n");
686 if (strcmp(ASCII(node), "splash-screen") == 0) {
687 splashscreen = calloc(1, sizeof(splashscreen_x));
688 if (splashscreen == NULL) {
689 _LOGD("Malloc Failed\n");
692 *splashscreens = g_list_append(*splashscreens, splashscreen);
693 ret = __ps_process_splashscreen(reader, splashscreen);
699 _LOGD("Processing splash-screen failed\n");
706 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
713 __save_xml_attribute(reader, "appid", &application->appid, NULL);
714 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
715 __save_xml_attribute(reader, "exec", &application->exec, NULL);
716 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
717 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
718 __save_xml_attribute(reader, "type", &application->type, NULL);
719 __save_xml_attribute(reader, "categories", &application->categories, NULL);
720 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
721 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
722 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
723 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
724 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
725 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
726 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
727 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
728 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
729 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
730 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
731 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
732 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
733 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
734 retvm_if(((strcmp(application->component_type, "svcapp") != 0) && (strcmp(application->component_type, "uiapp") != 0) && (strcmp(application->component_type, "widgetapp") != 0)), PM_PARSER_R_ERROR, "invalid component_type[%s]", application->component_type);
735 __save_xml_attribute(reader, "submode", &application->submode, "false");
736 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
737 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
738 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
739 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
740 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
741 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
742 __save_xml_attribute(reader, "splash-screen-display", &application->splash_screen_display, "true");
744 application->package = strdup(package);
745 /* overwrite some attributes if the app is widgetapp */
746 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
747 free((void *)application->nodisplay);
748 application->nodisplay = strdup("true");
749 free((void *)application->multiple);
750 application->multiple = strdup("true");
751 free((void *)application->type);
752 application->type = strdup("capp");
753 free((void *)application->taskmanage);
754 application->taskmanage = strdup("false");
755 free((void *)application->indicatordisplay);
756 application->indicatordisplay = strdup("false");
759 /* hw-acceleration values are changed from use-GL/not-use-GL/use-system-setting to on/off/default */
760 if (strcmp(application->hwacceleration, "use-GL") == 0) {
761 free((void *)application->hwacceleration);
762 application->hwacceleration = strdup("on");
763 } else if (strcmp(application->hwacceleration, "not-use-GL") == 0) {
764 free((void *)application->hwacceleration);
765 application->hwacceleration = strdup("off");
766 } else if (strcmp(application->hwacceleration, "use-system-setting") == 0) {
767 free((void *)application->hwacceleration);
768 application->hwacceleration = strdup("default");
771 depth = xmlTextReaderDepth(reader);
772 while ((ret = __next_child_element(reader, depth))) {
773 node = xmlTextReaderConstName(reader);
775 _LOGD("xmlTextReaderConstName value is NULL\n");
778 if (!strcmp(ASCII(node), "label")) {
779 label_x *label = calloc(1, sizeof(label_x));
781 _LOGD("Malloc Failed\n");
784 application->label = g_list_append(application->label, label);
785 ret = __ps_process_label(reader, label);
786 } else if (!strcmp(ASCII(node), "icon")) {
787 icon_x *icon = calloc(1, sizeof(icon_x));
789 _LOGD("Malloc Failed\n");
792 application->icon = g_list_append(application->icon, icon);
793 ret = __ps_process_icon(reader, icon, uid);
794 } else if (!strcmp(ASCII(node), "image")) {
795 image_x *image = calloc(1, sizeof(image_x));
797 _LOGD("Malloc Failed\n");
800 application->image = g_list_append(application->image, image);
801 ret = __ps_process_image(reader, image);
802 } else if (!strcmp(ASCII(node), "category")) {
804 ret = __ps_process_category(reader, &val);
806 application->category = g_list_append(application->category, (gpointer)val);
807 } else if (!strcmp(ASCII(node), "metadata")) {
808 metadata_x *metadata = calloc(1, sizeof(metadata_x));
809 if (metadata == NULL) {
810 _LOGD("Malloc Failed\n");
813 application->metadata = g_list_append(application->metadata, metadata);
814 ret = __ps_process_metadata(reader, metadata);
815 } else if (!strcmp(ASCII(node), "permission")) {
816 permission_x *permission = calloc(1, sizeof(permission_x));
817 if (permission == NULL) {
818 _LOGD("Malloc Failed\n");
821 application->permission = g_list_append(application->permission, permission);
822 ret = __ps_process_permission(reader, permission);
823 } else if (!strcmp(ASCII(node), "app-control")) {
824 ret = __ps_process_appcontrol(reader, &application->appcontrol);
825 } else if (!strcmp(ASCII(node), "application-service")) {
826 ret = __ps_process_appcontrol(reader, &application->appcontrol);
827 } else if (!strcmp(ASCII(node), "data-share")) {
828 datashare_x *datashare = calloc(1, sizeof(datashare_x));
829 if (datashare == NULL) {
830 _LOGD("Malloc Failed\n");
833 application->datashare = g_list_append(application->datashare, datashare);
834 ret = __ps_process_datashare(reader, datashare);
835 } else if (!strcmp(ASCII(node), "launch-conditions")) {
836 ret = __ps_process_launchconditions(reader, &application->launchconditions);
837 } else if (!strcmp(ASCII(node), "notification")) {
838 notification_x *notification = calloc(1, sizeof(notification_x));
839 if (notification == NULL) {
840 _LOGD("Malloc Failed\n");
843 application->notification = g_list_append(application->notification, notification);
844 ret = __ps_process_notification(reader, notification);
845 } else if (!strcmp(ASCII(node), "datacontrol")) {
846 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
847 if (datacontrol == NULL) {
848 _LOGD("Malloc Failed\n");
851 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
852 ret = __ps_process_datacontrol(reader, datacontrol);
853 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
854 ret = __ps_process_splashscreens(reader, &application->splashscreens);
858 _LOGD("Processing application failed\n");
866 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
868 _LOGD("__start_process\n");
873 depth = xmlTextReaderDepth(reader);
874 while ((ret = __next_child_element(reader, depth))) {
875 node = xmlTextReaderConstName(reader);
877 _LOGD("xmlTextReaderConstName value is NULL\n");
881 if (!strcmp(ASCII(node), "label")) {
882 label_x *label = calloc(1, sizeof(label_x));
884 _LOGD("Malloc Failed\n");
887 mfx->label = g_list_append(mfx->label, label);
888 ret = __ps_process_label(reader, label);
889 } else if (!strcmp(ASCII(node), "author")) {
890 author_x *author = calloc(1, sizeof(author_x));
891 if (author == NULL) {
892 _LOGD("Malloc Failed\n");
895 mfx->author = g_list_append(mfx->author, author);
896 ret = __ps_process_author(reader, author);
897 } else if (!strcmp(ASCII(node), "description")) {
898 description_x *description = calloc(1, sizeof(description_x));
899 if (description == NULL) {
900 _LOGD("Malloc Failed\n");
903 mfx->description = g_list_append(mfx->description, description);
904 ret = __ps_process_description(reader, description);
905 } else if (!strcmp(ASCII(node), "license")) {
906 license_x *license = calloc(1, sizeof(license_x));
907 if (license == NULL) {
908 _LOGD("Malloc Failed\n");
911 mfx->license = g_list_append(mfx->license, license);
912 ret = __ps_process_license(reader, license);
913 } else if (!strcmp(ASCII(node), "privileges")) {
914 ret = __ps_process_privileges(reader, &mfx->privileges);
915 } else if (!strcmp(ASCII(node), "ui-application")) {
916 application_x *application = calloc(1, sizeof(application_x));
917 if (application == NULL) {
918 _LOGD("Malloc Failed\n");
921 mfx->application = g_list_append(mfx->application, application);
922 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
923 } else if (!strcmp(ASCII(node), "service-application")) {
924 application_x *application = calloc(1, sizeof(application_x));
925 if (application == NULL) {
926 _LOGD("Malloc Failed\n");
929 mfx->application = g_list_append(mfx->application, application);
930 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
931 } else if (!strcmp(ASCII(node), "widget-application")) {
932 application_x *application = calloc(1, sizeof(application_x));
933 if (application == NULL) {
934 _LOGD("Malloc Failed\n");
937 mfx->application = g_list_append(mfx->application, application);
938 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
939 } else if (!strcmp(ASCII(node), "watch-application")) {
940 application_x *application = calloc(1, sizeof(application_x));
941 if (application == NULL) {
942 _LOGD("Malloc Failed\n");
945 mfx->application = g_list_append(mfx->application, application);
946 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
947 } else if (!strcmp(ASCII(node), "icon")) {
948 icon_x *icon = calloc(1, sizeof(icon_x));
950 _LOGD("Malloc Failed\n");
953 mfx->icon = g_list_append(mfx->icon, icon);
954 ret = __ps_process_icon(reader, icon, uid);
955 } else if (!strcmp(ASCII(node), "compatibility")) {
956 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
957 if (compatibility == NULL) {
958 _LOGD("Malloc Failed\n");
961 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
962 ret = __ps_process_compatibility(reader, compatibility);
963 } else if (!strcmp(ASCII(node), "shortcut-list")) {
965 } else if (!strcmp(ASCII(node), "livebox")) {
967 } else if (!strcmp(ASCII(node), "account")) {
969 } else if (!strcmp(ASCII(node), "notifications")) {
971 } else if (!strcmp(ASCII(node), "ime")) {
973 } else if (!strcmp(ASCII(node), "feature")) {
976 _LOGI("Unknown element: %s", ASCII(node));
981 _LOGD("Processing manifest failed\n");
988 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
993 if ((ret = __next_child_element(reader, -1))) {
994 node = xmlTextReaderConstName(reader);
996 _LOGD("xmlTextReaderConstName value is NULL\n");
1000 if (!strcmp(ASCII(node), "manifest")) {
1001 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1002 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1003 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1004 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1005 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1006 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1007 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1008 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1009 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1010 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1011 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1012 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1013 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1014 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1015 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1017 __save_xml_installed_time(mfx);
1018 __save_xml_root_path(mfx, uid);
1019 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1020 __save_xml_default_value(mfx);
1022 ret = __start_process(reader, mfx, uid);
1024 _LOGD("No Manifest element found\n");
1031 DEPRECATED API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
1033 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
1034 xmlTextReaderPtr reader;
1035 manifest_x *mfx = NULL;
1037 reader = xmlReaderForFile(manifest, NULL, 0);
1039 mfx = malloc(sizeof(manifest_x));
1041 memset(mfx, '\0', sizeof(manifest_x));
1042 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
1043 _LOGD("Parsing Failed\n");
1044 pkgmgr_parser_free_manifest_xml(mfx);
1047 _LOGD("Parsing Success\n");
1049 _LOGD("Memory allocation error\n");
1051 xmlFreeTextReader(reader);
1053 _LOGD("Unable to create xml reader\n");
1058 DEPRECATED API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
1060 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
1061 xmlTextReaderPtr reader;
1062 manifest_x *mfx = NULL;
1064 reader = xmlReaderForFile(manifest, NULL, 0);
1066 mfx = malloc(sizeof(manifest_x));
1068 memset(mfx, '\0', sizeof(manifest_x));
1069 if (__process_manifest(reader, mfx, uid) < 0) {
1070 _LOGD("Parsing Failed\n");
1071 pkgmgr_parser_free_manifest_xml(mfx);
1074 _LOGD("Parsing Success\n");
1076 _LOGD("Memory allocation error\n");
1078 xmlFreeTextReader(reader);
1080 _LOGD("Unable to create xml reader\n");
1085 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1088 char delims[] = "=";
1089 char *ret_result = NULL;
1096 for (tag = strdup(tagv[0]); tag != NULL; ) {
1097 ret_result = strtok_r(tag, delims, &ptr);
1099 /*check tag : preload */
1100 if (strcmp(ret_result, "preload") == 0) {
1101 ret_result = strtok_r(NULL, delims, &ptr);
1102 if (strcmp(ret_result, "true") == 0) {
1103 free((void *)mfx->preload);
1104 mfx->preload = strdup("true");
1105 } else if (strcmp(ret_result, "false") == 0) {
1106 free((void *)mfx->preload);
1107 mfx->preload = strdup("false");
1109 /*check tag : removable*/
1110 } else if (strcmp(ret_result, "removable") == 0) {
1111 ret_result = strtok_r(NULL, delims, &ptr);
1112 if (strcmp(ret_result, "true") == 0) {
1113 free((void *)mfx->removable);
1114 mfx->removable = strdup("true");
1115 } else if (strcmp(ret_result, "false") == 0) {
1116 free((void *)mfx->removable);
1117 mfx->removable = strdup("false");
1119 /*check tag : not matched*/
1121 _LOGD("tag process [%s]is not defined\n", ret_result);
1125 /*check next value*/
1126 if (tagv[++i] != NULL)
1127 tag = strdup(tagv[i]);
1129 _LOGD("tag process success...\n");
1135 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
1136 ACTION_TYPE action, const char *pkgid)
1138 int (*plugin_install) (xmlDocPtr, const char *);
1143 case ACTION_INSTALL:
1144 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
1146 case ACTION_UPGRADE:
1147 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
1149 case ACTION_UNINSTALL:
1150 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
1156 if ((plugin_install =
1157 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1158 _LOGE("can not find symbol[%s] \n", ac);
1162 ret = plugin_install(docPtr, pkgid);
1163 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
1169 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
1172 const xmlChar *name;
1174 if (xmlTextReaderDepth(reader) != 1) {
1175 _LOGE("Node depth is not 1");
1179 if (xmlTextReaderNodeType(reader) != 1) {
1180 _LOGE("Node type is not 1");
1184 const xmlChar *value;
1185 name = xmlTextReaderConstName(reader);
1187 _LOGE("TEST TEST TES\n");
1188 name = BAD_CAST "--";
1191 value = xmlTextReaderConstValue(reader);
1192 if (value != NULL) {
1193 if (xmlStrlen(value) > 40)
1194 _LOGD(" %.40s...", value);
1196 _LOGD(" %s", value);
1199 name = xmlTextReaderConstName(reader);
1201 _LOGE("TEST TEST TES\n");
1202 name = BAD_CAST "--";
1205 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
1206 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
1207 if (copyDocPtr == NULL)
1209 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
1210 if (rootElement == NULL)
1212 xmlNode *cur_node = xmlFirstElementChild(rootElement);
1213 if (cur_node == NULL)
1215 xmlNode *temp = xmlTextReaderExpand(reader);
1218 xmlNode *next_node = NULL;
1219 while (cur_node != NULL) {
1220 if ((strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
1221 (temp->line == cur_node->line)) {
1224 next_node = xmlNextElementSibling(cur_node);
1225 xmlUnlinkNode(cur_node);
1226 xmlFreeNode(cur_node);
1227 cur_node = next_node;
1230 if (cur_node == NULL)
1232 next_node = xmlNextElementSibling(cur_node);
1234 cur_node->next = NULL;
1235 next_node->prev = NULL;
1236 xmlFreeNodeList(next_node);
1237 xmlSetTreeDoc(cur_node, copyDocPtr);
1239 xmlSetTreeDoc(cur_node, copyDocPtr);
1242 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
1248 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
1250 switch (xmlTextReaderNodeType(reader)) {
1251 case XML_READER_TYPE_END_ELEMENT:
1255 case XML_READER_TYPE_ELEMENT:
1257 /* Elements without closing tag don't receive */
1258 const xmlChar *elementName =
1259 xmlTextReaderLocalName(reader);
1260 if (elementName == NULL)
1263 if (strcmp(tag, ASCII(elementName)) == 0) {
1264 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
1265 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
1276 static void __str_trim(char *input)
1278 char *trim_str = input;
1283 while (*input != 0) {
1284 if (!isspace(*input)) {
1295 static char *__get_parser_plugin(const char *type)
1298 char buffer[1024] = { 0 };
1299 char temp_path[1024] = { 0 };
1303 _LOGE("invalid argument\n");
1307 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1309 _LOGE("no matching backendlib\n");
1313 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1314 if (buffer[0] == '#')
1319 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
1320 path = path + strlen(PKG_PARSERLIB);
1324 memset(buffer, 0x00, 1024);
1331 _LOGE("no matching backendlib\n");
1335 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1337 return strdup(temp_path);
1340 static void *__open_lib_handle(char *tag)
1342 char *lib_path = NULL;
1343 void *lib_handle = NULL;
1345 lib_path = __get_parser_plugin(tag);
1346 retvm_if(!lib_path, NULL, "lib_path get fail");
1348 lib_handle = dlopen(lib_path, RTLD_LAZY);
1349 retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
1354 static void __close_lib_handle(void *lib_handle)
1356 dlclose(lib_handle);
1359 static char * __get_tag_by_key(char *md_key)
1361 char *md_tag = NULL;
1363 if (md_key == NULL) {
1364 _LOGD("md_key is NULL\n");
1368 md_tag = strrchr(md_key, 47) + 1;
1371 return strdup(md_tag);
1374 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1376 int (*plugin_install) (const char *);
1380 if (process == PLUGIN_PRE_PROCESS) {
1382 case ACTION_INSTALL:
1383 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
1385 case ACTION_UPGRADE:
1386 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
1388 case ACTION_UNINSTALL:
1389 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
1394 } else if (process == PLUGIN_POST_PROCESS) {
1396 case ACTION_INSTALL:
1397 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
1399 case ACTION_UPGRADE:
1400 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
1402 case ACTION_UNINSTALL:
1403 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
1411 if ((plugin_install =
1412 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1416 ret = plugin_install(pkgid);
1420 static int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1422 xmlTextReaderPtr reader;
1426 void *lib_handle = NULL;
1427 char tag[PKG_STRING_LEN_MAX] = { 0 };
1429 fp = fopen(TAG_PARSER_LIST, "r");
1430 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1432 while (fgets(tag, sizeof(tag), fp) != NULL) {
1435 lib_handle = __open_lib_handle(tag);
1436 if (lib_handle == NULL)
1439 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1440 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1442 docPtr = xmlReadFile(filename, NULL, 0);
1443 reader = xmlReaderWalker(docPtr);
1444 if (reader != NULL) {
1445 ret = xmlTextReaderRead(reader);
1447 __process_tag(lib_handle, reader, action, tag, mfx->package);
1448 ret = xmlTextReaderRead(reader);
1450 xmlFreeTextReader(reader);
1453 _LOGD("%s : failed to parse", filename);
1455 _LOGD("Unable to open %s", filename);
1458 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1459 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1461 __close_lib_handle(lib_handle);
1463 memset(tag, 0x00, sizeof(tag));
1472 static void __metadata_parser_clear_dir_list(GList* dir_list)
1475 __metadata_t* detail = NULL;
1478 list = g_list_first(dir_list);
1480 detail = (__metadata_t *)list->data;
1483 free((void *)detail->key);
1485 free((void *)detail->value);
1488 list = g_list_next(list);
1490 g_list_free(dir_list);
1494 static char *__get_metadata_parser_plugin(const char *type)
1497 char buffer[1024] = { 0 };
1498 char temp_path[1024] = { 0 };
1502 _LOGE("invalid argument\n");
1506 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1508 _LOGE("no matching metadata parser\n");
1512 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1513 if (buffer[0] == '#')
1518 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
1519 path = path + strlen(METADATA_PARSER_NAME);
1524 memset(buffer, 0x00, 1024);
1531 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME, type);
1535 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1537 return strdup(temp_path);
1540 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
1541 ACTION_TYPE action, const char *pkgid, const char *appid)
1543 char *lib_path = NULL;
1544 void *lib_handle = NULL;
1545 int (*metadata_parser_plugin) (const char *, const char *, GList *);
1550 case ACTION_INSTALL:
1551 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
1553 case ACTION_UPGRADE:
1554 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
1556 case ACTION_UNINSTALL:
1557 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
1563 lib_path = __get_metadata_parser_plugin(tag);
1565 _LOGE("get %s parser fail\n", tag);
1569 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1570 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1574 if ((metadata_parser_plugin =
1575 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1576 _LOGE("can not find symbol[%s] \n", ac);
1580 ret = metadata_parser_plugin(pkgid, appid, md_list);
1582 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1584 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1590 dlclose(lib_handle);
1594 static int __run_metadata_parser_prestep(manifest_x *mfx, char *md_key, ACTION_TYPE action)
1598 char buffer[1024] = { 0, };
1601 GList *md_tmp = NULL;
1603 char *md_tag = NULL;
1605 GList *md_list = NULL;
1606 __metadata_t *md_detail = NULL;
1608 md_tag = __get_tag_by_key(md_key);
1609 if (md_tag == NULL) {
1610 _LOGD("md_tag is NULL\n");
1614 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1615 app = (application_x *)app_tmp->data;
1618 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1619 md = (metadata_x *)md_tmp->data;
1622 /* get glist of metadata key and value combination */
1623 memset(buffer, 0x00, 1024);
1624 snprintf(buffer, 1024, "%s/", md_key);
1625 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
1626 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
1627 if (md_detail == NULL) {
1628 _LOGD("Memory allocation failed\n");
1632 md_detail->key = strdup(md->key);
1633 if (md_detail->key == NULL) {
1634 _LOGD("Memory allocation failed\n");
1639 md_detail->value = strdup(md->value);
1640 if (md_detail->value == NULL) {
1641 _LOGD("Memory allocation failed\n");
1642 free((void *)md_detail->key);
1647 md_list = g_list_append(md_list, (gpointer)md_detail);
1652 /* send glist to parser when tags for metadata plugin parser exist. */
1654 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
1656 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
1658 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
1660 __metadata_parser_clear_dir_list(md_list);
1667 __metadata_parser_clear_dir_list(md_list);
1675 static int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1677 fprintf(stdout, "__ps_process_metadata_parser\n");
1680 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1682 fp = fopen(METADATA_PARSER_LIST, "r");
1684 _LOGD("no preload list\n");
1688 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1690 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1701 static void __category_parser_clear_dir_list(GList* dir_list)
1704 __category_t* detail = NULL;
1707 list = g_list_first(dir_list);
1709 detail = (__category_t *)list->data;
1712 free((void *)detail->name);
1716 list = g_list_next(list);
1718 g_list_free(dir_list);
1722 static char *__get_category_parser_plugin(const char *type)
1725 char buffer[1024] = { 0 };
1726 char temp_path[1024] = { 0 };
1730 _LOGE("invalid argument\n");
1734 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1736 _LOGE("no matching metadata parser\n");
1740 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1741 if (buffer[0] == '#')
1746 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
1747 path = path + strlen(CATEGORY_PARSER_NAME);
1752 memset(buffer, 0x00, 1024);
1759 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME, type);
1763 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1765 return strdup(temp_path);
1768 static int __ps_run_category_parser(GList *category_list, const char *tag,
1769 ACTION_TYPE action, const char *pkgid, const char *appid)
1771 char *lib_path = NULL;
1772 void *lib_handle = NULL;
1773 int (*category_parser_plugin) (const char *, const char *, GList *);
1778 case ACTION_INSTALL:
1779 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
1781 case ACTION_UPGRADE:
1782 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
1784 case ACTION_UNINSTALL:
1785 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
1791 lib_path = __get_category_parser_plugin(tag);
1793 _LOGE("get %s parser fail\n", tag);
1797 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1798 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1802 if ((category_parser_plugin =
1803 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1804 _LOGE("can not find symbol[%s] \n", ac);
1808 ret = category_parser_plugin(pkgid, appid, category_list);
1810 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1812 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1818 dlclose(lib_handle);
1822 static int __run_category_parser_prestep(manifest_x *mfx, char *category_key, ACTION_TYPE action)
1826 char buffer[1024] = { 0, };
1829 GList *category_tmp;
1830 const char *category;
1831 char *category_tag = NULL;
1833 GList *category_list = NULL;
1834 __category_t *category_detail = NULL;
1836 category_tag = __get_tag_by_key(category_key);
1837 if (category_tag == NULL) {
1838 _LOGD("md_tag is NULL\n");
1842 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1843 app = (application_x *)app_tmp->data;
1846 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
1847 category = (const char *)category_tmp->data;
1848 /* get glist of category key and value combination */
1849 memset(buffer, 0x00, 1024);
1850 snprintf(buffer, 1024, "%s/", category_key);
1851 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
1852 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
1853 if (category_detail == NULL) {
1854 _LOGD("Memory allocation failed\n");
1858 category_detail->name = strdup(category);
1859 if (category_detail->name == NULL) {
1860 _LOGD("Memory allocation failed\n");
1861 free(category_detail);
1865 category_list = g_list_append(category_list, (gpointer)category_detail);
1870 /* send glist to parser when tags for metadata plugin parser exist. */
1872 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
1874 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
1876 _LOGD("category_parser success for tag[%s]\n", category_tag);
1878 __category_parser_clear_dir_list(category_list);
1879 category_list = NULL;
1885 __category_parser_clear_dir_list(category_list);
1893 static int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1897 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1899 fp = fopen(CATEGORY_PARSER_LIST, "r");
1901 _LOGD("no category parser list\n");
1905 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1906 __str_trim(category_key);
1907 ret = __run_category_parser_prestep(mfx, category_key, action);
1918 DEPRECATED API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
1920 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1921 _LOGD("parsing manifest for installation: %s\n", manifest);
1923 manifest_x *mfx = NULL;
1927 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1928 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1930 _LOGD("Parsing Finished\n");
1932 __ps_process_tag(mfx, tagv);
1934 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
1935 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
1937 _LOGD("DB Insert Success\n");
1939 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1940 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1942 _LOGD("Creating metadata parser failed\n");
1944 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1946 _LOGD("Creating category parser failed\n");
1948 pkgmgr_parser_free_manifest_xml(mfx);
1949 _LOGD("Free Done\n");
1955 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
1957 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1958 _LOGD("parsing manifest for installation: %s\n", manifest);
1959 manifest_x *mfx = NULL;
1963 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
1964 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1966 _LOGD("Parsing Finished\n");
1968 __ps_process_tag(mfx, tagv);
1970 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
1971 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
1973 _LOGD("DB Insert Success\n");
1975 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1976 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1978 _LOGD("Creating metadata parser failed\n");
1979 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1981 _LOGD("Creating category parser failed\n");
1983 pkgmgr_parser_free_manifest_xml(mfx);
1984 _LOGD("Free Done\n");
1990 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1992 if (!strstr(manifest, getUserManifestPath(uid,
1993 strcmp(mfx->preload, "true") == 0))) {
1994 /* if downloaded app is updated, then update tag set true*/
1996 free((void *)mfx->update);
1997 mfx->update = strdup("true");
2003 DEPRECATED API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2005 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2006 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2007 manifest_x *mfx = NULL;
2009 bool preload = false;
2010 bool system = false;
2011 char *csc_path = NULL;
2012 pkgmgrinfo_pkginfo_h handle = NULL;
2015 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2016 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2018 _LOGD("Parsing Finished\n");
2019 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2021 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2022 if (ret != PMINFO_R_OK)
2023 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2024 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2025 if (ret != PMINFO_R_OK)
2026 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2029 free((void *)mfx->preload);
2030 mfx->preload = strdup("true");
2033 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2034 if (ret != PMINFO_R_OK)
2035 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2037 free((void *)mfx->system);
2038 mfx->system = strdup("true");
2041 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2042 if (ret != PMINFO_R_OK)
2043 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2045 if (csc_path != NULL) {
2047 free((void *)mfx->csc_path);
2048 mfx->csc_path = strdup(csc_path);
2051 /*Delete from cert table*/
2052 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2054 _LOGD("Cert Info DB Delete Failed\n");
2058 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2059 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2061 _LOGD("DB Update Success\n");
2063 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2064 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2066 _LOGD("Upgrade metadata parser failed\n");
2067 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2069 _LOGD("Creating category parser failed\n");
2070 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2071 pkgmgr_parser_free_manifest_xml(mfx);
2072 _LOGD("Free Done\n");
2078 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2080 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2081 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2082 manifest_x *mfx = NULL;
2084 bool preload = false;
2085 bool system = false;
2086 char *csc_path = NULL;
2087 pkgmgrinfo_pkginfo_h handle = NULL;
2090 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2091 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2093 _LOGD("Parsing Finished\n");
2094 __check_preload_updated(mfx, manifest, uid);
2096 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2097 if (ret != PMINFO_R_OK)
2098 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2099 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2100 if (ret != PMINFO_R_OK)
2101 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2104 free((void *)mfx->preload);
2105 mfx->preload = strdup("true");
2108 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2109 if (ret != PMINFO_R_OK)
2110 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2113 free((void *)mfx->system);
2114 mfx->system = strdup("true");
2117 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2118 if (ret != PMINFO_R_OK)
2119 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2120 if (csc_path != NULL) {
2122 free((void *)mfx->csc_path);
2123 mfx->csc_path = strdup(csc_path);
2126 /*Delete from cert table*/
2127 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2129 _LOGD("Cert Info DB Delete Failed\n");
2133 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2134 retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2135 _LOGD("DB Update Success\n");
2137 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2138 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2140 _LOGD("Upgrade metadata parser failed\n");
2141 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2143 _LOGD("Creating category parser failed\n");
2144 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2145 pkgmgr_parser_free_manifest_xml(mfx);
2146 _LOGD("Free Done\n");
2152 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2154 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2155 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2157 manifest_x *mfx = NULL;
2160 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2161 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2163 _LOGD("Parsing Finished\n");
2165 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2167 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2169 _LOGD("Removing metadata parser failed\n");
2171 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2173 _LOGD("Creating category parser failed\n");
2175 /*Delete from cert table*/
2176 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2178 _LOGD("Cert Info DB Delete Failed\n");
2182 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2184 _LOGD("DB Delete failed\n");
2186 _LOGD("DB Delete Success\n");
2188 pkgmgr_parser_free_manifest_xml(mfx);
2189 _LOGD("Free Done\n");
2195 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
2197 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
2199 void *lib_handle = NULL;
2200 int (*appsvc_operation) (const char *, uid_t);
2203 application_x *application;
2205 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
2206 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
2210 if ((appsvc_operation =
2211 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
2212 _LOGE("can not find symbol \n");
2216 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2217 application = (application_x *)tmp->data;
2218 if (application == NULL)
2220 ret = appsvc_operation(application->appid, uid);
2222 _LOGE("can not operation symbol \n");
2227 dlclose(lib_handle);
2232 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2234 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2235 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2237 manifest_x *mfx = NULL;
2240 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2241 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2243 _LOGD("Parsing Finished\n");
2245 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2247 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2249 _LOGD("Removing metadata parser failed\n");
2251 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2253 _LOGD("Creating category parser failed\n");
2255 /*Delete from cert table*/
2256 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2258 _LOGD("Cert Info DB Delete Failed\n");
2262 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2264 _LOGD("DB Delete failed\n");
2266 _LOGD("DB Delete Success\n");
2268 ret = __ps_remove_appsvc_db(mfx, uid);
2270 _LOGD("Removing appsvc_db failed\n");
2272 _LOGD("Removing appsvc_db Success\n");
2274 pkgmgr_parser_free_manifest_xml(mfx);
2275 _LOGD("Free Done\n");