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