Use non-copying dict_set_list

This commit is contained in:
Willem Toorop 2016-03-21 12:50:43 +01:00
parent 6f157854ce
commit 4551f0850b
4 changed files with 136 additions and 94 deletions

View File

@ -3095,66 +3095,94 @@ upstream_port(getdns_upstream *upstream)
static getdns_dict* static getdns_dict*
_get_context_settings(getdns_context* context) _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; getdns_list *list;
size_t i;
if (!result) { if (!result)
return NULL; return NULL;
}
/* int fields */ /* int fields */
r = getdns_dict_set_int(result, "timeout", context->timeout); if ( getdns_dict_set_int(result, "timeout",
r = getdns_dict_set_int(result, "idle_timeout", context->idle_timeout); context->timeout)
r |= getdns_dict_set_int(result, "limit_outstanding_queries", context->limit_outstanding_queries); || getdns_dict_set_int(result, "idle_timeout",
r |= getdns_dict_set_int(result, "dnssec_allowed_skew", context->dnssec_allowed_skew); context->idle_timeout)
r |= getdns_dict_set_int(result, "follow_redirects", context->follow_redirects); || getdns_dict_set_int(result, "limit_outstanding_queries",
if (context->edns_maximum_udp_payload_size != -1) context->limit_outstanding_queries)
r |= getdns_dict_set_int(result, "edns_maximum_udp_payload_size", || getdns_dict_set_int(result, "dnssec_allowed_skew",
context->edns_maximum_udp_payload_size); context->dnssec_allowed_skew)
r |= getdns_dict_set_int(result, "edns_extended_rcode", context->edns_extended_rcode); || getdns_dict_set_int(result, "follow_redirects",
r |= getdns_dict_set_int(result, "edns_version", context->edns_version); context->follow_redirects)
r |= getdns_dict_set_int(result, "edns_do_bit", context->edns_do_bit); || ( context->edns_maximum_udp_payload_size != -1
r |= getdns_dict_set_int(result, "append_name", context->append_name); && getdns_dict_set_int(result, "edns_maximum_udp_payload_size",
/* list fields */ context->edns_maximum_udp_payload_size))
if (!getdns_context_get_suffix(context, &list)) { || getdns_dict_set_int(result, "edns_extended_rcode",
r |= getdns_dict_set_list(result, "suffix", list); 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); getdns_list_destroy(list);
goto error;
} }
if (!getdns_context_get_upstream_recursive_servers(context, &list)) { if (getdns_context_get_upstream_recursive_servers(context, &list))
r |= getdns_dict_set_list(result, "upstream_recursive_servers", goto error;
list);
if (_getdns_dict_set_this_list(
result, "upstream_recursive_servers", list)) {
getdns_list_destroy(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 */ /* create a namespace list */
size_t i; if (!(list = getdns_list_create_with_context(context)))
getdns_list* transports = getdns_list_create_with_context(context); goto error;
if (transports) {
for (i = 0; i < context->dns_transport_count; ++i) { for (i = 0; i < context->namespace_count; ++i) {
r |= getdns_list_set_int(transports, i, context->dns_transports[i]); if (getdns_list_set_int(list, i,
} context->namespaces[i])) {
r |= getdns_dict_set_list(result, "dns_transport_list", transports); getdns_list_destroy(list);
getdns_list_destroy(transports); goto error;
} }
r |= getdns_dict_set_int(result, "tls_authentication", context->tls_auth); }
} if (_getdns_dict_set_this_list(result, "namespaces", list)) {
if (context->namespace_count > 0) { getdns_list_destroy(list);
/* create a namespace list */ return NULL;
size_t i; }
getdns_list* namespaces = getdns_list_create_with_context(context); }
if (namespaces) { return result;
for (i = 0; i < context->namespace_count; ++i) { error:
r |= getdns_list_set_int(namespaces, i, context->namespaces[i]); getdns_dict_destroy(result);
} return NULL;
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;
} }
getdns_dict* getdns_dict*
@ -3282,17 +3310,17 @@ _getdns_context_local_namespace_resolve(
} }
if (!(jaa = getdns_list_create_with_context(context))) if (!(jaa = getdns_list_create_with_context(context)))
goto error; goto error;
for (i = 0; !getdns_list_get_dict(hnas->ipv4addrs, i, &addr); i++) for (i = 0; !getdns_list_get_dict(hnas->ipv4addrs, i, &addr); i++)
if (_getdns_list_append_dict(jaa, addr)) if (_getdns_list_append_dict(jaa, addr))
break; break;
for (i = 0; !getdns_list_get_dict(hnas->ipv6addrs, i, &addr); i++) for (i = 0; !getdns_list_get_dict(hnas->ipv6addrs, i, &addr); i++)
if (_getdns_list_append_dict(jaa, addr)) if (_getdns_list_append_dict(jaa, addr))
break; break;
if (!getdns_dict_set_list(*response, "just_address_answers", jaa)) { if (!_getdns_dict_set_this_list(*response, "just_address_answers", jaa))
getdns_list_destroy(jaa);
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} else
getdns_list_destroy(jaa); getdns_list_destroy(jaa);
error: error:
getdns_dict_destroy(*response); getdns_dict_destroy(*response);
return GETDNS_RETURN_GENERIC_ERROR; 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, if ((_getdns_get_pubkey_pinset_list(context,
upstream->tls_pubkey_pinset, upstream->tls_pubkey_pinset,
&pins) == GETDNS_RETURN_GOOD) && &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; break;
getdns_list_destroy(pins); }
} }
} }
} }

