vpnengine/vpnmanager/src/eventlogger.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2003-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 "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: Event logging.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <utf.h>
       
    19 
       
    20 #include "vpnmanagerserverdefs.h"
       
    21 #include "eventlogger.h"
       
    22 #include "log_r6.h"
       
    23 #include "vpnapiservant.h"
       
    24 #include "policystore.h"
       
    25 #include "pkiutil.h"
       
    26 #include "eventviewer.h"
       
    27 
       
    28 _LIT(KUnknownPolicy, "unknown");
       
    29 _LIT8(KUnknownVpnAp, "unknown");
       
    30 _LIT8(KUnknownIap, "unknown");
       
    31 
       
    32 
       
    33 CEventLogger* CEventLogger::NewL(CPolicyStore& aPolicyStore)
       
    34     {
       
    35     CEventLogger* self = new (ELeave) CEventLogger(aPolicyStore);
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop(); // self
       
    39     return self;
       
    40     }
       
    41 
       
    42 CEventLogger::CEventLogger(CPolicyStore& aPolicyStore)
       
    43     : iPolicyStore(aPolicyStore)
       
    44     {
       
    45     }
       
    46     
       
    47 void CEventLogger::ConstructL()
       
    48     {
       
    49     User::LeaveIfError(iEventMediator.Connect());
       
    50     }
       
    51 
       
    52 CEventLogger::~CEventLogger()
       
    53     {
       
    54     iEventMediator.Close();
       
    55     }
       
    56 
       
    57 void CEventLogger::LogEvent(TUint aMsgId, const TDesC* aDes1, const TDesC8* aDes2, TInt aInt1, TInt aInt2)
       
    58     {
       
    59     //Logging is an error diagnostic tool.
       
    60     //If the logging fails. There is much we can do. So we just ignore the error.
       
    61     TRAP_IGNORE(LogEventL(aMsgId, aDes1, aDes2, aInt1, aInt2));
       
    62     }
       
    63     
       
    64     
       
    65 void CEventLogger::LogEventL(TUint aMsgId, const TDesC* aDes1, const TDesC8* aDes2, TInt aInt1, TInt aInt2)
       
    66     {                
       
    67     TVpnPolicyInfo* policyInfo = new (ELeave) TVpnPolicyInfo;
       
    68     CleanupDeletePushL(policyInfo);
       
    69     
       
    70     
       
    71     // Special handling for event messages that have policy name in them
       
    72     __ASSERT_DEBUG((aMsgId == R_VPN_MSG_INSTALLED_POLICY_SERVER ||
       
    73                     aMsgId == R_VPN_MSG_INSTALLED_POLICY_FILE ||
       
    74                     aMsgId == R_VPN_MSG_POLICY_INSTALL_FAIL ||
       
    75                     aMsgId == R_VPN_MSG_CREATED_VPN_ACCESS_POINT_WITH_AP ||
       
    76                     aMsgId == R_VPN_MSG_CREATED_VPN_ACCESS_POINT_WITH_SNAP), User::Invariant());
       
    77                     
       
    78     // Descriptor parameter 1 is a policy ID
       
    79     if (aDes1 && aDes1->Length() > 0)
       
    80         {                                    
       
    81         if (iPolicyStore.GetPolicyInfo(*aDes1, *policyInfo) != KErrNone)
       
    82             {
       
    83             // ...use the policy ID as the name
       
    84             policyInfo->iName = *aDes1;
       
    85             }
       
    86         }
       
    87     else
       
    88         {
       
    89         // Completely unknown policy reference
       
    90         policyInfo->iName = KUnknownPolicy;
       
    91         }
       
    92 
       
    93     // Make a 8 bit copy of the policy name         
       
    94     HBufC8* nameCopy = CnvUtfConverter::ConvertFromUnicodeToUtf8L(policyInfo->iName);
       
    95     
       
    96     LogEvent(aMsgId, nameCopy, aDes2, aInt1, aInt2);   
       
    97     
       
    98     delete nameCopy;    
       
    99     nameCopy = NULL;
       
   100     
       
   101     CleanupStack::PopAndDestroy(); //policyInfo
       
   102     }
       
   103     
       
   104 void CEventLogger::LogEvent(TUint aMsgId, const TDesC8* aDes1, const TDesC8* aDes2, TInt aInt1, TInt aInt2)
       
   105   	{
       
   106     TPckgBuf<TInt> int1Des(aInt1);
       
   107 
       
   108     TUid sourceUid = (TUid)(KVpnManagerUid3);
       
   109 
       
   110     TIapName vpnApName(KUnknownVpnAp);
       
   111     TIapName realConnectionName(KUnknownIap);
       
   112                 
       
   113     switch (aMsgId)
       
   114         {
       
   115         case R_VPN_MSG_CREATED_VPN_ACCESS_POINT_WITH_AP:
       
   116             EventViewer::GetIapNames(aInt1, vpnApName, aInt2, realConnectionName);
       
   117 
       
   118             //The return value is ignored
       
   119             iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   120                                           R_VPN_MSG_CREATED_VPN_ACCESS_POINT_WITH_AP,
       
   121                                           3, &vpnApName, aDes1, &realConnectionName);
       
   122             break;
       
   123         case R_VPN_MSG_CREATED_VPN_ACCESS_POINT_WITH_SNAP:
       
   124             EventViewer::GetIapName(aInt1, vpnApName);
       
   125             EventViewer::GetSnapName(aInt2, realConnectionName);
       
   126 
       
   127             iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   128                                           R_VPN_MSG_CREATED_VPN_ACCESS_POINT_WITH_SNAP,
       
   129                                           3, &vpnApName, aDes1, &realConnectionName);
       
   130             
       
   131             break;        
       
   132         case R_VPN_MSG_INSTALLED_ENROLLMENT_SERVICE:
       
   133             if (aInt1) // if update...
       
   134                 {
       
   135                 iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   136                                               R_VPN_MSG_UPDATED_ENROLLMENT_SERVICE,
       
   137                                               2, aDes1, aDes2);
       
   138                 }
       
   139             else // install
       
   140                 {
       
   141                 iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   142                                               R_VPN_MSG_INSTALLED_ENROLLMENT_SERVICE,
       
   143                                               2, aDes1, aDes2);
       
   144                 }
       
   145             break;
       
   146             
       
   147         case R_VPN_MSG_DELETED_ENROLLMENT_SERVICE:
       
   148             iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   149                                           R_VPN_MSG_DELETED_ENROLLMENT_SERVICE,
       
   150                                           1, aDes1);
       
   151             break;
       
   152             
       
   153         case R_VPN_MSG_INSTALLED_POLICY_SERVER:
       
   154             LOG(Log::Printf(_L("Logging event R_VPN_MSG_INSTALLED_POLICY_SERVER, aInt2 = %d\n"), aInt2));
       
   155             if (aInt2) // if update...
       
   156                 {
       
   157                 if (aInt1 == KErrNone)
       
   158                     {
       
   159                     LOG(Log::Printf(_L("Logging event R_VPN_MSG_UPDATED_POLICY\n")));
       
   160                     iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   161                                                   R_VPN_MSG_UPDATED_POLICY,
       
   162                                                   2, aDes1, aDes2);
       
   163                     }
       
   164                 else
       
   165                     {
       
   166                     LOG(Log::Printf(_L("Logging event R_VPN_MSG_POLICY_UPDATE_FAIL\n")));
       
   167                     iEventMediator.ReportLogEvent(sourceUid, EError,
       
   168                                                   R_VPN_MSG_POLICY_UPDATE_FAIL,
       
   169                                                   2, aDes1, &int1Des);
       
   170                     }
       
   171                 }
       
   172             else // install
       
   173                 {
       
   174                 if (aInt1 == KErrNone)
       
   175                     {
       
   176                     LOG(Log::Printf(_L("Logging event R_VPN_MSG_INSTALLED_POLICY_SERVER\n")));
       
   177                     iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   178                                                   R_VPN_MSG_INSTALLED_POLICY_SERVER,
       
   179                                                   2, aDes1, aDes2);
       
   180                     }
       
   181                 else
       
   182                     {
       
   183                     LOG(Log::Printf(_L("Logging event R_VPN_MSG_POLICY_INSTALL_FAIL\n")));
       
   184                     iEventMediator.ReportLogEvent(sourceUid, EError,
       
   185                                                   R_VPN_MSG_POLICY_INSTALL_FAIL,
       
   186                                                   2, aDes1, &int1Des);
       
   187                     }
       
   188                 }
       
   189             break;
       
   190             
       
   191         case R_VPN_MSG_INSTALLED_POLICY_FILE:
       
   192             if (!aInt2) // if installation from file (to avoid event logging when installed from server)
       
   193                 {
       
   194                 iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   195                                               R_VPN_MSG_INSTALLED_POLICY_FILE,
       
   196                                               1, aDes1);
       
   197                 }
       
   198             break;
       
   199             
       
   200         case R_VPN_MSG_POLICY_INSTALL_FAIL:
       
   201             if (!aInt2) // if installation from file (failure in installation from server was covered above)
       
   202                 {
       
   203                 iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   204                                               R_VPN_MSG_POLICY_INSTALL_FAIL,
       
   205                                               2, aDes1, &int1Des);
       
   206                 }
       
   207             break;
       
   208                       
       
   209         case R_VPN_MSG_DELETED_POLICY:
       
   210             iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   211                                           R_VPN_MSG_DELETED_POLICY,
       
   212                                           1, aDes1);
       
   213             break;
       
   214             
       
   215         default:
       
   216             return;
       
   217         }
       
   218 
       
   219     LOG(Log::Printf(_L("Logged event %d\n"), aMsgId));
       
   220     }
       
   221 
       
   222 HBufC8* CEventLogger::CertSubjectNameL(const TDesC8& aCertData)
       
   223     {
       
   224     HBufC* certSubjectName = PkiUtil::CertSubjectNameL(aCertData);
       
   225     CleanupStack::PushL(certSubjectName);
       
   226     
       
   227     HBufC8* certSubjectName8 = HBufC8::NewL(certSubjectName->Length());
       
   228     certSubjectName8->Des().Copy(*certSubjectName);
       
   229 
       
   230     CleanupStack::PopAndDestroy(); // certSubjectName
       
   231 
       
   232     return certSubjectName8;
       
   233     }