Commit ed774b9a authored by Senthil Prabakaran's avatar Senthil Prabakaran Committed by Mouse

Fix Lint issues

parent 7c619357
...@@ -105,46 +105,6 @@ static const struct OCTET_STRING__jer_escape_table_s { ...@@ -105,46 +105,6 @@ static const struct OCTET_STRING__jer_escape_table_s {
OSXET("\046\147\164\073"), /* > */ OSXET("\046\147\164\073"), /* > */
}; };
static int
OS__check_escaped_control_char(const void *buf, int size) {
size_t i;
/*
* Inefficient algorithm which translates the escape sequences
* defined above into characters. Returns -1 if not found.
* TODO: replace by a faster algorithm (bsearch(), hash or
* nested table lookups).
*/
for(i = 0; i < 32 /* Don't spend time on the bottom half */; i++) {
const struct OCTET_STRING__jer_escape_table_s *el;
el = &OCTET_STRING__jer_escape_table[i];
if(el->size == size && memcmp(buf, el->string, size) == 0)
return i;
}
return -1;
}
static int
OCTET_STRING__handle_control_chars(void *struct_ptr, const void *chunk_buf, size_t chunk_size) {
/*
* This might be one of the escape sequences
* for control characters. Check it out.
* #11.15.5
*/
int control_char = OS__check_escaped_control_char(chunk_buf,chunk_size);
if(control_char >= 0) {
OCTET_STRING_t *st = (OCTET_STRING_t *)struct_ptr;
void *p = REALLOC(st->buf, st->size + 2);
if(p) {
st->buf = (uint8_t *)p;
st->buf[st->size++] = control_char;
st->buf[st->size] = '\0'; /* nul-termination */
return 0;
}
}
return -1; /* No, it's not */
}
asn_enc_rval_t asn_enc_rval_t
OCTET_STRING_encode_jer_utf8(const asn_TYPE_descriptor_t *td, const void *sptr, OCTET_STRING_encode_jer_utf8(const asn_TYPE_descriptor_t *td, const void *sptr,
int ilevel, enum jer_encoder_flags_e flags, int ilevel, enum jer_encoder_flags_e flags,
...@@ -188,146 +148,6 @@ OCTET_STRING_encode_jer_utf8(const asn_TYPE_descriptor_t *td, const void *sptr, ...@@ -188,146 +148,6 @@ OCTET_STRING_encode_jer_utf8(const asn_TYPE_descriptor_t *td, const void *sptr,
er.encoded = encoded_len; er.encoded = encoded_len;
ASN__ENCODED_OK(er); ASN__ENCODED_OK(er);
} }
/*
* Convert from hexadecimal format (cstring): "AB CD EF"
*/
static ssize_t OCTET_STRING__convert_hexadecimal(void *sptr, const void *chunk_buf, size_t chunk_size, int have_more) {
OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
const char *chunk_stop = (const char *)chunk_buf;
const char *p = chunk_stop;
const char *pend = p + chunk_size;
unsigned int clv = 0;
int half = 0; /* Half bit */
uint8_t *buf;
/* Reallocate buffer according to high cap estimation */
size_t new_size = st->size + (chunk_size + 1) / 2;
void *nptr = REALLOC(st->buf, new_size + 1);
if(!nptr) return -1;
st->buf = (uint8_t *)nptr;
buf = st->buf + st->size;
/*
* If something like " a b c " appears here, the " a b":3 will be
* converted, and the rest skipped. That is, unless buf_size is greater
* than chunk_size, then it'll be equivalent to "ABC0".
*/
for(; p < pend; p++) {
int ch = *(const unsigned char *)p;
switch(ch) {
case 0x09: case 0x0a: case 0x0c: case 0x0d:
case 0x20:
/* Ignore whitespace */
continue;
case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: /*01234*/
case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: /*56789*/
clv = (clv << 4) + (ch - 0x30);
break;
case 0x41: case 0x42: case 0x43: /* ABC */
case 0x44: case 0x45: case 0x46: /* DEF */
clv = (clv << 4) + (ch - 0x41 + 10);
break;
case 0x61: case 0x62: case 0x63: /* abc */
case 0x64: case 0x65: case 0x66: /* def */
clv = (clv << 4) + (ch - 0x61 + 10);
break;
default:
*buf = 0; /* JIC */
return -1;
}
if(half++) {
half = 0;
*buf++ = clv;
chunk_stop = p + 1;
}
}
/*
* Check partial decoding.
*/
if(half) {
if(have_more) {
/*
* Partial specification is fine,
* because no more more PJER_TEXT data is available.
*/
*buf++ = clv << 4;
chunk_stop = p;
}
} else {
chunk_stop = p;
}
st->size = buf - st->buf; /* Adjust the buffer size */
assert(st->size <= new_size);
st->buf[st->size] = 0; /* Courtesy termination */
return (chunk_stop - (const char *)chunk_buf); /* Converted size */
}
/*
* Convert from binary format: "00101011101"
*/
static ssize_t OCTET_STRING__convert_binary(void *sptr, const void *chunk_buf, size_t chunk_size, int have_more) {
BIT_STRING_t *st = (BIT_STRING_t *)sptr;
const char *p = (const char *)chunk_buf;
const char *pend = (p == NULL)? NULL : p + chunk_size;
int bits_unused = st->bits_unused & 0x7;
uint8_t *buf;
/* Reallocate buffer according to high cap estimation */
size_t new_size = st->size + (chunk_size + 7) / 8;
void *nptr = REALLOC(st->buf, new_size + 1);
if(!nptr) return -1;
st->buf = (uint8_t *)nptr;
buf = st->buf + st->size;
(void)have_more;
if(bits_unused == 0)
bits_unused = 8;
else if(st->size)
buf--;
/*
* Convert series of 0 and 1 into the octet string.
*/
for(; p < pend; p++) {
int ch = *(const unsigned char *)p;
switch(ch) {
case 0x09: case 0x0a: case 0x0c: case 0x0d:
case 0x20:
/* Ignore whitespace */
break;
case 0x30:
case 0x31:
if(bits_unused-- <= 0) {
*++buf = 0; /* Clean the cell */
bits_unused = 7;
}
*buf |= (ch&1) << bits_unused;
break;
default:
st->bits_unused = bits_unused;
return -1;
}
}
if(bits_unused == 8) {
st->size = buf - st->buf;
st->bits_unused = 0;
} else {
st->size = buf - st->buf + 1;
st->bits_unused = bits_unused;
}
assert(st->size <= new_size);
st->buf[st->size] = 0; /* Courtesy termination */
return chunk_size; /* Converted in full */
}
/* /*
* Something like strtod(), but with stricter rules. * Something like strtod(), but with stricter rules.
*/ */
...@@ -369,145 +189,3 @@ OS__strtoent(int base, const char *buf, const char *end, int32_t *ret_value) { ...@@ -369,145 +189,3 @@ OS__strtoent(int base, const char *buf, const char *end, int32_t *ret_value) {
*ret_value = -1; *ret_value = -1;
return (p - buf); return (p - buf);
} }
/*
* Convert from the plain UTF-8 format, expanding entity references: "2 &lt; 3"
*/
static ssize_t
OCTET_STRING__convert_entrefs(void *sptr, const void *chunk_buf,
size_t chunk_size, int have_more) {
OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
const char *p = (const char *)chunk_buf;
const char *pend = p + chunk_size;
uint8_t *buf;
/* Reallocate buffer */
size_t new_size = st->size + chunk_size;
void *nptr = REALLOC(st->buf, new_size + 1);
if(!nptr) return -1;
st->buf = (uint8_t *)nptr;
buf = st->buf + st->size;
/*
* Convert series of 0 and 1 into the octet string.
*/
for(; p < pend; p++) {
int ch = *(const unsigned char *)p;
int len; /* Length of the rest of the chunk */
if(ch != 0x26 /* '&' */) {
*buf++ = ch;
continue; /* That was easy... */
}
/*
* Process entity reference.
*/
len = chunk_size - (p - (const char *)chunk_buf);
if(len == 1 /* "&" */) goto want_more;
if(p[1] == 0x23 /* '#' */) {
const char *pval; /* Pointer to start of digits */
int32_t val = 0; /* Entity reference value */
int base;
if(len == 2 /* "&#" */) goto want_more;
if(p[2] == 0x78 /* 'x' */)
pval = p + 3, base = 16;
else
pval = p + 2, base = 10;
len = OS__strtoent(base, pval, p + len, &val);
if(len == -1) {
/* Invalid charset. Just copy verbatim. */
*buf++ = ch;
continue;
}
if(!len || pval[len-1] != 0x3b) goto want_more;
assert(val > 0);
p += (pval - p) + len - 1; /* Advance past entref */
if(val < 0x80) {
*buf++ = (char)val;
} else if(val < 0x800) {
*buf++ = 0xc0 | ((val >> 6));
*buf++ = 0x80 | ((val & 0x3f));
} else if(val < 0x10000) {
*buf++ = 0xe0 | ((val >> 12));
*buf++ = 0x80 | ((val >> 6) & 0x3f);
*buf++ = 0x80 | ((val & 0x3f));
} else if(val < 0x200000) {
*buf++ = 0xf0 | ((val >> 18));
*buf++ = 0x80 | ((val >> 12) & 0x3f);
*buf++ = 0x80 | ((val >> 6) & 0x3f);
*buf++ = 0x80 | ((val & 0x3f));
} else if(val < 0x4000000) {
*buf++ = 0xf8 | ((val >> 24));
*buf++ = 0x80 | ((val >> 18) & 0x3f);
*buf++ = 0x80 | ((val >> 12) & 0x3f);
*buf++ = 0x80 | ((val >> 6) & 0x3f);
*buf++ = 0x80 | ((val & 0x3f));
} else {
*buf++ = 0xfc | ((val >> 30) & 0x1);
*buf++ = 0x80 | ((val >> 24) & 0x3f);
*buf++ = 0x80 | ((val >> 18) & 0x3f);
*buf++ = 0x80 | ((val >> 12) & 0x3f);
*buf++ = 0x80 | ((val >> 6) & 0x3f);
*buf++ = 0x80 | ((val & 0x3f));
}
} else {
/*
* Ugly, limited parsing of &amp; &gt; &lt;
*/
char *sc = (char *)memchr(p, 0x3b, len > 5 ? 5 : len);
if(!sc) goto want_more;
if((sc - p) == 4
&& p[1] == 0x61 /* 'a' */
&& p[2] == 0x6d /* 'm' */
&& p[3] == 0x70 /* 'p' */) {
*buf++ = 0x26;
p = sc;
continue;
}
if((sc - p) == 3) {
if(p[1] == 0x6c) {
*buf = 0x3c; /* '<' */
} else if(p[1] == 0x67) {
*buf = 0x3e; /* '>' */
} else {
/* Unsupported entity reference */
*buf++ = ch;
continue;
}
if(p[2] != 0x74) {
/* Unsupported entity reference */
*buf++ = ch;
continue;
}
buf++;
p = sc;
continue;
}
/* Unsupported entity reference */
*buf++ = ch;
}
continue;
want_more:
if(have_more) {
/*
* We know that no more data (of the same type)
* is coming. Copy the rest verbatim.
*/
*buf++ = ch;
continue;
}
chunk_size = (p - (const char *)chunk_buf);
/* Processing stalled: need more data */
break;
}
st->size = buf - st->buf;
assert(st->size <= new_size);
st->buf[st->size] = 0; /* Courtesy termination */
return chunk_size; /* Converted in full */
}
...@@ -17,7 +17,6 @@ jer_encode(const asn_TYPE_descriptor_t *td, const void *sptr, ...@@ -17,7 +17,6 @@ jer_encode(const asn_TYPE_descriptor_t *td, const void *sptr,
asn_enc_rval_t tmper; asn_enc_rval_t tmper;
const char *mname; const char *mname;
size_t mlen; size_t mlen;
int xcan = 0;
if(!td || !sptr) goto cb_failed; if(!td || !sptr) goto cb_failed;
...@@ -67,32 +66,3 @@ jer_fprint(FILE *stream, const asn_TYPE_descriptor_t *td, const void *sptr) { ...@@ -67,32 +66,3 @@ jer_fprint(FILE *stream, const asn_TYPE_descriptor_t *td, const void *sptr) {
return fflush(stream); return fflush(stream);
} }
struct jer_buffer {
char *buffer;
size_t buffer_size;
size_t allocated_size;
};
static int
jer__buffer_append(const void *buffer, size_t size, void *app_key) {
struct jer_buffer *xb = app_key;
while(xb->buffer_size + size + 1 > xb->allocated_size) {
size_t new_size = 2 * (xb->allocated_size ? xb->allocated_size : 64);
char *new_buf = MALLOC(new_size);
if(!new_buf) return -1;
if (xb->buffer) {
memcpy(new_buf, xb->buffer, xb->buffer_size);
}
FREEMEM(xb->buffer);
xb->buffer = new_buf;
xb->allocated_size = new_size;
}
memcpy(xb->buffer + xb->buffer_size, buffer, size);
xb->buffer_size += size;
xb->buffer[xb->buffer_size] = '\0';
return 0;
}
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