applayerprotocols/httptransportfw/Test/T_HttpIntegration/CCmdParser.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // $Header$
       
    15 // GT0149 Applications Protocol Integration Test Harness
       
    16 // blank application
       
    17 // This file contains the implementation for CCmdPar class' member 
       
    18 // functions. CCmdPar is an abstract base class for deriving different
       
    19 // SET command classes.  CCmdPar contains parsing of SET commands.
       
    20 // rev:	mjdavey, symbian@mjdss.com, July 2002
       
    21 // for:	Typhoon (7.0s) & JetStream (8.0)
       
    22 // Include Files  
       
    23 // 
       
    24 //
       
    25 
       
    26 #include "CCmdParser.h"
       
    27 
       
    28 //-----------------------------------------------------------------------------
       
    29 
       
    30 CCmdPar::~CCmdPar ( )
       
    31 {
       
    32 }
       
    33 
       
    34 //-----------------------------------------------------------------------------
       
    35 
       
    36 void CCmdPar::ConstructL(TInt aCommandId,   // in: command identifier
       
    37 												const TDesC&  aKeyphrase )  // in: beginning of the command name
       
    38 {
       
    39 CCmdBase::ConstructL(aCommandId, aKeyphrase);
       
    40 }
       
    41 
       
    42 //-----------------------------------------------------------------------------
       
    43 //	This function parses and processes a SET command line
       
    44 
       
    45 TInt CCmdPar::ProcessL( const TDesC& aCommand)      // command line
       
    46 {
       
    47 // Complete the test machine - will then get the next cmd
       
    48 Machine()->CompleteRequest();
       
    49 
       
    50 TPtrC param;
       
    51 TRAPD( ret, param.Set( ParamsL( aCommand )) );
       
    52 if ( ret != KErrNone )
       
    53 	return Error(ret, KFmtErrInvalidCmd, &Keyphrase());
       
    54 
       
    55 // Mark that the value is set
       
    56 TInt old = iHasBeenSet;
       
    57 iHasBeenSet = ETrue;
       
    58 
       
    59 // Check that "=" or "+=" or ":=" follows
       
    60 TBool assignment = ETrue;
       
    61 TBool is_setfrom = EFalse;
       
    62 
       
    63 TLex parse(param);
       
    64 parse.SkipSpace();
       
    65 if (TfrLex::ValF(parse, KTxtAssign) == KErrNone)
       
    66 	assignment = ETrue;
       
    67 else if (TfrLex::ValF(parse, KTxtAddition) == KErrNone)
       
    68 	assignment = EFalse;
       
    69 else if (TfrLex::ValF(parse, KTxtSetFrom) == KErrNone)
       
    70 	assignment = is_setfrom = ETrue;
       
    71 else if (parse.TokenLength() == 0)
       
    72 	ret = Error(KErrArgument, KFmtErrInvalidCmd, &Keyphrase());
       
    73 else
       
    74 	ret = Error(KErrArgument, KFmtErrMissing, &KTxtAssign);
       
    75 
       
    76 // Check that the value exists and set or add the value
       
    77 if (ret == KErrNone)
       
    78 	{
       
    79 	parse.SkipSpace();
       
    80 	TPtrC token = parse.Remainder(); 
       
    81 	if (token.Length() == 0)
       
    82 		ret = Error(KErrArgument, KTxtErrValueMissing);
       
    83 	else if (assignment)
       
    84 		ret = (is_setfrom ? SetFrom(token) : SetValue(token));
       
    85 	else
       
    86 		ret = AddValue( token );
       
    87 	}
       
    88 
       
    89 // If not succeeded, reset information about setting
       
    90 if (ret != KErrNone)
       
    91 	iHasBeenSet = old;
       
    92 
       
    93 return ret;
       
    94 }
       
    95 
       
    96 //-----------------------------------------------------------------------------
       
    97 //	This function provides the default implementation which gives an 
       
    98 //	error message about addition
       
    99 
       
   100 TInt CCmdPar::AddValue(const TDesC& aValue)
       
   101 {
       
   102 aValue.Length();  // to avoid warning about unused parameter
       
   103 return Error(KErrArgument, KTxtErrNoAddition); 
       
   104 }
       
   105 
       
   106 //-----------------------------------------------------------------------------
       
   107 //	This function provides the default implementation which gives an 
       
   108 //	error message about setting the value from file. +TVi
       
   109 
       
   110 TInt CCmdPar::SetFrom(const TDesC& aValue)
       
   111 {
       
   112 aValue.Length();  // to avoid warning about unused parameter
       
   113 return Error(KErrArgument, KTxtErrNoSetFrom); 
       
   114 }
       
   115 
       
   116 //-----------------------------------------------------------------------------
       
   117 
       
   118 TBool CCmdPar::HasBeenSet ( )
       
   119 {
       
   120 return iHasBeenSet;
       
   121 }
       
   122 
       
   123 //-----------------------------------------------------------------------------
       
   124 
       
   125 void CCmdPar::MarkNotSet ( )
       
   126 {
       
   127 iHasBeenSet = EFalse;
       
   128 }
       
   129 
       
   130 //-----------------------------------------------------------------------------
       
   131 //  End of File  
       
   132 //-----------------------------------------------------------------------------
       
   133