imservices/ossprotocoladaptation/src/presentitygroups/caddpresentitygroupmemberrequest.cpp
changeset 46 860cd8a5168c
parent 35 085f765766a0
equal deleted inserted replaced
35:085f765766a0 46:860cd8a5168c
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Add Presentity Group Member Request to the Network Server.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ximpprotocolconnectionhost.h>
       
    20 #include "caddpresentitygroupmemberrequest.h"
       
    21 #include "cossprotocolconnectionmanager.h"
       
    22 #include "ossprotocolpluginlogger.h"
       
    23 
       
    24 #include <ximpobjectfactory.h>
       
    25 #include <protocolpresencedatahost.h>
       
    26 #include <presenceobjectfactory.h>
       
    27 #include <ximpobjectcollection.h>
       
    28 #include <protocolpresentitygroupsdatahost.h>
       
    29 #include <presentitygroupinfo.h>
       
    30 #include <presentitygroupmemberinfo.h>
       
    31 #include <ximpidentity.h>
       
    32 
       
    33 #include <glib/gstrfuncs.h>
       
    34 #include <gtypes.h>
       
    35 #include <stdlib.h>
       
    36 #include "stringutils.h"
       
    37 #include <string.h>
       
    38 #include <sys/types.h>
       
    39 #include <stdio.h>
       
    40 #include <glib/gprintf.h>
       
    41 #include "msgliterals.h"
       
    42 #include "msg_enums.h"
       
    43 #include "ossprotocoladaptutils.h"
       
    44 #include <avabilitytext.h>
       
    45 
       
    46 // ======== MEMBER FUNCTIONS ========
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CAddPresentityGroupMemberRequest::CAddPresentityGroupMemberRequest
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CAddPresentityGroupMemberRequest::CAddPresentityGroupMemberRequest( 
       
    53 						MOSSProtocolConnectionManager& aConnMan,
       
    54 						TXIMPRequestId aRequestId ) :
       
    55     CActive( EPriorityNormal ),
       
    56     iRequestId( aRequestId ),
       
    57     iConnMan( aConnMan )
       
    58     {
       
    59     LOGGER ( TXT("::CAddPresentityGroupMemberRequest Start") );
       
    60     CActiveScheduler::Add( this );
       
    61     
       
    62     LOGGER ( TXT("::CAddPresentityGroupMemberRequest End") );
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CAddPresentityGroupMemberRequest::ConstructL
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CAddPresentityGroupMemberRequest::ConstructL()
       
    71     {
       
    72     
       
    73     LOGGER ( TXT("CAddPresentityGroupMemberRequest::ConstructL Start-End") );
       
    74     iContactId = NULL;
       
    75     }
       
    76 
       
    77 
       
    78 
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CAddPresentityGroupMemberRequest::NewLC
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CAddPresentityGroupMemberRequest* CAddPresentityGroupMemberRequest::NewLC(
       
    86     MOSSProtocolConnectionManager& aConnMan,
       
    87     TXIMPRequestId aRequestId )
       
    88     {
       
    89     LOGGER ( TXT("CAddPresentityGroupMemberRequest::NewLC Start") );
       
    90     
       
    91     CAddPresentityGroupMemberRequest* self = new( ELeave ) 
       
    92     			CAddPresentityGroupMemberRequest( aConnMan, aRequestId );
       
    93     CleanupStack::PushL( self );
       
    94     self->ConstructL();
       
    95      
       
    96     LOGGER ( TXT("CAddPresentityGroupMemberRequest::NewLC End") );
       
    97     return self;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CAddPresentityGroupMemberRequest::~CAddPresentityGroupMemberRequest
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CAddPresentityGroupMemberRequest::~CAddPresentityGroupMemberRequest()
       
   105     {
       
   106     LOGGER ( TXT("::~CAddPresentityGroupMemberRequest Start") );
       
   107    
       
   108 	CActive::Cancel();
       
   109 	if(iContactId)
       
   110 	    {
       
   111 	    delete iContactId;
       
   112 	    }
       
   113     LOGGER ( TXT("::~CAddPresentityGroupMemberRequest End") );
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CAddPresentityGroupMemberRequest::DoCancel()
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CAddPresentityGroupMemberRequest::DoCancel()
       
   122     {
       
   123     LOGGER ( TXT("CAddPresentityGroupMemberRequest::DoCancel Start") );
       
   124    
       
   125     LOGGER ( TXT("CAddPresentityGroupMemberRequest::DoCancel End") );
       
   126     }
       
   127 
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CAddPresentityGroupMemberRequest::RunL()
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CAddPresentityGroupMemberRequest::RunL()
       
   134     {
       
   135     LOGGER ( TXT("CAddPresentityGroupMemberRequest::RunL Start") );
       
   136     message_hdr_resp* msg_struct = NULL;
       
   137     char* pResponse = NULL;  
       
   138 	User::LeaveIfError( iStatus.Int() );
       
   139    
       
   140 	pResponse = iConnMan.DataHandler().ResponseL ( iSendId );
       
   141 	
       
   142 	msg_struct = ( message_hdr_resp* )pResponse ;
       
   143 	if( !( msg_struct->response ) )
       
   144 	{
       
   145 		switch( msg_struct->error_type )
       
   146 		{
       
   147 	
       
   148 		default:  //for all other error codes like ssl related are mapped to general error
       
   149 			   iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KXIMPErrServiceGeneralError );
       
   150 		       break;       
       
   151 		}	
       
   152 	}
       
   153 	else
       
   154 	{
       
   155     //set presence as pending for the added contact
       
   156     MPresenceBuddyInfo2* buddyPresInfo = MPresenceBuddyInfo2::NewLC();
       
   157 
       
   158     MPresenceCacheWriter2* presenceCacheWriter = MPresenceCacheWriter2::CreateWriterL();
       
   159     CleanupDeletePushL(presenceCacheWriter);
       
   160     HBufC* name = HBufC::NewLC( iContactId->Length() + iConnMan.ServiceName().Length() + KColon().Length() );
       
   161     TPtr namePtr( name->Des() );
       
   162     namePtr.Zero();
       
   163     namePtr.Append(iConnMan.ServiceName() ); // prepend service name
       
   164     namePtr.Append(KColon);
       
   165     namePtr.Append(iContactId->Des() );
       
   166     buddyPresInfo->SetIdentityL(namePtr);
       
   167     LOGGER ( TXT ( "CPresenceNotificationHandler::ProcessIncomingDataL  :ContactName:%S " ), iContactId ); 
       
   168    
       
   169     buddyPresInfo->SetAnyFieldL(KExtensionKey,KPendingRequestExtensionValue());
       
   170     CleanupStack::PopAndDestroy(1);//name
       
   171 
       
   172     // Writing into Presence Cache
       
   173     TInt cacheerror = presenceCacheWriter->WritePresenceL(buddyPresInfo);
       
   174     User::LeaveIfError ( cacheerror);
       
   175     CleanupStack::PopAndDestroy(2);//presenceCacheWriter,buddyPresInfo
       
   176     
       
   177 	iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KErrNone );
       
   178 	}
       
   179 	free( pResponse );
       
   180 	delete this;
       
   181 	LOGGER ( TXT("CAddPresentityGroupMemberRequest::RunL End") );
       
   182     }
       
   183 
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CAddPresentityGroupMemberRequest::RunError
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 TInt CAddPresentityGroupMemberRequest::RunError( TInt  aError )
       
   190     {
       
   191     LOGGER ( TXT("CAddPresentityGroupMemberRequest::RunError Start") );
       
   192     
       
   193     iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, aError );
       
   194     delete this;
       
   195     
       
   196 	LOGGER ( TXT("CAddPresentityGroupMemberRequest::RunError End") );
       
   197     return KErrNone;
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CAddPresentityGroupMemberRequest::AddPresentityGroupMemberL
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void CAddPresentityGroupMemberRequest::AddPresentityGroupMemberL(
       
   205     const MXIMPIdentity& /*aGroupId*/,
       
   206     const MXIMPIdentity& aMemberId,
       
   207     const TDesC16& aMemberDisplayName)
       
   208     {   
       
   209     LOGGER ( TXT("CAddPresentityGroupMemberRequest::AddPresentityGroupMemberL Start") );
       
   210     if(iContactId)
       
   211         {
       
   212         delete iContactId;
       
   213         iContactId = NULL;
       
   214         }
       
   215     iContactId = aMemberId.Identity().AllocL();
       
   216   	char *smsg = NULL;
       
   217 	int totalLen = 0;
       
   218     message_hdr_req msgHdr = {0,};
       
   219     msgHdr.message_type = EAdd_Contact_Request;	
       
   220 
       
   221 	TInt headerLength = sizeof( message_hdr_req );
       
   222 	totalLen += headerLength;
       
   223 
       
   224 	// adding add contact
       
   225 	charFormatData  memberIdentityData  = OssProtocolAdapUtils::ConvertTUint16ToCharLC( aMemberId.Identity() );
       
   226     char* memberIdentity  = memberIdentityData.data;    
       
   227 	TInt memberIdLength = memberIdentityData.dataSize;
       
   228     totalLen += memberIdLength;
       
   229     
       
   230     charFormatData displayNameData = OssProtocolAdapUtils::ConvertTUint16ToCharLC( aMemberDisplayName ); 
       
   231     char* displayName = displayNameData.data;   	 	
       
   232 	TInt displayNameLength = displayNameData.dataSize;    
       
   233     totalLen += displayNameLength;
       
   234     
       
   235 	if ( totalLen > MAX_MSG_SIZE ) 
       
   236 		{
       
   237 		User::Leave(KErrArgument);		
       
   238 		}
       
   239     
       
   240     //after getting size now allocate memory.
       
   241     smsg = ( char* ) User::AllocLC(totalLen);
       
   242     memset ( smsg, '\0', totalLen );
       
   243     
       
   244     memcpy( smsg, &msgHdr, sizeof( message_hdr_req ) ); //header
       
   245     memcpy( smsg + headerLength , memberIdentity , memberIdLength ); //id
       
   246     memcpy( smsg + headerLength + memberIdLength + 1 , displayName , displayNameLength ); //display name
       
   247         
       
   248 	iSendId = iConnMan.DataHandler().SendDataL ( iStatus, smsg, totalLen );
       
   249     
       
   250     // signal the scheduler
       
   251 	SetActive();
       
   252 
       
   253 	CleanupStack::PopAndDestroy ( 3 );//smsg, memberIdentity, displayName. 
       
   254 	
       
   255 	LOGGER ( TXT("CAddPresentityGroupMemberRequest::AddPresentityGroupMemberL End") );
       
   256     }
       
   257 
       
   258 
       
   259 // End of file