From: Miek Gieben Date: Thu, 24 Feb 2005 12:42:18 +0000 (+0000) Subject: made a rr_list to buffer X-Git-Tag: release-0.50~381 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=57cc9eeabbda5dcfacfda3d949b4e0f042d01814;p=thirdparty%2Fldns.git made a rr_list to buffer made a bubblesort :-) rr_list sorter --- diff --git a/host2str.c b/host2str.c index 5b51052e..c9ef2254 100644 --- a/host2str.c +++ b/host2str.c @@ -807,6 +807,23 @@ ldns_rr2buffer_str(ldns_buffer *output, ldns_rr *rr) return ldns_buffer_status(output); } +/** + * convert a rr_list + * \param[in] output the buffer to output to + * \param[in] list the list to print + * \return ldns_status + */ +ldns_status +ldns_rr_list2buffer_str(ldns_buffer *output, ldns_rr_list *list) +{ + uint16_t i; + + for(i = 0; i < ldns_rr_list_rr_count(list); i++) { + ldns_rr2buffer_str(output, ldns_rr_list_rr(list, i)); + } + return ldns_buffer_status(output); +} + /** * Prints the header in default format in the given buffer */ diff --git a/ldns/rr.h b/ldns/rr.h index 8c84ea38..aa7c74c2 100644 --- a/ldns/rr.h +++ b/ldns/rr.h @@ -267,7 +267,7 @@ ldns_rr_type ldns_rr_get_type_by_name(char *); ldns_rr_class ldns_get_class_by_name(char *); size_t ldns_rr_uncompressed_size(ldns_rr *); int ldns_rr_compare(ldns_rr *, ldns_rr *); -ldns_status ldns_rr_sort(ldns_rr_list **); +void ldns_rr_sort(ldns_rr_list **); diff --git a/rr.c b/rr.c index b7e5dbeb..15a527d5 100644 --- a/rr.c +++ b/rr.c @@ -617,12 +617,37 @@ ldns_get_class_by_name(char *name) /** * sort an rr_list. the sorting is done inband * \param[in] unsorted the rr_list to be sorted - * \return ldns_status wether or not we are succesfull */ -ldns_status +void ldns_rr_sort(ldns_rr_list **unsorted) { - return LDNS_STATUS_OK; + /* we have a small amount of data (usually) go with the good + * old bubble sort ;-) */ + uint16_t rr_count; + uint16_t i,j; + ldns_rr *ri, *rj; + + rr_count = ldns_rr_list_rr_count(*unsorted); + for(i = 0; i < rr_count; i++) { + ri = ldns_rr_list_rr(*unsorted, i); + for(j = i; j < rr_count; j++) { + rj = ldns_rr_list_rr(*unsorted, j); + + switch(ldns_rr_compare(ri, rj)) { + /* equal */ + case 0: + /* equal - nop */ + case -1: + /* i before j - nop */ + break; + case 1: + /* switch */ + (*unsorted)->_rrs[i] = rj; + (*unsorted)->_rrs[j] = ri; + break; + } + } + } }