sipvoipprovider/src/svpsslogcall.cpp
branchRCL_3
changeset 22 d38647835c2e
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Logs Call details in case of Do Not Disturb
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "svpsslogcall.h"
       
    21 #include    "svpconsts.h"
       
    22 #include    "svplogger.h"
       
    23 
       
    24 #include    <utf.h> 
       
    25 
       
    26 #include	<cntitem.h>
       
    27 #include    <CPbkContactEngine.h> 
       
    28 #include    <CPbkContactIter.h>
       
    29 #include    <CPbkContactItem.h>
       
    30 #include    <CPbkFieldInfo.h>
       
    31 
       
    32 #include    <AknNotifyStd.h>
       
    33 #include    <AknSoftNotifier.h>
       
    34 #include    <LogsDomainCRKeys.h>
       
    35 
       
    36 #include    <RPbkViewResourceFile.h>
       
    37 #include    <coemain.h>
       
    38 
       
    39 // LOCAL CONSTANTS
       
    40 _LIT( KLogSubject, "0" );
       
    41 
       
    42 _LIT8( KLogTagVOIP, "VOIP" ); 
       
    43 _LIT8( KLogTagURL, "URL" );  
       
    44 _LIT8( KLogTagMA, "MA" );   
       
    45 _LIT8( KLogFieldDelimiter, "\t" );
       
    46 _LIT8( KLogValueDelimiter, "=" );
       
    47 
       
    48 const TInt KLogEventTempBufSize = 300;
       
    49 const TInt KMaxAddressLength = 256;
       
    50 
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // SVPSSLogCall::SVPSSLogCall
       
    56 // C++ default constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CSVPSSLogCall::CSVPSSLogCall() : CActive(0)
       
    61     {
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // SVPSSLogCall::ConstructL
       
    66 // Symbian 2nd phase constructor can leave.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CSVPSSLogCall::ConstructL()
       
    70     {
       
    71     SVPDEBUG1("CSVPSSLogCall::ConstructL, Enter"); 
       
    72     User::LeaveIfError( iFs.Connect() );
       
    73 
       
    74     iLogEvent = CLogEvent::NewL();
       
    75     iLogClient = CLogClient::NewL( iFs );
       
    76 	iLogsSession = CRepository::NewL( KCRUidLogs );
       
    77 
       
    78     CActiveScheduler::Add(this);
       
    79     SVPDEBUG1("CSVPSSLogCall::ConstructL, Exit"); 
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // SVPSSLogCall::NewL
       
    84 // Two-phased constructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CSVPSSLogCall* CSVPSSLogCall::NewL()
       
    88     {
       
    89     SVPDEBUG1("CSVPSSLogCall::NewL, Enter");
       
    90     
       
    91     CSVPSSLogCall* self = new( ELeave ) CSVPSSLogCall;
       
    92     
       
    93     CleanupStack::PushL( self );
       
    94     self->ConstructL();
       
    95     CleanupStack::Pop( self );
       
    96     
       
    97     SVPDEBUG1("CSVPSSLogCall::NewL, Exit");
       
    98     return self;
       
    99     }
       
   100     
       
   101 // -----------------------------------------------------------------------------
       
   102 // SVPSSLogCall::~CSVPSSLogCall
       
   103 // Destructor
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 CSVPSSLogCall::~CSVPSSLogCall()
       
   107     {
       
   108     SVPDEBUG1("CSVPSSLogCall::~CSVPSSLogCall, Enter"); 
       
   109 
       
   110     Cancel();
       
   111     delete iLogsSession;
       
   112     delete iLogClient;
       
   113     delete iLogEvent;
       
   114 	iFs.Close();
       
   115 
       
   116 	SVPDEBUG1("CSVPSSLogCall::~CSVPSSLogCall, Exit"); 
       
   117     }
       
   118 
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // SVPSSLogCall::Reset
       
   122 // REsets iLogEvent
       
   123 // (other items were commented in a header).
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CSVPSSLogCall::Reset()
       
   127     {
       
   128     SVPDEBUG1("CSVPSSLogCall::Reset, Enter");
       
   129     
       
   130     iLogEvent->SetId( KLogNullId ); 
       
   131     iLogEvent->SetEventType( KNullUid );
       
   132     iLogEvent->SetRemoteParty( KNullDesC );
       
   133     iLogEvent->SetDirection( KNullDesC );
       
   134     iLogEvent->SetTime( Time::NullTTime() );
       
   135     iLogEvent->SetDurationType( KLogNullDurationType );
       
   136     iLogEvent->SetDuration( KLogNullDuration );
       
   137     iLogEvent->SetStatus( KNullDesC ); 
       
   138     iLogEvent->SetSubject( KNullDesC );
       
   139     iLogEvent->SetNumber( KNullDesC );
       
   140     iLogEvent->SetContact( KNullContactId ); 
       
   141     iLogEvent->SetLink( KLogNullLink ); 
       
   142     iLogEvent->SetDescription( KNullDesC ); 
       
   143     iLogEvent->SetFlags( KLogNullFlags );  
       
   144     TRAP_IGNORE( iLogEvent->SetDataL( KNullDesC8 ) );
       
   145     
       
   146     SVPDEBUG1("CSVPSSLogCall::Reset, Exit");
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // SVPSSLogCall::FindContactIdL
       
   151 // Finds contact if from phonebook if one exists 
       
   152 // (other items were commented in a header).
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 HBufC* CSVPSSLogCall::FindContactTitleL( const TDesC& aSipUri )
       
   156     {
       
   157     SVPDEBUG1("CSVPSSLogCall::FindContactTitleL, Enter");    
       
   158     HBufC* title ( NULL );
       
   159     TBool manyCompleteMatches( EFalse );
       
   160 	TContactItemId compId( NULL );    
       
   161        
       
   162     CPbkContactEngine* contacts = CPbkContactEngine::NewL();
       
   163     CleanupStack::PushL( contacts );
       
   164     
       
   165     CPbkContactIter* iter = contacts->CreateContactIteratorLC();
       
   166 	TContactItemId contactId = iter->FirstL();
       
   167 
       
   168     while ( contactId != KNullContactId && !manyCompleteMatches )
       
   169         {
       
   170         //Get contact item
       
   171         CPbkContactItem* tempContactItem = iter->CurrentL();        
       
   172         
       
   173         TInt count = tempContactItem->CardFields().Count();
       
   174         SVPDEBUG2("  CSVPSSLogCall::FindContactTitleL count: %d", count );
       
   175 
       
   176         for ( TInt ind = 0; ind < count ; ind++ )
       
   177             {
       
   178             if ( EPbkFieldIdVOIP ==
       
   179                      tempContactItem->CardFields()[ind].FieldInfo().FieldId() ||
       
   180                  EPbkFieldIdXsp ==
       
   181                      tempContactItem->CardFields()[ind].FieldInfo().FieldId() ||
       
   182                  tempContactItem->CardFields()[ind].FieldInfo().IsVoipField() )
       
   183                 {
       
   184                 SVPDEBUG1("  CSVPSSLogCall::FindContactTitleL: Contact is FOUND" );
       
   185                 
       
   186                 //If contact have phone or Internet number fields, get address..  
       
   187                 TBuf<KMaxAddressLength> tmpPbookNumber( 
       
   188                     tempContactItem->CardFields()[ind].Text() );
       
   189 				
       
   190                 RemoveUnusedCharsFromSipAddress( tmpPbookNumber );
       
   191                 
       
   192                 if ( EPbkFieldIdXsp == tempContactItem->CardFields(
       
   193                          )[ind].FieldInfo().FieldId() )
       
   194                     {
       
   195                     SVPDEBUG1("CSVPSSLogCall::FindContactTitleL, EPbkFieldIdXsp" );
       
   196                     // remove all characters before ":" only leftmost part
       
   197                     TInt pos = tmpPbookNumber.Find( KSVPCln2 );
       
   198                     if ( KErrNotFound != pos )
       
   199                         {
       
   200                         tmpPbookNumber.Delete( KErrNone, pos + 1 );
       
   201                         }
       
   202                     }
       
   203                 
       
   204                 SVPDEBUG3("  CSVPSSLogCall::FindContactTitleL FoundContactText%d = %S",
       
   205                              ind, &tmpPbookNumber );
       
   206                 
       
   207                 // Compare complete addresses and set Id if found.
       
   208                 if ( CompareSipUri( aSipUri, tmpPbookNumber ) )
       
   209                     {
       
   210                     if ( compId )
       
   211                         {
       
   212                         SVPDEBUG1("CSVPSSLogCall::FindContactTitleL, manyCompleteMatches");
       
   213                         manyCompleteMatches = ETrue;
       
   214                         
       
   215                         // Set to NULL if multiple matches                     
       
   216                         if ( title )
       
   217                             {
       
   218                             delete title;
       
   219                             title = NULL;
       
   220                             }       
       
   221                         }
       
   222                     else
       
   223                         {
       
   224                         title = tempContactItem->GetContactTitleL();
       
   225                         compId = contactId;
       
   226                         ind = count;
       
   227                         }
       
   228                     }
       
   229                 }
       
   230             }
       
   231         contactId = iter->NextL();
       
   232         }
       
   233     
       
   234     // Set contact if only one match found
       
   235     if ( compId && !manyCompleteMatches )
       
   236         {
       
   237         iLogEvent->SetContact( compId );
       
   238         } 
       
   239 
       
   240     CleanupStack::PopAndDestroy( iter );
       
   241     CleanupStack::PopAndDestroy( contacts );
       
   242 
       
   243     SVPDEBUG1("CSVPSSLogCall::FindContactTitleL, Exit");
       
   244     return title;
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // SVPSSLogCall::HandleCallLoggingL
       
   249 // Logs Call information 
       
   250 // (other items were commented in a header).
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CSVPSSLogCall::HandleCallLoggingL( const TDesC8& aFrom )
       
   254     {
       
   255     SVPDEBUG1("CSVPSSLogCall::HandleCallLoggingL, Enter");
       
   256     
       
   257     Reset();
       
   258     
       
   259     // For recognizing VoIP number and getting
       
   260     // correct "Options" and internet call icon to log.
       
   261 	TBuf8<KLogEventTempBufSize> tempBufOne;
       
   262     TBuf8<KLogEventTempBufSize> tempBufTwo;
       
   263     
       
   264     tempBufOne.Append( KLogTagVOIP() );
       
   265     tempBufOne.Append( KLogFieldDelimiter() );
       
   266     tempBufOne.Append( KLogTagURL() );
       
   267     tempBufOne.Append( KLogValueDelimiter() );
       
   268     
       
   269     iLogEvent->SetEventType(KLogCallEventTypeUid);
       
   270     iLogEvent->SetSubject(KLogSubject);
       
   271     
       
   272     TLogString missed;
       
   273     iLogClient->GetString(missed, R_LOG_DIR_MISSED);
       
   274     iLogEvent->SetDirection(missed);
       
   275 
       
   276     iLogEvent->SetDurationType( KLogDurationNone );
       
   277     TLogDuration duration = 0;
       
   278     iLogEvent->SetDuration( duration );
       
   279     
       
   280     iLogEvent->SetNumber( KNullDesC );
       
   281     
       
   282     TLogString number;
       
   283     CnvUtfConverter::ConvertToUnicodeFromUtf8( number, aFrom );
       
   284     RemoveUnusedCharsFromSipAddress( number );
       
   285     SVPDEBUG2("  CSVPSSLogCall::HandleCallLoggingL, number = %S", &number );
       
   286 
       
   287     if ( KErrNotFound == aFrom.Find( KSVPAnonymousName8 ) )
       
   288     	{
       
   289         SVPDEBUG1("  CSVPSSLogCall::HandleCallLoggingL, URI address is seen" );
       
   290         HBufC* contactName = FindContactTitleL( number );
       
   291         if ( contactName )
       
   292             { 
       
   293             //  Phonebook contact id has been found
       
   294             tempBufTwo.Copy( number );
       
   295             iLogEvent->SetRemoteParty( contactName->Des() );
       
   296             }
       
   297         else
       
   298             { // No phonebook contact id has been found
       
   299            	tempBufTwo.Copy( number );
       
   300            	iLogEvent->SetRemoteParty( number );
       
   301             }
       
   302         
       
   303         if ( contactName )
       
   304             {
       
   305             delete contactName;
       
   306             contactName = NULL;
       
   307             }
       
   308         
       
   309         tempBufOne.Append( tempBufTwo );
       
   310         tempBufTwo.Zero();
       
   311         tempBufOne.Append( KLogFieldDelimiter() );
       
   312         tempBufOne.Append( KLogTagMA() );
       
   313         tempBufOne.Append( KLogValueDelimiter() );
       
   314         }
       
   315     else
       
   316         {
       
   317         SVPDEBUG1("  CSVPSSLogCall::HandleCallLoggingL, URI address is Anonymous" );
       
   318         iLogEvent->SetRemoteParty( KSVPPrivateNumber );
       
   319         }
       
   320     TRAP_IGNORE( iLogEvent->SetDataL( tempBufOne ) );
       
   321     TTime eventTime;
       
   322     eventTime.UniversalTime();
       
   323     iLogEvent->SetTime(eventTime);
       
   324     if( !IsActive() )
       
   325         {
       
   326         iLogClient->AddEvent(*iLogEvent, iStatus);
       
   327         SetActive();
       
   328         }
       
   329 	SVPDEBUG1("CSVPSSLogCall::HandleCallLoggingL, Exit");
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // SVPSSLogCall::DoCancel
       
   334 // Called when an aychronic request is cancelled
       
   335 // (other items were commented in a header).
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 void CSVPSSLogCall::DoCancel()
       
   339     {
       
   340     SVPDEBUG1("CSVPSSLogCall::DoCancel"); 
       
   341 	iLogClient->Cancel();
       
   342     }
       
   343     
       
   344 // -----------------------------------------------------------------------------
       
   345 // SVPSSLogCall::RunL
       
   346 // Called when an aychronic request is completed
       
   347 // (other items were commented in a header).
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CSVPSSLogCall::RunL()
       
   351     {
       
   352     SVPDEBUG1("CSVPSSLogCall::RunL, Enter");
       
   353     // If LogClient AddEvent successful, then show missed call soft notifier
       
   354     if ( KErrNone == iStatus.Int() )
       
   355         {
       
   356         TInt missedCallCount(0);
       
   357         TInt err = iLogsSession->Get( KLogsNewMissedCalls, missedCallCount );
       
   358         
       
   359         if( KErrNotFound == err || KErrUnknown == err || missedCallCount < 0 )
       
   360             {       
       
   361             missedCallCount = 0;
       
   362             iLogsSession->Set( KLogsNewMissedCalls, missedCallCount );
       
   363             }
       
   364         else
       
   365             {
       
   366             missedCallCount++;
       
   367             iLogsSession->Set( KLogsNewMissedCalls, missedCallCount );    
       
   368             }
       
   369         SVPDEBUG2("  CSVPSSLogCall::RunL, missedCallCount: %d", missedCallCount );
       
   370         }
       
   371         
       
   372 	SVPDEBUG1("CSVPSSLogCall::RunL, Exit");
       
   373     }
       
   374   
       
   375 // -----------------------------------------------------------------------------
       
   376 // SVPSSLogCall::RemoveUnusedCharsFromSipAddress
       
   377 // Removes unused chars from sip address
       
   378 // (other items were commented in a header). 
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 void CSVPSSLogCall::RemoveUnusedCharsFromSipAddress( TDes& aAddress )
       
   382     {
       
   383     SVPDEBUG1("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: Enter" );
       
   384     // Display name, '<' and '>' are not used when comparing addresses.
       
   385     TInt pos = aAddress.Find( KSVPLeftBracketMark2 );
       
   386     if ( KErrNotFound != pos )
       
   387         {
       
   388 	    SVPDEBUG1("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: '<' from uri" );
       
   389         aAddress.Delete( 0, pos + 1 );
       
   390         }
       
   391     
       
   392     pos = aAddress.Find( KSVPRightBracketMark2 );
       
   393     if ( KErrNotFound != pos )
       
   394         {
       
   395 	    SVPDEBUG3("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: \
       
   396     	'>' in uri pos = %d, length = %d",
       
   397         pos, aAddress.Length() );
       
   398         aAddress.Delete( pos, aAddress.Length() - pos );
       
   399         }
       
   400         
       
   401     // "sip:" is not used when comparing addresses. 
       
   402     if ( KSVPSipPrefixLength < aAddress.Length() )
       
   403         {
       
   404         TBuf<KSVPSipPrefixLength> sipPrefix;
       
   405         sipPrefix.Copy( aAddress.Left( KSVPSipPrefixLength ) );
       
   406         sipPrefix.LowerCase();
       
   407         if ( !sipPrefix.Compare( KSVPSipPrefix2 ) )
       
   408             {
       
   409             SVPDEBUG1("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: 'sip:' in uri" );
       
   410 			aAddress.Delete( KErrNone, KSVPSipPrefixLength );
       
   411             }
       
   412         }
       
   413 
       
   414     // remove all extra parameters from given address
       
   415 	pos = aAddress.Find( KSVPSemiColon );        
       
   416     if ( KErrNotFound != pos )
       
   417         {
       
   418 	    SVPDEBUG3("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: \
       
   419     	There is ';' in uri pos = %d, length = %d",
       
   420         pos, aAddress.Length() );
       
   421 
       
   422         // Delete ";" and text after it
       
   423         aAddress.Delete( pos, aAddress.Length() - pos );
       
   424         }
       
   425 
       
   426     SVPDEBUG1("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: Exit" );
       
   427     }    
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // SVPSSLogCall::::CompareSipUri
       
   431 // Compares whole sip uri
       
   432 // (other items were commented in a header).  
       
   433 // -----------------------------------------------------------------------------
       
   434 //
       
   435 TBool CSVPSSLogCall::CompareSipUri( 
       
   436     const TDesC& aTelNumber, const TDesC& aPbookNumber )
       
   437     {
       
   438     // Complete SIP address must contain host part.
       
   439     if ( KErrNotFound < aTelNumber.Find( KSVPAt2 ) &&
       
   440          KErrNotFound < aPbookNumber.Find( KSVPAt2 ) )
       
   441         {
       
   442         TBuf<KMaxAddressLength> tmpTelNumber( aTelNumber );
       
   443         TBuf<KMaxAddressLength> tmpPbookNumber( aPbookNumber );
       
   444     
       
   445         // Compare username parts, which are case sensitive.
       
   446         if ( CompareUsernamePart( tmpTelNumber, tmpPbookNumber ) )
       
   447             {
       
   448             // Convert descriptors to lowercase.
       
   449             tmpTelNumber.LowerCase();
       
   450             tmpPbookNumber.LowerCase();
       
   451 
       
   452             // Compare host part, which is not case sensitive.
       
   453             if ( !tmpTelNumber.Compare( tmpPbookNumber ) )
       
   454                 {
       
   455                 SVPDEBUG1("CSVPSSLogCall::CompareSipUri: SipUri's EQUAL");
       
   456                 return ETrue;
       
   457                 }
       
   458             }
       
   459         }
       
   460     SVPDEBUG1("CSVPSSLogCall::CompareSipUri: SipUri's do NOT EQUAL");    
       
   461     return EFalse;    
       
   462     }
       
   463     
       
   464 // -----------------------------------------------------------------------------
       
   465 // SVPSSLogCall::::CompareUsernamePart
       
   466 // Compares username of sip uri
       
   467 // (other items were commented in a header).  
       
   468 // -----------------------------------------------------------------------------
       
   469 //
       
   470 TBool CSVPSSLogCall::CompareUsernamePart( 
       
   471     const TDesC& aTelNumber, const TDesC& aPbookNumber )
       
   472     {
       
   473     TBuf<KMaxAddressLength> tmpTelNumber( aTelNumber );
       
   474     TBuf<KMaxAddressLength> tmpPbookNumber( aPbookNumber );
       
   475     
       
   476     // Remove uri part from tel. number.
       
   477     TInt pos = tmpTelNumber.Find( KSVPAt2 );
       
   478     if ( KErrNotFound < pos )
       
   479         {
       
   480         tmpTelNumber.Delete( pos, tmpTelNumber.Length() - pos );
       
   481         }
       
   482     
       
   483     // Remove uri part from phonebook number.
       
   484     pos = tmpPbookNumber.Find( KSVPAt2 );
       
   485     if ( KErrNotFound < pos )
       
   486         {
       
   487         tmpPbookNumber.Delete( pos, tmpPbookNumber.Length() - pos );
       
   488         }            
       
   489 
       
   490     // Compare parsed numbers.
       
   491     if ( !tmpTelNumber.Compare( tmpPbookNumber ) )
       
   492         {
       
   493         SVPDEBUG1("CSVPSSLogCall::CompareUsernamePart: Names EQUAL");
       
   494         return ETrue;
       
   495         }
       
   496 	SVPDEBUG1("CSVPSSLogCall::CompareUsernamePart: Names do NOT EQUAL");        
       
   497     return EFalse;
       
   498     }
       
   499 
       
   500 //  End of File