Fix reported errors by coverity 77/196977/1 accepted/tizen_4.0_unified tizen_4.0 accepted/tizen/4.0/unified/20190108.223817 submit/tizen_4.0/20190108.092603
authorKiseok Chang <kiso.chang@samsung.com>
Tue, 8 Jan 2019 09:10:49 +0000 (18:10 +0900)
committerKiseok Chang <kiso.chang@samsung.com>
Tue, 8 Jan 2019 09:13:38 +0000 (18:13 +0900)
Change-Id: Ie28547a6d2868d1ce1ced32788794c06bc8c80ba
Signed-off-by: Kiseok Chang <kiso.chang@samsung.com>
packaging/org.tizen.setting-profile_common.spec
setting-common/include/setting-common-data-slp-setting.h [changed mode: 0644->0755]
setting-common/src/setting-common-data-slp-setting.c [changed mode: 0644->0755]
setting-phone/src/setting-phone.c
src/CMakeLists.txt
src/conf_util/setting_confutil.c [deleted file]
src/conf_util/setting_confutil.h [deleted file]

index d701e3c351f7f64a6803e0d45fcf1126e632023b..66a1c1860458b4b2978869fec18aad61bfa788ee 100755 (executable)
@@ -220,7 +220,6 @@ mkdir -p %{_prefix}/apps/org.tizen.mode-syspopup/bin/
 
 %{PREFIX}/bin/setting
 %{CONFIGDIR}/*
-%{PREFIX}/bin/setting_conf_util
 %{PREFIX}/bin/setting_volume_popup
 
 %attr(0755,root,root) %{PREFIX}/bin/setting_help_ringtone
old mode 100644 (file)
new mode 100755 (executable)
index 7090281..059263d
@@ -283,9 +283,4 @@ extern void  setting_get_language_list_destroy();
 /* export&import function */
 typedef int (*status_handler_fp)(int total, int current, void *data);
 
-extern char *setting_export_json(status_handler_fp fp, void *data);
-extern void setting_import_json(status_handler_fp fp, void *data);
-
-
-
 #endif                         /* __SETTING_COMMON_DATA_SLP_SETTING_H__ */
old mode 100644 (file)
new mode 100755 (executable)
index 4d5b549..e46d599
@@ -394,7 +394,7 @@ void __foreach_attr(JsonObject *object, const gchar *public_key, JsonNode *membe
                                /* "true"  --> 1  "false" --> 0 */
                                if (retstr && safeStrCmp(retstr, "true") == 0) {
                                        g_sortedarr[i].value.b = 1;
-                               }       else if (retstr && safeStrCmp(retstr, "false") == 0) {
+                               } else if (retstr && safeStrCmp(retstr, "false") == 0) {
                                        g_sortedarr[i].value.b = 0;
                                }
                                break;
@@ -448,167 +448,6 @@ int __compareByCategory(const void *arg1, const void *arg2)
        return safeStrCmp(str1, str2);
 }
 
