voipplugins/sipconnectionprovider/src/scputility.cpp
changeset 0 a4daefaec16c
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007-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:  Provides static utility functions for SCP
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32property.h>
       
    20 #include <crcseprofileregistry.h>
       
    21 #include <ccherror.h>
       
    22 #include <siperr.h>
       
    23 
       
    24 #include "scputility.h"
       
    25 #include "scplogger.h"
       
    26 
       
    27 const TScpUtility::SCchErrorMapping TScpUtility::iErrorTable[] = 
       
    28     {
       
    29         { KCCHErrorInvalidSettings, KErrArgument },
       
    30         { KCCHErrorAccessPointNotDefined, KErrBadName },
       
    31         { KCCHErrorAuthenticationFailed, KErrSIPForbidden }
       
    32     };
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // TScpUtility::ConvertToConnectionEvent
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 TScpConnectionEvent TScpUtility::ConvertToConnectionEvent( 
       
    39     CScpSipConnection::TConnectionState aState,
       
    40     TInt aError )
       
    41     {
       
    42     TScpConnectionEvent returnEvent( EScpUnknown );    
       
    43 
       
    44     switch( aState )
       
    45         {
       
    46         case CScpSipConnection::ERegistered:
       
    47             {
       
    48             returnEvent = EScpRegistered;    
       
    49             }
       
    50             break;
       
    51 
       
    52         case CScpSipConnection::ERegistering:
       
    53             {
       
    54             if( aError == KErrNone )
       
    55                 {
       
    56                 returnEvent = EScpNetworkFound;
       
    57                 }
       
    58             else if( aError == KCCHErrorNetworkLost )
       
    59                 {
       
    60                 returnEvent = EScpNetworkLost;
       
    61                 }
       
    62             else
       
    63                 {
       
    64                 returnEvent = EScpRegistrationFailed;
       
    65                 }
       
    66             }
       
    67             break;
       
    68 
       
    69         case CScpSipConnection::EDeregistered:
       
    70             {
       
    71             returnEvent = EScpDeregistered;
       
    72             }
       
    73             break;
       
    74 
       
    75         case CScpSipConnection::EDeregistering:
       
    76             {
       
    77             returnEvent = EScpNetworkNotFound;
       
    78             }
       
    79             break;
       
    80 
       
    81         default:
       
    82             User::Panic( KNullDesC, KErrGeneral );
       
    83             break;
       
    84         }
       
    85 
       
    86     return returnEvent;
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // TScpUtility::ConvertToConnectionEvent
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 TScpConnectionEvent TScpUtility::ConvertToConnectionEvent( 
       
    94     TCCHSubserviceState aState )
       
    95     {
       
    96     TScpConnectionEvent returnEvent( EScpUnknown );    
       
    97 
       
    98     switch( aState )
       
    99         {
       
   100         case ECCHEnabled:
       
   101             {
       
   102             returnEvent = EScpRegistered;
       
   103             }
       
   104             break;
       
   105 
       
   106         case ECCHConnecting:
       
   107             {
       
   108             returnEvent = EScpNetworkFound;
       
   109             }
       
   110             break;
       
   111 
       
   112         case ECCHDisabled:
       
   113             {
       
   114             returnEvent = EScpDeregistered;
       
   115             }
       
   116             break;
       
   117 
       
   118         case ECCHDisconnecting:
       
   119             {
       
   120             returnEvent = EScpNetworkNotFound;
       
   121             }
       
   122             break;
       
   123 
       
   124         default:
       
   125             User::Panic( KNullDesC, KErrGeneral );
       
   126             break;
       
   127         }
       
   128 
       
   129     return returnEvent;
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // TScpUtility::ResetAndDestroyEntries
       
   134 // (other items were commented in a header).
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void TScpUtility::ResetAndDestroyEntries( TAny* anArray )
       
   138     {
       
   139     SCPLOGSTRING( "TScpUtility::ResetAndDestroyEntries" );
       
   140     
       
   141     RPointerArray<CRCSEProfileEntry>* array = 
       
   142         reinterpret_cast<RPointerArray<CRCSEProfileEntry>*>( anArray );
       
   143         
       
   144     if (array)
       
   145         {
       
   146         array->ResetAndDestroy();
       
   147         array->Close();
       
   148         }
       
   149     }
       
   150     
       
   151 // -----------------------------------------------------------------------------
       
   152 // TScpUtility::ConvertToCchError
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 TInt TScpUtility::ConvertToCchError( TInt aErrorCode )
       
   156     {
       
   157     TInt count = sizeof( iErrorTable ) / sizeof( struct SCchErrorMapping );
       
   158     TInt error = KErrUnknown;
       
   159     while( count-- )
       
   160         {
       
   161         if ( iErrorTable[ count ].iProtocolError == aErrorCode )
       
   162             {
       
   163             error = iErrorTable[ count ].iServiceError;
       
   164             break;
       
   165             }
       
   166         }
       
   167     return error; 
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // TScpUtility::RemovePrefixAndDomain
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TInt TScpUtility::RemovePrefixAndDomain( const TDesC8& aUsername, 
       
   175     RBuf8& aFormattedUsername )
       
   176     {
       
   177     TInt err( KErrNone );
       
   178     
       
   179     TInt startPosition = aUsername.Find( KColon() );
       
   180     if ( KErrNotFound == startPosition )
       
   181         {
       
   182         startPosition = 0;
       
   183         }
       
   184     else
       
   185         {
       
   186         startPosition = ( startPosition + KColon().Length() );
       
   187         }
       
   188     TInt endPos = aUsername.Find( KAt() );
       
   189     if ( KErrNotFound == endPos )
       
   190         {
       
   191         endPos = ( aUsername.Length() - startPosition );
       
   192         }            
       
   193     else
       
   194         {
       
   195         endPos = ( endPos - startPosition );
       
   196         }
       
   197     
       
   198     TPtrC8 formatted = aUsername.Mid( startPosition, endPos );            
       
   199     err = aFormattedUsername.Create( formatted.Length() );
       
   200     
       
   201     if ( KErrNone == err )
       
   202         {
       
   203         aFormattedUsername.Copy( formatted );
       
   204         }
       
   205     
       
   206     return err;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // TScpUtility::CheckSipUsername
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 TBool TScpUtility::CheckSipUsername( const TDesC8& aUsername )
       
   214     {
       
   215     TInt retval = ETrue;
       
   216 
       
   217     if ( KErrNotFound != aUsername.Find( KSipScheme() ) || 
       
   218          KErrNotFound != aUsername.Find( KAt() ) )
       
   219         {
       
   220         SCPLOGSTRING( "TScpUtility::CheckSipUsername: username has prefix or domain" );
       
   221         retval = EFalse;
       
   222         }
       
   223 
       
   224     if( aUsername == KNullDesC8 )
       
   225         {
       
   226         SCPLOGSTRING( "TScpUtility::CheckSipUsername: username is empty - not allowed" );
       
   227         retval = EFalse;
       
   228         }
       
   229         
       
   230     return retval; 
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // TScpUtility::CheckSipPassword
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 TBool TScpUtility::CheckSipPassword( const TDesC8& /*aPassword*/ )
       
   238     {
       
   239     TInt retval = ETrue;
       
   240 
       
   241     return retval; 
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // TScpUtility::GetValidPrefix
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void TScpUtility::GetValidPrefix( const TDesC8& aUsername, TDes8& aPrefix )
       
   249     {
       
   250     // no prefix -> use sip:
       
   251     aPrefix.Copy( KSipScheme() );
       
   252     
       
   253     TInt index = aUsername.Find( KColon() );
       
   254     if ( KErrNotFound != index )
       
   255         {
       
   256         index += KColon().Length();
       
   257         // if prefix isn't sip or sips, prefix isn't valid
       
   258         if ( !aUsername.Left( index ).Compare( KSipScheme() ) )
       
   259             {
       
   260             aPrefix.Copy( KSipScheme() );
       
   261             }
       
   262         else if ( !aUsername.Left( index ).Compare( KSipsScheme() ) )
       
   263             {
       
   264             aPrefix.Copy( KSipsScheme() );
       
   265             }
       
   266         else
       
   267             {
       
   268             // prefix not valid -> use sip:
       
   269             }
       
   270         }
       
   271         
       
   272     SCPLOGSTRING2( "TScpUtility::GetValidPrefix: %S", &aPrefix );
       
   273     }
       
   274 
       
   275 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   276 
       
   277 //  End of File