|
1 /* |
|
2 * Copyright (c) 2002-2006 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: Call back implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <utf.h> |
|
20 |
|
21 #include "dmadcallbackc.h" |
|
22 #include "dmadutil.h" |
|
23 #include "vpnlogger.h" |
|
24 |
|
25 #if defined(_DEBUG) |
|
26 _LIT(KDmAdLogFolder,"vpn"); |
|
27 _LIT(KDmAdLogFile,"dmadengine.log"); |
|
28 #endif |
|
29 |
|
30 |
|
31 DMAD_EXPORT_C CDmAdCallBack* CDmAdCallBack::NewL(MSmlDmCallback* aCallBack, const TDesC8& aSomeOwnUri) |
|
32 { |
|
33 |
|
34 //Is first method called from the dmadengine |
|
35 //This why the logging is initiated here. |
|
36 INITIALIZE_DEBUG_LOG_L(KDmAdLogFolder, KDmAdLogFile); |
|
37 DEBUG_LOG1(_L8("LOGGING INITIALIZED for %S"), &aSomeOwnUri); |
|
38 |
|
39 CDmAdCallBack* self = NewLC(aCallBack, aSomeOwnUri); |
|
40 CleanupStack::Pop(); // self |
|
41 return self; |
|
42 } |
|
43 |
|
44 DMAD_EXPORT_C CDmAdCallBack* CDmAdCallBack::NewLC(MSmlDmCallback* aCallBack, const TDesC8& aSomeOwnUri) |
|
45 { |
|
46 CDmAdCallBack* self = new (ELeave) CDmAdCallBack(aCallBack); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(aSomeOwnUri); |
|
49 return self; |
|
50 } |
|
51 |
|
52 void CDmAdCallBack::ConstructL(const TDesC8& aSomeOwnUri) |
|
53 { |
|
54 TRACE("CDmAdCallBack::ConstructL"); |
|
55 iSomeOwnUri = aSomeOwnUri.AllocL(); |
|
56 } |
|
57 |
|
58 CDmAdCallBack::CDmAdCallBack(MSmlDmCallback* aCallBack) : iCallBack(aCallBack) |
|
59 { |
|
60 } |
|
61 |
|
62 DMAD_EXPORT_C CDmAdCallBack::~CDmAdCallBack() |
|
63 { |
|
64 |
|
65 DEBUG_LOG1(_L8("FINALIZING LOGGING %S"), iSomeOwnUri); |
|
66 FINALIZE_DEBUG_LOG; |
|
67 |
|
68 delete iSomeOwnUri; |
|
69 } |
|
70 |
|
71 DMAD_EXPORT_C void CDmAdCallBack::SetResultsL(TInt aResultsRef, CBufBase& aObject, const TDesC8& aType) |
|
72 { |
|
73 TRACE("CDmAdCallBack::SetResultsL"); |
|
74 |
|
75 DEBUG_LOG1(_L("rref = %d"), aResultsRef); |
|
76 DEBUG_LOG1(_L("lth = %d"), aObject.Ptr(0).Length()); |
|
77 |
|
78 DEBUG_LOG_HEX(aObject.Ptr(0)); |
|
79 |
|
80 iCallBack->SetResultsL(aResultsRef, aObject, aType); |
|
81 } |
|
82 |
|
83 DMAD_EXPORT_C void CDmAdCallBack::SetStatusL(TInt aStatusRef, TInt aError) |
|
84 { |
|
85 TRACE("CDmAdCallBack::SetStatusL"); |
|
86 |
|
87 DEBUG_LOG1(_L("rref = %d"), aStatusRef); |
|
88 DEBUG_LOG1(_L("status = %d"), aError); |
|
89 |
|
90 iCallBack->SetStatusL(aStatusRef, TDmAdUtil::MapStatusCode(aError)); |
|
91 } |
|
92 |
|
93 DMAD_EXPORT_C void CDmAdCallBack::SetMappingL(const TDesC8& aUri, const TDesC8& aLuid) |
|
94 { |
|
95 TRACE("CDmAdCallBack::SetMappingL"); |
|
96 |
|
97 DEBUG_LOG1(_L8("aUri %S"), &aUri); |
|
98 DEBUG_LOG(_L8("aLuid:")); |
|
99 DEBUG_LOG_HEX(aLuid); |
|
100 |
|
101 iCallBack->SetMappingL(aUri, aLuid); |
|
102 } |
|
103 |
|
104 DMAD_EXPORT_C void CDmAdCallBack::FetchLinkL(const TDesC8& aUri, CBufBase& aData, MSmlDmAdapter::TError& aStatus) |
|
105 { |
|
106 TRACE("CDmAdCallBack::FetchLinkL"); |
|
107 |
|
108 aData.Reset(); |
|
109 iCallBack->FetchLinkL(aUri, aData, aStatus); |
|
110 |
|
111 DEBUG_LOG1(_L("FetchLinkL status %d"), aStatus); |
|
112 DEBUG_LOG1(_L("Data Length %d"), aData.Ptr(0).Length()); |
|
113 DEBUG_LOG1(_L8("aUri = %S"), &aUri); |
|
114 DEBUG_LOG_HEX(aData.Ptr(0)); |
|
115 |
|
116 //Some adapters are a bit sloppy and returns a malformed URI, which |
|
117 //ends with / character. This causes problems in our code. |
|
118 //So if the last character is /, we strip it off. |
|
119 |
|
120 TUint dataSize = aData.Size(); |
|
121 if (dataSize > 0) |
|
122 { |
|
123 TUint lastPosition = dataSize - 1; |
|
124 TUint8 lastCharacter; |
|
125 aData.Read(lastPosition, &lastCharacter, 1); |
|
126 |
|
127 if (lastCharacter == '/') |
|
128 { |
|
129 DEBUG_LOG(_L("WARNING: last character is /. Stripping it off...")); |
|
130 aData.ResizeL(lastPosition); |
|
131 } |
|
132 |
|
133 } |
|
134 } |
|
135 |
|
136 DMAD_EXPORT_C HBufC8* CDmAdCallBack::GetLuidAllocL(const TDesC8& aUri) |
|
137 { |
|
138 TRACE("CDmAdCallBack::GetLuidAllocL"); |
|
139 |
|
140 HBufC8* luid = iCallBack->GetLuidAllocL(aUri); |
|
141 |
|
142 DEBUG_LOG1(_L8("aUri %S"), &aUri); |
|
143 DEBUG_LOG(_L("luid:")); |
|
144 DEBUG_LOG_HEX(*luid); |
|
145 |
|
146 #if 1 // restore adapter index (fixes agent) |
|
147 |
|
148 HBufC8* tempLuid = iCallBack->GetLuidAllocL(*iSomeOwnUri); |
|
149 DEBUG_LOG1(_L8("iCallBack->GetLuidAllocL(%S) called"), iSomeOwnUri); |
|
150 delete tempLuid; |
|
151 #endif |
|
152 |
|
153 return luid; |
|
154 } |
|
155 |
|
156 DMAD_EXPORT_C HBufC8* CDmAdCallBack::FindChildUriL(const TDesC8& aParentUri, const TDesC8& aChildLuid) |
|
157 { |
|
158 TRACE("CDmAdCallBack::FindChildUriL"); |
|
159 |
|
160 DEBUG_LOG1(_L8("aParentUri = %S"), &aParentUri); |
|
161 DEBUG_LOG(_L8("aChildLuid:")); |
|
162 DEBUG_LOG_HEX(aChildLuid); |
|
163 |
|
164 CBufBase* childUriList = CBufFlat::NewL(16); |
|
165 CleanupStack::PushL(childUriList); |
|
166 MSmlDmAdapter::TError status; |
|
167 FetchLinkL(aParentUri, *childUriList, status); |
|
168 if (status == MSmlDmAdapter::ENotFound) |
|
169 { |
|
170 DEBUG_LOG(_L("Node not found")); |
|
171 CleanupStack::PopAndDestroy(); // childUriList |
|
172 return 0; |
|
173 } |
|
174 else if (status != MSmlDmAdapter::EOk) |
|
175 { |
|
176 DEBUG_LOG1(_L("Operation failed with %d"), status); |
|
177 User::Leave(KErrGeneral); |
|
178 } |
|
179 |
|
180 CArrayFix<TPtrC8>* uriSegList; |
|
181 TDmAdUtil::ParseUriLC(childUriList->Ptr(0), uriSegList); |
|
182 |
|
183 TBool found = EFalse; |
|
184 HBufC8* uri = 0; |
|
185 for (TInt i=0; i<uriSegList->Count(); ++i) |
|
186 { |
|
187 uri = TDmAdUtil::BuildUriLC(aParentUri, uriSegList->At(i)); |
|
188 HBufC8* luid = GetLuidAllocL(*uri); |
|
189 if (luid->Compare(aChildLuid) == 0) |
|
190 { |
|
191 found = ETrue; |
|
192 delete luid; |
|
193 break; |
|
194 } |
|
195 CleanupStack::PopAndDestroy(); // uri |
|
196 delete luid; |
|
197 } |
|
198 |
|
199 if (found) |
|
200 { |
|
201 CleanupStack::Pop(); // uri |
|
202 } |
|
203 |
|
204 CleanupStack::PopAndDestroy(2); //uriSegList, childUriList |
|
205 |
|
206 if (found) |
|
207 { |
|
208 DEBUG_LOG1(_L8("Found uri %S"), uri); |
|
209 return uri; |
|
210 } |
|
211 else |
|
212 { |
|
213 DEBUG_LOG(_L("Uri not found")); |
|
214 return 0; |
|
215 } |
|
216 } |