1d96d0d36a5fbe14f296c6b995b35b9b4a4e4881
[platform/core/appfw/pkgmgr-info.git] / parser / pkgmgr_parser.c
1 /*
2  * pkgmgr-info
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22 #define _GNU_SOURCE
23 #include <dlfcn.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <unistd.h>
28 #include <ctype.h>
29 #include <time.h>
30 #include <string.h>
31 #include <libxml/parser.h>
32 #include <libxml/xmlreader.h>
33 #include <libxml/xmlschemas.h>
34 #include <vconf.h>
35 #include <glib.h>
36 #include <grp.h>
37
38 #include "pkgmgr-info.h"
39 #include "pkgmgrinfo_basic.h"
40 #include "pkgmgrinfo_debug.h"
41
42 #include "pkgmgr_parser.h"
43 #include "pkgmgr_parser_internal.h"
44 #include "pkgmgr_parser_db.h"
45
46 #ifdef LOG_TAG
47 #undef LOG_TAG
48 #endif
49 #define LOG_TAG "PKGMGR_PARSER"
50
51 #define ASCII(s) (char *)s
52 #define XMLCHAR(s) (const xmlChar *)s
53
54 #define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/mdparser_list.txt"
55 #define METADATA_PARSER_NAME    "metadataparser:"
56
57 #define CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
58 #define CATEGORY_PARSER_NAME    "categoryparser:"
59
60 #define TAG_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/tag_parser_list.txt"
61 #define TAG_PARSER_NAME "parserlib:"
62
63 #define PKG_TAG_LEN_MAX 128
64 #define OWNER_ROOT 0
65 #define BUFSIZE 4096
66 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
67
68 /* plugin process_type */
69 typedef enum {
70         PLUGIN_PRE_PROCESS = 0,
71         PLUGIN_POST_PROCESS
72 } PLUGIN_PROCESS_TYPE;
73
74 const char *package;
75
76 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label);
77 static int __ps_process_privilege(xmlTextReaderPtr reader, char **privilege);
78 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges);
79 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed);
80 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition);
81 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
82 static int __ps_process_category(xmlTextReaderPtr reader, char **category);
83 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
84 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
85 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
86 static int __ps_process_request(xmlTextReaderPtr reader, char **request);
87 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
88 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions);
89 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
90 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
91 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
92 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
93 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
94 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol);
95 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
96 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid);
97 static int __next_child_element(xmlTextReaderPtr reader, int depth);
98 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
99 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
100 static void __str_trim(char *input);
101 static char *__get_parser_plugin(const char *type);
102 API int __is_admin();
103
104 static void __save_xml_attribute(xmlTextReaderPtr reader, char *attribute, char **xml_attribute, char *default_value)
105 {
106         xmlChar *attrib_val = xmlTextReaderGetAttribute(reader, XMLCHAR(attribute));
107         if (attrib_val) {
108                 *xml_attribute = strdup((const char *)attrib_val);
109                 xmlFree(attrib_val);
110         } else {
111                 if (default_value != NULL)
112                         *xml_attribute = strdup(default_value);
113         }
114 }
115
116 static void __save_xml_lang(xmlTextReaderPtr reader, char **xml_attribute)
117 {
118         const xmlChar *attrib_val = xmlTextReaderConstXmlLang(reader);
119         if (attrib_val != NULL)
120                 *xml_attribute = strdup(ASCII(attrib_val));
121         else
122                 *xml_attribute = strdup(DEFAULT_LOCALE);
123 }
124
125 static void __save_xml_value(xmlTextReaderPtr reader, char **xml_attribute)
126 {
127         xmlTextReaderRead(reader);
128         const xmlChar *attrib_val = xmlTextReaderConstValue(reader);
129
130         if (attrib_val)
131                 *xml_attribute = strdup((const char *)attrib_val);
132 }
133
134 static void __save_xml_installed_time(manifest_x *mfx)
135 {
136         char buf[PKG_STRING_LEN_MAX] = {'\0'};
137         char *val = NULL;
138         time_t current_time;
139         time(&current_time);
140         snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", (int)current_time);
141         val = strndup(buf, PKG_STRING_LEN_MAX - 1);
142         mfx->installed_time = val;
143 }
144
145 static void __save_xml_root_path(manifest_x *mfx, uid_t uid)
146 {
147         char root[PKG_STRING_LEN_MAX] = { '\0' };
148         const char *path;
149
150         if (mfx->root_path)
151                 return;
152
153         tzplatform_set_user(uid);
154         path = tzplatform_getenv((uid == OWNER_ROOT || uid == GLOBAL_USER) ? TZ_SYS_RO_APP : TZ_USER_APP);
155         snprintf(root, PKG_STRING_LEN_MAX - 1, "%s/%s", path, mfx->package);
156
157         mfx->root_path = strdup(root);
158
159         tzplatform_reset_user();
160 }
161
162 static void __save_xml_default_value(manifest_x * mfx)
163 {
164         mfx->preload = strdup("False");
165         mfx->removable = strdup("True");
166         mfx->readonly = strdup("False");
167         mfx->update = strdup("False");
168         mfx->system = strdup("False");
169         mfx->installed_storage = strdup("installed_internal");
170         package = mfx->package;
171 }
172
173 void *__open_lib_handle(char *tag)
174 {
175         char *lib_path = NULL;
176         void *lib_handle = NULL;
177
178         lib_path = __get_parser_plugin(tag);
179         retvm_if(!lib_path, NULL, "lib_path get fail");
180
181         lib_handle = dlopen(lib_path, RTLD_LAZY);
182         retvm_if(lib_handle == NULL, NULL, "dlopen is failed lib_path[%s]", lib_path);
183
184         return lib_handle;
185 }
186
187 void __close_lib_handle(void *lib_handle)
188 {
189         dlclose(lib_handle);
190 }
191
192 static void __str_trim(char *input)
193 {
194         char *trim_str = input;
195
196         if (input == NULL)
197                 return;
198
199         while (*input != 0) {
200                 if (!isspace(*input)) {
201                         *trim_str = *input;
202                         trim_str++;
203                 }
204                 input++;
205         }
206
207         *trim_str = 0;
208         return;
209 }
210
211 API int __is_admin()
212 {
213         uid_t uid = getuid();
214         if ((uid_t)0 == uid)
215                 return 1;
216         else
217                 return 0;
218 }
219
220
221
222 static char * __get_tag_by_key(char *md_key)
223 {
224         char *md_tag = NULL;
225
226         if (md_key == NULL) {
227                 _LOGD("md_key is NULL\n");
228                 return NULL;
229         }
230
231         md_tag = strrchr(md_key, 47) + 1;
232
233
234         return strdup(md_tag);
235 }
236
237 static char *__get_metadata_parser_plugin(const char *type)
238 {
239         FILE *fp = NULL;
240         char buffer[1024] = { 0 };
241         char temp_path[1024] = { 0 };
242         char *path = NULL;
243
244         if (type == NULL) {
245                 _LOGE("invalid argument\n");
246                 return NULL;
247         }
248
249         fp = fopen(PKG_PARSER_CONF_PATH, "r");
250         if (fp == NULL) {
251                 _LOGE("no matching metadata parser\n");
252                 return NULL;
253         }
254
255         while (fgets(buffer, sizeof(buffer), fp) != NULL) {
256                 if (buffer[0] == '#')
257                         continue;
258
259                 __str_trim(buffer);
260
261                 if ((path = strstr(buffer, METADATA_PARSER_NAME)) != NULL) {
262                         path = path + strlen(METADATA_PARSER_NAME);
263
264                         break;
265                 }
266
267                 memset(buffer, 0x00, 1024);
268         }
269
270         if (fp != NULL)
271                 fclose(fp);
272
273         if (path == NULL) {
274                 _LOGE("no matching [%s] [%s]\n", METADATA_PARSER_NAME, type);
275                 return NULL;
276         }
277
278         snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
279
280         return strdup(temp_path);
281 }
282
283 static char *__get_category_parser_plugin(const char *type)
284 {
285         FILE *fp = NULL;
286         char buffer[1024] = { 0 };
287         char temp_path[1024] = { 0 };
288         char *path = NULL;
289
290         if (type == NULL) {
291                 _LOGE("invalid argument\n");
292                 return NULL;
293         }
294
295         fp = fopen(PKG_PARSER_CONF_PATH, "r");
296         if (fp == NULL) {
297                 _LOGE("no matching metadata parser\n");
298                 return NULL;
299         }
300
301         while (fgets(buffer, sizeof(buffer), fp) != NULL) {
302                 if (buffer[0] == '#')
303                         continue;
304
305                 __str_trim(buffer);
306
307                 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
308                         path = path + strlen(CATEGORY_PARSER_NAME);
309
310                         break;
311                 }
312
313                 memset(buffer, 0x00, 1024);
314         }
315
316         if (fp != NULL)
317                 fclose(fp);
318
319         if (path == NULL) {
320                 _LOGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME, type);
321                 return NULL;
322         }
323
324         snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
325
326         return strdup(temp_path);
327 }
328
329 static char *__get_parser_plugin(const char *type)
330 {
331         FILE *fp = NULL;
332         char buffer[1024] = { 0 };
333         char temp_path[1024] = { 0 };
334         char *path = NULL;
335
336         if (type == NULL) {
337                 _LOGE("invalid argument\n");
338                 return NULL;
339         }
340
341         fp = fopen(PKG_PARSER_CONF_PATH, "r");
342         if (fp == NULL) {
343                 _LOGE("no matching backendlib\n");
344                 return NULL;
345         }
346
347         while (fgets(buffer, sizeof(buffer), fp) != NULL) {
348                 if (buffer[0] == '#')
349                         continue;
350
351                 __str_trim(buffer);
352
353                 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
354                         path = path + strlen(PKG_PARSERLIB);
355                         break;
356                 }
357
358                 memset(buffer, 0x00, 1024);
359         }
360
361         if (fp != NULL)
362                 fclose(fp);
363
364         if (path == NULL) {
365                 _LOGE("no matching backendlib\n");
366                 return NULL;
367         }
368
369         snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
370
371         return strdup(temp_path);
372 }
373
374 static int __ps_run_tag_parser(void *lib_handle, xmlDocPtr docPtr, const char *tag,
375                            ACTION_TYPE action, const char *pkgid)
376 {
377         int (*plugin_install) (xmlDocPtr, const char *);
378         int ret = -1;
379         char *ac = NULL;
380
381         switch (action) {
382         case ACTION_INSTALL:
383                 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
384                 break;
385         case ACTION_UPGRADE:
386                 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
387                 break;
388         case ACTION_UNINSTALL:
389                 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
390                 break;
391         default:
392                 goto END;
393         }
394
395         if ((plugin_install =
396                 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
397                 _LOGE("can not find symbol[%s] \n", ac);
398                 goto END;
399         }
400
401         ret = plugin_install(docPtr, pkgid);
402         _LOGD("tag parser[%s, %s] ACTION_TYPE[%d] result[%d]\n", pkgid, tag, action, ret);
403
404 END:
405         return ret;
406 }
407
408 static int __ps_run_metadata_parser(GList *md_list, const char *tag,
409                                 ACTION_TYPE action, const char *pkgid, const char *appid)
410 {
411         char *lib_path = NULL;
412         void *lib_handle = NULL;
413         int (*metadata_parser_plugin) (const char *, const char *, GList *);
414         int ret = -1;
415         char *ac = NULL;
416
417         switch (action) {
418         case ACTION_INSTALL:
419                 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
420                 break;
421         case ACTION_UPGRADE:
422                 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
423                 break;
424         case ACTION_UNINSTALL:
425                 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
426                 break;
427         default:
428                 goto END;
429         }
430
431         lib_path = __get_metadata_parser_plugin(tag);
432         if (!lib_path) {
433                 _LOGE("get %s parser fail\n", tag);
434                 goto END;
435         }
436
437         if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
438                 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
439                 goto END;
440         }
441
442         if ((metadata_parser_plugin =
443                 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
444                 _LOGE("can not find symbol[%s] \n", ac);
445                 goto END;
446         }
447
448         ret = metadata_parser_plugin(pkgid, appid, md_list);
449         if (ret < 0)
450                 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
451         else
452                 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
453
454 END:
455         if (lib_path)
456                 free(lib_path);
457         if (lib_handle)
458                 dlclose(lib_handle);
459         return ret;
460 }
461
462 static int __ps_run_category_parser(GList *category_list, const char *tag,
463                                 ACTION_TYPE action, const char *pkgid, const char *appid)
464 {
465         char *lib_path = NULL;
466         void *lib_handle = NULL;
467         int (*category_parser_plugin) (const char *, const char *, GList *);
468         int ret = -1;
469         char *ac = NULL;
470
471         switch (action) {
472         case ACTION_INSTALL:
473                 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
474                 break;
475         case ACTION_UPGRADE:
476                 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
477                 break;
478         case ACTION_UNINSTALL:
479                 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
480                 break;
481         default:
482                 goto END;
483         }
484
485         lib_path = __get_category_parser_plugin(tag);
486         if (!lib_path) {
487                 _LOGE("get %s parser fail\n", tag);
488                 goto END;
489         }
490
491         if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
492                 _LOGE("dlopen is failed lib_path[%s]\n", lib_path);
493                 goto END;
494         }
495
496         if ((category_parser_plugin =
497                 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
498                 _LOGE("can not find symbol[%s] \n", ac);
499                 goto END;
500         }
501
502         ret = category_parser_plugin(pkgid, appid, category_list);
503         if (ret < 0)
504                 _LOGD("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
505         else
506                 _LOGD("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
507
508 END:
509         if (lib_path)
510                 free(lib_path);
511         if (lib_handle)
512                 dlclose(lib_handle);
513         return ret;
514 }
515
516 static void __metadata_parser_clear_dir_list(GList* dir_list)
517 {
518         GList *list = NULL;
519         __metadata_t* detail = NULL;
520
521         if (dir_list) {
522                 list = g_list_first(dir_list);
523                 while (list) {
524                         detail = (__metadata_t *)list->data;
525                         if (detail) {
526                                 if (detail->key)
527                                         free((void *)detail->key);
528                                 if (detail->value)
529                                         free((void *)detail->value);
530                                 free(detail);
531                         }
532                         list = g_list_next(list);
533                 }
534                 g_list_free(dir_list);
535         }
536 }
537
538 static void __category_parser_clear_dir_list(GList* dir_list)
539 {
540         GList *list = NULL;
541         __category_t* detail = NULL;
542
543         if (dir_list) {
544                 list = g_list_first(dir_list);
545                 while (list) {
546                         detail = (__category_t *)list->data;
547                         if (detail) {
548                                 if (detail->name)
549                                         free((void *)detail->name);
550
551                                 free(detail);
552                         }
553                         list = g_list_next(list);
554                 }
555                 g_list_free(dir_list);
556         }
557 }
558
559 static int __run_tag_parser_prestep(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
560 {
561         int ret = -1;
562         const xmlChar *name;
563
564         if (xmlTextReaderDepth(reader) != 1) {
565                 _LOGE("Node depth is not 1");
566                 goto END;
567         }
568
569         if (xmlTextReaderNodeType(reader) != 1) {
570                 _LOGE("Node type is not 1");
571                 goto END;
572         }
573
574         const xmlChar *value;
575         name = xmlTextReaderConstName(reader);
576         if (name == NULL) {
577                 _LOGE("TEST TEST TES\n");
578                 name = BAD_CAST "--";
579         }
580
581         value = xmlTextReaderConstValue(reader);
582         if (value != NULL) {
583                 if (xmlStrlen(value) > 40)
584                         _LOGD(" %.40s...", value);
585                 else
586                         _LOGD(" %s", value);
587         }
588
589         name = xmlTextReaderConstName(reader);
590         if (name == NULL) {
591                 _LOGE("TEST TEST TES\n");
592                 name = BAD_CAST "--";
593         }
594
595         xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
596         xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
597         if (copyDocPtr == NULL)
598                 return -1;
599         xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
600         if (rootElement == NULL)
601                 return -1;
602         xmlNode *cur_node = xmlFirstElementChild(rootElement);
603         if (cur_node == NULL)
604                 return -1;
605         xmlNode *temp = xmlTextReaderExpand(reader);
606         if (temp == NULL)
607                 return -1;
608         xmlNode *next_node = NULL;
609         while (cur_node != NULL) {
610                 if ((strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
611                         (temp->line == cur_node->line)) {
612                         break;
613                 } else {
614                         next_node = xmlNextElementSibling(cur_node);
615                         xmlUnlinkNode(cur_node);
616                         xmlFreeNode(cur_node);
617                         cur_node = next_node;
618                 }
619         }
620         if (cur_node == NULL)
621                 return -1;
622         next_node = xmlNextElementSibling(cur_node);
623         if (next_node) {
624                 cur_node->next = NULL;
625                 next_node->prev = NULL;
626                 xmlFreeNodeList(next_node);
627                 xmlSetTreeDoc(cur_node, copyDocPtr);
628         } else {
629                 xmlSetTreeDoc(cur_node, copyDocPtr);
630         }
631
632         ret = __ps_run_tag_parser(lib_handle, copyDocPtr, ASCII(name), action, pkgid);
633  END:
634
635         return ret;
636 }
637
638 static int __run_metadata_parser_prestep(manifest_x *mfx, char *md_key, ACTION_TYPE action)
639 {
640         int ret = -1;
641         int tag_exist = 0;
642         char buffer[1024] = { 0, };
643         GList *app_tmp;
644         application_x *app;
645         GList *md_tmp = NULL;
646         metadata_x *md;
647         char *md_tag = NULL;
648
649         GList *md_list = NULL;
650         __metadata_t *md_detail = NULL;
651
652         md_tag = __get_tag_by_key(md_key);
653         if (md_tag == NULL) {
654                 _LOGD("md_tag is NULL\n");
655                 return -1;
656         }
657
658         for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
659                 app = (application_x *)app_tmp->data;
660                 if (app == NULL)
661                         continue;
662                 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
663                         md = (metadata_x *)md_tmp->data;
664                         if (md == NULL)
665                                 continue;
666                         /* get glist of metadata key and value combination */
667                         memset(buffer, 0x00, 1024);
668                         snprintf(buffer, 1024, "%s/", md_key);
669                         if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
670                                 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
671                                 if (md_detail == NULL) {
672                                         _LOGD("Memory allocation failed\n");
673                                         goto END;
674                                 }
675
676                                 md_detail->key = strdup(md->key);
677                                 if (md_detail->key == NULL) {
678                                         _LOGD("Memory allocation failed\n");
679                                         free(md_detail);
680                                         goto END;
681                                 }
682
683                                 md_detail->value = strdup(md->value);
684                                 if (md_detail->value == NULL) {
685                                         _LOGD("Memory allocation failed\n");
686                                         free((void *)md_detail->key);
687                                         free(md_detail);
688                                         goto END;
689                                 }
690
691                                 md_list = g_list_append(md_list, (gpointer)md_detail);
692                                 tag_exist = 1;
693                         }
694                 }
695
696                 /* send glist to parser when tags for metadata plugin parser exist. */
697                 if (tag_exist) {
698                         ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, app->appid);
699                         if (ret < 0)
700                                 _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
701                         else
702                                 _LOGD("metadata_parser success for tag[%s]\n", md_tag);
703                 }
704                 __metadata_parser_clear_dir_list(md_list);
705                 md_list = NULL;
706                 tag_exist = 0;
707         }
708
709         return 0;
710 END:
711         __metadata_parser_clear_dir_list(md_list);
712
713         if (md_tag)
714                 free(md_tag);
715
716         return ret;
717 }
718
719 static int __run_category_parser_prestep(manifest_x *mfx, char *category_key, ACTION_TYPE action)
720 {
721         int ret = -1;
722         int tag_exist = 0;
723         char buffer[1024] = { 0, };
724         GList *app_tmp;
725         application_x *app;
726         GList *category_tmp;
727         const char *category;
728         char *category_tag = NULL;
729
730         GList *category_list = NULL;
731         __category_t *category_detail = NULL;
732
733         category_tag = __get_tag_by_key(category_key);
734         if (category_tag == NULL) {
735                 _LOGD("md_tag is NULL\n");
736                 return -1;
737         }
738
739         for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
740                 app = (application_x *)app_tmp->data;
741                 if (app == NULL)
742                         continue;
743                 for (category_tmp = app->category; category_tmp; category_tmp = category_tmp->next) {
744                         category = (const char *)category_tmp->data;
745                         /* get glist of category key and value combination */
746                         memset(buffer, 0x00, 1024);
747                         snprintf(buffer, 1024, "%s/", category_key);
748                         if ((category) && (strncmp(category, category_key, strlen(category_key)) == 0)) {
749                                 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
750                                 if (category_detail == NULL) {
751                                         _LOGD("Memory allocation failed\n");
752                                         goto END;
753                                 }
754
755                                 category_detail->name = strdup(category);
756                                 if (category_detail->name == NULL) {
757                                         _LOGD("Memory allocation failed\n");
758                                         free(category_detail);
759                                         goto END;
760                                 }
761
762                                 category_list = g_list_append(category_list, (gpointer)category_detail);
763                                 tag_exist = 1;
764                         }
765                 }
766
767                 /* send glist to parser when tags for metadata plugin parser exist. */
768                 if (tag_exist) {
769                         ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, app->appid);
770                         if (ret < 0)
771                                 _LOGD("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
772                         else
773                                 _LOGD("category_parser success for tag[%s]\n", category_tag);
774                 }
775                 __category_parser_clear_dir_list(category_list);
776                 category_list = NULL;
777                 tag_exist = 0;
778         }
779
780         return 0;
781 END:
782         __category_parser_clear_dir_list(category_list);
783
784         if (category_tag)
785                 free(category_tag);
786
787         return ret;
788 }
789
790 static void __process_tag(void *lib_handle, xmlTextReaderPtr reader, ACTION_TYPE action, char *tag, const char *pkgid)
791 {
792         switch (xmlTextReaderNodeType(reader)) {
793         case XML_READER_TYPE_END_ELEMENT:
794                 {
795                         break;
796                 }
797         case XML_READER_TYPE_ELEMENT:
798                 {
799                         /* Elements without closing tag don't receive */
800                         const xmlChar *elementName =
801                             xmlTextReaderLocalName(reader);
802                         if (elementName == NULL)
803                                 break;
804
805                         if (strcmp(tag, ASCII(elementName)) == 0) {
806                                 _LOGD("find : tag[%s] ACTION_TYPE[%d] pkg[%s]\n", tag, action, pkgid);
807                                 __run_tag_parser_prestep(lib_handle, reader, action, pkgid);
808                                 break;
809                         }
810                         break;
811                 }
812
813         default:
814                 break;
815         }
816 }
817
818 static int __parser_send_tag(void *lib_handle, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
819 {
820         int (*plugin_install) (const char *);
821         int ret = -1;
822         char *ac = NULL;
823
824         if (process == PLUGIN_PRE_PROCESS) {
825                 switch (action) {
826                 case ACTION_INSTALL:
827                         ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
828                         break;
829                 case ACTION_UPGRADE:
830                         ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
831                         break;
832                 case ACTION_UNINSTALL:
833                         ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
834                         break;
835                 default:
836                         return -1;
837                 }
838         } else if (process == PLUGIN_POST_PROCESS) {
839                 switch (action) {
840                 case ACTION_INSTALL:
841                         ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
842                         break;
843                 case ACTION_UPGRADE:
844                         ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
845                         break;
846                 case ACTION_UNINSTALL:
847                         ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
848                         break;
849                 default:
850                         return -1;
851                 }
852         } else
853                 return -1;
854
855         if ((plugin_install =
856                 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
857                 return -1;
858         }
859
860         ret = plugin_install(pkgid);
861         return ret;
862 }
863
864 static int __next_child_element(xmlTextReaderPtr reader, int depth)
865 {
866         int ret = xmlTextReaderRead(reader);
867         int cur = xmlTextReaderDepth(reader);
868         while (ret == 1) {
869
870                 switch (xmlTextReaderNodeType(reader)) {
871                 case XML_READER_TYPE_ELEMENT:
872                         if (cur == depth + 1)
873                                 return 1;
874                         break;
875                 case XML_READER_TYPE_TEXT:
876                         /*text is handled by each function separately*/
877                         if (cur == depth + 1)
878                                 return 0;
879                         break;
880                 case XML_READER_TYPE_END_ELEMENT:
881                         if (cur == depth)
882                                 return 0;
883                         break;
884                 default:
885                         if (cur <= depth)
886                                 return 0;
887                         break;
888                 }
889                 ret = xmlTextReaderRead(reader);
890                 cur = xmlTextReaderDepth(reader);
891         }
892         return ret;
893 }
894 int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE action)
895 {
896         xmlTextReaderPtr reader;
897         xmlDocPtr docPtr;
898         int ret = -1;
899         FILE *fp = NULL;
900         void *lib_handle = NULL;
901         char tag[PKG_STRING_LEN_MAX] = { 0 };
902
903         fp = fopen(TAG_PARSER_LIST, "r");
904         retvm_if(fp == NULL, PMINFO_R_ERROR, "no preload list");
905
906         while (fgets(tag, sizeof(tag), fp) != NULL) {
907                 __str_trim(tag);
908
909                 lib_handle = __open_lib_handle(tag);
910                 if (lib_handle == NULL)
911                         continue;
912
913                 ret = __parser_send_tag(lib_handle, action, PLUGIN_PRE_PROCESS, mfx->package);
914                 _LOGD("PLUGIN_PRE_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
915
916                 docPtr = xmlReadFile(filename, NULL, 0);
917                 reader = xmlReaderWalker(docPtr);
918                 if (reader != NULL) {
919                         ret = xmlTextReaderRead(reader);
920                         while (ret == 1) {
921                                 __process_tag(lib_handle, reader, action, tag, mfx->package);
922                                 ret = xmlTextReaderRead(reader);
923                         }
924                         xmlFreeTextReader(reader);
925
926                         if (ret != 0)
927                                 _LOGD("%s : failed to parse", filename);
928                 } else {
929                         _LOGD("Unable to open %s", filename);
930                 }
931
932                 ret = __parser_send_tag(lib_handle, action, PLUGIN_POST_PROCESS, mfx->package);
933                 _LOGD("PLUGIN_POST_PROCESS[%s, %s] ACTION_TYPE[%d] result[%d]\n", mfx->package, tag, action, ret);
934
935                 __close_lib_handle(lib_handle);
936
937                 memset(tag, 0x00, sizeof(tag));
938         }
939
940         if (fp != NULL)
941                 fclose(fp);
942
943         return 0;
944 }
945
946 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
947 {
948         fprintf(stdout, "__ps_process_metadata_parser\n");
949         int ret = 0;
950         FILE *fp = NULL;
951         char md_key[PKG_STRING_LEN_MAX] = { 0 };
952
953         fp = fopen(METADATA_PARSER_LIST, "r");
954         if (fp == NULL) {
955                 _LOGD("no preload list\n");
956                 return -1;
957         }
958
959         while (fgets(md_key, sizeof(md_key), fp) != NULL) {
960                 __str_trim(md_key);
961                 ret = __run_metadata_parser_prestep(mfx, md_key, action);
962                 if (ret < 0)
963                         break;
964         }
965
966         if (fp != NULL)
967                 fclose(fp);
968
969         return ret;
970 }
971
972 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
973 {
974         int ret = 0;
975         FILE *fp = NULL;
976         char category_key[PKG_STRING_LEN_MAX] = { 0 };
977
978         fp = fopen(CATEGORY_PARSER_LIST, "r");
979         if (fp == NULL) {
980                 _LOGD("no category parser list\n");
981                 return -1;
982         }
983
984         while (fgets(category_key, sizeof(category_key), fp) != NULL) {
985                 __str_trim(category_key);
986                 ret = __run_category_parser_prestep(mfx, category_key, action);
987                 if (ret < 0)
988                         break;
989         }
990
991         if (fp != NULL)
992                 fclose(fp);
993
994         return ret;
995 }
996
997 static int __ps_process_allowed(xmlTextReaderPtr reader, char **allowed)
998 {
999         __save_xml_value(reader, allowed);
1000         return 0;
1001 }
1002
1003 static int __ps_process_condition(xmlTextReaderPtr reader, char **condition)
1004 {
1005         __save_xml_attribute(reader, "name", condition, NULL);
1006         return 0;
1007 }
1008
1009 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
1010 {
1011         __save_xml_attribute(reader, "name", &notification->name, NULL);
1012         __save_xml_value(reader, &notification->text);
1013         return 0;
1014 }
1015
1016 static int __ps_process_category(xmlTextReaderPtr reader, char **category)
1017 {
1018         __save_xml_attribute(reader, "name", category, NULL);
1019         return 0;
1020 }
1021
1022 static int __ps_process_privilege(xmlTextReaderPtr reader, char **privilege)
1023 {
1024         __save_xml_value(reader, privilege);
1025         return 0;
1026 }
1027
1028 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
1029 {
1030         __save_xml_attribute(reader, "key", &metadata->key, NULL);
1031         __save_xml_attribute(reader, "value", &metadata->value, NULL);
1032         return 0;
1033 }
1034
1035 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
1036 {
1037         __save_xml_attribute(reader, "type", &permission->type, NULL);
1038         __save_xml_value(reader, &permission->value);
1039         return 0;
1040 }
1041
1042 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
1043 {
1044         __save_xml_attribute(reader, "name", &compatibility->name, NULL);
1045         __save_xml_value(reader, &compatibility->text);
1046         return 0;
1047 }
1048
1049 static int __ps_process_request(xmlTextReaderPtr reader, char **request)
1050 {
1051         __save_xml_value(reader, request);
1052         return 0;
1053 }
1054
1055 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
1056 {
1057         const xmlChar *node;
1058         int ret = -1;
1059         int depth = -1;
1060         char *val;
1061
1062         __save_xml_attribute(reader, "path", &define->path, NULL);
1063
1064         depth = xmlTextReaderDepth(reader);
1065         while ((ret = __next_child_element(reader, depth))) {
1066                 node = xmlTextReaderConstName(reader);
1067                 if (!node) {
1068                         _LOGD("xmlTextReaderConstName value is NULL\n");
1069                         return -1;
1070                 }
1071
1072                 if (!strcmp(ASCII(node), "allowed")) {
1073                         val = NULL;
1074                         ret = __ps_process_allowed(reader, &val);
1075                         if (val)
1076                                 define->allowed = g_list_append(define->allowed, (gpointer)val);
1077                 } else if (!strcmp(ASCII(node), "request")) {
1078                         val = NULL;
1079                         ret = __ps_process_request(reader, &val);
1080                         if (val)
1081                                 define->request = g_list_append(define->request, (gpointer)val);
1082                 } else {
1083                         return -1;
1084                 }
1085                 if (ret < 0) {
1086                         _LOGD("Processing define failed\n");
1087                         return ret;
1088                 }
1089         }
1090         return ret;
1091 }
1092
1093 struct appcontrol_data {
1094         GList *operations;
1095         GList *uris;
1096         GList *mimes;
1097         GList *appcontrols;
1098         char operation[BUFSIZE];
1099         char uri[BUFSIZE];
1100         char mime[BUFSIZE];
1101 };
1102
1103 static void __ps_process_mime(gpointer data, gpointer user_data)
1104 {
1105         char *mime = (char *)data;
1106         struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1107         appcontrol_x *appcontrol;
1108
1109         snprintf(ad->mime, sizeof(ad->mime), "%s", mime);
1110
1111         appcontrol = calloc(1, sizeof(appcontrol_x));
1112         if (strlen(ad->operation))
1113                 appcontrol->operation = strdup(ad->operation);
1114         if (strlen(ad->uri))
1115                 appcontrol->uri = strdup(ad->uri);
1116         appcontrol->mime = strdup(ad->mime);
1117         ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1118 }
1119
1120 static void __ps_process_uri(gpointer data, gpointer user_data)
1121 {
1122         char *uri = (char *)data;
1123         struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1124         appcontrol_x *appcontrol;
1125
1126         snprintf(ad->uri, sizeof(ad->uri), "%s", uri);
1127
1128         if (ad->mimes != NULL) {
1129                 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1130         } else {
1131                 appcontrol = calloc(1, sizeof(appcontrol_x));
1132                 if (strlen(ad->operation))
1133                         appcontrol->operation = strdup(ad->operation);
1134                 appcontrol->uri = strdup(ad->uri);
1135                 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1136         }
1137 }
1138
1139 static void __ps_process_operation(gpointer data, gpointer user_data)
1140 {
1141         char *operation = (char *)data;
1142         struct appcontrol_data *ad = (struct appcontrol_data *)user_data;
1143         appcontrol_x *appcontrol;
1144
1145         snprintf(ad->operation, sizeof(ad->operation), "%s", operation);
1146
1147         if (ad->uris != NULL) {
1148                 g_list_foreach(ad->uris, __ps_process_uri, user_data);
1149         } else if (ad->mimes != NULL) {
1150                 g_list_foreach(ad->mimes, __ps_process_mime, user_data);
1151         } else {
1152                 appcontrol = calloc(1, sizeof(appcontrol_x));
1153                 appcontrol->operation = strdup(ad->operation);
1154                 ad->appcontrols = g_list_append(ad->appcontrols, appcontrol);
1155         }
1156 }
1157
1158 static GList *__make_appcontrol_list(GList *operations, GList *uris, GList *mimes)
1159 {
1160         struct appcontrol_data ad = {0, };
1161
1162         ad.operations = operations;
1163         ad.uris = uris;
1164         ad.mimes = mimes;
1165
1166         if (ad.operations == NULL)
1167                 return NULL;
1168
1169         g_list_foreach(ad.operations, __ps_process_operation, (gpointer)&ad);
1170
1171         return ad.appcontrols;
1172 }
1173
1174 static int __ps_process_appcontrol(xmlTextReaderPtr reader, GList **appcontrol)
1175 {
1176         const xmlChar *node;
1177         int ret = -1;
1178         int depth = -1;
1179         char *val;
1180         GList *operations = NULL;
1181         GList *uris = NULL;
1182         GList *mimes = NULL;
1183         GList *result;
1184
1185         depth = xmlTextReaderDepth(reader);
1186         while ((ret = __next_child_element(reader, depth)) > 0) {
1187                 node = xmlTextReaderConstName(reader);
1188                 if (!node) {
1189                         _LOGD("xmlTextReaderConstName value is NULL\n");
1190                         return -1;
1191                 }
1192
1193                 val = NULL;
1194                 if (!strcmp(ASCII(node), "operation")) {
1195                         __save_xml_attribute(reader, "name", &val, NULL);
1196                         if (val)
1197                                 operations = g_list_append(operations, (gpointer)val);
1198                         _LOGD("operation processing\n");
1199                 } else if (!strcmp(ASCII(node), "uri")) {
1200                         __save_xml_attribute(reader, "name", &val, NULL);
1201                         if (val)
1202                                 uris = g_list_append(uris, (gpointer)val);
1203                         _LOGD("uri processing\n");
1204                 } else if (!strcmp(ASCII(node), "mime")) {
1205                         __save_xml_attribute(reader, "name", &val, NULL);
1206                         if (val)
1207                                 mimes = g_list_append(mimes, (gpointer)val);
1208                         _LOGD("mime processing\n");
1209                 } else if (!strcmp(ASCII(node), "subapp")) {
1210                         continue;
1211                 } else {
1212                         ret = -1;
1213                 }
1214         }
1215
1216         if (ret < 0) {
1217                 _LOGD("Processing appcontrol failed\n");
1218                 g_list_free_full(operations, free);
1219                 g_list_free_full(uris, free);
1220                 g_list_free_full(mimes, free);
1221                 return ret;
1222         }
1223
1224         result = __make_appcontrol_list(operations, uris, mimes);
1225         if (result)
1226                 *appcontrol = g_list_concat(*appcontrol, result);
1227         else
1228                 ret = -1;
1229
1230         g_list_free_full(operations, free);
1231         g_list_free_full(uris, free);
1232         g_list_free_full(mimes, free);
1233
1234         return ret;
1235 }
1236
1237 static int __ps_process_privileges(xmlTextReaderPtr reader, GList **privileges)
1238 {
1239         const xmlChar *node;
1240         int ret = -1;
1241         int depth = -1;
1242         char *val;
1243
1244         depth = xmlTextReaderDepth(reader);
1245         while ((ret = __next_child_element(reader, depth))) {
1246                 node = xmlTextReaderConstName(reader);
1247                 if (!node) {
1248                         _LOGD("xmlTextReaderConstName value is NULL\n");
1249                         return -1;
1250                 }
1251
1252                 if (strcmp(ASCII(node), "privilege") == 0) {
1253                         val = NULL;
1254                         ret = __ps_process_privilege(reader, &val);
1255                         if (val)
1256                                 *privileges = g_list_append(*privileges, (gpointer)val);
1257                 } else
1258                         return -1;
1259                 if (ret < 0) {
1260                         _LOGD("Processing privileges failed\n");
1261                         return ret;
1262                 }
1263         }
1264         return ret;
1265 }
1266
1267 static int __ps_process_launchconditions(xmlTextReaderPtr reader, GList **launchconditions)
1268 {
1269         const xmlChar *node;
1270         int ret = -1;
1271         int depth = -1;
1272         char *val;
1273
1274         depth = xmlTextReaderDepth(reader);
1275         while ((ret = __next_child_element(reader, depth))) {
1276                 node = xmlTextReaderConstName(reader);
1277                 if (!node) {
1278                         _LOGD("xmlTextReaderConstName value is NULL\n");
1279                         return -1;
1280                 }
1281
1282                 if (strcmp(ASCII(node), "condition") == 0) {
1283                         val = NULL;
1284                         ret = __ps_process_condition(reader, &val);
1285                         if (val)
1286                                 *launchconditions = g_list_append(*launchconditions, (gpointer)val);
1287                 } else
1288                         return -1;
1289                 if (ret < 0) {
1290                         _LOGD("Processing launchconditions failed\n");
1291                         return ret;
1292                 }
1293         }
1294
1295         return ret;
1296 }
1297
1298 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
1299 {
1300         const xmlChar *node;
1301         int ret = -1;
1302         int depth = -1;
1303         char *val;
1304         depth = xmlTextReaderDepth(reader);
1305         while ((ret = __next_child_element(reader, depth))) {
1306                 node = xmlTextReaderConstName(reader);
1307                 if (!node) {
1308                         _LOGD("xmlTextReaderConstName value is NULL\n");
1309                         return -1;
1310                 }
1311
1312                 if (!strcmp(ASCII(node), "define")) {
1313                         define_x *define = calloc(1, sizeof(define_x));
1314                         if (define == NULL) {
1315                                 _LOGD("Malloc Failed\n");
1316                                 return -1;
1317                         }
1318                         datashare->define = g_list_append(datashare->define, define);
1319                         ret = __ps_process_define(reader, define);
1320                 } else if (!strcmp(ASCII(node), "request")) {
1321                         val = NULL;
1322                         ret = __ps_process_request(reader, &val);
1323                         if (val)
1324                                 datashare->request = g_list_append(datashare->request, (gpointer)val);
1325                 } else
1326                         return -1;
1327                 if (ret < 0) {
1328                         _LOGD("Processing data-share failed\n");
1329                         return ret;
1330                 }
1331         }
1332         return ret;
1333 }
1334
1335 static char *__get_icon_with_path(const char *icon, uid_t uid)
1336 {
1337         char icon_with_path[BUFSIZE];
1338         const char *app_path;
1339
1340         if (!icon || !package)
1341                 return NULL;
1342
1343         /* just use absolute path */
1344         if (index(icon, '/'))
1345                 return strdup(icon);
1346
1347         do {
1348                 if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
1349                         snprintf(icon_with_path, sizeof(icon_with_path),
1350                                 "%s%s", getIconPath(uid, true), icon);
1351                         if (access(icon_with_path, F_OK) == 0)
1352                                 break;
1353
1354                         snprintf(icon_with_path, sizeof(icon_with_path),
1355                                 "%s%s", getIconPath(uid, false), icon);
1356                         if (access(icon_with_path, F_OK) == 0)
1357                                 break;
1358
1359                         /* for backward compatibility (.../default/small/...)
1360                          * this should be removed
1361                          */
1362                         snprintf(icon_with_path, sizeof(icon_with_path),
1363                                 "%sdefault/small/%s",
1364                                 getIconPath(uid, true), icon);
1365                         if (access(icon_with_path, F_OK) == 0)
1366                                 break;
1367
1368                         snprintf(icon_with_path, sizeof(icon_with_path),
1369                                 "%sdefault/small/%s",
1370                                 getIconPath(uid, false), icon);
1371                         if (access(icon_with_path, F_OK) == 0)
1372                                 break;
1373
1374                         /* If doesn't exist in case of Global app,
1375                          * try to get icon directly into app's directory
1376                          */
1377                         app_path = tzplatform_getenv(TZ_SYS_RO_APP);
1378
1379                         snprintf(icon_with_path, sizeof(icon_with_path),
1380                                 "%s/%s/%s", app_path, package, icon);
1381                         if (access(icon_with_path, F_OK) == 0)
1382                                 break;
1383
1384                         app_path = tzplatform_getenv(TZ_SYS_RW_APP);
1385
1386                         snprintf(icon_with_path, sizeof(icon_with_path),
1387                                 "%s/%s/%s", app_path, package, icon);
1388                         if (access(icon_with_path, F_OK) == 0)
1389                                 break;
1390                 } else {
1391                         tzplatform_set_user(uid);
1392                         app_path = tzplatform_getenv(TZ_USER_APP);
1393                         tzplatform_reset_user();
1394
1395                         snprintf(icon_with_path, sizeof(icon_with_path),
1396                                 "%s/%s/%s", app_path, package, icon);
1397                         if (access(icon_with_path, F_OK) == 0)
1398                                 break;
1399                 }
1400
1401                 /* some preload package has icons at below path */
1402                 snprintf(icon_with_path, sizeof(icon_with_path),
1403                                 "%s/%s/res/icons/%s", app_path, package, icon);
1404                 if (access(icon_with_path, F_OK) == 0)
1405                         break;
1406
1407                 /* since 2.3 tpk package */
1408                 snprintf(icon_with_path, sizeof(icon_with_path),
1409                                 "%s/%s/shared/res/%s", app_path, package, icon);
1410                 if (access(icon_with_path, F_OK) == 0)
1411                         break;
1412
1413                 _LOGE("cannot find icon path for [%s]", icon);
1414                 return NULL;
1415         } while (0);
1416
1417         _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1418
1419         return strdup(icon_with_path);
1420 }
1421
1422 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
1423 {
1424         int i = 0;
1425         char delims[] = "=";
1426         char *ret_result = NULL;
1427         char *tag = NULL;
1428         char *ptr = NULL;
1429
1430         if (tagv == NULL)
1431                 return;
1432
1433         for (tag = strdup(tagv[0]); tag != NULL; ) {
1434                 ret_result = strtok_r(tag, delims, &ptr);
1435
1436                 /*check tag :  preload */
1437                 if (strcmp(ret_result, "preload") == 0) {
1438                         ret_result = strtok_r(NULL, delims, &ptr);
1439                         if (strcmp(ret_result, "true") == 0) {
1440                                 free((void *)mfx->preload);
1441                                 mfx->preload = strdup("true");
1442                         } else if (strcmp(ret_result, "false") == 0) {
1443                                 free((void *)mfx->preload);
1444                                 mfx->preload = strdup("false");
1445                         }
1446                 /*check tag :  removable*/
1447                 } else if (strcmp(ret_result, "removable") == 0) {
1448                         ret_result = strtok_r(NULL, delims, &ptr);
1449                         if (strcmp(ret_result, "true") == 0) {
1450                                 free((void *)mfx->removable);
1451                                 mfx->removable = strdup("true");
1452                         } else if (strcmp(ret_result, "false") == 0) {
1453                                 free((void *)mfx->removable);
1454                                 mfx->removable = strdup("false");
1455                         }
1456                 /*check tag :  not matched*/
1457                 } else
1458                         _LOGD("tag process [%s]is not defined\n", ret_result);
1459
1460                 free(tag);
1461
1462                 /*check next value*/
1463                 if (tagv[++i] != NULL)
1464                         tag = strdup(tagv[i]);
1465                 else {
1466                         _LOGD("tag process success...\n");
1467                         return;
1468                 }
1469         }
1470 }
1471
1472 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
1473 {
1474         __save_xml_attribute(reader, "section", &icon->section, NULL);
1475         __save_xml_attribute(reader, "size", &icon->size, NULL);
1476         __save_xml_attribute(reader, "resolution", &icon->resolution, NULL);
1477         __save_xml_lang(reader, &icon->lang);
1478
1479         xmlTextReaderRead(reader);
1480         char *text  = ASCII(xmlTextReaderValue(reader));
1481         if (text) {
1482                 icon->text = __get_icon_with_path(text, uid);
1483                 free(text);
1484         }
1485
1486         return 0;
1487 }
1488
1489 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
1490 {
1491         __save_xml_attribute(reader, "section", &image->section, NULL);
1492         __save_xml_lang(reader, &image->lang);
1493         __save_xml_value(reader, &image->text);
1494         return 0;
1495 }
1496
1497 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
1498 {
1499         __save_xml_attribute(reader, "name", &label->name, NULL);
1500         __save_xml_lang(reader, &label->lang);
1501         __save_xml_value(reader, &label->text);
1502         return 0;
1503
1504 }
1505
1506 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
1507 {
1508         __save_xml_attribute(reader, "email", &author->email, NULL);
1509         __save_xml_attribute(reader, "href", &author->href, NULL);
1510         __save_xml_value(reader, &author->text);
1511         return 0;
1512 }
1513
1514 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
1515 {
1516         __save_xml_lang(reader, &description->lang);
1517         __save_xml_value(reader, &description->text);
1518         return 0;
1519 }
1520
1521 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
1522 {
1523         __save_xml_lang(reader, &license->lang);
1524         __save_xml_value(reader, &license->text);
1525         return 0;
1526 }
1527
1528 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
1529 {
1530         __save_xml_attribute(reader, "providerid", &datacontrol->providerid, NULL);
1531         __save_xml_attribute(reader, "access", &datacontrol->access, NULL);
1532         __save_xml_attribute(reader, "type", &datacontrol->type, NULL);
1533         return 0;
1534 }
1535
1536 static int __ps_process_splashscreen(xmlTextReaderPtr reader, splashscreen_x *splashscreen)
1537 {
1538         __save_xml_attribute(reader, "src", &splashscreen->src, NULL);
1539         __save_xml_attribute(reader, "type", &splashscreen->type, NULL);
1540         __save_xml_attribute(reader, "dpi", &splashscreen->dpi, NULL);
1541         __save_xml_attribute(reader, "orientation", &splashscreen->orientation, NULL);
1542         __save_xml_attribute(reader, "indicator-display", &splashscreen->indicatordisplay, NULL);
1543         __save_xml_attribute(reader, "app-control-operation", &splashscreen->operation, NULL);
1544         __save_xml_attribute(reader, "color-depth", &splashscreen->color_depth, NULL);
1545         return 0;
1546 }
1547
1548 static int __ps_process_splashscreens(xmlTextReaderPtr reader, GList **splashscreens)
1549 {
1550         const xmlChar *node;
1551         int ret = -1;
1552         int depth = -1;
1553         splashscreen_x *splashscreen;
1554
1555         depth = xmlTextReaderDepth(reader);
1556         while ((ret = __next_child_element(reader, depth))) {
1557                 node = xmlTextReaderConstName(reader);
1558                 if (!node) {
1559                         _LOGD("xmlTextReaderConstName value is NULL\n");
1560                         return -1;
1561                 }
1562
1563                 if (strcmp(ASCII(node), "splash-screen") == 0) {
1564                         splashscreen = calloc(1, sizeof(splashscreen_x));
1565                         if (splashscreen == NULL) {
1566                                 _LOGD("Malloc Failed\n");
1567                                 return -1;
1568                         }
1569                         *splashscreens = g_list_append(*splashscreens, splashscreen);
1570                         ret = __ps_process_splashscreen(reader, splashscreen);
1571                 } else {
1572                         return -1;
1573                 }
1574
1575                 if (ret < 0) {
1576                         _LOGD("Processing splash-screen failed\n");
1577                         return ret;
1578                 }
1579         }
1580         return 0;
1581 }
1582
1583 static int __ps_process_application(xmlTextReaderPtr reader, application_x *application, int type, uid_t uid)
1584 {
1585         const xmlChar *node;
1586         int ret = -1;
1587         int depth = -1;
1588         char *val;
1589
1590         __save_xml_attribute(reader, "appid", &application->appid, NULL);
1591         retvm_if(application->appid == NULL, PM_PARSER_R_ERROR, "appid cant be NULL, appid field is mandatory\n");
1592         __save_xml_attribute(reader, "exec", &application->exec, NULL);
1593         __save_xml_attribute(reader, "nodisplay", &application->nodisplay, "false");
1594         __save_xml_attribute(reader, "multiple", &application->multiple, "false");
1595         __save_xml_attribute(reader, "type", &application->type, NULL);
1596         __save_xml_attribute(reader, "categories", &application->categories, NULL);
1597         __save_xml_attribute(reader, "extraid", &application->extraid, NULL);
1598         __save_xml_attribute(reader, "taskmanage", &application->taskmanage, "true");
1599         __save_xml_attribute(reader, "enabled", &application->enabled, "true");
1600         __save_xml_attribute(reader, "hw-acceleration", &application->hwacceleration, "default");
1601         __save_xml_attribute(reader, "screen-reader", &application->screenreader, "use-system-setting");
1602         __save_xml_attribute(reader, "mainapp", &application->mainapp, "false");
1603         __save_xml_attribute(reader, "recentimage", &application->recentimage, "false");
1604         __save_xml_attribute(reader, "launchcondition", &application->launchcondition, "false");
1605         __save_xml_attribute(reader, "indicatordisplay", &application->indicatordisplay, "true");
1606         __save_xml_attribute(reader, "portrait-effectimage", &application->portraitimg, NULL);
1607         __save_xml_attribute(reader, "landscape-effectimage", &application->landscapeimg, NULL);
1608         __save_xml_attribute(reader, "guestmode-visibility", &application->guestmode_visibility, "true");
1609         __save_xml_attribute(reader, "permission-type", &application->permission_type, "normal");
1610         __save_xml_attribute(reader, "component-type", &application->component_type, type == PMINFO_UI_APP ? "uiapp" : type == PMINFO_SVC_APP ? "svcapp" : "widgetapp");
1611         /*component_type has "svcapp" or "uiapp", if it is not, parsing manifest is fail*/
1612         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);
1613         __save_xml_attribute(reader, "submode", &application->submode, "false");
1614         __save_xml_attribute(reader, "submode-mainid", &application->submode_mainid, NULL);
1615         __save_xml_attribute(reader, "process-pool", &application->process_pool, "false");
1616         __save_xml_attribute(reader, "launch_mode", &application->launch_mode, "caller");
1617         __save_xml_attribute(reader, "ui-gadget", &application->ui_gadget, "false");
1618         __save_xml_attribute(reader, "auto-restart", &application->autorestart, "false");
1619         __save_xml_attribute(reader, "on-boot", &application->onboot, "false");
1620         __save_xml_attribute(reader, "splash-screen-display", &application->splash_screen_display, "true");
1621
1622         application->package = strdup(package);
1623         /* overwrite some attributes if the app is widgetapp */
1624         if (type == PMINFO_WIDGET_APP || type == PMINFO_WATCH_APP) {
1625                 free((void *)application->nodisplay);
1626                 application->nodisplay = strdup("true");
1627                 free((void *)application->multiple);
1628                 application->multiple = strdup("true");
1629                 free((void *)application->type);
1630                 application->type = strdup("capp");
1631                 free((void *)application->taskmanage);
1632                 application->taskmanage = strdup("false");
1633                 free((void *)application->indicatordisplay);
1634                 application->indicatordisplay = strdup("false");
1635         }
1636
1637         /* hw-acceleration values are changed from use-GL/not-use-GL/use-system-setting to on/off/default */
1638         if (strcmp(application->hwacceleration, "use-GL") == 0) {
1639                 free((void *)application->hwacceleration);
1640                 application->hwacceleration = strdup("on");
1641         } else if (strcmp(application->hwacceleration, "not-use-GL") == 0) {
1642                 free((void *)application->hwacceleration);
1643                 application->hwacceleration = strdup("off");
1644         } else if (strcmp(application->hwacceleration, "use-system-setting") == 0) {
1645                 free((void *)application->hwacceleration);
1646                 application->hwacceleration = strdup("default");
1647         }
1648
1649         depth = xmlTextReaderDepth(reader);
1650         while ((ret = __next_child_element(reader, depth))) {
1651                 node = xmlTextReaderConstName(reader);
1652                 if (!node) {
1653                         _LOGD("xmlTextReaderConstName value is NULL\n");
1654                         return -1;
1655                 }
1656                 if (!strcmp(ASCII(node), "label")) {
1657                         label_x *label = calloc(1, sizeof(label_x));
1658                         if (label == NULL) {
1659                                 _LOGD("Malloc Failed\n");
1660                                 return -1;
1661                         }
1662                         application->label = g_list_append(application->label, label);
1663                         ret = __ps_process_label(reader, label);
1664                 } else if (!strcmp(ASCII(node), "icon")) {
1665                         icon_x *icon = calloc(1, sizeof(icon_x));
1666                         if (icon == NULL) {
1667                                 _LOGD("Malloc Failed\n");
1668                                 return -1;
1669                         }
1670                         application->icon = g_list_append(application->icon, icon);
1671                         ret = __ps_process_icon(reader, icon, uid);
1672                 } else if (!strcmp(ASCII(node), "image")) {
1673                         image_x *image = calloc(1, sizeof(image_x));
1674                         if (image == NULL) {
1675                                 _LOGD("Malloc Failed\n");
1676                                 return -1;
1677                         }
1678                         application->image = g_list_append(application->image, image);
1679                         ret = __ps_process_image(reader, image);
1680                 } else if (!strcmp(ASCII(node), "category")) {
1681                         val = NULL;
1682                         ret = __ps_process_category(reader, &val);
1683                         if (val)
1684                                 application->category = g_list_append(application->category, (gpointer)val);
1685                 } else if (!strcmp(ASCII(node), "metadata")) {
1686                         metadata_x *metadata = calloc(1, sizeof(metadata_x));
1687                         if (metadata == NULL) {
1688                                 _LOGD("Malloc Failed\n");
1689                                 return -1;
1690                         }
1691                         application->metadata = g_list_append(application->metadata, metadata);
1692                         ret = __ps_process_metadata(reader, metadata);
1693                 } else if (!strcmp(ASCII(node), "permission")) {
1694                         permission_x *permission = calloc(1, sizeof(permission_x));
1695                         if (permission == NULL) {
1696                                 _LOGD("Malloc Failed\n");
1697                                 return -1;
1698                         }
1699                         application->permission = g_list_append(application->permission, permission);
1700                         ret = __ps_process_permission(reader, permission);
1701                 } else if (!strcmp(ASCII(node), "app-control")) {
1702                         ret = __ps_process_appcontrol(reader, &application->appcontrol);
1703                 } else if (!strcmp(ASCII(node), "application-service")) {
1704                         ret = __ps_process_appcontrol(reader, &application->appcontrol);
1705                 } else if (!strcmp(ASCII(node), "data-share")) {
1706                         datashare_x *datashare = calloc(1, sizeof(datashare_x));
1707                         if (datashare == NULL) {
1708                                 _LOGD("Malloc Failed\n");
1709                                 return -1;
1710                         }
1711                         application->datashare = g_list_append(application->datashare, datashare);
1712                         ret = __ps_process_datashare(reader, datashare);
1713                 } else if (!strcmp(ASCII(node), "launch-conditions")) {
1714                         ret = __ps_process_launchconditions(reader, &application->launchconditions);
1715                 } else if (!strcmp(ASCII(node), "notification")) {
1716                         notification_x *notification = calloc(1, sizeof(notification_x));
1717                         if (notification == NULL) {
1718                                 _LOGD("Malloc Failed\n");
1719                                 return -1;
1720                         }
1721                         application->notification = g_list_append(application->notification, notification);
1722                         ret = __ps_process_notification(reader, notification);
1723                 } else if (!strcmp(ASCII(node), "datacontrol")) {
1724                         datacontrol_x *datacontrol = calloc(1, sizeof(datacontrol_x));
1725                         if (datacontrol == NULL) {
1726                                 _LOGD("Malloc Failed\n");
1727                                 return -1;
1728                         }
1729                         application->datacontrol = g_list_append(application->datacontrol, datacontrol);
1730                         ret = __ps_process_datacontrol(reader, datacontrol);
1731                 } else if (!strcmp(ASCII(node), "splash-screens") == 0) {
1732                         ret = __ps_process_splashscreens(reader, &application->splashscreens);
1733                 } else
1734                         continue;
1735                 if (ret < 0) {
1736                         _LOGD("Processing application failed\n");
1737                         return ret;
1738                 }
1739         }
1740
1741         return ret;
1742 }
1743
1744 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
1745 {
1746         _LOGD("__start_process\n");
1747         const xmlChar *node;
1748         int ret = -1;
1749         int depth = -1;
1750
1751         depth = xmlTextReaderDepth(reader);
1752         while ((ret = __next_child_element(reader, depth))) {
1753                 node = xmlTextReaderConstName(reader);
1754                 if (!node) {
1755                         _LOGD("xmlTextReaderConstName value is NULL\n");
1756                         return -1;
1757                 }
1758
1759                 if (!strcmp(ASCII(node), "label")) {
1760                         label_x *label = calloc(1, sizeof(label_x));
1761                         if (label == NULL) {
1762                                 _LOGD("Malloc Failed\n");
1763                                 return -1;
1764                         }
1765                         mfx->label = g_list_append(mfx->label, label);
1766                         ret = __ps_process_label(reader, label);
1767                 } else if (!strcmp(ASCII(node), "author")) {
1768                         author_x *author = calloc(1, sizeof(author_x));
1769                         if (author == NULL) {
1770                                 _LOGD("Malloc Failed\n");
1771                                 return -1;
1772                         }
1773                         mfx->author = g_list_append(mfx->author, author);
1774                         ret = __ps_process_author(reader, author);
1775                 } else if (!strcmp(ASCII(node), "description")) {
1776                         description_x *description = calloc(1, sizeof(description_x));
1777                         if (description == NULL) {
1778                                 _LOGD("Malloc Failed\n");
1779                                 return -1;
1780                         }
1781                         mfx->description = g_list_append(mfx->description, description);
1782                         ret = __ps_process_description(reader, description);
1783                 } else if (!strcmp(ASCII(node), "license")) {
1784                         license_x *license = calloc(1, sizeof(license_x));
1785                         if (license == NULL) {
1786                                 _LOGD("Malloc Failed\n");
1787                                 return -1;
1788                         }
1789                         mfx->license = g_list_append(mfx->license, license);
1790                         ret = __ps_process_license(reader, license);
1791                 } else if (!strcmp(ASCII(node), "privileges")) {
1792                         ret = __ps_process_privileges(reader, &mfx->privileges);
1793                 } else if (!strcmp(ASCII(node), "ui-application")) {
1794                         application_x *application = calloc(1, sizeof(application_x));
1795                         if (application == NULL) {
1796                                 _LOGD("Malloc Failed\n");
1797                                 return -1;
1798                         }
1799                         mfx->application = g_list_append(mfx->application, application);
1800                         ret = __ps_process_application(reader, application, PMINFO_UI_APP, uid);
1801                 } else if (!strcmp(ASCII(node), "service-application")) {
1802                         application_x *application = calloc(1, sizeof(application_x));
1803                         if (application == NULL) {
1804                                 _LOGD("Malloc Failed\n");
1805                                 return -1;
1806                         }
1807                         mfx->application = g_list_append(mfx->application, application);
1808                         ret = __ps_process_application(reader, application, PMINFO_SVC_APP, uid);
1809                 } else if (!strcmp(ASCII(node), "widget-application")) {
1810                         application_x *application = calloc(1, sizeof(application_x));
1811                         if (application == NULL) {
1812                                 _LOGD("Malloc Failed\n");
1813                                 return -1;
1814                         }
1815                         mfx->application = g_list_append(mfx->application, application);
1816                         ret = __ps_process_application(reader, application, PMINFO_WIDGET_APP, uid);
1817                 } else if (!strcmp(ASCII(node), "watch-application")) {
1818                         application_x *application = calloc(1, sizeof(application_x));
1819                         if (application == NULL) {
1820                                 _LOGD("Malloc Failed\n");
1821                                 return -1;
1822                         }
1823                         mfx->application = g_list_append(mfx->application, application);
1824                         ret = __ps_process_application(reader, application, PMINFO_WATCH_APP, uid);
1825                 } else if (!strcmp(ASCII(node), "icon")) {
1826                         icon_x *icon = calloc(1, sizeof(icon_x));
1827                         if (icon == NULL) {
1828                                 _LOGD("Malloc Failed\n");
1829                                 return -1;
1830                         }
1831                         mfx->icon = g_list_append(mfx->icon, icon);
1832                         ret = __ps_process_icon(reader, icon, uid);
1833                 } else if (!strcmp(ASCII(node), "compatibility")) {
1834                         compatibility_x *compatibility = calloc(1, sizeof(compatibility_x));
1835                         if (compatibility == NULL) {
1836                                 _LOGD("Malloc Failed\n");
1837                                 return -1;
1838                         }
1839                         mfx->compatibility = g_list_append(mfx->compatibility, compatibility);
1840                         ret = __ps_process_compatibility(reader, compatibility);
1841                 } else if (!strcmp(ASCII(node), "shortcut-list")) {
1842                         continue;
1843                 } else if (!strcmp(ASCII(node), "livebox")) {
1844                         continue;
1845                 } else if (!strcmp(ASCII(node), "account")) {
1846                         continue;
1847                 } else if (!strcmp(ASCII(node), "notifications")) {
1848                         continue;
1849                 } else if (!strcmp(ASCII(node), "ime")) {
1850                         continue;
1851                 } else if (!strcmp(ASCII(node), "feature")) {
1852                         continue;
1853                 } else {
1854                         _LOGI("Unknown element: %s", ASCII(node));
1855                         continue;
1856                 }
1857
1858                 if (ret < 0) {
1859                         _LOGD("Processing manifest failed\n");
1860                         return ret;
1861                 }
1862         }
1863         return ret;
1864 }
1865
1866 static int __process_manifest(xmlTextReaderPtr reader, manifest_x *mfx, uid_t uid)
1867 {
1868         const xmlChar *node;
1869         int ret = -1;
1870
1871         if ((ret = __next_child_element(reader, -1))) {
1872                 node = xmlTextReaderConstName(reader);
1873                 if (!node) {
1874                         _LOGD("xmlTextReaderConstName value is NULL\n");
1875                         return -1;
1876                 }
1877
1878                 if (!strcmp(ASCII(node), "manifest")) {
1879                         __save_xml_attribute(reader, "xmlns", &mfx->ns, NULL);
1880                         __save_xml_attribute(reader, "package", &mfx->package, NULL);
1881                         retvm_if(mfx->package == NULL, PM_PARSER_R_ERROR, "package cant be NULL, package field is mandatory\n");
1882                         __save_xml_attribute(reader, "version", &mfx->version, NULL);
1883                         __save_xml_attribute(reader, "size", &mfx->package_size, NULL);
1884                         __save_xml_attribute(reader, "install-location", &mfx->installlocation, "internal-only");
1885                         __save_xml_attribute(reader, "type", &mfx->type, "tpk");
1886                         __save_xml_attribute(reader, "root_path", &mfx->root_path, NULL);
1887                         __save_xml_attribute(reader, "csc_path", &mfx->csc_path, NULL);
1888                         __save_xml_attribute(reader, "appsetting", &mfx->appsetting, "false");
1889                         __save_xml_attribute(reader, "storeclient-id", &mfx->storeclient_id, NULL);
1890                         __save_xml_attribute(reader, "nodisplay-setting", &mfx->nodisplay_setting, "false");
1891                         __save_xml_attribute(reader, "url", &mfx->package_url, NULL);
1892                         __save_xml_attribute(reader, "api-version", &mfx->api_version, NULL);
1893                         __save_xml_attribute(reader, "support-disable", &mfx->support_disable, "false");
1894
1895                         __save_xml_installed_time(mfx);
1896                         __save_xml_root_path(mfx, uid);
1897                         /*Assign default values. If required it will be overwritten in __add_preload_info()*/
1898                         __save_xml_default_value(mfx);
1899
1900                         ret = __start_process(reader, mfx, uid);
1901                 } else {
1902                         _LOGD("No Manifest element found\n");
1903                         return -1;
1904                 }
1905         }
1906         return ret;
1907 }
1908
1909 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
1910
1911 static int __ps_remove_appsvc_db(manifest_x *mfx, uid_t uid)
1912 {
1913         void *lib_handle = NULL;
1914         int (*appsvc_operation) (const char *, uid_t);
1915         int ret = 0;
1916         GList *tmp;
1917         application_x *application;
1918
1919         if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1920                 _LOGE("dlopen is failed LIBAPPSVC_PATH[%s]\n", LIBAPPSVC_PATH);
1921                 goto END;
1922         }
1923
1924         if ((appsvc_operation =
1925                  dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1926                 _LOGE("can not find symbol \n");
1927                 goto END;
1928         }
1929
1930         for (tmp = mfx->application; tmp; tmp = tmp->next) {
1931                 application = (application_x *)tmp->data;
1932                 if (application == NULL)
1933                         continue;
1934                 ret = appsvc_operation(application->appid, uid);
1935                 if (ret < 0)
1936                         _LOGE("can not operation  symbol \n");
1937         }
1938
1939 END:
1940         if (lib_handle)
1941                 dlclose(lib_handle);
1942
1943         return ret;
1944 }
1945
1946 static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
1947 {
1948         if (!strstr(manifest, getUserManifestPath(uid,
1949                 strcmp(mfx->preload, "true") == 0))) {
1950                 /* if downloaded app is updated, then update tag set true*/
1951                 if (mfx->update)
1952                         free((void *)mfx->update);
1953                 mfx->update = strdup("true");
1954         }
1955
1956         return 0;
1957 }
1958
1959 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
1960 {
1961         pkgmgrinfo_basic_free_package((package_x *)mfx);
1962 }
1963
1964 DEPRECATED API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
1965 {
1966         _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
1967         xmlTextReaderPtr reader;
1968         manifest_x *mfx = NULL;
1969
1970         reader = xmlReaderForFile(manifest, NULL, 0);
1971         if (reader) {
1972                 mfx = malloc(sizeof(manifest_x));
1973                 if (mfx) {
1974                         memset(mfx, '\0', sizeof(manifest_x));
1975                         if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
1976                                 _LOGD("Parsing Failed\n");
1977                                 pkgmgr_parser_free_manifest_xml(mfx);
1978                                 mfx = NULL;
1979                         } else
1980                                 _LOGD("Parsing Success\n");
1981                 } else {
1982                         _LOGD("Memory allocation error\n");
1983                 }
1984                 xmlFreeTextReader(reader);
1985         } else {
1986                 _LOGD("Unable to create xml reader\n");
1987         }
1988         return mfx;
1989 }
1990
1991
1992 DEPRECATED API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
1993 {
1994         _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
1995         xmlTextReaderPtr reader;
1996         manifest_x *mfx = NULL;
1997
1998         reader = xmlReaderForFile(manifest, NULL, 0);
1999         if (reader) {
2000                 mfx = malloc(sizeof(manifest_x));
2001                 if (mfx) {
2002                         memset(mfx, '\0', sizeof(manifest_x));
2003                         if (__process_manifest(reader, mfx, uid) < 0) {
2004                                 _LOGD("Parsing Failed\n");
2005                                 pkgmgr_parser_free_manifest_xml(mfx);
2006                                 mfx = NULL;
2007                         } else
2008                                 _LOGD("Parsing Success\n");
2009                 } else {
2010                         _LOGD("Memory allocation error\n");
2011                 }
2012                 xmlFreeTextReader(reader);
2013         } else {
2014                 _LOGD("Unable to create xml reader\n");
2015         }
2016         return mfx;
2017 }
2018
2019 API int pkgmgr_parser_usr_update_tep(const char *pkgid, const char *tep_path, uid_t uid)
2020 {
2021         return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, uid);
2022 }
2023
2024 API int pkgmgr_parser_update_tep(const char *pkgid, const char *tep_path)
2025 {
2026         return pkgmgr_parser_update_tep_info_in_db(pkgid, tep_path);
2027 }
2028
2029 DEPRECATED API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
2030 {
2031         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2032         _LOGD("parsing manifest for installation: %s\n", manifest);
2033
2034         manifest_x *mfx = NULL;
2035         int ret = -1;
2036
2037         xmlInitParser();
2038         mfx = pkgmgr_parser_process_manifest_xml(manifest);
2039         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2040
2041         _LOGD("Parsing Finished\n");
2042
2043         __ps_process_tag(mfx, tagv);
2044
2045         ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2046         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2047
2048         _LOGD("DB Insert Success\n");
2049
2050         __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2051         ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2052         if (ret == -1)
2053                 _LOGD("Creating metadata parser failed\n");
2054
2055         ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2056         if (ret == -1)
2057                 _LOGD("Creating category parser failed\n");
2058
2059         pkgmgr_parser_free_manifest_xml(mfx);
2060         _LOGD("Free Done\n");
2061         xmlCleanupParser();
2062
2063         return PMINFO_R_OK;
2064 }
2065
2066 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
2067 {
2068         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2069         _LOGD("parsing manifest for installation: %s\n", manifest);
2070         manifest_x *mfx = NULL;
2071         int ret = -1;
2072
2073         xmlInitParser();
2074         mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2075         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2076
2077         _LOGD("Parsing Finished\n");
2078
2079         __ps_process_tag(mfx, tagv);
2080
2081         ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2082         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2083
2084         _LOGD("DB Insert Success\n");
2085
2086         __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
2087         ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
2088         if (ret == -1)
2089                 _LOGD("Creating metadata parser failed\n");
2090         ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
2091         if (ret == -1)
2092                 _LOGD("Creating category parser failed\n");
2093
2094         pkgmgr_parser_free_manifest_xml(mfx);
2095         _LOGD("Free Done\n");
2096         xmlCleanupParser();
2097
2098         return PMINFO_R_OK;
2099 }
2100
2101 API int pkgmgr_parser_process_manifest_x_for_installation(manifest_x* mfx, const char *manifest)
2102 {
2103         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2104         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2105         _LOGD("processing manifest_x for installation: %s\n", manifest);
2106         int ret = -1;
2107
2108         ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
2109         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2110         _LOGD("DB Insert Success\n");
2111
2112         return PMINFO_R_OK;
2113 }
2114
2115 API int pkgmgr_parser_process_usr_manifest_x_for_installation(manifest_x* mfx, const char *manifest, uid_t uid)
2116 {
2117         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2118         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2119         _LOGD("processing manifest_x for installation: %s\n", manifest);
2120         int ret = -1;
2121
2122         ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
2123         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2124         _LOGD("DB Insert Success\n");
2125
2126         return PMINFO_R_OK;
2127 }
2128
2129 DEPRECATED API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
2130 {
2131         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2132         _LOGD("pkgmgr_parser_parse_manifest_for_upgrade  parsing manifest for upgradation: %s\n", manifest);
2133         manifest_x *mfx = NULL;
2134         int ret = -1;
2135         bool preload = false;
2136         bool system = false;
2137         char *csc_path = NULL;
2138         pkgmgrinfo_pkginfo_h handle = NULL;
2139
2140         xmlInitParser();
2141         mfx = pkgmgr_parser_process_manifest_xml(manifest);
2142         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2143
2144         _LOGD("Parsing Finished\n");
2145         __check_preload_updated(mfx, manifest, GLOBAL_USER);
2146
2147         ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
2148         if (ret != PMINFO_R_OK)
2149                 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2150         ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2151         if (ret != PMINFO_R_OK)
2152                 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2153
2154         if (preload) {
2155                 free((void *)mfx->preload);
2156                 mfx->preload = strdup("true");
2157         }
2158
2159         ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2160         if (ret != PMINFO_R_OK)
2161                 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2162         if (system) {
2163                 free((void *)mfx->system);
2164                 mfx->system = strdup("true");
2165         }
2166
2167         ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2168         if (ret != PMINFO_R_OK)
2169                 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2170
2171         if (csc_path != NULL) {
2172                 if (mfx->csc_path)
2173                         free((void *)mfx->csc_path);
2174                 mfx->csc_path = strdup(csc_path);
2175         }
2176
2177         /*Delete from cert table*/
2178         ret = pkgmgrinfo_delete_certinfo(mfx->package);
2179         if (ret) {
2180                 _LOGD("Cert Info  DB Delete Failed\n");
2181                 return -1;
2182         }
2183
2184         ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2185         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2186
2187         _LOGD("DB Update Success\n");
2188
2189         __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2190         ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2191         if (ret == -1)
2192                 _LOGD("Upgrade metadata parser failed\n");
2193         ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2194         if (ret == -1)
2195                 _LOGD("Creating category parser failed\n");
2196         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2197         pkgmgr_parser_free_manifest_xml(mfx);
2198         _LOGD("Free Done\n");
2199         xmlCleanupParser();
2200
2201         return PMINFO_R_OK;
2202 }
2203
2204 DEPRECATED API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
2205 {
2206         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2207         _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2208         manifest_x *mfx = NULL;
2209         int ret = -1;
2210         bool preload = false;
2211         bool system = false;
2212         char *csc_path = NULL;
2213         pkgmgrinfo_pkginfo_h handle = NULL;
2214
2215         xmlInitParser();
2216         mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2217         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2218
2219         _LOGD("Parsing Finished\n");
2220         __check_preload_updated(mfx, manifest, uid);
2221
2222         ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
2223         if (ret != PMINFO_R_OK)
2224                 _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
2225         ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
2226         if (ret != PMINFO_R_OK)
2227                 _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
2228
2229         if (preload) {
2230                 free((void *)mfx->preload);
2231                 mfx->preload = strdup("true");
2232         }
2233
2234         ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
2235         if (ret != PMINFO_R_OK)
2236                 _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
2237
2238         if (system) {
2239                 free((void *)mfx->system);
2240                 mfx->system = strdup("true");
2241         }
2242
2243         ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
2244         if (ret != PMINFO_R_OK)
2245                 _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
2246         if (csc_path != NULL) {
2247                 if (mfx->csc_path)
2248                         free((void *)mfx->csc_path);
2249                 mfx->csc_path = strdup(csc_path);
2250         }
2251
2252         /*Delete from cert table*/
2253         ret = pkgmgrinfo_delete_certinfo(mfx->package);
2254         if (ret) {
2255                 _LOGD("Cert Info  DB Delete Failed\n");
2256                 return -1;
2257         }
2258
2259         ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2260         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2261         _LOGD("DB Update Success\n");
2262
2263         __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
2264         ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
2265         if (ret == -1)
2266                 _LOGD("Upgrade metadata parser failed\n");
2267         ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
2268         if (ret == -1)
2269                 _LOGD("Creating category parser failed\n");
2270         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2271         pkgmgr_parser_free_manifest_xml(mfx);
2272         _LOGD("Free Done\n");
2273         xmlCleanupParser();
2274
2275         return PMINFO_R_OK;
2276 }
2277
2278 API int pkgmgr_parser_process_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest)
2279 {
2280         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2281         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2282         _LOGD("pkgmgr_parser_process_manifest_x_for_upgrade  parsing manifest for upgradation: %s\n", manifest);
2283         int ret = -1;
2284
2285         ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
2286         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2287         _LOGD("DB Update Success\n");
2288
2289         return PMINFO_R_OK;
2290 }
2291
2292 API int pkgmgr_parser_process_usr_manifest_x_for_upgrade(manifest_x* mfx, const char *manifest, uid_t uid)
2293 {
2294         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2295         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2296         _LOGD(" pkgmgr_parser_process_usr_manifest_x_for_upgrade parsing manifest for upgradation: %s\n", manifest);
2297         int ret = -1;
2298
2299         ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
2300         retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
2301         _LOGD("DB Update Success\n");
2302
2303         return PMINFO_R_OK;
2304 }
2305
2306 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
2307 {
2308         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2309         _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2310
2311         manifest_x *mfx = NULL;
2312         int ret = -1;
2313         xmlInitParser();
2314         mfx = pkgmgr_parser_process_manifest_xml(manifest);
2315         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2316
2317         _LOGD("Parsing Finished\n");
2318
2319         __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2320
2321         ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2322         if (ret == -1)
2323                 _LOGD("Removing metadata parser failed\n");
2324
2325         ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2326         if (ret == -1)
2327                 _LOGD("Creating category parser failed\n");
2328
2329         /*Delete from cert table*/
2330         ret = pkgmgrinfo_delete_certinfo(mfx->package);
2331         if (ret) {
2332                 _LOGD("Cert Info  DB Delete Failed\n");
2333                 return -1;
2334         }
2335
2336         ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2337         if (ret == -1)
2338                 _LOGD("DB Delete failed\n");
2339         else
2340                 _LOGD("DB Delete Success\n");
2341
2342         pkgmgr_parser_free_manifest_xml(mfx);
2343         _LOGD("Free Done\n");
2344         xmlCleanupParser();
2345
2346         return PMINFO_R_OK;
2347 }
2348
2349
2350 API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
2351 {
2352         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2353         _LOGD("parsing manifest for uninstallation: %s\n", manifest);
2354
2355         manifest_x *mfx = NULL;
2356         int ret = -1;
2357         xmlInitParser();
2358         mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
2359         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2360
2361         _LOGD("Parsing Finished\n");
2362
2363         __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
2364
2365         ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
2366         if (ret == -1)
2367                 _LOGD("Removing metadata parser failed\n");
2368
2369         ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
2370         if (ret == -1)
2371                 _LOGD("Creating category parser failed\n");
2372
2373         /*Delete from cert table*/
2374         ret = pkgmgrinfo_delete_certinfo(mfx->package);
2375         if (ret) {
2376                 _LOGD("Cert Info  DB Delete Failed\n");
2377                 return -1;
2378         }
2379
2380         ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2381         if (ret == -1)
2382                 _LOGD("DB Delete failed\n");
2383         else
2384                 _LOGD("DB Delete Success\n");
2385
2386         ret = __ps_remove_appsvc_db(mfx, uid);
2387         if (ret == -1)
2388                 _LOGD("Removing appsvc_db failed\n");
2389         else
2390                 _LOGD("Removing appsvc_db Success\n");
2391
2392         pkgmgr_parser_free_manifest_xml(mfx);
2393         _LOGD("Free Done\n");
2394         xmlCleanupParser();
2395
2396         return PMINFO_R_OK;
2397 }
2398
2399 API int pkgmgr_parser_process_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest)
2400 {
2401         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2402         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2403         _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2404
2405         int ret = -1;
2406         ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
2407         if (ret == -1)
2408                 _LOGD("DB Delete failed\n");
2409         else
2410                 _LOGD("DB Delete Success\n");
2411
2412         return PMINFO_R_OK;
2413 }
2414
2415 API int pkgmgr_parser_process_usr_manifest_x_for_uninstallation(manifest_x* mfx, const char *manifest, uid_t uid)
2416 {
2417         retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2418         retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2419         _LOGD("processing manifest_x for uninstallation: %s\n", manifest);
2420
2421         int ret = -1;
2422
2423         ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
2424         if (ret == -1)
2425                 _LOGD("DB Delete failed\n");
2426         else
2427                 _LOGD("DB Delete Success\n");
2428
2429         ret = __ps_remove_appsvc_db(mfx, uid);
2430         if (ret == -1)
2431                 _LOGD("Removing appsvc_db failed\n");
2432         else
2433                 _LOGD("Removing appsvc_db Success\n");
2434
2435         return PMINFO_R_OK;
2436 }
2437
2438 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
2439 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
2440 {
2441         if (manifest == NULL) {
2442                 _LOGE("manifest file is NULL\n");
2443                 return PMINFO_R_EINVAL;
2444         }
2445         int ret = -1;
2446         xmlSchemaParserCtxtPtr ctx;
2447         xmlSchemaValidCtxtPtr vctx;
2448         xmlSchemaPtr xschema;
2449         ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
2450         if (ctx == NULL) {
2451                 _LOGE("xmlSchemaNewParserCtxt() Failed\n");
2452                 return PMINFO_R_ERROR;
2453         }
2454         xschema = xmlSchemaParse(ctx);
2455         if (xschema == NULL) {
2456                 _LOGE("xmlSchemaParse() Failed\n");
2457                 return PMINFO_R_ERROR;
2458         }
2459         vctx = xmlSchemaNewValidCtxt(xschema);
2460         if (vctx == NULL) {
2461                 _LOGE("xmlSchemaNewValidCtxt() Failed\n");
2462                 return PMINFO_R_ERROR;
2463         }
2464         xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
2465         ret = xmlSchemaValidateFile(vctx, manifest, 0);
2466         if (ret == -1) {
2467                 _LOGE("xmlSchemaValidateFile() failed\n");
2468                 return PMINFO_R_ERROR;
2469         } else if (ret == 0) {
2470                 _LOGD("Manifest is Valid\n");
2471                 return PMINFO_R_OK;
2472         } else {
2473                 _LOGE("Manifest Validation Failed with error code %d\n", ret);
2474                 return PMINFO_R_ERROR;
2475         }
2476         return PMINFO_R_OK;
2477 }
2478