SVACE Fixes
[platform/core/connectivity/bluetooth-frwk.git] / bt-otp / bt-otpserver.c
index 4de7302..80348d1 100644 (file)
@@ -33,6 +33,7 @@
 #include "bt-otpserver.h"
 #include "bluetooth-api.h"
 
+#include <cynara-client.h>
 
 #undef LOG_TAG
 #define LOG_TAG "BLUETOOTH_OTP"
@@ -210,9 +211,8 @@ void _bt_otp_exit(void)
        if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("Failed to stop ADV %d", ret);
 
-       if (main_loop != NULL) {
+       if (main_loop != NULL)
                g_main_loop_quit(main_loop);
-       }
 }
 
 static void _bt_otp_set_char_value(const char *obj_path,
@@ -512,6 +512,7 @@ void _bt_otp_start_write_on_fd()
        FILE *fp;
        char file_path[BT_FILE_PATH_MAX_LEN] = {0, };
        int length;
+       char err_msg[256] = {0, };
 
        snprintf(file_path, BT_FILE_PATH_MAX_LEN, "%s%s",
                                        directory, selected_object->name);
@@ -519,7 +520,8 @@ void _bt_otp_start_write_on_fd()
 
        fp = fopen(file_path, "r");
        if (!fp) {
-               BT_DBG("fopen() failed : %s", strerror(errno));
+               cynara_strerror(errno, err_msg, sizeof(err_msg));
+               BT_ERR("fopen() failed : %s", err_msg);
                return;
        }
 
@@ -570,6 +572,7 @@ static gboolean __server_data_received_cb(GIOChannel *chan, GIOCondition cond,
        gsize len = 0;
        int written;
        int fd;
+       char err_msg[256] = {0, };
 
        BT_DBG("");
 
@@ -623,7 +626,8 @@ static gboolean __server_data_received_cb(GIOChannel *chan, GIOCondition cond,
                BT_DBG("file_path = [%s]", file_path);
                fp = fopen(file_path, "w");
                if (!fp) {
-                       BT_DBG("fopen() failed : %s", strerror(errno));
+                       cynara_strerror(errno, err_msg, sizeof(err_msg));
+                       BT_ERR("fopen() failed : %s", err_msg);
                        goto fail;
                }
                oacp_op->fp = fp;
@@ -700,9 +704,8 @@ static void _bt_otp_method(GDBusConnection *connection,
                        goto fail;
                }
 
-               while ((filename = g_dir_read_name(dir))) {
+               while ((filename = g_dir_read_name(dir)))
                        list = g_slist_append(list, (gpointer) filename);
-               }
 
                g_dir_close(dir);
 
@@ -1074,7 +1077,7 @@ int _bt_otp_send_launch_request(char *absolute_path)
 {
        void *handle;
        char *error;
-       int ret;
+       int ret = BLUETOOTH_ERROR_NONE;
 
        /* check ARCH 64 or 32*/
        if (!access(FILEPATH_ARCH_64, 0)) {
@@ -1093,7 +1096,7 @@ int _bt_otp_send_launch_request(char *absolute_path)
        dlerror();      /* Clear any existing error */
 
        int (*fun)(char *) = (int (*)(char *))dlsym(handle,
-                                       "bt_app_control_send_launch_request");
+                       "bt_app_control_send_launch_request");
 
        if ((error = dlerror()) != NULL)  {
                BT_ERR("Can not load symbol : %s", dlerror());
@@ -1101,7 +1104,8 @@ int _bt_otp_send_launch_request(char *absolute_path)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       ret = fun(absolute_path);
+       if (fun)
+               ret = fun(absolute_path);
        dlclose(handle);
 
        return ret;
@@ -1198,6 +1202,10 @@ void _bt_otp_restore_old_object()
 
        index = 0;
        object = _bt_otp_client_find_object(otp_object_list, prev_obj_id, &index);
+       if (!object) {
+               BT_ERR("Object is NULL");
+               return;
+       }
        oacp_create = FALSE;
        update_obj_metadata_charc_value(object);
        selected_object = object;
@@ -1622,6 +1630,7 @@ int _bt_otp_obj_name_write_cb(char *value, int len)
        char new_abs_filepath[BT_FILE_PATH_MAX_LEN] = {0, };
        int ret = BLUETOOTH_ERROR_NONE;
        FILE *fp = NULL;
+       char err_msg[256] = {0, };
 
        object = (struct object_metadata *) g_slist_nth_data(otp_object_list, curr_obj_index);
        if (!object)
@@ -1644,7 +1653,8 @@ int _bt_otp_obj_name_write_cb(char *value, int len)
 
                fp = fopen(new_abs_filepath, "a");
                if (!fp) {
-                       BT_DBG("fopen() failed : %s", strerror(errno));
+                       cynara_strerror(errno, err_msg, sizeof(err_msg));
+                       BT_ERR("fopen() failed : %s", err_msg);
                        ret = BLUETOOTH_ATT_ERROR_INTERNAL;
                        goto fail;
                }
@@ -1789,9 +1799,8 @@ int _bt_otp_read_cb(const char *obj_path, char **value, int *len, uint16_t offse
        }
 
        if (g_strcmp0(obj_path, otp_feature_obj_path)) {
-               if (!selected_object) {
+               if (!selected_object)
                        return BLUETOOTH_OTP_ERROR_OBJECT_NOT_SELECTED;
-               }
        }
 
        info = otp_get_char_value(obj_path);
@@ -1948,13 +1957,11 @@ void _bt_otp_gatt_char_property_changed_event(GVariant *msg,
 
                                        /* Send indication for CPs */
                                        if (!g_strcmp0(char_path, otp_oacp_obj_path)) {
-                                               if (OACP_indicate) {
+                                               if (OACP_indicate)
                                                        _bt_otp_send_indication(char_path, &info, &addr_hex);
-                                               }
                                        } else if (!g_strcmp0(char_path, otp_olcp_obj_path)) {
-                                               if (OLCP_indicate) {
+                                               if (OLCP_indicate)
                                                        _bt_otp_send_indication(char_path, &info, &addr_hex);
-                                               }
                                        }
                                } else {
                                        BT_ERR("Array Len 0");
@@ -2000,11 +2007,10 @@ void _bt_otp_gatt_char_property_changed_event(GVariant *msg,
                                indicate ? "StartNotify" : "StopNotify");
                        BT_INFO("Type '%s'\n", g_variant_get_type_string(var));
 
-                       if (!g_strcmp0(char_path, otp_oacp_obj_path)) {
+                       if (!g_strcmp0(char_path, otp_oacp_obj_path))
                                OACP_indicate = indicate;
-                       } else if (!g_strcmp0(char_path, otp_olcp_obj_path)) {
+                       else if (!g_strcmp0(char_path, otp_olcp_obj_path))
                                OLCP_indicate = indicate;
-                       }
                }
        }
        return;
@@ -2048,9 +2054,8 @@ void _bt_otp_adapter_event_filter(GDBusConnection *connection,
        BT_INFO("Interface %s, Signal %s", interface_name, signal_name);
 
        if (g_strcmp0(interface_name, BT_OTP_INTERFACE_NAME) == 0) {
-               if (strcasecmp(signal_name, BLE_DISABLED) == 0) {
+               if (strcasecmp(signal_name, BLE_DISABLED) == 0)
                        _bt_otp_exit();
-               }
        }
 }
 
@@ -2232,9 +2237,8 @@ int main(void)
 
        BT_DBG("g_main_loop_quit called!");
 
-       if (main_loop != NULL) {
+       if (main_loop != NULL)
                g_main_loop_unref(main_loop);
-       }
 
        return 0;
 }