Bug Summary

File:libsynthesis/src/syncml_tk/src/sml/xlt/all/xltenc.c
Warning:line 439, column 3
Value stored to '_err' is never read

Annotated Source Code

1/**
2 * @file
3 * Encoder source file
4 *
5 * @target_system All
6 * @target_os All
7 */
8
9/*
10 * Copyright Notice
11 * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication
12 * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc.,
13 * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001).
14 * All Rights Reserved.
15 * Implementation of all or part of any Specification may require
16 * licenses under third party intellectual property rights,
17 * including without limitation, patent rights (such a third party
18 * may or may not be a Supporter). The Sponsors of the Specification
19 * are not responsible and shall not be held responsible in any
20 * manner for identifying or failing to identify any or all such
21 * third party intellectual property rights.
22 *
23 * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED
24 * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM,
25 * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA,
26 * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML
27 * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
28 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
29 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
30 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
31 * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO.,
32 * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY
33 * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF
34 * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF
35 * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL,
36 * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH
37 * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED
38 * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
39 *
40 * The above notice and this paragraph must be included on all copies
41 * of this document that are made.
42 *
43 */
44
45/*************************************************************************/
46/* Definitions */
47/*************************************************************************/
48#include "syncml_tk_prefix_file.h" // %%% luz: needed for precompiled headers in eVC++
49
50#include <xltenc.h>
51#ifdef __SML_WBXML__
52 #include "xltencwbxml.h"
53#endif
54#ifdef __SML_XML__
55 #include "xltencxml.h"
56#endif
57#include "xlttags.h"
58#include "xltmetinf.h"
59#include "xltdevinf.h"
60#include "smlmetinfdtd.h"
61#include "smldevinfdtd.h"
62#include <libstr.h>
63#include <libmem.h>
64#include <smldtd.h>
65
66Ret_t getTNbyPE(SmlProtoElement_t, XltTagID_t*);
67Ret_t xltEncBlock(XltTagID_t, XltRO_t, const VoidPtr_t, SmlEncoding_t, BufferMgmtPtr_t, SmlPcdataExtension_t);
68Ret_t xltEncList(XltListType_t, XltRO_t, VoidPtr_t, SmlEncoding_t, BufferMgmtPtr_t, SmlPcdataExtension_t);
69#ifndef __SML_LITE__
70Ret_t xltBuildExtention(SmlPcdataExtension_t, XltRO_t, VoidPtr_t, SmlEncoding_t, BufferMgmtPtr_t);
71#endif
72
73typedef struct PEEnc_s
74{
75 XltTagID_t tagid;
76 SmlProtoElement_t type;
77} PEEnc_t, *PEEncPtr_t;
78
79/* luz 2005-08-17: simplified, removed unnecessary copying of the const static table */
80
81static const PEEnc_t cPE_Enc[] =
82 {
83 { TN_ADD, SML_PE_ADD },
84 { TN_ALERT, SML_PE_ALERT },
85 { TN_ATOMIC, SML_PE_ATOMIC_START },
86 { TN_ATOMIC_END, SML_PE_ATOMIC_END },
87 { TN_COPY, SML_PE_COPY },
88 { TN_DELETE, SML_PE_DELETE },
89 { TN_EXEC, SML_PE_EXEC },
90 { TN_GET, SML_PE_GET },
91 { TN_MAP, SML_PE_MAP },
92 { TN_PUT, SML_PE_PUT },
93 { TN_RESULTS, SML_PE_RESULTS },
94 { TN_SEARCH, SML_PE_SEARCH },
95 { TN_SEQUENCE, SML_PE_SEQUENCE_START },
96 { TN_SEQUENCE_END, SML_PE_SEQUENCE_END },
97 { TN_STATUS, SML_PE_STATUS },
98 { TN_SYNC, SML_PE_SYNC_START },
99 { TN_SYNC_END, SML_PE_SYNC_END },
100 { TN_REPLACE, SML_PE_REPLACE },
101 { TN_UNDEF, SML_PE_UNDEF }
102 };
103
104
105Ret_t getTNbyPE(SmlProtoElement_t pE, XltTagID_t *tagID)
106{
107 int i = 0;
108 while ((cPE_Enc[i].type) != SML_PE_UNDEF)
109 {
110 if ((cPE_Enc[i].type) == pE)
111 {
112 *tagID = cPE_Enc[i].tagid;
113 return SML_ERR_OK0x00;
114 }
115 i++;
116 }
117 *tagID = TN_UNDEF;
118 return SML_ERR_XLT_INVAL_PROTO_ELEM0x2008;
119}
120
121
122// %%% luz:2003-07-31: added SyncML FPI (formal public identifier) tables
123const char * const SyncMLFPI[SML_NUM_VERS] = {
124 "???",
125 "-//SYNCML//DTD SyncML 1.0//EN",
126 "-//SYNCML//DTD SyncML 1.1//EN",
127 "-//SYNCML//DTD SyncML 1.2//EN"
128};
129const char * const SyncMLDevInfFPI[SML_NUM_VERS] = {
130 "???",
131 "-//SYNCML//DTD DevInf 1.0//EN",
132 "-//SYNCML//DTD DevInf 1.1//EN",
133 "-//SYNCML//DTD DevInf 1.2//EN"
134};
135const int SyncMLWBXMLPublicID[SML_NUM_VERS] = {
136 0,
137 0, // we use the string ID, not the binary value (altough it seems to be defined as 0x0FD1
138 0x0FD3,
139 0x1201
140};
141const int SyncMLDevInfWBXMLPublicID[SML_NUM_VERS] = {
142 0,
143 0,
144 0x0FD4, // according to Nokia E70
145 0x1203 // according to Nokia E70
146};
147
148
149
150/**
151 * Initializes an XML buffer; Creates XML code for the SyncHdr
152 * and appends it to the buffer.
153 * Returns 0 if operation was successful.
154 *
155 * @pre no memory should be allocated for ppEncoder (should be NULL)
156 * pHeader has to contain a valid SyncHdr structure
157 * pBufEnd must point to the end of the (WB)XML buffer
158 * ppBufPos has to be initialized to the start point of the
159 * (WB)XML buffer.
160 * @post After the function call ppBufPos points to the
161 * first free byte in the buffer behind the (WB)XML document
162 * @param enc (IN)
163 * the encoding constant (SML_WBXML or SML_XML)
164 * @param pHeader (IN)
165 * the SyncML header structure
166 * @param pBufEnd (IN)
167 * pointer to the end of the buffer to write on
168 * @param ppBufPos (IN/OUT)
169 * current position of the bufferpointer
170 * @param ppEncoder (IN/OUT)
171 * the encoder object
172 * @param vers (IN)
173 * SyncML version
174 * @return shows error codes of function,\n
175 * 0, if OK\n
176 * Possible Error Codes:
177 * - SML_ERR_XLT_MISSING_CONT
178 * - SML_ERR_XLT_BUF_ERR
179 * - SML_ERR_XLT_INVAL_ELEM_TYPE
180 * - SML_ERR_XLT_INVAL_LIST_TYPE
181 * - SML_ERR_XLT_INVAL_TAG_TYPE
182 * - SML_ERR_XLT_ENC_UNK
183 * - SML_ERR_XLT_INVAL_PROTO_ELEM
184 */
185Ret_t xltEncInit(SmlEncoding_t enc,
186 const SmlSyncHdrPtr_t pHeader,
187 const MemPtr_t pBufEnd,
188 MemPtr_t *ppBufPos,
189 XltEncoderPtr_t *ppEncoder,
190 SmlVersion_t vers)
191{
192 // Return variable
193 Ret_t _err;
194
195 XltEncoderPtr_t _pEncoder;
196
197 //Structure containing buffer pointers, length and written bytes
198 BufferMgmtPtr_t _pBufMgr;
199
200#ifdef __SML_XML__
201 MemPtr_t _tmpStr;
202 MemPtr_t _xmlver = (MemPtr_t)XML_VERSION"1.0";
203 MemPtr_t _xmlenc = (MemPtr_t)XML_ENCODING"UTF-8";
204 MemByte_t _begpar = XML_BEGPAR'<';
205 MemByte_t _endpar = XML_ENDPAR'>';
206#endif
207
208#ifdef __SML_WBXML__
209 MemByte_t _wbxmlver = XLT_WBXMLVER0x02;
210 MemByte_t _charset = XLT_CHARSET0x6A;
211 // check if we want to send numeric or textual FPI
212 MemByte_t _pubident1 = 0; // default to textual
213 MemByte_t _pubident2 = 0;
214 const char *_syncmldtd = SyncMLFPI[vers];
215 unsigned short fpi = SyncMLWBXMLPublicID[vers];
216 MemByte_t _stablen = smlLibStrlen(_syncmldtd); // %% not 0x1D constant!
217 if (fpi) {
218 // numeric FPI available
219 _pubident1 = ((fpi>>7) & 0x7F)+0x80; // upper 7 bit
220 _pubident2 = (fpi & 0x7F); // lower 7 bits
221 _stablen = 0; // no string table
222 }
223#endif
224
225 //MemByte_t _tmp = 0x00;CURRENTLY NOT USED
226
227 if ((_pEncoder = (XltEncoderPtr_t)smlLibMalloc(sizeof(XltEncoder_t))) == NULL((void*)0)) return SML_ERR_NOT_ENOUGH_SPACE0x11;
228 if ((_pBufMgr = (BufferMgmtPtr_t)smlLibMalloc(sizeof(BufferMgmt_t))) == NULL((void*)0)) {
229 smlLibFree(_pEncoder);
230 return SML_ERR_NOT_ENOUGH_SPACE0x11;
231 }
232
233 //set the encoding
234 _pEncoder->enc = enc;
235
236 // %%% luz:2003-07-31: added version
237 _pEncoder->vers = vers;
238
239 _pEncoder->cur_ext = (SmlPcdataExtension_t)SML_EXT_UNDEFINED;
240 _pEncoder->last_ext = (SmlPcdataExtension_t)SML_EXT_UNDEFINED;
241 _pEncoder->end_tag_size = 0;
242 _pEncoder->space_evaluation = NULL((void*)0);
243
244
245 _pBufMgr->smlXltBufferP = *ppBufPos;
246 _pBufMgr->smlXltBufferLen = pBufEnd - *ppBufPos;
247 _pBufMgr->smlXltStoreBufP = _pBufMgr->smlXltBufferP;
248 _pBufMgr->smlXltWrittenBytes = 0;
249 _pBufMgr->smlCurExt = _pEncoder->cur_ext;
250 _pBufMgr->smlLastExt = _pEncoder->last_ext;
251 _pBufMgr->smlActiveExt = SML_EXT_UNDEFINED;
252 _pBufMgr->switchExtTag = TN_UNDEF;
253 _pBufMgr->spaceEvaluation = 0;
254 _pBufMgr->vers = vers;
255 _pBufMgr->endTagSize = 0;
256
257 switch (enc)
258 {
259
260#ifdef __SML_WBXML__
261 case SML_WBXML:
262 {
263
264 // Set the WBXML Header Values
265 // WBXML Version
266 if ((_err = wbxmlWriteTypeToBuffer((MemPtr_t)(&_wbxmlver), TAG, 1, _pBufMgr)) != SML_ERR_OK0x00) break;
267 // Public Idetifier - default unknown
268 if ((_err = wbxmlWriteTypeToBuffer((MemPtr_t)(&_pubident1), TAG, 1, _pBufMgr)) != SML_ERR_OK0x00) break;
269 if ((_err = wbxmlWriteTypeToBuffer((MemPtr_t)(&_pubident2), TAG, 1, _pBufMgr)) != SML_ERR_OK0x00) break;
270 // Character set - not yet implemented
271 if ((_err = wbxmlWriteTypeToBuffer((MemPtr_t)(&_charset), TAG, 1, _pBufMgr)) != SML_ERR_OK0x00) break;
272 // - String table length - only used for textual FPI
273 if ((_err = wbxmlWriteTypeToBuffer((MemPtr_t)(&_stablen), TAG, 1, _pBufMgr)) != SML_ERR_OK0x00) break;
274 // FPI - %%% luz:2003-07-31: not constant any more, varies according to SyncML version
275 if (fpi==0) {
276 // textual FPI
277 // - string table consisting of FPI only
278 if ((_err = xltAddToBuffer((MemPtr_t) (_syncmldtd) , smlLibStrlen((String_t)_syncmldtd), _pBufMgr)) != SML_ERR_OK0x00) break;
279 }
280 else {
281 // numeric FPI
282 // NOP - no string table
283 }
284
285 break;
286 }
287#endif
288
289#ifdef __SML_XML__
290 case SML_XML:
291 {
292
293 if ((_err = xltAddToBuffer((MemPtr_t)(&_begpar), 1, _pBufMgr)) != SML_ERR_OK0x00) break;
294 _tmpStr = (MemPtr_t)"?xml version=\"";
295 if ((_err = xltAddToBuffer(_tmpStr, smlLibStrlen((String_t)_tmpStr), _pBufMgr)) != SML_ERR_OK0x00) break;
296 _tmpStr = _xmlver;
297 if ((_err = xltAddToBuffer(_tmpStr, smlLibStrlen((String_t)_tmpStr), _pBufMgr)) != SML_ERR_OK0x00) break;
298 _tmpStr = (MemPtr_t)"\" encoding=\"";
299 if ((_err = xltAddToBuffer(_tmpStr, smlLibStrlen((String_t)_tmpStr), _pBufMgr)) != SML_ERR_OK0x00) break;
300 _tmpStr = _xmlenc;
301 if ((_err = xltAddToBuffer(_tmpStr, smlLibStrlen((String_t)_tmpStr), _pBufMgr)) != SML_ERR_OK0x00) break;
302 _tmpStr = (MemPtr_t)"\"?";
303 if ((_err = xltAddToBuffer(_tmpStr, smlLibStrlen((String_t)_tmpStr), _pBufMgr)) != SML_ERR_OK0x00) break;
304 if ((_err = xltAddToBuffer((MemPtr_t)(&_endpar), 1, _pBufMgr)) != SML_ERR_OK0x00) break;
305
306 break;
307 }
308#endif
309
310 default:
311 {
312 _err = SML_ERR_XLT_ENC_UNK0x2007;
313 }
314 }
315 if (_err != SML_ERR_OK0x00)
316 {
317 smlLibFree(_pBufMgr);
318 smlLibFree(_pEncoder);
319 return _err;
320 }
321
322 // SyncML Tag
323 if ((_err = xltGenerateTag(TN_SYNCML, TT_BEG, enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00)
324 {
325 smlLibFree(_pBufMgr);
326 smlLibFree(_pEncoder);
327 return _err;
328 }
329
330 // Generate SmlSyncHdr
331
332 if ((_err = xltEncBlock(TN_SYNCHDR, REQUIRED, pHeader, enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00)
333 {
334 smlLibFree(_pBufMgr);
335 smlLibFree(_pEncoder);
336 return _err;
337 }
338
339 // SyncBody Tag
340 if ((_err = xltGenerateTag(TN_SYNCBODY, TT_BEG, enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00)
341 {
342 smlLibFree(_pBufMgr);
343 smlLibFree(_pEncoder);
344 return _err;
345 }
346
347 _pEncoder->cur_ext = _pBufMgr->smlCurExt;
348 _pEncoder->last_ext = _pBufMgr->smlLastExt;
349 _pEncoder->end_tag_size = _pBufMgr->endTagSize;
350
351 *ppBufPos = _pBufMgr->smlXltBufferP;
352
353 smlLibFree(_pBufMgr);
354
355 _pEncoder->final = 0;
356
357 *ppEncoder = (XltEncoderPtr_t)_pEncoder;
358
359 return SML_ERR_OK0x00;
360}
361
362/**
363 * Generates (WB)XML code and appends it to the XML buffer.
364 *
365 * @pre pEncoder holds the initialized encoder structure.
366 * the initialization takes place in the xltEncAppend function
367 * pContent has to contain a valid content structure structure
368 * pBufEnd must point to the end of the (WB)XML buffer
369 * ppBufPos has to be initialized to the start point of the
370 * (WB)XML buffer.
371 * @post After the function call ppBufPos points to the
372 * first free byte in the buffer behind the (WB)XML document
373 * @param pEncoder (IN)
374 * the encoder object
375 * @param pe (IN)
376 * the protocol element (PE_ADD, ...)
377 * @param pBufEnd (IN)
378 * pointer to the end of the buffer to write on
379 * @param pContent (IN)
380 * the content to append to the SyncML document
381 * @param ppBufPos (IN/OUT)
382 * current position of the bufferpointer
383 * @return shows error codes of function,\n
384 * 0, if OK\n
385 * Possible Error Codes:
386 * - SML_ERR_XLT_MISSING_CONT
387 * - SML_ERR_XLT_BUF_ERR
388 * - SML_ERR_XLT_INVAL_ELEM_TYPE
389 * - SML_ERR_XLT_INVAL_LIST_TYPE
390 * - SML_ERR_XLT_INVAL_TAG_TYPE
391 * - SML_ERR_XLT_ENC_UNK
392 * - SML_ERR_XLT_INVAL_PROTO_ELEM
393 */
394Ret_t xltEncAppend(const XltEncoderPtr_t pEncoder,
395 SmlProtoElement_t pe,
396 const MemPtr_t pBufEnd,
397 const VoidPtr_t pContent,
398 MemPtr_t *ppBufPos)
399{
400 // Return variable
401 Ret_t _err;
402
403 XltTagID_t tagID = TN_UNDEF;
404
405 // encoding type
406 SmlEncoding_t _enc;
407
408 //Structure containing buffer pointers, length and written bytes
409 BufferMgmtPtr_t _pBufMgr;
410
411 if ((_pBufMgr = (BufferMgmtPtr_t)smlLibMalloc(sizeof(BufferMgmt_t))) == NULL((void*)0)) return SML_ERR_NOT_ENOUGH_SPACE0x11;
412 smlLibMemset(_pBufMgr, 0, sizeof(BufferMgmt_t));
413
414 //get the encoding type
415 _enc = pEncoder->enc;
416
417 _pBufMgr->vers = pEncoder->vers; // %%% luz:2003-07-31: pass SyncML version to bufmgr
418 _pBufMgr->smlXltBufferP = *ppBufPos;
419 _pBufMgr->smlXltBufferLen = pBufEnd - *ppBufPos;
420 _pBufMgr->smlXltStoreBufP = _pBufMgr->smlXltBufferP;
421 _pBufMgr->smlXltWrittenBytes = 0;
422 _pBufMgr->smlActiveExt = SML_EXT_UNDEFINED;
423 _pBufMgr->switchExtTag = TN_UNDEF;
424 _pBufMgr->spaceEvaluation = ((pEncoder->space_evaluation == NULL((void*)0)) ? 0 : 1);
425 // %%% luz 2002-09-03: evaluation may not mess with encoder state
426 if ( _pBufMgr->spaceEvaluation) {
427 // spaceEval state
428 _pBufMgr->smlCurExt = pEncoder->space_evaluation->cur_ext;
429 _pBufMgr->smlLastExt = pEncoder->space_evaluation->last_ext;
430 }
431 else {
432 // normal encoder state
433 _pBufMgr->smlCurExt = pEncoder->cur_ext;
434 _pBufMgr->smlLastExt = pEncoder->last_ext;
435 }
436
437 _pBufMgr->endTagSize =0;
438
439 _err = getTNbyPE(pe, &tagID);
Value stored to '_err' is never read
440
441 _err = xltEncBlock(tagID, REQUIRED, pContent, _enc, _pBufMgr, SML_EXT_UNDEFINED);
442 if (_err != SML_ERR_OK0x00)
443 {
444 smlLibFree(_pBufMgr);
445 return _err;
446 }
447
448
449 if (pEncoder->space_evaluation != NULL((void*)0)) {
450 // Only calculating size
451 pEncoder->space_evaluation->written_bytes += _pBufMgr->smlXltWrittenBytes;
452 pEncoder->space_evaluation->end_tag_size += _pBufMgr->endTagSize;
453 // save it only into evaluation state
454 pEncoder->space_evaluation->cur_ext = _pBufMgr->smlCurExt;
455 pEncoder->space_evaluation->last_ext = _pBufMgr->smlLastExt;
456 } else {
457 // really generating data
458 pEncoder->end_tag_size += _pBufMgr->endTagSize;
459 // save it into encoder state
460 pEncoder->cur_ext = _pBufMgr->smlCurExt;
461 pEncoder->last_ext = _pBufMgr->smlLastExt;
462 }
463
464 *ppBufPos = _pBufMgr->smlXltBufferP;
465
466 smlLibFree(_pBufMgr);
467
468 return SML_ERR_OK0x00;
469}
470
471/**
472 * Filnalizes the (WB)XML document and returns the size of written bytes to
473 * the workspace module
474 *
475 * @pre pEncoder holds the initialized encoder structure.
476 * the initialization takes place in the xltEncAppend function
477 * pBufEnd must point to the end of the (WB)XML buffer
478 * ppBufPos has to be initialized to the start point of the
479 * (WB)XML buffer.
480 * @post After the function call ppBufPos points to the
481 * first free byte in the buffer behind the (WB)XML document
482 * @param pEncoder (IN)
483 * the encoder object
484 * @param pBufEnd (IN)
485 * pointer to the end of the buffer to write on
486 * @param ppBufPos (IN/OUT)
487 * current position of the bufferpointer
488 * @return shows error codes of function,\n
489 * 0, if OK\n
490 * Possible Error Codes:
491 * - SML_ERR_XLT_BUF_ERR
492 * - SML_ERR_XLT_MISSING_CONT
493 * - SML_ERR_XLT_INVAL_ELEM_TYPE
494 * - SML_ERR_XLT_INVAL_LIST_TYPE
495 * - SML_ERR_XLT_INVAL_TAG_TYPE
496 * - SML_ERR_XLT_ENC_UNK
497 * - SML_ERR_XLT_INVAL_PROTO_ELEM
498 */
499Ret_t xltEncTerminate(const XltEncoderPtr_t pEncoder,
500 const MemPtr_t pBufEnd,
501 MemPtr_t *ppBufPos)
502{
503 // Return variable
504 Ret_t _err;
505
506 // encoding type
507 SmlEncoding_t _enc;
508
509 //Structure containing buffer pointers, length and written bytes
510 BufferMgmtPtr_t _pBufMgr;
511
512 //get the encoding type
513 _enc = pEncoder->enc;
514
515 //Initialize buffer variables
516 if ((_pBufMgr = smlLibMalloc(sizeof(BufferMgmt_t))) == NULL((void*)0)) {
517 smlLibFree(pEncoder);
518 return SML_ERR_NOT_ENOUGH_SPACE0x11;
519 }
520
521 _pBufMgr->vers = pEncoder->vers; // %%% luz:2003-07-31: pass SyncML version to bufmgr
522 _pBufMgr->smlXltWrittenBytes = 0;
523 _pBufMgr->smlXltBufferP = *ppBufPos;
524 _pBufMgr->smlXltStoreBufP = _pBufMgr->smlXltBufferP;
525 _pBufMgr->smlXltBufferLen = pBufEnd - *ppBufPos;
526 _pBufMgr->smlCurExt = pEncoder->cur_ext;
527 _pBufMgr->smlLastExt = pEncoder->last_ext;
528 _pBufMgr->smlActiveExt = pEncoder->cur_ext;
529 _pBufMgr->switchExtTag = TN_UNDEF;
530 _pBufMgr->spaceEvaluation = ((pEncoder->space_evaluation == NULL((void*)0)) ? 0 : 1);
531 _pBufMgr->endTagSize =0;
532
533 if (pEncoder->final == 1)
534 {
535 // Final Flag
536 if ((_err = xltGenerateTag(TN_FINAL, TT_ALL, _enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00)
537 {
538 smlLibFree(_pBufMgr);
539 xltEncReset(pEncoder);
540 return _err;
541 }
542 }
543
544 // SyncBody End Tag
545 if ((_err = xltGenerateTag(TN_SYNCBODY, TT_END, _enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00)
546 {
547 smlLibFree(_pBufMgr);
548 xltEncReset(pEncoder);
549 return _err;
550 }
551
552 // SyncML End Tag
553 if ((_err = xltGenerateTag(TN_SYNCML, TT_END, _enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00)
554 {
555 smlLibFree(_pBufMgr);
556 xltEncReset(pEncoder);
557 return _err;
558 }
559
560 pEncoder->cur_ext = _pBufMgr->smlCurExt;
561 pEncoder->last_ext = _pBufMgr->smlLastExt;
562
563 *ppBufPos = _pBufMgr->smlXltBufferP;
564
565 smlLibFree(_pBufMgr);
566
567 xltEncReset(pEncoder);
568
569 return SML_ERR_OK0x00;
570}
571
572Ret_t xltEncReset(XltEncoderPtr_t pEncoder)
573{
574 if ((pEncoder) && (pEncoder->space_evaluation)) {
575 smlLibFree(pEncoder->space_evaluation);
576 pEncoder->space_evaluation = NULL((void*)0);
577 }
578 smlLibFree(pEncoder);
579 return SML_ERR_OK0x00;
580}
581
582
583/**
584 * Starts an evaluation run which prevents further API-Calls to write tags -
585 * just the tag-sizes are calculated. Must be sopped via smlEndEvaluation
586 *
587 * @param pEncoder (IN)
588 * the encoder object
589 * @return Return Code
590 */
591SML_API Ret_t xltStartEvaluation(XltEncoderPtr_t pEncoder)
592{
593 XltSpaceEvaluationPtr_t _pSpaceEvaluation;
594
595 if (pEncoder->space_evaluation != NULL((void*)0))
596 return SML_ERR_WRONG_USAGE0x13;
597
598 if ((_pSpaceEvaluation = (XltSpaceEvaluationPtr_t)smlLibMalloc(sizeof(XltSpaceEvaluation_t))) == NULL((void*)0))
599 return SML_ERR_NOT_ENOUGH_SPACE0x11;
600 smlLibMemset(_pSpaceEvaluation, 0, sizeof(XltSpaceEvaluation_t));
601 // %%% luz 2002-09-03: init encoder state shadow copies for evaluation from real encoder
602 _pSpaceEvaluation->cur_ext = pEncoder->cur_ext;
603 _pSpaceEvaluation->last_ext = pEncoder->last_ext;
604
605 pEncoder->space_evaluation = _pSpaceEvaluation;
606 return SML_ERR_OK0x00;
607}
608
609
610/**
611 * Stops an evaluation run which prevents further API-Calls to write tags -
612 * the remaining free buffer size after all Tags are written is returned
613 *
614 * @param id (IN)
615 * instance ID
616 * @param pEncoder (IN)
617 * the encoder object
618 * @param freemem (IN/OUT)
619 * Size of free buffer for data after all tags are written
620 * @return Return Code
621 */
622SML_API Ret_t xltEndEvaluation(InstanceID_t id, XltEncoderPtr_t pEncoder, MemSize_t *freemem)
623{
624
625 MemSize_t _free;
626 XltSpaceEvaluationPtr_t _evaluation;
627
628 _evaluation = pEncoder->space_evaluation;
629
630 if (_evaluation == NULL((void*)0))
631 return SML_ERR_WRONG_USAGE0x13;
632
633 _free = smlGetFreeBuffer(id);
634 _free -= _evaluation->written_bytes;
635 _free -= _evaluation->end_tag_size;
636 _free -= pEncoder->end_tag_size;
637
638 *freemem = _free;
639
640 smlLibFree(_evaluation);
641 pEncoder->space_evaluation = NULL((void*)0);
642
643 return SML_ERR_OK0x00;
644}
645
646
647/**
648 * Generates a (WB)XML Block for a given tag ID and a given content
649 *
650 * @pre pContent holds a valid content structure
651 * tagId contains a valid SyncML tag ID
652 * @post the (WB)XML buffer in the pBufMgr structure contains the
653 * encoded (WB)XML block
654 * @param tagId (IN)
655 * the ID for the tag to generate (TN_ADD, ...)
656 * @param reqOptFlag (IN)
657 * flag if the block is required or optional
658 * @param pContent (IN)
659 * the content structure of the block
660 * @param enc (IN)
661 * the encoding constant (SML_WBXML or SML_XML)
662 * @param attFlag (IN)
663 * indicates if the encoded tag contain Attributes
664 * in namespace extensions
665 * @param pBufMgr (IN/OUT)
666 * pointer to a structure containing buffer management elements
667 * @return shows error codes of function,\n
668 * 0, if OK
669 */
670Ret_t xltEncBlock(XltTagID_t tagId, XltRO_t reqOptFlag, const VoidPtr_t pContent, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr, SmlPcdataExtension_t attFlag)
671{
672
673 //Return variable
674 Ret_t _err;
675
676
677 //Check if pContent of a required field is missing
678 if ((reqOptFlag == REQUIRED) && (pContent == NULL((void*)0))) {
679 switch ((int)tagId) {
680 case TN_ATOMIC_END:
681 case TN_SYNC_END:
682 case TN_SEQUENCE_END:
683 break;
684 default:
685 return SML_ERR_XLT_MISSING_CONT0x2001;
686 }
687 }
688 //Check if pContent of a optional field is missing
689 else if ((pContent == NULL((void*)0)) && (tagId != TN_SYNC_END) && (tagId != TN_ATOMIC_END) && (tagId != TN_SEQUENCE_END))
690 return SML_ERR_OK0x00;
691
692 //Generate the commands -> see DTD
693 switch ((int)tagId){
694 case TN_SYNCHDR:
695 // SyncHdr Begin Tag
696 if ((_err = xltGenerateTag(TN_SYNCHDR, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
697 // Version
698 if ((_err = xltEncBlock(TN_VERSION, REQUIRED, ((SmlSyncHdrPtr_t) pContent)->version, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
699 // Proto
700 if ((_err = xltEncBlock(TN_PROTO, REQUIRED, ((SmlSyncHdrPtr_t) pContent)->proto, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
701 // SessionID
702 if ((_err = xltEncBlock(TN_SESSIONID, REQUIRED, ((SmlSyncHdrPtr_t) pContent)->sessionID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
703 // MsgID
704 if ((_err = xltEncBlock(TN_MSGID, REQUIRED, ((SmlSyncHdrPtr_t) pContent)->msgID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
705 // Target
706 if ((_err = xltEncBlock(TN_TARGET, REQUIRED, ((SmlSyncHdrPtr_t) pContent)->target, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
707 // Source
708 if ((_err = xltEncBlock(TN_SOURCE, REQUIRED, ((SmlSyncHdrPtr_t) pContent)->source, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
709 // RespURI?
710 if ((_err = xltEncBlock(TN_RESPURI, OPTIONAL, ((SmlSyncHdrPtr_t) pContent)->respURI, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
711 // NoResp?
712 if ((_err = xltEncBlock(TN_NORESP, OPTIONAL, &((SmlSyncHdrPtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
713 // Cred?
714 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlSyncHdrPtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
715 // Meta?
716 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlSyncHdrPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
717 // SyncHdr End Tag
718 if ((_err = xltGenerateTag(TN_SYNCHDR, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
719
720 break;
721 case TN_CRED:
722 // Begin tag
723 if ((_err = xltGenerateTag(TN_CRED, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
724 // Meta?
725 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlCredPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
726 // Data
727 if ((_err = xltEncBlock(TN_DATA, REQUIRED, ((SmlCredPtr_t) pContent)->data, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
728 // End tag
729 if ((_err = xltGenerateTag(TN_CRED, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
730 break;
731
732 case TN_SOURCEPARENT:
733 case TN_TARGETPARENT:
734 // Begin tag
735 if ((_err = xltGenerateTag(tagId, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
736 // LocURI
737 if ((_err = xltEncBlock(TN_LOCURI, REQUIRED, ((SmlSourceParentPtr_t) pContent)->locURI, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
738 // End tag
739 if ((_err = xltGenerateTag(tagId, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
740 break;
741
742 case TN_SOURCE:
743 case TN_TARGET:
744 // Begin tag
745 if ((_err = xltGenerateTag(tagId, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
746 // LocURI
747 if ((_err = xltEncBlock(TN_LOCURI, REQUIRED, ((SmlSourcePtr_t) pContent)->locURI, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
748 // LocName?
749 if ((_err = xltEncBlock(TN_LOCNAME, OPTIONAL, ((SmlSourcePtr_t) pContent)->locName, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
750 // Filter?
751 if ((_err = xltEncBlock(TN_FILTER, OPTIONAL, ((SmlSourcePtr_t) pContent)->filter, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
752 // End tag
753 if ((_err = xltGenerateTag(tagId, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
754 break;
755
756 case TN_ITEM:
757 // Begin tag
758 if ((_err = xltGenerateTag(TN_ITEM, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
759 // Target?
760 if ((_err = xltEncBlock(TN_TARGET, OPTIONAL, ((SmlItemPtr_t) pContent)->target, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
761 // Source?
762 if ((_err = xltEncBlock(TN_SOURCE, OPTIONAL, ((SmlItemPtr_t) pContent)->source, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
763 // TargetParent?
764 if ((_err = xltEncBlock(TN_TARGETPARENT, OPTIONAL, ((SmlItemPtr_t) pContent)->targetParent, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
765 // SourceParent?
766 if ((_err = xltEncBlock(TN_SOURCEPARENT, OPTIONAL, ((SmlItemPtr_t) pContent)->sourceParent, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
767 // Meta?
768 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlItemPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
769 // Data?
770 if ((_err = xltEncBlock(TN_DATA, OPTIONAL, ((SmlItemPtr_t) pContent)->data, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
771 // MoreData?
772 if ((_err = xltEncBlock(TN_MOREDATA, OPTIONAL, &(((SmlItemPtr_t) pContent)->flags), enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
773 // End tag
774 if ((_err = xltGenerateTag(TN_ITEM, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
775 break;
776
777 /* %%% Added Filter tags 2005-08-17 by synthesis/luz for DS 1.2 */
778 case TN_FIELD:
779 case TN_RECORD:
780 // Begin tag
781 if ((_err = xltGenerateTag(tagId, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
782 // Item
783 if ((_err = xltEncBlock(TN_ITEM, REQUIRED, ((SmlRecordOrFieldFilterPtr_t) pContent)->item, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
784 // End tag
785 if ((_err = xltGenerateTag(tagId, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
786 break;
787
788 case TN_FILTER:
789 // Begin tag
790 if ((_err = xltGenerateTag(tagId, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
791 // Meta
792 if ((_err = xltEncBlock(TN_META, REQUIRED, ((SmlFilterPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
793 // Field?
794 if ((_err = xltEncBlock(TN_FIELD, OPTIONAL, ((SmlFilterPtr_t) pContent)->field, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
795 // Record?
796 if ((_err = xltEncBlock(TN_RECORD, OPTIONAL, ((SmlFilterPtr_t) pContent)->record, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
797 // FilterType?
798 if ((_err = xltEncBlock(TN_FILTERTYPE, OPTIONAL, ((SmlFilterPtr_t) pContent)->filtertype, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
799 // End tag
800 if ((_err = xltGenerateTag(tagId, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
801 break;
802
803 case TN_REPLACE:
804 case TN_ADD:
805 case TN_COPY:
806 case TN_MOVE:
807 // Begin tag
808 if ((_err = xltGenerateTag(tagId, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
809 // CmdID
810 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlGenericCmdPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
811 // NoResp?
812 if ((_err = xltEncBlock(TN_NORESP, OPTIONAL, &((SmlGenericCmdPtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
813 // Cred?
814 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlGenericCmdPtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
815 // Meta?
816 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlGenericCmdPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
817 // Item+
818 if ((_err = xltEncList(ITEM_LIST, REQUIRED, ((SmlGenericCmdPtr_t) pContent)->itemList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
819 // End tag
820 if ((_err = xltGenerateTag(tagId, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
821 break;
822
823 case TN_ALERT:
824 // Begin tag
825 if ((_err = xltGenerateTag(TN_ALERT, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
826 // CmdID
827 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlAlertPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
828 // NoResp?
829 if ((_err = xltEncBlock(TN_NORESP, OPTIONAL, &((SmlAlertPtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
830 // Cred?
831 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlAlertPtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
832 // Data?
833 if ((_err = xltEncBlock(TN_DATA, OPTIONAL, ((SmlAlertPtr_t) pContent)->data, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
834 // Item*
835 if ((_err = xltEncList(ITEM_LIST, OPTIONAL, ((SmlAlertPtr_t) pContent)->itemList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
836 // End tag
837 if ((_err = xltGenerateTag(TN_ALERT, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
838 break;
839
840#if (defined ATOMIC_SEND || defined SEQUENCE_SEND)
841 case TN_ATOMIC:
842 case TN_SEQUENCE:
843 // Begin tag
844 if ((_err = xltGenerateTag(tagId, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
845 // CmdID
846 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlAtomicPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
847 // NoResp?
848 if ((_err = xltEncBlock(TN_NORESP, OPTIONAL, &((SmlAtomicPtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
849 // Meta?
850 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlAtomicPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
851 //End tag in TN_ATOMIC_END
852 break;
853
854 case TN_ATOMIC_END:
855 // End tag
856 if ((_err = xltGenerateTag(TN_ATOMIC, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
857 break;
858
859 case TN_SEQUENCE_END:
860 // End tag
861 if ((_err = xltGenerateTag(TN_SEQUENCE, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
862 break;
863#endif
864
865 case TN_DELETE:
866 // Begin tag
867 if ((_err = xltGenerateTag(TN_DELETE, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
868 // CmdID
869 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlDeletePtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
870 // NoResp?
871 if ((_err = xltEncBlock(TN_NORESP, OPTIONAL, &((SmlDeletePtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
872 // Archive?
873 if ((_err = xltEncBlock(TN_ARCHIVE, OPTIONAL, &(((SmlDeletePtr_t) pContent)->flags), enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
874 // SftDel?
875 if ((_err = xltEncBlock(TN_SFTDEL, OPTIONAL, &(((SmlDeletePtr_t) pContent)->flags), enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
876 // Cred?
877 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlDeletePtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
878 // Meta?
879 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlDeletePtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
880 // Item+
881 if ((_err = xltEncList(ITEM_LIST, REQUIRED, ((SmlDeletePtr_t) pContent)->itemList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
882 // End tag
883 if ((_err = xltGenerateTag(TN_DELETE, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
884 break;
885
886#ifdef EXEC_SEND
887 case TN_EXEC:
888 // Begin tag
889 if ((_err = xltGenerateTag(TN_EXEC, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
890 // CmdID
891 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlExecPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
892 // NoResp?
893 if ((_err = xltEncBlock(TN_NORESP, OPTIONAL, &((SmlExecPtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
894 // Cred?
895 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlExecPtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
896 // Meta?
897 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlExecPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
898 // Item
899 if ((_err = xltEncBlock(TN_ITEM, REQUIRED, ((SmlExecPtr_t) pContent)->item, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
900 // End tag
901 if ((_err = xltGenerateTag(TN_EXEC, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
902 break;
903#endif
904
905 case TN_GET:
906 case TN_PUT:
907 // Begin tag
908 if ((_err = xltGenerateTag(tagId, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
909 // CmdID
910 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlGetPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
911 // NoResp?
912 if ((_err = xltEncBlock(TN_NORESP, OPTIONAL, &((SmlGetPtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
913 // Lang?
914 if ((_err = xltEncBlock(TN_LANG, OPTIONAL, ((SmlGetPtr_t) pContent)->lang, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
915 // Cred?
916 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlGetPtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
917 // Meta?
918 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlGetPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
919 // Item+
920 if ((_err = xltEncList(ITEM_LIST, REQUIRED, ((SmlGetPtr_t) pContent)->itemList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
921 // End tag
922 if ((_err = xltGenerateTag(tagId, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
923 break;
924
925 case TN_MAP:
926 // Begin tag
927 if ((_err = xltGenerateTag(TN_MAP, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
928 // CmdID
929 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlMapPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
930 // Target
931 if ((_err = xltEncBlock(TN_TARGET, REQUIRED, ((SmlMapPtr_t) pContent)->target, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
932 // Source
933 if ((_err = xltEncBlock(TN_SOURCE, REQUIRED, ((SmlMapPtr_t) pContent)->source, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
934 // Cred?
935 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlMapPtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
936 // Meta?
937 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlMapPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
938 // Mapitemlist
939 if ((_err = xltEncList(MAPITEM_LIST, REQUIRED, ((SmlMapPtr_t) pContent)->mapItemList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
940 // End tag
941 if ((_err = xltGenerateTag(TN_MAP, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
942 break;
943
944 case TN_MAPITEM:
945 // Begin tag
946 if ((_err = xltGenerateTag(TN_MAPITEM, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
947 // Target
948 if ((_err = xltEncBlock(TN_TARGET, REQUIRED, ((SmlMapItemPtr_t) pContent)->target, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
949 // Source
950 if ((_err = xltEncBlock(TN_SOURCE, REQUIRED, ((SmlMapItemPtr_t) pContent)->source, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
951 // End tag
952 if ((_err = xltGenerateTag(TN_MAPITEM, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
953 break;
954
955 case TN_RESULTS:
956 // Begin tag
957 if ((_err = xltGenerateTag(TN_RESULTS, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
958 // CmdID
959 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlResultsPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
960 // MsgRef?
961 if ((_err = xltEncBlock(TN_MSGREF, OPTIONAL, ((SmlResultsPtr_t) pContent)->msgRef, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
962 // CmdRef
963 if ((_err = xltEncBlock(TN_CMDREF, REQUIRED, ((SmlResultsPtr_t) pContent)->cmdRef, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
964 // Meta?
965 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlResultsPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
966 // TargetRef?
967 if ((_err = xltEncBlock(TN_TARGETREF, OPTIONAL, ((SmlResultsPtr_t) pContent)->targetRef, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
968 // SourceRef?
969 if ((_err = xltEncBlock(TN_SOURCEREF, OPTIONAL, ((SmlResultsPtr_t) pContent)->sourceRef, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
970 // Item+
971 if ((_err = xltEncList(ITEM_LIST, REQUIRED, ((SmlResultsPtr_t) pContent)->itemList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
972 // End tag
973 if ((_err = xltGenerateTag(TN_RESULTS, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
974 break;
975
976 case TN_CHAL:
977 // Begin tag
978 if ((_err = xltGenerateTag(TN_CHAL, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
979 // Meta
980 if ((_err = xltEncBlock(TN_META, REQUIRED, ((SmlChalPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
981 // End tag
982 if ((_err = xltGenerateTag(TN_CHAL, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
983 break;
984
985#ifdef SEARCH_SEND
986 case TN_SEARCH:
987 // Begin tag
988 if ((_err = xltGenerateTag(TN_SEARCH, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
989 // CmdID
990 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlSearchPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
991 // NoResp?
992 if ((_err = xltEncBlock(TN_NORESP, OPTIONAL, &((SmlSearchPtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
993 // NoResults?
994 if ((_err = xltEncBlock(TN_NORESULTS, OPTIONAL, &((SmlSearchPtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
995 // Cred?
996 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlSearchPtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
997 // Target?
998 if ((_err = xltEncBlock(TN_TARGET, OPTIONAL, ((SmlSearchPtr_t) pContent)->target, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
999 // Source List
1000 if ((_err = xltEncList(SOURCE_LIST, REQUIRED, ((SmlSearchPtr_t) pContent)->sourceList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1001 // Lang?
1002 if ((_err = xltEncBlock(TN_LANG, OPTIONAL, ((SmlSearchPtr_t) pContent)->lang, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1003 // Meta
1004 if ((_err = xltEncBlock(TN_META, REQUIRED, ((SmlSearchPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1005 // Dsta
1006 if ((_err = xltEncBlock(TN_DATA, REQUIRED, ((SmlSearchPtr_t) pContent)->data, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1007 // End tag
1008 if ((_err = xltGenerateTag(TN_SEARCH, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1009 break;
1010#endif
1011
1012 case TN_STATUS:
1013 // Begin tag
1014 if ((_err = xltGenerateTag(TN_STATUS, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1015 // CmdID
1016 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlStatusPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1017 // MsgRef?
1018 if ((_err = xltEncBlock(TN_MSGREF, REQUIRED, ((SmlStatusPtr_t) pContent)->msgRef, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1019 // CmdRef
1020 if ((_err = xltEncBlock(TN_CMDREF, REQUIRED, ((SmlStatusPtr_t) pContent)->cmdRef, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1021 // Cmd
1022 if ((_err = xltEncBlock(TN_CMD, REQUIRED, ((SmlStatusPtr_t) pContent)->cmd, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1023 // TargetRefList?
1024 if ((_err = xltEncList(TARGETREF_LIST, OPTIONAL, ((SmlStatusPtr_t) pContent)->targetRefList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1025 // SourceRefList?
1026 if ((_err = xltEncList(SOURCEREF_LIST, OPTIONAL, ((SmlStatusPtr_t) pContent)->sourceRefList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1027 // Cred?
1028 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlStatusPtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1029 // Chal?
1030 if ((_err = xltEncBlock(TN_CHAL, OPTIONAL, ((SmlStatusPtr_t) pContent)->chal, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1031 // Data
1032 if ((_err = xltEncBlock(TN_DATA, REQUIRED, ((SmlStatusPtr_t) pContent)->data, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1033 // Item*
1034 if ((_err = xltEncList(ITEM_LIST, OPTIONAL, ((SmlStatusPtr_t) pContent)->itemList, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1035 // End tag
1036 if ((_err = xltGenerateTag(TN_STATUS, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1037 break;
1038
1039 case TN_SYNC:
1040 // Begin tag
1041 if ((_err = xltGenerateTag(TN_SYNC, TT_BEG, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1042 // CmdID
1043 if ((_err = xltEncBlock(TN_CMDID, REQUIRED, ((SmlSyncPtr_t) pContent)->cmdID, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1044 // NoResp?
1045 if ((_err = xltEncBlock(TN_NORESP, OPTIONAL, &((SmlSyncPtr_t) pContent)->flags, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1046 // Cred?
1047 if ((_err = xltEncBlock(TN_CRED, OPTIONAL, ((SmlSyncPtr_t) pContent)->cred, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1048 // Target?
1049 if ((_err = xltEncBlock(TN_TARGET, OPTIONAL, ((SmlSyncPtr_t) pContent)->target, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1050 // Source?
1051 if ((_err = xltEncBlock(TN_SOURCE, OPTIONAL, ((SmlSyncPtr_t) pContent)->source, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1052 // Meta?
1053 if ((_err = xltEncBlock(TN_META, OPTIONAL, ((SmlSyncPtr_t) pContent)->meta, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1054 // NumberOfChanges?
1055 if ((_err = xltEncBlock(TN_NUMBEROFCHANGES, OPTIONAL, ((SmlSyncPtr_t) pContent)->noc, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1056 // End tag in TN_SYNC_END
1057 break;
1058
1059 case TN_SYNC_END:
1060 //End tag
1061 if ((_err = xltGenerateTag(TN_SYNC, TT_END, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1062 break;
1063
1064 case TN_ARCHIVE:
1065 //set the flag in the (WB)XML document if the flag is in the pContent
1066 if ((*((Flag_t*)pContent)) & (SmlArchive_f0x8000)) {
1067 if ((_err = xltGenerateTag(tagId, TT_ALL, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1068 }
1069 break;
1070
1071 case TN_SFTDEL:
1072 //set the flag in the (WB)XML document if the flag is in the pContent
1073 if ((*((Flag_t *) pContent)) & (SmlSftDel_f0x4000)) {
1074 if ((_err = xltGenerateTag(tagId, TT_ALL, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1075 }
1076 break;
1077
1078 case TN_MOREDATA:
1079 //set the flag in the (WB)XML document if the flag is in the pContent
1080 if ((*((Flag_t *) pContent)) & (SmlMoreData_f0x0400)) {
1081 if ((_err = xltGenerateTag(tagId, TT_ALL, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1082 }
1083 break;
1084
1085 case TN_NORESULTS:
1086 //set the flag in the (WB)XML document if the flag is in the pContent
1087 if ((*((Flag_t *) pContent)) & (SmlNoResults_f0x0200)) {
1088 if ((_err = xltGenerateTag(tagId, TT_ALL, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1089 }
1090 break;
1091
1092 case TN_NORESP:
1093 //set the flag in the (WB)XML document if the flag is in the pContent
1094 if ((*((Flag_t *) pContent)) & (SmlNoResp_f0x0100)){
1095 if ((_err = xltGenerateTag(tagId, TT_ALL, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1096 }
1097 break;
1098
1099 case TN_FINAL:
1100 //set the flag in the (WB)XML document if the flag is in the pContent
1101 if ((*((Flag_t *) pContent)) & (SmlFinal_f0x0001)) {
1102 if ((_err = xltGenerateTag(tagId, TT_ALL, enc, pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK0x00) return _err;
1103 }
1104 break;
1105
1106 default:
1107 // all leaf nodes (PCDATA#)
1108 return xltEncPcdata(tagId, reqOptFlag, pContent, enc, pBufMgr, attFlag);
1109
1110 }
1111 return SML_ERR_OK0x00;
1112}
1113
1114Ret_t xltEncPcdata(XltTagID_t tagId, XltRO_t reqOptFlag, const VoidPtr_t pContent, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr, SmlPcdataExtension_t attFlag) {
1115 //Return variable
1116 Ret_t _err;
1117
1118 //generate PCDATA begin tag
1119 if ((_err = xltGenerateTag(tagId, TT_BEG, enc, pBufMgr, attFlag)) != SML_ERR_OK0x00) return _err;
1120
1121 //write the pContent to the buffer according the encoding type
1122 switch ((int)enc) {
1123#ifdef __SML_WBXML__
1124 case SML_WBXML: {
1125 switch (((SmlPcdataPtr_t)pContent)->contentType) {
1126 case SML_PCDATA_STRING:
1127 if ((_err = wbxmlWriteTypeToBuffer(((SmlPcdataPtr_t)pContent)->content, STR_I, ((SmlPcdataPtr_t)pContent)->length, pBufMgr)) != SML_ERR_OK0x00) return _err;
1128 break;
1129 // Note: SML_PCDATA_CDATA case added by luz to allow direct translation from XML to WBXML
1130 case SML_PCDATA_CDATA:
1131 case SML_PCDATA_OPAQUE:
1132 if ((_err = wbxmlWriteTypeToBuffer(((SmlPcdataPtr_t)pContent)->content, OPAQUE, ((SmlPcdataPtr_t)pContent)->length, pBufMgr)) != SML_ERR_OK0x00) return _err;
1133 break;
1134#ifdef __USE_EXTENSIONS__
1135 case SML_PCDATA_EXTENSION:
1136 if ((_err = xltBuildExtention(((SmlPcdataPtr_t)pContent)->extension, reqOptFlag, ((SmlPcdataPtr_t)pContent)->content, enc, pBufMgr)) != SML_ERR_OK0x00) return _err;
1137 break;
1138#endif
1139 default:
1140 // 2003-11-24: Tomy to deal with pcdata empty extensions (for example <Meta></Meta> which is valid)
1141 // refer to xltdec.c to see that empty extensions result in SmlPcdataPtr_t with all fields (data) set to 0
1142 if (((SmlPcdataPtr_t)pContent)->contentType != SML_PCDATA_UNDEFINED ||
1143 ((SmlPcdataPtr_t)pContent)->extension != SML_EXT_UNDEFINED ||
1144 ((SmlPcdataPtr_t)pContent)->length != 0 ||
1145 ((SmlPcdataPtr_t)pContent)->content != NULL((void*)0))
1146 return SML_ERR_XLT_INVAL_PCDATA_TYPE0x2003;
1147 // return SML_ERR_XLT_INVAL_PCDATA_TYPE;
1148 // end modified by Tomy
1149 }; // eof switch(contenttype)
1150 break;
1151 } // case WBXML
1152#endif // eof WBXML
1153
1154#ifdef __SML_XML__
1155 case SML_XML: {
1156 MemPtr_t _tmpStr;
1157 MemPtr_t p;
1158 MemSize_t len,n;
1159 char c;
1160 switch (((SmlPcdataPtr_t)pContent)->contentType) {
1161 // Note: SML_PCDATA_OPAQUE case added by luz to allow direct translation from WBXML to XML
1162 #ifdef PCDATA_OPAQUE_AS_CDATA1
1163 case SML_PCDATA_OPAQUE:
1164 #endif
1165 case SML_PCDATA_CDATA:
1166 stringAsCData:
1167 {
1168 // %%% luz 2006-09-07 : made completely CDATA nesting safe
1169 // add CDATA
1170 _tmpStr = (MemPtr_t) "<![CDATA[";
1171 if ((_err = xltAddToBuffer(_tmpStr, smlLibStrlen((String_t)_tmpStr), pBufMgr)) != SML_ERR_OK0x00) return _err;
1172 // search and escape possibly contained ]]> sequences
1173 p=((SmlPcdataPtr_t)pContent)->content;
1174 len=((SmlPcdataPtr_t)pContent)->length;
1175 n=0;
1176 while (n+2<len) {
1177 if (p[n]==']' && p[n+1]==']' && p[n+2]=='>') {
1178 // we must substitute "]]>" with "]]>]<![CDATA[]>"
1179 // - copy what we have so far (includes ]]>)
1180 n+=3;
1181 if ((_err = xltAddToBuffer(p, n, pBufMgr)) != SML_ERR_OK0x00) return _err;
1182 // - add extra code needed
1183 _tmpStr = (MemPtr_t) "]<![CDATA[]>";
1184 if ((_err = xltAddToBuffer(_tmpStr, smlLibStrlen((String_t)_tmpStr), pBufMgr)) != SML_ERR_OK0x00) return _err;
1185 // - restart where we are now
1186 p+=n; // first char after ]]>
1187 len-=n; // remaining length
1188 n=0; // processed chars
1189 }
1190 else {
1191 n++; // just go to next char
1192 }
1193 }
1194 // add remaining data
1195 if ((_err = xltAddToBuffer(p, len, pBufMgr)) != SML_ERR_OK0x00) return _err;
1196 // add end of CDATA marker
1197 _tmpStr = (MemPtr_t) "]]>";
1198 if ((_err = xltAddToBuffer(_tmpStr, smlLibStrlen((String_t)_tmpStr), pBufMgr)) != SML_ERR_OK0x00) return _err;
1199 break;
1200 }
1201 // Note: SyncFest #5 shows that <![CDATA[ is not correctly parsed by the RTK
1202 // so we don't use it and risk the danger of failing on payload which has
1203 // XML in it.
1204 #ifndef PCDATA_OPAQUE_AS_CDATA1
1205 case SML_PCDATA_OPAQUE:
1206 #endif
1207 case SML_PCDATA_STRING: {
1208 // %%% luz 2006-09-07 : check for invalid characters that would break XML and use CDATA instead
1209 p=((SmlPcdataPtr_t)pContent)->content;
1210 len=((SmlPcdataPtr_t)pContent)->length;
1211 while (len-->0) {
1212 c=*p++;
1213 if (c=='&' || c=='<' || c=='>')
1214 goto stringAsCData; // encode as CDATA
1215 }
1216 // ok, string is clean and does not need CDATA
1217 if ((_err = xltAddToBuffer(((SmlPcdataPtr_t)pContent)->content, ((SmlPcdataPtr_t)pContent)->length, pBufMgr)) != SML_ERR_OK0x00) return _err;
1218 break;
1219 }
1220#ifdef __USE_EXTENSIONS__
1221 case SML_PCDATA_EXTENSION: {
1222 if ((_err = xltBuildExtention(((SmlPcdataPtr_t)pContent)->extension, reqOptFlag, ((SmlPcdataPtr_t)pContent)->content, enc, pBufMgr)) != SML_ERR_OK0x00) return _err;
1223 break;
1224 }
1225#endif
1226 default: {
1227 // 2003-11-24: Tomy to deal with pcdata empty extensions (for example <Meta></Meta> which is valid)
1228 // refer to xltdec.c to see that empty extensions result in SmlPcdataPtr_t with all fields (data) set to 0
1229 if (((SmlPcdataPtr_t)pContent)->contentType != SML_PCDATA_UNDEFINED ||
1230 ((SmlPcdataPtr_t)pContent)->extension != SML_EXT_UNDEFINED ||
1231 ((SmlPcdataPtr_t)pContent)->length != 0 ||
1232 ((SmlPcdataPtr_t)pContent)->content != NULL((void*)0))
1233 return SML_ERR_XLT_INVAL_PCDATA_TYPE0x2003;
1234 // return SML_ERR_XLT_INVAL_PCDATA_TYPE;
1235 // end modified by Tomy
1236 }
1237 } // switch tags
1238 break;
1239 } // case XML
1240#endif // eof XML
1241
1242 default:
1243 return SML_ERR_XLT_ENC_UNK0x2007;
1244 } // eof switch(enc)
1245
1246 //generate PCDATA END tag
1247 if ((_err = xltGenerateTag(tagId, TT_END, enc, pBufMgr, attFlag)) != SML_ERR_OK0x00) return _err;
1248 return SML_ERR_OK0x00;
1249}
1250
1251/**
1252 * Generates a list element which is not directly related to a tag
1253 *
1254 * @pre pList holds a valid list structure
1255 * listId contains a valid SyncML list ID
1256 * @post the (WB)XML buffer in the pBufMgr structure contains the
1257 * encoded (WB)XML list
1258 * @param listId (IN)
1259 * the ID of the list to generate (e.g. TARGET_LIST, ...)
1260 * @param reqOptFlag (IN)
1261 * flag if the block is required or optional
1262 * @param pList (IN)
1263 * reference to the list to process
1264 * @param enc (IN)
1265 * the encoding constant (SML_WBXML or SML_XML)
1266 * @param pBufMgr (IN/OUT)
1267 * pointer to a structure containing buffer management elements
1268 * @param attFlag (IN)
1269 * indicates if the encoded tag contain Attributes
1270 * in namespace extensions
1271 * @return shows error codes of function,\n
1272 * 0, if OK
1273 */
1274Ret_t xltEncList(XltListType_t listId, XltRO_t reqOptFlag, VoidPtr_t pList, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr, SmlPcdataExtension_t attFlag)
1275{
1276 //Return variable
1277 Ret_t _err;
1278
1279 //check if list is required or not
1280 if ((reqOptFlag == REQUIRED) && (pList == NULL((void*)0)))
1281 return SML_ERR_XLT_MISSING_CONT0x2001;
1282 else if (pList == NULL((void*)0))
1283 return SML_ERR_OK0x00;
1284
1285 //encode the different list types
1286 switch ((int)listId)
1287 {
1288 case ITEM_LIST:
1289 {
1290 do
1291 {
1292 if ((_err = xltEncBlock(TN_ITEM, OPTIONAL, ((SmlItemListPtr_t)pList)->item, enc, pBufMgr, attFlag)) != SML_ERR_OK0x00) return _err;
1293 pList = ((SmlItemListPtr_t)pList)->next;
1294 } while ((SmlItemListPtr_t)pList != NULL((void*)0));
1295
1296 break;
1297 }
1298 case SOURCE_LIST:
1299 {
1300 do
1301 {
1302 if ((_err = xltEncBlock(TN_SOURCE, OPTIONAL, ((SmlSourceListPtr_t)pList)->source, enc, pBufMgr, attFlag)) != SML_ERR_OK0x00) return _err;
1303 pList = ((SmlSourceListPtr_t)pList)->next;
1304 } while ((SmlSourceListPtr_t)pList != NULL((void*)0));
1305
1306 break;
1307 }
1308 case TARGETREF_LIST:
1309 {
1310 do
1311 {
1312 if ((_err = xltEncBlock(TN_TARGETREF, OPTIONAL, ((SmlTargetRefListPtr_t)pList)->targetRef, enc, pBufMgr, attFlag)) != SML_ERR_OK0x00) return _err;
1313 pList = ((SmlTargetRefListPtr_t)pList)->next;
1314 } while ((SmlTargetRefListPtr_t)pList != NULL((void*)0));
1315
1316 break;
1317 }
1318 case SOURCEREF_LIST:
1319 {
1320 do
1321 {
1322 if ((_err = xltEncBlock(TN_SOURCEREF, OPTIONAL, ((SmlSourceRefListPtr_t)pList)->sourceRef, enc, pBufMgr, attFlag)) != SML_ERR_OK0x00) return _err;
1323 pList = ((SmlSourceRefListPtr_t)pList)->next;
1324 } while ((SmlSourceRefListPtr_t)pList != NULL((void*)0));
1325
1326 break;
1327 }
1328 case MAPITEM_LIST:
1329 {
1330 do
1331 {
1332 if ((_err = xltEncBlock(TN_MAPITEM, OPTIONAL, ((SmlMapItemListPtr_t)pList)->mapItem, enc, pBufMgr, attFlag)) != SML_ERR_OK0x00) return _err;
1333 pList = ((SmlMapItemListPtr_t)pList)->next;
1334 } while ((SmlMapItemListPtr_t)pList != NULL((void*)0));
1335
1336 break;
1337 }
1338 default:
1339 return SML_ERR_XLT_INVAL_LIST_TYPE0x2004;
1340 }
1341
1342 return SML_ERR_OK0x00;
1343}
1344
1345/**
1346 * Generates a (WB)XML tag
1347 *
1348 * @pre valid parameters
1349 * @post the buffer contains a new tag
1350 * @param tagId (IN)
1351 * the tag ID
1352 * @param TagType (IN)
1353 * the tag type (begin tag, end tag, ...)
1354 * @param enc (IN)
1355 * the encoding constant (SML_WBXML or SML_XML)
1356 * @param attFlag (IN)
1357 * indicates if the encoded tag contain Attributes
1358 * in namespace extensions
1359 * @param pBufMgr (IN/OUT)
1360 * pointer to a structure containing buffer management elements
1361 * @return shows error codes of function,\n
1362 * 0, if OK
1363 */
1364Ret_t xltGenerateTag(XltTagID_t tagId, XltTagType_t TagType, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr, SmlPcdataExtension_t attFlag)
1365{
1366
1367 Ret_t _err;
1368#ifdef __SML_WBXML__
1369 MemByte_t _switchpage = XLT_SWITCHPAGE0x00;
1370#endif
1371
1372 switch ((int)enc) {
1373#ifdef __SML_WBXML__
1374 case SML_WBXML:
1375 /* in WBXML codepage switches are done for starting tags only */
1376 if (TagType != TT_END) {
1377 //codepage switching with wbxml instead of namespace
1378 if (getCodePage(attFlag) != getCodePage(pBufMgr->smlCurExt)) {
1379 MemByte_t _newcp = getCodePage(attFlag);
1380 if ((_err = wbxmlWriteTypeToBuffer((MemPtr_t)(&_switchpage), TAG, 1, pBufMgr)) != SML_ERR_OK0x00) return _err;
1381 if ((_err = wbxmlWriteTypeToBuffer((MemPtr_t)(&_newcp), TAG, 1, pBufMgr)) != SML_ERR_OK0x00) return _err;
1382 }
1383
1384 if (attFlag != pBufMgr->smlCurExt) {
1385 pBufMgr->switchExtTag = tagId;
1386 pBufMgr->smlLastExt = pBufMgr->smlCurExt;
1387 pBufMgr->smlCurExt = attFlag;
1388 }
1389 } // for TagType
1390 return wbxmlGenerateTag(tagId, TagType, pBufMgr);
1391#endif
1392#ifdef __SML_XML__
1393 case SML_XML:
1394
1395 if (attFlag != pBufMgr->smlCurExt) {
1396 pBufMgr->switchExtTag = tagId;
1397 pBufMgr->smlLastExt = pBufMgr->smlCurExt;
1398 pBufMgr->smlCurExt = attFlag;
1399 }
1400 return xmlGenerateTag(tagId, TagType, pBufMgr, attFlag);
1401#endif
1402 default:
1403 return SML_ERR_XLT_ENC_UNK0x2007;
1404 }
1405
1406 //return SML_ERR_XLT_ENC_UNK;NOT NEEDED
1407}
1408
1409#ifdef __USE_EXTENSIONS__
1410/* Entrypoint for SubDTD's. If we reached this point we already know
1411 * a) we have data fora sub-DTD to encode and
1412 * b) we know which sub-DTD should be encoded.
1413 * So just call the appropriate sub-DTD encoder and thats it.
1414 */
1415Ret_t xltBuildExtention(SmlPcdataExtension_t extId, XltRO_t reqOptFlag, VoidPtr_t pContent, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr) {
1416
1417 switch (extId) {
1418#ifdef __USE_METINF__
1419 case SML_EXT_METINF:
1420 /* a metaInf DTD always starts with this token */
1421 return metinfEncBlock(TN_METINF_METINF,reqOptFlag,pContent,enc,pBufMgr,SML_EXT_METINF);
1422 break;
1423#endif
1424#ifdef __USE_DEVINF__
1425 case SML_EXT_DEVINF:
1426 /* a deviceInf DTD always starts with this token */
1427 /* we have to choose, wether we have to encode the DevInf as XML or WBXML */
1428 /* in the latter case, we need a special treatment of this sub-dtd, as we have */
1429 /* to put it into a SML_PCDATA_OPAQUE field ... */
1430 if (enc == SML_XML)
1431 return devinfEncBlock(TN_DEVINF_DEVINF,reqOptFlag,pContent,enc,pBufMgr,SML_EXT_DEVINF);
1432 else
1433 return subdtdEncWBXML(TN_DEVINF_DEVINF,reqOptFlag,pContent,SML_WBXML,pBufMgr,SML_EXT_DEVINF);
1434 break;
1435#endif
1436 /* oops - we don not know about that extension -> bail out */
1437 default:
1438 return SML_ERR_XLT_INVAL_EXT0x2016;
1439 }
1440 //return SML_ERR_OK;CAN NOT BE REACHED
1441}
1442
1443
1444/* Sub DTD's need a special treatment when used together with WBXML.
1445 * We need to eoncode them as a complete WBXML message including headers and stuff
1446 * and store the result within an SML_PCDATA_OPAQUE datafield.
1447 * To archieve this we create a new encoder, encode the message and finally
1448 * copy the result into the allready existing encoder.
1449 */
1450#ifdef __SML_WBXML__
1451Ret_t subdtdEncWBXML(XltTagID_t tagId, XltRO_t reqOptFlag, const VoidPtr_t pContent, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr, SmlPcdataExtension_t attFlag)
1452{
1453 #ifdef __USE_DEVINF__
1454 Ret_t _err = SML_ERR_OK0x00;
1455 #endif
1456
1457 /* Double the size of SubBufSize for the memory is small for some complex
1458 * content.
1459 */
1460 MemSize_t SubBufSize = 12000 * 2; // for starters we use 12kB for each sub DTD to encode in WBXML
1461 BufferMgmtPtr_t pSubBufMgr = NULL((void*)0);
1462
1463 /* Even the doubled size was still too small. Instead of
1464 hard-coding the size, make it as large as the buffer we are
1465 copying into. The size of that one can be configured by the
1466 user of the toolkit. -- Patrick Ohly */
1467 MemSize_t VarSubBufSize = pBufMgr->smlXltBufferLen - pBufMgr->smlXltWrittenBytes;
1468 if (VarSubBufSize > SubBufSize) {
1469 SubBufSize = VarSubBufSize;
1470 }
1471
1472 // first create a sub buffer
1473 pSubBufMgr = (BufferMgmtPtr_t)smlLibMalloc(sizeof(BufferMgmt_t));
1474 if (pSubBufMgr == NULL((void*)0)) {
1475 if (enc && pContent && reqOptFlag && tagId) {
1476 }
1477 return SML_ERR_NOT_ENOUGH_SPACE0x11;
1478 }
1479
1480 smlLibMemset(pSubBufMgr, 0,sizeof(BufferMgmt_t));
1481 pSubBufMgr->smlXltBufferLen = SubBufSize;
1482 pSubBufMgr->smlXltBufferP = (MemPtr_t)smlLibMalloc(SubBufSize);
1483 if (pSubBufMgr->smlXltBufferP == NULL((void*)0)) {
1484 smlLibFree(pSubBufMgr);
1485 return SML_ERR_NOT_ENOUGH_SPACE0x11;
1486 }
1487
1488 smlLibMemset(pSubBufMgr->smlXltBufferP, 0, SubBufSize);
1489 pSubBufMgr->smlXltStoreBufP = pSubBufMgr->smlXltBufferP;
1490 pSubBufMgr->smlXltWrittenBytes = 0;
1491 pSubBufMgr->smlActiveExt = pBufMgr->smlActiveExt;
1492 pSubBufMgr->smlCurExt = pBufMgr->smlCurExt;
1493 pSubBufMgr->smlLastExt = pBufMgr->smlLastExt;
1494 pSubBufMgr->spaceEvaluation = pBufMgr->spaceEvaluation;
1495 pSubBufMgr->vers = pBufMgr->vers;
1496
1497 // check if we want to use numeric or textual FPI
1498 if (SyncMLDevInfWBXMLPublicID[pBufMgr->vers]==0) {
1499 // textual FPI
1500 // - get the FPI string
1501 const char *FPIstring = SyncMLDevInfFPI[pBufMgr->vers];
1502 Short_t FPIsize = smlLibStrlen(FPIstring);
1503 if (pSubBufMgr->spaceEvaluation == 0) {
1504 // - create the WBXML header
1505 pSubBufMgr->smlXltBufferP[0] = 0x02; // WBXML Version 1.2
1506 pSubBufMgr->smlXltBufferP[1] = 0x00; // use Stringtable for ID
1507 pSubBufMgr->smlXltBufferP[2] = 0x00; // empty/unknown public ID
1508 pSubBufMgr->smlXltBufferP[3] = 0x6A; // charset encoding UTF-8
1509 pSubBufMgr->smlXltBufferP[4] = FPIsize; // %%% not fixed=0x1D!! lenght of stringtable = length of FPIsize
1510 pSubBufMgr->smlXltBufferP += 5;
1511 // - Generate textual FPI
1512 smlLibMemmove(pSubBufMgr->smlXltBufferP, FPIstring, FPIsize);
1513 pSubBufMgr->smlXltBufferP += FPIsize;
1514 }
1515 // in case of space evaluation, just count the number of written bytes
1516 pSubBufMgr->smlXltWrittenBytes = 5 + FPIsize;
1517 }
1518 else {
1519 // numeric FPI, no string table
1520 if (pSubBufMgr->spaceEvaluation == 0) {
1521 // - create the WBXML header
1522 unsigned short fpi=SyncMLDevInfWBXMLPublicID[pBufMgr->vers];
1523 pSubBufMgr->smlXltBufferP[0] = 0x02; // WBXML Version 1.2
1524 pSubBufMgr->smlXltBufferP[1] = ((fpi>>7) & 0x7F)+0x80; // upper 7 bit
1525 pSubBufMgr->smlXltBufferP[2] = (fpi & 0x7F); // lower 7 bits
1526 pSubBufMgr->smlXltBufferP[3] = 0x6A; // charset encoding UTF-8
1527 pSubBufMgr->smlXltBufferP[4] = 0; // no string table
1528 pSubBufMgr->smlXltBufferP += 5;
1529 }
1530 // in case of space evaluation, just count the number of written bytes
1531 pSubBufMgr->smlXltWrittenBytes = 5;
1532 }
1533
1534 // do the encoding
1535 switch (attFlag) {
1536 #ifdef __USE_DEVINF__
1537 case SML_EXT_DEVINF:
1538 if ((_err = devinfEncBlock(TN_DEVINF_DEVINF,reqOptFlag,pContent,enc,pSubBufMgr,SML_EXT_DEVINF)) != SML_ERR_OK0x00) {
1539 smlLibFree(pSubBufMgr->smlXltStoreBufP);
1540 smlLibFree(pSubBufMgr);
1541 return _err;
1542 }
1543 break;
1544 #endif
1545 /* oops - we don not know about that extension -> bail out */
1546 default:
1547 smlLibFree(pSubBufMgr->smlXltStoreBufP);
1548 smlLibFree(pSubBufMgr);
1549 return SML_ERR_XLT_INVAL_EXT0x2016;
1550 }
1551
1552 #ifdef __USE_DEVINF__
1553 // move it to the 'real' encoder buffer
1554 // now set up the OPAQUE field
1555 if (pBufMgr->spaceEvaluation == 0) {
1556 pBufMgr->smlXltBufferP[0] = 0xC3; // OPAQUE data identifier
1557 pBufMgr->smlXltBufferP += 1;
1558
1559 wbxmlOpaqueSize2Buf(pSubBufMgr->smlXltWrittenBytes, pBufMgr);
1560
1561 smlLibMemmove(pBufMgr->smlXltBufferP, pSubBufMgr->smlXltStoreBufP, pSubBufMgr->smlXltWrittenBytes);
1562 pBufMgr->smlXltBufferP += pSubBufMgr->smlXltWrittenBytes;
1563 pBufMgr->smlXltWrittenBytes += pSubBufMgr->smlXltWrittenBytes;
1564 } else {
1565 pBufMgr->smlXltWrittenBytes++;
1566 wbxmlOpaqueSize2Buf(pSubBufMgr->smlXltWrittenBytes, pBufMgr);
1567 pBufMgr->smlXltWrittenBytes += pSubBufMgr->smlXltWrittenBytes;
1568 }
1569
1570 // clean up the temporary stuff
1571 smlLibFree(pSubBufMgr->smlXltStoreBufP);
1572 smlLibFree(pSubBufMgr);
1573
1574 return _err;
1575#endif
1576}
1577#endif
1578#endif