networksecurity/tls/protocol/LOGFILE.CPP
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include <e32base.h>
       
    18 #include "LOGFILE.H"
       
    19 
       
    20 #ifdef __TRACEFILE__
       
    21 
       
    22 const TInt KHexDumpWidth = 16;
       
    23 
       
    24 
       
    25 
       
    26 void Log::Write(const TDesC& aDes)
       
    27 	{
       
    28 	RFileLogger::Write(KSSLLogDir,KSSLLogFileName,EFileLoggingModeAppend,aDes);
       
    29 	}
       
    30 
       
    31 
       
    32 void Log::Printf(TRefByValue<const TDesC> aFmt, ...)
       
    33 	{
       
    34     //coverity[var_decl];
       
    35     VA_LIST list;
       
    36     VA_START(list, aFmt);
       
    37 	TBuf<0x100> buf;
       
    38     //coverity[uninit_use_in_call];
       
    39     buf.FormatList(aFmt, list);
       
    40 	Write(buf);
       
    41 	}
       
    42 
       
    43 
       
    44 void Log::HexDump(const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen)
       
    45 	{
       
    46 
       
    47 	TBuf<0x100> buf;
       
    48 	buf.SetLength(0);
       
    49 	TInt i = 0;
       
    50 	const TText* p = aHeader;
       
    51 	while (aLen>0)
       
    52 		{
       
    53 		TInt n = aLen>KHexDumpWidth ? KHexDumpWidth : aLen;
       
    54 		buf.AppendFormat(_L("%s%04x : "), p, i);
       
    55 		TInt j;
       
    56 		for (j=0; j<n; j++)
       
    57 			buf.AppendFormat(_L("%02x "), aPtr[i+j]);
       
    58 		while (j++<KHexDumpWidth)
       
    59 			buf.AppendFormat(_L("   "));
       
    60 		buf.AppendFormat(_L(" "));
       
    61 		for (j=0; j<n; j++)
       
    62 			buf.AppendFormat(_L("%c"), aPtr[i+j]<32 || aPtr[i+j]>126 ? '.' : aPtr[i+j]);
       
    63 		buf.AppendFormat(_L("\r\n"));
       
    64 		Log::Write(buf);
       
    65 		buf.SetLength(0);
       
    66 		aLen -= n;
       
    67 		i += n;
       
    68 		p = aMargin;
       
    69 		}
       
    70 	}
       
    71 
       
    72 
       
    73 #endif // __TRACEFILE__