Skip to content
Snippets Groups Projects
Commit 1e443961 authored by Lev Walkin's avatar Lev Walkin
Browse files

context sensitivity

parent 6ab88965
No related branches found
No related tags found
No related merge requests found
...@@ -146,7 +146,7 @@ BOOLEAN__xer_body_decode(void *sptr, void *chunk_buf, size_t chunk_size) { ...@@ -146,7 +146,7 @@ BOOLEAN__xer_body_decode(void *sptr, void *chunk_buf, size_t chunk_size) {
/* "<false/>" */ /* "<false/>" */
*st = 0; *st = 0;
break; break;
case XCT_UNEXPECTED: case XCT_UNKNOWN_BO:
if(xer_check_tag(chunk_buf, chunk_size, "true") if(xer_check_tag(chunk_buf, chunk_size, "true")
!= XCT_BOTH) != XCT_BOTH)
return -1; return -1;
......
...@@ -639,7 +639,7 @@ CHOICE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -639,7 +639,7 @@ CHOICE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
/* /*
* Get the next part of the XML stream. * Get the next part of the XML stream.
*/ */
ch_size = xer_next_token(buf_ptr, size, &ch_type); ch_size = xer_next_token(&ctx->context, buf_ptr, size, &ch_type);
switch(ch_size) { switch(ch_size) {
case -1: RETURN(RC_FAIL); case -1: RETURN(RC_FAIL);
case 0: RETURN(RC_WMORE); case 0: RETURN(RC_WMORE);
...@@ -667,6 +667,7 @@ CHOICE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -667,6 +667,7 @@ CHOICE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
continue; continue;
case 1: case 1:
ctx->phase = 3; ctx->phase = 3;
/* Fall through */
case 0: case 0:
XER_ADVANCE(ch_size); XER_ADVANCE(ch_size);
continue; continue;
......
...@@ -689,7 +689,8 @@ SEQUENCE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -689,7 +689,8 @@ SEQUENCE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
/* /*
* Get the next part of the XML stream. * Get the next part of the XML stream.
*/ */
ch_size = xer_next_token(buf_ptr, size, &ch_type); ch_size = xer_next_token(&ctx->context, buf_ptr, size,
&ch_type);
switch(ch_size) { switch(ch_size) {
case -1: RETURN(RC_FAIL); case -1: RETURN(RC_FAIL);
case 0: RETURN(RC_WMORE); case 0: RETURN(RC_WMORE);
......
...@@ -671,7 +671,8 @@ SET_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -671,7 +671,8 @@ SET_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
/* /*
* Get the next part of the XML stream. * Get the next part of the XML stream.
*/ */
ch_size = xer_next_token(buf_ptr, size, &ch_type); ch_size = xer_next_token(&ctx->context,
buf_ptr, size, &ch_type);
switch(ch_size) { switch(ch_size) {
case -1: RETURN(RC_FAIL); case -1: RETURN(RC_FAIL);
case 0: RETURN(RC_WMORE); case 0: RETURN(RC_WMORE);
...@@ -695,12 +696,11 @@ SET_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -695,12 +696,11 @@ SET_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
case -1: case -1:
ctx->phase = 4; ctx->phase = 4;
RETURN(RC_FAIL); RETURN(RC_FAIL);
case 0:
XER_ADVANCE(ch_size);
continue;
case 1: case 1:
XER_ADVANCE(ch_size);
ctx->phase = 1; ctx->phase = 1;
/* Fall through */
case 0:
XER_ADVANCE(ch_size);
continue; continue;
case 2: case 2:
ctx->phase = 1; ctx->phase = 1;
......
...@@ -536,7 +536,8 @@ SET_OF_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -536,7 +536,8 @@ SET_OF_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
/* /*
* Get the next part of the XML stream. * Get the next part of the XML stream.
*/ */
ch_size = xer_next_token(buf_ptr, size, &ch_type); ch_size = xer_next_token(&ctx->context,
buf_ptr, size, &ch_type);
switch(ch_size) { switch(ch_size) {
case -1: RETURN(RC_FAIL); case -1: RETURN(RC_FAIL);
case 0: RETURN(RC_WMORE); case 0: RETURN(RC_WMORE);
......
...@@ -23,10 +23,11 @@ struct asn_TYPE_member_s; /* Forward declaration */ ...@@ -23,10 +23,11 @@ struct asn_TYPE_member_s; /* Forward declaration */
* included into certain target language's structures, such as compound types. * included into certain target language's structures, such as compound types.
*/ */
typedef struct asn_struct_ctx_s { typedef struct asn_struct_ctx_s {
int phase; /* Decoding phase */ short phase; /* Decoding phase */
int step; /* Elementary step of a phase */ short step; /* Elementary step of a phase */
ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */ int context; /* Other context information */
void *ptr; /* Decoder-specific stuff (stack elements) */ void *ptr; /* Decoder-specific stuff (stack elements) */
ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */
} asn_struct_ctx_t; } asn_struct_ctx_t;
#include <ber_decoder.h> /* Basic Encoding Rules decoder */ #include <ber_decoder.h> /* Basic Encoding Rules decoder */
......
...@@ -17,10 +17,11 @@ check_next(char *xerbuf, int expected_chunk_size, pxer_chunk_type_e expected_chu ...@@ -17,10 +17,11 @@ check_next(char *xerbuf, int expected_chunk_size, pxer_chunk_type_e expected_chu
int xerbuf_len = strlen(xerbuf); int xerbuf_len = strlen(xerbuf);
pxer_chunk_type_e ch_type; pxer_chunk_type_e ch_type;
ssize_t ch_size; ssize_t ch_size;
int state = 0;
if(expected_chunk_size == -1) if(expected_chunk_size == -1)
expected_chunk_size = xerbuf_len; expected_chunk_size = xerbuf_len;
ch_size = xer_next_token(xerbuf, xerbuf_len, &ch_type); ch_size = xer_next_token(&state, xerbuf, xerbuf_len, &ch_type);
printf("[%s]:%d\n", xerbuf, xerbuf_len); printf("[%s]:%d\n", xerbuf, xerbuf_len);
printf("chunk sizes: %d vs %d, chunk types: %d vs %d\n", printf("chunk sizes: %d vs %d, chunk types: %d vs %d\n",
......
...@@ -51,13 +51,13 @@ xer__token_cb(pxml_chunk_type_e type, void *_chunk_data, size_t _chunk_size, voi ...@@ -51,13 +51,13 @@ xer__token_cb(pxml_chunk_type_e type, void *_chunk_data, size_t _chunk_size, voi
* Fetch the next token from the XER/XML stream. * Fetch the next token from the XER/XML stream.
*/ */
ssize_t ssize_t
xer_next_token(void *buffer, size_t size, pxer_chunk_type_e *ch_type) { xer_next_token(int *stateContext, void *buffer, size_t size, pxer_chunk_type_e *ch_type) {
struct xer__cb_arg arg; struct xer__cb_arg arg;
int stateContext = 0; int new_stateContext = *stateContext;
ssize_t ret; ssize_t ret;
arg.callback_not_invoked = 1; arg.callback_not_invoked = 1;
ret = pxml_parse(&stateContext, buffer, size, xer__token_cb, &arg); ret = pxml_parse(&new_stateContext, buffer, size, xer__token_cb, &arg);
if(ret < 0) return -1; if(ret < 0) return -1;
if(arg.callback_not_invoked) { if(arg.callback_not_invoked) {
assert(ret == 0); /* No data was consumed */ assert(ret == 0); /* No data was consumed */
...@@ -65,7 +65,6 @@ xer_next_token(void *buffer, size_t size, pxer_chunk_type_e *ch_type) { ...@@ -65,7 +65,6 @@ xer_next_token(void *buffer, size_t size, pxer_chunk_type_e *ch_type) {
} else { } else {
assert(arg.chunk_size); assert(arg.chunk_size);
assert(arg.chunk_buf == buffer); assert(arg.chunk_buf == buffer);
assert(stateContext == 0);
} }
/* /*
...@@ -85,6 +84,7 @@ xer_next_token(void *buffer, size_t size, pxer_chunk_type_e *ch_type) { ...@@ -85,6 +84,7 @@ xer_next_token(void *buffer, size_t size, pxer_chunk_type_e *ch_type) {
break; break;
} }
*stateContext = new_stateContext;
return arg.chunk_size; return arg.chunk_size;
} }
...@@ -136,13 +136,13 @@ xer_check_tag(const void *buf_ptr, int size, const char *need_tag) { ...@@ -136,13 +136,13 @@ xer_check_tag(const void *buf_ptr, int size, const char *need_tag) {
return ct; return ct;
} }
} }
return (XCT__UNK__MASK | ct); return (xer_check_tag_e)(XCT__UNK__MASK | ct);
} }
if(b == 0) if(b == 0)
return XCT_BROKEN; /* Embedded 0 in buf?! */ return XCT_BROKEN; /* Embedded 0 in buf?! */
} }
if(*need_tag) if(*need_tag)
return (XCT__UNK__MASK | ct); return (xer_check_tag_e)(XCT__UNK__MASK | ct);
return ct; return ct;
} }
...@@ -168,7 +168,8 @@ xer_check_tag(const void *buf_ptr, int size, const char *need_tag) { ...@@ -168,7 +168,8 @@ xer_check_tag(const void *buf_ptr, int size, const char *need_tag) {
(struct_key, chunk_buf, chunk_size, \ (struct_key, chunk_buf, chunk_size, \
(size_t)chunk_size < size); \ (size_t)chunk_size < size); \
if(converted_size == -1) RETURN(RC_FAIL); \ if(converted_size == -1) RETURN(RC_FAIL); \
if(converted_size == 0 && size == chunk_size) \ if(converted_size == 0 \
&& size == (size_t)chunk_size) \
RETURN(RC_WMORE); \ RETURN(RC_WMORE); \
chunk_size = converted_size; \ chunk_size = converted_size; \
} while(0) } while(0)
...@@ -212,7 +213,8 @@ xer_decode_general(asn_codec_ctx_t *opt_codec_ctx, ...@@ -212,7 +213,8 @@ xer_decode_general(asn_codec_ctx_t *opt_codec_ctx,
/* /*
* Get the next part of the XML stream. * Get the next part of the XML stream.
*/ */
ch_size = xer_next_token(buf_ptr, size, &ch_type); ch_size = xer_next_token(&ctx->context, buf_ptr, size,
&ch_type);
switch(ch_size) { switch(ch_size) {
case -1: RETURN(RC_FAIL); case -1: RETURN(RC_FAIL);
case 0: case 0:
......
...@@ -63,7 +63,8 @@ asn_dec_rval_t xer_decode_general(asn_codec_ctx_t *opt_codec_ctx, ...@@ -63,7 +63,8 @@ asn_dec_rval_t xer_decode_general(asn_codec_ctx_t *opt_codec_ctx,
PXER_TEXT, /* Plain text between XER tags */ PXER_TEXT, /* Plain text between XER tags */
PXER_COMMENT, /* A comment, may be part of */ PXER_COMMENT, /* A comment, may be part of */
} pxer_chunk_type_e; } pxer_chunk_type_e;
ssize_t xer_next_token(void *buffer, size_t size, pxer_chunk_type_e *_ch_type); ssize_t xer_next_token(int *stateContext,
void *buffer, size_t size, pxer_chunk_type_e *_ch_type);
/* /*
* This function checks the buffer against the tag name is expected to occur. * This function checks the buffer against the tag name is expected to occur.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment