Bug Fix and code cleaup 05/125805/3 accepted/tizen/unified/20170425.044941 submit/tizen/20170424.094825
authorMilind Ramesh Murhekar <m.murhekar@samsung.com>
Tue, 18 Apr 2017 15:06:29 +0000 (20:36 +0530)
committerMilind Ramesh Murhekar <m.murhekar@samsung.com>
Wed, 19 Apr 2017 05:02:20 +0000 (10:32 +0530)
Description: This change includes the
VD tizen 3.0 product changes which merged as a bug fixes
and code clean up

Change-Id: Ic9a8ab65c347eccc5028e457ced95c14e5bbddc8
Signed-off-by: Milind Ramesh Murhekar <m.murhekar@samsung.com>
packaging/capi-network-wifi-direct.spec
src/wifi-direct-client-proxy.c
test/test-wifi-direct.c

index fa91242..61adc94 100644 (file)
@@ -3,7 +3,7 @@
 
 Name:       capi-network-wifi-direct
 Summary:    Network WiFi-Direct Library
-Version:    1.2.78
+Version:    1.2.79
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
index 5c2b251..3238993 100644 (file)
@@ -3976,7 +3976,7 @@ int wifi_direct_set_display(wifi_direct_display_type_e type, int port, int hdcp)
        if (type < WIFI_DIRECT_DISPLAY_TYPE_SOURCE ||
                        type > WIFI_DIRECT_DISPLAY_TYPE_DUAL || port < 0 ||
                        hdcp < 0) {
-               WDC_LOGE("Invalid paramaeters passed type[%d], port[%d], hdcp[%d]!");
+               WDC_LOGE("Invalid paramaeters passed type[%d], port[%d], hdcp[%d]!", type, port, hdcp);
                __WDC_LOG_FUNC_END__;
                return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
        }
index 77d5dc9..1320e47 100644 (file)
@@ -23,7 +23,7 @@
 
 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
-
+#define MACSTR_LEN 18
 #define MAX_PEER_NUM 10
 
 static const char *test_wfd_convert_error_to_string(wifi_direct_error_e err_type)
@@ -453,11 +453,11 @@ int select_peer(struct appdata* ad)
 
        printf("input peer index:\n");
        if (scanf(" %3d", &target) < 1)
-               return -1;
+               return 0;
 
        if (target < 0 || target > ad->peer_count) {
                printf("Wrong contact index [%d]\n", target);
-               return -1;
+               return 0;
        } else
                ad->selected_peer_index = target;
 
