telutils/phoneparser/src/CPhoneGsmPcnProcedureParser.cpp
changeset 0 ff3b6d0fd310
child 12 ae8abd0db65c
child 43 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Parser for PCN procedures.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CPhoneGsmPcnProcedureParser.h"
       
    21 #include    "CPhoneGsmParserResult.h"
       
    22 #include    "CPhoneGsmOptionContainer.h"
       
    23 
       
    24 // CONSTANTS
       
    25 
       
    26 // GsmPcn sim lock code prefix
       
    27 _LIT( KPhoneGsmPcnSimLockCodePrefix, "*pw+" );
       
    28 
       
    29 // GsmPcn sim unlock code prefix
       
    30 _LIT( KPhoneGsmPcnSimUnlockCodePrefix, "#pw+" );
       
    31 
       
    32 // Plus character.
       
    33 const TInt KPhoneGsmPcnPlus = '+';
       
    34 
       
    35 // Hash string
       
    36 _LIT( KPhoneGsmPcnHash, "#" );
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CPhoneGsmPcnProcedureParser::CPhoneGsmPcnProcedureParser
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CPhoneGsmPcnProcedureParser::CPhoneGsmPcnProcedureParser()
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CPhoneGsmPcnProcedureParser::NewLC
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CPhoneGsmPcnProcedureParser* CPhoneGsmPcnProcedureParser::NewLC()
       
    53     {
       
    54     CPhoneGsmPcnProcedureParser* self = 
       
    55         new ( ELeave ) CPhoneGsmPcnProcedureParser;
       
    56     
       
    57     CleanupStack::PushL( self );
       
    58     
       
    59     return self;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CPhoneGsmPcnProcedureParser::ParseL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 TBool CPhoneGsmPcnProcedureParser::ParseL( 
       
    67         const TDesC& aString,
       
    68         CPhoneGsmParserResult& aResult,
       
    69         CPhoneGsmOptionContainerBase& aOptions )
       
    70     {
       
    71     TBool result = EFalse;
       
    72     aResult.ClearL();
       
    73     
       
    74     CPhoneGsmOptionContainer& options =
       
    75                 static_cast<CPhoneGsmOptionContainer&>( aOptions );
       
    76     
       
    77     if ( !options.FindOptionStatus( KPhoneOptionSend ) )
       
    78         {
       
    79         result = HandleSimLockCodeL( aString, aResult );
       
    80 
       
    81         if ( !result )
       
    82             {
       
    83             result = HandleSimUnlockCodeL( aString, aResult );
       
    84             }
       
    85         }
       
    86     
       
    87     return result;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CPhoneGsmPcnProcedureParser::HandleSimLockCodeL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 TBool CPhoneGsmPcnProcedureParser::HandleSimLockCodeL(
       
    95         const TDesC& aString,
       
    96         CPhoneGsmParserResult& aResult )
       
    97     {
       
    98     TBool result = EFalse;
       
    99 
       
   100     // Is this SIM lock command
       
   101     if ( IsPrefixOf( aString, KPhoneGsmPcnSimLockCodePrefix ) )
       
   102         {
       
   103         TLex input( aString );
       
   104         input.Inc( KPhoneGsmPcnSimLockCodePrefix().Length() );
       
   105        
       
   106         if ( HandleLockCodeParametersL( input.Remainder(), aResult ) )
       
   107             {
       
   108             result = ETrue;
       
   109             aResult.SetUid( KPhoneUidSimLockCode );
       
   110             }
       
   111         else if ( IsPostfixOf( aString, KPhoneGsmPcnHash ) )
       
   112             {
       
   113             result = ETrue;
       
   114             aResult.ClearL();
       
   115             aResult.SetUid( KPhoneUidSimLockCode );
       
   116             aResult.AddParameterL( KNullDesC );
       
   117             aResult.AddParameterL( KNullDesC );
       
   118             }
       
   119         }
       
   120 
       
   121     return result;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CPhoneGsmPcnProcedureParser::HandleSimUnlockCodeL
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 TBool CPhoneGsmPcnProcedureParser::HandleSimUnlockCodeL(
       
   129         const TDesC& aString,
       
   130         CPhoneGsmParserResult& aResult )
       
   131     {
       
   132     TBool result = EFalse;
       
   133 
       
   134     // Is this SIM unlock command
       
   135     if ( IsPrefixOf( aString, KPhoneGsmPcnSimUnlockCodePrefix ) )
       
   136         {
       
   137         TLex input( aString );
       
   138         input.Inc( KPhoneGsmPcnSimLockCodePrefix().Length() );
       
   139 
       
   140         if ( HandleLockCodeParametersL( input.Remainder(), aResult ) )
       
   141             {
       
   142             result = ETrue;
       
   143             aResult.SetUid( KPhoneUidSimUnlockCode );
       
   144             }
       
   145         else if ( IsPostfixOf( aString, KPhoneGsmPcnHash ) )
       
   146             {
       
   147             result = ETrue;
       
   148             aResult.ClearL();
       
   149             aResult.SetUid( KPhoneUidSimUnlockCode );
       
   150             aResult.AddParameterL( KNullDesC );
       
   151             aResult.AddParameterL( KNullDesC );
       
   152             }
       
   153         }
       
   154 
       
   155     return result;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CPhoneGsmPcnProcedureParser::HandleLockCodeParametersL
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TBool CPhoneGsmPcnProcedureParser::HandleLockCodeParametersL( 
       
   163         const TDesC& aString,
       
   164         CPhoneGsmParserResult& aResult )
       
   165     {
       
   166     TBool result = EFalse;
       
   167     TLex input( aString );
       
   168     TInt len; // length of strings
       
   169    
       
   170     // Extract first parameter
       
   171     TPtrC password( ExtractNumber( aString ) );
       
   172     len = password.Length();
       
   173 
       
   174     if ( len )
       
   175         {
       
   176         // Parameter ok
       
   177         input.Inc( len );       
       
   178 
       
   179         // Plus is separator of two parameters
       
   180         if ( input.Peek() == KPhoneGsmPcnPlus )
       
   181             {
       
   182             input.Inc();
       
   183 
       
   184             // Extract second parameter
       
   185             TPtrC type( ExtractNumber( input.Remainder() ) );
       
   186             len = type.Length();
       
   187 
       
   188             if ( len )
       
   189                 {
       
   190                 // Parameter ok
       
   191                 input.Inc( len );
       
   192 
       
   193                 // Check if we are at the end of string
       
   194                 if ( input.Remainder() == KPhoneGsmPcnHash )
       
   195                     {
       
   196                     aResult.AddParameterL( password );
       
   197                     aResult.AddParameterL( type );
       
   198 
       
   199                     result = ETrue;
       
   200                     }
       
   201                 }
       
   202             }
       
   203         }
       
   204     
       
   205     return result;
       
   206     }
       
   207 
       
   208 //  End of File