nettools/conntest/Engine/ipdumpengine.cpp
changeset 0 857a3e953887
equal deleted inserted replaced
-1:000000000000 0:857a3e953887
       
     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: CIpdumpEngine is used to control the ip logging protocol
       
    15 *
       
    16 */
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <nifman.h>
       
    20 #include "ipdumpengine.h"
       
    21 
       
    22 
       
    23 //
       
    24 // CIpdumpEngine.
       
    25 //
       
    26 
       
    27 CIpdumpEngine* CIpdumpEngine::NewL()
       
    28 {
       
    29     CIpdumpEngine* self = new (ELeave) CIpdumpEngine();
       
    30     CleanupStack::PushL(self);
       
    31     self->ConstructL();
       
    32     CleanupStack::Pop(self);
       
    33     return self;
       
    34 }
       
    35 
       
    36 CIpdumpEngine::CIpdumpEngine()
       
    37 : iLoggingEnabled(EFalse)
       
    38 {
       
    39     // If changed change the filename also
       
    40     // in the ip logging protocol to match
       
    41     _LIT(KLogFilePath, "c:\\logs\\tcpdump\\probe.cap"); 
       
    42     iLogFileName.Append(KLogFilePath);
       
    43 }
       
    44 
       
    45 // This is to get around of the restrictions of the secure file system,
       
    46 // when the conntest and the probe are installed from a sis
       
    47 // You cannot install the esk to the right place directly, so copy it here
       
    48 // Requires all files capability
       
    49 _LIT(KIpDumpEskImport, "\\private\\101f7989\\import\\esock\\ip.probe.esk");
       
    50 _LIT(KIpDumpEskEsock, "\\private\\101f7989\\esock\\ip.probe.esk");
       
    51 
       
    52 void AttemptToCopyEskFile()
       
    53 	{
       
    54 	RFs fs;
       
    55 	TInt err = fs.Connect();
       
    56 
       
    57 	if (err)
       
    58 		{
       
    59 		return;
       
    60 		}
       
    61 
       
    62 	CFileMan* fileman = NULL;
       
    63 	TRAP(err, fileman = CFileMan::NewL(fs));
       
    64 
       
    65 	if (err)
       
    66 		{
       
    67 		fs.Close();
       
    68 		return;
       
    69 		}
       
    70 
       
    71 	(void)fileman->Copy(KIpDumpEskImport, KIpDumpEskEsock, CFileMan::ERecurse);
       
    72 
       
    73 	delete fileman;
       
    74 	fs.Close();
       
    75 	}
       
    76 
       
    77 void CIpdumpEngine::ConstructL()
       
    78 {
       
    79 	AttemptToCopyEskFile();
       
    80 }
       
    81 
       
    82 
       
    83 CIpdumpEngine::~CIpdumpEngine()
       
    84 {
       
    85     DisableLogging();
       
    86 }
       
    87 
       
    88 
       
    89 
       
    90 TInt CIpdumpEngine::CreateLogDirectory()
       
    91 {
       
    92 
       
    93     RFs fs;
       
    94     TInt r;
       
    95     
       
    96     r = fs.Connect();
       
    97     
       
    98     if(r==KErrNone)
       
    99     {
       
   100         
       
   101         // Delete the old log file. After disabling the logging the file
       
   102         // is in use for short period of time, therefore doing the deletion
       
   103         // in loop to avoid error message in UI.
       
   104         while((r = fs.Delete(iLogFileName)) == KErrInUse)
       
   105         	User::After(1);
       
   106         
       
   107         if(r == KErrNotFound || r == KErrPathNotFound)
       
   108         {
       
   109             r = fs.MkDirAll(iLogFileName);
       
   110             r = (r==KErrAlreadyExists) ? KErrNone : r;
       
   111         }
       
   112     }
       
   113     
       
   114     fs.Close();
       
   115     return r;
       
   116 }
       
   117 
       
   118 
       
   119 
       
   120 
       
   121 void CIpdumpEngine::EnableLoggingL()
       
   122 {
       
   123     
       
   124     if(iLoggingEnabled)
       
   125     {
       
   126         return;
       
   127     }
       
   128     
       
   129     User::LeaveIfError(CreateLogDirectory());
       
   130     
       
   131     User::LeaveIfError(iSocketServ.Connect());    
       
   132     
       
   133     TProtocolDesc protocol;
       
   134     TProtocolName name(_S("probe"));
       
   135         
       
   136     User::LeaveIfError(iSocketServ.FindProtocol(name, protocol));
       
   137     
       
   138     User::LeaveIfError(iSocket.Open(iSocketServ, name));
       
   139         
       
   140     iLoggingEnabled = ETrue;
       
   141     
       
   142     return;
       
   143 }
       
   144 
       
   145 void CIpdumpEngine::DisableLogging()
       
   146 {
       
   147     if(iLoggingEnabled)
       
   148     {
       
   149         iSocket.Close();
       
   150         iSocketServ.Close();
       
   151         
       
   152         iLoggingEnabled = EFalse;
       
   153     }
       
   154 }
       
   155 
       
   156 TBool CIpdumpEngine::LoggingEnabled() const
       
   157 {
       
   158     
       
   159     return iLoggingEnabled;
       
   160 }
       
   161 
       
   162 const TDesC& CIpdumpEngine::LogFileName() const
       
   163 {
       
   164        return iLogFileName;
       
   165 }
       
   166 
       
   167