ipvalidator.cpp

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /** 
00023  * \file ipvalidator.cpp
00024  * \version $Id: ipvalidator.cpp 1563 2006-12-26 06:06:04Z edmanm $
00025  * \brief Validates an entered IP address
00026  */
00027 
00028 #include "ipvalidator.h"
00029 
00030 /** Regular expression to validate that input is a valid IP address. */
00031 #define IP_REGEXP "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"\
00032                   "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"\
00033                   "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"\
00034                   "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"
00035 
00036 #define MATCH_ALL "*" /**< Match all IP addresses. */
00037 
00038 
00039 /** Constructor. */
00040 IPValidator::IPValidator(QObject *parent)
00041 : QRegExpValidator(QRegExp(IP_REGEXP), parent)
00042 {
00043 }
00044 
00045 /** Validates the given input is either a valid IP or a "*". */
00046 QValidator::State
00047 IPValidator::validate(QString &input, int &pos) const
00048 {
00049   if (input == MATCH_ALL) {
00050     return QValidator::Acceptable;
00051   }
00052   return QRegExpValidator::validate(input, pos);
00053 }
00054 
00055 /** Validates the given input from position 0. */
00056 QValidator::State
00057 IPValidator::validate(QString &input) const
00058 {
00059   int discard = 0;
00060   return validate(input, discard);
00061 }
00062 

Generated on Wed Sep 5 15:49:27 2007 for Vidalia by  doxygen 1.5.3