-EXPORT_PUBLIC
-void setting_import_json(status_handler_fp fp, void *data)
-{
-       SETTING_TRACE_BEGIN;
-       /*--------------------------------------------------------------------------------- */
-       JsonParser *parser;
-       JsonNode *root;
-       GError *error;
-
-       /*---- */
-       int bcount = sizeof(g_btable) / sizeof(g_btable[0]) - 1;
-       int icount = sizeof(g_itable) / sizeof(g_itable[0]) - 1;
-       int scount = sizeof(g_stable) / sizeof(g_stable[0]) - 1; /* why?? buggy */
-       int total = bcount + icount + scount;
-       SETTING_TRACE(" >>> total : %d ", total);
-
-       VconfNode *arr3 = (VconfNode *)malloc(sizeof(VconfNode)*total);
-       if (!arr3) return;
-       memcpy(arr3, g_btable, sizeof(VconfNode)*(bcount));
-       memcpy(&arr3[bcount - 1], g_itable, sizeof(g_itable));
-       memcpy(&arr3[bcount - 1 + icount - 1], g_stable, sizeof(g_stable));
-       qsort(arr3, total, sizeof(VconfNode), __compareByCategory);
-       /*---- */
-
-       g_sortedarr = arr3;
-
-       parser = json_parser_new();
-
-       error = NULL;
-       json_parser_load_from_file(parser, SETTING_CFG_JSON_FILE_PATH, &error);
-       if (error) {
-               SETTING_TRACE("Unable to parse `%s': %s", SETTING_CFG_JSON_FILE_PATH, error->message);
-               g_error_free(error);
-               g_object_unref(parser);
-               return;
-       }
-
-       root = json_parser_get_root(parser);
-       /* manipulate the object tree and then exit */
-
-       JsonObject *obj1 = json_node_get_object(root);
-       if (json_object_has_member(obj1, "value")) {
-               JsonNode *node = json_object_get_member(obj1, "value");
-               JsonObject *object2 = json_node_get_object(node);
-               json_object_foreach_member(object2, __func_cb, NULL);   /* with g_sortedarr */
-       }
-       g_object_unref(parser);
-
-       FREE(arr3);
-       g_sortedarr = NULL;
-}
-
-/**
- * setting --> cloud : JSON
- *
- * int status_handler(int total, int current,  void* data);
- */
-EXPORT_PUBLIC
-char *setting_export_json(status_handler_fp fp, void *data)
-{
-       JsonNode *root = NULL;
-
-       root = json_node_new(JSON_NODE_OBJECT);
-       JsonObject *top = json_object_new();
-       json_node_take_object(root, top);
-
-       json_object_set_string_member(top, "key", "SETTINGS_359617040746834_8592d887-8b97-406e-9cf9-03aebc045f81");
-
-       int bcount = sizeof(g_btable) / sizeof(g_btable[0]) - 1;
-       int icount = sizeof(g_itable) / sizeof(g_itable[0]) - 1;
-       int scount = sizeof(g_stable) / sizeof(g_stable[0]) - 1; /* why?? buggy */
-
-       int total = bcount + icount + scount;
-
-       JsonNode *topnode = json_node_new(JSON_NODE_OBJECT);
-       JsonObject *topobj = json_object_new();
-       json_node_take_object(topnode, topobj);
-
-       json_object_set_member(top, "value", topnode);
-
-       VconfNode *arr3 = (VconfNode *)malloc(sizeof(VconfNode)*total);
-       if (!arr3) return NULL;
-       memcpy(arr3, g_btable, sizeof(VconfNode)*(bcount));
-       memcpy(&arr3[bcount - 1], g_itable, sizeof(g_itable));
-       memcpy(&arr3[bcount - 1 + icount - 1], g_stable, sizeof(g_stable));
-       qsort(arr3, total, sizeof(VconfNode), __compareByCategory);
-
-       char *public_groupkey = "";
-
-       /*JsonArray* array = NULL; */
-       JsonObject *obj = NULL;
-       JsonNode *node = NULL;
-
-       int i;
-       for (i = 0; i < total; i++) {
-               if (arr3[i].public_key) {
-                       if (public_groupkey && safeStrCmp(public_groupkey, arr3[i].public_groupkey) != 0) {
-                               public_groupkey = (char *)(arr3[i].public_groupkey);
-                               /*array = json_array_new(); */
-                               obj = json_object_new();
-                               node = json_node_new(JSON_NODE_OBJECT);
-                               json_node_take_object(node, obj);
-                               json_object_set_member(topobj, public_groupkey, node);
-                               /*json_array_add_element(array, node); */
-                       }
-
-                       /* get data from vconf */
-                       /* get vconf_get */
-                       char *val = NULL;
-                       char arr[1024];
-                       VconfNode result;
-                       switch (arr3[i].type) {
-                       case eBOOL:
-                               get_vconf(arr3[i], &result);
-                               if (result.value.b)
-                                       val = "true";
-                               else
-                                       val = "false";
-                               break;
-                       case eINT:
-                               get_vconf(arr3[i], &result);
-                               snprintf(arr, 1024, "%d", result.value.i);
-                               val = arr;
-                               /*if (val == NULL) val = "-100"; */
-                               break;
-                       case eSTRING:
-                               get_vconf(arr3[i], &result);
-                               val = result.value.c;
-                               if (val == NULL) val = "";
-                               break;
-                       default:
-                               val = "error";
-                       }
-
-                       json_object_set_string_member(obj, arr3[i].public_key, val);
-               }
-       }
-
-       /* save data to a file */
-       GError *error = NULL;
-       JsonGenerator *generator = json_generator_new();
-       json_generator_set_root(generator, root/*node*/);
-
-       gsize len;
-       char *buf = (char *)json_generator_to_data(generator, &len);
-
-       g_object_set(generator, "pretty", TRUE, NULL);   /*write file in indent format */
-       gboolean ret = json_generator_to_file(generator, SETTING_CFG_JSON_FILE_PATH, &error);
-       g_object_unref(generator);
-
-       if (FALSE == ret) {
-               SETTING_TRACE_ERROR("Error writing file %s!", SETTING_CFG_JSON_FILE_PATH);
-               /*return FALSE; */
-       }
-
-       json_node_free(root);
-       FREE(arr3);
-
-       return buf;
-}
-
 int set_vconf(VconfNode node, VconfNode *result)
 {
        /*SETTING_TRACE_BEGIN; */
@@ -978,30 +817,37 @@ static void __tree_walk_langlist(xmlNodePtr cur)
 {
        SETTING_TRACE_BEGIN;
        xmlNode *cur_node = NULL;
-       char *id;
-       char *string;
+       char *id = NULL;
+       char *string = NULL;
        char *mcc = NULL;
-       /*int number = 1; */
+       char *tmp = NULL;
+       setting_lang_entry *pitem = NULL;
 
        for (cur_node = cur; cur_node; cur_node = cur_node->next) {
                if (cur_node->type == XML_ELEMENT_NODE) {
 
-                       /*SETTING_TRACE(" name=%s title=%s \n", xmlGetProp(cur_node, (const xmlChar *)"id"), xmlGetProp(cur_node, (const xmlChar *)"string")); */
-                       id = (char *)g_strdup((char *)xmlGetProp(cur_node, (const xmlChar *)"id"));
-                       string = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar *)"string"));
-                       /*SETTING_TRACE_DEBUG("lang: %s", xmlGetProp(cur_node, (const xmlChar *)"lang")); */
-                       mcc = (char *)g_strdup((char *) xmlGetProp(cur_node, (const xmlChar *)"mcc"));
-                       /*number = atoi((char*) xmlGetProp(cur_node, (const xmlChar *)"no")); */
+                       tmp = (char *)xmlGetProp(cur_node, (const xmlChar *)"id");
+                       id = (char *)g_strdup(tmp);
+                       xmlFree(tmp);
+
+                       tmp = (char *)xmlGetProp(cur_node, (const xmlChar *)"string");
+                       string = (char *)g_strdup(tmp);
+                       xmlFree(tmp);
 
-                       setting_lang_entry *pitem = (setting_lang_entry *)calloc(1, sizeof(setting_lang_entry));
+                       tmp = (char *)xmlGetProp(cur_node, (const xmlChar *)"mcc");
+                       mcc = (char *)g_strdup(tmp);
+                       xmlFree(tmp);
+
+                       pitem = (setting_lang_entry *)calloc(1, sizeof(setting_lang_entry));
                        if (pitem) {
                                pitem->locale = id;
                                pitem->title = string;
                                pitem->mcc = mcc;
-                               /*pitem->number = number++; */
-                               /*SETTING_TRACE_DEBUG("no=%d", pitem->number); */
-                               /*SETTING_TRACE_DEBUG(">>>> locale: %s title: %s mcc: %s", pitem->locale, pitem->title, pitem->mcc); */
                                s_langlist = eina_list_append(s_langlist, pitem);
+                       } else {
+                               g_free(id);
+                               g_free(string);
+                               g_free(mcc);
                        }
                }
        }
