realtimenetprots/sipfw/SIP/Logging/inc/TSIPLogger.inl
changeset 0 307788aac0a8
child 55 36ea1f90a3d8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     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 "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 * Name          : TSIPLogger.inl
       
    16 * Part of       : SIP Logging
       
    17 * Version       :  
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <utf.h>
       
    25 #include <e32svr.h>
       
    26 #include <flogger.h>
       
    27 #include <f32file.h>
       
    28 
       
    29 #include "SipLogs.h"
       
    30 #include "TSIPLogger.h"
       
    31 
       
    32 _LIT(KSipLogFileDir, "Sip");
       
    33 _LIT(KSipLogFileName, "SipLog.txt");
       
    34 _LIT(KSeparator, "---------------");
       
    35 _LIT(KIntMessageFormat,"%S: %d");
       
    36 _LIT(KTwoIntMessageFormat,"%S: %d, %d");
       
    37 _LIT(KAddrMessageFormat,"%S: %S port %d");
       
    38 _LIT(KSipLogPath, "C:\\logs\\sip\\");
       
    39 
       
    40 inline void TSIPLogger::Print(const TDesC& aStr)
       
    41 	{
       
    42 	if ( LogDirExists( KSipLogPath ) )
       
    43 		{
       
    44 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
    45 			EFileLoggingModeAppend,aStr);                                  
       
    46 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
    47 			EFileLoggingModeAppend, KSeparator);
       
    48 		}
       
    49 	else
       
    50 		{
       
    51 		_LIT(KSIPFormat, "SIP: %S");
       
    52 		TBuf<256> log;
       
    53 		log.Format(KSIPFormat, &aStr);
       
    54 		RDebug::RawPrint(log);
       
    55 		}
       
    56 	}
       
    57 
       
    58 
       
    59 inline void TSIPLogger::Print(const TDesC& aStr, 
       
    60 		                      const TDesC8& aMsg)
       
    61 	{
       
    62 	if ( LogDirExists( KSipLogPath ) )
       
    63 		{
       
    64 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName,
       
    65 			EFileLoggingModeAppend, aStr);
       
    66 
       
    67 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
    68 				EFileLoggingModeAppend, aMsg);
       
    69 
       
    70 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
    71 			EFileLoggingModeAppend, KSeparator);
       
    72 		}
       
    73 	else
       
    74 		{
       
    75 		TBuf<100> msg;
       
    76 		TBuf<256> log;
       
    77 		TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8(msg, aMsg.Left(99));
       
    78 
       
    79 		_LIT(KSIPFormat, "SIP: %S: %S");
       
    80 		log.Format(KSIPFormat, &aStr, &msg);
       
    81 
       
    82 		RDebug::RawPrint(log);
       
    83 		}
       
    84 	}
       
    85 
       
    86 
       
    87 inline void TSIPLogger::Print(const TDesC& aStr, 
       
    88 		                      const TDesC16& aMsg)
       
    89 	{
       
    90 	if ( LogDirExists( KSipLogPath ) )
       
    91 		{
       
    92 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
    93 			EFileLoggingModeAppend, aStr);
       
    94 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
    95 			EFileLoggingModeAppend, aMsg);                                 
       
    96 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
    97 			EFileLoggingModeAppend, KSeparator);
       
    98 		}
       
    99 	else
       
   100 		{
       
   101 		_LIT(KSIPFormat, "SIP: %S: %S");
       
   102 		TBuf<256> log;
       
   103 		log.Format(KSIPFormat, &aStr, &aMsg);
       
   104 		RDebug::RawPrint(log);
       
   105 		}
       
   106 	}
       
   107 
       
   108 
       
   109 inline void TSIPLogger::Print(const TDesC& aStr,
       
   110 		                      TUint32 aValue)
       
   111 	{
       
   112 	if ( LogDirExists( KSipLogPath ) )
       
   113 		{
       
   114 		RFileLogger::WriteFormat (KSipLogFileDir, KSipLogFileName, 
       
   115 			EFileLoggingModeAppend, KIntMessageFormat, &aStr, aValue);
       
   116 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
   117 			EFileLoggingModeAppend, KSeparator);
       
   118 		}
       
   119 	else
       
   120 		{
       
   121 		_LIT(KSIPFormat, "SIP: %S: %d");
       
   122 		TBuf<256> log;
       
   123 		log.Format(KSIPFormat, &aStr, aValue);
       
   124 		RDebug::RawPrint(log);
       
   125 		}
       
   126 	}
       
   127 
       
   128 
       
   129 inline void TSIPLogger::Print(const TDesC& aStr,
       
   130 		                      TUint32 aValue1,
       
   131 		                      TUint32 aValue2)
       
   132 	{
       
   133 	if ( LogDirExists( KSipLogPath ) )
       
   134 		{
       
   135 		RFileLogger::WriteFormat (KSipLogFileDir, KSipLogFileName, 
       
   136 			EFileLoggingModeAppend, KTwoIntMessageFormat, &aStr, 
       
   137 			aValue1, aValue2);                                
       
   138 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
   139 			EFileLoggingModeAppend, KSeparator);
       
   140 		}
       
   141 	else
       
   142 		{
       
   143 		_LIT(KSIPFormat, "SIP: %S: %d, %d");
       
   144 		TBuf<256> log;
       
   145 		log.Format(KSIPFormat, &aStr, aValue1, aValue2);
       
   146 		RDebug::RawPrint(log);
       
   147 		}
       
   148 	}
       
   149 
       
   150   
       
   151 inline void TSIPLogger::Print(const TDesC& aStr,
       
   152                               const TInetAddr& aAddr) 
       
   153 	{
       
   154 	const TInt KIPv6AddrMaxLen = 39;
       
   155 	TBuf<KIPv6AddrMaxLen> addrBuf;
       
   156 	aAddr.Output(addrBuf);
       
   157 
       
   158 	if ( LogDirExists( KSipLogPath ) )
       
   159 		{
       
   160 		RFileLogger::WriteFormat (KSipLogFileDir, KSipLogFileName, 
       
   161 			EFileLoggingModeAppend, KAddrMessageFormat, &aStr,
       
   162 			&addrBuf, aAddr.Port());                                 
       
   163 		RFileLogger::Write (KSipLogFileDir, KSipLogFileName, 
       
   164 			EFileLoggingModeAppend, KSeparator);
       
   165 		}
       
   166 	else
       
   167 		{
       
   168 		_LIT(KSIPFormat, "SIP: %S: %S port %d");
       
   169 		TBuf<256> log;
       
   170 		log.Format(KSIPFormat, &aStr, &addrBuf, aAddr.Port());
       
   171 		RDebug::RawPrint(log);
       
   172 		}
       
   173 	}
       
   174 
       
   175 inline TBool TSIPLogger::LogDirExists( const TDesC& aFolderName )
       
   176 	{
       
   177     TBool exists( EFalse );
       
   178     RFs fs;
       
   179     if ( KErrNone == fs.Connect() )
       
   180         {
       
   181         TEntry entry;
       
   182         exists = ( fs.Entry( aFolderName, entry ) == KErrNone );
       
   183         fs.Close();        
       
   184         }
       
   185     return exists;
       
   186 	}