syncmlfw/common/obex/obexclient/src/NSmlSdpAttributeParser.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     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:  SyncML Obex client
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bt_sock.h>
       
    20 #include "NSmlSdpAttributeParser.h"
       
    21 #include "NSmlSdpAttributeNotifier.h"
       
    22 
       
    23 
       
    24 //------------------------------------------------------------
       
    25 // TSdpAttributeParser::TSdpAttributeParser
       
    26 //------------------------------------------------------------
       
    27 TSdpAttributeParser::TSdpAttributeParser(
       
    28     TSdpAttributeList& aNodeList, 
       
    29     MSdpAttributeNotifier& aObserver
       
    30 ) 
       
    31 :   iObserver(aObserver),
       
    32     iNodeList(aNodeList),
       
    33     iCurrentNodeIndex(0)
       
    34     {
       
    35     // no implementation required
       
    36     }
       
    37 //------------------------------------------------------------
       
    38 // TSdpAttributeParser::HasFinished
       
    39 //------------------------------------------------------------
       
    40 TBool TSdpAttributeParser::HasFinished() const
       
    41     {
       
    42     return CurrentNode().iCommand == EFinished;
       
    43     }
       
    44 //------------------------------------------------------------
       
    45 // TSdpAttributeParser::VisitAttributeValueL
       
    46 //------------------------------------------------------------
       
    47 void TSdpAttributeParser::VisitAttributeValueL(CSdpAttrValue& aValue, TSdpElementType aType)
       
    48     {
       
    49     switch(CurrentNode().iCommand)
       
    50         {
       
    51         case ECheckType:
       
    52             CheckTypeL(aType);
       
    53             break;
       
    54 
       
    55         case ECheckValue:
       
    56             CheckTypeL(aType);
       
    57             CheckValueL(aValue);
       
    58             break;
       
    59 
       
    60         case ECheckEnd:
       
    61             User::Leave(KErrGeneral);   //  list element contains too many items
       
    62             break;
       
    63 
       
    64         case ESkip:
       
    65             break;  // no checking required
       
    66 
       
    67         case EReadValue:
       
    68             CheckTypeL(aType);
       
    69             ReadValueL(aValue);
       
    70             break;
       
    71 
       
    72         case EFinished:
       
    73             User::Leave(KErrGeneral);   // element is after value should have ended
       
    74             return;
       
    75 
       
    76         default:
       
    77             Panic(ESdpAttributeParserInvalidCommand);
       
    78         }
       
    79 
       
    80     AdvanceL();
       
    81     }
       
    82 //------------------------------------------------------------
       
    83 // TSdpAttributeParser::StartListL
       
    84 //------------------------------------------------------------
       
    85 void TSdpAttributeParser::StartListL(CSdpAttrValueList& /*aList*/)
       
    86     {
       
    87     // no checks done here
       
    88     }
       
    89 //------------------------------------------------------------
       
    90 // TSdpAttributeParser::EndListL
       
    91 //------------------------------------------------------------
       
    92 void TSdpAttributeParser::EndListL()
       
    93     {
       
    94     // check we are at the end of a list
       
    95     if (CurrentNode().iCommand != ECheckEnd)
       
    96         {
       
    97         User::Leave(KErrGeneral);
       
    98         }
       
    99 
       
   100     AdvanceL();
       
   101     }
       
   102 //------------------------------------------------------------
       
   103 // TSdpAttributeParser::CheckTypeL
       
   104 //------------------------------------------------------------
       
   105 void TSdpAttributeParser::CheckTypeL(TSdpElementType aElementType) const
       
   106     {
       
   107     if (CurrentNode().iType != aElementType)
       
   108         {
       
   109         User::Leave(KErrGeneral);
       
   110         }
       
   111     }
       
   112 //------------------------------------------------------------
       
   113 // TSdpAttributeParser::CheckValueL
       
   114 //------------------------------------------------------------
       
   115 void TSdpAttributeParser::CheckValueL(CSdpAttrValue& aValue) const
       
   116     {
       
   117     switch(aValue.Type())
       
   118         {
       
   119         case ETypeNil:
       
   120             Panic(ESdpAttributeParserNoValue);
       
   121             break;
       
   122 
       
   123         case ETypeUint:
       
   124             if (aValue.Uint() != (TUint)CurrentNode().iValue)
       
   125                 {
       
   126                 User::Leave(KErrArgument);
       
   127                 }
       
   128             break;
       
   129 
       
   130         case ETypeInt:
       
   131             if (aValue.Int() != CurrentNode().iValue)
       
   132                 {
       
   133                 User::Leave(KErrArgument);
       
   134                 }
       
   135             break;
       
   136 
       
   137         case ETypeBoolean:
       
   138             if (aValue.Bool() != CurrentNode().iValue)
       
   139                 {
       
   140                 User::Leave(KErrArgument);
       
   141                 }
       
   142             break;
       
   143 
       
   144         case ETypeUUID:
       
   145             if (aValue.UUID() != TUUID(CurrentNode().iValue))
       
   146                 {
       
   147                 User::Leave(KErrArgument);
       
   148                 }
       
   149             break;
       
   150 
       
   151         // these are lists, so have to check contents
       
   152         case ETypeDES:
       
   153         case ETypeDEA:
       
   154             Panic(ESdpAttributeParserValueIsList);
       
   155             break;
       
   156 
       
   157         // these aren't supported - use EReadValue and leave on error
       
   158         //case ETypeString:
       
   159         //case ETypeURL:
       
   160         //case ETypeEncoded:
       
   161         default:
       
   162             Panic(ESdpAttributeParserValueTypeUnsupported);
       
   163             break;
       
   164         }
       
   165     }
       
   166 //------------------------------------------------------------
       
   167 // TSdpAttributeParser::ReadValueL
       
   168 //------------------------------------------------------------
       
   169 void TSdpAttributeParser::ReadValueL(CSdpAttrValue& aValue) const
       
   170     {
       
   171     iObserver.FoundElementL(CurrentNode().iValue, aValue);
       
   172     }
       
   173 //------------------------------------------------------------
       
   174 // TSdpAttributeParser::CurrentNode
       
   175 //------------------------------------------------------------
       
   176 const TSdpAttributeParser::SSdpAttributeNode& TSdpAttributeParser::CurrentNode() const
       
   177     {
       
   178     return  iNodeList[iCurrentNodeIndex];
       
   179     }
       
   180 //------------------------------------------------------------
       
   181 // TSdpAttributeParser::AdvanceL
       
   182 //------------------------------------------------------------
       
   183 void TSdpAttributeParser::AdvanceL()
       
   184     {
       
   185     // check not at end
       
   186     if (CurrentNode().iCommand == EFinished)
       
   187         {
       
   188         User::Leave(KErrEof);
       
   189         }
       
   190 
       
   191     // move to the next item
       
   192     ++iCurrentNodeIndex;
       
   193     }
       
   194 
       
   195