[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r2960: Some more bugfixes and changes according to proposal 121. * (vidalia/branches/hidden-services/src/vidalia/config)



Author: borkdomenik
Date: 2008-08-14 10:03:39 -0400 (Thu, 14 Aug 2008)
New Revision: 2960

Modified:
   vidalia/branches/hidden-services/src/vidalia/config/service.cpp
   vidalia/branches/hidden-services/src/vidalia/config/service.h
   vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp
   vidalia/branches/hidden-services/src/vidalia/config/servicepage.h
   vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp
   vidalia/branches/hidden-services/src/vidalia/config/userauthorizationdata.cpp
Log:
Some more bugfixes and changes according to proposal 121.
* make the comment for client authorization optional (client side)
* changes in the serviceAccessValueChanged because of the point mentioned above
* remove the validation for the comment/identification on client side
* improve the ui.file (not finished yet!)
* applied checkSpace.pl

Modified: vidalia/branches/hidden-services/src/vidalia/config/service.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/service.cpp	2008-08-14 10:01:50 UTC (rev 2959)
+++ vidalia/branches/hidden-services/src/vidalia/config/service.cpp	2008-08-14 14:03:39 UTC (rev 2960)
@@ -15,8 +15,8 @@
 }
 
 /** Constructor to create a new Service with initial settings */
-Service::Service(QString serviceAddress, QString virtualPort,
- QString physicalAddressPort, QString serviceDirectory, bool enabled, bool stealth)
+Service::Service(QString serviceAddress, QString virtualPort,QString
+ physicalAddressPort,QString serviceDirectory,bool enabled,bool stealth)
 {
 
   _serviceAddress = serviceAddress;
@@ -127,7 +127,7 @@
 
   /* Read in from the data stream */
   in >> serviceAddress >> virtualPort  >> physicalAddressPort
-   >> serviceDirectory >> enabled >> stealth 
+   >> serviceDirectory >> enabled >> stealth
    >> additionalServiceOptions >> users;
 
   /* Set the appropriate class member variables */
@@ -154,7 +154,7 @@
     stealth = "x1";
   }
   s.append(_serviceAddress +"#"+ _virtualPort +"#"+  _physicalAddressPort +
-    "#"+ _serviceDirectory +"#"+  _enabled + "#"+ stealth +"#"+ 
+    "#"+ _serviceDirectory +"#"+  _enabled + "#"+ stealth +"#"+
     _additionalServiceOptions + "#");
   foreach(UserAuthorizationData user, _users)
   {

Modified: vidalia/branches/hidden-services/src/vidalia/config/service.h
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/service.h	2008-08-14 10:01:50 UTC (rev 2959)
+++ vidalia/branches/hidden-services/src/vidalia/config/service.h	2008-08-14 14:03:39 UTC (rev 2960)
@@ -24,7 +24,8 @@
   Service();
   /** Constructor to create a new Service with initial settings */
   Service(QString serviceAddress, QString virtualPort,
-   QString physicalAddressPort, QString serviceDirectory, bool enabled, bool stealth);
+   QString physicalAddressPort, QString serviceDirectory,
+   bool enabled, bool stealth);
   /** Destructor */
   virtual ~Service();
   /** Returns the service Adress of the service */

Modified: vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp	2008-08-14 10:01:50 UTC (rev 2959)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp	2008-08-14 14:03:39 UTC (rev 2960)
@@ -42,7 +42,7 @@
   _torServices = new QMap<QString, Service>();
   /* a map mapping from the unique identification, to the auth data
    * of a service*/
-  _consumedServices = new QMap<QString, ServiceAuthorizationData>();
+  _consumedServices = new QMap<int, ServiceAuthorizationData>();
   /** A QRegExpValidator to validate the identification of client auth(Id)
    * and service auth(Id)*/
   QRegExp rx("[a-zA-Z0-9\\+\\-\\_]{0,18}([a-zA-Z0-9\\+\\-\\_])");
