Merge branch 'tizen_2.2' into tizen
[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
37 #include "pkgmgr_parser.h"
38 #include "pkgmgr_parser_internal.h"
39 #include "pkgmgr_parser_db.h"
40 #include "pkgmgr-info.h"
41
42 #define MANIFEST_RW_DIRECTORY "/opt/share/packages"
43 #define MANIFEST_RO_DIRECTORY "/usr/share/packages"
44 #define ASCII(s) (const char *)s
45 #define XMLCHAR(s) (const xmlChar *)s
46
47 #define MDPARSER_LIST "/usr/etc/package-manager/parserlib/metadata/mdparser_list.txt"
48 #define MDPARSER_NAME   "mdparser:"
49
50 #define CATEGORY_PARSER_LIST "/usr/etc/package-manager/parserlib/category/category_parser_list.txt"
51 #define CATEGORY_PARSER_NAME    "categoryparser:"
52
53 #define PKG_TAG_LEN_MAX 128
54
55 /* operation_type */
56 typedef enum {
57         ACTION_INSTALL = 0,
58         ACTION_UPGRADE,
59         ACTION_UNINSTALL,
60         ACTION_MAX
61 } ACTION_TYPE;
62
63 /* plugin process_type */
64 typedef enum {
65         PLUGIN_PRE_PROCESS = 0,
66         PLUGIN_POST_PROCESS
67 } PLUGIN_PROCESS_TYPE;
68
69 typedef struct {
70         const char *key;
71         const char *value;
72 } __metadata_t;
73
74 typedef struct {
75         const char *name;
76 } __category_t;
77
78 const char *package;
79
80 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label);
81 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege);
82 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges);
83 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile);
84 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed);
85 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation);
86 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri);
87 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime);
88 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp);
89 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition);
90 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notifiation);
91 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category);
92 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata);
93 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission);
94 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility);
95 static int __ps_process_resolution(xmlTextReaderPtr reader, resolution_x *resolution);
96 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request);
97 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
98 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc);
99 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions);
100 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
101 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon);
102 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
103 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
104 static int __ps_process_capability(xmlTextReaderPtr reader, capability_x *capability);
105 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
106 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol);
107 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
108 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication);
109 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication);
110 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font);
111 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme);
112 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon);
113 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime);
114 static void __ps_free_label(label_x *label);
115 static void __ps_free_privilege(privilege_x *privilege);
116 static void __ps_free_privileges(privileges_x *privileges);
117 static void __ps_free_deviceprofile(deviceprofile_x * deviceprofile);
118 static void __ps_free_allowed(allowed_x *allowed);
119 static void __ps_free_operation(operation_x *operation);
120 static void __ps_free_uri(uri_x *uri);
121 static void __ps_free_mime(mime_x *mime);
122 static void __ps_free_subapp(subapp_x *subapp);
123 static void __ps_free_condition(condition_x *condition);
124 static void __ps_free_notification(notification_x *notifiation);
125 static void __ps_free_category(category_x *category);
126 static void __ps_free_metadata(metadata_x *metadata);
127 static void __ps_free_permission(permission_x *permission);
128 static void __ps_free_compatibility(compatibility_x *compatibility);
129 static void __ps_free_resolution(resolution_x *resolution);
130 static void __ps_free_request(request_x *request);
131 static void __ps_free_define(define_x *define);
132 static void __ps_free_appsvc(appsvc_x *appsvc);
133 static void __ps_free_launchconditions(launchconditions_x *launchconditions);
134 static void __ps_free_datashare(datashare_x *datashare);
135 static void __ps_free_icon(icon_x *icon);
136 static void __ps_free_author(author_x *author);
137 static void __ps_free_description(description_x *description);
138 static void __ps_free_capability(capability_x *capability);
139 static void __ps_free_license(license_x *license);
140 static void __ps_free_appcontrol(appcontrol_x *appcontrol);
141 static void __ps_free_datacontrol(datacontrol_x *datacontrol);
142 static void __ps_free_uiapplication(uiapplication_x *uiapplication);
143 static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication);
144 static void __ps_free_font(font_x *font);
145 static void __ps_free_theme(theme_x *theme);
146 static void __ps_free_daemon(daemon_x *daemon);
147 static void __ps_free_ime(ime_x *ime);
148 static char *__pkgid_to_manifest(const char *pkgid);
149 static int __next_child_element(xmlTextReaderPtr reader, int depth);
150 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx);
151 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx);
152 static void __str_trim(char *input);
153 static char *__get_parser_plugin(const char *type);
154 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
155 static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid);
156 static void __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], const char *pkgid);
157 static void __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid);
158 static int __validate_appid(const char *pkgid, const char *appid, char **newappid);
159
160 static void __str_trim(char *input)
161 {
162         char *trim_str = input;
163
164         if (input == NULL)
165                 return;
166
167         while (*input != 0) {
168                 if (!isspace(*input)) {
169                         *trim_str = *input;
170                         trim_str++;
171                 }
172                 input++;
173         }
174
175         *trim_str = 0;
176         return;
177 }
178
179 static int __validate_appid(const char *pkgid, const char *appid, char **newappid)
180 {
181         if (!pkgid || !appid || !newappid) {
182                 DBG("Arg supplied is NULL\n");
183                 return -1;
184         }
185         int pkglen = strlen(pkgid);
186         int applen = strlen(appid);
187         char *ptr = NULL;
188         char *newapp = NULL;
189         int len = 0;
190         if (strncmp(appid, ".", 1) == 0) {
191                 len = pkglen + applen + 1;
192                 newapp = calloc(1,len);
193                 if (newapp == NULL) {
194                         DBG("Malloc failed\n");
195                         return -1;
196                 }
197                 strncpy(newapp, pkgid, pkglen);
198                 strncat(newapp, appid, applen);
199                 DBG("new appid is %s\n", newapp);
200                 *newappid = newapp;
201                 return 0;
202         }
203         if (applen < pkglen) {
204                 DBG("app id is not proper\n");
205                 *newappid = NULL;
206 #ifdef _VALIDATE_APPID_
207                 return -1;
208 #else
209                 return 0;
210 #endif
211         }
212         if (!strcmp(appid, pkgid)) {
213                 DBG("appid is proper\n");
214                 *newappid = NULL;
215                 return 0;
216         }
217         else if (strncmp(appid, pkgid, pkglen) == 0) {
218                 ptr = strstr(appid, pkgid);
219                 ptr = ptr + pkglen;
220                 if (strncmp(ptr, ".", 1) == 0) {
221                         DBG("appid is proper\n");
222                         *newappid = NULL;
223                         return 0;
224                 }
225                 else {
226                         DBG("appid is not proper\n");
227                         *newappid = NULL;
228 #ifdef _VALIDATE_APPID_
229                         return -1;
230 #else
231                         return 0;
232 #endif
233                 }
234         } else {
235                 DBG("appid is not proper\n");
236                 *newappid = NULL;
237 #ifdef _VALIDATE_APPID_
238                 return -1;
239 #else
240                 return 0;
241 #endif
242         }
243         return 0;
244 }
245
246 static char * __get_tag_by_key(char *md_key)
247 {
248         char *md_tag = NULL;
249
250         if (md_key == NULL) {
251                 DBG("md_key is NULL\n");
252                 return NULL;
253         }
254
255         md_tag = strrchr(md_key, 47) + 1;
256
257
258         return strdup(md_tag);
259 }
260
261 static char *__get_mdparser_plugin(const char *type)
262 {
263         FILE *fp = NULL;
264         char buffer[1024] = { 0 };
265         char temp_path[1024] = { 0 };
266         char *path = NULL;
267
268         if (type == NULL) {
269                 DBGE("invalid argument\n");
270                 return NULL;
271         }
272
273         fp = fopen(PKG_PARSER_CONF_PATH, "r");
274         if (fp == NULL) {
275                 DBGE("no matching mdparser\n");
276                 return NULL;
277         }
278
279         while (fgets(buffer, sizeof(buffer), fp) != NULL) {
280                 if (buffer[0] == '#')
281                         continue;
282
283                 __str_trim(buffer);
284
285                 if ((path = strstr(buffer, MDPARSER_NAME)) != NULL) {
286                         path = path + strlen(MDPARSER_NAME);
287
288                         break;
289                 }
290
291                 memset(buffer, 0x00, 1024);
292         }
293
294         if (fp != NULL)
295                 fclose(fp);
296
297         if (path == NULL) {
298                 DBGE("no matching [%s] [%s]\n", MDPARSER_NAME,type);
299                 return NULL;
300         }
301
302         snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
303
304         return strdup(temp_path);
305 }
306
307 static char *__get_category_parser_plugin(const char *type)
308 {
309         FILE *fp = NULL;
310         char buffer[1024] = { 0 };
311         char temp_path[1024] = { 0 };
312         char *path = NULL;
313
314         if (type == NULL) {
315                 DBGE("invalid argument\n");
316                 return NULL;
317         }
318
319         fp = fopen(PKG_PARSER_CONF_PATH, "r");
320         if (fp == NULL) {
321                 DBGE("no matching mdparser\n");
322                 return NULL;
323         }
324
325         while (fgets(buffer, sizeof(buffer), fp) != NULL) {
326                 if (buffer[0] == '#')
327                         continue;
328
329                 __str_trim(buffer);
330
331                 if ((path = strstr(buffer, CATEGORY_PARSER_NAME)) != NULL) {
332                         path = path + strlen(CATEGORY_PARSER_NAME);
333
334                         break;
335                 }
336
337                 memset(buffer, 0x00, 1024);
338         }
339
340         if (fp != NULL)
341                 fclose(fp);
342
343         if (path == NULL) {
344                 DBGE("no matching [%s] [%s]\n", CATEGORY_PARSER_NAME,type);
345                 return NULL;
346         }
347
348         snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
349
350         return strdup(temp_path);
351 }
352
353 static char *__get_parser_plugin(const char *type)
354 {
355         FILE *fp = NULL;
356         char buffer[1024] = { 0 };
357         char temp_path[1024] = { 0 };
358         char *path = NULL;
359
360         if (type == NULL) {
361                 DBGE("invalid argument\n");
362                 return NULL;
363         }
364
365         fp = fopen(PKG_PARSER_CONF_PATH, "r");
366         if (fp == NULL) {
367                 DBGE("no matching backendlib\n");
368                 return NULL;
369         }
370
371         while (fgets(buffer, sizeof(buffer), fp) != NULL) {
372                 if (buffer[0] == '#')
373                         continue;
374
375                 __str_trim(buffer);
376
377                 if ((path = strstr(buffer, PKG_PARSERLIB)) != NULL) {
378                         path = path + strlen(PKG_PARSERLIB);
379                         break;
380                 }
381
382                 memset(buffer, 0x00, 1024);
383         }
384
385         if (fp != NULL)
386                 fclose(fp);
387
388         if (path == NULL) {
389                 DBGE("no matching backendlib\n");
390                 return NULL;
391         }
392
393         snprintf(temp_path, sizeof(temp_path) - 1, "%slib%s.so", path, type);
394
395         return strdup(temp_path);
396 }
397
398 static int __ps_run_mdparser(GList *md_list, const char *tag,
399                                 ACTION_TYPE action, const char *pkgid, const char *appid)
400 {
401         char *lib_path = NULL;
402         void *lib_handle = NULL;
403         int (*mdparser_plugin) (const char *, const char *, GList *);
404         int ret = -1;
405         char *ac = NULL;
406
407         switch (action) {
408         case ACTION_INSTALL:
409                 ac = "PKGMGR_MDPARSER_PLUGIN_INSTALL";
410                 break;
411         case ACTION_UPGRADE:
412                 ac = "PKGMGR_MDPARSER_PLUGIN_UPGRADE";
413                 break;
414         case ACTION_UNINSTALL:
415                 ac = "PKGMGR_MDPARSER_PLUGIN_UNINSTALL";
416                 break;
417         default:
418                 goto END;
419         }
420
421         lib_path = __get_mdparser_plugin(tag);
422         if (!lib_path) {
423                 DBGE("get %s parser fail\n", tag);
424                 goto END;
425         }
426
427         if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
428                 DBGE("dlopen is failed lib_path[%s]\n", lib_path);
429                 goto END;
430         }
431
432         if ((mdparser_plugin =
433                 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
434                 DBGE("can not find symbol[%s] \n",ac);
435                 goto END;
436         }
437
438         ret = mdparser_plugin(pkgid, appid, md_list);
439         if (ret < 0)
440                 DBG("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
441         else
442                 DBG("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
443
444 END:
445         if (lib_path)
446                 free(lib_path);
447         if (lib_handle)
448                 dlclose(lib_handle);
449         return ret;
450 }
451
452 static int __ps_run_category_parser(GList *category_list, const char *tag,
453                                 ACTION_TYPE action, const char *pkgid, const char *appid)
454 {
455         char *lib_path = NULL;
456         void *lib_handle = NULL;
457         int (*category_parser_plugin) (const char *, const char *, GList *);
458         int ret = -1;
459         char *ac = NULL;
460
461         switch (action) {
462         case ACTION_INSTALL:
463                 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL";
464                 break;
465         case ACTION_UPGRADE:
466                 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE";
467                 break;
468         case ACTION_UNINSTALL:
469                 ac = "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL";
470                 break;
471         default:
472                 goto END;
473         }
474
475         lib_path = __get_category_parser_plugin(tag);
476         if (!lib_path) {
477                 DBGE("get %s parser fail\n", tag);
478                 goto END;
479         }
480
481         if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
482                 DBGE("dlopen is failed lib_path[%s]\n", lib_path);
483                 goto END;
484         }
485
486         if ((category_parser_plugin =
487                 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
488                 DBGE("can not find symbol[%s] \n",ac);
489                 goto END;
490         }
491
492         ret = category_parser_plugin(pkgid, appid, category_list);
493         if (ret < 0)
494                 DBG("[appid = %s, libpath = %s plugin fail\n", appid, lib_path);
495         else
496                 DBG("[appid = %s, libpath = %s plugin success\n", appid, lib_path);
497
498 END:
499         if (lib_path)
500                 free(lib_path);
501         if (lib_handle)
502                 dlclose(lib_handle);
503         return ret;
504 }
505
506 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag,
507                            ACTION_TYPE action, const char *pkgid)
508 {
509         char *lib_path = NULL;
510         void *lib_handle = NULL;
511         int (*plugin_install) (xmlDocPtr, const char *);
512         int ret = -1;
513         char *ac = NULL;
514
515         switch (action) {
516         case ACTION_INSTALL:
517                 ac = "PKGMGR_PARSER_PLUGIN_INSTALL";
518                 break;
519         case ACTION_UPGRADE:
520                 ac = "PKGMGR_PARSER_PLUGIN_UPGRADE";
521                 break;
522         case ACTION_UNINSTALL:
523                 ac = "PKGMGR_PARSER_PLUGIN_UNINSTALL";
524                 break;
525         default:
526                 goto END;
527         }
528
529         lib_path = __get_parser_plugin(tag);
530         if (!lib_path) {
531                 goto END;
532         }
533
534         if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
535                 DBGE("dlopen is failed lib_path[%s]\n", lib_path);
536                 goto END;
537         }
538         if ((plugin_install =
539                 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
540                 DBGE("can not find symbol[%s] \n", ac);
541                 goto END;
542         }
543
544         ret = plugin_install(docPtr, pkgid);
545         if (ret < 0)
546                 DBG("[pkgid = %s, libpath = %s plugin fail\n", pkgid, lib_path);
547         else
548                 DBG("[pkgid = %s, libpath = %s plugin success\n", pkgid, lib_path);
549
550 END:
551         if (lib_path)
552                 free(lib_path);
553         if (lib_handle)
554                 dlclose(lib_handle);
555         return ret;
556 }
557
558 static char *__pkgid_to_manifest(const char *pkgid)
559 {
560         char *manifest;
561         int size;
562
563         if (pkgid == NULL) {
564                 DBGE("pkgid is NULL");
565                 return NULL;
566         }
567
568         size = strlen(MANIFEST_RW_DIRECTORY) + strlen(pkgid) + 10;
569         manifest = malloc(size);
570         if (manifest == NULL) {
571                 DBGE("No memory");
572                 return NULL;
573         }
574         memset(manifest, '\0', size);
575         snprintf(manifest, size, MANIFEST_RW_DIRECTORY "/%s.xml", pkgid);
576
577         if (access(manifest, F_OK)) {
578                 snprintf(manifest, size, MANIFEST_RO_DIRECTORY "/%s.xml", pkgid);
579         }
580
581         return manifest;
582 }
583
584 static void __mdparser_clear_dir_list(GList* dir_list)
585 {
586         GList *list = NULL;
587         __metadata_t* detail = NULL;
588
589         if (dir_list) {
590                 list = g_list_first(dir_list);
591                 while (list) {
592                         detail = (__metadata_t *)list->data;
593                         if (detail) {
594                                 if (detail->key)
595                                         free(detail->key);
596                                 if (detail->value)
597                                         free(detail->value);
598                                 free(detail);
599                         }
600                         list = g_list_next(list);
601                 }
602                 g_list_free(dir_list);
603         }
604 }
605
606 static void __category_parser_clear_dir_list(GList* dir_list)
607 {
608         GList *list = NULL;
609         __category_t* detail = NULL;
610
611         if (dir_list) {
612                 list = g_list_first(dir_list);
613                 while (list) {
614                         detail = (__category_t *)list->data;
615                         if (detail) {
616                                 if (detail->name)
617                                         free(detail->name);
618
619                                 free(detail);
620                         }
621                         list = g_list_next(list);
622                 }
623                 g_list_free(dir_list);
624         }
625 }
626
627 static int __run_mdparser_prestep (manifest_x *mfx, char *md_key, ACTION_TYPE action)
628 {
629         int ret = -1;
630         int tag_exist = 0;
631         char buffer[1024] = { 0, };
632         uiapplication_x *up = mfx->uiapplication;
633         metadata_x *md = NULL;
634         char *md_tag = NULL;
635
636         GList *md_list = NULL;
637         __metadata_t *md_detail = NULL;
638
639         md_tag = __get_tag_by_key(md_key);
640         if (md_tag == NULL) {
641                 DBG("md_tag is NULL\n");
642                 return -1;
643         }
644
645         while(up != NULL)
646         {
647                 md = up->metadata;
648                 while (md != NULL)
649                 {
650                         //get glist of meatdata key and value combination
651                         memset(buffer, 0x00, 1024);
652                         snprintf(buffer, 1024, "%s/", md_key);
653                         if ((md->key && md->value) && (strncmp(md->key, md_key, strlen(md_key)) == 0) && (strncmp(buffer, md->key, strlen(buffer)) == 0)) {
654                                 md_detail = (__metadata_t*) calloc(1, sizeof(__metadata_t));
655                                 if (md_detail == NULL) {
656                                         DBG("Memory allocation failed\n");
657                                         goto END;
658                                 }
659
660                                 md_detail->key = (char*) calloc(1, sizeof(char)*(strlen(md->key)+2));
661                                 if (md_detail->key == NULL) {
662                                         DBG("Memory allocation failed\n");
663                                         free(md_detail);
664                                         goto END;
665                                 }
666                                 snprintf(md_detail->key, (strlen(md->key)+1), "%s", md->key);
667
668                                 md_detail->value = (char*) calloc(1, sizeof(char)*(strlen(md->value)+2));
669                                 if (md_detail->value == NULL) {
670                                         DBG("Memory allocation failed\n");
671                                         free(md_detail->key);
672                                         free(md_detail);
673                                         goto END;
674                                 }
675                                 snprintf(md_detail->value, (strlen(md->value)+1), "%s", md->value);
676
677                                 md_list = g_list_append(md_list, (gpointer)md_detail);
678                                 tag_exist = 1;
679                         }
680                         md = md->next;
681                 }
682
683                 //send glist to parser when tags for metadata plugin parser exist.
684                 if (tag_exist) {
685                         ret = __ps_run_mdparser(md_list, md_tag, action, mfx->package, up->appid);
686                         if (ret < 0)
687                                 DBG("mdparser failed[%d] for tag[%s]\n", ret, md_tag);
688                         else
689                                 DBG("mdparser success for tag[%s]\n", md_tag);
690                 }
691                 __mdparser_clear_dir_list(md_list);
692                 md_list = NULL;
693                 tag_exist = 0;
694                 up = up->next;
695         }
696
697         return 0;
698 END:
699         __mdparser_clear_dir_list(md_list);
700
701         if (md_tag)
702                 free(md_tag);
703
704         return ret;
705 }
706
707 static int __run_category_parser_prestep (manifest_x *mfx, char *category_key, ACTION_TYPE action)
708 {
709         int ret = -1;
710         int tag_exist = 0;
711         char buffer[1024] = { 0, };
712         uiapplication_x *up = mfx->uiapplication;
713         category_x *category = NULL;
714         char *category_tag = NULL;
715
716         GList *category_list = NULL;
717         __category_t *category_detail = NULL;
718
719         category_tag = __get_tag_by_key(category_key);
720         if (category_tag == NULL) {
721                 DBG("md_tag is NULL\n");
722                 return -1;
723         }
724
725         while(up != NULL)
726         {
727                 category = up->category;
728                 while (category != NULL)
729                 {
730                         //get glist of meatdata key and value combination
731                         memset(buffer, 0x00, 1024);
732                         snprintf(buffer, 1024, "%s/", category_key);
733                         if ((category->name) && (strncmp(category->name, category_key, strlen(category_key)) == 0)) {
734                                 category_detail = (__category_t*) calloc(1, sizeof(__category_t));
735                                 if (category_detail == NULL) {
736                                         DBG("Memory allocation failed\n");
737                                         goto END;
738                                 }
739
740                                 category_detail->name = (char*) calloc(1, sizeof(char)*(strlen(category->name)+2));
741                                 if (category_detail->name == NULL) {
742                                         DBG("Memory allocation failed\n");
743                                         free(category_detail);
744                                         goto END;
745                                 }
746                                 snprintf(category_detail->name, (strlen(category->name)+1), "%s", category->name);
747
748                                 category_list = g_list_append(category_list, (gpointer)category_detail);
749                                 tag_exist = 1;
750                         }
751                         category = category->next;
752                 }
753
754                 //send glist to parser when tags for metadata plugin parser exist.
755                 if (tag_exist) {
756                         ret = __ps_run_category_parser(category_list, category_tag, action, mfx->package, up->appid);
757                         if (ret < 0)
758                                 DBG("category_parser failed[%d] for tag[%s]\n", ret, category_tag);
759                         else
760                                 DBG("category_parser success for tag[%s]\n", category_tag);
761                 }
762                 __category_parser_clear_dir_list(category_list);
763                 category_list = NULL;
764                 tag_exist = 0;
765                 up = up->next;
766         }
767
768         return 0;
769 END:
770         __category_parser_clear_dir_list(category_list);
771
772         if (category_tag)
773                 free(category_tag);
774
775         return ret;
776 }
777
778 static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, const char *pkgid)
779 {
780         int ret = -1;
781         const xmlChar *name;
782
783         DBG("__run_parser_prestep");
784
785         if (xmlTextReaderDepth(reader) != 1) {
786                 DBGE("Node depth is not 1");
787                 goto END;
788         }
789
790         if (xmlTextReaderNodeType(reader) != 1) {
791                 DBGE("Node type is not 1");
792                 goto END;
793         }
794
795         const xmlChar *value;
796         name = xmlTextReaderConstName(reader);
797         if (name == NULL) {
798                 DBGE("TEST TEST TES\n");
799                 name = BAD_CAST "--";
800         }
801
802         value = xmlTextReaderConstValue(reader);
803         DBG("%d %d %s %d %d",
804             xmlTextReaderDepth(reader),
805             xmlTextReaderNodeType(reader),
806             name,
807             xmlTextReaderIsEmptyElement(reader), xmlTextReaderHasValue(reader));
808
809         if (value == NULL) {
810                 DBG("ConstValue NULL");
811         } else {
812                 if (xmlStrlen(value) > 40) {
813                         DBG(" %.40s...", value);
814                 } else {
815                         DBG(" %s", value);
816                 }
817         }
818
819         name = xmlTextReaderConstName(reader);
820         if (name == NULL) {
821                 DBGE("TEST TEST TES\n");
822                 name = BAD_CAST "--";
823         }
824
825         xmlDocPtr docPtr = xmlTextReaderCurrentDoc(reader);
826         DBG("docPtr->URL %s\n", (char *)docPtr->URL);
827         xmlDocPtr copyDocPtr = xmlCopyDoc(docPtr, 1);
828         if (copyDocPtr == NULL)
829                 return -1;
830         xmlNode *rootElement = xmlDocGetRootElement(copyDocPtr);
831         if (rootElement == NULL)
832                 return -1;
833         xmlNode *cur_node = xmlFirstElementChild(rootElement);
834         if (cur_node == NULL)
835                 return -1;
836         xmlNode *temp = xmlTextReaderExpand(reader);
837         if (temp == NULL)
838                 return -1;
839         xmlNode *next_node = NULL;
840         while(cur_node != NULL) {
841                 if ( (strcmp(ASCII(temp->name), ASCII(cur_node->name)) == 0) &&
842                         (temp->line == cur_node->line) ) {
843                         break;
844                 }
845                 else {
846                         next_node = xmlNextElementSibling(cur_node);
847                         xmlUnlinkNode(cur_node);
848                         xmlFreeNode(cur_node);
849                         cur_node = next_node;
850                 }
851         }
852         if (cur_node == NULL)
853                 return -1;
854         next_node = xmlNextElementSibling(cur_node);
855         if (next_node) {
856                 cur_node->next = NULL;
857                 next_node->prev = NULL;
858                 xmlFreeNodeList(next_node);
859                 xmlSetTreeDoc(cur_node, copyDocPtr);
860         } else {
861                 xmlSetTreeDoc(cur_node, copyDocPtr);
862         }
863
864 #ifdef __DEBUG__
865
866 //#else
867         DBG("node type: %d, name: %s children->name: %s last->name: %s\n"
868             "parent->name: %s next->name: %s prev->name: %s\n",
869             cur_node->type, cur_node->name,
870             cur_node->children ? cur_node->children->name : "NULL",
871             cur_node->last ? cur_node->last->name : "NULL",
872             cur_node->parent ? cur_node->parent->name : "NULL",
873             cur_node->next ? cur_node->next->name : "NULL",
874             cur_node->prev ? cur_node->prev->name : "NULL");
875
876         FILE *fp = fopen("/opt/share/test.xml", "a");
877         xmlDocDump(fp, copyDocPtr);
878         fprintf(fp, "\n");
879         fclose(fp);
880 #endif
881
882         ret = __ps_run_parser(copyDocPtr, ASCII(name), action, pkgid);
883  END:
884
885         return ret;
886 }
887
888 static void
889 __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], const char *pkgid)
890 {
891         char *tag = NULL;
892         int i = 0;
893
894         switch (xmlTextReaderNodeType(reader)) {
895         case XML_READER_TYPE_END_ELEMENT:
896                 {
897                         //            DBG("XML_READER_TYPE_END_ELEMENT");
898                         break;
899                 }
900
901         case XML_READER_TYPE_ELEMENT:
902                 {
903                         // Elements without closing tag don't receive
904                         // XML_READER_TYPE_END_ELEMENT event.
905
906                         const xmlChar *elementName =
907                             xmlTextReaderLocalName(reader);
908                         if (elementName == NULL) {
909 //                              DBG("elementName %s\n", (char *)elementName);
910                                 break;
911                         }
912
913                         const xmlChar *nameSpace =
914                             xmlTextReaderConstNamespaceUri(reader);
915                         if (nameSpace) {
916 //                              DBG("nameSpace %s\n", (char *)nameSpace);
917                         }
918 /*
919                         DBG("XML_READER_TYPE_ELEMENT %s, %s\n",
920                             elementName ? elementName : "NULL",
921                             nameSpace ? nameSpace : "NULL");
922 */
923                         if (tagv == NULL) {
924                                 DBG("__run_parser_prestep pkgid[%s]\n", pkgid);
925                                 __run_parser_prestep(reader, action, pkgid);
926                         }
927                         else {
928                                 i = 0;
929                                 for (tag = tagv[0]; tag; tag = tagv[++i])
930                                         if (strcmp(tag, ASCII(elementName)) == 0) {
931                                                 DBG("__run_parser_prestep tag[%s] pkgid[%s]\n", tag, pkgid);
932                                                 __run_parser_prestep(reader,
933                                                                      action, pkgid);
934                                                 break;
935                                         }
936                         }
937
938                         break;
939                 }
940         case XML_READER_TYPE_TEXT:
941         case XML_READER_TYPE_CDATA:
942                 {
943                         const xmlChar *value = xmlTextReaderConstValue(reader);
944                         if (value) {
945 //                              DBG("value %s\n", value);
946                         }
947
948                         const xmlChar *lang = xmlTextReaderConstXmlLang(reader);
949                         if (lang) {
950 //                              DBG("lang\n", lang);
951                         }
952
953 /*                      DBG("XML_READER_TYPE_TEXT %s, %s\n",
954                             value ? value : "NULL", lang ? lang : "NULL");
955 */
956                         break;
957                 }
958         default:
959 //              DBG("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
960                 break;
961         }
962 }
963
964 static void __plugin_send_tag(const char *tag, ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
965 {
966         char *lib_path = NULL;
967         void *lib_handle = NULL;
968         int (*plugin_install) (const char *);
969         int ret = -1;
970         char *ac = NULL;
971
972         if (process == PLUGIN_PRE_PROCESS) {
973                 switch (action) {
974                 case ACTION_INSTALL:
975                         ac = "PKGMGR_PARSER_PLUGIN_PRE_INSTALL";
976                         break;
977                 case ACTION_UPGRADE:
978                         ac = "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE";
979                         break;
980                 case ACTION_UNINSTALL:
981                         ac = "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL";
982                         break;
983                 default:
984                         goto END;
985                 }
986         } else if (process == PLUGIN_POST_PROCESS) {
987                 switch (action) {
988                 case ACTION_INSTALL:
989                         ac = "PKGMGR_PARSER_PLUGIN_POST_INSTALL";
990                         break;
991                 case ACTION_UPGRADE:
992                         ac = "PKGMGR_PARSER_PLUGIN_POST_UPGRADE";
993                         break;
994                 case ACTION_UNINSTALL:
995                         ac = "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL";
996                         break;
997                 default:
998                         goto END;
999                 }
1000         } else
1001                 goto END;
1002
1003         lib_path = __get_parser_plugin(tag);
1004         if (!lib_path) {
1005                 goto END;
1006         }
1007
1008         if ((lib_handle = dlopen(lib_path, RTLD_LAZY)) == NULL) {
1009                 DBGE("dlopen is failed lib_path[%s] for tag[%s]\n", lib_path, tag);
1010                 goto END;
1011         }
1012         if ((plugin_install =
1013                 dlsym(lib_handle, ac)) == NULL || dlerror() != NULL) {
1014                 DBGE("can not find symbol[%s] for tag[%s] \n", ac, tag);
1015                 goto END;
1016         }
1017
1018         ret = plugin_install(pkgid);
1019         if (ret < 0)
1020                 DBG("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin fail\n", process, pkgid, tag);
1021         else
1022                 DBG("[PLUGIN_PROCESS_TYPE[%d] pkgid=%s, tag=%s plugin success\n", process, pkgid, tag);
1023
1024 END:
1025         if (lib_path)
1026                 free(lib_path);
1027         if (lib_handle)
1028                 dlclose(lib_handle);
1029 }
1030
1031 static void
1032 __plugin_process_tag(char *const tag_list[], ACTION_TYPE action, PLUGIN_PROCESS_TYPE process, const char *pkgid)
1033 {
1034         char *tag = NULL;
1035         int i = 0;
1036
1037         for (tag = tag_list[0]; tag; tag = tag_list[++i])
1038                 __plugin_send_tag(tag, action, process, pkgid);
1039
1040 }
1041
1042 static void
1043 __plugin_save_tag(xmlTextReaderPtr reader, char *const tagv[], char *tag_list[])
1044 {
1045         char *tag = NULL;
1046         int i = 0;
1047         static int pre_cnt=0;
1048
1049         switch (xmlTextReaderNodeType(reader)) {
1050         case XML_READER_TYPE_ELEMENT:
1051                 {
1052                         const xmlChar *elementName = xmlTextReaderLocalName(reader);
1053                         if (elementName == NULL) {
1054                                 break;
1055                         }
1056                         i = 0;
1057                         for (tag = tag_list[0]; tag; tag = tag_list[++i])
1058                                 if (strcmp(ASCII(elementName), tag) == 0) {
1059                                         return;
1060                                 }
1061                         i = 0;
1062                         for (tag = tagv[0]; tag; tag = tagv[++i])
1063                                 if (strcmp(tag, ASCII(elementName)) == 0) {
1064                                         tag_list[pre_cnt++] = tag;
1065                                         break;
1066                                 }
1067                         break;
1068                 }
1069         default:
1070 //              DBG("Ignoring Node of Type: %d", xmlTextReaderNodeType(reader));
1071                 break;
1072         }
1073 }
1074
1075 static void
1076 __plugin_find_tag(const char *filename, char *const tagv[], char *tag_list[])
1077 {
1078         xmlTextReaderPtr reader;
1079         xmlDocPtr docPtr;
1080         int ret;
1081
1082         docPtr = xmlReadFile(filename, NULL, 0);
1083         reader = xmlReaderWalker(docPtr);
1084         if (reader != NULL) {
1085                 ret = xmlTextReaderRead(reader);
1086                 while (ret == 1) {
1087                         __plugin_save_tag(reader, tagv, tag_list);
1088                         ret = xmlTextReaderRead(reader);
1089                 }
1090                 xmlFreeTextReader(reader);
1091
1092                 if (ret != 0) {
1093                         DBG("xmlReaderWalker fail");
1094                 }
1095         } else {
1096                 DBG("xmlReaderWalker fail");
1097         }
1098 }
1099
1100 static void
1101 __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid)
1102 {
1103         xmlTextReaderPtr reader;
1104         xmlDocPtr docPtr;
1105         int ret;
1106         char *tag_list[PKG_TAG_LEN_MAX] = {'\0'};
1107
1108         __plugin_find_tag(filename, tagv, tag_list);
1109         __plugin_process_tag(tag_list, action, PLUGIN_PRE_PROCESS, pkgid);
1110
1111         docPtr = xmlReadFile(filename, NULL, 0);
1112         reader = xmlReaderWalker(docPtr);
1113         if (reader != NULL) {
1114                 ret = xmlTextReaderRead(reader);
1115                 while (ret == 1) {
1116                         __processNode(reader, action, tagv, pkgid);
1117                         ret = xmlTextReaderRead(reader);
1118                 }
1119                 xmlFreeTextReader(reader);
1120
1121                 if (ret != 0) {
1122                         DBGE("%s : failed to parse", filename);
1123                 }
1124         } else {
1125                 DBGE("Unable to open %s", filename);
1126         }
1127
1128         __plugin_process_tag(tag_list, action, PLUGIN_POST_PROCESS, pkgid);
1129 }
1130
1131 static int __next_child_element(xmlTextReaderPtr reader, int depth)
1132 {
1133         int ret = xmlTextReaderRead(reader);
1134         int cur = xmlTextReaderDepth(reader);
1135         while (ret == 1) {
1136
1137                 switch (xmlTextReaderNodeType(reader)) {
1138                 case XML_READER_TYPE_ELEMENT:
1139                         if (cur == depth + 1)
1140                                 return 1;
1141                         break;
1142                 case XML_READER_TYPE_TEXT:
1143                         /*text is handled by each function separately*/
1144                         if (cur == depth + 1)
1145                                 return 0;
1146                         break;
1147                 case XML_READER_TYPE_END_ELEMENT:
1148                         if (cur == depth)
1149                                 return 0;
1150                         break;
1151                 default:
1152                         if (cur <= depth)
1153                                 return 0;
1154                         break;
1155                 }
1156                 ret = xmlTextReaderRead(reader);
1157                 cur = xmlTextReaderDepth(reader);
1158         }
1159         return ret;
1160 }
1161
1162 static void __ps_free_category(category_x *category)
1163 {
1164         if (category == NULL)
1165                 return;
1166         if (category->name) {
1167                 free((void *)category->name);
1168                 category->name = NULL;
1169         }
1170         free((void*)category);
1171         category = NULL;
1172 }
1173
1174 static void __ps_free_privilege(privilege_x *privilege)
1175 {
1176         if (privilege == NULL)
1177                 return;
1178         if (privilege->text) {
1179                 free((void *)privilege->text);
1180                 privilege->text = NULL;
1181         }
1182         free((void*)privilege);
1183         privilege = NULL;
1184 }
1185
1186 static void __ps_free_privileges(privileges_x *privileges)
1187 {
1188         if (privileges == NULL)
1189                 return;
1190         /*Free Privilege*/
1191         if (privileges->privilege) {
1192                 privilege_x *privilege = privileges->privilege;
1193                 privilege_x *tmp = NULL;
1194                 while(privilege != NULL) {
1195                         tmp = privilege->next;
1196                         __ps_free_privilege(privilege);
1197                         privilege = tmp;
1198                 }
1199         }
1200         free((void*)privileges);
1201         privileges = NULL;
1202 }
1203
1204 static void __ps_free_metadata(metadata_x *metadata)
1205 {
1206         if (metadata == NULL)
1207                 return;
1208         if (metadata->key) {
1209                 free((void *)metadata->key);
1210                 metadata->key = NULL;
1211         }
1212         if (metadata->value) {
1213                 free((void *)metadata->value);
1214                 metadata->value = NULL;
1215         }
1216         free((void*)metadata);
1217         metadata = NULL;
1218 }
1219
1220 static void __ps_free_permission(permission_x *permission)
1221 {
1222         if (permission == NULL)
1223                 return;
1224         if (permission->type) {
1225                 free((void *)permission->type);
1226                 permission->type = NULL;
1227         }
1228         if (permission->value) {
1229                 free((void *)permission->value);
1230                 permission->value = NULL;
1231         }
1232         free((void*)permission);
1233         permission = NULL;
1234 }
1235
1236 static void __ps_free_icon(icon_x *icon)
1237 {
1238         if (icon == NULL)
1239                 return;
1240         if (icon->text) {
1241                 free((void *)icon->text);
1242                 icon->text = NULL;
1243         }
1244         if (icon->lang) {
1245                 free((void *)icon->lang);
1246                 icon->lang = NULL;
1247         }
1248         if (icon->name) {
1249                 free((void *)icon->name);
1250                 icon->name= NULL;
1251         }
1252         if (icon->section) {
1253                 free((void *)icon->section);
1254                 icon->section = NULL;
1255         }
1256         if (icon->size) {
1257                 free((void *)icon->size);
1258                 icon->size = NULL;
1259         }
1260         if (icon->resolution) {
1261                 free((void *)icon->resolution);
1262                 icon->resolution = NULL;
1263         }
1264         free((void*)icon);
1265         icon = NULL;
1266 }
1267
1268 static void __ps_free_image(image_x *image)
1269 {
1270         if (image == NULL)
1271                 return;
1272         if (image->text) {
1273                 free((void *)image->text);
1274                 image->text = NULL;
1275         }
1276         if (image->lang) {
1277                 free((void *)image->lang);
1278                 image->lang = NULL;
1279         }
1280         if (image->name) {
1281                 free((void *)image->name);
1282                 image->name= NULL;
1283         }
1284         if (image->section) {
1285                 free((void *)image->section);
1286                 image->section = NULL;
1287         }
1288         free((void*)image);
1289         image = NULL;
1290 }
1291
1292 static void __ps_free_operation(operation_x *operation)
1293 {
1294         if (operation == NULL)
1295                 return;
1296         if (operation->text) {
1297                 free((void *)operation->text);
1298                 operation->text = NULL;
1299         }
1300         free((void*)operation);
1301         operation = NULL;
1302 }
1303
1304 static void __ps_free_uri(uri_x *uri)
1305 {
1306         if (uri == NULL)
1307                 return;
1308         if (uri->text) {
1309                 free((void *)uri->text);
1310                 uri->text = NULL;
1311         }
1312         free((void*)uri);
1313         uri = NULL;
1314 }
1315
1316 static void __ps_free_mime(mime_x *mime)
1317 {
1318         if (mime == NULL)
1319                 return;
1320         if (mime->text) {
1321                 free((void *)mime->text);
1322                 mime->text = NULL;
1323         }
1324         free((void*)mime);
1325         mime = NULL;
1326 }
1327
1328 static void __ps_free_subapp(subapp_x *subapp)
1329 {
1330         if (subapp == NULL)
1331                 return;
1332         if (subapp->text) {
1333                 free((void *)subapp->text);
1334                 subapp->text = NULL;
1335         }
1336         free((void*)subapp);
1337         subapp = NULL;
1338 }
1339
1340 static void __ps_free_condition(condition_x *condition)
1341 {
1342         if (condition == NULL)
1343                 return;
1344         if (condition->text) {
1345                 free((void *)condition->text);
1346                 condition->text = NULL;
1347         }
1348         if (condition->name) {
1349                 free((void *)condition->name);
1350                 condition->name = NULL;
1351         }
1352         free((void*)condition);
1353         condition = NULL;
1354 }
1355
1356 static void __ps_free_notification(notification_x *notification)
1357 {
1358         if (notification == NULL)
1359                 return;
1360         if (notification->text) {
1361                 free((void *)notification->text);
1362                 notification->text = NULL;
1363         }
1364         if (notification->name) {
1365                 free((void *)notification->name);
1366                 notification->name = NULL;
1367         }
1368         free((void*)notification);
1369         notification = NULL;
1370 }
1371
1372 static void __ps_free_compatibility(compatibility_x *compatibility)
1373 {
1374         if (compatibility == NULL)
1375                 return;
1376         if (compatibility->text) {
1377                 free((void *)compatibility->text);
1378                 compatibility->text = NULL;
1379         }
1380         if (compatibility->name) {
1381                 free((void *)compatibility->name);
1382                 compatibility->name = NULL;
1383         }
1384         free((void*)compatibility);
1385         compatibility = NULL;
1386 }
1387
1388 static void __ps_free_resolution(resolution_x *resolution)
1389 {
1390         if (resolution == NULL)
1391                 return;
1392         if (resolution->mimetype) {
1393                 free((void *)resolution->mimetype);
1394                 resolution->mimetype = NULL;
1395         }
1396         if (resolution->urischeme) {
1397                 free((void *)resolution->urischeme);
1398                 resolution->urischeme = NULL;
1399         }
1400         free((void*)resolution);
1401         resolution = NULL;
1402 }
1403
1404 static void __ps_free_capability(capability_x *capability)
1405 {
1406         if (capability == NULL)
1407                 return;
1408         if (capability->operationid) {
1409                 free((void *)capability->operationid);
1410                 capability->operationid = NULL;
1411         }
1412         /*Free Resolution*/
1413         if (capability->resolution) {
1414                 resolution_x *resolution = capability->resolution;
1415                 resolution_x *tmp = NULL;
1416                 while(resolution != NULL) {
1417                         tmp = resolution->next;
1418                         __ps_free_resolution(resolution);
1419                         resolution = tmp;
1420                 }
1421         }
1422         free((void*)capability);
1423         capability = NULL;
1424 }
1425
1426 static void __ps_free_allowed(allowed_x *allowed)
1427 {
1428         if (allowed == NULL)
1429                 return;
1430         if (allowed->name) {
1431                 free((void *)allowed->name);
1432                 allowed->name = NULL;
1433         }
1434         if (allowed->text) {
1435                 free((void *)allowed->text);
1436                 allowed->text = NULL;
1437         }
1438         free((void*)allowed);
1439         allowed = NULL;
1440 }
1441
1442 static void __ps_free_request(request_x *request)
1443 {
1444         if (request == NULL)
1445                 return;
1446         if (request->text) {
1447                 free((void *)request->text);
1448                 request->text = NULL;
1449         }
1450         free((void*)request);
1451         request = NULL;
1452 }
1453
1454 static void __ps_free_datacontrol(datacontrol_x *datacontrol)
1455 {
1456         if (datacontrol == NULL)
1457                 return;
1458         if (datacontrol->providerid) {
1459                 free((void *)datacontrol->providerid);
1460                 datacontrol->providerid = NULL;
1461         }
1462         /*Free Capability*/
1463         if (datacontrol->capability) {
1464                 capability_x *capability = datacontrol->capability;
1465                 capability_x *tmp = NULL;
1466                 while(capability != NULL) {
1467                         tmp = capability->next;
1468                         __ps_free_capability(capability);
1469                         capability = tmp;
1470                 }
1471         }
1472         free((void*)datacontrol);
1473         datacontrol = NULL;
1474 }
1475
1476 static void __ps_free_launchconditions(launchconditions_x *launchconditions)
1477 {
1478         if (launchconditions == NULL)
1479                 return;
1480         if (launchconditions->text) {
1481                 free((void *)launchconditions->text);
1482                 launchconditions->text = NULL;
1483         }
1484         /*Free Condition*/
1485         if (launchconditions->condition) {
1486                 condition_x *condition = launchconditions->condition;
1487                 condition_x *tmp = NULL;
1488                 while(condition != NULL) {
1489                         tmp = condition->next;
1490                         __ps_free_condition(condition);
1491                         condition = tmp;
1492                 }
1493         }
1494         free((void*)launchconditions);
1495         launchconditions = NULL;
1496 }
1497
1498 static void __ps_free_appcontrol(appcontrol_x *appcontrol)
1499 {
1500         if (appcontrol == NULL)
1501                 return;
1502         if (appcontrol->text) {
1503                 free((void *)appcontrol->text);
1504                 appcontrol->text = NULL;
1505         }
1506         /*Free Operation*/
1507         if (appcontrol->operation) {
1508                 operation_x *operation = appcontrol->operation;
1509                 operation_x *tmp = NULL;
1510                 while(operation != NULL) {
1511                         tmp = operation->next;
1512                         __ps_free_operation(operation);
1513                         operation = tmp;
1514                 }
1515         }
1516         /*Free Uri*/
1517         if (appcontrol->uri) {
1518                 uri_x *uri = appcontrol->uri;
1519                 uri_x *tmp = NULL;
1520                 while(uri != NULL) {
1521                         tmp = uri->next;
1522                         __ps_free_uri(uri);
1523                         uri = tmp;
1524                 }
1525         }
1526         /*Free Mime*/
1527         if (appcontrol->mime) {
1528                 mime_x *mime = appcontrol->mime;
1529                 mime_x *tmp = NULL;
1530                 while(mime != NULL) {
1531                         tmp = mime->next;
1532                         __ps_free_mime(mime);
1533                         mime = tmp;
1534                 }
1535         }
1536         /*Free subapp*/
1537         if (appcontrol->subapp) {
1538                 subapp_x *subapp = appcontrol->subapp;
1539                 subapp_x *tmp = NULL;
1540                 while(subapp != NULL) {
1541                         tmp = subapp->next;
1542                         __ps_free_subapp(subapp);
1543                         subapp = tmp;
1544                 }
1545         }
1546         free((void*)appcontrol);
1547         appcontrol = NULL;
1548 }
1549
1550 static void __ps_free_appsvc(appsvc_x *appsvc)
1551 {
1552         if (appsvc == NULL)
1553                 return;
1554         if (appsvc->text) {
1555                 free((void *)appsvc->text);
1556                 appsvc->text = NULL;
1557         }
1558         /*Free Operation*/
1559         if (appsvc->operation) {
1560                 operation_x *operation = appsvc->operation;
1561                 operation_x *tmp = NULL;
1562                 while(operation != NULL) {
1563                         tmp = operation->next;
1564                         __ps_free_operation(operation);
1565                         operation = tmp;
1566                 }
1567         }
1568         /*Free Uri*/
1569         if (appsvc->uri) {
1570                 uri_x *uri = appsvc->uri;
1571                 uri_x *tmp = NULL;
1572                 while(uri != NULL) {
1573                         tmp = uri->next;
1574                         __ps_free_uri(uri);
1575                         uri = tmp;
1576                 }
1577         }
1578         /*Free Mime*/
1579         if (appsvc->mime) {
1580                 mime_x *mime = appsvc->mime;
1581                 mime_x *tmp = NULL;
1582                 while(mime != NULL) {
1583                         tmp = mime->next;
1584                         __ps_free_mime(mime);
1585                         mime = tmp;
1586                 }
1587         }
1588         /*Free subapp*/
1589         if (appsvc->subapp) {
1590                 subapp_x *subapp = appsvc->subapp;
1591                 subapp_x *tmp = NULL;
1592                 while(subapp != NULL) {
1593                         tmp = subapp->next;
1594                         __ps_free_subapp(subapp);
1595                         subapp = tmp;
1596                 }
1597         }
1598         free((void*)appsvc);
1599         appsvc = NULL;
1600 }
1601
1602 static void __ps_free_deviceprofile(deviceprofile_x *deviceprofile)
1603 {
1604         return;
1605 }
1606
1607 static void __ps_free_define(define_x *define)
1608 {
1609         if (define == NULL)
1610                 return;
1611         if (define->path) {
1612                 free((void *)define->path);
1613                 define->path = NULL;
1614         }
1615         /*Free Request*/
1616         if (define->request) {
1617                 request_x *request = define->request;
1618                 request_x *tmp = NULL;
1619                 while(request != NULL) {
1620                         tmp = request->next;
1621                         __ps_free_request(request);
1622                         request = tmp;
1623                 }
1624         }
1625         /*Free Allowed*/
1626         if (define->allowed) {
1627                 allowed_x *allowed = define->allowed;
1628                 allowed_x *tmp = NULL;
1629                 while(allowed != NULL) {
1630                         tmp = allowed->next;
1631                         __ps_free_allowed(allowed);
1632                         allowed = tmp;
1633                 }
1634         }
1635         free((void*)define);
1636         define = NULL;
1637 }
1638
1639 static void __ps_free_datashare(datashare_x *datashare)
1640 {
1641         if (datashare == NULL)
1642                 return;
1643         /*Free Define*/
1644         if (datashare->define) {
1645                 define_x *define =  datashare->define;
1646                 define_x *tmp = NULL;
1647                 while(define != NULL) {
1648                         tmp = define->next;
1649                         __ps_free_define(define);
1650                         define = tmp;
1651                 }
1652         }
1653         /*Free Request*/
1654         if (datashare->request) {
1655                 request_x *request = datashare->request;
1656                 request_x *tmp = NULL;
1657                 while(request != NULL) {
1658                         tmp = request->next;
1659                         __ps_free_request(request);
1660                         request = tmp;
1661                 }
1662         }
1663         free((void*)datashare);
1664         datashare = NULL;
1665 }
1666
1667 static void __ps_free_label(label_x *label)
1668 {
1669         if (label == NULL)
1670                 return;
1671         if (label->name) {
1672                 free((void *)label->name);
1673                 label->name = NULL;
1674         }
1675         if (label->text) {
1676                 free((void *)label->text);
1677                 label->text = NULL;
1678         }
1679         if (label->lang) {
1680                 free((void *)label->lang);
1681                 label->lang= NULL;
1682         }
1683         free((void*)label);
1684         label = NULL;
1685 }
1686
1687 static void __ps_free_author(author_x *author)
1688 {
1689         if (author == NULL)
1690                 return;
1691         if (author->email) {
1692                 free((void *)author->email);
1693                 author->email = NULL;
1694         }
1695         if (author->text) {
1696                 free((void *)author->text);
1697                 author->text = NULL;
1698         }
1699         if (author->href) {
1700                 free((void *)author->href);
1701                 author->href = NULL;
1702         }
1703         if (author->lang) {
1704                 free((void *)author->lang);
1705                 author->lang = NULL;
1706         }
1707         free((void*)author);
1708         author = NULL;
1709 }
1710
1711 static void __ps_free_description(description_x *description)
1712 {
1713         if (description == NULL)
1714                 return;
1715         if (description->name) {
1716                 free((void *)description->name);
1717                 description->name = NULL;
1718         }
1719         if (description->text) {
1720                 free((void *)description->text);
1721                 description->text = NULL;
1722         }
1723         if (description->lang) {
1724                 free((void *)description->lang);
1725                 description->lang = NULL;
1726         }
1727         free((void*)description);
1728         description = NULL;
1729 }
1730
1731 static void __ps_free_license(license_x *license)
1732 {
1733         if (license == NULL)
1734                 return;
1735         if (license->text) {
1736                 free((void *)license->text);
1737                 license->text = NULL;
1738         }
1739         if (license->lang) {
1740                 free((void *)license->lang);
1741                 license->lang = NULL;
1742         }
1743         free((void*)license);
1744         license = NULL;
1745 }
1746
1747 static void __ps_free_uiapplication(uiapplication_x *uiapplication)
1748 {
1749         if (uiapplication == NULL)
1750                 return;
1751         if (uiapplication->exec) {
1752                 free((void *)uiapplication->exec);
1753                 uiapplication->exec = NULL;
1754         }
1755         if (uiapplication->appid) {
1756                 free((void *)uiapplication->appid);
1757                 uiapplication->appid = NULL;
1758         }
1759         if (uiapplication->nodisplay) {
1760                 free((void *)uiapplication->nodisplay);
1761                 uiapplication->nodisplay = NULL;
1762         }
1763         if (uiapplication->multiple) {
1764                 free((void *)uiapplication->multiple);
1765                 uiapplication->multiple = NULL;
1766         }
1767         if (uiapplication->type) {
1768                 free((void *)uiapplication->type);
1769                 uiapplication->type = NULL;
1770         }
1771         if (uiapplication->categories) {
1772                 free((void *)uiapplication->categories);
1773                 uiapplication->categories = NULL;
1774         }
1775         if (uiapplication->extraid) {
1776                 free((void *)uiapplication->extraid);
1777                 uiapplication->extraid = NULL;
1778         }
1779         if (uiapplication->taskmanage) {
1780                 free((void *)uiapplication->taskmanage);
1781                 uiapplication->taskmanage = NULL;
1782         }
1783         if (uiapplication->enabled) {
1784                 free((void *)uiapplication->enabled);
1785                 uiapplication->enabled = NULL;
1786         }
1787         if (uiapplication->hwacceleration) {
1788                 free((void *)uiapplication->hwacceleration);
1789                 uiapplication->hwacceleration = NULL;
1790         }
1791         if (uiapplication->screenreader) {
1792                 free((void *)uiapplication->screenreader);
1793                 uiapplication->screenreader = NULL;
1794         }
1795         if (uiapplication->mainapp) {
1796                 free((void *)uiapplication->mainapp);
1797                 uiapplication->mainapp = NULL;
1798         }
1799         if (uiapplication->recentimage) {
1800                 free((void *)uiapplication->recentimage);
1801                 uiapplication->recentimage = NULL;
1802         }
1803         if (uiapplication->package) {
1804                 free((void *)uiapplication->package);
1805                 uiapplication->package = NULL;
1806         }
1807         if (uiapplication->launchcondition) {
1808                 free((void *)uiapplication->launchcondition);
1809                 uiapplication->launchcondition = NULL;
1810         }
1811         /*Free Label*/
1812         if (uiapplication->label) {
1813                 label_x *label = uiapplication->label;
1814                 label_x *tmp = NULL;
1815                 while(label != NULL) {
1816                         tmp = label->next;
1817                         __ps_free_label(label);
1818                         label = tmp;
1819                 }
1820         }
1821         /*Free Icon*/
1822         if (uiapplication->icon) {
1823                 icon_x *icon = uiapplication->icon;
1824                 icon_x *tmp = NULL;
1825                 while(icon != NULL) {
1826                         tmp = icon->next;
1827                         __ps_free_icon(icon);
1828                         icon = tmp;
1829                 }
1830         }
1831         /*Free image*/
1832         if (uiapplication->image) {
1833                 image_x *image = uiapplication->image;
1834                 image_x *tmp = NULL;
1835                 while(image != NULL) {
1836                         tmp = image->next;
1837                         __ps_free_image(image);
1838                         image = tmp;
1839                 }
1840         }
1841         /*Free AppControl*/
1842         if (uiapplication->appcontrol) {
1843                 appcontrol_x *appcontrol = uiapplication->appcontrol;
1844                 appcontrol_x *tmp = NULL;
1845                 while(appcontrol != NULL) {
1846                         tmp = appcontrol->next;
1847                         __ps_free_appcontrol(appcontrol);
1848                         appcontrol = tmp;
1849                 }
1850         }
1851         /*Free LaunchConditions*/
1852         if (uiapplication->launchconditions) {
1853                 launchconditions_x *launchconditions = uiapplication->launchconditions;
1854                 launchconditions_x *tmp = NULL;
1855                 while(launchconditions != NULL) {
1856                         tmp = launchconditions->next;
1857                         __ps_free_launchconditions(launchconditions);
1858                         launchconditions = tmp;
1859                 }
1860         }
1861         /*Free Notification*/
1862         if (uiapplication->notification) {
1863                 notification_x *notification = uiapplication->notification;
1864                 notification_x *tmp = NULL;
1865                 while(notification != NULL) {
1866                         tmp = notification->next;
1867                         __ps_free_notification(notification);
1868                         notification = tmp;
1869                 }
1870         }
1871         /*Free DataShare*/
1872         if (uiapplication->datashare) {
1873                 datashare_x *datashare = uiapplication->datashare;
1874                 datashare_x *tmp = NULL;
1875                 while(datashare != NULL) {
1876                         tmp = datashare->next;
1877                         __ps_free_datashare(datashare);
1878                         datashare = tmp;
1879                 }
1880         }
1881         /*Free AppSvc*/
1882         if (uiapplication->appsvc) {
1883                 appsvc_x *appsvc = uiapplication->appsvc;
1884                 appsvc_x *tmp = NULL;
1885                 while(appsvc != NULL) {
1886                         tmp = appsvc->next;
1887                         __ps_free_appsvc(appsvc);
1888                         appsvc = tmp;
1889                 }
1890         }
1891         /*Free Category*/
1892         if (uiapplication->category) {
1893                 category_x *category = uiapplication->category;
1894                 category_x *tmp = NULL;
1895                 while(category != NULL) {
1896                         tmp = category->next;
1897                         __ps_free_category(category);
1898                         category = tmp;
1899                 }
1900         }
1901         /*Free Metadata*/
1902         if (uiapplication->metadata) {
1903                 metadata_x *metadata = uiapplication->metadata;
1904                 metadata_x *tmp = NULL;
1905                 while(metadata != NULL) {
1906                         tmp = metadata->next;
1907                         __ps_free_metadata(metadata);
1908                         metadata = tmp;
1909                 }
1910         }
1911         /*Free permission*/
1912         if (uiapplication->permission) {
1913                 permission_x *permission = uiapplication->permission;
1914                 permission_x *tmp = NULL;
1915                 while(permission != NULL) {
1916                         tmp = permission->next;
1917                         __ps_free_permission(permission);
1918                         permission = tmp;
1919                 }
1920         }
1921         /* _PRODUCT_LAUNCHING_ENHANCED_ START */
1922         if (uiapplication->indicatordisplay) {
1923                 free((void *)uiapplication->indicatordisplay);
1924                 uiapplication->indicatordisplay = NULL;
1925         }
1926         if (uiapplication->portraitimg) {
1927                 free((void *)uiapplication->portraitimg);
1928                 uiapplication->portraitimg = NULL;
1929         }
1930         if (uiapplication->landscapeimg) {
1931                 free((void *)uiapplication->landscapeimg);
1932                 uiapplication->landscapeimg = NULL;
1933         }
1934         /* _PRODUCT_LAUNCHING_ENHANCED_ END */
1935         if (uiapplication->guestmode_visibility) {
1936                 free((void *)uiapplication->guestmode_visibility);
1937                 uiapplication->guestmode_visibility = NULL;
1938         }
1939         if (uiapplication->app_component) {
1940                 free((void *)uiapplication->app_component);
1941                 uiapplication->app_component = NULL;
1942         }
1943         if (uiapplication->permission_type) {
1944                 free((void *)uiapplication->permission_type);
1945                 uiapplication->permission_type = NULL;
1946         }
1947         if (uiapplication->component_type) {
1948                 free((void *)uiapplication->component_type);
1949                 uiapplication->component_type = NULL;
1950         }
1951         if (uiapplication->preload) {
1952                 free((void *)uiapplication->preload);
1953                 uiapplication->preload = NULL;
1954         }
1955         if (uiapplication->submode) {
1956                 free((void *)uiapplication->submode);
1957                 uiapplication->submode = NULL;
1958         }
1959         if (uiapplication->submode_mainid) {
1960                 free((void *)uiapplication->submode_mainid);
1961                 uiapplication->submode_mainid = NULL;
1962         }
1963
1964         free((void*)uiapplication);
1965         uiapplication = NULL;
1966 }
1967
1968 static void __ps_free_serviceapplication(serviceapplication_x *serviceapplication)
1969 {
1970         if (serviceapplication == NULL)
1971                 return;
1972         if (serviceapplication->exec) {
1973                 free((void *)serviceapplication->exec);
1974                 serviceapplication->exec = NULL;
1975         }
1976         if (serviceapplication->appid) {
1977                 free((void *)serviceapplication->appid);
1978                 serviceapplication->appid = NULL;
1979         }
1980         if (serviceapplication->onboot) {
1981                 free((void *)serviceapplication->onboot);
1982                 serviceapplication->onboot = NULL;
1983         }
1984         if (serviceapplication->autorestart) {
1985                 free((void *)serviceapplication->autorestart);
1986                 serviceapplication->autorestart = NULL;
1987         }
1988         if (serviceapplication->type) {
1989                 free((void *)serviceapplication->type);
1990                 serviceapplication->type = NULL;
1991         }
1992         if (serviceapplication->enabled) {
1993                 free((void *)serviceapplication->enabled);
1994                 serviceapplication->enabled = NULL;
1995         }
1996         if (serviceapplication->package) {
1997                 free((void *)serviceapplication->package);
1998                 serviceapplication->package = NULL;
1999         }
2000         if (serviceapplication->permission_type) {
2001                 free((void *)serviceapplication->permission_type);
2002                 serviceapplication->permission_type = NULL;
2003         }
2004         /*Free Label*/
2005         if (serviceapplication->label) {
2006                 label_x *label = serviceapplication->label;
2007                 label_x *tmp = NULL;
2008                 while(label != NULL) {
2009                         tmp = label->next;
2010                         __ps_free_label(label);
2011                         label = tmp;
2012                 }
2013         }
2014         /*Free Icon*/
2015         if (serviceapplication->icon) {
2016                 icon_x *icon = serviceapplication->icon;
2017                 icon_x *tmp = NULL;
2018                 while(icon != NULL) {
2019                         tmp = icon->next;
2020                         __ps_free_icon(icon);
2021                         icon = tmp;
2022                 }
2023         }
2024         /*Free AppControl*/
2025         if (serviceapplication->appcontrol) {
2026                 appcontrol_x *appcontrol = serviceapplication->appcontrol;
2027                 appcontrol_x *tmp = NULL;
2028                 while(appcontrol != NULL) {
2029                         tmp = appcontrol->next;
2030                         __ps_free_appcontrol(appcontrol);
2031                         appcontrol = tmp;
2032                 }
2033         }
2034         /*Free DataControl*/
2035         if (serviceapplication->datacontrol) {
2036                 datacontrol_x *datacontrol = serviceapplication->datacontrol;
2037                 datacontrol_x *tmp = NULL;
2038                 while(datacontrol != NULL) {
2039                         tmp = datacontrol->next;
2040                         __ps_free_datacontrol(datacontrol);
2041                         datacontrol = tmp;
2042                 }
2043         }
2044         /*Free LaunchConditions*/
2045         if (serviceapplication->launchconditions) {
2046                 launchconditions_x *launchconditions = serviceapplication->launchconditions;
2047                 launchconditions_x *tmp = NULL;
2048                 while(launchconditions != NULL) {
2049                         tmp = launchconditions->next;
2050                         __ps_free_launchconditions(launchconditions);
2051                         launchconditions = tmp;
2052                 }
2053         }
2054         /*Free Notification*/
2055         if (serviceapplication->notification) {
2056                 notification_x *notification = serviceapplication->notification;
2057                 notification_x *tmp = NULL;
2058                 while(notification != NULL) {
2059                         tmp = notification->next;
2060                         __ps_free_notification(notification);
2061                         notification = tmp;
2062                 }
2063         }
2064         /*Free DataShare*/
2065         if (serviceapplication->datashare) {
2066                 datashare_x *datashare = serviceapplication->datashare;
2067                 datashare_x *tmp = NULL;
2068                 while(datashare != NULL) {
2069                         tmp = datashare->next;
2070                         __ps_free_datashare(datashare);
2071                         datashare = tmp;
2072                 }
2073         }
2074         /*Free AppSvc*/
2075         if (serviceapplication->appsvc) {
2076                 appsvc_x *appsvc = serviceapplication->appsvc;
2077                 appsvc_x *tmp = NULL;
2078                 while(appsvc != NULL) {
2079                         tmp = appsvc->next;
2080                         __ps_free_appsvc(appsvc);
2081                         appsvc = tmp;
2082                 }
2083         }
2084         /*Free Category*/
2085         if (serviceapplication->category) {
2086                 category_x *category = serviceapplication->category;
2087                 category_x *tmp = NULL;
2088                 while(category != NULL) {
2089                         tmp = category->next;
2090                         __ps_free_category(category);
2091                         category = tmp;
2092                 }
2093         }
2094         /*Free Metadata*/
2095         if (serviceapplication->metadata) {
2096                 metadata_x *metadata = serviceapplication->metadata;
2097                 metadata_x *tmp = NULL;
2098                 while(metadata != NULL) {
2099                         tmp = metadata->next;
2100                         __ps_free_metadata(metadata);
2101                         metadata = tmp;
2102                 }
2103         }
2104         /*Free permission*/
2105         if (serviceapplication->permission) {
2106                 permission_x *permission = serviceapplication->permission;
2107                 permission_x *tmp = NULL;
2108                 while(permission != NULL) {
2109                         tmp = permission->next;
2110                         __ps_free_permission(permission);
2111                         permission = tmp;
2112                 }
2113         }
2114         free((void*)serviceapplication);
2115         serviceapplication = NULL;
2116 }
2117
2118 static void __ps_free_font(font_x *font)
2119 {
2120         if (font == NULL)
2121                 return;
2122         if (font->name) {
2123                 free((void *)font->name);
2124                 font->name = NULL;
2125         }
2126         if (font->text) {
2127                 free((void *)font->text);
2128                 font->text = NULL;
2129         }
2130         free((void*)font);
2131         font = NULL;
2132 }
2133
2134 static void __ps_free_theme(theme_x *theme)
2135 {
2136         if (theme == NULL)
2137                 return;
2138         if (theme->name) {
2139                 free((void *)theme->name);
2140                 theme->name = NULL;
2141         }
2142         if (theme->text) {
2143                 free((void *)theme->text);
2144                 theme->text = NULL;
2145         }
2146         free((void*)theme);
2147         theme = NULL;
2148 }
2149
2150 static void __ps_free_daemon(daemon_x *daemon)
2151 {
2152         if (daemon == NULL)
2153                 return;
2154         if (daemon->name) {
2155                 free((void *)daemon->name);
2156                 daemon->name = NULL;
2157         }
2158         if (daemon->text) {
2159                 free((void *)daemon->text);
2160                 daemon->text = NULL;
2161         }
2162         free((void*)daemon);
2163         daemon = NULL;
2164 }
2165
2166 static void __ps_free_ime(ime_x *ime)
2167 {
2168         if (ime == NULL)
2169                 return;
2170         if (ime->name) {
2171                 free((void *)ime->name);
2172                 ime->name = NULL;
2173         }
2174         if (ime->text) {
2175                 free((void *)ime->text);
2176                 ime->text = NULL;
2177         }
2178         free((void*)ime);
2179         ime = NULL;
2180 }
2181
2182 int __ps_process_mdparser(manifest_x *mfx, ACTION_TYPE action)
2183 {
2184         int ret = -1;
2185         FILE *fp = NULL;
2186         char md_key[PKG_STRING_LEN_MAX] = { 0 };
2187
2188         fp = fopen(MDPARSER_LIST, "r");
2189         if (fp == NULL) {
2190                 DBG("no preload list\n");
2191                 return -1;
2192         }
2193
2194         while (fgets(md_key, sizeof(md_key), fp) != NULL) {
2195                 __str_trim(md_key);
2196                 ret = __run_mdparser_prestep(mfx, md_key, action);
2197
2198                 memset(md_key, 0x00, sizeof(md_key));
2199         }
2200
2201         if (fp != NULL)
2202                 fclose(fp);
2203
2204         return 0;
2205 }
2206
2207 int __ps_process_category_parser(manifest_x *mfx, ACTION_TYPE action)
2208 {
2209         int ret = -1;
2210         FILE *fp = NULL;
2211         char category_key[PKG_STRING_LEN_MAX] = { 0 };
2212
2213         fp = fopen(CATEGORY_PARSER_LIST, "r");
2214         if (fp == NULL) {
2215                 DBG("no category parser list\n");
2216                 return -1;
2217         }
2218
2219         while (fgets(category_key, sizeof(category_key), fp) != NULL) {
2220                 __str_trim(category_key);
2221                 ret = __run_category_parser_prestep(mfx, category_key, action);
2222
2223                 memset(category_key, 0x00, sizeof(category_key));
2224         }
2225
2226         if (fp != NULL)
2227                 fclose(fp);
2228
2229         return 0;
2230 }
2231
2232 static int __ps_process_allowed(xmlTextReaderPtr reader, allowed_x *allowed)
2233 {
2234         xmlTextReaderRead(reader);
2235         if (xmlTextReaderValue(reader))
2236                 allowed->text = ASCII(xmlTextReaderValue(reader));
2237         return 0;
2238 }
2239
2240 static int __ps_process_operation(xmlTextReaderPtr reader, operation_x *operation)
2241 {
2242         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2243                 operation->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2244 /* Text does not exist. Only attribute exists
2245         xmlTextReaderRead(reader);
2246         if (xmlTextReaderValue(reader))
2247                 operation->text = ASCII(xmlTextReaderValue(reader));
2248 */
2249         return 0;
2250 }
2251
2252 static int __ps_process_uri(xmlTextReaderPtr reader, uri_x *uri)
2253 {
2254         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2255                 uri->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2256 /* Text does not exist. Only attribute exists
2257         xmlTextReaderRead(reader);
2258         if (xmlTextReaderValue(reader))
2259                 uri->text = ASCII(xmlTextReaderValue(reader));
2260 */
2261         return 0;
2262 }
2263
2264 static int __ps_process_mime(xmlTextReaderPtr reader, mime_x *mime)
2265 {
2266         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2267                 mime->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2268 /* Text does not exist. Only attribute exists
2269         xmlTextReaderRead(reader);
2270         if (xmlTextReaderValue(reader))
2271                 mime->text = ASCII(xmlTextReaderValue(reader));
2272 */
2273         return 0;
2274 }
2275
2276 static int __ps_process_subapp(xmlTextReaderPtr reader, subapp_x *subapp)
2277 {
2278         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2279                 subapp->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2280 /* Text does not exist. Only attribute exists
2281         xmlTextReaderRead(reader);
2282         if (xmlTextReaderValue(reader))
2283                 mime->text = ASCII(xmlTextReaderValue(reader));
2284 */
2285         return 0;
2286 }
2287
2288 static int __ps_process_condition(xmlTextReaderPtr reader, condition_x *condition)
2289 {
2290         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2291                 condition->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2292         xmlTextReaderRead(reader);
2293         if (xmlTextReaderValue(reader))
2294                 condition->text = ASCII(xmlTextReaderValue(reader));
2295         return 0;
2296 }
2297
2298 static int __ps_process_notification(xmlTextReaderPtr reader, notification_x *notification)
2299 {
2300         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2301                 notification->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2302         xmlTextReaderRead(reader);
2303         if (xmlTextReaderValue(reader))
2304                 notification->text = ASCII(xmlTextReaderValue(reader));
2305         return 0;
2306 }
2307
2308 static int __ps_process_category(xmlTextReaderPtr reader, category_x *category)
2309 {
2310         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2311                 category->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2312         return 0;
2313 }
2314
2315 static int __ps_process_privilege(xmlTextReaderPtr reader, privilege_x *privilege)
2316 {
2317         xmlTextReaderRead(reader);
2318         if (xmlTextReaderValue(reader)) {
2319                 privilege->text = ASCII(xmlTextReaderValue(reader));
2320         }
2321         return 0;
2322 }
2323
2324 static int __ps_process_metadata(xmlTextReaderPtr reader, metadata_x *metadata)
2325 {
2326         if (xmlTextReaderGetAttribute(reader, XMLCHAR("key")))
2327                 metadata->key = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("key")));
2328         if (xmlTextReaderGetAttribute(reader, XMLCHAR("value")))
2329                 metadata->value = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("value")));
2330         return 0;
2331 }
2332
2333 static int __ps_process_permission(xmlTextReaderPtr reader, permission_x *permission)
2334 {
2335         if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
2336                 permission->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
2337
2338         xmlTextReaderRead(reader);
2339         if (xmlTextReaderValue(reader))
2340                 permission->value = ASCII(xmlTextReaderValue(reader));
2341         return 0;
2342 }
2343
2344 static int __ps_process_compatibility(xmlTextReaderPtr reader, compatibility_x *compatibility)
2345 {
2346         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2347                 compatibility->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2348         xmlTextReaderRead(reader);
2349         if (xmlTextReaderValue(reader))
2350                 compatibility->text = ASCII(xmlTextReaderValue(reader));
2351         return 0;
2352 }
2353
2354 static int __ps_process_resolution(xmlTextReaderPtr reader, resolution_x *resolution)
2355 {
2356         if (xmlTextReaderGetAttribute(reader, XMLCHAR("mime-type")))
2357                 resolution->mimetype = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("mime-type")));
2358         if (xmlTextReaderGetAttribute(reader, XMLCHAR("uri-scheme")))
2359                 resolution->urischeme = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("uri-scheme")));
2360         return 0;
2361 }
2362
2363 static int __ps_process_request(xmlTextReaderPtr reader, request_x *request)
2364 {
2365         xmlTextReaderRead(reader);
2366         if (xmlTextReaderValue(reader))
2367                 request->text = ASCII(xmlTextReaderValue(reader));
2368         return 0;
2369 }
2370
2371 static int __ps_process_define(xmlTextReaderPtr reader, define_x *define)
2372 {
2373         const xmlChar *node;
2374         int ret = -1;
2375         int depth = -1;
2376         allowed_x *tmp1 = NULL;
2377         request_x *tmp2 = NULL;
2378
2379         if (xmlTextReaderGetAttribute(reader, XMLCHAR("path")))
2380                 define->path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("path")));
2381
2382         depth = xmlTextReaderDepth(reader);
2383         while ((ret = __next_child_element(reader, depth))) {
2384                 node = xmlTextReaderConstName(reader);
2385                 if (!node) {
2386                         DBG("xmlTextReaderConstName value is NULL\n");
2387                         return -1;
2388                 }
2389
2390                 if (!strcmp(ASCII(node), "allowed")) {
2391                         allowed_x *allowed= malloc(sizeof(allowed_x));
2392                         if (allowed == NULL) {
2393                                 DBG("Malloc Failed\n");
2394                                 return -1;
2395                         }
2396                         memset(allowed, '\0', sizeof(allowed_x));
2397                         LISTADD(define->allowed, allowed);
2398                         ret = __ps_process_allowed(reader, allowed);
2399                 } else if (!strcmp(ASCII(node), "request")) {
2400                         request_x *request = malloc(sizeof(request_x));
2401                         if (request == NULL) {
2402                                 DBG("Malloc Failed\n");
2403                                 return -1;
2404                         }
2405                         memset(request, '\0', sizeof(request_x));
2406                         LISTADD(define->request, request);
2407                         ret = __ps_process_request(reader, request);
2408                 } else
2409                         return -1;
2410                 if (ret < 0) {
2411                         DBG("Processing define failed\n");
2412                         return ret;
2413                 }
2414         }
2415         if (define->allowed) {
2416                 LISTHEAD(define->allowed, tmp1);
2417                 define->allowed = tmp1;
2418         }
2419         if (define->request) {
2420                 LISTHEAD(define->request, tmp2);
2421                 define->request = tmp2;
2422         }
2423         return ret;
2424 }
2425
2426 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol)
2427 {
2428         const xmlChar *node;
2429         int ret = -1;
2430         int depth = -1;
2431         operation_x *tmp1 = NULL;
2432         uri_x *tmp2 = NULL;
2433         mime_x *tmp3 = NULL;
2434         subapp_x *tmp4 = NULL;
2435
2436         depth = xmlTextReaderDepth(reader);
2437         while ((ret = __next_child_element(reader, depth))) {
2438                 node = xmlTextReaderConstName(reader);
2439                 if (!node) {
2440                         DBG("xmlTextReaderConstName value is NULL\n");
2441                         return -1;
2442                 }
2443
2444                 if (!strcmp(ASCII(node), "operation")) {
2445                         operation_x *operation = malloc(sizeof(operation_x));
2446                         if (operation == NULL) {
2447                                 DBG("Malloc Failed\n");
2448                                 return -1;
2449                         }
2450                         memset(operation, '\0', sizeof(operation_x));
2451                         LISTADD(appcontrol->operation, operation);
2452                         ret = __ps_process_operation(reader, operation);
2453                         DBG("operation processing\n");
2454                 } else if (!strcmp(ASCII(node), "uri")) {
2455                         uri_x *uri= malloc(sizeof(uri_x));
2456                         if (uri == NULL) {
2457                                 DBG("Malloc Failed\n");
2458                                 return -1;
2459                         }
2460                         memset(uri, '\0', sizeof(uri_x));
2461                         LISTADD(appcontrol->uri, uri);
2462                         ret = __ps_process_uri(reader, uri);
2463                         DBG("uri processing\n");
2464                 } else if (!strcmp(ASCII(node), "mime")) {
2465                         mime_x *mime = malloc(sizeof(mime_x));
2466                         if (mime == NULL) {
2467                                 DBG("Malloc Failed\n");
2468                                 return -1;
2469                         }
2470                         memset(mime, '\0', sizeof(mime_x));
2471                         LISTADD(appcontrol->mime, mime);
2472                         ret = __ps_process_mime(reader, mime);
2473                         DBG("mime processing\n");
2474                 } else if (!strcmp(ASCII(node), "subapp")) {
2475                         subapp_x *subapp = malloc(sizeof(subapp_x));
2476                         if (subapp == NULL) {
2477                                 DBG("Malloc Failed\n");
2478                                 return -1;
2479                         }
2480                         memset(subapp, '\0', sizeof(subapp_x));
2481                         LISTADD(appcontrol->subapp, subapp);
2482                         ret = __ps_process_subapp(reader, subapp);
2483                         DBG("subapp processing\n");
2484                 } else
2485                         return -1;
2486                 if (ret < 0) {
2487                         DBG("Processing appcontrol failed\n");
2488                         return ret;
2489                 }
2490         }
2491         if (appcontrol->operation) {
2492                 LISTHEAD(appcontrol->operation, tmp1);
2493                 appcontrol->operation = tmp1;
2494         }
2495         if (appcontrol->uri) {
2496                 LISTHEAD(appcontrol->uri, tmp2);
2497                 appcontrol->uri = tmp2;
2498         }
2499         if (appcontrol->mime) {
2500                 LISTHEAD(appcontrol->mime, tmp3);
2501                 appcontrol->mime = tmp3;
2502         }
2503         if (appcontrol->subapp) {
2504                 LISTHEAD(appcontrol->subapp, tmp4);
2505                 appcontrol->subapp = tmp4;
2506         }
2507
2508         xmlTextReaderRead(reader);
2509         if (xmlTextReaderValue(reader))
2510                 appcontrol->text = ASCII(xmlTextReaderValue(reader));
2511
2512         return ret;
2513 }
2514
2515 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc)
2516 {
2517         const xmlChar *node;
2518         int ret = -1;
2519         int depth = -1;
2520         operation_x *tmp1 = NULL;
2521         uri_x *tmp2 = NULL;
2522         mime_x *tmp3 = NULL;
2523         subapp_x *tmp4 = NULL;
2524
2525         depth = xmlTextReaderDepth(reader);
2526         while ((ret = __next_child_element(reader, depth))) {
2527                 node = xmlTextReaderConstName(reader);
2528                 if (!node) {
2529                         DBG("xmlTextReaderConstName value is NULL\n");
2530                         return -1;
2531                 }
2532
2533                 if (!strcmp(ASCII(node), "operation")) {
2534                         operation_x *operation = malloc(sizeof(operation_x));
2535                         if (operation == NULL) {
2536                                 DBG("Malloc Failed\n");
2537                                 return -1;
2538                         }
2539                         memset(operation, '\0', sizeof(operation_x));
2540                         LISTADD(appsvc->operation, operation);
2541                         ret = __ps_process_operation(reader, operation);
2542                         DBG("operation processing\n");
2543                 } else if (!strcmp(ASCII(node), "uri")) {
2544                         uri_x *uri= malloc(sizeof(uri_x));
2545                         if (uri == NULL) {
2546                                 DBG("Malloc Failed\n");
2547                                 return -1;
2548                         }
2549                         memset(uri, '\0', sizeof(uri_x));
2550                         LISTADD(appsvc->uri, uri);
2551                         ret = __ps_process_uri(reader, uri);
2552                         DBG("uri processing\n");
2553                 } else if (!strcmp(ASCII(node), "mime")) {
2554                         mime_x *mime = malloc(sizeof(mime_x));
2555                         if (mime == NULL) {
2556                                 DBG("Malloc Failed\n");
2557                                 return -1;
2558                         }
2559                         memset(mime, '\0', sizeof(mime_x));
2560                         LISTADD(appsvc->mime, mime);
2561                         ret = __ps_process_mime(reader, mime);
2562                         DBG("mime processing\n");
2563                 } else if (!strcmp(ASCII(node), "subapp")) {
2564                         subapp_x *subapp = malloc(sizeof(subapp_x));
2565                         if (subapp == NULL) {
2566                                 DBG("Malloc Failed\n");
2567                                 return -1;
2568                         }
2569                         memset(subapp, '\0', sizeof(subapp_x));
2570                         LISTADD(appsvc->subapp, subapp);
2571                         ret = __ps_process_subapp(reader, subapp);
2572                         DBG("subapp processing\n");
2573                 } else
2574                         return -1;
2575                 if (ret < 0) {
2576                         DBG("Processing appsvc failed\n");
2577                         return ret;
2578                 }
2579         }
2580         if (appsvc->operation) {
2581                 LISTHEAD(appsvc->operation, tmp1);
2582                 appsvc->operation = tmp1;
2583         }
2584         if (appsvc->uri) {
2585                 LISTHEAD(appsvc->uri, tmp2);
2586                 appsvc->uri = tmp2;
2587         }
2588         if (appsvc->mime) {
2589                 LISTHEAD(appsvc->mime, tmp3);
2590                 appsvc->mime = tmp3;
2591         }
2592         if (appsvc->subapp) {
2593                 LISTHEAD(appsvc->subapp, tmp4);
2594                 appsvc->subapp = tmp4;
2595         }
2596
2597         xmlTextReaderRead(reader);
2598         if (xmlTextReaderValue(reader))
2599                 appsvc->text = ASCII(xmlTextReaderValue(reader));
2600
2601         return ret;
2602 }
2603
2604
2605 static int __ps_process_privileges(xmlTextReaderPtr reader, privileges_x *privileges)
2606 {
2607         const xmlChar *node;
2608         int ret = -1;
2609         int depth = -1;
2610         privilege_x *tmp1 = NULL;
2611
2612         depth = xmlTextReaderDepth(reader);
2613         while ((ret = __next_child_element(reader, depth))) {
2614                 node = xmlTextReaderConstName(reader);
2615                 if (!node) {
2616                         DBG("xmlTextReaderConstName value is NULL\n");
2617                         return -1;
2618                 }
2619
2620                 if (strcmp(ASCII(node), "privilege") == 0) {
2621                         privilege_x *privilege = malloc(sizeof(privilege_x));
2622                         if (privilege == NULL) {
2623                                 DBG("Malloc Failed\n");
2624                                 return -1;
2625                         }
2626                         memset(privilege, '\0', sizeof(privilege_x));
2627                         LISTADD(privileges->privilege, privilege);
2628                         ret = __ps_process_privilege(reader, privilege);
2629                 } else
2630                         return -1;
2631                 if (ret < 0) {
2632                         DBG("Processing privileges failed\n");
2633                         return ret;
2634                 }
2635         }
2636         if (privileges->privilege) {
2637                 LISTHEAD(privileges->privilege, tmp1);
2638                 privileges->privilege = tmp1;
2639         }
2640         return ret;
2641 }
2642
2643 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions)
2644 {
2645         const xmlChar *node;
2646         int ret = -1;
2647         int depth = -1;
2648         condition_x *tmp1 = NULL;
2649
2650         depth = xmlTextReaderDepth(reader);
2651         while ((ret = __next_child_element(reader, depth))) {
2652                 node = xmlTextReaderConstName(reader);
2653                 if (!node) {
2654                         DBG("xmlTextReaderConstName value is NULL\n");
2655                         return -1;
2656                 }
2657
2658                 if (strcmp(ASCII(node), "condition") == 0) {
2659                         condition_x *condition = malloc(sizeof(condition_x));
2660                         if (condition == NULL) {
2661                                 DBG("Malloc Failed\n");
2662                                 return -1;
2663                         }
2664                         memset(condition, '\0', sizeof(condition_x));
2665                         LISTADD(launchconditions->condition, condition);
2666                         ret = __ps_process_condition(reader, condition);
2667                 } else
2668                         return -1;
2669                 if (ret < 0) {
2670                         DBG("Processing launchconditions failed\n");
2671                         return ret;
2672                 }
2673         }
2674         if (launchconditions->condition) {
2675                 LISTHEAD(launchconditions->condition, tmp1);
2676                 launchconditions->condition = tmp1;
2677         }
2678
2679         xmlTextReaderRead(reader);
2680         if (xmlTextReaderValue(reader))
2681                 launchconditions->text = ASCII(xmlTextReaderValue(reader));
2682
2683         return ret;
2684 }
2685
2686 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare)
2687 {
2688         const xmlChar *node;
2689         int ret = -1;
2690         int depth = -1;
2691         define_x *tmp1 = NULL;
2692         request_x *tmp2 = NULL;
2693         depth = xmlTextReaderDepth(reader);
2694         while ((ret = __next_child_element(reader, depth))) {
2695                 node = xmlTextReaderConstName(reader);
2696                 if (!node) {
2697                         DBG("xmlTextReaderConstName value is NULL\n");
2698                         return -1;
2699                 }
2700
2701                 if (!strcmp(ASCII(node), "define")) {
2702                         define_x *define= malloc(sizeof(define_x));
2703                         if (define == NULL) {
2704                                 DBG("Malloc Failed\n");
2705                                 return -1;
2706                         }
2707                         memset(define, '\0', sizeof(define_x));
2708                         LISTADD(datashare->define, define);
2709                         ret = __ps_process_define(reader, define);
2710                 } else if (!strcmp(ASCII(node), "request")) {
2711                         request_x *request= malloc(sizeof(request_x));
2712                         if (request == NULL) {
2713                                 DBG("Malloc Failed\n");
2714                                 return -1;
2715                         }
2716                         memset(request, '\0', sizeof(request_x));
2717                         LISTADD(datashare->request, request);
2718                         ret = __ps_process_request(reader, request);
2719                 } else
2720                         return -1;
2721                 if (ret < 0) {
2722                         DBG("Processing data-share failed\n");
2723                         return ret;
2724                 }
2725         }
2726         if (datashare->define) {
2727                 LISTHEAD(datashare->define, tmp1);
2728                 datashare->define = tmp1;
2729         }
2730         if (datashare->request) {
2731                 LISTHEAD(datashare->request, tmp2);
2732                 datashare->request = tmp2;
2733         }
2734         return ret;
2735 }
2736
2737 static char*
2738 __get_icon_with_path(const char* icon)
2739 {
2740         if (!icon)
2741                 return NULL;
2742
2743         if (index(icon, '/') == NULL) {
2744                 char* theme = NULL;
2745                 char* icon_with_path = NULL;
2746                 int len;
2747
2748                 if (!package)
2749                         return NULL;
2750
2751                 theme = vconf_get_str("db/setting/theme");
2752                 if (!theme) {
2753                         theme = strdup("default");
2754                         if(!theme) {
2755                                 return NULL;
2756                         }
2757                 }
2758
2759                 len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
2760                 icon_with_path = malloc(len);
2761                 if(icon_with_path == NULL) {
2762                         DBG("(icon_with_path == NULL) return\n");
2763                         free(theme);
2764                         return NULL;
2765                 }
2766
2767                 memset(icon_with_path, 0, len);
2768
2769                 snprintf(icon_with_path, len, "/opt/share/icons/%s/small/%s", theme, icon);
2770                 do {
2771                         if (access(icon_with_path, R_OK) == 0) break;
2772                         snprintf(icon_with_path, len, "/usr/share/icons/%s/small/%s", theme, icon);
2773                         if (access(icon_with_path, R_OK) == 0) break;
2774                         DBG("cannot find icon %s", icon_with_path);
2775                         snprintf(icon_with_path, len,"/opt/share/icons/default/small/%s", icon);
2776                         if (access(icon_with_path, R_OK) == 0) break;
2777                         snprintf(icon_with_path, len, "/usr/share/icons/default/small/%s", icon);
2778                         if (access(icon_with_path, R_OK) == 0) break;
2779
2780                         /* icon path is going to be moved intto the app directory */
2781                         DBGE("icon file must be moved to %s", icon_with_path);
2782                         snprintf(icon_with_path, len, "/opt/apps/%s/res/icons/%s/small/%s", package, theme, icon);
2783                         if (access(icon_with_path, R_OK) == 0) break;
2784                         snprintf(icon_with_path, len, "/usr/apps/%s/res/icons/%s/small/%s", package, theme, icon);
2785                         if (access(icon_with_path, R_OK) == 0) break;
2786                         DBG("cannot find icon %s", icon_with_path);
2787                         snprintf(icon_with_path, len, "/opt/apps/%s/res/icons/default/small/%s", package, icon);
2788                         if (access(icon_with_path, R_OK) == 0) break;
2789                         snprintf(icon_with_path, len, "/usr/apps/%s/res/icons/default/small/%s", package, icon);
2790                         if (access(icon_with_path, R_OK) == 0) break;
2791                         snprintf(icon_with_path, len, "/usr/ug/res/images/%s/%s", package, icon);
2792                         if (access(icon_with_path, R_OK) == 0) break;
2793                 } while (0);
2794
2795                 free(theme);
2796
2797                 DBG("Icon path : %s ---> %s", icon, icon_with_path);
2798
2799                 return icon_with_path;
2800         } else {
2801                 char* confirmed_icon = NULL;
2802
2803                 confirmed_icon = strdup(icon);
2804                 if (!confirmed_icon)
2805                         return NULL;
2806                 return confirmed_icon;
2807         }
2808 }
2809
2810 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
2811 {
2812         int i = 0;
2813         char delims[] = "=";
2814         char *ret_result = NULL;
2815         char *tag = NULL;
2816
2817         if (tagv == NULL)
2818                 return;
2819
2820         for (tag = strdup(tagv[0]); tag != NULL; ) {
2821                 ret_result = strtok(tag, delims);
2822
2823                 /*check tag :  preload */
2824                 if (strcmp(ret_result, "preload") == 0) {
2825                         ret_result = strtok(NULL, delims);
2826                         if (strcmp(ret_result, "true") == 0) {
2827                                 free((void *)mfx->preload);
2828                                 mfx->preload = strdup("true");
2829                         } else if (strcmp(ret_result, "false") == 0) {
2830                                 free((void *)mfx->preload);
2831                                 mfx->preload = strdup("false");
2832                         }
2833                 /*check tag :  removable*/
2834                 } else if (strcmp(ret_result, "removable") == 0) {
2835                         ret_result = strtok(NULL, delims);
2836                         if (strcmp(ret_result, "true") == 0){
2837                                 free((void *)mfx->removable);
2838                                 mfx->removable = strdup("true");
2839                         } else if (strcmp(ret_result, "false") == 0) {
2840                                 free((void *)mfx->removable);
2841                                 mfx->removable = strdup("false");
2842                         }
2843                 /*check tag :  not matched*/
2844                 } else
2845                         DBG("tag process [%s]is not defined\n", ret_result);
2846
2847                 free(tag);
2848
2849                 /*check next value*/
2850                 if (tagv[++i] != NULL)
2851                         tag = strdup(tagv[i]);
2852                 else {
2853                         DBG("tag process success...\n");
2854                         return;
2855                 }
2856         }
2857 }
2858
2859 static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon)
2860 {
2861         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2862                 icon->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2863         if (xmlTextReaderConstXmlLang(reader)) {
2864                 icon->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2865                 if (icon->lang == NULL)
2866                         icon->lang = strdup(DEFAULT_LOCALE);
2867         } else {
2868                 icon->lang = strdup(DEFAULT_LOCALE);
2869         }
2870         if (xmlTextReaderGetAttribute(reader, XMLCHAR("section")))
2871                 icon->section = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("section")));
2872         if (xmlTextReaderGetAttribute(reader, XMLCHAR("size")))
2873                 icon->size = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("size")));
2874         if (xmlTextReaderGetAttribute(reader, XMLCHAR("resolution")))
2875                 icon->resolution = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("resolution")));
2876         xmlTextReaderRead(reader);
2877         if (xmlTextReaderValue(reader)) {
2878                 const char *text  = ASCII(xmlTextReaderValue(reader));
2879                 if(text) {
2880                         icon->text = (const char *)__get_icon_with_path(text);
2881                         free((void *)text);
2882                 }
2883         }
2884
2885         return 0;
2886 }
2887
2888 static int __ps_process_image(xmlTextReaderPtr reader, image_x *image)
2889 {
2890         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2891                 image->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2892         if (xmlTextReaderConstXmlLang(reader)) {
2893                 image->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2894                 if (image->lang == NULL)
2895                         image->lang = strdup(DEFAULT_LOCALE);
2896         } else {
2897                 image->lang = strdup(DEFAULT_LOCALE);
2898         }
2899         if (xmlTextReaderGetAttribute(reader, XMLCHAR("section")))
2900                 image->section = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("section")));
2901         xmlTextReaderRead(reader);
2902         if (xmlTextReaderValue(reader))
2903                 image->text = ASCII(xmlTextReaderValue(reader));
2904
2905         return 0;
2906 }
2907
2908 static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
2909 {
2910         if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
2911                 label->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
2912         if (xmlTextReaderConstXmlLang(reader)) {
2913                 label->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2914                 if (label->lang == NULL)
2915                         label->lang = strdup(DEFAULT_LOCALE);
2916         } else {
2917                 label->lang = strdup(DEFAULT_LOCALE);
2918         }
2919         xmlTextReaderRead(reader);
2920         if (xmlTextReaderValue(reader))
2921                 label->text = ASCII(xmlTextReaderValue(reader));
2922
2923 /*      DBG("lable name %s\n", label->name);
2924         DBG("lable lang %s\n", label->lang);
2925         DBG("lable text %s\n", label->text);
2926 */
2927         return 0;
2928
2929 }
2930
2931 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author)
2932 {
2933         if (xmlTextReaderGetAttribute(reader, XMLCHAR("email")))
2934                 author->email = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("email")));
2935         if (xmlTextReaderGetAttribute(reader, XMLCHAR("href")))
2936                 author->href = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("href")));
2937         if (xmlTextReaderConstXmlLang(reader)) {
2938                 author->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2939                 if (author->lang == NULL)
2940                         author->lang = strdup(DEFAULT_LOCALE);
2941         } else {
2942                 author->lang = strdup(DEFAULT_LOCALE);
2943         }
2944         xmlTextReaderRead(reader);
2945         if (xmlTextReaderValue(reader)) {
2946                 const char *text  = ASCII(xmlTextReaderValue(reader));
2947                 if (*text == '\n') {
2948                         author->text = NULL;
2949                         free((void *)text);
2950                         return 0;
2951                 }
2952                 author->text = ASCII(xmlTextReaderValue(reader));
2953         }
2954         return 0;
2955 }
2956
2957 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description)
2958 {
2959         if (xmlTextReaderConstXmlLang(reader)) {
2960                 description->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2961                 if (description->lang == NULL)
2962                         description->lang = strdup(DEFAULT_LOCALE);
2963         } else {
2964                 description->lang = strdup(DEFAULT_LOCALE);
2965         }
2966         xmlTextReaderRead(reader);
2967         if (xmlTextReaderValue(reader)) {
2968                 const char *text  = ASCII(xmlTextReaderValue(reader));
2969                 if (*text == '\n') {
2970                         description->text = NULL;
2971                         free((void *)text);
2972                         return 0;
2973                 }
2974                 description->text = ASCII(xmlTextReaderValue(reader));
2975         }
2976         return 0;
2977 }
2978
2979 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license)
2980 {
2981         if (xmlTextReaderConstXmlLang(reader)) {
2982                 license->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
2983                 if (license->lang == NULL)
2984                         license->lang = strdup(DEFAULT_LOCALE);
2985         } else {
2986                 license->lang = strdup(DEFAULT_LOCALE);
2987         }
2988         xmlTextReaderRead(reader);
2989         if (xmlTextReaderValue(reader))
2990                 license->text = ASCII(xmlTextReaderValue(reader));
2991         return 0;
2992 }
2993
2994 static int __ps_process_capability(xmlTextReaderPtr reader, capability_x *capability)
2995 {
2996         const xmlChar *node;
2997         int ret = -1;
2998         int depth = -1;
2999         resolution_x *tmp1 = NULL;
3000
3001         if (xmlTextReaderGetAttribute(reader, XMLCHAR("operation-id")))
3002                 capability->operationid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("operation-id")));
3003
3004         depth = xmlTextReaderDepth(reader);
3005         while ((ret = __next_child_element(reader, depth))) {
3006                 node = xmlTextReaderConstName(reader);
3007                 if (!node) {
3008                         DBG("xmlTextReaderConstName value is NULL\n");
3009                         return -1;
3010                 }
3011
3012                 if (!strcmp(ASCII(node), "resolution")) {
3013                         resolution_x *resolution = malloc(sizeof(resolution_x));
3014                         if (resolution == NULL) {
3015                                 DBG("Malloc Failed\n");
3016                                 return -1;
3017                         }
3018                         memset(resolution, '\0', sizeof(resolution_x));
3019                         LISTADD(capability->resolution, resolution);
3020                         ret = __ps_process_resolution(reader, resolution);
3021                 } else
3022                         return -1;
3023                 if (ret < 0) {
3024                         DBG("Processing capability failed\n");
3025                         return ret;
3026                 }
3027         }
3028
3029         if (capability->resolution) {
3030                 LISTHEAD(capability->resolution, tmp1);
3031                 capability->resolution = tmp1;
3032         }
3033
3034         return ret;
3035 }
3036
3037 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol)
3038 {
3039         const xmlChar *node;
3040         int ret = -1;
3041         int depth = -1;
3042         capability_x *tmp1 = NULL;
3043
3044         if (xmlTextReaderGetAttribute(reader, XMLCHAR("provider-id")))
3045                 datacontrol->providerid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("provider-id")));
3046
3047         depth = xmlTextReaderDepth(reader);
3048         while ((ret = __next_child_element(reader, depth))) {
3049                 node = xmlTextReaderConstName(reader);
3050                 if (!node) {
3051                         DBG("xmlTextReaderConstName value is NULL\n");
3052                         return -1;
3053                 }
3054
3055                 if (!strcmp(ASCII(node), "capability")) {
3056                         capability_x *capability = malloc(sizeof(capability_x));
3057                         if (capability == NULL) {
3058                                 DBG("Malloc Failed\n");
3059                                 return -1;
3060                         }
3061                         memset(capability, '\0', sizeof(capability_x));
3062                         LISTADD(datacontrol->capability, capability);
3063                         ret = __ps_process_capability(reader, capability);
3064                 } else
3065                         return -1;
3066                 if (ret < 0) {
3067                         DBG("Processing datacontrol failed\n");
3068                         return ret;
3069                 }
3070         }
3071
3072         if (datacontrol->capability) {
3073                 LISTHEAD(datacontrol->capability, tmp1);
3074                 datacontrol->capability = tmp1;
3075         }
3076
3077         return ret;
3078 }
3079
3080 static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication)
3081 {
3082         const xmlChar *node;
3083         int ret = -1;
3084         int depth = -1;
3085         char *newappid = NULL;
3086         label_x *tmp1 = NULL;
3087         icon_x *tmp2 = NULL;
3088         appsvc_x *tmp3 = NULL;
3089         appcontrol_x *tmp4 = NULL;
3090         launchconditions_x *tmp5 = NULL;
3091         notification_x *tmp6 = NULL;
3092         datashare_x *tmp7 = NULL;
3093         category_x *tmp8 = NULL;
3094         metadata_x *tmp9 = NULL;
3095         image_x *tmp10 = NULL;
3096         permission_x *tmp11 = NULL;
3097
3098         if (xmlTextReaderGetAttribute(reader, XMLCHAR("appid"))) {
3099                 uiapplication->appid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appid")));
3100                 if (uiapplication->appid == NULL) {
3101                         DBG("appid cant be NULL\n");
3102                         return -1;
3103                 }
3104         } else {
3105                 DBG("appid is mandatory\n");
3106                 return -1;
3107         }
3108         /*check appid*/
3109         ret = __validate_appid(package, uiapplication->appid, &newappid);
3110         if (ret == -1) {
3111                 DBG("appid is not proper\n");
3112                 return -1;
3113         } else {
3114                 if (newappid) {
3115                         if (uiapplication->appid)
3116                                 free((void *)uiapplication->appid);
3117                         uiapplication->appid = newappid;
3118                 }
3119                 uiapplication->package= strdup(package);
3120         }
3121         if (xmlTextReaderGetAttribute(reader, XMLCHAR("exec")))
3122                 uiapplication->exec = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("exec")));
3123         if (xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay"))) {
3124                 uiapplication->nodisplay = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay")));
3125                 if (uiapplication->nodisplay == NULL)
3126                         uiapplication->nodisplay = strdup("false");
3127         } else {
3128                 uiapplication->nodisplay = strdup("false");
3129         }
3130         if (xmlTextReaderGetAttribute(reader, XMLCHAR("multiple"))) {
3131                 uiapplication->multiple = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("multiple")));
3132                 if (uiapplication->multiple == NULL)
3133                         uiapplication->multiple = strdup("false");
3134         } else {
3135                 uiapplication->multiple = strdup("false");
3136         }
3137         if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
3138                 uiapplication->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
3139         if (xmlTextReaderGetAttribute(reader, XMLCHAR("categories")))
3140                 uiapplication->categories = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("categories")));
3141         if (xmlTextReaderGetAttribute(reader, XMLCHAR("extraid")))
3142                 uiapplication->extraid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("extraid")));
3143         if (xmlTextReaderGetAttribute(reader, XMLCHAR("taskmanage"))) {
3144                 uiapplication->taskmanage = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("taskmanage")));
3145                 if (uiapplication->taskmanage == NULL)
3146                         uiapplication->taskmanage = strdup("true");
3147         } else {
3148                 uiapplication->taskmanage = strdup("true");
3149         }
3150         if (xmlTextReaderGetAttribute(reader, XMLCHAR("enabled"))) {
3151                 uiapplication->enabled = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("enabled")));
3152                 if (uiapplication->enabled == NULL)
3153                         uiapplication->enabled = strdup("true");
3154         } else {
3155                 uiapplication->enabled = strdup("true");
3156         }
3157         if (xmlTextReaderGetAttribute(reader, XMLCHAR("hw-acceleration"))) {
3158                 uiapplication->hwacceleration = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("hw-acceleration")));
3159                 if (uiapplication->hwacceleration == NULL)
3160                         uiapplication->hwacceleration = strdup("use-system-setting");
3161         } else {
3162                 uiapplication->hwacceleration = strdup("use-system-setting");
3163         }
3164         if (xmlTextReaderGetAttribute(reader, XMLCHAR("screen-reader"))) {
3165                 uiapplication->screenreader = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("screen-reader")));
3166                 if (uiapplication->screenreader == NULL)
3167                         uiapplication->screenreader = strdup("use-system-setting");
3168         } else {
3169                 uiapplication->screenreader = strdup("use-system-setting");
3170         }
3171         if (xmlTextReaderGetAttribute(reader, XMLCHAR("recentimage")))
3172                 uiapplication->recentimage = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("recentimage")));
3173         if (xmlTextReaderGetAttribute(reader, XMLCHAR("mainapp"))) {
3174                 uiapplication->mainapp = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("mainapp")));
3175                 if (uiapplication->mainapp == NULL)
3176                         uiapplication->mainapp = strdup("false");
3177         } else {
3178                 uiapplication->mainapp = strdup("false");
3179         }
3180         if (xmlTextReaderGetAttribute(reader, XMLCHAR("launchcondition"))) {
3181                 uiapplication->launchcondition = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("launchcondition")));
3182                 if (uiapplication->launchcondition == NULL)
3183                         uiapplication->launchcondition = strdup("false");
3184         } else {
3185                 uiapplication->launchcondition = strdup("false");
3186         }
3187
3188         if (xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay"))) {
3189                 uiapplication->indicatordisplay = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("indicatordisplay")));
3190                 if (uiapplication->indicatordisplay == NULL)
3191                         uiapplication->indicatordisplay = strdup("true");
3192         } else {
3193                 uiapplication->indicatordisplay = strdup("true");
3194         }
3195         if (xmlTextReaderGetAttribute(reader, XMLCHAR("portrait-effectimage")))
3196                 uiapplication->portraitimg = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("portrait-effectimage")));
3197         else
3198                 uiapplication->portraitimg = NULL;
3199         if (xmlTextReaderGetAttribute(reader, XMLCHAR("landscape-effectimage")))
3200                 uiapplication->landscapeimg = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("landscape-effectimage")));
3201         else
3202                 uiapplication->landscapeimg = NULL;
3203         if (xmlTextReaderGetAttribute(reader, XMLCHAR("guestmode-visibility"))) {
3204                 uiapplication->guestmode_visibility = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("guestmode-visibility")));
3205                 if (uiapplication->guestmode_visibility == NULL)
3206                         uiapplication->guestmode_visibility = strdup("true");
3207         } else {
3208                 uiapplication->guestmode_visibility = strdup("true");
3209         }
3210         if (xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type"))) {
3211                 uiapplication->permission_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type")));
3212                 if (uiapplication->permission_type == NULL)
3213                         uiapplication->permission_type = strdup("normal");
3214         } else {
3215                 uiapplication->permission_type = strdup("normal");
3216         }
3217         if (xmlTextReaderGetAttribute(reader, XMLCHAR("component-type"))) {
3218                 uiapplication->component_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("component-type")));
3219                 if (uiapplication->component_type == NULL)
3220                         uiapplication->component_type = strdup("uiapp");
3221         } else {
3222                 uiapplication->component_type = strdup("uiapp");
3223         }
3224         if (xmlTextReaderGetAttribute(reader, XMLCHAR("submode"))) {
3225                 uiapplication->submode = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("submode")));
3226                 if (uiapplication->submode == NULL)
3227                         uiapplication->submode = strdup("false");
3228         } else {
3229                 uiapplication->submode = strdup("false");
3230         }
3231         if (xmlTextReaderGetAttribute(reader, XMLCHAR("submode-mainid")))
3232                 uiapplication->submode_mainid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("submode-mainid")));
3233
3234         depth = xmlTextReaderDepth(reader);
3235         while ((ret = __next_child_element(reader, depth))) {
3236                 node = xmlTextReaderConstName(reader);
3237                 if (!node) {
3238                         DBG("xmlTextReaderConstName value is NULL\n");
3239                         return -1;
3240                 }
3241                 if (!strcmp(ASCII(node), "label")) {
3242                         label_x *label = malloc(sizeof(label_x));
3243                         if (label == NULL) {
3244                                 DBG("Malloc Failed\n");
3245                                 return -1;
3246                         }
3247                         memset(label, '\0', sizeof(label_x));
3248                         LISTADD(uiapplication->label, label);
3249                         ret = __ps_process_label(reader, label);
3250                 } else if (!strcmp(ASCII(node), "icon")) {
3251                         icon_x *icon = malloc(sizeof(icon_x));
3252                         if (icon == NULL) {
3253                                 DBG("Malloc Failed\n");
3254                                 return -1;
3255                         }
3256                         memset(icon, '\0', sizeof(icon_x));
3257                         LISTADD(uiapplication->icon, icon);
3258                         ret = __ps_process_icon(reader, icon);
3259                 } else if (!strcmp(ASCII(node), "image")) {
3260                         image_x *image = malloc(sizeof(image_x));
3261                         if (image == NULL) {
3262                                 DBG("Malloc Failed\n");
3263                                 return -1;
3264                         }
3265                         memset(image, '\0', sizeof(image_x));
3266                         LISTADD(uiapplication->image, image);
3267                         ret = __ps_process_image(reader, image);
3268                 } else if (!strcmp(ASCII(node), "category")) {
3269                         category_x *category = malloc(sizeof(category_x));
3270                         if (category == NULL) {
3271                                 DBG("Malloc Failed\n");
3272                                 return -1;
3273                         }
3274                         memset(category, '\0', sizeof(category_x));
3275                         LISTADD(uiapplication->category, category);
3276                         ret = __ps_process_category(reader, category);
3277                 } else if (!strcmp(ASCII(node), "metadata")) {
3278                         metadata_x *metadata = malloc(sizeof(metadata_x));
3279                         if (metadata == NULL) {
3280                                 DBG("Malloc Failed\n");
3281                                 return -1;
3282                         }
3283                         memset(metadata, '\0', sizeof(metadata_x));
3284                         LISTADD(uiapplication->metadata, metadata);
3285                         ret = __ps_process_metadata(reader, metadata);
3286                 } else if (!strcmp(ASCII(node), "permission")) {
3287                         permission_x *permission = malloc(sizeof(permission_x));
3288                         if (permission == NULL) {
3289                                 DBG("Malloc Failed\n");
3290                                 return -1;
3291                         }
3292                         memset(permission, '\0', sizeof(permission_x));
3293                         LISTADD(uiapplication->permission, permission);
3294                         ret = __ps_process_permission(reader, permission);
3295                 } else if (!strcmp(ASCII(node), "app-control")) {
3296                         appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
3297                         if (appcontrol == NULL) {
3298                                 DBG("Malloc Failed\n");
3299                                 return -1;
3300                         }
3301                         memset(appcontrol, '\0', sizeof(appcontrol_x));
3302                         LISTADD(uiapplication->appcontrol, appcontrol);
3303                         ret = __ps_process_appcontrol(reader, appcontrol);
3304                 } else if (!strcmp(ASCII(node), "application-service")) {
3305                         appsvc_x *appsvc = malloc(sizeof(appsvc_x));
3306                         if (appsvc == NULL) {
3307                                 DBG("Malloc Failed\n");
3308                                 return -1;
3309                         }
3310                         memset(appsvc, '\0', sizeof(appsvc_x));
3311                         LISTADD(uiapplication->appsvc, appsvc);
3312                         ret = __ps_process_appsvc(reader, appsvc);
3313                 } else if (!strcmp(ASCII(node), "data-share")) {
3314                         datashare_x *datashare = malloc(sizeof(datashare_x));
3315                         if (datashare == NULL) {
3316                                 DBG("Malloc Failed\n");
3317                                 return -1;
3318                         }
3319                         memset(datashare, '\0', sizeof(datashare_x));
3320                         LISTADD(uiapplication->datashare, datashare);
3321                         ret = __ps_process_datashare(reader, datashare);
3322                 } else if (!strcmp(ASCII(node), "launch-conditions")) {
3323                         launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
3324                         if (launchconditions == NULL) {
3325                                 DBG("Malloc Failed\n");
3326                                 return -1;
3327                         }
3328                         memset(launchconditions, '\0', sizeof(launchconditions_x));
3329                         LISTADD(uiapplication->launchconditions, launchconditions);
3330                         ret = __ps_process_launchconditions(reader, launchconditions);
3331                 } else if (!strcmp(ASCII(node), "notification")) {
3332                         notification_x *notification = malloc(sizeof(notification_x));
3333                         if (notification == NULL) {
3334                                 DBG("Malloc Failed\n");
3335                                 return -1;
3336                         }
3337                         memset(notification, '\0', sizeof(notification_x));
3338                         LISTADD(uiapplication->notification, notification);
3339                         ret = __ps_process_notification(reader, notification);
3340                 } else
3341                         return -1;
3342                 if (ret < 0) {
3343                         DBG("Processing uiapplication failed\n");
3344                         return ret;
3345                 }
3346         }
3347
3348         if (uiapplication->label) {
3349                 LISTHEAD(uiapplication->label, tmp1);
3350                 uiapplication->label = tmp1;
3351         }
3352         if (uiapplication->icon) {
3353                 LISTHEAD(uiapplication->icon, tmp2);
3354                 uiapplication->icon = tmp2;
3355         }
3356         if (uiapplication->appsvc) {
3357                 LISTHEAD(uiapplication->appsvc, tmp3);
3358                 uiapplication->appsvc = tmp3;
3359         }
3360         if (uiapplication->appcontrol) {
3361                 LISTHEAD(uiapplication->appcontrol, tmp4);
3362                 uiapplication->appcontrol = tmp4;
3363         }
3364         if (uiapplication->launchconditions) {
3365                 LISTHEAD(uiapplication->launchconditions, tmp5);
3366                 uiapplication->launchconditions = tmp5;
3367         }
3368         if (uiapplication->notification) {
3369                 LISTHEAD(uiapplication->notification, tmp6);
3370                 uiapplication->notification = tmp6;
3371         }
3372         if (uiapplication->datashare) {
3373                 LISTHEAD(uiapplication->datashare, tmp7);
3374                 uiapplication->datashare = tmp7;
3375         }
3376         if (uiapplication->category) {
3377                 LISTHEAD(uiapplication->category, tmp8);
3378                 uiapplication->category = tmp8;
3379         }
3380         if (uiapplication->metadata) {
3381                 LISTHEAD(uiapplication->metadata, tmp9);
3382                 uiapplication->metadata = tmp9;
3383         }
3384         if (uiapplication->image) {
3385                 LISTHEAD(uiapplication->image, tmp10);
3386                 uiapplication->image = tmp10;
3387         }
3388         if (uiapplication->permission) {
3389                 LISTHEAD(uiapplication->permission, tmp11);
3390                 uiapplication->permission = tmp11;
3391         }
3392
3393         return ret;
3394 }
3395
3396 static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication)
3397 {
3398         const xmlChar *node;
3399         int ret = -1;
3400         int depth = -1;
3401         char *newappid = NULL;
3402         label_x *tmp1 = NULL;
3403         icon_x *tmp2 = NULL;
3404         appsvc_x *tmp3 = NULL;
3405         appcontrol_x *tmp4 = NULL;
3406         datacontrol_x *tmp5 = NULL;
3407         launchconditions_x *tmp6 = NULL;
3408         notification_x *tmp7 = NULL;
3409         datashare_x *tmp8 = NULL;
3410         category_x *tmp9 = NULL;
3411         metadata_x *tmp10 = NULL;
3412         permission_x *tmp11 = NULL;
3413
3414         if (xmlTextReaderGetAttribute(reader, XMLCHAR("appid"))) {
3415                 serviceapplication->appid = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appid")));
3416                 if (serviceapplication->appid == NULL) {
3417                         DBG("appid cant be NULL\n");
3418                         return -1;
3419                 }
3420         } else {
3421                 DBG("appid is mandatory\n");
3422                 return -1;
3423         }
3424         /*check appid*/
3425         ret = __validate_appid(package, serviceapplication->appid, &newappid);
3426         if (ret == -1) {
3427                 DBG("appid is not proper\n");
3428                 return -1;
3429         } else {
3430                 if (newappid) {
3431                         if (serviceapplication->appid)
3432                                 free((void *)serviceapplication->appid);
3433                         serviceapplication->appid = newappid;
3434                 }
3435         }
3436         if (xmlTextReaderGetAttribute(reader, XMLCHAR("exec")))
3437                 serviceapplication->exec = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("exec")));
3438         if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
3439                 serviceapplication->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
3440         if (xmlTextReaderGetAttribute(reader, XMLCHAR("on-boot"))) {
3441                 serviceapplication->onboot = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("on-boot")));
3442                 if (serviceapplication->onboot == NULL)
3443                         serviceapplication->onboot = strdup("false");
3444         } else {
3445                 serviceapplication->onboot = strdup("false");
3446         }
3447         if (xmlTextReaderGetAttribute(reader, XMLCHAR("auto-restart"))) {
3448                 serviceapplication->autorestart = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("auto-restart")));
3449                 if (serviceapplication->autorestart == NULL)
3450                         serviceapplication->autorestart = strdup("false");
3451         } else {
3452                 serviceapplication->autorestart = strdup("false");
3453         }
3454         if (xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type"))) {
3455                 serviceapplication->permission_type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("permission-type")));
3456                 if (serviceapplication->permission_type == NULL)
3457                         serviceapplication->permission_type = strdup("normal");
3458         } else {
3459                 serviceapplication->permission_type = strdup("normal");
3460         }
3461
3462         depth = xmlTextReaderDepth(reader);
3463         while ((ret = __next_child_element(reader, depth))) {
3464                 node = xmlTextReaderConstName(reader);
3465                 if (!node) {
3466                         DBG("xmlTextReaderConstName value is NULL\n");
3467                         return -1;
3468                 }
3469
3470                 if (!strcmp(ASCII(node), "label")) {
3471                         label_x *label = malloc(sizeof(label_x));
3472                         if (label == NULL) {
3473                                 DBG("Malloc Failed\n");
3474                                 return -1;
3475                         }
3476                         memset(label, '\0', sizeof(label_x));
3477                         LISTADD(serviceapplication->label, label);
3478                         ret = __ps_process_label(reader, label);
3479                 } else if (!strcmp(ASCII(node), "icon")) {
3480                         icon_x *icon = malloc(sizeof(icon_x));
3481                         if (icon == NULL) {
3482                                 DBG("Malloc Failed\n");
3483                                 return -1;
3484                         }
3485                         memset(icon, '\0', sizeof(icon_x));
3486                         LISTADD(serviceapplication->icon, icon);
3487                         ret = __ps_process_icon(reader, icon);
3488                 } else if (!strcmp(ASCII(node), "category")) {
3489                         category_x *category = malloc(sizeof(category_x));
3490                         if (category == NULL) {
3491                                 DBG("Malloc Failed\n");
3492                                 return -1;
3493                         }
3494                         memset(category, '\0', sizeof(category_x));
3495                         LISTADD(serviceapplication->category, category);
3496                         ret = __ps_process_category(reader, category);
3497                 } else if (!strcmp(ASCII(node), "metadata")) {
3498                         metadata_x *metadata = malloc(sizeof(metadata_x));
3499                         if (metadata == NULL) {
3500                                 DBG("Malloc Failed\n");
3501                                 return -1;
3502                         }
3503                         memset(metadata, '\0', sizeof(metadata_x));
3504                         LISTADD(serviceapplication->metadata, metadata);
3505                         ret = __ps_process_metadata(reader, metadata);
3506                 } else if (!strcmp(ASCII(node), "permission")) {
3507                         permission_x *permission = malloc(sizeof(permission_x));
3508                         if (permission == NULL) {
3509                                 DBG("Malloc Failed\n");
3510                                 return -1;
3511                         }
3512                         memset(permission, '\0', sizeof(permission_x));
3513                         LISTADD(serviceapplication->permission, permission);
3514                         ret = __ps_process_permission(reader, permission);
3515                 } else if (!strcmp(ASCII(node), "app-control")) {
3516                         appcontrol_x *appcontrol = malloc(sizeof(appcontrol_x));
3517                         if (appcontrol == NULL) {
3518                                 DBG("Malloc Failed\n");
3519                                 return -1;
3520                         }
3521                         memset(appcontrol, '\0', sizeof(appcontrol_x));
3522                         LISTADD(serviceapplication->appcontrol, appcontrol);
3523                         ret = __ps_process_appcontrol(reader, appcontrol);
3524                 } else if (!strcmp(ASCII(node), "application-service")) {
3525                         appsvc_x *appsvc = malloc(sizeof(appsvc_x));
3526                         if (appsvc == NULL) {
3527                                 DBG("Malloc Failed\n");
3528                                 return -1;
3529                         }
3530                         memset(appsvc, '\0', sizeof(appsvc_x));
3531                         LISTADD(serviceapplication->appsvc, appsvc);
3532                         ret = __ps_process_appsvc(reader, appsvc);
3533                 } else if (!strcmp(ASCII(node), "data-share")) {
3534                         datashare_x *datashare = malloc(sizeof(datashare_x));
3535                         if (datashare == NULL) {
3536                                 DBG("Malloc Failed\n");
3537                                 return -1;
3538                         }
3539                         memset(datashare, '\0', sizeof(datashare_x));
3540                         LISTADD(serviceapplication->datashare, datashare);
3541                         ret = __ps_process_datashare(reader, datashare);
3542                 } else if (!strcmp(ASCII(node), "launch-conditions")) {
3543                         launchconditions_x *launchconditions = malloc(sizeof(launchconditions_x));
3544                         if (launchconditions == NULL) {
3545                                 DBG("Malloc Failed\n");
3546                                 return -1;
3547                         }
3548                         memset(launchconditions, '\0', sizeof(launchconditions_x));
3549                         LISTADD(serviceapplication->launchconditions, launchconditions);
3550                         ret = __ps_process_launchconditions(reader, launchconditions);
3551                 } else if (!strcmp(ASCII(node), "notification")) {
3552                         notification_x *notification = malloc(sizeof(notification_x));
3553                         if (notification == NULL) {
3554                                 DBG("Malloc Failed\n");
3555                                 return -1;
3556                         }
3557                         memset(notification, '\0', sizeof(notification_x));
3558                         LISTADD(serviceapplication->notification, notification);
3559                         ret = __ps_process_notification(reader, notification);
3560                 } else if (!strcmp(ASCII(node), "data-control")) {
3561                         datacontrol_x *datacontrol = malloc(sizeof(datacontrol_x));
3562                         if (datacontrol == NULL) {
3563                                 DBG("Malloc Failed\n");
3564                                 return -1;
3565                         }
3566                         memset(datacontrol, '\0', sizeof(datacontrol_x));
3567                         LISTADD(serviceapplication->datacontrol, datacontrol);
3568                         ret = __ps_process_datacontrol(reader, datacontrol);
3569                 } else
3570                         return -1;
3571                 if (ret < 0) {
3572                         DBG("Processing serviceapplication failed\n");
3573                         return ret;
3574                 }
3575         }
3576
3577         if (serviceapplication->label) {
3578                 LISTHEAD(serviceapplication->label, tmp1);
3579                 serviceapplication->label = tmp1;
3580         }
3581         if (serviceapplication->icon) {
3582                 LISTHEAD(serviceapplication->icon, tmp2);
3583                 serviceapplication->icon = tmp2;
3584         }
3585         if (serviceapplication->appsvc) {
3586                 LISTHEAD(serviceapplication->appsvc, tmp3);
3587                 serviceapplication->appsvc = tmp3;
3588         }
3589         if (serviceapplication->appcontrol) {
3590                 LISTHEAD(serviceapplication->appcontrol, tmp4);
3591                 serviceapplication->appcontrol = tmp4;
3592         }
3593         if (serviceapplication->datacontrol) {
3594                 LISTHEAD(serviceapplication->datacontrol, tmp5);
3595                 serviceapplication->datacontrol = tmp5;
3596         }
3597         if (serviceapplication->launchconditions) {
3598                 LISTHEAD(serviceapplication->launchconditions, tmp6);
3599                 serviceapplication->launchconditions = tmp6;
3600         }
3601         if (serviceapplication->notification) {
3602                 LISTHEAD(serviceapplication->notification, tmp7);
3603                 serviceapplication->notification = tmp7;
3604         }
3605         if (serviceapplication->datashare) {
3606                 LISTHEAD(serviceapplication->datashare, tmp8);
3607                 serviceapplication->datashare = tmp8;
3608         }
3609         if (serviceapplication->category) {
3610                 LISTHEAD(serviceapplication->category, tmp9);
3611                 serviceapplication->category = tmp9;
3612         }
3613         if (serviceapplication->metadata) {
3614                 LISTHEAD(serviceapplication->metadata, tmp10);
3615                 serviceapplication->metadata = tmp10;
3616         }
3617         if (serviceapplication->permission) {
3618                 LISTHEAD(serviceapplication->permission, tmp11);
3619                 serviceapplication->permission = tmp11;
3620         }
3621
3622         return ret;
3623 }
3624
3625 static int __ps_process_deviceprofile(xmlTextReaderPtr reader, deviceprofile_x *deviceprofile)
3626 {
3627         /*TODO: once policy is set*/
3628         return 0;
3629 }
3630
3631 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font)
3632 {
3633         /*TODO: once policy is set*/
3634         return 0;
3635 }
3636
3637 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme)
3638 {
3639         /*TODO: once policy is set*/
3640         return 0;
3641 }
3642
3643 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon)
3644 {
3645         /*TODO: once policy is set*/
3646         return 0;
3647 }
3648
3649 static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
3650 {
3651         /*TODO: once policy is set*/
3652         return 0;
3653 }
3654
3655 static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
3656 {
3657         DBG("__start_process\n");
3658         const xmlChar *node;
3659         int ret = -1;
3660         int depth = -1;
3661         label_x *tmp1 = NULL;
3662         author_x *tmp2 = NULL;
3663         description_x *tmp3 = NULL;
3664         license_x *tmp4 = NULL;
3665         uiapplication_x *tmp5 = NULL;
3666         serviceapplication_x *tmp6 = NULL;
3667         daemon_x *tmp7 = NULL;
3668         theme_x *tmp8 = NULL;
3669         font_x *tmp9 = NULL;
3670         ime_x *tmp10 = NULL;
3671         icon_x *tmp11 = NULL;
3672         compatibility_x *tmp12 = NULL;
3673         deviceprofile_x *tmp13 = NULL;
3674         privileges_x *tmp14 = NULL;
3675
3676         depth = xmlTextReaderDepth(reader);
3677         while ((ret = __next_child_element(reader, depth))) {
3678                 node = xmlTextReaderConstName(reader);
3679                 if (!node) {
3680                         DBG("xmlTextReaderConstName value is NULL\n");
3681                         return -1;
3682                 }
3683
3684                 if (!strcmp(ASCII(node), "label")) {
3685                         label_x *label = malloc(sizeof(label_x));
3686                         if (label == NULL) {
3687                                 DBG("Malloc Failed\n");
3688                                 return -1;
3689                         }
3690                         memset(label, '\0', sizeof(label_x));
3691                         LISTADD(mfx->label, label);
3692                         ret = __ps_process_label(reader, label);
3693                 } else if (!strcmp(ASCII(node), "author")) {
3694                         author_x *author = malloc(sizeof(author_x));
3695                         if (author == NULL) {
3696                                 DBG("Malloc Failed\n");
3697                                 return -1;
3698                         }
3699                         memset(author, '\0', sizeof(author_x));
3700                         LISTADD(mfx->author, author);
3701                         ret = __ps_process_author(reader, author);
3702                 } else if (!strcmp(ASCII(node), "description")) {
3703                         description_x *description = malloc(sizeof(description_x));
3704                         if (description == NULL) {
3705                                 DBG("Malloc Failed\n");
3706                                 return -1;
3707                         }
3708                         memset(description, '\0', sizeof(description_x));
3709                         LISTADD(mfx->description, description);
3710                         ret = __ps_process_description(reader, description);
3711                 } else if (!strcmp(ASCII(node), "license")) {
3712                         license_x *license = malloc(sizeof(license_x));
3713                         if (license == NULL) {
3714                                 DBG("Malloc Failed\n");
3715                                 return -1;
3716                         }
3717                         memset(license, '\0', sizeof(license_x));
3718                         LISTADD(mfx->license, license);
3719                         ret = __ps_process_license(reader, license);
3720                 } else if (!strcmp(ASCII(node), "privileges")) {
3721                         privileges_x *privileges = malloc(sizeof(privileges_x));
3722                         if (privileges == NULL) {
3723                                 DBG("Malloc Failed\n");
3724                                 return -1;
3725                         }
3726                         memset(privileges, '\0', sizeof(privileges_x));
3727                         LISTADD(mfx->privileges, privileges);
3728                         ret = __ps_process_privileges(reader, privileges);
3729                 } else if (!strcmp(ASCII(node), "ui-application")) {
3730                         uiapplication_x *uiapplication = malloc(sizeof(uiapplication_x));
3731                         if (uiapplication == NULL) {
3732                                 DBG("Malloc Failed\n");
3733                                 return -1;
3734                         }
3735                         memset(uiapplication, '\0', sizeof(uiapplication_x));
3736                         LISTADD(mfx->uiapplication, uiapplication);
3737                         ret = __ps_process_uiapplication(reader, uiapplication);
3738                 } else if (!strcmp(ASCII(node), "service-application")) {
3739                         serviceapplication_x *serviceapplication = malloc(sizeof(serviceapplication_x));
3740                         if (serviceapplication == NULL) {
3741                                 DBG("Malloc Failed\n");
3742                                 return -1;
3743                         }
3744                         memset(serviceapplication, '\0', sizeof(serviceapplication_x));
3745                         LISTADD(mfx->serviceapplication, serviceapplication);
3746                         ret = __ps_process_serviceapplication(reader, serviceapplication);
3747                 } else if (!strcmp(ASCII(node), "daemon")) {
3748                         daemon_x *daemon = malloc(sizeof(daemon_x));
3749                         if (daemon == NULL) {
3750                                 DBG("Malloc Failed\n");
3751                                 return -1;
3752                         }
3753                         memset(daemon, '\0', sizeof(daemon_x));
3754                         LISTADD(mfx->daemon, daemon);
3755                         ret = __ps_process_daemon(reader, daemon);
3756                 } else if (!strcmp(ASCII(node), "theme")) {
3757                         theme_x *theme = malloc(sizeof(theme_x));
3758                         if (theme == NULL) {
3759                                 DBG("Malloc Failed\n");
3760                                 return -1;
3761                         }
3762                         memset(theme, '\0', sizeof(theme_x));
3763                         LISTADD(mfx->theme, theme);
3764                         ret = __ps_process_theme(reader, theme);
3765                 } else if (!strcmp(ASCII(node), "font")) {
3766                         font_x *font = malloc(sizeof(font_x));
3767                         if (font == NULL) {
3768                                 DBG("Malloc Failed\n");
3769                                 return -1;
3770                         }
3771                         memset(font, '\0', sizeof(font_x));
3772                         LISTADD(mfx->font, font);
3773                         ret = __ps_process_font(reader, font);
3774                 } else if (!strcmp(ASCII(node), "ime")) {
3775                         ime_x *ime = malloc(sizeof(ime_x));
3776                         if (ime == NULL) {
3777                                 DBG("Malloc Failed\n");
3778                                 return -1;
3779                         }
3780                         memset(ime, '\0', sizeof(ime_x));
3781                         LISTADD(mfx->ime, ime);
3782                         ret = __ps_process_ime(reader, ime);
3783                 } else if (!strcmp(ASCII(node), "icon")) {
3784                         icon_x *icon = malloc(sizeof(icon_x));
3785                         if (icon == NULL) {
3786                                 DBG("Malloc Failed\n");
3787                                 return -1;
3788                         }
3789                         memset(icon, '\0', sizeof(icon_x));
3790                         LISTADD(mfx->icon, icon);
3791                         ret = __ps_process_icon(reader, icon);
3792                 } else if (!strcmp(ASCII(node), "device-profile")) {
3793                         deviceprofile_x *deviceprofile = malloc(sizeof(deviceprofile_x));
3794                         if (deviceprofile == NULL) {
3795                                 DBG("Malloc Failed\n");
3796                                 return -1;
3797                         }
3798                         memset(deviceprofile, '\0', sizeof(deviceprofile_x));
3799                         LISTADD(mfx->deviceprofile, deviceprofile);
3800                         ret = __ps_process_deviceprofile(reader, deviceprofile);
3801                 } else if (!strcmp(ASCII(node), "compatibility")) {
3802                         compatibility_x *compatibility = malloc(sizeof(compatibility_x));
3803                         if (compatibility == NULL) {
3804                                 DBG("Malloc Failed\n");
3805                                 return -1;
3806                         }
3807                         memset(compatibility, '\0', sizeof(compatibility_x));
3808                         LISTADD(mfx->compatibility, compatibility);
3809                         ret = __ps_process_compatibility(reader, compatibility);
3810                 } else if (!strcmp(ASCII(node), "shortcut-list")) {
3811                         continue;
3812                 } else if (!strcmp(ASCII(node), "livebox")) {
3813                         continue;
3814                 } else if (!strcmp(ASCII(node), "account")) {
3815                         continue;
3816                 } else if (!strcmp(ASCII(node), "notifications")) {
3817                         continue;
3818                 } else if (!strcmp(ASCII(node), "ime")) {
3819                         continue;
3820                 } else
3821                         return -1;
3822
3823                 if (ret < 0) {
3824                         DBG("Processing manifest failed\n");
3825                         return ret;
3826                 }
3827         }
3828         if (mfx->label) {
3829                 LISTHEAD(mfx->label, tmp1);
3830                 mfx->label = tmp1;
3831         }
3832         if (mfx->author) {
3833                 LISTHEAD(mfx->author, tmp2);
3834                 mfx->author = tmp2;
3835         }
3836         if (mfx->description) {
3837                 LISTHEAD(mfx->description, tmp3);
3838                 mfx->description= tmp3;
3839         }
3840         if (mfx->license) {
3841                 LISTHEAD(mfx->license, tmp4);
3842                 mfx->license= tmp4;
3843         }
3844         if (mfx->uiapplication) {
3845                 LISTHEAD(mfx->uiapplication, tmp5);
3846                 mfx->uiapplication = tmp5;
3847         }
3848         if (mfx->serviceapplication) {
3849                 LISTHEAD(mfx->serviceapplication, tmp6);
3850                 mfx->serviceapplication = tmp6;
3851         }
3852         if (mfx->daemon) {
3853                 LISTHEAD(mfx->daemon, tmp7);
3854                 mfx->daemon= tmp7;
3855         }
3856         if (mfx->theme) {
3857                 LISTHEAD(mfx->theme, tmp8);
3858                 mfx->theme= tmp8;
3859         }
3860         if (mfx->font) {
3861                 LISTHEAD(mfx->font, tmp9);
3862                 mfx->font= tmp9;
3863         }
3864         if (mfx->ime) {
3865                 LISTHEAD(mfx->ime, tmp10);
3866                 mfx->ime= tmp10;
3867         }
3868         if (mfx->icon) {
3869                 LISTHEAD(mfx->icon, tmp11);
3870                 mfx->icon= tmp11;
3871         }
3872         if (mfx->compatibility) {
3873                 LISTHEAD(mfx->compatibility, tmp12);
3874                 mfx->compatibility= tmp12;
3875         }
3876         if (mfx->deviceprofile) {
3877                 LISTHEAD(mfx->deviceprofile, tmp13);
3878                 mfx->deviceprofile= tmp13;
3879         }
3880         if (mfx->privileges) {
3881                 LISTHEAD(mfx->privileges, tmp14);
3882                 mfx->privileges = tmp14;
3883         }
3884         return ret;
3885 }
3886
3887 static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
3888 {
3889         const xmlChar *node;
3890         int ret = -1;
3891
3892         if ((ret = __next_child_element(reader, -1))) {
3893                 node = xmlTextReaderConstName(reader);
3894                 if (!node) {
3895                         DBG("xmlTextReaderConstName value is NULL\n");
3896                         return -1;
3897                 }
3898
3899                 if (!strcmp(ASCII(node), "manifest")) {
3900                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")))
3901                                 mfx->ns = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")));
3902                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("package"))) {
3903                                 mfx->package= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("package")));
3904                                 if (mfx->package == NULL) {
3905                                         DBG("package cant be NULL\n");
3906                                         return -1;
3907                                 }
3908                         } else {
3909                                 DBG("package field is mandatory\n");
3910                                 return -1;
3911                         }
3912                         package = mfx->package;
3913                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("version")))
3914                                 mfx->version= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("version")));
3915                         /*app2ext needs package size for external installation*/
3916                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("size")))
3917                                 mfx->package_size = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("size")));
3918                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("install-location")))
3919                                 mfx->installlocation = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("install-location")));
3920                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("type")))
3921                                 mfx->type = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("type")));
3922                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("root_path")))
3923                                 mfx->root_path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("root_path")));
3924                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("csc_path")))
3925                                 mfx->csc_path = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("csc_path")));
3926                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting"))) {
3927                                 mfx->appsetting = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("appsetting")));
3928                                 if (mfx->appsetting == NULL)
3929                                         mfx->appsetting = strdup("false");
3930                         } else {
3931                                 mfx->appsetting = strdup("false");
3932                         }
3933                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")))
3934                                 mfx->storeclient_id= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("storeclient-id")));
3935                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay-setting"))) {
3936                                 mfx->nodisplay_setting = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("nodisplay-setting")));
3937                                 if (mfx->nodisplay_setting == NULL)
3938                                         mfx->nodisplay_setting = strdup("false");
3939                         } else {
3940                                 mfx->nodisplay_setting = strdup("false");
3941                         }
3942                         if (xmlTextReaderGetAttribute(reader, XMLCHAR("url")))
3943                                 mfx->package_url= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("url")));
3944
3945                         /*Assign default values. If required it will be overwritten in __add_preload_info()*/
3946                         mfx->preload = strdup("False");
3947                         mfx->removable = strdup("True");
3948                         mfx->readonly = strdup("False");
3949                         mfx->update = strdup("False");
3950                         mfx->system = strdup("False");
3951                         char buf[PKG_STRING_LEN_MAX] = {'\0'};
3952                         char *val = NULL;
3953                         time_t current_time;
3954                         time(&current_time);
3955                         snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", current_time);
3956                         val = strndup(buf, PKG_STRING_LEN_MAX - 1);
3957                         mfx->installed_time = val;
3958
3959                         mfx->installed_storage= strdup("installed_internal");
3960
3961                         ret = __start_process(reader, mfx);
3962                 } else {
3963                         DBG("No Manifest element found\n");
3964                         return -1;
3965                 }
3966         }
3967         return ret;
3968 }
3969
3970 #define DESKTOP_RW_PATH "/opt/share/applications/"
3971 #define DESKTOP_RO_PATH "/usr/share/applications/"
3972 #define MANIFEST_RO_PREFIX "/usr/share/packages/"
3973
3974 static char* __convert_to_system_locale(const char *mlocale)
3975 {
3976         if (mlocale == NULL)
3977                 return NULL;
3978         char *locale = NULL;
3979         locale = (char *)calloc(1, 6);
3980         if (!locale) {
3981                 DBGE("Malloc Failed\n");
3982                 return NULL;
3983         }
3984
3985         strncpy(locale, mlocale, 2);
3986         strncat(locale, "_", 1);
3987         locale[3] = toupper(mlocale[3]);
3988         locale[4] = toupper(mlocale[4]);
3989         return locale;
3990 }
3991
3992 #define LIBAIL_PATH LIB_PATH "/libail.so.0"
3993
3994 /* operation_type */
3995 typedef enum {
3996         AIL_INSTALL = 0,
3997         AIL_UPDATE,
3998         AIL_REMOVE,
3999         AIL_CLEAN,
4000         AIL_MAX
4001 } AIL_TYPE;
4002
4003 static int __ail_change_info(int op, const char *appid)
4004 {
4005         void *lib_handle = NULL;
4006         int (*ail_desktop_operation) (const char *);
4007         char *aop = NULL;
4008         int ret = 0;
4009
4010         if ((lib_handle = dlopen(LIBAIL_PATH, RTLD_LAZY)) == NULL) {
4011                 DBGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAIL_PATH);
4012                 goto END;
4013         }
4014
4015
4016         switch (op) {
4017                 case 0:
4018                         aop  = "ail_desktop_add";
4019                         break;
4020                 case 1:
4021                         aop  = "ail_desktop_update";
4022                         break;
4023                 case 2:
4024                         aop  = "ail_desktop_remove";
4025                         break;
4026                 case 3:
4027                         aop  = "ail_desktop_clean";
4028                         break;
4029                 default:
4030                         goto END;
4031                         break;
4032         }
4033
4034         if ((ail_desktop_operation =
4035              dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
4036                 DBGE("can not find symbol \n");
4037                 goto END;
4038         }
4039
4040         ret = ail_desktop_operation(appid);
4041
4042 END:
4043         if (lib_handle)
4044                 dlclose(lib_handle);
4045
4046         return ret;
4047 }
4048
4049
4050 /* desktop shoud be generated automatically based on manifest */
4051 /* Currently removable, taskmanage, etc fields are not considerd. it will be decided soon.*/
4052 #define BUFMAX 1024*128
4053 static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, bool is_update)
4054 {
4055         FILE* file = NULL;
4056         int fd = 0;
4057         char filepath[PKG_STRING_LEN_MAX] = "";
4058         char *buf = NULL;
4059         char *buftemp = NULL;
4060         char *locale = NULL;
4061
4062         buf = (char *)calloc(1, BUFMAX);
4063         if (!buf) {
4064                 DBGE("Malloc Failed\n");
4065                 return -1;
4066         }
4067
4068         buftemp = (char *)calloc(1, BUFMAX);
4069         if (!buftemp) {
4070                 DBGE("Malloc Failed\n");
4071                 free(buf);
4072                 return -1;
4073         }
4074
4075         if (is_update)
4076                 __ail_change_info(AIL_CLEAN, mfx->package);
4077
4078         for(; mfx->uiapplication; mfx->uiapplication=mfx->uiapplication->next) {
4079
4080                 if (manifest != NULL) {
4081                         /* skip making a deskfile and update ail, if preload app is updated */
4082                         if(strstr(manifest, MANIFEST_RO_PREFIX)) {
4083                                 __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
4084                     DBGE("preload app is update : skip and update ail : %s", manifest);
4085                                 continue;
4086                         }
4087                 }
4088
4089                 if(mfx->readonly && !strcasecmp(mfx->readonly, "True"))
4090                         snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RO_PATH, mfx->uiapplication->appid);
4091                 else
4092                         snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, mfx->uiapplication->appid);
4093
4094                 /* skip if desktop exists
4095                 if (access(filepath, R_OK) == 0)
4096                         continue;
4097                 */
4098
4099                 file = fopen(filepath, "w");
4100                 if(file == NULL)
4101                 {
4102                     DBGE("Can't open %s", filepath);
4103                     free(buf);
4104                     free(buftemp);
4105                     return -1;
4106                 }
4107
4108                 snprintf(buf, BUFMAX, "[Desktop Entry]\n");
4109                 fwrite(buf, 1, strlen(buf), file);
4110
4111                 for( ; mfx->uiapplication->label ; mfx->uiapplication->label = mfx->uiapplication->label->next) {
4112                         if(!strcmp(mfx->uiapplication->label->lang, DEFAULT_LOCALE)) {
4113                                 snprintf(buf, BUFMAX, "Name=%s\n",      mfx->uiapplication->label->text);
4114                         } else {
4115                                 locale = __convert_to_system_locale(mfx->uiapplication->label->lang);
4116                                 snprintf(buf, BUFMAX, "Name[%s]=%s\n", locale,
4117                                         mfx->uiapplication->label->text);
4118                                 free(locale);
4119                         }
4120                         fwrite(buf, 1, strlen(buf), file);
4121                 }
4122
4123                 if(mfx->uiapplication->label && mfx->uiapplication->label->text) {
4124                         snprintf(buf, BUFMAX, "Name=%s\n", mfx->uiapplication->label->text);
4125                         fwrite(buf, 1, strlen(buf), file);
4126                 }
4127 /*
4128                 else if(mfx->label && mfx->label->text) {
4129                         snprintf(buf, BUFMAX, "Name=%s\n", mfx->label->text);
4130                         fwrite(buf, 1, strlen(buf), file);
4131                 } else {
4132                         snprintf(buf, BUFMAX, "Name=%s\n", mfx->package);
4133                         fwrite(buf, 1, strlen(buf), file);
4134                 }
4135 */
4136
4137
4138                 snprintf(buf, BUFMAX, "Type=Application\n");
4139                 fwrite(buf, 1, strlen(buf), file);
4140
4141                 if(mfx->uiapplication->exec) {
4142                         snprintf(buf, BUFMAX, "Exec=%s\n", mfx->uiapplication->exec);
4143                         fwrite(buf, 1, strlen(buf), file);
4144                 }
4145
4146                 if(mfx->uiapplication->icon && mfx->uiapplication->icon->text) {
4147                         snprintf(buf, BUFMAX, "Icon=%s\n", mfx->uiapplication->icon->text);
4148                         fwrite(buf, 1, strlen(buf), file);
4149                 } else if(mfx->icon && mfx->icon->text) {
4150                         snprintf(buf, BUFMAX, "Icon=%s\n", mfx->icon->text);
4151                         fwrite(buf, 1, strlen(buf), file);
4152                 }
4153
4154                 // MIME types
4155                 if(mfx->uiapplication && mfx->uiapplication->appsvc) {
4156                         appsvc_x *asvc = mfx->uiapplication->appsvc;
4157                         mime_x *mi = NULL;
4158                         const char *mime = NULL;
4159                         const char *mime_delim = "; ";
4160                         int mime_count = 0;
4161
4162                         strncpy(buf, "MimeType=", BUFMAX-1);
4163                         while (asvc) {
4164                                 mi = asvc->mime;
4165                                 while (mi) {
4166                                         mime_count++;
4167                                         mime = mi->name;
4168                                         DBG("MIME type: %s\n", mime);
4169                                         strncat(buf, mime, BUFMAX-strlen(buf)-1);
4170                                         if(mi->next) {
4171                                                 strncat(buf, mime_delim, BUFMAX-strlen(buf)-1);
4172                                         }
4173
4174                                         mi = mi->next;
4175                                         mime = NULL;
4176                                 }
4177                                 asvc = asvc->next;
4178                         }
4179                         DBG("MIME types: buf[%s]\n", buf);
4180                         DBG("MIME count: %d\n", mime_count);
4181                         if(mime_count)
4182                                 fwrite(buf, 1, strlen(buf), file);
4183                 }
4184
4185                 if(mfx->version) {
4186                         snprintf(buf, BUFMAX, "Version=%s\n", mfx->version);
4187                         fwrite(buf, 1, strlen(buf), file);
4188                 }
4189
4190                 if(mfx->uiapplication->nodisplay) {
4191                         snprintf(buf, BUFMAX, "NoDisplay=%s\n", mfx->uiapplication->nodisplay);
4192                         fwrite(buf, 1, strlen(buf), file);
4193                 }
4194
4195                 if(mfx->uiapplication->categories) {
4196                         snprintf(buf, BUFMAX, "Categories=%s\n", mfx->uiapplication->categories);
4197                         fwrite(buf, 1, strlen(buf), file);
4198                 }
4199
4200                 if(mfx->uiapplication->taskmanage && !strcasecmp(mfx->uiapplication->taskmanage, "False")) {
4201                         snprintf(buf, BUFMAX, "X-TIZEN-TaskManage=False\n");
4202                         fwrite(buf, 1, strlen(buf), file);
4203                 }
4204
4205                 if(mfx->uiapplication->enabled && !strcasecmp(mfx->uiapplication->enabled, "False")) {
4206                         snprintf(buf, BUFMAX, "X-TIZEN-Enabled=False\n");
4207                         fwrite(buf, 1, strlen(buf), file);
4208                 }
4209
4210                 if(mfx->uiapplication->hwacceleration) {
4211                         snprintf(buf, BUFMAX, "Hw-Acceleration=%s\n", mfx->uiapplication->hwacceleration);
4212                         fwrite(buf, 1, strlen(buf), file);
4213                 }
4214
4215                 if(mfx->uiapplication->multiple && !strcasecmp(mfx->uiapplication->multiple, "True")) {
4216                         snprintf(buf, BUFMAX, "X-TIZEN-Multiple=True\n");
4217                         fwrite(buf, 1, strlen(buf), file);
4218                 }
4219
4220                 if(mfx->uiapplication->extraid) {
4221                         snprintf(buf, BUFMAX, "X-TIZEN-PackageID=%s\n", mfx->uiapplication->extraid);
4222                         fwrite(buf, 1, strlen(buf), file);
4223                 }
4224
4225                 if(mfx->removable && !strcasecmp(mfx->removable, "False")) {
4226                         snprintf(buf, BUFMAX, "X-TIZEN-Removable=False\n");
4227                         fwrite(buf, 1, strlen(buf), file);
4228                 }
4229
4230                 if(mfx->type) {
4231                         snprintf(buf, BUFMAX, "X-TIZEN-PackageType=%s\n", mfx->type);
4232                         fwrite(buf, 1, strlen(buf), file);
4233                 }
4234
4235                 snprintf(buf, BUFMAX, "X-TIZEN-PkgID=%s\n", mfx->package);
4236                 fwrite(buf, 1, strlen(buf), file);
4237
4238
4239 //              snprintf(buf, BUFMAX, "X-TIZEN-PackageType=rpm\n");
4240 //              fwrite(buf, 1, strlen(buf), file);
4241
4242
4243                 if(mfx->uiapplication->appsvc) {
4244                         snprintf(buf, BUFMAX, "X-TIZEN-Svc=");
4245                         DBG("buf[%s]\n", buf);
4246
4247
4248                         uiapplication_x *up = mfx->uiapplication;
4249                         appsvc_x *asvc = NULL;
4250                         operation_x *op = NULL;
4251                         mime_x *mi = NULL;
4252                         uri_x *ui = NULL;
4253                         subapp_x *sub = NULL;
4254                         const char *operation = NULL;
4255                         const char *mime = NULL;
4256                         const char *uri = NULL;
4257                         const char *subapp = NULL;
4258                         int i = 0;
4259
4260
4261                         asvc = up->appsvc;
4262                         while(asvc != NULL) {
4263                                 op = asvc->operation;
4264                                 while(op != NULL) {
4265                                         if (op)
4266                                                 operation = op->name;
4267                                         mi = asvc->mime;
4268
4269                                         do
4270                                         {
4271                                                 if (mi)
4272                                                         mime = mi->name;
4273                                                 sub = asvc->subapp;
4274                                                 do
4275                                                 {
4276                                                         if (sub)
4277                                                                 subapp = sub->name;
4278                                                         ui = asvc->uri;
4279                                                         do
4280                                                         {
4281                                                                 if (ui)
4282                                                                         uri = ui->name;
4283
4284                                                                 if(i++ > 0) {
4285                                                                         strncpy(buftemp, buf, BUFMAX);
4286                                                                         snprintf(buf, BUFMAX, "%s;", buftemp);
4287                                                                 }
4288
4289
4290                                                                 strncpy(buftemp, buf, BUFMAX);
4291                                                                 snprintf(buf, BUFMAX, "%s%s|%s|%s|%s", buftemp, operation?operation:"NULL", uri?uri:"NULL", mime?mime:"NULL", subapp?subapp:"NULL");
4292                                                                 DBG("buf[%s]\n", buf);
4293
4294                                                                 if (ui)
4295                                                                         ui = ui->next;
4296                                                                 uri = NULL;
4297                                                         } while(ui != NULL);
4298                                                 if (sub)
4299                                                                 sub = sub->next;
4300                                                         subapp = NULL;
4301                                                 }while(sub != NULL);
4302                                                 if (mi)
4303                                                         mi = mi->next;
4304                                                 mime = NULL;
4305                                         }while(mi != NULL);
4306                                         if (op)
4307                                                 op = op->next;
4308                                         operation = NULL;
4309                                 }
4310                                 asvc = asvc->next;
4311                         }
4312
4313
4314                         fwrite(buf, 1, strlen(buf), file);
4315
4316 //                      strncpy(buftemp, buf, BUFMAX);
4317 //                      snprintf(buf, BUFMAX, "%s\n", buftemp);
4318 //                      fwrite(buf, 1, strlen(buf), file);
4319                 }
4320
4321                 if(mfx->uiapplication->appcontrol) {
4322                         snprintf(buf, BUFMAX, "X-TIZEN-Svc=");
4323                         DBG("buf[%s]\n", buf);
4324
4325                         uiapplication_x *up = mfx->uiapplication;
4326                         appcontrol_x *acontrol = NULL;
4327                         operation_x *op = NULL;
4328                         mime_x *mi = NULL;
4329                         uri_x *ui = NULL;
4330                         subapp_x *sub = NULL;
4331                         const char *operation = NULL;
4332                         const char *mime = NULL;
4333                         const char *uri = NULL;
4334                         const char *subapp = NULL;
4335                         int i = 0;
4336
4337                         acontrol = up->appcontrol;
4338                         while(acontrol != NULL) {
4339                                 op = acontrol->operation;
4340                                 while(op != NULL) {
4341                                         if (op)
4342                                                 operation = op->name;
4343                                         mi = acontrol->mime;
4344
4345                                         do
4346                                         {
4347                                                 if (mi)
4348                                                         mime = mi->name;
4349                                                 sub = acontrol->subapp;
4350                                                 do
4351                                                 {
4352                                                         if (sub)
4353                                                                 subapp = sub->name;
4354                                                         ui = acontrol->uri;
4355                                                         do
4356                                                         {
4357                                                                 if (ui)
4358                                                                         uri = ui->name;
4359
4360                                                                 if(i++ > 0) {
4361                                                                         strncpy(buftemp, buf, BUFMAX);
4362                                                                         snprintf(buf, BUFMAX, "%s;", buftemp);
4363                                                                 }
4364
4365                                                                 strncpy(buftemp, buf, BUFMAX);
4366                                                                 snprintf(buf, BUFMAX, "%s%s|%s|%s|%s", buftemp, operation?operation:"NULL", uri?uri:"NULL", mime?mime:"NULL", subapp?subapp:"NULL");
4367                                                                 DBG("buf[%s]\n", buf);
4368
4369                                                                 if (ui)
4370                                                                         ui = ui->next;
4371                                                                 uri = NULL;
4372                                                         } while(ui != NULL);
4373                                                 if (sub)
4374                                                                 sub = sub->next;
4375                                                         subapp = NULL;
4376                                                 }while(sub != NULL);
4377                                                 if (mi)
4378                                                         mi = mi->next;
4379                                                 mime = NULL;
4380                                         }while(mi != NULL);
4381                                         if (op)
4382                                                 op = op->next;
4383                                         operation = NULL;
4384                                 }
4385                                 acontrol = acontrol->next;
4386                         }
4387
4388
4389                         fwrite(buf, 1, strlen(buf), file);
4390
4391 //                      strncpy(buftemp, buf, BUFMAX);
4392 //                      snprintf(buf, BUFMAX, "%s\n", buftemp);
4393 //                      fwrite(buf, 1, strlen(buf), file);
4394                 }
4395
4396                 fflush(file);
4397                 fd = fileno(file);
4398                 fsync(fd);
4399                 fclose(file);
4400
4401                 __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
4402         }
4403
4404         free(buf);
4405         free(buftemp);
4406
4407         return 0;
4408 }
4409
4410 static int __ps_remove_nativeapp_desktop(manifest_x *mfx)
4411 {
4412         char filepath[PKG_STRING_LEN_MAX] = "";
4413         int ret = 0;
4414         uiapplication_x *uiapplication = mfx->uiapplication;
4415
4416         for(; uiapplication; uiapplication=uiapplication->next) {
4417                 snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
4418
4419                 __ail_change_info(AIL_REMOVE, uiapplication->appid);
4420
4421                 ret = remove(filepath);
4422                 if (ret <0)
4423                         return -1;
4424         }
4425
4426         return 0;
4427 }
4428
4429 #define LIBAPPSVC_PATH LIB_PATH "/libappsvc.so.0"
4430
4431 static int __ps_remove_appsvc_db(manifest_x *mfx)
4432 {
4433         void *lib_handle = NULL;
4434         int (*appsvc_operation) (const char *);
4435         int ret = 0;
4436         uiapplication_x *uiapplication = mfx->uiapplication;
4437
4438         if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
4439                 DBGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAPPSVC_PATH);
4440                 goto END;
4441         }
4442
4443         if ((appsvc_operation =
4444                  dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
4445                 DBGE("can not find symbol \n");
4446                 goto END;
4447         }
4448
4449         for(; uiapplication; uiapplication=uiapplication->next) {
4450                 ret = appsvc_operation(uiapplication->appid);
4451                 if (ret <0)
4452                         DBGE("can not operation  symbol \n");
4453         }
4454
4455 END:
4456         if (lib_handle)
4457                 dlclose(lib_handle);
4458
4459         return ret;
4460 }
4461
4462 #define PRELOAD_PACKAGE_LIST SYSCONFDIR "/package-manager/preload/preload_list.txt"
4463 static int __add_preload_info(manifest_x * mfx, const char *manifest)
4464 {
4465         FILE *fp = NULL;
4466         char buffer[1024] = { 0 };
4467         int state = 0;
4468
4469         if(strstr(manifest, MANIFEST_RO_PREFIX)) {
4470                 free((void *)mfx->readonly);
4471                 mfx->readonly = strdup("True");
4472
4473                 free((void *)mfx->preload);
4474                 mfx->preload = strdup("True");
4475
4476                 free((void *)mfx->removable);
4477                 mfx->removable = strdup("False");
4478
4479                 free((void *)mfx->system);
4480                 mfx->system = strdup("True");
4481
4482                 return 0;
4483         }
4484
4485         fp = fopen(PRELOAD_PACKAGE_LIST, "r");
4486         if (fp == NULL) {
4487                 DBGE("no preload list\n");
4488                 return -1;
4489         }
4490
4491         while (fgets(buffer, sizeof(buffer), fp) != NULL) {
4492                 if (buffer[0] == '#') {
4493                         if(strcasestr(buffer, "RW_NORM"))
4494                                 state = 2;
4495                         else if(strcasestr(buffer, "RW_RM"))
4496                                 state = 3;
4497                         else
4498                                 continue;
4499                 }
4500
4501                 __str_trim(buffer);
4502
4503                 if(!strcmp(mfx->package, buffer)) {
4504                         free((void *)mfx->preload);
4505                         mfx->preload = strdup("True");
4506                         if(state == 2){
4507                                 free((void *)mfx->readonly);
4508                                 mfx->readonly = strdup("False");
4509                                 free((void *)mfx->removable);
4510                                 mfx->removable = strdup("False");
4511                         } else if(state == 3){
4512                                 free((void *)mfx->readonly);
4513                                 mfx->readonly = strdup("False");
4514                                 free((void *)mfx->removable);
4515                                 mfx->removable = strdup("True");
4516                         }
4517                 }
4518
4519                 memset(buffer, 0x00, sizeof(buffer));
4520         }
4521
4522         if (fp != NULL)
4523                 fclose(fp);
4524
4525         return 0;
4526 }
4527
4528 static int __check_preload_updated(manifest_x * mfx, const char *manifest)
4529 {
4530         char filepath[PKG_STRING_LEN_MAX] = "";
4531         int ret = 0;
4532         uiapplication_x *uiapplication = mfx->uiapplication;
4533
4534         if(strstr(manifest, MANIFEST_RO_PREFIX)) {
4535                 /* if preload app is updated, then remove previous desktop file on RW*/
4536                 for(; uiapplication; uiapplication=uiapplication->next) {
4537                                 snprintf(filepath, sizeof(filepath),"%s%s.desktop", DESKTOP_RW_PATH, uiapplication->appid);
4538                         ret = remove(filepath);
4539                         if (ret <0)
4540                                 return -1;
4541                 }
4542         } else {
4543                 /* if downloaded app is updated, then update tag set true*/
4544                 free((void *)mfx->update);
4545                 mfx->update = strdup("true");
4546         }
4547
4548         return 0;
4549 }
4550
4551
4552 API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
4553 {
4554         int ret = 0;
4555         if (mfx == NULL) {
4556                 DBG("Manifest pointer is NULL\n");
4557                 return -1;
4558         }
4559         ret = __ps_make_nativeapp_desktop(mfx, NULL, 0);
4560         if (ret == -1)
4561                 DBG("Creating desktop file failed\n");
4562         else
4563                 DBG("Creating desktop file Success\n");
4564         return ret;
4565 }
4566
4567 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
4568 {
4569         if (mfx == NULL)
4570                 return;
4571         if (mfx->ns) {
4572                 free((void *)mfx->ns);
4573                 mfx->ns = NULL;
4574         }
4575         if (mfx->package) {
4576                 free((void *)mfx->package);
4577                 mfx->package = NULL;
4578         }
4579         if (mfx->version) {
4580                 free((void *)mfx->version);
4581                 mfx->version = NULL;
4582         }
4583         if (mfx->installlocation) {
4584                 free((void *)mfx->installlocation);
4585                 mfx->installlocation = NULL;
4586         }
4587         if (mfx->preload) {
4588                 free((void *)mfx->preload);
4589                 mfx->preload = NULL;
4590         }
4591         if (mfx->readonly) {
4592                 free((void *)mfx->readonly);
4593                 mfx->readonly = NULL;
4594         }
4595         if (mfx->removable) {
4596                 free((void *)mfx->removable);
4597                 mfx->removable = NULL;
4598         }
4599         if (mfx->update) {
4600                 free((void *)mfx->update);
4601                 mfx->update = NULL;
4602         }
4603         if (mfx->system) {
4604                 free((void *)mfx->system);
4605                 mfx->system = NULL;
4606         }
4607         if (mfx->type) {
4608                 free((void *)mfx->type);
4609                 mfx->type = NULL;
4610         }
4611         if (mfx->package_size) {
4612                 free((void *)mfx->package_size);
4613                 mfx->package_size = NULL;
4614         }
4615         if (mfx->installed_time) {
4616                 free((void *)mfx->installed_time);
4617                 mfx->installed_time = NULL;
4618         }
4619         if (mfx->installed_storage) {
4620                 free((void *)mfx->installed_storage);
4621                 mfx->installed_storage = NULL;
4622         }
4623         if (mfx->storeclient_id) {
4624                 free((void *)mfx->storeclient_id);
4625                 mfx->storeclient_id = NULL;
4626         }
4627         if (mfx->mainapp_id) {
4628                 free((void *)mfx->mainapp_id);
4629                 mfx->mainapp_id = NULL;
4630         }
4631         if (mfx->package_url) {
4632                 free((void *)mfx->package_url);
4633                 mfx->package_url = NULL;
4634         }
4635         if (mfx->root_path) {
4636                 free((void *)mfx->root_path);
4637                 mfx->root_path = NULL;
4638         }
4639         if (mfx->csc_path) {
4640                 free((void *)mfx->csc_path);
4641                 mfx->csc_path = NULL;
4642         }
4643         if (mfx->appsetting) {
4644                 free((void *)mfx->appsetting);
4645                 mfx->appsetting = NULL;
4646         }
4647         if (mfx->nodisplay_setting) {
4648                 free((void *)mfx->nodisplay_setting);
4649                 mfx->nodisplay_setting = NULL;
4650         }
4651
4652         /*Free Icon*/
4653         if (mfx->icon) {
4654                 icon_x *icon = mfx->icon;
4655                 icon_x *tmp = NULL;
4656                 while(icon != NULL) {
4657                         tmp = icon->next;
4658                         __ps_free_icon(icon);
4659                         icon = tmp;
4660                 }
4661         }
4662         /*Free Label*/
4663         if (mfx->label) {
4664                 label_x *label = mfx->label;
4665                 label_x *tmp = NULL;
4666                 while(label != NULL) {
4667                         tmp = label->next;
4668                         __ps_free_label(label);
4669                         label = tmp;
4670                 }
4671         }
4672         /*Free Author*/
4673         if (mfx->author) {
4674                 author_x *author = mfx->author;
4675                 author_x *tmp = NULL;
4676                 while(author != NULL) {
4677                         tmp = author->next;
4678                         __ps_free_author(author);
4679                         author = tmp;
4680                 }
4681         }
4682         /*Free Description*/
4683         if (mfx->description) {
4684                 description_x *description = mfx->description;
4685                 description_x *tmp = NULL;
4686                 while(description != NULL) {
4687                         tmp = description->next;
4688                         __ps_free_description(description);
4689                         description = tmp;
4690                 }
4691         }
4692         /*Free License*/
4693         if (mfx->license) {
4694                 license_x *license = mfx->license;
4695                 license_x *tmp = NULL;
4696                 while(license != NULL) {
4697                         tmp = license->next;
4698                         __ps_free_license(license);
4699                         license = tmp;
4700                 }
4701         }
4702         /*Free Privileges*/
4703         if (mfx->privileges) {
4704                 privileges_x *privileges = mfx->privileges;
4705                 privileges_x *tmp = NULL;
4706                 while(privileges != NULL) {
4707                         tmp = privileges->next;
4708                         __ps_free_privileges(privileges);
4709                         privileges = tmp;
4710                 }
4711         }
4712         /*Free UiApplication*/
4713         if (mfx->uiapplication) {
4714                 uiapplication_x *uiapplication = mfx->uiapplication;
4715                 uiapplication_x *tmp = NULL;
4716                 while(uiapplication != NULL) {
4717                         tmp = uiapplication->next;
4718                         __ps_free_uiapplication(uiapplication);
4719                         uiapplication = tmp;
4720                 }
4721         }
4722         /*Free ServiceApplication*/
4723         if (mfx->serviceapplication) {
4724                 serviceapplication_x *serviceapplication = mfx->serviceapplication;
4725                 serviceapplication_x *tmp = NULL;
4726                 while(serviceapplication != NULL) {
4727                         tmp = serviceapplication->next;
4728                         __ps_free_serviceapplication(serviceapplication);
4729                         serviceapplication = tmp;
4730                 }
4731         }
4732         /*Free Daemon*/
4733         if (mfx->daemon) {
4734                 daemon_x *daemon = mfx->daemon;
4735                 daemon_x *tmp = NULL;
4736                 while(daemon != NULL) {
4737                         tmp = daemon->next;
4738                         __ps_free_daemon(daemon);
4739                         daemon = tmp;
4740                 }
4741         }
4742         /*Free Theme*/
4743         if (mfx->theme) {
4744                 theme_x *theme = mfx->theme;
4745                 theme_x *tmp = NULL;
4746                 while(theme != NULL) {
4747                         tmp = theme->next;
4748                         __ps_free_theme(theme);
4749                         theme = tmp;
4750                 }
4751         }
4752         /*Free Font*/
4753         if (mfx->font) {
4754                 font_x *font = mfx->font;
4755                 font_x *tmp = NULL;
4756                 while(font != NULL) {
4757                         tmp = font->next;
4758                         __ps_free_font(font);
4759                         font = tmp;
4760                 }
4761         }
4762         /*Free Ime*/
4763         if (mfx->ime) {
4764                 ime_x *ime = mfx->ime;
4765                 ime_x *tmp = NULL;
4766                 while(ime != NULL) {
4767                         tmp = ime->next;
4768                         __ps_free_ime(ime);
4769                         ime = tmp;
4770                 }
4771         }
4772         /*Free Compatibility*/
4773         if (mfx->compatibility) {
4774                 compatibility_x *compatibility = mfx->compatibility;
4775                 compatibility_x *tmp = NULL;
4776                 while(compatibility != NULL) {
4777                         tmp = compatibility->next;
4778                         __ps_free_compatibility(compatibility);
4779                         compatibility = tmp;
4780                 }
4781         }
4782         /*Free DeviceProfile*/
4783         if (mfx->deviceprofile) {
4784                 deviceprofile_x *deviceprofile = mfx->deviceprofile;
4785                 deviceprofile_x *tmp = NULL;
4786                 while(deviceprofile != NULL) {
4787                         tmp = deviceprofile->next;
4788                         __ps_free_deviceprofile(deviceprofile);
4789                         deviceprofile = tmp;
4790                 }
4791         }
4792         free((void*)mfx);
4793         mfx = NULL;
4794         return;
4795 }
4796
4797 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
4798 {
4799         DBG("parsing start\n");
4800         xmlTextReaderPtr reader;
4801         manifest_x *mfx = NULL;
4802
4803         reader = xmlReaderForFile(manifest, NULL, 0);
4804         if (reader) {
4805                 mfx = malloc(sizeof(manifest_x));
4806                 if (mfx) {
4807                         memset(mfx, '\0', sizeof(manifest_x));
4808                         if (__process_manifest(reader, mfx) < 0) {
4809                                 DBG("Parsing Failed\n");
4810                                 pkgmgr_parser_free_manifest_xml(mfx);
4811                                 mfx = NULL;
4812                         } else
4813                                 DBG("Parsing Success\n");
4814                 } else {
4815                         DBG("Memory allocation error\n");
4816                 }
4817                 xmlFreeTextReader(reader);
4818         } else {
4819                 DBG("Unable to create xml reader\n");
4820         }
4821         return mfx;
4822 }
4823
4824 /* These APIs are intended to call parser directly */
4825
4826 API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
4827 {
4828         char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
4829         if (manifest == NULL) {
4830                 DBG("argument supplied is NULL\n");
4831                 return PMINFO_R_EINVAL;
4832         }
4833         DBG("parsing manifest for installation: %s\n", manifest);
4834         manifest_x *mfx = NULL;
4835         int ret = -1;
4836         char roxml_check[PKG_STRING_LEN_MAX] = {'\0'};
4837
4838         xmlInitParser();
4839         mfx = pkgmgr_parser_process_manifest_xml(manifest);
4840         DBG("Parsing Finished\n");
4841         if (mfx == NULL)
4842                 return PMINFO_R_ERROR;
4843
4844         __streamFile(manifest, ACTION_INSTALL, temp, mfx->package);
4845         __add_preload_info(mfx, manifest);
4846         DBG("Added preload infomation\n");
4847
4848         __ps_process_tag(mfx, tagv);
4849
4850         ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
4851         if (ret == -1)
4852                 DBG("DB Insert failed\n");
4853         else
4854                 DBG("DB Insert Success\n");
4855
4856         ret = __ps_process_mdparser(mfx, ACTION_INSTALL);
4857         if (ret == -1)
4858                 DBG("Creating metadata parser failed\n");
4859
4860         ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
4861         if (ret == -1)
4862                 DBG("Creating category parser failed\n");
4863
4864         ret = __ps_make_nativeapp_desktop(mfx, NULL, 0);
4865         if (ret == -1)
4866                 DBG("Creating desktop file failed\n");
4867         else
4868                 DBG("Creating desktop file Success\n");
4869
4870         pkgmgr_parser_free_manifest_xml(mfx);
4871         DBG("Free Done\n");
4872         xmlCleanupParser();
4873
4874         return PMINFO_R_OK;
4875 }
4876
4877 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
4878 {
4879         char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
4880         if (manifest == NULL) {
4881                 DBG("argument supplied is NULL\n");
4882                 return PMINFO_R_EINVAL;
4883         }
4884         DBG("parsing manifest for upgradation: %s\n", manifest);
4885         manifest_x *mfx = NULL;
4886         int ret = -1;
4887         bool preload = false;
4888         bool system = false;
4889         char *csc_path = NULL;
4890         pkgmgrinfo_pkginfo_h handle = NULL;
4891
4892         xmlInitParser();
4893         mfx = pkgmgr_parser_process_manifest_xml(manifest);
4894         DBG("Parsing Finished\n");
4895         if (mfx == NULL)
4896                 return PMINFO_R_ERROR;
4897         
4898         __streamFile(manifest, ACTION_UPGRADE, temp, mfx->package);
4899         __add_preload_info(mfx, manifest);
4900         DBG("Added preload infomation\n");
4901         __check_preload_updated(mfx, manifest);
4902
4903         ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
4904         if (ret != PMINFO_R_OK)
4905                 DBG("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
4906
4907         ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
4908         if (ret != PMINFO_R_OK)
4909                 DBG("pkgmgrinfo_pkginfo_is_preload failed\n");
4910
4911         if (preload) {
4912                 free((void *)mfx->preload);
4913                 mfx->preload = strdup("true");
4914         }
4915
4916         ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
4917         if (ret != PMINFO_R_OK)
4918                 DBG("pkgmgrinfo_pkginfo_is_system failed\n");
4919
4920         if (system) {
4921                 free((void *)mfx->system);
4922                 mfx->system = strdup("true");
4923         }
4924
4925         ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
4926         if (ret != PMINFO_R_OK)
4927                 DBG("pkgmgrinfo_pkginfo_get_csc_path failed\n");
4928
4929         if (csc_path != NULL) {
4930                 if (mfx->csc_path)
4931                         free((void *)mfx->csc_path);
4932                 mfx->csc_path = strdup(csc_path);
4933         }
4934
4935         ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
4936         if (ret == -1)
4937                 DBG("DB Update failed\n");
4938         else
4939                 DBG("DB Update Success\n");
4940
4941         ret = __ps_process_mdparser(mfx, ACTION_UPGRADE);
4942         if (ret == -1)
4943                 DBG("Upgrade metadata parser failed\n");
4944
4945         ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
4946         if (ret == -1)
4947                 DBG("Creating category parser failed\n");
4948
4949         ret = __ps_make_nativeapp_desktop(mfx, manifest, 1);
4950         if (ret == -1)
4951                 DBG("Creating desktop file failed\n");
4952         else
4953                 DBG("Creating desktop file Success\n");
4954
4955         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
4956         pkgmgr_parser_free_manifest_xml(mfx);
4957         DBG("Free Done\n");
4958         xmlCleanupParser();
4959
4960         return PMINFO_R_OK;
4961 }
4962
4963 API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
4964 {
4965         char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
4966         if (manifest == NULL) {
4967                 DBG("argument supplied is NULL\n");
4968                 return PMINFO_R_EINVAL;
4969         }
4970         DBG("parsing manifest for uninstallation: %s\n", manifest);
4971         manifest_x *mfx = NULL;
4972         int ret = -1;
4973         xmlInitParser();
4974         mfx = pkgmgr_parser_process_manifest_xml(manifest);
4975         DBG("Parsing Finished\n");
4976         if (mfx == NULL)
4977                 return PMINFO_R_ERROR;
4978         
4979         __streamFile(manifest, ACTION_UNINSTALL, temp, mfx->package);
4980         __add_preload_info(mfx, manifest);
4981         DBG("Added preload infomation\n");
4982
4983         ret = __ps_process_mdparser(mfx, ACTION_UNINSTALL);
4984         if (ret == -1)
4985                 DBG("Removing metadata parser failed\n");
4986
4987         ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
4988         if (ret == -1)
4989                 DBG("Creating category parser failed\n");
4990
4991         ret = pkgmgr_parser_delete_manifest_info_from_db(mfx);
4992         if (ret == -1)
4993                 DBG("DB Delete failed\n");
4994         else
4995                 DBG("DB Delete Success\n");
4996
4997         ret = __ps_remove_nativeapp_desktop(mfx);
4998         if (ret == -1)
4999                 DBG("Removing desktop file failed\n");
5000         else
5001                 DBG("Removing desktop file Success\n");
5002
5003         ret = __ps_remove_appsvc_db(mfx);
5004         if (ret == -1)
5005                 DBG("Removing appsvc_db failed\n");
5006         else
5007                 DBG("Removing appsvc_db Success\n");
5008
5009         pkgmgr_parser_free_manifest_xml(mfx);
5010         DBG("Free Done\n");
5011         xmlCleanupParser();
5012
5013         return PMINFO_R_OK;
5014 }
5015
5016 API int pkgmgr_parser_parse_manifest_for_preload()
5017 {
5018         return pkgmgr_parser_update_preload_info_in_db();
5019 }
5020
5021 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
5022 {
5023         return __pkgid_to_manifest(pkgid);
5024 }
5025
5026 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
5027 {
5028         return __ps_run_parser(docPtr, tag, ACTION_INSTALL, pkgid);
5029 }
5030
5031 API int pkgmgr_parser_run_parser_for_upgrade(xmlDocPtr docPtr, const char *tag, const char *pkgid)
5032 {
5033         return __ps_run_parser(docPtr, tag, ACTION_UPGRADE, pkgid);
5034 }
5035
5036 API int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
5037 {
5038         return __ps_run_parser(docPtr, tag, ACTION_UNINSTALL, pkgid);
5039 }
5040
5041 #define SCHEMA_FILE SYSCONFDIR "/package-manager/preload/manifest.xsd"
5042 #if 1
5043 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
5044 {
5045         if (manifest == NULL) {
5046                 DBGE("manifest file is NULL\n");
5047                 return PMINFO_R_EINVAL;
5048         }
5049         int ret = -1;
5050         xmlSchemaParserCtxtPtr ctx;
5051         xmlSchemaValidCtxtPtr vctx;
5052         xmlSchemaPtr xschema;
5053         ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE);
5054         if (ctx == NULL) {
5055                 DBGE("xmlSchemaNewParserCtxt() Failed\n");
5056                 return PMINFO_R_ERROR;
5057         }
5058         xschema = xmlSchemaParse(ctx);
5059         if (xschema == NULL) {
5060                 DBGE("xmlSchemaParse() Failed\n");
5061                 return PMINFO_R_ERROR;
5062         }
5063         vctx = xmlSchemaNewValidCtxt(xschema);
5064         if (vctx == NULL) {
5065                 DBGE("xmlSchemaNewValidCtxt() Failed\n");
5066                 return PMINFO_R_ERROR;
5067         }
5068         xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) fprintf, (xmlSchemaValidityWarningFunc) fprintf, stderr);
5069         ret = xmlSchemaValidateFile(vctx, manifest, 0);
5070         if (ret == -1) {
5071                 DBGE("xmlSchemaValidateFile() failed\n");
5072                 return PMINFO_R_ERROR;
5073         } else if (ret == 0) {
5074                 DBGE("Manifest is Valid\n");
5075                 return PMINFO_R_OK;
5076         } else {
5077                 DBGE("Manifest Validation Failed with error code %d\n", ret);
5078                 return PMINFO_R_ERROR;
5079         }
5080         return PMINFO_R_OK;
5081 }
5082
5083 #else
5084 API int pkgmgr_parser_check_manifest_validation(const char *manifest)
5085 {
5086         int err = 0;
5087         int status = 0;
5088         pid_t pid;
5089
5090         pid = fork();
5091
5092         switch (pid) {
5093         case -1:
5094                 DBGE("fork failed\n");
5095                 return -1;
5096         case 0:
5097                 /* child */
5098                 {
5099                         int dev_null_fd = open ("/dev/null", O_RDWR);
5100                         if (dev_null_fd >= 0)
5101                         {
5102                                 dup2 (dev_null_fd, 0);/*stdin*/
5103                                 dup2 (dev_null_fd, 1);/*stdout*/
5104                                 dup2 (dev_null_fd, 2);/*stderr*/
5105                         }
5106
5107                         if (execl("/usr/bin/xmllint", "xmllint", manifest, "--schema",
5108                                 SCHEMA_FILE, NULL) < 0) {
5109                                 DBGE("execl error\n");
5110                         }
5111
5112                         _exit(100);
5113                 }
5114         default:
5115                 /* parent */
5116                 break;
5117         }
5118
5119         while ((err = waitpid(pid, &status, WNOHANG)) != pid) {
5120                 if (err < 0) {
5121                         if (errno == EINTR)
5122                                 continue;
5123                         DBGE("waitpid failed\n");
5124                         return -1;
5125                 }
5126         }
5127
5128
5129         if(WIFEXITED(status) && !WEXITSTATUS(status))
5130                 return 0;
5131         else
5132                 return -1;
5133 }
5134 #endif