printf removed
[apps/native/ug-wifi-direct.git] / popup-wifidirect / src / wfd-app-client.c
index 283416d..cc42794 100755 (executable)
@@ -1,13 +1,13 @@
 /*
 *  WiFi-Direct UG
 *
-* Copyright 2012  Samsung Electronics Co., Ltd
+* Copyright 2012 Samsung Electronics Co., Ltd
 
-* Licensed under the Flora License, Version 1.0 (the "License");
+* Licensed under the Flora License, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 
-* http://www.tizenopensource.org/license
+* http://floralicense.org/license
 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
+#include <notification.h>
+#include <vconf.h>
+
 #include "wfd-app.h"
 #include "wfd-app-util.h"
 #include "wfd-app-strings.h"
-#include <vconf.h>
 
 /**
  *     This function let the app make a callback for connected peer
@@ -53,7 +56,9 @@ bool _wfd_connected_peer_cb(wifi_direct_connected_peer_info_s *peer, void *user_
        WDPOP_LOGD( "%dth connected peer. [%s]\n", peer_cnt, peer->device_name);
 
        strncpy(ad->raw_connected_peers[peer_cnt].ssid, peer->device_name, sizeof(ad->raw_connected_peers[peer_cnt].ssid));
+       ad->raw_connected_peers[peer_cnt].ssid[31] = '\0';
        strncpy(ad->raw_connected_peers[peer_cnt].mac_address, peer->mac_address, WFD_MAC_ADDRESS_SIZE);
+       ad->raw_connected_peers[peer_cnt].mac_address[17] = '\0';
        WDPOP_LOGD( "\tSSID: [%s]\n", ad->raw_connected_peers[peer_cnt].ssid);
        ad->raw_connected_peer_cnt++;
 
@@ -165,9 +170,9 @@ void _add_wfd_peers_connected_notification(void *user_data)
        res = notification_set_execute_option(ad->noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
        if (res != NOTIFICATION_ERROR_NONE) {
                WDPOP_LOGD( "Failed to notification_set_execute_option. [%d]", res);
+               bundle_free(b);
                return;
        }
-
        bundle_free(b);
 
        /* set display application list */
@@ -238,9 +243,9 @@ void _add_wfd_turn_off_notification(void *user_data)
        res = notification_set_execute_option(ad->noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
        if (res != NOTIFICATION_ERROR_NONE) {
                WDPOP_LOGD( "Failed to notification_set_execute_option. [%d]", res);
+               bundle_free(b);
                return;
        }
-
        bundle_free(b);
 
        /* set display application list */
@@ -386,6 +391,7 @@ bool _wfd_app_discoverd_peer_cb(wifi_direct_discovered_peer_info_s *peer, void *
        if (NULL != peer->device_name) {
                WDPOP_LOGD( "discovered peer ssid[%s]\n", peer->device_name);
                strncpy(ad->discovered_peers[ad->discovered_peer_count].ssid, peer->device_name, 32);
+               ad->discovered_peers[ad->discovered_peer_count].ssid[31] = '\0';
        } else {
                WDPOP_LOGD( "peer's device name is NULL\n");
        }
@@ -393,6 +399,7 @@ bool _wfd_app_discoverd_peer_cb(wifi_direct_discovered_peer_info_s *peer, void *
        if (NULL != peer->mac_address) {
                WDPOP_LOGD( "discovered peer mac[%s]\n", peer->mac_address);
                strncpy(ad->discovered_peers[ad->discovered_peer_count].mac_address, peer->mac_address, 18);
+               ad->discovered_peers[ad->discovered_peer_count].mac_address[17] = '\0';
        } else {
                WDPOP_LOGD( "peer's mac is NULL\n");
        }
@@ -483,6 +490,7 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                memset(ad->peer_mac, 0, sizeof(ad->peer_mac));
                memset(ad->peer_name, 0, sizeof(ad->peer_name));
                strncpy(ad->peer_mac, mac_address, strlen(mac_address));
+               ad->peer_mac[17] = '\0';
                peer_info = _wfd_app_find_peer_by_mac_address(ad, mac_address);
 
                if (NULL == peer_info) {
@@ -492,10 +500,12 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                } else {
                        WDPOP_LOGD( "SSID from connection is %s.\n", peer_info->ssid);
                        strncpy(ad->peer_name, peer_info->ssid, strlen(peer_info->ssid));
+                       ad->peer_name[31] = '\0';
                }
 
                if (0 == strlen(ad->peer_name)) {
                        strncpy(ad->peer_name, ad->peer_mac, strlen(ad->peer_mac));
+                       ad->peer_name[31] = '\0';
                }
        }
 
@@ -513,11 +523,11 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
 
                        /* tickernoti popup */
                        snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECTED, ad->peer_name);
-                       wfd_tickernoti_popup(msg);
+                       notification_status_message_post(msg);
                } else if (error_code == WIFI_DIRECT_ERROR_AUTH_FAILED) {
                        WDPOP_LOGD(
                                        "Error Code - WIFI_DIRECT_ERROR_AUTH_FAILED\n");
-                       wfd_tickernoti_popup(_("IDS_WFD_POP_PIN_INVALID"));
+                       notification_status_message_post(_("IDS_WFD_POP_PIN_INVALID"));
                } else {
                        if (error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT) {
                                WDPOP_LOGD(
@@ -529,7 +539,7 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
 
                        /* tickernoti popup */
                        snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
-                       wfd_tickernoti_popup(msg);
+                       notification_status_message_post(msg);
                }
        }
        break;
@@ -564,6 +574,7 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                        }
 
                        strncpy(ad->pin_number, pin, 64);
