upnp/upnpstack/serviceframework/src/upnpbodyofsoapcontenthandler.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:  Implements the CUpnpBodyOfSoapContentHandler class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpbodyofsoapcontenthandler.h"
       
    20 #include "upnpcontenthandlerscontroller.h"
       
    21 #include "upnpsoapliterals.h"
       
    22 #include "upnpsingletagcontenthandler.h"
       
    23 #include "upnperrorcodeseekercontenthandler.h"
       
    24 #include "upnpdescriptionproperty.h"
       
    25 
       
    26 _LIT8( KUpnpActionName, "ActionName" );
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CUpnpBodyOfSoapContentHandler::NewL
       
    30 // Two-phased constructor
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CUpnpBodyOfSoapContentHandler* CUpnpBodyOfSoapContentHandler::NewL(
       
    34     CUpnpContentHandlersController& aController,
       
    35     RPointerArray<CUpnpDescriptionProperty>& aResultSetOfArguments )
       
    36     {
       
    37     CUpnpBodyOfSoapContentHandler* soapContentHandler =
       
    38         CUpnpBodyOfSoapContentHandler::NewLC( aController, aResultSetOfArguments );
       
    39     CleanupStack::Pop( soapContentHandler );
       
    40     return soapContentHandler;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CUpnpBodyOfSoapContentHandler::NewLC
       
    45 // Two-phased constructor. Leaves teh object on the CleanupStack
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CUpnpBodyOfSoapContentHandler* CUpnpBodyOfSoapContentHandler::NewLC(
       
    49     CUpnpContentHandlersController& aController,
       
    50     RPointerArray<CUpnpDescriptionProperty>& aResultSetOfArguments)
       
    51     {
       
    52     CUpnpBodyOfSoapContentHandler* soapContentHandler =
       
    53         new (ELeave) CUpnpBodyOfSoapContentHandler( aController, aResultSetOfArguments );
       
    54     CleanupStack::PushL( soapContentHandler );
       
    55     soapContentHandler->ConstructL();
       
    56     return soapContentHandler;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CUpnpBodyOfSoapContentHandler::~CUpnpBodyOfSoapContentHandler
       
    61 // Destructor of CUpnpBodyOfSoapContentHandler class
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CUpnpBodyOfSoapContentHandler::~CUpnpBodyOfSoapContentHandler()
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CUpnpBodyOfSoapContentHandler::CUpnpBodyOfSoapContentHandler
       
    70 // Constructor
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CUpnpBodyOfSoapContentHandler::CUpnpBodyOfSoapContentHandler(
       
    74     CUpnpContentHandlersController& aController,
       
    75                 RPointerArray<CUpnpDescriptionProperty>& aResultSetOfArguments) :
       
    76     CUpnpPropertysetContentHandler( aController, aResultSetOfArguments )
       
    77     {
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CUpnpBodyOfSoapContentHandler::ConstructL
       
    82 // Second phase constructor
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CUpnpBodyOfSoapContentHandler::ConstructL()
       
    86     {
       
    87     CUpnpPropertysetContentHandler::ConstructL();
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CUpnpBodyOfSoapContentHandler::OnStartElementL
       
    92 // This method is a callback to indicate an element has been parsed.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CUpnpBodyOfSoapContentHandler::OnStartElementL(
       
    96     const RTagInfo& aElement, const RAttributeArray& /*aAttributes*/)
       
    97     {
       
    98     const TDesC8& elementName( aElement.LocalName().DesC() );
       
    99 
       
   100     if ( iIsInsideOfAction )
       
   101         {
       
   102         if ( InsideOfArgument() )   
       
   103             {
       
   104             SetIgnoreHandlerL();
       
   105             }
       
   106         else
       
   107             {
       
   108             CUpnpSingleTagContentHandler::SafeCopyL( iCurrentPropertyKey,
       
   109                 elementName);
       
   110             }
       
   111         }
       
   112     else
       
   113         {
       
   114         if ( elementName == KUpnpSoapFault ) 
       
   115             {
       
   116             iResultPropertyset.ResetAndDestroy();
       
   117             iCurrentPropertyKey = KUpnpSoapFault;
       
   118             iController.SetCurrentContentHandlerL(
       
   119                 CUpnpErrorCodeSeekerContentHandler::NewL( iController, iCurrentPropertyValue )
       
   120             );
       
   121             }
       
   122         else
       
   123             {
       
   124             //we're assuming that now is 'actionName'/'actionName'Response tag
       
   125             //we're also ignoring namespaces
       
   126             //these both things could be changed if we want to have stricter parser
       
   127             StoreCurrentPropertyL();
       
   128             iCurrentPropertyKey = KUpnpActionName;
       
   129             CUpnpSingleTagContentHandler::SafeCopyL( iCurrentPropertyValue, elementName );
       
   130             StoreCurrentPropertyL();
       
   131             iIsInsideOfAction = ETrue;
       
   132             }
       
   133         }
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CUpnpBodyOfSoapContentHandler::OnEndElementL
       
   138 // This method is a callback to indicate the end of the element has been reached.
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CUpnpBodyOfSoapContentHandler::OnEndElementL( const RTagInfo& /*aElement*/ )
       
   142     {
       
   143     if ( iIsInsideOfAction )
       
   144         {
       
   145         if ( !InsideOfArgument() )
       
   146             {
       
   147             iIsInsideOfAction = EFalse;
       
   148             }
       
   149         StoreCurrentPropertyL();
       
   150         }
       
   151     else
       
   152         {
       
   153         StoreCurrentPropertyL();
       
   154         iController.SetPreviousContentHandler();
       
   155         }
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CUpnpBodyOfSoapContentHandler::OnContentL
       
   160 // This method is a callback that sends the content of the element.
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CUpnpBodyOfSoapContentHandler::OnContentL( const TDesC8& aBytes)
       
   164     {
       
   165     if ( iIsInsideOfAction && InsideOfArgument() )
       
   166         {
       
   167         CUpnpSingleTagContentHandler::SafeCopyL( iCurrentPropertyValue, aBytes );
       
   168         }
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CUpnpBodyOfSoapContentHandler::InterestedInAllNamespaces
       
   173 // We are interested in tags from all possible namespaces
       
   174 // Specific namespace we can check in event callback functions (On...Element)
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TBool CUpnpBodyOfSoapContentHandler::InterestedInAllNamespaces()
       
   178     {
       
   179     return ETrue;
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CUpnpBodyOfSoapContentHandler::InsideOfArgument
       
   184 // Returns true if content handler is in inside argument state
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 TBool CUpnpBodyOfSoapContentHandler::InsideOfArgument()
       
   188     {
       
   189     return (iCurrentPropertyKey.Length() > 0);
       
   190     }
       
   191 
       
   192 //  End of File