[PC-BSD Commits] r18404 - pcbsd/current/src-qt4/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Sat Aug 11 07:11:56 PDT 2012


Author: kenmoore
Date: 2012-08-11 14:11:56 +0000 (Sat, 11 Aug 2012)
New Revision: 18404

Modified:
   pcbsd/current/src-qt4/libpcbsd/netif.cpp
Log:
Fix the wifiQuickCOnnect in LibPCBSD to overwrite an existing entry in wpa_supplicant.conf instead of adding extra entries for the same SSID



Modified: pcbsd/current/src-qt4/libpcbsd/netif.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/netif.cpp	2012-08-11 09:17:44 UTC (rev 18403)
+++ pcbsd/current/src-qt4/libpcbsd/netif.cpp	2012-08-11 14:11:56 UTC (rev 18404)
@@ -417,20 +417,57 @@
 	
     //Determine if the wpa_supplicant file exists already or is empty
     bool newWPASup = true;
+    bool existingSSID = false;
+    QStringList tmpFileList;
+    QString tmpEntry;
     QFile fileout( "/etc/wpa_supplicant.conf" );
     if( fileout.open( QIODevice::ReadOnly ) ){
       QTextStream streamtmp(&fileout);
       streamtmp.setCodec("UTF-8");
         QString line;
+        bool inEntry = false;
+        bool eStart, eEnd;
         while ( !streamtmp.atEnd() ) {
+            eStart = false; 
+            eEnd = false;	
             line = streamtmp.readLine();
-	    if ( line.indexOf("ctrl_interface=/var/run/wpa_supplicant") == 0 ) {
+	    if ( line.contains("ctrl_interface=/var/run/wpa_supplicant") ) {
    		newWPASup = false;
-		break;
-	    }
+	    }else if(line.contains("ssid=") && line.contains(SSID)){
+	    	existingSSID=true;
+	    }else if(line.contains("network={")){eStart = true;}
+	    else if(line.contains("}")){eEnd = true; }
+	    
+	    //Save the file by entry temporarily
+	    if(eStart){ tmpEntry = line; inEntry = true; }
+	    else if(eEnd){ tmpEntry.append(" ::: "+line); tmpFileList << tmpEntry; inEntry=false; }	    
+	    else if(inEntry){ tmpEntry.append(" ::: "+line); }
+	    else{ tmpFileList << line; }
 	}
 	fileout.close();
     }
+    //If the desired SSID already has an entry, remove it from wpa_supplicant.conf
+    if(existingSSID){
+      QFile tmpFile( "/etc/wpa_supplicant.conf.tmp" );
+      if(tmpFile.open(QIODevice::WriteOnly | QIODevice::Text )){
+        QTextStream oStr(&tmpFile);
+        for(int i=0; i<tmpFileList.length(); i++){
+          if(tmpFileList[i].startsWith("network={")){
+          	  QStringList tmp = tmpFileList[i].split(" ::: ");
+            //skip it if the new SSID
+            if( !tmp[tmp.indexOf("ssid=")].contains(SSID) ){
+              for(int j=0; j<tmp.length(); j++){
+            	oStr << tmp[j] + "/n";    	    
+              }
+            }
+          }else{
+            oStr << tmpFileList[i] + "/n";	  
+          }			
+        }
+      }
+      tmpFile.close();
+      Utils::runShellCommand("mv /etc/wpa_supplicant.conf.tmp /etc/wpa_supplicant.conf");
+    }
     // Create the wpa_supplicant file based on saved configuration    
     if ( fileout.open( QIODevice::Append ) ) {
        QTextStream streamout( &fileout );



More information about the Commits mailing list