1 // Copyright (c) 2000-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 <smuthdr.h> |
|
18 #include "SMSSPAN.H" |
|
19 #include "SMSRecipientSend.h" |
|
20 #include <logwraplimits.h> |
|
21 |
|
22 #ifndef _MSG_NO_LOGGING |
|
23 _LIT(KWapRecipientSendLogFile, "WapSend.txt"); |
|
24 #endif |
|
25 |
|
26 CWapRecipientSend* CWapRecipientSend::NewL(TSmsProgress& aProgress, RFs& aFs, CMsvServerEntry& aServerEntry) |
|
27 { |
|
28 CWapRecipientSend* self = new (ELeave) CWapRecipientSend(aProgress, aFs, aServerEntry); |
|
29 CleanupStack::PushL(self); |
|
30 |
|
31 self->ConstructL(); |
|
32 |
|
33 CleanupStack::Pop(); |
|
34 return self; |
|
35 } |
|
36 |
|
37 TBool CWapRecipientSend::AcceptMessage(const TMsvEntry& aEntry, const CSmsHeader& aHeader) const |
|
38 { |
|
39 TBool retVal = (aEntry.iBioType != 0); |
|
40 |
|
41 const TBioMsgIdType bearer = aHeader.BioMsgIdType(); |
|
42 |
|
43 if (retVal) |
|
44 { |
|
45 retVal = (bearer == EBioMsgIdWap || bearer == EBioMsgIdWapSecure); |
|
46 retVal |= (bearer == EBioMsgIdNbs && aHeader.Submit().Alphabet() == TSmsDataCodingScheme::ESmsAlphabet7Bit); |
|
47 } |
|
48 |
|
49 if (retVal) |
|
50 { |
|
51 TInt err = AcceptBioType(aEntry.iBioType, bearer); |
|
52 retVal = (err == KErrNone); |
|
53 } |
|
54 |
|
55 return retVal; |
|
56 } |
|
57 |
|
58 TBool CWapRecipientSend::AcceptBioMsgId(const TBioMsgId& aBioMsgId) const |
|
59 { |
|
60 TBool retVal = (aBioMsgId.iType == EBioMsgIdWap || aBioMsgId.iType == EBioMsgIdWapSecure); |
|
61 |
|
62 if (!retVal) |
|
63 { |
|
64 retVal = (aBioMsgId.iType == EBioMsgIdNbs && !aBioMsgId.iText.Length()); |
|
65 } |
|
66 |
|
67 retVal &= (aBioMsgId.iPort > 0); |
|
68 |
|
69 return retVal; |
|
70 } |
|
71 |
|
72 |
|
73 CWapRecipientSend::CWapRecipientSend(TSmsProgress& aProgress, RFs& aFs, CMsvServerEntry& aServerEntry) |
|
74 : CSmsRecipientSend(aProgress, aFs, aServerEntry) |
|
75 { |
|
76 } |
|
77 |
|
78 void CWapRecipientSend::StartL() |
|
79 { |
|
80 if (iRecipient->LogId() == KLogNullId) |
|
81 { |
|
82 AddLogEvent(); |
|
83 } |
|
84 else |
|
85 { |
|
86 GetLogEvent(); |
|
87 } |
|
88 } |
|
89 |
|
90 void CWapRecipientSend::SendMessageL() |
|
91 { |
|
92 SMSSLOG(FLogFormat(_L8("CWapRecipientSend::SendMessageL() for msg %d"), iEntry.Id())); |
|
93 |
|
94 __ASSERT_DEBUG(iEntry.iBioType, Panic(KSmssPanicBioTypeNotSet)); |
|
95 |
|
96 const CSmsMessage& message = iHeader->Message(); |
|
97 |
|
98 SMSSLOG(FLogMessage(iEntry, message, iHeader->BioMsgIdType(), KWapRecipientSendLogFile)); |
|
99 |
|
100 //Convert the telephone number to a 8-bit descriptor |
|
101 HBufC8* addr = HBufC8::NewLC(message.ToFromAddress().Length()); |
|
102 TPtr8 addrPtr(addr->Des()); |
|
103 addrPtr.Copy(message.ToFromAddress()); |
|
104 |
|
105 //Extract the message from the CSmsMessage |
|
106 const TInt length = message.Buffer().Length(); |
|
107 HBufC* msg = HBufC::NewLC(length); |
|
108 TPtr msgPtr(msg->Des()); |
|
109 message.Buffer().Extract(msgPtr, 0, length); |
|
110 |
|
111 //Convert the message to 8-bit |
|
112 delete iMessage8; |
|
113 iMessage8 = NULL; |
|
114 iMessage8 = HBufC8::NewL(length); |
|
115 TPtr8 msg8Ptr(iMessage8->Des()); |
|
116 msg8Ptr.Copy(msgPtr); |
|
117 |
|
118 //Get the port number from the BIO Database |
|
119 TBioMsgId bioMsgId; |
|
120 GetDefaultSendBearerL(iEntry.iBioType, iHeader->BioMsgIdType(), bioMsgId); |
|
121 iWapAddr.SetWapAddress(*addr); |
|
122 iWapAddr.SetPort(bioMsgId.iPort); |
|
123 |
|
124 if (!iSession.Handle()) |
|
125 { |
|
126 User::LeaveIfError(iSession.Connect()); |
|
127 } |
|
128 |
|
129 if (!iSocket.SubSessionHandle()) |
|
130 { |
|
131 User::LeaveIfError(iSocket.Open(iSession, KWAPSMSAddrFamily, KSockDatagram, KWAPSMSDatagramProtocol)); |
|
132 } |
|
133 |
|
134 //Set the SMS Data Encoding Scheme |
|
135 switch (iHeader->Submit().Alphabet()) |
|
136 { |
|
137 case TSmsDataCodingScheme::ESmsAlphabet8Bit: |
|
138 { |
|
139 TWapSmsDataCodingScheme codingScheme = EWapSms8BitDCS; |
|
140 User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,codingScheme)); |
|
141 break; |
|
142 } |
|
143 case TSmsDataCodingScheme::ESmsAlphabet7Bit: |
|
144 break; |
|
145 default: |
|
146 User::Leave(KErrNotSupported); |
|
147 } |
|
148 |
|
149 //Send the message |
|
150 iSocket.SendTo(*iMessage8, iWapAddr, 0, iStatus); |
|
151 CleanupStack::PopAndDestroy(2); //addr, msg |
|
152 iState = ESmsRecipientSendSendingMessage; |
|
153 SetActive(); |
|
154 } |
|
155 |
|
156 void CWapRecipientSend::DoCancelSendingMessage() |
|
157 { |
|
158 SMSSLOG(FLogFormat(_L8("CWapRecipientSend::DoCancelSendingMessage() while sending msg %d"), iEntry.Id())); |
|
159 iSocket.CancelSend(); |
|
160 } |
|
161 |
|
162 CWapRecipientSend::~CWapRecipientSend() |
|
163 { |
|
164 Cancel(); |
|
165 delete iMessage8; |
|
166 } |
|