upnpmediaserver/avobjects/src/upnpdlnaprotocolinfo.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /** @file
       
     2 * Copyright (c) 2005-2008 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:  ProtocolInfo DLNA functionality class 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpdlnaprotocolinfo.h"
       
    20 #include "upnpdlnaprotocolinfocons.h"
       
    21 #include "upnpprotocolinfolocal.h"
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <e32cons.h>
       
    25 
       
    26 using namespace UpnpDlnaProtocolInfo;
       
    27 
       
    28 
       
    29 //-----------------------------------------------------------------
       
    30 //  CProtocolInfoDlna::CProtocolInfoDlna()
       
    31 //  Constructor of the class
       
    32 //-----------------------------------------------------------------
       
    33 CUpnpDlnaProtocolInfo::CUpnpDlnaProtocolInfo(): CUpnpProtocolInfo(),
       
    34                                             iDlnaCi( KErrNotFound ) 
       
    35     {    
       
    36     }
       
    37 
       
    38 //-----------------------------------------------------------------
       
    39 //  CProtocolInfoDlna::~CProtocolInfoDlna()
       
    40 //  Destructor of the class
       
    41 //-----------------------------------------------------------------
       
    42 CUpnpDlnaProtocolInfo::~CUpnpDlnaProtocolInfo()
       
    43     {    
       
    44     delete iDlnaPn; 
       
    45     delete iDlnaPs; 
       
    46     delete iOtherParams;
       
    47     delete iFlagsParam;
       
    48     delete iOpParam;
       
    49     }
       
    50 
       
    51 
       
    52 //-----------------------------------------------------------------
       
    53 // CProtocolInfoDlna::NewL
       
    54 // Factory method for creating instance of class. aInputString must contain protocolInfo string.
       
    55 //-----------------------------------------------------------------
       
    56 EXPORT_C CUpnpDlnaProtocolInfo* CUpnpDlnaProtocolInfo::NewL()
       
    57     {
       
    58     CUpnpDlnaProtocolInfo* newElement = new (ELeave) CUpnpDlnaProtocolInfo();
       
    59     CleanupStack::PushL( newElement );
       
    60     CleanupStack::Pop( newElement );
       
    61     return newElement; 
       
    62     }
       
    63 
       
    64     
       
    65 //-----------------------------------------------------------------
       
    66 // CProtocolInfoDlna::NewL
       
    67 // Factory method for creating instance of class. aInputString must contain protocolInfo string.
       
    68 //-----------------------------------------------------------------
       
    69 EXPORT_C CUpnpDlnaProtocolInfo* CUpnpDlnaProtocolInfo::NewL(const TDesC8& aInputString)
       
    70     {
       
    71     CUpnpDlnaProtocolInfo* newElement = new (ELeave) CUpnpDlnaProtocolInfo();
       
    72     CleanupStack::PushL( newElement );
       
    73     newElement->BaseConstructL( aInputString );     
       
    74     CleanupStack::Pop( newElement );
       
    75     return newElement; 
       
    76     }
       
    77     
       
    78 //-----------------------------------------------------------------
       
    79 //  CProtocolInfoDlna::ConstructL(TDesC8& aInputString)
       
    80 //  Method for creating instance of class. aInputString must contain protocolInfo string.
       
    81 //-----------------------------------------------------------------
       
    82 void CUpnpDlnaProtocolInfo::ConstructL(const TDesC8& aInputString) 
       
    83     {
       
    84     BaseConstructL(aInputString);
       
    85     
       
    86     TInt result = ParseL( aInputString );
       
    87     if ( result != KErrNone ) 
       
    88         {
       
    89         User::Leave( result );            
       
    90         }
       
    91     }
       
    92 
       
    93 
       
    94 //-----------------------------------------------------------------
       
    95 //  CProtocolInfoDlna::SetOpTimeParam(TBool aValue)
       
    96 //  Setter for DLNA.ORG_OP time seek parameter.
       
    97 //-----------------------------------------------------------------
       
    98 void CUpnpDlnaProtocolInfo::SetOpTimeParam(TBool aValue)
       
    99     {
       
   100     SetDlnaParam( aValue, A_VAL );
       
   101     }
       
   102 
       
   103 //-----------------------------------------------------------------
       
   104 //  CProtocolInfoDlna::SetOpRangeParam(TBool aValue)
       
   105 //  Setter for DLNA.ORG_OP range seek parameter.
       
   106 //-----------------------------------------------------------------
       
   107 void CUpnpDlnaProtocolInfo::SetOpRangeParam(TBool aValue)
       
   108     {
       
   109     return SetDlnaParam( aValue, B_VAL );
       
   110     }
       
   111 
       
   112 //-----------------------------------------------------------------
       
   113 //  CProtocolInfoDlna::SetDlnaFlag(TBool aValue, TInt aFlagIndex)
       
   114 //  Setter for DLNA_FLAGS
       
   115 //-----------------------------------------------------------------
       
   116 void  CUpnpDlnaProtocolInfo::SetDlnaFlag(TBool aValue, TUint8 aFlagIndex)
       
   117     {
       
   118     if ( aFlagIndex >= KDLNA_FLAGS_QUANTITY) return;
       
   119     TInt index = aFlagIndex / K32BIT;
       
   120     SetIntBit32((TUint32&) iDlnaFlags[ index ], aValue, aFlagIndex);
       
   121     }    
       
   122     
       
   123 
       
   124 //-----------------------------------------------------------------
       
   125 //  CProtocolInfoDlna::GetDlnaFlag(TInt aFlagIndex)
       
   126 //  Getter for DLNA_FLAGS
       
   127 //-----------------------------------------------------------------
       
   128 TBool CUpnpDlnaProtocolInfo::GetDlnaFlag(TInt aFlagIndex)
       
   129     {
       
   130     if ( aFlagIndex >= KDLNA_FLAGS_QUANTITY ) return EFalse;
       
   131     TUint8 index = aFlagIndex / K32BIT;
       
   132     TUint8 bit_index = aFlagIndex % K32BIT;
       
   133     TUint32 bit = 1<<bit_index;    
       
   134     if ( iDlnaFlags[ index ]  & bit )
       
   135         {
       
   136         return ETrue;
       
   137         }
       
   138     else 
       
   139         {
       
   140         return EFalse;
       
   141         }
       
   142     
       
   143     }        
       
   144 
       
   145 //-----------------------------------------------------------------
       
   146 //  CProtocolInfoDlna::ParseL(TDesC8& aInputString)
       
   147 //  Parses aInputString into protocolInfo object.
       
   148 //-----------------------------------------------------------------
       
   149 TInt CUpnpDlnaProtocolInfo::ParseL(const TDesC8& aInputString)
       
   150     {
       
   151         TInt result = KErrNone;        
       
   152         CUpnpProtocolInfo::ParseL(aInputString);
       
   153         
       
   154         result = ParseForthParameterL();
       
   155         if ( iDlnaPn != NULL)
       
   156             {
       
   157             delete iFourthParameter; 
       
   158             iFourthParameter = NULL;
       
   159             }
       
   160         return result;        
       
   161     }
       
   162 
       
   163 //-----------------------------------------------------------------
       
   164 //  CProtocolInfoDlna::ParseForthParameterL()
       
   165 //  Parses the fourth field.
       
   166 //-----------------------------------------------------------------
       
   167 TInt CUpnpDlnaProtocolInfo::ParseForthParameterL()
       
   168     {
       
   169     HBufC8* forth = iFourthParameter;
       
   170     if ( !forth )
       
   171         {
       
   172         return KErrArgument;
       
   173         }
       
   174 
       
   175     TLex8 input(*forth);
       
   176     TBool end = EFalse;
       
   177     while( (!input.Eos()) && (!end))
       
   178         {
       
   179         ParseAtomToDelimeter( input, KDlnaTokenizer);
       
   180         TPtrC8 name(input.MarkedToken());
       
   181         Skip(input,1);
       
   182         end = ParseForthParameterInternalL( name, input);
       
   183         }
       
   184     return KErrNone;
       
   185     }
       
   186 
       
   187 //-----------------------------------------------------------------
       
   188 //  CProtocolInfoDlna::ParseDlnaPsParamL(TLex8& aLexer)
       
   189 //  Parses DLNA.ORG_PS params.
       
   190 //-----------------------------------------------------------------
       
   191 void CUpnpDlnaProtocolInfo::ParseDlnaPsParamL(TLex8& aLexer)
       
   192     {
       
   193     ParseAtomToDelimeter(aLexer, KDlnaDelimeter);
       
   194     TPtrC8 value (aLexer.MarkedToken());
       
   195     if ( aLexer.MarkedToken().Length() == 0 ) User::Leave( KErrArgument );
       
   196     SetPsParameterL(value);
       
   197     SkipAndMark(aLexer, 1);
       
   198     }
       
   199 
       
   200 //-----------------------------------------------------------------
       
   201 //  CProtocolInfoDlna::ParseDlnaPnParamL(TLex8& aLexer)
       
   202 //  Parses DLNA.ORG_PN params.
       
   203 //-----------------------------------------------------------------
       
   204 void CUpnpDlnaProtocolInfo::ParseDlnaPnParamL(TLex8& aLexer)
       
   205     {
       
   206     ParseAtomToDelimeter(aLexer, KDlnaDelimeter);
       
   207     TPtrC8 value (aLexer.MarkedToken());
       
   208     if ( aLexer.MarkedToken().Length() == 0 ) User::Leave( KErrArgument );
       
   209     SetPnParameterL(value);
       
   210     SkipAndMark(aLexer, 1);
       
   211     }
       
   212 
       
   213 //-----------------------------------------------------------------
       
   214 //  CProtocolInfoDlna::ParseDlnaOpParamL(TLex8& aLexer)
       
   215 //  Parses DLNA.ORG_OP params.
       
   216 //-----------------------------------------------------------------
       
   217 void CUpnpDlnaProtocolInfo::ParseDlnaOpParamL(TLex8& aLexer)
       
   218     {
       
   219     ParseAtomToDelimeter(aLexer, KDlnaDelimeter);
       
   220     TPtrC8 value (aLexer.MarkedToken());
       
   221     if (value.Length() != 2) User::Leave( KErrArgument );
       
   222     TChar character = value[0]; 
       
   223     User::LeaveIfError(CheckBooleanValue(character));
       
   224     SetOpTimeParam(character == KDLNA_BOOLEAN_TRUE);    
       
   225     character = value[1]; 
       
   226     User::LeaveIfError(CheckBooleanValue(character));
       
   227     SetOpRangeParam(character == KDLNA_BOOLEAN_TRUE);
       
   228     //SetOpParameter
       
   229     SkipAndMark(aLexer, 1);
       
   230     }
       
   231 
       
   232 //-----------------------------------------------------------------
       
   233 //  CProtocolInfoDlna::ParseDlnaCiParamL(TLex8& aLexer)
       
   234 //  Parses DLNA.ORG_CI params.
       
   235 //-----------------------------------------------------------------
       
   236 void CUpnpDlnaProtocolInfo::ParseDlnaCiParamL(TLex8& aLexer)
       
   237     {
       
   238     ParseAtomToDelimeter(aLexer, KDlnaDelimeter);
       
   239     TPtrC8 value (aLexer.MarkedToken());
       
   240     if (value.Length() != 1) User::Leave( KErrArgument );
       
   241     TChar character = value[0]; 
       
   242     User::LeaveIfError(CheckBooleanValue(character));    
       
   243     SetCiParameter(character == KDLNA_BOOLEAN_TRUE);
       
   244     //SetOpParameter
       
   245     SkipAndMark(aLexer, 1);
       
   246     }
       
   247 
       
   248 //-----------------------------------------------------------------
       
   249 //  CProtocolInfoDlna::ParseDlnaFlagsParamL(TLex8& aLexer)
       
   250 //  Parses DLNA.ORG_FLAGS params.
       
   251 //-----------------------------------------------------------------
       
   252 void CUpnpDlnaProtocolInfo::ParseDlnaFlagsParamL(TLex8& aLexer)
       
   253     {
       
   254     ParseAtomToDelimeter(aLexer, KDlnaDelimeter);
       
   255     
       
   256     if ( aLexer.MarkedToken().Length() != 
       
   257         KDLNA_FLAGS_NUMBER * KMAX_INT_LENGTH_STRING) 
       
   258         User::Leave( KErrArgument );
       
   259     
       
   260     TLex8 plagLex(aLexer.MarkedToken());    
       
   261     
       
   262     for(int i = 0; i < KDLNA_FLAGS_NUMBER; i++)
       
   263         {
       
   264         plagLex.Mark();
       
   265         plagLex.Inc( KMAX_INT_LENGTH_STRING );
       
   266         TPtrC8 value (plagLex.MarkedToken());
       
   267         // check if values are from HEX range
       
   268         for (TInt j = 0; j < KMAX_INT_LENGTH_STRING;j++)
       
   269             if (!((value[j] >='0' &&  value[j] <='9') ||
       
   270                 (value[j] >='a' &&  value[j] <='f') || 
       
   271                 (value[j] >='A' &&  value[j] <='F')))
       
   272                 User::Leave( KErrArgument );
       
   273         
       
   274         TLex8* ptr = new TLex8(value);
       
   275         User::LeaveIfError(ptr->Val(iDlnaFlags[i], EHex)); 
       
   276         delete ptr;
       
   277         }
       
   278     SkipAndMark(aLexer,1);
       
   279     }
       
   280 
       
   281 //-----------------------------------------------------------------
       
   282 //  CProtocolInfoDlna::ParseOtherParamsL(TLex8& aLexer)
       
   283 //  Parses other params.
       
   284 //-----------------------------------------------------------------
       
   285 void CUpnpDlnaProtocolInfo::ParseOtherParamsL(TLex8& /*aLexer*/)
       
   286     {
       
   287     if ( iDlnaPn != NULL )
       
   288         {
       
   289         
       
   290         //    SetOtherParamL(aLexer.RemainderFromMark());
       
   291         }
       
   292     }
       
   293     
       
   294 //-----------------------------------------------------------------
       
   295 //  CProtocolInfoDlna::ParseForthParameterInternalL( TDesC8& aName, TLex8& aLexer)
       
   296 //  Parses the fourth param.
       
   297 //-----------------------------------------------------------------
       
   298 TBool CUpnpDlnaProtocolInfo::ParseForthParameterInternalL( const TDesC8& aName, TLex8& aLexer)
       
   299     {
       
   300     TBool result = EFalse;
       
   301     if ( aName.Compare(KDLNA_PN) == 0)
       
   302         {
       
   303         aLexer.Mark();
       
   304         ParseDlnaPnParamL(aLexer);
       
   305         }
       
   306     else if ( aName.Compare(KDLNA_OP) == 0 )
       
   307         {
       
   308         aLexer.Mark();
       
   309         ParseDlnaOpParamL(aLexer);
       
   310         }
       
   311     else if ( aName.Compare(KDLNA_PS) == 0 )
       
   312         {
       
   313         aLexer.Mark();
       
   314         ParseDlnaPsParamL(aLexer);
       
   315         }
       
   316     else if ( aName.Compare(KDLNA_CI) == 0 )        
       
   317         {
       
   318         aLexer.Mark();
       
   319         ParseDlnaCiParamL(aLexer);
       
   320         }
       
   321     else if ( aName.Compare(KDLNA_FLAGS) == 0 )                
       
   322         {
       
   323         aLexer.Mark();
       
   324         ParseDlnaFlagsParamL(aLexer);
       
   325         }
       
   326     else 
       
   327         {
       
   328         ParseOtherParamsL(aLexer);
       
   329         result = ETrue;
       
   330         }
       
   331     return result;
       
   332     }
       
   333         
       
   334 //-----------------------------------------------------------------
       
   335 //  CUpnpDlnaProtocolInfo::FourthField()
       
   336 //  
       
   337 //-----------------------------------------------------------------
       
   338 EXPORT_C TPtrC8 CUpnpDlnaProtocolInfo::FourthField()
       
   339     {
       
   340      TRAPD( error, FourthParameterInternalL() )
       
   341      if ( error )
       
   342          { 
       
   343          return KNullDesC8();
       
   344          }    
       
   345     return iFourthParameter->Des();
       
   346     }
       
   347 
       
   348 
       
   349 //-----------------------------------------------------------------
       
   350 //  CUpnpDlnaProtocolInfo::FourthParameterInternalL()
       
   351 //  
       
   352 //-----------------------------------------------------------------    
       
   353 void CUpnpDlnaProtocolInfo::FourthParameterInternalL()
       
   354     {
       
   355     TInt len = GetFourthParameterLength();
       
   356     
       
   357     HBufC8* buf = HBufC8::NewLC(len);
       
   358     TPtr8 bufPtr(buf->Des());
       
   359     GetFourthParameterInternalL(bufPtr);
       
   360     
       
   361     delete iFourthParameter;
       
   362     iFourthParameter = buf;
       
   363     
       
   364     CleanupStack::Pop(buf);        
       
   365     }
       
   366     
       
   367     
       
   368         
       
   369 //-----------------------------------------------------------------
       
   370 //  CProtocolInfoDlna::SetIntBit(TInt& aParameter, TBool aValue, TInt aBitNumber)
       
   371 //  Setter for DLNA_FLAGS
       
   372 //-----------------------------------------------------------------
       
   373 void CUpnpDlnaProtocolInfo::SetIntBit8(TUint8& aParameter, TBool aValue, TUint8 aBitNumber)
       
   374     {
       
   375     if ( aBitNumber >= KMAX_INT_LENGTH_STRING ) return;
       
   376     if ( ! (aValue == EFalse) )
       
   377         {
       
   378         aParameter |= (TUint8)1<<aBitNumber;
       
   379         }
       
   380     else
       
   381         {
       
   382         aParameter  &= ~((TUint8)1<<aBitNumber);
       
   383         }
       
   384     }
       
   385 
       
   386 //-----------------------------------------------------------------
       
   387 //  CProtocolInfoDlna::SetIntBit(TInt& aParameter, TBool aValue, TInt aBitNumber)
       
   388 //  Setter for DLNA_FLAGS
       
   389 //-----------------------------------------------------------------
       
   390 void CUpnpDlnaProtocolInfo::SetIntBit32(TUint32& aParameter, TBool aValue, TUint8 aBitNumber)
       
   391     {
       
   392     if ( aBitNumber >= K32BIT ) return;
       
   393     if ( ! (aValue == EFalse) )
       
   394         {
       
   395         aParameter |= (TUint32)1<<aBitNumber;
       
   396         }
       
   397     else
       
   398         {
       
   399         aParameter  &= ~((TUint32)1<<aBitNumber);
       
   400         }
       
   401     }    
       
   402     
       
   403 //-----------------------------------------------------------------
       
   404 //  CProtocolInfoDlna::SetDlnaParam(TBool aValue, TInt aParamIndex)
       
   405 //  Setter for a DLNA parameter.
       
   406 //-----------------------------------------------------------------
       
   407 void CUpnpDlnaProtocolInfo::SetDlnaParam(TBool aValue, TUint8 aParamIndex)
       
   408     {
       
   409     SetIntBit8((TUint8&) iParams, aValue, aParamIndex);
       
   410     }    
       
   411             
       
   412 //-----------------------------------------------------------------
       
   413 //  CProtocolInfoDlna::GetDlnaParam(TInt aParamIndex)
       
   414 //  Getter for DLNA params.
       
   415 //-----------------------------------------------------------------
       
   416 TBool CUpnpDlnaProtocolInfo::GetDlnaParam(TInt aParamIndex)
       
   417     {
       
   418      return ( iParams  & ((TUint8)1<<aParamIndex));
       
   419     }
       
   420 
       
   421 //-----------------------------------------------------------------
       
   422 //  CProtocolInfoDlna::IsDlnaFlagsSet()
       
   423 //  This function returns ETrue if at least one dlna flag is set
       
   424 //-----------------------------------------------------------------
       
   425 TBool CUpnpDlnaProtocolInfo::IsDlnaFlagsSet()
       
   426     {
       
   427     for( int i = 0; i < KDLNA_FLAGS_NUMBER  ; i++)
       
   428         {
       
   429         if (iDlnaFlags[i] != 0 )
       
   430             return ETrue;     
       
   431         }
       
   432     //if not DLNA flags not set
       
   433     return EFalse;        
       
   434     }
       
   435 
       
   436 //-----------------------------------------------------------------
       
   437 //  CProtocolInfoDlna::GetForthParameterInternalL(TPtr8& aBuffer)
       
   438 //  This function produces a string containing all info taken from fourth ProtocolInfo field
       
   439 //-----------------------------------------------------------------
       
   440 void CUpnpDlnaProtocolInfo::GetFourthParameterInternalL(TDes8& aBuffer)
       
   441     {
       
   442     
       
   443     //if ( FourthField() != KNullDesC8)
       
   444     //    {
       
   445     //    aBuffer.Append( *iFourthParameter );
       
   446     //    return;
       
   447     //    }    
       
   448     
       
   449     
       
   450     if ( PnParameter() == KNullDesC8 )        
       
   451         {
       
   452         aBuffer.Append(KDlnaAllStar);
       
   453         return;
       
   454         }
       
   455     aBuffer.Append( KDLNA_PN );
       
   456     aBuffer.Append( KDlnaTokenizer ); 
       
   457     aBuffer.Append( *iDlnaPn );
       
   458     if ( GetDlnaOpRangeParam() || GetDlnaOpTimeParam() )
       
   459         {
       
   460         aBuffer.Append( KDlnaDelimeter ); 
       
   461         aBuffer.Append( KDLNA_OP );
       
   462         aBuffer.Append( KDlnaTokenizer ); 
       
   463         aBuffer.Append( GetDlnaOpTimeParam() ? KDLNA_BOOLEAN_TRUE:KDLNA_BOOLEAN_FALSE); //Time value 0,1
       
   464         aBuffer.Append( GetDlnaOpRangeParam() ? KDLNA_BOOLEAN_TRUE:KDLNA_BOOLEAN_FALSE); //Range value 0,1
       
   465         }
       
   466     if ( PsParameter() != KNullDesC8 )
       
   467         {
       
   468         aBuffer.Append( KDlnaDelimeter ); 
       
   469         aBuffer.Append( KDLNA_PS );
       
   470         aBuffer.Append( KDlnaTokenizer ); 
       
   471         aBuffer.Append( *iDlnaPs );
       
   472         }
       
   473     if ( iDlnaCi != KErrNotFound )
       
   474         {
       
   475         aBuffer.Append( KDlnaDelimeter ); 
       
   476         aBuffer.Append( KDLNA_CI );
       
   477         aBuffer.Append( KDlnaTokenizer ); 
       
   478         aBuffer.Append( iDlnaCi ? KOneChar() : KZeroChar() ); 
       
   479         }
       
   480     
       
   481     TBool saveDlnaFlags = IsDlnaFlagsSet();
       
   482     
       
   483     if ( saveDlnaFlags )
       
   484         {
       
   485         aBuffer.Append( KDlnaDelimeter ); 
       
   486         aBuffer.Append( KDLNA_FLAGS );
       
   487         aBuffer.Append( KDlnaTokenizer ); 
       
   488         SerializeDlnaFlagsL( aBuffer );
       
   489         }
       
   490     if ( GetOtherParams() != KNullDesC8) 
       
   491         {
       
   492         aBuffer.Append( KDlnaDelimeter ); 
       
   493         aBuffer.Append( *iOtherParams );
       
   494         }
       
   495     }
       
   496 //-----------------------------------------------------------------
       
   497 //  CProtocolInfoDlna::GetForthParameterParameterLength
       
   498 //  This function returns length of the string containing all relevant information from fourth ProtocolInfo field. 
       
   499 //-----------------------------------------------------------------
       
   500 TInt CUpnpDlnaProtocolInfo::GetFourthParameterLength()
       
   501     {
       
   502     
       
   503     //if ( FourthField() != KNullDesC8)
       
   504     //    {
       
   505     //    return iFourthParameter->Length();
       
   506     //    }
       
   507     
       
   508     
       
   509     if ( PnParameter() == KNullDesC8 )        
       
   510         {
       
   511         return 1; 
       
   512         }
       
   513     TInt result = 0; 
       
   514     result += KDLNA_PN.operator()().Length();
       
   515     result += 1 ; 
       
   516     result += iDlnaPn->Length();
       
   517     if ( GetDlnaOpRangeParam() || GetDlnaOpTimeParam() )
       
   518         {
       
   519         result += 1; // ; 
       
   520         result += KDLNA_OP.operator()().Length();
       
   521         result += 1; //= 
       
   522         result += 1; //Time value 0,1
       
   523         result += 1; //Range value 0,1
       
   524         }
       
   525     if ( PsParameter() != KNullDesC8 )
       
   526         {
       
   527         result += 1; // ; separator
       
   528         result += KDLNA_PS.operator()().Length();
       
   529         result += 1; // = 
       
   530         result += iDlnaPs->Length();
       
   531         }
       
   532     if ( iDlnaCi != KErrNotFound )
       
   533         {
       
   534         result += 1; //; 
       
   535         result += KDLNA_CI.operator()().Length();
       
   536         result += 1; //= 
       
   537         result += 1; // value 
       
   538         }
       
   539     
       
   540     TBool saveDlnaFlags = IsDlnaFlagsSet();
       
   541     
       
   542     if ( saveDlnaFlags )
       
   543         {
       
   544         result += 1; //; 
       
   545         result += KDLNA_FLAGS.operator()().Length();
       
   546         result += 1; // = 
       
   547         result += KDLNA_FLAGS_NUMBER * KMAX_INT_LENGTH_STRING; // Values length
       
   548         }
       
   549     if ( GetOtherParams() != KNullDesC8 ) 
       
   550         {
       
   551         result += 1; //; 
       
   552         result += iOtherParams->Length();
       
   553         }
       
   554     return result;
       
   555     }
       
   556 
       
   557 //-----------------------------------------------------------------
       
   558 //  CProtocolInfoDlna::SerializeDlnaFlagsL(TPtr8& aBuffer)
       
   559 //  Serializes iDlnaFlags member variable into a string.
       
   560 //-----------------------------------------------------------------
       
   561 void CUpnpDlnaProtocolInfo::SerializeDlnaFlagsL(TDes8& aBuffer)
       
   562     {
       
   563     HBufC8* number = HBufC8::NewL(KMAX_INT_LENGTH_STRING);
       
   564     TPtr8 ptrNumber( number->Des() );
       
   565     for(int i = 0; i < KDLNA_FLAGS_NUMBER ; i++)    
       
   566         {
       
   567         ptrNumber.NumFixedWidth(iDlnaFlags[i], EHex, KMAX_INT_LENGTH_STRING);
       
   568         ptrNumber.UpperCase();
       
   569         aBuffer.Append( *number);
       
   570         }
       
   571     delete number;
       
   572     }
       
   573 
       
   574 //-----------------------------------------------------------------
       
   575 //  CProtocolInfoDlna::GetDlnaOpTimeParam()
       
   576 //  Getter for DLNA.ORG_OP time seek parameter.
       
   577 //-----------------------------------------------------------------
       
   578 TBool CUpnpDlnaProtocolInfo::GetDlnaOpTimeParam()
       
   579     {
       
   580     return GetDlnaParam(A_VAL);
       
   581     }
       
   582 
       
   583 //-----------------------------------------------------------------
       
   584 //  CProtocolInfoDlna::GetDlnaOpRangeParam()
       
   585 //  Getter for DLNA.ORG_OP range seek parameter.
       
   586 //-----------------------------------------------------------------
       
   587 TBool CUpnpDlnaProtocolInfo::GetDlnaOpRangeParam()
       
   588     {
       
   589     return GetDlnaParam(B_VAL);
       
   590     }
       
   591 
       
   592 //-----------------------------------------------------------------
       
   593 //  CProtocolInfoDlna::SetOpParameterL(TPtrC8 aValue)
       
   594 //  Setter for DLNA.ORG_OP parameter.
       
   595 //-----------------------------------------------------------------
       
   596 EXPORT_C void CUpnpDlnaProtocolInfo::SetOpParameterL(const TDesC8& aValue)
       
   597     {                   
       
   598     TPtrC8 opParamName;
       
   599     TPtrC8 opParamValue;
       
   600         
       
   601     //---- getting a proper value of DLNA.ORG_OP param --
       
   602     if ( aValue.Locate(KDlnaTokenizer) > KErrNotFound )
       
   603     {
       
   604         TLex8 lexer(aValue);    
       
   605         ParseAtomToDelimeter( lexer, KDlnaTokenizer);
       
   606         opParamName.Set( lexer.MarkedToken() );
       
   607         
       
   608         if ( opParamName != KDLNA_OP)
       
   609             {
       
   610             User::Leave(KErrBadDescriptor);    
       
   611             }
       
   612         
       
   613         Skip(lexer, 1);            
       
   614         opParamValue.Set( lexer.Remainder() );         
       
   615         }
       
   616     else
       
   617         {
       
   618         opParamValue.Set(aValue);            
       
   619         }
       
   620                 
       
   621     //---- parsing DLNA.ORG_OP param value ---------------
       
   622     if ( opParamValue.Length() == 2 && 
       
   623         !CheckBooleanValue(((TChar)opParamValue[0])) && 
       
   624         !CheckBooleanValue(((TChar)opParamValue[1])) 
       
   625         )
       
   626         {                        
       
   627         TBool opTimeParam = ((TChar)opParamValue[0]).GetNumericValue();
       
   628         TBool opRangeParam = ((TChar)opParamValue[1]).GetNumericValue();
       
   629         
       
   630         SetOpTimeParam(opTimeParam);
       
   631         SetOpRangeParam(opRangeParam);        
       
   632         }
       
   633     else 
       
   634         {        
       
   635         User::Leave(KErrBadDescriptor);
       
   636         }                                                                                        
       
   637     } 
       
   638     
       
   639 //-----------------------------------------------------------------
       
   640 //  CProtocolInfoDlna::SetOpParameterL(UpnpDlnaProtocolInfo::TDlnaParams param,TBool aValue)
       
   641 //  Setter for DLNA.ORG_OP parameter.
       
   642 //-----------------------------------------------------------------
       
   643 EXPORT_C void CUpnpDlnaProtocolInfo::SetOpParameterL(UpnpDlnaProtocolInfo::TDlnaParams param,TBool aValue)
       
   644     {
       
   645     SetDlnaParam( aValue, param );
       
   646     }
       
   647     
       
   648 //-----------------------------------------------------------------
       
   649 //  CUpnpDlnaProtocolInfo::OpParameterL()
       
   650 //  Getter for DLNA.ORG_OP parameter.
       
   651 //-----------------------------------------------------------------
       
   652 EXPORT_C TPtrC8 CUpnpDlnaProtocolInfo::OpParameterL()
       
   653     {
       
   654     TBool opTimeParam = GetDlnaOpTimeParam();
       
   655     TBool opRangeParam = GetDlnaOpRangeParam();
       
   656     HBufC8* opParameter = HBufC8::NewLC(2);    
       
   657     opParameter->Des().AppendNum( opTimeParam ? 1:0 );
       
   658     opParameter->Des().AppendNum( opRangeParam ? 1:0 );           
       
   659        
       
   660     CleanupStack::Pop(opParameter);
       
   661        
       
   662     delete iOpParam;
       
   663     iOpParam = opParameter;
       
   664     return iOpParam->Des();
       
   665     }
       
   666 
       
   667 //-----------------------------------------------------------------
       
   668 //  CProtocolInfoDlna::SetOpParameterL(UpnpDlnaProtocolInfo::TDlnaParams param,TBool aValue)
       
   669 //  Setter for DLNA.ORG_OP parameter.
       
   670 //-----------------------------------------------------------------
       
   671 EXPORT_C TBool CUpnpDlnaProtocolInfo::OpParameter(UpnpDlnaProtocolInfo::TDlnaParams param)
       
   672     {
       
   673     return GetDlnaParam( param );
       
   674     }
       
   675     
       
   676 //-----------------------------------------------------------------
       
   677 //  CUpnpDlnaProtocolInfo::SetFlagsParameterL(const TDesC8& flags)
       
   678 //  Setter for DLNA.ORG_CI parameter.
       
   679 //-----------------------------------------------------------------
       
   680 EXPORT_C void CUpnpDlnaProtocolInfo::SetFlagsParameterL(const TDesC8& flags)
       
   681     {                
       
   682     TPtrC8 flagsParamName(KDLNA_FLAGS);        
       
   683     TLex8 lexer(flags);
       
   684     TInt len = flags.Length();
       
   685                 
       
   686     //---- getting a proper value of DLNA.ORG_FLAGS ----
       
   687     if ( flags.Locate(KDlnaTokenizer) > KErrNotFound )
       
   688         {                    
       
   689         ParseAtomToDelimeter( lexer, KDlnaTokenizer);
       
   690         flagsParamName.Set( lexer.MarkedToken() );
       
   691             
       
   692         if ( flagsParamName != KDLNA_FLAGS )
       
   693             {
       
   694             User::Leave(KErrBadDescriptor);    
       
   695             }
       
   696             
       
   697         Skip(lexer, 1);
       
   698         TPtrC8 tmp = lexer.Remainder();
       
   699                         
       
   700         len = tmp.Length();
       
   701         lexer = tmp;
       
   702         }                                        
       
   703         
       
   704     //---- checking if DLNA.ORG_FLAGS has proper value --                
       
   705     if (len != 32)
       
   706         {
       
   707         User::Leave( KErrBadDescriptor );
       
   708         }
       
   709         
       
   710     while( !lexer.Eos() )
       
   711         {
       
   712         if ( !lexer.Get().IsHexDigit() )
       
   713             {
       
   714             User::Leave( KErrBadDescriptor );
       
   715             }
       
   716         }
       
   717         
       
   718     lexer.UnGetToMark();                                                
       
   719     ParseForthParameterInternalL( flagsParamName, lexer );                       
       
   720     }
       
   721     
       
   722 //-----------------------------------------------------------------
       
   723 //  CUpnpDlnaProtocolInfo::FlagsParameterL()
       
   724 //  Getter for DLNA.ORG_CI parameter.
       
   725 //----------------------------------------------------------------
       
   726 EXPORT_C TPtrC8 CUpnpDlnaProtocolInfo::FlagsParameterL()
       
   727     {
       
   728     TInt len = KDLNA_FLAGS_NUMBER * KMAX_INT_LENGTH_STRING; // Values length
       
   729     HBufC8* flagsParameter = HBufC8::NewLC(len);
       
   730     TPtr8 ptr = flagsParameter->Des();
       
   731     SerializeDlnaFlagsL(ptr);
       
   732     CleanupStack::Pop(flagsParameter);    
       
   733     delete iFlagsParam;
       
   734     iFlagsParam = flagsParameter;            
       
   735     return iFlagsParam->Des();
       
   736     }
       
   737 
       
   738 //-----------------------------------------------------------------
       
   739 //  CProtocolInfoDlna::SetCiParameter(TBool aValue)
       
   740 //  Setter for DLNA.ORG_CI parameter.
       
   741 //-----------------------------------------------------------------
       
   742 EXPORT_C void CUpnpDlnaProtocolInfo::SetCiParameter(TBool aValue)
       
   743     {
       
   744     iDlnaCi = aValue;
       
   745     }
       
   746 
       
   747 //-----------------------------------------------------------------
       
   748 //  CProtocolInfoDlna::CiParameter()
       
   749 //  Getter for DLNA.ORG_CI parameter.
       
   750 //-----------------------------------------------------------------
       
   751 EXPORT_C TBool CUpnpDlnaProtocolInfo::CiParameter()
       
   752     {
       
   753     return !(iDlnaCi <= 0);
       
   754     }
       
   755 
       
   756 //-----------------------------------------------------------------
       
   757 //  CProtocolInfoDlna::SetOtherParamsL(TDesC8& aValue)
       
   758 //  Setter for other parameter value.
       
   759 //-----------------------------------------------------------------
       
   760 EXPORT_C void CUpnpDlnaProtocolInfo::SetOtherParamL(const TDesC8& aValue)
       
   761      {
       
   762      if ( iOtherParams)
       
   763          {
       
   764          delete iOtherParams;
       
   765          iOtherParams = NULL;
       
   766          }
       
   767      iOtherParams = aValue.AllocL();
       
   768      }    
       
   769 
       
   770 //-----------------------------------------------------------------
       
   771 //  CProtocolInfoDlna::GetOtherParams()
       
   772 //  Getter for other parameter value.
       
   773 //-----------------------------------------------------------------
       
   774 EXPORT_C TPtrC8 CUpnpDlnaProtocolInfo::GetOtherParams()
       
   775      {
       
   776      if ( iOtherParams )
       
   777          {
       
   778          return iOtherParams->Des();
       
   779          }
       
   780      else
       
   781          {
       
   782          return KNullDesC8();
       
   783          }
       
   784      }
       
   785 
       
   786 //-----------------------------------------------------------------
       
   787 //  CProtocolInfoDlna::SetDlnaFlag(TBool aValue,TInt flag)
       
   788 //  Setter for a single flag.
       
   789 //-----------------------------------------------------------------
       
   790 EXPORT_C void CUpnpDlnaProtocolInfo::SetDlnaFlag(UpnpDlnaProtocolInfo::TDlnaFlags flag, TBool aValue)
       
   791     {
       
   792     SetDlnaFlag( aValue, flag);
       
   793     }
       
   794 
       
   795 //-----------------------------------------------------------------
       
   796 //  ProtocolInfo::DlnaFlag()
       
   797 //  Getter for a single flag.
       
   798 //-----------------------------------------------------------------
       
   799 EXPORT_C TBool CUpnpDlnaProtocolInfo::DlnaFlag(UpnpDlnaProtocolInfo::TDlnaFlags flag)
       
   800     {
       
   801     return GetDlnaFlag(flag);
       
   802     }
       
   803 
       
   804 //-----------------------------------------------------------------
       
   805 //  CProtocolInfoDlna::SetDlnaPnParameterL(TDesC8& aValue)
       
   806 //  Setter for DLNA.ORG_PN.
       
   807 //-----------------------------------------------------------------
       
   808 EXPORT_C void CUpnpDlnaProtocolInfo::SetPnParameterL(const TDesC8& aValue)
       
   809      {
       
   810     if ( iDlnaPn )
       
   811         {
       
   812         delete iDlnaPn ; 
       
   813         iDlnaPn = NULL;
       
   814         }
       
   815     iDlnaPn = aValue.AllocL();
       
   816     }
       
   817  
       
   818 //-----------------------------------------------------------------
       
   819 //  CProtocolInfoDlna::GetDlnaPnParameter()
       
   820 //  Getter for DLNA.ORG_PN.
       
   821 //-----------------------------------------------------------------
       
   822 EXPORT_C TPtrC8 CUpnpDlnaProtocolInfo::PnParameter()
       
   823     {
       
   824      if ( iDlnaPn )
       
   825          {
       
   826          return iDlnaPn->Des();
       
   827          }
       
   828      else 
       
   829          {
       
   830          return KNullDesC8();
       
   831          }
       
   832      }
       
   833 
       
   834 //-----------------------------------------------------------------
       
   835 //  CProtocolInfoDlna::SetDlnaPsParameterL(TDesC8& aValue)
       
   836 //  Setter for DLNA.ORG_PS.
       
   837 //-----------------------------------------------------------------
       
   838 EXPORT_C void CUpnpDlnaProtocolInfo::SetPsParameterL(const TDesC8& aValue)
       
   839     {
       
   840     if ( iDlnaPs )
       
   841         {
       
   842         delete iDlnaPs ; 
       
   843         iDlnaPs = NULL;
       
   844         }
       
   845     iDlnaPs = aValue.AllocL();    
       
   846     }
       
   847  
       
   848 //-----------------------------------------------------------------
       
   849 //  CProtocolInfoDlna::GetDlnaPsParameter()
       
   850 //  Getter for DLNA.ORG_PS.
       
   851 //-----------------------------------------------------------------
       
   852 EXPORT_C TPtrC8 CUpnpDlnaProtocolInfo::PsParameter()
       
   853      {
       
   854      if ( iDlnaPs )
       
   855          {
       
   856          return iDlnaPs->Des();
       
   857          }
       
   858      else
       
   859         {
       
   860         return KNullDesC8();
       
   861         }
       
   862      }
       
   863 
       
   864      
       
   865 //end of file