diff options
author | Lev Walkin <vlm@lionet.info> | 2006-03-14 16:31:37 +0000 |
---|---|---|
committer | Lev Walkin <vlm@lionet.info> | 2006-03-14 16:31:37 +0000 |
commit | 9d542d223252ea642347330dcc1acd337e49c0e2 (patch) | |
tree | 516c3c202cb1a763f5e7c6dd8d34cfef08930a8c /libasn1parser/asn1p_class.c | |
parent | 5a405b25c99e7ceb470bcd349a32584f92c2ddfa (diff) |
new WITH SYNTAX clause parsing
Diffstat (limited to 'libasn1parser/asn1p_class.c')
-rw-r--r-- | libasn1parser/asn1p_class.c | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/libasn1parser/asn1p_class.c b/libasn1parser/asn1p_class.c index cd0e385a..741d98e1 100644 --- a/libasn1parser/asn1p_class.c +++ b/libasn1parser/asn1p_class.c @@ -18,10 +18,13 @@ asn1p_wsyntx_chunk_new() { void asn1p_wsyntx_chunk_free(asn1p_wsyntx_chunk_t *wc) { if(wc) { - if(wc->ref) - asn1p_ref_free(wc->ref); - if(wc->buf) - free(wc->buf); + switch(wc->type) { + case WC_LITERAL: free(wc->content.token); break; + case WC_REFERENCE: asn1p_ref_free(wc->content.ref); break; + case WC_OPTIONALGROUP: + asn1p_wsyntx_free(wc->content.syntax); + break; + } free(wc); } } @@ -32,21 +35,17 @@ asn1p_wsyntx_chunk_clone(asn1p_wsyntx_chunk_t *wc) { nc = asn1p_wsyntx_chunk_new(); if(nc) { - if(wc->buf) { - nc->buf = malloc(wc->len + 1); - if(nc->buf) { - nc->len = wc->len; - memcpy(nc->buf, wc->buf, wc->len); - nc->buf[nc->len] = '\0'; - } - } - if(wc->ref) { - nc->ref = asn1p_ref_clone(wc->ref); - } - - if(!nc->ref && !nc->buf) { - asn1p_wsyntx_chunk_free(nc); - return NULL; + switch(wc->type) { + case WC_LITERAL: + nc->content.token = malloc(strlen(wc->content.token)+1); + strcpy(nc->content.token, wc->content.token); + break; + case WC_REFERENCE: + nc->content.ref = asn1p_ref_clone(wc->content.ref); + break; + case WC_OPTIONALGROUP: + nc->content.syntax = asn1p_wsyntx_clone(wc->content.syntax); + break; } } @@ -103,11 +102,15 @@ asn1p_wsyntx_chunk_fromref(asn1p_ref_t *ref, int do_copy) { if(do_copy) { static asn1p_wsyntx_chunk_t tmp; - tmp.ref = ref; + tmp.type = WC_REFERENCE; + tmp.content.ref = ref; wc = asn1p_wsyntx_chunk_clone(&tmp); } else { wc = asn1p_wsyntx_chunk_new(); - if(wc) wc->ref = ref; + if(wc) { + wc->type = WC_REFERENCE; + wc->content.ref = ref; + } } return wc; @@ -119,17 +122,31 @@ asn1p_wsyntx_chunk_frombuf(char *buf, int len, int do_copy) { if(do_copy) { static asn1p_wsyntx_chunk_t tmp; - tmp.buf = buf; - tmp.len = len; + tmp.type = WC_LITERAL; + tmp.content.token = buf; wc = asn1p_wsyntx_chunk_clone(&tmp); } else { wc = asn1p_wsyntx_chunk_new(); if(wc) { - wc->buf = buf; - wc->len = len; + wc->type = WC_LITERAL; + wc->content.token = buf; } } return wc; } + +asn1p_wsyntx_chunk_t * +asn1p_wsyntx_chunk_fromsyntax(asn1p_wsyntx_t *syntax) { + asn1p_wsyntx_chunk_t *wc; + + wc = asn1p_wsyntx_chunk_new(); + if(wc) { + wc->type = WC_OPTIONALGROUP; + wc->content.syntax = syntax; + } + + return wc; +} + |