voipplugins/sipimresolver/src/sipimresolver.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 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:  implementation of sipimresolver
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <spentry.h>
       
    20 #include <spproperty.h>
       
    21 #include <spsettings.h>
       
    22 #include <sdpmediafield.h>
       
    23 
       
    24 #include "sipimresolver.h"
       
    25 #include "csipclientresolverutils.h"
       
    26 #include "sipimresolverdebug.h"
       
    27 
       
    28 // media field descriptors
       
    29 _LIT8( KIMField1, "m=application 0 TCP SIPIM\r\n" );
       
    30 // For content-type header
       
    31 _LIT8( KIMContentType, "text/plain" );
       
    32 // For content-type header checks
       
    33 _LIT8( KIMMediaTypeApp, "text" );
       
    34 // SDP media subtype
       
    35 _LIT8( KIMMediaSubtypeSdp, "plain" );
       
    36 
       
    37 // ======== LOCAL FUNCTIONS ========
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CleanupSdpMediasArray
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void CleanupSdpMediasArray( TAny* aObj )
       
    44     {
       
    45     if ( aObj )
       
    46         {
       
    47         static_cast<RPointerArray<CSdpMediaField>*>( aObj )->
       
    48             ResetAndDestroy();
       
    49         }
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CleanupSipContentTypeHeaderArray
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CleanupSipContentTypeHeaderArray( TAny* aObj )
       
    57     {
       
    58     if ( aObj )
       
    59         {
       
    60         static_cast<RPointerArray<CSIPContentTypeHeader>*>( aObj )->
       
    61             ResetAndDestroy();
       
    62         }
       
    63     }
       
    64 
       
    65 
       
    66 // ======== MEMBER FUNCTIONS ========
       
    67 
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CSipImResolver::CSipImResolver
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CSipImResolver::CSipImResolver() 
       
    74     {
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CSipImResolver::NewL
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 CSipImResolver* CSipImResolver::NewL()
       
    82 	{
       
    83 	SIPIMRLOG( "[SIPIMRESOLVER] -> CSipImResolver::NewL()" )
       
    84 	CSipImResolver* self = new ( ELeave ) CSipImResolver;
       
    85 	return self;
       
    86 	}
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CSipImResolver::~CSipImResolver
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 CSipImResolver::~CSipImResolver()
       
    93 	{
       
    94     SIPIMRLOG( "[SIPIMRESOLVER] -> CSipImResolver::~CSipImResolver()" )
       
    95 	}
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // From class CSIPResolvedClient2
       
    99 // CSipImResolver::MatchAcceptContactsL
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 TBool CSipImResolver::MatchAcceptContactsL(
       
   103     RStringF /*aMethod*/,
       
   104     const CUri8& /*aRequestUri*/,
       
   105     const RPointerArray<CSIPHeaderBase>& /*aHeaders*/,
       
   106     const TDesC8& /*aContent*/,
       
   107     const CSIPContentTypeHeader* /*aContentType*/,
       
   108     TUid& /*aClientUid*/ )
       
   109     {
       
   110     return EFalse;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // From class CSIPResolvedClient2
       
   115 // CSipImResolver::MatchEventL
       
   116 // ---------------------------------------------------------------------------
       
   117 // 
       
   118 TBool CSipImResolver::MatchEventL(
       
   119     RStringF /*aMethod*/,
       
   120     const CUri8& /*aRequestUri*/,
       
   121     const RPointerArray<CSIPHeaderBase>& /*aHeaders*/,
       
   122     const TDesC8& /*aContent*/,
       
   123     const CSIPContentTypeHeader* /*aContentType*/,
       
   124     TUid& /*aClientUid*/)
       
   125     {
       
   126     return EFalse;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // From class CSIPResolvedClient2
       
   131 // CSIPImResolver::MatchRequestL
       
   132 // ---------------------------------------------------------------------------
       
   133 // 
       
   134 TBool CSipImResolver::MatchRequestL(
       
   135     RStringF /*aMethod*/,
       
   136     const CUri8& aRequestUri,
       
   137     const RPointerArray<CSIPHeaderBase>& /*aHeaders*/,
       
   138     const TDesC8& aContent,
       
   139     const CSIPContentTypeHeader* aContentType,
       
   140     TUid& aClientUid )
       
   141     {
       
   142     SIPIMRLOG( "[SIPIMRESOLVER] MatchRequetsL() IN" )
       
   143     
       
   144     aClientUid.iUid = 0;
       
   145     RArray<TInt> callProviderIds;
       
   146     CleanupClosePushL( callProviderIds );
       
   147     
       
   148     TBool match( EFalse );
       
   149     TBool imrequest = ( aContent.Length() > 0 && aContentType &&
       
   150         aContentType->MediaType().CompareF( KIMMediaTypeApp ) == 0 &&
       
   151         aContentType->MediaSubtype().CompareF( KIMMediaSubtypeSdp ) == 0 );
       
   152     
       
   153     if( imrequest )
       
   154         {
       
   155         CSPSettings* spSettings = CSPSettings::NewLC();
       
   156         CSPProperty* property = CSPProperty::NewLC();
       
   157         
       
   158         RArray<TUint> serviceIds;
       
   159         CleanupClosePushL( serviceIds );
       
   160         spSettings->FindServiceIdsL( serviceIds );
       
   161         
       
   162         for( TInt i( 0 ) ; i < serviceIds.Count() ; i++ )
       
   163             {
       
   164             TInt err = spSettings->FindPropertyL( 
       
   165                 serviceIds[ i ],
       
   166                 EPropertyCallProviderPluginId,
       
   167                 *property );
       
   168             
       
   169             if ( !err )
       
   170                 {
       
   171                 TInt callProviderId( 0 );
       
   172                 err = property->GetValue( callProviderId );
       
   173                 
       
   174                 if ( !err )
       
   175                     {
       
   176                     callProviderIds.AppendL( callProviderId );
       
   177                     }
       
   178                 }
       
   179             }
       
   180         
       
   181         CleanupStack::PopAndDestroy( &serviceIds );
       
   182         CleanupStack::PopAndDestroy( property );
       
   183         CleanupStack::PopAndDestroy( spSettings ); 
       
   184         
       
   185         CSipClientResolverUtils* resolver = CSipClientResolverUtils::NewLC();
       
   186                 
       
   187         RArray<TUid> uids;
       
   188         CleanupClosePushL( uids );
       
   189         
       
   190         TRAPD( err, resolver->GetAllImplementationUidsWithUserL(
       
   191             aRequestUri.Uri().Extract( EUriUserinfo ), uids ) );
       
   192         if ( KErrNotFound != err && KErrNone != err )
       
   193             {
       
   194             User::Leave( err );
       
   195             }
       
   196         TInt imProviderId( KErrNotFound );
       
   197         for ( TInt j( 0 ) ; j < uids.Count() ; j++ )
       
   198             {
       
   199             TInt ret = callProviderIds.Find( uids[ j ].iUid );
       
   200             
       
   201             if ( KErrNotFound == ret )
       
   202                 {
       
   203                 imProviderId = uids[ j ].iUid;
       
   204                 break;
       
   205                 }         
       
   206             }
       
   207         
       
   208         CleanupStack::PopAndDestroy( &uids );
       
   209         CleanupStack::PopAndDestroy( resolver );
       
   210         
       
   211         if ( !err && ( KErrNotFound != imProviderId ) )
       
   212             {
       
   213             aClientUid.iUid = imProviderId;
       
   214             match = ETrue;
       
   215             }
       
   216         }
       
   217     
       
   218     CleanupStack::PopAndDestroy( &callProviderIds );
       
   219     
       
   220     SIPIMRLOGP( "[SIPIMRESOLVER] MatchRequetsL() match = %d", match  )
       
   221     SIPIMRLOGP( "[SIPIMRESOLVER] MatchRequetsL() client uid = %d", aClientUid.iUid  )
       
   222   
       
   223     return match; 
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // From class CSIPResolvedClient2
       
   228 // CSIPImResolver::ConnectSupported
       
   229 // ---------------------------------------------------------------------------
       
   230 // 
       
   231 TBool CSipImResolver::ConnectSupported()
       
   232     {
       
   233     return EFalse;
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // From class CSIPResolvedClient2
       
   238 // CSIPImResolver::ConnectL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CSipImResolver::ConnectL( const TUid& /*aClientUid*/ )
       
   242     {
       
   243     // do nothing
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // From class CSIPResolvedClient2
       
   248 // CSIPImResolver::CancelConnect
       
   249 // ---------------------------------------------------------------------------
       
   250 // 
       
   251 void CSipImResolver::CancelConnect( const TUid& /*aClientUid*/ )
       
   252     {
       
   253     // do nothing
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // From class CSIPResolvedClient2
       
   258 // CSIPImResolver::SupportedContentTypesL
       
   259 // ---------------------------------------------------------------------------
       
   260 // 
       
   261 RPointerArray<CSIPContentTypeHeader> CSipImResolver::SupportedContentTypesL()
       
   262     {
       
   263     SIPIMRLOG( "[SIPIMRESOLVER] -> CSipImResolver::SupportedContentTypesL()" )
       
   264 
       
   265     RPointerArray<CSIPContentTypeHeader> ret;   
       
   266     TCleanupItem tci( CleanupSipContentTypeHeaderArray, &ret );
       
   267     
       
   268     CleanupStack::PushL( tci );
       
   269     CSIPContentTypeHeader* ctype = CSIPContentTypeHeader::DecodeL(
       
   270         KIMContentType );
       
   271     ret.AppendL( ctype );
       
   272     CleanupStack::Pop( ); // TCleanupItem
       
   273 
       
   274     SIPIMRLOG( "[SIPIMRESOLVER] <- CSipImResolver::SupportedContentTypesL()" )
       
   275     return ret;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // From class CSIPResolvedClient2
       
   280 // CSIPImResolver::SupportedSdpMediasL
       
   281 // ---------------------------------------------------------------------------
       
   282 // 
       
   283 RPointerArray<CSdpMediaField> CSipImResolver::SupportedSdpMediasL()
       
   284     {
       
   285     SIPIMRLOG( "[SIPIMRESOLVER] -> CSipImResolver::SupportedSdpMediasL()" )
       
   286     
       
   287     // Initialise return array
       
   288     RPointerArray<CSdpMediaField> ret;
       
   289     TCleanupItem tci( CleanupSdpMediasArray, &ret );
       
   290     CleanupStack::PushL( tci );  
       
   291     
       
   292     CSdpMediaField* field = CSdpMediaField::DecodeLC( KIMField1 );
       
   293     ret.AppendL( field );
       
   294     CleanupStack::Pop( field );    
       
   295     
       
   296     CleanupStack::Pop( ); // TCleanupItem
       
   297 
       
   298     SIPIMRLOG( "[SIPIMRESOLVER] <- CSipImResolver::SupportedSdpMediasL()" )
       
   299     return ret;
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 // From class CSIPResolvedClient2
       
   304 // CSIPImResolver::AddClientSpecificHeadersForOptionsResponseL
       
   305 // ---------------------------------------------------------------------------
       
   306 // 
       
   307 void CSipImResolver::AddClientSpecificHeadersForOptionsResponseL(
       
   308     RPointerArray<CSIPHeaderBase>& /*aHeaders*/ )
       
   309     {
       
   310     // do nothing
       
   311     }