@@ -113,8 +113,10 @@
    SLOT(serviceAccessValueChanged()));
   connect(ui.serviceAccessWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this,
    SLOT(serviceAccessSelectionChanged()));
-  connect(ui.checkBox_basic, SIGNAL(toggled(bool)), this, SLOT(checkBoxBasicToggled()));
-  connect(ui.checkBox_stealth, SIGNAL(toggled(bool)), this, SLOT(checkBoxStealthToggled()));
+  connect(ui.checkBox_basic, SIGNAL(toggled(bool)), this,
+   SLOT(checkBoxBasicToggled()));
+  connect(ui.checkBox_stealth, SIGNAL(toggled(bool)), this,
+   SLOT(checkBoxStealthToggled()));
 }
 
 /** Destructor */
@@ -221,8 +223,8 @@
       //aks the user how to react
       if(VMessageBox::warning(this, tr("Error"), tr("Some of the required user\
        authorization identification fields are empty. Do you want Vidalia to\
-       create some dummy values you can change later? If not, the corresponding\
-       authorization data is going to be deleted."),
+       create some dummy values you can change later? If not, the\
+       corresponding authorization data is going to be deleted."),
         VMessageBox::Yes, VMessageBox::No) == VMessageBox::Yes) {
           //create a list containing of all identifications to ensure
           //no double ones
@@ -254,7 +256,7 @@
            //discard the incorrect ones
            for(int i = 0; i < ui.serviceAuthWidget->rowCount(); i++) {
              QTableWidgetItem *currentItem = ui.serviceAuthWidget->item(i, 1);
-             if(currentItem->text() == NULL || currentItem->text().length()==0){
+             if(currentItem->text()==NULL || currentItem->text().length()==0){
                ui.serviceAuthWidget->removeRow(i);
                i--;
              }
@@ -312,13 +314,11 @@
         stealthMode = "stealth";
       }
       serviceConfString.append(" hiddenserviceversion=\"2\" \
-       hiddenserviceauthorizeclient="+string_escape(stealthMode+" " + 
+       hiddenserviceauthorizeclient="+string_escape(stealthMode+" " +
        createUserAuthStringForTor(publishedUsers)));
     }
     serviceConfString.append(" "+ temp.additionalServiceOptions());
   }
-  VMessageBox::warning(this, tr("torConfString"), serviceConfString,
-     VMessageBox::Ok);
   _serviceSettings->applyServices(serviceConfString, &errmsg);
 }
 
@@ -379,8 +379,6 @@
   QList<Service> completeList;
   QString torConfigurationString = _serviceSettings->
    getHiddenServiceDirectories();
-   VMessageBox::warning(this, tr("kompletter string:"), torConfigurationString,
-             VMessageBox::Ok);
   torServiceList = extractSingleServices(torConfigurationString);
   // the services stored with vidalia
   ServiceList serviceList = _serviceSettings->getServices();
@@ -452,7 +450,8 @@
        additionalOptions.remove(indexstart, (indexend-indexstart));
      }
     //remove first appearance of HiddenServiceVerison
-    indexstart = additionalOptions.indexOf("hiddenserviceversion", 0, Qt::CaseInsensitive);
+    indexstart = additionalOptions.indexOf("hiddenserviceversion", 0,
+     Qt::CaseInsensitive);
     endindex = additionalOptions.indexOf("250", indexstart);
     if(endindex != -1) {
       additionalOptions.remove(indexstart, (endindex-indexstart)+4);
@@ -581,54 +580,13 @@
           address = hostname;
         }
   }
-  Service service(address, virtualPort, physAddressPort, serviceDir, true, stealth);
+  Service service(address,virtualPort,physAddressPort,serviceDir,true,stealth);
   service.setAdditionalServiceOptions(additionalOptions);
   service.setUsers(actualUsers);
   _torServices->insert(serviceDir, service);
   return service;
 }
 
