]> git.stg.codes - stg.git/blobdiff - libs/smux/xer_decoder.c
Finalize transition to Boost.UnitTest.
[stg.git] / libs / smux / xer_decoder.c
index 161dc78ce5320368d07c0cd9b01032d07997e0fb..299a7c1eed8ae2bb9056ce3091612e072a6fe069 100644 (file)
@@ -27,7 +27,7 @@ xer_decode(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
        } else {
                /* If context is not given, be security-conscious anyway */
                memset(&s_codec_ctx, 0, sizeof(s_codec_ctx));
-               s_codec_ctx.max_stack_size = _ASN_DEFAULT_STACK_MAX;
+               s_codec_ctx.max_stack_size = ASN__DEFAULT_STACK_MAX;
                opt_codec_ctx = &s_codec_ctx;
        }
 
@@ -70,6 +70,7 @@ xer_next_token(int *stateContext, const void *buffer, size_t size, pxer_chunk_ty
        if(ret < 0) return -1;
        if(arg.callback_not_invoked) {
                assert(ret == 0);       /* No data was consumed */
+        *ch_type = PXER_WMORE;
                return 0;               /* Try again with more data */
        } else {
                assert(arg.chunk_size);
@@ -83,7 +84,9 @@ xer_next_token(int *stateContext, const void *buffer, size_t size, pxer_chunk_ty
        case PXML_TEXT:
                *ch_type = PXER_TEXT;
                break;
-       case PXML_TAG: return 0;        /* Want more */
+       case PXML_TAG:
+        *ch_type = PXER_WMORE;
+        return 0;      /* Want more */
        case PXML_TAG_END:
                *ch_type = PXER_TAG;
                break;
@@ -109,7 +112,8 @@ xer_check_tag(const void *buf_ptr, int size, const char *need_tag) {
 
        if(size < 2 || buf[0] != LANGLE || buf[size-1] != RANGLE) {
                if(size >= 2)
-               ASN_DEBUG("Broken XML tag: \"%c...%c\"", buf[0], buf[size - 1]);
+                       ASN_DEBUG("Broken XML tag: \"%c...%c\"",
+                       buf[0], buf[size - 1]);
                return XCT_BROKEN;
        }
 
@@ -230,12 +234,12 @@ xer_decode_general(asn_codec_ctx_t *opt_codec_ctx,
                 */
                ch_size = xer_next_token(&ctx->context, buf_ptr, size,
                        &ch_type);
-               switch(ch_size) {
-               case -1: RETURN(RC_FAIL);
-               case 0:
-                       RETURN(RC_WMORE);
-               default:
+               if(ch_size == -1) {
+            RETURN(RC_FAIL);
+        } else {
                        switch(ch_type) {
+                       case PXER_WMORE:
+                RETURN(RC_WMORE);
                        case PXER_COMMENT:              /* Got XML comment */
                                ADVANCE(ch_size);       /* Skip silently */
                                continue;
@@ -315,8 +319,8 @@ xer_decode_general(asn_codec_ctx_t *opt_codec_ctx,
 }
 
 
-int
-xer_is_whitespace(const void *chunk_buf, size_t chunk_size) {
+size_t
+xer_whitespace_span(const void *chunk_buf, size_t chunk_size) {
        const char *p = (const char *)chunk_buf;
        const char *pend = p + chunk_size;
 
@@ -329,12 +333,13 @@ xer_is_whitespace(const void *chunk_buf, size_t chunk_size) {
                 * SPACE (32)
                 */
                case 0x09: case 0x0a: case 0x0d: case 0x20:
-                       break;
+                       continue;
                default:
-                       return 0;
+                       break;
                }
+               break;
        }
-       return 1;       /* All whitespace */
+       return (p - (const char *)chunk_buf);
 }
 
 /*