Convert identifier on-demand if needed
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 26 Feb 2009 22:45:29 +0000 (23:45 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 26 Feb 2009 22:45:29 +0000 (23:45 +0100)
plugins/supplicant.c
src/device.c
src/network.c

index f9af81a..b5c9699 100644 (file)
@@ -845,9 +845,8 @@ static void properties_reply(DBusPendingCall *call, void *user_data)
        struct connman_network *network;
        DBusMessage *reply;
        DBusMessageIter array, dict;
-       char *security, *temp = NULL;
+       char *security;
        unsigned char strength;
-       unsigned int i;
 
        DBG("task %p", task);
 
@@ -922,17 +921,6 @@ static void properties_reply(DBusPendingCall *call, void *user_data)
        if (result.identifier[0] == '\0')
                goto done;
 
-       temp = g_strdup(result.identifier);
-       if (temp == NULL)
-               goto done;
-
-       for (i = 0; i < strlen(temp); i++) {
-               char tmp = temp[i];
-               if ((tmp < '0' || tmp > '9') && (tmp < 'A' || tmp > 'Z') &&
-                                               (tmp < 'a' || tmp > 'z'))
-                       temp[i] = '_';
-       }
-
        strength = result.quality;
 
        if (result.has_rsn == TRUE)
@@ -944,12 +932,12 @@ static void properties_reply(DBusPendingCall *call, void *user_data)
        else
                security = "none";
 
-       network = connman_device_get_network(task->device, temp);
+       network = connman_device_get_network(task->device, result.identifier);
        if (network == NULL) {
                const char *mode;
                int index;
 
-               network = connman_network_create(temp,
+               network = connman_network_create(result.identifier,
                                                CONNMAN_NETWORK_TYPE_WIFI);
                if (network == NULL)
                        goto done;
@@ -985,7 +973,6 @@ static void properties_reply(DBusPendingCall *call, void *user_data)
 done:
        g_free(result.identifier);
        g_free(result.ssid);
-       g_free(temp);
 
        dbus_message_unref(reply);
 
index 8427a2c..701528f 100644 (file)
@@ -1449,9 +1449,28 @@ int connman_device_add_network(struct connman_device *device,
 struct connman_network *connman_device_get_network(struct connman_device *device,
                                                        const char *identifier)
 {
+       struct connman_network *network;
+       char *temp;
+       unsigned int i;
+
        DBG("device %p identifier %s", device, identifier);
 
-       return g_hash_table_lookup(device->networks, identifier);
+       temp = g_strdup(identifier);
+       if (temp == NULL)
+               return NULL;
+
+       for (i = 0; i < strlen(temp); i++) {
+               char tmp = temp[i];
+               if ((tmp < '0' || tmp > '9') && (tmp < 'A' || tmp > 'Z') &&
+                                               (tmp < 'a' || tmp > 'z'))
+                       temp[i] = '_';
+       }
+
+       network = g_hash_table_lookup(device->networks, temp);
+
+       g_free(temp);
+
+       return network;
 }
 
 /**
index e5b2ae5..66158e9 100644 (file)
@@ -447,6 +447,8 @@ struct connman_network *connman_network_create(const char *identifier,
        struct connman_network *network;
        connman_uint8_t strength = 0;
        const char *str;
+       char *temp;
+       unsigned int i;
 
        DBG("identifier %s type %d", identifier, type);
 
@@ -458,7 +460,20 @@ struct connman_network *connman_network_create(const char *identifier,
 
        __connman_element_initialize(&network->element);
 
-       network->element.name = g_strdup(identifier);
+       temp = g_strdup(identifier);
+       if (temp == NULL) {
+               g_free(network);
+               return NULL;
+       }
+
+       for (i = 0; i < strlen(temp); i++) {
+               char tmp = temp[i];
+               if ((tmp < '0' || tmp > '9') && (tmp < 'A' || tmp > 'Z') &&
+                                               (tmp < 'a' || tmp > 'z'))
+                       temp[i] = '_';
+       }
+
+       network->element.name = temp;
        network->element.type = CONNMAN_ELEMENT_TYPE_NETWORK;
 
        network->element.network = network;