|
1 // Copyright (c) 2008-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 "cupnpservicecomposer.h" |
|
17 #include "upnpdescriptionschema.h" |
|
18 #include "inetprottextutils.h" |
|
19 #include "tattributeiter.h" |
|
20 #include "cattribute.h" |
|
21 |
|
22 _LIT8(KBeginOpen,"\n<"); |
|
23 _LIT8(KBeginClose,"</"); |
|
24 _LIT8(KEnd,">"); |
|
25 |
|
26 _LIT8(KStringXmlStart,"<?xml version=\"1.0\" encoding=\"utf-8\"?>"); |
|
27 |
|
28 _LIT8(KStringScpdStart,"\n<scpd xmlns=\"urn:schemas-upnp-org:service-1-0\">"); |
|
29 |
|
30 _LIT8(KStringStVarStart,"\n\t\t<stateVariable sendEvents=\""); |
|
31 _LIT8(KStringStVarStart1,"\">"); |
|
32 #define COMPOSE_BUFLENGTH 1024 |
|
33 |
|
34 void CUPnPServiceXmlComposer::AppendLiteralL(TInt aTag, RBuf8& aBuf, TInt& count, TBool aIsStart ) |
|
35 { |
|
36 |
|
37 RString str = iStringPool.String(aTag,UPNPDESCRIPTIONXMLTAGS::Table ); |
|
38 TInt litSize = str.DesC().Size(); |
|
39 |
|
40 if(aIsStart) |
|
41 { |
|
42 litSize+= KBeginOpen.iTypeLength + KEnd.iTypeLength; |
|
43 } |
|
44 else |
|
45 { |
|
46 litSize+= KBeginClose.iTypeLength + KEnd.iTypeLength; |
|
47 } |
|
48 |
|
49 if((count+litSize)>= aBuf.MaxSize()) |
|
50 { |
|
51 aBuf.ReAllocL(((aBuf.MaxSize()+COMPOSE_BUFLENGTH)<(aBuf.MaxSize()+litSize))?(aBuf.MaxSize()+litSize):(aBuf.MaxSize()+COMPOSE_BUFLENGTH)); |
|
52 } |
|
53 |
|
54 if(aIsStart) |
|
55 { |
|
56 aBuf.Append(KBeginOpen); |
|
57 } |
|
58 else |
|
59 { |
|
60 aBuf.Append(KBeginClose); |
|
61 } |
|
62 aBuf.Append(str.DesC()); |
|
63 aBuf.Append(KEnd); |
|
64 count+=litSize; |
|
65 } |
|
66 |
|
67 void CUPnPServiceXmlComposer::AppendLiteralL(const RString& aString, RBuf8& aBuf, TInt& count, TBool aIsStart ) |
|
68 { |
|
69 TInt litSize = aString.DesC().Size(); |
|
70 if(aIsStart) |
|
71 { |
|
72 litSize+= KBeginOpen.iTypeLength + KEnd.iTypeLength; |
|
73 } |
|
74 else |
|
75 { |
|
76 litSize+= KBeginClose.iTypeLength + KEnd.iTypeLength; |
|
77 } |
|
78 |
|
79 if((count+litSize)>= aBuf.MaxSize()) |
|
80 { |
|
81 aBuf.ReAllocL(((aBuf.MaxSize()+COMPOSE_BUFLENGTH)<(aBuf.MaxSize()+litSize))?(aBuf.MaxSize()+litSize):(aBuf.MaxSize()+COMPOSE_BUFLENGTH)); |
|
82 } |
|
83 |
|
84 if(aIsStart) |
|
85 { |
|
86 aBuf.Append(KBeginOpen); |
|
87 } |
|
88 else |
|
89 { |
|
90 aBuf.Append(KBeginClose); |
|
91 } |
|
92 aBuf.Append(aString.DesC()); |
|
93 aBuf.Append(KEnd); |
|
94 count+=litSize; |
|
95 } |
|
96 void CUPnPServiceXmlComposer::AppendLiteralL(const TDesC8& aLiteral, RBuf8& aBuf, TInt& count) |
|
97 { |
|
98 TInt litSize = aLiteral.Length(); |
|
99 |
|
100 if((count+litSize)>= aBuf.MaxSize()) |
|
101 { |
|
102 aBuf.ReAllocL(((aBuf.MaxSize()+COMPOSE_BUFLENGTH)<(aBuf.MaxSize()+litSize))?(aBuf.MaxSize()+litSize):(aBuf.MaxSize()+COMPOSE_BUFLENGTH)); |
|
103 } |
|
104 |
|
105 aBuf.Append(aLiteral); |
|
106 count+=litSize; |
|
107 } |
|
108 /** |
|
109 Allocates and constructs a CUPnPServiceXmlComposer object. |
|
110 Initialises all member data to their default values. |
|
111 */ |
|
112 CUPnPServiceXmlComposer* CUPnPServiceXmlComposer::NewL( const RStringPool& aStringPool ) |
|
113 { |
|
114 CUPnPServiceXmlComposer* self = new (ELeave) CUPnPServiceXmlComposer( aStringPool ); |
|
115 return self; |
|
116 } |
|
117 |
|
118 CUPnPServiceXmlComposer::CUPnPServiceXmlComposer( const RStringPool& aStringPool ):iStringPool ( aStringPool ) |
|
119 { |
|
120 iError = KErrNone; |
|
121 } |
|
122 /** |
|
123 Destructor |
|
124 */ |
|
125 CUPnPServiceXmlComposer::~CUPnPServiceXmlComposer() |
|
126 { |
|
127 } |
|
128 |
|
129 |
|
130 const TStringTable& CUPnPServiceXmlComposer::GetTable() |
|
131 { |
|
132 return UPNPDESCRIPTIONXMLTAGS::Table; |
|
133 } |
|
134 |
|
135 void CUPnPServiceXmlComposer::AppendActionL(const CUPnPAction* aUPnPAction, RBuf8 &aXmlData, TInt &count) |
|
136 { |
|
137 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EAction,aXmlData,count,ETrue); |
|
138 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EName,aXmlData,count,ETrue); |
|
139 AppendLiteralL(aUPnPAction->Property(iStringPool.String(UPNPDESCRIPTIONXMLTAGS::EName, GetTable())),aXmlData,count); |
|
140 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EName,aXmlData,count,EFalse); |
|
141 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EArgumentList,aXmlData,count,ETrue); |
|
142 |
|
143 for(TInt j =0;j< aUPnPAction->Count();j++ ) |
|
144 { |
|
145 CUPnPArgument *uPnPArgument = aUPnPAction->At(j); |
|
146 if (!uPnPArgument->Validate(iStringPool, GetTable())) |
|
147 User::Leave(KErrCorrupt); |
|
148 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EArgument,aXmlData,count,ETrue); |
|
149 TAttributeIter it(uPnPArgument); |
|
150 const CAttribute* nextParam = NULL; |
|
151 while (!it.AtEnd()) |
|
152 { |
|
153 nextParam = it(); |
|
154 AppendLiteralL(nextParam->AttributeName(),aXmlData,count,ETrue); |
|
155 AppendLiteralL(nextParam->AttributeValue(),aXmlData,count); |
|
156 AppendLiteralL(nextParam->AttributeName(),aXmlData,count,EFalse); |
|
157 ++it; |
|
158 } |
|
159 if ( uPnPArgument->RetVal() ) |
|
160 { |
|
161 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::ERetValue,aXmlData,count,ETrue); |
|
162 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::ERetValue,aXmlData,count,EFalse); |
|
163 } |
|
164 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EArgument,aXmlData,count,EFalse); |
|
165 } |
|
166 |
|
167 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EArgumentList,aXmlData,count,EFalse); |
|
168 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EAction,aXmlData,count,EFalse); |
|
169 } |
|
170 |
|
171 void CUPnPServiceXmlComposer::AppendStateVariableL(const CUPnPStateVariable* aUPnPStateVariable, RBuf8 &aXmlData, TInt &count) |
|
172 { |
|
173 |
|
174 AppendLiteralL(KStringStVarStart,aXmlData,count); |
|
175 AppendLiteralL(aUPnPStateVariable->Property(iStringPool.String(UPNPDESCRIPTIONXMLTAGS::ESendEvents, GetTable())),aXmlData,count); |
|
176 AppendLiteralL(KStringStVarStart1,aXmlData,count); |
|
177 |
|
178 TAttributeIter it(aUPnPStateVariable); |
|
179 const CAttribute* nextParam = NULL; |
|
180 while (!it.AtEnd()) |
|
181 { |
|
182 nextParam = it(); |
|
183 if ( nextParam->AttributeName() == iStringPool.String(UPNPDESCRIPTIONXMLTAGS::ESendEvents, GetTable())) |
|
184 { |
|
185 ++it; |
|
186 continue; |
|
187 } |
|
188 else |
|
189 { |
|
190 AppendLiteralL(nextParam->AttributeName(),aXmlData,count,ETrue); |
|
191 AppendLiteralL(nextParam->AttributeValue(),aXmlData,count); |
|
192 AppendLiteralL(nextParam->AttributeName(),aXmlData,count,EFalse); |
|
193 ++it; |
|
194 } |
|
195 } |
|
196 |
|
197 if(aUPnPStateVariable->AllowedValues()) |
|
198 { |
|
199 if(aUPnPStateVariable->AllowedValueType()) |
|
200 { |
|
201 const CUPnPArgValueList* aTempArgValueList = static_cast<const CUPnPArgValueList*>(aUPnPStateVariable->AllowedValues()); |
|
202 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EAllowedValueList,aXmlData,count,ETrue); |
|
203 for(TInt k = 0; k< aTempArgValueList->Count();k++) |
|
204 { |
|
205 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EAllowedValue,aXmlData,count,ETrue); |
|
206 AppendLiteralL(aTempArgValueList->At(k),aXmlData,count); |
|
207 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EAllowedValue,aXmlData,count,EFalse); |
|
208 } |
|
209 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EAllowedValueList,aXmlData,count,EFalse); |
|
210 } |
|
211 else |
|
212 { |
|
213 const CUPnPValueRange* aTempValueRange = static_cast<const CUPnPValueRange*>(aUPnPStateVariable->AllowedValues()); |
|
214 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EAllowedValueRange,aXmlData,count,ETrue); |
|
215 TAttributeIter it(aTempValueRange); |
|
216 const CAttribute* nextParam = NULL; |
|
217 while (!it.AtEnd()) |
|
218 { |
|
219 nextParam = it(); |
|
220 AppendLiteralL(nextParam->AttributeName(),aXmlData,count,ETrue); |
|
221 AppendLiteralL(nextParam->AttributeValue(),aXmlData,count); |
|
222 AppendLiteralL(nextParam->AttributeName(),aXmlData,count,EFalse); |
|
223 ++it; |
|
224 } |
|
225 |
|
226 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EAllowedValueRange,aXmlData,count,EFalse); |
|
227 } |
|
228 } |
|
229 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EStateVariable,aXmlData,count,EFalse); |
|
230 } |
|
231 |
|
232 |
|
233 void CUPnPServiceXmlComposer::ComposeServiceXmlL(const CUPnPServiceDescription *aServDescObj, RBuf8 &aXmlData) |
|
234 { |
|
235 RBuf unicode; |
|
236 TInt count = 0; |
|
237 |
|
238 |
|
239 if(!(aServDescObj->Validate(iStringPool, GetTable()))) |
|
240 User::Leave(KErrCorrupt); |
|
241 |
|
242 User::LeaveIfError(aXmlData.Create(COMPOSE_BUFLENGTH)); |
|
243 |
|
244 |
|
245 AppendLiteralL(KStringXmlStart,aXmlData,count); |
|
246 AppendLiteralL(KStringScpdStart,aXmlData,count); |
|
247 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::ESpecVersion,aXmlData,count,ETrue); |
|
248 |
|
249 HBufC8* versionMajor = NULL; |
|
250 HBufC8* versionMinor = NULL; |
|
251 InetProtTextUtils::ConvertIntToDescriptorL(aServDescObj->MajorNumber(), versionMajor); |
|
252 InetProtTextUtils::ConvertIntToDescriptorL(aServDescObj->MinorNumber(), versionMinor); |
|
253 CleanupStack::PushL(versionMajor); |
|
254 CleanupStack::PushL(versionMinor); |
|
255 |
|
256 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EMajorNumber,aXmlData,count,ETrue); |
|
257 AppendLiteralL(versionMajor->Des(),aXmlData,count); |
|
258 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EMajorNumber,aXmlData,count,EFalse); |
|
259 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EMinorNumber,aXmlData,count,ETrue); |
|
260 AppendLiteralL(versionMinor->Des(),aXmlData,count); |
|
261 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EMinorNumber,aXmlData,count,EFalse); |
|
262 |
|
263 CleanupStack::PopAndDestroy(versionMinor); |
|
264 CleanupStack::PopAndDestroy(versionMajor); |
|
265 |
|
266 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::ESpecVersion,aXmlData,count,EFalse); |
|
267 |
|
268 |
|
269 if(aServDescObj->CountOfActionList()!= 0) |
|
270 { |
|
271 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EActionList,aXmlData,count,ETrue); |
|
272 } |
|
273 |
|
274 for(TInt i =0;i< aServDescObj->CountOfActionList();i++ ) |
|
275 { |
|
276 const CUPnPAction *uPnPAction = aServDescObj->AtActionList(i); |
|
277 AppendActionL(uPnPAction,aXmlData,count); |
|
278 } |
|
279 if(aServDescObj->CountOfActionList()!= 0) |
|
280 { |
|
281 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EActionList,aXmlData,count,EFalse); |
|
282 } |
|
283 |
|
284 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EServiceStateTable,aXmlData,count,ETrue); |
|
285 |
|
286 for(TInt i =0;i< aServDescObj->CountOfServiceStateTable();i++ ) |
|
287 { |
|
288 const CUPnPStateVariable *uPnPStateVariable = aServDescObj->AtServiceStateTable(i); |
|
289 AppendStateVariableL(uPnPStateVariable,aXmlData, count); |
|
290 } |
|
291 |
|
292 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EServiceStateTable,aXmlData,count,EFalse); |
|
293 |
|
294 AppendLiteralL(UPNPDESCRIPTIONXMLTAGS::EScpd,aXmlData,count,EFalse); |
|
295 |
|
296 |
|
297 |
|
298 unicode.CreateL(aXmlData.Length()); |
|
299 unicode.Copy(aXmlData); |
|
300 unicode.Close(); |
|
301 } |