Commit 8471ceca authored by Lev Walkin's avatar Lev Walkin
Browse files

brushing up

parent 5f56091c
......@@ -180,12 +180,13 @@ INTEGER_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
* Decode the chunk of XML text encoding INTEGER.
*/
static ssize_t
INTEGER__xer_body_decode(INTEGER_t *st, void *chunk_buf, size_t chunk_size) {
INTEGER__xer_body_decode(void *sptr, void *chunk_buf, size_t chunk_size) {
INTEGER_t *st = (INTEGER_t *)sptr;
long sign = 1;
long value;
char *lp;
char *lstart = (char *)chunk_buf;
char *lstop = chunk_buf + chunk_size;
char *lstop = lstart + chunk_size;
enum {
ST_SKIPSPACE,
ST_WAITDIGITS,
......@@ -231,7 +232,8 @@ INTEGER__xer_body_decode(INTEGER_t *st, void *chunk_buf, size_t chunk_size) {
if(value < 0) {
/* Check whether it is a LONG_MIN */
if(sign == -1
&& value == ~((unsigned long)-1 >> 1)) {
&& (unsigned long)value
== ~((unsigned long)-1 >> 1)) {
sign = 1;
} else {
/* Overflow */
......@@ -261,7 +263,7 @@ INTEGER_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
void *buf_ptr, size_t size) {
return xer_decode_primitive(opt_codec_ctx, td,
(ASN__PRIMITIVE_TYPE_t **)sptr, opt_mname,
sptr, sizeof(INTEGER_t), opt_mname,
buf_ptr, size, INTEGER__xer_body_decode);
}
......@@ -356,7 +358,7 @@ asn_long2INTEGER(INTEGER_t *st, long value) {
return -1;
}
buf = MALLOC(sizeof(value));
buf = (uint8_t *)MALLOC(sizeof(value));
if(!buf) return -1;
pstart = (uint8_t *)&value;
......
......@@ -28,7 +28,7 @@ asn_TYPE_descriptor_t asn_DEF_NativeReal = {
asn_generic_no_constraint,
NativeReal_decode_ber,
NativeReal_encode_der,
0, /* Not implemented yet */
NativeReal_decode_xer,
NativeReal_encode_xer,
0, /* Use generic outmost tag fetcher */
asn_DEF_NativeReal_tags,
......@@ -143,6 +143,41 @@ NativeReal_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
}
/*
* Decode the chunk of XML text encoding REAL.
*/
asn_dec_rval_t
NativeReal_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
void *buf_ptr, size_t size) {
asn_dec_rval_t rval;
REAL_t *st = 0;
double *Dbl = (double *)*sptr;
if(!Dbl) {
(void *)Dbl = *sptr = CALLOC(1, sizeof(double));
if(!Dbl) {
rval.code = RC_FAIL;
rval.consumed = 0;
return rval;
}
}
rval = REAL_decode_xer(opt_codec_ctx, td, (void **)&st, opt_mname,
buf_ptr, size);
if(rval.code == RC_OK) {
if(asn_REAL2double(st, Dbl)) {
rval.code = RC_FAIL;
rval.consumed = 0;
}
} else {
rval.consumed = 0;
}
asn_DEF_REAL.free_struct(&asn_DEF_REAL, st, 0);
return rval;
}
asn_enc_rval_t
NativeReal_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags,
......
......@@ -19,6 +19,7 @@ asn_struct_free_f NativeReal_free;
asn_struct_print_f NativeReal_print;
ber_type_decoder_f NativeReal_decode_ber;
der_type_encoder_f NativeReal_encode_der;
xer_type_decoder_f NativeReal_decode_xer;
xer_type_encoder_f NativeReal_encode_xer;
#endif /* ASN_TYPE_NativeReal_H */
......@@ -49,7 +49,7 @@ typedef enum specialRealValue {
} specialRealValue_e;
static struct specialRealValue_s {
char *string;
int length;
size_t length;
double dv;
} specialRealValue[] = {
#define SRV_SET(foo, val) { foo, sizeof(foo) - 1, val }
......@@ -248,7 +248,8 @@ REAL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
* Decode the chunk of XML text encoding REAL.
*/
static ssize_t
REAL__xer_body_decode(REAL_t *st, void *chunk_buf, size_t chunk_size) {
REAL__xer_body_decode(void *sptr, void *chunk_buf, size_t chunk_size) {
REAL_t *st = (REAL_t *)sptr;
double value;
char *xerdata = (char *)chunk_buf;
char *endptr = 0;
......@@ -280,10 +281,10 @@ REAL__xer_body_decode(REAL_t *st, void *chunk_buf, size_t chunk_size) {
/*
* Copy chunk into the nul-terminated string, and run strtod.
*/
b = MALLOC(chunk_size + 1);
b = (char *)MALLOC(chunk_size + 1);
if(!b) return -1;
memcpy(b, chunk_buf, chunk_size);
b[chunk_size] = 0;
b[chunk_size] = 0; /* nul-terminate */
value = strtod(b, &endptr);
free(b);
......@@ -301,7 +302,7 @@ REAL_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
void *buf_ptr, size_t size) {
return xer_decode_primitive(opt_codec_ctx, td,
(ASN__PRIMITIVE_TYPE_t **)sptr, opt_mname,
sptr, sizeof(REAL_t), opt_mname,
buf_ptr, size, REAL__xer_body_decode);
}
......
......@@ -136,8 +136,8 @@ ASN__PRIMITIVE_TYPE_free(asn_TYPE_descriptor_t *td, void *sptr,
* Local internal type passed around as an argument.
*/
struct xdp_arg_s {
ASN__PRIMITIVE_TYPE_t *sptr;
ssize_t (*prim_body_decode)(ASN__PRIMITIVE_TYPE_t *sptr,
void *struct_key;
ssize_t (*prim_body_decode)(void *struct_key,
void *chunk_buf, size_t chunk_size);
int decoded_something;
int want_more;
......@@ -181,7 +181,7 @@ xer_decode__unexpected_tag(void *key, void *chunk_buf, size_t chunk_size) {
return -1;
}
decoded = arg->prim_body_decode(arg->sptr, chunk_buf, chunk_size);
decoded = arg->prim_body_decode(arg->struct_key, chunk_buf, chunk_size);
if(decoded < 0) {
return -1;
} else {
......@@ -218,7 +218,7 @@ xer_decode__body(void *key, void *chunk_buf, size_t chunk_size, int have_more) {
return -1;
}
decoded = arg->prim_body_decode(arg->sptr, chunk_buf, chunk_size);
decoded = arg->prim_body_decode(arg->struct_key, chunk_buf, chunk_size);
if(decoded < 0) {
return -1;
} else {
......@@ -231,10 +231,11 @@ xer_decode__body(void *key, void *chunk_buf, size_t chunk_size, int have_more) {
asn_dec_rval_t
xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *td,
ASN__PRIMITIVE_TYPE_t **sptr,
void **sptr,
size_t struct_size,
const char *opt_mname,
void *buf_ptr, size_t size,
ssize_t (*prim_body_decode)(ASN__PRIMITIVE_TYPE_t *sptr,
ssize_t (*prim_body_decode)(void *struct_key,
void *chunk_buf, size_t chunk_size)
) {
const char *xml_tag = opt_mname ? opt_mname : td->xml_tag;
......@@ -246,7 +247,7 @@ xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx,
* Create the structure if does not exist.
*/
if(!*sptr) {
*sptr = CALLOC(1, sizeof(ASN__PRIMITIVE_TYPE_t));
*sptr = CALLOC(1, struct_size);
if(!*sptr) {
asn_dec_rval_t rval;
rval.code = RC_FAIL;
......@@ -256,7 +257,7 @@ xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx,
}
memset(&s_ctx, 0, sizeof(s_ctx));
s_arg.sptr = *sptr;
s_arg.struct_key = *sptr;
s_arg.prim_body_decode = prim_body_decode;
s_arg.decoded_something = 0;
s_arg.want_more = 0;
......
......@@ -17,16 +17,15 @@ ber_type_decoder_f ber_decode_primitive;
der_type_encoder_f der_encode_primitive;
/*
* Specific function to decode simple primitive values
* (INTEGER, ENUMERATED, REAL, OBJECT IDENTIFIER, etc).
* Specific function to decode simple primitive types.
* Also see xer_decode_general() in xer_decoder.h
*/
asn_dec_rval_t xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx,
asn_TYPE_descriptor_t *type_descriptor,
ASN__PRIMITIVE_TYPE_t **struct_ptr,
void **struct_ptr, size_t struct_size,
const char *opt_mname,
void *buf_ptr, size_t size,
ssize_t (*prim_body_decode)(ASN__PRIMITIVE_TYPE_t *struct_ptr,
ssize_t (*prim_body_decode)(void *struct_ptr,
void *chunk_buf, size_t chunk_size)
);
......
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