X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/46b0747592074017ff0ea4b33d4a7194235886e5..0c097ef3435d2a45c1ee4ac80f8bd3f254fb8df5:/libs/smux/xer_decoder.c?ds=inline diff --git a/libs/smux/xer_decoder.c b/libs/smux/xer_decoder.c index 161dc78c..5b87703a 100644 --- a/libs/smux/xer_decoder.c +++ b/libs/smux/xer_decoder.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2005 Lev Walkin . All rights reserved. + * Copyright (c) 2004-2017 Lev Walkin . All rights reserved. * Redistribution and modifications are permitted subject to BSD license. */ #include @@ -11,9 +11,10 @@ * Decode the XER encoding of a given type. */ asn_dec_rval_t -xer_decode(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, - void **struct_ptr, const void *buffer, size_t size) { - asn_codec_ctx_t s_codec_ctx; +xer_decode(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **struct_ptr, + const void *buffer, size_t size) { + asn_codec_ctx_t s_codec_ctx; /* * Stack checker requires that the codec context @@ -27,14 +28,14 @@ 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; } /* * Invoke type-specific decoder. */ - return td->xer_decoder(opt_codec_ctx, td, struct_ptr, 0, buffer, size); + return td->op->xer_decoder(opt_codec_ctx, td, struct_ptr, 0, buffer, size); } @@ -70,6 +71,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 +85,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 +113,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; } @@ -197,7 +202,7 @@ xer_check_tag(const void *buf_ptr, int size, const char *need_tag) { * Generalized function for decoding the primitive values. */ asn_dec_rval_t -xer_decode_general(asn_codec_ctx_t *opt_codec_ctx, +xer_decode_general(const asn_codec_ctx_t *opt_codec_ctx, asn_struct_ctx_t *ctx, /* Type decoder context */ void *struct_key, const char *xml_tag, /* Expected XML tag */ @@ -230,12 +235,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 +320,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 +334,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); } /*