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");
473 g_list_free_full(operations, free);
474 g_list_free_full(uris, free);
475 g_list_free_full(mimes, free);
480 if (!strcmp(ASCII(node), "operation")) {
481 __save_xml_attribute(reader, "name", &val, NULL);
483 operations = g_list_append(operations, (gpointer)val);
484 _LOGD("operation processing\n");
485 } else if (!strcmp(ASCII(node), "uri")) {
486 __save_xml_attribute(reader, "name", &val, NULL);
488 uris = g_list_append(uris, (gpointer)val);
489 _LOGD("uri processing\n");
490 } else if (!strcmp(ASCII(node), "mime")) {
491 __save_xml_attribute(reader, "name", &val, NULL);
493 mimes = g_list_append(mimes, (gpointer)val);
494 _LOGD("mime processing\n");
495 } else if (!strcmp(ASCII(node), "subapp")) {
503 _LOGD("Processing appcontrol failed\n");
504 g_list_free_full(operations, free);
505 g_list_free_full(uris, free);
506 g_list_free_full(mimes, free);
510 result = __make_appcontrol_list(operations, uris, mimes);
512 *appcontrol = g_list_concat(*appcontrol, result);
516 g_list_free_full(operations, free);
517 g_list_free_full(uris, free);
518 g_list_free_full(mimes, free);
523 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed)
525 __save_xml_value(reader, allowed);
529 static int __ps_process_request(xmlTextReaderPtr reader, char **request)
531 __save_xml_value(reader, request);
535 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
542 __save_xml_attribute(reader, "path", &define->path, NULL);
544 depth = xmlTextReaderDepth(reader);
545 while ((ret = __next_child_element(reader, depth))) {
546 node = xmlTextReaderConstName(reader);
548 _LOGD("xmlTextReaderConstName value is NULL\n");
552 if (!strcmp(ASCII(node), "allowed")) {
554 ret = __ps_process_allowed(reader, &val);
556 define->allowed = g_list_append(define->allowed, (gpointer)val);
557 } else if (!strcmp(ASCII(node), "request")) {
559 ret = __ps_process_request(reader, &val);
561 define->request = g_list_append(define->request, (gpointer)val);
566 _LOGD("Processing define failed\n");
573 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
579 depth = xmlTextReaderDepth(reader);
580 while ((ret = __next_child_element(reader, depth))) {
581 node = xmlTextReaderConstName(reader);
583 _LOGD("xmlTextReaderConstName value is NULL\n");
587 if (!strcmp(ASCII(node), "define")) {
588 define_x *define = calloc(1, sizeof(define_x));
589 if (define == NULL) {
590 _LOGD("Malloc Failed\n");
593 datashare->define = g_list_append(datashare->define, define);
594 ret = __ps_process_define(reader, define);
595 } else if (!strcmp(ASCII(node), "request")) {
597 ret = __ps_process_request(reader, &val);
599 datashare->request = g_list_append(datashare->request, (gpointer)val);
603 _LOGD("Processing data-share failed\n");
610 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition)
612 __save_xml_attribute(reader, "name", condition, NULL);
616 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
623 depth = xmlTextReaderDepth(reader);
624 while ((ret = __next_child_element(reader, depth))) {
625 node = xmlTextReaderConstName(reader);
627 _LOGD("xmlTextReaderConstName value is NULL\n");
631 if (strcmp(ASCII(node), "condition") == 0) {
633 ret = __ps_process_condition(reader, &val);
635 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
639 _LOGD("Processing launchconditions failed\n");
647 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
649 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
650 __save_xml_value(reader, ¬ification->text);
654 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
656 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
657 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
658 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
662 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
664 __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
665 __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
666 __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
667 __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
668 __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
669 __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
670 __save_xml_attribute(reader, "color-depth", &splashscreen->color_depth, NULL);
674 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
679 splashscreen_x *splashscreen;
681 depth = xmlTextReaderDepth(reader);
682 while ((ret = __next_child_element(reader, depth))) {
683 node = xmlTextReaderConstName(reader);
685 _LOGD("xmlTextReaderConstName value is NULL\n");
689 if (strcmp(ASCII(node), "splash-screen") == 0) {
690 splashscreen = calloc(1, sizeof(splashscreen_x));
691 if (splashscreen == NULL) {
692 _LOGD("Malloc Failed\n");
695 *splashscreens = g_list_append(*splashscreens, splashscreen);
696 ret = __ps_process_splashscreen(reader, splashscreen);
702 _LOGD("Processing splash-screen failed\n");
709 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
716 __save_xml_attribute(reader, "appid", &application->appid, NULL);
717 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
718 __save_xml_attribute(reader, "exec", &application->exec, NULL);
719 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
720 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
721 __save_xml_attribute(reader, "type", &application->type, NULL);
722 __save_xml_attribute(reader, "categories", &application->categories, NULL);
723 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
724 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
725 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
726 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
727 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
728 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
729 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
730 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
731 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
732 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
733 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
734 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
735 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
736 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
737 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);
738 __save_xml_attribute(reader, "submode", &application->submode, "false");
739 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
740 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
741 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
742 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
743 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
744 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
745 __save_xml_attribute(reader, "splash-screen-display", &application->splash_screen_display, "true");
747 application->package = strdup(package);
748 /* overwrite some attributes if the app is widgetapp */
749 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
750 free((void *)application->nodisplay);
751 application->nodisplay = strdup("true");
752 free((void *)application->multiple);
753 application->multiple = strdup("true");
754 free((void *)application->type);
755 application->type = strdup("capp");
756 free((void *)application->taskmanage);
757 application->taskmanage = strdup("false");
758 free((void *)application->indicatordisplay);
759 application->indicatordisplay = strdup("false");
762 /* hw-acceleration values are changed from use-GL/not-use-GL/use-system-setting to on/off/default */
763 if (strcmp(application->hwacceleration, "use-GL") == 0) {
764 free((void *)application->hwacceleration);
765 application->hwacceleration = strdup("on");
766 } else if (strcmp(application->hwacceleration, "not-use-GL") == 0) {
767 free((void *)application->hwacceleration);
768 application->hwacceleration = strdup("off");
769 } else if (strcmp(application->hwacceleration, "use-system-setting") == 0) {
770 free((void *)application->hwacceleration);
771 application->hwacceleration = strdup("default");
774 depth = xmlTextReaderDepth(reader);
775 while ((ret = __next_child_element(reader, depth))) {
776 node = xmlTextReaderConstName(reader);
778 _LOGD("xmlTextReaderConstName value is NULL\n");
781 if (!strcmp(ASCII(node), "label")) {
782 label_x *label = calloc(1, sizeof(label_x));
784 _LOGD("Malloc Failed\n");
787 application->label = g_list_append(application->label, label);
788 ret = __ps_process_label(reader, label);
789 } else if (!strcmp(ASCII(node), "icon")) {
790 icon_x *icon = calloc(1, sizeof(icon_x));
792 _LOGD("Malloc Failed\n");
795 application->icon = g_list_append(application->icon, icon);
796 ret = __ps_process_icon(reader, icon, uid);
797 } else if (!strcmp(ASCII(node), "image")) {
798 image_x *image = calloc(1, sizeof(image_x));
800 _LOGD("Malloc Failed\n");
803 application->image = g_list_append(application->image, image);
804 ret = __ps_process_image(reader, image);
805 } else if (!strcmp(ASCII(node), "category")) {
807 ret = __ps_process_category(reader, &val);
809 application->category = g_list_append(application->category, (gpointer)val);
810 } else if (!strcmp(ASCII(node), "metadata")) {
811 metadata_x *metadata = calloc(1, sizeof(metadata_x));
812 if (metadata == NULL) {
813 _LOGD("Malloc Failed\n");
816 application->metadata = g_list_append(application->metadata, metadata);
817 ret = __ps_process_metadata(reader, metadata);
818 } else if (!strcmp(ASCII(node), "permission")) {
819 permission_x *permission = calloc(1, sizeof(permission_x));
820 if (permission == NULL) {
821 _LOGD("Malloc Failed\n");
824 application->permission = g_list_append(application->permission, permission);
825 ret = __ps_process_permission(reader, permission);
826 } else if (!strcmp(ASCII(node), "app-control")) {
827 ret = __ps_process_appcontrol(reader, &application->appcontrol);
828 } else if (!strcmp(ASCII(node), "application-service")) {
829 ret = __ps_process_appcontrol(reader, &application->appcontrol);
830 } else if (!strcmp(ASCII(node), "data-share")) {
831 datashare_x *datashare = calloc(1, sizeof(datashare_x));
832 if (datashare == NULL) {
833 _LOGD("Malloc Failed\n");
836 application->datashare = g_list_append(application->datashare, datashare);
837 ret = __ps_process_datashare(reader, datashare);
838 } else if (!strcmp(ASCII(node), "launch-conditions")) {
839 ret = __ps_process_launchconditions(reader, &application->launchconditions);
840 } else if (!strcmp(ASCII(node), "notification")) {
841 notification_x *notification = calloc(1, sizeof(notification_x));
842 if (notification == NULL) {
843 _LOGD("Malloc Failed\n");
846 application->notification = g_list_append(application->notification, notification);
847 ret = __ps_process_notification(reader, notification);
848 } else if (!strcmp(ASCII(node), "datacontrol")) {
849 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
850 if (datacontrol == NULL) {
851 _LOGD("Malloc Failed\n");
854 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
855 ret = __ps_process_datacontrol(reader, datacontrol);
856 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
857 ret = __ps_process_splashscreens(reader, &application->splashscreens);
861 _LOGD("Processing application failed\n");
869 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
871 _LOGD("__start_process\n");
876 depth = xmlTextReaderDepth(reader);
877 while ((ret = __next_child_element(reader, depth))) {
878 node = xmlTextReaderConstName(reader);
880 _LOGD("xmlTextReaderConstName value is NULL\n");
884 if (!strcmp(ASCII(node), "label")) {
885 label_x *label = calloc(1, sizeof(label_x));
887 _LOGD("Malloc Failed\n");
890 mfx->label = g_list_append(mfx->label, label);
891 ret = __ps_process_label(reader, label);
892 } else if (!strcmp(ASCII(node), "author")) {
893 author_x *author = calloc(1, sizeof(author_x));
894 if (author == NULL) {
895 _LOGD("Malloc Failed\n");
898 mfx->author = g_list_append(mfx->author, author);
899 ret = __ps_process_author(reader, author);
900 } else if (!strcmp(ASCII(node), "description")) {
901 description_x *description = calloc(1, sizeof(description_x));
902 if (description == NULL) {
903 _LOGD("Malloc Failed\n");
906 mfx->description = g_list_append(mfx->description, description);
907 ret = __ps_process_description(reader, description);
908 } else if (!strcmp(ASCII(node), "license")) {
909 license_x *license = calloc(1, sizeof(license_x));
910 if (license == NULL) {
911 _LOGD("Malloc Failed\n");
914 mfx->license = g_list_append(mfx->license, license);
915 ret = __ps_process_license(reader, license);
916 } else if (!strcmp(ASCII(node), "privileges")) {
917 ret = __ps_process_privileges(reader, &mfx->privileges);
918 } else if (!strcmp(ASCII(node), "ui-application")) {
919 application_x *application = calloc(1, sizeof(application_x));
920 if (application == NULL) {
921 _LOGD("Malloc Failed\n");
924 mfx->application = g_list_append(mfx->application, application);
925 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
926 } else if (!strcmp(ASCII(node), "service-application")) {
927 application_x *application = calloc(1, sizeof(application_x));
928 if (application == NULL) {
929 _LOGD("Malloc Failed\n");
932 mfx->application = g_list_append(mfx->application, application);
933 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
934 } else if (!strcmp(ASCII(node), "widget-application")) {
935 application_x *application = calloc(1, sizeof(application_x));
936 if (application == NULL) {
937 _LOGD("Malloc Failed\n");
940 mfx->application = g_list_append(mfx->application, application);
941 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
942 } else if (!strcmp(ASCII(node), "watch-application")) {
943 application_x *application = calloc(1, sizeof(application_x));
944 if (application == NULL) {
945 _LOGD("Malloc Failed\n");
948 mfx->application = g_list_append(mfx->application, application);
949 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
950 } else if (!strcmp(ASCII(node), "icon")) {
951 icon_x *icon = calloc(1, sizeof(icon_x));
953 _LOGD("Malloc Failed\n");
956 mfx->icon = g_list_append(mfx->icon, icon);
957 ret = __ps_process_icon(reader, icon, uid);
958 } else if (!strcmp(ASCII(node), "compatibility")) {
959 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
960 if (compatibility == NULL) {
961 _LOGD("Malloc Failed\n");
964 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
965 ret = __ps_process_compatibility(reader, compatibility);
966 } else if (!strcmp(ASCII(node), "shortcut-list")) {
968 } else if (!strcmp(ASCII(node), "livebox")) {
970 } else if (!strcmp(ASCII(node), "account")) {
972 } else if (!strcmp(ASCII(node), "notifications")) {
974 } else if (!strcmp(ASCII(node), "ime")) {
976 } else if (!strcmp(ASCII(node), "feature")) {
979 _LOGI("Unknown element: %s", ASCII(node));
984 _LOGD("Processing manifest failed\n");
991 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
996 if ((ret = __next_child_element(reader, -1))) {
997 node = xmlTextReaderConstName(reader);
999 _LOGD("xmlTextReaderConstName value is NULL\n");
1003 if (!strcmp(ASCII(node), "manifest")) {
1004 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1005 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1006 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1007 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1008 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1009 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1010 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1011 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1012 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1013 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1014 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1015 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1016 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1017 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1018 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1020 __save_xml_installed_time(mfx);
1021 __save_xml_root_path(mfx, uid);
1022 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1023 __save_xml_default_value(mfx);
1025 ret = __start_process(reader, mfx, uid);
1027 _LOGD("No Manifest element found\n");
1034 DEPRECATED API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
1036 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
1037 xmlTextReaderPtr reader;
1038 manifest_x *mfx = NULL;
1040 reader = xmlReaderForFile(manifest, NULL, 0);
1042 mfx = malloc(sizeof(manifest_x));
1044 memset(mfx, '\0', sizeof(manifest_x));
1045 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
1046 _LOGD("Parsing Failed\n");
1047 pkgmgr_parser_free_manifest_xml(mfx);
1050 _LOGD("Parsing Success\n");
1052 _LOGD("Memory allocation error\n");
1054 xmlFreeTextReader(reader);
1056 _LOGD("Unable to create xml reader\n");
1061 DEPRECATED API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
1063 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
1064 xmlTextReaderPtr reader;
1065 manifest_x *mfx = NULL;
1067 reader = xmlReaderForFile(manifest, NULL, 0);
1069 mfx = malloc(sizeof(manifest_x));
1071 memset(mfx, '\0', sizeof(manifest_x));
1072 if (__process_manifest(reader, mfx, uid) < 0) {
1073 _LOGD("Parsing Failed\n");
1074 pkgmgr_parser_free_manifest_xml(mfx);
1077 _LOGD("Parsing Success\n");
1079 _LOGD("Memory allocation error\n");
1081 xmlFreeTextReader(reader);
1083 _LOGD("Unable to create xml reader\n");
1088 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1091 char delims[] = "=";
1092 char *ret_result = NULL;
1099 for (tag = strdup(tagv[0]); tag != NULL; ) {
1100 ret_result = strtok_r(tag, delims, &ptr);
1102 /*check tag : preload */
1103 if (strcmp(ret_result, "preload") == 0) {
1104 ret_result = strtok_r(NULL, delims, &ptr);
1105 if (strcmp(ret_result, "true") == 0) {
1106 free((void *)mfx->preload);
1107 mfx->preload = strdup("true");
1108 } else if (strcmp(ret_result, "false") == 0) {
1109 free((void *)mfx->preload);
1110 mfx->preload = strdup("false");
1112 /*check tag : removable*/
1113 } else if (strcmp(ret_result, "removable") == 0) {
1114 ret_result = strtok_r(NULL, delims, &ptr);
1115 if (strcmp(ret_result, "true") == 0) {
1116 free((void *)mfx->removable);
1117 mfx->removable = strdup("true");
1118 } else if (strcmp(ret_result, "false") == 0) {
1119 free((void *)mfx->removable);
1120 mfx->removable = strdup("false");
1122 /*check tag : not matched*/
1124 _LOGD("tag process [%s]is not defined\n", ret_result);
1128 /*check next value*/
1129 if (tagv[++i] != NULL)
1130 tag = strdup(tagv[i]);
1132 _LOGD("tag process success...\n");
1138 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
1139 ACTION_TYPE action, const char *pkgid)
1141 int (*plugin_install) (xmlDocPtr, const char *);
1146 case ACTION_INSTALL:
1147 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
1149 case ACTION_UPGRADE:
1150 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
1152 case ACTION_UNINSTALL:
1153 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
1159 if ((plugin_install =
1160 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1161 _LOGE("can not find symbol[%s] \n", ac);
1165 ret = plugin_install(docPtr, pkgid);
1166 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
1172 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
1175 const xmlChar *name;
1177 if (xmlTextReaderDepth(reader) != 1) {
1178 _LOGE("Node depth is not 1");
1182 if (xmlTextReaderNodeType(reader) != 1) {
1183 _LOGE("Node type is not 1");
1187 const xmlChar *value;
1188 name = xmlTextReaderConstName(reader);
1190 _LOGE("TEST TEST TES\n");
1191 name = BAD_CAST "--";
1194 value = xmlTextReaderConstValue(reader);
1195 if (value != NULL) {
1196 if (xmlStrlen(value) > 40)
1197 _LOGD(" %.40s...", value);
1199 _LOGD(" %s", value);
1202 name = xmlTextReaderConstName(reader);
1204 _LOGE("TEST TEST TES\n");
1205 name = BAD_CAST "--";
1208 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
1209 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
1210 if (copyDocPtr == NULL)
1212 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
1213 if (rootElement == NULL)
1215 xmlNode *cur_node = xmlFirstElementChild(rootElement);
1216 if (cur_node == NULL)
1218 xmlNode *temp = xmlTextReaderExpand(reader);
1221 xmlNode *next_node = NULL;
1222 while (cur_node != NULL) {
1223 if ((strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
1224 (temp->line == cur_node->line)) {
1227 next_node = xmlNextElementSibling(cur_node);
1228 xmlUnlinkNode(cur_node);
1229 xmlFreeNode(cur_node);
1230 cur_node = next_node;
1233 if (cur_node == NULL)
1235 next_node = xmlNextElementSibling(cur_node);
1237 cur_node->next = NULL;
1238 next_node->prev = NULL;
1239 xmlFreeNodeList(next_node);
1240 xmlSetTreeDoc(cur_node, copyDocPtr);
1242 xmlSetTreeDoc(cur_node, copyDocPtr);
1245 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
1251 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
1253 switch (xmlTextReaderNodeType(reader)) {
1254 case XML_READER_TYPE_END_ELEMENT:
1258 case XML_READER_TYPE_ELEMENT:
1260 /* Elements without closing tag don't receive */
1261 const xmlChar *elementName =
1262 xmlTextReaderLocalName(reader);
1263 if (elementName == NULL)
1266 if (strcmp(tag, ASCII(elementName)) == 0) {
1267 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
1268 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
1279 static void __str_trim(char *input)
1281 char *trim_str = input;
1286 while (*input != 0) {
1287 if (!isspace(*input)) {
1298 static char *__get_parser_plugin(const char *type)
1301 char buffer[1024] = { 0 };
1302 char temp_path[1024] = { 0 };
1306 _LOGE("invalid argument\n");
1310 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1312 _LOGE("no matching backendlib\n");
1316 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1317 if (buffer[0] == '#')
1322 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
1323 path = path + strlen(PKG_PARSERLIB);
1327 memset(buffer, 0x00, 1024);
1334 _LOGE("no matching backendlib\n");
1338 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1340 return strdup(temp_path);
1343 static void *__open_lib_handle(char *tag)
1345 char *lib_path = NULL;
1346 void *lib_handle = NULL;
1348 lib_path = __get_parser_plugin(tag);
1349 retvm_if(!lib_path, NULL, "lib_path get fail");
1351 lib_handle = dlopen(lib_path, RTLD_LAZY);
1352 if (lib_handle == NULL)
1353 _LOGE("dlopen is failed lib_path[%s]", lib_path);
1360 static void __close_lib_handle(void *lib_handle)
1362 dlclose(lib_handle);
1365 static char * __get_tag_by_key(char *md_key)
1367 char *md_tag = NULL;
1369 if (md_key == NULL) {
1370 _LOGD("md_key is NULL\n");
1374 md_tag = strrchr(md_key, 47) + 1;
1377 return strdup(md_tag);
1380 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1382 int (*plugin_install) (const char *);
1386 if (process == PLUGIN_PRE_PROCESS) {
1388 case ACTION_INSTALL:
1389 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
1391 case ACTION_UPGRADE:
1392 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
1394 case ACTION_UNINSTALL:
1395 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
1400 } else if (process == PLUGIN_POST_PROCESS) {
1402 case ACTION_INSTALL:
1403 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
1405 case ACTION_UPGRADE:
1406 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
1408 case ACTION_UNINSTALL:
1409 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
1417 if ((plugin_install =
1418 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1422 ret = plugin_install(pkgid);
1426 static int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1428 xmlTextReaderPtr reader;
1432 void *lib_handle = NULL;
1433 char tag[PKG_STRING_LEN_MAX] = { 0 };
1435 fp = fopen(TAG_PARSER_LIST, "r");
1436 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1438 while (fgets(tag, sizeof(tag), fp) != NULL) {
1441 lib_handle = __open_lib_handle(tag);
1442 if (lib_handle == NULL)
1445 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1446 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1448 docPtr = xmlReadFile(filename, NULL, 0);
1449 reader = xmlReaderWalker(docPtr);
1450 if (reader != NULL) {
1451 ret = xmlTextReaderRead(reader);
1453 __process_tag(lib_handle, reader, action, tag, mfx->package);
1454 ret = xmlTextReaderRead(reader);
1456 xmlFreeTextReader(reader);
1459 _LOGD("%s : failed to parse", filename);
1461 _LOGD("Unable to open %s", filename);
1464 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1465 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1467 __close_lib_handle(lib_handle);
1469 memset(tag, 0x00, sizeof(tag));
1478 static void __metadata_parser_clear_dir_list(GList* dir_list)
1481 __metadata_t* detail = NULL;
1484 list = g_list_first(dir_list);
1486 detail = (__metadata_t *)list->data;
1489 free((void *)detail->key);
1491 free((void *)detail->value);
1494 list = g_list_next(list);
1496 g_list_free(dir_list);
1500 static char *__get_metadata_parser_plugin(const char *type)
1503 char buffer[1024] = { 0 };
1504 char temp_path[1024] = { 0 };
1508 _LOGE("invalid argument\n");
1512 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1514 _LOGE("no matching metadata parser\n");
1518 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1519 if (buffer[0] == '#')
1524 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
1525 path = path + strlen(METADATA_PARSER_NAME);
1530 memset(buffer, 0x00, 1024);
1537 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME, type);
1541 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1543 return strdup(temp_path);
1546 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
1547 ACTION_TYPE action, const char *pkgid, const char *appid)
1549 char *lib_path = NULL;
1550 void *lib_handle = NULL;
1551 int (*metadata_parser_plugin) (const char *, const char *, GList *);
1556 case ACTION_INSTALL:
1557 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
1559 case ACTION_UPGRADE:
1560 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
1562 case ACTION_UNINSTALL:
1563 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
1569 lib_path = __get_metadata_parser_plugin(tag);
1571 _LOGE("get %s parser fail\n", tag);
1575 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1576 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1580 if ((metadata_parser_plugin =
1581 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1582 _LOGE("can not find symbol[%s] \n", ac);
1586 ret = metadata_parser_plugin(pkgid, appid, md_list);
1588 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1590 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1596 dlclose(lib_handle);
1600 static int __run_metadata_parser_prestep(manifest_x *mfx, char *md_key, ACTION_TYPE action)
1604 char buffer[1024] = { 0, };
1607 GList *md_tmp = NULL;
1609 char *md_tag = NULL;
1611 GList *md_list = NULL;
1612 __metadata_t *md_detail = NULL;
1614 md_tag = __get_tag_by_key(md_key);
1615 if (md_tag == NULL) {
1616 _LOGD("md_tag is NULL\n");
1620 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1621 app = (application_x *)app_tmp->data;
1624 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1625 md = (metadata_x *)md_tmp->data;
1628 /* get glist of metadata key and value combination */
1629 memset(buffer, 0x00, 1024);
1630 snprintf(buffer, 1024, "%s/", md_key);
1631 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
1632 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
1633 if (md_detail == NULL) {
1634 _LOGD("Memory allocation failed\n");
1638 md_detail->key = strdup(md->key);
1639 if (md_detail->key == NULL) {
1640 _LOGD("Memory allocation failed\n");
1645 md_detail->value = strdup(md->value);
1646 if (md_detail->value == NULL) {
1647 _LOGD("Memory allocation failed\n");
1648 free((void *)md_detail->key);
1653 md_list = g_list_append(md_list, (gpointer)md_detail);
1658 /* send glist to parser when tags for metadata plugin parser exist. */
1660 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
1662 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
1664 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
1666 __metadata_parser_clear_dir_list(md_list);
1675 __metadata_parser_clear_dir_list(md_list);
1682 static int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1684 fprintf(stdout, "__ps_process_metadata_parser\n");
1687 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1689 fp = fopen(METADATA_PARSER_LIST, "r");
1691 _LOGD("no preload list\n");
1695 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1697 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1708 static void __category_parser_clear_dir_list(GList* dir_list)
1711 __category_t* detail = NULL;
1714 list = g_list_first(dir_list);
1716 detail = (__category_t *)list->data;
1719 free((void *)detail->name);
1723 list = g_list_next(list);
1725 g_list_free(dir_list);
1729 static char *__get_category_parser_plugin(const char *type)
1732 char buffer[1024] = { 0 };
1733 char temp_path[1024] = { 0 };
1737 _LOGE("invalid argument\n");
1741 fp = fopen(PKG_PARSER_CONF_PATH, "r");
1743 _LOGE("no matching metadata parser\n");
1747 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
1748 if (buffer[0] == '#')
1753 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
1754 path = path + strlen(CATEGORY_PARSER_NAME);
1759 memset(buffer, 0x00, 1024);
1766 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME, type);
1770 snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
1772 return strdup(temp_path);
1775 static int __ps_run_category_parser(GList *category_list, const char *tag,
1776 ACTION_TYPE action, const char *pkgid, const char *appid)
1778 char *lib_path = NULL;
1779 void *lib_handle = NULL;
1780 int (*category_parser_plugin) (const char *, const char *, GList *);
1785 case ACTION_INSTALL:
1786 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
1788 case ACTION_UPGRADE:
1789 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
1791 case ACTION_UNINSTALL:
1792 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
1798 lib_path = __get_category_parser_plugin(tag);
1800 _LOGE("get %s parser fail\n", tag);
1804 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1805 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1809 if ((category_parser_plugin =
1810 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1811 _LOGE("can not find symbol[%s] \n", ac);
1815 ret = category_parser_plugin(pkgid, appid, category_list);
1817 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1819 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1825 dlclose(lib_handle);
1829 static int __run_category_parser_prestep(manifest_x *mfx, char *category_key, ACTION_TYPE action)
1833 char buffer[1024] = { 0, };
1836 GList *category_tmp;
1837 const char *category;
1838 char *category_tag = NULL;
1840 GList *category_list = NULL;
1841 __category_t *category_detail = NULL;
1843 category_tag = __get_tag_by_key(category_key);
1844 if (category_tag == NULL) {
1845 _LOGD("md_tag is NULL\n");
1849 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1850 app = (application_x *)app_tmp->data;
1853 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
1854 category = (const char *)category_tmp->data;
1855 /* get glist of category key and value combination */
1856 memset(buffer, 0x00, 1024);
1857 snprintf(buffer, 1024, "%s/", category_key);
1858 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
1859 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
1860 if (category_detail == NULL) {
1861 _LOGD("Memory allocation failed\n");
1865 category_detail->name = strdup(category);
1866 if (category_detail->name == NULL) {
1867 _LOGD("Memory allocation failed\n");
1868 free(category_detail);
1872 category_list = g_list_append(category_list, (gpointer)category_detail);
1877 /* send glist to parser when tags for metadata plugin parser exist. */
1879 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
1881 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
1883 _LOGD("category_parser success for tag[%s]\n", category_tag);
1885 __category_parser_clear_dir_list(category_list);
1886 category_list = NULL;
1894 __category_parser_clear_dir_list(category_list);
1901 static int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1905 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1907 fp = fopen(CATEGORY_PARSER_LIST, "r");
1909 _LOGD("no category parser list\n");
1913 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1914 __str_trim(category_key);
1915 ret = __run_category_parser_prestep(mfx, category_key, action);
1926 DEPRECATED API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
1928 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1929 _LOGD("parsing manifest for installation: %s\n", manifest);
1931 manifest_x *mfx = NULL;
1935 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1936 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1938 _LOGD("Parsing Finished\n");
1940 __ps_process_tag(mfx, tagv);
1942 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
1943 if (ret == PMINFO_R_ERROR) {
1944 _LOGE("DB Insert failed");
1945 pkgmgr_parser_free_manifest_xml(mfx);
1946 return PMINFO_R_ERROR;
1949 _LOGD("DB Insert Success\n");
1951 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1952 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1954 _LOGD("Creating metadata parser failed\n");
1956 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1958 _LOGD("Creating category parser failed\n");
1960 pkgmgr_parser_free_manifest_xml(mfx);
1961 _LOGD("Free Done\n");
1967 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
1969 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1970 _LOGD("parsing manifest for installation: %s\n", manifest);
1971 manifest_x *mfx = NULL;
1975 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
1976 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1978 _LOGD("Parsing Finished\n");
1980 __ps_process_tag(mfx, tagv);
1982 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
1983 if (ret == PMINFO_R_ERROR) {
1984 _LOGE("DB Insert failed");
1985 pkgmgr_parser_free_manifest_xml(mfx);
1986 return PMINFO_R_ERROR;
1989 _LOGD("DB Insert Success\n");
1991 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1992 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1994 _LOGD("Creating metadata parser failed\n");
1995 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1997 _LOGD("Creating category parser failed\n");
1999 pkgmgr_parser_free_manifest_xml(mfx);
2000 _LOGD("Free Done\n");
2006 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
2008 if (!strstr(manifest, getUserManifestPath(uid,
2009 strcmp(mfx->preload, "true") == 0))) {
2010 /* if downloaded app is updated, then update tag set true*/
2012 free((void *)mfx->update);
2013 mfx->update = strdup("true");
2019 DEPRECATED API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2021 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2022 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2023 manifest_x *mfx = NULL;
2025 bool preload = false;
2026 bool system = false;
2027 char *csc_path = NULL;
2028 pkgmgrinfo_pkginfo_h handle = NULL;
2031 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2032 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2034 _LOGD("Parsing Finished\n");
2035 __check_preload_updated(mfx, manifest, GLOBAL_USER);
2037 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2038 if (ret != PMINFO_R_OK)
2039 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2040 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2041 if (ret != PMINFO_R_OK)
2042 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2045 free((void *)mfx->preload);
2046 mfx->preload = strdup("true");
2049 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2050 if (ret != PMINFO_R_OK)
2051 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2053 free((void *)mfx->system);
2054 mfx->system = strdup("true");
2057 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2058 if (ret != PMINFO_R_OK)
2059 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2061 if (csc_path != NULL) {
2063 free((void *)mfx->csc_path);
2064 mfx->csc_path = strdup(csc_path);
2067 /*Delete from cert table*/
2068 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2069 if (ret != PMINFO_R_OK) {
2070 _LOGD("Cert Info DB Delete Failed\n");
2071 pkgmgr_parser_free_manifest_xml(mfx);
2072 return PMINFO_R_ERROR;
2075 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2076 if (ret != PMINFO_R_OK) {
2077 _LOGD("DB Insert failed\n");
2078 pkgmgr_parser_free_manifest_xml(mfx);
2079 return PMINFO_R_ERROR;
2082 _LOGD("DB Update Success\n");
2084 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2085 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2087 _LOGD("Upgrade metadata parser failed\n");
2088 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2090 _LOGD("Creating category parser failed\n");
2091 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2092 pkgmgr_parser_free_manifest_xml(mfx);
2093 _LOGD("Free Done\n");
2099 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2101 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2102 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2103 manifest_x *mfx = NULL;
2105 bool preload = false;
2106 bool system = false;
2107 char *csc_path = NULL;
2108 pkgmgrinfo_pkginfo_h handle = NULL;
2111 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2112 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2114 _LOGD("Parsing Finished\n");
2115 __check_preload_updated(mfx, manifest, uid);
2117 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2118 if (ret != PMINFO_R_OK)
2119 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2120 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2121 if (ret != PMINFO_R_OK)
2122 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2125 free((void *)mfx->preload);
2126 mfx->preload = strdup("true");
2129 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2130 if (ret != PMINFO_R_OK)
2131 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2134 free((void *)mfx->system);
2135 mfx->system = strdup("true");
2138 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2139 if (ret != PMINFO_R_OK)
2140 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2141 if (csc_path != NULL) {
2143 free((void *)mfx->csc_path);
2144 mfx->csc_path = strdup(csc_path);
2147 /*Delete from cert table*/
2148 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2149 if (ret != PMINFO_R_OK) {
2150 _LOGD("Cert Info DB Delete Failed\n");
2151 pkgmgr_parser_free_manifest_xml(mfx);
2152 return PMINFO_R_ERROR;
2155 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2156 if (ret != PMINFO_R_OK) {
2157 _LOGD("DB Insert failed\n");
2158 pkgmgr_parser_free_manifest_xml(mfx);
2159 return PMINFO_R_ERROR;
2162 _LOGD("DB Update Success\n");
2164 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2165 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2167 _LOGD("Upgrade metadata parser failed\n");
2168 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2170 _LOGD("Creating category parser failed\n");
2171 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2172 pkgmgr_parser_free_manifest_xml(mfx);
2173 _LOGD("Free Done\n");
2179 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2181 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2182 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2184 manifest_x *mfx = NULL;
2187 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2188 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2190 _LOGD("Parsing Finished\n");
2192 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2194 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2196 _LOGD("Removing metadata parser failed\n");
2198 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2200 _LOGD("Creating category parser failed\n");
2202 /*Delete from cert table*/
2203 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2205 _LOGD("Cert Info DB Delete Failed\n");
2206 pkgmgr_parser_free_manifest_xml(mfx);
2210 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2212 _LOGD("DB Delete failed\n");
2214 _LOGD("DB Delete Success\n");
2216 pkgmgr_parser_free_manifest_xml(mfx);
2217 _LOGD("Free Done\n");
2223 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
2225 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
2227 void *lib_handle = NULL;
2228 int (*appsvc_operation) (const char *, uid_t);
2231 application_x *application;
2233 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
2234 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
2238 if ((appsvc_operation =
2239 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
2240 _LOGE("can not find symbol \n");
2244 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2245 application = (application_x *)tmp->data;
2246 if (application == NULL)
2248 ret = appsvc_operation(application->appid, uid);
2250 _LOGE("can not operation symbol \n");
2255 dlclose(lib_handle);
2260 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2262 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2263 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2265 manifest_x *mfx = NULL;
2268 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2269 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2271 _LOGD("Parsing Finished\n");
2273 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2275 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2277 _LOGD("Removing metadata parser failed\n");
2279 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2281 _LOGD("Creating category parser failed\n");
2283 /*Delete from cert table*/
2284 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2286 _LOGD("Cert Info DB Delete Failed\n");
2287 pkgmgr_parser_free_manifest_xml(mfx);
2291 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2293 _LOGD("DB Delete failed\n");
2295 _LOGD("DB Delete Success\n");
2297 ret = __ps_remove_appsvc_db(mfx, uid);
2299 _LOGD("Removing appsvc_db failed\n");
2301 _LOGD("Removing appsvc_db Success\n");
2303 pkgmgr_parser_free_manifest_xml(mfx);
2304 _LOGD("Free Done\n");