networksecurity/ipsec/ipsecpolparser/src/spdb.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // spdb.cpp - security policy database module
       
    15 // "Runtime" methods of "CSecurityPolicy" class
       
    16 //
       
    17 
       
    18 #include <networking/pfkeyv2.h>
       
    19 #include "spdb.h"
       
    20 
       
    21 //
       
    22 //  CPolicySelector
       
    23 //
       
    24 CPolicySelector::CPolicySelector()
       
    25     {}
       
    26 
       
    27 EXPORT_C CPolicySelector*
       
    28 CPolicySelector::NewL()
       
    29     {
       
    30     CPolicySelector* self = new (ELeave) CPolicySelector();
       
    31     self->Construct();
       
    32     return self;
       
    33     }
       
    34 
       
    35 EXPORT_C void
       
    36 CPolicySelector::Construct()
       
    37     {
       
    38     iIcmpType = -1;           // used, if != -1
       
    39     iType = -1;               // used, if != -1
       
    40     iIcmpCode = -1;           // used, if != -1
       
    41     iGlobalSelector = EFalse; // the global flag defaults to false
       
    42     iIsFinal = EFalse;
       
    43     iIsMerge = EFalse;
       
    44     iDirection = KPolicySelector_SYMMETRIC;
       
    45     iDropAction = EFalse;
       
    46     iProtocol = 0;
       
    47 
       
    48     // Init addresses to undefined    
       
    49     iLocal.SetFamily(KAFUnspec);
       
    50     iLocalMask.SetFamily(KAFUnspec);
       
    51     iRemote.SetFamily(KAFUnspec);
       
    52     iRemoteMask.SetFamily(KAFUnspec);
       
    53     
       
    54     // Clear interface name
       
    55     iInterface.Zero();
       
    56     
       
    57     // Init Endpoint names to NULL
       
    58     iLocSelEpName = NULL;
       
    59     iLocMaskEpName = NULL;
       
    60     iRemSelEpName = NULL;
       
    61     iRemMaskEpName = NULL;
       
    62     
       
    63     iSequenceNumber = 0;
       
    64     iCompWord = 0;
       
    65     }
       
    66 
       
    67 EXPORT_C CPolicySelector*
       
    68 CPolicySelector::NewL(CPolicySelector* aPS)
       
    69     {
       
    70     CPolicySelector* self = new (ELeave) CPolicySelector();
       
    71     CleanupStack::PushL(self);
       
    72     self->ConstructL(aPS);
       
    73     CleanupStack::Pop();
       
    74     return self;
       
    75     }
       
    76 
       
    77 EXPORT_C void
       
    78 CPolicySelector::ConstructL(CPolicySelector* aPS)
       
    79     {
       
    80     iDirection = aPS->iDirection;
       
    81     iRemote = aPS->iRemote;         // including port selector, if port non-zero
       
    82     iRemoteMask = aPS->iRemoteMask; // only address part used, as a mask
       
    83     iLocal = aPS->iLocal;           // including port selector, if port non-zero
       
    84     iLocalMask = aPS->iLocalMask;   // only address part used, as a mask
       
    85     iProtocol = aPS->iProtocol;     // used, if non-zero
       
    86     iIcmpType = aPS->iIcmpType;     // used, if != -1
       
    87     iType = aPS->iType;             // used, if != -1
       
    88     iIcmpCode = aPS->iIcmpCode;     // used, if != -1
       
    89     iGlobalSelector = aPS->iGlobalSelector;
       
    90     iIsFinal = aPS->iIsFinal;
       
    91     iIsMerge = aPS->iIsMerge;
       
    92     iDropAction = aPS->iDropAction;
       
    93     iInterface = aPS->iInterface;
       
    94     
       
    95     iSequenceNumber = aPS->iSequenceNumber;
       
    96     iCompWord = aPS->iSequenceNumber;
       
    97 
       
    98     // Copy EndPoint names    
       
    99     if (aPS->iLocSelEpName && aPS->iLocSelEpName->Length())
       
   100         {
       
   101         iLocSelEpName = HBufC8::NewL(aPS->iLocSelEpName->Length());
       
   102         *iLocSelEpName = *aPS->iLocSelEpName;
       
   103         }
       
   104     if (aPS->iLocMaskEpName && aPS->iLocMaskEpName->Length())
       
   105         {
       
   106         iLocMaskEpName = HBufC8::NewL(aPS->iLocMaskEpName->Length());
       
   107         *iLocMaskEpName = *aPS->iLocMaskEpName;
       
   108         }
       
   109     if (aPS->iRemSelEpName && aPS->iRemSelEpName->Length())
       
   110         {
       
   111         iRemSelEpName = HBufC8::NewL(aPS->iRemSelEpName->Length());
       
   112         *iRemSelEpName = *aPS->iRemSelEpName;
       
   113         }
       
   114     if (aPS->iRemMaskEpName && aPS->iRemMaskEpName->Length())
       
   115         {
       
   116         iRemMaskEpName = HBufC8::NewL(aPS->iRemMaskEpName->Length());
       
   117         *iRemMaskEpName = *aPS->iRemMaskEpName;
       
   118         }
       
   119 
       
   120     TSecpolBundleIter iterl(aPS->iBundle);
       
   121     CSecpolBundleItem* itemL(NULL);
       
   122     CSecpolBundleItem* newItemL(NULL);
       
   123     while ((itemL = iterl++) != NULL)
       
   124         {
       
   125         newItemL = new (ELeave) CSecpolBundleItem;
       
   126         
       
   127         // Points to the same SA
       
   128         newItemL->iSpec = itemL->iSpec;      
       
   129         
       
   130         // No need to fill iNext. Is filled when adding
       
   131         newItemL->iTunnel = itemL->iTunnel;  
       
   132         iBundle.AddLast(*newItemL);
       
   133         }
       
   134 
       
   135     iNext = aPS->iNext;
       
   136     }
       
   137 
       
   138 CSecpolBundleItem*
       
   139 CPolicySelector::FindBundleL(TInt aIndex)
       
   140     {
       
   141     TSecpolBundleIter iterL(iBundle);
       
   142     CSecpolBundleItem* itemL(NULL);
       
   143     CSecpolBundleItem* newItemL(NULL);
       
   144     TInt i = 0;
       
   145     while (((itemL = iterL++) != NULL) && (i < aIndex))
       
   146         {
       
   147         i++;
       
   148         }
       
   149 
       
   150     // The element exists. We create a copy
       
   151     if ((i == aIndex) && (itemL != NULL))    
       
   152         {
       
   153         newItemL = new (ELeave) CSecpolBundleItem;
       
   154         
       
   155         // Need a copy to have separed bundle lists
       
   156         newItemL->iSpec = itemL->iSpec;      
       
   157         
       
   158         // No need to fill iNext. Is filled when adding
       
   159         newItemL->iTunnel = itemL->iTunnel;  
       
   160         }
       
   161 
       
   162     return newItemL;
       
   163     }
       
   164 
       
   165 CSecpolBundleItem::~CSecpolBundleItem()
       
   166     {
       
   167     delete iTunnelEpName;
       
   168     }
       
   169 
       
   170 EXPORT_C
       
   171 CPolicySelector::~CPolicySelector()
       
   172     {
       
   173     TSecpolBundleIter iterl(iBundle);
       
   174     CSecpolBundleItem* itemL(NULL);
       
   175     while ((itemL = iterl++) != NULL)
       
   176         {
       
   177         iBundle.Remove(*itemL);
       
   178         delete itemL;
       
   179         }
       
   180 
       
   181     delete iRemSelEpName;
       
   182     delete iRemMaskEpName;
       
   183     delete iLocMaskEpName;
       
   184     delete iLocSelEpName;
       
   185     }
       
   186 
       
   187 // Match a selector against the packet information
       
   188 //
       
   189 // Returns 0, if selector does not match the information
       
   190 //         1, if selector matches the information
       
   191 TInt
       
   192 CPolicySelector::Match(
       
   193     const TInetAddr &aSrc,         // The src address, and port if known
       
   194     const TInetAddr &aDst,         // The dst address, and port if known
       
   195     TInt aProtocol,                // Transport protocol, if > 0 (known)
       
   196     TInt aIcmpType,                // ICMP Type, if ICMP (-1 otherwise)
       
   197     TInt aIcmpCode,                // ICMP Code, if ICMP (-1 otherwise)
       
   198     TInt aType) const              // Type code, (-1 if not used)
       
   199     {
       
   200     return (aDst.Match(iRemote, iRemoteMask)
       
   201             && aSrc.Match(iLocal, iLocalMask)
       
   202             && (iProtocol == 0 || iProtocol == aProtocol)
       
   203             && (iRemote.Port() == 0 || iRemote.Port() == aDst.Port())
       
   204             && (iLocal.Port() == 0 || iLocal.Port() == aDst.Port())
       
   205             && (iIcmpType == -1 || iIcmpType == aIcmpType)
       
   206             && (iIcmpCode == -1 || iIcmpCode == aIcmpCode)
       
   207             && (iType == -1 || iType == aType));
       
   208     }
       
   209 
       
   210 // Checks if this policy is using this SA
       
   211 EXPORT_C TBool
       
   212 CPolicySelector::UseSA(CPolicySpec* aSA, TInetAddr* tunnel)
       
   213     {
       
   214     TSecpolBundleIter iterBundle(iBundle);
       
   215     CSecpolBundleItem* itemBundle(NULL);
       
   216 
       
   217     while ((itemBundle = iterBundle++) != NULL)
       
   218         {
       
   219         if (itemBundle->iSpec)
       
   220             {
       
   221             // SA used in a Policy. 2 SA cannot have the same name
       
   222             if (!(itemBundle->iSpec->iName->Compare(*aSA->iName)))
       
   223                 {
       
   224                 if (tunnel)
       
   225                     {
       
   226                     *tunnel = itemBundle->iTunnel;
       
   227                     }
       
   228                 return ETrue;
       
   229                 }
       
   230             }
       
   231         }
       
   232 
       
   233     return EFalse;  // This selector doesn't use the SA
       
   234     }
       
   235 
       
   236 //
       
   237 // CSAPairList: Translation table used when copying a policy
       
   238 CSAPairList::~CSAPairList()
       
   239     {
       
   240     TSAPairNode* next(NULL);
       
   241     TSAPairNode* node(iList);
       
   242     while (node)
       
   243         {
       
   244         next = node->iNext;
       
   245         delete node;
       
   246         node = next;
       
   247         }
       
   248     }
       
   249 
       
   250 //
       
   251 // Add at the begining to make it faster
       
   252 void
       
   253 CSAPairList::AddL(CPolicySpec* aOldSA, CPolicySpec* aNewSA)
       
   254     {
       
   255     TSAPairNode* node = new (ELeave) TSAPairNode;
       
   256     node->iOldSA = aOldSA;
       
   257     node->iNewSA = aNewSA;
       
   258     node->iNext = iList;
       
   259     iList = node;
       
   260     }
       
   261 
       
   262 CPolicySpec*
       
   263 CSAPairList::Translate(CPolicySpec* aOldSA)
       
   264     {
       
   265     TSAPairNode* node = iList;
       
   266     while (node)
       
   267         {
       
   268         if (node->iOldSA == aOldSA)
       
   269             return node->iNewSA;
       
   270         node = node->iNext;
       
   271         }
       
   272 
       
   273     // Not found
       
   274     return(NULL);
       
   275     }
       
   276 
       
   277 EXPORT_C
       
   278 CSecurityPolicy::CSecurityPolicy()
       
   279     {}
       
   280 
       
   281 EXPORT_C void
       
   282 CSecurityPolicy::ConstructL()
       
   283     {
       
   284     iSpecs = CSAList::NewL(1);
       
   285     iSelectors = CSelectorList::NewL(1);
       
   286     }
       
   287 
       
   288 // Creates a Security Policy from an existing one
       
   289 EXPORT_C void
       
   290 CSecurityPolicy::ConstructL(CSecurityPolicy* aSecPol)
       
   291     {
       
   292     // Creates a new SA List with new SA nodes!!!
       
   293     if (aSecPol->SAList()->Count() > 0)
       
   294         {
       
   295         iSpecs = CSAList::NewL(aSecPol->SAList());
       
   296         }
       
   297     else
       
   298         {
       
   299         iSpecs = CSAList::NewL(1);
       
   300         }
       
   301 
       
   302     // The selector bundles use references to the old SA nodes
       
   303     // so if we copy only the content we'll have invalid references.
       
   304     // Therefore, we need a translations tables from old nodes to new
       
   305     // ones to pass it to the selector constructor
       
   306     if (aSecPol->SelectorList()->Count() > 0)
       
   307         {
       
   308         CSAPairList* table = CreateTranslationTableL(aSecPol->SAList(), iSpecs);
       
   309         CleanupStack::PushL(table);
       
   310         iSelectors = CSelectorList::NewL(aSecPol->SelectorList(), table);
       
   311 
       
   312         // The table is not needed anymore
       
   313         CleanupStack::PopAndDestroy();
       
   314         }
       
   315     else
       
   316         {
       
   317         iSelectors = CSelectorList::NewL(1);
       
   318         }
       
   319     }
       
   320 
       
   321 CSAPairList*
       
   322 CSecurityPolicy::CreateTranslationTableL(
       
   323     CSAList* aOldSAList,
       
   324     CSAList* aNewSAList)
       
   325     {
       
   326     CSAPairList* table = new (ELeave) CSAPairList;
       
   327     CleanupStack::PushL(table);
       
   328     TInt count(aOldSAList->Count());
       
   329     for (TInt i = 0; i < count; i++)
       
   330         {
       
   331         table->AddL(aOldSAList->At(i), aNewSAList->At(i));
       
   332         }
       
   333     CleanupStack::Pop();
       
   334     return (table);
       
   335     }
       
   336 
       
   337 CSecurityPolicy::~CSecurityPolicy()
       
   338     {
       
   339     if (iSpecs)
       
   340         {
       
   341         // Deletes all the elems in the list
       
   342         TInt count(iSpecs->Count());
       
   343         for (TInt i = 0; i < count; i++) 
       
   344             {
       
   345             delete iSpecs->At(i);
       
   346             }
       
   347         delete iSpecs;
       
   348         iSpecs = NULL;
       
   349         }
       
   350 
       
   351     if (iSelectors)
       
   352         {
       
   353         // Deletes all the elems in the list
       
   354         TInt count(iSelectors->Count());
       
   355         for (TInt i = 0; i < count; i++) 
       
   356             {
       
   357             delete iSelectors->At(i);
       
   358             }
       
   359         delete iSelectors;
       
   360         iSelectors = NULL;
       
   361         }
       
   362     }
       
   363 
       
   364 TSecpolBundle*
       
   365 CSecurityPolicy::FindBundle(
       
   366     TUint aDirection,              // Direction flag
       
   367     const TInetAddr& aSrc,         // Source Address (and optionally port)
       
   368     const TInetAddr& aDst,         // Destination Address (and optionally port)
       
   369     TInt aProtocol,                // Transport protocol (if > 0)
       
   370     TInt aIcmpType,                // (if != -1)
       
   371     TInt aIcmpCode,                // (if != -1)
       
   372     TInt aType)                    // (if != -1)
       
   373     {
       
   374     TInt count(iSelectors->Count());
       
   375     for (TInt i = 0; i < count; i++)
       
   376         {
       
   377         CPolicySelector* selector = iSelectors->At(i);
       
   378         if ((selector->iDirection & aDirection)
       
   379             && selector->Match(aSrc, 
       
   380                                aDst, 
       
   381                                aProtocol, 
       
   382                                aIcmpType, 
       
   383                                aIcmpCode, 
       
   384                                aType))
       
   385             {
       
   386             return (&selector->iBundle);
       
   387             }
       
   388         }
       
   389 
       
   390     return (NULL);
       
   391     }
       
   392 
       
   393 TInt
       
   394 CSecurityPolicy::SearchForEPNameL(TDesC& aTokenString)
       
   395     {
       
   396     TInt err(KErrNotFound);
       
   397     HBufC8* name = HBufC8::NewL(aTokenString.Length());
       
   398     name->Des().Copy(aTokenString);
       
   399 
       
   400     // Iterate through the policy specification list
       
   401     TInt count(iSpecs->Count());
       
   402     for (TInt i = 0; i < count; i++)
       
   403         {
       
   404         CPolicySpec* polSpec = iSpecs->At(i);
       
   405         // Check if spesification type is EndPoint and name for it exists
       
   406         if (polSpec->iSpectype == EPolSpecEP && polSpec->iName)
       
   407             {
       
   408             // Compare EndPoint name against given name
       
   409             if (name->Des().Compare(polSpec->iName->Des()) == 0)
       
   410                 {
       
   411                 // Match found so set return value to success
       
   412                 err = KErrNone;
       
   413                 break;
       
   414                 }
       
   415             }
       
   416         }
       
   417 
       
   418     // Free memory allocated for name and then return
       
   419     delete name;
       
   420     return (err);
       
   421     }
       
   422 
       
   423 EXPORT_C CPolicySpec*
       
   424 CSecurityPolicy::FindSpec(const TDesC8& aName)
       
   425     {
       
   426     CPolicySpec* spec(NULL);
       
   427     TInt count(iSpecs->Count());
       
   428     for (TInt i = 0; i < count; i++)
       
   429         {
       
   430         spec = iSpecs->At(i);
       
   431         if ((*spec->iName).Compare(aName) == 0)
       
   432             {
       
   433             return spec;
       
   434             }
       
   435         }
       
   436     return (NULL);
       
   437     }
       
   438 
       
   439 //
       
   440 //  CPolicySpec
       
   441 //
       
   442 CPolicySpec::CPolicySpec()
       
   443     {
       
   444 #ifdef SYMBIAN_IPSEC_VOIP_SUPPORT      
       
   445     iPropList = CPropList::NewL(1);
       
   446 #endif
       
   447     }
       
   448 
       
   449 EXPORT_C CPolicySpec*
       
   450 CPolicySpec::NewL()
       
   451     {
       
   452     CPolicySpec* self = new (ELeave) CPolicySpec();
       
   453     self->Construct();
       
   454     return self;
       
   455     }
       
   456 
       
   457 EXPORT_C void
       
   458 CPolicySpec::Construct()
       
   459     {
       
   460     iEpSpec.iIsOptional = EFalse;
       
   461     iEpSpec.iEpAddr = NULL;
       
   462     }
       
   463 
       
   464 EXPORT_C CPolicySpec*
       
   465 CPolicySpec::NewL(TDesC& aName, TPolicySpecType iSpectype)
       
   466     {
       
   467     CPolicySpec* self = new (ELeave) CPolicySpec();
       
   468     CleanupStack::PushL(self);
       
   469     self->ConstructL(aName, iSpectype);
       
   470     CleanupStack::Pop();
       
   471     return self;
       
   472     }
       
   473 
       
   474 EXPORT_C void
       
   475 CPolicySpec::ConstructL(TDesC& aName, TPolicySpecType aSpectype)
       
   476     {
       
   477     iName = HBufC8::NewL(aName.Length());
       
   478     iName->Des().Copy(aName);
       
   479     iSpectype = aSpectype;
       
   480     }
       
   481 
       
   482 // Used to initialize with an existing CPolicySpec
       
   483 EXPORT_C CPolicySpec*
       
   484 CPolicySpec::NewL(CPolicySpec* aPolSpec)
       
   485     {
       
   486     CPolicySpec* self = new (ELeave) CPolicySpec();
       
   487     CleanupStack::PushL(self);
       
   488     self->ConstructL(aPolSpec);
       
   489     CleanupStack::Pop();
       
   490     return self;
       
   491     }
       
   492 
       
   493 EXPORT_C void
       
   494 CPolicySpec::ConstructL(CPolicySpec* aPolSpec)
       
   495     {
       
   496     // Always bigger than 0
       
   497     iName = HBufC8::NewL(aPolSpec->iName->Length()); 
       
   498     *iName = *aPolSpec->iName;
       
   499 
       
   500     if (aPolSpec->iRemoteIdentity)
       
   501         {
       
   502         iRemoteIdentity = HBufC8::NewL(aPolSpec->iRemoteIdentity->Length());
       
   503         *iRemoteIdentity = *aPolSpec->iRemoteIdentity;
       
   504         }
       
   505 
       
   506     if (aPolSpec->iLocalIdentity)
       
   507         {
       
   508         iLocalIdentity = HBufC8::NewL(aPolSpec->iLocalIdentity->Length());
       
   509         *iLocalIdentity = *aPolSpec->iLocalIdentity;
       
   510         }
       
   511     iSpec = aPolSpec->iSpec;
       
   512     // Even the queue position is cloned    
       
   513     iNext = aPolSpec->iNext;  
       
   514     }
       
   515 
       
   516 EXPORT_C
       
   517 CPolicySpec::~CPolicySpec()
       
   518     {
       
   519     delete iName;
       
   520     delete iRemoteIdentity;
       
   521     delete iLocalIdentity;
       
   522 #ifdef SYMBIAN_IPSEC_VOIP_SUPPORT      
       
   523       if (iPropList)
       
   524         {
       
   525         // Deletes all the elems in the list
       
   526         TInt count(iPropList->Count());
       
   527         for (TInt i = 0; i < count; i++) 
       
   528             {
       
   529             delete iPropList->At(i);
       
   530             }
       
   531         delete iPropList;
       
   532         iPropList = NULL;       
       
   533         }
       
   534 #endif       
       
   535     }
       
   536 #ifdef SYMBIAN_IPSEC_VOIP_SUPPORT  
       
   537 // CPropList
       
   538 CPropList::CPropList(TInt aGranularity) :
       
   539     CArrayFixFlat<CSecurityProposalSpec *>(aGranularity)
       
   540     {}
       
   541 
       
   542 CPropList*
       
   543 CPropList::NewL(TInt aGranularity)
       
   544     {
       
   545     CPropList* self = new (ELeave) CPropList(aGranularity);
       
   546     self->Construct(aGranularity);
       
   547     return self;
       
   548     }
       
   549 
       
   550 void
       
   551 CPropList::Construct(TInt /* aGranularity */)
       
   552     {}
       
   553 
       
   554 CPropList::CPropList(CPropList* aSAList) :
       
   555     CArrayFixFlat<CSecurityProposalSpec *>(aSAList->Count())
       
   556     {}
       
   557 
       
   558 CPropList*
       
   559 CPropList::NewL(CPropList* aSAList)
       
   560     {
       
   561     CPropList* self = new (ELeave) CPropList(aSAList);
       
   562     CleanupStack::PushL(self);
       
   563     self->ConstructL(aSAList);
       
   564     CleanupStack::Pop();
       
   565     return self;
       
   566     }
       
   567 
       
   568 void
       
   569 CPropList::ConstructL(CPropList* aSAList)
       
   570     {
       
   571     TInt count(aSAList->Count());
       
   572  
       
   573     }
       
   574 #endif    
       
   575 // CSAList
       
   576 CSAList::CSAList(TInt aGranularity) :
       
   577     CArrayFixFlat<CPolicySpec *>(aGranularity)
       
   578     {}
       
   579 
       
   580 EXPORT_C CSAList*
       
   581 CSAList::NewL(TInt aGranularity)
       
   582     {
       
   583     CSAList* self = new (ELeave) CSAList(aGranularity);
       
   584     self->Construct(aGranularity);
       
   585     return self;
       
   586     }
       
   587 
       
   588 EXPORT_C void
       
   589 CSAList::Construct(TInt /* aGranularity */)
       
   590     {}
       
   591 
       
   592 CSAList::CSAList(CSAList* aSAList) :
       
   593     CArrayFixFlat<CPolicySpec *>(aSAList->Count())
       
   594     {}
       
   595 
       
   596 EXPORT_C CSAList*
       
   597 CSAList::NewL(CSAList* aSAList)
       
   598     {
       
   599     CSAList* self = new (ELeave) CSAList(aSAList);
       
   600     CleanupStack::PushL(self);
       
   601     self->ConstructL(aSAList);
       
   602     CleanupStack::Pop();
       
   603     return self;
       
   604     }
       
   605 
       
   606 EXPORT_C void
       
   607 CSAList::ConstructL(CSAList* aSAList)
       
   608     {
       
   609     TInt count(aSAList->Count());
       
   610     for (TInt i = 0; i < count; i++)
       
   611         {
       
   612         CPolicySpec* policy = CPolicySpec::NewL(aSAList->At(i));
       
   613         CleanupStack::PushL(policy);
       
   614         AppendL(policy);
       
   615         CleanupStack::Pop();
       
   616         }
       
   617     }
       
   618 
       
   619 //
       
   620 // CSelectorList
       
   621 //
       
   622 CSelectorList::CSelectorList(TInt aGranularity) :
       
   623     CArrayFixFlat<CPolicySelector *>(aGranularity)
       
   624     {}
       
   625 
       
   626 EXPORT_C CSelectorList*
       
   627 CSelectorList::NewL(TInt aGranularity)
       
   628     {
       
   629     CSelectorList* self = new (ELeave) CSelectorList(aGranularity);
       
   630     self->Construct(aGranularity);
       
   631     return self;
       
   632     }
       
   633 
       
   634 EXPORT_C void
       
   635 CSelectorList::Construct(TInt /*aGranularity*/)
       
   636     {}
       
   637 
       
   638 CSelectorList::CSelectorList(CSelectorList* aSelList,
       
   639                              CSAPairList* /* aTable */) :
       
   640     CArrayFixFlat<CPolicySelector *>(aSelList->Count())
       
   641     {}
       
   642 
       
   643 EXPORT_C CSelectorList*
       
   644 CSelectorList::NewL(CSelectorList* aSelList,
       
   645                     CSAPairList* aTable)
       
   646     {
       
   647     CSelectorList* self = new (ELeave) CSelectorList(aSelList, aTable);
       
   648     CleanupStack::PushL(self);
       
   649     self->ConstructL(aSelList, aTable);
       
   650     CleanupStack::Pop();
       
   651     return self;
       
   652     }
       
   653 
       
   654 EXPORT_C void
       
   655 CSelectorList::ConstructL(CSelectorList* aSelList,
       
   656                           CSAPairList* aTable)
       
   657     {
       
   658     TInt count(aSelList->Count());
       
   659     for (TInt i = 0; i < count; i++)
       
   660         {
       
   661         CPolicySelector* selector = CPolicySelector::NewL(aSelList->At(i));
       
   662         // Bundle translation
       
   663         TSecpolBundleIter iterL(selector->iBundle);
       
   664         CSecpolBundleItem* itemL(NULL);
       
   665         while (((itemL = iterL++) != NULL))
       
   666             {
       
   667             if (itemL->iSpec)
       
   668                 {
       
   669                 itemL->iSpec = aTable->Translate(itemL->iSpec);
       
   670                 }
       
   671             }
       
   672 
       
   673         // Specs in the Bundle translated
       
   674         CleanupStack::PushL(selector);
       
   675         AppendL(selector);
       
   676         CleanupStack::Pop();
       
   677         }
       
   678     }
       
   679