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: CXcapDeletion |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "XcapCache.h" |
|
23 #include "XcapProtocol.h" |
|
24 #include "XcapDeletion.h" |
|
25 #include "XcapAppUsage.h" |
|
26 #include "XcapDocument.h" |
|
27 #include "XcapUriParser.h" |
|
28 #include "XdmXmlParser.h" |
|
29 #include "XcapDocumentNode.h" |
|
30 #include "XcapHttpTransport.h" |
|
31 #include "XcapHttpOperation.h" |
|
32 #include "XcapHttpReqDelete.h" |
|
33 #include "XcapOperationFactory.h" |
|
34 |
|
35 // ================= MEMBER FUNCTIONS ======================= |
|
36 |
|
37 // --------------------------------------------------------- |
|
38 // CXcapDeletion::CXcapDeletion |
|
39 // |
|
40 // --------------------------------------------------------- |
|
41 // |
|
42 CXcapDeletion::CXcapDeletion( CXcapDocument& aParentDoc, |
|
43 CXcapDocumentNode* aDocumentSubset, |
|
44 CXcapOperationFactory& aOperationFactory ) : |
|
45 CXcapHttpOperation( aParentDoc, aDocumentSubset, aOperationFactory ), |
|
46 iOperationType( iDocumentSubset == NULL ? |
|
47 EXdmDocument : EXdmPartialDocument ) |
|
48 { |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------- |
|
52 // CXcapDeletion::NewL |
|
53 // |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 CXcapDeletion* CXcapDeletion::NewL( CXcapDocument& aParentDoc, |
|
57 CXcapDocumentNode* aDocumentSubset, |
|
58 CXcapOperationFactory& aOperationFactory ) |
|
59 { |
|
60 CXcapDeletion* self = new ( ELeave ) CXcapDeletion( aParentDoc, aDocumentSubset, aOperationFactory ); |
|
61 CleanupStack::PushL( self ); |
|
62 self->BaseConstructL(); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CXcapDeletion::ConstructL |
|
70 // |
|
71 // --------------------------------------------------------- |
|
72 // |
|
73 void CXcapDeletion::ConstructL() |
|
74 { |
|
75 CXcapHttpReqDelete* request = Transport().DeleteL( iTargetDoc.Name() ); |
|
76 CleanupStack::PushL( request ); |
|
77 User::LeaveIfError( iRequestQueue.Append( request ) ); |
|
78 request->SetExpiryTimeL( NULL, KDefaultHttpRequestTimeout * 1000000 ); |
|
79 CleanupStack::Pop(); //request |
|
80 if( iOperationType != EXdmDocument && iDocumentSubset != NULL ) |
|
81 { |
|
82 iUriParser->SetDocumentSubset( iDocumentSubset ); |
|
83 //Add namespace mappings |
|
84 User::LeaveIfError( iTargetDoc.ApplicationUsage().Validate( |
|
85 *iDocumentSubset, iUriParser, ETrue ) ); |
|
86 } |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------- |
|
90 // CXcapDeletion::ExecuteL |
|
91 // |
|
92 // --------------------------------------------------------- |
|
93 // |
|
94 void CXcapDeletion::ExecuteL() |
|
95 { |
|
96 #ifdef _DEBUG |
|
97 iOperationFactory.WriteToLog( _L8( "CXcapDeletion::ExecuteL()" ) ); |
|
98 #endif |
|
99 TPtrC8 eTag = iTargetDoc.ETag(); |
|
100 if( eTag.Length() > 0 ) |
|
101 iActiveRequest->SetHeaderL( KHttpHeaderIfMatch, eTag ); |
|
102 TRAPD( error, iUriParser->ParseL( iActiveRequest->RequestUriL() ) ); |
|
103 if( error == KErrNone ) |
|
104 { |
|
105 TPtrC8 uri = iUriParser->DesC8(); |
|
106 #ifdef _DEBUG |
|
107 iOperationFactory.WriteToLog( _L8( " New URI: %S" ), &uri ); |
|
108 #endif |
|
109 HBufC8* escape = CXcapHttpOperation::EscapeLC( uri ); |
|
110 iActiveRequest->UpdateRequestUriL( escape->Des() ); |
|
111 CleanupStack::PopAndDestroy(); //escape |
|
112 } |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------- |
|
116 // CXcapDeletion::OperationCompleteL |
|
117 // |
|
118 // --------------------------------------------------------- |
|
119 // |
|
120 void CXcapDeletion::OperationCompleteL() |
|
121 { |
|
122 #ifdef _DEBUG |
|
123 iOperationFactory.WriteToLog( _L8( "CXcapDeletion::OperationCompleteL()" ) ); |
|
124 #endif |
|
125 switch( iRequestData->iHttpStatus ) |
|
126 { |
|
127 case 200: //Document was deleted |
|
128 { |
|
129 #ifdef _DEBUG |
|
130 iOperationFactory.WriteToLog( _L8( " Status 200 - Document deleted" ) ); |
|
131 #endif |
|
132 iOperationType == EXdmDocument ? |
|
133 HandleDocDeletion() : |
|
134 HandlePartialDeletion(); |
|
135 iCompleted = ETrue; |
|
136 } |
|
137 break; |
|
138 case 404: //Document was not found |
|
139 { |
|
140 #ifdef _DEBUG |
|
141 iOperationFactory.WriteToLog( _L8( " Status 404 - Document not found" ) ); |
|
142 #endif |
|
143 iCompleted = ETrue; |
|
144 iResult = KErrNotFound; |
|
145 } |
|
146 break; |
|
147 default: |
|
148 #ifdef _DEBUG |
|
149 iOperationFactory.WriteToLog( _L8( " Default case - Status: %d" ), |
|
150 iRequestData->iHttpStatus ); |
|
151 #endif |
|
152 iCompleted = ETrue; |
|
153 break; |
|
154 } |
|
155 iResult = ReinterpretStatus( iRequestData->iHttpStatus ); |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------- |
|
159 // CXcapDeletion::HandleDocDeletion |
|
160 // |
|
161 // --------------------------------------------------------- |
|
162 // |
|
163 void CXcapDeletion::HandleDocDeletion() |
|
164 { |
|
165 #ifdef _DEBUG |
|
166 iOperationFactory.WriteToLog( _L8( "CXcapDeletion::HandleDocDeletion()" ) ); |
|
167 #endif |
|
168 TPtrC name = iTargetDoc.Name(); |
|
169 TPtrC8 root = Transport().RootUri(); |
|
170 RXcapCache* cache = iTargetDoc.Protocol().Cache(); |
|
171 if( cache != NULL ) |
|
172 { |
|
173 TInt error = cache->Delete( name, root ); |
|
174 #ifdef _DEBUG |
|
175 iOperationFactory.WriteToLog( _L8( " Document deleted from the cache" ) ); |
|
176 #endif |
|
177 } |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------- |
|
181 // CXcapDeletion::HandlePartialDeletion |
|
182 // |
|
183 // --------------------------------------------------------- |
|
184 // |
|
185 void CXcapDeletion::HandlePartialDeletion() |
|
186 { |
|
187 #ifdef _DEBUG |
|
188 iOperationFactory.WriteToLog( _L8( "CXcapDeletion::HandlePartialDeletion()" ) ); |
|
189 #endif |
|
190 TPtrC name = iTargetDoc.Name(); |
|
191 TPtrC8 root = Transport().RootUri(); |
|
192 iTargetDoc.RemoveFromModelL( iDocumentSubset ); |
|
193 TPtrC8 eTag = Descriptor( iRequestData->iETag ); |
|
194 RXcapCache* cache = iTargetDoc.Protocol().Cache(); |
|
195 if( cache != NULL ) |
|
196 { |
|
197 HBufC8* newDoc = iXmlParser->FormatToXmlLC( ETrue, &iTargetDoc, iTargetDoc.DocumentRoot() ); |
|
198 cache->Store( eTag, name, root, newDoc->Des() ); |
|
199 CleanupStack::PopAndDestroy(); //newDoc |
|
200 } |
|
201 iTargetDoc.SetETag( eTag ); |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------- |
|
205 // CXcapDeletion::OperationFailedL |
|
206 // |
|
207 // --------------------------------------------------------- |
|
208 // |
|
209 void CXcapDeletion::OperationFailedL() |
|
210 { |
|
211 #ifdef _DEBUG |
|
212 iOperationFactory.WriteToLog( _L8( "CXcapDeletion::OperationFailedL() - Error: %d" ), |
|
213 iStatus.Int() ); |
|
214 #endif |
|
215 if( iStatus.Int() >= KErrNone ) |
|
216 { |
|
217 TInt status = iActiveRequest->ResponseData()->iHttpStatus; |
|
218 TInt completion = iActiveRequest->ResponseData()->iCompletion; |
|
219 iResult = status < KErrNone || completion < KErrNone ? status : ReinterpretStatus( status ); |
|
220 } |
|
221 else iResult = iStatus.Int(); |
|
222 iCompleted = ETrue; |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // CXcapDeletion::Result |
|
227 // |
|
228 // --------------------------------------------------------- |
|
229 // |
|
230 TBool CXcapDeletion::Result() const |
|
231 { |
|
232 return ETrue; |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------- |
|
236 // CXcapDeletion::~CXcapDeletion |
|
237 // |
|
238 // --------------------------------------------------------- |
|
239 // |
|
240 CXcapDeletion::~CXcapDeletion() |
|
241 { |
|
242 #ifdef _DEBUG |
|
243 iOperationFactory.WriteToLog( _L8( "CXcapDeletion::~CXcapDeletion()" ) ); |
|
244 #endif |
|
245 } |
|
246 |
|
247 // End of File |
|
248 |
|