"Fossies" - the Fresh Open Source Software Archive

Member "xstress/src/userinterface.cc" (19 Feb 2009, 7862 Bytes) of package /linux/privat/old/xstress-src-0.375-beta-20090219.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "userinterface.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * xstress - xk0derz SMTP Stress Tester
    3  *
    4  * (c) Amit Singh amit@xkoder.com
    5  * http://xkoder.com
    6  *
    7  * This software and related files are licensed under GNU GPL version 2
    8  * Please visit the following webpage for more details
    9  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
   10  */
   11 #include <cstdlib>
   12 #include <cstring>
   13 
   14 #include "common.h"
   15 #include "userinterface.h"
   16 #include "config.h"
   17 
   18 using namespace std;
   19 
   20 const char *cmdOptStr[]=
   21 {
   22   "  ",
   23   "-v",
   24   "--ver",
   25   "--version",
   26   "--help",
   27   "-h",
   28   "--threads",
   29   "-t",
   30   "-m",
   31   "--mails",
   32   "--server",
   33   "-s",
   34   "--port",
   35   "-p",
   36   "--timeout",
   37   "--conf",
   38   "--logfile",
   39   "--license",
   40   "-u",
   41   "--username",
   42   "-P",
   43   "--password",
   44   "-a",
   45   "--auth-type",
   46   "-d",
   47   "--debug",
   48   " "
   49 };
   50 
   51 
   52 void UserInterface::setConfig(Config &configObj)
   53 {
   54   if(!sServerIP.empty()) configObj.sServerIP = sServerIP;
   55   if(!sLogFile.empty()) configObj.sLogFile = sLogFile;
   56   
   57   if(uiThreads>0) configObj.uiThreads = uiThreads;
   58   if(uiMailsPerThread>=0) configObj.uiMailsPerThread = uiMailsPerThread;
   59   if(uiTimeout>0) configObj.uiTimeout = uiTimeout;
   60   if(uiServerPort>0) configObj.uiServerPort = uiServerPort;
   61   
   62   if(!sUsername.empty()) configObj.sUsername = sUsername;
   63   if(!sPassword.empty()) configObj.sPassword = sPassword;
   64   
   65   if(!sAuthType.empty()) configObj.sAuthType = sAuthType;
   66 
   67 }
   68 
   69 unsigned int UserInterface::override()
   70 {
   71   return uiOverride;
   72 }
   73 
   74 UserInterface::UserInterface()
   75 {
   76   uiServerPort = -1;
   77   uiThreads = -1;
   78   uiMailsPerThread = -1;
   79   uiTimeout = -1;
   80   sServerIP = "";
   81   sLogFile = "";
   82   sUsername = "";
   83   sPassword = "";
   84   sAuthType = "";
   85 
   86   sConfigFile = DEFAULT_CONFIG_FILE;  
   87   uiOverride = false;
   88 }
   89 
   90 int UserInterface::processOptions(int argc, const char *argv[])
   91 {
   92   string sOpt, sVal;
   93   int iRetVal = true, ii, jj;
   94   int iOpt;
   95   if(argc<2) return iRetVal;
   96 
   97   for(ii=1;ii<argc;ii++)
   98   {
   99     sOpt = argv[ii];
  100     iOpt = CO_NONE;
  101     for(jj = 1; jj < CO_MAX; jj++)
  102     {
  103       if(sOpt == cmdOptStr[jj])
  104       {
  105         iOpt = jj;
  106         break;
  107       }
  108     }
  109     
  110     switch(iOpt)
  111     {
  112       case CO_D:
  113       case CO_DEBUG:
  114             bDebug = true;
  115         break;
  116 
  117       case CO_A:
  118       case CO_AUTH_TYPE:
  119             if(ii<(argc-1))
  120             {
  121               ii++;
  122               sAuthType = argv[ii];
  123               char cBuf[255];
  124               if(sAuthType.length() < 200)
  125               {
  126                   strcpy(cBuf, sAuthType.c_str());
  127                   int jj = 0;
  128                   while(cBuf[jj])
  129                   {
  130                       cBuf[jj] = toupper(cBuf[jj]);
  131                       jj++;
  132                   }
  133                   sAuthType = cBuf;
  134               }
  135               uiOverride = true;
  136             }
  137             else
  138             {
  139               cout << "Option " << argv[ii] << " requires a value" << endl;
  140               iRetVal = false;
  141             }
  142             break;
  143       case CO_BIG_P:
  144       case CO_PASSWORD:
  145             if(ii<(argc-1))
  146             {
  147               ii++;
  148               sPassword = argv[ii];
  149               uiOverride = true;
  150             }
  151             else
  152             {
  153               cout << "Option " << argv[ii] << " requires a value" << endl;
  154               iRetVal = false;
  155             }
  156             break;
  157       case CO_U:
  158       case CO_USERNAME:
  159             if(ii<(argc-1))
  160             {
  161               ii++;
  162               sUsername = argv[ii];
  163               uiOverride = true;
  164             }
  165             else
  166             {
  167               cout << "Option " << argv[ii] << " requires a value" << endl;
  168               iRetVal = false;
  169             }
  170             break;
  171       case CO_V:
  172       case CO_VER:
  173       case CO_VERSION:
  174             cout << VERSION << endl;
  175             cout << COPYRIGHT << endl;
  176             iRetVal = false;
  177             break;
  178       case CO_HELP:
  179       case CO_H:
  180             cout << VERSION << endl;
  181             cout << COPYRIGHT << endl;
  182             cout << endl;
  183             cout << HELP_MSG << endl;
  184             iRetVal = false;
  185             break;
  186       case CO_THREADS:
  187       case CO_T:
  188             if(ii<(argc-1))
  189             {
  190               ii++;
  191               uiThreads = atoi(argv[ii]);
  192               uiOverride = true;
  193             }
  194             else
  195             {
  196               cout << "Option " << argv[ii] << " requires a value" << endl;
  197               iRetVal = false;
  198             }
  199             break;
  200       case CO_M:
  201       case CO_MAILS_PER_THREADS:
  202             if(ii<(argc-1))
  203             {
  204               ii++;
  205               uiMailsPerThread = atoi(argv[ii]);
  206               uiOverride = true;
  207             }
  208             else
  209             {
  210               cout << "Option " << argv[ii] << " requires a value" << endl;
  211               iRetVal = false;
  212             }
  213             break;
  214       case CO_SERVER:
  215       case CO_S:
  216             if(ii<(argc-1))
  217             {
  218               ii++;
  219               sServerIP = argv[ii];
  220               uiOverride = true;
  221             }
  222             else
  223             {
  224               cout << "Option " << argv[ii] << " requires a value" << endl;
  225               iRetVal = false;
  226             }
  227             break;
  228       case CO_PORT:
  229       case CO_P:
  230             if(ii<(argc-1))
  231             {
  232               ii++;
  233               uiServerPort = atoi(argv[ii]);
  234               uiOverride = true;
  235             }
  236             else
  237             {
  238               cout << "Option " << argv[ii] << " requires a value" << endl;
  239               iRetVal = false;
  240             }
  241             break;
  242       case CO_TIMEOUT:
  243             if(ii<argc)
  244             {
  245               ii++;
  246               uiTimeout = atoi(argv[ii]);
  247               uiOverride = true;
  248             }
  249             else
  250             {
  251               cout << "Option " << argv[ii] << " requires a value" << endl;
  252               iRetVal = false;
  253             }
  254             break;
  255       case CO_CONF:
  256             if(ii<(argc-1))
  257             {
  258               ii++;
  259               sConfigFile = argv[ii];
  260               uiOverride = true;
  261             }
  262             else
  263             {
  264               cout << "Option " << argv[ii] << " requires a value" << endl;
  265               iRetVal = false;
  266             }
  267             break;
  268       case CO_LOGFILE:
  269             if(ii<(argc-1))
  270             {
  271               ii++;
  272               sLogFile = argv[ii];
  273               uiOverride = true;
  274             }
  275             else
  276             {
  277               cout << "Option " << argv[ii] << " requires a value" << endl;
  278               iRetVal = false;
  279             }
  280             break;
  281       case CO_LICENSE:
  282             {
  283 
  284               cout << VERSION << endl;
  285               cout << COPYRIGHT << endl << endl;
  286 
  287               cout << "This program is free software; you can redistribute it and/or" <<endl;
  288               cout << "modify it under the terms of the GNU General";
  289               cout << " Public License version 2" << endl;
  290               cout << "as published by the Free Software Foundation."<< endl;
  291               cout << endl;
  292               cout << "This program is distributed in the hope that it will be useful," << endl;
  293               cout << "but WITHOUT ANY WARRANTY; without even the implied warranty of" << endl;
  294               cout << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the" << endl;
  295               cout << "GNU General Public License for more details." << endl;
  296               cout << endl;
  297               cout << "You should have received a copy of the GNU General Public License" << endl;
  298               cout << "along with this program; if not, write to the Free Software" << endl;
  299               cout << "Foundation, Inc., 51 Franklin Street, Fifth Floor,";
  300               cout << " Boston, MA  02110-1301, USA." << endl;
  301               cout << endl;
  302               cout << "You may contact the author at amit@xkoder.com" << endl;
  303 
  304               iRetVal = false;
  305 
  306             }
  307           break;
  308     }
  309   }
  310   return iRetVal;
  311 }