Removed limit on 25 APs to be returned
authorjaviplx <javiplx@gmail.com>
Sat, 16 Oct 2010 11:17:19 +0000 (11:17 +0000)
committerjaviplx <javiplx@gmail.com>
Sat, 16 Oct 2010 11:17:19 +0000 (11:17 +0000)
git-svn-id: file:///svnroot/wifihood/trunk@63 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiscand/wifiscand.c

index 8aa1d81..d0df690 100644 (file)
@@ -99,22 +99,22 @@ void* makeScan(WirelessInterface* wlan, gchar *message) {
 
        if ( delay == 0 ) {
 
-               scan = (ScanInfo**) malloc( 25 * sizeof(ScanInfo *) );
-               memset(scan, 0, 25 * sizeof(ScanInfo *) );
-               *scan = NULL;
-               int i;
-               for (i=0; i<25; i++) *(scan+i) = NULL;
+               int i = 1; // To acount for the final NULL
+               struct wireless_scan *ap = context.result;
+               while ( ap != NULL ) {
+                                       ap = ap->next;
+                                       i++;
+                       }
+               scan = (ScanInfo**) malloc( i * sizeof(ScanInfo *) );
+               memset(scan, 0, i * sizeof(ScanInfo *) );
 
-               i = 0;
-               ScanInfo *sc = NULL;
+               ScanInfo **sc = scan;
 
                /* Extract values */
-               struct wireless_scan *ap = context.result;
-               while ( ap != NULL && i < 25 ) {
-                               WirelessInterface_ScanItem(ap, &sc);
-                                       *(scan+i) = sc;
+               ap = context.result;
+               while ( ap != NULL ) {
+                               WirelessInterface_ScanItem(ap, sc++);
                                        ap = ap->next;
-                                       i++;
                        }
 
        } else {
@@ -253,15 +253,19 @@ gint dbus_req_handler(const gchar * interface, const gchar * method,
             return OSSO_ERROR;
         }
 
-        int i;
-        for (i=0; i<25&&*(scan+i)!=NULL; i++) {
-            ScanInfo* sc = *(scan+i);
-            retval->value.s = (gchar *) realloc(retval->value.s,23*(i+1)*sizeof(gchar *));
+        int i = 0;
+        while ( *(scan+i) != NULL ) i++;
+        retval->value.s = (gchar *) malloc( (22*i+1) * sizeof(gchar *) );
            if ( retval->value.s == NULL ) {
                 retval->value.s = "Error allocating memory";
                 return OSSO_ERROR;
-           }
-            sprintf(retval->value.s+strlen(retval->value.s),"%s:%d ",sc->mac,sc->rssi);
+               }
+        memset(retval->value.s, '\0', (22*i+1) * sizeof(gchar *) );
+        i = 0;
+        while ( *scan != NULL ) {
+            sprintf(retval->value.s+(22*i),"%s:%d ",(*scan)->mac,(*scan)->rssi);
+            scan++;
+            i++;
         }
 
         retval->value.s[strlen(retval->value.s)-1]  = '\0';