Code review changes

Commented inline on github
This commit is contained in:
Willem Toorop 2015-11-04 16:17:53 +09:00
parent 30043d2ba5
commit 3a19050413
1 changed files with 63 additions and 74 deletions

View File

@ -672,81 +672,68 @@ success:
} }
getdns_dict * getdns_dict *
_getdns_create_call_debugging_dict(getdns_context *context, _getdns_create_call_debugging_dict(
getdns_network_req *netreq, getdns_context *context, getdns_network_req *netreq)
getdns_dict *reply) { {
getdns_bindata qname;
getdns_dict *netreq_debug;
getdns_dict *address_debug = NULL;
getdns_bindata *qname = NULL; assert(netreq);
uint32_t qtype;
getdns_dict *question = NULL;
if (getdns_dict_get_dict(reply, "question", &question)) {
return NULL;
}
if (getdns_dict_get_bindata(question, "qname", &qname)) {
return NULL;
}
if (getdns_dict_get_int(question, "qtype", &qtype)) {
return NULL;
}
/* It is the responsibility of the caller to free this */ /* It is the responsibility of the caller to free this */
getdns_dict *netreq_debug = getdns_dict_create_with_context(context); if (!(netreq_debug = getdns_dict_create_with_context(context)))
if (netreq_debug == NULL) {
return NULL; return NULL;
}
getdns_dict *address_debug = getdns_dict_create_with_context(context); qname.data = netreq->owner->name;
if (address_debug == NULL){ qname.size = netreq->owner->name_len;
getdns_dict_destroy(netreq_debug);
return NULL; if (getdns_dict_set_bindata(netreq_debug, "query_name", &qname) ||
} getdns_dict_set_int( netreq_debug, "query_type"
_getdns_sockaddr_to_dict(context, &netreq->upstream->addr, &address_debug); , netreq->request_type ) ||
/* Safe, because uint32_t facilitates RRT's of almost 50 days*/
getdns_dict_set_int(netreq_debug, "run_time/ms",
(uint32_t)(( netreq->debug_end_time
- netreq->debug_start_time)/1000))) {
if (getdns_dict_set_bindata(netreq_debug, "query_name", qname)) {
getdns_dict_destroy(netreq_debug); getdns_dict_destroy(netreq_debug);
getdns_dict_destroy(address_debug);
return NULL; return NULL;
}
if (getdns_dict_set_int(netreq_debug, "query_type", qtype)) { } else if (!netreq->upstream)
getdns_dict_destroy(netreq_debug);
/* Nothing more for full recursion */
return netreq_debug;
/* Stub resolver debug data */
_getdns_sockaddr_to_dict(
context, &netreq->upstream->addr, &address_debug);
if (getdns_dict_set_dict(netreq_debug, "query_to", address_debug) ||
getdns_dict_set_int( netreq_debug, "transport"
, netreq->upstream->transport)) {
getdns_dict_destroy(address_debug); getdns_dict_destroy(address_debug);
return NULL;
}
if (getdns_dict_set_dict(netreq_debug, "query_to", address_debug)) {
getdns_dict_destroy(netreq_debug); getdns_dict_destroy(netreq_debug);
getdns_dict_destroy(address_debug);
return NULL; return NULL;
} }
getdns_dict_destroy(address_debug); getdns_dict_destroy(address_debug);
if (getdns_dict_set_int(netreq_debug, "transport", if (netreq->upstream->transport != GETDNS_TRANSPORT_TLS)
netreq->upstream->transport)) { return netreq_debug;
getdns_dict_destroy(netreq_debug);
return NULL;
}
/* TODO: This is not safe */
uint32_t run_time = (uint32_t)(netreq->debug_end_time - netreq->debug_start_time);
if (getdns_dict_set_int(netreq_debug, "run_time/ms", run_time/1000)) {
getdns_dict_destroy(netreq_debug);
return NULL;
}
/* Only include the auth status if TLS was used */ /* Only include the auth status if TLS was used */
if (netreq->upstream->transport == GETDNS_TRANSPORT_TLS) { if (getdns_dict_util_set_string(netreq_debug, "tls_auth_status",
if (getdns_dict_util_set_string(netreq_debug, "tls_auth_status", netreq->debug_tls_auth_status == 0 ?
netreq->debug_tls_auth_status == 0 ? "OK: Hostname matched valid cert":"FAILED: Server not validated")){
"OK: Hostname matched valid cert." :
"FAILED: Server not validated.")) { getdns_dict_destroy(netreq_debug);
getdns_dict_destroy(netreq_debug); return NULL;
return NULL;
}
} }
return netreq_debug; return netreq_debug;
} }
getdns_dict * getdns_dict *
_getdns_create_getdns_response(getdns_dns_req *completed_request) _getdns_create_getdns_response(getdns_dns_req *completed_request)
{ {
@ -754,13 +741,14 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
getdns_list *just_addrs = NULL; getdns_list *just_addrs = NULL;
getdns_list *replies_full; getdns_list *replies_full;
getdns_list *replies_tree; getdns_list *replies_tree;
getdns_list *call_debugging; getdns_list *call_debugging = NULL;
getdns_network_req *netreq, **netreq_p; getdns_network_req *netreq, **netreq_p;
int rrsigs_in_answer = 0; int rrsigs_in_answer = 0;
getdns_dict *reply; getdns_dict *reply;
getdns_bindata *canonical_name = NULL; getdns_bindata *canonical_name = NULL;
int nreplies = 0, nanswers = 0, nsecure = 0, ninsecure = 0, nbogus = 0; int nreplies = 0, nanswers = 0, nsecure = 0, ninsecure = 0, nbogus = 0;
getdns_bindata full_data; getdns_bindata full_data;
getdns_dict *netreq_debug;
/* info (bools) about dns_req */ /* info (bools) about dns_req */
int dnssec_return_status; int dnssec_return_status;
@ -790,10 +778,9 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
if (!(replies_tree = getdns_list_create_with_context(context))) if (!(replies_tree = getdns_list_create_with_context(context)))
goto error_free_replies_full; goto error_free_replies_full;
if (completed_request->return_call_debugging) { if (completed_request->return_call_debugging &&
if (!(call_debugging = getdns_list_create_with_context(context))) !(call_debugging = getdns_list_create_with_context(context)))
goto error_free_result; goto error_free_replies_full;
}
for ( netreq_p = completed_request->netreqs for ( netreq_p = completed_request->netreqs
; (netreq = *netreq_p) ; netreq_p++) { ; (netreq = *netreq_p) ; netreq_p++) {
@ -852,13 +839,17 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
goto error; goto error;
} }
if (completed_request->return_call_debugging) { if (call_debugging) {
getdns_dict *netreq_debug; if (!(netreq_debug =
if (!(netreq_debug = _getdns_create_call_debugging_dict(context, _getdns_create_call_debugging_dict(context,netreq)))
netreq, reply))) { goto error;
if (_getdns_list_append_dict(
call_debugging, netreq_debug)) {
getdns_dict_destroy(netreq_debug);
goto error; goto error;
} }
_getdns_list_append_dict(call_debugging, netreq_debug);
getdns_dict_destroy(netreq_debug); getdns_dict_destroy(netreq_debug);
} }
@ -874,15 +865,14 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
goto error; goto error;
getdns_list_destroy(replies_tree); getdns_list_destroy(replies_tree);
if (call_debugging &&
getdns_dict_set_list(result, "call_debugging", call_debugging))
goto error_free_call_debugging;
if (getdns_dict_set_list(result, "replies_full", replies_full)) if (getdns_dict_set_list(result, "replies_full", replies_full))
goto error_free_replies_full; goto error_free_replies_full;
getdns_list_destroy(replies_full); getdns_list_destroy(replies_full);
if (completed_request->return_call_debugging) {
if (getdns_dict_set_list(result, "call_debugging", call_debugging))
goto error_free_call_debugging;
}
if (just_addrs && getdns_dict_set_list( if (just_addrs && getdns_dict_set_list(
result, GETDNS_STR_KEY_JUST_ADDRS, just_addrs)) result, GETDNS_STR_KEY_JUST_ADDRS, just_addrs))
goto error_free_result; goto error_free_result;
@ -902,11 +892,10 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
error: error:
/* cleanup */ /* cleanup */
getdns_list_destroy(replies_tree); getdns_list_destroy(replies_tree);
error_free_call_debugging:
getdns_list_destroy(call_debugging);
error_free_replies_full: error_free_replies_full:
getdns_list_destroy(replies_full); getdns_list_destroy(replies_full);
error_free_call_debugging:
if (completed_request->return_call_debugging)
getdns_list_destroy(call_debugging);
error_free_result: error_free_result:
getdns_list_destroy(just_addrs); getdns_list_destroy(just_addrs);
getdns_dict_destroy(result); getdns_dict_destroy(result);