From 9b90ced59521d48fc1a10465dbfc65d4884606b0 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Wed, 18 Feb 2015 20:39:56 +0100 Subject: [PATCH] Make special handlers for rdf work + bugfix in repetition of rdf blocks --- src/rr-dict.c | 13 +++++++------ src/rr-dict.h | 8 ++++---- src/rr-iter.c | 10 ++++++++-- src/util-internal.c | 27 ++++++++++++++++++++++----- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/rr-dict.c b/src/rr-dict.c index 62ea1684..89c4ba73 100644 --- a/src/rr-dict.c +++ b/src/rr-dict.c @@ -55,12 +55,12 @@ template_dict_set_value(getdns_dict *dict, uint8_t *rdf) return GETDNS_RETURN_GENERIC_ERROR; } static getdns_return_t -template_list_set_value(getdns_list *list, uint8_t *rdf) +template_list_append_value(getdns_list *list, uint8_t *rdf) { return GETDNS_RETURN_GENERIC_ERROR; } static priv_getdns_rdf_special template = { - template_rdf_end, template_dict_set_value, template_list_set_value + template_rdf_end, template_dict_set_value, template_list_append_value }; */ @@ -75,12 +75,12 @@ apl_n_dict_set_value(getdns_dict *dict, uint8_t *rdf) return getdns_dict_set_int(dict, "n", (*rdf >> 7)); } static getdns_return_t -apl_n_list_set_value(getdns_list *list, uint8_t *rdf) +apl_n_list_append_value(getdns_list *list, uint8_t *rdf) { return getdns_list_append_int(list, (*rdf >> 7)); } static priv_getdns_rdf_special apl_n = { - apl_n_rdf_end, apl_n_dict_set_value, apl_n_list_set_value + apl_n_rdf_end, apl_n_dict_set_value, apl_n_list_append_value }; static uint8_t * @@ -96,13 +96,14 @@ apl_afdpart_dict_set_value(getdns_dict *dict, uint8_t *rdf) return getdns_dict_set_bindata(dict, "afdpart", &bindata); } static getdns_return_t -apl_afdpart_list_set_value(getdns_list *list, uint8_t *rdf) +apl_afdpart_list_append_value(getdns_list *list, uint8_t *rdf) { getdns_bindata bindata = { (rdf[-1] & 0x7F), rdf }; return getdns_list_append_bindata(list, &bindata); } static priv_getdns_rdf_special apl_afdpart = { - apl_afdpart_rdf_end, apl_afdpart_dict_set_value, apl_afdpart_list_set_value + apl_afdpart_rdf_end, + apl_afdpart_dict_set_value, apl_afdpart_list_append_value }; static priv_getdns_rdata_def a_rdata[] = { diff --git a/src/rr-dict.h b/src/rr-dict.h index a8043ded..316cf178 100644 --- a/src/rr-dict.h +++ b/src/rr-dict.h @@ -40,13 +40,13 @@ typedef uint8_t *(*priv_getdns_rdf_end_t)( /* Limit checks are already done with priv_getdns_rdf_end_t */ typedef getdns_return_t (*priv_getdns_rdf_dict_set_value_t)( getdns_dict *dict, uint8_t *rdf); -typedef getdns_return_t (*priv_getdns_rdf_list_set_value_t)( +typedef getdns_return_t (*priv_getdns_rdf_list_append_value_t)( getdns_list *list, uint8_t *rdf); typedef struct priv_getdns_rdf_special { - priv_getdns_rdf_end_t rdf_end; - priv_getdns_rdf_dict_set_value_t dict_set_value; - priv_getdns_rdf_list_set_value_t list_set_value; + priv_getdns_rdf_end_t rdf_end; + priv_getdns_rdf_dict_set_value_t dict_set_value; + priv_getdns_rdf_list_append_value_t list_append_value; } priv_getdns_rdf_special; /* draft-levine-dnsextlang'ish type rr and rdata definitions */ diff --git a/src/rr-iter.c b/src/rr-iter.c index 0336c6df..44f965b5 100644 --- a/src/rr-iter.c +++ b/src/rr-iter.c @@ -214,10 +214,10 @@ rdf_iter_find_nxt(priv_getdns_rdf_iter *i) assert(i->rdd_pos); if (!i->rdd_repeat && (i->rdd_pos->type & GETDNS_RDF_REPEAT)) { + i->rdd_repeat = i->rdd_pos; if (i->rdd_pos->type == GETDNS_RDF_REPEAT && ++i->rdd_pos == i->rdd_end) goto done; - i->rdd_repeat = i->rdd_pos; } if (i->rdd_pos->type & GETDNS_RDF_FIXEDSZ) i->nxt = i->pos + (i->rdd_pos->type & GETDNS_RDF_FIXEDSZ); @@ -241,7 +241,11 @@ rdf_iter_find_nxt(priv_getdns_rdf_iter *i) } else if (*pos & 0xC0) /* Uknown label type */ goto done; } - else + else if ((i->rdd_pos->type & GETDNS_RDF_SPECIAL) && i->rdd_pos->special) { + if (!(i->nxt = i->rdd_pos->special->rdf_end( + i->pkt, i->pkt_end, i->pos))) + i->nxt = i->end; + } else i->nxt = i->end; if (i->nxt <= i->end) @@ -298,6 +302,8 @@ priv_getdns_rdf_iter_next(priv_getdns_rdf_iter *i) goto done; /* Out of rdata */ if (i->rdd_pos >= i->rdd_end && !(i->rdd_pos = i->rdd_repeat)) goto done; /* Remaining rdata, but out of definitions! */ + if (i->rdd_pos->type == GETDNS_RDF_REPEAT) + i->rdd_pos += 1; return rdf_iter_find_nxt(i); done: diff --git a/src/util-internal.c b/src/util-internal.c index 11954397..c9859b1b 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -422,7 +422,10 @@ priv_getdns_rr_iter2rr_dict(getdns_context *context, priv_getdns_rr_iter *i) bindata.data = rdf->pos; break; } - } else + } else if (rdf->rdd_pos->type == GETDNS_RDF_SPECIAL) + /* Abuse t_dict for special values */ + val_type = t_dict; + else assert(0); if (! rdf->rdd_repeat) { @@ -437,12 +440,16 @@ priv_getdns_rr_iter2rr_dict(getdns_context *context, priv_getdns_rr_iter *i) rdf->rdd_pos->name, &bindata)) goto rdata_error; break; + case t_dict: + if (rdf->rdd_pos->special->dict_set_value( + rdata_dict, rdf->pos)) + goto rdata_error; default: break; } continue; - - } else if (rdf->rdd_pos == rdf->rdd_repeat) { + } + if (rdf->rdd_pos == rdf->rdd_repeat) { /* list with rdf values */ if (! repeat_list && !(repeat_list = @@ -460,16 +467,22 @@ priv_getdns_rr_iter2rr_dict(getdns_context *context, priv_getdns_rr_iter *i) &bindata)) goto rdata_error; break; + case t_dict: + if (rdf->rdd_pos->special->list_append_value( + repeat_list, rdf->pos)) + goto rdata_error; default: break; } continue; - } - /* list with dicts with rdf values */ if (rdf->rdd_pos == rdf->rdd_repeat + 1) { if (repeat_dict) { + if (! repeat_list && !(repeat_list = + getdns_list_create_with_context(context))) + goto rdata_error; + if (getdns_list_append_dict( repeat_list, repeat_dict)) goto rdata_error; @@ -493,6 +506,10 @@ priv_getdns_rr_iter2rr_dict(getdns_context *context, priv_getdns_rr_iter *i) rdf->rdd_pos->name, &bindata)) goto rdata_error; break; + case t_dict: + if (rdf->rdd_pos->special->dict_set_value( + repeat_dict, rdf->pos)) + goto rdata_error; default: break; }