-/** this method is called to parse the client_keys file in order to
- *  get all users that had a authorization for the Service
- * @return a list of all users found in client_keys*/
-//QList<UserAuthorizationData>
-//ServicePage::parseClientKeys(QString dir)
-//{
-  //QList<UserAuthorizationData> result;
-  //QString value;
-  //XTODO hier änderungen!!
-  //QFile file(dir.append("/hostname"));
-  //if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
-    //return result;
-  //} else {
-      //QTextStream in(&file);
-      //QString content;
-      //while (!in.atEnd()) {
-        //content.append(in.readLine());
-        //content.append("\n");
-      //}
-      //value = content;
-  //}
-  //QStringList strList1 = value.split("\n");
-  //foreach(QString user, strList1) {
-   //if(user.length() > 1) {
-     //QString onion, cookie, id;
-     //QStringList strList2 = user.split(" ");
-     //onion = strList2.first();
-     //strList2.removeFirst();
-     //cookie = strList2.first();
-     //strList2.removeFirst();
-     //strList2.removeFirst();
-     //strList2.removeFirst();
-     //id = strList2.first();
-     //UserAuthorizationData u(onion+" "+cookie, id);
-     //u.setEnabled(false);
-     //result.push_back(u);
-   //}
- //}
-  //return result;
-//}
-
 /** this method merges the list of services received from Vidalia and Tor
   * @return a list containing all services without double entries */
 QList<Service>
@@ -742,24 +700,28 @@
 }
 
 void
-ServicePage::initServiceAccessTable(QList<ServiceAuthorizationData> authdataList)
+ServicePage::initServiceAccessTable(QList<ServiceAuthorizationData>
+ authdataList)
 {
   while(ui.serviceAccessWidget->rowCount() > 0) {
     ui.serviceAccessWidget->removeRow(0);
   }
+  int index = 0;
   foreach(ServiceAuthorizationData tempService, authdataList) {
-    int rows = ui.serviceAccessWidget->rowCount();
+    //int rows = ui.serviceAccessWidget->rowCount();
     QString authdata = tempService.authdata();
-    QString identification = tempService.identification();
+    QString identification = ""+tempService.identification();
     ServiceAuthorizationData s(authdata, identification);
-    ui.serviceAccessWidget->insertRow(rows);
+    ui.serviceAccessWidget->insertRow(index);
     QTableWidgetItem* authdataItem = new QTableWidgetItem(authdata);
-    QTableWidgetItem* identificationItem = new QTableWidgetItem(identification);
+    QTableWidgetItem* identificationItem = new
+     QTableWidgetItem(identification);
     identificationItem->setData(32, identification);
     authdataItem->setData(32, authdata);
-    ui.serviceAccessWidget->setItem(rows, 0, authdataItem);
-    ui.serviceAccessWidget->setItem(rows, 1, identificationItem);
-    _consumedServices->insert(identification, s);
+    ui.serviceAccessWidget->setItem(index, 0, authdataItem);
+    ui.serviceAccessWidget->setItem(index, 1, identificationItem);
+    _consumedServices->insert(index, s);
+    index++;
   }
 }
 
@@ -886,7 +848,7 @@
               authdata = ui.serviceAuthWidget->item(i, 0)->text();
               identification = ui.serviceAuthWidget->item(i, 1)->text();
               UserAuthorizationData u(authdata, identification);
