realtimenetprots/sipfw/SampleApp/resolverplugin/Src/SIPExResolverPlugin.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2005-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 
       
    17 
       
    18 #include "SIPExResolverPlugin.h"
       
    19 
       
    20 #include <apacmdln.h>
       
    21 
       
    22 // SIPEx capabilities - could be also defined in resource of this plugin
       
    23 // but then length of capablities text is in resource file limited to 
       
    24 // 255 characters. However, defining capabilities in resource file's opaque_data 
       
    25 // field is more efficient way.
       
    26 _LIT8(KCapabilities,
       
    27 "<SIP_CLIENT ALLOW_STARTING=\"YES\">\
       
    28 <SIP_HEADERS>\
       
    29 <ACCEPT value=\"application/sdp\"/>\
       
    30 <ACCEPT value=\"SIPEx/InstantMessage\"/>\
       
    31 </SIP_HEADERS>\
       
    32 <SDP_LINES>\
       
    33 <LINE name=\"m\" value=\"application 0 TCP SIPEx\"/>\
       
    34 </SDP_LINES>\
       
    35 </SIP_CLIENT>");
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CTTCNResolverPlugin1::NewL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CSIPExResolverPlugin* CSIPExResolverPlugin::NewL()
       
    42 	{
       
    43 	CSIPExResolverPlugin* self = new ( ELeave ) CSIPExResolverPlugin;
       
    44 	CleanupStack::PushL( self );
       
    45 	self->ConstructL();
       
    46 	CleanupStack::Pop( self );
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CSIPExResolverPlugin::ConstructL
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CSIPExResolverPlugin::ConstructL()
       
    55 	{
       
    56 	const TUid KMyImplementationUid = { KSIPExResolverPluginUID };
       
    57 
       
    58 	RImplInfoPtrArray infoArray;
       
    59 	REComSession::ListImplementationsL( KSIPResolvedClientIFUid, infoArray );
       
    60 	CleanupStack::PushL( TCleanupItem( ResetAndDestroy, &infoArray ) );
       
    61 
       
    62 	TBool found = EFalse;
       
    63 	for ( TInt i=0; !found && i < infoArray.Count(); i++ )
       
    64 		{
       
    65 		CImplementationInformation* info = infoArray[ i ];
       
    66 		if ( info->ImplementationUid() == KMyImplementationUid )
       
    67 			{
       
    68 			TLex8 lex( info->DataType() );
       
    69 			TUint value( 0 );
       
    70 			User::LeaveIfError( lex.Val( value, EHex ) );
       
    71 		    iApplicationUID.iUid = value;
       
    72 			found = ETrue;
       
    73 			}
       
    74 		}
       
    75 
       
    76 	CleanupStack::PopAndDestroy( 1 ); // infoArray
       
    77 
       
    78 	if ( !found )
       
    79 		{
       
    80 		User::Leave( KErrNotFound );
       
    81 		}
       
    82 		
       
    83 	User::LeaveIfError( iApaSession.Connect() );
       
    84 	User::LeaveIfError( iApaSession.GetAppInfo( iAppInfo, iApplicationUID ) );		
       
    85 	}
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSIPExResolverPlugin::~CSIPExResolverPlugin
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CSIPExResolverPlugin::~CSIPExResolverPlugin()
       
    92 	{
       
    93 	iApaSession.Close();
       
    94 	}
       
    95 	
       
    96 // -----------------------------------------------------------------------------
       
    97 // CSIPExResolverPlugin::ChannelL
       
    98 // -----------------------------------------------------------------------------
       
    99 //	
       
   100 TUid CSIPExResolverPlugin::ChannelL( RStringF /*aMethod*/,
       
   101     const TDesC8& /*aRequestUri*/,
       
   102     const RPointerArray<CSIPHeaderBase>& /*aHeaders*/,
       
   103     const TDesC8& /*aContent*/,
       
   104     const CSIPContentTypeHeader* /*aContentType*/)
       
   105     {
       
   106     return iApplicationUID;
       
   107     }
       
   108 
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CSIPExResolverPlugin::ConnectL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CSIPExResolverPlugin::ConnectL( TUid aUid )
       
   115 	{
       
   116 	// Launch app based on uid passed from SIP stack
       
   117 	//
       
   118 	TApaAppInfo appInfo;
       
   119 	User::LeaveIfError( iApaSession.GetAppInfo( appInfo, aUid ) );
       
   120 	CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   121 #ifdef EKA2
       
   122 	cmdLine->SetExecutableNameL( appInfo.iFullName );
       
   123 #else
       
   124 	cmdLine->SetLibraryNameL( appInfo.iFullName );
       
   125 #endif
       
   126 	User::LeaveIfError( iApaSession.StartApp( *cmdLine ) );
       
   127 	CleanupStack::PopAndDestroy( cmdLine ); 
       
   128 	}
       
   129 	
       
   130 // -----------------------------------------------------------------------------
       
   131 // CTTCNResolverPlugin1::Capabilities
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 const TDesC8& CSIPExResolverPlugin::Capabilities()
       
   135     {
       
   136     return KCapabilities;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CSIPExResolverPlugin::ResetAndDestroy
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CSIPExResolverPlugin::ResetAndDestroy( TAny* anArray )
       
   144 	{
       
   145     RImplInfoPtrArray* array = reinterpret_cast<RImplInfoPtrArray*>( anArray );
       
   146     if (array)
       
   147         {
       
   148         array->ResetAndDestroy();
       
   149         }
       
   150 	}
       
   151