natfw/natfwshared/inc/natfwlogs.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef NATFWLOGS_H
       
    22 #define NATFWLOGS_H
       
    23 
       
    24 #include <utf.h>
       
    25 #include <e32debug.h>
       
    26 #include <in_sock.h>
       
    27 
       
    28 
       
    29 _LIT( KNATFWWarning, "NATFW: Text contains not allowed characters, log ignored" );
       
    30 
       
    31 class TNATFWLog
       
    32     {
       
    33     public:
       
    34 
       
    35     inline static void Print( const TDesC16& aName, const TDesC16& aStr ) 
       
    36         {
       
    37         TChar notAllowed('%');
       
    38         if ( aStr.Locate( notAllowed ) == KErrNotFound )
       
    39             {
       
    40             TBuf<256> str;
       
    41             _LIT( KNATFW, "%S %S" );
       
    42             str.Format( KNATFW(), &aName, &aStr );
       
    43             RDebug::Print(str);
       
    44             }
       
    45         else
       
    46             {
       
    47             RDebug::Print( KNATFWWarning );
       
    48             }    
       
    49         }    
       
    50 
       
    51     inline static void Print( 
       
    52         const TDesC16& aName, 
       
    53         const TDesC16& aStr, 
       
    54         TInt           aValue ) 
       
    55         {
       
    56         TChar notAllowed('%');
       
    57         if ( aStr.Locate( notAllowed ) == KErrNotFound )
       
    58             {
       
    59             TBuf<256> str;
       
    60             _LIT( KNATFW, "%S %S %d" );
       
    61             str.Format( KNATFW(), &aName, &aStr, aValue );
       
    62             RDebug::Print(str);                
       
    63             }
       
    64         else
       
    65             {
       
    66             RDebug::Print( KNATFWWarning );                            
       
    67             }    
       
    68         }
       
    69         
       
    70     inline static void Print(
       
    71         const TDesC16& aName, 
       
    72         const TDesC16& aStr1, 
       
    73         TInt           aValue1, 
       
    74         const TDesC16& aStr2, 
       
    75         TInt           aValue2) 
       
    76         {
       
    77         TChar notAllowed('%');
       
    78         if ( aStr1.Locate( notAllowed ) == KErrNotFound &&
       
    79              aStr2.Locate( notAllowed ) == KErrNotFound)
       
    80             {
       
    81             TBuf<256> str;
       
    82             _LIT( KNATFW, "%S %S %d, %S %d" );
       
    83             str.Format( KNATFW(), &aName, &aStr1, aValue1, 
       
    84                         &aStr2, aValue2 );
       
    85             RDebug::Print(str);                
       
    86             }
       
    87         else
       
    88             {
       
    89             RDebug::Print( KNATFWWarning );                            
       
    90             }
       
    91         }
       
    92         
       
    93     inline static void Print(
       
    94         const TDesC16& aName, 
       
    95         const TDesC16& aStr1, 
       
    96         TInt           aValue1, 
       
    97         const TDesC16& aStr2, 
       
    98         TInt           aValue2, 
       
    99         const TDesC16& aStr3, 
       
   100         TInt           aValue3 ) 
       
   101         {
       
   102         TChar notAllowed('%');
       
   103         if ( aStr1.Locate( notAllowed ) == KErrNotFound &&
       
   104              aStr2.Locate( notAllowed ) == KErrNotFound &&
       
   105              aStr3.Locate( notAllowed ) == KErrNotFound )
       
   106             {
       
   107             TBuf<256> str;
       
   108             _LIT( KNATFW, "%S %S %d, %S %d, %S %d" );
       
   109             str.Format( KNATFW(), &aName, &aStr1, aValue1, 
       
   110                         &aStr2, aValue2, &aStr3, aValue3 );
       
   111             RDebug::Print( str );
       
   112             }
       
   113         else
       
   114             {
       
   115             RDebug::Print( KNATFWWarning );                            
       
   116             }
       
   117         }
       
   118     
       
   119     inline static void Print(
       
   120         const TDesC16& aName, 
       
   121         const TDesC16& aStr1, 
       
   122         TInt           aValue1, 
       
   123         const TDesC16& aStr2, 
       
   124         TInt           aValue2, 
       
   125         const TDesC16& aStr3, 
       
   126         TInt           aValue3, 
       
   127         const TDesC16& aStr4, 
       
   128         TInt           aValue4) 
       
   129         {
       
   130         TChar notAllowed('%');
       
   131         if ( aStr1.Locate( notAllowed ) == KErrNotFound &&
       
   132              aStr2.Locate( notAllowed ) == KErrNotFound &&
       
   133              aStr3.Locate( notAllowed ) == KErrNotFound &&
       
   134              aStr4.Locate( notAllowed ) == KErrNotFound)
       
   135             {
       
   136             TBuf<256> str;
       
   137             _LIT( KNATFW, "%S %S %d, %S %d, %S %d, %S %d" );
       
   138             str.Format( KNATFW(), &aName, &aStr1, aValue1, 
       
   139                         &aStr2, aValue2, &aStr3, aValue3, &aStr4, aValue4 );
       
   140             RDebug::Print(str);                
       
   141             }
       
   142         else
       
   143             {
       
   144             RDebug::Print( KNATFWWarning );                            
       
   145             }
       
   146         }    
       
   147 
       
   148     inline static void Print(
       
   149         const TDesC16& aName, 
       
   150         const TDesC16& aStr1, 
       
   151         TInt           aValue1, 
       
   152         TInt           aValue2) 
       
   153         {
       
   154         TChar notAllowed('%');
       
   155         if ( aStr1.Locate( notAllowed ) == KErrNotFound )
       
   156             {
       
   157             TBuf<256> str;
       
   158             _LIT( KNATFW, "%S %S %d, %d" );
       
   159             str.Format( KNATFW(), &aName, &aStr1, aValue1, 
       
   160                         aValue2 );
       
   161             RDebug::Print(str);                
       
   162             }
       
   163         else
       
   164             {
       
   165             RDebug::Print( KNATFWWarning );                            
       
   166             }
       
   167         }
       
   168 
       
   169     inline static void Print(
       
   170         const TDesC16& aName,
       
   171         const TDesC16& aStrA,
       
   172         const TDesC8& aStrB) 
       
   173         {
       
   174         TChar notAllowed('%');
       
   175         if ( aName.Locate( notAllowed ) == KErrNotFound  &&
       
   176              aStrB.Locate( notAllowed ) == KErrNotFound )
       
   177             {
       
   178             TBuf<100> str2;
       
   179             CnvUtfConverter::ConvertToUnicodeFromUtf8(str2, aStrB);
       
   180 
       
   181             TBuf<256> str;
       
   182             _LIT(KNATFW, "%S, %S %S");
       
   183             str.Format(KNATFW(), &aName, &aStrA, &str2);
       
   184             RDebug::Print(str);
       
   185             }
       
   186         else
       
   187             {
       
   188             RDebug::Print( KNATFWWarning );                        
       
   189             }    
       
   190         }
       
   191     
       
   192     inline static void Print( const TDesC16& aStr,
       
   193                               const TInetAddr& aAddr )
       
   194         {
       
   195         _LIT(KLogFormat, "NATFWMultiplexer Protocols: %S: %S port %d \n");
       
   196         const TInt KIPv6AddrMaxLen = 39;
       
   197         TBuf<KIPv6AddrMaxLen> addrBuf;
       
   198         aAddr.Output(addrBuf);
       
   199         TBuf<256> str;
       
   200         str.Format(KLogFormat, &aStr, &addrBuf, aAddr.Port());
       
   201 
       
   202         RDebug::RawPrint(str);
       
   203         }
       
   204     
       
   205     inline static void Print( const TDesC16& aModuleName, 
       
   206                               const TDesC16& aTraceStr,
       
   207                               const TInetAddr& aAddr )
       
   208         {
       
   209         const TInt KIPv6AddrMaxLen = 39;
       
   210         TBuf<KIPv6AddrMaxLen> addrBuf;
       
   211         aAddr.Output( addrBuf );
       
   212         
       
   213         TBuf<256> str;
       
   214         _LIT( KLogFormat, "%S %S %S port %d \n" );
       
   215         str.Format( KLogFormat, &aModuleName, &aTraceStr, &addrBuf, aAddr.Port() );
       
   216 
       
   217         RDebug::RawPrint( str );
       
   218         }
       
   219     }; 
       
   220 
       
   221 #endif // end of class TNATFWLog
       
   222 
       
   223 // End of File