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)
79 const xmlChar *attrib_val;
81 ret = xmlTextReaderRead(reader);
84 attrib_val = xmlTextReaderConstValue(reader);
87 *xml_attribute = strdup((const char *)attrib_val);
90 static void __save_xml_lang(xmlTextReaderPtr reader, char **xml_attribute)
92 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
93 if (attrib_val != NULL)
94 *xml_attribute = strdup(ASCII(attrib_val));
96 *xml_attribute = strdup(DEFAULT_LOCALE);
99 static void __save_xml_installed_time(manifest_x *mfx)
101 char buf[PKG_STRING_LEN_MAX] = {'\0'};
105 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
106 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
107 mfx->installed_time = val;
110 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
112 char root[PKG_STRING_LEN_MAX] = { '\0' };
118 tzplatform_set_user(uid);
119 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
120 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
122 mfx->root_path = strdup(root);
124 tzplatform_reset_user();
127 static void __save_xml_default_value(manifest_x * mfx)
129 mfx->preload = strdup("False");
130 mfx->removable = strdup("True");
131 mfx->readonly = strdup("False");
132 mfx->update = strdup("False");
133 mfx->system = strdup("False");
134 mfx->installed_storage = strdup("installed_internal");
135 package = mfx->package;
138 static int __next_child_element(xmlTextReaderPtr reader, int depth)
140 int ret = xmlTextReaderRead(reader);
141 int cur = xmlTextReaderDepth(reader);
144 switch (xmlTextReaderNodeType(reader)) {
145 case XML_READER_TYPE_ELEMENT:
146 if (cur == depth + 1)
149 case XML_READER_TYPE_TEXT:
150 /*text is handled by each function separately*/
151 if (cur == depth + 1)
154 case XML_READER_TYPE_END_ELEMENT:
163 ret = xmlTextReaderRead(reader);
164 cur = xmlTextReaderDepth(reader);
169 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
171 __save_xml_attribute(reader, "name", &label->name, NULL);
172 __save_xml_lang(reader, &label->lang);
173 __save_xml_value(reader, &label->text);
178 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
180 __save_xml_attribute(reader, "email", &author->email, NULL);
181 __save_xml_attribute(reader, "href", &author->href, NULL);
182 __save_xml_value(reader, &author->text);
186 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
188 __save_xml_lang(reader, &description->lang);
189 __save_xml_value(reader, &description->text);
193 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
195 __save_xml_lang(reader, &license->lang);
196 __save_xml_value(reader, &license->text);
200 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
202 __save_xml_attribute(reader, "type", &privilege->type, "tpk");
203 __save_xml_value(reader, &privilege->value);
206 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
212 depth = xmlTextReaderDepth(reader);
213 while ((ret = __next_child_element(reader, depth))) {
214 node = xmlTextReaderConstName(reader);
216 _LOGD("xmlTextReaderConstName value is NULL\n");
220 if (strcmp(ASCII(node), "privilege") == 0) {
221 privilege_x *privilege = calloc(1, sizeof(privilege_x));
222 if (privilege == NULL) {
223 _LOGD("Malloc Failed\n");
226 ret = __ps_process_privilege(reader, privilege);
230 *privileges = g_list_append(*privileges, (gpointer)privilege);
235 _LOGD("Processing privileges failed\n");
242 static char *__get_icon_with_path(const char *icon, uid_t uid)
244 char icon_with_path[BUFSIZE];
245 const char *app_path;
247 if (!icon || !package)
250 /* just use absolute path */
251 if (index(icon, '/'))
255 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
256 snprintf(icon_with_path, sizeof(icon_with_path),
257 "%s%s", getIconPath(uid, true), icon);
258 if (access(icon_with_path, F_OK) == 0)
261 snprintf(icon_with_path, sizeof(icon_with_path),
262 "%s%s", getIconPath(uid, false), icon);
263 if (access(icon_with_path, F_OK) == 0)
266 /* for backward compatibility (.../default/small/...)
267 * this should be removed
269 snprintf(icon_with_path, sizeof(icon_with_path),
270 "%sdefault/small/%s",
271 getIconPath(uid, true), icon);
272 if (access(icon_with_path, F_OK) == 0)
275 snprintf(icon_with_path, sizeof(icon_with_path),
276 "%sdefault/small/%s",
277 getIconPath(uid, false), icon);
278 if (access(icon_with_path, F_OK) == 0)
281 /* If doesn't exist in case of Global app,
282 * try to get icon directly into app's directory
284 app_path = tzplatform_getenv(TZ_SYS_RO_APP);
286 snprintf(icon_with_path, sizeof(icon_with_path),
287 "%s/%s/%s", app_path, package, icon);
288 if (access(icon_with_path, F_OK) == 0)
291 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
293 snprintf(icon_with_path, sizeof(icon_with_path),
294 "%s/%s/%s", app_path, package, icon);
295 if (access(icon_with_path, F_OK) == 0)
298 tzplatform_set_user(uid);
299 app_path = tzplatform_getenv(TZ_USER_APP);
300 tzplatform_reset_user();
302 snprintf(icon_with_path, sizeof(icon_with_path),
303 "%s/%s/%s", app_path, package, icon);
304 if (access(icon_with_path, F_OK) == 0)
308 /* some preload package has icons at below path */
309 snprintf(icon_with_path, sizeof(icon_with_path),
310 "%s/%s/res/icons/%s", app_path, package, icon);
311 if (access(icon_with_path, F_OK) == 0)
314 /* since 2.3 tpk package */
315 snprintf(icon_with_path, sizeof(icon_with_path),
316 "%s/%s/shared/res/%s", app_path, package, icon);
317 if (access(icon_with_path, F_OK) == 0)
320 _LOGE("cannot find icon path for [%s]", icon);
324 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
326 return strdup(icon_with_path);
329 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
334 __save_xml_attribute(reader, "section", &icon->section, NULL);
335 __save_xml_attribute(reader, "size", &icon->size, NULL);
336 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
337 __save_xml_lang(reader, &icon->lang);
339 ret = xmlTextReaderRead(reader);
342 text = ASCII(xmlTextReaderValue(reader));
344 icon->text = __get_icon_with_path(text, uid);
351 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
353 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
354 __save_xml_value(reader, &compatibility->text);
358 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
360 __save_xml_attribute(reader, "section", &image->section, NULL);
361 __save_xml_lang(reader, &image->lang);
362 __save_xml_value(reader, &image->text);
366 static int __ps_process_category(xmlTextReaderPtr reader, char **category)
368 __save_xml_attribute(reader, "name", category, NULL);
372 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
374 __save_xml_attribute(reader, "key", &metadata->key, NULL);
375 __save_xml_attribute(reader, "value", &metadata->value, NULL);
379 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
381 __save_xml_attribute(reader, "type", &permission->type, NULL);
382 __save_xml_value(reader, &permission->value);
386 struct appcontrol_data {
391 char operation[BUFSIZE];
396 static void __ps_process_mime(gpointer data, gpointer user_data)
398 char *mime = (char *)data;
399 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
400 appcontrol_x *appcontrol;
402 snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
404 appcontrol = calloc(1, sizeof(appcontrol_x));
405 if (strlen(ad->operation))
406 appcontrol->operation = strdup(ad->operation);
408 appcontrol->uri = strdup(ad->uri);
409 appcontrol->mime = strdup(ad->mime);
410 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
413 static void __ps_process_uri(gpointer data, gpointer user_data)
415 char *uri = (char *)data;
416 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
417 appcontrol_x *appcontrol;
419 snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
421 if (ad->mimes != NULL) {
422 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
424 appcontrol = calloc(1, sizeof(appcontrol_x));
425 if (strlen(ad->operation))
426 appcontrol->operation = strdup(ad->operation);
427 appcontrol->uri = strdup(ad->uri);
428 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
432 static void __ps_process_operation(gpointer data, gpointer user_data)
434 char *operation = (char *)data;
435 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
436 appcontrol_x *appcontrol;
438 snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
440 if (ad->uris != NULL) {
441 g_list_foreach(ad->uris, __ps_process_uri, user_data);
442 } else if (ad->mimes != NULL) {
443 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
445 appcontrol = calloc(1, sizeof(appcontrol_x));
446 appcontrol->operation = strdup(ad->operation);
447 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
451 static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
453 struct appcontrol_data ad = {0, };
455 ad.operations = operations;
459 if (ad.operations == NULL)
462 g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
464 return ad.appcontrols;
467 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
473 GList *operations = NULL;
478 depth = xmlTextReaderDepth(reader);
479 while ((ret = __next_child_element(reader, depth)) > 0) {
480 node = xmlTextReaderConstName(reader);
482 _LOGD("xmlTextReaderConstName value is NULL\n");
483 g_list_free_full(operations, free);
484 g_list_free_full(uris, free);
485 g_list_free_full(mimes, free);
490 if (!strcmp(ASCII(node), "operation")) {
491 __save_xml_attribute(reader, "name", &val, NULL);
493 operations = g_list_append(operations, (gpointer)val);
494 _LOGD("operation processing\n");
495 } else if (!strcmp(ASCII(node), "uri")) {
496 __save_xml_attribute(reader, "name", &val, NULL);
498 uris = g_list_append(uris, (gpointer)val);
499 _LOGD("uri processing\n");
500 } else if (!strcmp(ASCII(node), "mime")) {
501 __save_xml_attribute(reader, "name", &val, NULL);
503 mimes = g_list_append(mimes, (gpointer)val);
504 _LOGD("mime processing\n");
505 } else if (!strcmp(ASCII(node), "subapp")) {
513 _LOGD("Processing appcontrol failed\n");
514 g_list_free_full(operations, free);
515 g_list_free_full(uris, free);
516 g_list_free_full(mimes, free);
520 result = __make_appcontrol_list(operations, uris, mimes);
522 *appcontrol = g_list_concat(*appcontrol, result);
526 g_list_free_full(operations, free);
527 g_list_free_full(uris, free);
528 g_list_free_full(mimes, free);
533 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed)
535 __save_xml_value(reader, allowed);
539 static int __ps_process_request(xmlTextReaderPtr reader, char **request)
541 __save_xml_value(reader, request);
545 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
552 __save_xml_attribute(reader, "path", &define->path, NULL);
554 depth = xmlTextReaderDepth(reader);
555 while ((ret = __next_child_element(reader, depth))) {
556 node = xmlTextReaderConstName(reader);
558 _LOGD("xmlTextReaderConstName value is NULL\n");
562 if (!strcmp(ASCII(node), "allowed")) {
564 ret = __ps_process_allowed(reader, &val);
566 define->allowed = g_list_append(define->allowed, (gpointer)val);
567 } else if (!strcmp(ASCII(node), "request")) {
569 ret = __ps_process_request(reader, &val);
571 define->request = g_list_append(define->request, (gpointer)val);
576 _LOGD("Processing define failed\n");
583 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
589 depth = xmlTextReaderDepth(reader);
590 while ((ret = __next_child_element(reader, depth))) {
591 node = xmlTextReaderConstName(reader);
593 _LOGD("xmlTextReaderConstName value is NULL\n");
597 if (!strcmp(ASCII(node), "define")) {
598 define_x *define = calloc(1, sizeof(define_x));
599 if (define == NULL) {
600 _LOGD("Malloc Failed\n");
603 datashare->define = g_list_append(datashare->define, define);
604 ret = __ps_process_define(reader, define);
605 } else if (!strcmp(ASCII(node), "request")) {
607 ret = __ps_process_request(reader, &val);
609 datashare->request = g_list_append(datashare->request, (gpointer)val);
613 _LOGD("Processing data-share failed\n");
620 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition)
622 __save_xml_attribute(reader, "name", condition, NULL);
626 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
633 depth = xmlTextReaderDepth(reader);
634 while ((ret = __next_child_element(reader, depth))) {
635 node = xmlTextReaderConstName(reader);
637 _LOGD("xmlTextReaderConstName value is NULL\n");
641 if (strcmp(ASCII(node), "condition") == 0) {
643 ret = __ps_process_condition(reader, &val);
645 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
649 _LOGD("Processing launchconditions failed\n");
657 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
659 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
660 __save_xml_value(reader, ¬ification->text);
664 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
666 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
667 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
668 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
672 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
674 __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
675 __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
676 __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
677 __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
678 __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
679 __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
680 __save_xml_attribute(reader, "color-depth", &splashscreen->color_depth, NULL);
684 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
689 splashscreen_x *splashscreen;
691 depth = xmlTextReaderDepth(reader);
692 while ((ret = __next_child_element(reader, depth))) {
693 node = xmlTextReaderConstName(reader);
695 _LOGD("xmlTextReaderConstName value is NULL\n");
699 if (strcmp(ASCII(node), "splash-screen") == 0) {
700 splashscreen = calloc(1, sizeof(splashscreen_x));
701 if (splashscreen == NULL) {
702 _LOGD("Malloc Failed\n");
705 *splashscreens = g_list_append(*splashscreens, splashscreen);
706 ret = __ps_process_splashscreen(reader, splashscreen);
712 _LOGD("Processing splash-screen failed\n");
719 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
726 __save_xml_attribute(reader, "appid", &application->appid, NULL);
727 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
728 __save_xml_attribute(reader, "exec", &application->exec, NULL);
729 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
730 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
731 __save_xml_attribute(reader, "type", &application->type, NULL);
732 __save_xml_attribute(reader, "categories", &application->categories, NULL);
733 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
734 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
735 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
736 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
737 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
738 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
739 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
740 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
741 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
742 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
743 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
744 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
745 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
746 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
747 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);
748 __save_xml_attribute(reader, "submode", &application->submode, "false");
749 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
750 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
751 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
752 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
753 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
754 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
755 __save_xml_attribute(reader, "splash-screen-display", &application->splash_screen_display, "true");
757 application->package = strdup(package);
758 /* overwrite some attributes if the app is widgetapp */
759 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
760 free((void *)application->nodisplay);
761 application->nodisplay = strdup("true");
762 free((void *)application->multiple);
763 application->multiple = strdup("true");
764 free((void *)application->type);
765 application->type = strdup("capp");
766 free((void *)application->taskmanage);
767 application->taskmanage = strdup("false");
768 free((void *)application->indicatordisplay);
769 application->indicatordisplay = strdup("false");
772 /* hw-acceleration values are changed from use-GL/not-use-GL/use-system-setting to on/off/default */
773 if (strcmp(application->hwacceleration, "use-GL") == 0) {
774 free((void *)application->hwacceleration);
775 application->hwacceleration = strdup("on");
776 } else if (strcmp(application->hwacceleration, "not-use-GL") == 0) {
777 free((void *)application->hwacceleration);
778 application->hwacceleration = strdup("off");
779 } else if (strcmp(application->hwacceleration, "use-system-setting") == 0) {
780 free((void *)application->hwacceleration);
781 application->hwacceleration = strdup("default");
784 depth = xmlTextReaderDepth(reader);
785 while ((ret = __next_child_element(reader, depth))) {
786 node = xmlTextReaderConstName(reader);
788 _LOGD("xmlTextReaderConstName value is NULL\n");
791 if (!strcmp(ASCII(node), "label")) {
792 label_x *label = calloc(1, sizeof(label_x));
794 _LOGD("Malloc Failed\n");
797 application->label = g_list_append(application->label, label);
798 ret = __ps_process_label(reader, label);
799 } else if (!strcmp(ASCII(node), "icon")) {
800 icon_x *icon = calloc(1, sizeof(icon_x));
802 _LOGD("Malloc Failed\n");
805 application->icon = g_list_append(application->icon, icon);
806 ret = __ps_process_icon(reader, icon, uid);
807 } else if (!strcmp(ASCII(node), "image")) {
808 image_x *image = calloc(1, sizeof(image_x));
810 _LOGD("Malloc Failed\n");
813 application->image = g_list_append(application->image, image);
814 ret = __ps_process_image(reader, image);
815 } else if (!strcmp(ASCII(node), "category")) {
817 ret = __ps_process_category(reader, &val);
819 application->category = g_list_append(application->category, (gpointer)val);
820 } else if (!strcmp(ASCII(node), "metadata")) {
821 metadata_x *metadata = calloc(1, sizeof(metadata_x));
822 if (metadata == NULL) {
823 _LOGD("Malloc Failed\n");
826 application->metadata = g_list_append(application->metadata, metadata);
827 ret = __ps_process_metadata(reader, metadata);
828 } else if (!strcmp(ASCII(node), "permission")) {
829 permission_x *permission = calloc(1, sizeof(permission_x));
830 if (permission == NULL) {
831 _LOGD("Malloc Failed\n");
834 application->permission = g_list_append(application->permission, permission);
835 ret = __ps_process_permission(reader, permission);
836 } else if (!strcmp(ASCII(node), "app-control")) {
837 ret = __ps_process_appcontrol(reader, &application->appcontrol);
838 } else if (!strcmp(ASCII(node), "application-service")) {
839 ret = __ps_process_appcontrol(reader, &application->appcontrol);
840 } else if (!strcmp(ASCII(node), "data-share")) {
841 datashare_x *datashare = calloc(1, sizeof(datashare_x));
842 if (datashare == NULL) {
843 _LOGD("Malloc Failed\n");
846 application->datashare = g_list_append(application->datashare, datashare);
847 ret = __ps_process_datashare(reader, datashare);
848 } else if (!strcmp(ASCII(node), "launch-conditions")) {
849 ret = __ps_process_launchconditions(reader, &application->launchconditions);
850 } else if (!strcmp(ASCII(node), "notification")) {
851 notification_x *notification = calloc(1, sizeof(notification_x));
852 if (notification == NULL) {
853 _LOGD("Malloc Failed\n");
856 application->notification = g_list_append(application->notification, notification);
857 ret = __ps_process_notification(reader, notification);
858 } else if (!strcmp(ASCII(node), "datacontrol")) {
859 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
860 if (datacontrol == NULL) {
861 _LOGD("Malloc Failed\n");
864 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
865 ret = __ps_process_datacontrol(reader, datacontrol);
866 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
867 ret = __ps_process_splashscreens(reader, &application->splashscreens);
871 _LOGD("Processing application failed\n");
879 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
881 _LOGD("__start_process\n");
886 depth = xmlTextReaderDepth(reader);
887 while ((ret = __next_child_element(reader, depth))) {
888 node = xmlTextReaderConstName(reader);
890 _LOGD("xmlTextReaderConstName value is NULL\n");
894 if (!strcmp(ASCII(node), "label")) {
895 label_x *label = calloc(1, sizeof(label_x));
897 _LOGD("Malloc Failed\n");
900 mfx->label = g_list_append(mfx->label, label);
901 ret = __ps_process_label(reader, label);
902 } else if (!strcmp(ASCII(node), "author")) {
903 author_x *author = calloc(1, sizeof(author_x));
904 if (author == NULL) {
905 _LOGD("Malloc Failed\n");
908 mfx->author = g_list_append(mfx->author, author);
909 ret = __ps_process_author(reader, author);
910 } else if (!strcmp(ASCII(node), "description")) {
911 description_x *description = calloc(1, sizeof(description_x));
912 if (description == NULL) {
913 _LOGD("Malloc Failed\n");
916 mfx->description = g_list_append(mfx->description, description);
917 ret = __ps_process_description(reader, description);
918 } else if (!strcmp(ASCII(node), "license")) {
919 license_x *license = calloc(1, sizeof(license_x));
920 if (license == NULL) {
921 _LOGD("Malloc Failed\n");
924 mfx->license = g_list_append(mfx->license, license);
925 ret = __ps_process_license(reader, license);
926 } else if (!strcmp(ASCII(node), "privileges")) {
927 ret = __ps_process_privileges(reader, &mfx->privileges);
928 } else if (!strcmp(ASCII(node), "ui-application")) {
929 application_x *application = calloc(1, sizeof(application_x));
930 if (application == NULL) {
931 _LOGD("Malloc Failed\n");
934 mfx->application = g_list_append(mfx->application, application);
935 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
936 } else if (!strcmp(ASCII(node), "service-application")) {
937 application_x *application = calloc(1, sizeof(application_x));
938 if (application == NULL) {
939 _LOGD("Malloc Failed\n");
942 mfx->application = g_list_append(mfx->application, application);
943 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
944 } else if (!strcmp(ASCII(node), "widget-application")) {
945 application_x *application = calloc(1, sizeof(application_x));
946 if (application == NULL) {
947 _LOGD("Malloc Failed\n");
950 mfx->application = g_list_append(mfx->application, application);
951 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
952 } else if (!strcmp(ASCII(node), "watch-application")) {
953 application_x *application = calloc(1, sizeof(application_x));
954 if (application == NULL) {
955 _LOGD("Malloc Failed\n");
958 mfx->application = g_list_append(mfx->application, application);
959 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
960 } else if (!strcmp(ASCII(node), "icon")) {
961 icon_x *icon = calloc(1, sizeof(icon_x));
963 _LOGD("Malloc Failed\n");
966 mfx->icon = g_list_append(mfx->icon, icon);
967 ret = __ps_process_icon(reader, icon, uid);
968 } else if (!strcmp(ASCII(node), "compatibility")) {
969 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
970 if (compatibility == NULL) {
971 _LOGD("Malloc Failed\n");
974 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
975 ret = __ps_process_compatibility(reader, compatibility);
976 } else if (!strcmp(ASCII(node), "shortcut-list")) {
978 } else if (!strcmp(ASCII(node), "livebox")) {
980 } else if (!strcmp(ASCII(node), "account")) {
982 } else if (!strcmp(ASCII(node), "notifications")) {
984 } else if (!strcmp(ASCII(node), "ime")) {
986 } else if (!strcmp(ASCII(node), "feature")) {
989 _LOGI("Unknown element: %s", ASCII(node));
994 _LOGD("Processing manifest failed\n");
1001 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1003 const xmlChar *node;
1006 if ((ret = __next_child_element(reader, -1))) {
1007 node = xmlTextReaderConstName(reader);
1009 _LOGD("xmlTextReaderConstName value is NULL\n");
1013 if (!strcmp(ASCII(node), "manifest")) {
1014 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1015 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1016 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1017 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1018 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1019 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1020 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1021 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1022 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1023 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1024 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1025 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1026 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1027 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1028 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1030 __save_xml_installed_time(mfx);
1031 __save_xml_root_path(mfx, uid);
1032 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1033 __save_xml_default_value(mfx);
1035 ret = __start_process(reader, mfx, uid);
1037 _LOGD("No Manifest element found\n");
1044 DEPRECATED API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
1046 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
1047 xmlTextReaderPtr reader;
1048 manifest_x *mfx = NULL;
1050 reader = xmlReaderForFile(manifest, NULL, 0);
1052 mfx = malloc(sizeof(manifest_x));
1054 memset(mfx, '\0', sizeof(manifest_x));
1055 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
1056 _LOGD("Parsing Failed\n");
1057 pkgmgr_parser_free_manifest_xml(mfx);
1060 _LOGD("Parsing Success\n");
1062 _LOGD("Memory allocation error\n");
1064 xmlFreeTextReader(reader);
1066 _LOGD("Unable to create xml reader\n");
1071 DEPRECATED API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
1073 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
1074 xmlTextReaderPtr reader;
1075 manifest_x *mfx = NULL;
1077 reader = xmlReaderForFile(manifest, NULL, 0);
1079 mfx = malloc(sizeof(manifest_x));
1081 memset(mfx, '\0', sizeof(manifest_x));
1082 if (__process_manifest(reader, mfx, uid) < 0) {
1083 _LOGD("Parsing Failed\n");
1084 pkgmgr_parser_free_manifest_xml(mfx);
1087 _LOGD("Parsing Success\n");
1089 _LOGD("Memory allocation error\n");
1091 xmlFreeTextReader(reader);
1093 _LOGD("Unable to create xml reader\n");
1098 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1101 char delims[] = "=";
1102 char *ret_result = NULL;
1109 for (tag = strdup(tagv[0]); tag != NULL; ) {
1110 ret_result = strtok_r(tag, delims, &ptr);
1111 if (ret_result != NULL) {
1112 /*check tag : preload */
1113 if (strcmp(ret_result, "preload") == 0) {
1114 ret_result = strtok_r(NULL, delims, &ptr);
1115 if (ret_result && strcmp(ret_result, "true") == 0) {
1116 free((void *)mfx->preload);
1117 mfx->preload = strdup("true");
1118 } else if (ret_result && strcmp(ret_result, "false") == 0) {
1119 free((void *)mfx->preload);
1120 mfx->preload = strdup("false");
1122 /*check tag : removable*/
1123 } else if (strcmp(ret_result, "removable") == 0) {
1124 ret_result = strtok_r(NULL, delims, &ptr);
1125 if (ret_result && strcmp(ret_result, "true") == 0) {
1126 free((void *)mfx->removable);
1127 mfx->removable = strdup("true");
1128 } else if (ret_result && strcmp(ret_result, "false") == 0) {
1129 free((void *)mfx->removable);
1130 mfx->removable = strdup("false");
1132 /*check tag : not matched*/
1134 _LOGD("tag process [%s]is not defined\n", ret_result);
1138 /*check next value*/
1139 if (tagv[++i] != NULL)
1140 tag = strdup(tagv[i]);
1142 _LOGD("tag process success...\n");
1148 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
1149 ACTION_TYPE action, const char *pkgid)
1151 int (*plugin_install) (xmlDocPtr, const char *);
1156 case ACTION_INSTALL:
1157 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
1159 case ACTION_UPGRADE:
1160 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
1162 case ACTION_UNINSTALL:
1163 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
1169 if ((plugin_install =
1170 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1171 _LOGE("can not find symbol[%s] \n", ac);
1175 ret = plugin_install(docPtr, pkgid);
1176 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
1182 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
1185 const xmlChar *name;
1187 if (xmlTextReaderDepth(reader) != 1) {
1188 _LOGE("Node depth is not 1");
1192 if (xmlTextReaderNodeType(reader) != 1) {
1193 _LOGE("Node type is not 1");
1197 const xmlChar *value;
1198 name = xmlTextReaderConstName(reader);
1200 _LOGE("TEST TEST TES\n");
1201 name = BAD_CAST "--";
1204 value = xmlTextReaderConstValue(reader);
1205 if (value != NULL) {
1206 if (xmlStrlen(value) > 40)
1207 _LOGD(" %.40s...", value);
1209 _LOGD(" %s", value);
1212 name = xmlTextReaderConstName(reader);
1214 _LOGE("TEST TEST TES\n");
1215 name = BAD_CAST "--";
1218 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
1219 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
1220 if (copyDocPtr == NULL)
1222 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
1223 if (rootElement == NULL)
1225 xmlNode *cur_node = xmlFirstElementChild(rootElement);
1226 if (cur_node == NULL)
1228 xmlNode *temp = xmlTextReaderExpand(reader);
1231 xmlNode *next_node = NULL;
1232 while (cur_node != NULL) {
1233 if ((strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
1234 (temp->line == cur_node->line)) {
1237 next_node = xmlNextElementSibling(cur_node);
1238 xmlUnlinkNode(cur_node);
1239 xmlFreeNode(cur_node);
1240 cur_node = next_node;
1243 if (cur_node == NULL)
1245 next_node = xmlNextElementSibling(cur_node);
1247 cur_node->next = NULL;
1248 next_node->prev = NULL;
1249 xmlFreeNodeList(next_node);
1250 xmlSetTreeDoc(cur_node, copyDocPtr);
1252 xmlSetTreeDoc(cur_node, copyDocPtr);
1255 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
1261 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
1263 switch (xmlTextReaderNodeType(reader)) {
1264 case XML_READER_TYPE_END_ELEMENT:
1268 case XML_READER_TYPE_ELEMENT:
1270 /* Elements without closing tag don't receive */
1271 const xmlChar *elementName =
1272 xmlTextReaderLocalName(reader);
1273 if (elementName == NULL)
1276 if (strcmp(tag, ASCII(elementName)) == 0) {
1277 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
1278 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
1289 static void __str_trim(char *input)
1291 char *trim_str = input;
1296 while (*input != 0) {
1297 if (!isspace(*input)) {
1308 static char *__get_parser_plugin(const char *type)
1311 char buffer[1024] = { 0 };
1312 char temp_path[1024] = { 0 };
1316 _LOGE("invalid argument\n");
1320 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1322 _LOGE("no matching backendlib\n");
1326 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1327 if (buffer[0] == '#')
1332 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
1333 path = path + strlen(PKG_PARSERLIB);
1337 memset(buffer, 0x00, 1024);
1344 _LOGE("no matching backendlib\n");
1348 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1350 return strdup(temp_path);
1353 static void *__open_lib_handle(char *tag)
1355 char *lib_path = NULL;
1356 void *lib_handle = NULL;
1358 lib_path = __get_parser_plugin(tag);
1359 retvm_if(!lib_path, NULL, "lib_path get fail");
1361 lib_handle = dlopen(lib_path, RTLD_LAZY);
1362 if (lib_handle == NULL)
1363 _LOGE("dlopen is failed lib_path[%s]", lib_path);
1370 static void __close_lib_handle(void *lib_handle)
1372 dlclose(lib_handle);
1375 static char * __get_tag_by_key(char *md_key)
1377 char *md_tag = NULL;
1379 if (md_key == NULL) {
1380 _LOGD("md_key is NULL\n");
1384 md_tag = strrchr(md_key, 47) + 1;
1387 return strdup(md_tag);
1390 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1392 int (*plugin_install) (const char *);
1396 if (process == PLUGIN_PRE_PROCESS) {
1398 case ACTION_INSTALL:
1399 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
1401 case ACTION_UPGRADE:
1402 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
1404 case ACTION_UNINSTALL:
1405 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
1410 } else if (process == PLUGIN_POST_PROCESS) {
1412 case ACTION_INSTALL:
1413 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
1415 case ACTION_UPGRADE:
1416 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
1418 case ACTION_UNINSTALL:
1419 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
1427 if ((plugin_install =
1428 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1432 ret = plugin_install(pkgid);
1436 static int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1438 xmlTextReaderPtr reader;
1442 void *lib_handle = NULL;
1443 char tag[PKG_STRING_LEN_MAX] = { 0 };
1445 fp = fopen(TAG_PARSER_LIST, "r");
1446 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1448 while (fgets(tag, sizeof(tag), fp) != NULL) {
1451 lib_handle = __open_lib_handle(tag);
1452 if (lib_handle == NULL)
1455 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1456 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1458 docPtr = xmlReadFile(filename, NULL, 0);
1459 reader = xmlReaderWalker(docPtr);
1460 if (reader != NULL) {
1461 ret = xmlTextReaderRead(reader);
1463 __process_tag(lib_handle, reader, action, tag, mfx->package);
1464 ret = xmlTextReaderRead(reader);
1466 xmlFreeTextReader(reader);
1469 _LOGD("%s : failed to parse", filename);
1471 _LOGD("Unable to open %s", filename);
1474 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1475 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1477 __close_lib_handle(lib_handle);
1479 memset(tag, 0x00, sizeof(tag));
1488 static void __metadata_parser_clear_dir_list(GList* dir_list)
1491 __metadata_t* detail = NULL;
1494 list = g_list_first(dir_list);
1496 detail = (__metadata_t *)list->data;
1499 free((void *)detail->key);
1501 free((void *)detail->value);
1504 list = g_list_next(list);
1506 g_list_free(dir_list);
1510 static char *__get_metadata_parser_plugin(const char *type)
1513 char buffer[1024] = { 0 };
1514 char temp_path[1024] = { 0 };
1518 _LOGE("invalid argument\n");
1522 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1524 _LOGE("no matching metadata parser\n");
1528 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1529 if (buffer[0] == '#')
1534 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
1535 path = path + strlen(METADATA_PARSER_NAME);
1540 memset(buffer, 0x00, 1024);
1547 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME, type);
1551 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1553 return strdup(temp_path);
1556 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
1557 ACTION_TYPE action, const char *pkgid, const char *appid)
1559 char *lib_path = NULL;
1560 void *lib_handle = NULL;
1561 int (*metadata_parser_plugin) (const char *, const char *, GList *);
1566 case ACTION_INSTALL:
1567 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
1569 case ACTION_UPGRADE:
1570 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
1572 case ACTION_UNINSTALL:
1573 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
1579 lib_path = __get_metadata_parser_plugin(tag);
1581 _LOGE("get %s parser fail\n", tag);
1585 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1586 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1590 if ((metadata_parser_plugin =
1591 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1592 _LOGE("can not find symbol[%s] \n", ac);
1596 ret = metadata_parser_plugin(pkgid, appid, md_list);
1598 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1600 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1606 dlclose(lib_handle);
1610 static int __run_metadata_parser_prestep(manifest_x *mfx, char *md_key, ACTION_TYPE action)
1614 char buffer[1024] = { 0, };
1617 GList *md_tmp = NULL;
1619 char *md_tag = NULL;
1621 GList *md_list = NULL;
1622 __metadata_t *md_detail = NULL;
1624 md_tag = __get_tag_by_key(md_key);
1625 if (md_tag == NULL) {
1626 _LOGD("md_tag is NULL\n");
1630 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1631 app = (application_x *)app_tmp->data;
1634 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1635 md = (metadata_x *)md_tmp->data;
1638 /* get glist of metadata key and value combination */
1639 memset(buffer, 0x00, 1024);
1640 snprintf(buffer, 1024, "%s/", md_key);
1641 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
1642 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
1643 if (md_detail == NULL) {
1644 _LOGD("Memory allocation failed\n");
1648 md_detail->key = strdup(md->key);
1649 if (md_detail->key == NULL) {
1650 _LOGD("Memory allocation failed\n");
1655 md_detail->value = strdup(md->value);
1656 if (md_detail->value == NULL) {
1657 _LOGD("Memory allocation failed\n");
1658 free((void *)md_detail->key);
1663 md_list = g_list_append(md_list, (gpointer)md_detail);
1668 /* send glist to parser when tags for metadata plugin parser exist. */
1670 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
1672 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
1674 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
1676 __metadata_parser_clear_dir_list(md_list);
1685 __metadata_parser_clear_dir_list(md_list);
1692 static int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1694 fprintf(stdout, "__ps_process_metadata_parser\n");
1697 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1699 fp = fopen(METADATA_PARSER_LIST, "r");
1701 _LOGD("no preload list\n");
1705 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1707 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1718 static void __category_parser_clear_dir_list(GList* dir_list)
1721 __category_t* detail = NULL;
1724 list = g_list_first(dir_list);
1726 detail = (__category_t *)list->data;
1729 free((void *)detail->name);
1733 list = g_list_next(list);
1735 g_list_free(dir_list);
1739 static char *__get_category_parser_plugin(const char *type)
1742 char buffer[1024] = { 0 };
1743 char temp_path[1024] = { 0 };
1747 _LOGE("invalid argument\n");
1751 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1753 _LOGE("no matching metadata parser\n");
1757 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1758 if (buffer[0] == '#')
1763 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
1764 path = path + strlen(CATEGORY_PARSER_NAME);
1769 memset(buffer, 0x00, 1024);
1776 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME, type);
1780 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1782 return strdup(temp_path);
1785 static int __ps_run_category_parser(GList *category_list, const char *tag,
1786 ACTION_TYPE action, const char *pkgid, const char *appid)
1788 char *lib_path = NULL;
1789 void *lib_handle = NULL;
1790 int (*category_parser_plugin) (const char *, const char *, GList *);
1795 case ACTION_INSTALL:
1796 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
1798 case ACTION_UPGRADE:
1799 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
1801 case ACTION_UNINSTALL:
1802 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
1808 lib_path = __get_category_parser_plugin(tag);
1810 _LOGE("get %s parser fail\n", tag);
1814 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1815 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1819 if ((category_parser_plugin =
1820 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1821 _LOGE("can not find symbol[%s] \n", ac);
1825 ret = category_parser_plugin(pkgid, appid, category_list);
1827 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1829 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1835 dlclose(lib_handle);
1839 static int __run_category_parser_prestep(manifest_x *mfx, char *category_key, ACTION_TYPE action)
1843 char buffer[1024] = { 0, };
1846 GList *category_tmp;
1847 const char *category;
1848 char *category_tag = NULL;
1850 GList *category_list = NULL;
1851 __category_t *category_detail = NULL;
1853 category_tag = __get_tag_by_key(category_key);
1854 if (category_tag == NULL) {
1855 _LOGD("md_tag is NULL\n");
1859 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1860 app = (application_x *)app_tmp->data;
1863 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
1864 category = (const char *)category_tmp->data;
1865 /* get glist of category key and value combination */
1866 memset(buffer, 0x00, 1024);
1867 snprintf(buffer, 1024, "%s/", category_key);
1868 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
1869 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
1870 if (category_detail == NULL) {
1871 _LOGD("Memory allocation failed\n");
1875 category_detail->name = strdup(category);
1876 if (category_detail->name == NULL) {
1877 _LOGD("Memory allocation failed\n");
1878 free(category_detail);
1882 category_list = g_list_append(category_list, (gpointer)category_detail);
1887 /* send glist to parser when tags for metadata plugin parser exist. */
1889 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
1891 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
1893 _LOGD("category_parser success for tag[%s]\n", category_tag);
1895 __category_parser_clear_dir_list(category_list);
1896 category_list = NULL;
1904 __category_parser_clear_dir_list(category_list);
1911 static int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1915 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1917 fp = fopen(CATEGORY_PARSER_LIST, "r");
1919 _LOGD("no category parser list\n");
1923 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1924 __str_trim(category_key);
1925 ret = __run_category_parser_prestep(mfx, category_key, action);
1936 DEPRECATED API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
1938 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1939 _LOGD("parsing manifest for installation: %s\n", manifest);
1941 manifest_x *mfx = NULL;
1945 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1946 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1948 _LOGD("Parsing Finished\n");
1950 __ps_process_tag(mfx, tagv);
1952 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
1953 if (ret == PMINFO_R_ERROR) {
1954 _LOGE("DB Insert failed");
1955 pkgmgr_parser_free_manifest_xml(mfx);
1956 return PMINFO_R_ERROR;
1959 _LOGD("DB Insert Success\n");
1961 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1962 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1964 _LOGD("Creating metadata parser failed\n");
1966 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1968 _LOGD("Creating category parser failed\n");
1970 pkgmgr_parser_free_manifest_xml(mfx);
1971 _LOGD("Free Done\n");
1977 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
1979 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1980 _LOGD("parsing manifest for installation: %s\n", manifest);
1981 manifest_x *mfx = NULL;
1985 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
1986 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1988 _LOGD("Parsing Finished\n");
1990 __ps_process_tag(mfx, tagv);
1992 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
1993 if (ret == PMINFO_R_ERROR) {
1994 _LOGE("DB Insert failed");
1995 pkgmgr_parser_free_manifest_xml(mfx);
1996 return PMINFO_R_ERROR;
1999 _LOGD("DB Insert Success\n");
2001 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2002 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2004 _LOGD("Creating metadata parser failed\n");
2005 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2007 _LOGD("Creating category parser failed\n");
2009 pkgmgr_parser_free_manifest_xml(mfx);
2010 _LOGD("Free Done\n");
2016 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
2018 if (!strstr(manifest, getUserManifestPath(uid,
2019 strcmp(mfx->preload, "true") == 0))) {
2020 /* if downloaded app is updated, then update tag set true*/
2022 free((void *)mfx->update);
2023 mfx->update = strdup("true");
2029 DEPRECATED API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2031 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2032 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2033 manifest_x *mfx = NULL;
2035 bool preload = false;
2036 bool system = false;
2037 char *csc_path = NULL;
2038 pkgmgrinfo_pkginfo_h handle = NULL;
2041 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2042 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2044 _LOGD("Parsing Finished\n");
2045 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2047 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2048 if (ret != PMINFO_R_OK)
2049 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2050 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2051 if (ret != PMINFO_R_OK)
2052 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2055 free((void *)mfx->preload);
2056 mfx->preload = strdup("true");
2059 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2060 if (ret != PMINFO_R_OK)
2061 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2063 free((void *)mfx->system);
2064 mfx->system = strdup("true");
2067 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2068 if (ret != PMINFO_R_OK)
2069 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2071 if (csc_path != NULL) {
2073 free((void *)mfx->csc_path);
2074 mfx->csc_path = strdup(csc_path);
2077 /*Delete from cert table*/
2078 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2079 if (ret != PMINFO_R_OK) {
2080 _LOGD("Cert Info DB Delete Failed\n");
2081 pkgmgr_parser_free_manifest_xml(mfx);
2082 return PMINFO_R_ERROR;
2085 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2086 if (ret != PMINFO_R_OK) {
2087 _LOGD("DB Insert failed\n");
2088 pkgmgr_parser_free_manifest_xml(mfx);
2089 return PMINFO_R_ERROR;
2092 _LOGD("DB Update Success\n");
2094 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2095 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2097 _LOGD("Upgrade metadata parser failed\n");
2098 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2100 _LOGD("Creating category parser failed\n");
2101 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2102 pkgmgr_parser_free_manifest_xml(mfx);
2103 _LOGD("Free Done\n");
2109 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2111 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2112 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2113 manifest_x *mfx = NULL;
2115 bool preload = false;
2116 bool system = false;
2117 char *csc_path = NULL;
2118 pkgmgrinfo_pkginfo_h handle = NULL;
2121 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2122 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2124 _LOGD("Parsing Finished\n");
2125 __check_preload_updated(mfx, manifest, uid);
2127 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2128 if (ret != PMINFO_R_OK)
2129 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2130 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2131 if (ret != PMINFO_R_OK)
2132 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2135 free((void *)mfx->preload);
2136 mfx->preload = strdup("true");
2139 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2140 if (ret != PMINFO_R_OK)
2141 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2144 free((void *)mfx->system);
2145 mfx->system = strdup("true");
2148 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2149 if (ret != PMINFO_R_OK)
2150 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2151 if (csc_path != NULL) {
2153 free((void *)mfx->csc_path);
2154 mfx->csc_path = strdup(csc_path);
2157 /*Delete from cert table*/
2158 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2159 if (ret != PMINFO_R_OK) {
2160 _LOGD("Cert Info DB Delete Failed\n");
2161 pkgmgr_parser_free_manifest_xml(mfx);
2162 return PMINFO_R_ERROR;
2165 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2166 if (ret != PMINFO_R_OK) {
2167 _LOGD("DB Insert failed\n");
2168 pkgmgr_parser_free_manifest_xml(mfx);
2169 return PMINFO_R_ERROR;
2172 _LOGD("DB Update Success\n");
2174 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2175 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2177 _LOGD("Upgrade metadata parser failed\n");
2178 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2180 _LOGD("Creating category parser failed\n");
2181 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2182 pkgmgr_parser_free_manifest_xml(mfx);
2183 _LOGD("Free Done\n");
2189 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2191 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2192 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2194 manifest_x *mfx = NULL;
2197 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2198 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2200 _LOGD("Parsing Finished\n");
2202 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2204 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2206 _LOGD("Removing metadata parser failed\n");
2208 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2210 _LOGD("Creating category parser failed\n");
2212 /*Delete from cert table*/
2213 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2215 _LOGD("Cert Info DB Delete Failed\n");
2216 pkgmgr_parser_free_manifest_xml(mfx);
2220 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2222 _LOGD("DB Delete failed\n");
2224 _LOGD("DB Delete Success\n");
2226 pkgmgr_parser_free_manifest_xml(mfx);
2227 _LOGD("Free Done\n");
2233 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
2235 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
2237 void *lib_handle = NULL;
2238 int (*appsvc_operation) (const char *, uid_t);
2241 application_x *application;
2243 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
2244 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
2248 if ((appsvc_operation =
2249 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
2250 _LOGE("can not find symbol \n");
2254 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2255 application = (application_x *)tmp->data;
2256 if (application == NULL)
2258 ret = appsvc_operation(application->appid, uid);
2260 _LOGE("can not operation symbol \n");
2265 dlclose(lib_handle);
2270 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2272 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2273 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2275 manifest_x *mfx = NULL;
2278 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2279 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2281 _LOGD("Parsing Finished\n");
2283 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2285 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2287 _LOGD("Removing metadata parser failed\n");
2289 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2291 _LOGD("Creating category parser failed\n");
2293 /*Delete from cert table*/
2294 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2296 _LOGD("Cert Info DB Delete Failed\n");
2297 pkgmgr_parser_free_manifest_xml(mfx);
2301 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2303 _LOGD("DB Delete failed\n");
2305 _LOGD("DB Delete Success\n");
2307 ret = __ps_remove_appsvc_db(mfx, uid);
2309 _LOGD("Removing appsvc_db failed\n");
2311 _LOGD("Removing appsvc_db Success\n");
2313 pkgmgr_parser_free_manifest_xml(mfx);
2314 _LOGD("Free Done\n");