webservices/wsdescription/src/sencredential.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-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:        
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include "SenCredential.h"
       
    27 
       
    28 //#include "SenDebug.h"
       
    29 
       
    30 #include <SenDateUtils.h>
       
    31 
       
    32 #include <SenXmlElement.h>
       
    33 #include <SenXmlUtils.h>
       
    34 
       
    35 
       
    36 #ifdef SYMBIAN_SECURE_ECOM 
       
    37     // for S60 FP3 (2.8) platform or newer (3.0 and above)
       
    38     #include <xml/attribute.h> // needed for RAttributeArray
       
    39 //#else  // for S60 FP2 platform (2.6) or older
       
    40     //#include "Attribute.h"
       
    41 #endif
       
    42 
       
    43 using namespace Xml;
       
    44 
       
    45 namespace
       
    46 {
       
    47     /* milliseconds before actual notOnOrAfter time
       
    48      * when credentials are treated
       
    49      * as expired.
       
    50      */
       
    51 
       
    52     // Identifiers which are accepted (and searched after)
       
    53     _LIT8(KId,                      "ID");
       
    54     _LIT8(Kwsu_ns_plus_Id,          "wsu:Id");
       
    55     _LIT8(KAssertionId,             "AssertionID");
       
    56 
       
    57     _LIT8(KConditions,              "Conditions");
       
    58     _LIT8(KVal_NotOnOrAfter,        "NotOnOrAfter");
       
    59 }
       
    60 
       
    61 EXPORT_C CSenCredential* CSenCredential::NewL(
       
    62     const TDesC8& aNsUri,
       
    63     const TDesC8& aLocalName,
       
    64     const TDesC8& aQName,
       
    65     const RAttributeArray& aAttributes
       
    66     )
       
    67     {
       
    68     CSenCredential* pNew = NewLC(aNsUri, aLocalName, aQName, aAttributes);
       
    69     CleanupStack::Pop(); // pNew;
       
    70     return pNew;
       
    71     }
       
    72 
       
    73 EXPORT_C CSenCredential* CSenCredential::NewLC(
       
    74     const TDesC8& aNsUri,
       
    75     const TDesC8& aLocalName,
       
    76     const TDesC8& aQName,
       
    77     const RAttributeArray& aAttributes
       
    78     )
       
    79     {
       
    80     CSenCredential* pNew = new (ELeave) CSenCredential;
       
    81     CleanupStack::PushL(pNew);
       
    82     pNew->ConstructL(aNsUri, aLocalName, aQName, aAttributes);
       
    83     return pNew;
       
    84     }
       
    85 
       
    86 EXPORT_C CSenCredential* CSenCredential::NewL(
       
    87     const TDesC8& aNsUri,
       
    88     const TDesC8& aLocalName,
       
    89     const TDesC8& aQName,
       
    90     const RAttributeArray& aAttributes,
       
    91     CSenElement& aParent
       
    92     )
       
    93     {
       
    94     CSenCredential* pNew = NewLC(aNsUri, aLocalName, 
       
    95                                 aQName, aAttributes, aParent);
       
    96     CleanupStack::Pop(); // pNew;
       
    97     return pNew;
       
    98     }
       
    99 
       
   100 EXPORT_C CSenCredential* CSenCredential::NewLC(
       
   101     const TDesC8& aNsUri,
       
   102     const TDesC8& aLocalName,
       
   103     const TDesC8& aQName,
       
   104     const RAttributeArray& aAttributes,
       
   105     CSenElement& aParent
       
   106     )
       
   107     {
       
   108     CSenCredential* pNew = new (ELeave) CSenCredential;
       
   109     CleanupStack::PushL(pNew);
       
   110     pNew->ConstructL(aNsUri, aLocalName, aQName, aAttributes, aParent);
       
   111     return pNew;
       
   112     }
       
   113 
       
   114 
       
   115 EXPORT_C CSenCredential* CSenCredential::NewL(
       
   116                                              const CSenCredential& aCredential)
       
   117     {
       
   118     CSenCredential* pNew = NewLC(aCredential);
       
   119     CleanupStack::Pop(); // pNew;
       
   120     return pNew;
       
   121     }
       
   122 
       
   123 EXPORT_C CSenCredential* CSenCredential::NewLC(
       
   124                                              const CSenCredential& aCredential)
       
   125     {
       
   126     CSenCredential* pNew = new (ELeave) CSenCredential;
       
   127     CleanupStack::PushL(pNew);
       
   128     pNew->ConstructL((CSenCredential&)aCredential);
       
   129     return pNew;
       
   130     }
       
   131 
       
   132 
       
   133 EXPORT_C void CSenCredential::ConstructL(CSenCredential& aCredential)
       
   134     {
       
   135     ipElement = CSenXmlElement::NewL(aCredential.ipElement->LocalName());
       
   136     ipElement->CopyFromL(*(CSenXmlElement*)(aCredential.ipElement));
       
   137     if (aCredential.ValidUntil() != Time::NullTTime())
       
   138         {
       
   139         SetValidUntil(aCredential.ValidUntil());
       
   140         }
       
   141     SetIdL(aCredential.Id());
       
   142     }
       
   143 
       
   144 EXPORT_C void CSenCredential::ConstructL(
       
   145     const TDesC8&  aNsUri,
       
   146     const TDesC8&  aLocalName,
       
   147     const TDesC8&  aQName,
       
   148     const RAttributeArray& aAttributes,
       
   149     CSenElement& aParent
       
   150     )
       
   151     {
       
   152     BaseConstructL(aNsUri, aLocalName, aQName, aAttributes, aParent);
       
   153     // this ensures we take note of possible namespaces and
       
   154     // prefixed attributes
       
   155     CSenBaseFragment::SetAttributesL(aAttributes);
       
   156     // we want to save its ID and validity
       
   157 
       
   158     TPtrC8 identifier = SenXmlUtils::AttrValue(aAttributes, KId);
       
   159     if(identifier.Length()>0)
       
   160         {
       
   161         SetIdL(identifier);
       
   162         }
       
   163 
       
   164     TPtrC8 identifier2 = SenXmlUtils::AttrValue(aAttributes, Kwsu_ns_plus_Id);
       
   165     if(identifier2.Length()>0)
       
   166         {
       
   167         SetIdL(identifier2);
       
   168         }
       
   169     
       
   170     TPtrC8 identifier3 = SenXmlUtils::AttrValue(aAttributes, KAssertionId);
       
   171     if(identifier3.Length()>0)
       
   172         {
       
   173         SetIdL(identifier3);
       
   174         }
       
   175 
       
   176     /*
       
   177 
       
   178     for(int i=0; i<aAttributes.Count(); i++)
       
   179         {
       
   180         TPtrC8 attrName = aAttributes[i].Attribute().LocalName().DesC();
       
   181         if( attrName == KId)
       
   182             {
       
   183 
       
   184             SetIdL(aAttributes[i].Value().DesC());
       
   185             }
       
   186         else if(attrName == Kwsu_ns_plus_Id)
       
   187             {
       
   188             SetIdL(aAttributes[i].Value().DesC());
       
   189             }
       
   190 
       
   191         else if(attrName == KAssertionId)
       
   192             {
       
   193             SetIdL(aAttributes[i].Value().DesC());
       
   194             }
       
   195         }
       
   196     */
       
   197 
       
   198     }
       
   199 
       
   200 EXPORT_C void CSenCredential::ConstructL(
       
   201     const TDesC8&  aNsUri,
       
   202     const TDesC8&  aLocalName,
       
   203     const TDesC8&  aQName,
       
   204     const RAttributeArray& aAttributes )
       
   205     {
       
   206     BaseConstructL(aNsUri, aLocalName, aQName, aAttributes);
       
   207     // this ensures we take note of possible namespaces and
       
   208     // prefixed attributes
       
   209     CSenBaseFragment::SetAttributesL(aAttributes);
       
   210 
       
   211     TPtrC8 identifier = SenXmlUtils::AttrValue(aAttributes, KId);
       
   212     if(identifier.Length()>0)
       
   213         {
       
   214         SetIdL(identifier);
       
   215         }
       
   216 
       
   217     TPtrC8 identifier2 = SenXmlUtils::AttrValue(aAttributes, Kwsu_ns_plus_Id);
       
   218     if(identifier2.Length()>0)
       
   219         {
       
   220         SetIdL(identifier2);
       
   221         }
       
   222     
       
   223     TPtrC8 identifier3 = SenXmlUtils::AttrValue(aAttributes, KAssertionId);
       
   224     if(identifier3.Length()>0)
       
   225         {
       
   226         SetIdL(identifier3);
       
   227         }
       
   228     /*
       
   229     // we want to save its ID and validity
       
   230     for(int i=0; i<aAttributes.Count(); i++)
       
   231         {
       
   232         TPtrC8 attrName = aAttributes[i].Attribute().LocalName().DesC();
       
   233         if(attrName == KId)  
       
   234             {
       
   235             SetIdL(aAttributes[i].Value().DesC());
       
   236             }
       
   237 
       
   238         if(attrName == Kwsu_ns_plus_Id)
       
   239             {
       
   240             SetIdL(aAttributes[i].Value().DesC());
       
   241             }
       
   242 
       
   243         if(attrName == KAssertionId)
       
   244             {
       
   245             SetIdL(aAttributes[i].Value().DesC());
       
   246             }
       
   247         }
       
   248     */
       
   249     }
       
   250 
       
   251 EXPORT_C CSenCredential::CSenCredential()
       
   252 :
       
   253     iId(NULL),
       
   254     iNotOnOrAfter(Time::NullTTime())
       
   255     {
       
   256     }
       
   257 
       
   258 EXPORT_C CSenCredential::~CSenCredential()
       
   259     {
       
   260     delete iId;
       
   261     }
       
   262 
       
   263 void CSenCredential::SetIdL(const TDesC8& aNewId)
       
   264     {
       
   265     HBufC8* pNew = aNewId.AllocL();
       
   266     delete iId;
       
   267     iId = pNew;
       
   268     }
       
   269 
       
   270 EXPORT_C const TDesC8& CSenCredential::Id()
       
   271     {
       
   272     if(iId)
       
   273         {
       
   274         return *iId;
       
   275         }
       
   276     else
       
   277         {
       
   278         return KNullDesC8();
       
   279         }
       
   280     }
       
   281 
       
   282 
       
   283 EXPORT_C void CSenCredential::StartElementL(
       
   284     const TDesC8& aNsUri,
       
   285     const TDesC8& aLocalName,
       
   286     const TDesC8& aQName,
       
   287     const RAttributeArray& aAttributes
       
   288     )
       
   289     {
       
   290     if(aLocalName.Compare(KConditions) == 0)
       
   291         {
       
   292         // we should save the notOnOrAfter attribute value
       
   293         TPtrC8 ptr = SenXmlUtils::AttrValue(aAttributes, KVal_NotOnOrAfter );
       
   294 
       
   295         // Convert dateTime (from XML schema) to Symbian TTime.
       
   296         // The returned time will be in UTC.
       
   297         if (ptr.Length() > 0)
       
   298             {
       
   299             iNotOnOrAfter = SenDateUtils::FromXmlDateTimeL(ptr);
       
   300             }
       
   301         }
       
   302     CSenBaseFragment::StartElementL(aNsUri, 
       
   303             aLocalName, aQName, aAttributes);
       
   304     }
       
   305 
       
   306 EXPORT_C TTime& CSenCredential::ValidUntil()
       
   307     {
       
   308     return iNotOnOrAfter;
       
   309     }
       
   310 
       
   311 
       
   312 EXPORT_C void CSenCredential::SetValidUntil(TTime& aTime)
       
   313     {
       
   314     iNotOnOrAfter = aTime;
       
   315     }
       
   316 
       
   317 
       
   318 // END OF FILE
       
   319