36 #include "libxml/parser.h" 37 #include "libxml/tree.h" 45 CXMLTextDecoder::CXMLTextDecoder (
46 const CTypeRegistry * pTypeRegistry,
48 int nBuffer) : CDecoder(pTypeRegistry)
52 xmlLineNumbersDefault(1);
55 m_pDoc = xmlReadMemory((
char*) pBuffer, nBuffer,
"noName.xml", NULL,
56 XML_PARSE_COMPACT | XML_PARSE_NONET);
61 m_pxmlNodeTree = xmlDocGetRootElement(m_pDoc);
65 fprintf(stderr,
"could not parse XML memory buffer");
69 CXMLTextDecoder::CXMLTextDecoder (
70 const CTypeRegistry * pTypeRegistry,
71 struct _xmlNode * pNodeTree) : CDecoder(pTypeRegistry)
74 xmlLineNumbersDefault(1);
79 m_pxmlNodeTree = pNodeTree;
82 CXMLTextDecoder::CXMLTextDecoder (
83 const CTypeRegistry * pTypeRegistry,
84 char * fname) : CDecoder(pTypeRegistry)
87 xmlLineNumbersDefault(1);
90 m_pDoc = xmlReadFile(fname,
92 XML_PARSE_COMPACT | XML_PARSE_NONET);
97 m_pxmlNodeTree = xmlDocGetRootElement(m_pDoc);
101 fprintf(stderr,
"could not parse XML file");
105 CXMLTextDecoder::~CXMLTextDecoder (
void)
112 m_pxmlNodeTree = NULL;
116 CXMLTextDecoder::decodeMessage (
void)
119 CXMLTextDecoderStream DecoderStream(
this);
120 CErrorDetails *pError = &m_ErrorDetails;
122 if(NULL == m_pxmlNodeTree)
125 pError->m_pWhatStr =
"Unable to Extract XML Node Tree";
126 pError->m_pRefType = NULL;
127 pError->m_pRefField = NULL;
128 pError->m_OtherDetail = (int) 0;
131 pMessage = (CMessage *) DecoderStream.decodeElement(TRUE, TRUE);
137 CXMLTextDecoder::cleanupParser (
void)
142 CXMLTextDecoderStream::CXMLTextDecoderStream (
143 CXMLTextDecoder * pDecoder)
146 m_pDecoder = pDecoder;
147 m_pEnclosingDecoderStream = NULL;
149 m_pTargetNode = pDecoder->m_pxmlNodeTree;
150 m_pCurrentChildNode = NULL;
153 CXMLTextDecoderStream::CXMLTextDecoderStream (
154 CXMLTextDecoderStream * pEnclosingDecoderStream)
156 m_pDecoder = pEnclosingDecoderStream->m_pDecoder;
157 m_pEnclosingDecoderStream = pEnclosingDecoderStream;
158 m_pRefType = pEnclosingDecoderStream->m_pRefType;
159 m_pTargetNode = pEnclosingDecoderStream->m_pCurrentChildNode;
160 m_pCurrentChildNode = NULL;
164 CXMLTextDecoderStream::decodeElement (
168 CErrorDetails *pError = &m_pDecoder->m_ErrorDetails;
169 const CTypeDescriptor* pTypeDescriptor;
170 llrp_u32_t MessageID = 0;
173 if(
RC_OK != pError->m_eResultCode)
181 while ((NULL != m_pTargetNode) &&
182 ( isInsignificantNode(m_pTargetNode) ||
183 xmlIsBlankNode(m_pTargetNode)))
185 m_pTargetNode = m_pTargetNode->next;
190 if(NULL == m_pTargetNode)
196 if(m_pTargetNode->type != XML_ELEMENT_NODE)
199 pError->m_pWhatStr =
"unexpected XML node type";
200 pError->m_pRefType = m_pRefType;
201 pError->m_pRefField = NULL;
202 pError->m_OtherDetail = (int) m_pTargetNode->line;
207 pTypeDescriptor = m_pDecoder->m_pRegistry->lookupByName(
208 (
char*) m_pTargetNode->name);
210 if(NULL == pTypeDescriptor)
213 pError->m_pWhatStr =
"unknown message or parameter type";
214 pError->m_pRefType = m_pRefType;
215 pError->m_pRefField = NULL;
216 pError->m_OtherDetail = (int) m_pTargetNode->line;
220 m_pRefType = pTypeDescriptor;
223 if(pTypeDescriptor->m_bIsMessage)
225 xmlChar * pMessageIDStr;
230 pError->m_pWhatStr =
"message as subparameter";
231 pError->m_pRefType = m_pRefType;
232 pError->m_pRefField = NULL;
233 pError->m_OtherDetail = (int) m_pTargetNode->line;
238 pMessageIDStr = xmlGetProp(m_pTargetNode,
239 (xmlChar*)
"MessageID");
240 if(NULL != pMessageIDStr)
242 char * pArg = (
char *) pMessageIDStr;
243 char * pTail = pArg + strlen((
char*) pMessageIDStr);
245 cleanString((
const llrp_u8_t **) &pArg, (
const llrp_u8_t **) &pTail);
246 MessageID = strtoul(pArg, &pTmp, 10);
247 xmlFree(pMessageIDStr);
253 pError->m_pWhatStr =
"malformed MessageID";
254 pError->m_pRefType = m_pRefType;
255 pError->m_pRefField = NULL;
256 pError->m_OtherDetail = (int) m_pTargetNode->line;
263 pElement = pTypeDescriptor->constructElement();
268 pError->m_pWhatStr =
"element allocation failed";
269 pError->m_pRefType = m_pRefType;
270 pError->m_pRefField = NULL;
271 pError->m_OtherDetail = (int) m_pTargetNode->line;
276 if(pTypeDescriptor->m_bIsMessage)
278 ((CMessage *) pElement)->setMessageID(MessageID);
283 m_pCurrentChildNode = m_pTargetNode->children;
286 pTypeDescriptor->m_pfDecodeFields(
this, pElement);
288 if(
RC_OK != pError->m_eResultCode)
300 for(; m_pCurrentChildNode != NULL;
301 m_pCurrentChildNode = m_pCurrentChildNode->next)
303 CElement * pSubElement;
304 CParameter * pParameter;
306 if(isInsignificantNode(m_pCurrentChildNode))
311 if(xmlIsBlankNode(m_pCurrentChildNode))
316 CXMLTextDecoderStream NestStream(
this);
318 pSubElement = NestStream.decodeElement(FALSE, FALSE);
321 if(NULL == pSubElement)
326 pParameter = (CParameter *) pSubElement;
328 pParameter->m_pParent = pElement;
329 pElement->addSubParameterToAllList(pParameter);
332 if(
RC_OK != pError->m_eResultCode)
338 pElement->assimilateSubParameters(pError);
340 if(
RC_OK != pError->m_eResultCode)
351 CXMLTextDecoderStream::get_u8 (
352 const CFieldDescriptor * pFieldDesc)
355 Value = (llrp_u8_t) getIntegerField(pFieldDesc, MIN_U8, MAX_U8);
361 CXMLTextDecoderStream::get_s8 (
362 const CFieldDescriptor * pFieldDesc)
365 Value = (llrp_s8_t) getIntegerField(pFieldDesc, MIN_S8, MAX_S8);
371 CXMLTextDecoderStream::get_u8v (
372 const CFieldDescriptor * pFieldDesc)
374 CErrorDetails * pError;
378 pError = &m_pDecoder->m_ErrorDetails;
380 switch(pFieldDesc->m_eFieldFormat)
383 case CFieldDescriptor::FMT_NORMAL:
384 case CFieldDescriptor::FMT_DEC:
385 Tmp = getSpacedVectorField(pFieldDesc, MIN_U8, MAX_U8);
387 case CFieldDescriptor::FMT_HEX:
388 Tmp = getFixedVectorField(pFieldDesc, 2, MIN_U8, MAX_U8);
391 case CFieldDescriptor::FMT_UTF8:
392 case CFieldDescriptor::FMT_DATETIME:
396 pError->m_pWhatStr =
"Format type not support for field";
397 pError->m_pRefType = m_pRefType;
398 pError->m_pRefField = pFieldDesc;
399 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
408 nValue = Tmp.m_nValue;
409 Value = llrp_u8v_t(nValue);
410 if(verifyVectorAllocation(Value.m_pValue, pFieldDesc))
414 for(Ix = 0; Ix < nValue; Ix++)
416 Value.m_pValue[Ix] = (llrp_u8_t) Tmp.m_pValue[Ix];
426 CXMLTextDecoderStream::get_s8v (
427 const CFieldDescriptor * pFieldDesc)
429 CErrorDetails * pError;
433 pError = &m_pDecoder->m_ErrorDetails;
435 switch(pFieldDesc->m_eFieldFormat)
438 case CFieldDescriptor::FMT_NORMAL:
439 case CFieldDescriptor::FMT_DEC:
440 Tmp = getSpacedVectorField(pFieldDesc, MIN_S8, MAX_S8);
442 case CFieldDescriptor::FMT_HEX:
443 Tmp = getFixedVectorField(pFieldDesc, 2, MIN_S8, MAX_S8);
446 case CFieldDescriptor::FMT_UTF8:
447 case CFieldDescriptor::FMT_DATETIME:
451 pError->m_pWhatStr =
"Format type not support for field";
452 pError->m_pRefType = m_pRefType;
453 pError->m_pRefField = pFieldDesc;
454 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
463 nValue = Tmp.m_nValue;
464 Value = llrp_s8v_t(nValue);
465 if(verifyVectorAllocation(Value.m_pValue, pFieldDesc))
469 for(Ix = 0; Ix < nValue; Ix++)
471 Value.m_pValue[Ix] = (llrp_s8_t) Tmp.m_pValue[Ix];
485 CXMLTextDecoderStream::get_u16 (
486 const CFieldDescriptor * pFieldDesc)
489 Value = (llrp_u16_t) getIntegerField(pFieldDesc, MIN_U16, MAX_U16);
495 CXMLTextDecoderStream::get_s16 (
496 const CFieldDescriptor * pFieldDesc)
499 Value = (llrp_s16_t) getIntegerField(pFieldDesc, MIN_S16, MAX_S16);
505 CXMLTextDecoderStream::get_u16v (
506 const CFieldDescriptor * pFieldDesc)
508 CErrorDetails * pError;
512 pError = &m_pDecoder->m_ErrorDetails;
514 switch(pFieldDesc->m_eFieldFormat)
517 case CFieldDescriptor::FMT_NORMAL:
518 case CFieldDescriptor::FMT_DEC:
519 case CFieldDescriptor::FMT_HEX:
520 Tmp = getSpacedVectorField(pFieldDesc, MIN_U16, MAX_U16);
523 case CFieldDescriptor::FMT_UTF8:
524 case CFieldDescriptor::FMT_DATETIME:
528 pError->m_pWhatStr =
"Format type not support for field";
529 pError->m_pRefType = m_pRefType;
530 pError->m_pRefField = pFieldDesc;
531 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
540 nValue = Tmp.m_nValue;
541 Value = llrp_u16v_t(nValue);
542 if(verifyVectorAllocation(Value.m_pValue, pFieldDesc))
546 for(Ix = 0; Ix < nValue; Ix++)
548 Value.m_pValue[Ix] = (llrp_u16_t) Tmp.m_pValue[Ix];
557 CXMLTextDecoderStream::get_s16v (
558 const CFieldDescriptor * pFieldDesc)
560 CErrorDetails * pError;
564 pError = &m_pDecoder->m_ErrorDetails;
566 switch(pFieldDesc->m_eFieldFormat)
569 case CFieldDescriptor::FMT_NORMAL:
570 case CFieldDescriptor::FMT_DEC:
571 case CFieldDescriptor::FMT_HEX:
572 Tmp = getSpacedVectorField(pFieldDesc, MIN_S16, MAX_S16);
575 case CFieldDescriptor::FMT_UTF8:
576 case CFieldDescriptor::FMT_DATETIME:
580 pError->m_pWhatStr =
"Format type not support for field";
581 pError->m_pRefType = m_pRefType;
582 pError->m_pRefField = pFieldDesc;
583 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
592 nValue = Tmp.m_nValue;
593 Value = llrp_s16v_t(nValue);
594 if(verifyVectorAllocation(Value.m_pValue, pFieldDesc))
598 for(Ix = 0; Ix < nValue; Ix++)
600 Value.m_pValue[Ix] = (llrp_s16_t) Tmp.m_pValue[Ix];
613 CXMLTextDecoderStream::get_u32 (
614 const CFieldDescriptor * pFieldDesc)
617 Value = (llrp_u32_t) getIntegerField(pFieldDesc, MIN_U32, MAX_U32);
623 CXMLTextDecoderStream::get_s32 (
624 const CFieldDescriptor * pFieldDesc)
627 Value = (llrp_s32_t) getIntegerField(pFieldDesc, MIN_S32, MAX_S32);
633 CXMLTextDecoderStream::get_u32v (
634 const CFieldDescriptor * pFieldDesc)
636 CErrorDetails * pError;
640 pError = &m_pDecoder->m_ErrorDetails;
642 switch(pFieldDesc->m_eFieldFormat)
645 case CFieldDescriptor::FMT_NORMAL:
646 case CFieldDescriptor::FMT_DEC:
647 case CFieldDescriptor::FMT_HEX:
648 Tmp = getSpacedVectorField(pFieldDesc, MIN_U32, MAX_U32);
651 case CFieldDescriptor::FMT_UTF8:
652 case CFieldDescriptor::FMT_DATETIME:
656 pError->m_pWhatStr =
"Format type not support for field";
657 pError->m_pRefType = m_pRefType;
658 pError->m_pRefField = pFieldDesc;
659 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
668 nValue = Tmp.m_nValue;
669 Value = llrp_u32v_t(nValue);
670 if(verifyVectorAllocation(Value.m_pValue, pFieldDesc))
674 for(Ix = 0; Ix < nValue; Ix++)
676 Value.m_pValue[Ix] = (llrp_u32_t) Tmp.m_pValue[Ix];
685 CXMLTextDecoderStream::get_s32v (
686 const CFieldDescriptor * pFieldDesc)
688 CErrorDetails * pError;
692 pError = &m_pDecoder->m_ErrorDetails;
694 switch(pFieldDesc->m_eFieldFormat)
697 case CFieldDescriptor::FMT_NORMAL:
698 case CFieldDescriptor::FMT_DEC:
699 case CFieldDescriptor::FMT_HEX:
700 Tmp = getSpacedVectorField(pFieldDesc, MIN_S32, MAX_S32);
703 case CFieldDescriptor::FMT_UTF8:
704 case CFieldDescriptor::FMT_DATETIME:
708 pError->m_pWhatStr =
"Format type not support for field";
709 pError->m_pRefType = m_pRefType;
710 pError->m_pRefField = pFieldDesc;
711 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
720 nValue = Tmp.m_nValue;
721 Value = llrp_s32v_t(nValue);
722 if(verifyVectorAllocation(Value.m_pValue, pFieldDesc))
726 for(Ix = 0; Ix < nValue; Ix++)
728 Value.m_pValue[Ix] = (llrp_s32_t) Tmp.m_pValue[Ix];
741 CXMLTextDecoderStream::get_u64 (
742 const CFieldDescriptor * pFieldDesc)
745 Value = (llrp_u64_t) getIntegerField(pFieldDesc, MIN_U64, MAX_U64);
751 CXMLTextDecoderStream::get_s64 (
752 const CFieldDescriptor * pFieldDesc)
755 Value = (llrp_s64_t) getIntegerField(pFieldDesc, MIN_S64, MAX_S64);
761 CXMLTextDecoderStream::get_u64v (
762 const CFieldDescriptor * pFieldDesc)
764 CErrorDetails * pError;
768 pError = &m_pDecoder->m_ErrorDetails;
770 switch(pFieldDesc->m_eFieldFormat)
773 case CFieldDescriptor::FMT_NORMAL:
774 case CFieldDescriptor::FMT_DEC:
775 case CFieldDescriptor::FMT_HEX:
776 case CFieldDescriptor::FMT_DATETIME:
777 Tmp = getSpacedVectorField(pFieldDesc, MIN_U64, MAX_U64);
780 case CFieldDescriptor::FMT_UTF8:
784 pError->m_pWhatStr =
"Format type not support for field";
785 pError->m_pRefType = m_pRefType;
786 pError->m_pRefField = pFieldDesc;
787 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
796 nValue = Tmp.m_nValue;
797 Value = llrp_u64v_t(nValue);
798 if(verifyVectorAllocation(Value.m_pValue, pFieldDesc))
802 for(Ix = 0; Ix < nValue; Ix++)
804 Value.m_pValue[Ix] = (llrp_u64_t) Tmp.m_pValue[Ix];
813 CXMLTextDecoderStream::get_s64v (
814 const CFieldDescriptor * pFieldDesc)
817 Value = getSpacedVectorField(pFieldDesc, MIN_S64, MAX_S64);
827 CXMLTextDecoderStream::get_u1 (
828 const CFieldDescriptor * pFieldDesc)
831 Value = (llrp_u1_t) getIntegerField(pFieldDesc, 0, 1);
837 CXMLTextDecoderStream::get_u1v (
838 const CFieldDescriptor * pFieldDesc)
840 CErrorDetails * pError;
844 pError = &m_pDecoder->m_ErrorDetails;
845 Tmp = getFixedVectorField(pFieldDesc, 2, 0, 255);
851 nValue = Tmp.m_nValue;
852 Value = llrp_u1v_t(nValue*8);
853 if(verifyVectorAllocation(Value.m_pValue, pFieldDesc))
858 for(Ix = 0; Ix < nValue; Ix++)
860 Value.m_pValue[Ix] = (llrp_u1_t) Tmp.m_pValue[Ix];
864 Value.m_nBit = Tmp.m_nValue * 8;
867 if(NULL != m_pLastFieldNode)
869 pCountStr = xmlGetProp(m_pLastFieldNode,
871 if(NULL != pCountStr)
873 char * pArg = (
char *) pCountStr;
874 char * pTail = pArg + strlen((
char*) pCountStr);
877 nBits = (llrp_u16_t) strtoul(pArg, &pTail, 10);
879 (nBits > (Tmp.m_nValue * 8)))
883 pError->m_pWhatStr =
"malformed Count Attribute";
884 pError->m_pRefType = m_pRefType;
885 pError->m_pRefField = pFieldDesc;
886 pError->m_OtherDetail = (int) m_pLastFieldNode->line;
890 llrp_u16_t lastByteBits;
891 llrp_u8_t lastByteMask;
893 Value.m_nBit = nBits;
896 lastByteBits = nBits % 8;
900 lastByteBits = 8 - lastByteBits;
901 lastByteMask = (1 << lastByteBits) - 1;
903 lastByteMask = ~lastByteMask;
905 Value.m_pValue[Ix] &= lastByteMask;
918 CXMLTextDecoderStream::get_u2 (
919 const CFieldDescriptor * pFieldDesc)
922 Value = (llrp_u2_t) getIntegerField(pFieldDesc, 0, 3);
928 CXMLTextDecoderStream::get_u96 (
929 const CFieldDescriptor * pFieldDesc)
931 CErrorDetails * pError;
936 pError = &m_pDecoder->m_ErrorDetails;
938 Tmp = getFixedVectorField( pFieldDesc, 2, 0, 255);
940 if((
RC_OK != pError->m_eResultCode) && (Tmp.m_nValue != 12))
945 pError->m_pWhatStr =
"Illegal length u96 field";
946 pError->m_pRefType = m_pRefType;
947 pError->m_pRefField = pFieldDesc;
948 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
954 for(Ix = 0; Ix < Tmp.m_nValue; Ix++)
956 Value.m_aValue[Ix] = (llrp_u8_t) Tmp.m_pValue[Ix];
964 CXMLTextDecoderStream::get_utf8v (
965 const CFieldDescriptor * pFieldDesc)
969 const llrp_u8_t * pbuf;
970 const llrp_u8_t * pend;
972 if(getFieldStringPtr(pFieldDesc, &pbuf, &pend))
974 nValue = (llrp_u16_t) strlen((
char*) pbuf);
975 Value = llrp_utf8v_t(nValue);
977 if(verifyVectorAllocation(Value.m_pValue, pFieldDesc))
981 for(Ix = 0; Ix < nValue; Ix++)
983 Value.m_pValue[Ix] = pbuf[Ix];
998 CXMLTextDecoderStream::get_bytesToEnd (
999 const CFieldDescriptor * pFieldDesc)
1001 llrp_bytesToEnd_t Value;
1005 Tmp = getFixedVectorField( pFieldDesc, 2, 0, 255);
1007 if(verifyVectorAllocation(Tmp.m_pValue, pFieldDesc))
1010 Value = llrp_bytesToEnd_t(Tmp.m_nValue);
1011 if(verifyVectorAllocation(Tmp.m_pValue, pFieldDesc))
1014 for(Ix = 0; Ix < Tmp.m_nValue; Ix++)
1016 Value.m_pValue[Ix] = (llrp_byte_t) Tmp.m_pValue[Ix];
1018 Value.m_nValue = Tmp.m_nValue;
1030 CXMLTextDecoderStream::get_e1 (
1031 const CFieldDescriptor * pFieldDesc)
1034 Value = (int) getIntegerField(pFieldDesc, 0, 1);
1040 CXMLTextDecoderStream::get_e2 (
1041 const CFieldDescriptor * pFieldDesc)
1044 Value = (int) getIntegerField(pFieldDesc, 0, 3);
1050 CXMLTextDecoderStream::get_e8 (
1051 const CFieldDescriptor * pFieldDesc)
1054 Value = (int) getIntegerField(pFieldDesc, MIN_U8, MAX_U8);
1060 CXMLTextDecoderStream::get_e16 (
1061 const CFieldDescriptor * pFieldDesc)
1064 Value = (int) getIntegerField(pFieldDesc, MIN_U16, MAX_U16);
1070 CXMLTextDecoderStream::get_e32 (
1071 const CFieldDescriptor * pFieldDesc)
1074 Value = (int) getIntegerField(pFieldDesc, MIN_U32, MAX_U32);
1080 CXMLTextDecoderStream::get_e8v (
1081 const CFieldDescriptor * pFieldDesc)
1086 Tmp = getSpacedVectorField( pFieldDesc, MIN_U8, MAX_U8);
1091 nValue = Tmp.m_nValue;
1092 Value = llrp_u8v_t(nValue);
1093 if(verifyVectorAllocation(Value.m_pValue,pFieldDesc))
1097 for(Ix = 0; Ix < nValue; Ix++)
1099 Value.m_pValue[Ix] = (llrp_u8_t) Tmp.m_pValue[Ix];
1108 CXMLTextDecoderStream::get_reserved (
1115 CXMLTextDecoderStream::verifyVectorAllocation (
1116 const void * pValue,
1117 const CFieldDescriptor * pFieldDescriptor)
1121 CErrorDetails * pError = &m_pDecoder->m_ErrorDetails;
1124 pError->m_pWhatStr =
"field allocation failed";
1125 pError->m_pRefType = m_pRefType;
1126 pError->m_pRefField = pFieldDescriptor;
1127 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
1138 CXMLTextDecoderStream::isInsignificantNode (
1139 struct _xmlNode * pnode)
1144 case XML_COMMENT_NODE:
1145 case XML_NOTATION_NODE:
1147 case XML_XINCLUDE_START:
1148 case XML_XINCLUDE_END:
1154 case XML_ELEMENT_NODE:
1155 case XML_ATTRIBUTE_NODE:
1159 case XML_CDATA_SECTION_NODE:
1162 case XML_ENTITY_REF_NODE:
1163 case XML_ENTITY_NODE:
1164 case XML_ENTITY_DECL:
1167 case XML_DOCUMENT_NODE:
1168 case XML_DOCUMENT_TYPE_NODE:
1169 case XML_DOCUMENT_FRAG_NODE:
1170 case XML_HTML_DOCUMENT_NODE:
1174 case XML_ELEMENT_DECL:
1175 case XML_ATTRIBUTE_DECL:
1176 case XML_NAMESPACE_DECL:
1186 CXMLTextDecoderStream::getFieldStringPtr(
1187 const CFieldDescriptor * pFieldDescriptor,
1188 const llrp_u8_t ** pbuf,
1189 const llrp_u8_t ** pend)
1191 CErrorDetails * pError = &m_pDecoder->m_ErrorDetails;
1198 m_pLastFieldNode = NULL;
1200 if(
RC_OK != pError->m_eResultCode)
1206 while ((NULL != m_pCurrentChildNode) &&
1207 (isInsignificantNode(m_pCurrentChildNode) ||
1208 xmlIsBlankNode(m_pCurrentChildNode)))
1210 m_pCurrentChildNode = m_pCurrentChildNode->next;
1213 if(NULL == m_pCurrentChildNode)
1216 pError->m_pWhatStr =
"underrun at field";
1217 pError->m_pRefType = m_pRefType;
1218 pError->m_pRefField = pFieldDescriptor;
1219 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
1224 if(m_pCurrentChildNode->type != XML_ELEMENT_NODE)
1227 pError->m_pWhatStr =
"unexpected field value";
1228 pError->m_pRefType = m_pRefType;
1229 pError->m_pRefField = pFieldDescriptor;
1230 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
1235 if(0 != strcmp((
char*) m_pCurrentChildNode->name,
1236 pFieldDescriptor->m_pName))
1239 pError->m_pWhatStr =
"missing field value";
1240 pError->m_pRefType = m_pRefType;
1241 pError->m_pRefField = pFieldDescriptor;
1242 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
1247 m_pLastFieldNode = m_pCurrentChildNode;
1250 pSave = m_pCurrentChildNode->children;
1253 m_pCurrentChildNode = m_pCurrentChildNode->next;
1256 while ((NULL !=pSave) &&
1257 (isInsignificantNode(pSave) ||
1258 xmlIsBlankNode(pSave)))
1260 pSave = pSave->next;
1272 if(XML_TEXT_NODE != pSave->type)
1275 pError->m_pWhatStr =
"invalid XML Node found during field decode";
1276 pError->m_pRefType = m_pRefType;
1277 pError->m_pRefField = pFieldDescriptor;
1278 pError->m_OtherDetail = (int) pSave->line;
1282 *pbuf = pSave->content;
1285 pSave = pSave->next;
1286 while ((NULL !=pSave) &&
1287 (isInsignificantNode(pSave) ||
1288 xmlIsBlankNode(pSave)))
1290 pSave = pSave->next;
1296 pError->m_pWhatStr =
"extra XML node found";
1297 pError->m_pRefType = m_pRefType;
1298 pError->m_pRefField = pFieldDescriptor;
1299 pError->m_OtherDetail = (int) pSave->line;
1303 *pend = *pbuf + strlen((
char*) *pbuf);
1308 CXMLTextDecoderStream::getSpacedVectorField (
1309 const CFieldDescriptor * pFieldDescriptor,
1310 llrp_s64_t minValue,
1311 llrp_s64_t maxValue)
1313 CErrorDetails * pError = &m_pDecoder->m_ErrorDetails;
1314 const llrp_u8_t * pTok;
1315 const llrp_u8_t * pEnd;
1316 const llrp_u8_t * pTokEnd;
1318 llrp_u16_t elementCount;
1322 if(
RC_OK != pError->m_eResultCode)
1329 if(!getFieldStringPtr(pFieldDescriptor, &pTok, &pEnd))
1335 length = cleanString(&pTok, &pEnd);
1336 elementCount = countElements((
char *) pTok, length);
1339 Value = llrp_s64v_t(elementCount);
1341 for(count = 0;count <elementCount ; count++)
1344 while(isspace(*pTok) && (pTok < pEnd))
1350 for(pTokEnd = pTok; (!isspace(*pTokEnd)) && (*pTokEnd !=
'\0'); pTokEnd++)
1356 Value.m_pValue[count] = getInteger(pFieldDescriptor,
1362 if(
RC_OK != pError->m_eResultCode)
1371 Value.m_nValue = count;
1377 CXMLTextDecoderStream::getFixedVectorField (
1378 const CFieldDescriptor * pFieldDescriptor,
1379 unsigned int vectorSize,
1380 llrp_s64_t minValue,
1381 llrp_s64_t maxValue)
1383 CErrorDetails * pError = &m_pDecoder->m_ErrorDetails;
1384 const llrp_u8_t * pTok;
1385 const llrp_u8_t * pEnd;
1387 llrp_u16_t elementCount;
1391 if(
RC_OK != pError->m_eResultCode)
1397 if(!getFieldStringPtr(pFieldDescriptor, &pTok, &pEnd))
1401 Value.m_pValue = NULL;
1405 length = cleanString(&pTok, &pEnd);
1408 if (length % vectorSize)
1411 pError->m_pWhatStr =
"field size must be multiple of basic type";
1412 pError->m_pRefType = m_pRefType;
1413 pError->m_pRefField = pFieldDescriptor;
1414 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
1419 elementCount = (length + vectorSize - 1)/vectorSize;
1422 Value = llrp_s64v_t(elementCount);
1424 for(count = 0;count <elementCount ; count++, pTok += vectorSize)
1426 pEnd = pTok + vectorSize;
1429 Value.m_pValue[count] = getInteger(pFieldDescriptor,
1436 if(
RC_OK != pError->m_eResultCode)
1443 Value.m_nValue = count;
1450 CXMLTextDecoderStream::getIntegerField (
1451 const CFieldDescriptor * pFieldDescriptor,
1452 llrp_s64_t minValue,
1453 llrp_s64_t maxValue)
1455 CErrorDetails * pError = &m_pDecoder->m_ErrorDetails;
1456 const llrp_u8_t * pbuf;
1457 const llrp_u8_t * pend;
1460 memset(&Value, 0x00,
sizeof(Value));
1462 if(
RC_OK != pError->m_eResultCode)
1468 if(getFieldStringPtr(pFieldDescriptor, &pbuf, &pend))
1470 cleanString(&pbuf, &pend);
1471 Value = getInteger(pFieldDescriptor,
1481 pError->m_pWhatStr =
"underrun at field no characters";
1482 pError->m_pRefType = m_pRefType;
1483 pError->m_pRefField = pFieldDescriptor;
1484 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
1492 llrp_s64_t CXMLTextDecoderStream::getInteger(
1493 const CFieldDescriptor * pFieldDescriptor,
1494 const llrp_u8_t * pbuf,
1495 const llrp_u8_t * pend,
1496 CErrorDetails * pError,
1497 llrp_s64_t minValue,
1498 llrp_s64_t maxValue)
1501 const llrp_u8_t * endPtr = NULL;
1504 if(pFieldDescriptor->m_eFieldType == CFieldDescriptor::FT_U1)
1508 endPtr = getSingleU1(pbuf, pend, &Value);
1510 else if((pFieldDescriptor->m_eFieldType == CFieldDescriptor::FT_E1 ) ||
1511 (pFieldDescriptor->m_eFieldType == CFieldDescriptor::FT_E2 ) ||
1512 (pFieldDescriptor->m_eFieldType == CFieldDescriptor::FT_E8 ) ||
1513 (pFieldDescriptor->m_eFieldType == CFieldDescriptor::FT_E16 ) ||
1514 (pFieldDescriptor->m_eFieldType == CFieldDescriptor::FT_E32 ) ||
1515 (pFieldDescriptor->m_eFieldType == CFieldDescriptor::FT_E8V ) )
1518 endPtr = getSingleEnum(pFieldDescriptor, pbuf, pend, &Value);
1520 else switch(pFieldDescriptor->m_eFieldFormat)
1524 case CFieldDescriptor::FMT_NORMAL:
1525 case CFieldDescriptor::FMT_DEC:
1526 endPtr = getSingleDecimal(pbuf, pend, &Value);
1528 case CFieldDescriptor::FMT_HEX:
1529 endPtr = getSingleHexidecimal(pbuf, pend, &Value);
1531 case CFieldDescriptor::FMT_UTF8:
1533 const llrp_u8_t *ptr;
1535 for(ptr = pbuf; ptr < pend; ptr++)
1537 Value = 256*Value + *ptr;
1541 case CFieldDescriptor::FMT_DATETIME:
1542 endPtr = getSingleTimestamp(pbuf, pend, &Value);
1551 pError->m_pWhatStr =
"Illegal field value";
1552 pError->m_pRefType = m_pRefType;
1553 pError->m_pRefField = pFieldDescriptor;
1554 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
1557 else if (endPtr != pend)
1562 pError->m_pWhatStr =
"overrun at field extra characters";
1563 pError->m_pRefType = m_pRefType;
1564 pError->m_pRefField = pFieldDescriptor;
1565 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
1569 else if((Value > maxValue) || (Value < minValue))
1573 pError->m_pWhatStr =
"out of range value";
1574 pError->m_pRefType = m_pRefType;
1575 pError->m_pRefField = pFieldDescriptor;
1576 pError->m_OtherDetail = (int) m_pCurrentChildNode->line;
1585 CXMLTextDecoderStream::getSingleU1(
1586 const llrp_u8_t * pbuf,
1587 const llrp_u8_t * pend,
1588 llrp_s64_t * pValue)
1590 const llrp_u8_t * endPtr = pbuf;
1591 const int len = (int) (pend - pbuf);
1593 if((len >= 4) && (0 == strncasecmp(
"true", (
char*) pbuf, 4)))
1598 else if ((len >= 5) && (0 == strncasecmp(
"false", (
char*) pbuf, 5)))
1603 else if ((len >= 1) && (*pbuf ==
'0'))
1608 else if ((len >= 1) && (*pbuf ==
'1'))
1617 CXMLTextDecoderStream::getSingleEnum(
1618 const CFieldDescriptor * pFieldDescriptor,
1619 const llrp_u8_t * pbuf,
1620 const llrp_u8_t * pend,
1621 llrp_s64_t * pValue)
1623 const llrp_u8_t * endPtr = pbuf;
1624 const int length = (int) (pend - pbuf);
1625 const SEnumTableEntry * pEntry;
1630 pEntry = pFieldDescriptor->m_pEnumTable;
1631 NULL != pEntry->pName;
1634 int len = (int) strlen(pEntry->pName);
1635 if((len == length) &&
1636 (memcmp(pbuf, pEntry->pName, len) == 0))
1642 if(NULL == pEntry->pName)
1647 *pValue = pEntry->Value;
1648 endPtr = pbuf + length;
1653 CXMLTextDecoderStream::getSingleDecimal(
1654 const llrp_u8_t * pbuf,
1655 const llrp_u8_t * pend,
1656 llrp_s64_t * pValue)
1659 const llrp_u8_t * endPtr;
1663 for(endPtr = pbuf; endPtr < pend; endPtr++)
1668 }
else if (isdigit(*endPtr))
1670 *pValue = 10 * *pValue + (*endPtr -
'0');
1688 CXMLTextDecoderStream::getSingleHexidecimal(
1689 const llrp_u8_t * pbuf,
1690 const llrp_u8_t * pend,
1691 llrp_s64_t * pValue)
1693 const llrp_u8_t * endPtr;
1696 for(endPtr = pbuf; endPtr < pend; endPtr++)
1698 if(isdigit(*endPtr))
1700 *pValue = 16 * *pValue + (*endPtr -
'0');
1702 else if (*endPtr >=
'A' && *endPtr <=
'F')
1704 *pValue = 16 * *pValue + (*endPtr -
'A' + 10);
1706 else if (*endPtr >=
'a' && *endPtr <=
'f')
1708 *pValue = 16 * *pValue + (*endPtr -
'a' + 10);
1721 CXMLTextDecoderStream::cleanString(
1722 const llrp_u8_t ** ppbuf,
1723 const llrp_u8_t ** ppend)
1726 while( isspace(**ppbuf) && (*ppbuf <= *ppend))
1732 while((*ppend > *ppbuf) && (isspace(*(*ppend-1)) || (*(*ppend-1) ==
'\0')))
1736 return (
int) (*ppend - *ppbuf);
1742 static const llrp_u8_t *
1744 const llrp_u8_t * pbuf,
1745 const llrp_u8_t * pend,
1746 llrp_s64_t * pValue)
1748 const llrp_u8_t * endPtr = pbuf;
1749 const int len = pend - pbuf;
1761 CXMLTextDecoderStream::getSingleTimestamp(
1762 const llrp_u8_t * pbuf,
1763 const llrp_u8_t * pend,
1764 llrp_s64_t * pValue)
1766 const llrp_u8_t * endPtr;
1767 const llrp_u8_t * tmpPtr;
1768 struct tm importTime;
1769 llrp_s64_t micros = 0;
1770 llrp_s64_t temp = 0;
1773 llrp_s64_t offset = 0;
1775 memset(&importTime, 0x00,
sizeof(importTime));
1778 endPtr = (llrp_u8_t*) strptime((
char*) tmpPtr,
"%Y-%m-%dT%T", &importTime);
1782 goto timeParseError;
1787 if((endPtr = getSingleChar(tmpPtr, pend, &temp)) == tmpPtr)
1798 if((endPtr = getSingleDecimal(tmpPtr, pend, µs)) == tmpPtr)
1800 goto timeParseError;
1803 length = endPtr - tmpPtr;
1813 goto timeParseError;
1818 if((endPtr = getSingleChar(tmpPtr, pend, &temp)) == tmpPtr)
1825 if(temp ==
'-' || temp ==
'+')
1837 if((endPtr = getSingleDecimal(tmpPtr, pend, &temp)) == (tmpPtr+2))
1839 goto timeParseError;
1842 offset = scale*temp*60*60;
1845 if((endPtr = getSingleChar(tmpPtr, pend, &temp)) == tmpPtr)
1851 goto timeParseError;
1855 if((endPtr = getSingleDecimal(tmpPtr, pend, &temp)) == (tmpPtr+2))
1857 goto timeParseError;
1860 offset += (scale * temp * 60);
1863 else if ((temp ==
'z') || (temp ==
'Z'))
1873 tt = timegm(&importTime);
1876 tt = timelocal(&importTime);
1880 if(tt != (time_t) -1)
1883 *pValue = 1000000ll * (llrp_s64_t) (tt + offset) + micros;
1894 CXMLTextDecoderStream::countElements(
1898 const llrp_u8_t * pTok;
1899 const llrp_u8_t * pEnd;
1901 llrp_u16_t elements = 0;
1906 pTok = (llrp_u8_t*) &pval[0];
1910 for(lastChar =
' '; pTok < pEnd; pTok++)
1912 if((!isspace(*pTok)) && (isspace(lastChar)))
Based type descriptions for the LTKCPP library.
Classes to encode and decode LTK-XML.