pnpmobileservices/pnpms/PnP/NHwrParser/HttpProvHeaders.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2007-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: Implementation of PnPMS components
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "HttpProvHeaders.h"
       
    20 #include "NHwrParserLogger.h"
       
    21 
       
    22 
       
    23 CHttpProvHeaders* CHttpProvHeaders::NewL( const TDesC8& aHeaders )
       
    24     {
       
    25     CHttpProvHeaders* self = NewLC( aHeaders );
       
    26     CleanupStack::Pop(self);
       
    27     return self;
       
    28     }
       
    29 
       
    30     
       
    31 CHttpProvHeaders* CHttpProvHeaders::NewLC( const TDesC8& aHeaders )
       
    32     {
       
    33     CHttpProvHeaders* self = new (ELeave) CHttpProvHeaders();
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL( aHeaders );
       
    36     return self;
       
    37     }
       
    38 
       
    39 
       
    40 CHttpProvHeaders::CHttpProvHeaders() :
       
    41     iReportUrl( KNullDesC8 ),
       
    42     iSignatureValue( KNullDesC8 ),
       
    43     iDigestValue( KNullDesC8 ),
       
    44     iProvisioningActivation( KNullDesC8 ),
       
    45     iUserInteraction( KNullDesC8 )
       
    46     {
       
    47     }
       
    48 
       
    49 
       
    50 CHttpProvHeaders::~CHttpProvHeaders()
       
    51     {
       
    52     LOGSTRING( "~CHttpProvHeaders - done" );
       
    53     }
       
    54 
       
    55 
       
    56 void CHttpProvHeaders::ConstructL( const TDesC8& aHeaders )
       
    57     {
       
    58     ParseL( aHeaders );
       
    59     }
       
    60 
       
    61 void CHttpProvHeaders::ParseL( const TDesC8& aHeaders  )
       
    62     {
       
    63     LOGSTRING( "CHttpProvHeaders::ParseL" );
       
    64     TPtrC8 work( aHeaders );
       
    65     TPtrC8 line( aHeaders );
       
    66     TInt nextLinePos = 0;
       
    67     TBool firstLine = ETrue;
       
    68 
       
    69     TInt err;
       
    70     FOREVER
       
    71         {
       
    72         TRAP( err, GetLineL(work, line, nextLinePos) );
       
    73         LOGSTRING2( "got line with len:%i", line.Length() );
       
    74         if( err == KErrNotFound )
       
    75             {
       
    76             // if thre is a single line in the headers it currently does not end with CRLF
       
    77             //   as COULD be assumed from the specs
       
    78             //   so continue to the length check...
       
    79             if( !firstLine )
       
    80                 {
       
    81                 break;
       
    82                 }
       
    83             firstLine = EFalse;
       
    84             }
       
    85         if( line.Length() == 0 )
       
    86             {
       
    87             break;
       
    88             }
       
    89 
       
    90         LOGSTRING( "line:" );
       
    91         LOGTEXT( line );
       
    92 
       
    93         HandleHeaderLineL( line );
       
    94             
       
    95         if( nextLinePos == KErrNotFound )
       
    96             {
       
    97             break;
       
    98             }
       
    99         LOGSTRING( "work.Set( work.Mid(nextLinePos) )" );
       
   100 LOGSTRING2( "nextLinePos: %i", nextLinePos );
       
   101         work.Set( work.Mid(nextLinePos) );
       
   102         }
       
   103 LOGSTRING( "end" );
       
   104     }
       
   105 
       
   106 void CHttpProvHeaders::GetLineL( const TDesC8& aBuffer, TPtrC8& aLine, TInt& aNextLinePos )
       
   107     {
       
   108 LOGSTRING("*1");
       
   109     TInt newlinePos = aBuffer.Locate( '\n' );
       
   110     if( newlinePos == KErrNotFound )
       
   111         {
       
   112 LOGSTRING("*2");
       
   113         aNextLinePos = KErrNotFound;
       
   114         if( aBuffer.Length() )
       
   115             aLine.Set( aBuffer );
       
   116         User::Leave( KErrNotFound );
       
   117         }
       
   118     if( aBuffer.Length() > (newlinePos+1) )
       
   119         {    
       
   120 LOGSTRING("*3");
       
   121         aNextLinePos = newlinePos + 1;
       
   122         }
       
   123     else
       
   124         {
       
   125 LOGSTRING("*4");
       
   126         aNextLinePos = KErrNotFound;
       
   127         }
       
   128     if( newlinePos > 0 ) // 
       
   129         {
       
   130 LOGSTRING("*5");
       
   131         if( aBuffer[newlinePos-1] == '\r' )
       
   132             {
       
   133             LOGSTRING( "aLine.Set( aBuffer.Left(newlinePos-1) )" );
       
   134             aLine.Set( aBuffer.Left(newlinePos-1) );
       
   135             return;
       
   136             }
       
   137         }
       
   138     LOGSTRING( "aLine.Set( aBuffer.Left(newlinePos) )" );
       
   139     aLine.Set( aBuffer.Left(newlinePos) );
       
   140     }
       
   141 
       
   142 void CHttpProvHeaders::HandleHeaderLineL( const TDesC8& aLine )
       
   143     {
       
   144     LOGSTRING( "HandleHeaderLineL" );
       
   145 
       
   146     TBuf8<1> empty;
       
   147     TPtrC8 left( empty );
       
   148     TPtrC8 right( empty );
       
   149 
       
   150     LOGSTRING( "splitting" );    
       
   151     SplitLineL(aLine, ':', left, right );
       
   152     
       
   153     LOGSTRING( "left:" );
       
   154     LOGTEXT( left );
       
   155     LOGSTRING( "right:" );
       
   156     LOGTEXT( right );
       
   157 
       
   158     while( left[left.Length()-1] == ' ' )
       
   159         {
       
   160         left.Set( left.Left(left.Length()-1) );
       
   161         }
       
   162         
       
   163     if( right.Length() > 1 )
       
   164         {
       
   165         right.Set( right.Mid(0) ); // no space in this spec
       
   166         }
       
   167     SetParamL( left, right );
       
   168     }
       
   169 
       
   170 void CHttpProvHeaders::SetParamL( const TDesC8& aName, const TPtrC8& aVal )
       
   171     {
       
   172     LOGSTRING( "SetParamL" );
       
   173     LOGSTRING( "aName:" );
       
   174     LOGTEXT( aName );
       
   175     LOGSTRING( "aVal:" );
       
   176     LOGTEXT( aVal );
       
   177 
       
   178     if( aName.Compare( KReportUrl ) == 0 ) 
       
   179         iReportUrl.Set( aVal );
       
   180     else if( aName.Compare( KSignatureValue ) == 0 ) 
       
   181         iSignatureValue.Set( aVal );
       
   182     else if( aName.Compare( KDigestValue ) == 0 )
       
   183         iDigestValue.Set( aVal );
       
   184     else if( aName.Compare( KProvisioningActivation ) == 0 )
       
   185         iProvisioningActivation.Set( aVal );
       
   186     else if( aName.Compare( KUserInteraction ) == 0 )
       
   187         iUserInteraction.Set( aVal );
       
   188     }
       
   189 
       
   190 const TDesC8& CHttpProvHeaders::GetParamValL( const TDesC8& aName ) const
       
   191     {
       
   192     LOGSTRING( "GetParamValL" );
       
   193     if( aName.Compare( KReportUrl ) == 0 ) 
       
   194         {
       
   195         if( iReportUrl.Length() == 0 ) User::Leave( KErrNotFound );
       
   196         return( iReportUrl);
       
   197         }
       
   198     else if( aName.Compare( KSignatureValue ) == 0 ) 
       
   199         {
       
   200         if( iSignatureValue.Length() == 0 ) User::Leave( KErrNotFound );
       
   201         return iSignatureValue;
       
   202         }
       
   203     else if( aName.Compare( KDigestValue ) == 0 )
       
   204         {
       
   205         if( iDigestValue.Length() == 0 ) User::Leave( KErrNotFound );
       
   206         return iDigestValue;
       
   207         }
       
   208     else if( aName.Compare( KProvisioningActivation ) == 0 )
       
   209         {
       
   210         LOGTEXT( KProvisioningActivation );
       
   211         if( iProvisioningActivation.Length() == 0 ) User::Leave( KErrNotFound );
       
   212         LOGTEXT( iProvisioningActivation );
       
   213         return iProvisioningActivation;
       
   214         }
       
   215     else if( aName.Compare( KUserInteraction ) == 0 )
       
   216         {
       
   217         LOGTEXT( KUserInteraction );
       
   218         if( iUserInteraction.Length() == 0 ) User::Leave( KErrNotFound );
       
   219         return iUserInteraction;
       
   220         }
       
   221     else 
       
   222         {
       
   223         LOGSTRING( "GetParamValL error" );
       
   224         return KNullDesC8;
       
   225         }
       
   226     }
       
   227 
       
   228 void CHttpProvHeaders::SplitLineL( const TDesC8& aLine, TChar aSplitBy, TPtrC8& aLeft, TPtrC8& aRight )
       
   229     {
       
   230     TInt splitIdx = aLine.Locate( aSplitBy );
       
   231     if( splitIdx == KErrNotFound )
       
   232         {
       
   233         User::Leave( splitIdx );
       
   234         }
       
   235     aLeft.Set( aLine.Left(splitIdx) );
       
   236     if( aLine.Length() >= splitIdx+2 )
       
   237         {
       
   238         aRight.Set( aLine.Mid(splitIdx+1) );
       
   239         }
       
   240     }