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 CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
46 #define TAG_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/tag_parser_list.txt"
48 #define PLUGIN_PATH_PREFIX SYSCONFDIR "/package-manager/parserlib/"
53 /* plugin process_type */
55 PLUGIN_PRE_PROCESS = 0,
57 } PLUGIN_PROCESS_TYPE;
61 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, char **xml_attribute, char *default_value)
63 xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
65 *xml_attribute = strdup((const char *)attrib_val);
68 if (default_value != NULL)
69 *xml_attribute = strdup(default_value);
73 static void __save_xml_value(xmlTextReaderPtr reader, char **xml_attribute)
76 const xmlChar *attrib_val;
78 ret = xmlTextReaderRead(reader);
81 attrib_val = xmlTextReaderConstValue(reader);
84 *xml_attribute = strdup((const char *)attrib_val);
87 static void __save_xml_lang(xmlTextReaderPtr reader, char **xml_attribute)
89 const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
90 if (attrib_val != NULL)
91 *xml_attribute = strdup(ASCII(attrib_val));
93 *xml_attribute = strdup(DEFAULT_LOCALE);
96 static void __save_xml_installed_time(manifest_x *mfx)
98 char buf[PKG_STRING_LEN_MAX] = {'\0'};
102 snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
103 val = strndup(buf, PKG_STRING_LEN_MAX - 1);
104 mfx->installed_time = val;
107 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
109 char root[PKG_STRING_LEN_MAX] = { '\0' };
115 tzplatform_set_user(uid);
116 path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
117 snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
119 mfx->root_path = strdup(root);
121 tzplatform_reset_user();
124 static void __save_xml_default_value(manifest_x * mfx)
126 mfx->preload = strdup("False");
127 mfx->removable = strdup("True");
128 mfx->readonly = strdup("False");
129 mfx->update = strdup("False");
130 mfx->system = strdup("False");
131 mfx->installed_storage = strdup("installed_internal");
132 package = mfx->package;
135 static int __next_child_element(xmlTextReaderPtr reader, int depth)
137 int ret = xmlTextReaderRead(reader);
138 int cur = xmlTextReaderDepth(reader);
141 switch (xmlTextReaderNodeType(reader)) {
142 case XML_READER_TYPE_ELEMENT:
143 if (cur == depth + 1)
146 case XML_READER_TYPE_TEXT:
147 /*text is handled by each function separately*/
148 if (cur == depth + 1)
151 case XML_READER_TYPE_END_ELEMENT:
160 ret = xmlTextReaderRead(reader);
161 cur = xmlTextReaderDepth(reader);
166 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
168 __save_xml_attribute(reader, "name", &label->name, NULL);
169 __save_xml_lang(reader, &label->lang);
170 __save_xml_value(reader, &label->text);
175 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
177 __save_xml_attribute(reader, "email", &author->email, NULL);
178 __save_xml_attribute(reader, "href", &author->href, NULL);
179 __save_xml_value(reader, &author->text);
183 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
185 __save_xml_lang(reader, &description->lang);
186 __save_xml_value(reader, &description->text);
190 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
192 __save_xml_lang(reader, &license->lang);
193 __save_xml_value(reader, &license->text);
197 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
199 __save_xml_attribute(reader, "type", &privilege->type, "tpk");
200 __save_xml_value(reader, &privilege->value);
203 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
209 depth = xmlTextReaderDepth(reader);
210 while ((ret = __next_child_element(reader, depth))) {
211 node = xmlTextReaderConstName(reader);
213 _LOGD("xmlTextReaderConstName value is NULL\n");
217 if (strcmp(ASCII(node), "privilege") == 0) {
218 privilege_x *privilege = calloc(1, sizeof(privilege_x));
219 if (privilege == NULL) {
220 _LOGD("Malloc Failed\n");
223 ret = __ps_process_privilege(reader, privilege);
227 *privileges = g_list_append(*privileges, (gpointer)privilege);
232 _LOGD("Processing privileges failed\n");
239 static char *__get_icon_with_path(const char *icon, uid_t uid)
241 char icon_with_path[BUFSIZE];
242 const char *app_path;
244 if (!icon || !package)
247 /* just use absolute path */
248 if (index(icon, '/'))
252 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
253 snprintf(icon_with_path, sizeof(icon_with_path),
254 "%s%s", getIconPath(uid, true), icon);
255 if (access(icon_with_path, F_OK) == 0)
258 snprintf(icon_with_path, sizeof(icon_with_path),
259 "%s%s", getIconPath(uid, false), icon);
260 if (access(icon_with_path, F_OK) == 0)
263 /* for backward compatibility (.../default/small/...)
264 * this should be removed
266 snprintf(icon_with_path, sizeof(icon_with_path),
267 "%sdefault/small/%s",
268 getIconPath(uid, true), icon);
269 if (access(icon_with_path, F_OK) == 0)
272 snprintf(icon_with_path, sizeof(icon_with_path),
273 "%sdefault/small/%s",
274 getIconPath(uid, false), icon);
275 if (access(icon_with_path, F_OK) == 0)
278 /* If doesn't exist in case of Global app,
279 * try to get icon directly into app's directory
281 app_path = tzplatform_getenv(TZ_SYS_RO_APP);
283 snprintf(icon_with_path, sizeof(icon_with_path),
284 "%s/%s/%s", app_path, package, icon);
285 if (access(icon_with_path, F_OK) == 0)
288 app_path = tzplatform_getenv(TZ_SYS_RW_APP);
290 snprintf(icon_with_path, sizeof(icon_with_path),
291 "%s/%s/%s", app_path, package, icon);
292 if (access(icon_with_path, F_OK) == 0)
295 tzplatform_set_user(uid);
296 app_path = tzplatform_getenv(TZ_USER_APP);
297 tzplatform_reset_user();
299 snprintf(icon_with_path, sizeof(icon_with_path),
300 "%s/%s/%s", app_path, package, icon);
301 if (access(icon_with_path, F_OK) == 0)
305 /* some preload package has icons at below path */
306 snprintf(icon_with_path, sizeof(icon_with_path),
307 "%s/%s/res/icons/%s", app_path, package, icon);
308 if (access(icon_with_path, F_OK) == 0)
311 /* since 2.3 tpk package */
312 snprintf(icon_with_path, sizeof(icon_with_path),
313 "%s/%s/shared/res/%s", app_path, package, icon);
314 if (access(icon_with_path, F_OK) == 0)
317 _LOGE("cannot find icon path for [%s]", icon);
321 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
323 return strdup(icon_with_path);
326 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
331 __save_xml_attribute(reader, "section", &icon->section, NULL);
332 __save_xml_attribute(reader, "size", &icon->size, NULL);
333 __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
334 __save_xml_lang(reader, &icon->lang);
336 ret = xmlTextReaderRead(reader);
339 text = ASCII(xmlTextReaderValue(reader));
341 icon->text = __get_icon_with_path(text, uid);
348 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
350 __save_xml_attribute(reader, "name", &compatibility->name, NULL);
351 __save_xml_value(reader, &compatibility->text);
355 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
357 __save_xml_attribute(reader, "section", &image->section, NULL);
358 __save_xml_lang(reader, &image->lang);
359 __save_xml_value(reader, &image->text);
363 static int __ps_process_category(xmlTextReaderPtr reader, char **category)
365 __save_xml_attribute(reader, "name", category, NULL);
369 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
371 __save_xml_attribute(reader, "key", &metadata->key, NULL);
372 __save_xml_attribute(reader, "value", &metadata->value, NULL);
376 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
378 __save_xml_attribute(reader, "type", &permission->type, NULL);
379 __save_xml_value(reader, &permission->value);
383 struct appcontrol_data {
388 char operation[BUFSIZE];
393 static void __ps_process_mime(gpointer data, gpointer user_data)
395 char *mime = (char *)data;
396 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
397 appcontrol_x *appcontrol;
399 snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
401 appcontrol = calloc(1, sizeof(appcontrol_x));
402 if (appcontrol == NULL) {
403 _LOGD("Malloc Failed\n");
406 if (strlen(ad->operation))
407 appcontrol->operation = strdup(ad->operation);
409 appcontrol->uri = strdup(ad->uri);
410 appcontrol->mime = strdup(ad->mime);
411 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
414 static void __ps_process_uri(gpointer data, gpointer user_data)
416 char *uri = (char *)data;
417 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
418 appcontrol_x *appcontrol;
420 snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
422 if (ad->mimes != NULL) {
423 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
425 appcontrol = calloc(1, sizeof(appcontrol_x));
426 if (appcontrol == NULL) {
427 _LOGD("Malloc Failed\n");
430 if (strlen(ad->operation))
431 appcontrol->operation = strdup(ad->operation);
432 appcontrol->uri = strdup(ad->uri);
433 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
437 static void __ps_process_operation(gpointer data, gpointer user_data)
439 char *operation = (char *)data;
440 struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
441 appcontrol_x *appcontrol;
443 snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
445 if (ad->uris != NULL) {
446 g_list_foreach(ad->uris, __ps_process_uri, user_data);
447 } else if (ad->mimes != NULL) {
448 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
450 appcontrol = calloc(1, sizeof(appcontrol_x));
451 if (appcontrol == NULL) {
452 _LOGD("Malloc Failed\n");
455 appcontrol->operation = strdup(ad->operation);
456 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
460 static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
462 struct appcontrol_data ad = {0, };
464 ad.operations = operations;
468 if (ad.operations == NULL)
471 g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
473 return ad.appcontrols;
476 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
482 GList *operations = NULL;
487 depth = xmlTextReaderDepth(reader);
488 while ((ret = __next_child_element(reader, depth)) > 0) {
489 node = xmlTextReaderConstName(reader);
491 _LOGD("xmlTextReaderConstName value is NULL\n");
492 g_list_free_full(operations, free);
493 g_list_free_full(uris, free);
494 g_list_free_full(mimes, free);
499 if (!strcmp(ASCII(node), "operation")) {
500 __save_xml_attribute(reader, "name", &val, NULL);
502 operations = g_list_append(operations, (gpointer)val);
503 _LOGD("operation processing\n");
504 } else if (!strcmp(ASCII(node), "uri")) {
505 __save_xml_attribute(reader, "name", &val, NULL);
507 uris = g_list_append(uris, (gpointer)val);
508 _LOGD("uri processing\n");
509 } else if (!strcmp(ASCII(node), "mime")) {
510 __save_xml_attribute(reader, "name", &val, NULL);
512 mimes = g_list_append(mimes, (gpointer)val);
513 _LOGD("mime processing\n");
514 } else if (!strcmp(ASCII(node), "subapp")) {
522 _LOGD("Processing appcontrol failed\n");
523 g_list_free_full(operations, free);
524 g_list_free_full(uris, free);
525 g_list_free_full(mimes, free);
529 result = __make_appcontrol_list(operations, uris, mimes);
531 *appcontrol = g_list_concat(*appcontrol, result);
535 g_list_free_full(operations, free);
536 g_list_free_full(uris, free);
537 g_list_free_full(mimes, free);
542 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed)
544 __save_xml_value(reader, allowed);
548 static int __ps_process_request(xmlTextReaderPtr reader, char **request)
550 __save_xml_value(reader, request);
554 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
561 __save_xml_attribute(reader, "path", &define->path, NULL);
563 depth = xmlTextReaderDepth(reader);
564 while ((ret = __next_child_element(reader, depth))) {
565 node = xmlTextReaderConstName(reader);
567 _LOGD("xmlTextReaderConstName value is NULL\n");
571 if (!strcmp(ASCII(node), "allowed")) {
573 ret = __ps_process_allowed(reader, &val);
575 define->allowed = g_list_append(define->allowed, (gpointer)val);
576 } else if (!strcmp(ASCII(node), "request")) {
578 ret = __ps_process_request(reader, &val);
580 define->request = g_list_append(define->request, (gpointer)val);
585 _LOGD("Processing define failed\n");
592 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
598 depth = xmlTextReaderDepth(reader);
599 while ((ret = __next_child_element(reader, depth))) {
600 node = xmlTextReaderConstName(reader);
602 _LOGD("xmlTextReaderConstName value is NULL\n");
606 if (!strcmp(ASCII(node), "define")) {
607 define_x *define = calloc(1, sizeof(define_x));
608 if (define == NULL) {
609 _LOGD("Malloc Failed\n");
612 datashare->define = g_list_append(datashare->define, define);
613 ret = __ps_process_define(reader, define);
614 } else if (!strcmp(ASCII(node), "request")) {
616 ret = __ps_process_request(reader, &val);
618 datashare->request = g_list_append(datashare->request, (gpointer)val);
622 _LOGD("Processing data-share failed\n");
629 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition)
631 __save_xml_attribute(reader, "name", condition, NULL);
635 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
642 depth = xmlTextReaderDepth(reader);
643 while ((ret = __next_child_element(reader, depth))) {
644 node = xmlTextReaderConstName(reader);
646 _LOGD("xmlTextReaderConstName value is NULL\n");
650 if (strcmp(ASCII(node), "condition") == 0) {
652 ret = __ps_process_condition(reader, &val);
654 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
658 _LOGD("Processing launchconditions failed\n");
666 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
668 __save_xml_attribute(reader, "name", ¬ification->name, NULL);
669 __save_xml_value(reader, ¬ification->text);
673 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
675 __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
676 __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
677 __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
681 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
683 __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
684 __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
685 __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
686 __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
687 __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
688 __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
689 __save_xml_attribute(reader, "color-depth", &splashscreen->color_depth, NULL);
693 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
698 splashscreen_x *splashscreen;
700 depth = xmlTextReaderDepth(reader);
701 while ((ret = __next_child_element(reader, depth))) {
702 node = xmlTextReaderConstName(reader);
704 _LOGD("xmlTextReaderConstName value is NULL\n");
708 if (strcmp(ASCII(node), "splash-screen") == 0) {
709 splashscreen = calloc(1, sizeof(splashscreen_x));
710 if (splashscreen == NULL) {
711 _LOGD("Malloc Failed\n");
714 *splashscreens = g_list_append(*splashscreens, splashscreen);
715 ret = __ps_process_splashscreen(reader, splashscreen);
721 _LOGD("Processing splash-screen failed\n");
728 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
735 __save_xml_attribute(reader, "appid", &application->appid, NULL);
736 retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
737 __save_xml_attribute(reader, "exec", &application->exec, NULL);
738 __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
739 __save_xml_attribute(reader, "multiple", &application->multiple, "false");
740 __save_xml_attribute(reader, "type", &application->type, NULL);
741 __save_xml_attribute(reader, "categories", &application->categories, NULL);
742 __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
743 __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
744 __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
745 __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
746 __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
747 __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
748 __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
749 __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
750 __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
751 __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
752 __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
753 __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
754 __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
755 /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
756 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);
757 __save_xml_attribute(reader, "submode", &application->submode, "false");
758 __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
759 __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
760 __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
761 __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
762 __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
763 __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
764 __save_xml_attribute(reader, "splash-screen-display", &application->splash_screen_display, "true");
766 application->package = strdup(package);
767 /* overwrite some attributes if the app is widgetapp */
768 if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
769 free((void *)application->nodisplay);
770 application->nodisplay = strdup("true");
771 free((void *)application->multiple);
772 application->multiple = strdup("true");
773 free((void *)application->type);
774 application->type = strdup("capp");
775 free((void *)application->taskmanage);
776 application->taskmanage = strdup("false");
777 free((void *)application->indicatordisplay);
778 application->indicatordisplay = strdup("false");
781 /* hw-acceleration values are changed from use-GL/not-use-GL/use-system-setting to on/off/default */
782 if (strcmp(application->hwacceleration, "use-GL") == 0) {
783 free((void *)application->hwacceleration);
784 application->hwacceleration = strdup("on");
785 } else if (strcmp(application->hwacceleration, "not-use-GL") == 0) {
786 free((void *)application->hwacceleration);
787 application->hwacceleration = strdup("off");
788 } else if (strcmp(application->hwacceleration, "use-system-setting") == 0) {
789 free((void *)application->hwacceleration);
790 application->hwacceleration = strdup("default");
793 depth = xmlTextReaderDepth(reader);
794 while ((ret = __next_child_element(reader, depth))) {
795 node = xmlTextReaderConstName(reader);
797 _LOGD("xmlTextReaderConstName value is NULL\n");
800 if (!strcmp(ASCII(node), "label")) {
801 label_x *label = calloc(1, sizeof(label_x));
803 _LOGD("Malloc Failed\n");
806 application->label = g_list_append(application->label, label);
807 ret = __ps_process_label(reader, label);
808 } else if (!strcmp(ASCII(node), "icon")) {
809 icon_x *icon = calloc(1, sizeof(icon_x));
811 _LOGD("Malloc Failed\n");
814 application->icon = g_list_append(application->icon, icon);
815 ret = __ps_process_icon(reader, icon, uid);
816 } else if (!strcmp(ASCII(node), "image")) {
817 image_x *image = calloc(1, sizeof(image_x));
819 _LOGD("Malloc Failed\n");
822 application->image = g_list_append(application->image, image);
823 ret = __ps_process_image(reader, image);
824 } else if (!strcmp(ASCII(node), "category")) {
826 ret = __ps_process_category(reader, &val);
828 application->category = g_list_append(application->category, (gpointer)val);
829 } else if (!strcmp(ASCII(node), "metadata")) {
830 metadata_x *metadata = calloc(1, sizeof(metadata_x));
831 if (metadata == NULL) {
832 _LOGD("Malloc Failed\n");
835 application->metadata = g_list_append(application->metadata, metadata);
836 ret = __ps_process_metadata(reader, metadata);
837 } else if (!strcmp(ASCII(node), "permission")) {
838 permission_x *permission = calloc(1, sizeof(permission_x));
839 if (permission == NULL) {
840 _LOGD("Malloc Failed\n");
843 application->permission = g_list_append(application->permission, permission);
844 ret = __ps_process_permission(reader, permission);
845 } else if (!strcmp(ASCII(node), "app-control")) {
846 ret = __ps_process_appcontrol(reader, &application->appcontrol);
847 } else if (!strcmp(ASCII(node), "application-service")) {
848 ret = __ps_process_appcontrol(reader, &application->appcontrol);
849 } else if (!strcmp(ASCII(node), "data-share")) {
850 datashare_x *datashare = calloc(1, sizeof(datashare_x));
851 if (datashare == NULL) {
852 _LOGD("Malloc Failed\n");
855 application->datashare = g_list_append(application->datashare, datashare);
856 ret = __ps_process_datashare(reader, datashare);
857 } else if (!strcmp(ASCII(node), "launch-conditions")) {
858 ret = __ps_process_launchconditions(reader, &application->launchconditions);
859 } else if (!strcmp(ASCII(node), "notification")) {
860 notification_x *notification = calloc(1, sizeof(notification_x));
861 if (notification == NULL) {
862 _LOGD("Malloc Failed\n");
865 application->notification = g_list_append(application->notification, notification);
866 ret = __ps_process_notification(reader, notification);
867 } else if (!strcmp(ASCII(node), "datacontrol")) {
868 datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
869 if (datacontrol == NULL) {
870 _LOGD("Malloc Failed\n");
873 application->datacontrol = g_list_append(application->datacontrol, datacontrol);
874 ret = __ps_process_datacontrol(reader, datacontrol);
875 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
876 ret = __ps_process_splashscreens(reader, &application->splashscreens);
880 _LOGD("Processing application failed\n");
888 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
890 _LOGD("__start_process\n");
895 depth = xmlTextReaderDepth(reader);
896 while ((ret = __next_child_element(reader, depth))) {
897 node = xmlTextReaderConstName(reader);
899 _LOGD("xmlTextReaderConstName value is NULL\n");
903 if (!strcmp(ASCII(node), "label")) {
904 label_x *label = calloc(1, sizeof(label_x));
906 _LOGD("Malloc Failed\n");
909 mfx->label = g_list_append(mfx->label, label);
910 ret = __ps_process_label(reader, label);
911 } else if (!strcmp(ASCII(node), "author")) {
912 author_x *author = calloc(1, sizeof(author_x));
913 if (author == NULL) {
914 _LOGD("Malloc Failed\n");
917 mfx->author = g_list_append(mfx->author, author);
918 ret = __ps_process_author(reader, author);
919 } else if (!strcmp(ASCII(node), "description")) {
920 description_x *description = calloc(1, sizeof(description_x));
921 if (description == NULL) {
922 _LOGD("Malloc Failed\n");
925 mfx->description = g_list_append(mfx->description, description);
926 ret = __ps_process_description(reader, description);
927 } else if (!strcmp(ASCII(node), "license")) {
928 license_x *license = calloc(1, sizeof(license_x));
929 if (license == NULL) {
930 _LOGD("Malloc Failed\n");
933 mfx->license = g_list_append(mfx->license, license);
934 ret = __ps_process_license(reader, license);
935 } else if (!strcmp(ASCII(node), "privileges")) {
936 ret = __ps_process_privileges(reader, &mfx->privileges);
937 } else if (!strcmp(ASCII(node), "ui-application")) {
938 application_x *application = calloc(1, sizeof(application_x));
939 if (application == NULL) {
940 _LOGD("Malloc Failed\n");
943 mfx->application = g_list_append(mfx->application, application);
944 ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
945 } else if (!strcmp(ASCII(node), "service-application")) {
946 application_x *application = calloc(1, sizeof(application_x));
947 if (application == NULL) {
948 _LOGD("Malloc Failed\n");
951 mfx->application = g_list_append(mfx->application, application);
952 ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
953 } else if (!strcmp(ASCII(node), "widget-application")) {
954 application_x *application = calloc(1, sizeof(application_x));
955 if (application == NULL) {
956 _LOGD("Malloc Failed\n");
959 mfx->application = g_list_append(mfx->application, application);
960 ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
961 } else if (!strcmp(ASCII(node), "watch-application")) {
962 application_x *application = calloc(1, sizeof(application_x));
963 if (application == NULL) {
964 _LOGD("Malloc Failed\n");
967 mfx->application = g_list_append(mfx->application, application);
968 ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
969 } else if (!strcmp(ASCII(node), "icon")) {
970 icon_x *icon = calloc(1, sizeof(icon_x));
972 _LOGD("Malloc Failed\n");
975 mfx->icon = g_list_append(mfx->icon, icon);
976 ret = __ps_process_icon(reader, icon, uid);
977 } else if (!strcmp(ASCII(node), "compatibility")) {
978 compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
979 if (compatibility == NULL) {
980 _LOGD("Malloc Failed\n");
983 mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
984 ret = __ps_process_compatibility(reader, compatibility);
985 } else if (!strcmp(ASCII(node), "shortcut-list")) {
987 } else if (!strcmp(ASCII(node), "livebox")) {
989 } else if (!strcmp(ASCII(node), "account")) {
991 } else if (!strcmp(ASCII(node), "notifications")) {
993 } else if (!strcmp(ASCII(node), "ime")) {
995 } else if (!strcmp(ASCII(node), "feature")) {
998 _LOGI("Unknown element: %s", ASCII(node));
1003 _LOGD("Processing manifest failed\n");
1010 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1012 const xmlChar *node;
1015 if ((ret = __next_child_element(reader, -1))) {
1016 node = xmlTextReaderConstName(reader);
1018 _LOGD("xmlTextReaderConstName value is NULL\n");
1022 if (!strcmp(ASCII(node), "manifest")) {
1023 __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1024 __save_xml_attribute(reader, "package", &mfx->package, NULL);
1025 retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1026 __save_xml_attribute(reader, "version", &mfx->version, NULL);
1027 __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1028 __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1029 __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1030 __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1031 __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1032 __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1033 __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1034 __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1035 __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1036 __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1037 __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1039 __save_xml_installed_time(mfx);
1040 __save_xml_root_path(mfx, uid);
1041 /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1042 __save_xml_default_value(mfx);
1044 ret = __start_process(reader, mfx, uid);
1046 _LOGD("No Manifest element found\n");
1053 DEPRECATED API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
1055 _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
1056 xmlTextReaderPtr reader;
1057 manifest_x *mfx = NULL;
1059 reader = xmlReaderForFile(manifest, NULL, 0);
1061 mfx = malloc(sizeof(manifest_x));
1063 memset(mfx, '\0', sizeof(manifest_x));
1064 if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
1065 _LOGD("Parsing Failed\n");
1066 pkgmgr_parser_free_manifest_xml(mfx);
1069 _LOGD("Parsing Success\n");
1071 _LOGD("Memory allocation error\n");
1073 xmlFreeTextReader(reader);
1075 _LOGD("Unable to create xml reader\n");
1080 DEPRECATED API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
1082 _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
1083 xmlTextReaderPtr reader;
1084 manifest_x *mfx = NULL;
1086 reader = xmlReaderForFile(manifest, NULL, 0);
1088 mfx = malloc(sizeof(manifest_x));
1090 memset(mfx, '\0', sizeof(manifest_x));
1091 if (__process_manifest(reader, mfx, uid) < 0) {
1092 _LOGD("Parsing Failed\n");
1093 pkgmgr_parser_free_manifest_xml(mfx);
1096 _LOGD("Parsing Success\n");
1098 _LOGD("Memory allocation error\n");
1100 xmlFreeTextReader(reader);
1102 _LOGD("Unable to create xml reader\n");
1107 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1110 char delims[] = "=";
1111 char *ret_result = NULL;
1118 for (tag = strdup(tagv[0]); tag != NULL; ) {
1119 ret_result = strtok_r(tag, delims, &ptr);
1120 if (ret_result != NULL) {
1121 /*check tag : preload */
1122 if (strcmp(ret_result, "preload") == 0) {
1123 ret_result = strtok_r(NULL, delims, &ptr);
1124 if (ret_result && strcmp(ret_result, "true") == 0) {
1125 free((void *)mfx->preload);
1126 mfx->preload = strdup("true");
1127 } else if (ret_result && strcmp(ret_result, "false") == 0) {
1128 free((void *)mfx->preload);
1129 mfx->preload = strdup("false");
1131 /*check tag : removable*/
1132 } else if (strcmp(ret_result, "removable") == 0) {
1133 ret_result = strtok_r(NULL, delims, &ptr);
1134 if (ret_result && strcmp(ret_result, "true") == 0) {
1135 free((void *)mfx->removable);
1136 mfx->removable = strdup("true");
1137 } else if (ret_result && strcmp(ret_result, "false") == 0) {
1138 free((void *)mfx->removable);
1139 mfx->removable = strdup("false");
1141 /*check tag : not matched*/
1143 _LOGD("tag process [%s]is not defined\n", ret_result);
1147 /*check next value*/
1148 if (tagv[++i] != NULL)
1149 tag = strdup(tagv[i]);
1151 _LOGD("tag process success...\n");
1157 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
1158 ACTION_TYPE action, const char *pkgid)
1160 int (*plugin_install) (xmlDocPtr, const char *);
1165 case ACTION_INSTALL:
1166 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
1168 case ACTION_UPGRADE:
1169 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
1171 case ACTION_UNINSTALL:
1172 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
1178 if ((plugin_install =
1179 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1180 _LOGE("can not find symbol[%s] \n", ac);
1184 ret = plugin_install(docPtr, pkgid);
1185 _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
1191 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
1194 const xmlChar *name;
1196 if (xmlTextReaderDepth(reader) != 1) {
1197 _LOGE("Node depth is not 1");
1201 if (xmlTextReaderNodeType(reader) != 1) {
1202 _LOGE("Node type is not 1");
1206 const xmlChar *value;
1207 name = xmlTextReaderConstName(reader);
1209 _LOGE("TEST TEST TES\n");
1210 name = BAD_CAST "--";
1213 value = xmlTextReaderConstValue(reader);
1214 if (value != NULL) {
1215 if (xmlStrlen(value) > 40)
1216 _LOGD(" %.40s...", value);
1218 _LOGD(" %s", value);
1221 name = xmlTextReaderConstName(reader);
1223 _LOGE("TEST TEST TES\n");
1224 name = BAD_CAST "--";
1227 xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
1228 xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
1229 if (copyDocPtr == NULL)
1231 xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
1232 if (rootElement == NULL)
1234 xmlNode *cur_node = xmlFirstElementChild(rootElement);
1235 if (cur_node == NULL)
1237 xmlNode *temp = xmlTextReaderExpand(reader);
1240 xmlNode *next_node = NULL;
1241 while (cur_node != NULL) {
1242 if ((strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
1243 (temp->line == cur_node->line)) {
1246 next_node = xmlNextElementSibling(cur_node);
1247 xmlUnlinkNode(cur_node);
1248 xmlFreeNode(cur_node);
1249 cur_node = next_node;
1252 if (cur_node == NULL)
1254 next_node = xmlNextElementSibling(cur_node);
1256 cur_node->next = NULL;
1257 next_node->prev = NULL;
1258 xmlFreeNodeList(next_node);
1259 xmlSetTreeDoc(cur_node, copyDocPtr);
1261 xmlSetTreeDoc(cur_node, copyDocPtr);
1264 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
1270 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
1272 switch (xmlTextReaderNodeType(reader)) {
1273 case XML_READER_TYPE_END_ELEMENT:
1277 case XML_READER_TYPE_ELEMENT:
1279 /* Elements without closing tag don't receive */
1280 const xmlChar *elementName =
1281 xmlTextReaderLocalName(reader);
1282 if (elementName == NULL)
1285 if (strcmp(tag, ASCII(elementName)) == 0) {
1286 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
1287 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
1298 static void __str_trim(char *input)
1300 char *trim_str = input;
1305 while (*input != 0) {
1306 if (!isspace(*input)) {
1317 static char *__get_parser_plugin(const char *type)
1319 char temp_path[1024] = { 0 };
1323 _LOGE("invalid argument\n");
1327 ret = snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so",
1328 PLUGIN_PATH_PREFIX, type);
1329 if (ret < 0 || ret > sizeof(temp_path) -1) {
1330 _LOGE("snprintf fail");
1334 return strdup(temp_path);
1337 static void *__open_lib_handle(char *tag)
1339 char *lib_path = NULL;
1340 void *lib_handle = NULL;
1342 lib_path = __get_parser_plugin(tag);
1343 retvm_if(!lib_path, NULL, "lib_path get fail");
1345 lib_handle = dlopen(lib_path, RTLD_LAZY);
1346 if (lib_handle == NULL)
1347 _LOGE("dlopen is failed lib_path[%s]", lib_path);
1354 static void __close_lib_handle(void *lib_handle)
1356 dlclose(lib_handle);
1359 static char * __get_tag_by_key(char *md_key)
1361 char *md_tag = NULL;
1363 if (md_key == NULL) {
1364 _LOGD("md_key is NULL\n");
1368 md_tag = strrchr(md_key, 47) + 1;
1371 return strdup(md_tag);
1374 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1376 int (*plugin_install) (const char *);
1380 if (process == PLUGIN_PRE_PROCESS) {
1382 case ACTION_INSTALL:
1383 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
1385 case ACTION_UPGRADE:
1386 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
1388 case ACTION_UNINSTALL:
1389 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
1394 } else if (process == PLUGIN_POST_PROCESS) {
1396 case ACTION_INSTALL:
1397 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
1399 case ACTION_UPGRADE:
1400 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
1402 case ACTION_UNINSTALL:
1403 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
1411 if ((plugin_install =
1412 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1416 ret = plugin_install(pkgid);
1420 static int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1422 xmlTextReaderPtr reader;
1426 void *lib_handle = NULL;
1427 char tag[PKG_STRING_LEN_MAX] = { 0 };
1429 fp = fopen(TAG_PARSER_LIST, "r");
1430 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1432 while (fgets(tag, sizeof(tag), fp) != NULL) {
1435 lib_handle = __open_lib_handle(tag);
1436 if (lib_handle == NULL)
1439 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1440 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1442 docPtr = xmlReadFile(filename, NULL, 0);
1443 reader = xmlReaderWalker(docPtr);
1444 if (reader != NULL) {
1445 ret = xmlTextReaderRead(reader);
1447 __process_tag(lib_handle, reader, action, tag, mfx->package);
1448 ret = xmlTextReaderRead(reader);
1450 xmlFreeTextReader(reader);
1453 _LOGD("%s : failed to parse", filename);
1455 _LOGD("Unable to open %s", filename);
1458 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1459 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1461 __close_lib_handle(lib_handle);
1463 memset(tag, 0x00, sizeof(tag));
1472 static void __metadata_parser_clear_dir_list(GList* dir_list)
1475 __metadata_t* detail = NULL;
1478 list = g_list_first(dir_list);
1480 detail = (__metadata_t *)list->data;
1483 free((void *)detail->key);
1485 free((void *)detail->value);
1488 list = g_list_next(list);
1490 g_list_free(dir_list);
1494 static char *__get_metadata_parser_plugin(const char *type)
1496 char temp_path[1024] = { 0 };
1499 _LOGE("invalid argument\n");
1503 snprintf(temp_path, sizeof(temp_path) - 1, "%smetadata/lib%s.so",
1504 PLUGIN_PATH_PREFIX, type);
1506 return strdup(temp_path);
1509 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
1510 ACTION_TYPE action, const char *pkgid, const char *appid)
1512 char *lib_path = NULL;
1513 void *lib_handle = NULL;
1514 int (*metadata_parser_plugin) (const char *, const char *, GList *);
1519 case ACTION_INSTALL:
1520 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
1522 case ACTION_UPGRADE:
1523 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
1525 case ACTION_UNINSTALL:
1526 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
1532 lib_path = __get_metadata_parser_plugin(tag);
1534 _LOGE("get %s parser fail\n", tag);
1538 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1539 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1543 if ((metadata_parser_plugin =
1544 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1545 _LOGE("can not find symbol[%s] \n", ac);
1549 ret = metadata_parser_plugin(pkgid, appid, md_list);
1551 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1553 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1559 dlclose(lib_handle);
1563 static int __run_metadata_parser_prestep(manifest_x *mfx, char *md_key, ACTION_TYPE action)
1567 char buffer[1024] = { 0, };
1570 GList *md_tmp = NULL;
1572 char *md_tag = NULL;
1574 GList *md_list = NULL;
1575 __metadata_t *md_detail = NULL;
1577 md_tag = __get_tag_by_key(md_key);
1578 if (md_tag == NULL) {
1579 _LOGD("md_tag is NULL\n");
1583 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1584 app = (application_x *)app_tmp->data;
1587 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1588 md = (metadata_x *)md_tmp->data;
1591 /* get glist of metadata key and value combination */
1592 memset(buffer, 0x00, 1024);
1593 ret = snprintf(buffer, 1024, "%s/", md_key);
1594 if (ret < 0 || ret > 1024) {
1595 _LOGD("snprintf fail\n");
1599 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
1600 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
1601 if (md_detail == NULL) {
1602 _LOGD("Memory allocation failed\n");
1606 md_detail->key = strdup(md->key);
1607 if (md_detail->key == NULL) {
1608 _LOGD("Memory allocation failed\n");
1613 md_detail->value = strdup(md->value);
1614 if (md_detail->value == NULL) {
1615 _LOGD("Memory allocation failed\n");
1616 free((void *)md_detail->key);
1621 md_list = g_list_append(md_list, (gpointer)md_detail);
1626 /* send glist to parser when tags for metadata plugin parser exist. */
1628 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
1630 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
1632 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
1634 __metadata_parser_clear_dir_list(md_list);
1643 __metadata_parser_clear_dir_list(md_list);
1650 static int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1652 fprintf(stdout, "__ps_process_metadata_parser\n");
1655 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1657 fp = fopen(METADATA_PARSER_LIST, "r");
1659 _LOGD("no preload list\n");
1663 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1665 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1676 static void __category_parser_clear_dir_list(GList* dir_list)
1679 __category_t* detail = NULL;
1682 list = g_list_first(dir_list);
1684 detail = (__category_t *)list->data;
1687 free((void *)detail->name);
1691 list = g_list_next(list);
1693 g_list_free(dir_list);
1697 static char *__get_category_parser_plugin(const char *type)
1699 char temp_path[1024] = { 0 };
1702 _LOGE("invalid argument\n");
1706 snprintf(temp_path, sizeof(temp_path) - 1, "%s/category/lib%s.so",
1707 PLUGIN_PATH_PREFIX, type);
1709 return strdup(temp_path);
1712 static int __ps_run_category_parser(GList *category_list, const char *tag,
1713 ACTION_TYPE action, const char *pkgid, const char *appid)
1715 char *lib_path = NULL;
1716 void *lib_handle = NULL;
1717 int (*category_parser_plugin) (const char *, const char *, GList *);
1722 case ACTION_INSTALL:
1723 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
1725 case ACTION_UPGRADE:
1726 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
1728 case ACTION_UNINSTALL:
1729 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
1735 lib_path = __get_category_parser_plugin(tag);
1737 _LOGE("get %s parser fail\n", tag);
1741 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1742 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1746 if ((category_parser_plugin =
1747 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1748 _LOGE("can not find symbol[%s] \n", ac);
1752 ret = category_parser_plugin(pkgid, appid, category_list);
1754 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1756 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1762 dlclose(lib_handle);
1766 static int __run_category_parser_prestep(manifest_x *mfx, char *category_key, ACTION_TYPE action)
1770 char buffer[1024] = { 0, };
1773 GList *category_tmp;
1774 const char *category;
1775 char *category_tag = NULL;
1777 GList *category_list = NULL;
1778 __category_t *category_detail = NULL;
1780 category_tag = __get_tag_by_key(category_key);
1781 if (category_tag == NULL) {
1782 _LOGD("md_tag is NULL\n");
1786 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1787 app = (application_x *)app_tmp->data;
1790 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
1791 category = (const char *)category_tmp->data;
1792 /* get glist of category key and value combination */
1793 memset(buffer, 0x00, 1024);
1794 ret = snprintf(buffer, 1024, "%s/", category_key);
1795 if (ret < 0 || ret > 1024) {
1796 _LOGD("snprintf fail\n");
1800 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
1801 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
1802 if (category_detail == NULL) {
1803 _LOGD("Memory allocation failed\n");
1807 category_detail->name = strdup(category);
1808 if (category_detail->name == NULL) {
1809 _LOGD("Memory allocation failed\n");
1810 free(category_detail);
1814 category_list = g_list_append(category_list, (gpointer)category_detail);
1819 /* send glist to parser when tags for metadata plugin parser exist. */
1821 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
1823 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
1825 _LOGD("category_parser success for tag[%s]\n", category_tag);
1827 __category_parser_clear_dir_list(category_list);
1828 category_list = NULL;
1836 __category_parser_clear_dir_list(category_list);
1843 static int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1847 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1849 fp = fopen(CATEGORY_PARSER_LIST, "r");
1851 _LOGD("no category parser list\n");
1855 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1856 __str_trim(category_key);
1857 ret = __run_category_parser_prestep(mfx, category_key, action);
1868 DEPRECATED API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
1870 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1871 _LOGD("parsing manifest for installation: %s\n", manifest);
1873 manifest_x *mfx = NULL;
1877 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1878 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1880 _LOGD("Parsing Finished\n");
1882 __ps_process_tag(mfx, tagv);
1884 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
1885 if (ret == PMINFO_R_ERROR) {
1886 _LOGE("DB Insert failed");
1887 pkgmgr_parser_free_manifest_xml(mfx);
1888 return PMINFO_R_ERROR;
1891 _LOGD("DB Insert Success\n");
1893 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1894 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1896 _LOGD("Creating metadata parser failed\n");
1898 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1900 _LOGD("Creating category parser failed\n");
1902 pkgmgr_parser_free_manifest_xml(mfx);
1903 _LOGD("Free Done\n");
1909 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
1911 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1912 _LOGD("parsing manifest for installation: %s\n", manifest);
1913 manifest_x *mfx = NULL;
1917 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
1918 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1920 _LOGD("Parsing Finished\n");
1922 __ps_process_tag(mfx, tagv);
1924 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
1925 if (ret == PMINFO_R_ERROR) {
1926 _LOGE("DB Insert failed");
1927 pkgmgr_parser_free_manifest_xml(mfx);
1928 return PMINFO_R_ERROR;
1931 _LOGD("DB Insert Success\n");
1933 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1934 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1936 _LOGD("Creating metadata parser failed\n");
1937 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1939 _LOGD("Creating category parser failed\n");
1941 pkgmgr_parser_free_manifest_xml(mfx);
1942 _LOGD("Free Done\n");
1948 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1950 if (!strstr(manifest, getUserManifestPath(uid,
1951 strcmp(mfx->preload, "true") == 0))) {
1952 /* if downloaded app is updated, then update tag set true*/
1954 free((void *)mfx->update);
1955 mfx->update = strdup("true");
1961 DEPRECATED API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
1963 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1964 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
1965 manifest_x *mfx = NULL;
1967 bool preload = false;
1968 bool system = false;
1969 char *csc_path = NULL;
1970 pkgmgrinfo_pkginfo_h handle = NULL;
1973 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1974 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1976 _LOGD("Parsing Finished\n");
1977 __check_preload_updated(mfx, manifest, GLOBAL_USER);
1979 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
1980 if (ret != PMINFO_R_OK)
1981 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
1982 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
1983 if (ret != PMINFO_R_OK)
1984 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
1987 free((void *)mfx->preload);
1988 mfx->preload = strdup("true");
1991 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
1992 if (ret != PMINFO_R_OK)
1993 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
1995 free((void *)mfx->system);
1996 mfx->system = strdup("true");
1999 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2000 if (ret != PMINFO_R_OK)
2001 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2003 if (csc_path != NULL) {
2005 free((void *)mfx->csc_path);
2006 mfx->csc_path = strdup(csc_path);
2009 /*Delete from cert table*/
2010 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2011 if (ret != PMINFO_R_OK) {
2012 _LOGD("Cert Info DB Delete Failed\n");
2013 pkgmgr_parser_free_manifest_xml(mfx);
2014 return PMINFO_R_ERROR;
2017 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2018 if (ret != PMINFO_R_OK) {
2019 _LOGD("DB Insert failed\n");
2020 pkgmgr_parser_free_manifest_xml(mfx);
2021 return PMINFO_R_ERROR;
2024 _LOGD("DB Update Success\n");
2026 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2027 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2029 _LOGD("Upgrade metadata parser failed\n");
2030 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2032 _LOGD("Creating category parser failed\n");
2033 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2034 pkgmgr_parser_free_manifest_xml(mfx);
2035 _LOGD("Free Done\n");
2041 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2043 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2044 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2045 manifest_x *mfx = NULL;
2047 bool preload = false;
2048 bool system = false;
2049 char *csc_path = NULL;
2050 pkgmgrinfo_pkginfo_h handle = NULL;
2053 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2054 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2056 _LOGD("Parsing Finished\n");
2057 __check_preload_updated(mfx, manifest, uid);
2059 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2060 if (ret != PMINFO_R_OK)
2061 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2062 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2063 if (ret != PMINFO_R_OK)
2064 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2067 free((void *)mfx->preload);
2068 mfx->preload = strdup("true");
2071 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2072 if (ret != PMINFO_R_OK)
2073 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2076 free((void *)mfx->system);
2077 mfx->system = strdup("true");
2080 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2081 if (ret != PMINFO_R_OK)
2082 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2083 if (csc_path != NULL) {
2085 free((void *)mfx->csc_path);
2086 mfx->csc_path = strdup(csc_path);
2089 /*Delete from cert table*/
2090 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2091 if (ret != PMINFO_R_OK) {
2092 _LOGD("Cert Info DB Delete Failed\n");
2093 pkgmgr_parser_free_manifest_xml(mfx);
2094 return PMINFO_R_ERROR;
2097 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2098 if (ret != PMINFO_R_OK) {
2099 _LOGD("DB Insert failed\n");
2100 pkgmgr_parser_free_manifest_xml(mfx);
2101 return PMINFO_R_ERROR;
2104 _LOGD("DB Update Success\n");
2106 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2107 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2109 _LOGD("Upgrade metadata parser failed\n");
2110 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2112 _LOGD("Creating category parser failed\n");
2113 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2114 pkgmgr_parser_free_manifest_xml(mfx);
2115 _LOGD("Free Done\n");
2121 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2123 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2124 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2126 manifest_x *mfx = NULL;
2129 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2130 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2132 _LOGD("Parsing Finished\n");
2134 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2136 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2138 _LOGD("Removing metadata parser failed\n");
2140 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2142 _LOGD("Creating category parser failed\n");
2144 /*Delete from cert table*/
2145 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2147 _LOGD("Cert Info DB Delete Failed\n");
2148 pkgmgr_parser_free_manifest_xml(mfx);
2152 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2154 _LOGD("DB Delete failed\n");
2156 _LOGD("DB Delete Success\n");
2158 pkgmgr_parser_free_manifest_xml(mfx);
2159 _LOGD("Free Done\n");
2165 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
2167 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
2169 void *lib_handle = NULL;
2170 int (*appsvc_operation) (const char *, uid_t);
2173 application_x *application;
2175 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
2176 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
2180 if ((appsvc_operation =
2181 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
2182 _LOGE("can not find symbol \n");
2186 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2187 application = (application_x *)tmp->data;
2188 if (application == NULL)
2190 ret = appsvc_operation(application->appid, uid);
2192 _LOGE("can not operation symbol \n");
2197 dlclose(lib_handle);
2202 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2204 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2205 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2207 manifest_x *mfx = NULL;
2210 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2211 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2213 _LOGD("Parsing Finished\n");
2215 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2217 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2219 _LOGD("Removing metadata parser failed\n");
2221 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2223 _LOGD("Creating category parser failed\n");
2225 /*Delete from cert table*/
2226 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2228 _LOGD("Cert Info DB Delete Failed\n");
2229 pkgmgr_parser_free_manifest_xml(mfx);
2233 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2235 _LOGD("DB Delete failed\n");
2237 _LOGD("DB Delete Success\n");
2239 ret = __ps_remove_appsvc_db(mfx, uid);
2241 _LOGD("Removing appsvc_db failed\n");
2243 _LOGD("Removing appsvc_db Success\n");
2245 pkgmgr_parser_free_manifest_xml(mfx);
2246 _LOGD("Free Done\n");