sipvoipprovider/src/svpsslogcall.cpp
changeset 0 a4daefaec16c
child 10 ed1e38b404e5
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     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                     else
       
   216                         {
       
   217     					iLogEvent->SetContact( contactId ); // Set aItem based on complete match.
       
   218 						title = tempContactItem->GetContactTitleL();
       
   219                         compId = contactId;
       
   220                         ind = count;
       
   221                         }
       
   222                     }
       
   223                 }
       
   224             }
       
   225         contactId = iter->NextL();
       
   226         }
       
   227 
       
   228     CleanupStack::PopAndDestroy( iter );
       
   229     CleanupStack::PopAndDestroy( contacts );
       
   230 
       
   231     SVPDEBUG1("CSVPSSLogCall::FindContactTitleL, Exit");
       
   232     return title;
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // SVPSSLogCall::HandleCallLoggingL
       
   237 // Logs Call information 
       
   238 // (other items were commented in a header).
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 void CSVPSSLogCall::HandleCallLoggingL( const TDesC8& aFrom )
       
   242     {
       
   243     SVPDEBUG1("CSVPSSLogCall::HandleCallLoggingL, Enter");
       
   244     
       
   245     Reset();
       
   246     
       
   247     // For recognizing VoIP number and getting
       
   248     // correct "Options" and internet call icon to log.
       
   249 	TBuf8<KLogEventTempBufSize> tempBufOne;
       
   250     TBuf8<KLogEventTempBufSize> tempBufTwo;
       
   251     
       
   252     tempBufOne.Append( KLogTagVOIP() );
       
   253     tempBufOne.Append( KLogFieldDelimiter() );
       
   254     tempBufOne.Append( KLogTagURL() );
       
   255     tempBufOne.Append( KLogValueDelimiter() );
       
   256     
       
   257     iLogEvent->SetEventType(KLogCallEventTypeUid);
       
   258     iLogEvent->SetSubject(KLogSubject);
       
   259     
       
   260     TLogString missed;
       
   261     iLogClient->GetString(missed, R_LOG_DIR_MISSED);
       
   262     iLogEvent->SetDirection(missed);
       
   263 
       
   264     iLogEvent->SetDurationType( KLogDurationNone );
       
   265     TLogDuration duration = 0;
       
   266     iLogEvent->SetDuration( duration );
       
   267     
       
   268     iLogEvent->SetNumber( KNullDesC );
       
   269     
       
   270     TLogString number;
       
   271     CnvUtfConverter::ConvertToUnicodeFromUtf8( number, aFrom );
       
   272     RemoveUnusedCharsFromSipAddress( number );            
       
   273 	SVPDEBUG2("  CSVPSSLogCall::HandleCallLoggingL, number = %S", &number );        
       
   274 
       
   275     if ( KErrNotFound == aFrom.Find( KSVPAnonymousName8 ) )
       
   276     	{
       
   277         SVPDEBUG1("  CSVPSSLogCall::HandleCallLoggingL, URI address is seen" );
       
   278         HBufC* contactName = FindContactTitleL( number );
       
   279 	    if ( contactName )
       
   280 		    { //  Phonebook contact id has been found
       
   281 		    //tempBufTwo.Copy( contactName->Des() );
       
   282 		    tempBufTwo.Copy( number );
       
   283 		    iLogEvent->SetRemoteParty( contactName->Des() );
       
   284 	        }
       
   285 	    else
       
   286 	        { // No phonebook contact id has been found
       
   287 	       	tempBufTwo.Copy( number );
       
   288 	       	iLogEvent->SetRemoteParty( number );
       
   289 	        }
       
   290 	    delete contactName;
       
   291 	    tempBufOne.Append( tempBufTwo );             
       
   292 	    tempBufTwo.Zero();
       
   293 	    tempBufOne.Append( KLogFieldDelimiter() );
       
   294 	    tempBufOne.Append( KLogTagMA() );
       
   295 	    tempBufOne.Append( KLogValueDelimiter() );
       
   296     	}
       
   297     else
       
   298 	    {
       
   299         SVPDEBUG1("  CSVPSSLogCall::HandleCallLoggingL, URI address is Anonymous" );
       
   300         iLogEvent->SetRemoteParty( KSVPPrivateNumber );
       
   301 	    }
       
   302     TRAP_IGNORE( iLogEvent->SetDataL( tempBufOne ) );
       
   303     TTime eventTime;
       
   304     eventTime.UniversalTime();
       
   305     iLogEvent->SetTime(eventTime);
       
   306     iLogClient->AddEvent(*iLogEvent, iStatus);
       
   307 
       
   308     SetActive();
       
   309 	SVPDEBUG1("CSVPSSLogCall::HandleCallLoggingL, Exit");
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // SVPSSLogCall::DoCancel
       
   314 // Called when an aychronic request is cancelled
       
   315 // (other items were commented in a header).
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CSVPSSLogCall::DoCancel()
       
   319     {
       
   320     SVPDEBUG1("CSVPSSLogCall::DoCancel"); 
       
   321 	iLogClient->Cancel();
       
   322     }
       
   323     
       
   324 // -----------------------------------------------------------------------------
       
   325 // SVPSSLogCall::RunL
       
   326 // Called when an aychronic request is completed
       
   327 // (other items were commented in a header).
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void CSVPSSLogCall::RunL()
       
   331     {
       
   332     SVPDEBUG1("CSVPSSLogCall::RunL, Enter");
       
   333     // If LogClient AddEvent successful, then show missed call soft notifier
       
   334     if ( KErrNone == iStatus.Int() )
       
   335         {
       
   336         TInt missedCallCount(0);
       
   337         TInt err = iLogsSession->Get( KLogsNewMissedCalls, missedCallCount );
       
   338         
       
   339         if( KErrNotFound == err || KErrUnknown == err || missedCallCount < 0 )
       
   340             {       
       
   341             missedCallCount = 0;
       
   342             iLogsSession->Set( KLogsNewMissedCalls, missedCallCount );
       
   343             }
       
   344         else
       
   345             {
       
   346             missedCallCount++;
       
   347             iLogsSession->Set( KLogsNewMissedCalls, missedCallCount );    
       
   348             }
       
   349         SVPDEBUG2("  CSVPSSLogCall::RunL, missedCallCount: %d", missedCallCount );
       
   350         }
       
   351         
       
   352 	SVPDEBUG1("CSVPSSLogCall::RunL, Exit");
       
   353     }
       
   354   
       
   355 // -----------------------------------------------------------------------------
       
   356 // SVPSSLogCall::RemoveUnusedCharsFromSipAddress
       
   357 // Removes unused chars from sip address
       
   358 // (other items were commented in a header). 
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 void CSVPSSLogCall::RemoveUnusedCharsFromSipAddress( TDes& aAddress )
       
   362     {
       
   363     SVPDEBUG1("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: Enter" );
       
   364     // Display name, '<' and '>' are not used when comparing addresses.
       
   365     TInt pos = aAddress.Find( KSVPLeftBracketMark2 );
       
   366     if ( KErrNotFound != pos )
       
   367         {
       
   368 	    SVPDEBUG1("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: '<' from uri" );
       
   369         aAddress.Delete( 0, pos + 1 );
       
   370         }
       
   371     
       
   372     pos = aAddress.Find( KSVPRightBracketMark2 );
       
   373     if ( KErrNotFound != pos )
       
   374         {
       
   375 	    SVPDEBUG3("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: \
       
   376     	'>' in uri pos = %d, length = %d",
       
   377         pos, aAddress.Length() );
       
   378         aAddress.Delete( pos, aAddress.Length() - pos );
       
   379         }
       
   380         
       
   381     // "sip:" is not used when comparing addresses. 
       
   382     if ( KSVPSipPrefixLength < aAddress.Length() )
       
   383         {
       
   384         TBuf<KSVPSipPrefixLength> sipPrefix;
       
   385         sipPrefix.Copy( aAddress.Left( KSVPSipPrefixLength ) );
       
   386         sipPrefix.LowerCase();
       
   387         if ( !sipPrefix.Compare( KSVPSipPrefix2 ) )
       
   388             {
       
   389             SVPDEBUG1("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: 'sip:' in uri" );
       
   390 			aAddress.Delete( KErrNone, KSVPSipPrefixLength );
       
   391             }
       
   392         }
       
   393 
       
   394     // remove all extra parameters from given address
       
   395 	pos = aAddress.Find( KSVPSemiColon );        
       
   396     if ( KErrNotFound != pos )
       
   397         {
       
   398 	    SVPDEBUG3("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: \
       
   399     	There is ';' in uri pos = %d, length = %d",
       
   400         pos, aAddress.Length() );
       
   401 
       
   402         // Delete ";" and text after it
       
   403         aAddress.Delete( pos, aAddress.Length() - pos );
       
   404         }
       
   405 
       
   406     SVPDEBUG1("CSVPSSLogCall::RemoveUnusedCharsFromSipAddress: Exit" );
       
   407     }    
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // SVPSSLogCall::::CompareSipUri
       
   411 // Compares whole sip uri
       
   412 // (other items were commented in a header).  
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 TBool CSVPSSLogCall::CompareSipUri( 
       
   416     const TDesC& aTelNumber, const TDesC& aPbookNumber )
       
   417     {
       
   418     // Complete SIP address must contain host part.
       
   419     if ( KErrNotFound < aTelNumber.Find( KSVPAt2 ) &&
       
   420          KErrNotFound < aPbookNumber.Find( KSVPAt2 ) )
       
   421         {
       
   422         TBuf<KMaxAddressLength> tmpTelNumber( aTelNumber );
       
   423         TBuf<KMaxAddressLength> tmpPbookNumber( aPbookNumber );
       
   424     
       
   425         // Compare username parts, which are case sensitive.
       
   426         if ( CompareUsernamePart( tmpTelNumber, tmpPbookNumber ) )
       
   427             {
       
   428             // Convert descriptors to lowercase.
       
   429             tmpTelNumber.LowerCase();
       
   430             tmpPbookNumber.LowerCase();
       
   431 
       
   432             // Compare host part, which is not case sensitive.
       
   433             if ( !tmpTelNumber.Compare( tmpPbookNumber ) )
       
   434                 {
       
   435                 SVPDEBUG1("CSVPSSLogCall::CompareSipUri: SipUri's EQUAL");
       
   436                 return ETrue;
       
   437                 }
       
   438             }
       
   439         }
       
   440     SVPDEBUG1("CSVPSSLogCall::CompareSipUri: SipUri's do NOT EQUAL");    
       
   441     return EFalse;    
       
   442     }
       
   443     
       
   444 // -----------------------------------------------------------------------------
       
   445 // SVPSSLogCall::::CompareUsernamePart
       
   446 // Compares username of sip uri
       
   447 // (other items were commented in a header).  
       
   448 // -----------------------------------------------------------------------------
       
   449 //
       
   450 TBool CSVPSSLogCall::CompareUsernamePart( 
       
   451     const TDesC& aTelNumber, const TDesC& aPbookNumber )
       
   452     {
       
   453     TBuf<KMaxAddressLength> tmpTelNumber( aTelNumber );
       
   454     TBuf<KMaxAddressLength> tmpPbookNumber( aPbookNumber );
       
   455     
       
   456     // Remove uri part from tel. number.
       
   457     TInt pos = tmpTelNumber.Find( KSVPAt2 );
       
   458     if ( KErrNotFound < pos )
       
   459         {
       
   460         tmpTelNumber.Delete( pos, tmpTelNumber.Length() - pos );
       
   461         }
       
   462     
       
   463     // Remove uri part from phonebook number.
       
   464     pos = tmpPbookNumber.Find( KSVPAt2 );
       
   465     if ( KErrNotFound < pos )
       
   466         {
       
   467         tmpPbookNumber.Delete( pos, tmpPbookNumber.Length() - pos );
       
   468         }            
       
   469 
       
   470     // Compare parsed numbers.
       
   471     if ( !tmpTelNumber.Compare( tmpPbookNumber ) )
       
   472         {
       
   473         SVPDEBUG1("CSVPSSLogCall::CompareUsernamePart: Names EQUAL");
       
   474         return ETrue;
       
   475         }
       
   476 	SVPDEBUG1("CSVPSSLogCall::CompareUsernamePart: Names do NOT EQUAL");        
       
   477     return EFalse;
       
   478     }
       
   479 
       
   480 //  End of File