authenticationservices/authenticationserver/test/authtool/authtool.cpp
changeset 29 ece3df019add
equal deleted inserted replaced
19:cd501b96611d 29:ece3df019add
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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 the License "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 * AuthTool provides a console interface to the AuthServer query
       
    16 * methods, basically dumping the contents of the AuthServer's database.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file 
       
    23 */
       
    24 #include <e32cons.h>
       
    25 #include "authserver_client.h"
       
    26 
       
    27 using namespace AuthServer;
       
    28 
       
    29 _LIT(KAnyStr, "Default");
       
    30 _LIT(KBiometricStr, "Biometric");
       
    31 _LIT(KKnowledgeStr, "Knowledge");
       
    32 _LIT(KTokenStr, "Token");
       
    33 
       
    34 TAuthPluginType types[] = { EAuthDefault, EAuthBiometric, EAuthKnowledge, EAuthToken };
       
    35 TPtrC typeNames[] = {KAnyStr(), KBiometricStr(), KKnowledgeStr(), KTokenStr() }; 
       
    36 
       
    37 _LIT(KUnTrainedStr, "Untrained");
       
    38 _LIT(KTrainedStr , "Trained");
       
    39 _LIT(KFullyTraininedStr, "Fully Trained");
       
    40 TPtrC trainNames[] = { KUnTrainedStr(), KTrainedStr(), KFullyTraininedStr() }; 
       
    41 
       
    42 _LIT(KMsgAuthToolPanic,"AuthTool: ");
       
    43 
       
    44 TInt ExtractDetailsL();
       
    45 TInt DisplayPlugins(RPluginDescriptions&);
       
    46 
       
    47 
       
    48 GLDEF_C TInt E32Main()
       
    49     {
       
    50     __UHEAP_MARK;
       
    51 	
       
    52     CTrapCleanup* cleanupstack=CTrapCleanup::New(); 
       
    53     TRAPD(error,ExtractDetailsL());
       
    54     __ASSERT_ALWAYS(!error,User::Panic(KMsgAuthToolPanic, error)); 
       
    55     delete cleanupstack;
       
    56 	
       
    57     __UHEAP_MARKEND;
       
    58     return 0;
       
    59     }
       
    60 
       
    61 CConsoleBase* console = 0;
       
    62 
       
    63 TInt ExtractDetailsL()
       
    64   {
       
    65   // create the console
       
    66   console = Console::NewL(_L("AuthTool"),
       
    67 										TSize(KDefaultConsWidth,
       
    68 											  KDefaultConsHeight));
       
    69   CleanupStack::PushL(console);
       
    70     
       
    71   // connect to server
       
    72   RAuthClient authClient;
       
    73   User::LeaveIfError(authClient.Connect());
       
    74   CleanupClosePushL(authClient);
       
    75 
       
    76   // get the plugins
       
    77   RPluginDescriptions plugins;
       
    78   authClient.PluginsL(plugins);
       
    79   CleanupClosePushL(plugins);
       
    80 
       
    81   DisplayPlugins(plugins);
       
    82   
       
    83   // get the preferences
       
    84   console->Printf(_L("\nPreferences\n-----------\n"));
       
    85 
       
    86   TInt count = sizeof(types)/sizeof(TInt);
       
    87   for (TInt i = 0  ; i < count ; ++i)
       
    88 	{
       
    89     console->Printf(_L("%10S : 0x%x\n"), &typeNames[i],
       
    90 					authClient.PreferredTypePluginL(types[i]));
       
    91 	}
       
    92   console->Printf(_L("\nPress any key to continue\n"));
       
    93   console->Getch();
       
    94 
       
    95   // get the identities
       
    96   console->Printf(_L("\nIdentities\n-----------\n"));
       
    97   
       
    98   RIdentityIdArray ids;
       
    99   authClient.IdentitiesL(ids);
       
   100   CleanupClosePushL(ids);
       
   101   
       
   102   for (TInt index = 0  ; index < ids.Count(); ++index)
       
   103 	{
       
   104     HBufC* str = authClient.IdentityStringL(ids[index]);	
       
   105 
       
   106 	CleanupStack::PushL(str);
       
   107 	if (str != 0)
       
   108 	  {
       
   109       console->Printf(_L("0x%x : %S\n"), ids[index],
       
   110 						str);
       
   111 	  }
       
   112 	else
       
   113 	  {
       
   114       console->Printf(_L("0x%x : No Name\n"), ids[index]);
       
   115 	  }
       
   116 	CleanupStack::PopAndDestroy(str);
       
   117 	}
       
   118   console->Printf(_L("\nPress any key to finish\n"));	
       
   119   console->Getch();
       
   120 
       
   121   CleanupStack::PopAndDestroy(4,console);
       
   122   return 0;
       
   123   }
       
   124 
       
   125 TPtrC* train(TAuthTrainingStatus aT)
       
   126   {
       
   127   TInt idx =0; 
       
   128   switch (aT)
       
   129 	{
       
   130   case EAuthUntrained:
       
   131 	idx = 0;
       
   132 	break;
       
   133   case EAuthTrained:
       
   134 	idx = 1;
       
   135 	break;
       
   136   case EAuthFullyTrained:
       
   137 	idx = 2;
       
   138 	break;
       
   139 	}
       
   140   return &trainNames[idx];
       
   141   } 
       
   142 
       
   143 TPtrC* type(TAuthPluginType aT)
       
   144   {
       
   145   TInt idx =0; 
       
   146   switch (aT)
       
   147 	{
       
   148   case EAuthDefault:
       
   149 	idx = 0;
       
   150 	break;
       
   151   case EAuthBiometric:
       
   152 	idx = 1;
       
   153 	break;
       
   154   case EAuthKnowledge:
       
   155 	idx = 2;
       
   156 	break;
       
   157   case EAuthToken:
       
   158 	idx = 3;
       
   159 	break;
       
   160   case EAuthPerformance:
       
   161 	idx = 4;
       
   162 	break;
       
   163 	}
       
   164   return &typeNames[idx];
       
   165   } 
       
   166 
       
   167 TInt DisplayPlugins(RPluginDescriptions& aPlugins)
       
   168   {
       
   169   console->Printf(_L("\nPlugin Descriptions\n-------------------\n"));
       
   170   for (TInt i = 0  ; i < aPlugins.Count(); ++i)
       
   171 	{
       
   172 	console->Printf(_L("ID            : 0x%x\n"), aPlugins[i]->Id());
       
   173 	console->Printf(_L("Name          : %S\n"), aPlugins[i]->Name());
       
   174 	console->Printf(_L("Type          : %S\n"), type(aPlugins[i]->Type()));
       
   175 	console->Printf(_L("Training      : %S\n"), train(aPlugins[i]->TrainingStatus()));
       
   176 	console->Printf(_L("#Combinations : %d\n"), aPlugins[i]->MinEntropy());
       
   177 	console->Printf(_L("FPR           : %d\n"), aPlugins[i]->FalsePositiveRate());
       
   178 	console->Printf(_L("FNR           : %d\n\n"), aPlugins[i]->FalseNegativeRate());
       
   179     console->Printf(_L("\nPress any key to continue\n"));
       
   180     console->Getch();
       
   181 	}
       
   182   
       
   183   return 0;
       
   184   }
       
   185