+                       ad->pin_number[63] = '\0';
                        free(pin);
                        pin = NULL;
 
@@ -595,7 +606,7 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
 
                if (auto_connection_mode == TRUE) {
                        result = wifi_direct_accept_connection(ad->peer_mac);
-                       printf("wifi_direct_accept_connection() result=[%d]\n", result);
+                       WDPOP_LOGD("wifi_direct_accept_connection() result=[%d]\n", result);
                } else {
                        if (wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) {
                                WDPOP_LOGD( "wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n");
@@ -623,7 +634,7 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
 
                /* tickernoti popup */
                snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_DISCONNECTED, ad->peer_name);
-               wfd_tickernoti_popup(msg);
+               notification_status_message_post(msg);
        }
        break;
 
@@ -637,14 +648,14 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
 
                /* tickernoti popup */
                snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_DISCONNECTED, ad->peer_name);
-               wfd_tickernoti_popup(msg);
+               notification_status_message_post(msg);
        }
        break;
        case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
        {
                WDPOP_LOGD( "event ------------------ WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
                /* tickernoti popup */
-               wfd_tickernoti_popup(_("IDS_WFD_POP_CONNECTING"));
+               notification_status_message_post(_("IDS_WFD_POP_CONNECTING"));
        }
        break;
        case WIFI_DIRECT_INVITATION_REQ:
@@ -655,7 +666,7 @@ void _cb_connection(int error_code, wifi_direct_connection_state_e connection_st
                wifi_direct_is_autoconnection_mode(&auto_connection_mode);
                if (auto_connection_mode == TRUE) {
                        result = wifi_direct_connect(ad->peer_mac);
-                       printf("wifi_direct_accept_connection() result=[%d]\n", result);
+                       WDPOP_LOGD("wifi_direct_accept_connection() result=[%d]\n", result);
                } else {
                        wfd_prepare_popup(WFD_POP_APRV_CONNECTION_INVITATION_REQ, NULL);
                }
@@ -797,12 +808,7 @@ int init_wfd_popup_client(wfd_appdata_t *ad)
        }
 
        __WDPOP_LOG_FUNC_EXIT__;
-
-       if (ret == WIFI_DIRECT_ERROR_NONE) {
-               return TRUE;
-       } else {
-               return FALSE;
-       }
+       return TRUE;
 }
 
 /**
@@ -844,7 +850,6 @@ int deinit_wfd_popup_client(wfd_appdata_t *ad)
        }
 
        __WDPOP_LOG_FUNC_EXIT__;
-
        if (ret == WIFI_DIRECT_ERROR_NONE) {
                return TRUE;
        } else {