simpleengine/xdmrlspres/src/prescondmisc.cpp
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006 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:    RLS and Presence XDM, This class represents those parts of 
       
    15 *                 presence identity which are not present in any other class.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // Includes
       
    23 #include <XdmDocumentNode.h>
       
    24 #include <XdmNodeAttribute.h>
       
    25 #include <xcapappusagedef.h>
       
    26 #include <utf.h>
       
    27 
       
    28 #include "prescondmisc.h"
       
    29 #include "cpresencexdm.h"
       
    30 #include "rlspresxdmlogger.h"
       
    31 #include "rlspresxdmconstsint.h"
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // TPresCondMisc::TPresCondMisc()
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 EXPORT_C TPresCondMisc::TPresCondMisc(): iPresXDM(NULL)
       
    39     {
       
    40     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::TPresCondMisc()" ));
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // TPresCondMisc::Init()
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 EXPORT_C void TPresCondMisc::Init(CPresenceXDM* const aPresXDM)
       
    48     {
       
    49     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::Init(%d)" ), aPresXDM);
       
    50     iPresXDM = aPresXDM;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // TPresCondMisc::AddOtherIdentityL()
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C TInt TPresCondMisc::AddOtherIdentityL(const TDesC& aRuleId)
       
    58     {
       
    59     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::AddOtherIdentityL(%S)"), &aRuleId);
       
    60 	
       
    61     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
    62     
       
    63     TInt ret(KErrNotFound);
       
    64 	
       
    65 	CXdmDocumentNode* otherIdentityNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
    66 	                                                KXdmOtherIdentity, ETrue);
       
    67 	if(otherIdentityNode)
       
    68 	    ret = KErrNone;
       
    69 	
       
    70     OPENG_DP(D_OPENG_LIT( "     return: %d"),ret);
       
    71     return ret;
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // TPresCondMisc::IsOtherIdentityExistL()
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C TBool TPresCondMisc::IsOtherIdentityExistL(const TDesC& aRuleId)
       
    79     {
       
    80     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::IsOtherIdentityExistL(%S)"), &aRuleId);
       
    81 	
       
    82     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
    83     
       
    84     TBool ret(EFalse);
       
    85 	
       
    86 	CXdmDocumentNode* otherIdentityNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
    87 	                                                KXdmOtherIdentity, EFalse);
       
    88 	if(otherIdentityNode)
       
    89 	    ret = ETrue;
       
    90 	
       
    91     OPENG_DP(D_OPENG_LIT( "     return: %d"),ret);
       
    92     return ret;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // TPresCondMisc::RemoveOtherIdentityL()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C TInt TPresCondMisc::RemoveOtherIdentityL(const TDesC& aRuleId)
       
   100     {
       
   101     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::RemoveOtherIdentityL(%S)"), &aRuleId);
       
   102 	
       
   103     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   104     
       
   105     TInt ret(KErrNotFound);
       
   106 	
       
   107 	CXdmDocumentNode* otherIdentityNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   108 	                                                KXdmOtherIdentity,EFalse);
       
   109 	if(otherIdentityNode)
       
   110 	    {
       
   111 	    iPresXDM->RemoveFromModelL(otherIdentityNode);
       
   112 	    ret = KErrNone;
       
   113 	    }
       
   114 	    
       
   115     OPENG_DP(D_OPENG_LIT( "     return: %d"),ret);
       
   116     return ret;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // TPresCondMisc::AddAnonymousRequestL()
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C TInt TPresCondMisc::AddAnonymousRequestL(const TDesC& aRuleId)
       
   124     {
       
   125     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::AddAnonymousRequestL(%S)"), &aRuleId);
       
   126 	
       
   127     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   128     
       
   129     TInt ret(KErrNotFound);
       
   130 	
       
   131 	CXdmDocumentNode* anonymousReqNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   132 	                                                KXdmAnonymousRequest, ETrue);
       
   133 	if(anonymousReqNode)
       
   134 	    ret = KErrNone;
       
   135 	
       
   136     OPENG_DP(D_OPENG_LIT( "     return: %d"),ret);
       
   137     return ret;
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // TPresCondMisc::IsAnonymousRequestExistL()
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 EXPORT_C TBool TPresCondMisc::IsAnonymousRequestExistL(const TDesC& aRuleId)
       
   145     {
       
   146     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::IsAnonymousRequestExistL(%S)"), &aRuleId);
       
   147 	
       
   148     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   149     
       
   150     TBool ret(EFalse);
       
   151 	
       
   152 	CXdmDocumentNode* anonymousReqNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   153 	                                                KXdmAnonymousRequest, EFalse);
       
   154 	if(anonymousReqNode)
       
   155 	    ret = ETrue;
       
   156 	
       
   157     OPENG_DP(D_OPENG_LIT( "     return: %d"),ret);
       
   158     return ret;
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // TPresCondMisc::RemoveAnonymousRequestL()
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C TInt TPresCondMisc::RemoveAnonymousRequestL(const TDesC& aRuleId)
       
   166     {
       
   167     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::RemoveAnonymousRequestL(%S)"), &aRuleId);
       
   168 	
       
   169     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   170     
       
   171     TInt ret(KErrNotFound);
       
   172 	
       
   173 	CXdmDocumentNode* anonymousReqNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   174 	                                                KXdmAnonymousRequest,EFalse);
       
   175 	if(anonymousReqNode)
       
   176 	    {
       
   177 	    iPresXDM->RemoveFromModelL(anonymousReqNode);
       
   178 	    ret = KErrNone;
       
   179 	    }
       
   180 	    
       
   181     OPENG_DP(D_OPENG_LIT( "     return: %d"),ret);
       
   182     return ret;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // TPresCondMisc::AddExternListL()
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 EXPORT_C TInt TPresCondMisc::AddExternListL(const TDesC& aRuleId, 
       
   190                                                             const TDesC& aUri)
       
   191     {
       
   192     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::AddExternListL()" ) );
       
   193     OPENG_DP(D_OPENG_LIT( "     aRuleId = %S, aUri = %S"),&aRuleId, &aUri);
       
   194 	
       
   195     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   196 	
       
   197 	CXdmDocumentNode* extListNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   198 	                                                KXdmExternalList, ETrue);
       
   199 	if(extListNode==NULL)
       
   200 	    return KErrNotFound;
       
   201 	
       
   202 	if(IsExternListExistL(aRuleId,aUri))
       
   203 	    return KErrAlreadyExists;
       
   204 	
       
   205     CXdmDocumentNode* entryNode(NULL);
       
   206     CXdmNodeAttribute* ancAttr(NULL);
       
   207    
       
   208     entryNode = extListNode->CreateChileNodeL(KXdmEntry);
       
   209     ancAttr = entryNode->CreateAttributeL(KXdmAnc);
       
   210     ancAttr->SetAttributeValueL(aUri);
       
   211     
       
   212     OPENG_DP(D_OPENG_LIT( "     return: KErrNone"));
       
   213     return KErrNone;
       
   214     }
       
   215     
       
   216 // ---------------------------------------------------------------------------
       
   217 // TPresCondMisc::IsExternListExistL()
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 EXPORT_C TBool TPresCondMisc::IsExternListExistL(const TDesC& aRuleId,
       
   221                                                             const TDesC& aUri)
       
   222     {
       
   223     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::IsExternListExistL()" ) );
       
   224     OPENG_DP(D_OPENG_LIT( "     aRuleId = %S, aUri = %S"),&aRuleId, &aUri);
       
   225 
       
   226     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   227 
       
   228 	CXdmDocumentNode* extListNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   229 	                                                KXdmExternalList, EFalse);
       
   230 	if(extListNode==NULL)
       
   231 	    return EFalse;
       
   232 
       
   233 	RPointerArray<CXdmDocumentNode> nodes;
       
   234     CXdmNodeAttribute* ancAttr(NULL);
       
   235 	
       
   236 	// finding entry nodes
       
   237     TInt err = extListNode->Find(KXdmEntry, nodes);
       
   238     
       
   239     // extracting lists from entry nodes
       
   240     TInt entriesCountInNode = nodes.Count();
       
   241     OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),entriesCountInNode);
       
   242     
       
   243     for (TInt i=0;i<entriesCountInNode;i++)
       
   244         { // get the anc attribute
       
   245         ancAttr = (nodes[i])->Attribute(KXdmAnc);
       
   246         if (aUri==(ancAttr->AttributeValue()))
       
   247             {
       
   248             OPENG_DP(D_OPENG_LIT( "     ETrue"));
       
   249             nodes.Close();
       
   250             return ETrue;               
       
   251             }
       
   252         }
       
   253 
       
   254     nodes.Close();    
       
   255     return EFalse;
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // TPresCondMisc::GetExternalListsL()
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 EXPORT_C void TPresCondMisc::GetExternalListsL(const TDesC& aRuleId, 
       
   263                                                             CDesCArray& aUris)
       
   264     {
       
   265     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::GetExternalListsL()" ) );
       
   266     OPENG_DP(D_OPENG_LIT( "     aRuleId = %S" ),&aRuleId);
       
   267     
       
   268     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   269     
       
   270 	CXdmDocumentNode* extListNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   271 	                                                KXdmExternalList, EFalse);
       
   272 	if(extListNode==NULL)
       
   273 	    return;
       
   274 	
       
   275 	RPointerArray<CXdmDocumentNode> nodes;
       
   276     CXdmNodeAttribute* ancAttr(NULL);
       
   277 	
       
   278 	// finding entry nodes
       
   279     TInt err = extListNode->Find(KXdmEntry, nodes);
       
   280     OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),nodes.Count());
       
   281 
       
   282     // extracting lists from entry nodes
       
   283     TInt entriesCountInNode = nodes.Count();
       
   284     for (TInt i=0;i<entriesCountInNode;i++)
       
   285         { // get the anc attribute
       
   286         ancAttr = (nodes[i])->Attribute(KXdmAnc);
       
   287         // push it to given discriptor array
       
   288         aUris.AppendL(ancAttr->AttributeValue());
       
   289         }
       
   290 
       
   291     nodes.Close();    
       
   292     return;
       
   293     }                                            
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // TPresCondMisc::DeleteExternalListL()
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 EXPORT_C TInt TPresCondMisc::DeleteExternalListL(const TDesC& aRuleId, 
       
   300                                                             const TDesC& aUri)
       
   301     {
       
   302     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::DeleteExternalListL()" ) );
       
   303     OPENG_DP(D_OPENG_LIT( "     aRuleId = %S, aUri = %S"),&aRuleId, &aUri);
       
   304 	
       
   305     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   306 	
       
   307 	TInt ret(KErrNotFound);
       
   308 	
       
   309 	CXdmDocumentNode* extListNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   310 	                                                KXdmExternalList, EFalse);
       
   311 	if(extListNode==NULL)
       
   312 	    return ret;
       
   313 
       
   314 	RPointerArray<CXdmDocumentNode> nodes;
       
   315     CXdmNodeAttribute* ancAttr(NULL);
       
   316 	
       
   317 	// finding entry nodes
       
   318     if ( (extListNode->Find(KXdmEntry, nodes))==KErrNone)
       
   319         {
       
   320         // extracting lists from entry nodes
       
   321         TInt entriesCountInNode = nodes.Count();
       
   322         OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),entriesCountInNode);
       
   323        
       
   324         for (TInt i=0;i<entriesCountInNode;i++)
       
   325             { // get the anc attribute
       
   326             ancAttr = (nodes[i])->Attribute(KXdmAnc);
       
   327             if (aUri==(ancAttr->AttributeValue()))
       
   328                 {
       
   329                 OPENG_DP(D_OPENG_LIT( "     RemoveFromModelL: i=%d" ),i);
       
   330                 iPresXDM->RemoveFromModelL(nodes[i]);
       
   331                 ret = KErrNone;
       
   332                 break;               
       
   333                 }
       
   334             }
       
   335         }
       
   336     nodes.Close();    
       
   337     return ret;
       
   338     }                                            
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // TPresCondMisc::DeleteAllExternalListsL()
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 EXPORT_C void TPresCondMisc::DeleteAllExternalListsL(const TDesC& aRuleId)
       
   345     {
       
   346     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::DeleteAllExternalListsL()" ) );
       
   347     OPENG_DP(D_OPENG_LIT( "     aRuleId = %S"),&aRuleId);
       
   348 	
       
   349     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   350 	
       
   351 	CXdmDocumentNode* extListNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   352 	                                                KXdmExternalList, EFalse);
       
   353 	if(extListNode==NULL)
       
   354 	    return;
       
   355 	
       
   356 	RPointerArray<CXdmDocumentNode> nodes;
       
   357 	
       
   358 	// finding entry nodes
       
   359     TInt err = extListNode->Find(KXdmEntry, nodes);
       
   360     
       
   361     // extracting lists from entry nodes
       
   362     TInt entriesCountInNode = nodes.Count();
       
   363     OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),entriesCountInNode);
       
   364     
       
   365     for (TInt i=0;i<entriesCountInNode;i++)
       
   366         {
       
   367         iPresXDM->RemoveFromModelL(nodes[i]);
       
   368         }
       
   369 
       
   370     nodes.Close();    
       
   371     return;
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // TPresCondMisc::DeleteAllExternalListsL()
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 EXPORT_C void TPresCondMisc::DeleteExternalListsL(const TDesC& aRuleId,
       
   379                                                     const MDesCArray& aUris)
       
   380     {
       
   381     OPENG_DP(D_OPENG_LIT( "TPresCondMisc::DeleteExternalListsL()" ) );
       
   382     OPENG_DP(D_OPENG_LIT( "     aRuleId = %S, aUrisCount = %d" ),&aRuleId, 
       
   383                                                         aUris.MdcaCount() );
       
   384 	
       
   385     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));                                                    
       
   386 	
       
   387 	CXdmDocumentNode* extListNode = iPresXDM->GetConditionChildNodeL(aRuleId, 
       
   388 	                                                KXdmExternalList, EFalse);
       
   389 	if(extListNode==NULL)
       
   390 	    return;
       
   391 	
       
   392 	RPointerArray<CXdmDocumentNode> nodes;
       
   393     CXdmNodeAttribute* ancAttr(NULL);
       
   394 	
       
   395 	// finding entry nodes
       
   396     TInt err = extListNode->Find(KXdmEntry, nodes);
       
   397 
       
   398     // extracting lists from entry nodes
       
   399     TInt entriesCountInNode = nodes.Count();
       
   400     OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),entriesCountInNode);
       
   401 
       
   402     TInt entitiesCount = aUris.MdcaCount();
       
   403     for (TInt i=0;i<entriesCountInNode;i++)
       
   404         { // get the anc attribute
       
   405         ancAttr = (nodes[i])->Attribute(KXdmAnc);
       
   406         // match it with all given entries
       
   407         for (TInt j=0;j<entitiesCount ; j++)
       
   408             {
       
   409             if ((aUris.MdcaPoint(j))==(ancAttr->AttributeValue()))
       
   410                 {
       
   411                 OPENG_DP(D_OPENG_LIT( "     RemoveFromModelL i=%d,j=%d" ),i,j);
       
   412                 iPresXDM->RemoveFromModelL(nodes[i]);
       
   413                 break;               
       
   414                 }
       
   415             }
       
   416         }
       
   417 
       
   418     nodes.Close();    
       
   419     return;
       
   420     }