/*
- * Copyright (c) 2004, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
+ * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_application.h>
* 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
} 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);
}
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);
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;
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;
}
* 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 */
*/
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;
}
-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;
* 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);
}
/*