@@ -1126,21 +972,26 @@ void setting_destory_listen_list(Eina_List **listened_list)
 EXPORT_PUBLIC
 bool setting_add_listen_node(Eina_List **listened_list, const char *vconf, vconf_callback_fn cb, void *data)
 {
-       Vconf_Change_Node *node = calloc(1, sizeof(Vconf_Change_Node));
        bool ret = TRUE;
-       if (node && vconf && cb) {
-               node->in_key = vconf;
-               node->cb = cb;
-               node->cb_data = data;
-
-               if (0 == vconf_notify_key_changed(vconf, cb, data)) {
-                       /*SETTING_TRACE("Register callback[%p] of %s", node->cb, node->in_key); */
-                       *listened_list = eina_list_append(*listened_list, node);
-               } else {
-                       SETTING_TRACE_ERROR("Failed to register callback[%p] of %s", node->cb, node->in_key);
-                       FREE(node);
-                       ret = FALSE;
-               }
+       if (!vconf || cb)
+               return ret;
+
+       Vconf_Change_Node *node = calloc(1, sizeof(Vconf_Change_Node));
+       if (!node)
+               return ret;
+       
+       
+       node->in_key = vconf;
+       node->cb = cb;
+       node->cb_data = data;
+
+       if (0 == vconf_notify_key_changed(vconf, cb, data)) {
+               /*SETTING_TRACE("Register callback[%p] of %s", node->cb, node->in_key); */
+               *listened_list = eina_list_append(*listened_list, node);
+       } else {
+               SETTING_TRACE_ERROR("Failed to register callback[%p] of %s", node->cb, node->in_key);
+               FREE(node);
+               ret = FALSE;
        }
        return ret;
 }
index ad9703acb925aab6d6e7262145ddfb6963c3a234..d30716efdeab64d3b400e59a0ec8a04a1324c4e7 100755 (executable)
@@ -250,7 +250,8 @@ char *setting_phone_lang_get_region_str(const char *region)
        char source[256] = {0,};
        UChar dest[256] = {0,};
        if (strlen(str_displayname) < 256) {
-               strncpy(source, str_displayname, 256);
+               strncpy(source, str_displayname, 256-1);
+               source[256-1] = '\0';
        } else {
                FREE(str_displayname);
                return NULL;
index 97c7eb3ff91041b60effad64b313380542b79aba..dcc2fc3b75471ac85c788b9cc14b4ddea5dbae35 100755 (executable)
@@ -69,15 +69,6 @@ ADD_EXECUTABLE(${PROJECT_NAME}
        ./setting-main.c
        )
 
-# conf_tool
-SET(SETTING_CONFUTIL setting_conf_util)
-ADD_EXECUTABLE(${SETTING_CONFUTIL}
-       ./conf_util/setting_confutil.c
-       )
-TARGET_LINK_LIBRARIES(${SETTING_CONFUTIL} -L${CMAKE_BINARY_DIR}/${SETTING_COMMON} -lsetting-common)
-TARGET_LINK_LIBRARIES(${SETTING_CONFUTIL} ${pkgs_main_LDFLAGS} "-pie")
-INSTALL(TARGETS ${SETTING_CONFUTIL} DESTINATION ${TZ_SYS_RO_APP}/${SETTING_PKG_NAME}/bin)
-
 ####FOR TEST>>>>########
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} -L${CMAKE_BINARY_DIR}/${SETTING_COMMON} -lsetting-common)
 
