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) {
1233 xmlFreeDoc(copyDocPtr);
1236 xmlNode *cur_node = xmlFirstElementChild(rootElement);
1237 if (cur_node == NULL) {
1238 xmlFreeDoc(copyDocPtr);
1241 xmlNode *temp = xmlTextReaderExpand(reader);
1243 xmlFreeDoc(copyDocPtr);
1246 xmlNode *next_node = NULL;
1247 while (cur_node != NULL) {
1248 if ((strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
1249 (temp->line == cur_node->line)) {
1252 next_node = xmlNextElementSibling(cur_node);
1253 xmlUnlinkNode(cur_node);
1254 xmlFreeNode(cur_node);
1255 cur_node = next_node;
1258 if (cur_node == NULL) {
1259 xmlFreeDoc(copyDocPtr);
1262 next_node = xmlNextElementSibling(cur_node);
1264 cur_node->next = NULL;
1265 next_node->prev = NULL;
1266 xmlFreeNodeList(next_node);
1267 xmlSetTreeDoc(cur_node, copyDocPtr);
1269 xmlSetTreeDoc(cur_node, copyDocPtr);
1272 ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
1278 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
1280 xmlChar *elementName;
1282 switch (xmlTextReaderNodeType(reader)) {
1283 case XML_READER_TYPE_END_ELEMENT:
1287 case XML_READER_TYPE_ELEMENT:
1289 /* Elements without closing tag don't receive */
1290 elementName = xmlTextReaderLocalName(reader);
1291 if (elementName == NULL)
1294 if (strcmp(tag, ASCII(elementName)) == 0) {
1295 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
1296 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
1298 xmlFree(elementName);
1307 static void __str_trim(char *input)
1309 char *trim_str = input;
1314 while (*input != 0) {
1315 if (!isspace(*input)) {
1326 static char *__get_parser_plugin(const char *type)
1328 char temp_path[1024] = { 0 };
1332 _LOGE("invalid argument\n");
1336 ret = snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so",
1337 PLUGIN_PATH_PREFIX, type);
1338 if (ret < 0 || ret > sizeof(temp_path) -1) {
1339 _LOGE("snprintf fail");
1343 return strdup(temp_path);
1346 static void *__open_lib_handle(char *tag)
1348 char *lib_path = NULL;
1349 void *lib_handle = NULL;
1351 lib_path = __get_parser_plugin(tag);
1352 retvm_if(!lib_path, NULL, "lib_path get fail");
1354 lib_handle = dlopen(lib_path, RTLD_LAZY);
1355 if (lib_handle == NULL)
1356 _LOGE("dlopen is failed lib_path[%s]", lib_path);
1363 static void __close_lib_handle(void *lib_handle)
1365 dlclose(lib_handle);
1368 static char * __get_tag_by_key(char *md_key)
1370 char *md_tag = NULL;
1372 if (md_key == NULL) {
1373 _LOGD("md_key is NULL\n");
1377 md_tag = strrchr(md_key, 47) + 1;
1380 return strdup(md_tag);
1383 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1385 int (*plugin_install) (const char *);
1389 if (process == PLUGIN_PRE_PROCESS) {
1391 case ACTION_INSTALL:
1392 ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
1394 case ACTION_UPGRADE:
1395 ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
1397 case ACTION_UNINSTALL:
1398 ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
1403 } else if (process == PLUGIN_POST_PROCESS) {
1405 case ACTION_INSTALL:
1406 ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
1408 case ACTION_UPGRADE:
1409 ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
1411 case ACTION_UNINSTALL:
1412 ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
1420 if ((plugin_install =
1421 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1425 ret = plugin_install(pkgid);
1429 static int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
1431 xmlTextReaderPtr reader;
1435 void *lib_handle = NULL;
1436 char tag[PKG_STRING_LEN_MAX] = { 0 };
1438 fp = fopen(TAG_PARSER_LIST, "r");
1439 retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
1441 while (fgets(tag, sizeof(tag), fp) != NULL) {
1444 lib_handle = __open_lib_handle(tag);
1445 if (lib_handle == NULL)
1448 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
1449 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1451 docPtr = xmlReadFile(filename, NULL, 0);
1452 reader = xmlReaderWalker(docPtr);
1453 if (reader != NULL) {
1454 ret = xmlTextReaderRead(reader);
1456 __process_tag(lib_handle, reader, action, tag, mfx->package);
1457 ret = xmlTextReaderRead(reader);
1459 xmlFreeTextReader(reader);
1462 _LOGD("%s : failed to parse", filename);
1464 _LOGD("Unable to open %s", filename);
1467 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
1468 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
1470 __close_lib_handle(lib_handle);
1472 memset(tag, 0x00, sizeof(tag));
1481 static void __metadata_parser_clear_dir_list(GList* dir_list)
1484 __metadata_t* detail = NULL;
1487 list = g_list_first(dir_list);
1489 detail = (__metadata_t *)list->data;
1492 free((void *)detail->key);
1494 free((void *)detail->value);
1497 list = g_list_next(list);
1499 g_list_free(dir_list);
1503 static char *__get_metadata_parser_plugin(const char *type)
1505 char temp_path[1024] = { 0 };
1508 _LOGE("invalid argument\n");
1512 snprintf(temp_path, sizeof(temp_path) - 1, "%smetadata/lib%s.so",
1513 PLUGIN_PATH_PREFIX, type);
1515 return strdup(temp_path);
1518 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
1519 ACTION_TYPE action, const char *pkgid, const char *appid)
1521 char *lib_path = NULL;
1522 void *lib_handle = NULL;
1523 int (*metadata_parser_plugin) (const char *, const char *, GList *);
1528 case ACTION_INSTALL:
1529 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
1531 case ACTION_UPGRADE:
1532 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
1534 case ACTION_UNINSTALL:
1535 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
1541 lib_path = __get_metadata_parser_plugin(tag);
1543 _LOGE("get %s parser fail\n", tag);
1547 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1548 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1552 if ((metadata_parser_plugin =
1553 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1554 _LOGE("can not find symbol[%s] \n", ac);
1558 ret = metadata_parser_plugin(pkgid, appid, md_list);
1560 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1562 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1568 dlclose(lib_handle);
1572 static int __run_metadata_parser_prestep(manifest_x *mfx, char *md_key, ACTION_TYPE action)
1576 char buffer[1024] = { 0, };
1579 GList *md_tmp = NULL;
1581 char *md_tag = NULL;
1583 GList *md_list = NULL;
1584 __metadata_t *md_detail = NULL;
1586 md_tag = __get_tag_by_key(md_key);
1587 if (md_tag == NULL) {
1588 _LOGD("md_tag is NULL\n");
1592 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1593 app = (application_x *)app_tmp->data;
1596 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1597 md = (metadata_x *)md_tmp->data;
1600 /* get glist of metadata key and value combination */
1601 memset(buffer, 0x00, 1024);
1602 ret = snprintf(buffer, 1024, "%s/", md_key);
1603 if (ret < 0 || ret > 1024) {
1604 _LOGD("snprintf fail\n");
1608 if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
1609 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
1610 if (md_detail == NULL) {
1611 _LOGD("Memory allocation failed\n");
1615 md_detail->key = strdup(md->key);
1616 if (md_detail->key == NULL) {
1617 _LOGD("Memory allocation failed\n");
1622 md_detail->value = strdup(md->value);
1623 if (md_detail->value == NULL) {
1624 _LOGD("Memory allocation failed\n");
1625 free((void *)md_detail->key);
1630 md_list = g_list_append(md_list, (gpointer)md_detail);
1635 /* send glist to parser when tags for metadata plugin parser exist. */
1637 ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
1639 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
1641 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
1643 __metadata_parser_clear_dir_list(md_list);
1652 __metadata_parser_clear_dir_list(md_list);
1659 static int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
1661 fprintf(stdout, "__ps_process_metadata_parser\n");
1664 char md_key[PKG_STRING_LEN_MAX] = { 0 };
1666 fp = fopen(METADATA_PARSER_LIST, "r");
1668 _LOGD("no preload list\n");
1672 while (fgets(md_key, sizeof(md_key), fp) != NULL) {
1674 ret = __run_metadata_parser_prestep(mfx, md_key, action);
1685 static void __category_parser_clear_dir_list(GList* dir_list)
1688 __category_t* detail = NULL;
1691 list = g_list_first(dir_list);
1693 detail = (__category_t *)list->data;
1696 free((void *)detail->name);
1700 list = g_list_next(list);
1702 g_list_free(dir_list);
1706 static char *__get_category_parser_plugin(const char *type)
1708 char temp_path[1024] = { 0 };
1711 _LOGE("invalid argument\n");
1715 snprintf(temp_path, sizeof(temp_path) - 1, "%s/category/lib%s.so",
1716 PLUGIN_PATH_PREFIX, type);
1718 return strdup(temp_path);
1721 static int __ps_run_category_parser(GList *category_list, const char *tag,
1722 ACTION_TYPE action, const char *pkgid, const char *appid)
1724 char *lib_path = NULL;
1725 void *lib_handle = NULL;
1726 int (*category_parser_plugin) (const char *, const char *, GList *);
1731 case ACTION_INSTALL:
1732 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
1734 case ACTION_UPGRADE:
1735 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
1737 case ACTION_UNINSTALL:
1738 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
1744 lib_path = __get_category_parser_plugin(tag);
1746 _LOGE("get %s parser fail\n", tag);
1750 if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1751 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
1755 if ((category_parser_plugin =
1756 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1757 _LOGE("can not find symbol[%s] \n", ac);
1761 ret = category_parser_plugin(pkgid, appid, category_list);
1763 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
1765 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
1771 dlclose(lib_handle);
1775 static int __run_category_parser_prestep(manifest_x *mfx, char *category_key, ACTION_TYPE action)
1779 char buffer[1024] = { 0, };
1782 GList *category_tmp;
1783 const char *category;
1784 char *category_tag = NULL;
1786 GList *category_list = NULL;
1787 __category_t *category_detail = NULL;
1789 category_tag = __get_tag_by_key(category_key);
1790 if (category_tag == NULL) {
1791 _LOGD("md_tag is NULL\n");
1795 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1796 app = (application_x *)app_tmp->data;
1799 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
1800 category = (const char *)category_tmp->data;
1801 /* get glist of category key and value combination */
1802 memset(buffer, 0x00, 1024);
1803 ret = snprintf(buffer, 1024, "%s/", category_key);
1804 if (ret < 0 || ret > 1024) {
1805 _LOGD("snprintf fail\n");
1809 if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
1810 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
1811 if (category_detail == NULL) {
1812 _LOGD("Memory allocation failed\n");
1816 category_detail->name = strdup(category);
1817 if (category_detail->name == NULL) {
1818 _LOGD("Memory allocation failed\n");
1819 free(category_detail);
1823 category_list = g_list_append(category_list, (gpointer)category_detail);
1828 /* send glist to parser when tags for metadata plugin parser exist. */
1830 ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
1832 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
1834 _LOGD("category_parser success for tag[%s]\n", category_tag);
1836 __category_parser_clear_dir_list(category_list);
1837 category_list = NULL;
1845 __category_parser_clear_dir_list(category_list);
1852 static int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
1856 char category_key[PKG_STRING_LEN_MAX] = { 0 };
1858 fp = fopen(CATEGORY_PARSER_LIST, "r");
1860 _LOGD("no category parser list\n");
1864 while (fgets(category_key, sizeof(category_key), fp) != NULL) {
1865 __str_trim(category_key);
1866 ret = __run_category_parser_prestep(mfx, category_key, action);
1877 DEPRECATED API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
1879 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1880 _LOGD("parsing manifest for installation: %s\n", manifest);
1882 manifest_x *mfx = NULL;
1886 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1887 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1889 _LOGD("Parsing Finished\n");
1891 __ps_process_tag(mfx, tagv);
1893 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
1894 if (ret == PMINFO_R_ERROR) {
1895 _LOGE("DB Insert failed");
1896 pkgmgr_parser_free_manifest_xml(mfx);
1897 return PMINFO_R_ERROR;
1900 _LOGD("DB Insert Success\n");
1902 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1903 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1905 _LOGD("Creating metadata parser failed\n");
1907 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1909 _LOGD("Creating category parser failed\n");
1911 pkgmgr_parser_free_manifest_xml(mfx);
1912 _LOGD("Free Done\n");
1918 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
1920 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1921 _LOGD("parsing manifest for installation: %s\n", manifest);
1922 manifest_x *mfx = NULL;
1926 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
1927 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1929 _LOGD("Parsing Finished\n");
1931 __ps_process_tag(mfx, tagv);
1933 ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
1934 if (ret == PMINFO_R_ERROR) {
1935 _LOGE("DB Insert failed");
1936 pkgmgr_parser_free_manifest_xml(mfx);
1937 return PMINFO_R_ERROR;
1940 _LOGD("DB Insert Success\n");
1942 __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
1943 ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
1945 _LOGD("Creating metadata parser failed\n");
1946 ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
1948 _LOGD("Creating category parser failed\n");
1950 pkgmgr_parser_free_manifest_xml(mfx);
1951 _LOGD("Free Done\n");
1957 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1959 if (!strstr(manifest, getUserManifestPath(uid,
1960 strcmp(mfx->preload, "true") == 0))) {
1961 /* if downloaded app is updated, then update tag set true*/
1963 free((void *)mfx->update);
1964 mfx->update = strdup("true");
1970 DEPRECATED API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
1972 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1973 _LOGD("pkgmgr_parser_parse_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
1974 manifest_x *mfx = NULL;
1976 bool preload = false;
1977 bool system = false;
1978 char *csc_path = NULL;
1979 pkgmgrinfo_pkginfo_h handle = NULL;
1982 mfx = pkgmgr_parser_process_manifest_xml(manifest);
1983 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
1985 _LOGD("Parsing Finished\n");
1986 __check_preload_updated(mfx, manifest, GLOBAL_USER);
1988 ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
1989 if (ret != PMINFO_R_OK)
1990 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
1991 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
1992 if (ret != PMINFO_R_OK)
1993 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
1996 free((void *)mfx->preload);
1997 mfx->preload = strdup("true");
2000 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2001 if (ret != PMINFO_R_OK)
2002 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2004 free((void *)mfx->system);
2005 mfx->system = strdup("true");
2008 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2009 if (ret != PMINFO_R_OK)
2010 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2012 if (csc_path != NULL) {
2014 free((void *)mfx->csc_path);
2015 mfx->csc_path = strdup(csc_path);
2018 /*Delete from cert table*/
2019 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2020 if (ret != PMINFO_R_OK) {
2021 _LOGD("Cert Info DB Delete Failed\n");
2022 pkgmgr_parser_free_manifest_xml(mfx);
2023 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2024 return PMINFO_R_ERROR;
2027 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2028 if (ret != PMINFO_R_OK) {
2029 _LOGD("DB Insert failed\n");
2030 pkgmgr_parser_free_manifest_xml(mfx);
2031 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2032 return PMINFO_R_ERROR;
2035 _LOGD("DB Update Success\n");
2037 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2038 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2040 _LOGD("Upgrade metadata parser failed\n");
2041 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2043 _LOGD("Creating category parser failed\n");
2044 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2045 pkgmgr_parser_free_manifest_xml(mfx);
2046 _LOGD("Free Done\n");
2052 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2054 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2055 _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2056 manifest_x *mfx = NULL;
2058 bool preload = false;
2059 bool system = false;
2060 char *csc_path = NULL;
2061 pkgmgrinfo_pkginfo_h handle = NULL;
2064 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2065 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2067 _LOGD("Parsing Finished\n");
2068 __check_preload_updated(mfx, manifest, uid);
2070 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2071 if (ret != PMINFO_R_OK)
2072 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2073 ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2074 if (ret != PMINFO_R_OK)
2075 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2078 free((void *)mfx->preload);
2079 mfx->preload = strdup("true");
2082 ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2083 if (ret != PMINFO_R_OK)
2084 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2087 free((void *)mfx->system);
2088 mfx->system = strdup("true");
2091 ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2092 if (ret != PMINFO_R_OK)
2093 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2094 if (csc_path != NULL) {
2096 free((void *)mfx->csc_path);
2097 mfx->csc_path = strdup(csc_path);
2100 /*Delete from cert table*/
2101 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2102 if (ret != PMINFO_R_OK) {
2103 _LOGD("Cert Info DB Delete Failed\n");
2104 pkgmgr_parser_free_manifest_xml(mfx);
2105 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2106 return PMINFO_R_ERROR;
2109 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2110 if (ret != PMINFO_R_OK) {
2111 _LOGD("DB Insert failed\n");
2112 pkgmgr_parser_free_manifest_xml(mfx);
2113 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2114 return PMINFO_R_ERROR;
2117 _LOGD("DB Update Success\n");
2119 __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2120 ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2122 _LOGD("Upgrade metadata parser failed\n");
2123 ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2125 _LOGD("Creating category parser failed\n");
2126 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2127 pkgmgr_parser_free_manifest_xml(mfx);
2128 _LOGD("Free Done\n");
2134 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2136 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2137 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2139 manifest_x *mfx = NULL;
2142 mfx = pkgmgr_parser_process_manifest_xml(manifest);
2143 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2145 _LOGD("Parsing Finished\n");
2147 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2149 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2151 _LOGD("Removing metadata parser failed\n");
2153 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2155 _LOGD("Creating category parser failed\n");
2157 /*Delete from cert table*/
2158 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2160 _LOGD("Cert Info DB Delete Failed\n");
2161 pkgmgr_parser_free_manifest_xml(mfx);
2165 ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2167 _LOGD("DB Delete failed\n");
2169 _LOGD("DB Delete Success\n");
2171 pkgmgr_parser_free_manifest_xml(mfx);
2172 _LOGD("Free Done\n");
2178 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
2180 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
2182 void *lib_handle = NULL;
2183 int (*appsvc_operation) (const char *, uid_t);
2186 application_x *application;
2188 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
2189 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
2193 if ((appsvc_operation =
2194 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
2195 _LOGE("can not find symbol \n");
2199 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2200 application = (application_x *)tmp->data;
2201 if (application == NULL)
2203 ret = appsvc_operation(application->appid, uid);
2205 _LOGE("can not operation symbol \n");
2210 dlclose(lib_handle);
2215 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2217 retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2218 _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2220 manifest_x *mfx = NULL;
2223 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2224 retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2226 _LOGD("Parsing Finished\n");
2228 __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2230 ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2232 _LOGD("Removing metadata parser failed\n");
2234 ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2236 _LOGD("Creating category parser failed\n");
2238 /*Delete from cert table*/
2239 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2241 _LOGD("Cert Info DB Delete Failed\n");
2242 pkgmgr_parser_free_manifest_xml(mfx);
2246 ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2248 _LOGD("DB Delete failed\n");
2250 _LOGD("DB Delete Success\n");
2252 ret = __ps_remove_appsvc_db(mfx, uid);
2254 _LOGD("Removing appsvc_db failed\n");
2256 _LOGD("Removing appsvc_db Success\n");
2258 pkgmgr_parser_free_manifest_xml(mfx);
2259 _LOGD("Free Done\n");