]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
made a rr_list to buffer
authorMiek Gieben <miekg@NLnetLabs.nl>
Thu, 24 Feb 2005 12:42:18 +0000 (12:42 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Thu, 24 Feb 2005 12:42:18 +0000 (12:42 +0000)
made a bubblesort :-) rr_list sorter

host2str.c
ldns/rr.h
rr.c

index 5b51052e0a4f79c2c2c4d267dea0f7dd656d8a3a..c9ef22543afff0dc94a0c33840ce3b050bc604bf 100644 (file)
@@ -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
  */
index 8c84ea38cc63d28ca94f9a4c1eb0903ce56571a7..aa7c74c2791b1d5b34478a370ab96791257be533 100644 (file)
--- 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 b7e5dbeb6348d08b1a2b3bbd2390a0f084105dd2..15a527d5c39a1dfc64619902fd77f45decd810d7 100644 (file)
--- 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;
+                       }
+               }
+       }
 }