webservices/wsstar/wsstarplugin/src/wsstarpolicyrequest.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2006-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:        
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #include "wsstarpolicyrequest.h"
       
    25 
       
    26 //---------------------------------------------------------------------------
       
    27 // 
       
    28 //---------------------------------------------------------------------------
       
    29 //     
       
    30 CPolicyRequest* CPolicyRequest::NewL(const TDesC8& aContract)
       
    31 {
       
    32     CPolicyRequest* self   = CPolicyRequest::NewLC(aContract);
       
    33     CleanupStack::Pop();
       
    34     return self;
       
    35     
       
    36 }
       
    37 //---------------------------------------------------------------------------
       
    38 // 
       
    39 //---------------------------------------------------------------------------
       
    40 //                                
       
    41 CPolicyRequest* CPolicyRequest::NewLC(const TDesC8& aContract)
       
    42 {
       
    43     CPolicyRequest* self   = new (ELeave) CPolicyRequest();
       
    44     CleanupStack::PushL (self);
       
    45     self->ConstructL(aContract);
       
    46     return self;
       
    47     
       
    48 }
       
    49 //---------------------------------------------------------------------------
       
    50 // 
       
    51 //---------------------------------------------------------------------------
       
    52 //    
       
    53 CPolicyRequest::~CPolicyRequest()
       
    54 {
       
    55     delete iContract; //service contract representing the policy
       
    56     iPolicies.ResetAndDestroy();
       
    57 }
       
    58 //---------------------------------------------------------------------------
       
    59 // 
       
    60 //---------------------------------------------------------------------------
       
    61 //
       
    62 CPolicyRequest::CPolicyRequest() :
       
    63 iSD(NULL),iContract(NULL)
       
    64 {
       
    65     
       
    66 }
       
    67 //---------------------------------------------------------------------------
       
    68 // 
       
    69 //---------------------------------------------------------------------------
       
    70 //
       
    71 void CPolicyRequest::ConstructL(const TDesC8& aContract)
       
    72 {
       
    73     if(aContract.Length() < 1)
       
    74         User::Leave (KErrArgument);
       
    75     
       
    76     iContract = aContract.AllocL();
       
    77     
       
    78 }
       
    79 //---------------------------------------------------------------------------
       
    80 // 
       
    81 //---------------------------------------------------------------------------
       
    82 //    
       
    83 TPtrC8  CPolicyRequest::Contract()
       
    84 {
       
    85     if (iContract != NULL)
       
    86         return iContract->Des();
       
    87     else
       
    88         return KNullDesC8();
       
    89 
       
    90 }
       
    91 //---------------------------------------------------------------------------
       
    92 // 
       
    93 //---------------------------------------------------------------------------
       
    94 //
       
    95 CSenWSDescription* CPolicyRequest::ServiceDescription()
       
    96 {
       
    97     return iSD;    
       
    98 }
       
    99 //---------------------------------------------------------------------------
       
   100 // 
       
   101 //---------------------------------------------------------------------------
       
   102 //
       
   103 TInt CPolicyRequest::SetSD(CSenWSDescription* aSD)
       
   104 {
       
   105     if(aSD != NULL && aSD->Contract().Compare(iContract->Des()) == 0)
       
   106     {
       
   107         iSD = aSD; //not owned              
       
   108     }
       
   109     else
       
   110     {
       
   111         iSD = NULL;
       
   112     }
       
   113          
       
   114     return KErrNone;         
       
   115 }
       
   116 //---------------------------------------------------------------------------
       
   117 // 
       
   118 //---------------------------------------------------------------------------
       
   119 //
       
   120 void CPolicyRequest::URIs(RArray<TPtrC8>& aURI)
       
   121 {
       
   122     for(TInt i = 0; i <iPolicies.Count(); i++ )
       
   123     {
       
   124         CPolicyReq* req = iPolicies[i];
       
   125         if(req)
       
   126         {
       
   127             TPtrC8 uri = req->URI();    
       
   128             aURI.Append(uri);
       
   129         }
       
   130     }
       
   131 }
       
   132 //---------------------------------------------------------------------------
       
   133 // 
       
   134 //---------------------------------------------------------------------------
       
   135 //
       
   136 TInt CPolicyRequest::LookForUri( const TDesC8& aUri )
       
   137     {
       
   138     for (TInt i = 0; i< iPolicies.Count(); i++)
       
   139         {
       
   140         CPolicyReq* req = iPolicies[i];
       
   141         if (req->URI().Compare(aUri) == 0)
       
   142             {
       
   143             return i;   
       
   144             }
       
   145         }
       
   146     return KErrNotFound;
       
   147     }
       
   148 //---------------------------------------------------------------------------
       
   149 // 
       
   150 //---------------------------------------------------------------------------
       
   151 //
       
   152 TInt CPolicyRequest::AddMetadataUriL( const TDesC8& aUri )
       
   153 {
       
   154     if(aUri.Length() < 1)    
       
   155         return KErrArgument;
       
   156     
       
   157     TInt indx = LookForUri(aUri);
       
   158     if(indx == KErrNotFound)
       
   159     {
       
   160         CPolicyReq* req = CPolicyReq::NewL(aUri);
       
   161         if(req)
       
   162             return iPolicies.Append(req);
       
   163     }
       
   164     else
       
   165     {
       
   166         return indx;
       
   167     }
       
   168     
       
   169     return KErrNotFound;        
       
   170 }
       
   171 //---------------------------------------------------------------------------
       
   172 // 
       
   173 //---------------------------------------------------------------------------
       
   174 //
       
   175 TInt CPolicyRequest::AddMetadataUriL( const TDesC8& aUri, const TDesC8& aName)
       
   176 {
       
   177 
       
   178     if(aUri.Length() < 1 || aName.Length() < 1)    
       
   179         return KErrArgument;
       
   180     
       
   181     TInt indx = LookForUri(aUri);
       
   182     if(indx == KErrNotFound)
       
   183     {
       
   184         CPolicyReq* req = CPolicyReq::NewL(aUri);
       
   185         if(req)
       
   186         {
       
   187             req->SetNameL(aName);    
       
   188             return iPolicies.Append(req);
       
   189         }
       
   190     }
       
   191     else
       
   192     {
       
   193         CPolicyReq* req = iPolicies[indx];
       
   194         req->SetNameL(aName);
       
   195         return indx;
       
   196     }
       
   197     
       
   198     return KErrNotFound;
       
   199     
       
   200 }
       
   201 //---------------------------------------------------------------------------
       
   202 // 
       
   203 //---------------------------------------------------------------------------
       
   204 //
       
   205 TInt CPolicyRequest::AddMetadataUriL(const TDesC8& aUri, const TDesC8& aName, const TDesC8& aContents )
       
   206 {
       
   207 
       
   208     if(aUri.Length() < 1 || aName.Length() < 1 || aContents.Length() < 1)    
       
   209         return KErrArgument;
       
   210     
       
   211     TInt indx = LookForUri(aUri);
       
   212     if(indx == KErrNotFound)
       
   213     {
       
   214         CPolicyReq* req = CPolicyReq::NewL(aUri);
       
   215         if(req)
       
   216         {
       
   217             req->SetNameL(aName);
       
   218             req->SetContentsL(aContents);
       
   219             return iPolicies.Append(req);
       
   220         }
       
   221     }
       
   222     else
       
   223     {
       
   224         CPolicyReq* req = iPolicies[indx];
       
   225         req->SetNameL(aName);
       
   226         req->SetContentsL(aContents);
       
   227         return indx;
       
   228 
       
   229     }
       
   230     return KErrNotFound;        
       
   231 }
       
   232 //---------------------------------------------------------------------------
       
   233 // 
       
   234 //---------------------------------------------------------------------------
       
   235 //
       
   236 TInt CPolicyRequest::SetContentsL( const TDesC8& aUri, const TDesC8& aContent )
       
   237     {
       
   238     if(aUri.Length() < 1 || aContent.Length() < 1)    
       
   239         {
       
   240         return KErrArgument;
       
   241         }
       
   242     TInt indx = LookForUri(aUri);
       
   243     if(indx != KErrNotFound)
       
   244         {
       
   245         CPolicyReq* req = iPolicies[indx];
       
   246         req->SetContentsL(aContent);
       
   247         return indx;
       
   248         }
       
   249     return KErrNotFound;    
       
   250     }
       
   251 //---------------------------------------------------------------------------
       
   252 // 
       
   253 //---------------------------------------------------------------------------
       
   254 //
       
   255 TInt CPolicyRequest::SetPolicyL( const TDesC8& aUri, CWSPolicy* aPolicy )
       
   256     {
       
   257     if(aUri.Length() < 1 || aPolicy == NULL)    
       
   258         {
       
   259         return KErrArgument;
       
   260         }
       
   261     TInt indx = LookForUri(aUri);
       
   262     if(indx != KErrNotFound)
       
   263         {
       
   264         CPolicyReq* req = iPolicies[indx];
       
   265         req->SetPolicy(aPolicy);
       
   266         return indx;
       
   267         }
       
   268     return KErrNotFound;    
       
   269     }
       
   270 //---------------------------------------------------------------------------
       
   271 // 
       
   272 //---------------------------------------------------------------------------
       
   273 //
       
   274 CSenElement* CPolicyRequest::PolicyL()	//codescannerwarnings
       
   275     {
       
   276     if(iPolicies.Count() > 0)
       
   277         {
       
   278         CPolicyReq* req = iPolicies[0];
       
   279          // return NULL if there was no way to fetch policy from network
       
   280         CWSPolicy* pol = req->Policy();
       
   281         if(pol)
       
   282             {
       
   283                 return pol->PolicyL();	//codescannerwarning
       
   284             }
       
   285             else
       
   286             {
       
   287                 return NULL;
       
   288             }
       
   289         }
       
   290     else
       
   291         {
       
   292         return NULL;
       
   293         }
       
   294     }
       
   295 //---------------------------------------------------------------------------
       
   296 // 
       
   297 //---------------------------------------------------------------------------
       
   298 //
       
   299 CSenElement* CPolicyRequest::PolicyL( const TDesC8& aUri )	//codescannerwarnings
       
   300     {
       
   301     if( aUri.Length() < 1 )    
       
   302         {
       
   303         return NULL;
       
   304         }
       
   305     TInt indx = LookForUri(aUri);
       
   306     if(indx != KErrNotFound)
       
   307         {
       
   308         CPolicyReq* req = iPolicies[indx];
       
   309         CWSPolicy* pol = req->Policy();
       
   310         if(pol)
       
   311             {
       
   312             return pol->PolicyL();	//codescannerwarning
       
   313             }
       
   314         }
       
   315     return NULL;
       
   316     }
       
   317 //---------------------------------------------------------------------------
       
   318 // 
       
   319 //---------------------------------------------------------------------------
       
   320 //
       
   321 CSenElement* CPolicyRequest::OriginalPolicyL( const TDesC8& aUri )	//codescannerwarnings
       
   322     {
       
   323     if( aUri.Length() < 1 )    
       
   324         {
       
   325         return NULL;
       
   326         }
       
   327     TInt indx = LookForUri( aUri );
       
   328     if(indx != KErrNotFound)
       
   329         {
       
   330         CPolicyReq* req = iPolicies[indx];
       
   331         CWSPolicy* pol = req->Policy();
       
   332         if( pol )
       
   333             {
       
   334             return pol->NonNormalizedPolicyL();		//codescannerwarning
       
   335             }
       
   336         }
       
   337     return NULL;    
       
   338     }
       
   339 
       
   340 //---------------------------------------------------------------------------
       
   341 // 
       
   342 //---------------------------------------------------------------------------
       
   343 //  
       
   344 CPolicyReq* CPolicyReq::NewL(const TDesC8& aUri)
       
   345 {
       
   346     CPolicyReq* self   = CPolicyReq::NewLC(aUri);
       
   347     CleanupStack::Pop();
       
   348     return self;
       
   349     
       
   350 }
       
   351 //---------------------------------------------------------------------------
       
   352 // 
       
   353 //---------------------------------------------------------------------------
       
   354 //
       
   355 CPolicyReq* CPolicyReq::NewLC(const TDesC8& aUri)
       
   356 {
       
   357     CPolicyReq* self   = new (ELeave) CPolicyReq();
       
   358     CleanupStack::PushL (self);
       
   359     self->ConstructL(aUri);
       
   360     return self;
       
   361     
       
   362 }
       
   363 //---------------------------------------------------------------------------
       
   364 // 
       
   365 //---------------------------------------------------------------------------
       
   366 //
       
   367 CPolicyReq::~CPolicyReq()
       
   368 {
       
   369     delete iPolicy;
       
   370     delete iName; //policy name
       
   371     delete iURI; //uri to download
       
   372     delete iContents; //contents
       
   373     
       
   374 }
       
   375 //---------------------------------------------------------------------------
       
   376 // 
       
   377 //---------------------------------------------------------------------------
       
   378 //
       
   379 TPtrC8  CPolicyReq::Name()
       
   380 {
       
   381     if (iName != NULL)
       
   382     return iName->Des();
       
   383     else
       
   384     return KNullDesC8();
       
   385 }
       
   386 //---------------------------------------------------------------------------
       
   387 // 
       
   388 //---------------------------------------------------------------------------
       
   389 //
       
   390 TPtrC8  CPolicyReq::URI()
       
   391 {
       
   392         if (iURI != NULL)
       
   393         return iURI->Des();
       
   394     else
       
   395         return KNullDesC8();
       
   396     
       
   397 }
       
   398 //---------------------------------------------------------------------------
       
   399 // 
       
   400 //---------------------------------------------------------------------------
       
   401 //
       
   402 TPtrC8  CPolicyReq::Contents()
       
   403 {
       
   404     if (iContents != NULL)
       
   405         return iContents->Des();
       
   406     else
       
   407         return KNullDesC8();
       
   408 }
       
   409 //---------------------------------------------------------------------------
       
   410 // 
       
   411 //---------------------------------------------------------------------------
       
   412 //
       
   413 TInt    CPolicyReq::SetNameL(const TDesC8& aName)
       
   414 {
       
   415     if(aName.Length() < 1)    
       
   416     return KErrArgument;
       
   417 
       
   418     if (iName != NULL)
       
   419     {
       
   420         delete iName;
       
   421         iName = NULL;
       
   422     }
       
   423 
       
   424    iName = aName.AllocL(); 
       
   425    return KErrNone;
       
   426      
       
   427 }
       
   428 //---------------------------------------------------------------------------
       
   429 // 
       
   430 //---------------------------------------------------------------------------
       
   431 //
       
   432 TInt    CPolicyReq::SetContentsL(const TDesC8& aContent)
       
   433 {
       
   434     if(aContent.Length() < 1)    
       
   435     return KErrArgument;
       
   436 
       
   437     if (iContents != NULL)
       
   438     {
       
   439         delete iContents;
       
   440         iContents = NULL;
       
   441     }
       
   442 
       
   443    iContents = aContent.AllocL();     
       
   444    return KErrNone;
       
   445     
       
   446 }
       
   447 //---------------------------------------------------------------------------
       
   448 // 
       
   449 //---------------------------------------------------------------------------
       
   450 //
       
   451 CPolicyReq::CPolicyReq() : 
       
   452 iPolicy(NULL), iName(NULL),iURI(NULL),iContents(NULL)
       
   453 {
       
   454     
       
   455 }
       
   456 //---------------------------------------------------------------------------
       
   457 // 
       
   458 //---------------------------------------------------------------------------
       
   459 //
       
   460 void CPolicyReq::ConstructL(const TDesC8& aUri)
       
   461 {
       
   462     if(aUri.Length() < 1)    
       
   463     User::Leave (KErrArgument);
       
   464         
       
   465     iURI = aUri.AllocL();
       
   466 }
       
   467 //---------------------------------------------------------------------------
       
   468 // 
       
   469 //---------------------------------------------------------------------------
       
   470 //
       
   471 CWSPolicy* CPolicyReq::Policy()
       
   472 {
       
   473     return iPolicy;    
       
   474 }
       
   475 //---------------------------------------------------------------------------
       
   476 // 
       
   477 //---------------------------------------------------------------------------
       
   478 //
       
   479 TInt CPolicyReq::SetPolicy(CWSPolicy* aPolicy)
       
   480 {
       
   481     if(iPolicy)    
       
   482     {
       
   483         delete iPolicy;
       
   484         iPolicy = NULL;
       
   485     }
       
   486     
       
   487     iPolicy = aPolicy;
       
   488     return KErrNone;
       
   489 }
       
   490 //---------------------------------------------------------------------------
       
   491 // 
       
   492 //---------------------------------------------------------------------------
       
   493 //
       
   494 CPolicyReqMap* CPolicyReqMap::NewL(const TDesC8& aContract)
       
   495 {
       
   496     CPolicyReqMap* self   = CPolicyReqMap::NewLC(aContract);
       
   497     CleanupStack::Pop();
       
   498     return self;
       
   499     
       
   500 }
       
   501 //---------------------------------------------------------------------------
       
   502 // 
       
   503 //---------------------------------------------------------------------------
       
   504 //
       
   505 CPolicyReqMap* CPolicyReqMap::NewLC(const TDesC8& aContract)
       
   506 {
       
   507     CPolicyReqMap* self   = new (ELeave) CPolicyReqMap();
       
   508     CleanupStack::PushL (self);
       
   509     self->ConstructL(aContract);
       
   510     return self;
       
   511     
       
   512 }
       
   513 //---------------------------------------------------------------------------
       
   514 // 
       
   515 //---------------------------------------------------------------------------
       
   516 //
       
   517 CPolicyReqMap::CPolicyReqMap(): iURI(NULL), iContents(NULL), iSD(NULL) 
       
   518 {
       
   519     
       
   520 }
       
   521 //---------------------------------------------------------------------------
       
   522 // 
       
   523 //---------------------------------------------------------------------------
       
   524 //
       
   525 CPolicyReqMap::~CPolicyReqMap()
       
   526 {
       
   527     delete iContract; //service contract
       
   528     delete iURI; //uri to download
       
   529     delete iContents; //contents
       
   530 }
       
   531 //---------------------------------------------------------------------------
       
   532 // 
       
   533 //---------------------------------------------------------------------------
       
   534 //
       
   535 void CPolicyReqMap::ConstructL(const TDesC8& aContract)
       
   536 {
       
   537     if (aContract.Length() > 0)    
       
   538         iContract = aContract.AllocL();
       
   539         
       
   540 }
       
   541 //---------------------------------------------------------------------------
       
   542 // 
       
   543 //---------------------------------------------------------------------------
       
   544 //
       
   545 TPtrC8  CPolicyReqMap::Contract()
       
   546 {
       
   547     if(iContract)
       
   548         return iContract->Des();
       
   549     else
       
   550         return KNullDesC8();
       
   551     
       
   552 }
       
   553 //---------------------------------------------------------------------------
       
   554 // 
       
   555 //---------------------------------------------------------------------------
       
   556 //
       
   557 TPtrC8  CPolicyReqMap::Uri()
       
   558 {
       
   559     if(iURI)
       
   560         return iURI->Des();
       
   561     else
       
   562         return KNullDesC8();
       
   563 }
       
   564 //---------------------------------------------------------------------------
       
   565 // 
       
   566 //---------------------------------------------------------------------------
       
   567 //
       
   568 TPtrC8  CPolicyReqMap::Contents()
       
   569 {
       
   570     if(iContents)
       
   571         return iContents->Des();
       
   572     else
       
   573         return KNullDesC8();
       
   574 }
       
   575 //---------------------------------------------------------------------------
       
   576 // 
       
   577 //---------------------------------------------------------------------------
       
   578 //
       
   579 TInt    CPolicyReqMap::SetUriL(const TDesC8& aUri)
       
   580 {
       
   581     if(aUri.Length() > 0)
       
   582     {
       
   583         iURI = aUri.AllocL();
       
   584         return KErrNone;
       
   585     }
       
   586     return KErrArgument;
       
   587     
       
   588 }
       
   589 //---------------------------------------------------------------------------
       
   590 // 
       
   591 //---------------------------------------------------------------------------
       
   592 //
       
   593 TInt    CPolicyReqMap::SetContentsL(const TDesC8& aContent)
       
   594 {
       
   595 
       
   596     if(iContents)
       
   597     {
       
   598         delete iContents;
       
   599         iContents = NULL;
       
   600     }
       
   601 
       
   602     if(aContent.Length() > 0)
       
   603     {
       
   604         iContents = aContent.AllocL();
       
   605     }
       
   606     return KErrNone;
       
   607     
       
   608 }
       
   609 //---------------------------------------------------------------------------
       
   610 // 
       
   611 //---------------------------------------------------------------------------
       
   612 //
       
   613 CSenWSDescription* CPolicyReqMap::ServiceDescription()
       
   614 {
       
   615     return iSD;
       
   616 }
       
   617 //---------------------------------------------------------------------------
       
   618 // 
       
   619 //---------------------------------------------------------------------------
       
   620 //
       
   621 TInt CPolicyReqMap::SetSD(CSenWSDescription* aSD)
       
   622 {
       
   623     iSD  =   aSD; 
       
   624     return KErrNone;
       
   625 }
       
   626 // END OF FILE
       
   627 
       
   628 
       
   629 
       
   630