upnp/upnpstack/serviceframework/src/upnpsoapparser.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2007 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:  TUpnpSoapParser
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpsoapparser.h"
       
    20 
       
    21 #include "upnpsoapmessage.h"
       
    22 #include "upnpcontenthandlerscontroller.h"
       
    23 #include "upnpaction.h"
       
    24 #include "upnpsoapliterals.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // C++ constructor
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 TUpnpSoapParser::TUpnpSoapParser(
       
    31     CUpnpContentHandlersController& aParsingController )
       
    32     : iParsingController( aParsingController )
       
    33     {
       
    34     }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CleanupResetAndDestroy
       
    38 // Releases array, and object keapt in it.
       
    39 // Used as method passed to TCleanupItem object.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 LOCAL_C void CleanupResetAndDestroy(TAny* aRPointerArray)
       
    43     {
       
    44     reinterpret_cast<RPointerArray<CUpnpDescriptionProperty>* >(aRPointerArray)
       
    45         ->ResetAndDestroy();
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // TUpnpSoapParser::UpdateActionWithOKResponseL
       
    50 // For internal use. Update all necessary information from a SOAP-message
       
    51 // that should be OK answer (e.g. received by Http 200 OK message).
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void TUpnpSoapParser::UpdateActionWithOKResponseL( CUpnpSoapMessage* aMessage,
       
    55     CUpnpAction* aAction )
       
    56     {
       
    57     if ( NULL == aMessage )
       
    58         {
       
    59         return;
       
    60         }
       
    61     RPointerArray<CUpnpDescriptionProperty> parsedValues;
       
    62     CleanupStack::PushL( TCleanupItem( CleanupResetAndDestroy, &parsedValues ) );
       
    63 
       
    64     UpdateActionL( aMessage, aAction, parsedValues );
       
    65     if ( parsedValues[0]->Name() == KUpnpSoapFault )
       
    66         {
       
    67         UpdateActionFaultL( parsedValues[0], aAction );
       
    68         }
       
    69     else
       
    70         {
       
    71         ProcessActionArgumentsL( parsedValues, aAction );
       
    72         }
       
    73     CleanupStack::PopAndDestroy( &parsedValues );
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // TUpnpSoapParser::UpdateActionWithErrorResponseL
       
    78 // For internal use. Update all necessary information from a SOAP-message
       
    79 // that should contain SOAP error (fault) message (eg. received by http
       
    80 // 500 InternalServerError message.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void TUpnpSoapParser::UpdateActionWithErrorResponseL(
       
    84     CUpnpSoapMessage* aMessage, CUpnpAction* aAction )
       
    85     {
       
    86     if ( NULL == aMessage )
       
    87         {
       
    88         return;
       
    89         }
       
    90     RPointerArray<CUpnpDescriptionProperty> parsedValues;
       
    91     CleanupStack::PushL( TCleanupItem( CleanupResetAndDestroy, &parsedValues ) );
       
    92 
       
    93     UpdateActionL( aMessage, aAction, parsedValues );
       
    94     if ( parsedValues[0]->Name() == KUpnpSoapFault )
       
    95         {
       
    96         UpdateActionFaultL( parsedValues[0], aAction );
       
    97         }
       
    98     else
       
    99         {
       
   100         User::Leave( KErrArgument );
       
   101         }
       
   102     CleanupStack::PopAndDestroy( &parsedValues );
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // TUpnpSoapParser::UpdateActionWithRequestL
       
   107 // Update action with all necessary information from
       
   108 // a SOAP request message.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void TUpnpSoapParser::UpdateActionWithRequestL(
       
   112     CUpnpSoapMessage* aMessage, CUpnpAction* aAction )
       
   113     {
       
   114     if ( NULL == aMessage )
       
   115         {
       
   116         return;
       
   117         }
       
   118     RPointerArray<CUpnpDescriptionProperty> parsedArguments;
       
   119     CleanupStack::PushL( TCleanupItem( CleanupResetAndDestroy, &parsedArguments ) );
       
   120 
       
   121     UpdateActionL( aMessage, aAction, parsedArguments );
       
   122     ProcessActionArgumentsL( parsedArguments, aAction );
       
   123     CleanupStack::PopAndDestroy( &parsedArguments );
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // TUpnpSoapParser::UpdateActionL
       
   128 // Common code used by 3 particular soap update action methods methods
       
   129 // @post if there were no leave aParsedValues has at least 1 object within
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void TUpnpSoapParser::UpdateActionL( CUpnpSoapMessage* aMessage,
       
   133     CUpnpAction* aAction, RPointerArray<CUpnpDescriptionProperty>& aParsedValues )
       
   134     {
       
   135     aAction->SetSender( aMessage->Sender() );
       
   136     aAction->SetLocal( aMessage->Local() );
       
   137     aAction->SetSessionId( aMessage->SessionId() );
       
   138 
       
   139     iParsingController.ParseSoapL( aMessage->Body(), aParsedValues );
       
   140     if ( aParsedValues.Count() == 0 )    //error of parsing, nothing retrieved
       
   141         {
       
   142         User::Leave( KErrArgument );
       
   143         }
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // TUpnpSoapParser::ProcessActionArgumentsL
       
   148 // Process parsed description property, and the rest of parsed properties
       
   149 // and update action arguments with them.
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void TUpnpSoapParser::ProcessActionArgumentsL(
       
   153     RPointerArray<CUpnpDescriptionProperty>& aProperties, CUpnpAction* aAction )
       
   154     {
       
   155     TRAPD( err, UpdateActionArgumentsL( aProperties, aAction ) );
       
   156     if( KErrNone != err )
       
   157         {
       
   158         if ( EInvalidArgs == err )
       
   159             {
       
   160             User::Leave( KErrArgument );
       
   161             }
       
   162         }
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // TUpnpSoapParser::UpdateActionArgumentsL
       
   167 // Update all action arguments with previously parsed properties.
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void TUpnpSoapParser::UpdateActionArgumentsL(
       
   171     RPointerArray<CUpnpDescriptionProperty>& aProperties, CUpnpAction* aAction )
       
   172     {
       
   173     aAction->SetError( EHttpOk );
       
   174     for ( TInt i(1); i < aProperties.Count(); ++i )
       
   175         {
       
   176         CUpnpDescriptionProperty* property = aProperties[i];
       
   177         aAction->SetArgumentL( property->Name(), property->Value() );
       
   178         }
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // TUpnpSoapParser::UpdateActionFaultL
       
   183 // Update action error value from parsed description property
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 void TUpnpSoapParser::UpdateActionFaultL(
       
   187     CUpnpDescriptionProperty* aProperty, CUpnpAction* aAction )
       
   188     {
       
   189     TLex8 code( aProperty->Value() );
       
   190     TInt errNumber( aAction->Error() );
       
   191     TInt parseErr = code.Val( errNumber );
       
   192     aAction->SetError( errNumber );
       
   193     User::LeaveIfError( parseErr );
       
   194     }
       
   195 
       
   196 //  End of File