/** dump message entry */ static int dump_msg(SSL* ssl, struct query_info* k, struct reply_info* d, time_t now) { size_t i; char* nm, *tp, *cl; if(!k || !d) return 1; if(d->ttl < now) return 1; /* expired */ nm = sldns_wire2str_dname(k->qname, k->qname_len); tp = sldns_wire2str_type(k->qtype); cl = sldns_wire2str_class(k->qclass); if(!nm || !tp || !cl) { free(nm); free(tp); free(cl); return 1; /* skip this entry */ } if(!rrset_array_lock(d->ref, d->rrset_count, now)) { /* rrsets have timed out or do not exist */ free(nm); free(tp); free(cl); return 1; /* skip this entry */ } /* meta line */ if(!ssl_printf(ssl, "msg %s %s %s %d %d " ARG_LL "d %d %u %u %u\n", nm, cl, tp, (int)d->flags, (int)d->qdcount, (long long)(d->ttl-now), (int)d->security, (unsigned)d->an_numrrsets, (unsigned)d->ns_numrrsets, (unsigned)d->ar_numrrsets)) { free(nm); free(tp); free(cl); rrset_array_unlock(d->ref, d->rrset_count); return 0; } free(nm); free(tp); free(cl); for(i=0; i<d->rrset_count; i++) { if(!dump_msg_ref(ssl, d->rrsets[i])) { rrset_array_unlock(d->ref, d->rrset_count); return 0; } } rrset_array_unlock(d->ref, d->rrset_count); return 1; }
/** dump message entry */ static int dump_msg(SSL* ssl, struct query_info* k, struct reply_info* d, uint32_t now) { size_t i; char* nm, *tp, *cl; ldns_rdf* rdf; ldns_status status; size_t pos; if(!k || !d) return 1; if(d->ttl < now) return 1; /* expired */ pos = 0; status = ldns_wire2dname(&rdf, k->qname, k->qname_len, &pos); if(status != LDNS_STATUS_OK) { return 1; /* skip this entry */ } nm = ldns_rdf2str(rdf); ldns_rdf_deep_free(rdf); tp = ldns_rr_type2str(k->qtype); cl = ldns_rr_class2str(k->qclass); if(!nm || !tp || !cl) { free(nm); free(tp); free(cl); return 1; /* skip this entry */ } if(!rrset_array_lock(d->ref, d->rrset_count, now)) { /* rrsets have timed out or do not exist */ free(nm); free(tp); free(cl); return 1; /* skip this entry */ } /* meta line */ if(!ssl_printf(ssl, "msg %s %s %s %d %d %u %d %u %u %u\n", nm, cl, tp, (int)d->flags, (int)d->qdcount, (unsigned)(d->ttl-now), (int)d->security, (unsigned)d->an_numrrsets, (unsigned)d->ns_numrrsets, (unsigned)d->ar_numrrsets)) { free(nm); free(tp); free(cl); rrset_array_unlock(d->ref, d->rrset_count); return 0; } free(nm); free(tp); free(cl); for(i=0; i<d->rrset_count; i++) { if(!dump_msg_ref(ssl, d->rrsets[i])) { rrset_array_unlock(d->ref, d->rrset_count); return 0; } } rrset_array_unlock(d->ref, d->rrset_count); return 1; }