1 /* |
|
2 * Copyright (c) 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: CXcapReplacement |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "XcapAppUsage.h" |
|
23 #include "XcapDocument.h" |
|
24 #include "XcapUriParser.h" |
|
25 #include "XdmXmlParser.h" |
|
26 #include "XcapHttpReqPut.h" |
|
27 #include "XcapReplacement.h" |
|
28 #include "XcapHttpReqDelete.h" |
|
29 #include "XcapHttpTransport.h" |
|
30 #include "XcapHttpOperation.h" |
|
31 #include "XdmNodeAttribute.h" |
|
32 #include "XcapEngineDefines.h" |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // C++ constructor can NOT contain any code, that might leave. |
|
36 // |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 CXcapReplacement::CXcapReplacement( CXcapDocument& aParentDoc, |
|
40 CXcapDocumentNode* aOldNode, |
|
41 CXcapDocumentNode* aNewNode, |
|
42 CXcapOperationFactory& aOperationFactory ) : |
|
43 CXcapHttpOperation( aParentDoc, aOldNode, aOperationFactory ), |
|
44 iNewNode( ( CXcapDocumentNode* )aNewNode ), |
|
45 iOperationType( aOldNode == NULL ? |
|
46 EXdmDocument : EXdmPartialDocument ) |
|
47 |
|
48 { |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------- |
|
52 // Two-phased constructor. |
|
53 // |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 CXcapReplacement* CXcapReplacement::NewL( CXcapDocument& aParentDoc, |
|
57 CXcapDocumentNode* aOldNode, |
|
58 CXcapDocumentNode* aNewNode, |
|
59 CXcapOperationFactory& aOperationFactory ) |
|
60 { |
|
61 CXcapReplacement* self = new ( ELeave ) CXcapReplacement( aParentDoc, aOldNode, aNewNode, aOperationFactory ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->BaseConstructL(); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // CXcapReplacement::ConstructL |
|
71 // |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 void CXcapReplacement::ConstructL() |
|
75 { |
|
76 CXcapHttpReqPut* request = Transport().PutL( iTargetDoc.Name() ); |
|
77 CleanupStack::PushL( request ); |
|
78 User::LeaveIfError( iRequestQueue.Append( request ) ); |
|
79 request->SetExpiryTimeL( NULL, KDefaultHttpRequestTimeout * 1000000 ); |
|
80 CleanupStack::Pop(); //request |
|
81 //If they point to the same node, we're dealing with a complete document |
|
82 if( iDocumentSubset != NULL && iTargetDoc.DocumentRoot() != iDocumentSubset ) |
|
83 iUriParser->SetDocumentSubset( iDocumentSubset ); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------- |
|
87 // CXcapReplacement::FormatModRequestL |
|
88 // |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 TInt CXcapReplacement::FormatModRequestL( const CXcapDocumentNode* aDocumentNode ) |
|
92 { |
|
93 #ifdef _DEBUG |
|
94 iOperationFactory.WriteToLog( _L8( "CXcapReplacement::FormatModRequestL()" ) ); |
|
95 iOperationFactory.WriteToLog( _L8( " Operation type: %d" ), iOperationType ); |
|
96 iOperationFactory.WriteToLog( _L8( " Document subset: %x" ), iDocumentSubset ); |
|
97 #endif |
|
98 return CXcapHttpOperation::FormatModRequestL( aDocumentNode ); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------- |
|
102 // CXcapReplacement::ExecuteL |
|
103 // |
|
104 // --------------------------------------------------------- |
|
105 // |
|
106 void CXcapReplacement::ExecuteL() |
|
107 { |
|
108 #ifdef _DEBUG |
|
109 iOperationFactory.WriteToLog( _L8( "CXcapReplacement::ExecuteL()" ) ); |
|
110 #endif |
|
111 User::LeaveIfError( FormatModRequestL( iNewNode ) ); |
|
112 if( iOperationType == EXdmPartialDocument ) |
|
113 { |
|
114 TPtrC8 eTag = iTargetDoc.ETag(); |
|
115 if( eTag.Length() > 0 ) |
|
116 iActiveRequest->SetHeaderL( KHttpHeaderIfMatch, eTag ); |
|
117 //If they match semantically, there's no need for DELETE operation |
|
118 if( iDocumentSubset->Match( *iNewNode ) ) |
|
119 iOperationPhase = EHttpPutting; |
|
120 else |
|
121 { |
|
122 CXcapHttpReqDelete* request = Transport().DeleteL( iTargetDoc.Name() ); |
|
123 CleanupStack::PushL( request ); |
|
124 User::LeaveIfError( iRequestQueue.Insert( request, 0 ) ); |
|
125 CleanupStack::Pop(); //request |
|
126 if( eTag.Length() > 0 ) |
|
127 request->SetHeaderL( KHttpHeaderIfMatch, eTag ); |
|
128 request->SetHeaderL( KHttpHeaderAccept, _L8( "application/xcap-diff+xml" ) ); |
|
129 iActiveRequest = request; |
|
130 iOperationPhase = EHttpDeleting; |
|
131 } |
|
132 TRAPD( error, iUriParser->ParseL( iActiveRequest->RequestUriL() ) ); |
|
133 if( error == KErrNone ) |
|
134 { |
|
135 TPtrC8 uri = iUriParser->DesC8(); |
|
136 #ifdef _DEBUG |
|
137 iOperationFactory.WriteToLog( _L8( " New URI: %S" ), &uri ); |
|
138 #endif |
|
139 HBufC8* escape = CXcapHttpOperation::EscapeLC( uri ); |
|
140 iActiveRequest->UpdateRequestUriL( escape->Des() ); |
|
141 CleanupStack::PopAndDestroy(); //escape |
|
142 } |
|
143 } |
|
144 else |
|
145 { |
|
146 |
|
147 } |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------- |
|
151 // CXcapReplacement::OperationCompleteL |
|
152 // |
|
153 // --------------------------------------------------------- |
|
154 // |
|
155 void CXcapReplacement::OperationCompleteL() |
|
156 { |
|
157 #ifdef _DEBUG |
|
158 iOperationFactory.WriteToLog( |
|
159 _L8( "CXcapReplacement::OperationCompleteL() - Phase: %d" ), iOperationPhase ); |
|
160 #endif |
|
161 switch( iOperationPhase ) |
|
162 { |
|
163 case EHttpDeleting: |
|
164 break; |
|
165 case EHttpPutting: |
|
166 break; |
|
167 default: |
|
168 iCompleted = ETrue; |
|
169 break; |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CXcapReplacement::OperationFailedL |
|
175 // |
|
176 // --------------------------------------------------------- |
|
177 // |
|
178 void CXcapReplacement::OperationFailedL() |
|
179 { |
|
180 #ifdef _DEBUG |
|
181 iOperationFactory.WriteToLog( _L8( "CXcapReplacement::OperationFailedL() - Error: %d" ), |
|
182 iStatus.Int() ); |
|
183 TInt httpStatus = iRequestData == NULL ? KErrUnknown : |
|
184 iRequestData->iHttpStatus; |
|
185 #endif |
|
186 |
|
187 switch( iOperationPhase ) |
|
188 { |
|
189 case EHttpDeleting: |
|
190 #ifdef _DEBUG |
|
191 iOperationFactory.WriteToLog( |
|
192 _L8( "DELETE failed - Error: %d Status: %d" ), iStatus.Int(), httpStatus ); |
|
193 #endif |
|
194 break; |
|
195 case EHttpPutting: |
|
196 #ifdef _DEBUG |
|
197 iOperationFactory.WriteToLog( |
|
198 _L8( "PUT failed - Error: %d Status: %d" ), iStatus.Int(), httpStatus ); |
|
199 #endif |
|
200 break; |
|
201 default: |
|
202 break; |
|
203 } |
|
204 iResult = iStatus.Int(); |
|
205 iCompleted = ETrue; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------- |
|
209 // CXcapReplacement::Result |
|
210 // |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 TBool CXcapReplacement::Result() const |
|
214 { |
|
215 return ETrue; |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------- |
|
219 // CXcapReplacement::~CXcapReplacement |
|
220 // |
|
221 // --------------------------------------------------------- |
|
222 // |
|
223 CXcapReplacement::~CXcapReplacement() |
|
224 { |
|
225 #ifdef _DEBUG |
|
226 iOperationFactory.WriteToLog( _L8( "CXcapReplacement::~CXcapReplacement()" ) ); |
|
227 #endif |
|
228 } |
|
229 |
|
230 // End of File |
|
231 |
|