📄 xltenc.c
字号:
//generate PCDATA END tag if ((_err = xltGenerateTag(tagId, TT_END, enc, pBufMgr, attFlag)) != SML_ERR_OK) return _err; return SML_ERR_OK;}/** * FUNCTION: xltEncList * * Generates a list element which is not directly related to a tag * * PRE-Condition: pList holds a valid list structure * listId contains a valid SyncML list ID * * POST-Condition: the (WB)XML buffer in the pBufMgr structure contains the * encoded (WB)XML list * * IN: listId, the ID of the list to generate (e.g. TARGET_LIST, ...) * pList, reference to the list to process * enc, the encoding constant (SML_WBXML or SML_XML) * attFlag, indicates if the encoded tag contain Attributes in namespace extensions * * IN/OUT: pBufMgr, pointer to a structure containing buffer management elements * * RETURN: shows error codes of function, * 0, if OK */Ret_t xltEncList(XltListType_t listId, XltRO_t reqOptFlag, VoidPtr_t pList, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr, SmlPcdataExtension_t attFlag){ //Return variable Ret_t _err; //check if list is required or not if ((reqOptFlag == REQUIRED) && (pList == NULL)) return SML_ERR_XLT_MISSING_CONT; else if (pList == NULL) return SML_ERR_OK; //encode the different list types switch ((int)listId) { case ITEM_LIST: { do { if ((_err = xltEncBlock(TN_ITEM, OPTIONAL, ((SmlItemListPtr_t)pList)->item, enc, pBufMgr, attFlag)) != SML_ERR_OK) return _err; pList = ((SmlItemListPtr_t)pList)->next; } while ((SmlItemListPtr_t)pList != NULL); break; } case SOURCE_LIST: { do { if ((_err = xltEncBlock(TN_SOURCE, OPTIONAL, ((SmlSourceListPtr_t)pList)->source, enc, pBufMgr, attFlag)) != SML_ERR_OK) return _err; pList = ((SmlSourceListPtr_t)pList)->next; } while ((SmlSourceListPtr_t)pList != NULL); break; } case TARGETREF_LIST: { do { if ((_err = xltEncBlock(TN_TARGETREF, OPTIONAL, ((SmlTargetRefListPtr_t)pList)->targetRef, enc, pBufMgr, attFlag)) != SML_ERR_OK) return _err; pList = ((SmlTargetRefListPtr_t)pList)->next; } while ((SmlTargetRefListPtr_t)pList != NULL); break; } case SOURCEREF_LIST: { do { if ((_err = xltEncBlock(TN_SOURCEREF, OPTIONAL, ((SmlSourceRefListPtr_t)pList)->sourceRef, enc, pBufMgr, attFlag)) != SML_ERR_OK) return _err; pList = ((SmlSourceRefListPtr_t)pList)->next; } while ((SmlSourceRefListPtr_t)pList != NULL); break; } case MAPITEM_LIST: { do { if ((_err = xltEncBlock(TN_MAPITEM, OPTIONAL, ((SmlMapItemListPtr_t)pList)->mapItem, enc, pBufMgr, attFlag)) != SML_ERR_OK) return _err; pList = ((SmlMapItemListPtr_t)pList)->next; } while ((SmlMapItemListPtr_t)pList != NULL); break; } default: return SML_ERR_XLT_INVAL_LIST_TYPE; } return SML_ERR_OK;}/** * FUNCTION: xltGenerateTag * * Generates a (WB)XML tag * * PRE-Condition: valis parameters * * POST-Condition: the buffer contains a new tag * * IN: tagId, the tag ID * TagType, the tag type (begin tag, end tag, ...) * enc, the encoding constant (SML_WBXML or SML_XML) * attFlag, indicates if the encoded tag contain Attributes in namespace extensions * * IN/OUT: pBufMgr, pointer to a structure containing buffer management elements * * RETURN: shows error codes of function, * 0, if OK */Ret_t xltGenerateTag(XltTagID_t tagId, XltTagType_t TagType, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr, SmlPcdataExtension_t attFlag){ Ret_t _err;#ifdef __SML_WBXML__ MemByte_t _switchpage = XLT_SWITCHPAGE;#endif switch ((int)enc) {#ifdef __SML_WBXML__ case SML_WBXML: /* in WBXML codepage switches are done for starting tags only */ if (TagType != TT_END) { //codepage switching with wbxml instead of namespace if (getCodePage(attFlag) != getCodePage(pBufMgr->smlCurExt)) { MemByte_t _newcp = getCodePage(attFlag); if ((_err = wbxmlWriteTypeToBuffer((MemPtr_t)(&_switchpage), TAG, 1, pBufMgr)) != SML_ERR_OK) return _err; if ((_err = wbxmlWriteTypeToBuffer((MemPtr_t)(&_newcp), TAG, 1, pBufMgr)) != SML_ERR_OK) return _err; } if (attFlag != pBufMgr->smlCurExt) { pBufMgr->switchExtTag = tagId; pBufMgr->smlLastExt = pBufMgr->smlCurExt; pBufMgr->smlCurExt = attFlag; } } // for TagType return wbxmlGenerateTag(tagId, TagType, pBufMgr); #endif#ifdef __SML_XML__ case SML_XML: if (attFlag != pBufMgr->smlCurExt) { pBufMgr->switchExtTag = tagId; pBufMgr->smlLastExt = pBufMgr->smlCurExt; pBufMgr->smlCurExt = attFlag; } return xmlGenerateTag(tagId, TagType, pBufMgr, attFlag);#endif default: return SML_ERR_XLT_ENC_UNK; } //return SML_ERR_XLT_ENC_UNK;NOT NEEDED}#ifdef __USE_EXTENSIONS__/* Entrypoint for SubDTD's. If we reached this point we already know * a) we have data fora sub-DTD to encode and * b) we know which sub-DTD should be encoded. * So just call the appropriate sub-DTD encoder and thats it. */Ret_t xltBuildExtention(SmlPcdataExtension_t extId, XltRO_t reqOptFlag, VoidPtr_t pContent, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr) { switch (extId) {#ifdef __USE_METINF__ case SML_EXT_METINF: /* a metaInf DTD always starts with this token */ return metinfEncBlock(TN_METINF_METINF,reqOptFlag,pContent,enc,pBufMgr,SML_EXT_METINF); break;#endif #ifdef __USE_DEVINF__ case SML_EXT_DEVINF: /* a deviceInf DTD always starts with this token */ /* we have to choose, wether we have to encode the DevInf as XML or WBXML */ /* in the latter case, we need a special treatment of this sub-dtd, as we have */ /* to put it into a SML_PCDATA_OPAQUE field ... */ if (enc == SML_XML) return devinfEncBlock(TN_DEVINF_DEVINF,reqOptFlag,pContent,enc,pBufMgr,SML_EXT_DEVINF); else return subdtdEncWBXML(TN_DEVINF_DEVINF,reqOptFlag,pContent,SML_WBXML,pBufMgr,SML_EXT_DEVINF); break;#endif /* oops - we don not know about that extension -> bail out */ default: return SML_ERR_XLT_INVAL_EXT; } //return SML_ERR_OK;CAN NOT BE REACHED}/* Sub DTD's need a special treatment when used together with WBXML. * We need to eoncode them as a complete WBXML message including headers and stuff * and store the result within an SML_PCDATA_OPAQUE datafield. * To archieve this we create a new encoder, encode the message and finally * copy the result into the allready existing encoder. */#ifdef __SML_WBXML__Ret_t subdtdEncWBXML(XltTagID_t tagId, XltRO_t reqOptFlag, const VoidPtr_t pContent, SmlEncoding_t enc, BufferMgmtPtr_t pBufMgr, SmlPcdataExtension_t attFlag){ #ifdef __USE_DEVINF__ Ret_t _err = SML_ERR_OK; #endif Short_t SubBufSize = 12000; // for starters we use 12kB for each sub DTD to encode in WBXML BufferMgmtPtr_t pSubBufMgr = NULL; // %%% luz 2003-07-31: ensured that we send the right version here! const char *FPIstring = SyncMLDevInfFPI[pBufMgr->vers]; Short_t FPIsize = smlLibStrlen(FPIstring); // first create a sub buffer pSubBufMgr = (BufferMgmtPtr_t)smlLibMalloc(sizeof(BufferMgmt_t)); if (pSubBufMgr == NULL) { if (enc && pContent && reqOptFlag && tagId) { } return SML_ERR_NOT_ENOUGH_SPACE;} smlLibMemset(pSubBufMgr, 0,sizeof(BufferMgmt_t)); pSubBufMgr->smlXltBufferLen = SubBufSize; pSubBufMgr->smlXltBufferP = (MemPtr_t)smlLibMalloc(SubBufSize); if (pSubBufMgr->smlXltBufferP == NULL) { smlLibFree(pSubBufMgr); return SML_ERR_NOT_ENOUGH_SPACE; } smlLibMemset(pSubBufMgr->smlXltBufferP, 0, SubBufSize); pSubBufMgr->smlXltStoreBufP = pSubBufMgr->smlXltBufferP; pSubBufMgr->smlXltWrittenBytes = 0; pSubBufMgr->smlActiveExt = pBufMgr->smlActiveExt; pSubBufMgr->smlCurExt = pBufMgr->smlCurExt; pSubBufMgr->smlLastExt = pBufMgr->smlLastExt; pSubBufMgr->spaceEvaluation = pBufMgr->spaceEvaluation; // in case of space evaluation, just count the number of written bytes if (pSubBufMgr->spaceEvaluation == 0) { // create the WBXML header pSubBufMgr->smlXltBufferP[0] = 0x02; // WBXML Version 1.2 pSubBufMgr->smlXltBufferP[1] = 0x00; // use Stringtable for ID pSubBufMgr->smlXltBufferP[2] = 0x00; // empty/unknown public ID pSubBufMgr->smlXltBufferP[3] = 0x6A; // charset encoding UTF-8 pSubBufMgr->smlXltBufferP[4] = 0x1D; // lenght of stringtable pSubBufMgr->smlXltBufferP += 5; // Generate FPI // %%% luz 2003-07-31: ensured that we send the right version here! smlLibMemmove(pSubBufMgr->smlXltBufferP, FPIstring, FPIsize); pSubBufMgr->smlXltBufferP += FPIsize; } pSubBufMgr->smlXltWrittenBytes = 5 + FPIsize; // do the encoding switch (attFlag) {#ifdef __USE_DEVINF__ case SML_EXT_DEVINF: if ((_err = devinfEncBlock(TN_DEVINF_DEVINF,reqOptFlag,pContent,enc,pSubBufMgr,SML_EXT_DEVINF)) != SML_ERR_OK) { smlLibFree(pSubBufMgr->smlXltStoreBufP); smlLibFree(pSubBufMgr); return _err; } break;#endif /* oops - we don not know about that extension -> bail out */ default: smlLibFree(pSubBufMgr->smlXltStoreBufP); smlLibFree(pSubBufMgr); return SML_ERR_XLT_INVAL_EXT; }#ifdef __USE_DEVINF__ // move it to the 'real' encoder buffer // now set up the OPAQUE field if (pBufMgr->spaceEvaluation == 0) { pBufMgr->smlXltBufferP[0] = 0xC3; // OPAQUE data identifier pBufMgr->smlXltBufferP += 1; wbxmlOpaqueSize2Buf(pSubBufMgr->smlXltWrittenBytes, pBufMgr); smlLibMemmove(pBufMgr->smlXltBufferP, pSubBufMgr->smlXltStoreBufP, pSubBufMgr->smlXltWrittenBytes); pBufMgr->smlXltBufferP += pSubBufMgr->smlXltWrittenBytes; pBufMgr->smlXltWrittenBytes += pSubBufMgr->smlXltWrittenBytes; } else { pBufMgr->smlXltWrittenBytes++; wbxmlOpaqueSize2Buf(pSubBufMgr->smlXltWrittenBytes, pBufMgr); pBufMgr->smlXltWrit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -