|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32std.h> |
|
17 #include <gsmumsg.h> |
|
18 #include <smutset.h> |
|
19 #include "SMSRecipientSend.h" |
|
20 |
|
21 #include <smsuaddr.h> |
|
22 #include <smsustrm.h> |
|
23 #include <smuthdr.h> |
|
24 #include <csmsemailfields.h> |
|
25 #include "SmssSimUtils.h" |
|
26 #include <msventry.h> |
|
27 #include <logwraplimits.h> |
|
28 |
|
29 #ifndef _MSG_NO_LOGGING |
|
30 _LIT(KTextRecipientSendLogFile, "TextSend.txt"); |
|
31 #endif |
|
32 |
|
33 CTextRecipientSend* CTextRecipientSend::NewL(TSmsProgress& aProgress, RFs& aFs, CMsvServerEntry& aServerEntry) |
|
34 { |
|
35 CTextRecipientSend* self = new (ELeave) CTextRecipientSend(aProgress, aFs, aServerEntry); |
|
36 CleanupStack::PushL(self); |
|
37 |
|
38 self->ConstructL(); |
|
39 |
|
40 CleanupStack::Pop(); |
|
41 return self; |
|
42 } |
|
43 |
|
44 TBool CTextRecipientSend::AcceptMessage(const TMsvEntry& aEntry, const CSmsHeader& aHeader) const |
|
45 { |
|
46 TBool retVal = (aHeader.BioMsgIdType() == EBioMsgIdNbs); |
|
47 |
|
48 if (retVal && aEntry.iBioType) |
|
49 { |
|
50 TInt err = AcceptBioType(aEntry.iBioType, aHeader.BioMsgIdType()); |
|
51 retVal = (err == KErrNone); |
|
52 } |
|
53 |
|
54 return retVal; |
|
55 } |
|
56 |
|
57 TBool CTextRecipientSend::AcceptBioMsgId(const TBioMsgId& aBioMsgId) const |
|
58 { |
|
59 return aBioMsgId.iType == EBioMsgIdNbs && aBioMsgId.iPort <= 0 && aBioMsgId.iText.Length(); |
|
60 } |
|
61 |
|
62 CTextRecipientSend::CTextRecipientSend(TSmsProgress& aProgress, RFs& aFs, CMsvServerEntry& aServerEntry) |
|
63 : CSmsRecipientSend(aProgress, aFs, aServerEntry) |
|
64 { |
|
65 } |
|
66 |
|
67 CTextRecipientSend::~CTextRecipientSend() |
|
68 { |
|
69 Cancel(); |
|
70 } |
|
71 |
|
72 void CTextRecipientSend::StartL() |
|
73 { |
|
74 if (iRecipient->LogId() == KLogNullId) |
|
75 AddLogEvent(); |
|
76 else |
|
77 GetLogEvent(); |
|
78 } |
|
79 |
|
80 void CTextRecipientSend::PrependNbsStringL(const TMsvEntry& aEntry, CSmsMessage& arMessage, HBufC*& rOldMessage) |
|
81 { |
|
82 rOldMessage = NULL; |
|
83 |
|
84 const CSmsEmailFields& fields = iHeader->EmailFields(); |
|
85 |
|
86 if (aEntry.iBioType) |
|
87 { |
|
88 if( fields.HasAddress() ) |
|
89 { |
|
90 // This is a BIO message that has email fields - not supported. |
|
91 User::Leave(KErrNotSupported); |
|
92 } |
|
93 |
|
94 CSmsBufferBase& buffer = arMessage.Buffer(); |
|
95 TInt length = buffer.Length(); |
|
96 HBufC* oldMessage = HBufC::NewLC(length); |
|
97 TPtr oldPtr(oldMessage->Des()); |
|
98 buffer.Extract(oldPtr, 0, length); |
|
99 |
|
100 TBioMsgId bioMsgId; |
|
101 GetDefaultSendBearerL(aEntry.iBioType, EBioMsgIdNbs, bioMsgId); //will leave with KErrNotFound if a bioIdType is not found |
|
102 |
|
103 //Only prepend the nbs string if it doesn't exist already |
|
104 if (oldMessage->FindF(bioMsgId.iText) != 0) //case insensitve |
|
105 { |
|
106 length += bioMsgId.iText.Length(); |
|
107 length += 1; //for the line feed |
|
108 |
|
109 HBufC* newMessage = HBufC::NewLC(length); |
|
110 TPtr newPtr(newMessage->Des()); |
|
111 |
|
112 newPtr.Append(bioMsgId.iText); |
|
113 newPtr.Append(_L("\n")); //according to the Smart Messaging Spec |
|
114 newPtr.Append(*oldMessage); |
|
115 |
|
116 //Pre-pend the string to the CSmsMessage |
|
117 buffer.Reset(); |
|
118 buffer.InsertL(0, newPtr); |
|
119 |
|
120 CleanupStack::PopAndDestroy(newMessage); |
|
121 CleanupStack::Pop(oldMessage); |
|
122 rOldMessage = oldMessage; |
|
123 } |
|
124 else |
|
125 { |
|
126 CleanupStack::PopAndDestroy(oldMessage); |
|
127 } |
|
128 } |
|
129 else |
|
130 { |
|
131 // Check if this is an email message - just check the email fields have |
|
132 // a length greater than zero. The PID will have been set for email. |
|
133 if( fields.HasAddress() ) |
|
134 { |
|
135 __ASSERT_DEBUG( arMessage.SmsPDU().TelematicDeviceType() == TSmsProtocolIdentifier::ESmsInternetElectronicMail, User::Invariant() ); |
|
136 |
|
137 // Create the email header. |
|
138 HBufC* buf = fields.ComposeLC(); |
|
139 |
|
140 // Need to append the email fields to the start of the message body. |
|
141 CSmsBufferBase& body = arMessage.Buffer(); |
|
142 body.InsertL(0, *buf); |
|
143 CleanupStack::PopAndDestroy(buf); |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 void CTextRecipientSend::RevertBackToOldMessageL(const TDesC& aOldMessage, CSmsMessage& arMessage) |
|
149 { |
|
150 CSmsBufferBase& buffer = arMessage.Buffer(); |
|
151 buffer.Reset(); |
|
152 buffer.InsertL(0, aOldMessage); |
|
153 } |
|
154 |
|
155 void CTextRecipientSend::SendMessageL() |
|
156 { |
|
157 SMSSLOG(FLogFormat(_L8("CTextRecipientSend::SendMessageL() for msg %d"), iEntry.Id())); |
|
158 //Store the header to preserve the log ID |
|
159 const TMsvId oldId = iServerEntry.Entry().Id(); |
|
160 User::LeaveIfError(iServerEntry.SetEntry(iEntry.Id())); |
|
161 StoreHeaderL(*iHeader); |
|
162 iServerEntry.SetEntry(oldId); //ignore error |
|
163 |
|
164 CSmsMessage& message = iHeader->Message(); |
|
165 |
|
166 HBufC* oldMessage = NULL; |
|
167 |
|
168 PrependNbsStringL(iEntry, message, oldMessage); |
|
169 |
|
170 if (oldMessage) |
|
171 { |
|
172 CleanupStack::PushL(oldMessage); |
|
173 } |
|
174 |
|
175 SMSSLOG(FLogMessage(iEntry, message, iHeader->BioMsgIdType(), KTextRecipientSendLogFile)); |
|
176 |
|
177 CSmsSimUtils::ConnectL(iSession, iSocket, ESmsAddrSendOnly); |
|
178 |
|
179 RSmsSocketWriteStream writestream(iSocket); |
|
180 writestream << message; |
|
181 |
|
182 if (oldMessage) |
|
183 { |
|
184 RevertBackToOldMessageL(*oldMessage, message); |
|
185 CleanupStack::PopAndDestroy(); //oldMessage |
|
186 } |
|
187 |
|
188 writestream.CommitL(); |
|
189 |
|
190 iSocket.Ioctl(KIoctlSendSmsMessage, iStatus,&iSendBuffer, KSolSmsProv); |
|
191 |
|
192 iState = ESmsRecipientSendSendingMessage; |
|
193 SetActive(); |
|
194 } |
|
195 |
|
196 void CTextRecipientSend::DoCancelSendingMessage() |
|
197 { |
|
198 SMSSLOG(FLogFormat(_L8("CTextRecipientSend::DoCancelSendingMessage() while sending msg %d"), iEntry.Id())); |
|
199 iSocket.CancelIoctl(); |
|
200 } |