IMPSengine/engsrv/src/impssession.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002-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: Class for Imps session.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "impsserver.h"
       
    22 #include    "impsutils.h"
       
    23 #include    "impssession.h"
       
    24 #include    "impsfields.h"
       
    25 #include    "impserrors.h"
       
    26 #include    "impstimer.h"
       
    27 #include    "impssubsession.h"
       
    28 #include    "ImpsVariantAPI.h"
       
    29 #include    "impspacked.h"
       
    30 
       
    31 // MACROS
       
    32 #ifndef _DEBUG
       
    33 #define _NO_IMPS_LOGGING_
       
    34 #endif
       
    35 
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // C++ default constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 //
       
    42 CImpsSession::CImpsSession( RMessage2& aMsg )
       
    43         :     CSession2(),
       
    44         iCanceled( EFalse ),
       
    45         iMessageCompleted( EFalse ),
       
    46         iMsgR( aMsg )
       
    47     {
       
    48 #ifndef _NO_IMPS_LOGGING_
       
    49     CImpsClientLogger::Log( _L( "Session: NEW session sess=%d" ), ( TInt )this );
       
    50 #endif
       
    51     }
       
    52 
       
    53 
       
    54 // Destructor
       
    55 // RHandleBase::Close() causes this destructor to be called
       
    56 CImpsSession::~CImpsSession()
       
    57     {
       
    58 #ifndef _NO_IMPS_LOGGING_
       
    59     CImpsClientLogger::Log( _L( "Session: DELETE session sess=%d" ), ( TInt )this );
       
    60 #endif
       
    61     // Check if destructor is called by CServer2 class in failed
       
    62     // entity creation or in other case. iContainer is the last
       
    63     // member created is CreateL() so it can be used for this purpose.
       
    64     TBool wasComplete = iContainer ? ETrue : EFalse;
       
    65     // This is here to close CSP session if client is deleted
       
    66     // without calling close method.
       
    67     CloseSession();
       
    68     TImpsSessIdent csp( SID(), SAP(), UserId() );
       
    69     Server()->CloseSession( csp, wasComplete );
       
    70     delete iApplicationId;
       
    71     delete iSID;
       
    72     delete iSAP;
       
    73     delete iUserId;
       
    74     delete iStream;
       
    75     delete iFields;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CImpsSession::CreateL()
       
    80 // ---------------------------------------------------------
       
    81 // This overloads the base class implementation
       
    82 void CImpsSession::CreateL( )
       
    83     {
       
    84     iFields = CImpsFields::NewL();
       
    85     // create new object index
       
    86     iSubSessions = CObjectIx::NewL();
       
    87     // initialize the object container using the object container index in the server.
       
    88     iContainer = Server()->NewContainerL();
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CImpsSession::DispatchMessageL()
       
    93 // ---------------------------------------------------------
       
    94 void CImpsSession::DispatchMessageL( const RMessage2& aMessage )
       
    95     {
       
    96     TInt nbrSess = 0;
       
    97     TUint flag = 0;
       
    98 
       
    99     iMsgR = aMessage;
       
   100 
       
   101     if ( iCanceled )
       
   102         {
       
   103 #ifndef _NO_IMPS_LOGGING_
       
   104         CImpsClientLogger::Log( _L( "Session: already CANCELED aMsg=%d" ),
       
   105                                 aMessage.Function() );
       
   106 #endif
       
   107         CompleteMe( KErrCancel );
       
   108         return;
       
   109         }
       
   110 
       
   111     // Set ETrue at the same time as Message().Complete() takes place
       
   112     iMessageCompleted = EFalse;
       
   113     TInt msg = aMessage.Function();
       
   114     // stripp off bit mask in an upper word
       
   115     msg = msg & 0x0FFFF;
       
   116 
       
   117 #ifndef _NO_IMPS_LOGGING_
       
   118     CImpsClientLogger::Log( _L( "Session: DispatchMessageL msg=%d sess=%d" ), msg, ( TInt )this );
       
   119 #endif
       
   120 
       
   121     // current CSP indetification
       
   122     TImpsSessIdent csp( SID(), SAP(), UserId() );
       
   123 
       
   124     switch ( msg )
       
   125         {
       
   126         case EImpsServAssign:
       
   127             AssignIdL();
       
   128             // Notice that in this case there is subsession specific part too.
       
   129             // So, do not return yet.
       
   130             break;
       
   131 
       
   132         case EImpsAccessRegister2:
       
   133             // NewSubSessionL will check SHUTTING_DOWN state of server and
       
   134             // leaves when necessary
       
   135             NewSubSessionL( EImpsEventServerLogin, aMessage );
       
   136             return;
       
   137 
       
   138         case EImpsImRegister:
       
   139             NewSubSessionL( EImpsEventMessage, aMessage );
       
   140             return;
       
   141 
       
   142         case EImpsFundRegister:
       
   143             NewSubSessionL( EImpsEventCommon, aMessage );
       
   144             return;
       
   145 
       
   146         case EImpsGroupRegister:
       
   147             NewSubSessionL( EImpsEventGroup, aMessage );
       
   148             return;
       
   149 
       
   150         case EImpsServPureRegister:
       
   151             {
       
   152             NewSubSessionL( EImpsEventPresencePure, aMessage );
       
   153             }
       
   154         return;
       
   155 
       
   156         case EImpsServIsLogged:
       
   157             // This has to return positive value is CSP is found
       
   158             // and it has got SID.
       
   159             if ( IsThisLogged() )
       
   160                 {
       
   161                 CompleteMe( KErrNone );
       
   162                 }
       
   163             else
       
   164                 {
       
   165                 CompleteMe( KImpsErrorNotLogged );
       
   166                 }
       
   167             return;
       
   168 
       
   169         case EImpsServNbrSessions:
       
   170             nbrSess = NbrOfSessionsL( );
       
   171             CompleteMe( nbrSess );
       
   172             return;
       
   173 
       
   174         case EImpsServServices:
       
   175 #ifndef _NO_IMPS_LOGGING_
       
   176             CImpsClientLogger::Log( _L( "Session: EImpsServServices" ) );
       
   177 #endif
       
   178             CurrentServicesL();
       
   179             return;
       
   180 
       
   181         case EImpsServPush:
       
   182             // multi-csp supported, i.e. CIR given for every CSP session
       
   183             // until sessoin cookie matches
       
   184             if ( Server()->IsShuttingDown() )
       
   185                 {
       
   186                 User::Leave( KImpsErrorShuttingDown );
       
   187                 }
       
   188             PushMessageL();
       
   189             iCIRSess = ETrue;
       
   190             return;
       
   191 
       
   192         case EImpsServBuffSizeReq:
       
   193             CompleteMe( IsThisLogged() ? Server()->BufferSize() : 0 );
       
   194             return;
       
   195 
       
   196         case EImpsServCloseAll:		// close all sessions
       
   197             Server()->LogoutAll();
       
   198             CompleteMe( KErrNone );
       
   199             return;
       
   200         }
       
   201 
       
   202     // subsession specific requests
       
   203     TInt myHandle = aMessage.Int3( );
       
   204     CImpsSubSession* sub = ConnectionFromHandle( myHandle );
       
   205     if ( !sub )
       
   206         {
       
   207         PanicClient( EImpsBadRequest );
       
   208         return;
       
   209         }
       
   210 
       
   211     TBool reactive( EFalse );
       
   212 
       
   213     switch ( msg )
       
   214         {
       
   215 
       
   216         case EImpsServAssign:
       
   217             sub->AssignIdL( csp );
       
   218             return;
       
   219 
       
   220             // completion of request made in ServiceL
       
   221         case EImpsServReactiveLogin:
       
   222             reactive = ETrue;
       
   223         case EImpsServWVLogin:
       
   224             if ( Server()->IsShuttingDown() )
       
   225                 {
       
   226                 User::Leave( KImpsErrorShuttingDown );
       
   227                 }
       
   228             if ( !Server()->IsConAllowed() )
       
   229                 {
       
   230                 User::Leave( KImpsErrorTerminalOffLine );
       
   231                 }
       
   232             // multi: check if this session is already logged in.
       
   233             if ( IsThisLogged() )
       
   234                 {
       
   235                 User::Leave( KImpsErrorAlreadyLogged );
       
   236                 }
       
   237             iLogoutTID = KNullDesC;
       
   238             sub->LoginL( reactive );
       
   239             return;
       
   240 
       
   241             // case EImpsServWVLogoutOne:
       
   242         case EImpsServWVLogout:
       
   243             if ( Server()->IsShuttingDown() )
       
   244                 {
       
   245                 User::Leave( KImpsErrorShuttingDown );
       
   246                 }
       
   247             if ( !IsThisActive() )
       
   248                 {
       
   249                 User::Leave( KImpsErrorNotLogged );
       
   250                 }
       
   251             iLogoutTID = KNullDesC;
       
   252             iLogoutTID = sub->LogoutL( csp, EFalse );
       
   253             // The following is needed if no force logout
       
   254             // and a shared CSP exists.
       
   255             CompleteMe( KErrNone );
       
   256             return;
       
   257 
       
   258         case EImpsServWVSendOnly:
       
   259         case EImpsServBlock:
       
   260         case EImpsServGroup:
       
   261         case EImpsServPres:
       
   262         case EImpsServFundSearch:
       
   263         case EImpsServFundInvite:
       
   264             if ( Server()->IsShuttingDown() )
       
   265                 {
       
   266                 User::Leave( KImpsErrorShuttingDown );
       
   267                 }
       
   268             // multi: check if this handle is logged
       
   269             if ( !IsThisLogged() )
       
   270                 {
       
   271                 User::Leave( KImpsErrorNotLogged );
       
   272                 }
       
   273             else if ( !Server()->IsConAllowed() )
       
   274                 {
       
   275                 User::Leave( KImpsErrorTerminalOffLine );
       
   276                 }
       
   277             sub->SendPrimitiveL( aMessage.Function(), csp );
       
   278             return;
       
   279 
       
   280         case EImpsServNextEvent:
       
   281             sub->NextEventL( aMessage );
       
   282             // This is completed later
       
   283             iMessageCompleted = ETrue;
       
   284             return;
       
   285 
       
   286         case EImpsServEventBody:
       
   287             sub->SendEventBodyL( aMessage );
       
   288             // This is completed later
       
   289             iMessageCompleted = ETrue;
       
   290             return;
       
   291 
       
   292         case EImpsServCloseSub:
       
   293 #ifndef _NO_IMPS_LOGGING_
       
   294             CImpsClientLogger::Log( _L( "Session: EImpsServCloseSub" ) );
       
   295 #endif
       
   296             sub->Unregister();
       
   297             // remove subsession type
       
   298             flag = sub->Type();
       
   299             iTypes = ( iTypes & ~flag );
       
   300             CompleteMe( KErrNone );
       
   301             return;
       
   302 
       
   303         case EImpsServDeleteSub:
       
   304             // remove subsession entity
       
   305 #ifndef _NO_IMPS_LOGGING_
       
   306             CImpsClientLogger::Log( _L( "Session: EImpsServDeleteSub" ) );
       
   307 #endif
       
   308             sub->DeleteSub();
       
   309             CompleteMe( KErrNone );
       
   310             return;
       
   311 
       
   312         case EImpsServGetBlocked:
       
   313             if ( Server()->IsShuttingDown() )
       
   314                 {
       
   315                 User::Leave( KImpsErrorShuttingDown );
       
   316                 }
       
   317             // multi: check if this handle is logged in
       
   318             if ( !IsThisLogged() )
       
   319                 {
       
   320                 User::Leave( KImpsErrorNotLogged );
       
   321                 }
       
   322             else if ( !Server()->IsConAllowed() )
       
   323                 {
       
   324                 User::Leave( KImpsErrorTerminalOffLine );
       
   325                 }
       
   326             sub->SendGetBlockedL( csp );
       
   327             return;
       
   328 
       
   329         case EImpsServStatusReg:
       
   330             sub->SetStatusObserver( ETrue );
       
   331             CompleteMe( KErrNone );
       
   332             return;
       
   333 
       
   334         case EImpsServStatusUnreg:
       
   335             sub->SetStatusObserver( EFalse );
       
   336             CompleteMe( KErrNone );
       
   337             return;
       
   338 
       
   339         case EImpsServDetailedReg:
       
   340             sub->SetDetailedError( ETrue );
       
   341             CompleteMe( KErrNone );
       
   342             return;
       
   343 
       
   344         case EImpsServDetailedUnreg:
       
   345             sub->SetDetailedError( EFalse );
       
   346             CompleteMe( KErrNone );
       
   347             return;
       
   348 
       
   349         case EImpsServCspVersion:
       
   350             CompleteMe( Server()->CspVersion() );
       
   351             return;
       
   352 
       
   353         case EImpsServCancelLogin:	// cancel ongoing login
       
   354             if ( Server()->IsShuttingDown() )
       
   355                 {
       
   356                 User::Leave( KImpsErrorShuttingDown );
       
   357                 }
       
   358             // Call logout with cancel parameter.
       
   359             ( void )sub->LogoutL( csp, ETrue );
       
   360             return;
       
   361 
       
   362         case EImpsServCancelTrans:	// cancel transaction
       
   363             // If the specified request is not found then just complete the current request.
       
   364             if ( !sub->CancelTrans( aMessage, csp ) )
       
   365                 {
       
   366                 CompleteMe( KErrNone );
       
   367                 }
       
   368             else
       
   369                 {
       
   370                 // Complete with cancel if operation is cancelled
       
   371                 CompleteMe( KErrCancel );
       
   372                 }
       
   373             return;
       
   374 
       
   375         case EImpsServSetExpiry:
       
   376             sub->SetExpiryTime( aMessage );
       
   377             CompleteMe( KErrNone );
       
   378             return;
       
   379 
       
   380         default:
       
   381             PanicClient( EImpsBadRequest );
       
   382             return;
       
   383         }
       
   384     }
       
   385 
       
   386 
       
   387 // ---------------------------------------------------------
       
   388 // CImpsSession::NewSubSessionL
       
   389 // ---------------------------------------------------------
       
   390 // Create a new connection; pass back its handle via the message
       
   391 // Ensures the object is cleaned up on failure
       
   392 void CImpsSession::NewSubSessionL(
       
   393     TImpsEventType aType,
       
   394     const RMessage2& aMessage )
       
   395     {
       
   396 #ifndef _NO_IMPS_LOGGING_
       
   397     CImpsClientLogger::Log( _L( "Session: NewSubSessionL sess=%d" ), TInt( this ) );
       
   398 #endif
       
   399     // Reject request if server is SHUTTING_DOWN
       
   400     if ( Server()->IsShuttingDown() )
       
   401         {
       
   402         User::Leave( KImpsErrorShuttingDown );
       
   403         }
       
   404     CImpsSubSession* sub = CImpsSubSession::NewL( this, aType, aMessage );
       
   405     CleanupClosePushL( *sub );
       
   406     iContainer->AddL( sub );
       
   407     // Add subsession to object index, this returns unique handle
       
   408     TInt handle = iSubSessions->AddL( sub );
       
   409     // write the handle to client
       
   410     TPckg<TInt> handlePckg( handle );
       
   411     TRAPD( res, aMessage.WriteL( 3, handlePckg ) );
       
   412     if ( res != KErrNone )
       
   413         {
       
   414         // Removing sub from object index will
       
   415         // cause Close() to be called on sub, and that calls destructor
       
   416         CleanupStack::Pop();
       
   417         iSubSessions->Remove( handle );
       
   418         PanicClient( EImpsCorrupted );
       
   419         User::Leave( res );
       
   420         }
       
   421     sub->SetHandle( handle );
       
   422     // notch up another resource
       
   423     iResourceCount++;
       
   424     // update iTypes bit Mask
       
   425     iTypes = iTypes | aType;
       
   426     CleanupStack::Pop( );
       
   427     }
       
   428 
       
   429 // ---------------------------------------------------------
       
   430 // CImpsSession::ConnectionFromHandle()
       
   431 // ---------------------------------------------------------
       
   432 CImpsSubSession* CImpsSession::ConnectionFromHandle( TUint aHandle )
       
   433     {
       
   434     CImpsSubSession* sub = ( CImpsSubSession* )iSubSessions->At( aHandle );
       
   435     return sub;
       
   436     }
       
   437 
       
   438 // ---------------------------------------------------------
       
   439 // CImpsSession::DeleteSubSession
       
   440 // ---------------------------------------------------------
       
   441 void CImpsSession::DeleteSubSession( TUint aHandle )
       
   442     {
       
   443 #ifndef _NO_IMPS_LOGGING_
       
   444     CImpsClientLogger::Log( _L( "Session: DeleteSubSession sess=%d" ), ( TInt )this );
       
   445 #endif
       
   446     // panic if bad handle
       
   447     CImpsSubSession* sub = ConnectionFromHandle( aHandle );
       
   448     if ( sub == NULL )
       
   449         {
       
   450 #ifndef _NO_IMPS_LOGGING_
       
   451         CImpsClientLogger::Log( _L( "Session: PANIC" ) );
       
   452 #endif
       
   453         PanicClient( EImpsCorrupted );
       
   454         }
       
   455 
       
   456     // remove subsession
       
   457     iSubSessions->Remove( aHandle );
       
   458     // decrement resource count
       
   459     iResourceCount--;
       
   460 
       
   461 #ifndef _NO_IMPS_LOGGING_
       
   462     TInt count = iSubSessions->ActiveCount();
       
   463     CImpsClientLogger::Log( _L( "Session: DeleteSubSession nbrsub=%d %d subses=%d" ),
       
   464                             count, iResourceCount,  ( TInt )sub );
       
   465 #endif
       
   466     }
       
   467 
       
   468 // ---------------------------------------------------------
       
   469 // CImpsSession::MatchSession
       
   470 // ---------------------------------------------------------
       
   471 TBool CImpsSession::MatchSession( TImpsSessIdent aCSP )
       
   472     {
       
   473     // -----------------------------------
       
   474     // Notice: comment
       
   475     // extra stuff for debugging
       
   476     /*
       
   477     TPtrC pp1 = aCSP.SAP();
       
   478     TPtrC pp2 = aCSP.UserId();
       
   479     TPtrC pp3 = aCSP.SID();
       
   480     TPtrC ppa = SAP();
       
   481     TPtrC ppb = UserId();
       
   482     TPtrC ppc = SID();
       
   483     CImpsClientLogger::Log(_L("Session: MatchSession aCSP sap=%S user=%S sid=%S"), &pp1, &pp2, &pp3);
       
   484     CImpsClientLogger::Log(_L("Session: MatchSession this sap=%S user=%S sid=%S"), &ppa, &ppb, &ppc);
       
   485     */
       
   486     // -----------------------------------
       
   487 
       
   488     // The current session-id must match if it is non-zero
       
   489     if ( aCSP.SID().Length() > 0 &&
       
   490          SID().Length() > 0 &&
       
   491          aCSP.SID().CompareF( SID() ) )
       
   492         {
       
   493         return EFalse;
       
   494         }
       
   495     // Also user-id and SAP address must match
       
   496     else if ( !( SAP().CompareF( aCSP.SAP() ) ) &&
       
   497               !( UserId().CompareF( aCSP.UserId() ) ) )
       
   498         {
       
   499 #ifndef _NO_IMPS_LOGGING_
       
   500         TPtrC p1 = SAP();
       
   501         TPtrC p2 = UserId();
       
   502         TPtrC p3 = aCSP.SID();
       
   503         CImpsClientLogger::Log( _L( "Session: MatchSession MATCH sess=%d sap=%S user=%S sid=%S" ),
       
   504                                 ( TInt )this,  &p1, &p2, &p3 );
       
   505 #endif
       
   506         return ETrue;
       
   507         }
       
   508     else
       
   509         {
       
   510         return EFalse;
       
   511         }
       
   512     }
       
   513 
       
   514 
       
   515 // ---------------------------------------------------------
       
   516 // CImpsSession::SendEvent()
       
   517 // ---------------------------------------------------------
       
   518 void CImpsSession::SendEvent(
       
   519     CImpsFields *aFields,
       
   520     TInt aOpId,
       
   521     TImpsServRequest aRequestType,
       
   522     TImpsMessageType aReqMsgType,
       
   523     TUint aHandle )
       
   524     {
       
   525     // It is possible that the cancel request from client is not
       
   526     // complete and this session entity is still waiting deletion.
       
   527     if ( iCanceled )
       
   528         {
       
   529         return;
       
   530         }
       
   531 
       
   532     TInt errx = KErrNone;
       
   533 
       
   534 #ifndef _NO_IMPS_LOGGING_
       
   535     CImpsClientLogger::Log( _L( "Session: SendEvent begins" ) );
       
   536 #endif
       
   537 
       
   538     // specified subsession
       
   539     if ( aHandle )
       
   540         {
       
   541         CImpsSubSession* sub = ConnectionFromHandle( aHandle );
       
   542         if ( sub )
       
   543             {
       
   544             sub->SendEvent(
       
   545                 aFields,
       
   546                 aOpId,
       
   547                 aRequestType,
       
   548                 aReqMsgType );
       
   549             }
       
   550         }
       
   551     // scan subsessions
       
   552     else
       
   553         {
       
   554         // This is safe even if client would close session or subsession
       
   555         // Scheduler does not allocate time for it until this loop ends.
       
   556         TInt count = iSubSessions->Count();
       
   557         for ( TInt i = 0; i < count; i++ )
       
   558             {
       
   559             CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   560             if ( sub )
       
   561                 {
       
   562                 TRAP( errx, sub->SendEvent(
       
   563                           aFields,
       
   564                           aOpId,
       
   565                           aRequestType,
       
   566                           aReqMsgType ) );
       
   567                 }
       
   568             }
       
   569         }
       
   570 
       
   571 #ifndef _NO_IMPS_LOGGING_
       
   572     CImpsClientLogger::Log( _L( "Session: SendEvent ends" ) );
       
   573 #endif
       
   574     }
       
   575 
       
   576 // ---------------------------------------------------------
       
   577 // CImpsSession::SendEvent()
       
   578 // Lighter version for engine status event
       
   579 // ---------------------------------------------------------
       
   580 void CImpsSession::SendEvent(
       
   581     EImpsInternalStatus aStatus )
       
   582     {
       
   583 
       
   584     // It is possible that the cancel request from client is not
       
   585     // complete and this session entity is still waiting deletion.
       
   586     if ( iCanceled )
       
   587         {
       
   588         return;
       
   589         }
       
   590 
       
   591 #ifndef _NO_IMPS_LOGGING_
       
   592     CImpsClientLogger::Log( _L( "Session: SendEvent begins aStatus=%d" ), aStatus );
       
   593 #endif
       
   594 
       
   595     if ( aStatus == EInternal_NOT_LOGGED || aStatus == EInternal_SHUTTING_DOWN )
       
   596         {
       
   597         // NOT_LOGGED event is sent after LogoutResponse and it cleans
       
   598         // the WV CSP TID, so that it will not receive any further
       
   599         // messages from transport.
       
   600         CleanSID();
       
   601         SetThisInactive();
       
   602         }
       
   603 
       
   604     // Scan subsessions
       
   605     TInt count = iSubSessions->Count();
       
   606     for ( TInt i = 0; i < count; i++ )
       
   607         {
       
   608         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   609         if ( sub )
       
   610             {
       
   611             sub->SendEvent( aStatus );
       
   612             }
       
   613         }
       
   614 
       
   615 #ifndef _NO_IMPS_LOGGING_
       
   616     CImpsClientLogger::Log( _L( "Session: SendEvent ends" ) );
       
   617 #endif
       
   618     }
       
   619 
       
   620 // ---------------------------------------------------------
       
   621 // CImpsSession::SendLogoutEvent
       
   622 // ---------------------------------------------------------
       
   623 void CImpsSession::SendLogoutEvent(
       
   624     TInt aRespStatus, TInt aOpId, CImpsSubSession* aSub,
       
   625     TUint aHandle )
       
   626     {
       
   627     // It is possible that the cancel request from client is not
       
   628     // complete and this session entity is still waiting deletion.
       
   629     if ( iCanceled )
       
   630         {
       
   631         return;
       
   632         }
       
   633 
       
   634 #ifndef _NO_IMPS_LOGGING_
       
   635     CImpsClientLogger::Log( _L( "Session: SendLogoutEventL" ) );
       
   636 #endif
       
   637 
       
   638     // specified subsession only
       
   639     if ( aHandle )
       
   640         {
       
   641         CImpsSubSession* sub = ConnectionFromHandle( aHandle );
       
   642         if ( sub )
       
   643             {
       
   644             sub->SendLogoutEvent( aRespStatus, aOpId );
       
   645             return;
       
   646             }
       
   647         }
       
   648 
       
   649     // Scan subsessions
       
   650     TInt count = iSubSessions->Count();
       
   651     for ( TInt i = 0; i < count; i++ )
       
   652         {
       
   653         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   654         // Igone a specific subsession
       
   655         if ( sub && sub != aSub )
       
   656             {
       
   657             sub->SendLogoutEvent( aRespStatus, aOpId );
       
   658             }
       
   659         }
       
   660     }
       
   661 
       
   662 // ---------------------------------------------------------
       
   663 // CImpsSession::CheckNotification()
       
   664 // ---------------------------------------------------------
       
   665 TBool CImpsSession::CheckNotifications(
       
   666     CImpsFields* aFields, TImpsSessIdent aCSP )
       
   667     {
       
   668     TBool retVal( EFalse );
       
   669     // It is possible that the cancel request from client is not
       
   670     // complete and this session entity is still waiting deletion.
       
   671     // Multi: Validate the CSP connection id and check that
       
   672     // client has not completed logout request.
       
   673     if ( iCanceled || !MatchSession( aCSP ) || !IsThisActive() )
       
   674         {
       
   675         return retVal;
       
   676         }
       
   677 
       
   678     TInt myType = 0;
       
   679     TInt myOpId = 0;
       
   680     // Notice: client thread use this information
       
   681     if ( aFields->MessageType() == EImpsDisconnect )
       
   682         {
       
   683         myType = EImpsServWVLogout;
       
   684         }
       
   685 
       
   686 
       
   687     // Scan subsessions
       
   688     TInt count = iSubSessions->Count();
       
   689     for ( TInt i = 0; i < count; i++ )
       
   690         {
       
   691         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   692         if ( sub && sub->CheckNotification( aFields ) )
       
   693             {
       
   694             retVal = ETrue;
       
   695             sub->SendEvent(
       
   696                 aFields, myOpId, ( TImpsServRequest )myType, EImpsMessageNone );
       
   697             }
       
   698         }
       
   699     return retVal;
       
   700     }
       
   701 
       
   702 // ---------------------------------------------------------
       
   703 // CImpsSession::HandleAllOrphans()
       
   704 // ---------------------------------------------------------
       
   705 void CImpsSession::HandleAllOrphans()
       
   706     {
       
   707     // current CSP indetification
       
   708     TImpsSessIdent csp( SID(), SAP(), UserId() );
       
   709     // Scan subsessions
       
   710     TInt count = iSubSessions->Count();
       
   711     for ( TInt i = 0; i < count; i++ )
       
   712         {
       
   713         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   714         if ( sub )
       
   715             {
       
   716             sub->HandleAllOrphans( csp );
       
   717             }
       
   718         }
       
   719     }
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // CImpsSession::CloseSession()
       
   723 // -----------------------------------------------------------------------------
       
   724 void CImpsSession::CloseSession()
       
   725     {
       
   726 #ifndef _NO_IMPS_LOGGING_
       
   727     CImpsClientLogger::Log( _L( "Session: CloseSession" ) );
       
   728 #endif
       
   729 
       
   730     iCanceled = ETrue;
       
   731     DeleteAllRequests();
       
   732     void DeleteAllEvents();
       
   733     // Delete the object index (this stores the objects for this session)
       
   734     delete iSubSessions;
       
   735     iSubSessions = NULL;
       
   736     Server()->RemoveContainer( iContainer );
       
   737     iContainer = NULL;
       
   738     }
       
   739 
       
   740 // ---------------------------------------------------------
       
   741 // CImpsSession::CheckRequests()
       
   742 // ---------------------------------------------------------
       
   743 TUint CImpsSession::CheckRequests(
       
   744     const TDesC& aTid,
       
   745     TInt& aOpId,
       
   746     TImpsServRequest& aRequestType,
       
   747     TImpsMessageType& aReqMsgType,
       
   748     TImpsSessIdent aCSP )
       
   749     {
       
   750 
       
   751     // It is possible that the cancel request from client is not
       
   752     // complete and this session entity is still waiting deletion.
       
   753     if ( iCanceled )
       
   754         {
       
   755         return 0;
       
   756         }
       
   757 
       
   758     // Check also that the CSP session matches
       
   759     if ( !MatchSession( aCSP ) )
       
   760         {
       
   761         return 0;
       
   762         }
       
   763 
       
   764     // Scan subsessions
       
   765     TInt count = iSubSessions->Count();
       
   766     for ( TInt i = 0; i < count; i++ )
       
   767         {
       
   768         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   769         if ( sub && sub->CheckRequests(
       
   770                  aTid,
       
   771                  aOpId,
       
   772                  aRequestType,
       
   773                  aReqMsgType ) )
       
   774             {
       
   775             // Check if a successful response for login
       
   776             if ( SID().Length() == 0 &&
       
   777                  aCSP.SID().Length() > 0 &&
       
   778                  aRequestType == EImpsServWVLogin )
       
   779                 {
       
   780                 // If OOM here then this returns 0 and expiry routines
       
   781                 // handles the request later on. This is extremely
       
   782                 // rare situation anyway.
       
   783                 TRAPD( errx, ModifySIDL( aCSP.SID() ) );
       
   784                 if ( errx )
       
   785                     {
       
   786                     return 0;
       
   787                     }
       
   788                 }
       
   789             return sub->Handle();
       
   790             }
       
   791         }
       
   792 
       
   793     return 0;
       
   794     }
       
   795 
       
   796 // ---------------------------------------------------------
       
   797 // CImpsSession::DiscardRequests()
       
   798 // ---------------------------------------------------------
       
   799 void CImpsSession::DiscardRequests(
       
   800     TTime aExpiryTime,
       
   801     TImpsEventType aServiceType,
       
   802     TImpsSessIdent aCSP,
       
   803     MImpsCSPSession* aSess )
       
   804     {
       
   805 
       
   806     // It is possible that the cancel request from client is not
       
   807     // complete and this session entity is still waiting deletion.
       
   808     // Multi: Validate the CSP connection too.
       
   809     if ( iCanceled || !MatchSession( aCSP ) )
       
   810         {
       
   811         return;
       
   812         }
       
   813 
       
   814     // Scan subsessions
       
   815     TInt count = iSubSessions->Count();
       
   816     for ( TInt i = 0; i < count; i++ )
       
   817         {
       
   818         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   819         if ( sub )
       
   820             {
       
   821             sub->DiscardRequests( aExpiryTime, aServiceType, aSess );
       
   822             }
       
   823         }
       
   824     }
       
   825 
       
   826 // ---------------------------------------------------------
       
   827 // CImpsSession::DiscardRequests()
       
   828 // ---------------------------------------------------------
       
   829 void CImpsSession::DiscardRequests(
       
   830     TInt aError,
       
   831     TImpsEventType aServiceType,
       
   832     TImpsSessIdent aCSP,
       
   833     MImpsCSPSession* aSess )
       
   834     {
       
   835 
       
   836     // It is possible that the cancel request from client is not
       
   837     // complete and this session entity is still waiting deletion.
       
   838     // It is possible that the cancel request from client is not
       
   839     // complete and this session entity is still waiting deletion.
       
   840     // Multi: Validate the CSP connection too.
       
   841     if ( iCanceled || !MatchSession( aCSP ) )
       
   842         {
       
   843         return;
       
   844         }
       
   845 
       
   846     // Scan subsessions
       
   847     TInt count = iSubSessions->Count();
       
   848     for ( TInt i = 0; i < count; i++ )
       
   849         {
       
   850         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   851         if ( sub )
       
   852             {
       
   853             sub->DiscardRequests( aError, aServiceType, aSess );
       
   854             }
       
   855         }
       
   856     }
       
   857 
       
   858 // ---------------------------------------------------------
       
   859 // CImpsSession::DiscardRequest()
       
   860 // ---------------------------------------------------------
       
   861 TBool CImpsSession::DiscardRequest(
       
   862     const TDesC& aTid,
       
   863     TImpsEventType aServiceType,
       
   864     TInt aCode,
       
   865     TImpsSessIdent aCSP )
       
   866     {
       
   867 
       
   868     TBool ret( EFalse );
       
   869 
       
   870     // It is possible that the cancel request from client is not
       
   871     // complete and this session entity is still waiting deletion.
       
   872     // Multi: Validate the CSP connection too.
       
   873     if ( iCanceled || !MatchSession( aCSP ) )
       
   874         {
       
   875         return EFalse;
       
   876         }
       
   877 
       
   878     // Scan subsessions
       
   879     TInt count = iSubSessions->Count();
       
   880     for ( TInt i = 0; i < count; i++ )
       
   881         {
       
   882         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   883         if ( sub )
       
   884             {
       
   885             ret = sub->DiscardRequest( aTid, aServiceType, aCode );
       
   886             if ( ret )
       
   887                 {
       
   888                 return ETrue;
       
   889                 }
       
   890             }
       
   891         }
       
   892 
       
   893     return EFalse;
       
   894     }
       
   895 
       
   896 // -----------------------------------------------------------------------------
       
   897 // CImpsSession::DeleteAllRequests()
       
   898 // -----------------------------------------------------------------------------
       
   899 void CImpsSession::DeleteAllRequests( )
       
   900     {
       
   901 #ifndef _NO_IMPS_LOGGING_
       
   902     CImpsClientLogger::Log( _L( "Session: DeleteAllRequests" ) );
       
   903 #endif
       
   904     if ( iCanceled )
       
   905         {
       
   906         return;
       
   907         }
       
   908 
       
   909     // Delete all buffered requests from this client.
       
   910     // Delete from subsessions
       
   911     TInt count = iSubSessions->Count();
       
   912     for ( TInt i = 0; i < count; i++ )
       
   913         {
       
   914         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   915         if ( sub )
       
   916             {
       
   917             sub->DeleteAllRequests();
       
   918             }
       
   919         }
       
   920 
       
   921     }
       
   922 
       
   923 // -----------------------------------------------------------------------------
       
   924 // CImpsSession::DeleteAllRequests()
       
   925 // -----------------------------------------------------------------------------
       
   926 void CImpsSession::DeleteAllRequests( TImpsSessIdent* aCSP )
       
   927     {
       
   928 #ifndef _NO_IMPS_LOGGING_
       
   929     CImpsClientLogger::Log( _L( "Session: DeleteAllRequests aCSP" ) );
       
   930 #endif
       
   931     if ( iCanceled )
       
   932         {
       
   933         return;
       
   934         }
       
   935 
       
   936     if ( !MatchSession( *aCSP ) )
       
   937         {
       
   938         return;
       
   939         }
       
   940 
       
   941     // Delete all buffered requests from this client.
       
   942     // Delete from subsessions
       
   943     TInt count = iSubSessions->Count();
       
   944     for ( TInt i = 0; i < count; i++ )
       
   945         {
       
   946         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   947         if ( sub )
       
   948             {
       
   949             sub->DeleteAllRequests();
       
   950             }
       
   951         }
       
   952 
       
   953     }
       
   954 
       
   955 // -----------------------------------------------------------------------------
       
   956 // CImpsSession::DeleteRequest
       
   957 // -----------------------------------------------------------------------------
       
   958 void CImpsSession::DeleteRequest( TInt aOpId, TUint aSubHandle )
       
   959     {
       
   960 
       
   961     if ( aSubHandle )
       
   962         {
       
   963         CImpsSubSession* sub = ConnectionFromHandle( aSubHandle );
       
   964         if ( sub )
       
   965             {
       
   966             sub->DeleteRequest( aOpId );
       
   967             }
       
   968         return;
       
   969         }
       
   970     }
       
   971 
       
   972 // -----------------------------------------------------------------------------
       
   973 // CImpsSession::ExpiryTime
       
   974 // -----------------------------------------------------------------------------
       
   975 TInt CImpsSession::ExpiryTime( )
       
   976     {
       
   977     if ( iCanceled )
       
   978         {
       
   979         return 0;
       
   980         }
       
   981 
       
   982     // Search the minimum subsession expiry time.
       
   983     TInt sesexp = 0;
       
   984     TInt exp = 0;
       
   985     TInt count = iSubSessions->Count();
       
   986     for ( TInt i = 0; i < count; i++ )
       
   987         {
       
   988         CImpsSubSession* sub = ( CImpsSubSession* )( ( *iSubSessions )[i] );
       
   989         if ( sub )
       
   990             {
       
   991             exp = sub->ExpiryTime();
       
   992             if ( ( exp && exp < sesexp ) || !sesexp )
       
   993                 {
       
   994                 sesexp = exp;
       
   995                 }
       
   996             }
       
   997         }
       
   998     return sesexp;
       
   999     }
       
  1000 
       
  1001 // ---------------------------------------------------------
       
  1002 // CImpsSession::CompleteMe()
       
  1003 // ---------------------------------------------------------
       
  1004 void CImpsSession::CompleteMe( TInt aStatus )
       
  1005     {
       
  1006     iMsgR.Complete( aStatus );
       
  1007     iMessageCompleted = ETrue;
       
  1008     }
       
  1009 
       
  1010 // ---------------------------------------------------------
       
  1011 // CImpsSession::PushMessageL()
       
  1012 // ---------------------------------------------------------
       
  1013 void CImpsSession::PushMessageL()
       
  1014     {
       
  1015     // read cookie
       
  1016 #ifndef _NO_IMPS_LOGGING_
       
  1017     CImpsClientLogger::Log( _L( "Session: PushMessageL" ) );
       
  1018 #endif
       
  1019     if ( !iStream )
       
  1020         {
       
  1021         iStream = HBufC8::NewL( KImpsMaxCookie );
       
  1022         }
       
  1023 
       
  1024     // server instance saves these after successful login
       
  1025     ( void ) ReadBuffer8L(  1, iStream );
       
  1026     Server()->CirMessageL( iStream->Des() );
       
  1027     }
       
  1028 
       
  1029 
       
  1030 // ---------------------------------------------------------
       
  1031 // CImpsSession::ServiceL()
       
  1032 // ---------------------------------------------------------
       
  1033 
       
  1034 void CImpsSession::ServiceL( const RMessage2& aMessage )
       
  1035     {
       
  1036     TRAPD( err, DispatchMessageL( aMessage ) );
       
  1037     if ( !iMessageCompleted )
       
  1038         {
       
  1039         CompleteMe( err );
       
  1040         }
       
  1041     }
       
  1042 
       
  1043 // ---------------------------------------------------------
       
  1044 // CImpsSession::PanicClient()
       
  1045 // ---------------------------------------------------------
       
  1046 void CImpsSession::PanicClient( TImpsPanic aPanic ) const
       
  1047     {
       
  1048     iMsgR.Panic( KImpsPanicCategory, aPanic );
       
  1049     }
       
  1050 
       
  1051 // ---------------------------------------------------------
       
  1052 // CImpsSession::CurrentServicesL()
       
  1053 // ---------------------------------------------------------
       
  1054 void CImpsSession::CurrentServicesL()
       
  1055     {
       
  1056 
       
  1057     TImpsSessIdent csp( SID(), SAP(), UserId() );
       
  1058     if ( !Server()->IsNegotiated( csp ) )
       
  1059         {
       
  1060         User::Leave( KImpsErrorServices );
       
  1061         }
       
  1062 
       
  1063     // Buffer for response
       
  1064     TBuf < sizeof( TImpsServices ) + 4 >
       
  1065     myBuf( sizeof( TImpsServices ) + 4 );
       
  1066     TImpsServices myServices;
       
  1067     myServices.Reset();
       
  1068 
       
  1069     TImpsServices* activeServices = Server()->Services( csp );
       
  1070     if ( !activeServices )
       
  1071         {
       
  1072         User::Leave( KImpsErrorServices );
       
  1073         }
       
  1074     myServices.Copy( *activeServices );
       
  1075 
       
  1076     // Copy service tree to the local descriptor buffer
       
  1077     const TUint8* aPtrStart = ( const TUint8* )myBuf.Ptr();
       
  1078     TInt32 tempSize = 0;
       
  1079     tempSize = sizeof( TImpsServices );
       
  1080     Mem::Copy( ( void* )aPtrStart, &tempSize, sizeof( tempSize ) );
       
  1081     aPtrStart = aPtrStart + sizeof( tempSize );
       
  1082     if ( tempSize )
       
  1083         {
       
  1084         Mem::Copy( ( void* )aPtrStart, ( void* )&myServices, tempSize );
       
  1085         }
       
  1086     TInt ret = iMsgR.Write( 0, myBuf );
       
  1087     // complete the request
       
  1088     CompleteMe( ret );
       
  1089 
       
  1090     }
       
  1091 
       
  1092 // ---------------------------------------------------------
       
  1093 // CImpsSession::ReadBuffer8L()
       
  1094 // aBuffer must be a member if there is a risk that
       
  1095 // more memory must be allocated, because of cleanupstack is
       
  1096 // inconsistent otherwise.
       
  1097 // ---------------------------------------------------------
       
  1098 TBool CImpsSession::ReadBuffer8L(
       
  1099     TInt aIndex,
       
  1100     HBufC8*& aBuffer )
       
  1101 //
       
  1102 // Copies a buffer from the client
       
  1103 // Only fails if there is not enough memory to increase the buffer size
       
  1104 //
       
  1105     {
       
  1106     TBool alloced = EFalse;
       
  1107     TInt desLen = iMsgR.GetDesLength( aIndex );
       
  1108 
       
  1109     if ( desLen < 0 )
       
  1110         {
       
  1111         User::Leave( desLen );
       
  1112         }
       
  1113 
       
  1114     HBufC8* newBuffer = NULL;
       
  1115 
       
  1116     if ( aBuffer == NULL )
       
  1117         {
       
  1118         newBuffer = HBufC8::NewLC( desLen );
       
  1119         alloced = ETrue;
       
  1120         }
       
  1121     else if ( desLen > aBuffer->Des().MaxLength() )
       
  1122         {
       
  1123         alloced = ETrue;
       
  1124         // we have to increase the size of buffer
       
  1125         aBuffer->Des().SetLength( 0 ); // to avoid copying the contents
       
  1126         newBuffer = aBuffer->ReAllocL( desLen  );
       
  1127         CleanupStack::PushL( newBuffer );
       
  1128         }
       
  1129 
       
  1130     TPtr8 desPtr = alloced ? newBuffer->Des() : aBuffer->Des();  //lint !e613 !e661
       
  1131     // newBuffer is allocated, aBuffer must not be zero
       
  1132     iMsgR.ReadL( aIndex, desPtr );
       
  1133 
       
  1134     if ( alloced )
       
  1135         {
       
  1136         aBuffer = newBuffer;
       
  1137         CleanupStack::Pop();
       
  1138         }
       
  1139 
       
  1140     return alloced;
       
  1141 
       
  1142     }
       
  1143 
       
  1144 // ---------------------------------------------------------
       
  1145 // CImpsSession::ApplicationId()
       
  1146 // ---------------------------------------------------------
       
  1147 TPtrC CImpsSession::ApplicationId()
       
  1148     {
       
  1149     return iApplicationId ? TPtrC( *iApplicationId ) : TPtrC();
       
  1150     }
       
  1151 
       
  1152 // ---------------------------------------------------------
       
  1153 // CImpsSession::SetUserIdL()
       
  1154 // ---------------------------------------------------------
       
  1155 void CImpsSession::SetUserIdL( const TDesC& aId )
       
  1156     {
       
  1157     delete iUserId;
       
  1158     iUserId = NULL;
       
  1159     iUserId = aId.AllocL();
       
  1160     }
       
  1161 
       
  1162 // ---------------------------------------------------------
       
  1163 // CImpsSession::SetSAPL()
       
  1164 // ---------------------------------------------------------
       
  1165 void CImpsSession::SetSAPL( const TDesC& aId )
       
  1166     {
       
  1167     delete iSAP;
       
  1168     iSAP = NULL;
       
  1169     iSAP = aId.AllocL();
       
  1170     }
       
  1171 
       
  1172 // ---------------------------------------------------------
       
  1173 // CImpsSession::SetThisInactive()
       
  1174 // Use iUserId to check whether client session is logged in
       
  1175 // ---------------------------------------------------------
       
  1176 void CImpsSession::SetThisInactive()
       
  1177     {
       
  1178 #ifndef _NO_IMPS_LOGGING_
       
  1179     CImpsClientLogger::Log( _L( "Session: SetThisInactive sess=%d" ), ( TInt )this );
       
  1180 #endif
       
  1181     delete iUserId;
       
  1182     iUserId = NULL;
       
  1183     }
       
  1184 
       
  1185 // ---------------------------------------------------------
       
  1186 // CImpsSession::NewFieldsL()
       
  1187 // Old iFields must not be deleted because of CImpsServer
       
  1188 // still uses that.
       
  1189 // ---------------------------------------------------------
       
  1190 void CImpsSession::NewFieldsL()
       
  1191     {
       
  1192     CImpsFields* newF = CImpsFields::NewL();
       
  1193     iFields = newF;
       
  1194     }
       
  1195 
       
  1196 // ---------------------------------------------------------
       
  1197 // CImpsSession::AssignIdL()
       
  1198 // ---------------------------------------------------------
       
  1199 void CImpsSession::AssignIdL()
       
  1200     {
       
  1201 
       
  1202 #ifndef _NO_IMPS_LOGGING_
       
  1203     CImpsClientLogger::Log( _L( "Session: AssignIdL begins" ) );
       
  1204 #endif
       
  1205     // Generate session's application id and client id
       
  1206     RMessage2 myMsg( iMsgR );
       
  1207     // verify that length is valid
       
  1208     TInt desLen = myMsg.GetDesLength( 0 );
       
  1209     if ( desLen > KImpsMaxClientId )
       
  1210         {
       
  1211 #ifndef _NO_IMPS_LOGGING_
       
  1212         CImpsClientLogger::Log( _L( "Session: Error: too long client-id" ) );
       
  1213 #endif
       
  1214         User::Leave( KImpsErrorValidate );
       
  1215         }
       
  1216     // allocate memory dynamically
       
  1217     delete iApplicationId;
       
  1218     iApplicationId = NULL;
       
  1219     iApplicationId = HBufC::NewL( desLen );
       
  1220     TPtr desPtr = iApplicationId->Des();
       
  1221     myMsg.ReadL( 0, desPtr );
       
  1222     }
       
  1223 
       
  1224 // ---------------------------------------------------------
       
  1225 // CImpsSession::CleanSID()
       
  1226 // ---------------------------------------------------------
       
  1227 void CImpsSession::CleanSID()
       
  1228     {
       
  1229     if ( !iSID )
       
  1230         {
       
  1231         return;
       
  1232         }
       
  1233 #ifndef _NO_IMPS_LOGGING_
       
  1234     TPtr p = iSID->Des();
       
  1235     CImpsClientLogger::Log( _L( "Session: CleanSID sess=%d sid=%S" ), ( TInt )this, &p );
       
  1236 #endif
       
  1237     delete iSID;
       
  1238     iSID = NULL;
       
  1239     }
       
  1240 
       
  1241 // ---------------------------------------------------------
       
  1242 // CImpsSession::ModifySIDL()
       
  1243 // ---------------------------------------------------------
       
  1244 void CImpsSession::ModifySIDL( const TDesC& aSID )
       
  1245     {
       
  1246 #ifndef _NO_IMPS_LOGGING_
       
  1247     TPtrC p = aSID;
       
  1248     CImpsClientLogger::Log( _L( "Session: ModifySIDL sess=%d sid=%S" ), ( TInt )this, &p );
       
  1249 #endif
       
  1250     delete iSID;
       
  1251     iSID = NULL;
       
  1252     iSID = aSID.AllocL();
       
  1253     }
       
  1254 
       
  1255 // ---------------------------------------------------------
       
  1256 // CImpsSession::NbrSessionsL( )
       
  1257 // ---------------------------------------------------------
       
  1258 TInt CImpsSession::NbrOfSessionsL()
       
  1259     {
       
  1260     RMessage2 myMsg( Message() );
       
  1261 
       
  1262     // Read PACKED ARRAY
       
  1263     CDesCArrayFlat* tempArr = new ( ELeave )CDesCArrayFlat( 2 );
       
  1264     CleanupStack::PushL( tempArr );   // << tempArr
       
  1265 
       
  1266     HBufC8* stream = *StreamBufAddr();
       
  1267     if ( ReadBuffer8L( 0, stream ) )
       
  1268         {
       
  1269         HBufC8** stream2 = StreamBufAddr();
       
  1270         *stream2 = stream;
       
  1271         }
       
  1272     TImpsPackedEntity packedMessage( stream );
       
  1273     const TUint8* pS = stream->Ptr();
       
  1274     packedMessage.DoUnpackArrayL( pS, tempArr );
       
  1275 
       
  1276     __ASSERT_DEBUG(
       
  1277         tempArr->MdcaCount() == 2,
       
  1278         User::Panic( KImpsPanicCategory,
       
  1279                      EImpsCorrupted ) );
       
  1280 
       
  1281     TPtrC tempUser = tempArr->MdcaPoint( 1 );
       
  1282     TPtrC tempSAP = tempArr->MdcaPoint( 0 );
       
  1283     TImpsSessIdent csp( KNullDesC, tempSAP, tempUser );
       
  1284 
       
  1285     // ask number of clint sessions
       
  1286     TInt ret =  Server()->NbrSessions( EFalse, csp );
       
  1287 
       
  1288     tempArr->Reset();
       
  1289     CleanupStack::PopAndDestroy( 1 );   // >> tempArr
       
  1290 
       
  1291     return ret;
       
  1292     }
       
  1293 
       
  1294 
       
  1295 // -----------------------------------------------------------------------------
       
  1296 // CWvEvent::CWvEvent
       
  1297 // -----------------------------------------------------------------------------
       
  1298 
       
  1299 CWvEvent::CWvEvent( TImpsEventType aType ) :
       
  1300         iType( aType ),
       
  1301         iMessageType( EImpsStatus ), // just default
       
  1302         iSent( EFalse ),
       
  1303         iPackedMessage ( NULL )
       
  1304     {}
       
  1305 
       
  1306 CWvEvent::~CWvEvent()
       
  1307     {
       
  1308     if ( iPackedMessage )
       
  1309         {
       
  1310         delete iPackedMessage;
       
  1311         }
       
  1312     iPackedMessage = NULL;
       
  1313     }
       
  1314 
       
  1315 void CWvEvent::Destroy()
       
  1316     {
       
  1317     iLink.Deque();
       
  1318     delete this;
       
  1319     }
       
  1320 
       
  1321 // -----------------------------------------------------------------------------
       
  1322 // CRequest::CRequest
       
  1323 // -----------------------------------------------------------------------------
       
  1324 CRequest::CRequest(
       
  1325     const TDesC& aTID,
       
  1326     TInt aOpId,
       
  1327     TImpsServRequest aRequestType,
       
  1328     TTime aExpiry,
       
  1329     TImpsMessageType aMessageType )
       
  1330         : iOpId( aOpId ),
       
  1331         iRequestType ( aRequestType ),
       
  1332         iMessageType ( aMessageType ),
       
  1333         iExpiry( aExpiry )
       
  1334     {
       
  1335     iTID = aTID;
       
  1336     }
       
  1337 
       
  1338 CRequest::~CRequest()
       
  1339     {
       
  1340 
       
  1341     }
       
  1342 
       
  1343 void CRequest::Destroy()
       
  1344     {
       
  1345     iLink.Deque();
       
  1346     delete this;
       
  1347     }
       
  1348 
       
  1349 //  End of File