2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). 
 
     4 * This component and the accompanying materials are made available
 
     5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
 
     6 * which accompanies this distribution, and is available
 
     7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
 
     9 * Initial Contributors:
 
    10 * Nokia Corporation - initial contribution.
 
    14 * Description:        Class implements the most common value object used in WSF, 
 
    15 *                which is used to  describe some invocable service. 
 
    26 #ifndef SEN_XML_SERVICE_DESCRIPTION_H
 
    27 #define SEN_XML_SERVICE_DESCRIPTION_H
 
    33 #include <MSenServiceDescription.h>
 
    34 #include <MSenProviderPolicy.h>
 
    35 #include <SenDomFragment.h>
 
    38 const TInt KStateParsingCredentials         = 12;
 
    39 const TInt KStateParsingSingleCredential    = 122;
 
    40 const TInt KStateParsingProviderPolicy      = 1222;
 
    41 const TInt KStateParsingServicePolicy       = 12222;
 
    43 _LIT8( KSenAttrSoap12,                  "SOAP12"               );
 
    44 _LIT8( KSenAttrAddressing,              "Addressing"           );
 
    45 _LIT8( KSenAttrClientEntropy,           "ClientEntropy"        );
 
    46 _LIT8( KSenAttrTokenType,               "TokenType"            );
 
    47 _LIT8( KSenAttrPassportExtensions,      "PassportExtensions"   );
 
    48 _LIT8( KSenAttrMetadataEndpoint,        "MetadataEndpoint"     );
 
    49 _LIT8( KSenAttrUsernameTokenOverTLS,    "UsernameTokenOverTLS" );
 
    50 _LIT8( KSenAttrPromptUserInfo,          "promptUserInfo"       );
 
    52 // FORWARD DECLARATIONS
 
    54 class CSenProviderPolicy;
 
    55 class CSenServicePolicy;
 
    56 class MSenServicePolicy;
 
    59 typedef RPointerArray<CSenCredential> RCredentialList;
 
    64 * CSenXmlServiceDescription class implements the most
 
    65 * common value object used in WSF, which is used to 
 
    66 * describe some invocable service. 
 
    68 * Class offers basic properties which describe some
 
    69 * service and methods to manipulate this info. These
 
    70 * properties are stored in XML fragment format and 
 
    71 * a class instance can be represented as one XML tree.
 
    73 * The main properties for service description are:
 
    74 *    - contract (typically some URI)
 
    75 *    - endpoint (typically some URL)
 
    78 *  @lib SenServDesc.lib
 
    81 class CSenXmlServiceDescription : public CSenDomFragment,
 
    82                                   public MSenServiceDescription,
 
    83                                   public MSenProviderPolicy
 
    85     public:  // Constructors and destructor
 
    88         * Standard 2 phase constructor
 
    89         * @return a pointer to a new CSenXmlServiceDescription instance.
 
    91         IMPORT_C static CSenXmlServiceDescription* NewL();
 
    94         * Standard 2 phase constructor
 
    95         * @return a pointer to a new CSenXmlServiceDescription instance,
 
    96         *        which is left on cleanup stack.
 
    98         IMPORT_C static CSenXmlServiceDescription* NewLC();
 
   101         * Standard 2 phase constructor
 
   102         * @param aNamespaceURI namespace URI for the service description.
 
   103         * @return a pointer to a new CSenXmlServiceDescription instance
 
   105         IMPORT_C static CSenXmlServiceDescription* NewL(const TDesC8& aNamespaceURI);
 
   108         * Standard 2 phase constructor
 
   109         * @param aNamespaceURI namespace URI for the service description.
 
   110         * @return a pointer to a new CSenXmlServiceDescription instance,
 
   111         *        which is left on cleanup stack.
 
   113         IMPORT_C static CSenXmlServiceDescription* NewLC(const TDesC8& aNamespaceURI);
 
   116         * Standard 2 phase constructors
 
   117         * @param aEndpoint the service endpoint. Note that endpoint cannot 
 
   118         *        include characters which are illegal in XML. If endpoint
 
   119         *        is an URL which contains illegal characters (like '&'-char),
 
   120         *        those need to be encoded into XML entity form (like &).
 
   121         *        EncodeHttpCharactersLC() method from XmlUtils can be used
 
   122         *        for encoding of basic XML entities.
 
   123         * @param aContract identifies the service type. 
 
   124         * @return a pointer to a new CSenXmlServiceDescription instance
 
   126         IMPORT_C static CSenXmlServiceDescription* NewL(const TDesC8& aEndPoint,
 
   127                                                         const TDesC8& aContract);
 
   130         * Standard 2 phase constructors
 
   131         * @param aEndpoint the service endpoint. Note that endpoint cannot 
 
   132         *        include characters which are illegal in XML. If endpoint
 
   133         *        is an URL which contains illegal characters (like '&'-char),
 
   134         *        those need to be encoded into XML entity form (like &).
 
   135         *        EncodeHttpCharactersLC() method from XmlUtils can be used
 
   136         *        for encoding of basic XML entities.
 
   137         * @param aContract identifies the service type. 
 
   138         * @return a pointer to a new CSenXmlServiceDescription instance,
 
   139         *        which is left on cleanup stack.
 
   141         IMPORT_C static CSenXmlServiceDescription* NewLC(const TDesC8& aEndPoint,
 
   142                                                          const TDesC8& aContract);
 
   147         IMPORT_C virtual ~CSenXmlServiceDescription();
 
   152         * Setter for the framework ID.
 
   153         * The developer may use a FrameworkID to search for a session of    
 
   154         * (i.e. connection to) a certain service invocation framework.
 
   155         * @since Series60 3.0
 
   156         * @param aFrameworkId
 
   157         * If set to KNullDesC8, then any matching framework may be used.
 
   158         * The default frameworkID in WSF is "ID-WSF" 
 
   159         * (KDefaultIdWsfFrameworkID).
 
   160         * Note that Basic Web Services MUST use "WS-I" 
 
   161         * (KDefaultBasicWebServicesFrameworkID).
 
   163         IMPORT_C void SetFrameworkIdL(const TDesC8& aFrameworkID);
 
   166         * Method returns the localname for this service description.
 
   167         * This is the localname of the element, when this class is
 
   168         * represented as an XML element.
 
   169         * @since Series60 3.0
 
   170         * @return descriptor to XML localname of this service description
 
   172         IMPORT_C virtual const TDesC8& NewElementName();
 
   175         * Returns list of credentials. Ownership is not transferred, any
 
   176         * modifications to the contents of the list modify the real objects.
 
   177         * @since Series60 3.0
 
   178         * @return the list of credentials (CSenCredential objects).
 
   180         IMPORT_C  RCredentialList& Credentials();        
 
   182         // Functions from base classes
 
   184         // From MSenProviderPolicy
 
   185         IMPORT_C virtual void SetIapIdL(TUint32 aIapId);
 
   186         IMPORT_C virtual TInt IapId(TUint32& aCurrentIapId);
 
   187         IMPORT_C virtual void SetIdentityProviderIdsL(
 
   188                                         CSenIdentityProviderIdArray8& aList);
 
   189 		IMPORT_C TInt SetTransportPropertiesL(const TDesC8& aProperties);
 
   191         IMPORT_C virtual TInt AddIdentityProviderIdL(TDesC8& aProviderId);
 
   192         IMPORT_C virtual TInt RebuildFrom(MSenProviderPolicy& aTemplate);
 
   193         IMPORT_C virtual const CSenIdentityProviderIdArray8&
 
   194                                                     IdentityProviderIds8L();
 
   195 	    IMPORT_C TInt TransportPropertiesL(HBufC8*& aProperties);
 
   197         IMPORT_C virtual TBool Accepts(MSenProviderPolicy& aPolicyPattern);
 
   199         // From MSenServiceDescription:
 
   200         IMPORT_C TDescriptionClassType DescriptionClassType();
 
   201         IMPORT_C TBool Matches(MSenServiceDescription& aPattern);
 
   202         IMPORT_C TPtrC8 Contract();
 
   206         * Method for checking if service description has a certain facet.
 
   207         * @since Series60 3.0
 
   208         * @param aURI       the facet to check, typically some URI.
 
   209         * @param aHasFacet  is ETrue if facet is found and EFalse, if not.
 
   210         * @return       KErrNone or other system-wide Symbian error codes.
 
   212         IMPORT_C virtual TInt HasFacetL(const TDesC8& aURI, TBool& aHasFacet);
 
   214         // From MSenServiceDescription
 
   215         IMPORT_C virtual TInt FacetValue(TDesC8& aURI, HBufC8*& aValueTo);
 
   216         IMPORT_C virtual TInt AddFacetL(const CSenFacet& aFacet);
 
   217         IMPORT_C virtual TInt SetFacetL(const CSenFacet& aFacet);
 
   218         IMPORT_C virtual TInt RemoveFacet(const TDesC8& aURI);
 
   219         IMPORT_C virtual TInt FacetsL(RFacetArray& aFacetArray);
 
   223         * On success, this method returns a positive integer if this 
 
   224         * service description matches with the given pattern in at 
 
   225         * least one aspect. Higher numbers mean a closer match.
 
   227         * The bits of information that are in the pattern are read and compared
 
   228         * to corresponding fields in this ServiceDescription. Note that a pattern
 
   229         * may have far fewer fields and that only the non-null fields are compared.
 
   230         * For example, assume that a pattern with only a contract was defined;
 
   231         * with the contract set to "urn:example.com:service". 
 
   232         * Each ServiceDescription with the same contract will match the pattern,
 
   233         * even if such a ServiceDescription has non-null fields for other aspects.
 
   234         * @since Series60 3.0
 
   235         * @param    aPattern a ServiceDescription, typically with partial
 
   237         * @return the score or error. If nothing matches, returns 0. In case of 
 
   238         *  any error, a negative value is returned. 
 
   240         IMPORT_C virtual TInt ScoreMatchL(MSenServiceDescription& aPattern);
 
   242         // From MSenServiceDescription
 
   244         IMPORT_C TPtrC8 Endpoint();
 
   245         IMPORT_C TPtrC8 FrameworkId();
 
   246         IMPORT_C TPtrC8 FrameworkVersion();
 
   247         IMPORT_C void SetContractL(const TDesC8& aContract);
 
   248         IMPORT_C void SetEndPointL(const TDesC8& aEndPoint);
 
   250         // From CSenBaseFragment 
 
   253         * Gets the service description as XML fragment in UTF-8 format.
 
   254         * @since Series60 3.0
 
   255         * @return the service description as XML, which ownership is
 
   256         *         transferred to the caller.
 
   258         IMPORT_C virtual HBufC8* AsXmlL();
 
   261         * Gets the service description as XML, in Unicode (UCS-2)
 
   262         * @since Series60 3.0
 
   263         * @return the service description as XML, in Unicode (UCS-2)
 
   266         IMPORT_C virtual HBufC* AsXmlUnicodeL();
 
   269         * Writes this service description as XML, in UTF-8 form to a stream
 
   270         * @since Series60 3.0
 
   271         * @param aWriteStream   to write into.
 
   273         IMPORT_C virtual void WriteAsXMLToL(RWriteStream& aWriteStream);
 
   276         // From CSenDomFragment 
 
   279         * Method looks for FrameworkID attribute from the given XML attribute
 
   280         * array and if one is found, sets its value for this instance. In
 
   281         * addition, all the namespace attributes are copied. All other
 
   282         * attributes are discarded.
 
   283         * @since Series60 3.0
 
   284         * @param aAttributes    the attribute list.
 
   286         IMPORT_C void SetAttributesL(const RAttributeArray& aAttributes);
 
   289         * Resumes the parsing. Called by the delegate fragment 
 
   290         * in order to notify owner, which needs to regain 
 
   291         * (take over) parsing. For example, when a policy fragment
 
   292         * is parsed, the service description fragment should
 
   293         * resume parsing the rest of its own XML document 
 
   295         * @since Series60 3.0
 
   296         * @param aNsUri     The namespace URI of the current element
 
   297         * @param aLocalName The local name of the current element
 
   298         * @param aQName     The qualified name of the current element
 
   300         IMPORT_C void ResumeParsingFromL(const TDesC8& aNsUri,
 
   301                                          const TDesC8& aLocalName,
 
   302                                          const TDesC8& aQName);
 
   304     protected:  // New functions
 
   307         * C++ default constructor.
 
   308         * @param aType enumeration defining the type of this class.
 
   310         IMPORT_C CSenXmlServiceDescription(TDescriptionClassType aType);
 
   313          * Basic ConstructL function.
 
   315         IMPORT_C void ConstructL();
 
   318         * Basic ConstructL function.
 
   319         * @since Series60 3.0
 
   320         * @param aNamespaceURI for this service description, which is
 
   321         *        also an XML element.
 
   323         IMPORT_C void ConstructL(const TDesC8& aNamespaceURI);
 
   326         * Basic ConstructL function.
 
   327         * @since Series60 3.0
 
   328         * @param aEndpoint the service endpoint. Note that endpoint cannot 
 
   329         *        include characters which are illegal in XML. If endpoint
 
   330         *        is an URL which contains illegal characters (like '&'-char),
 
   331         *        those need to be encoded into XML entity form (like &).
 
   332         *        EncodeHttpCharactersLC() method from XmlUtils can be used
 
   333         *        for encoding of basic XML entities.
 
   334         * @param aContract identifies the service type, typically some URN.
 
   336         IMPORT_C void ConstructL(const TDesC8& aEndPoint, const TDesC8& aContract);
 
   338         // Functions from base classes
 
   340         // From CSenDomFragment 
 
   343         * Callback function which implements the XML content handler interface.
 
   344         * @since Series60 3.0
 
   345         * @param aNsURI     The namespace URI of the new element
 
   346         * @param aLocalName The local name of the new element
 
   347         * @param aQName     The qualified name of the new element
 
   348         * @param aAttributes    The attributes of the new element
 
   350         IMPORT_C virtual void StartElementL(const TDesC8& aNsUri,
 
   351                                             const TDesC8& aLocalName,
 
   352                                             const TDesC8& aQName,
 
   353                                             const RAttributeArray& aAttributes);
 
   355         // From CSenBaseFragment 
 
   357         * Callback function which implement the XML content handler interface.
 
   358         * @since Series60 3.0
 
   359         * @param aNsUri     The namespace URI of the new element
 
   360         * @param aLocalName The local name of the new element
 
   361         * @param aQName     The qualified name of the new element
 
   363         IMPORT_C virtual void EndElementL(const TDesC8& aNsUri,
 
   364                                           const TDesC8& aLocalName,
 
   365                                       const TDesC8& aQName);
 
   369         * Method returns ETrue if the primary keys of this service description
 
   370         * are equal. Definition of primary keys varies on concrete implementations.
 
   372         * In a typical XML sub class implementation the primary keys are Contract 
 
   373         * and Endpoint elements. 
 
   375         * Difference to Match() method is that primary keys - often descriptors - 
 
   376         * MUST be equal both in this service description and in aCandidate, unlike
 
   377         * in Match(), where argument is more like wildcard pattern matching even
 
   378         * in cases where it includes fewer fields (less information).
 
   381         * @param    aCandidate is a service description, which primary keys are
 
   382         *           checked in this comparison.
 
   384         * @return TBool ETrue if primary keys are equal, EFalse otherwise. 
 
   386         IMPORT_C TBool HasEqualPrimaryKeysL(MSenServiceDescription& aCandidate);
 
   389         * Method checks specific pieces of information to determine, whether this
 
   390         * service description is local or not. Typically this is defined by the
 
   391         * endpoint's scheme, which is KSenTransportSchemeLocal in most of the cases,
 
   392         * when this method returns true.
 
   393         * @return boolean indicating whether this endpoint is local or not.
 
   395         IMPORT_C TBool IsLocalL(); 
 
   399         * Method for binding transport plug-in type with the endpoint in question.
 
   400         * Function adds/sets XML attribute called "cue" for <Endpoint> element:
 
   402         *  <ServiceDescription>
 
   403         *    <Endpoint cue="com.nokia.wsf.transport.plugin.hostlet">
 
   404         *        local://urn:nokia.com.test.hostlet
 
   406         *  </ServiceDescription>
 
   408         * In above example, eventhough endpoint scheme "local://" would normally
 
   409         * invoke different type of plug-in (ECOM hostlet), the "cue" attribute 
 
   410         * overrides this, and forces hostlet connection transport plug-in to be
 
   413         * Transport plug-in types (cues):
 
   415         *    _LIT8(KSenTransportCueHTTP,              "com.nokia.wsf.transport.plugin.httpchannel");
 
   416         *    _LIT8(KSenTransportCueVirtualTCP,        "com.nokia.wsf.transport.plugin.virtualtcp");
 
   417         *    _LIT8(KSenTransportCueLocalEcom,         "com.nokia.wsf.transport.plugin.local");  
 
   418         *    _LIT8(KSenTransportCueHostletConnection, "com.nokia.wsf.transport.plugin.hostlet");
 
   421         * Note that this method does not attempt to load the plug-in - it might not
 
   422         * even exist in the system. Neither is this attribute checked when XML service
 
   423         * description is parsed. As a conclusion, if non-existant plug-ins are bind 
 
   424         * to endpoints, they will be ignored, and the transport is created in normal
 
   425         * way and plug-in is chosen based on endpoint scheme and/or defaults.
 
   427         * @param aTransportCue is the ECOM cue of CSenTransport implementation.
 
   428         * In ECOM resource files, cue is the value of "default_data" property.
 
   429         * @return KErrNone on success
 
   430         *         KErrSenNoEndpoint, if  endpoint element does not exist in this XML
 
   431         *         service description.
 
   433         IMPORT_C TInt SetTransportCueL(const TDesC8& aTransportCue);
 
   437         * Getter for transport cue, assuming that attribute has been set,
 
   438         * and that has "cue" -attribute.
 
   439         * @return transport plug-in ECOM cue, or KNullDesC8, if it has
 
   440         * not been set in this service description. In each ECOM resource
 
   441         * file the cue is defined by "default_data" property.
 
   443         IMPORT_C TPtrC8 TransportCue();
 
   446         * Getter for (web) service policy
 
   447         * @return pointer to service policy, or NULL, if it is not available
 
   449         IMPORT_C MSenServicePolicy* ServicePolicy();
 
   452         * Method provides convenient way to add a new value in Client Policy
 
   453         * This method will add elements such as <SOAP12> or <UsernameTokenOverTLS>
 
   454         * in the Policy to be used by stack. Infact this method adds a new element 
 
   455         * in xml representation of ServicePolicy.
 
   456         * @param aName is the Name of the attribute.
 
   457         * @return KErrNone on success, KErrArgument if any of the arguments 
 
   458         * (descriptors) is of zero-length, or one of the system-wide 
 
   459         * error codes otherwise.
 
   461         IMPORT_C TInt SetPolicyL(const TDesC8& aName);
 
   464         * Method provides convenient way to add a new value in Client Policy
 
   465         * This method will add elements such as <Addressing>
 
   466         * in the Policy to be used by stack. Infact this method adds a new element 
 
   467         * in xml representation of ServicePolicy and adds its value as contents of the element.
 
   468         * <Addressing>http://schemas.xmlsoap.org/ws/2004/03/addressing</Addressing>
 
   469         * @param aName is the Name of the Policy attribute.
 
   470         * @param aValue is the Contents of the Policy attribute.
 
   471         * @return KErrNone on success, KErrArgument if any of the arguments 
 
   472         * (descriptors) is of zero-length, or one of the system-wide 
 
   473         * error codes otherwise.
 
   475         IMPORT_C TInt SetPolicyL(const TDesC8& aName, const TDesC8& aValue);
 
   478         * Method provides convenient way to add a new value in Client Policy
 
   479         * This method will add elements such as <Addressing>
 
   480         * in the Policy to be used by stack, plus it will add one specified
 
   481         * attribute (name and value) for that element. Infact this method adds
 
   482         * a new element - and it's attribute - in the xml representation of 
 
   483         * ServicePolicy element, which is direct child to ServiceDescription
 
   484         * (root element) document.
 
   485         * <MetadataEndpoint method = "GET">http://www.mypolicyendpoint.com/policy2/</MetadataEndpoint>
 
   486         * @param aName is the Name of the Policy attribute.
 
   487         * @param aValue is the Contents of the Policy attribute.
 
   488         * @param aAttribName is the Name of the attribute in element aName
 
   489         * @param aAttribValue is the Contents of the aAttribName attribute.
 
   490         * @return KErrNone on success, KErrArgument if any of the arguments 
 
   491         * (descriptors) is of zero-length, or one of the system-wide 
 
   492         * error codes otherwise.
 
   494         IMPORT_C TInt SetPolicyL(const TDesC8& aName, const TDesC8& aValue, const TDesC8& aAttribName, const TDesC8& aAttribValue);
 
   497         * Setter for (identity) provider ID
 
   498         * @since Series60 5.0
 
   499         * @param aProviderID the unique identifier of the (identity) provider
 
   500         * @return KErrNone on success, KErrArgument if aProviderID is of zero-length,
 
   501         * or one of the system-wide Symbian error codes otherwise.
 
   503         IMPORT_C TInt SetProviderIdL( const TDesC8& aProviderID );
 
   506         * Getter for (identity) provider ID
 
   507         * @since Series60 5.0
 
   508         * @return the (locally) unique identifier of the (identity) provider
 
   509         * @return KErrNone on success, KErrArgument if aProviderID is of zero-length,
 
   510         * or one of the system-wide Symbian error codes otherwise.
 
   512         IMPORT_C TPtrC8 ProviderId();
 
   515         * Setter for userinfo (KSenAttrPromptUserInfo) attribute, which 
 
   516         * - password notifier dialog is shown to end-user or not, when 
 
   517         * authentication fails (due wrong, or incomplete userinfo).
 
   518         * @param aPromptUserInfoMode 
 
   519         *  EFalse dictates that an error must be returned when creating
 
   520         *         a service connection and userinfo is not accepted by 
 
   521         *         (remote) authentication, instead of showing the dialog.
 
   522         *  ETrue (or if attribute does not exist in this XML SD) means that
 
   523         *         end-user should be prompted (default behaviour). The number
 
   524         *         of retry attempts (each showing a dialog) is service invocation
 
   525         *         framework spesific; typically 3 retries are permitted.     
 
   527         IMPORT_C void CSenXmlServiceDescription::SetPromptUserInfoL( TBool aPromptUserInfoMode );
 
   530         * Getter for current userinfo mode (KSenAttrPromptUserInfo attribute).
 
   531         * @return Boolean that indicates the mode:
 
   532         *  EFalse means that end-user prompts (notifier dialogs) have been 
 
   533         *  explicitely surpressed, and thus will not be shown to end-user:
 
   534         *  attribute value is exactly as follows: "false"
 
   535         *  ETrue means that attribute named as KSenAttrPromptUserInfo 
 
   536         *  does not exist (default), or it has ANY value OTHER than "false"
 
   538         IMPORT_C TBool PromptUserInfo();
 
   543         * @param aIapId  A TUint32 Snap ID
 
   545         IMPORT_C void SetSnapIdL(TUint32 aIapId); 
 
   548         * @param aCurrentSnapId  A TUint32 reference to be filled in with the
 
   549         *                       value of the SNAP ID.
 
   550         * @return               KErrNone if no error, or some of the system
 
   553         IMPORT_C TInt SnapId(TUint32& aCurrentIapId); 
 
   556         TInt FacetValueL(TDesC8& aURI, HBufC8*& aValueTo);
 
   557         TInt RemoveFacetL(const TDesC8& aURI);
 
   560         // the type of this class instance
 
   561         const TDescriptionClassType iType;
 
   564         CSenServicePolicy* iServicePolicy;
 
   565         CSenCredential* iCredential;
 
   566         RCredentialList iCredentialList;
 
   568         // Timestamp indicating validity of credentials. Using SenDateUtils 
 
   569         // FromXmlDateTimeL and ToXmlDateTimeUtf8L is recommended for conversions.
 
   571         CSenProviderPolicy* iProviderPolicy;
 
   574 #endif // SEN_XML_SERVICE_DESCRIPTION_H