Commit 4c509a36 authored by Senthil Prabakaran's avatar Senthil Prabakaran Committed by Mouse

Fix for compile

parent 6a90fcd7
......@@ -83,253 +83,6 @@ INTEGER_st_prealloc(INTEGER_t *st, int min_size) {
}
}
/*
* Decode the chunk of XML text encoding INTEGER.
*/
static enum jer_pbd_rval
INTEGER__jer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr,
const void *chunk_buf, size_t chunk_size) {
const asn_INTEGER_specifics_t *specs =
(const asn_INTEGER_specifics_t *)td->specifics;
INTEGER_t *st = (INTEGER_t *)sptr;
intmax_t dec_value;
intmax_t hex_value = 0;
const char *lp;
const char *lstart = (const char *)chunk_buf;
const char *lstop = lstart + chunk_size;
enum {
ST_LEADSPACE,
ST_SKIPSPHEX,
ST_WAITDIGITS,
ST_DIGITS,
ST_DIGITS_TRAILSPACE,
ST_HEXDIGIT1,
ST_HEXDIGIT2,
ST_HEXDIGITS_TRAILSPACE,
ST_HEXCOLON,
ST_END_ENUM,
ST_UNEXPECTED
} state = ST_LEADSPACE;
const char *dec_value_start = 0; /* INVARIANT: always !0 in ST_DIGITS */
const char *dec_value_end = 0;
if(chunk_size)
ASN_DEBUG("INTEGER body %ld 0x%2x..0x%2x",
(long)chunk_size, *lstart, lstop[-1]);
if(INTEGER_st_prealloc(st, (chunk_size/3) + 1))
return XPBD_SYSTEM_FAILURE;
/*
* We may have received a tag here. It will be processed inline.
* Use strtoul()-like code and serialize the result.
*/
for(lp = lstart; lp < lstop; lp++) {
int lv = *lp;
switch(lv) {
case 0x09: case 0x0a: case 0x0d: case 0x20:
switch(state) {
case ST_LEADSPACE:
case ST_DIGITS_TRAILSPACE:
case ST_HEXDIGITS_TRAILSPACE:
case ST_SKIPSPHEX:
continue;
case ST_DIGITS:
dec_value_end = lp;
state = ST_DIGITS_TRAILSPACE;
continue;
case ST_HEXCOLON:
state = ST_HEXDIGITS_TRAILSPACE;
continue;
default:
break;
}
break;
case 0x2d: /* '-' */
if(state == ST_LEADSPACE) {
dec_value = 0;
dec_value_start = lp;
state = ST_WAITDIGITS;
continue;
}
break;
case 0x2b: /* '+' */
if(state == ST_LEADSPACE) {
dec_value = 0;
dec_value_start = lp;
state = ST_WAITDIGITS;
continue;
}
break;
case 0x30: case 0x31: case 0x32: case 0x33: case 0x34:
case 0x35: case 0x36: case 0x37: case 0x38: case 0x39:
switch(state) {
case ST_DIGITS: continue;
case ST_SKIPSPHEX: /* Fall through */
case ST_HEXDIGIT1:
hex_value = (lv - 0x30) << 4;
state = ST_HEXDIGIT2;
continue;
case ST_HEXDIGIT2:
hex_value += (lv - 0x30);
state = ST_HEXCOLON;
st->buf[st->size++] = (uint8_t)hex_value;
continue;
case ST_HEXCOLON:
return XPBD_BROKEN_ENCODING;
case ST_LEADSPACE:
dec_value = 0;
dec_value_start = lp;
/* FALL THROUGH */
case ST_WAITDIGITS:
state = ST_DIGITS;
continue;
default:
break;
}
break;
case 0x3c: /* '<', start of XML encoded enumeration */
if(state == ST_LEADSPACE) {
const asn_INTEGER_enum_map_t *el;
el = INTEGER_map_enum2value(
(const asn_INTEGER_specifics_t *)
td->specifics, lstart, lstop);
if(el) {
ASN_DEBUG("Found \"%s\" => %ld",
el->enum_name, el->nat_value);
dec_value = el->nat_value;
state = ST_END_ENUM;
lp = lstop - 1;
continue;
}
ASN_DEBUG("Unknown identifier for INTEGER");
}
return XPBD_BROKEN_ENCODING;
case 0x3a: /* ':' */
if(state == ST_HEXCOLON) {
/* This colon is expected */
state = ST_HEXDIGIT1;
continue;
} else if(state == ST_DIGITS) {
/* The colon here means that we have
* decoded the first two hexadecimal
* places as a decimal value.
* Switch decoding mode. */
ASN_DEBUG("INTEGER re-evaluate as hex form");
state = ST_SKIPSPHEX;
dec_value_start = 0;
lp = lstart - 1;
continue;
} else {
ASN_DEBUG("state %d at %ld", state, (long)(lp - lstart));
break;
}
/* [A-Fa-f] */
case 0x41:case 0x42:case 0x43:case 0x44:case 0x45:case 0x46:
case 0x61:case 0x62:case 0x63:case 0x64:case 0x65:case 0x66:
switch(state) {
case ST_SKIPSPHEX:
case ST_LEADSPACE: /* Fall through */
case ST_HEXDIGIT1:
hex_value = lv - ((lv < 0x61) ? 0x41 : 0x61);
hex_value += 10;
hex_value <<= 4;
state = ST_HEXDIGIT2;
continue;
case ST_HEXDIGIT2:
hex_value += lv - ((lv < 0x61) ? 0x41 : 0x61);
hex_value += 10;
st->buf[st->size++] = (uint8_t)hex_value;
state = ST_HEXCOLON;
continue;
case ST_DIGITS:
ASN_DEBUG("INTEGER re-evaluate as hex form");
state = ST_SKIPSPHEX;
dec_value_start = 0;
lp = lstart - 1;
continue;
default:
break;
}
break;
}
/* Found extra non-numeric stuff */
ASN_DEBUG("INTEGER :: Found non-numeric 0x%2x at %ld",
lv, (long)(lp - lstart));
state = ST_UNEXPECTED;
break;
}
switch(state) {
case ST_END_ENUM:
/* Got a complete and valid enumeration encoded as a tag. */
break;
case ST_DIGITS:
dec_value_end = lstop;
/* FALL THROUGH */
case ST_DIGITS_TRAILSPACE:
/* The last symbol encountered was a digit. */
switch(asn_strtoimax_lim(dec_value_start, &dec_value_end, &dec_value)) {
case ASN_STRTOX_OK:
if(specs && specs->field_unsigned && (uintmax_t) dec_value <= ULONG_MAX) {
break;
} else if(dec_value >= LONG_MIN && dec_value <= LONG_MAX) {
break;
} else {
/*
* We model INTEGER on long for JER,
* to avoid rewriting all the tests at once.
*/
ASN_DEBUG("INTEGER exceeds long range");
}
/* Fall through */
case ASN_STRTOX_ERROR_RANGE:
ASN_DEBUG("INTEGER decode %s hit range limit", td->name);
return XPBD_DECODER_LIMIT;
case ASN_STRTOX_ERROR_INVAL:
case ASN_STRTOX_EXPECT_MORE:
case ASN_STRTOX_EXTRA_DATA:
return XPBD_BROKEN_ENCODING;
}
break;
case ST_HEXCOLON:
case ST_HEXDIGITS_TRAILSPACE:
st->buf[st->size] = 0; /* Just in case termination */
return XPBD_BODY_CONSUMED;
case ST_HEXDIGIT1:
case ST_HEXDIGIT2:
case ST_SKIPSPHEX:
return XPBD_BROKEN_ENCODING;
case ST_LEADSPACE:
/* Content not found */
return XPBD_NOT_BODY_IGNORE;
case ST_WAITDIGITS:
case ST_UNEXPECTED:
ASN_DEBUG("INTEGER: No useful digits (state %d)", state);
return XPBD_BROKEN_ENCODING; /* No digits */
}
/*
* Convert the result of parsing of enumeration or a straight
* decimal value into a BER representation.
*/
if(asn_imax2INTEGER(st, dec_value)) {
ASN_DEBUG("INTEGER decode %s conversion failed", td->name);
return XPBD_SYSTEM_FAILURE;
}
return XPBD_BODY_CONSUMED;
}
asn_dec_rval_t
INTEGER_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
const asn_TYPE_descriptor_t *td, void **sptr,
const char *opt_mname, const void *buf_ptr, size_t size) {
return jer_decode_primitive(opt_codec_ctx, td,
sptr, sizeof(INTEGER_t), opt_mname,
buf_ptr, size, INTEGER__jer_body_decode);
}
asn_enc_rval_t
INTEGER_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr,
......
......@@ -26,156 +26,6 @@
consumed_myself += num; \
} while(0)
/*
* Decode the JER (XML) data.
*/
asn_dec_rval_t
SET_OF_decode_jer(const asn_codec_ctx_t *opt_codec_ctx,
const asn_TYPE_descriptor_t *td, void **struct_ptr,
const char *opt_mname, const void *buf_ptr, size_t size) {
/*
* Bring closer parts of structure description.
*/
const asn_SET_OF_specifics_t *specs = (const asn_SET_OF_specifics_t *)td->specifics;
const asn_TYPE_member_t *element = td->elements;
const char *elm_tag;
const char *xml_tag = opt_mname ? opt_mname : td->xml_tag;
/*
* ... and parts of the structure being constructed.
*/
void *st = *struct_ptr; /* Target structure. */
asn_struct_ctx_t *ctx; /* Decoder context */
asn_dec_rval_t rval = {RC_OK, 0}; /* Return value from a decoder */
ssize_t consumed_myself = 0; /* Consumed bytes from ptr */
/*
* Create the target structure if it is not present already.
*/
if(st == 0) {
st = *struct_ptr = CALLOC(1, specs->struct_size);
if(st == 0) RETURN(RC_FAIL);
}
/* Which tag is expected for the downstream */
if(specs->as_XMLValueList) {
elm_tag = (specs->as_XMLValueList == 1) ? 0 : "";
} else {
elm_tag = (*element->name)
? element->name : element->type->xml_tag;
}
/*
* Restore parsing context.
*/
ctx = (asn_struct_ctx_t *)((char *)st + specs->ctx_offset);
/*
* Phases of JER/XML processing:
* Phase 0: Check that the opening tag matches our expectations.
* Phase 1: Processing body and reacting on closing tag.
* Phase 2: Processing inner type.
*/
for(; ctx->phase <= 2;) {
pjer_chunk_type_e ch_type; /* JER chunk type */
ssize_t ch_size; /* Chunk size */
jer_check_tag_e tcv; /* Tag check value */
/*
* Go inside the inner member of a set.
*/
if(ctx->phase == 2) {
asn_dec_rval_t tmprval = {RC_OK, 0};
/* Invoke the inner type decoder, m.b. multiple times */
ASN_DEBUG("JER/SET OF element [%s]", elm_tag);
tmprval = element->type->op->jer_decoder(opt_codec_ctx,
element->type,
&ctx->ptr, elm_tag,
buf_ptr, size);
if(tmprval.code == RC_OK) {
asn_anonymous_set_ *list = _A_SET_FROM_VOID(st);
if(ASN_SET_ADD(list, ctx->ptr) != 0)
RETURN(RC_FAIL);
ctx->ptr = 0;
JER_ADVANCE(tmprval.consumed);
} else {
JER_ADVANCE(tmprval.consumed);
RETURN(tmprval.code);
}
ctx->phase = 1; /* Back to body processing */
ASN_DEBUG("JER/SET OF phase => %d", ctx->phase);
/* Fall through */
}
/*
* Get the next part of the XML stream.
*/
ch_size = jer_next_token(&ctx->context,
buf_ptr, size, &ch_type);
if(ch_size == -1) {
RETURN(RC_FAIL);
} else {
switch(ch_type) {
case PJER_WMORE:
RETURN(RC_WMORE);
case PJER_COMMENT: /* Got XML comment */
case PJER_TEXT: /* Ignore free-standing text */
JER_ADVANCE(ch_size); /* Skip silently */
continue;
case PJER_TAG:
break; /* Check the rest down there */
}
}
tcv = jer_check_tag(buf_ptr, ch_size, xml_tag);
ASN_DEBUG("JER/SET OF: tcv = %d, ph=%d t=%s",
tcv, ctx->phase, xml_tag);
switch(tcv) {
case XCT_CLOSING:
if(ctx->phase == 0) break;
ctx->phase = 0;
/* Fall through */
case XCT_BOTH:
if(ctx->phase == 0) {
/* No more things to decode */
JER_ADVANCE(ch_size);
ctx->phase = 3; /* Phase out */
RETURN(RC_OK);
}
/* Fall through */
case XCT_OPENING:
if(ctx->phase == 0) {
JER_ADVANCE(ch_size);
ctx->phase = 1; /* Processing body phase */
continue;
}
/* Fall through */
case XCT_UNKNOWN_OP:
case XCT_UNKNOWN_BO:
ASN_DEBUG("JER/SET OF: tcv=%d, ph=%d", tcv, ctx->phase);
if(ctx->phase == 1) {
/*
* Process a single possible member.
*/
ctx->phase = 2;
continue;
}
/* Fall through */
default:
break;
}
ASN_DEBUG("Unexpected XML tag in SET OF");
break;
}
ctx->phase = 3; /* "Phase out" on hard failure */
RETURN(RC_FAIL);
}
typedef struct jer_tmp_enc_s {
void *buffer;
size_t offset;
......@@ -225,7 +75,7 @@ SET_OF_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
const char *mname = specs->as_XMLValueList
? 0 : ((*elm->name) ? elm->name : elm->type->xml_tag);
size_t mlen = mname ? strlen(mname) : 0;
int xcan = (flags & JER_F_CANONICAL);
int xcan = 0;
jer_tmp_enc_t *encs = 0;
size_t encs_count = 0;
void *original_app_key = app_key;
......
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