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