vpnengine/sit/src/eventlogger.cpp
changeset 0 33413c0669b9
child 22 9f4e37332ce5
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: Logs events related to the SIT tasks.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <ipsecpolapi.h>
       
    19 
       
    20 #include "sit.h"
       
    21 #include "eventlogger.h"
       
    22 #include "log.h"
       
    23 #include "eventmediatorapi.h"
       
    24 #include "vpnconnstarter.h"
       
    25 
       
    26 
       
    27 /**
       
    28  * Used to log events related to the SIT tasks. 
       
    29  */
       
    30 CEventLogger* CEventLogger::NewL(REventMediator& aEventMediator, TUint32 aVpnIapId, TUint32 aRealIapId)
       
    31     {
       
    32     LOG(Log::Printf(_L("CEventLogger::NewL - begin\n")));
       
    33     CEventLogger* self = new (ELeave) CEventLogger(aEventMediator, aVpnIapId, aRealIapId);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop(); // self
       
    37     LOG(Log::Printf(_L("CEventLogger::NewL - end\n")));
       
    38     return self;
       
    39     }
       
    40 
       
    41 CEventLogger::CEventLogger(REventMediator& aEventMediator, TUint32 aVpnIapId, TUint32 aRealIapId)
       
    42     : iEventMediator(aEventMediator), iVpnIapId(aVpnIapId), iRealIapId(aRealIapId)
       
    43     {
       
    44     }
       
    45 
       
    46 void CEventLogger::ConstructL()
       
    47     {
       
    48     // Set default access point names just
       
    49     // in case the real name fetching fails
       
    50     iVpnApName.Copy(KUnknownVpnAp);
       
    51     iRealApName.Copy(KUnknownIap);
       
    52 
       
    53     EventViewer::GetIapNames(iVpnIapId, iVpnApName, iRealIapId, iRealApName);
       
    54     }
       
    55     
       
    56 CEventLogger::~CEventLogger()
       
    57     {
       
    58     LOG(Log::Printf(_L("CEventLogger::~CEventLogger\n")));
       
    59     }
       
    60 
       
    61 void CEventLogger::LogEvent(TUint aMsgId, TAny* aAnyPtr, TInt aStatusCode, TInt aReasonCode)
       
    62     {
       
    63     DoLogEvent( aMsgId, aAnyPtr, aStatusCode, aReasonCode );
       
    64     }
       
    65 
       
    66 TInt CEventLogger::DoLogEvent(TUint aMsgId, TAny* aAnyPtr, TInt aStatusCode, TInt aReasonCode)
       
    67     {
       
    68     TBuf<KMaxIpAddressLength> ifAddr;
       
    69     TBuf8<KMaxIpAddressLength> ifAddr8;
       
    70 
       
    71     TPckgBuf<TInt> statusCodeDes(aStatusCode);
       
    72 
       
    73     TUid sourceUid = (TUid)(KUidSit);
       
    74     
       
    75     TInt ret = KErrNone;
       
    76                 
       
    77     switch (aMsgId)
       
    78         {
       
    79         case R_VPN_MSG_VPN_IAP_ACTIVATED:
       
    80             if (aStatusCode == KErrNone)
       
    81                 {
       
    82                 static_cast<TInetAddr*>(aAnyPtr)->Output(ifAddr);
       
    83                 ifAddr8.Copy(ifAddr);
       
    84                 
       
    85                 ret = iEventMediator.ReportLogEvent(sourceUid, EInfo, aMsgId, 2,
       
    86                                                     &iVpnApName, &ifAddr8);
       
    87                 }
       
    88             break;
       
    89             
       
    90         case R_VPN_MSG_VPN_IAP_ACT_FAILED:
       
    91             if (aStatusCode == KKmdIkeNoCertFoundErr)
       
    92                 {
       
    93                 ret = iEventMediator.ReportLogEvent(sourceUid, EError,
       
    94                                                     R_VPN_MSG_VPN_IAP_ACT_FAILED_CERT_EXP_MISS,
       
    95                                                     1, &iVpnApName);
       
    96                 }
       
    97             else if (aStatusCode != KErrNone && aStatusCode != KErrCancel)
       
    98                 {
       
    99                 ret = iEventMediator.ReportLogEvent(sourceUid, EError, aMsgId, 2,
       
   100                                                     &iVpnApName, &statusCodeDes);
       
   101                 }
       
   102             break;
       
   103             
       
   104         case R_VPN_MSG_REAL_IAP_ACT_FAILED:
       
   105             if (aStatusCode != KErrNone && aStatusCode != KErrCancel)
       
   106                 {
       
   107                 ret = iEventMediator.ReportLogEvent(sourceUid, EError, aMsgId, 3,
       
   108                                                     &iRealApName, &iVpnApName, &statusCodeDes);
       
   109                 }
       
   110             break;
       
   111             
       
   112         case R_VPN_MSG_VPN_IAP_DEACT:
       
   113             if (aStatusCode == KErrNone ||
       
   114                 aStatusCode == EUnknownPolicyHandle)
       
   115                 {
       
   116                 if (aReasonCode == EDeactivateForced)
       
   117                     {
       
   118                     ret = iEventMediator.ReportLogEvent(sourceUid, EInfo,
       
   119                                                         R_VPN_MSG_VPN_IAP_DEACT_REAL_IAP_TERMINATED, 2,
       
   120                                                         &iVpnApName, &iRealApName);
       
   121                     }
       
   122                 else
       
   123                     {
       
   124                     ret = iEventMediator.ReportLogEvent(sourceUid, EInfo, aMsgId, 1,
       
   125                                                         &iVpnApName);
       
   126                     }
       
   127                 }
       
   128             break;
       
   129             
       
   130         case R_VPN_MSG_REAL_IAP_REACTIVATED:
       
   131             if (aStatusCode == KErrNone)
       
   132                 {
       
   133                 ret = iEventMediator.ReportLogEvent(sourceUid, EInfo, aMsgId, 2,
       
   134                                                     &iRealApName, &iVpnApName);
       
   135                 }
       
   136             else
       
   137                 {
       
   138                 ret = iEventMediator.ReportLogEvent(sourceUid, EError, R_VPN_MSG_REAL_IAP_ACT_FAILED, 3,
       
   139                                                     &iRealApName, &iVpnApName, &statusCodeDes);
       
   140                 }
       
   141             break;
       
   142 
       
   143         case R_VPN_MSG_VPN_IAP_ACT_START:
       
   144             // NSSM removal
       
   145             break;
       
   146             
       
   147         case R_VPN_MSG_VPN_IAP_ACT_CANCEL:
       
   148             break;
       
   149 
       
   150         case R_VPN_MSG_VPN_IAP_ACT_END:
       
   151             break;
       
   152             
       
   153         default:
       
   154             return ret;
       
   155         }
       
   156 
       
   157     LOG(Log::Printf(_L("Logged event %d, logging status = %d\n"), aMsgId, ret));
       
   158     return ret;
       
   159     }