Commit e56a4b33 authored by v0-e's avatar v0-e

jer: SET decoder fix

parent e20bd952
...@@ -33,22 +33,6 @@ ...@@ -33,22 +33,6 @@
consumed_myself += num; \ consumed_myself += num; \
} while(0) } while(0)
#define JER_SAVE_STATE \
do { \
ptr0 = ptr; \
size0 = size; \
consumed_myself0 = consumed_myself; \
context0 = ctx->context;\
} while(0)
#define JER_RESTORE_STATE \
do { \
ptr = ptr0; \
size = size0; \
consumed_myself = consumed_myself0; \
ctx->context = context0; \
} while(0)
/* /*
* Decode the JER (JSON) data. * Decode the JER (JSON) data.
*/ */
...@@ -62,7 +46,6 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -62,7 +46,6 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
const asn_SET_specifics_t *specs const asn_SET_specifics_t *specs
= (const asn_SET_specifics_t *)td->specifics; = (const asn_SET_specifics_t *)td->specifics;
asn_TYPE_member_t *elements = td->elements; asn_TYPE_member_t *elements = td->elements;
const char *json_key = opt_mname ? opt_mname : td->xml_tag;
/* /*
* ... and parts of the structure being constructed. * ... and parts of the structure being constructed.
...@@ -72,7 +55,7 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -72,7 +55,7 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
asn_dec_rval_t rval; /* Return value from a decoder */ asn_dec_rval_t rval; /* Return value from a decoder */
ssize_t consumed_myself = 0; /* Consumed bytes from ptr */ ssize_t consumed_myself = 0; /* Consumed bytes from ptr */
ssize_t edx = -1; /* Element index */ ssize_t edx; /* Element index */
/* /*
* Create the target structure if it is not present already. * Create the target structure if it is not present already.
...@@ -87,12 +70,6 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -87,12 +70,6 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
*/ */
ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset); ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset);
asn_dec_rval_t tmprval = {0};
/* Restore vars */
const void* ptr0 = ptr;
size_t size0 = size;
ssize_t consumed_myself0 = consumed_myself; /* Consumed bytes from ptr */
int context0 = ctx->context;
/* /*
* Phases of JER/JSON processing: * Phases of JER/JSON processing:
...@@ -113,10 +90,18 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -113,10 +90,18 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
* Go inside the inner member of a sequence. * Go inside the inner member of a sequence.
*/ */
if(ctx->phase == 2) { if(ctx->phase == 2) {
asn_dec_rval_t tmprval;
void *memb_ptr_dontuse; /* Pointer to the member */ void *memb_ptr_dontuse; /* Pointer to the member */
void **memb_ptr2; /* Pointer to that pointer */ void **memb_ptr2; /* Pointer to that pointer */
elm = &td->elements[edx]; if(ASN_SET_ISPRESENT2((char *)st + specs->pres_offset,
edx)) {
ASN_DEBUG("SET %s: Duplicate element %s (%" ASN_PRI_SSIZE ")",
td->name, elements[edx].name, edx);
RETURN(RC_FAIL);
}
elm = &elements[edx];
if(elm->flags & ATF_POINTER) { if(elm->flags & ATF_POINTER) {
/* Member is a pointer to another structure */ /* Member is a pointer to another structure */
memb_ptr2 = (void **)((char *)st + elm->memb_offset); memb_ptr2 = (void **)((char *)st + elm->memb_offset);
...@@ -125,21 +110,16 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -125,21 +110,16 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
memb_ptr2 = &memb_ptr_dontuse; /* Only use of memb_ptr_dontuse */ memb_ptr2 = &memb_ptr_dontuse; /* Only use of memb_ptr_dontuse */
} }
if(elm->flags & ATF_OPEN_TYPE) { /* Invoke the inner type decoder, m.b. multiple times */
//tmprval = OPEN_TYPE_xer_get(opt_codec_ctx, td, st, elm, ptr, size); tmprval = elm->type->op->jer_decoder(opt_codec_ctx,
} else { elm->type, memb_ptr2, elm->name,
/* Invoke the inner type decoder, m.b. multiple times */ ptr, size);
tmprval = elm->type->op->jer_decoder(opt_codec_ctx,
elm->type, memb_ptr2, elm->name,
ptr, size);
}
JER_ADVANCE(tmprval.consumed); JER_ADVANCE(tmprval.consumed);
if(tmprval.code != RC_OK) if(tmprval.code != RC_OK)
RETURN(tmprval.code); RETURN(tmprval.code);
ctx->phase = 1; /* Back to body processing */ ctx->phase = 1; /* Back to body processing */
ctx->step = ++edx; ASN_SET_MKPRESENT((char *)st + specs->pres_offset, edx);
ASN_DEBUG("JER/SEQUENCE phase => %d, step => %d", ASN_DEBUG("JER/SET phase => %d", ctx->phase);
ctx->phase, ctx->step);
/* Fall through */ /* Fall through */
} }
...@@ -166,8 +146,8 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -166,8 +146,8 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
} }
} }
scv = jer_check_sym(ptr, ch_size, ctx->phase == 0 ? json_key : NULL); scv = jer_check_sym(ptr, ch_size, NULL);
ASN_DEBUG("JER/SEQUENCE: scv = %d, ph=%d [%s]", ASN_DEBUG("JER/SET: scv = %d, ph=%d [%s]",
scv, ctx->phase, json_key); scv, ctx->phase, json_key);
...@@ -194,10 +174,22 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -194,10 +174,22 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
case JCK_OEND: case JCK_OEND:
if(ctx->phase == 0) break; if(ctx->phase == 0) break;
ctx->phase = 0; ctx->phase = 0;
/* Fall through */
case JCK_KEY: if(_SET_is_populated(td, st)) {
JER_ADVANCE(ch_size);
JER_ADVANCE(jer_whitespace_span(ptr, size));
ctx->phase = 4; /* Phase out */
RETURN(RC_OK);
} else {
ASN_DEBUG("Premature end of JER SET");
RETURN(RC_FAIL);
}
case JCK_COMMA: case JCK_COMMA:
JER_ADVANCE(ch_size);
continue;
case JCK_OSTART:
if(ctx->phase == 0) { if(ctx->phase == 0) {
JER_ADVANCE(ch_size); JER_ADVANCE(ch_size);
ctx->phase = 1; /* Processing body phase */ ctx->phase = 1; /* Processing body phase */
...@@ -205,9 +197,9 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -205,9 +197,9 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
} }
/* Fall through */ /* Fall through */
case JCK_KEY:
case JCK_UNKNOWN: case JCK_UNKNOWN:
case JCK_OSTART: ASN_DEBUG("JER/SET: scv=%d, ph=%d, edx=%" ASN_PRI_SIZE "",
ASN_DEBUG("JER/SEQUENCE: scv=%d, ph=%d, edx=%" ASN_PRI_SIZE "",
scv, ctx->phase, edx); scv, ctx->phase, edx);
if(ctx->phase != 1) { if(ctx->phase != 1) {
break; /* Really unexpected */ break; /* Really unexpected */
...@@ -219,50 +211,44 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -219,50 +211,44 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
} }
if(edx < td->elements_count) { if(edx < td->elements_count) {
JER_ADVANCE(ch_size);
/* /*
* We have to check which member is next. * We have to check which member is next.
*/ */
JER_SAVE_STATE; for(edx = 0; edx < td->elements_count; edx++) {
ctx->context = 0; elm = &elements[edx];
ch_size = jer_next_token(&ctx->context, ptr, size, &ch_type);
if(ch_size == -1) {
RETURN(RC_FAIL);
}
if(ch_type != PJER_KEY) {
JER_ADVANCE(ch_size); /* Skip silently */
ch_size = jer_next_token(&ctx->context, ptr, size, &ch_type);
if(ch_size == -1) {
RETURN(RC_FAIL);
}
}
size_t n;
size_t edx_end = edx + elements[edx].optional + 1;
if(edx_end > td->elements_count) {
edx_end = td->elements_count;
}
for(n = edx; n < edx_end; n++) {
elm = &td->elements[n];
scv = jer_check_sym(ptr, ch_size, elm->name); scv = jer_check_sym(ptr, ch_size, elm->name);
switch (scv) { switch (scv) {
case JCK_KEY: case JCK_KEY:
ctx->step = edx = n; ctx->step = edx;
ctx->phase = 2; ctx->phase = 2;
break;
case JCK_UNKNOWN: JER_ADVANCE(ch_size); /* skip key */
continue; /* skip colon */
default: ch_size = jer_next_token(&ctx->context, ptr, size,
n = edx_end; &ch_type);
break; /* Phase out */ if(ch_size == -1) {
RETURN(RC_FAIL);
} else {
switch(ch_type) {
case PJER_WMORE:
RETURN(RC_WMORE);
case PJER_TEXT:
JER_ADVANCE(ch_size);
break;
default:
RETURN(RC_FAIL);
}
}
break;
case JCK_UNKNOWN:
continue;
default:
edx = td->elements_count;
break; /* Phase out */
} }
break; break;
} }
JER_RESTORE_STATE; if(edx != td->elements_count)
if(n != edx_end)
continue; continue;
} else { } else {
ASN_DEBUG("Out of defined members: %" ASN_PRI_SIZE "/%u", ASN_DEBUG("Out of defined members: %" ASN_PRI_SIZE "/%u",
...@@ -283,7 +269,7 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -283,7 +269,7 @@ SET_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
break; break;
} }
ASN_DEBUG("Unexpected JSON key in SEQUENCE [%c%c%c%c%c%c]", ASN_DEBUG("Unexpected JSON key in SET [%c%c%c%c%c%c]",
size>0?((const char *)ptr)[0]:'.', size>0?((const char *)ptr)[0]:'.',
size>1?((const char *)ptr)[1]:'.', size>1?((const char *)ptr)[1]:'.',
size>2?((const char *)ptr)[2]:'.', size>2?((const char *)ptr)[2]:'.',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment