replace sprintf with snprintf for secure-coding
[platform/core/api/system-settings.git] / src / system_setting_platform.c
index e3a1a15..135c2b1 100644 (file)
@@ -37,6 +37,8 @@
 
 #include <fontconfig/fontconfig.h>
 
+#include <alarm.h>
+
 #include <pkgmgr-info.h>
 
 #include <system_settings.h>
@@ -61,7 +63,7 @@ int _is_file_accessible(const char *path);
 bool dl_is_supported_image_type_load(char *path);
 bool dl_font_config_set(char *font_name);
 char *dl_get_font_info(char *str);
-int *dl_is_available_font(char *str);
+int dl_is_available_font(char *str);
 void dl_font_size_set();
 void dl_font_config_set_notification();
 
@@ -69,7 +71,7 @@ void dl_font_config_set_notification();
 /**
  * VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR has a path of the ringtone file which user choose
  * @return the ringtone file path specified by user in normal case
- *         if it's not accessable, return the default ringtone path
+ *                if it's not accessable, return the default ringtone path
  */
 int system_setting_get_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
 {
@@ -302,147 +304,159 @@ int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_se
 
 bool dl_is_supported_image_type_load(char *path)
 {
-       void *handle;
-       int error;
+       void *handle = NULL;
+       char *error;
        bool ret = false;
        bool (*image_type_check)(char *path);
 
        handle = dlopen("/usr/lib/libsystem-settings-util.so.0.1.0",  RTLD_LAZY);
-       if(!handle)
-       {
+       if (!handle) {
                SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
                return false;
        }
 
        image_type_check = dlsym(handle, "__is_supported_image_type_load");
-       if((error = dlerror()) != NULL) {
+       if ((error = dlerror()) != NULL) {
                SETTING_TRACE("ERROR!! canNOT find __is_supported_image_type_load function at libsystem-settings-util.so.0.1.0");
+               if (handle)
+                       dlclose(handle);
                return false;
        }
        ret = image_type_check(path);
-       dlclose(handle);
+       if (handle)
+               dlclose(handle);
        return ret;
 }
 
-int *dl_is_available_font(char *str)
+int dl_is_available_font(char *str)
 {
-       void *handle;
-       int error;
+       void *handle = NULL;
+       char *error;
        int ret = false;
        int (*check_available_font)(char *font_name);
 
        handle = dlopen("/usr/lib/libsystem-settings-util.so.0.1.0",  RTLD_LAZY);
-       if(!handle)
-       {
+       if (!handle) {
                SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
                return false;
        }
 
-       check_available_font = dlsym(handle, "_is_available_font");
-       if((error = dlerror()) != NULL) {
-               SETTING_TRACE("ERROR!! canNOT find font_config_set function at libsystem-settings-util.so.0.1.0");
+       check_available_font = dlsym(handle, "__is_available_font");
+       if ((error = dlerror()) != NULL) {
+               SETTING_TRACE("ERROR!! canNOT find __is_available_font function at libsystem-settings-util.so.0.1.0");
+               if (handle)
+                       dlclose(handle);
                return false;
        }
        ret = check_available_font(str);
-       dlclose(handle);
+       if (handle)
+               dlclose(handle);
        return ret;
 }
 
 void dl_font_size_set()
 {
-       void *handle;
-       int error;
+       void *handle = NULL;
+       char *error;
        void (*set_font_size)();
 
        handle = dlopen("/usr/lib/libsystem-settings-util.so.0.1.0",  RTLD_LAZY);
-       if(!handle)
-       {
+       if (!handle) {
                SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
                return;
        }
 
        set_font_size = dlsym(handle, "__font_size_set");
-       if((error = dlerror()) != NULL) {
-               SETTING_TRACE("ERROR!! canNOT find font_config_set function at libsystem-settings-util.so.0.1.0");
+       if ((error = dlerror()) != NULL) {
+               SETTING_TRACE("ERROR!! canNOT find __font_size_set function at libsystem-settings-util.so.0.1.0");
+               if (handle)
+                       dlclose(handle);
                return;
        }
        set_font_size();
-       dlclose(handle);
+       if (handle)
+               dlclose(handle);
        return;
 }
 
 void dl_font_config_set_notification()
 {
-       void *handle;
-       int error;
+       void *handle = NULL;
+       char *error;
        void (*set_font_nodification)();
 
        handle = dlopen("/usr/lib/libsystem-settings-util.so.0.1.0",  RTLD_LAZY);
-       if(!handle)
-       {
+       if (!handle) {
                SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
                return;
        }
 
        set_font_nodification = dlsym(handle, "font_config_set_notification");
-       if((error = dlerror()) != NULL) {
-               SETTING_TRACE("ERROR!! canNOT find font_config_set function at libsystem-settings-util.so.0.1.0");
+       if ((error = dlerror()) != NULL) {
+               SETTING_TRACE("ERROR!! canNOT find font_config_set_notification function at libsystem-settings-util.so.0.1.0");
+               if (handle)
+                       dlclose(handle);
                return;
        }
        set_font_nodification();
-       dlclose(handle);
+       if (handle)
+               dlclose(handle);
        return;
 }
 
 bool dl_font_config_set(char *font_name)
 {
-       void *handle;
-       int error;
+       void *handle = NULL;
+       char *error;
        bool ret = false;
        bool (*check_font_type)(char *font_name);
 
        handle = dlopen("/usr/lib/libsystem-settings-util.so.0.1.0",  RTLD_LAZY);
-       if(!handle)
-       {
+       if (!handle) {
                SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
                return false;
        }
 
        check_font_type = dlsym(handle, "font_config_set");
-       if((error = dlerror()) != NULL) {
+       if ((error = dlerror()) != NULL) {
                SETTING_TRACE("ERROR!! canNOT find font_config_set function at libsystem-settings-util.so.0.1.0");
+               if (handle)
+                       dlclose(handle);
                return false;
        }
        ret = check_font_type(font_name);
-       dlclose(handle);
+       if (handle)
+               dlclose(handle);
        return ret;
 }
 
 char *dl_get_font_info(char *str)
 {
-       void *handle;
-       int error;
-       charret = NULL;
+       void *handle = NULL;
+       char *error;
+       char *ret = NULL;
        char *(*get_font_info)();
 
        handle = dlopen("/usr/lib/libsystem-settings-util.so.0.1.0",  RTLD_LAZY);
-       if(!handle)
-       {
+       if (!handle) {
                SETTING_TRACE("ERROR!! canNOT find libsystem-settings-util.so.0.1.0");
                return false;
        }
 
-       if(strcmp(str,"cur") == 0)
+       if (strcmp(str, "cur") == 0)
                get_font_info = dlsym(handle, "_get_cur_font");
        else
                get_font_info = dlsym(handle, "_get_default_font");
 
-       if((error = dlerror()) != NULL) {
+       if ((error = dlerror()) != NULL) {
                SETTING_TRACE("ERROR!! canNOT find %s function at libsystem-settings-util.so.0.1.0", str);
+               if (handle)
+                       dlclose(handle);
                return false;
        }
        ret = get_font_info();
-       dlclose(handle);
+       if (handle)
+               dlclose(handle);
        return ret;
 }
 
@@ -650,11 +664,11 @@ int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_s
 
                /* Numbering rule: Gear is odd number */
                max_image_num = (max_image_num % 2 == 0) ? max_image_num + 1
-                               : max_image_num + 2;
+                                                       : max_image_num + 2;
 
                char file_name_buffer[512];
                snprintf(file_name_buffer, sizeof(file_name_buffer) - 1,
-                        _TZ_SYS_DATA"/setting/wallpaper/extended_wallpaper_%d.jpg", max_image_num);
+                                       _TZ_SYS_DATA"/setting/wallpaper/extended_wallpaper_%d.jpg", max_image_num);
 
                /* Copy image to _TZ_SYS_DATA/setting/wallpaper/ */
                if (system_setting_copy_extended_wallpaper(file_name_buffer, vconf_value)
@@ -676,7 +690,7 @@ int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_s
                }
 
                if (system_setting_vconf_set_value_int(VCONFKEY_SETAPPL_WALLPAPER_CHANGED_NOTI_INT,
-                                                      VCONFKEY_WALLPAPER_CHANGED_NOTI_GEAR)) {
+                                                                                                       VCONFKEY_WALLPAPER_CHANGED_NOTI_GEAR)) {
                        return SYSTEM_SETTINGS_ERROR_IO_ERROR;
                }
        } else {
@@ -1261,24 +1275,43 @@ int system_setting_unset_changed_callback_locale_timeformat_24hour(system_settin
 int system_setting_get_locale_timezone(system_settings_key_e key, system_setting_data_type_e data_type, void **value)
 {
        SETTING_TRACE_BEGIN;
-#if 0
-       char tzpath[256];
-       ssize_t len = readlink(SETTING_TZONE_SYMLINK_PATH, tzpath, sizeof(tzpath) - 1);
-       if (len != -1) {
-               tzpath[len] = '\0';
-       } else {
-               SETTING_TRACE("parse error for SETTING_TZONE_SYMLINK_PATH");
-               return SYSTEM_SETTINGS_ERROR_IO_ERROR;
-       }
-       /* "/usr/share/zoneinfo/Asia/Seoul" */
-       SETTING_TRACE("tzpath : %s ", &tzpath[20]);
-       *value = strdup(&tzpath[20]);
-#else
        *value = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
-#endif
        return SYSTEM_SETTINGS_ERROR_NONE;
 }
 
+int system_setting_set_locale_timezone(system_settings_key_e key, system_setting_data_type_e data_type, void *value)
+{
+       SETTING_TRACE_BEGIN;
+       char *vconf_value = NULL;
+       vconf_value = (char *)value;
+
+       char tz_path[1024];
+       snprintf(tz_path, 1024, "/usr/share/zoneinfo/%s", vconf_value);
+
+       int is_load = _is_file_accessible(tz_path);
+       if (is_load == 0) {
+               alarmmgr_set_timezone(tz_path);
+
+               if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_TIMEZONE_ID, vconf_value)) {
+                       return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+               }
+               return SYSTEM_SETTINGS_ERROR_NONE;
+       }
+       return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
+}
+
+
+
+int system_setting_set_changed_callback_locale_timezone(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
+{
+       return system_setting_vconf_set_changed_cb(VCONFKEY_SETAPPL_TIMEZONE_ID, SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE, 4, user_data);
+}
+
+int system_setting_unset_changed_callback_locale_timezone(system_settings_key_e key)
+{
+       return system_setting_vconf_unset_changed_cb(VCONFKEY_SETAPPL_TIMEZONE_ID, 4);
+}
+
 int system_setting_set_changed_callback_locale_timezone_changed(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
 {
        SETTING_TRACE_BEGIN;