diff --git a/src/conf_util/setting_confutil.c b/src/conf_util/setting_confutil.c
deleted file mode 100755 (executable)
index 20259de..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * setting_confutil
- *
- *
- *
-       $ setting_confutil                              // create a cfg file in default
-       $ setting_confutil export               // export current status to a xml file
-       $ setting_confutil timezone_init        // timezone init
- */
-#include <stdio.h>
-
-#include <setting-cfg.h>
-#include <setting-debug.h>
-#include <stdio.h>
-#include <Elementary.h>
-#include <setting-common-general-func.h>
-#include <setting-common-data-slp-setting.h>
-#include <unistd.h>
-#include <system_settings.h>
-
-#include <stdio.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <setting-common-search.h>
-
-static char *get_timezone();
-
-static void get_gmt_offset(char *str_buf, int size)
-{
-       /* timezone string +/-<n> ex. +9, -1 */
-       time_t t = time(0);             /* get unix time. sec. */
-
-       struct tm *pdata, data;
-       pdata = localtime_r(&t, &data);         /* save time as structure. */
-       setting_retm_if(!pdata, "data is NULL");
-       pdata->tm_isdst = 0;                    /* summer time, not applied. */
-       time_t a = mktime(pdata);
-
-       pdata = gmtime_r(&a, &data);
-       setting_retm_if(!pdata, "data is NULL");
-       pdata->tm_isdst = 0;                    /* summer time, not applied. */
-       time_t b = mktime(pdata);
-
-       int gmtoffset_hour = (a - b) / 3600;    /* result : hour. */
-       int gmtoffset_min = ((a - b) % 3600) / 60;      /* result : min. */
-       if (gmtoffset_min != 0) {
-               gmtoffset_min = 30;
-       }
-
-       snprintf(str_buf, size, "%+d:%02u", gmtoffset_hour, gmtoffset_min);
-       SETTING_TRACE("szTimezone is of a valid format: GMT: %s", str_buf);
-}
-
-int generate_setting_cfg()
-{
-       if (0 == setting_cfg_create(false)) {
-               SETTING_TRACE_ERROR("Error to create a new config file");
-               return 0 ;
-       }
-
-       return 1;
-}
-
-int migrate_setting_cfg()
-{
-       SETTING_TRACE_BEGIN;
-       if (0 == setting_cfg_migrate()) {
-               SETTING_TRACE_ERROR("Fail to migrate config file");
-               return 0 ;
-       }
-       SETTING_TRACE_END;
-       return 1;
-}
-
-void timezone_init()
-{
-       char *tzpath = get_timezone();
-       int ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_ID, tzpath + 20);
-       if (ret != 0) {
-               SETTING_TRACE("fail to set vconf");
-       }
-       char str_buf[256] = {0, };
-       get_gmt_offset(str_buf, 256);
-       SETTING_TRACE(">>> time zone GMT string : %s", str_buf);
-       g_free(tzpath);
-}
-
-void get_current_font()
-{
-       char *value = NULL;
-       int retcode = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &value);
-       if (retcode != 0) {
-               SETTING_TRACE("fail to set SYSTEM_SETTINGS_KEY_FONT_TYPE");
-       }
-       SETTING_TRACE(">>> get current font type : %s \n", value);
-}
-
-int status_fp(int total, int current, void *data)
-{
-       SETTING_TRACE(">> total : %d ---- current : %d ", total, current);
-       return 0;
-}
-
-
-/**
-sh-4.1# [_TZ_SYS_RW_APP]/org.tizen.setting/bin/setting_conf_util timezone_check
-debug level init 1(1)
->>> time zone : /usr/share/zoneinfo/Asia/Seoul
-*/
-int main(int argc, char *argv[])
-{
-       elm_init(argc, argv);
-       setting_set_i18n_force(SETTING_PACKAGE, SETTING_LOCALEDIR);
-
-       if ((argc == 2) && (0 == strcmp(argv[1], "export_json"))) {
-               setting_export_json(status_fp, NULL);
-       } else if ((argc == 2) && (0 == strcmp(argv[1], "import_json"))) {
-               setting_import_json(status_fp, NULL);
-       } else if ((argc == 2) && (0 == strcmp(argv[1], "timezone_init"))) {
-               timezone_init();
-       } else if ((argc == 2) && (0 == strcmp(argv[1], "get_current_font"))) {
-               get_current_font();
-       } else if ((argc == 2) && (0 == strcmp(argv[1], "gen_cfg"))) {
-               generate_setting_cfg();
-       } else if ((argc == 2) && (0 == strcmp(argv[1], "mig_cfg"))) {
-               migrate_setting_cfg();
-       } else {
-               /* cfg create */
-               /* TRUE or FALSE */
-               setting_cfg_create(false);
-       }
-       return 0;
-}
-
-/* automatic */
-static char *get_timezone()
-{
-       SETTING_TRACE_BEGIN;
-
-       enum { BUFFERSIZE = 1024 };
-       char buf[BUFFERSIZE] = {0, };
-       ssize_t len = readlink(_TZ_SYS_ETC"/localtime", buf, sizeof(buf) - 1);
-
-       if (len != -1) {
-               buf[len] = '\0';
-       } else {
-               /* handle error condition */
-               return NULL;
-       }
-       return g_strdup(buf);
-}
-
diff --git a/src/conf_util/setting_confutil.h b/src/conf_util/setting_confutil.h
deleted file mode 100644 (file)
index 4a3cb4e..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef __SETTING_CONFIG_UTIL_
-#define __SETTING_CONFIG_UTIL_
-
-#include <system_settings.h>
-
-
-#endif