Fix memory leak when loading global settings
[platform/upstream/connman.git] / src / technology.c
index 34476df..2ba02e2 100644 (file)
@@ -216,10 +216,12 @@ static void technology_save(struct connman_technology *technology)
                                        "Tethering.Identifier",
                                        technology->tethering_ident);
 
-       if (technology->tethering_passphrase)
+       if (technology->tethering_passphrase) {
+               char *enc = g_strescape(technology->tethering_passphrase, NULL);
                g_key_file_set_string(keyfile, identifier,
-                                       "Tethering.Passphrase",
-                                       technology->tethering_passphrase);
+                                       "Tethering.Passphrase", enc);
+               g_free(enc);
+       }
 
 #ifdef TIZEN_EXT
        if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
@@ -446,6 +448,11 @@ static void technology_load(struct connman_technology *technology)
        gchar *identifier;
        GError *error = NULL;
        bool enable, need_saving = false;
+#ifdef TIZEN_EXT
+       char *enc = NULL;
+#else
+       char *enc;
+#endif
 
        DBG("technology %p", technology);
 
@@ -502,9 +509,10 @@ static void technology_load(struct connman_technology *technology)
        technology->tethering_ident = g_key_file_get_string(keyfile,
                                identifier, "Tethering.Identifier", NULL);
 
-       technology->tethering_passphrase = g_key_file_get_string(keyfile,
+       enc = g_key_file_get_string(keyfile,
                                identifier, "Tethering.Passphrase", NULL);
-
+       if (enc)
+               technology->tethering_passphrase = g_strcompress(enc);
 #ifdef TIZEN_EXT
        if (technology->type == CONNMAN_SERVICE_TYPE_WIFI) {
                unsigned int val = 0;
@@ -535,6 +543,9 @@ static void technology_load(struct connman_technology *technology)
 done:
        g_free(identifier);
 
+#ifdef TIZEN_EXT
+       g_free(enc);
+#endif
        g_key_file_free(keyfile);
 }
 
@@ -711,6 +722,7 @@ static void append_properties(DBusMessageIter *iter,
                                        DBUS_TYPE_STRING,
                                        &technology->tethering_passphrase);
 
+#if defined TIZEN_EXT
        connman_dbus_dict_append_basic(&dict, "MacPolicy",
                                        DBUS_TYPE_UINT32,
                                        &(technology->mac_policy));
@@ -722,10 +734,14 @@ static void append_properties(DBusMessageIter *iter,
        connman_dbus_dict_append_basic(&dict, "RandomMacLifetime",
                                        DBUS_TYPE_UINT32,
                                        &(technology->random_mac_lifetime));
-#if defined TIZEN_EXT
+
        if (technology->type == CONNMAN_SERVICE_TYPE_WIFI)
                connman_dbus_dict_append_dict(&dict, "Device.List",
                                        append_devices, technology);
+       if (technology->regdom)
+               connman_dbus_dict_append_basic(&dict, "CountryCode",
+                                       DBUS_TYPE_STRING,
+                                       &technology->regdom);
 #endif
        connman_dbus_dict_close(iter, &dict);
 }
@@ -1658,6 +1674,43 @@ static void __connman_technology_notify_device_detected(
 
        DBG("Successfuly sent DeviceDetected signal");
 }
+
+void __connman_technology_notify_roaming_state(const char *ifname,
+               const char *state, const char *cur_bssid, const char *dst_bssid)
+{
+       DBG("");
+       DBusMessage *signal;
+       DBusMessageIter array, dict;
+
+       signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
+                       CONNMAN_MANAGER_INTERFACE, "RoamingStateChanged");
+       if (!signal)
+               return;
+
+       dbus_message_iter_init_append(signal, &array);
+
+       connman_dbus_dict_open(&array, &dict);
+
+       if (ifname)
+               connman_dbus_dict_append_basic(&dict, "Interface",
+                                       DBUS_TYPE_STRING, &ifname);
+       if (state)
+               connman_dbus_dict_append_basic(&dict, "State",
+                                       DBUS_TYPE_STRING, &state);
+       if (cur_bssid)
+               connman_dbus_dict_append_basic(&dict, "ConnectedBSSID",
+                                       DBUS_TYPE_STRING, &cur_bssid);
+       if (dst_bssid)
+               connman_dbus_dict_append_basic(&dict, "TargetBSSID",
+                                       DBUS_TYPE_STRING, &dst_bssid);
+
+       connman_dbus_dict_close(&array, &dict);
+
+       dbus_connection_send(connection, signal, NULL);
+       dbus_message_unref(signal);
+
+       DBG("Successfully sent Roaming State Changed signal");
+}
 #endif
 
 void __connman_technology_scan_started(struct connman_device *device)
@@ -2210,10 +2263,17 @@ void technology_save_device(struct connman_device *device)
        enum connman_service_type type;
 
        type = __connman_device_get_service_type(device);
+
+       if (type != CONNMAN_SERVICE_TYPE_WIFI)
+               return;
+
        technology = technology_get(type);
        if (!technology)
                return;
 
+       if (!g_slist_find(technology->device_list, device))
+               return;
+
        GKeyFile *keyfile;
        gchar *identifier;
        const char *name = get_name(technology->type);
@@ -2235,7 +2295,7 @@ void technology_save_device(struct connman_device *device)
        gchar **ifname_list = NULL;
        guint dev_count = g_slist_length(technology->device_list);
 
-       if (dev_count > 1) {
+       if (dev_count >= 1) {
                GString *ifname_str = g_string_new(NULL);
 
                if (ifname_str) {
@@ -3215,7 +3275,7 @@ int __connman_technology_add_device(struct connman_device *device)
 #if defined TIZEN_EXT
                bool found = true;
                int err = 0;
-               if (technology->enabled_devices) {
+               if (technology->enabled_devices && type == CONNMAN_SERVICE_TYPE_WIFI) {
                        int i = 0;
                        found = false;
                        const char *ifname = connman_device_get_string(device, "Interface");
@@ -3252,6 +3312,8 @@ done:
                                                                device);
 
 #if defined TIZEN_EXT
+       technology_save_device(device);
+
        const char *ifname = connman_device_get_string(device, "Interface");
        __connman_technology_notify_device_detected(technology, ifname, true);
 
@@ -3282,6 +3344,8 @@ int __connman_technology_remove_device(struct connman_device *device)
                                                                device);
 
 #if defined TIZEN_EXT
+       technology_save_device(device);
+
        const char *ifname = connman_device_get_string(device, "Interface");
        __connman_technology_notify_device_detected(technology, ifname, false);
 #endif