xdmprotocols/XcapProtocol/src/XcapProtocol.cpp
branchRCL_3
changeset 17 2669f8761a99
parent 16 2580314736af
child 18 fbd2e7cec7ef
equal deleted inserted replaced
16:2580314736af 17:2669f8761a99
     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: CXcapProtocol
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <hal.h>
       
    21 #include <f32file.h>
       
    22 #include <flogger.h>
       
    23 #include <XdmSettingsApi.h>
       
    24 #include <XdmSettingsProperty.h>
       
    25 #include <XdmSettingsCollection.h>
       
    26 #include <implementationproxy.h>
       
    27 #include <msgconnmanagerapi.h>
       
    28 #include "XcapAppUsage.h"
       
    29 #include "XcapEarlyIms.h"
       
    30 #include "XcapProtocol.h"
       
    31 #include "XcapDocument.h"
       
    32 #include "xdmlogwriter.h"
       
    33 #include "XcapDocumentNode.h"
       
    34 #include "XcapDirectory.h"
       
    35 #include "XdmXmlParser.h"
       
    36 #include "XdmCredentials.h"
       
    37 #include "XcapHttpReqGet.h"
       
    38 #include "XdmProtocolInfo.h"
       
    39 #include "XdmShutdownTimer.h"
       
    40 #include "XcapHttpTransport.h"
       
    41 #include "XdmOperationFactory.h"
       
    42 
       
    43 // ----------------------------------------------------------
       
    44 // CXcapProtocol::CXcapProtocol
       
    45 // 
       
    46 // ----------------------------------------------------------
       
    47 //
       
    48 CXcapProtocol::CXcapProtocol() : iSuspend( EFalse ),
       
    49                                  iCacheUsage( EFalse ),
       
    50                                  iTransferMediaOpen( EFalse ),
       
    51                                  iSimRequestPending( EFalse ),
       
    52                                  iAuthType( EXcapAuthHttpDigest )
       
    53     {   
       
    54     }
       
    55         
       
    56 // ----------------------------------------------------------
       
    57 // CXcapProtocol::DeleteLogFileL
       
    58 // 
       
    59 // ----------------------------------------------------------
       
    60 //
       
    61 CXcapProtocol* CXcapProtocol::NewL( const TXdmProtocolParams& aProtocolParams )
       
    62     {
       
    63     CXcapProtocol* self = new ( ELeave ) CXcapProtocol();
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL( aProtocolParams );
       
    66     CleanupStack::Pop();
       
    67     return self;
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------
       
    71 // CXcapProtocol::DeleteLogFileL
       
    72 // 
       
    73 // ----------------------------------------------------------
       
    74 //
       
    75 CXcapProtocol::~CXcapProtocol()
       
    76     {
       
    77     #ifdef _DEBUG
       
    78         WriteToLog( _L8( "CXcapProtocol::~CXcapProtocol()" ) );  
       
    79     #endif
       
    80     delete iRootUri;
       
    81     delete iPublicId;
       
    82     delete iXmlParser;
       
    83     delete iCapabilities;
       
    84     delete iImsResolver;
       
    85     delete iHttpTransport;
       
    86     delete iIdleTimer;
       
    87     if( iCacheUsage )
       
    88         {
       
    89         iCacheClient.Flush();
       
    90         #ifdef _DEBUG
       
    91             WriteToLog( _L8( "  Cache flushed" ) );
       
    92         #endif
       
    93         iCacheClient.Close();
       
    94         #ifdef _DEBUG
       
    95             WriteToLog( _L8( "  Cache closed" ) );
       
    96         #endif
       
    97         }
       
    98     if( iConnectionManager != NULL )
       
    99         iConnectionManager->Destroy();
       
   100     #ifdef _DEBUG
       
   101         WriteToLog( _L8( "  ConnMan destroyed" ) );
       
   102     #endif
       
   103     #ifdef _DEBUG
       
   104         WriteToLog( _L8( "  All finished, about to delete file logger" ) );
       
   105     #endif
       
   106     delete iLogWriter;
       
   107     iNotifyeeQueue.Close();
       
   108     }
       
   109  
       
   110 // ----------------------------------------------------------
       
   111 // CXcapProtocol::ConstructL
       
   112 // 
       
   113 // ----------------------------------------------------------
       
   114 //
       
   115 void CXcapProtocol::ConstructL( const TXdmProtocolParams& aProtocolParams )
       
   116     {
       
   117     #ifdef _DEBUG
       
   118         iLogWriter = CXdmLogWriter::NewL( KXcapEngLogFile );
       
   119         WriteToLog( _L8( "CXcapProtocol::ConstructL()" ) );  
       
   120     #endif
       
   121     iXdmEngine = CONST_CAST( CXdmEngine*, &aProtocolParams.iXdmEngine );
       
   122     iProtocolInfo = &aProtocolParams.iProtocolInfo;
       
   123     TInt error = SaveSettingsL();
       
   124     if( error == KErrNone )
       
   125         {
       
   126         iXmlParser = CXdmXmlParser::NewL();
       
   127         iIdleTimer = new ( ELeave ) CXdmShutdownTimer( *this, this );
       
   128         iIdleTimer->ConstructL();
       
   129         if( iProtocolInfo->IsCacheEnabled() )
       
   130             {
       
   131             iCacheUsage = ETrue;
       
   132             TInt error = iCacheClient.Connect();
       
   133             #ifdef _DEBUG
       
   134                 WriteToLog( _L8( "  Cache start: %d" ), error );  
       
   135             #endif
       
   136             __ASSERT_DEBUG( ( error == KErrNone || error == KErrAlreadyExists ),
       
   137                               User::Panic( _L( "CXcapProtocol" ), 1 ) );
       
   138             }
       
   139         iUserName.Copy( iCredentials.iUserName );
       
   140         iConnectionManager = NewMsgConnManagerL( iAccessPoint );
       
   141         __ASSERT_DEBUG( iRootUri->Des().Length() > 0, User::Panic( _L( "CXcapProtocol" ), 1 ) );
       
   142         TBool secure = iProtocolInfo->IsSecure() || iRootUri->Des().FindF( KHttps ) == 0;
       
   143         HBufC* root = ParseRootLocationLC( secure, iRootUri->Des() );
       
   144         __ASSERT_ALWAYS( root != NULL, User::Panic( _L( "CXcapProtocol" ), 1 ) );
       
   145         iHttpTransport = CXcapHttpTransport::NewL( root->Des(), *iConnectionManager, iCredentials );
       
   146         CleanupStack::PopAndDestroy();  //root   
       
   147         }
       
   148     else User::Leave( error );
       
   149     }
       
   150 
       
   151 // ----------------------------------------------------------
       
   152 // CXcapProtocol::PublicID
       
   153 // 
       
   154 // ----------------------------------------------------------
       
   155 //
       
   156 EXPORT_C TPtrC8 CXcapProtocol::PublicID()
       
   157     {
       
   158     return iPublicId != NULL ? iPublicId->Des() : TPtrC8();  
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------------
       
   162 // CXcapProtocol::Cache
       
   163 // 
       
   164 // ----------------------------------------------------------
       
   165 //
       
   166 EXPORT_C RXcapCache* CXcapProtocol::Cache()
       
   167     {
       
   168     return iCacheUsage ? &iCacheClient : NULL;  
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------
       
   172 // CXcapProtocol::Parser
       
   173 // 
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 EXPORT_C CXdmXmlParser& CXcapProtocol::Parser()
       
   177     {
       
   178     return *iXmlParser;
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------
       
   182 // CXcapProtocol::Transport
       
   183 // 
       
   184 // ---------------------------------------------------------
       
   185 //
       
   186 EXPORT_C CXcapHttpTransport& CXcapProtocol::Transport()
       
   187     {
       
   188     return *iHttpTransport;
       
   189     }
       
   190    
       
   191 // ----------------------------------------------------------
       
   192 // CXcapProtocol::IsNetworkAvailable
       
   193 // 
       
   194 // ----------------------------------------------------------
       
   195 //
       
   196 EXPORT_C TBool CXcapProtocol::IsNetworkAvailable()
       
   197     {
       
   198     return iConnectionManager->Status();
       
   199     } 
       
   200        
       
   201 // ----------------------------------------------------------
       
   202 // CXcapProtocol::SaveSettingsL
       
   203 // 
       
   204 // ----------------------------------------------------------
       
   205 //
       
   206 TInt CXcapProtocol::SaveSettingsL()
       
   207     {
       
   208     TInt settingsId = iProtocolInfo->SettingsID();
       
   209     #ifdef _DEBUG
       
   210         WriteToLog( _L8( "CXcapProtocol::SaveSettingsL() - ID: %d" ), settingsId );
       
   211     #endif
       
   212     CXdmSettingsCollection* settings = NULL;
       
   213     TRAPD( error, settings = TXdmSettingsApi::SettingsCollectionL( settingsId ) );
       
   214     if( error == KErrNone && settings != NULL )
       
   215         {
       
   216         CleanupStack::PushL( settings );
       
   217         SaveFromCollectionL( *settings );
       
   218         CleanupStack::PopAndDestroy();  //settings
       
   219         }
       
   220     else   //Default to HTTP-DIGEST
       
   221         {
       
   222         iAuthType = EXcapAuthHttpDigest;
       
   223         iAccessPoint = iProtocolInfo->AccessPoint();
       
   224         iCredentials = iProtocolInfo->Credentials();
       
   225         iRootUri = iProtocolInfo->Root().AllocL();
       
   226         error = iRootUri->Des().Length() > 0 &&
       
   227                 iCredentials.iUserName.Length() > 0 &&
       
   228                 iCredentials.iPassword.Length() > 0 ?
       
   229                 KErrNone : KErrArgument;
       
   230         }
       
   231     return error;
       
   232     }
       
   233 
       
   234 // ----------------------------------------------------------
       
   235 // CXcapProtocol::SelectAuthType
       
   236 // 
       
   237 // ----------------------------------------------------------
       
   238 //
       
   239 void CXcapProtocol::SelectAuthTypeL( const CXdmSettingsCollection& aSettings )
       
   240     {
       
   241     #ifdef _DEBUG
       
   242         WriteToLog( _L8( "CXcapProtocol::SelectAuthTypeL()" ) );  
       
   243     #endif
       
   244     TPtrC authType( aSettings.Property( EXdmPropAuthType ) );
       
   245     if( authType.Compare( KXdmAuthGaa ) == 0 ) 
       
   246         {
       
   247         iAuthType = EXcapAuthGaa;
       
   248         #ifdef _DEBUG
       
   249             CXcapProtocol::WriteToLog( _L8( " GAA" ) );
       
   250         #endif
       
   251         }
       
   252     else if( authType.Compare( KXdmAuthEarlyIms ) == 0 )
       
   253         {
       
   254         #ifndef __WINSCW__ 
       
   255             iAuthType = EXcapAuthEarlyIms;
       
   256             ResolveIdentityL();
       
   257             #ifdef _DEBUG
       
   258                 CXcapProtocol::WriteToLog( _L8( " EARLY-IMS" ) );
       
   259             #endif
       
   260         #endif
       
   261         #ifdef __FAKE_IMPU__
       
   262             iAuthType = EXcapAuthEarlyIms;
       
   263             ResolveIdentityL();
       
   264             #ifdef _DEBUG
       
   265                 CXcapProtocol::WriteToLog( _L8( " EARLY-IMS" ) );
       
   266             #endif
       
   267         #else
       
   268             #ifdef _DEBUG
       
   269                 CXcapProtocol::WriteToLog( _L8( " WINS, cannot authenticate without SIM card => ignore" ) );
       
   270             #endif
       
   271             iAuthType = EXcapAuthHttpDigest;
       
   272         #endif   
       
   273         }
       
   274     else
       
   275         {
       
   276         iAuthType = EXcapAuthHttpDigest;
       
   277         #ifdef _DEBUG
       
   278             CXcapProtocol::WriteToLog( _L8( " HTTP-DIGEST" ) );
       
   279         #endif
       
   280         } 
       
   281     //Fallback position: in case the server challenges us even though EXcapAuthEarlyIms
       
   282     //has been defined, use the credentials the client supplied regardless of what they are.
       
   283     TPtrC authName( aSettings.Property( EXdmPropAuthName ) );
       
   284     TPtrC authSecret( aSettings.Property( EXdmPropAuthSecret ) );
       
   285     //But they must not exceed the stipulated length
       
   286     __ASSERT_ALWAYS( authName.Length() <= KXdmMaxUserNameLength, User::Leave( KErrCorrupt ) );
       
   287     __ASSERT_ALWAYS( authSecret.Length() <= KXdmMaxPasswordLength, User::Leave( KErrCorrupt ) );
       
   288     iCredentials = TXdmCredentials( authName, authSecret );
       
   289     }
       
   290 
       
   291 // ----------------------------------------------------------
       
   292 // CXcapProtocol::SaveFromCollectionL
       
   293 // 
       
   294 // ----------------------------------------------------------
       
   295 //
       
   296 void CXcapProtocol::SaveFromCollectionL( const CXdmSettingsCollection& aSettings )
       
   297     {
       
   298     #ifdef _DEBUG
       
   299         for( TInt i = 0;i < aSettings.Count();i++ )
       
   300             {
       
   301             const CXdmSettingsProperty& prop = aSettings.Property( i );
       
   302             HBufC8* value = HBufC8::NewLC( prop.PropertyValue().Length() );
       
   303             value->Des().Copy( prop.PropertyValue() );
       
   304             TPtrC8 valueDes( value->Des() );
       
   305             WriteToLog( _L8( "  Property %d - Name: %d  Value: %S" ), i, prop.PropertyName(), &valueDes );
       
   306             CleanupStack::PopAndDestroy();  //value
       
   307             }
       
   308     #endif
       
   309     SelectAuthTypeL( aSettings );
       
   310     __ASSERT_DEBUG( aSettings.Property( EXdmPropToNapId ).Length() > 0, User::Leave( KErrCorrupt ) );
       
   311     __ASSERT_DEBUG( aSettings.Property( EXdmPropUri ).Length() > 0, User::Leave( KErrCorrupt ) );
       
   312     TLex accessPoint( aSettings.Property( EXdmPropToNapId ) );
       
   313     TInt error = accessPoint.Val( iAccessPoint );
       
   314     __ASSERT_DEBUG( error == KErrNone, User::Leave( KErrCorrupt ) );
       
   315     iRootUri = aSettings.Property( EXdmPropUri ).AllocL();
       
   316     #ifdef _DEBUG
       
   317         TBuf8<KXdmMaxUserNameLength> name( iCredentials.iUserName );
       
   318         TBuf8<KXdmMaxPasswordLength> password( iCredentials.iPassword );
       
   319         HBufC8* rootUri = HBufC8::NewLC( iRootUri->Des().Length() );
       
   320         rootUri->Des().Copy( iRootUri->Des() );
       
   321         TPtrC8 uriDes( rootUri->Des() );
       
   322         WriteToLog( _L8( " Finished - Error:    %d" ), error );
       
   323         WriteToLog( _L8( "  Access point:       %d" ), iAccessPoint );
       
   324         WriteToLog( _L8( "  URI:                %S" ), &uriDes );
       
   325         WriteToLog( _L8( "  User name:          %S" ), &name );
       
   326         WriteToLog( _L8( "  Password:           %S" ), &password );
       
   327         CleanupStack::PopAndDestroy();  //rootUri
       
   328     #endif
       
   329     iUserName.Copy( iCredentials.iUserName );
       
   330     }
       
   331     
       
   332 // ----------------------------------------------------------
       
   333 // CXcapProtocol::ParseRootLocationLC
       
   334 // 
       
   335 // ----------------------------------------------------------
       
   336 //
       
   337 HBufC* CXcapProtocol::ParseRootLocationLC( const TBool aSecurity,
       
   338                                            const TDesC& aRootLocation )
       
   339     {
       
   340     #ifdef _DEBUG
       
   341         TBuf8<1024> root;
       
   342         root.Copy( aRootLocation );
       
   343         WriteToLog( _L8( "CXcapProtocol::ParseRootLocationLC()" ) );
       
   344         WriteToLog( _L8( "  Security:     %d" ), aSecurity );
       
   345         WriteToLog( _L8( "  Provided URI: %S" ), &root );
       
   346     #endif
       
   347     HBufC* ret = NULL;
       
   348     HBufC* temp = CheckProtocolPrefixL( aRootLocation );
       
   349     if( temp != NULL )
       
   350         {
       
   351         CleanupStack::PushL( temp );
       
   352         ret = aSecurity ? ConstructSecureUriL( temp->Des() ) :
       
   353                           ConstructStandardUriL( temp->Des() );
       
   354         CleanupStack::PopAndDestroy();  //temp                       
       
   355         }
       
   356     else
       
   357         ret = aSecurity ? ConstructSecureUriL( aRootLocation ) :
       
   358                           ConstructStandardUriL( aRootLocation );
       
   359 	TPtr desc( ret->Des() );
       
   360 	if( desc[desc.Length() - 1] == '/' )
       
   361     	desc.Delete( desc.Length() - 1, 1 );
       
   362     CleanupStack::PushL( ret );
       
   363     return ret;
       
   364     }
       
   365 
       
   366 // ----------------------------------------------------------
       
   367 // CXcapProtocol::CheckProtocolPrefixLC
       
   368 // 
       
   369 // ----------------------------------------------------------
       
   370 //
       
   371 HBufC* CXcapProtocol::CheckProtocolPrefixL( const TDesC& aRootLocation )
       
   372     {
       
   373     #ifdef _DEBUG
       
   374         WriteToLog( _L8( "CXcapProtocol::CheckProtocolPrefixL()" ) );  
       
   375     #endif
       
   376     HBufC* buffer = NULL;
       
   377     if( aRootLocation.FindF( KHttp ) == 0 || aRootLocation.FindF( KHttps ) == 0 )
       
   378         {
       
   379         TInt length = aRootLocation.FindF( KHttp ) == 0 ?
       
   380                       KHttp().Length() : KHttps().Length();
       
   381         buffer = HBufC::NewL( aRootLocation.Length() - length );
       
   382         TPtrC desc( aRootLocation );
       
   383         TPtrC temp = desc.Right( aRootLocation.Length() - length );
       
   384         buffer->Des().Copy( temp );
       
   385         }  
       
   386     return buffer;
       
   387     }
       
   388     
       
   389 // ----------------------------------------------------------
       
   390 // CXcapProtocol::ConstructStandardUriL
       
   391 // 
       
   392 // ----------------------------------------------------------
       
   393 //
       
   394 HBufC* CXcapProtocol::ConstructStandardUriL( const TDesC& aBasicUri )
       
   395     {
       
   396     #ifdef _DEBUG
       
   397         WriteToLog( _L8( "CXcapProtocol::ConstructStandardUriLC()" ) );  
       
   398     #endif
       
   399     HBufC* ret = HBufC::NewL( aBasicUri.Length() +
       
   400                               TPtrC( KHttp ).Length() );
       
   401 	TPtr desc( ret->Des() );
       
   402     desc.Copy( KHttp );
       
   403     desc.Append( aBasicUri );
       
   404     return ret;
       
   405     }
       
   406     
       
   407 // ----------------------------------------------------------
       
   408 // CXcapProtocol::ConstructSecureUriL
       
   409 // 
       
   410 // ----------------------------------------------------------
       
   411 //
       
   412 HBufC* CXcapProtocol::ConstructSecureUriL( const TDesC& aBasicUri )
       
   413     {
       
   414     #ifdef _DEBUG
       
   415         WriteToLog( _L8( "CXcapProtocol::ConstructSecureUriLC()" ) );  
       
   416     #endif
       
   417     TInt index = aBasicUri.FindF( KHostSeparator );
       
   418     HBufC* ret = HBufC::NewL( aBasicUri.Length() +
       
   419                         TPtrC( KHttps ).Length() );
       
   420     TPtr uriDesc( ret->Des() );
       
   421     if( index > 0 )
       
   422         {
       
   423         TPtrC basic( aBasicUri.Left( index ) );
       
   424         TPtrC theRest( aBasicUri.Mid( index ) );
       
   425         uriDesc.Copy( KHttps );
       
   426         uriDesc.Append( basic );
       
   427         uriDesc.Append( theRest );
       
   428         }
       
   429     else
       
   430         {
       
   431         uriDesc.Copy( KHttps );
       
   432         uriDesc.Append( aBasicUri );
       
   433         }
       
   434     return ret;
       
   435     }
       
   436 
       
   437 // ----------------------------------------------------------
       
   438 // CXcapProtocol::ResolveIdentityL
       
   439 // 
       
   440 // ----------------------------------------------------------
       
   441 //
       
   442 void CXcapProtocol::ResolveIdentityL()
       
   443     {
       
   444     #ifdef _DEBUG
       
   445         WriteToLog( _L8( "CXcapProtocol::ResolveIdentityL()" ) );  
       
   446     #endif
       
   447     iImsResolver = CXcapEarlyIms::NewL();
       
   448     iImsResolver->RequestSimDataL( this );
       
   449     iSimRequestPending = ETrue;
       
   450     }
       
   451 
       
   452 // ---------------------------------------------------------
       
   453 // CXcapProtocol::CheckActivity
       
   454 //
       
   455 // ---------------------------------------------------------
       
   456 //
       
   457 void CXcapProtocol::CheckActivity()
       
   458     {
       
   459     #ifdef _DEBUG
       
   460         WriteToLog( _L8( "CXcapProtocol::CheckActivity()" ) );
       
   461     #endif
       
   462     TBool activity = EFalse;
       
   463     const RPointerArray<CXdmDocument>& documents = iXdmEngine->DocumentCollection();
       
   464     const RPointerArray<CXdmDirectory>& directories = iXdmEngine->DirectoryCollection();
       
   465     TInt docCount = documents.Count();
       
   466     TInt dirCount = directories.Count();
       
   467     if( docCount > 0 || dirCount > 0 )
       
   468         {
       
   469         TInt i = 0;
       
   470         for( ;!activity && i < docCount;i++ )
       
   471             activity = documents[i]->IsActive();
       
   472         for( i = 0 && !activity;!activity && i < dirCount;i++ )
       
   473             activity = directories[i]->IsActive();
       
   474         }
       
   475     if( !activity )
       
   476         {
       
   477         //Just in case...
       
   478         iIdleTimer->Cancel();
       
   479         iIdleTimer->Start( iIdleTimeout * 1000000 );
       
   480         }
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------
       
   484 // CXcapProtocol::SimRequestPending
       
   485 // 
       
   486 // ---------------------------------------------------------
       
   487 //
       
   488 TBool CXcapProtocol::IsSimRequestPending( TInt& aError ) const
       
   489     {
       
   490     aError = iSimRequestPending ? KErrNotReady : iImsResolverError;
       
   491     return iSimRequestPending; 
       
   492     }
       
   493 
       
   494 // ---------------------------------------------------------
       
   495 // CXcapProtocol::AppendNotifyeeL
       
   496 // 
       
   497 // ---------------------------------------------------------
       
   498 //
       
   499 void CXcapProtocol::AppendNotifyeeL( CXcapDocument* aPendingDoc )
       
   500     {
       
   501     User::LeaveIfError( iNotifyeeQueue.Append( aPendingDoc ) );
       
   502     }
       
   503 
       
   504 // ---------------------------------------------------------
       
   505 // CXcapProtocol::CancelImsResolver
       
   506 // 
       
   507 // ---------------------------------------------------------
       
   508 //
       
   509 void CXcapProtocol::CancelImsResolver()
       
   510     {
       
   511     #ifdef _DEBUG
       
   512         CXcapProtocol::WriteToLog( _L8( "CXcapDocument::CancelImsResolver()" ) );
       
   513     #endif
       
   514     if( iImsResolver )
       
   515         iImsResolver->Cancel();
       
   516     }
       
   517        
       
   518 // ---------------------------------------------------------
       
   519 // CXcapDocument::RequestComplete
       
   520 // 
       
   521 // ---------------------------------------------------------
       
   522 //
       
   523 void CXcapProtocol::RequestComplete( TInt aError )
       
   524     {
       
   525     #ifdef _DEBUG
       
   526         CXcapProtocol::WriteToLog( _L8( "CXcapDocument::RequestComplete()" ) );
       
   527     #endif
       
   528     if( aError == KErrNone )
       
   529         {
       
   530         #ifdef _DEBUG
       
   531             CXcapProtocol::WriteToLog( _L8( " Public ID retrieved successfully" ) );
       
   532         #endif
       
   533         iPublicId = iImsResolver->PublicIDL().AllocL();
       
   534         delete iImsResolver;
       
   535         iImsResolver = NULL;
       
   536         }
       
   537     else
       
   538         {
       
   539         #ifdef _DEBUG
       
   540             CXcapProtocol::WriteToLog( _L8( " Public ID retrieval failed - Status: %d" ), aError );
       
   541         #endif
       
   542         iImsResolverError = aError;
       
   543         }
       
   544     for( TInt i = 0;i < iNotifyeeQueue.Count();i++ )
       
   545         {
       
   546         CXcapDocument* document = iNotifyeeQueue[i];
       
   547         if( document )
       
   548             document->NotifyResolverCompleteL( aError );
       
   549         }
       
   550     iSimRequestPending = EFalse;
       
   551     iNotifyeeQueue.Reset();
       
   552     }
       
   553         
       
   554 // ----------------------------------------------------------
       
   555 // CXcapProtocol::WriteToLog
       
   556 // 
       
   557 // ----------------------------------------------------------
       
   558 //
       
   559 void CXcapProtocol::WriteToLog( TRefByValue<const TDesC8> aFmt,... ) const                                 
       
   560     {
       
   561     VA_LIST list;
       
   562     VA_START( list, aFmt );
       
   563     TBuf8<KLogBufferMaxSize> buf;
       
   564     buf.FormatList( aFmt, list );
       
   565     iLogWriter->WriteToLog( buf );
       
   566     }
       
   567 
       
   568 // ----------------------------------------------------
       
   569 // CXcapProtocol::InitTransferMedium
       
   570 // 
       
   571 // ----------------------------------------------------
       
   572 //
       
   573 void CXcapProtocol::InitTransferMedium( TInt aIdleTimeout, TRequestStatus& aStatus )
       
   574     {
       
   575     #ifdef _DEBUG
       
   576         WriteToLog( _L8( "CXcapProtocol::InitTransferMedium()" ) );  
       
   577     #endif
       
   578     iIdleTimer->Cancel();
       
   579     iIdleTimeout = aIdleTimeout;
       
   580     if( !IsNetworkAvailable() )
       
   581         iConnectionManager->StartConnection( aStatus );
       
   582     else  //Already open
       
   583         {
       
   584         TRequestStatus* status = &aStatus;
       
   585         User::RequestComplete( status, KErrNone );
       
   586         }
       
   587     }
       
   588 
       
   589 // ----------------------------------------------------
       
   590 // CXcapProtocol::CancelTransferMediumInit
       
   591 // 
       
   592 // ----------------------------------------------------
       
   593 //
       
   594 void CXcapProtocol::CancelTransferMediumInit()
       
   595     {
       
   596     #ifdef _DEBUG
       
   597         WriteToLog( _L8( "CXcapProtocol::CancelTransferMediumInit()" ) );  
       
   598     #endif
       
   599     TInt error = KErrNone;
       
   600     TRAP( error, iConnectionManager->CancelStartL() );
       
   601     #ifdef _DEBUG
       
   602         WriteToLog( _L8( " Transfer media cancel completed - Error: %d" ), error );  
       
   603     #endif
       
   604     //Suppress build warning
       
   605     error = KErrNone;
       
   606     }
       
   607 
       
   608 // ---------------------------------------------------------
       
   609 // CXcapProtocol::IsTransferAvailable
       
   610 // 
       
   611 // ---------------------------------------------------------
       
   612 //
       
   613 TBool CXcapProtocol::IsTransferAvailable() const
       
   614     {
       
   615     return iConnectionManager->Status();
       
   616     }
       
   617     
       
   618 // ---------------------------------------------------------
       
   619 // CXcapProtocol::AuthType
       
   620 // 
       
   621 // ---------------------------------------------------------
       
   622 //
       
   623 TXcapAuthType CXcapProtocol::AuthType() const
       
   624     {
       
   625     return iAuthType;
       
   626     }
       
   627              
       
   628 // ---------------------------------------------------------
       
   629 // CXdmEngine::XdmProtocol
       
   630 // 
       
   631 // ---------------------------------------------------------
       
   632 //
       
   633 void CXcapProtocol::SwitchOff()
       
   634     {
       
   635     #ifdef _DEBUG
       
   636         WriteToLog( _L8( "CXcapProtocol::SwitchOff()" ) );
       
   637     #endif
       
   638     iConnectionManager->StopConnection();
       
   639     }
       
   640 
       
   641 // ----------------------------------------------------
       
   642 // CXcapProtocol::CreateDocumentL
       
   643 // 
       
   644 // ----------------------------------------------------
       
   645 //
       
   646 CXdmDocument* CXcapProtocol::CreateDocumentL( const TDesC& aDocumentName,
       
   647                                               const TXdmDocType aDocumentType )
       
   648     {
       
   649     return CXcapDocument::NewL( aDocumentType, aDocumentName, *iXdmEngine, *this );
       
   650     }
       
   651     
       
   652 // ----------------------------------------------------
       
   653 // CXcapProtocol::CreateDirectoryL
       
   654 //
       
   655 // ----------------------------------------------------
       
   656 //
       
   657 CXdmDirectory* CXcapProtocol::CreateDirectoryL( const TDesC& aDirectoryPath )
       
   658     {
       
   659     _LIT( KDirectoryDocName, "directory.xml" );
       
   660     CXdmDocument* document = iXdmEngine->CreateDocumentModelL( KDirectoryDocName, EXdmDirectory );
       
   661     CleanupStack::PushL( document );
       
   662     CXdmDirectory* directory = CXcapDirectory::NewL( aDirectoryPath, *iXdmEngine, document, *this );
       
   663     CleanupStack::Pop();               //document
       
   664     return directory;
       
   665     }
       
   666 
       
   667 // ----------------------------------------------------
       
   668 // CXcapProtocol::CreateDocumentNodeL
       
   669 // 
       
   670 // ----------------------------------------------------
       
   671 //
       
   672 CXdmDocumentNode* CXcapProtocol::CreateDocumentNodeL()
       
   673     {
       
   674     return CXcapDocumentNode::NewL( *iXdmEngine, *this );
       
   675     }
       
   676         
       
   677 // ---------------------------------------------------------
       
   678 // CXcapProtocol::GenerateUniqueIdL
       
   679 // 
       
   680 // ---------------------------------------------------------
       
   681 //
       
   682 TInt CXcapProtocol::GenerateUniqueIdL()
       
   683     {
       
   684     TInt period = 0;
       
   685     User::LeaveIfError( HAL::Get( HALData::ESystemTickPeriod, period ) );
       
   686     TInt millisecsPerTick = period / 1000;
       
   687     return User::TickCount() * millisecsPerTick;
       
   688     }
       
   689 
       
   690 // ----------------------------------------------------------
       
   691 // CXdmProtocol::UserName
       
   692 // 
       
   693 // ----------------------------------------------------------
       
   694 //
       
   695 TPtrC8 CXcapProtocol::UserName() const
       
   696     {
       
   697     return iUserName;
       
   698     }
       
   699         
       
   700 // ----------------------------------------------------------
       
   701 // CXdmProtocol::HandleBearerEventL
       
   702 // 
       
   703 // ----------------------------------------------------------
       
   704 //
       
   705 void CXcapProtocol::HandleBearerEventL( TBool aAuthoritativeClose,
       
   706                                         TMsgBearerEvent aBearerEvent )
       
   707     {
       
   708     #ifdef _DEBUG
       
   709         WriteToLog( _L8( "CXcapProtocol::HandleBearerEventL(): %d" ), aBearerEvent );
       
   710     #endif
       
   711     switch( aBearerEvent )
       
   712         {
       
   713         case EMsgBearerSuspended:
       
   714             #ifdef _DEBUG
       
   715                 WriteToLog( _L8( "  Bearer suspended" ) );
       
   716             #endif
       
   717             iSuspend = ETrue;
       
   718             break;
       
   719         case EMsgBearerActive:
       
   720             #ifdef _DEBUG
       
   721                 WriteToLog( _L8( "  Bearer active" ) );
       
   722             #endif
       
   723             iSuspend = EFalse;
       
   724             break;
       
   725         case EMsgBearerLost:
       
   726             #ifdef _DEBUG
       
   727                 WriteToLog( _L8( "  Bearer lost - Authoritative: %d" ),
       
   728                                     aAuthoritativeClose );
       
   729             #endif
       
   730             break;
       
   731         default:
       
   732         		//Suppress build warning
       
   733         		aAuthoritativeClose = EFalse;
       
   734             break;
       
   735         }
       
   736     }
       
   737 
       
   738 // ---------------------------------------------------------
       
   739 // Map the interface UIDs to implementation factory functions
       
   740 // 
       
   741 // ---------------------------------------------------------
       
   742 //
       
   743 const TImplementationProxy ImplementationTable[] = 
       
   744 	{
       
   745 #ifdef __EABI__
       
   746     IMPLEMENTATION_PROXY_ENTRY( 0x10207423,	CXcapProtocol::NewL )
       
   747 #else
       
   748     { { 0x10207423 }, CXcapProtocol::NewL }
       
   749 #endif
       
   750     };
       
   751 
       
   752 // ---------------------------------------------------------
       
   753 // Return the implementation table & number of implementations
       
   754 // 
       
   755 // ---------------------------------------------------------
       
   756 //
       
   757 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   758     {
       
   759     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   760     return ImplementationTable;
       
   761     }
       
   762     
       
   763 
       
   764   
       
   765 // End of File