|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include <badesca.h> |
|
27 #include <SenXmlReader.h> |
|
28 #include <s32mem.h> |
|
29 #include <utf.h> |
|
30 |
|
31 #include "SenWsSecurityHeader.h" |
|
32 #include "SenSoapMessage.h" |
|
33 |
|
34 |
|
35 EXPORT_C CSenSoapMessage* CSenSoapMessage::NewL() |
|
36 { |
|
37 CSenSoapMessage* pNew = new (ELeave) CSenSoapMessage; |
|
38 CleanupStack::PushL(pNew); |
|
39 pNew->BaseConstructL(); |
|
40 CleanupStack::Pop(); // pNew; |
|
41 return pNew; |
|
42 } |
|
43 |
|
44 EXPORT_C CSenSoapMessage* CSenSoapMessage::NewL(TSOAPVersion aVersion) |
|
45 { |
|
46 CSenSoapMessage* pNew = new (ELeave) CSenSoapMessage; |
|
47 CleanupStack::PushL(pNew); |
|
48 pNew->BaseConstructL(aVersion); |
|
49 CleanupStack::Pop(); // pNew; |
|
50 return pNew; |
|
51 } |
|
52 |
|
53 EXPORT_C CSenSoapMessage* CSenSoapMessage::NewL(TSOAPVersion aVersion, const TDesC8& aSecurityNs) |
|
54 { |
|
55 CSenSoapMessage* pNew = new (ELeave) CSenSoapMessage; |
|
56 CleanupStack::PushL(pNew); |
|
57 pNew->BaseConstructL(aVersion, aSecurityNs); |
|
58 CleanupStack::Pop(); // pNew; |
|
59 return pNew; |
|
60 } |
|
61 |
|
62 EXPORT_C CSenSoapMessage::~CSenSoapMessage() |
|
63 { |
|
64 if (ipSecurityHeader) |
|
65 { |
|
66 // We do not own the element, so remove it from the fragment. |
|
67 ipSecurityHeader->ExtractElement(); |
|
68 delete ipSecurityHeader; |
|
69 } |
|
70 } |
|
71 EXPORT_C CSenSoapMessage::CSenSoapMessage() |
|
72 : ipSecurityHeader(NULL) |
|
73 { |
|
74 } |
|
75 |
|
76 EXPORT_C void CSenSoapMessage::BaseConstructL() |
|
77 { |
|
78 CSenSoapEnvelope::BaseConstructL(); |
|
79 } |
|
80 EXPORT_C void CSenSoapMessage::BaseConstructL(TSOAPVersion aVersion) |
|
81 { |
|
82 CSenSoapEnvelope::BaseConstructL(aVersion); |
|
83 } |
|
84 |
|
85 EXPORT_C void CSenSoapMessage::BaseConstructL(TSOAPVersion aVersion, const TDesC8& aSecurityNs) |
|
86 { |
|
87 BaseConstructL(aVersion); |
|
88 if ((aSecurityNs == KSecuritySchemeXmlNs) ||(aSecurityNs == KSecurityXmlNs)) |
|
89 { |
|
90 ipSecurityHeader = CSenWsSecurityHeader::NewL(KNullDesC8, aSecurityNs); |
|
91 CSenElement& soapHeader = HeaderL(); |
|
92 soapHeader.AddElementL(ipSecurityHeader->AsElement()); |
|
93 } |
|
94 } |
|
95 |
|
96 EXPORT_C void CSenSoapMessage::SetSecurityHeaderL(const TDesC8& aData) |
|
97 { |
|
98 CSenWsSecurityHeader* pTemp = NULL; |
|
99 |
|
100 if(aData==KNullDesC8) |
|
101 { |
|
102 // we don't have credential |
|
103 pTemp = NewSecurityHeaderLC(NULL); |
|
104 } |
|
105 else |
|
106 { |
|
107 // there is a credential to add.. |
|
108 pTemp = NewSecurityHeaderLC(&aData); |
|
109 } |
|
110 |
|
111 delete HeaderL().RemoveElement(pTemp->XmlNs(), KSecurityName); |
|
112 if (ipSecurityHeader) |
|
113 { |
|
114 // We do not own the element, so remove it from the fragment. |
|
115 ipSecurityHeader->ExtractElement(); |
|
116 delete ipSecurityHeader; |
|
117 ipSecurityHeader = NULL; |
|
118 } |
|
119 ipSecurityHeader = pTemp; |
|
120 CleanupStack::Pop(); // pTemp |
|
121 this->AddHeaderL(ipSecurityHeader->AsElement()); |
|
122 } |
|
123 |
|
124 EXPORT_C void CSenSoapMessage::ParseHeaderL( |
|
125 const TDesC8& aNsUri, |
|
126 const TDesC8& aLocalName, |
|
127 const TDesC8& aQName, |
|
128 const RAttributeArray& aAttributes |
|
129 ) |
|
130 { |
|
131 CSenWsSecurityHeader* pTemp = NewSecurityHeaderLC(); |
|
132 |
|
133 if ((pTemp->XmlNs() == aNsUri) && (KSecurityName() == aLocalName)) |
|
134 { |
|
135 // Remove existing <Security> header |
|
136 delete HeaderL().RemoveElement(pTemp->XmlNs(), KSecurityName); |
|
137 if (ipSecurityHeader) |
|
138 { |
|
139 // We do not own the element, so remove it from the fragment. |
|
140 ipSecurityHeader->ExtractElement(); |
|
141 delete ipSecurityHeader; |
|
142 ipSecurityHeader = NULL; |
|
143 } |
|
144 ipSecurityHeader = pTemp; |
|
145 CleanupStack::Pop(); // pTemp |
|
146 DelegateParsingL(*ipSecurityHeader); |
|
147 this->AddHeaderL(ipSecurityHeader->AsElement()); |
|
148 } |
|
149 else |
|
150 { |
|
151 CleanupStack::PopAndDestroy(); // pTemp |
|
152 CSenSoapEnvelope::ParseHeaderL( |
|
153 aNsUri, |
|
154 aLocalName, |
|
155 aQName, |
|
156 aAttributes); |
|
157 } |
|
158 } |
|
159 |
|
160 EXPORT_C TInt CSenSoapMessage::AddSecurityTokenL(const TDesC8& aNewToken) |
|
161 { |
|
162 CSenElement& soapHeader = HeaderL(); |
|
163 |
|
164 CSenWsSecurityHeader* pHeader = NewSecurityHeaderLC(); |
|
165 |
|
166 CSenElement* wsSecurityHeader = NULL; |
|
167 wsSecurityHeader = soapHeader.Element(pHeader->XmlNs(), KSecurityName); |
|
168 |
|
169 if(!wsSecurityHeader) |
|
170 { |
|
171 wsSecurityHeader = pHeader->ExtractElement(); // Let's take ownership |
|
172 soapHeader.AddElementL(*wsSecurityHeader); // takes ownership |
|
173 } |
|
174 CleanupStack::PopAndDestroy(); // pHeader // safe to delete |
|
175 |
|
176 HBufC8* pContent = HBufC8::NewLC(wsSecurityHeader->Content().Length() + |
|
177 aNewToken.Length()); |
|
178 |
|
179 TPtr8 content = pContent->Des(); |
|
180 content.Append(wsSecurityHeader->Content()); |
|
181 content.Append(aNewToken); |
|
182 wsSecurityHeader->SetContentL(content); |
|
183 CleanupStack::PopAndDestroy(); // pContent |
|
184 |
|
185 return KErrNone; |
|
186 } |
|
187 |
|
188 EXPORT_C CSenWsSecurityHeader* CSenSoapMessage::NewSecurityHeaderLC( |
|
189 const TDesC8* aData) |
|
190 { |
|
191 CSenWsSecurityHeader* pNew = NULL; |
|
192 if(aData) |
|
193 { |
|
194 if (ipSecurityHeader) |
|
195 { |
|
196 pNew = CSenWsSecurityHeader::NewL(*aData, ipSecurityHeader->XmlNs()); |
|
197 } |
|
198 else |
|
199 { |
|
200 pNew = CSenWsSecurityHeader::NewL(*aData); |
|
201 } |
|
202 |
|
203 } |
|
204 else |
|
205 { |
|
206 if (ipSecurityHeader) |
|
207 { |
|
208 pNew = CSenWsSecurityHeader::NewL(KNullDesC8, ipSecurityHeader->XmlNs()); |
|
209 } |
|
210 else |
|
211 { |
|
212 pNew = CSenWsSecurityHeader::NewL(); |
|
213 } |
|
214 } |
|
215 CleanupStack::PushL(pNew); |
|
216 return pNew; |
|
217 } |
|
218 |
|
219 // End of File |