cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_list.cpp
changeset 15 da2ae96f639b
parent 8 35751d3474b7
equal deleted inserted replaced
10:afc583cfa176 15:da2ae96f639b
    25 
    25 
    26 _LIT(KCaType, "ca");
    26 _LIT(KCaType, "ca");
    27 _LIT(KUserType, "user");
    27 _LIT(KUserType, "user");
    28 _LIT(KPeerType, "peer");
    28 _LIT(KPeerType, "peer");
    29 
    29 
       
    30 // The number of certificates being listed at a time.
       
    31 #define LIST_COUNT 30
       
    32 
    30 /*static*/ CCertToolList* CCertToolList::NewLC(CCertToolController* aController)
    33 /*static*/ CCertToolList* CCertToolList::NewLC(CCertToolController* aController)
    31 	{
    34 	{
    32 	CCertToolList* self = new (ELeave) CCertToolList(aController);
    35 	CCertToolList* self = new (ELeave) CCertToolList(aController);
    33 	CleanupStack::PushL(self);
    36 	CleanupStack::PushL(self);
    34 	self->ConstructL();
    37 	self->ConstructL();
   105 		iCertStore->List(iCertInfos, *iFilter, iStatus);		
   108 		iCertStore->List(iCertInfos, *iFilter, iStatus);		
   106 		}
   109 		}
   107 	SetActive();	
   110 	SetActive();	
   108 	}
   111 	}
   109 	
   112 	
       
   113 	
       
   114 
       
   115 
       
   116 void CCertToolList::InitializeIterations()
       
   117     { 	
       
   118 	// Initialize the current list count and iCurrentListOffset with default LIST_COUNT.
       
   119     iCurrentListCount = iCurrentListOffset = LIST_COUNT;				
       
   120 			
       
   121     if (iCertInfos.Count() < LIST_COUNT)
       
   122         {
       
   123         iCurrentListCount = iCurrentListOffset = iCertInfos.Count();
       
   124         }
       
   125 				    
       
   126     // Compute the number of iterations for listing.    
       
   127     // The latter operation is to add another iteration count if iCertInfos 
       
   128     // count is not an exact multiple of LIST_COUNT.
       
   129 	iNumberOfIterationsLeft =  (iCertInfos.Count() / LIST_COUNT) + !!(iCertInfos.Count() % LIST_COUNT);   
       
   130 								
       
   131 
       
   132    // Initialize the last iteration offset with default LIST_COUNT.				
       
   133    iLastIterationOffset = LIST_COUNT;		
       
   134                 		
       
   135    if (iCertInfos.Count() % LIST_COUNT)
       
   136        {
       
   137        // If the number of certificates is not an exact multiple of default LIST_COUNT.
       
   138    	   iLastIterationOffset = (iCertInfos.Count() % LIST_COUNT);        			 
       
   139        }
       
   140    }       
       
   141 	
   110 void CCertToolList::RunL()
   142 void CCertToolList::RunL()
   111 	{
   143 	{
   112 	if (iStatus.Int() != KErrNone)
   144 	if (iStatus.Int() != KErrNone)
   113 		{
   145 		{
   114 		if (iState != EGetApps && iStatus.Int() != KErrNotSupported)
   146 		if (iState != EGetApps && iStatus.Int() != KErrNotSupported)
   115 			{
   147 			{
   116 			// A problem occured. Handle gracefully.
   148 			// A problem occured. Handle gracefully.
   117 			User::Leave(iStatus.Int());	
   149 			User::Leave(iStatus.Int());	
   118 			}
   150 			}
   119 		}
   151 		}		
   120 		
   152 		
   121 	switch (iState)
   153 	switch (iState)
   122 		{
   154 		{
   123 		case EListCerts :
   155 		case EListCerts :
   124 			{
   156 			{
   157 						CActiveScheduler::Stop();
   189 						CActiveScheduler::Stop();
   158 						break;
   190 						break;
   159 						}						
   191 						}						
   160 					KeyToolUtils::FilterCertsL(iCertInfos, ownerType);
   192 					KeyToolUtils::FilterCertsL(iCertInfos, ownerType);
   161 					}
   193 					}
       
   194 
       
   195                
       
   196                 InitializeIterations();   
       
   197 
   162   				iState = ERetrieve;
   198   				iState = ERetrieve;
   163   				iIndex = 0;
   199   				iIndex = 0;
   164 				if (iIndex <= (iCertInfos.Count()-1 ))
   200 				if (iIndex <= (iCertInfos.Count()-1 ))
   165 					{
   201 					{
   166 					iCertStore->Retrieve(*iCertInfos[iIndex], iCertificate, iStatus);
   202 					iCertStore->Retrieve(*iCertInfos[iIndex], iCertificate, iStatus);
   174 				}
   210 				}
   175 			}
   211 			}
   176 			break;
   212 			break;
   177 		case ERetrieve :
   213 		case ERetrieve :
   178 			{
   214 			{
       
   215             // This marks the beginning of the current iteration.           
       
   216 			// Retrieve all the certificates up to the current list count.            
       
   217                        
   179 			iParsedCerts.Append(iCertificate);
   218 			iParsedCerts.Append(iCertificate);
   180 			iIndex++;
   219 			iIndex++;
   181 			if (iIndex <= (iCertInfos.Count()-1 ))
   220 
   182 				{
   221 			if (iIndex < iCurrentListCount)
   183 				iCertStore->Retrieve(*iCertInfos[iIndex], iCertificate, iStatus);
   222 			    {
   184 				SetActive();
   223 			    iCertStore->Retrieve(*iCertInfos[iIndex], iCertificate, iStatus);            
   185 				}
   224 			    SetActive();
       
   225 			    }
   186 			else
   226 			else
   187 				{
   227 			    {                
   188 				iState = EGetApps;
   228 			    iState = EGetApps;
   189 				iIndex = 0;
   229                                                  
   190 				iCertStore->Applications(*iCertInfos[iIndex], iApps, iStatus);
   230 			    // Start getting the applications starting from the iIndex(current list's beginning). 
   191 				SetActive();
   231 			    iIndex = iCurrentListCount - iCurrentListOffset;
   192 				}
   232 			    RUidArray t;
       
   233 			    iApps = t;
       
   234 			    iCertStore->Applications(*iCertInfos[iIndex], iApps, iStatus);
       
   235 			    SetActive();
       
   236 			    }
   193 			}
   237 			}
   194 			break;
   238 			break;
   195 		case EGetApps :
   239 		case EGetApps :
   196 			{	
   240 			{	
   197 			iCertApps.Append(iApps);
   241 			iCertApps.Append(iApps);
   198 
   242 
   199 			iIndex++;
   243 			iIndex++;
   200 			if (iIndex <= (iCertInfos.Count()-1 ))
   244 
   201 				{
   245 			// Get all the applications up to the current list count.            
   202 				RUidArray t;
   246 			if (iIndex < iCurrentListCount)
   203 				iApps = t;				
   247 			    {      
   204 				iCertStore->Applications(*iCertInfos[iIndex], iApps, iStatus);
   248 			    RUidArray t;
   205 				SetActive();
   249 			    iApps = t;				
   206 				}
   250 			    iCertStore->Applications(*iCertInfos[iIndex], iApps, iStatus);
       
   251 			    SetActive();
       
   252 			    }
   207 			else
   253 			else
   208 				{
   254 			    {
   209 				iState = EGetTrust;
   255 			    iState = EGetTrust;
   210 				iIndex = 0;
   256                                 
   211 				iCertStore->Trusted(*iCertInfos[iIndex], iTrust, iStatus);
   257 		    	// Start getting the trust starting from the iIndex(current list's beginning). 
   212 				SetActive();
   258 			    iIndex = iCurrentListCount - iCurrentListOffset;                
   213 				}			
   259 			    iCertStore->Trusted(*iCertInfos[iIndex], iTrust, iStatus);
       
   260 			    SetActive();
       
   261 			    }			
   214 			}
   262 			}
   215 			break;
   263 			break;
   216 		case EGetTrust :
   264 		case EGetTrust :
   217 			{	
   265 			{	
   218 			iCertTrust.Append(iTrust);
   266 			iCertTrust.Append(iTrust);
   219 
   267 
   220 			iIndex++;
   268 			iIndex++;
   221 			if (iIndex <= (iCertInfos.Count()-1 ))
   269 	
   222 				{
   270   			// Get all the trust up to the current list count. 
   223 				iCertStore->Trusted(*iCertInfos[iIndex], iTrust, iStatus);
   271   			if (iIndex < iCurrentListCount) 
   224 				SetActive();
   272 		            {
   225 				}
   273 		            iCertStore->Trusted(*iCertInfos[iIndex], iTrust, iStatus);
   226 			else
   274 		            SetActive();
   227 				{
   275 		            }
   228 				iState = EFinished;
   276   			else 
   229 				TInt certCount = iCertInfos.Count();
   277 		            {
   230 				for (TInt i = 0; i < certCount; i++)
   278                     // Update the number of iterations.                  
   231  					{
   279                     iNumberOfIterationsLeft--;                                        
   232  					iController->DisplayCertL(*iCertInfos[i], *iParsedCerts[i], iCertApps[i], iCertTrust[i], iParams->iIsDetailed, iParams->iPageWise);
   280 
   233  					}
   281                     // Check if this happens to be the last iteration. If so, adjust the list offset.                                                                    
   234 				CActiveScheduler::Stop();
   282 			        if (iNumberOfIterationsLeft == 0)
   235 				}			
   283 			            {
       
   284 			            iCurrentListOffset = iLastIterationOffset;
       
   285 			            }                                
       
   286                                 
       
   287 		            // We are done with the current list processing, it's time to display the collected data.                
       
   288 		            TInt DisplayOffset = iCurrentListOffset;
       
   289                     
       
   290              	    // Display(list) the certificates just processed.  This marks the end of the current iteration.    
       
   291 		            for (TInt i = iIndex - DisplayOffset; i < iCurrentListCount; i++)
       
   292 		                 {
       
   293 		                 iController->DisplayCertL(*iCertInfos[i], *iParsedCerts[i], iCertApps[i], iCertTrust[i], iParams->iIsDetailed, iParams->iPageWise);                      
       
   294 	                         if (iParsedCerts[i] )
       
   295 		                     {
       
   296 		                     delete iParsedCerts[i];  // Relinquish the resources for facilitating the subsequent listing.
       
   297 		                     iParsedCerts[i] = 0;     
       
   298 		                     }
       
   299 		                 }                 
       
   300                 
       
   301     	                    // How many more are remaining??
       
   302 		            TInt RemainingListCount = iCertInfos.Count() - iCurrentListCount;                
       
   303                 
       
   304 
       
   305                             if (RemainingListCount == 0)
       
   306 		                {
       
   307             	                iState = EFinished;
       
   308 		                CActiveScheduler::Stop();
       
   309 		                break;
       
   310 		                }                                                    
       
   311                 
       
   312 		            if (RemainingListCount < LIST_COUNT)
       
   313 		                {       
       
   314                         // Total number of certificates is not an exact multiple of default LIST_COUNT.
       
   315                         // Last iteration will have the list count lesser than the default LIST_COUNT.
       
   316                         // So, only one iteration is left.
       
   317 		                iCurrentListCount += RemainingListCount;
       
   318 		                }
       
   319 		            else
       
   320 		                {
       
   321                                 //  Still a few more are left.
       
   322 	                        iCurrentListCount += LIST_COUNT;
       
   323 		                }
       
   324                   
       
   325 		            // Start the next iteration.   
       
   326 		            iState = ERetrieve;               
       
   327 		            iCertStore->Retrieve(*iCertInfos[iIndex], iCertificate, iStatus);
       
   328 		            SetActive();                                         
       
   329 		            }			
   236 			}
   330 			}
   237 			break;
   331 			break;
   238 		case EFinished :
   332 		case EFinished :
   239 			{
   333 			{
   240 			}
   334 			}