mirror of https://github.com/getdnsapi/getdns.git
Use non-copying dict_set_list
This commit is contained in:
parent
6f157854ce
commit
4551f0850b
147
src/context.c
147
src/context.c
|
@ -3095,66 +3095,94 @@ upstream_port(getdns_upstream *upstream)
|
|||
static getdns_dict*
|
||||
_get_context_settings(getdns_context* context)
|
||||
{
|
||||
getdns_return_t r = GETDNS_RETURN_GOOD;
|
||||
getdns_dict* result = getdns_dict_create_with_context(context);
|
||||
getdns_dict *result = getdns_dict_create_with_context(context);
|
||||
getdns_list *list;
|
||||
size_t i;
|
||||
|
||||
if (!result) {
|
||||
return NULL;
|
||||
}
|
||||
/* int fields */
|
||||
r = getdns_dict_set_int(result, "timeout", context->timeout);
|
||||
r = getdns_dict_set_int(result, "idle_timeout", context->idle_timeout);
|
||||
r |= getdns_dict_set_int(result, "limit_outstanding_queries", context->limit_outstanding_queries);
|
||||
r |= getdns_dict_set_int(result, "dnssec_allowed_skew", context->dnssec_allowed_skew);
|
||||
r |= getdns_dict_set_int(result, "follow_redirects", context->follow_redirects);
|
||||
if (context->edns_maximum_udp_payload_size != -1)
|
||||
r |= getdns_dict_set_int(result, "edns_maximum_udp_payload_size",
|
||||
context->edns_maximum_udp_payload_size);
|
||||
r |= getdns_dict_set_int(result, "edns_extended_rcode", context->edns_extended_rcode);
|
||||
r |= getdns_dict_set_int(result, "edns_version", context->edns_version);
|
||||
r |= getdns_dict_set_int(result, "edns_do_bit", context->edns_do_bit);
|
||||
r |= getdns_dict_set_int(result, "append_name", context->append_name);
|
||||
/* list fields */
|
||||
if (!getdns_context_get_suffix(context, &list)) {
|
||||
r |= getdns_dict_set_list(result, "suffix", list);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
/* int fields */
|
||||
if ( getdns_dict_set_int(result, "timeout",
|
||||
context->timeout)
|
||||
|| getdns_dict_set_int(result, "idle_timeout",
|
||||
context->idle_timeout)
|
||||
|| getdns_dict_set_int(result, "limit_outstanding_queries",
|
||||
context->limit_outstanding_queries)
|
||||
|| getdns_dict_set_int(result, "dnssec_allowed_skew",
|
||||
context->dnssec_allowed_skew)
|
||||
|| getdns_dict_set_int(result, "follow_redirects",
|
||||
context->follow_redirects)
|
||||
|| ( context->edns_maximum_udp_payload_size != -1
|
||||
&& getdns_dict_set_int(result, "edns_maximum_udp_payload_size",
|
||||
context->edns_maximum_udp_payload_size))
|
||||
|| getdns_dict_set_int(result, "edns_extended_rcode",
|
||||
context->edns_extended_rcode)
|
||||
|| getdns_dict_set_int(result, "edns_version",
|
||||
context->edns_version)
|
||||
|| getdns_dict_set_int(result, "edns_do_bit",
|
||||
context->edns_do_bit)
|
||||
|| getdns_dict_set_int(result, "append_name",
|
||||
context->append_name)
|
||||
|| getdns_dict_set_int(result, "tls_authentication",
|
||||
context->tls_auth))
|
||||
goto error;
|
||||
|
||||
/* list fields */
|
||||
if (getdns_context_get_suffix(context, &list))
|
||||
goto error;
|
||||
|
||||
if (_getdns_dict_set_this_list(result, "suffix", list)) {
|
||||
getdns_list_destroy(list);
|
||||
goto error;
|
||||
}
|
||||
if (!getdns_context_get_upstream_recursive_servers(context, &list)) {
|
||||
r |= getdns_dict_set_list(result, "upstream_recursive_servers",
|
||||
list);
|
||||
if (getdns_context_get_upstream_recursive_servers(context, &list))
|
||||
goto error;
|
||||
|
||||
if (_getdns_dict_set_this_list(
|
||||
result, "upstream_recursive_servers", list)) {
|
||||
getdns_list_destroy(list);
|
||||
goto error;
|
||||
}
|
||||
if (context->dns_transport_count > 0) {
|
||||
if (context->dns_transport_count > 0) {
|
||||
/* create a namespace list */
|
||||
if (!(list = getdns_list_create_with_context(context)))
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < context->dns_transport_count; ++i) {
|
||||
if (getdns_list_set_int(list, i,
|
||||
context->dns_transports[i])) {
|
||||
getdns_list_destroy(list);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (_getdns_dict_set_this_list(
|
||||
result, "dns_transport_list", list)) {
|
||||
getdns_list_destroy(list);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (context->namespace_count > 0) {
|
||||
/* create a namespace list */
|
||||
size_t i;
|
||||
getdns_list* transports = getdns_list_create_with_context(context);
|
||||
if (transports) {
|
||||
for (i = 0; i < context->dns_transport_count; ++i) {
|
||||
r |= getdns_list_set_int(transports, i, context->dns_transports[i]);
|
||||
}
|
||||
r |= getdns_dict_set_list(result, "dns_transport_list", transports);
|
||||
getdns_list_destroy(transports);
|
||||
}
|
||||
r |= getdns_dict_set_int(result, "tls_authentication", context->tls_auth);
|
||||
}
|
||||
if (context->namespace_count > 0) {
|
||||
/* create a namespace list */
|
||||
size_t i;
|
||||
getdns_list* namespaces = getdns_list_create_with_context(context);
|
||||
if (namespaces) {
|
||||
for (i = 0; i < context->namespace_count; ++i) {
|
||||
r |= getdns_list_set_int(namespaces, i, context->namespaces[i]);
|
||||
}
|
||||
r |= getdns_dict_set_list(result, "namespaces", namespaces);
|
||||
getdns_list_destroy(namespaces);
|
||||
}
|
||||
}
|
||||
if (r != GETDNS_RETURN_GOOD) {
|
||||
getdns_dict_destroy(result);
|
||||
result = NULL;
|
||||
}
|
||||
return result;
|
||||
if (!(list = getdns_list_create_with_context(context)))
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < context->namespace_count; ++i) {
|
||||
if (getdns_list_set_int(list, i,
|
||||
context->namespaces[i])) {
|
||||
getdns_list_destroy(list);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (_getdns_dict_set_this_list(result, "namespaces", list)) {
|
||||
getdns_list_destroy(list);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
error:
|
||||
getdns_dict_destroy(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
getdns_dict*
|
||||
|
@ -3282,17 +3310,17 @@ _getdns_context_local_namespace_resolve(
|
|||
}
|
||||
if (!(jaa = getdns_list_create_with_context(context)))
|
||||
goto error;
|
||||
|
||||
for (i = 0; !getdns_list_get_dict(hnas->ipv4addrs, i, &addr); i++)
|
||||
if (_getdns_list_append_dict(jaa, addr))
|
||||
break;
|
||||
for (i = 0; !getdns_list_get_dict(hnas->ipv6addrs, i, &addr); i++)
|
||||
if (_getdns_list_append_dict(jaa, addr))
|
||||
break;
|
||||
if (!getdns_dict_set_list(*response, "just_address_answers", jaa)) {
|
||||
getdns_list_destroy(jaa);
|
||||
if (!_getdns_dict_set_this_list(*response, "just_address_answers", jaa))
|
||||
return GETDNS_RETURN_GOOD;
|
||||
}
|
||||
getdns_list_destroy(jaa);
|
||||
else
|
||||
getdns_list_destroy(jaa);
|
||||
error:
|
||||
getdns_dict_destroy(*response);
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
|
@ -3598,9 +3626,10 @@ getdns_context_get_upstream_recursive_servers(getdns_context *context,
|
|||
if ((_getdns_get_pubkey_pinset_list(context,
|
||||
upstream->tls_pubkey_pinset,
|
||||
&pins) == GETDNS_RETURN_GOOD) &&
|
||||
(r = getdns_dict_set_list(d, "tls_pubkey_pinset", pins)))
|
||||
(r = _getdns_dict_set_this_list(d, "tls_pubkey_pinset", pins))) {
|
||||
getdns_list_destroy(pins);
|
||||
break;
|
||||
getdns_list_destroy(pins);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -667,13 +667,20 @@ _getdns_wire2msg_dict_scan(struct mem_funcs *mf,
|
|||
}
|
||||
rr_dict = NULL;
|
||||
}
|
||||
if ((r = getdns_dict_set_list(result, "answer",
|
||||
sections[GLDNS_SECTION_ANSWER])) ||
|
||||
(r = getdns_dict_set_list(result, "authority",
|
||||
sections[GLDNS_SECTION_AUTHORITY])) ||
|
||||
(r = getdns_dict_set_list(result, "additional",
|
||||
sections[GLDNS_SECTION_ADDITIONAL])))
|
||||
goto error;
|
||||
if (!(r = _getdns_dict_set_this_list(result, "answer",
|
||||
sections[GLDNS_SECTION_ANSWER])))
|
||||
sections[GLDNS_SECTION_ANSWER] = NULL;
|
||||
else goto error;
|
||||
|
||||
if (!(r = _getdns_dict_set_this_list(result, "authority",
|
||||
sections[GLDNS_SECTION_AUTHORITY])))
|
||||
sections[GLDNS_SECTION_AUTHORITY] = NULL;
|
||||
else goto error;
|
||||
|
||||
if (!(r = _getdns_dict_set_this_list(result, "additional",
|
||||
sections[GLDNS_SECTION_ADDITIONAL])))
|
||||
sections[GLDNS_SECTION_ADDITIONAL] = NULL;
|
||||
else goto error;
|
||||
|
||||
*wire_len -= (eop - *wire);
|
||||
*wire = eop;
|
||||
|
|
|
@ -3239,9 +3239,9 @@ static void check_chain_complete(chain_head *chain)
|
|||
|
||||
response_dict = _getdns_create_getdns_response(dnsreq);
|
||||
if (val_chain_list) {
|
||||
(void) getdns_dict_set_list(
|
||||
response_dict, "validation_chain", val_chain_list);
|
||||
getdns_list_destroy(val_chain_list);
|
||||
if (_getdns_dict_set_this_list(
|
||||
response_dict, "validation_chain", val_chain_list))
|
||||
getdns_list_destroy(val_chain_list);
|
||||
}
|
||||
|
||||
/* Final user callback */
|
||||
|
|
|
@ -370,10 +370,9 @@ _getdns_rr_iter2rr_dict(struct mem_funcs *mf, _getdns_rr_iter *i)
|
|||
repeat_dict = NULL;
|
||||
}
|
||||
if (repeat_list) {
|
||||
if (getdns_dict_set_list(rdata_dict,
|
||||
if (_getdns_dict_set_this_list(rdata_dict,
|
||||
rdf_storage.rdd_repeat->name, repeat_list))
|
||||
goto rdata_error;
|
||||
getdns_list_destroy(repeat_list);
|
||||
repeat_list = NULL;
|
||||
}
|
||||
if (_getdns_dict_set_this_dict(rr_dict, "rdata", rdata_dict))
|
||||
|
@ -605,17 +604,20 @@ _getdns_create_reply_dict(getdns_context *context, getdns_network_req *req,
|
|||
goto error;
|
||||
}
|
||||
}
|
||||
if (getdns_dict_set_list(result, "answer",
|
||||
sections[GLDNS_SECTION_ANSWER]) ||
|
||||
if (!_getdns_dict_set_this_list(result, "answer",
|
||||
sections[GLDNS_SECTION_ANSWER]))
|
||||
sections[GLDNS_SECTION_ANSWER] = NULL;
|
||||
else goto error;
|
||||
|
||||
getdns_dict_set_list(result, "authority",
|
||||
sections[GLDNS_SECTION_AUTHORITY]) ||
|
||||
if (!_getdns_dict_set_this_list(result, "authority",
|
||||
sections[GLDNS_SECTION_AUTHORITY]))
|
||||
sections[GLDNS_SECTION_AUTHORITY] = NULL;
|
||||
else goto error;
|
||||
|
||||
getdns_dict_set_list(result, "additional",
|
||||
sections[GLDNS_SECTION_ADDITIONAL])) {
|
||||
|
||||
goto error;
|
||||
}
|
||||
if (!_getdns_dict_set_this_list(result, "additional",
|
||||
sections[GLDNS_SECTION_ADDITIONAL]))
|
||||
sections[GLDNS_SECTION_ADDITIONAL] = NULL;
|
||||
else goto error;
|
||||
|
||||
/* other stuff
|
||||
* Note that spec doesn't explicitely mention these.
|
||||
|
@ -732,8 +734,9 @@ _getdns_create_reply_dict(getdns_context *context, getdns_network_req *req,
|
|||
_getdns_list_append_int(bad_dns, GETDNS_BAD_DNS_ALL_NUMERIC_LABEL))
|
||||
goto error;
|
||||
|
||||
if (getdns_dict_set_list(result, "bad_dns", bad_dns))
|
||||
if (_getdns_dict_set_this_list(result, "bad_dns", bad_dns))
|
||||
goto error;
|
||||
else bad_dns = NULL;
|
||||
|
||||
goto success;
|
||||
error:
|
||||
|
@ -976,23 +979,26 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
|
|||
if (_getdns_list_append_bindata(replies_full, &full_data))
|
||||
goto error;
|
||||
}
|
||||
if (getdns_dict_set_list(result, "replies_tree", replies_tree))
|
||||
if (_getdns_dict_set_this_list(result, "replies_tree", replies_tree))
|
||||
goto error;
|
||||
getdns_list_destroy(replies_tree);
|
||||
replies_tree = NULL;
|
||||
|
||||
if (call_reporting &&
|
||||
getdns_dict_set_list(result, "call_reporting", call_reporting))
|
||||
goto error_free_call_reporting;
|
||||
|
||||
if (getdns_dict_set_list(result, "replies_full", replies_full))
|
||||
if (call_reporting) {
|
||||
if (_getdns_dict_set_this_list(
|
||||
result, "call_reporting", call_reporting))
|
||||
goto error_free_call_reporting;
|
||||
call_reporting = NULL;
|
||||
}
|
||||
if (_getdns_dict_set_this_list(result, "replies_full", replies_full))
|
||||
goto error_free_replies_full;
|
||||
getdns_list_destroy(replies_full);
|
||||
|
||||
if (just_addrs && getdns_dict_set_list(
|
||||
result, GETDNS_STR_KEY_JUST_ADDRS, just_addrs))
|
||||
goto error_free_result;
|
||||
getdns_list_destroy(just_addrs);
|
||||
replies_full = NULL;
|
||||
|
||||
if (just_addrs) {
|
||||
if (_getdns_dict_set_this_list(
|
||||
result, GETDNS_STR_KEY_JUST_ADDRS, just_addrs))
|
||||
goto error_free_result;
|
||||
just_addrs = NULL;
|
||||
}
|
||||
if (getdns_dict_set_int(result, GETDNS_STR_KEY_STATUS,
|
||||
nreplies == 0 ? GETDNS_RESPSTATUS_ALL_TIMEOUT :
|
||||
completed_request->dnssec_return_only_secure && nsecure == 0 && ninsecure > 0
|
||||
|
|
Loading…
Reference in New Issue