@@ -789,10 +789,10 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                event_printf("event - WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
 
                if (error_code == WIFI_DIRECT_ERROR_NONE) {
-                       char _peer_mac[18] = {0, };
+                       char _peer_mac[MACSTR_LEN+1] = {0,};
 
                        if (NULL != mac_address)
-                               strncpy(_peer_mac, mac_address, strlen(mac_address));
+                               g_strlcpy(_peer_mac, mac_address, sizeof(_peer_mac));
 
                        printf("Connection start with [%s] \n", _peer_mac);
                        event_printf("Error None\n");
@@ -805,11 +805,11 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                event_printf("event - WIFI_DIRECT_CONNECTION_RSP\n");
 
                if (error_code == WIFI_DIRECT_ERROR_NONE) {
-                       char incomming_peer_mac[18] = {0, };
+                       char incomming_peer_mac[MACSTR_LEN+1] = {0,};
                        char status[100] = {0,};
 
                        if (NULL != mac_address)
-                               strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+                               g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
 
                        printf("Connection response with [%s] \n", incomming_peer_mac);
                        event_printf("Error None\n");
@@ -818,14 +818,14 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                        if (owner) {
                                wifi_direct_get_ip_address(&ip_addr);
                                if (NULL != ip_addr) {
-                                       sprintf(status, "<color=#FFFFFF>GO - IP : %s", ip_addr);
+                                       snprintf(status, sizeof(status), "<color=#FFFFFF>GO - IP : %s", ip_addr);
                                        free(ip_addr);
                                }
 
                        } else {
                                wifi_direct_get_ip_address(&ip_addr);
                                if (NULL != ip_addr) {
-                                       sprintf(status, "<color=#FFFFFF>STA - IP : %s", ip_addr);
+                                       snprintf(status, sizeof(status), "<color=#FFFFFF>STA - IP : %s", ip_addr);
                                        free(ip_addr);
                                }
                        }
@@ -905,7 +905,7 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
        case WIFI_DIRECT_CONNECTION_REQ:
        {
                event_printf("event - WIFI_DIRECT_CONNECTION_REQ\n");
-               char incomming_peer_mac[18];
+               char incomming_peer_mac[MACSTR_LEN+1];
                wifi_direct_wps_type_e wps_mode;
                bool auto_connection_mode;
                bool allow_connection = FALSE;
@@ -914,7 +914,7 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                memset(incomming_peer_mac, 0, sizeof(incomming_peer_mac));
 
                if (NULL != mac_address)
-                       strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+                       g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
 
                printf("Connection Request from [%s] \n", incomming_peer_mac);
 
@@ -987,10 +987,10 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                event_printf("event - WIFI_DIRECT_DISCONNECTION_IND\n");
 
                if (error_code == WIFI_DIRECT_ERROR_NONE) {
-                       char incomming_peer_mac[18] = {0, };
+                       char incomming_peer_mac[MACSTR_LEN+1] = {0,};
 
                        if (NULL != mac_address)
-                               strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+                               g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
 
                        printf("Disconnection IND from [%s] \n", incomming_peer_mac);
 
@@ -1005,10 +1005,10 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                event_printf("event - WIFI_DIRECT_DISCONNECTION_RSP\n");
 
                if (error_code == WIFI_DIRECT_ERROR_NONE) {
-                       char incomming_peer_mac[18] = {0, };
+                       char incomming_peer_mac[MACSTR_LEN+1] = {0,};
 
                        if (NULL != mac_address)
-                               strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+                               g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
 
                        printf("Disconnection RSP with [%s] \n", incomming_peer_mac);
 
@@ -1023,10 +1023,10 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                event_printf("event - WIFI_DIRECT_DISASSOCIATION_IND\n");
 
                if (error_code == WIFI_DIRECT_ERROR_NONE) {
-                       char incomming_peer_mac[18] = {0, };
+                       char incomming_peer_mac[MACSTR_LEN+1] = {0,};
 
                        if (NULL != mac_address)
-                               strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+                               g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
 
                        printf("Disassociation IND from [%s] \n", incomming_peer_mac);
 
@@ -1847,9 +1847,10 @@ void process_input(const char *input, gpointer user_data)
 
                        result = wifi_direct_get_mac_address(&device_mac);
                        printf("wifi_direct_get_mac_addr() result=[%d]\n", result);
-                       if (NULL != device_mac)
+                       if (NULL != device_mac) {
                                printf("MAC [%s] \n", device_mac);
-                       else
+                               free(device_mac);
+                       } else
                                printf("device_mac is NULL !! \n");
                }
                break;
@@ -2511,12 +2512,14 @@ static gboolean test_terminal_read_std_input(GIOChannel * source,
        errno = 0;
        n = read(fd, buf, 1024);
 
-       buf[n - 1] = '\0'; /* remove new line... */
        if (n == 0) {
                printf("Error: read() from stdin returns 0.\n");
        } else if (n < 0) {
-               printf("input: read, err=%s\n", strerror(errno));
+               char error_buf[100] = {0, };
+               strerror_r(errno, error_buf, sizeof(error_buf));
+               printf("input: read, err=%s\n", error_buf);
        } else {
+               buf[n - 1] = '\0'; /* remove new line... */
                printf("\n\n");
                /* printf("Read [%d]bytes data: [%s]\n", n, buf); */
                /* printf("Processing it ---------------------\n", n, buf); */
@@ -2538,7 +2541,9 @@ int main(int argc, char **argv)
 
        main_loop = g_main_loop_new(NULL, FALSE);
 
-       ad = (struct appdata*)malloc(sizeof(struct appdata));
+       ad = (struct appdata*)g_try_malloc0(sizeof(struct appdata));
+       if (!ad)
+               return -1;
 
        ad->main_loop = main_loop;
 
@@ -2559,5 +2564,6 @@ int main(int argc, char **argv)
 
        g_main_loop_run(main_loop);
 
+       g_free(ad);
        return 0;
 }