mirror of https://github.com/getdnsapi/getdns.git
Already lose some replaced functions
This commit is contained in:
parent
05cc557de0
commit
a722778b3c
200
src/rr-dict.c
200
src/rr-dict.c
|
@ -972,48 +972,6 @@ priv_getdns_create_dict_from_rr(
|
|||
return r;
|
||||
}
|
||||
|
||||
getdns_return_t
|
||||
priv_getdns_create_reply_question_dict(
|
||||
struct getdns_context *context, ldns_pkt *pkt, struct getdns_dict** q_dict)
|
||||
{
|
||||
getdns_return_t r = GETDNS_RETURN_GOOD;
|
||||
ldns_rr *rr;
|
||||
struct getdns_bindata qname;
|
||||
|
||||
assert(pkt);
|
||||
assert(q_dict);
|
||||
|
||||
*q_dict = getdns_dict_create_with_context(context);
|
||||
if (! *q_dict)
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
|
||||
rr = ldns_rr_list_rr(ldns_pkt_question(pkt), 0);
|
||||
if (! rr)
|
||||
return GETDNS_RETURN_GOOD;
|
||||
|
||||
do { /* break on error (to cleanup *q_dict) */
|
||||
r = getdns_dict_set_int(*q_dict,
|
||||
"qtype", ldns_rr_get_type(rr));
|
||||
if (r != GETDNS_RETURN_GOOD)
|
||||
break;
|
||||
r = getdns_dict_set_int(*q_dict,
|
||||
"qclass", ldns_rr_get_class(rr));
|
||||
if (r != GETDNS_RETURN_GOOD)
|
||||
break;
|
||||
|
||||
/* "qname" attribute.
|
||||
* ldns_rr_owner(rr) is already uncompressed!
|
||||
*/
|
||||
qname.size = ldns_rdf_size(ldns_rr_owner(rr));
|
||||
qname.data = ldns_rdf_data(ldns_rr_owner(rr));
|
||||
r = getdns_dict_set_bindata(*q_dict, "qname", &qname);
|
||||
if (r == GETDNS_RETURN_GOOD)
|
||||
return r;
|
||||
} while (0);
|
||||
getdns_dict_destroy(*q_dict);
|
||||
return r;
|
||||
}
|
||||
|
||||
static getdns_return_t priv_getdns_construct_wire_rdata_from_rdata(
|
||||
struct getdns_dict *rdata, uint32_t rr_type,
|
||||
uint8_t **wire, size_t *wire_size)
|
||||
|
@ -1203,161 +1161,3 @@ priv_getdns_create_rr_from_dict(struct getdns_dict *rr_dict, ldns_rr **rr)
|
|||
return r;
|
||||
}
|
||||
|
||||
static getdns_return_t
|
||||
priv_getdns_get_opt_dict(struct getdns_context* context,
|
||||
struct getdns_dict** record_dict, uint8_t* record_start,
|
||||
size_t* bytes_remaining, size_t* bytes_parsed) {
|
||||
|
||||
getdns_return_t r = GETDNS_RETURN_GOOD;
|
||||
struct getdns_dict* opt = NULL;
|
||||
uint16_t code;
|
||||
struct getdns_bindata opt_data;
|
||||
if (*bytes_remaining < 4) {
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
code = ldns_read_uint16(record_start);
|
||||
opt_data.size = ldns_read_uint16(record_start + 2);
|
||||
if (*bytes_remaining < (4 + opt_data.size)) {
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
opt = getdns_dict_create_with_context(context);
|
||||
if (!opt) {
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
}
|
||||
/* set code */
|
||||
r = getdns_dict_set_int(opt, opt_rdata[1].name, code);
|
||||
if (r != GETDNS_RETURN_GOOD) {
|
||||
getdns_dict_destroy(opt);
|
||||
return r;
|
||||
}
|
||||
/* set data */
|
||||
opt_data.data = record_start + 4;
|
||||
getdns_dict_set_bindata(opt, opt_rdata[2].name, &opt_data);
|
||||
if (r != GETDNS_RETURN_GOOD) {
|
||||
getdns_dict_destroy(opt);
|
||||
return r;
|
||||
}
|
||||
/* set result data */
|
||||
*bytes_remaining = *bytes_remaining - (4 + opt_data.size);
|
||||
*bytes_parsed = *bytes_parsed + (4 + opt_data.size);
|
||||
*record_dict = opt;
|
||||
return r;
|
||||
}
|
||||
|
||||
static getdns_return_t
|
||||
priv_getdns_create_opt_rr(
|
||||
struct getdns_context *context, ldns_rdf* rdf,
|
||||
struct getdns_dict** rr_dict) {
|
||||
|
||||
struct getdns_dict* result = NULL;
|
||||
getdns_return_t r = GETDNS_RETURN_GOOD;
|
||||
size_t bytes_remaining = ldns_rdf_size(rdf);
|
||||
size_t bytes_parsed = 0;
|
||||
uint8_t* record_start = ldns_rdf_data(rdf);
|
||||
struct getdns_list* records = getdns_list_create_with_context(context);
|
||||
size_t idx = 0;
|
||||
if (!records) {
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
}
|
||||
while (r == GETDNS_RETURN_GOOD && bytes_remaining > 0) {
|
||||
struct getdns_dict* opt = NULL;
|
||||
r = priv_getdns_get_opt_dict(context, &opt,
|
||||
record_start + bytes_parsed, &bytes_remaining,
|
||||
&bytes_parsed);
|
||||
if (r == GETDNS_RETURN_GOOD) {
|
||||
getdns_list_set_dict(records, idx, opt);
|
||||
getdns_dict_destroy(opt);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
if (r != GETDNS_RETURN_GOOD) {
|
||||
getdns_list_destroy(records);
|
||||
return r;
|
||||
}
|
||||
result = getdns_dict_create_with_context(context);
|
||||
if (!result) {
|
||||
getdns_list_destroy(records);
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
}
|
||||
/* cheat */
|
||||
r = 0;
|
||||
r |= getdns_dict_set_list(result,
|
||||
opt_rdata[0].name, records);
|
||||
getdns_list_destroy(records);
|
||||
|
||||
/* does class makes sense? */
|
||||
if (r != GETDNS_RETURN_GOOD) {
|
||||
getdns_dict_destroy(result);
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
*rr_dict = result;
|
||||
return r;
|
||||
}
|
||||
|
||||
getdns_return_t priv_getdns_append_opt_rr(
|
||||
getdns_context *context, getdns_list *rdatas, ldns_pkt *pkt)
|
||||
{
|
||||
getdns_dict *opt_rr = NULL;
|
||||
getdns_dict *rr_dict;
|
||||
getdns_return_t r = 0;
|
||||
getdns_bindata rdata;
|
||||
ldns_rdf* edns_data = ldns_pkt_edns_data(pkt);
|
||||
size_t list_len;
|
||||
getdns_list *options;
|
||||
|
||||
if (!ldns_pkt_edns(pkt))
|
||||
/* nothing to do */
|
||||
return GETDNS_RETURN_GOOD;
|
||||
|
||||
if ((r = getdns_list_get_length(rdatas, &list_len)))
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
|
||||
if (!(rr_dict = getdns_dict_create_with_context(context)))
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
|
||||
if (edns_data) {
|
||||
r |= priv_getdns_create_opt_rr(context, edns_data, &opt_rr);
|
||||
|
||||
rdata.size = ldns_rdf_size(edns_data);
|
||||
rdata.data = ldns_rdf_data(edns_data);
|
||||
|
||||
} else {
|
||||
if (!(opt_rr = getdns_dict_create_with_context(context)))
|
||||
r |= GETDNS_RETURN_GENERIC_ERROR;
|
||||
|
||||
rdata.size = 0;
|
||||
rdata.data = NULL;
|
||||
|
||||
if (!(options = getdns_list_create_with_context(context)))
|
||||
r |= GETDNS_RETURN_GENERIC_ERROR;
|
||||
|
||||
r |= getdns_dict_set_list(opt_rr, "options", options);
|
||||
getdns_list_destroy(options);
|
||||
}
|
||||
|
||||
/* add data */
|
||||
r |= getdns_dict_set_bindata(opt_rr, "rdata_raw", &rdata);
|
||||
r |= getdns_dict_set_dict(rr_dict, "rdata", opt_rr);
|
||||
getdns_dict_destroy(opt_rr);
|
||||
|
||||
|
||||
/* add rest of the fields */
|
||||
r |= getdns_dict_set_int(rr_dict, "type", GETDNS_RRTYPE_OPT);
|
||||
r |= getdns_dict_set_int(rr_dict, "udp_payload_size",
|
||||
ldns_pkt_edns_udp_size(pkt));
|
||||
r |= getdns_dict_set_int(rr_dict, "extended_rcode",
|
||||
ldns_pkt_edns_extended_rcode(pkt));
|
||||
r |= getdns_dict_set_int(rr_dict, "version",
|
||||
ldns_pkt_edns_version(pkt));
|
||||
r |= getdns_dict_set_int(rr_dict, "do", ldns_pkt_edns_do(pkt));
|
||||
r |= getdns_dict_set_int(rr_dict, "z",
|
||||
ldns_pkt_edns_z(pkt) & 0x7FFF);
|
||||
|
||||
/* append */
|
||||
r |= getdns_list_set_dict(rdatas, list_len, rr_dict);
|
||||
getdns_dict_destroy(rr_dict);
|
||||
if (r)
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
else
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
|
|
|
@ -93,17 +93,11 @@ const priv_getdns_rr_def *priv_getdns_rr_def_lookup(uint16_t rr_type);
|
|||
getdns_return_t priv_getdns_create_dict_from_rr(
|
||||
struct getdns_context *context, ldns_rr *rr, struct getdns_dict** rr_dict);
|
||||
|
||||
getdns_return_t priv_getdns_create_reply_question_dict(
|
||||
struct getdns_context *context, ldns_pkt *pkt, struct getdns_dict** q_dict);
|
||||
|
||||
getdns_return_t priv_getdns_create_rr_from_dict(
|
||||
struct getdns_dict *rr_dict, ldns_rr **rr);
|
||||
|
||||
const char *priv_getdns_rr_type_name(int rr_type);
|
||||
|
||||
getdns_return_t priv_getdns_append_opt_rr(
|
||||
struct getdns_context *context, struct getdns_list* rdatas, ldns_pkt* pkt);
|
||||
|
||||
#endif
|
||||
|
||||
/* rrs.h */
|
||||
|
|
Loading…
Reference in New Issue