xdmprotocols/XcapProtocol/XcapAppUsage/inc/XcapAppUsage.h
branchRCL_3
changeset 35 fbd2e7cec7ef
parent 0 c8caa15ef882
child 12 e6a66db4e9d0
equal deleted inserted replaced
34:2669f8761a99 35:fbd2e7cec7ef
       
     1 /*
       
     2 * Copyright (c) 2005 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:  CXcapAppUsage
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __XCAPAPPUSAGE__
       
    22 #define __XCAPAPPUSAGE__
       
    23 
       
    24 // INCLUDES
       
    25 #include <ecom.h>
       
    26 
       
    27 #include <XdmEngine.h>
       
    28 #include <XdmProtocolUidList.h>
       
    29 #include "XcapAppUsageDef.h"
       
    30 
       
    31 // CONSTANTS
       
    32 #ifdef _DEBUG
       
    33 _LIT( KXdmAppUsageLogDir,                          "Xdm" );
       
    34 _LIT( KXdmAppUsageLogFile,                         "XcapAppUsage.txt" );
       
    35 const TInt KAppUsageLogBufferMaxSize                = 2000;
       
    36 #endif
       
    37 
       
    38 _LIT( KXdmDefaultNsAttrName, "xmlns");
       
    39 _LIT( KXdmNonDefaultNsAttrName, "xmlns:");
       
    40 const TInt KXdmMaxPrefixLength = 10;
       
    41 
       
    42 // FORWARD DECLARATIONS
       
    43 class CXdmDocument;
       
    44 class MXcapUriInterface;
       
    45 
       
    46 // NOTE
       
    47 // If _NAMESPACES_TO_NODE_SELECTOR flag is defined, used namespaces will be added to the node selector
       
    48 // when updating partial documents.
       
    49 // The default namespace of the usage will not be added.
       
    50 #define _NAMESPACES_TO_NODE_SELECTOR
       
    51 
       
    52 // If _ADD_NAMESPACE_ATTRIBUTES flag is defined, namespace information is
       
    53 // added as an node atttribute when updating partial documents.
       
    54 // The default namespace of the usage will not be added.
       
    55 #define _ADD_NAMESPACE_ATTRIBUTES
       
    56 
       
    57 /**
       
    58 * A helper class for  parameter passing from
       
    59 * the XCAP protocol to the application usage
       
    60 *
       
    61 * NOTE: There will most probably be more than one parameter!
       
    62 *
       
    63 */
       
    64 class TXcapAppUsageParams
       
    65     {
       
    66     public:
       
    67         
       
    68         /**
       
    69         * @param CXdmEngine& XDM Engine
       
    70         * @return TXcapAppUsageParams
       
    71         */
       
    72         TXcapAppUsageParams( const CXdmEngine& aXdmEngine ) :
       
    73                              iXdmEngine( aXdmEngine ){}
       
    74     
       
    75     public:
       
    76     
       
    77         const CXdmEngine&    iXdmEngine;
       
    78     };
       
    79 
       
    80 // CLASS DECLARATION
       
    81 /**
       
    82 * Application usage base class
       
    83 */
       
    84 class CXcapAppUsage : public CBase
       
    85     {
       
    86     public:
       
    87 
       
    88         /**
       
    89         * Symbian OS constructor
       
    90         * @param aXdmEngine XdmEngine reference
       
    91         * @param aDocumentType Type of the document
       
    92         * @return CXcapAppUsage*
       
    93         * REMOVE THIS WHEN USAGE IN ENGINE CHANGED!!!
       
    94         */
       
    95         static CXcapAppUsage* NewL( const CXdmEngine& aXdmEngine,
       
    96                                     const TXdmDocType aDocumentType );
       
    97                                     
       
    98         /**
       
    99         * Symbian OS constructor
       
   100         * @param aXdmEngine XdmEngine reference
       
   101         * @param aDocumentType Type of the document
       
   102         * @return CXcapAppUsage*
       
   103         */
       
   104         IMPORT_C CXcapAppUsage* NewL( const CXdmEngine& aXdmEngine,
       
   105                                     const TInt aDocumentType );
       
   106         
       
   107         /**
       
   108         * Destructor
       
   109         */
       
   110         virtual ~CXcapAppUsage();
       
   111     
       
   112         /**
       
   113         * Validate the document in the parameter.
       
   114         * Calls ValidateNodeL( aXdmNode ) method from derived class
       
   115         * for each node in document and ValidateAttributeL( aXdmNodeAttr )
       
   116         * for each attribute in document. If the document is outgoing, 
       
   117         * calls also AddNamespaceInformationL method from derived class.
       
   118         * @param aXdmDocument document reference
       
   119         * @param aAddNamespaces if true, the namespaces will be added
       
   120         * @return KErrNone or error code.
       
   121         */
       
   122         IMPORT_C TInt Validate( CXdmDocument& aXdmDocument, TBool aAddNamespaces ) ;
       
   123                                  
       
   124         /**
       
   125         * Validate the node in the parameter.
       
   126         * Calls ValidateNodeL( aXdmNode ) method from derived class for 
       
   127         * current node and it's descendants and ValidateAttributeL( aXdmNodeAttr )
       
   128         * for each attribute. Stores the uri of the node.
       
   129         * @param aXdmNode node reference
       
   130         * @param TBool aIsGetOrDelete indication of http get or delete
       
   131         * @return KErrNone or error code.
       
   132         */
       
   133         IMPORT_C TInt Validate( CXdmDocumentNode& aXdmNode, 
       
   134                                 MXcapUriInterface* aUriInterface,
       
   135                                 TBool aIsGetOrDelete ) ;
       
   136                                                      
       
   137     
       
   138     
       
   139     public:  // Application Usage API
       
   140         
       
   141         /**
       
   142         * AUID for this usage
       
   143         * @return AUID
       
   144         */
       
   145         virtual TPtrC8 AUID() const = 0;
       
   146            
       
   147         /**
       
   148         * MIME type for this usage
       
   149         * @return MIME type
       
   150         */
       
   151         virtual TPtrC8 ContentType() const = 0;
       
   152         
       
   153         /**
       
   154         * Default namespace for this usage
       
   155         * @return Default namespace definition
       
   156         */
       
   157         virtual TPtrC8 DefaultNamespace() const = 0;
       
   158         
       
   159         /**
       
   160         * Validate the node in the parameter
       
   161         * This method is called by base class for each node
       
   162         * in document, here we have to check element datatype,
       
   163         * restrictions for values and also do all checking that concerns  
       
   164         * the structure of the element. If the datatype is some of
       
   165         * the common datatypes defined in xcapappusage.h, the node
       
   166         * can pe passed to the base class for value validation.
       
   167         * @param CXdmDocumentNode& node reference
       
   168         * @return True, if the node belongs to the current namespace
       
   169         */
       
   170         virtual TBool ValidateNodeL( CXdmDocumentNode& aXdmNode ) = 0;
       
   171         
       
   172         /**
       
   173         * Validate the attribute in the parameter
       
   174         * This method is called by base class for each attribute
       
   175         * in document, here we have to define data types
       
   176         * for attributes, and pass them to the base class
       
   177         * for the actual data checking.
       
   178         * @param aXdmNodeAttr attribute reference
       
   179         */
       
   180         virtual void ValidateAttributeL( const CXdmNodeAttribute& aXdmNodeAttr ) = 0;
       
   181           
       
   182         /**
       
   183         * Add namespaces and namespace prefixes used in document
       
   184         * @param aXdmDocument document reference
       
   185         */
       
   186         virtual void AddNamespaceInformationL( CXdmDocument& aXdmDocument ) = 0;
       
   187                               
       
   188                               
       
   189     protected:
       
   190         
       
   191         /**
       
   192         * C++ constructor
       
   193         */
       
   194         CXcapAppUsage( const CXdmEngine& aXdmEngine );
       
   195     
       
   196         /**
       
   197         * Validates basic data types
       
   198         * @param aDataType type of the data
       
   199         * @param aXdmNode node reference
       
   200         */
       
   201         void ValidateDataL ( TDataType aDataType, CXdmDocumentNode& aXdmNode );
       
   202        
       
   203        /**
       
   204         * Validates basic data types
       
   205         * @param aDataType type of the data
       
   206         * @param aXdmNodeAttr attribute reference
       
   207         */
       
   208         void ValidateDataL ( TDataType aDataType, const CXdmNodeAttribute& aXdmNodeAttr );
       
   209         
       
   210         /**
       
   211         * If outgoing document, adds namespacePrefix 
       
   212         * to the node in parameter
       
   213         * @param aXdmNode node reference
       
   214         * @param aPrefix namespace prefix
       
   215         */
       
   216         void SetPrefixL( CXdmDocumentNode& aXdmNode, const TDesC8& aPrefix );
       
   217         
       
   218         /**
       
   219         * Helper method for string comparison
       
   220         * @param aLeft first string
       
   221         * @param aRight second string
       
   222         * @return ETrue, if the strings are equal
       
   223         */
       
   224         TBool Match( const TDesC& aLeft, const TDesC& aRight );
       
   225         
       
   226         /**
       
   227         * Helper method for string comparison
       
   228         * @param aLeft first string
       
   229         * @param aRight second string
       
   230         * @return ETrue, if the strings are equal
       
   231         */
       
   232         TBool Match( const TDesC8& aLeft, const TDesC8& aRight );
       
   233         
       
   234         /**
       
   235         * To be used when an error occurs, however if the node is
       
   236         * for http get or delete request, this do not leave
       
   237         * @param aErrorCode function will leave with this error code
       
   238         */
       
   239         void LeaveWithErrorL( TInt aErrorCode );
       
   240         
       
   241 #ifdef _DEBUG        
       
   242         /**
       
   243         * Writes logs to file.
       
   244         */
       
   245         void WriteToLog( TRefByValue<const TDesC8> aFmt,... );
       
   246 #endif
       
   247     
       
   248     private:
       
   249         
       
   250         /**
       
   251         * Validate the document in the parameter.
       
   252         * @param aXdmDocument document reference
       
   253         */
       
   254         void DoValidateL( CXdmDocument& aXdmDocument ) ;
       
   255         
       
   256         /**
       
   257         * Validate the node in the parameter. 
       
   258         * @param aXdmNode node reference
       
   259         */
       
   260         void DoValidateL( CXdmDocumentNode& aXdmNode ) ;
       
   261         
       
   262         /**
       
   263         * Validates basic data types
       
   264         * @param aDataType type of the data
       
   265         * @param aData validated data
       
   266         */
       
   267         void ValidateDataL ( TDataType aDataType, TDesC8& aData );
       
   268         
       
   269         /**
       
   270         * Updates member variables for used namespaces
       
   271         * @param aPrefix prefix of the namespace
       
   272         */        
       
   273         void AddUsedNamespace( const TDesC8& aPrefix ) ;
       
   274 
       
   275         /**
       
   276         * Resets member variables for used namespaces
       
   277         */
       
   278         void ResetUsedNamespaces( ); 
       
   279         
       
   280         /**
       
   281         * Appends namespace information to the node's uri interface. 
       
   282         * Called if _NAMESPACES_TO_NODE_SELECTOR defined.
       
   283         * @param aUriInterface interface for storing the uri
       
   284         */
       
   285         void AppendUsedNamespacesL( MXcapUriInterface* aUriInterface ); 
       
   286         
       
   287         /**
       
   288         * Creates namespace attribute for the node. 
       
   289         * Called if _ADD_NAMESPACE_ATTRIBUTES is defined
       
   290         * and validating partial document.
       
   291         * @param aXdmNode node for storing the uri
       
   292         */
       
   293         void CreateNamespaceAttributesL( CXdmDocumentNode& aXdmNode, MXcapUriInterface* aUriInterface );
       
   294            
       
   295         /**
       
   296         * Removes namespace attributes from the node
       
   297         * and it's child nodes
       
   298         * @param aXdmNode 
       
   299         */
       
   300         void RemoveNamespaceAttributesL( CXdmDocumentNode& aXdmNode ); 
       
   301         
       
   302         /**
       
   303         * Adds namespace attributes that are used in 
       
   304         * partial document
       
   305         * @param aXdmNode 
       
   306         */
       
   307         void AppendNamespaceAttributesL( CXdmDocumentNode& aXdmNode ) ;
       
   308         
       
   309         /**
       
   310         * Creates namespace attribute for node
       
   311         * @param aXdmNode 
       
   312         * @param aPrefix prefix of the namespace
       
   313         * @param aNamespace namespace definition
       
   314         */
       
   315         void CreateNamespaceAttributeL( CXdmDocumentNode& aXdmNode, const TDesC8& aPrefix, const TDesC8& aNamespace );
       
   316         
       
   317         
       
   318         /**
       
   319         * Goes through all nodes and checks if 
       
   320         * default namespace is used in document fragment
       
   321         * the namespace given in parameter
       
   322         * @param aXdmNode 
       
   323         * @return ETrue or EFalse
       
   324         */
       
   325         TBool DefaultNamespaceUsed( CXdmDocumentNode& aXdmNode );
       
   326         
       
   327     protected:  // Data
       
   328     
       
   329         CXdmEngine&                 iXdmEngine;
       
   330        
       
   331     private:  // Data
       
   332     
       
   333         TBool                       iAddNamespaces;
       
   334         TBool                       iNsToNodeSelector;
       
   335         TBool                       iAddNsAttributes;
       
   336         TBool                       iIsGetOrDelete;
       
   337         TUid                        iDestructorKey;
       
   338 		// Variables for used namespaces
       
   339 		// Add new one here if needed
       
   340         TBool iRL;
       
   341         TBool iCR;
       
   342         TBool iCP ;
       
   343         TBool iPR;
       
   344         TBool iLS;
       
   345         TBool iPOC;
       
   346         TBool iOPR;
       
   347         TBool iRLS;
       
   348         TBool iOU;
       
   349     // add new prefix definitions here 
       
   350 
       
   351 
       
   352     };
       
   353 
       
   354 
       
   355 // ----------------------------------------------------
       
   356 // CXcapAppUsage::NewL
       
   357 // Create a new application usage implementation
       
   358 // REMOVE THIS WHEN USAGE IN ENGINE CHANGED!!!
       
   359 // ----------------------------------------------------
       
   360 //
       
   361 inline CXcapAppUsage* CXcapAppUsage::NewL( const CXdmEngine& aXdmEngine,
       
   362                                            const TXdmDocType aDocumentType )
       
   363     {
       
   364     TAny* ptr = NULL;
       
   365     TXcapAppUsageParams params( aXdmEngine );
       
   366     switch( aDocumentType )
       
   367         {
       
   368         case EXdmCapabilities:
       
   369             {
       
   370             TUid KDefaultImplementationUid = { 0x10207418 };
       
   371             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   372                    KDefaultImplementationUid,
       
   373                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   374                    ( TAny* )&params ) );
       
   375             }
       
   376             break;
       
   377         case EXdmDirectory:
       
   378             {
       
   379             TUid KDefaultImplementationUid = { 0x10207419 };
       
   380             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   381                    KDefaultImplementationUid,
       
   382                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   383                    ( TAny* )&params ) );
       
   384             }
       
   385             break;
       
   386         case EXdmTestDocType:
       
   387             {
       
   388             TUid KDefaultImplementationUid = { 0x1020741A };
       
   389             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   390                    KDefaultImplementationUid,
       
   391                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   392                    ( TAny* )&params ) );
       
   393             }
       
   394             break;
       
   395         case EXdmPoCGroup:
       
   396             {
       
   397             TUid KDefaultImplementationUid = { 0x1020741B };
       
   398             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   399                    KDefaultImplementationUid,
       
   400                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   401                    ( TAny* )&params ) );
       
   402             }
       
   403             break;
       
   404         case EXdmPoCUserAccessPolicy:
       
   405             {
       
   406             TUid KDefaultImplementationUid = { 0x1020741C };
       
   407             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   408                    KDefaultImplementationUid,
       
   409                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   410                    ( TAny* )&params ) );
       
   411             }
       
   412             break;
       
   413         case EXdmSharedXdm:
       
   414             {
       
   415             TUid KDefaultImplementationUid = { 0x1020741D };
       
   416             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   417                    KDefaultImplementationUid,
       
   418                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   419                    ( TAny* )&params ) );
       
   420             }
       
   421             break;
       
   422        case EXdmRlsServices:
       
   423             {
       
   424             TUid KDefaultImplementationUid = { 0x1020741E };
       
   425             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   426                    KDefaultImplementationUid,
       
   427                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   428                    ( TAny* )&params ) );
       
   429             }
       
   430             break;
       
   431       case EXdmResourceLists:
       
   432             {
       
   433             TUid KDefaultImplementationUid = { 0x10275080 };
       
   434             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   435                    KDefaultImplementationUid,
       
   436                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   437                    ( TAny* )&params ) );
       
   438             }
       
   439             break;
       
   440       case EXdmIetfCommonPolicy:
       
   441             {
       
   442             TUid KDefaultImplementationUid = { 0x10275081 };
       
   443             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   444                    KDefaultImplementationUid,
       
   445                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   446                    ( TAny* )&params ) );
       
   447             }
       
   448             break;
       
   449       case EXdmOmaCommonPolicy:
       
   450             {
       
   451             TUid KDefaultImplementationUid = { 0x10275082 };
       
   452             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   453                    KDefaultImplementationUid,
       
   454                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   455                    ( TAny* )&params ) );
       
   456             }
       
   457             break;
       
   458       case EXdmIetfPresenceRules:
       
   459             {
       
   460             TUid KDefaultImplementationUid = { 0x10275083 };
       
   461             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   462                    KDefaultImplementationUid,
       
   463                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   464                    ( TAny* )&params ) );
       
   465             }
       
   466             break;
       
   467       case EXdmOmaPresenceRules:
       
   468             {
       
   469             TUid KDefaultImplementationUid = { 0x102750AB };
       
   470             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   471                    KDefaultImplementationUid,
       
   472                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   473                    ( TAny* )&params ) );
       
   474             }
       
   475             break;
       
   476 // PRES-CONTENT STARTS
       
   477       case EXdmPresContent:
       
   478             {
       
   479             TUid KDefaultImplementationUid = { 0x20028701 };
       
   480             TRAPD( error, ptr = REComSession::CreateImplementationL( 
       
   481                 KDefaultImplementationUid,
       
   482                 _FOFF( CXcapAppUsage, iDestructorKey ),
       
   483                ( TAny* )&params ) );
       
   484             }
       
   485             break;
       
   486 // PRES-CONTENT ENDS
       
   487         default:
       
   488             User::Leave( KErrNotSupported );
       
   489         }
       
   490     return reinterpret_cast<CXcapAppUsage*>( ptr );
       
   491     }
       
   492     
       
   493     
       
   494 #endif          //__XCAPAPPUSAGE__
       
   495 
       
   496 
       
   497 // End of File
       
   498