upnpmediaserver/avobjects/src/upnpprotocolinfo.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /** @file
       
     2 * Copyright (c) 2005-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:  ProtocolInfo base functionality class 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpprotocolinfo.h"
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32cons.h>
       
    23 
       
    24 
       
    25 const char KProtocolInfoDelimeter = ':'; 
       
    26 
       
    27 
       
    28 //-----------------------------------------------------------------
       
    29 //  CProtocolInfo::CProtocolInfo()
       
    30 //  Constructor of the class
       
    31 //-----------------------------------------------------------------
       
    32 CUpnpProtocolInfo::CUpnpProtocolInfo()
       
    33     {
       
    34     }
       
    35 
       
    36 //-----------------------------------------------------------------
       
    37 //  CProtocolInfo::~CProtocolInfo()
       
    38 //  Destructor of the class
       
    39 //-----------------------------------------------------------------
       
    40 CUpnpProtocolInfo::~CUpnpProtocolInfo()
       
    41     {
       
    42     delete iFirstParameter; 
       
    43     delete iSecondParameter; 
       
    44     delete iThirdParameter; 
       
    45     delete iFourthParameter;    
       
    46     delete iProtocolInfo;
       
    47     }
       
    48 
       
    49 
       
    50 //-----------------------------------------------------------------
       
    51 // CProtocolInfo::NewL
       
    52 // Factory method for creating instance of class. aInputString must contain protocolInfo string.
       
    53 //-----------------------------------------------------------------
       
    54 EXPORT_C CUpnpProtocolInfo* CUpnpProtocolInfo::NewL()
       
    55     {
       
    56     CUpnpProtocolInfo* newElement = new (ELeave) CUpnpProtocolInfo();
       
    57     CleanupStack::PushL( newElement );
       
    58     CleanupStack::Pop( newElement );
       
    59     return newElement; 
       
    60     }
       
    61     
       
    62 //-----------------------------------------------------------------
       
    63 // CProtocolInfo::NewL
       
    64 // Factory method for creating instance of class. aInputString must contain protocolInfo string.
       
    65 //-----------------------------------------------------------------
       
    66 EXPORT_C CUpnpProtocolInfo* CUpnpProtocolInfo::NewL(const TDesC8& aInputString)
       
    67     {
       
    68     CUpnpProtocolInfo* newElement = new (ELeave) CUpnpProtocolInfo();
       
    69     CleanupStack::PushL( newElement );
       
    70     newElement->BaseConstructL( aInputString );     
       
    71     CleanupStack::Pop( newElement );
       
    72     return newElement; 
       
    73     }
       
    74     
       
    75 //-----------------------------------------------------------------
       
    76 //  CProtocolInfo::BaseConstructL(TDesC8& aInputString)
       
    77 //  Method for creating instance of class. aInputString must contain protocolInfo string.
       
    78 //-----------------------------------------------------------------
       
    79 void CUpnpProtocolInfo::BaseConstructL(const TDesC8& aInputString)
       
    80     {
       
    81     TInt result = ParseL( aInputString );
       
    82     if ( result != KErrNone ) 
       
    83         {
       
    84         User::Leave( result );            
       
    85         }
       
    86     }
       
    87 
       
    88 
       
    89 //-----------------------------------------------------------------
       
    90 //  CProtocolInfo::ParseL(TDesC8& aInputString)
       
    91 //  Parses aInputString into protocolInfo object.
       
    92 //-----------------------------------------------------------------
       
    93 TInt CUpnpProtocolInfo::ParseL(const TDesC8& aInputString)
       
    94     {
       
    95     TLex8 input(aInputString);
       
    96     TInt i = 0;
       
    97     TInt result = KErrNone;
       
    98     while( (!input.Eos()) )
       
    99         {
       
   100         ParseAtomToDelimeter( input, KProtocolInfoDelimeter);
       
   101         SetParameterL(i++, input.MarkedToken());
       
   102         SkipAndMark( input, 1 );
       
   103         }
       
   104             
       
   105     return result;        
       
   106     }
       
   107 
       
   108 //-----------------------------------------------------------------
       
   109 //  CProtocolInfo::GetFourthParameterParameterLength
       
   110 //  This function returns length of the string containing all relevant information from fourth ProtocolInfo field. 
       
   111 //-----------------------------------------------------------------
       
   112 TInt CUpnpProtocolInfo::GetFourthParameterLength()
       
   113     {
       
   114     if ( FourthField() != KNullDesC8)
       
   115         {
       
   116         return iFourthParameter->Length();
       
   117         }
       
   118     else
       
   119         {
       
   120         return 0;        
       
   121         }    
       
   122     }
       
   123 
       
   124 //-----------------------------------------------------------------
       
   125 //  CProtocolInfo::ParseAtomToDelimeter(TLex8& aLexeme, TChar aDelimeter)
       
   126 //  It marks a string placed between start position and aDelimeter
       
   127 //-----------------------------------------------------------------
       
   128 void CUpnpProtocolInfo::ParseAtomToDelimeter(TLex8& aLexeme, TChar aDelimeter)
       
   129     {
       
   130     aLexeme.Mark(); 
       
   131     while( ( aLexeme.Peek() != aDelimeter ) && ( !aLexeme.Eos() ) )
       
   132         {
       
   133         aLexeme.Inc();        
       
   134         }
       
   135     }
       
   136 
       
   137 //-----------------------------------------------------------------
       
   138 //  CProtocolInfo::SetParameterL(TInt aWhich, TDesC8& aValue)    
       
   139 //  Sets protcolInfo parameters in object.
       
   140 //-----------------------------------------------------------------
       
   141 void CUpnpProtocolInfo::SetParameterL(TInt aWhich, const TDesC8& aValue)    
       
   142     {
       
   143     switch ( aWhich )
       
   144         {
       
   145         case 0: // FIrst parameter.
       
   146             SetFirstFieldL(aValue);
       
   147             break;
       
   148         case 1: //Second parameter
       
   149             SetSecondFieldL(aValue);
       
   150             break; 
       
   151         case 2: // third parameter. 
       
   152             SetThirdFieldL(aValue);
       
   153             break;
       
   154         case 3: // fourth parameter. 
       
   155             SetFourthFieldL(aValue);
       
   156             break;
       
   157         default: 
       
   158             User::Leave(KErrTooBig);
       
   159         }
       
   160     }
       
   161         
       
   162 //-----------------------------------------------------------------
       
   163 //  CProtocolInfo::SkipAndMark(TLex8& aLexer, TInt aValue)
       
   164 //  Skips aValue characters and marks after end of skipping.
       
   165 //-----------------------------------------------------------------
       
   166 void CUpnpProtocolInfo::SkipAndMark(TLex8& aLexer, TInt aValue)
       
   167     {
       
   168     if (!aLexer.Eos())
       
   169         {
       
   170         aLexer.SkipAndMark(aValue);
       
   171         }
       
   172     }
       
   173 
       
   174 //-----------------------------------------------------------------
       
   175 //  CProtocolInfo::Skip(TLex8& aLexer, TInt aValue)
       
   176 //  Skips aValue characters. Do not mark
       
   177 //-----------------------------------------------------------------
       
   178 void CUpnpProtocolInfo::Skip(TLex8& aLexer, TInt aValue)
       
   179     {
       
   180     if (!aLexer.Eos())
       
   181         {
       
   182         aLexer.Inc(aValue);
       
   183         }
       
   184     }    
       
   185         
       
   186 //-----------------------------------------------------------------
       
   187 //  CProtocolInfo::CheckBooleanValue()
       
   188 //  Check if character contains correct value for boolean type (1 or 0)
       
   189 //-----------------------------------------------------------------     
       
   190 TInt CUpnpProtocolInfo::CheckBooleanValue(TChar aCharacter)
       
   191     {
       
   192     if (aCharacter == '0' || 
       
   193         aCharacter == '1')
       
   194         return KErrNone;
       
   195     else
       
   196         return KErrArgument;
       
   197     }
       
   198 
       
   199 //-----------------------------------------------------------------
       
   200 // CProtocolInfo::GetProtocolInfoLength()
       
   201 // Returns the length of the string currently stored in the class.
       
   202 //-----------------------------------------------------------------
       
   203 TInt CUpnpProtocolInfo::GetProtocolInfoLength()
       
   204     {
       
   205     TInt result = 0; 
       
   206     result += FirstField().Length();
       
   207     result++;
       
   208     result += SecondField().Length();
       
   209     result++; 
       
   210     result += ThirdField().Length(); 
       
   211     result++; 
       
   212     result += GetFourthParameterLength();
       
   213     return result; 
       
   214     }
       
   215 
       
   216 //// PUBLIC ACCESS METHODS EXPORTED INTERFACE    
       
   217 //-----------------------------------------------------------------
       
   218 //  CProtocolInfo::GetProtocolInfoL()
       
   219 //  Getter for pointer to ProtocolInfo
       
   220 //-----------------------------------------------------------------
       
   221 EXPORT_C TPtrC8 CUpnpProtocolInfo::ProtocolInfoL()
       
   222     {
       
   223     const TInt size = GetProtocolInfoLength();
       
   224     HBufC8* buffer = HBufC8::NewL(size);
       
   225     CleanupStack::PushL( buffer );
       
   226     TPtr8 bufPtr(buffer->Des());
       
   227     bufPtr.Append(FirstField());
       
   228     bufPtr.Append(KProtocolInfoDelimeter);
       
   229     bufPtr.Append(SecondField());
       
   230     bufPtr.Append(KProtocolInfoDelimeter);
       
   231     bufPtr.Append(ThirdField());
       
   232     bufPtr.Append(KProtocolInfoDelimeter);
       
   233     GetFourthParameterInternalL(bufPtr);
       
   234     if ( iProtocolInfo ) 
       
   235         {
       
   236         delete iProtocolInfo;
       
   237         iProtocolInfo = NULL;            
       
   238         }
       
   239     iProtocolInfo = bufPtr.Alloc();
       
   240     CleanupStack::PopAndDestroy( buffer );
       
   241     return iProtocolInfo->Des();    
       
   242     }
       
   243 
       
   244 //-----------------------------------------------------------------
       
   245 //  CProtocolInfo::GetFirstField()
       
   246 //  Getter for pointer to first parameter.
       
   247 //-----------------------------------------------------------------
       
   248 EXPORT_C TPtrC8 CUpnpProtocolInfo::FirstField()
       
   249     {
       
   250     if ( iFirstParameter )
       
   251         {
       
   252         return iFirstParameter->Des(); 
       
   253         }
       
   254     else
       
   255         {
       
   256         return KNullDesC8();
       
   257         }
       
   258     }
       
   259     
       
   260 //-----------------------------------------------------------------
       
   261 //  CProtocolInfo::SetFirstFieldL(TDesC8& aValue)
       
   262 //  Setter for first parameter.
       
   263 //-----------------------------------------------------------------
       
   264 EXPORT_C void CUpnpProtocolInfo::SetFirstFieldL(const TDesC8& aValue)
       
   265     {
       
   266     if ( aValue == KNullDesC8 )
       
   267         {
       
   268         return; 
       
   269         }
       
   270     if ( iFirstParameter )
       
   271         {
       
   272         delete iFirstParameter; 
       
   273         iFirstParameter = NULL;
       
   274         }
       
   275     iFirstParameter = aValue.AllocL();
       
   276     }
       
   277     
       
   278 //-----------------------------------------------------------------
       
   279 //  CProtocolInfo::GetSecondField()
       
   280 //  Getter for second parameter.
       
   281 //-----------------------------------------------------------------
       
   282 EXPORT_C TPtrC8 CUpnpProtocolInfo::SecondField()
       
   283     {
       
   284     if ( iSecondParameter )
       
   285         {
       
   286         return iSecondParameter->Des(); 
       
   287         }
       
   288     else
       
   289         {
       
   290         return KNullDesC8();
       
   291         }
       
   292     }
       
   293     
       
   294 //-----------------------------------------------------------------
       
   295 // CProtocolInfo::SetSecondFieldL(TDesC8& aValue)
       
   296 //  Setter for second parameter.
       
   297 //-----------------------------------------------------------------
       
   298 EXPORT_C void CUpnpProtocolInfo::SetSecondFieldL(const TDesC8& aValue)
       
   299     {
       
   300     if ( aValue == KNullDesC8 )
       
   301         {
       
   302         return; 
       
   303         }
       
   304     if ( iSecondParameter )
       
   305         {
       
   306         delete iSecondParameter;
       
   307         iSecondParameter = NULL; 
       
   308         }
       
   309     iSecondParameter = aValue.AllocL();
       
   310     }
       
   311     
       
   312 //-----------------------------------------------------------------
       
   313 //  CProtocolInfo::GetThirdField()
       
   314 //  Getter for third parameter.
       
   315 //-----------------------------------------------------------------
       
   316 EXPORT_C TPtrC8 CUpnpProtocolInfo::ThirdField()
       
   317     {
       
   318     if ( iThirdParameter )
       
   319         {
       
   320         return iThirdParameter->Des(); 
       
   321         }
       
   322     else 
       
   323         {
       
   324         return KNullDesC8();
       
   325         }
       
   326     }
       
   327     
       
   328 //-----------------------------------------------------------------
       
   329 //  CProtocolInfo::SetThirdFieldL(TDesC8& aValue)
       
   330 //  Setter for third parameter.
       
   331 //-----------------------------------------------------------------
       
   332 EXPORT_C void CUpnpProtocolInfo::SetThirdFieldL(const TDesC8& aValue)
       
   333     {
       
   334     if ( iThirdParameter )
       
   335         {
       
   336         delete iThirdParameter; 
       
   337         iThirdParameter = NULL;
       
   338         }
       
   339     iThirdParameter = aValue.AllocL();
       
   340 
       
   341     }
       
   342 
       
   343 //-----------------------------------------------------------------
       
   344 //  CProtocolInfo::GetFourthField()
       
   345 //  Getter for fourth parameter.
       
   346 //-----------------------------------------------------------------
       
   347 EXPORT_C TPtrC8 CUpnpProtocolInfo::FourthField()
       
   348     {
       
   349     if ( iFourthParameter )
       
   350         {
       
   351         return iFourthParameter->Des(); 
       
   352         }
       
   353     else 
       
   354         {
       
   355         return KNullDesC8(); 
       
   356         }
       
   357     }
       
   358     
       
   359 //-----------------------------------------------------------------
       
   360 //  CProtocolInfo::SetFourthFieldL(TDesC8& aValue)
       
   361 //  Setter for fourth parameter value.
       
   362 //-----------------------------------------------------------------
       
   363 EXPORT_C void CUpnpProtocolInfo::SetFourthFieldL(const TDesC8& aValue)
       
   364     {
       
   365     if ( iFourthParameter )
       
   366         {
       
   367         delete iFourthParameter; 
       
   368         iFourthParameter = NULL;
       
   369         }
       
   370     iFourthParameter = aValue.AllocL();
       
   371     }
       
   372         
       
   373 //-----------------------------------------------------------------
       
   374 //  CProtocolInfo::GetFourthParameterInternalL
       
   375 //-----------------------------------------------------------------
       
   376 void CUpnpProtocolInfo::GetFourthParameterInternalL(TDes8& aBuffer)
       
   377     {
       
   378     aBuffer.Append(FourthField());        
       
   379     }
       
   380 
       
   381 //end of file