Logo Search packages:      
Sourcecode: ldns version File versions  Download package

ldns_rr_list* ldns_rr_list_pop_rrset ( ldns_rr_list rr_list  ) 

pops the first rrset from the list, the list must be sorted, so that all rr's from each rrset are next to each other

Definition at line 1076 of file rr.c.

References ldns_rdf_compare(), ldns_rr_get_class(), ldns_rr_get_type(), ldns_rr_list_free(), ldns_rr_list_new(), ldns_rr_list_pop_rr(), ldns_rr_list_pop_rrset(), ldns_rr_list_push_rr(), ldns_rr_list_rr(), ldns_rr_list_rr_count(), and ldns_rr_owner().

Referenced by ldns_rr_list_pop_rrset().

{
      ldns_rr_list *rrset;
      ldns_rr *last_rr = NULL;
      ldns_rr *next_rr;
      
      if (!rr_list) {
            return NULL;
      }
      
      rrset = ldns_rr_list_new();
      if (!last_rr) {
            last_rr = ldns_rr_list_pop_rr(rr_list);
            if (!last_rr) {
                  ldns_rr_list_free(rrset);
                  return NULL;
            } else {
                  ldns_rr_list_push_rr(rrset, last_rr);
            }
      }

      if (ldns_rr_list_rr_count(rr_list) > 0) {
            next_rr = ldns_rr_list_rr(rr_list, ldns_rr_list_rr_count(rr_list) - 1);
      } else {
            next_rr = NULL;
      }

      while (next_rr) {
            if (
                  ldns_rdf_compare(ldns_rr_owner(next_rr),
                               ldns_rr_owner(last_rr)) == 0
                  &&
                  ldns_rr_get_type(next_rr) == ldns_rr_get_type(last_rr)
                  &&
                  ldns_rr_get_class(next_rr) == ldns_rr_get_class(last_rr)
               ) {
                  ldns_rr_list_push_rr(rrset, ldns_rr_list_pop_rr(rr_list));
                  if (ldns_rr_list_rr_count(rr_list) > 0) {
                        last_rr = next_rr;
                        next_rr = ldns_rr_list_rr(rr_list, ldns_rr_list_rr_count(rr_list) - 1);
                  } else {
                        next_rr = NULL;
                  }
            } else {
                  next_rr = NULL;
            }
      }

      return rrset;
}


Generated by  Doxygen 1.6.0   Back to index