/** fill data into result */ static int fill_res(struct ub_result* res, struct ub_packed_rrset_key* answer, uint8_t* finalcname, struct query_info* rq) { size_t i; struct packed_rrset_data* data; if(!answer) { if(finalcname) { if(!fill_canon(res, finalcname)) return 0; /* out of memory */ } res->data = (char**)calloc(1, sizeof(char*)); res->len = (int*)calloc(1, sizeof(int)); return (res->data && res->len); } data = (struct packed_rrset_data*)answer->entry.data; if(query_dname_compare(rq->qname, answer->rk.dname) != 0) { if(!fill_canon(res, answer->rk.dname)) return 0; /* out of memory */ } else res->canonname = NULL; res->data = (char**)calloc(data->count+1, sizeof(char*)); res->len = (int*)calloc(data->count+1, sizeof(int)); if(!res->data || !res->len) return 0; /* out of memory */ for(i=0; i<data->count; i++) { /* remove rdlength from rdata */ res->len[i] = (int)(data->rr_len[i] - 2); res->data[i] = memdup(data->rr_data[i]+2, (size_t)res->len[i]); if(!res->data[i]) return 0; /* out of memory */ } res->data[data->count] = NULL; res->len[data->count] = 0; return 1; }
/** fill data into result */ static int fill_res(struct ub_result* res, struct ub_packed_rrset_key* answer, uint8_t* finalcname, struct query_info* rq, struct reply_info* rep) { size_t i; struct packed_rrset_data* data; res->ttl = 0; if(!answer) { if(finalcname) { if(!fill_canon(res, finalcname)) return 0; /* out of memory */ } if(rep->rrset_count != 0) res->ttl = (int)rep->ttl; res->data = (char**)calloc(1, sizeof(char*)); res->len = (int*)calloc(1, sizeof(int)); return (res->data && res->len); } data = (struct packed_rrset_data*)answer->entry.data; if(query_dname_compare(rq->qname, answer->rk.dname) != 0) { if(!fill_canon(res, answer->rk.dname)) return 0; /* out of memory */ } else res->canonname = NULL; res->data = (char**)calloc(data->count+1, sizeof(char*)); res->len = (int*)calloc(data->count+1, sizeof(int)); if(!res->data || !res->len) return 0; /* out of memory */ for(i=0; i<data->count; i++) { /* remove rdlength from rdata */ res->len[i] = (int)(data->rr_len[i] - 2); res->data[i] = memdup(data->rr_data[i]+2, (size_t)res->len[i]); if(!res->data[i]) return 0; /* out of memory */ } /* ttl for positive answers, from CNAME and answer RRs */ if(data->count != 0) { size_t j; res->ttl = (int)data->ttl; for(j=0; j<rep->an_numrrsets; j++) { struct packed_rrset_data* d = (struct packed_rrset_data*)rep->rrsets[j]-> entry.data; if((int)d->ttl < res->ttl) res->ttl = (int)d->ttl; } } /* ttl for negative answers */ if(data->count == 0 && rep->rrset_count != 0) res->ttl = (int)rep->ttl; res->data[data->count] = NULL; res->len[data->count] = 0; return 1; }