#include <vconf.h>
#include "sst.h"
#include "sst_vconf.h"
-#include "sst_utils.h"
+#include "sst_misc.h"
#include "sst_interface.h"
-int system_setting_get_locale_country(system_setting_h item, void **value)
+int sst_locale_get_country(sst_interface *iface, char **value)
{
- char *vconf_value = NULL;
- if (sst_vconf_get_string(item->vconf_key, &vconf_value))
+ char *locale = NULL;
+ if (sst_vconf_get_str_ally(iface->vconf_key, &locale)) {
+ ERR("sst_vconf_get_str_ally(%s) Fail", iface->vconf_key);
return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+ }
- /* parsing validation */
- /* en_US.UTF-8 */
- char arr[21] = {0};
- snprintf(arr, 20, "%s", vconf_value);
- for (int i = 0; i < strlen(arr); i++) {
- if ('.' == arr[i]) {
- arr[i] = 0;
- SST_SECURE_TRACE("replace . to NULL : %d", i);
+ // remove encoding ex) en_US.UTF-8 => en_US
+ int i;
+ char country[21];
+ for (i = 0; i < sizeof(country); i++) {
+ country[i] = locale[i];
+ if ('.' == country[i])
+ country[i] = 0;
+ if (0 == country[i])
break;
- }
}
- *value = strdup(arr);
- free(vconf_value);
- vconf_value = NULL;
+ if (sizeof(country) <= i) {
+ ERR("Invalid locale(%s)", locale);
+ free(locale);
+ return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+ }
+
+ *value = strdup(country);
+ free(locale);
return SYSTEM_SETTINGS_ERROR_NONE;
}
-int system_setting_set_locale_country(system_setting_h item, void *value)
+int sst_locale_set_country(sst_interface *iface, const char *country)
{
- char *vconf_value = NULL;
- vconf_value = (char*)value;
+ const char *codeset = "UTF-8";
- char *ext = "UTF-8";
+ char locale[100];
+ snprintf(locale, sizeof(locale), "%s.%s", country, codeset);
- char arr[20];
- snprintf(arr, 20, "%s.%s", vconf_value, ext);
-
- if (vconf_set_str(item->vconf_key, arr))
+ if (vconf_set_str(iface->vconf_key, locale)) {
+ ERR("vconf_set_str(%s) Fail", iface->vconf_key);
return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+ }
return SYSTEM_SETTINGS_ERROR_NONE;
}
-int system_setting_get_locale_language(system_setting_h item, void **value)
+int sst_locale_get_language(sst_interface *iface, char **value)
{
- char *vconf_value = NULL;
- if (sst_vconf_get_string(item->vconf_key, &vconf_value))
- return SYSTEM_SETTINGS_ERROR_IO_ERROR;
-
- /* parsing validation */
- /* en_US.UTF-8 */
- char arr[21] = {0};
- snprintf(arr, 20, "%s", vconf_value);
- for (int i = 0; i < strlen(arr); i++) {
- if ('.' == arr[i]) {
- arr[i] = 0;
- SST_SECURE_TRACE("replace . to NULL : %d", i);
- break;
- }
+ //It is same data with sst_locale_get_country()
+ int ret = sst_locale_get_country(iface, value);
+ if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
+ ERR("sst_locale_get_country() Fail(%d)", ret);
+ return ret;
}
- *value = strdup(arr);
- free(vconf_value);
- vconf_value = NULL;
+
return SYSTEM_SETTINGS_ERROR_NONE;
}
-int system_setting_set_locale_language(system_setting_h item, void *value)
+int sst_locale_set_language(sst_interface *iface, const char *value)
{
- char *vconf_value = NULL;
- vconf_value = (char*)value;
-
- char *ext = "UTF-8";
-
- char arr[20];
- snprintf(arr, 20, "%s.%s", vconf_value, ext);
-
- if (vconf_set_str(item->vconf_key, arr))
- return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+ //It is same data with sst_locale_set_country()
+ int ret = sst_locale_set_country(iface, value);
+ if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
+ ERR("sst_locale_set_country() Fail(%d)", ret);
+ return ret;
+ }
return SYSTEM_SETTINGS_ERROR_NONE;
}
-int system_setting_get_locale_timeformat_24hour(system_setting_h item, void **value)
+int sst_locale_get_timeformat_24hour(sst_interface *iface, bool *value)
{
- int vconf_value;
+ int time_fmt;
- if (vconf_get_int(item->vconf_key, &vconf_value))
+ if (vconf_get_int(iface->vconf_key, &time_fmt)) {
+ ERR("vconf_get_int(%s) Fail", iface->vconf_key);
return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+ }
- bool ret_value = true;
- if (vconf_value == VCONFKEY_TIME_FORMAT_12)
- ret_value = false;
- else if (vconf_value == VCONFKEY_TIME_FORMAT_24)
- ret_value = true;
+ bool result = true;
+ if (time_fmt == VCONFKEY_TIME_FORMAT_12)
+ result = false;
+ else if (time_fmt == VCONFKEY_TIME_FORMAT_24)
+ result = true;
- *value = (void*)ret_value;
+ *value = result;
return SYSTEM_SETTINGS_ERROR_NONE;
}
-int system_setting_set_locale_timeformat_24hour(system_setting_h item, void *value)
+int sst_locale_set_timeformat_24hour(sst_interface *iface, bool is_24hour)
{
- bool *vconf_value;
+ int vconf_val;
- vconf_value = (bool*)value;
+ if (is_24hour)
+ vconf_val = VCONFKEY_TIME_FORMAT_24;
+ else
+ vconf_val = VCONFKEY_TIME_FORMAT_12;
- if (*vconf_value) {
- if (vconf_set_int(item->vconf_key, VCONFKEY_TIME_FORMAT_24))
- return SYSTEM_SETTINGS_ERROR_IO_ERROR;
- } else {
- if (vconf_set_int(item->vconf_key, VCONFKEY_TIME_FORMAT_12))
- return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+ if (vconf_set_int(iface->vconf_key, vconf_val)) {
+ ERR("vconf_set_int(%s) Fail", iface->vconf_key);
+ return SYSTEM_SETTINGS_ERROR_IO_ERROR;
}
return SYSTEM_SETTINGS_ERROR_NONE;
}
-int system_setting_get_locale_timezone(system_setting_h item, void **value)
+int sst_locale_get_timezone(sst_interface *iface, char **value)
{
- char tzpath[256];
+ char tzpath[PATH_MAX];
ssize_t len = readlink(SETTING_TZONE_SYMLINK_PATH, tzpath, sizeof(tzpath) - 1);
- if (len != -1) {
- tzpath[len] = '\0';
- } else {
- SST_SECURE_TRACE("parse error for SETTING_TZONE_SYMLINK_PATH");
+ if (-1 == len) {
+ ERR("readlink(%s) Fail(%d)", SETTING_TZONE_SYMLINK_PATH, errno);
return SYSTEM_SETTINGS_ERROR_IO_ERROR;
}
+ tzpath[len] = '\0';
+
+ // for including last '/', it used sizeof instead of strlen
+ int start = sizeof(SETTING_TIME_ZONEINFO_PATH);
- SST_SECURE_TRACE("tzpath : %s ", &tzpath[20]);
- *value = strdup(&tzpath[20]);
+ *value = strdup(&tzpath[start]);
return SYSTEM_SETTINGS_ERROR_NONE;
}
-int system_setting_set_locale_timezone(system_setting_h item, void *value)
+int sst_locale_set_timezone(sst_interface *iface, const char *timezone)
{
- char *timezone_value = NULL;
- timezone_value = (char*)value;
-
- char tz_path[1024];
- snprintf(tz_path, 1024, "/usr/share/zoneinfo/%s", timezone_value);
+ char tzpath[PATH_MAX];
+ snprintf(tzpath, sizeof(tzpath), SETTING_TIME_ZONEINFO_PATH"/%s", timezone);
- int is_load = sst_is_valid_file(tz_path);
- if (is_load == 0) {
- alarmmgr_set_timezone(tz_path);
+ if (false == sst_misc_file_exists(tzpath)) {
+ ERR("sst_misc_file_exists(%s) Fail", tzpath);
+ return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
+ }
- if (vconf_set_str(item->vconf_key, timezone_value))
- return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+ int ret = alarmmgr_set_timezone(tzpath);
+ if (ALARMMGR_RESULT_SUCCESS != ret)
+ ERR("alarmmgr_set_timezone(%s) Fail", tzpath);
- return SYSTEM_SETTINGS_ERROR_NONE;
+ if (vconf_set_str(iface->vconf_key, timezone)) {
+ ERR("vconf_set_str(%s) Fail", iface->vconf_key);
+ return SYSTEM_SETTINGS_ERROR_IO_ERROR;
}
- return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
+
+ return SYSTEM_SETTINGS_ERROR_NONE;
}
-int system_setting_get_time_changed(system_setting_h item, void **value)
+//TODO : checking this function is being used or not.
+int sst_time_get_changed(sst_interface *iface, int *value)
{
time_t cur_tick;
- int **val = (int**)value;
+
cur_tick = time(NULL);
- **val = cur_tick;
- /* struct tm * localtime = time (cur_tick); */
- /* printf("%s\n", ctime(&cur_tick); */
+ *value = cur_tick;
+
return SYSTEM_SETTINGS_ERROR_NONE;
}