Ticket #2965: tor-2965-vidalia-parameter-handling.patch

File tor-2965-vidalia-parameter-handling.patch, 2.8 KB (added by jrklein, 9 years ago)

Vidalia: Improved Parameter Handling

  • src/vidalia/Vidalia.cpp

    From 86e2c9b858029889cc30f5b725976214c2ac58a8 Mon Sep 17 00:00:00 2001
    From: Jason Klein <trac.torproject.org@my.jrklein.com>
    Date: Wed, 20 Apr 2011 16:55:29 -0500
    Subject: [PATCH] Vidalia: Improved Parameter Handling (#2965)
    
    Vidalia ignores parameters and values that are separated by an equal sign.
    (ie: Vidalia --datadir=data --logfile=log)
    
    Attached patch updates parseArguments() to support keys and values separated by equal sign.
    
    Vidalia does not reject parameters that should include a value.
    (ie: Vidalia --datadir --logfile)
    
    Attached patch calls argNeedsValue() from validateArguments() to determine if value is required.  Vidalia notifies user if required parameter value is missing.
    
    NOTE: validateArguments() was static, so could not call argNeedsValue().  No longer static.  If function needs to be static, could pass an instance of Vidalia as a function parameter instead.
    ---
     src/vidalia/Vidalia.cpp |   16 ++++++++++++++++
     src/vidalia/Vidalia.h   |    2 +-
     2 files changed, 17 insertions(+), 1 deletions(-)
    
    diff --git a/src/vidalia/Vidalia.cpp b/src/vidalia/Vidalia.cpp
    index f88c94f..6e95e3d 100644
    a b Vidalia::parseArguments(QStringList args) 
    252252    if (arg.startsWith("-")) {
    253253      arg = arg.mid((arg.startsWith("--") ? 2 : 1));
    254254    }
     255    /* Argument names do not include equal sign. Assume value follows. */
     256    if (arg.indexOf("=") > -1) {
     257      value = arg.right(arg.length() - (arg.indexOf("=")+1));
     258      arg = arg.left(arg.indexOf("="));
     259    }
     260    else
    255261    /* Check if it takes a value and there is one on the command-line */
    256262    if (i < args.size()-1 && argNeedsValue(arg)) {
    257263      value = args.at(++i);
    Vidalia::parseArguments(QStringList args) 
    265271bool
    266272Vidalia::validateArguments(QString &errmsg)
    267273{
     274  /* Check for missing parameter values */
     275  QMapIterator<QString, QString> _i(_args);
     276  QString tmp;
     277  while(_i.hasNext()) {
     278    _i.next();
     279    if(argNeedsValue(_i.key()) && (_i.value() == "")) {
     280      errmsg = tr("Value required for parameter :") + _i.key();
     281      return false;
     282    }
     283  }
    268284  /* Check for a language that Vidalia recognizes. */
    269285  if (_args.contains(ARG_LANGUAGE) &&
    270286      !LanguageSupport::isValidLanguageCode(_args.value(ARG_LANGUAGE))) {
  • src/vidalia/Vidalia.h

    diff --git a/src/vidalia/Vidalia.h b/src/vidalia/Vidalia.h
    index bc5d124..13d61a0 100644
    a b public: 
    5454  ~Vidalia();
    5555
    5656  /** Validates that all arguments were well-formed. */
    57   static bool validateArguments(QString &errmsg);
     57  bool validateArguments(QString &errmsg);
    5858  /** Displays usage information for command-line args. */
    5959  static void showUsageMessageBox();
    6060  /** Returns true if the user wants to see usage information. */