replace strerror() to strerror_r() for thread safety
[platform/core/uifw/download-fonts-service.git] / pkgmgr_font / src / font_service_register.c
1 /*
2  * Copyright 2013 Samsung Electronics Co., Ltd
3  *
4  *
5  * Contact: Minsu Seo <minsu15.seo@samsung.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 #include <stdio.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <sys/xattr.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <dirent.h>
26 #include <glib.h>
27 #include <dlog.h>
28 #include <fontconfig/fontconfig.h>
29 #include <Elementary.h>
30 #include <pkgmgr-info.h>
31 #include <pkgmgr_installer_info.h>
32 #include "system_settings.h"
33
34 #define FONT_SERVICE_TAG                "FONT_SERVICE"
35 #define DEBUG_LOG(frmt, args...)                \
36         do { SLOG(LOG_DEBUG,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
37         __func__, ##args);} while (0)
38 #define DEBUG_WARNING(frmt, args...)            \
39         do { SLOG(LOG_WARN,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
40         __func__, ##args);} while (0)
41 #define DEBUG_ERROR(frmt, args...)              \
42         do { SLOG(LOG_ERROR,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\
43         __func__, ##args);} while (0)
44 #define DEBUG_ERROR_ERRNO(frmt, args...)                \
45         do { \
46                 char error_string[255] = { 0 }; \
47                 strerror_r(errno, error_string, sizeof(error_string)); \
48                 SLOG(LOG_ERROR,FONT_SERVICE_TAG, "[font_service] %s: "frmt": %s\n",\
49         __func__, ##args, error_string);} while (0)
50
51 static const char *PARENT_PATH = "/opt/share/fonts";
52 static const char *DOWNLOAD_PATH = "/opt/share/fonts/download";
53 static const char *PRELOADED_PATH = "/opt/share/fonts/preloaded";
54
55 #define MAX_FILE_LEN 4096
56 #define APP_OWNER_ID 5001
57 #define APP_GROUP_ID 100
58
59 static int make_dir(const char *path);
60 static int symbolic_link(const char *srcpath, const char *destpath);
61 static int do_install(const char *parent, const char *appid, const char *rootpath, pkgmgrinfo_pkginfo_h handle);
62 static int do_uninstall(const char *deletedir);
63 static int move_path(const char *srcpath, const char *destpath);
64 static const char* check_preloaded(const char *app_root_path);
65 #ifdef CHECK_FAMILY_NAME
66 static int check_family_name(const char *srcpath);
67 #endif
68
69 static const char* check_preloaded(const char *app_root_path)
70 {
71         char tpk_path[MAX_FILE_LEN];
72         char wgt_path[MAX_FILE_LEN];
73
74         snprintf(tpk_path, sizeof(tpk_path), "%s/preloaded", app_root_path);
75         snprintf(wgt_path, sizeof(wgt_path), "%s/res/wgt/preloaded", app_root_path);
76
77         if ((access(tpk_path, F_OK) == 0) || (access(wgt_path, F_OK) == 0))
78         {
79                 return PRELOADED_PATH;
80         }
81
82         return DOWNLOAD_PATH;
83 }
84
85 static int make_dir(const char *path)
86 {
87         int ret = 0;
88
89         if (access(path, F_OK) == 0)
90         {
91                 return ret;
92         }
93         else
94         {
95                 ret = mkdir(path, 0755);
96                 if (ret < 0)
97                 {
98                         DEBUG_ERROR("make current directory %s is failed \n",path);
99                         return ret;
100                 }
101
102                 ret = chown(path, getuid(), APP_GROUP_ID);
103                 if (ret < 0)
104                 {
105                         DEBUG_ERROR("chown is failed %s\n",path);
106                         return ret;
107                 }
108
109                 ret = chmod(path, 0755);
110                 if (ret < 0)
111                 {
112                         DEBUG_ERROR("chmod is failed %s\n",path);
113                         rmdir(path);
114                         return ret;
115                 }
116         }
117
118         return ret;
119 }
120
121 static int symbolic_link(const char *srcpath, const char *destpath)
122 {
123         DIR *d;
124         struct dirent *e;
125         int ret = 0;
126
127         d = opendir(srcpath);
128         while ((e = readdir (d)))
129         {
130                 if (e->d_name[0] != '.' && strlen((char *)e->d_name) < MAX_FILE_LEN)
131                 {
132                         char srcdir[MAX_FILE_LEN];
133                         char destdir[MAX_FILE_LEN];
134                         struct stat       statb;
135
136                         if (strlen (srcpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
137                         {
138                                 DEBUG_ERROR("srcdir length is not available \n");
139                                 goto FAIL;
140                         }
141
142                         if (strlen (destpath) + strlen ((char *)e->d_name) + 2 >= MAX_FILE_LEN )
143                         {
144                                 DEBUG_ERROR("destdir length is not available \n");
145                                 goto FAIL;
146                         }
147
148                         snprintf(srcdir, sizeof(srcdir), "%s/%s", srcpath, (char *)e->d_name);
149                         snprintf(destdir, sizeof(destdir), "%s/%s", destpath, (char *)e->d_name);
150                         if (stat (srcdir, &statb) == -1)
151                         {
152                                 DEBUG_ERROR("stat %s is failed \n",srcdir);
153                                 goto FAIL;
154                         }
155
156                         if (S_ISDIR (statb.st_mode))
157                         {
158                                 if (make_dir(destdir)<0)
159                                 {
160                                         DEBUG_ERROR("make current directory %s is failed \n",destdir);
161                                         goto FAIL;
162                                 }
163                                 ret = symbolic_link(srcdir,destdir);
164                                 if (ret < 0)
165                                 {
166                                         DEBUG_ERROR("symlink is failed \n");
167                                         goto FAIL;
168                                 }
169                                 continue;
170                         }
171                         DEBUG_LOG("srcdir =%s\n",(char *) srcdir);
172                         DEBUG_LOG("destdir =%s\n",(char *) destdir);
173                         DEBUG_LOG("file name =%s\n",(char *) e->d_name);
174
175                         ret = symlink((const char *)srcdir,(const char *)destdir);
176                         if (ret < 0)
177                         {
178                                 DEBUG_ERROR("symlink is failed \n");
179                                 goto FAIL;
180                         }
181                 }
182         }
183         closedir (d);
184         return ret;
185
186 FAIL:
187         closedir (d);
188         return -1;
189 }
190
191 #define COPY_BUF_SIZE 16777216
192
193 static int copy_file(const char *srcpath, const char *destpath) {
194         FILE *in = NULL, *out = NULL;
195         char *buf = NULL;
196         size_t len;
197
198         if (!srcpath || !destpath)
199         {
200                 DEBUG_ERROR("copyfile is failed. A given param is NULL ... srcpath[%s], destpath[%s]\n", srcpath, destpath);
201                 goto FAIL;
202         }
203
204         if (!strcmp(srcpath, destpath))
205         {
206                 DEBUG_ERROR("copyfile is failed. The both path are same ... srcpath[%s], destpath[%s]\n", srcpath, destpath);
207                 goto FAIL;
208         }
209
210         if ((in  = fopen(srcpath, "rb")) == NULL)
211         {
212                 DEBUG_ERROR_ERRNO("copyfile is failed. The srcpath[%s] is not opened with read permission. fopen()", srcpath);
213                 goto FAIL;
214         }
215
216         if ((out = fopen(destpath, "wb")) == NULL)
217         {
218                 DEBUG_ERROR_ERRNO("copyfile is failed. The destpath[%s] is not opened with write permission. fopen()", destpath);
219                 goto FAIL;
220         }
221
222         if ((buf = (char *) malloc(COPY_BUF_SIZE)) == NULL)
223         {
224                 DEBUG_ERROR_ERRNO("copyfile is failed. Memory allocation for copy buffer is failed. Request size [%d]. malloc()", COPY_BUF_SIZE);
225                 goto FAIL;
226         }
227
228         while ((len = fread(buf, sizeof(char), sizeof(buf), in)) != 0)
229         {
230                 if (fwrite(buf, sizeof(char), len, out) == 0)
231                 {
232                         /* Reads "len" string. But, it fails to write file.
233                            We need to remove wrong result. */
234                         DEBUG_ERROR_ERRNO("copyfile is failed. fwrite fails to write. fwrite()");
235
236                         fclose(out);
237                         out = NULL;
238
239                         if (remove(destpath) == -1)
240                                 DEBUG_ERROR_ERRNO("removing copied file with error is failed. remove()");
241
242                         goto FAIL;
243                 }
244         }
245
246         /* Copy file DONE! */
247         if (in) fclose(in);
248         if (out) fclose(out);
249         if (buf) free(buf);
250         return 0;
251
252 FAIL:
253         if (in) fclose(in);
254         if (out) fclose(out);
255         if (buf) free(buf);
256         return -1;
257 }
258
259 static int move_path(const char *srcpath, const char *destpath)
260 {
261         DIR *d;
262         struct dirent *e;
263         int ret = 0;
264
265         d = opendir(srcpath);
266         while ((e = readdir(d)))
267         {
268                 if (e->d_name[0] != '.' && strlen((char *)e->d_name) < MAX_FILE_LEN)
269                 {
270                         char srcdir[MAX_FILE_LEN];
271                         char destdir[MAX_FILE_LEN];
272                         struct stat statb;
273
274                         if (strlen(srcpath) + strlen((char *)e->d_name) + 2 >= MAX_FILE_LEN)
275                         {
276                                 DEBUG_ERROR("srcdir length is not available \n");
277                                 goto FAIL;
278                         }
279
280                         if (strlen(destpath) + strlen((char *)e->d_name) + 2 >= MAX_FILE_LEN)
281                         {
282                                 DEBUG_ERROR("destdir length is not available \n");
283                                 goto FAIL;
284                         }
285
286                         snprintf(srcdir, sizeof(srcdir), "%s/%s", srcpath, (char *)e->d_name);
287                         snprintf(destdir, sizeof(destdir), "%s/%s", destpath, (char *)e->d_name);
288
289                         if (stat(srcdir, &statb) == -1)
290                         {
291                                 DEBUG_ERROR("stat %s is failed \n",srcdir);
292                                 goto FAIL;
293                         }
294
295                         if (S_ISDIR(statb.st_mode))
296                         {
297                                 if (make_dir(destdir) < 0)
298                                 {
299                                         DEBUG_ERROR("make current directory %s is failed \n", destdir);
300                                         goto FAIL;
301                                 }
302                                 continue;
303                         }
304
305                         DEBUG_LOG("srcdir =%s\n", (char *)srcdir);
306                         DEBUG_LOG("destdir =%s\n", (char *)destdir);
307                         DEBUG_LOG("file name =%s\n", (char *)e->d_name);
308
309                         /* We need copy font file instead of rename() function.
310                            To apply smack label of parent directory, we need create new file to the path. */
311                         ret = copy_file(srcdir, destdir);
312                         if (ret < 0)
313                         {
314                                 DEBUG_ERROR("copy_file is failed \n");
315                                 goto FAIL;
316                         }
317
318                         if (remove(srcdir) == -1)
319                                 DEBUG_ERROR_ERRNO("removing src file[%s] is failed. remove()", srcdir);
320                 }
321         }
322
323         closedir(d);
324         return ret;
325
326 FAIL:
327         closedir(d);
328         return -1;
329 }
330
331 #ifdef CHECK_FAMILY_NAME
332 static int check_family_name(const char *srcpath)
333 {
334         FcObjectSet *os = NULL;
335         FcFontSet* fs = NULL;
336         FcPattern* pat = NULL;
337         FcConfig* font_config = NULL;
338         bool is_only_one_family = false;
339
340         font_config = FcInitLoadConfigAndFonts();
341
342         if(font_config == NULL) {
343                 DEBUG_ERROR("Failed: FcInitLoadConfigAndFonts");
344                 return -1;
345         }
346
347         pat = FcPatternCreate();
348
349         os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *) 0);
350
351         if (os) {
352                 fs = FcFontList(font_config, pat, os);
353                 FcObjectSetDestroy(os);
354                 os = NULL;
355         }
356
357         if (pat) {
358                 FcPatternDestroy(pat);
359                 pat = NULL;
360         }
361
362         if (fs)
363         {
364                 int j;
365                 char* only_one_family = NULL;
366
367                 for (j = 0; j < fs->nfont; j++)
368                 {
369                         FcChar8 *family = NULL;
370                         FcChar8 *file = NULL;
371
372                         if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
373                         {
374                                 int font_path_len = strlen(srcpath);
375
376                                         /* always shown for src path */
377                                         if (strncmp((const char*)file, srcpath, font_path_len) == 0)
378                                         {
379                                                                 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, 0, &family) != FcResultMatch)
380                                                                 {
381                                                                         DEBUG_ERROR("Family name is invalid");
382                                                                         continue;
383                                                                 }
384                                                                 //DEBUG_ERROR("-------- FOUND FONT - family = %s", (char *)family);
385
386                                                                 // first found family name
387                                                                 if (only_one_family == NULL  && strlen((char *)family) > 0)
388                                                                 {
389                                                                         is_only_one_family = true;
390                                                                         only_one_family = (char *)family;
391                                                                         //DEBUG_ERROR("--------First FOUND FONT - family = %s", only_one_family);
392                                                                 }
393                                                                 else if (only_one_family != NULL  && strlen((char *)family) > 0)// after first
394                                                                 {
395                                                                                 if (strcmp(only_one_family,  (char *)family) != 0)
396                                                                                 {
397                                                                                         DEBUG_ERROR("Not supported various font famliy. only one font famliy. %s %s", only_one_family, (char *)family);
398                                                                                         is_only_one_family = false;
399                                                                                         break;
400                                                                                 }
401                                                                 }
402                                                                 else
403                                                                 {
404                                                                         DEBUG_ERROR("invalid fonts");
405                                                                         break;
406                                                                 }
407                                         }
408                         }
409                 }
410
411                 FcFontSetDestroy(fs);
412                 fs = NULL;
413         }
414
415         FcConfigDestroy(font_config);
416         font_config = NULL;
417
418         if (is_only_one_family == false)
419         {
420                 //DEBUG_ERROR("Not supported various font famliy. only one font famliy");
421                 return -1;
422         }
423
424         return 0;
425 }
426 #endif
427
428 static int do_install(const char *parent, const char *appid, const char *rootpath, pkgmgrinfo_pkginfo_h handle)
429 {
430         char destdir[MAX_FILE_LEN];
431         char path[MAX_FILE_LEN];
432         char *type = NULL;
433         int ret = 0;
434
435         if (strlen (parent) + strlen (appid) + 2 >= MAX_FILE_LEN )
436         {
437                 DEBUG_ERROR("appid length is not available \n");
438                 return -1;
439         }
440
441         snprintf(destdir, sizeof(destdir), "%s/%s", parent, appid);
442         ret = make_dir(destdir);
443         if (ret < 0)
444         {
445                 DEBUG_ERROR("make current directory %s is failed \n", destdir);
446                 goto FAIL;
447         }
448
449         if (strlen (rootpath) + 2 >= MAX_FILE_LEN )
450         {
451                 DEBUG_ERROR("rootpath length is not available \n");
452                 goto FAIL;
453         }
454
455         ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
456         if (ret < 0)
457         {
458                 DEBUG_ERROR("pkgmgrinfo_pkginfo_get_type is failed\n");
459                 goto FAIL;
460         }
461
462         snprintf(path, sizeof(path), "%s/shared/res", rootpath);
463
464         if (!strcmp(type,"wgt"))
465         {
466                 char srcpath[MAX_FILE_LEN];
467                 snprintf(srcpath, sizeof(srcpath), "%s/res/wgt/shared/res", rootpath);
468                 ret = move_path(srcpath, path);
469         }
470
471         if (ret < 0)
472         {
473                 DEBUG_ERROR("move_path is failed\n");
474                 goto FAIL;
475         }
476
477         ret = symbolic_link(path, destdir);
478
479         if (ret < 0)
480         {
481                 DEBUG_ERROR("install is failed \n", destdir);
482                 goto FAIL;
483         }
484
485 #ifdef CHECK_FAMILY_NAME
486         ret = check_family_name(destdir);
487
488         if (ret < 0)
489         {
490                 DEBUG_ERROR("Invaid font files\n");
491                 goto FAIL;
492         }
493 #endif
494
495         return ret;
496
497 FAIL:
498         do_uninstall(destdir);
499         return -1;
500 }
501
502
503 static int do_uninstall(const char *deletedir)
504 {
505         DIR     *d;
506         struct dirent *e;
507
508         d = opendir(deletedir);
509         while((e = readdir (d)))
510         {
511                 if (e->d_name[0] != '.')
512                 {
513                         char destfile[MAX_FILE_LEN];
514                         struct stat       statb;
515
516                         if (strlen (deletedir) + strlen ((char *) e->d_name) + 2 >= MAX_FILE_LEN )
517                         {
518                                 DEBUG_ERROR("destfile length is not available \n");
519                                 goto FAIL;
520                         }
521
522                         snprintf(destfile, sizeof(destfile), "%s/%s", deletedir, (char *)e->d_name);
523                         if (lstat (destfile, &statb) == -1)
524                         {
525                                 DEBUG_ERROR("lstat %s is failed \n",destfile);
526                                 goto FAIL;
527                         }
528
529                         if (S_ISDIR (statb.st_mode))
530                         {
531                                 if (do_uninstall(destfile)<0)
532                                         goto FAIL;
533                         }
534                         else if (unlink(destfile) < 0)
535                         {
536                                 DEBUG_ERROR("unlink is failed %s\n",destfile);
537                                 goto FAIL;
538                         }
539                         DEBUG_LOG("destfile =%s\n",destfile);
540                 }
541         }
542
543         closedir (d);
544
545         if (rmdir(deletedir) < 0)
546         {
547                 DEBUG_ERROR("rmdir is failed \n");
548                 return -1;
549         }
550
551         DEBUG_LOG("rmdir =%s\n",deletedir);
552         return 0;
553
554 FAIL:
555         closedir (d);
556         return -1;
557 }
558
559
560 int COMMON_PKGMGR_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
561 {
562         int ret;
563         pkgmgrinfo_pkginfo_h handle = NULL;
564         const char *app_root_path = NULL;
565         const char *dest_path = NULL;
566         uid_t uid = 0;
567
568         pkgmgr_installer_info_get_target_uid(&uid);
569         ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
570
571         if (ret < 0)
572         {
573                 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
574                 return -1;
575         }
576
577         ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
578         if (ret < 0)
579         {
580                 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
581                 goto FAIL;
582         }
583
584         if (appid == NULL)
585         {
586                 DEBUG_ERROR("appid is NULL \n");
587                 goto FAIL;
588         }
589
590         ret = make_dir(PARENT_PATH);
591
592         if (ret < 0)
593         {
594                 DEBUG_ERROR("make current directory is failed \n");
595                 goto FAIL;
596         }
597
598         dest_path = check_preloaded(app_root_path);
599
600         if (make_dir(dest_path)<0)
601         {
602                 DEBUG_ERROR("make current directory is failed \n");
603                 return -1;
604         }
605
606         ret = do_install(dest_path,appid, app_root_path, handle);
607         if (ret < 0)
608         {
609                 DEBUG_ERROR("font install is failed \n");
610                 goto FAIL;
611         }
612
613         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
614
615         return ret;
616
617 FAIL:
618         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
619         return -1;
620 }
621
622
623 int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
624 {
625         char deletedir[MAX_FILE_LEN];
626         int ret = 0;
627         pkgmgrinfo_pkginfo_h handle = NULL;
628         const char* app_root_path = NULL;
629         const char* dest_path = NULL;
630         uid_t uid = 0;
631
632         pkgmgr_installer_info_get_target_uid(&uid);
633         ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
634
635         if (ret < 0)
636         {
637                 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
638                 return -1;
639         }
640
641         ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
642         if (ret < 0)
643         {
644                 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
645                 goto FAIL;
646         }
647
648         if (appid == NULL)
649         {
650                 DEBUG_ERROR("appid is NULL \n");
651                 goto FAIL;
652         }
653
654         dest_path = check_preloaded(app_root_path);
655
656         if (strlen (dest_path) + strlen (appid) + 2 >= MAX_FILE_LEN )
657         {
658                 DEBUG_ERROR("appid length is not available \n");
659                 goto FAIL;
660         }
661
662         snprintf(deletedir, sizeof(deletedir), "%s/%s", dest_path, appid);
663
664         if (access(deletedir, F_OK) == -1)
665         {
666                 DEBUG_ERROR_ERRNO("dest directory(%s) is not exist", deletedir);
667                 goto FAIL;
668         }
669
670         ret = do_uninstall(deletedir);
671         if (ret < 0)
672         {
673                 DEBUG_ERROR("do_uninstall is failed \n");
674                 goto FAIL;
675         }
676
677         ret = make_dir(PARENT_PATH);
678         if (ret < 0)
679         {
680                 DEBUG_ERROR_ERRNO("make current directory(%s) is failed", PARENT_PATH);
681                 goto FAIL;
682         }
683
684         ret = make_dir(dest_path);
685         if (ret < 0)
686         {
687                 DEBUG_ERROR_ERRNO("make current directory(%s) is failed", dest_path);
688                 goto FAIL;
689         }
690
691         ret = do_install(dest_path, appid, app_root_path, handle);
692         if (ret < 0)
693         {
694                 DEBUG_ERROR("do_install is failed \n");
695                 goto FAIL;
696         }
697
698         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
699         return ret;
700
701 FAIL:
702         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
703         return -1;
704 }
705
706
707
708 int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
709 {
710         char deletedir[MAX_FILE_LEN];
711         FcObjectSet *os = NULL;
712         FcPattern *pat = NULL;
713         FcFontSet *fs = NULL;
714         pkgmgrinfo_pkginfo_h handle = NULL;
715         const char* app_root_path = NULL;
716         const char *dest_path = NULL;
717         int ret, deletedir_len;
718         uid_t uid = 0;
719
720         elm_init(0, NULL);
721
722         if (appid == NULL)
723         {
724                 DEBUG_ERROR("appid is NULL \n");
725                 return -1;
726         }
727
728         pkgmgr_installer_info_get_target_uid(&uid);
729         ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
730
731         if (ret < 0)
732         {
733                 DEBUG_ERROR("pkgid[%s] handle get fail", pkgid);
734                 return -1;
735         }
736
737         ret = pkgmgrinfo_pkginfo_get_root_path(handle, (char **)&app_root_path);
738         if (ret < 0)
739         {
740                 DEBUG_ERROR("pkgid[%s] path get fail", pkgid);
741                 goto FAIL;
742         }
743
744         dest_path = check_preloaded(app_root_path);
745
746         if (strlen (dest_path) + strlen (appid) + 2 >= MAX_FILE_LEN )
747         {
748                 DEBUG_ERROR("appid length is not available \n");
749                 goto FAIL;
750         }
751
752         /* It must contain "/" character at end of the delete dir path.
753          * It prevents file path comparing issues when there are many similar path. */
754         snprintf(deletedir, sizeof(deletedir), "%s/%s/", dest_path, appid);
755
756         //check if current using font is same with uninstall font
757         deletedir_len = strlen(deletedir);
758
759         pat = FcPatternCreate();
760         if (pat == NULL)
761         {
762                 DEBUG_ERROR("FcPatternCreate is NULL \n");
763                 goto FAIL;
764         }
765
766         char *current_font_name = NULL;
767         ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &current_font_name);
768         if (ret < 0)
769         {
770                 DEBUG_ERROR("Get current font is failed \n");
771                 goto FAIL;
772         }
773
774         DEBUG_LOG("current_font_name =%s\n",current_font_name);
775
776         FcInitLoadConfigAndFonts();
777         FcPatternAddString (pat, FC_FAMILY,(FcChar8*)current_font_name);
778         os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *) 0);
779         fs = FcFontList(NULL, pat, os);
780
781         FcPatternDestroy(pat);
782         pat = NULL;
783         free(current_font_name);
784         current_font_name = NULL;
785
786         if (fs)
787         {
788                 int j;
789
790                 for (j = 0; j < fs->nfont; j++)
791                 {
792                         FcChar8 *file = NULL;
793                         if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
794                         {
795                                 DEBUG_LOG("file =%s, deletedir =%s\n", file, deletedir);
796                                 if (strncmp((const char*)file, deletedir, deletedir_len) == 0)
797                                 {
798                                         DEBUG_LOG("change to default font\n");
799                                         char *default_font_name = NULL;
800
801                                         ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEFAULT_FONT_TYPE, &default_font_name);
802                                         if (ret < 0)
803                                         {
804                                                 DEBUG_ERROR("Get default font is failed \n");
805                                                 goto FAIL;
806                                         }
807
808                                         DEBUG_LOG("default_font_name = %s \n",default_font_name);
809                                         ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, default_font_name);
810                                         if (ret < 0)
811                                         {
812                                                 DEBUG_ERROR("Set default font is failed ret=%d \n",ret);
813                                                 free(default_font_name);
814                                                 break;
815                                         }
816
817                                         free(default_font_name);
818                                         DEBUG_LOG("success change to default font\n");
819                                         break;
820                                 }
821                         }
822                 }
823         }
824
825         if (access(deletedir, F_OK) == -1)
826         {
827                 DEBUG_ERROR_ERRNO("dest directory(%s) is not exist", deletedir);
828                 goto FAIL;
829         }
830
831         elm_shutdown();
832         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
833
834         return do_uninstall(deletedir);
835
836 FAIL:
837         if (pat) FcPatternDestroy(pat);
838         elm_shutdown();
839         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
840
841         return -1;
842 }
843
844 #if USE_META_DATA
845 int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
846 {
847         return COMMON_PKGMGR_PLUGIN_INSTALL(pkgid, appid, list);
848 }
849
850 int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
851 {
852         return COMMON_PKGMGR_PLUGIN_UPGRADE(pkgid, appid, list);
853 }
854
855 int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
856 {
857         return COMMON_PKGMGR_PLUGIN_UNINSTALL(pkgid, appid, list);
858 }
859 #endif
860
861 int PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *list)
862 {
863         return COMMON_PKGMGR_PLUGIN_INSTALL(pkgid, appid, list);
864 }
865
866 int PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *list)
867 {
868         return COMMON_PKGMGR_PLUGIN_UPGRADE(pkgid, appid, list);
869 }
870
871 int PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList *list)
872 {
873         return COMMON_PKGMGR_PLUGIN_UNINSTALL(pkgid, appid, list);
874 }
875
876
877 /* End of a file */