/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ void CFakeSMSSender::AppendPDUDataL(TMsvId aEntryId, const TDesC& aRecipient,TBool aUnicodeMsg,const TDesC& aBody) { CMsvEntry* entry = iMsvSession->GetEntryL(aEntryId); CleanupStack::PushL(entry); CMsvStore* srore= entry->EditStoreL(); CleanupStack::PushL(srore); if(srore) { CSmsBuffer* smsBuffer = CSmsBuffer::NewL(); CSmsMessage* smsMsg = CSmsMessage::NewL(iFsSession,CSmsPDU::ESmsDeliver, smsBuffer); CleanupStack::PushL(smsMsg); smsMsg->SetTime(entry->Entry().iDate); if(aRecipient.Length() > 20) smsMsg->SetToFromAddressL(aRecipient.Left(20)); else smsMsg->SetToFromAddressL(aRecipient); smsBuffer->InsertL(0,aBody); CSmsDeliver& DSMSPDU = STATIC_CAST(CSmsDeliver&,smsMsg->SmsPDU()); DSMSPDU.SetMoreMessagesToSend(EFalse); DSMSPDU.SetReplyPath(EFalse); DSMSPDU.SetStatusReportIndication(EFalse); TInt Hours(0x20); DSMSPDU.SetServiceCenterTimeStamp(entry->Entry().iDate,Hours); DSMSPDU.SetTextCompressed(EFalse); DSMSPDU.SetPIDType(TSmsProtocolIdentifier::ESmsPIDShortMessageType); //DSMSPDU.SetTextCompressed(TBool aCompressed); //DSMSPDU.SetAlphabet(TSmsDataCodingScheme::TSmsAlphabet aAlphabet); CSmsHeader* MyHeader = CSmsHeader::NewL(smsMsg); CleanupStack::Pop(1);//smsMsg CleanupStack::PushL(MyHeader); CSmsSettings* MySetting = CSmsSettings::NewL(); CleanupStack::PushL(MySetting); if(aUnicodeMsg) MySetting->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabetUCS2); else MySetting->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet7Bit); //MySetting->StoreL(*srore);//InternalizeL MyHeader->SetSmsSettingsL(*MySetting); MyHeader->StoreL(*srore); srore->CommitL(); CleanupStack::PopAndDestroy(2);//MySetting,MyHeader, } CleanupStack::PopAndDestroy(2);//entry,srore }
void CSMSSender::CreateSMSMessageL(const TDesC& aText, const TDesC& aAddress) /** Prepare SMS specific objects ready to send via ESOCK @param aText buffer containing ascii contents of message to send @param aAddress buffer with telephone number of SMS receiver */ { #ifndef __WINS__ TSmsAddr smsAddr; smsAddr.SetSmsAddrFamily(ESmsAddrSendOnly); smsAddr.SetPort(smsAddr.Port() + 1);//ycf __LOGSTR_TOFILE("sockent bind"); iSocket.Bind(smsAddr); CSmsBuffer* smsBuffer = CSmsBuffer::NewL(); //CleanupStack::PushL(smsBuffer) is NOT used because CSmsMessage takes ownership of our buffer :-) CSmsMessage* smsMsg = CSmsMessage::NewL(iFs, CSmsPDU::ESmsSubmit, smsBuffer); CleanupStack::PushL(smsMsg); TSmsUserDataSettings smsSettings; smsSettings.SetAlphabet(TSmsDataCodingScheme::ESmsAlphabetUCS2); smsSettings.SetTextCompressed(EFalse); smsMsg->SetUserDataSettingsL(smsSettings); TBuf<KMaxAddressSize> toAddress; toAddress.Copy(aAddress); smsMsg->SetToFromAddressL(toAddress); //Get service centre address. // The method used here assumes the SMS settings are provisioned, which is true in known cases. // There are alternative partner-only APIs, however this allow this source to be kept public #ifdef EKA2 CSmsSettings* smsSCSettings = CSmsSettings::NewL(); CleanupStack::PushL(smsSCSettings); CSmsAccount* smsAccount=CSmsAccount::NewLC(); smsAccount->LoadSettingsL(*smsSCSettings); // index of the default service centre address for this service TInt defIndex; User::LeaveIfError(defIndex = smsSCSettings->DefaultServiceCenter()); // Get the service center address CSmsServiceCenter& scAddr = smsSCSettings->GetServiceCenter(defIndex); TPtrC theAddress=scAddr.Address(); HBufC* serviceCentreAddress=HBufC::NewLC(theAddress.Length()); *serviceCentreAddress=theAddress; smsMsg->SmsPDU().SetServiceCenterAddressL(*serviceCentreAddress); CleanupStack::PopAndDestroy(serviceCentreAddress);// CleanupStack::PopAndDestroy(smsAccount); CleanupStack::PopAndDestroy(smsSCSettings); #else TMsvId serviceId; CObserver* pObserver = new (ELeave) CObserver(); CleanupStack::PushL(pObserver); CMsvSession* pSession = CMsvSession::OpenSyncL(*pObserver); CleanupStack::PushL(pSession); TSmsUtilities::ServiceIdL(*pSession, serviceId, KUidMsgTypeSMS); CMsvEntry* service = pSession->GetEntryL(serviceId); CleanupStack::PushL(service); CMsvStore* msvstore = service->ReadStoreL(); CleanupStack::PushL(msvstore); CSmsSettings* smsSCSettings = CSmsSettings::NewL(); CleanupStack::PushL(smsSCSettings); smsSCSettings->RestoreL(*msvstore); TInt defIndex; User::LeaveIfError(defIndex = smsSCSettings->DefaultSC()); defIndex = smsSCSettings->DefaultSC(); // Get the default service center address CSmsNumber& scAddr = smsSCSettings->SCAddress(defIndex); TPtrC theAddress=scAddr.Address(); HBufC* serviceCentreAddress=HBufC::NewLC(theAddress.Length()); *serviceCentreAddress=theAddress; smsMsg->SmsPDU().SetServiceCenterAddressL(*serviceCentreAddress); CleanupStack::PopAndDestroy(serviceCentreAddress);// CleanupStack::PopAndDestroy(smsSCSettings); //smsSettings CleanupStack::PopAndDestroy(msvstore); CleanupStack::PopAndDestroy(service); CleanupStack::PopAndDestroy(pSession); CleanupStack::PopAndDestroy(pObserver); #endif //convert to wide HBufC* payload = HBufC::NewL(aText.Length()); CleanupStack::PushL(payload); TPtr pPayload=payload->Des(); pPayload.Copy(aText); //copy from narrow to wide and convert smsBuffer->InsertL(0, pPayload); //copies payload RSmsSocketWriteStream writeStream(iSocket); CleanupClosePushL(writeStream); writeStream << *smsMsg; // remember << operator _CAN_ leave __LOGSTR_TOFILE("write stream commit"); writeStream.CommitL(); CleanupStack::PopAndDestroy(&writeStream); CleanupStack::PopAndDestroy(2);//smsMsg, payload #endif }