Add xmlSaveFormatFile() check routine
[platform/core/api/system-settings.git] / src / sst_font.c
index ed93d07..e14f709 100644 (file)
 #include "sst.h"
 #include "sst_utils_wrapper.h"
 
-int sst_font_set_size(sst_interface *iface, void *value)
+int sst_font_set_size(sst_interface *iface, int value)
 {
-       int *vconf_value;
-       vconf_value = *(int **)value;
+       RETVM_IF(value < 0 || SYSTEM_SETTINGS_FONT_SIZE_GIANT < value,
+               SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid size(%d)", value);
 
-       RETVM_IF(*vconf_value < 0 || SYSTEM_SETTINGS_FONT_SIZE_GIANT < *vconf_value,
-               SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, "Invalid value(%d)", *vconf_value);
-
-       if (vconf_set_int(iface->vconf_key, *vconf_value)) {
-               ERR("vconf_set_int(%s) Fail", iface->vconf_key);
+       if (vconf_set_int(iface->vconf_key, value)) {
+               ERR("vconf_set_int(%s, %d) Fail", iface->vconf_key, value);
                return SYSTEM_SETTINGS_ERROR_IO_ERROR;
        }
 
@@ -37,7 +34,7 @@ int sst_font_set_size(sst_interface *iface, void *value)
        return SYSTEM_SETTINGS_ERROR_NONE;
 }
 
-static void* font_conf_doc_parse(char *doc_name, char *font_name)
+static void* font_conf_doc_parse(const char *doc_name, const char *font_name)
 {
        xmlDocPtr doc = NULL;
        xmlNodePtr cur = NULL;
@@ -46,9 +43,7 @@ static void* font_conf_doc_parse(char *doc_name, char *font_name)
        xmlChar *key = NULL;
 
        doc = xmlParseFile(doc_name);
-
        cur = xmlDocGetRootElement(doc);
-
        if (cur == NULL) {
                xmlFreeDoc(doc);
                doc = NULL;
@@ -132,17 +127,12 @@ static void* font_conf_doc_parse(char *doc_name, char *font_name)
        }
 }
 
-int sst_font_set_type(sst_interface *iface, void *value)
+int sst_font_set_type(sst_interface *iface, const char *font_name)
 {
-       char *font_name = NULL;
-       font_name = (char*)value;
-
        /* get current font list */
        int is_found = sstu_is_available_font(font_name);
-       if (is_found == 1) {
-               DBG("found font : %s ", font_name);
-       } else {
-               ERR(" NOT found font : %s ", font_name);
+       if (FALSE == is_found) {
+               ERR("NO font(%s)", font_name);
                return SYSTEM_SETTINGS_ERROR_IO_ERROR;
        }
 
@@ -154,24 +144,25 @@ int sst_font_set_type(sst_interface *iface, void *value)
 
        xmlDocPtr doc = font_conf_doc_parse(SETTING_FONT_CONF_FILE, font_name);
        if (doc != NULL) {
-               xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
+               int ret = xmlSaveFormatFile(SETTING_FONT_CONF_FILE, doc, 0);
                xmlFreeDoc(doc);
-               doc = NULL;
+               if (ret <= -1) {
+                       ERR("xmlSaveFormatFile() Fail");
+                       return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+               }
        }
 
        sstu_font_config_set_notification();
 
-       char *vconf_value;
-       vconf_value = (char*)value;
-       if (vconf_set_str(iface->vconf_key, vconf_value)) {
-               ERR("vconf_set_str(%s) Fail", iface->vconf_key);
+       if (vconf_set_str(iface->vconf_key, font_name)) {
+               ERR("vconf_set_str(%s, %s) Fail", iface->vconf_key, font_name);
                return SYSTEM_SETTINGS_ERROR_IO_ERROR;
        }
 
        return SYSTEM_SETTINGS_ERROR_NONE;
 }
 
-int sst_font_get_default_type(sst_interface *iface, void **value)
+int sst_font_get_default_type(sst_interface *iface, char **value)
 {
        char *font_name = sstu_get_default_font();
        if (NULL == font_name) {
@@ -179,6 +170,6 @@ int sst_font_get_default_type(sst_interface *iface, void **value)
                return SYSTEM_SETTINGS_ERROR_IO_ERROR;
        }
 
-       *value = (void*)font_name;
+       *value = font_name;
        return SYSTEM_SETTINGS_ERROR_NONE;
 }