-              if(ui.serviceAuthWidget->item(i,2)->checkState() == Qt::Checked) {
+              if(ui.serviceAuthWidget->item(i,2)->checkState()==Qt::Checked){
                 enabled = true;
               }
               u.setEnabled(enabled);
@@ -901,7 +863,7 @@
             //no double ones
             QList<QString> identifications;
             for(int i = 0; i < ui.serviceAuthWidget->rowCount(); i++) {
-              QTableWidgetItem *selectedItem = ui.serviceAuthWidget->item(i, 1);
+              QTableWidgetItem *selectedItem = ui.serviceAuthWidget->item(i,1);
               if(selectedItem->text() != NULL &&
                selectedItem->text().length() > 0) {
                 identifications.push_back(selectedItem->text());
@@ -1226,8 +1188,8 @@
   serviceAuthdata = ui.authLineAccess->text();
   serviceIdentification = ""+ui.commentLineAccess->text();
   if(serviceAuthdata.length() == 0) {
-    VMessageBox::warning(this, tr("Error"), tr("Authorization data has to be set."),
-     VMessageBox::Ok);
+    VMessageBox::warning(this, tr("Error"), tr("Authorization data\
+     has to be set."), VMessageBox::Ok);
      return;
   } else {
     int pos = 0;
@@ -1237,14 +1199,14 @@
         QTableWidgetItem* authItem = new QTableWidgetItem(serviceAuthdata);
         QTableWidgetItem* identificationItem =
          new QTableWidgetItem(serviceIdentification);
-        identificationItem->setData(32, serviceIdentification);
+        //identificationItem->setData(32, serviceIdentification);
         authItem->setData(32, serviceAuthdata);
         ui.serviceAccessWidget->setItem(rows, 0, authItem);
         ui.serviceAccessWidget->setItem(rows, 1, identificationItem);
         ui.authLineAccess->clear();
         ui.commentLineAccess->clear();
         ServiceAuthorizationData s(serviceAuthdata, serviceIdentification);
-        _consumedServices->insert(serviceIdentification, s);
+        _consumedServices->insert(rows, s);
       } else {
          VMessageBox::warning(this, tr("Error"), tr("Invalid input for the\
           authorization. Only [onion-Address] [descriptor-cookie] allowed."),
@@ -1276,8 +1238,8 @@
       return QValidator::Invalid;
     }
   } else {
-    VMessageBox::warning(this, tr("Error"), tr("Your onion adress is not valid,\
-     please correct it."), VMessageBox::Ok);
+    VMessageBox::warning(this, tr("Error"), tr("Your onion adress is\
+     not valid, please correct it."), VMessageBox::Ok);
     return QValidator::Invalid;
   }
 }
@@ -1286,10 +1248,19 @@
 void
 ServicePage::removeServiceAuthBtnClicked()
 {
-  QString identification = ui.serviceAccessWidget->item(ui.serviceAccessWidget->
-   currentRow(), 1)->text();
-  _consumedServices->take(identification);
-  ui.serviceAccessWidget->removeRow(ui.serviceAccessWidget->currentRow());
+  int id = ui.serviceAccessWidget->currentRow();
+  _consumedServices->take(id);
+  ui.serviceAccessWidget->removeRow(id);
+  //shift all higher ones one row up!
+  for(int index = id+1; index < ui.serviceAccessWidget->rowCount(); index++){
+    ServiceAuthorizationData s = _consumedServices->take(index);
+    _consumedServices->insert(id,s);
+    QTableWidgetItem* auth = new QTableWidgetItem(s.authdata());
+    QTableWidgetItem* ident = new QTableWidgetItem(s.identification());
+    ui.serviceAccessWidget->setItem(id, 0, auth);
+    ui.serviceAccessWidget->setItem(id, 1, ident);
+    id++;
+  }
 }
 
 /** Called when the user wants to copy athorization data for a service to
@@ -1377,76 +1348,59 @@
 void
 ServicePage::serviceAccessValueChanged()
 {
-  QString currentString, currentAuthdata;
-  QStringList values;
+  QString currentAuthdata;
   QTableWidgetItem *item = ui.serviceAccessWidget->item(
    ui.serviceAccessWidget->currentRow(), 1);
   QTableWidgetItem* authItem = ui.serviceAccessWidget->item(
    ui.serviceAccessWidget->currentRow(), 0);
-  if(item == NULL || item->text() == NULL || item->text().length() == 0 ||
-    authItem == NULL) {
+  if(item == NULL || authItem == NULL) {
     // nothing to validate here
     return;
   } else {
-    currentString = item->text();
-    for(int i = 0; i < ui.serviceAccessWidget->rowCount(); i++) {
-      if(i != ui.serviceAccessWidget->currentRow()) {
-        QTableWidgetItem* tempItem = ui.serviceAccessWidget->item(i, 1);
-        if(tempItem != NULL && tempItem->text() != NULL &&
-         tempItem->text().length() > 0) {
-          values.push_back(tempItem->text());
-        }
-      }
-    }
-    if(values.contains(currentString)) {
-      VMessageBox::warning(this, tr("Error"), tr("The identification has to be\
-      unique, please choose a different one."), VMessageBox::Ok);
-      if(item->data(32).toString() != NULL &&
-       item->data(32).toString().length() > 0) {
-          item->setText(item->data(32).toString());
+    QString identification = ""+item->text();
+    ServiceAuthorizationData s = _consumedServices->take(
+     ui.serviceAccessWidget->currentRow());
+    s.setIdentification(identification);
+    _consumedServices->insert(ui.serviceAccessWidget->currentRow(), s);
+    if(authItem->text() == NULL || authItem->text().length() == 0) {
+      VMessageBox::warning(this, tr("Error"), tr("No empty authorization\
+       allowed!"), VMessageBox::Ok);
+      if(authItem->data(32).toString() != NULL &&
+        authItem->data(32).toString().length() > 0) {
+        currentAuthdata = authItem->data(32).toString();
+        authItem->setText(currentAuthdata);
+        s.setAuthdata(currentAuthdata);
+        _consumedServices->insert(ui.serviceAccessWidget->currentRow(), s);
       } else {
-        item->setText("");
-       }
-    } else {
-      int pos = 0;
-      if(_identificationValidator->validate(currentString, pos) ==
-       QValidator::Acceptable) {
-        if(authItem->text() == NULL || authItem->text().length() == 0) {
-          VMessageBox::warning(this, tr("Error"), tr("No empty authorization\
-           allowed!"), VMessageBox::Ok);
-           if(authItem->data(32).toString() != NULL &&
-            authItem->data(32).toString().length() > 0) {
-             authItem->setText(authItem->data(32).toString());
-           } else {
-             authItem->setText("");
-           }
-        } else {
-          currentAuthdata = authItem->text();
-          if(validateServiceAuth(authItem->text()) == QValidator::Acceptable) {
-            authItem->setData(32, currentAuthdata);
-            authItem->setText(currentAuthdata);
-          } else {
-            if(authItem->data(32).toString() != NULL &&
-             authItem->data(32).toString().length() > 0) {
-               authItem->setText(authItem->data(32).toString());
-             } else {
-               authItem->setText("");
-             }
-          }
+        authItem->setText("");
+        s.setAuthdata("");
+        _consumedServices->insert(ui.serviceAccessWidget->currentRow(), s);
         }
+    } else {
+      currentAuthdata = authItem->text();
+      if(validateServiceAuth(authItem->text()) == QValidator::Acceptable) {
+        authItem->setData(32, currentAuthdata);
+        authItem->setText(currentAuthdata);
+        s.setAuthdata(currentAuthdata);
+        _consumedServices->insert(ui.serviceAccessWidget->currentRow(), s);
       } else {
         VMessageBox::warning(this, tr("Error"), tr("Invalid characters for the\
-         identification, only {[a-z][A-Z][0-9]+-_} allowed. The length has to\
-         be between 1 and 19."), VMessageBox::Ok);
-        if(item->data(32) == NULL || item->data(32).toString() == NULL ||
-         item->data(32).toString().length() <= 0) {
-          item->setText("");
-        } else {
-          item->setText(item->data(32).toString());
-         }
+         authorization. Only [onion-Address] [descriptor-cookie] allowed"),
+         VMessageBox::Ok);
+        if(authItem->data(32).toString() != NULL &&
+         authItem->data(32).toString().length() > 0) {
+          currentAuthdata = authItem->data(32).toString();
+          authItem->setText(currentAuthdata);
+          s.setAuthdata(currentAuthdata);
+          _consumedServices->insert(ui.serviceAccessWidget->currentRow(), s);
+         } else {
+           authItem->setText("");
+           s.setAuthdata("");
+           _consumedServices->insert(ui.serviceAccessWidget->currentRow(), s);
+           }
+        }
       }
-    }
-  }
+   }
 }
 
 /** Called whenever the user selects a different service access
@@ -1523,6 +1477,7 @@
   return true;
 }
 
+/** Called whenever the user clicks on the basic authorization checkbox*/
 void
 ServicePage::checkBoxBasicToggled()
 {
@@ -1537,6 +1492,7 @@
   _services->insert(ui.serviceWidget->currentRow(), s);
 }
 
+/** Called whenever the user clicks on the stealth authorization checkbox*/
 void
 ServicePage::checkBoxStealthToggled()
 {

Modified: vidalia/branches/hidden-services/src/vidalia/config/servicepage.h
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicepage.h	2008-08-14 10:01:50 UTC (rev 2959)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicepage.h	2008-08-14 14:03:39 UTC (rev 2960)
@@ -50,10 +50,6 @@
   *  string a user wants to store within vidalia
   *  @return a QValidator::State signalling whether the string is valid or not*/
   QValidator::State validateServiceAuth(QString authString);
-  /** this method is called to parse the client_keys file in order to
-  * get all users that had a authorization for the Service
-  * @return a list of all users found in client_keys*/
-  //QList<UserAuthorizationData> parseClientKeys(QString dir);
   /** this method creates the configuration string for tor including the
    * user authorization*/
   QString createUserAuthStringForTor(QList<UserAuthorizationData> users);
@@ -113,7 +109,9 @@
   /** Called whenever the user selects a different service authorization
    * entry(Provided Services)*/
   void serviceAuthSelectionChanged();
+  /** Called whenever the user clicks on the basic authorization checkbox*/
   void checkBoxBasicToggled();
+  /** Called whenever the user clicks on the stealth authorization checkbox*/
   void checkBoxStealthToggled();
 
 private:
@@ -125,7 +123,7 @@
   /** A QList, consisting of all running services before vidalia starts */
   QMap<QString, Service>* _torServices;
   /* a map mapping from the unique comment, to the auth data of a service*/
-  QMap<QString, ServiceAuthorizationData>* _consumedServices;
+  QMap<int, ServiceAuthorizationData>* _consumedServices;
   /** Qt Designer generated object */
   Ui::ServicePage ui;
   /** A QRegExpValidator to validate the identification of client auth(Id)

Modified: vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp	2008-08-14 10:01:50 UTC (rev 2959)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp	2008-08-14 14:03:39 UTC (rev 2960)
@@ -53,7 +53,6 @@
 bool
 ServiceSettings::apply(QString *errmsg)
 {
-  //dummy
   return true;
 }
 
@@ -61,7 +60,8 @@
 ServiceList
 ServiceSettings::getServices()
 {
-  QString address,virtualPort,physAddrPort,serviceDir,enabledS,stealthS,additionalData;
+  QString address,virtualPort,physAddrPort,serviceDir,enabledS,
+   stealthS,additionalData;
   bool enabled = false;
   bool stealth = false;
   QStringList stringList;
@@ -105,7 +105,7 @@
         users.push_back(u);
       }
     }
-    Service s(address, virtualPort, physAddrPort, serviceDir, enabled, stealth);
+    Service s(address,virtualPort,physAddrPort,serviceDir,enabled,stealth);
     s.setAdditionalServiceOptions(additionalData);
     s.setUsers(users);
     services.addService(s);

Modified: vidalia/branches/hidden-services/src/vidalia/config/userauthorizationdata.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/userauthorizationdata.cpp	2008-08-14 10:01:50 UTC (rev 2959)
+++ vidalia/branches/hidden-services/src/vidalia/config/userauthorizationdata.cpp	2008-08-14 14:03:39 UTC (rev 2960)
@@ -15,8 +15,8 @@
 }
 
 /** Constructor to create a new User with initial settings */
-UserAuthorizationData::UserAuthorizationData(QString authdata, QString identification):
- AbstractAuthorizationData(authdata, identification)
+UserAuthorizationData::UserAuthorizationData(QString authdata,
+ QString identification):AbstractAuthorizationData(authdata,identification)
 {
 }