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

ldns_rr* ldns_axfr_next ( ldns_resolver resolver  ) 

get the next stream of RRs in a AXFR

Parameters:
[in] resolver the resolver to use. First ldns_axfr_start() must be called
Returns:
ldns_rr the next RR from the AXFR stream

Definition at line 988 of file resolver.c.

References ldns_struct_resolver::_axfr_i, ldns_struct_resolver::_axfr_soa_count, ldns_struct_resolver::_cur_axfr_pkt, ldns_struct_resolver::_socket, ldns_axfr_next(), ldns_pkt_ancount(), ldns_pkt_answer(), ldns_pkt_free(), ldns_pkt_get_rcode(), ldns_rr_clone(), ldns_rr_get_type(), ldns_rr_list_rr(), LDNS_RR_TYPE_SOA, ldns_tcp_read_wire(), and ldns_wire2pkt().

Referenced by ldns_axfr_next().

{
      ldns_rr *cur_rr;
      uint8_t *packet_wire;
      size_t packet_wire_size;
      ldns_lookup_table *rcode;
      ldns_status status;
      
      /* check if start() has been called */
      if (!resolver || resolver->_socket == 0) {
            return NULL;
      }
      
      if (resolver->_cur_axfr_pkt) {
            if (resolver->_axfr_i == ldns_pkt_ancount(resolver->_cur_axfr_pkt)) {
                  ldns_pkt_free(resolver->_cur_axfr_pkt);
                  resolver->_cur_axfr_pkt = NULL;
                  return ldns_axfr_next(resolver);
            }
            cur_rr = ldns_rr_clone(ldns_rr_list_rr(
                              ldns_pkt_answer(resolver->_cur_axfr_pkt), 
                              resolver->_axfr_i));
            resolver->_axfr_i++;
            if (ldns_rr_get_type(cur_rr) == LDNS_RR_TYPE_SOA) {
                  resolver->_axfr_soa_count++;
                  if (resolver->_axfr_soa_count >= 2) {
                        close(resolver->_socket);
                        resolver->_socket = 0;
                        ldns_pkt_free(resolver->_cur_axfr_pkt);
                        resolver->_cur_axfr_pkt = NULL;
                  }
            }
            return cur_rr;
      } else {
            packet_wire = ldns_tcp_read_wire(resolver->_socket, &packet_wire_size);
            if(!packet_wire) 
                  return NULL;
            
            status = ldns_wire2pkt(&resolver->_cur_axfr_pkt, packet_wire, 
                             packet_wire_size);
            free(packet_wire);

            resolver->_axfr_i = 0;
            if (status != LDNS_STATUS_OK) {
                  /* TODO: make status return type of this function (...api change) */
                  fprintf(stderr, "Error parsing rr during AXFR: %s\n", ldns_get_errorstr_by_id(status));
                  return NULL;
            } else if (ldns_pkt_get_rcode(resolver->_cur_axfr_pkt) != 0) {
                  rcode = ldns_lookup_by_id(ldns_rcodes, (int) ldns_pkt_get_rcode(resolver->_cur_axfr_pkt));
                  fprintf(stderr, "Error in AXFR: %s\n", rcode->name);
                  return NULL;
            } else {
                  return ldns_axfr_next(resolver);
            }
            
      }
      
}


Generated by  Doxygen 1.6.0   Back to index