browserutilities/schemehandler/SchemeDispatcher/src/WtaiHandler.cpp
changeset 0 dd21522fd290
child 26 cb62a4f66ebe
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002 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 the License "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 *      Implementation of Scheme handler interface implementation for wtai:// scheme
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "WtaiHandler.h"
       
    24 #include "SchemeDispLogger.h"
       
    25 #include <ECom.h>		// For REComSession
       
    26 #include <eikenv.h>
       
    27 #include <apparc.h>
       
    28 #include <apgcli.h>
       
    29 
       
    30 // ================= CONSTANTS =======================
       
    31 LOCAL_C const TText KSemiColon = ';';
       
    32 LOCAL_C const TText KExclamationMark = '!';
       
    33 // NW_STAT_WTAI_UNSUPPORTED_LIBRARY
       
    34 LOCAL_C const TInt KErrUnsuppLibrary = (-26179);
       
    35 // NW_STAT_WTAI_UNSUPPORTED_FUNCTION
       
    36 LOCAL_C const TInt KErrUnsupFunction = (-26178);
       
    37 
       
    38 _LIT( KWtai, "wtai://");
       
    39 _LIT( KWPMC, "wp/mc" );
       
    40 _LIT( KWPSD, "wp/sd" );
       
    41 _LIT( KWPAP, "wp/ap" );
       
    42 
       
    43 _LIT( KWP, "wp/" );
       
    44 _LIT( KMC, "mc;" );
       
    45 _LIT( KSD, "sd;" );
       
    46 _LIT( KAP, "ap;" );
       
    47 
       
    48 // ================= MEMBER FUNCTIONS =======================
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CWtaiHandler::NewL()
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 CWtaiHandler* CWtaiHandler::NewL( const TDesC& aUrl )
       
    55 	{
       
    56 	CLOG_ENTERFN( "CWtaiHandler::NewL()" );
       
    57 
       
    58 	CWtaiHandler* self=new(ELeave) CWtaiHandler();
       
    59 	CleanupStack::PushL(self);
       
    60 	self->ConstructL( aUrl );
       
    61 	CleanupStack::Pop(self);
       
    62 
       
    63 	CLOG_LEAVEFN( "CWtaiHandler::NewL()" );
       
    64 
       
    65 	return self;
       
    66 	}
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // CWtaiHandler::~CWtaiHandler()
       
    70 // ---------------------------------------------------------
       
    71 //
       
    72 CWtaiHandler::~CWtaiHandler()
       
    73 	{
       
    74 	CLOG_ENTERFN( "CWtaiHandler::~CWtaiHandler()" );
       
    75 
       
    76     if( iTelService != NULL )
       
    77         {
       
    78 	    iTelService->RemoveObserver(this);
       
    79 	    delete iTelService;
       
    80         iTelService = NULL;
       
    81         }
       
    82 
       
    83 	CLOG_LEAVEFN( "CWtaiHandler::~CWtaiHandler()" );
       
    84 	}
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CWtaiHandler::CWtaiHandler()
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 CWtaiHandler::CWtaiHandler() : CBaseHandler()
       
    91 	{
       
    92 	// Deliberately do nothing here : See ConstructL() for initialisation 
       
    93     // completion.
       
    94 	}
       
    95 
       
    96 // ---------------------------------------------------------
       
    97 // CWtaiHandler::ConstructL()
       
    98 // ---------------------------------------------------------
       
    99 //
       
   100 void CWtaiHandler::ConstructL( const TDesC& aUrl )
       
   101 	{
       
   102 	CLOG_ENTERFN( "CWtaiHandler::ConstructL()" );
       
   103 
       
   104 	BaseConstructL( aUrl );
       
   105 
       
   106 	CLOG_ENTERFN( "calling CBrowserTelService::NewL()" );
       
   107 
       
   108 	CLOG_LEAVEFN( "CWtaiHandler::ConstructL()" );
       
   109 	}
       
   110 
       
   111 // ---------------------------------------------------------
       
   112 // CWtaiHandler::HandleUrlEmbeddedL()
       
   113 // ---------------------------------------------------------
       
   114 //
       
   115 void CWtaiHandler::HandleUrlEmbeddedL()
       
   116 	{
       
   117 	CLOG_ENTERFN( "CWtaiHandler::HandleUrlEmbeddedL()" );
       
   118     TInt err;
       
   119 
       
   120 	TPtrC library_function;
       
   121 
       
   122 	iTelService = CBrowserTelService::NewL();
       
   123     iTelService->AddObserver(this);
       
   124 
       
   125 	TRAP( err, library_function.Set( GetWtaiLibraryFunctionL() ) );
       
   126 	TInt count = GetParameterCountL();
       
   127     TBool confirmDtmfValue = ReadSdConfirmDtmfValueL();
       
   128 	if( ( err == KErrNone ) || ( count <= 0 ) )
       
   129 		{
       
   130 		if( 0 == library_function.CompareF( KWPMC ) )
       
   131 			{
       
   132 			TPtrC number = GetParameterL( ESchemeWtaiNumber );
       
   133 
       
   134 			CLOG_WRITE_FORMAT( "CWtaiHandler::GetParameter: number: %S", &number );
       
   135 
       
   136             err = iTelService->MakeCall( number, confirmDtmfValue );
       
   137 			}
       
   138 		else if( 0 == library_function.CompareF( KWPSD ) )
       
   139 			{
       
   140 			TPtrC dtmf = GetParameterL( ESchemeWtaiNumber );
       
   141 
       
   142 			CLOG_WRITE_FORMAT( "CWtaiHandler::GetParameter: dtmf: %S", &dtmf );
       
   143 
       
   144             err = iTelService->SendDTMF(dtmf, confirmDtmfValue);
       
   145 			}
       
   146 		else if( 0 == library_function.CompareF( KWPAP ) )
       
   147 			{
       
   148 			TPtrC number = GetParameterL( ESchemeWtaiNumber );
       
   149 			CLOG_WRITE_FORMAT( "CWtaiHandler::GetParameter: number: %S", &number );
       
   150 			TPtrC name = GetParameterL( ESchemeWtaiName );
       
   151 			CLOG_WRITE_FORMAT( "CWtaiHandler::GetParameter: name: %S", &name );
       
   152 			TPtrC email = GetParameterL( ESchemeWtaiEmail );
       
   153 			CLOG_WRITE_FORMAT( "CWtaiHandler::GetParameter: email: %S", &email );
       
   154 			err = iTelService->AddPBEntryL( number, name, email );
       
   155 			}
       
   156 		}
       
   157 
       
   158     NotifyClient();
       
   159 
       
   160     ErrorHandlerL( err );
       
   161 
       
   162 	CLOG_LEAVEFN( "CWtaiHandler::HandleUrlEmbeddedL()" );
       
   163 	}
       
   164 
       
   165 // ---------------------------------------------------------
       
   166 // CWtaiHandler::HandleUrlStandaloneL()
       
   167 // ---------------------------------------------------------
       
   168 //
       
   169 void CWtaiHandler::HandleUrlStandaloneL()
       
   170 	{
       
   171 	CLOG_ENTERFN( "CWtaiHandler::HandleUrlStandaloneL()" );
       
   172 
       
   173     LaunchSchemeAppWithCommandLineL();
       
   174 
       
   175 	CLOG_LEAVEFN( "CWtaiHandler::HandleUrlStandaloneL()" );
       
   176 	}
       
   177 
       
   178 // ---------------------------------------------------------
       
   179 // CWtaiHandler::GetWtaiLibraryFunctionL()
       
   180 // ---------------------------------------------------------
       
   181 //
       
   182 TPtrC CWtaiHandler::GetWtaiLibraryFunctionL()
       
   183 	{
       
   184 	CLOG_ENTERFN( "CWtaiHandler::GetWtaiLibraryFunction()" );
       
   185     // wtai://<library>/<function> (; <parameter>)*
       
   186 
       
   187 	TPtrC path = RemoveSchemeFromUrlL( KWtai );
       
   188 
       
   189 	// <library>/<function> (; <parameter>)*
       
   190     TInt colonPos = VerifyWtaiSchemeL( path );
       
   191 
       
   192 	TPtrC library_function = path.Left( colonPos );
       
   193 
       
   194 	CLOG_LEAVEFN( "CWtaiHandler::GetWtaiLibraryFunction()" );
       
   195 
       
   196 	return library_function; // <library>/<function>
       
   197 	}
       
   198 
       
   199 // ---------------------------------------------------------
       
   200 // CWtaiHandler::VerifyWtaiSchemeL()
       
   201 // ---------------------------------------------------------
       
   202 //
       
   203 TInt CWtaiHandler::VerifyWtaiSchemeL( TPtrC path )
       
   204     {
       
   205 	TInt colonPos = path.Locate( ';' ); // first occurance
       
   206 
       
   207 	if ( colonPos <= 0 )
       
   208 		{
       
   209  		User::Leave( KErrGeneral );
       
   210 		}
       
   211     else if( KErrNotFound == path.FindF( KWP() ) ) // check if it's valid library
       
   212         {
       
   213         User::Leave( KErrUnsuppLibrary );
       
   214         }
       
   215     else if( ( KErrNotFound != path.FindF( KMC() ) ) ||
       
   216              ( KErrNotFound != path.FindF( KSD() ) ) ||
       
   217              ( KErrNotFound != path.FindF( KAP() ) ) ) // check if it's valid function
       
   218         {
       
   219         return colonPos;
       
   220         }
       
   221     else
       
   222         {
       
   223         User::Leave( KErrUnsupFunction );
       
   224         }
       
   225 
       
   226     return colonPos;
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------
       
   230 // CWtaiHandler::GetParameterCountL()
       
   231 // ---------------------------------------------------------
       
   232 //
       
   233 TInt CWtaiHandler::GetParameterCountL()
       
   234 	{
       
   235 	CLOG_ENTERFN( "CWtaiHandler::GetParameterCount()" );
       
   236 
       
   237 	// wtai://<library>/<function> (; <parameter>)*
       
   238 
       
   239 	TInt retVal = 0;
       
   240 	TPtrC path = RemoveSchemeFromUrlL( KWtai );
       
   241 	TInt length = path.Length();
       
   242 
       
   243 	/* Count for the amount of parameter */
       
   244 	for( TInt i = 0; i < length; i++ )
       
   245 		{
       
   246 		if( path[i] == KSemiColon )
       
   247 			{
       
   248 			retVal++;
       
   249 			}
       
   250 		}
       
   251 
       
   252 	CLOG_LEAVEFN( "CWtaiHandler::GetParameterCount()" );
       
   253 
       
   254 	return retVal;
       
   255 	}
       
   256 
       
   257 // ---------------------------------------------------------
       
   258 // CWtaiHandler::GetParameterL()
       
   259 // ---------------------------------------------------------
       
   260 //
       
   261 TPtrC CWtaiHandler::GetParameterL(TInt aPos)
       
   262 	{
       
   263 	CLOG_ENTERFN( "CWtaiHandler::GetParameter()" );
       
   264 
       
   265 	// wtai://<library>/<function> (; <parameter>)*
       
   266 
       
   267 	TPtrC path = RemoveSchemeFromUrlL( KWtai );
       
   268 
       
   269 	// <library>/<function> (; <parameter>)*
       
   270 
       
   271 	TInt length = path.Length();
       
   272 	TInt start = 0; // starting position of the required parameter
       
   273 	TInt pos = 1;   // current parameter
       
   274 	TInt i = 0;     // character iterator
       
   275 
       
   276 	while( i < length )
       
   277 		{
       
   278 		if( ( path[i] == KSemiColon )  || ( path[i] == KExclamationMark ) )
       
   279 			{
       
   280 			// begining of a parameter is found
       
   281 			if( ( pos == aPos ) &&  ( path[i] != KExclamationMark ) )
       
   282 				{
       
   283 				// begining of the required parameter
       
   284 				start = i + 1; // skipping semicolon
       
   285 				}
       
   286 			else
       
   287 				{
       
   288 				if( start != 0 )
       
   289 					{
       
   290 					// end of the required parameter
       
   291 					break;
       
   292 					}
       
   293 				}
       
   294 			pos++;
       
   295 			}
       
   296 		i++;
       
   297 		}
       
   298 
       
   299 	start = ( start == 0 ) ? i : start; // there is n parameter but the (n+1). is required
       
   300 
       
   301 	CLOG_LEAVEFN( "CWtaiHandler::GetParameter()" );
       
   302 
       
   303 	return path.Mid( start, i-start ); // found parameter
       
   304 	}
       
   305 
       
   306 // ---------------------------------------------------------
       
   307 // CWtaiHandler::BrowserTelServiceEvent()
       
   308 // ---------------------------------------------------------
       
   309 //
       
   310 void CWtaiHandler::BrowserTelServiceEvent( TBrowserTelServiceState aEvent )
       
   311 	{
       
   312 	CLOG_ENTERFN( "CWtaiHandler::BrowserTelServiceEvent()" );
       
   313 
       
   314 	if( EIdle == aEvent )
       
   315 		{
       
   316 		NotifyClient();
       
   317 		}
       
   318 	}
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // CWtaiHandler::BrowserTelServiceError()
       
   322 // ---------------------------------------------------------
       
   323 //
       
   324 void CWtaiHandler::BrowserTelServiceError( TBrowserTelServiceError /*aError*/)
       
   325 	{
       
   326 	}
       
   327 
       
   328 // ---------------------------------------------------------
       
   329 // CWtaiHandler::BrowserTelServiceError()
       
   330 // ---------------------------------------------------------
       
   331 //
       
   332 void CWtaiHandler::NotifyClient()
       
   333 	{
       
   334 	if( NULL !=iSchemeDoc )
       
   335 		{
       
   336         iSchemeDoc->HandleServerAppExit( KErrNone );
       
   337 		}
       
   338 	}