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