00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <assert.h>
00023 #include <ctype.h>
00024 #include <string.h>
00025
00026 #include "ltkc_platform.h"
00027 #include "ltkc_base.h"
00028 #include "ltkc_xmltext.h"
00029
00030
00031
00032
00033
00034
00035 LLRP_tSXMLTextDecoder *
00036 LLRP_XMLTextDecoder_construct (
00037 const LLRP_tSTypeRegistry * pTypeRegistry,
00038 unsigned char * pBuffer,
00039 unsigned int nBuffer);
00040
00041 static void
00042 decoderDestruct (
00043 LLRP_tSDecoder * pBaseDecoder);
00044
00045 static LLRP_tSMessage *
00046 topDecodeMessage (
00047 LLRP_tSDecoder * pBaseDecoder);
00048
00049 static int
00050 getTag (
00051 LLRP_tSXMLTextDecoder * pDecoder);
00052
00053 static int
00054 getTextChar (
00055 LLRP_tSXMLTextDecoder * pDecoder);
00056
00057 static int
00058 getText (
00059 LLRP_tSXMLTextDecoder * pDecoder);
00060
00061 static int
00062 skipInsignificantText (
00063 LLRP_tSXMLTextDecoder * pDecoder);
00064
00065 static void
00066 skipXMLComment (
00067 LLRP_tSXMLTextDecoder * pDecoder);
00068
00069 static void
00070 skipXMLProcessingInstruction (
00071 LLRP_tSXMLTextDecoder * pDecoder);
00072
00073 static llrp_u8_t
00074 get_u8 (
00075 LLRP_tSDecoderStream * pBaseDecoderStream,
00076 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00077
00078 static llrp_s8_t
00079 get_s8 (
00080 LLRP_tSDecoderStream * pBaseDecoderStream,
00081 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00082
00083 static llrp_u8v_t
00084 get_u8v (
00085 LLRP_tSDecoderStream * pBaseDecoderStream,
00086 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00087
00088 static llrp_s8v_t
00089 get_s8v (
00090 LLRP_tSDecoderStream * pBaseDecoderStream,
00091 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00092
00093 static llrp_u16_t
00094 get_u16 (
00095 LLRP_tSDecoderStream * pBaseDecoderStream,
00096 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00097
00098 static llrp_s16_t
00099 get_s16 (
00100 LLRP_tSDecoderStream * pBaseDecoderStream,
00101 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00102
00103 static llrp_u16v_t
00104 get_u16v (
00105 LLRP_tSDecoderStream * pBaseDecoderStream,
00106 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00107
00108 static llrp_s16v_t
00109 get_s16v (
00110 LLRP_tSDecoderStream * pBaseDecoderStream,
00111 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00112
00113 static llrp_u32_t
00114 get_u32 (
00115 LLRP_tSDecoderStream * pBaseDecoderStream,
00116 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00117
00118 static llrp_s32_t
00119 get_s32 (
00120 LLRP_tSDecoderStream * pBaseDecoderStream,
00121 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00122
00123 static llrp_u32v_t
00124 get_u32v (
00125 LLRP_tSDecoderStream * pBaseDecoderStream,
00126 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00127
00128 static llrp_s32v_t
00129 get_s32v (
00130 LLRP_tSDecoderStream * pBaseDecoderStream,
00131 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00132
00133 static llrp_u64_t
00134 get_u64 (
00135 LLRP_tSDecoderStream * pBaseDecoderStream,
00136 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00137
00138 static llrp_s64_t
00139 get_s64 (
00140 LLRP_tSDecoderStream * pBaseDecoderStream,
00141 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00142
00143 static llrp_u64v_t
00144 get_u64v (
00145 LLRP_tSDecoderStream * pBaseDecoderStream,
00146 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00147
00148 static llrp_s64v_t
00149 get_s64v (
00150 LLRP_tSDecoderStream * pBaseDecoderStream,
00151 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00152
00153 static llrp_u1_t
00154 get_u1 (
00155 LLRP_tSDecoderStream * pBaseDecoderStream,
00156 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00157
00158 static llrp_u1v_t
00159 get_u1v (
00160 LLRP_tSDecoderStream * pBaseDecoderStream,
00161 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00162
00163 static llrp_u2_t
00164 get_u2 (
00165 LLRP_tSDecoderStream * pBaseDecoderStream,
00166 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00167
00168 static llrp_u96_t
00169 get_u96 (
00170 LLRP_tSDecoderStream * pBaseDecoderStream,
00171 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00172
00173 static llrp_utf8v_t
00174 get_utf8v (
00175 LLRP_tSDecoderStream * pBaseDecoderStream,
00176 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00177
00178 static llrp_bytesToEnd_t
00179 get_bytesToEnd (
00180 LLRP_tSDecoderStream * pBaseDecoderStream,
00181 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00182
00183 static int
00184 get_e1 (
00185 LLRP_tSDecoderStream * pBaseDecoderStream,
00186 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00187
00188 static int
00189 get_e2 (
00190 LLRP_tSDecoderStream * pBaseDecoderStream,
00191 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00192
00193 static int
00194 get_e8 (
00195 LLRP_tSDecoderStream * pBaseDecoderStream,
00196 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00197
00198 static int
00199 get_e16 (
00200 LLRP_tSDecoderStream * pBaseDecoderStream,
00201 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00202
00203 static int
00204 get_e32 (
00205 LLRP_tSDecoderStream * pBaseDecoderStream,
00206 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00207
00208 static void
00209 get_reserved (
00210 LLRP_tSDecoderStream * pBaseDecoderStream,
00211 unsigned int nBit);
00212
00213 static void
00214 streamConstruct_outermost (
00215 LLRP_tSXMLTextDecoderStream * pDecoderStream,
00216 LLRP_tSXMLTextDecoder * pDecoder);
00217
00218 static void
00219 streamConstruct_nested (
00220 LLRP_tSXMLTextDecoderStream * pDecoderStream,
00221 LLRP_tSXMLTextDecoderStream * pEnclosingDecoderStream);
00222
00223 static LLRP_tSElement *
00224 decodeElement (
00225 LLRP_tSXMLTextDecoderStream * pDecoderStream,
00226 int bAllowMessage);
00227
00228 static llrp_bool_t
00229 getFieldText (
00230 LLRP_tSXMLTextDecoderStream * pDecoderStream,
00231 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00232
00233 static llrp_s64_t
00234 getFieldIntg (
00235 LLRP_tSXMLTextDecoderStream * pDecoderStream,
00236 const LLRP_tSFieldDescriptor *pFieldDescriptor,
00237 llrp_s64_t minValue,
00238 llrp_s64_t maxValue);
00239
00240 static llrp_bool_t
00241 getFieldIntgVec (
00242 LLRP_tSXMLTextDecoderStream * pDecoderStream,
00243 const LLRP_tSFieldDescriptor *pFieldDescriptor,
00244 unsigned int nValueMax,
00245 llrp_s64_t minValue,
00246 llrp_s64_t maxValue);
00247
00248 static llrp_bool_t
00249 getFieldHexBinary (
00250 LLRP_tSXMLTextDecoderStream * pDecoderStream,
00251 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00252
00253 static int
00254 getFieldEnum (
00255 LLRP_tSXMLTextDecoderStream * pDecoderStream,
00256 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00257
00258 static llrp_bool_t
00259 verifyVectorAllocation (
00260 LLRP_tSXMLTextDecoderStream * pDecoderStream,
00261 const void * pValue,
00262 const LLRP_tSFieldDescriptor *pFieldDescriptor);
00263
00264
00265
00266
00267
00268
00269 #define MAX_U8 ((1ull << 8u) - 1u)
00270 #define MIN_U8 0ull
00271 #define MAX_S8 ((1ull << 7u) - 1u)
00272 #define MIN_S8 (-1ull - MAX_S8)
00273
00274 #define MAX_U16 ((1ull << 16u) - 1u)
00275 #define MIN_U16 0ull
00276 #define MAX_S16 ((1ull << 15u) - 1u)
00277 #define MIN_S16 (-1ull - MAX_S16)
00278
00279 #define MAX_U32 ((1ull << 32u) - 1u)
00280 #define MIN_U32 0ull
00281 #define MAX_S32 ((1ull << 31u) - 1u)
00282 #define MIN_S32 (-1ull - MAX_S32)
00283
00284 #define MAX_U64 ((1ull << 63u) - 1u) // one bit lost
00285 #define MIN_U64 0ull
00286 #define MAX_S64 ((1ull << 63u) - 1u)
00287 #define MIN_S64 (-1ull - MAX_S64)
00288
00289
00290 #define ARRAY_COUNT(X) (sizeof(X) / sizeof(X[0]))
00291
00292 #define ISQUOTE(C) ((C) == '"' || (C) == '\'')
00293
00294
00295
00296 static LLRP_tSDecoderOps
00297 s_XMLTextDecoderOps =
00298 {
00299 .pfDestruct = decoderDestruct,
00300 .pfDecodeMessage = topDecodeMessage,
00301 };
00302
00303 static LLRP_tSDecoderStreamOps
00304 s_XMLTextDecoderStreamOps =
00305 {
00306 .pfGet_u8 = get_u8,
00307 .pfGet_s8 = get_s8,
00308 .pfGet_u8v = get_u8v,
00309 .pfGet_s8v = get_s8v,
00310
00311 .pfGet_u16 = get_u16,
00312 .pfGet_s16 = get_s16,
00313 .pfGet_u16v = get_u16v,
00314 .pfGet_s16v = get_s16v,
00315
00316 .pfGet_u32 = get_u32,
00317 .pfGet_s32 = get_s32,
00318 .pfGet_u32v = get_u32v,
00319 .pfGet_s32v = get_s32v,
00320
00321 .pfGet_u64 = get_u64,
00322 .pfGet_s64 = get_s64,
00323 .pfGet_u64v = get_u64v,
00324 .pfGet_s64v = get_s64v,
00325
00326 .pfGet_u1 = get_u1,
00327 .pfGet_u1v = get_u1v,
00328 .pfGet_u2 = get_u2,
00329 .pfGet_u96 = get_u96,
00330 .pfGet_utf8v = get_utf8v,
00331 .pfGet_bytesToEnd = get_bytesToEnd,
00332
00333 .pfGet_e1 = get_e1,
00334 .pfGet_e2 = get_e2,
00335 .pfGet_e8 = get_e8,
00336 .pfGet_e16 = get_e16,
00337 .pfGet_e32 = get_e32,
00338
00339 .pfGet_reserved = get_reserved,
00340 };
00341
00342 LLRP_tSXMLTextDecoder *
00343 LLRP_XMLTextDecoder_construct (
00344 const LLRP_tSTypeRegistry * pTypeRegistry,
00345 unsigned char * pInput,
00346 unsigned int nInput)
00347 {
00348 LLRP_tSXMLTextDecoder * pDecoder;
00349
00350 pDecoder = malloc(sizeof *pDecoder);
00351 if(NULL == pDecoder)
00352 {
00353 return pDecoder;
00354 }
00355
00356 memset(pDecoder, 0, sizeof *pDecoder);
00357
00358 pDecoder->decoderHdr.pDecoderOps = &s_XMLTextDecoderOps;
00359 pDecoder->decoderHdr.pRegistry = pTypeRegistry;
00360
00361 pDecoder->pInput = pInput;
00362 pDecoder->nInput = nInput;
00363
00364 pDecoder->iNext = 0;
00365
00366 return pDecoder;
00367 }
00368
00369 static void
00370 decoderDestruct (
00371 LLRP_tSDecoder * pBaseDecoder)
00372 {
00373 LLRP_tSXMLTextDecoder * pDecoder =
00374 (LLRP_tSXMLTextDecoder*)pBaseDecoder;
00375
00376 free(pDecoder);
00377 }
00378
00379 static LLRP_tSMessage *
00380 topDecodeMessage (
00381 LLRP_tSDecoder * pBaseDecoder)
00382 {
00383 LLRP_tSXMLTextDecoder * pDecoder;
00384 LLRP_tSXMLTextDecoderStream DecoderStream;
00385 LLRP_tSMessage * pMessage;
00386
00387 pDecoder = (LLRP_tSXMLTextDecoder *) pBaseDecoder;
00388
00389 streamConstruct_outermost(&DecoderStream, pDecoder);
00390
00391 pMessage = (LLRP_tSMessage *) decodeElement(&DecoderStream, TRUE);
00392
00393 return pMessage;
00394 }
00395
00396 static int
00397 getTag (
00398 LLRP_tSXMLTextDecoder * pDecoder)
00399 {
00400 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
00401 unsigned char * pText = pDecoder->aTagBuf;
00402 unsigned iTextEnd = ARRAY_COUNT(pDecoder->aTagBuf);
00403 unsigned char * pTextEnd = &pText[iTextEnd - 1];
00404 unsigned int iSave;
00405 unsigned char * pScan;
00406 unsigned char * pInEnd = &pDecoder->pInput[pDecoder->nInput];
00407 int bInWord = FALSE;
00408 int bInQuote = FALSE;
00409 int quoteChar = 0;
00410 int bEndTag = FALSE;
00411 int bEmptyTag = FALSE;
00412
00413 pDecoder->nTagArg = 0;
00414
00415 if(LLRP_RC_OK != pError->eResultCode)
00416 {
00417 return -1;
00418 }
00419
00420 skipInsignificantText(pDecoder);
00421
00422 if(LLRP_RC_OK != pError->eResultCode)
00423 {
00424 return -1;
00425 }
00426
00427 iSave = pDecoder->iNext;
00428
00429 pScan = &pDecoder->pInput[pDecoder->iNext];
00430
00431 if(pScan < pInEnd && '<' != *pScan)
00432 {
00433 pDecoder->iNext = iSave;
00434
00435
00436 pError->eResultCode = LLRP_RC_MiscError;
00437 pError->pWhatStr = "missing tag";
00438 pError->pRefType = NULL;
00439 pError->pRefField = NULL;
00440 pError->OtherDetail = pDecoder->iNext;
00441
00442 return -1;
00443 }
00444 pScan++;
00445
00446 if(pScan < pInEnd && '/' == *pScan)
00447 {
00448 pScan++;
00449 bEndTag = TRUE;
00450 }
00451
00452 for(; pScan < pInEnd; )
00453 {
00454 int c = *pScan++;
00455
00456 if(c == '>')
00457 {
00458 break;
00459 }
00460
00461 if(c == '/' && pScan < pInEnd && '>' == *pScan)
00462 {
00463 /* empty tag */
00464 pScan++;
00465 bEmptyTag = TRUE;
00466 break;
00467 }
00468
00469 if(pText >= pTextEnd)
00470 {
00471 /* text buffer overflow */
00472 break;
00473 }
00474
00475 if(bInWord)
00476 {
00477 if(bInQuote)
00478 {
00479 if(c == quoteChar)
00480 {
00481 bInQuote = FALSE;
00482 }
00483 else
00484 {
00485 *pText++ = c;
00486 }
00487 }
00488 else if(isspace(c))
00489 {
00490 *pText++ = 0;
00491 bInWord = FALSE;
00492 }
00493 else if(ISQUOTE(c))
00494 {
00495 bInQuote = TRUE;
00496 quoteChar = c;
00497 }
00498 else
00499 {
00500 *pText++ = c;
00501 }
00502 }
00503 else if(!isspace(c))
00504 {
00505 /* start word */
00506 pDecoder->apTagArg[pDecoder->nTagArg++] = pText;
00507 bInWord = TRUE;
00508 if(ISQUOTE(c))
00509 {
00510 bInQuote = TRUE;
00511 quoteChar = c;
00512 }
00513 else
00514 {
00515 *pText++ = c;
00516 }
00517 }
00518 else
00519 {
00520 /* isspace() and not in word, just skip over it */
00521 }
00522 }
00523
00524 if(bInWord)
00525 {
00526 *pText++ = 0;
00527 bInWord = FALSE;
00528 }
00529
00530 if(bEndTag)
00531 {
00532 pDecoder->eTagType = XMLTEXT_END_TAG;
00533 }
00534 else if(bEmptyTag)
00535 {
00536 pDecoder->eTagType = XMLTEXT_EMPTY_TAG;
00537 }
00538 else
00539 {
00540 pDecoder->eTagType = XMLTEXT_START_TAG;
00541 }
00542
00543 if(0 == pDecoder->nTagArg)
00544 {
00545 pDecoder->iNext = iSave;
00546
00547 // TODO good error
00548 pError->eResultCode = LLRP_RC_MiscError;
00549 pError->pWhatStr = "malformed tag";
00550 pError->pRefType = NULL;
00551 pError->pRefField = NULL;
00552 pError->OtherDetail = pDecoder->iNext;
00553
00554 return -1;
00555 }
00556
00557 pDecoder->iNext = pScan - pDecoder->pInput;
00558
00559 return TRUE;
00560 }
00561
00562 static int
00563 getTextChar (
00564 LLRP_tSXMLTextDecoder * pDecoder)
00565 {
00566 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
00567 int c;
00568
00569 if(LLRP_RC_OK != pError->eResultCode)
00570 {
00571 return -1;
00572 }
00573
00574 if(pDecoder->iNext >= pDecoder->nInput)
00575 {
00576 return -1;
00577 }
00578
00579 pDecoder->iLastGetTextChar = pDecoder->iNext;
00580
00581 c = 0xFF & pDecoder->pInput[pDecoder->iNext];
00582
00583 if('<' == c)
00584 {
00585 unsigned char * pScan = &pDecoder->pInput[pDecoder->iNext];
00586 unsigned char * pInEnd = &pDecoder->pInput[pDecoder->nInput];
00587
00588 if(pScan+4 <= pInEnd && 0 == memcmp(pScan, "<!--", 4))
00589 {
00590 pDecoder->iNext += 4;
00591 skipXMLComment(pDecoder);
00592 if(LLRP_RC_OK != pError->eResultCode)
00593 {
00594 return -1;
00595 }
00596 else
00597 {
00598 return ' ';
00599 }
00600 }
00601
00602 if(pScan+2 <= pInEnd && 0 == memcmp(pScan, "<?", 2))
00603 {
00604 pDecoder->iNext += 2;
00605 skipXMLProcessingInstruction(pDecoder);
00606 if(LLRP_RC_OK != pError->eResultCode)
00607 {
00608 return -1;
00609 }
00610 else
00611 {
00612 return ' ';
00613 }
00614 }
00615
00616 return -1;
00617 }
00618
00619 if('&' == c)
00620 {
00621 /* TODO: entity call-out */
00622 // TODO good error
00623 LLRP_Error_resultCodeAndWhatStr(pError, LLRP_RC_MiscError,
00624 "unsupported entity reference");
00625 return -1;
00626 }
00627 else
00628 {
00629 pDecoder->iNext++;
00630 }
00631
00632 return c;
00633 }
00634
00635
00636 static int
00637 getText (
00638 LLRP_tSXMLTextDecoder * pDecoder)
00639 {
00640 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
00641 unsigned char * pText = pDecoder->aTextBuf;
00642 unsigned iTextEnd = ARRAY_COUNT(pDecoder->aTagBuf);
00643 unsigned char * pTextEnd = &pText[iTextEnd - 1];
00644
00645 pDecoder->iLastText = pDecoder->iNext;
00646
00647 for(;;)
00648 {
00649 int c;
00650
00651 if(LLRP_RC_OK != pError->eResultCode)
00652 {
00653 break;
00654 }
00655
00656 c = getTextChar(pDecoder);
00657 if(0 > c)
00658 {
00659 break;
00660 }
00661
00662 if(pText >= pTextEnd)
00663 {
00664 LLRP_Error_resultCodeAndWhatStr(pError, LLRP_RC_MiscError,
00665 "text overrun");
00666 continue;
00667 }
00668
00669 if(pText == pDecoder->aTextBuf)
00670 {
00671 if(isspace(c))
00672 {
00673 /* trim leading space */
00674 continue;
00675 }
00676 pDecoder->iLastText = pDecoder->iNext;
00677 }
00678
00679 *pText++ = c;
00680 }
00681
00682 *pText = 0;
00683 pDecoder->nTextBuf = pText - pDecoder->aTextBuf;
00684
00685 if(LLRP_RC_OK != pError->eResultCode)
00686 {
00687 return FALSE;
00688 }
00689 else
00690 {
00691 return TRUE;
00692 }
00693 }
00694
00695 static int
00696 skipInsignificantText (
00697 LLRP_tSXMLTextDecoder * pDecoder)
00698 {
00699 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
00700
00701 for(;;)
00702 {
00703 int c;
00704
00705 if(LLRP_RC_OK != pError->eResultCode)
00706 {
00707 break;
00708 }
00709
00710 c = getTextChar(pDecoder);
00711 if(0 > c)
00712 {
00713 break;
00714 }
00715
00716 if(!isspace(c))
00717 {
00718 pDecoder->iNext = pDecoder->iLastGetTextChar;
00719
00720 // TODO good error
00721 pError->eResultCode = LLRP_RC_MiscError;
00722 pError->pWhatStr = "unexpected text";
00723 pError->pRefType = NULL;
00724 pError->pRefField = NULL;
00725 pError->OtherDetail = pDecoder->iNext;
00726 break;
00727 }
00728 }
00729
00730 if(LLRP_RC_OK != pError->eResultCode)
00731 {
00732 return -1;
00733 }
00734 else
00735 {
00736 return 1;
00737 }
00738 }
00739
00740 static void
00741 skipXMLComment (
00742 LLRP_tSXMLTextDecoder * pDecoder)
00743 {
00744 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
00745 unsigned char * pScan = &pDecoder->pInput[pDecoder->iNext];
00746 unsigned char * pInEnd = &pDecoder->pInput[pDecoder->nInput];
00747 int bFound = 0;
00748
00749 if(LLRP_RC_OK != pError->eResultCode)
00750 {
00751 return;
00752 }
00753
00754 for(; pScan+3 < pInEnd; pScan++)
00755 {
00756 if(0 == memcmp(pScan, "-->", 3))
00757 {
00758 pScan += 3;
00759 bFound = 1;
00760 break;
00761 }
00762
00763 if(0 == memcmp(pScan, "--", 2))
00764 {
00765 pDecoder->iNext = pScan - pDecoder->pInput;
00766
00767 // TODO good error
00768 LLRP_Error_resultCodeAndWhatStr(pError, LLRP_RC_MiscError,
00769 "illegal in comment");
00770 pError->OtherDetail = pDecoder->iNext;
00771 return;
00772 }
00773 }
00774
00775 if(!bFound)
00776 {
00777 /* unterminated comment */
00778
00779 // TODO good error
00780 LLRP_Error_resultCodeAndWhatStr(pError, LLRP_RC_MiscError,
00781 "unterminated comment");
00782
00783 return;
00784 }
00785
00786 pDecoder->iNext = pScan - pDecoder->pInput;
00787 }
00788
00789 static void
00790 skipXMLProcessingInstruction (
00791 LLRP_tSXMLTextDecoder * pDecoder)
00792 {
00793 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
00794 unsigned char * pScan = &pDecoder->pInput[pDecoder->iNext];
00795 unsigned char * pInEnd = &pDecoder->pInput[pDecoder->nInput];
00796 int bFound = 0;
00797
00798 if(LLRP_RC_OK != pError->eResultCode)
00799 {
00800 return;
00801 }
00802
00803 for(; pScan+2 < pInEnd; pScan++)
00804 {
00805 if(0 == memcmp(pScan, "?>", 2))
00806 {
00807 pScan += 2;
00808 bFound = 1;
00809 break;
00810 }
00811 }
00812
00813 if(!bFound)
00814 {
00815 /* unterminated processing instruction */
00816
00817 // TODO good error
00818 LLRP_Error_resultCodeAndWhatStr(pError, LLRP_RC_MiscError,
00819 "unterminated processing instruction");
00820
00821 return;
00822 }
00823
00824 pDecoder->iNext = pScan - pDecoder->pInput;
00825 }
00826
00827 static llrp_bool_t
00828 matchStartTag (
00829 LLRP_tSXMLTextDecoder * pDecoder,
00830 const char * pPattern)
00831 {
00832 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
00833 unsigned int iSave;
00834
00835 if(LLRP_RC_OK != pError->eResultCode)
00836 {
00837 return FALSE;
00838 }
00839
00840 skipInsignificantText(pDecoder);
00841
00842 if(LLRP_RC_OK != pError->eResultCode)
00843 {
00844 return FALSE;
00845 }
00846
00847 iSave = pDecoder->iNext;
00848
00849 getTag(pDecoder);
00850
00851 if(XMLTEXT_START_TAG == pDecoder->eTagType &&
00852 0 == strcmp(pPattern, pDecoder->apTagArg[0]))
00853 {
00854 return TRUE;
00855 }
00856
00857 pDecoder->iNext = iSave;
00858
00859 return FALSE;
00860 }
00861
00862 static llrp_bool_t
00863 matchEndTag (
00864 LLRP_tSXMLTextDecoder * pDecoder,
00865 const char * pPattern)
00866 {
00867 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
00868 unsigned int iSave;
00869
00870 if(LLRP_RC_OK != pError->eResultCode)
00871 {
00872 return FALSE;
00873 }
00874
00875 skipInsignificantText(pDecoder);
00876
00877 if(LLRP_RC_OK != pError->eResultCode)
00878 {
00879 return FALSE;
00880 }
00881
00882 iSave = pDecoder->iNext;
00883
00884 if(pDecoder->iNext+2 > pDecoder->nInput ||
00885 '<' != pDecoder->pInput[pDecoder->iNext+0] ||
00886 '/' != pDecoder->pInput[pDecoder->iNext+1])
00887 {
00888 return FALSE;
00889 }
00890
00891 getTag(pDecoder);
00892
00893 if(XMLTEXT_END_TAG == pDecoder->eTagType &&
00894 0 == strcmp(pPattern, pDecoder->apTagArg[0]))
00895 {
00896 return TRUE;
00897 }
00898
00899 pDecoder->iNext = iSave;
00900
00901 return FALSE;
00902 }
00903
00904 static llrp_u8_t
00905 get_u8 (
00906 LLRP_tSDecoderStream * pBaseDecoderStream,
00907 const LLRP_tSFieldDescriptor *pFieldDescriptor)
00908 {
00909 LLRP_tSXMLTextDecoderStream *pDecoderStream;
00910 llrp_u8_t Value;
00911
00912 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
00913
00914 Value = (llrp_u8_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
00915 MIN_U8, MAX_U8);
00916
00917 return Value;
00918 }
00919
00920 static llrp_s8_t
00921 get_s8 (
00922 LLRP_tSDecoderStream * pBaseDecoderStream,
00923 const LLRP_tSFieldDescriptor *pFieldDescriptor)
00924 {
00925 LLRP_tSXMLTextDecoderStream *pDecoderStream;
00926 llrp_s8_t Value;
00927
00928 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
00929
00930 Value = (llrp_s8_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
00931 MIN_S8, MAX_S8);
00932
00933 return Value;
00934 }
00935
00936 static llrp_u8v_t
00937 get_u8v (
00938 LLRP_tSDecoderStream * pBaseDecoderStream,
00939 const LLRP_tSFieldDescriptor *pFieldDescriptor)
00940 {
00941 LLRP_tSXMLTextDecoderStream *pDecoderStream;
00942 llrp_u8v_t Value;
00943
00944 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
00945 memset(&Value, 0, sizeof Value);
00946
00947 if(getFieldIntgVec(pDecoderStream, pFieldDescriptor,
00948 0, MIN_U8, MAX_U8))
00949 {
00950 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
00951 llrp_u16_t nValue;
00952
00953 nValue = pDecoder->nIntgValue;
00954 Value = LLRP_u8v_construct(nValue);
00955 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
00956 pFieldDescriptor))
00957 {
00958 unsigned int Ix;
00959
00960 for(Ix = 0; Ix < nValue; Ix++)
00961 {
00962 Value.pValue[Ix] = (llrp_u8_t) pDecoder->aIntgValue[Ix];
00963 }
00964 }
00965 }
00966
00967 return Value;
00968 }
00969
00970 static llrp_s8v_t
00971 get_s8v (
00972 LLRP_tSDecoderStream * pBaseDecoderStream,
00973 const LLRP_tSFieldDescriptor *pFieldDescriptor)
00974 {
00975 LLRP_tSXMLTextDecoderStream *pDecoderStream;
00976 llrp_s8v_t Value;
00977
00978 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
00979 memset(&Value, 0, sizeof Value);
00980
00981 if(getFieldIntgVec(pDecoderStream, pFieldDescriptor,
00982 0, MIN_S8, MAX_S8))
00983 {
00984 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
00985 llrp_u16_t nValue;
00986
00987 nValue = pDecoder->nIntgValue;
00988 Value = LLRP_s8v_construct(nValue);
00989 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
00990 pFieldDescriptor))
00991 {
00992 unsigned int Ix;
00993
00994 for(Ix = 0; Ix < nValue; Ix++)
00995 {
00996 Value.pValue[Ix] = (llrp_s8_t) pDecoder->aIntgValue[Ix];
00997 }
00998 }
00999 }
01000
01001 return Value;
01002 }
01003
01004 static llrp_u16_t
01005 get_u16 (
01006 LLRP_tSDecoderStream * pBaseDecoderStream,
01007 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01008 {
01009 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01010 llrp_u16_t Value;
01011
01012 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01013
01014 Value = (llrp_u16_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
01015 MIN_U16, MAX_U16);
01016
01017 return Value;
01018 }
01019
01020 static llrp_s16_t
01021 get_s16 (
01022 LLRP_tSDecoderStream * pBaseDecoderStream,
01023 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01024 {
01025 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01026 llrp_s16_t Value;
01027
01028 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01029
01030 Value = (llrp_s16_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
01031 MIN_S16, MAX_S16);
01032
01033 return Value;
01034 }
01035
01036 static llrp_u16v_t
01037 get_u16v (
01038 LLRP_tSDecoderStream * pBaseDecoderStream,
01039 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01040 {
01041 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01042 llrp_u16v_t Value;
01043
01044 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01045 memset(&Value, 0, sizeof Value);
01046
01047 if(getFieldIntgVec(pDecoderStream, pFieldDescriptor,
01048 0, MIN_U16, MAX_U16))
01049 {
01050 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01051 llrp_u16_t nValue;
01052
01053 nValue = pDecoder->nIntgValue;
01054 Value = LLRP_u16v_construct(nValue);
01055 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
01056 pFieldDescriptor))
01057 {
01058 unsigned int Ix;
01059
01060 for(Ix = 0; Ix < nValue; Ix++)
01061 {
01062 Value.pValue[Ix] = (llrp_u16_t) pDecoder->aIntgValue[Ix];
01063 }
01064 }
01065 }
01066
01067 return Value;
01068 }
01069
01070 static llrp_s16v_t
01071 get_s16v (
01072 LLRP_tSDecoderStream * pBaseDecoderStream,
01073 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01074 {
01075 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01076 llrp_s16v_t Value;
01077
01078 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01079 memset(&Value, 0, sizeof Value);
01080
01081 if(getFieldIntgVec(pDecoderStream, pFieldDescriptor,
01082 0, MIN_S16, MAX_S16))
01083 {
01084 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01085 llrp_u16_t nValue;
01086
01087 nValue = pDecoder->nIntgValue;
01088 Value = LLRP_s16v_construct(nValue);
01089 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
01090 pFieldDescriptor))
01091 {
01092 unsigned int Ix;
01093
01094 for(Ix = 0; Ix < nValue; Ix++)
01095 {
01096 Value.pValue[Ix] = (llrp_u16_t) pDecoder->aIntgValue[Ix];
01097 }
01098 }
01099 }
01100
01101 return Value;
01102 }
01103
01104 static llrp_u32_t
01105 get_u32 (
01106 LLRP_tSDecoderStream * pBaseDecoderStream,
01107 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01108 {
01109 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01110 llrp_u32_t Value;
01111
01112 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01113
01114 Value = (llrp_u32_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
01115 MIN_U32, MAX_U32);
01116
01117 return Value;
01118 }
01119
01120 static llrp_s32_t
01121 get_s32 (
01122 LLRP_tSDecoderStream * pBaseDecoderStream,
01123 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01124 {
01125 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01126 llrp_s32_t Value;
01127
01128 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01129
01130 Value = (llrp_s32_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
01131 MIN_S32, MAX_S32);
01132
01133 return Value;
01134 }
01135
01136 static llrp_u32v_t
01137 get_u32v (
01138 LLRP_tSDecoderStream * pBaseDecoderStream,
01139 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01140 {
01141 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01142 llrp_u32v_t Value;
01143
01144 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01145 memset(&Value, 0, sizeof Value);
01146
01147 if(getFieldIntgVec(pDecoderStream, pFieldDescriptor,
01148 0, MIN_U32, MAX_U32))
01149 {
01150 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01151 llrp_u16_t nValue;
01152
01153 nValue = pDecoder->nIntgValue;
01154 Value = LLRP_u32v_construct(nValue);
01155 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
01156 pFieldDescriptor))
01157 {
01158 unsigned int Ix;
01159
01160 for(Ix = 0; Ix < nValue; Ix++)
01161 {
01162 Value.pValue[Ix] = (llrp_u32_t) pDecoder->aIntgValue[Ix];
01163 }
01164 }
01165 }
01166
01167 return Value;
01168 }
01169
01170 static llrp_s32v_t
01171 get_s32v (
01172 LLRP_tSDecoderStream * pBaseDecoderStream,
01173 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01174 {
01175 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01176 llrp_s32v_t Value;
01177
01178 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01179 memset(&Value, 0, sizeof Value);
01180
01181 if(getFieldIntgVec(pDecoderStream, pFieldDescriptor,
01182 0, MIN_S32, MAX_S32))
01183 {
01184 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01185 llrp_u16_t nValue;
01186
01187 nValue = pDecoder->nIntgValue;
01188 Value = LLRP_s32v_construct(nValue);
01189 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
01190 pFieldDescriptor))
01191 {
01192 unsigned int Ix;
01193
01194 for(Ix = 0; Ix < nValue; Ix++)
01195 {
01196 Value.pValue[Ix] = (llrp_s32_t) pDecoder->aIntgValue[Ix];
01197 }
01198 }
01199 }
01200
01201 return Value;
01202 }
01203
01204 static llrp_u64_t
01205 get_u64 (
01206 LLRP_tSDecoderStream * pBaseDecoderStream,
01207 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01208 {
01209 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01210 llrp_u64_t Value;
01211
01212 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01213
01214 Value = (llrp_u64_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
01215 MIN_U64, MAX_U64);
01216
01217 return Value;
01218 }
01219
01220 static llrp_s64_t
01221 get_s64 (
01222 LLRP_tSDecoderStream * pBaseDecoderStream,
01223 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01224 {
01225 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01226 llrp_s64_t Value;
01227
01228 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01229
01230 Value = (llrp_s64_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
01231 MIN_S64, MAX_S64);
01232
01233 return Value;
01234 }
01235
01236 static llrp_u64v_t
01237 get_u64v (
01238 LLRP_tSDecoderStream * pBaseDecoderStream,
01239 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01240 {
01241 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01242 llrp_u64v_t Value;
01243
01244 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01245 memset(&Value, 0, sizeof Value);
01246
01247 if(getFieldIntgVec(pDecoderStream, pFieldDescriptor,
01248 0, MIN_U64, MAX_U64))
01249 {
01250 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01251 llrp_u16_t nValue;
01252
01253 nValue = pDecoder->nIntgValue;
01254 Value = LLRP_u64v_construct(nValue);
01255 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
01256 pFieldDescriptor))
01257 {
01258 unsigned int Ix;
01259
01260 for(Ix = 0; Ix < nValue; Ix++)
01261 {
01262 Value.pValue[Ix] = (llrp_u64_t) pDecoder->aIntgValue[Ix];
01263 }
01264 }
01265 }
01266
01267 return Value;
01268 }
01269
01270 static llrp_s64v_t
01271 get_s64v (
01272 LLRP_tSDecoderStream * pBaseDecoderStream,
01273 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01274 {
01275 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01276 llrp_s64v_t Value;
01277
01278 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01279 memset(&Value, 0, sizeof Value);
01280
01281 if(getFieldIntgVec(pDecoderStream, pFieldDescriptor,
01282 0, MIN_S64, MAX_S64))
01283 {
01284 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01285 llrp_u16_t nValue;
01286
01287 nValue = pDecoder->nIntgValue;
01288 Value = LLRP_s64v_construct(nValue);
01289 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
01290 pFieldDescriptor))
01291 {
01292 unsigned int Ix;
01293
01294 for(Ix = 0; Ix < nValue; Ix++)
01295 {
01296 Value.pValue[Ix] = (llrp_s64_t) pDecoder->aIntgValue[Ix];
01297 }
01298 }
01299 }
01300
01301 return Value;
01302 }
01303
01304 static llrp_u1_t
01305 get_u1 (
01306 LLRP_tSDecoderStream * pBaseDecoderStream,
01307 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01308 {
01309 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01310 llrp_u1_t Value;
01311
01312 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01313
01314 Value = (llrp_u1_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
01315 0, 1);
01316
01317 return Value;
01318 }
01319
01320 static llrp_u1v_t
01321 get_u1v (
01322 LLRP_tSDecoderStream * pBaseDecoderStream,
01323 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01324 {
01325 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01326 llrp_u1v_t Value;
01327
01328 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01329 memset(&Value, 0, sizeof Value);
01330
01331 if(getFieldHexBinary(pDecoderStream, pFieldDescriptor))
01332 {
01333 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01334 llrp_u16_t nByte;
01335 llrp_u16_t nBit;
01336 unsigned int Ix;
01337
01338 nByte = pDecoder->nTextBuf;
01339 nBit = nByte * 8u;
01340
01341 for(Ix = 1; Ix < pDecoder->nTagArg; Ix++)
01342 {
01343 if(0 == strncmp(pDecoder->apTagArg[Ix], "Count=", 6))
01344 {
01345 nBit = atoi(pDecoder->apTagArg[Ix]+6);
01346 }
01347 }
01348
01349 nByte = (nBit + 7u) / 8u;
01350
01351 if(nByte != pDecoder->nTextBuf)
01352 {
01353 LLRP_tSErrorDetails *pError = &pDecoder->decoderHdr.ErrorDetails;
01354
01355 pDecoder->iNext = pDecoder->iLastText;
01356
01357 pError->eResultCode = LLRP_RC_MiscError;
01358 pError->pWhatStr = "incorrect number of bytes";
01359 pError->pRefType = pDecoderStream->pRefType;
01360 pError->pRefField = pFieldDescriptor;
01361 pError->OtherDetail = pDecoder->iNext;
01362 }
01363 else
01364 {
01365 Value = LLRP_u1v_construct(nBit);
01366 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
01367 pFieldDescriptor))
01368 {
01369 for(Ix = 0; Ix < nByte; Ix++)
01370 {
01371 Value.pValue[Ix] = pDecoder->aTextBuf[Ix];
01372 }
01373 Value.pValue[Ix] = 0;
01374 }
01375 }
01376 }
01377
01378 return Value;
01379 }
01380
01381 static llrp_u2_t
01382 get_u2 (
01383 LLRP_tSDecoderStream * pBaseDecoderStream,
01384 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01385 {
01386 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01387 llrp_u2_t Value;
01388
01389 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01390
01391 Value = (llrp_u2_t) getFieldIntg(pDecoderStream, pFieldDescriptor,
01392 0, 3);
01393
01394 return Value;
01395 }
01396
01397 static llrp_u96_t
01398 get_u96 (
01399 LLRP_tSDecoderStream * pBaseDecoderStream,
01400 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01401 {
01402 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01403 llrp_u96_t Value;
01404
01405 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01406 memset(&Value, 0, sizeof Value);
01407
01408 if(getFieldHexBinary(pDecoderStream, pFieldDescriptor))
01409 {
01410 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01411 llrp_u16_t nValue = pDecoder->nTextBuf;
01412 unsigned int Ix;
01413
01414 if(12 > nValue)
01415 {
01416 nValue = 12;
01417 }
01418
01419 for(Ix = 0; Ix < nValue; Ix++)
01420 {
01421 Value.aValue[Ix] = pDecoder->aTextBuf[Ix];
01422 }
01423
01424 /* TODO: check it */
01425 if(12 != pDecoder->nTextBuf)
01426 {
01427 LLRP_tSErrorDetails *pError = &pDecoder->decoderHdr.ErrorDetails;
01428
01429 pDecoder->iNext = pDecoder->iLastText;
01430
01431 pError->eResultCode = LLRP_RC_MiscError;
01432 pError->pWhatStr = "incorrect number of bytes";
01433 pError->pRefType = pDecoderStream->pRefType;
01434 pError->pRefField = pFieldDescriptor;
01435 pError->OtherDetail = pDecoder->iNext;
01436 }
01437 }
01438
01439 return Value;
01440 }
01441
01442 static llrp_utf8v_t
01443 get_utf8v (
01444 LLRP_tSDecoderStream * pBaseDecoderStream,
01445 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01446 {
01447 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01448 llrp_utf8v_t Value;
01449
01450 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01451 memset(&Value, 0, sizeof Value);
01452
01453 if(getFieldText(pDecoderStream, pFieldDescriptor))
01454 {
01455 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01456 llrp_u16_t nValue;
01457
01458 nValue = pDecoder->nTextBuf;
01459 Value = LLRP_utf8v_construct(nValue + 1);
01460 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
01461 pFieldDescriptor))
01462 {
01463 unsigned int Ix;
01464
01465 for(Ix = 0; Ix < nValue; Ix++)
01466 {
01467 Value.pValue[Ix] = pDecoder->aTextBuf[Ix];
01468 }
01469 Value.pValue[Ix] = 0;
01470 }
01471 }
01472
01473 return Value;
01474 }
01475
01476 static llrp_bytesToEnd_t
01477 get_bytesToEnd (
01478 LLRP_tSDecoderStream * pBaseDecoderStream,
01479 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01480 {
01481 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01482 llrp_bytesToEnd_t Value;
01483
01484 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01485 memset(&Value, 0, sizeof Value);
01486
01487 if(getFieldText(pDecoderStream, pFieldDescriptor))
01488 {
01489 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01490 llrp_u16_t nValue;
01491
01492 nValue = pDecoder->nTextBuf;
01493 Value = LLRP_bytesToEnd_construct(nValue);
01494 if(verifyVectorAllocation(pDecoderStream, Value.pValue,
01495 pFieldDescriptor))
01496 {
01497 unsigned int Ix;
01498
01499 for(Ix = 0; Ix < nValue; Ix++)
01500 {
01501 Value.pValue[Ix] = pDecoder->aTextBuf[Ix];
01502 }
01503 Value.pValue[Ix] = 0;
01504 }
01505 }
01506
01507 return Value;
01508 }
01509
01510 static int
01511 get_e1 (
01512 LLRP_tSDecoderStream * pBaseDecoderStream,
01513 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01514 {
01515 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01516 int Value;
01517
01518 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01519 Value = getFieldEnum(pDecoderStream, pFieldDescriptor);
01520 return Value;
01521 }
01522
01523 static int
01524 get_e2 (
01525 LLRP_tSDecoderStream * pBaseDecoderStream,
01526 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01527 {
01528 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01529 int Value;
01530
01531 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01532 Value = getFieldEnum(pDecoderStream, pFieldDescriptor);
01533 return Value;
01534 }
01535
01536 static int
01537 get_e8 (
01538 LLRP_tSDecoderStream * pBaseDecoderStream,
01539 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01540 {
01541 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01542 int Value;
01543
01544 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01545 Value = getFieldEnum(pDecoderStream, pFieldDescriptor);
01546 return Value;
01547 }
01548
01549 static int
01550 get_e16 (
01551 LLRP_tSDecoderStream * pBaseDecoderStream,
01552 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01553 {
01554 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01555 int Value;
01556
01557 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01558 Value = getFieldEnum(pDecoderStream, pFieldDescriptor);
01559 return Value;
01560 }
01561
01562 static int
01563 get_e32 (
01564 LLRP_tSDecoderStream * pBaseDecoderStream,
01565 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01566 {
01567 LLRP_tSXMLTextDecoderStream *pDecoderStream;
01568 int Value;
01569
01570 pDecoderStream = (LLRP_tSXMLTextDecoderStream *) pBaseDecoderStream;
01571 Value = getFieldEnum(pDecoderStream, pFieldDescriptor);
01572 return Value;
01573 }
01574
01575 static void
01576 get_reserved (
01577 LLRP_tSDecoderStream * pBaseDecoderStream,
01578 unsigned int nBit)
01579 {
01580 return;
01581 }
01582
01583 static void
01584 streamConstruct_outermost (
01585 LLRP_tSXMLTextDecoderStream * pDecoderStream,
01586 LLRP_tSXMLTextDecoder * pDecoder)
01587 {
01588 memset(pDecoderStream, 0, sizeof *pDecoderStream);
01589 pDecoderStream->decoderStreamHdr.pDecoderStreamOps =
01590 &s_XMLTextDecoderStreamOps;
01591
01592 pDecoderStream->pDecoder = pDecoder;
01593 pDecoderStream->pEnclosingDecoderStream = NULL;
01594 pDecoderStream->pRefType = NULL;
01595 }
01596
01597 static void
01598 streamConstruct_nested (
01599 LLRP_tSXMLTextDecoderStream * pDecoderStream,
01600 LLRP_tSXMLTextDecoderStream * pEnclosingDecoderStream)
01601 {
01602 LLRP_tSXMLTextDecoder * pDecoder;
01603
01604 pDecoder = pEnclosingDecoderStream->pDecoder;
01605
01606 memset(pDecoderStream, 0, sizeof *pDecoderStream);
01607 pDecoderStream->decoderStreamHdr.pDecoderStreamOps =
01608 &s_XMLTextDecoderStreamOps;
01609
01610 pDecoderStream->pDecoder = pDecoder;
01611 pDecoderStream->pEnclosingDecoderStream = pEnclosingDecoderStream;
01612 pDecoderStream->pRefType = NULL;
01613 }
01614
01615 static LLRP_tSElement *
01616 decodeElement (
01617 LLRP_tSXMLTextDecoderStream * pDecoderStream,
01618 int bAllowMessage)
01619 {
01620 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01621 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
01622 const LLRP_tSTypeRegistry * pRegistry = pDecoder->decoderHdr.pRegistry;
01623 LLRP_tSDecoderStream * pBaseDecoderStream =
01624 &pDecoderStream->decoderStreamHdr;
01625 const LLRP_tSTypeDescriptor *pTypeDescriptor;
01626 llrp_u32_t MessageID = 0;
01627 LLRP_tSElement * pElement;
01628 unsigned int iSave;
01629
01630 if(LLRP_RC_OK != pError->eResultCode)
01631 {
01632 return NULL;
01633 }
01634
01635 skipInsignificantText(pDecoder);
01636
01637 if(LLRP_RC_OK != pError->eResultCode)
01638 {
01639 return NULL;
01640 }
01641
01642 iSave = pDecoder->iNext;
01643
01644 getTag(pDecoder);
01645
01646 if(LLRP_RC_OK != pError->eResultCode)
01647 {
01648 return NULL;
01649 }
01650
01651 if(XMLTEXT_START_TAG != pDecoder->eTagType)
01652 {
01653 pDecoder->iNext = iSave;
01654
01655 // TODO good error
01656 pError->eResultCode = LLRP_RC_MiscError;
01657 pError->pWhatStr = "missing start tag";
01658 pError->pRefType = NULL;
01659 pError->pRefField = NULL;
01660 pError->OtherDetail = pDecoder->iNext;
01661 return NULL;
01662 }
01663
01664 pTypeDescriptor = LLRP_TypeRegistry_lookupByName(pRegistry,
01665 pDecoder->apTagArg[0]);
01666
01667 if(NULL == pTypeDescriptor)
01668 {
01669 pDecoder->iNext = iSave;
01670
01671 // TODO good error
01672 pError->eResultCode = LLRP_RC_UnknownParameterType;
01673 pError->pWhatStr = "unknown element type";
01674 pError->pRefType = NULL;
01675 pError->pRefField = NULL;
01676 pError->OtherDetail = pDecoder->iNext;
01677 return NULL;
01678 }
01679
01680 pDecoderStream->pRefType = pTypeDescriptor;
01681
01682 if(pTypeDescriptor->bIsMessage)
01683 {
01684 int iTagArg;
01685
01686 if(!bAllowMessage)
01687 {
01688 pDecoder->iNext = iSave;
01689
01690 pError->eResultCode = LLRP_RC_MiscError;
01691 pError->pWhatStr = "message as subparameter";
01692 pError->pRefType = pTypeDescriptor;
01693 pError->pRefField = NULL;
01694 pError->OtherDetail = pDecoder->iNext;
01695 return NULL;
01696 }
01697
01698 for(iTagArg = 1; iTagArg < pDecoder->nTagArg; iTagArg++)
01699 {
01700 char * pArg = pDecoder->apTagArg[iTagArg];
01701
01702 if(0 == strncmp("MessageID=", pArg, 10))
01703 {
01704 char * pTail;
01705
01706 MessageID = strtoul(pArg+10, &pTail, 0);
01707 if(*pTail != 0)
01708 {
01709 /* malformed */
01710 pDecoder->iNext = iSave;
01711
01712 pError->eResultCode = LLRP_RC_MiscError;
01713 pError->pWhatStr = "malformed MessageID";
01714 pError->pRefType = pTypeDescriptor;
01715 pError->pRefField = NULL;
01716 pError->OtherDetail = pDecoder->iNext;
01717 return NULL;
01718 }
01719 break;
01720 }
01721 }
01722 }
01723
01724 pElement = LLRP_Element_construct(pTypeDescriptor);
01725
01726 if(NULL == pElement)
01727 {
01728 pDecoder->iNext = iSave;
01729
01730 pError->eResultCode = LLRP_RC_MessageAllocationFailed;
01731 pError->pWhatStr = "element allocation failed";
01732 pError->pRefType = pTypeDescriptor;
01733 pError->pRefField = NULL;
01734 pError->OtherDetail = pDecoder->iNext;
01735 return NULL;
01736 }
01737
01738 ((LLRP_tSMessage *) pElement)->MessageID = MessageID;
01739
01740 pTypeDescriptor->pfDecodeFields(pElement, pBaseDecoderStream);
01741
01742 if(LLRP_RC_OK != pError->eResultCode)
01743 {
01744 LLRP_Element_destruct(pElement);
01745 return NULL;
01746 }
01747
01748 /*
01749 * Subparameters
01750 */
01751 for(;;)
01752 {
01753 LLRP_tSXMLTextDecoderStream NestStream;
01754 LLRP_tSElement * pSubElement;
01755 LLRP_tSParameter * pParameter;
01756
01757 skipInsignificantText(pDecoder);
01758
01759 if(LLRP_RC_OK != pError->eResultCode)
01760 {
01761 break;
01762 }
01763
01764 iSave = pDecoder->iNext;
01765
01766 getTag(pDecoder);
01767
01768 if(LLRP_RC_OK != pError->eResultCode)
01769 {
01770 break;
01771 }
01772
01773 if(XMLTEXT_END_TAG == pDecoder->eTagType)
01774 {
01775 if(0 != strcmp(pDecoder->apTagArg[0], pTypeDescriptor->pName))
01776 {
01777 pDecoder->iNext = iSave;
01778
01779 // TODO good error
01780 pError->eResultCode = LLRP_RC_MiscError;
01781 pError->pWhatStr = "missing end tag";
01782 pError->pRefType = pTypeDescriptor;
01783 pError->pRefField = NULL;
01784 pError->OtherDetail = pDecoder->iNext;
01785 }
01786 break;
01787 }
01788
01789 pDecoder->iNext = iSave;
01790
01791 streamConstruct_nested(&NestStream, pDecoderStream);
01792
01793 pSubElement = decodeElement(&NestStream, FALSE);
01794
01795 if(NULL == pSubElement)
01796 {
01797 if(LLRP_RC_OK == pError->eResultCode)
01798 {
01799 pDecoder->iNext = iSave;
01800
01801 pError->eResultCode = LLRP_RC_Botch;
01802 pError->pWhatStr = "botch -- no param and no error";
01803 pError->pRefType = pTypeDescriptor;
01804 pError->pRefField = NULL;
01805 pError->OtherDetail = pDecoder->iNext;
01806 }
01807 break;
01808 }
01809
01810 pParameter = (LLRP_tSParameter *) pSubElement;
01811
01812 pParameter->elementHdr.pParent = pElement;
01813 LLRP_Element_addSubParameterToAllList(pElement, pParameter);
01814 }
01815
01816 if(LLRP_RC_OK != pError->eResultCode)
01817 {
01818 LLRP_Element_destruct(pElement);
01819 return NULL;
01820 }
01821
01822 pTypeDescriptor->pfAssimilateSubParameters(pElement, pError);
01823
01824 if(LLRP_RC_OK != pError->eResultCode)
01825 {
01826 LLRP_Element_destruct(pElement);
01827 return NULL;
01828 }
01829
01830 return pElement;
01831 }
01832
01833 static llrp_bool_t
01834 getFieldText (
01835 LLRP_tSXMLTextDecoderStream * pDecoderStream,
01836 const LLRP_tSFieldDescriptor *pFieldDescriptor)
01837 {
01838 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01839 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
01840 const char * pFieldName = pFieldDescriptor->pName;
01841
01842 if(LLRP_RC_OK != pError->eResultCode)
01843 {
01844 return FALSE;
01845 }
01846
01847 skipInsignificantText(pDecoder);
01848
01849 if(LLRP_RC_OK != pError->eResultCode)
01850 {
01851 return FALSE;
01852 }
01853
01854 if(!matchStartTag(pDecoder, pFieldName))
01855 {
01856 if(LLRP_RC_OK == pError->eResultCode)
01857 {
01858 pError->eResultCode = LLRP_RC_MiscError;
01859 pError->pWhatStr = "missing field start tag";
01860 pError->pRefType = pDecoderStream->pRefType;
01861 pError->pRefField = pFieldDescriptor;
01862 pError->OtherDetail = pDecoder->iNext;
01863 }
01864
01865 return FALSE;
01866 }
01867
01868 getText(pDecoder);
01869
01870 if(LLRP_RC_OK != pError->eResultCode)
01871 {
01872 return FALSE;
01873 }
01874
01875 if(!matchEndTag(pDecoder, pFieldName))
01876 {
01877 if(LLRP_RC_OK == pError->eResultCode)
01878 {
01879 pError->eResultCode = LLRP_RC_MiscError;
01880 pError->pWhatStr = "missing field end tag";
01881 pError->pRefType = pDecoderStream->pRefType;
01882 pError->pRefField = pFieldDescriptor;
01883 pError->OtherDetail = pDecoder->iNext;
01884 }
01885
01886 return FALSE;
01887 }
01888
01889 return TRUE;
01890 }
01891
01892 static llrp_s64_t
01893 getFieldIntg (
01894 LLRP_tSXMLTextDecoderStream * pDecoderStream,
01895 const LLRP_tSFieldDescriptor *pFieldDescriptor,
01896 llrp_s64_t minValue,
01897 llrp_s64_t maxValue)
01898 {
01899 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01900
01901 if(getFieldIntgVec(pDecoderStream, pFieldDescriptor,
01902 1, minValue, maxValue))
01903 {
01904 if(1 != pDecoder->nIntgValue)
01905 {
01906 LLRP_tSErrorDetails *pError = &pDecoder->decoderHdr.ErrorDetails;
01907
01908 pDecoder->iNext = pDecoder->iLastText;
01909
01910 pError->eResultCode = LLRP_RC_MiscError;
01911 pError->pWhatStr = "missing value";
01912 pError->pRefType = pDecoderStream->pRefType;
01913 pError->pRefField = pFieldDescriptor;
01914 pError->OtherDetail = pDecoder->iNext;
01915 }
01916
01917 return pDecoder->aIntgValue[0];
01918 }
01919 else
01920 {
01921 return 0;
01922 }
01923 }
01924
01925 static llrp_bool_t
01926 getFieldIntgVec (
01927 LLRP_tSXMLTextDecoderStream * pDecoderStream,
01928 const LLRP_tSFieldDescriptor *pFieldDescriptor,
01929 unsigned int nValueMax,
01930 llrp_s64_t minValue,
01931 llrp_s64_t maxValue)
01932 {
01933 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
01934 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
01935 const char * pFieldName = pFieldDescriptor->pName;
01936 unsigned int iSave;
01937
01938 pDecoder->nIntgValue = 0;
01939
01940 if(0 == nValueMax)
01941 {
01942 nValueMax = 200;
01943 }
01944
01945 if(LLRP_RC_OK != pError->eResultCode)
01946 {
01947 return FALSE;
01948 }
01949
01950 skipInsignificantText(pDecoder);
01951
01952 if(LLRP_RC_OK != pError->eResultCode)
01953 {
01954 return FALSE;
01955 }
01956
01957 if(!matchStartTag(pDecoder, pFieldName))
01958 {
01959 if(LLRP_RC_OK == pError->eResultCode)
01960 {
01961 pError->eResultCode = LLRP_RC_MiscError;
01962 pError->pWhatStr = "missing field start tag";
01963 pError->pRefType = pDecoderStream->pRefType;
01964 pError->pRefField = pFieldDescriptor;
01965 pError->OtherDetail = pDecoder->iNext;
01966 }
01967
01968 return FALSE;
01969 }
01970
01971 pDecoder->iLastText = pDecoder->iNext;
01972
01973 for(;;)
01974 {
01975 int c = getTextChar(pDecoder);
01976 int bNeg = FALSE;
01977 unsigned int nDigit = 0;
01978 llrp_s64_t intgValue = 0;
01979
01980 if(LLRP_RC_OK != pError->eResultCode)
01981 {
01982 return FALSE;
01983 }
01984
01985 if(0 > c)
01986 {
01987 break;
01988 }
01989
01990 if(isspace(c))
01991 {
01992 continue;
01993 }
01994
01995 iSave = pDecoder->iLastGetTextChar;
01996
01997 if('-' == c)
01998 {
01999 bNeg = TRUE;
02000 c = getTextChar(pDecoder);
02001 }
02002
02003 while(0 <= c && isdigit(c))
02004 {
02005 intgValue *= 10u;
02006 intgValue += c - '0';
02007 nDigit++;
02008 c = getTextChar(pDecoder);
02009 }
02010
02011 if(LLRP_RC_OK != pError->eResultCode)
02012 {
02013 return FALSE;
02014 }
02015
02016 if(0 == nDigit)
02017 {
02018 pDecoder->iNext = iSave;
02019
02020 pError->eResultCode = LLRP_RC_MiscError;
02021 pError->pWhatStr = "conversion error";
02022 pError->pRefType = pDecoderStream->pRefType;
02023 pError->pRefField = pFieldDescriptor;
02024 pError->OtherDetail = pDecoder->iNext;
02025
02026 return FALSE;
02027 }
02028
02029 if(bNeg)
02030 {
02031 intgValue = -intgValue;
02032 }
02033
02034 if(intgValue < minValue || maxValue < intgValue)
02035 {
02036 pDecoder->iNext = iSave;
02037
02038 pError->eResultCode = LLRP_RC_MiscError;
02039 pError->pWhatStr = "out of range";
02040 pError->pRefType = pDecoderStream->pRefType;
02041 pError->pRefField = pFieldDescriptor;
02042 pError->OtherDetail = pDecoder->iNext;
02043
02044 return FALSE;
02045 }
02046
02047 if(256u <= pDecoder->nIntgValue || nValueMax <= pDecoder->nIntgValue)
02048 {
02049 pDecoder->iNext = iSave;
02050
02051 pError->eResultCode = LLRP_RC_MiscError;
02052 pError->pWhatStr = "too many values";
02053 pError->pRefType = pDecoderStream->pRefType;
02054 pError->pRefField = pFieldDescriptor;
02055 pError->OtherDetail = pDecoder->iNext;
02056
02057 return FALSE;
02058 }
02059
02060 pDecoder->aIntgValue[pDecoder->nIntgValue++] = intgValue;
02061 }
02062
02063 #if 0
02064 if(0 == pDecoder->nIntgValue)
02065 {
02066 pError->eResultCode = LLRP_RC_MiscError;
02067 pError->pWhatStr = "missing value(s)";
02068 pError->pRefType = pDecoderStream->pRefType;
02069 pError->pRefField = pFieldDescriptor;
02070 pError->OtherDetail = pDecoder->iNext;
02071
02072 return FALSE;
02073 }
02074 #endif
02075
02076 if(!matchEndTag(pDecoder, pFieldName))
02077 {
02078 pError->eResultCode = LLRP_RC_FieldUnderrun;
02079 pError->pWhatStr = "missing field end tag";
02080 pError->pRefType = pDecoderStream->pRefType;
02081 pError->pRefField = pFieldDescriptor;
02082 pError->OtherDetail = pDecoder->iNext;
02083
02084 return FALSE;
02085 }
02086
02087 return TRUE;
02088 }
02089
02090 static llrp_bool_t
02091 getFieldHexBinary (
02092 LLRP_tSXMLTextDecoderStream * pDecoderStream,
02093 const LLRP_tSFieldDescriptor *pFieldDescriptor)
02094 {
02095 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
02096 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
02097 const char * pFieldName = pFieldDescriptor->pName;
02098 unsigned int iSave;
02099 unsigned int nDigit = 0;
02100 llrp_u8_t intgValue = 0;
02101
02102 pDecoder->nTextBuf = 0;
02103
02104 if(LLRP_RC_OK != pError->eResultCode)
02105 {
02106 return FALSE;
02107 }
02108
02109 skipInsignificantText(pDecoder);
02110
02111 if(LLRP_RC_OK != pError->eResultCode)
02112 {
02113 return FALSE;
02114 }
02115
02116 if(!matchStartTag(pDecoder, pFieldName))
02117 {
02118 if(LLRP_RC_OK == pError->eResultCode)
02119 {
02120 pError->eResultCode = LLRP_RC_MiscError;
02121 pError->pWhatStr = "missing field start tag";
02122 pError->pRefType = pDecoderStream->pRefType;
02123 pError->pRefField = pFieldDescriptor;
02124 pError->OtherDetail = pDecoder->iNext;
02125 }
02126
02127 return FALSE;
02128 }
02129
02130 pDecoder->iLastText = pDecoder->iNext;
02131
02132 for(;;)
02133 {
02134 int c = getTextChar(pDecoder);
02135
02136 if(LLRP_RC_OK != pError->eResultCode)
02137 {
02138 return FALSE;
02139 }
02140
02141 if(0 > c)
02142 {
02143 break;
02144 }
02145
02146 if(isspace(c))
02147 {
02148 continue;
02149 }
02150
02151 iSave = pDecoder->iLastGetTextChar;
02152
02153 if('0' <= c && c <= '9')
02154 {
02155 c -= '0';
02156 }
02157 else if('A' <= c && c <= 'F')
02158 {
02159 c -= 'A';
02160 c += 10;
02161 }
02162 else if('a' <= c && c <= 'f')
02163 {
02164 c -= 'a';
02165 c += 10;
02166 }
02167 else
02168 {
02169 pDecoder->iNext = iSave;
02170
02171 pError->eResultCode = LLRP_RC_MiscError;
02172 pError->pWhatStr = "conversion error";
02173 pError->pRefType = pDecoderStream->pRefType;
02174 pError->pRefField = pFieldDescriptor;
02175 pError->OtherDetail = pDecoder->iNext;
02176
02177 return FALSE;
02178 }
02179
02180 intgValue <<= 4u;
02181 intgValue += c;
02182 nDigit++;
02183
02184 if(2 == nDigit)
02185 {
02186 pDecoder->aTextBuf[pDecoder->nTextBuf++] = intgValue;
02187 intgValue = 0;
02188 nDigit = 0;
02189 }
02190 }
02191
02192 if(nDigit != 0)
02193 {
02194 intgValue <<= 4u;
02195 pDecoder->aTextBuf[pDecoder->nTextBuf++] = intgValue;
02196 }
02197
02198 if(!matchEndTag(pDecoder, pFieldName))
02199 {
02200 pError->eResultCode = LLRP_RC_FieldUnderrun;
02201 pError->pWhatStr = "missing field end tag";
02202 pError->pRefType = pDecoderStream->pRefType;
02203 pError->pRefField = pFieldDescriptor;
02204 pError->OtherDetail = pDecoder->iNext;
02205
02206 return FALSE;
02207 }
02208
02209 return TRUE;
02210 }
02211
02212 static int
02213 getFieldEnum (
02214 LLRP_tSXMLTextDecoderStream * pDecoderStream,
02215 const LLRP_tSFieldDescriptor *pFieldDescriptor)
02216 {
02217 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
02218 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
02219 const LLRP_tSEnumTableEntry *pEntry;
02220 unsigned char * pScan;
02221
02222 if(!getFieldText(pDecoderStream, pFieldDescriptor))
02223 {
02224 return 0;
02225 }
02226
02227 /*
02228 * Trim trailing whitespace
02229 */
02230 pScan = strchr(pDecoder->aTextBuf, 0);
02231 while(pScan > pDecoder->aTextBuf && isspace(pScan[-1]))
02232 {
02233 *--pScan = 0;
02234 }
02235
02236 /*
02237 * Skip over leading white space
02238 */
02239 pScan = pDecoder->aTextBuf;
02240 while(isspace(*pScan))
02241 {
02242 pScan++;
02243 }
02244
02245 for(
02246 pEntry = pFieldDescriptor->pEnumTable;
02247 NULL != pEntry->pName;
02248 pEntry++)
02249 {
02250 if(0 == strcmp(pEntry->pName, pScan))
02251 {
02252 break;
02253 }
02254 }
02255
02256 if(NULL == pEntry->pName)
02257 {
02258 /*
02259 * TODO: check for intg value
02260 */
02261
02262 if(LLRP_RC_OK == pError->eResultCode)
02263 {
02264 pDecoder->iNext = pDecoder->iLastText;
02265
02266 pError->eResultCode = LLRP_RC_MiscError;
02267 pError->pWhatStr = "invalid value";
02268 pError->pRefType = pDecoderStream->pRefType;
02269 pError->pRefField = pFieldDescriptor;
02270 pError->OtherDetail = pDecoder->iNext;
02271 }
02272
02273 return 0;
02274 }
02275
02276 return pEntry->Value;
02277 }
02278
02279 static llrp_bool_t
02280 verifyVectorAllocation (
02281 LLRP_tSXMLTextDecoderStream * pDecoderStream,
02282 const void * pValue,
02283 const LLRP_tSFieldDescriptor *pFieldDescriptor)
02284 {
02285 if(NULL == pValue)
02286 {
02287 LLRP_tSXMLTextDecoder * pDecoder = pDecoderStream->pDecoder;
02288 LLRP_tSErrorDetails * pError = &pDecoder->decoderHdr.ErrorDetails;
02289
02290 pError->eResultCode = LLRP_RC_FieldAllocationFailed;
02291 pError->pWhatStr = "field allocation failed";
02292 pError->pRefType = pDecoderStream->pRefType;
02293 pError->pRefField = pFieldDescriptor;
02294 pError->OtherDetail = pDecoder->iNext;
02295
02296 return FALSE;
02297 }
02298 else
02299 {
02300 return TRUE;
02301 }
02302 }