View File

@ -667,13 +667,20 @@ _getdns_wire2msg_dict_scan(struct mem_funcs *mf,
} }
rr_dict = NULL; rr_dict = NULL;
} }
if ((r = getdns_dict_set_list(result, "answer", if (!(r = _getdns_dict_set_this_list(result, "answer",
sections[GLDNS_SECTION_ANSWER])) || sections[GLDNS_SECTION_ANSWER])))
(r = getdns_dict_set_list(result, "authority", sections[GLDNS_SECTION_ANSWER] = NULL;
sections[GLDNS_SECTION_AUTHORITY])) || else goto error;
(r = getdns_dict_set_list(result, "additional",
sections[GLDNS_SECTION_ADDITIONAL]))) if (!(r = _getdns_dict_set_this_list(result, "authority",
goto error; 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_len -= (eop - *wire);
*wire = eop; *wire = eop;

View File

@ -3239,9 +3239,9 @@ static void check_chain_complete(chain_head *chain)
response_dict = _getdns_create_getdns_response(dnsreq); response_dict = _getdns_create_getdns_response(dnsreq);
if (val_chain_list) { if (val_chain_list) {
(void) getdns_dict_set_list( if (_getdns_dict_set_this_list(
response_dict, "validation_chain", val_chain_list); response_dict, "validation_chain", val_chain_list))
getdns_list_destroy(val_chain_list); getdns_list_destroy(val_chain_list);
} }
/* Final user callback */ /* Final user callback */

View File

@ -370,10 +370,9 @@ _getdns_rr_iter2rr_dict(struct mem_funcs *mf, _getdns_rr_iter *i)
repeat_dict = NULL; repeat_dict = NULL;
} }
if (repeat_list) { 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)) rdf_storage.rdd_repeat->name, repeat_list))
goto rdata_error; goto rdata_error;
getdns_list_destroy(repeat_list);
repeat_list = NULL; repeat_list = NULL;
} }
if (_getdns_dict_set_this_dict(rr_dict, "rdata", rdata_dict)) 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; goto error;
} }
} }
if (getdns_dict_set_list(result, "answer", if (!_getdns_dict_set_this_list(result, "answer",
sections[GLDNS_SECTION_ANSWER]) || sections[GLDNS_SECTION_ANSWER]))
sections[GLDNS_SECTION_ANSWER] = NULL;
else goto error;
getdns_dict_set_list(result, "authority", if (!_getdns_dict_set_this_list(result, "authority",
sections[GLDNS_SECTION_AUTHORITY]) || sections[GLDNS_SECTION_AUTHORITY]))
sections[GLDNS_SECTION_AUTHORITY] = NULL;
else goto error;
getdns_dict_set_list(result, "additional", if (!_getdns_dict_set_this_list(result, "additional",
sections[GLDNS_SECTION_ADDITIONAL])) { sections[GLDNS_SECTION_ADDITIONAL]))
sections[GLDNS_SECTION_ADDITIONAL] = NULL;
goto error; else goto error;
}
/* other stuff /* other stuff
* Note that spec doesn't explicitely mention these. * 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)) _getdns_list_append_int(bad_dns, GETDNS_BAD_DNS_ALL_NUMERIC_LABEL))
goto error; 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; goto error;
else bad_dns = NULL;
goto success; goto success;
error: error:
@ -976,23 +979,26 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
if (_getdns_list_append_bindata(replies_full, &full_data)) if (_getdns_list_append_bindata(replies_full, &full_data))
goto error; 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; goto error;
getdns_list_destroy(replies_tree); replies_tree = NULL;
if (call_reporting && if (call_reporting) {
getdns_dict_set_list(result, "call_reporting", call_reporting)) if (_getdns_dict_set_this_list(
goto error_free_call_reporting; result, "call_reporting", call_reporting))
goto error_free_call_reporting;
if (getdns_dict_set_list(result, "replies_full", replies_full)) call_reporting = NULL;
}
if (_getdns_dict_set_this_list(result, "replies_full", replies_full))
goto error_free_replies_full; goto error_free_replies_full;
getdns_list_destroy(replies_full); replies_full = NULL;
if (just_addrs && getdns_dict_set_list(
result, GETDNS_STR_KEY_JUST_ADDRS, just_addrs))
goto error_free_result;
getdns_list_destroy(just_addrs);
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, if (getdns_dict_set_int(result, GETDNS_STR_KEY_STATUS,
nreplies == 0 ? GETDNS_RESPSTATUS_ALL_TIMEOUT : nreplies == 0 ? GETDNS_RESPSTATUS_ALL_TIMEOUT :
completed_request->dnssec_return_only_secure && nsecure == 0 && ninsecure > 0 completed_request->dnssec_return_only_secure && nsecure == 0 && ninsecure > 0