📄 xltenc.c
字号:
#endif default: { _err = SML_ERR_XLT_ENC_UNK; } } if (_err != SML_ERR_OK) { smlLibFree(_pBufMgr); smlLibFree(_pEncoder); return _err; } // SyncML Tag if ((_err = xltGenerateTag(TN_SYNCML, TT_BEG, enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK) { smlLibFree(_pBufMgr); smlLibFree(_pEncoder); return _err; } // Generate SmlSyncHdr if ((_err = xltEncBlock(TN_SYNCHDR, REQUIRED, pHeader, enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK) { smlLibFree(_pBufMgr); smlLibFree(_pEncoder); return _err; } // SyncBody Tag if ((_err = xltGenerateTag(TN_SYNCBODY, TT_BEG, enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK) { smlLibFree(_pBufMgr); smlLibFree(_pEncoder); return _err; } _pEncoder->cur_ext = _pBufMgr->smlCurExt; _pEncoder->last_ext = _pBufMgr->smlLastExt; _pEncoder->end_tag_size = _pBufMgr->endTagSize; *ppBufPos = _pBufMgr->smlXltBufferP; smlLibFree(_pBufMgr); _pEncoder->final = 0; *ppEncoder = (XltEncoderPtr_t)_pEncoder; return SML_ERR_OK;}/** * FUNCTION: smlXltEncAppend * * Generates (WB)XML code and appends it to the XML buffer. * * PRE-Condition: pEncoder holds the initialized encoder structure. * the initialization takes place in the xltEncAppend function * pContent has to contain a valid content structure structure * pBufEnd must point to the end of the (WB)XML buffer * ppBufPos has to be initialized to the start point of the * (WB)XML buffer. * * * POST-Condition: After the function call ppBufPos points to the * first free byte in the buffer behind the (WB)XML document * * IN: pEncoder, the encoder object * pe, the protocol element (PE_ADD, ...) * pBufEnd, pointer to the end of the buffer to write on * pContent, the content to append to the SyncML document * * IN/OUT: ppBufPos, current position of the bufferpointer * * RETURN: shows error codes of function, * 0, if OK * Possible Error Codes: * SML_ERR_XLT_MISSING_CONT * SML_ERR_XLT_BUF_ERR * SML_ERR_XLT_INVAL_ELEM_TYPE * SML_ERR_XLT_INVAL_LIST_TYPE * SML_ERR_XLT_INVAL_TAG_TYPE * SML_ERR_XLT_ENC_UNK * SML_ERR_XLT_INVAL_PROTO_ELEM */Ret_t xltEncAppend(const XltEncoderPtr_t pEncoder, SmlProtoElement_t pe, const MemPtr_t pBufEnd, const VoidPtr_t pContent, MemPtr_t *ppBufPos){ // Return variable Ret_t _err; XltTagID_t tagID = TN_UNDEF; // encoding type SmlEncoding_t _enc; //Structure containing buffer pointers, length and written bytes BufferMgmtPtr_t _pBufMgr; if ((_pBufMgr = (BufferMgmtPtr_t)smlLibMalloc(sizeof(BufferMgmt_t))) == NULL) return SML_ERR_NOT_ENOUGH_SPACE; smlLibMemset(_pBufMgr, 0, sizeof(BufferMgmt_t)); //get the encoding type _enc = pEncoder->enc; _pBufMgr->vers = pEncoder->vers; // %%% luz:2003-07-31: pass SyncML version to bufmgr _pBufMgr->smlXltBufferP = *ppBufPos; _pBufMgr->smlXltBufferLen = pBufEnd - *ppBufPos; _pBufMgr->smlXltStoreBufP = _pBufMgr->smlXltBufferP; _pBufMgr->smlXltWrittenBytes = 0; _pBufMgr->smlActiveExt = SML_EXT_UNDEFINED; _pBufMgr->switchExtTag = TN_UNDEF; _pBufMgr->spaceEvaluation = ((pEncoder->space_evaluation == NULL) ? 0 : 1); // %%% luz 2002-09-03: evaluation may not mess with encoder state if ( _pBufMgr->spaceEvaluation) { // spaceEval state _pBufMgr->smlCurExt = pEncoder->space_evaluation->cur_ext; _pBufMgr->smlLastExt = pEncoder->space_evaluation->last_ext; } else { // normal encoder state _pBufMgr->smlCurExt = pEncoder->cur_ext; _pBufMgr->smlLastExt = pEncoder->last_ext; } _pBufMgr->endTagSize =0; _err = getTNbyPE(pe, &tagID); _err = xltEncBlock(tagID, REQUIRED, pContent, _enc, _pBufMgr, SML_EXT_UNDEFINED); if (_err != SML_ERR_OK) { smlLibFree(_pBufMgr); return _err; } if (pEncoder->space_evaluation != NULL) { // Only calculating size pEncoder->space_evaluation->written_bytes += _pBufMgr->smlXltWrittenBytes; pEncoder->space_evaluation->end_tag_size += _pBufMgr->endTagSize; // save it only into evaluation state pEncoder->space_evaluation->cur_ext = _pBufMgr->smlCurExt; pEncoder->space_evaluation->last_ext = _pBufMgr->smlLastExt; } else { // really generating data pEncoder->end_tag_size += _pBufMgr->endTagSize; // save it into encoder state pEncoder->cur_ext = _pBufMgr->smlCurExt; pEncoder->last_ext = _pBufMgr->smlLastExt; } *ppBufPos = _pBufMgr->smlXltBufferP; smlLibFree(_pBufMgr); return SML_ERR_OK;}/** * FUNCTION: smlXltEncTerminate * * Filnalizes the (WB)XML document and returns the size of written bytes to * the workspace module * * PRE-Condition: pEncoder holds the initialized encoder structure. * the initialization takes place in the xltEncAppend function * pBufEnd must point to the end of the (WB)XML buffer * ppBufPos has to be initialized to the start point of the * (WB)XML buffer. * * POST-Condition: After the function call ppBufPos points to the * first free byte in the buffer behind the (WB)XML document * * IN: pEncoder, the encoder object * pBufEnd, pointer to the end of the buffer to write on * * IN/OUT: ppBufPos, current position of the bufferpointer * * RETURN: shows error codes of function, * 0, if OK * Possible Error Codes: * SML_ERR_XLT_BUF_ERR * SML_ERR_XLT_MISSING_CONT * SML_ERR_XLT_INVAL_ELEM_TYPE * SML_ERR_XLT_INVAL_LIST_TYPE * SML_ERR_XLT_INVAL_TAG_TYPE * SML_ERR_XLT_ENC_UNK * SML_ERR_XLT_INVAL_PROTO_ELEM */Ret_t xltEncTerminate(const XltEncoderPtr_t pEncoder, const MemPtr_t pBufEnd, MemPtr_t *ppBufPos){ // Return variable Ret_t _err; // encoding type SmlEncoding_t _enc; //Structure containing buffer pointers, length and written bytes BufferMgmtPtr_t _pBufMgr; //get the encoding type _enc = pEncoder->enc; //Initialize buffer variables if ((_pBufMgr = smlLibMalloc(sizeof(BufferMgmt_t))) == NULL) { smlLibFree(pEncoder); return SML_ERR_NOT_ENOUGH_SPACE; } _pBufMgr->vers = pEncoder->vers; // %%% luz:2003-07-31: pass SyncML version to bufmgr _pBufMgr->smlXltWrittenBytes = 0; _pBufMgr->smlXltBufferP = *ppBufPos; _pBufMgr->smlXltStoreBufP = _pBufMgr->smlXltBufferP; _pBufMgr->smlXltBufferLen = pBufEnd - *ppBufPos; _pBufMgr->smlCurExt = pEncoder->cur_ext; _pBufMgr->smlLastExt = pEncoder->last_ext; _pBufMgr->smlActiveExt = pEncoder->cur_ext; _pBufMgr->switchExtTag = TN_UNDEF; _pBufMgr->spaceEvaluation = ((pEncoder->space_evaluation == NULL) ? 0 : 1); _pBufMgr->endTagSize =0; if (pEncoder->final == 1) { // Final Flag if ((_err = xltGenerateTag(TN_FINAL, TT_ALL, _enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK) { smlLibFree(_pBufMgr); xltEncReset(pEncoder); return _err; } } // SyncBody End Tag if ((_err = xltGenerateTag(TN_SYNCBODY, TT_END, _enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK) { smlLibFree(_pBufMgr); xltEncReset(pEncoder); return _err; } // SyncML End Tag if ((_err = xltGenerateTag(TN_SYNCML, TT_END, _enc, _pBufMgr, SML_EXT_UNDEFINED)) != SML_ERR_OK) { smlLibFree(_pBufMgr); xltEncReset(pEncoder); return _err; } pEncoder->cur_ext = _pBufMgr->smlCurExt; pEncoder->last_ext = _pBufMgr->smlLastExt; *ppBufPos = _pBufMgr->smlXltBufferP; smlLibFree(_pBufMgr); xltEncReset(pEncoder); return SML_ERR_OK;}Ret_t xltEncReset(XltEncoderPtr_t pEncoder){ if ((pEncoder) && (pEncoder->space_evaluation)) { smlLibFree(pEncoder->space_evaluation); pEncoder->space_evaluation = NULL; } smlLibFree(pEncoder); return SML_ERR_OK;}/** * FUNCTION: smlXltStartEvaluation * * Starts an evaluation run which prevents further API-Calls to write tags - * just the tag-sizes are calculated. Must be sopped via smlEndEvaluation * * IN: XltEncoderPtr_t * the encoder object * *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -