src/test/tests_dnssec.c
void
callbackfn(struct getdns_context *context,
	getdns_callback_type_t callback_type,
	struct getdns_dict *response, void *userarg,
	getdns_transaction_t transaction_id)
{
	struct getdns_list *validation_chain;
	struct getdns_list *trust_anchors;
	struct getdns_list *replies_tree;
	size_t replies_tree_length, i;
	struct getdns_dict *reply;
	struct getdns_list *answer;
	size_t answer_length;
	getdns_return_t r;

	do {
		if (callback_type == GETDNS_CALLBACK_CANCEL) {
			fprintf(stderr,
				"The callback with ID %llu was cancelled.\n",
				(long long unsigned int)transaction_id);
			break;
		} else if (callback_type != GETDNS_CALLBACK_COMPLETE) {
			fprintf(stderr,
				"The callback got a callback_type of %d.\n",
				callback_type);
			break;
		}
		r = getdns_dict_get_list(response,
			"validation_chain", &validation_chain);
		if (r != GETDNS_RETURN_GOOD) {
			fprintf(stderr,
				"Could not get \"validation_chain\" from response:"
				" %d\n", r);
			break;
		}
		r = getdns_dict_get_list(response, "replies_tree", &replies_tree);
		if (r != GETDNS_RETURN_GOOD) {
			fprintf(stderr,
				"Could not get \"replies_tree\" from response:"
				" %d\n", r);
			break;
		}
		r = getdns_list_get_length(replies_tree, &replies_tree_length);
		if (r != GETDNS_RETURN_GOOD) {
			fprintf(stderr,
				"Could not get length of the replies_tree:"
				" %d\n", r);
			break;
		}
		trust_anchors = getdns_root_trust_anchor(NULL);
		if (! trust_anchors) {
			fprintf(stderr,
				"No root trust anchor present:"
				" %d\n", r);
			break;
		}
		for (i = 0; i < replies_tree_length; i++) {
			r = getdns_list_get_dict(replies_tree, i, &reply);
			if (r != GETDNS_RETURN_GOOD) {
				fprintf(stderr,
					"Could not get \"reply\" from replies_tree:"
					" %d\n", r);
				break;
			}
			r = getdns_dict_get_list(reply, "answer", &answer);
			if (r != GETDNS_RETURN_GOOD) {
				fprintf(stderr,
					"Could not get \"answer\" from reply:"
					" %d\n", r);
				break;
			}
			r = getdns_list_get_length(answer, &answer_length);
			if (r != GETDNS_RETURN_GOOD) {
				fprintf(stderr,
					"Could not get length of answer list:"
					" %d\n", r);
				break;
			}
			if (answer_length == 0)
				continue;

			r = getdns_validate_dnssec(answer,
				validation_chain, trust_anchors);
			printf("getdns_validate_dnssec returned: %d\n", r);
		}
		getdns_list_destroy(trust_anchors);
	} while (0);
	getdns_dict_destroy(response);
}
/* Set up the callback function, which will also do the processing of the results */
Set up the callback function, which will also do the processing of the results
Set up the callback function which will also do the processing of the results
void
callbackfn(struct getdns_context *context,
	getdns_callback_type_t callback_type,
	struct getdns_dict *response, void *userarg,
	getdns_transaction_t transaction_id)
{
	struct getdns_list *validation_chain;
	struct getdns_list *trust_anchors;
	struct getdns_list *replies_tree;
	size_t replies_tree_length, i;
	struct getdns_dict *reply;
	struct getdns_list *answer;
	size_t answer_length;
	getdns_return_t r;
	do {
		if (callback_type == GETDNS_CALLBACK_CANCEL) {
			fprintf(stderr,
				"The callback with ID %llu was cancelled.\n",
				(long long unsigned int)transaction_id);
			break;
		} else if (callback_type != GETDNS_CALLBACK_COMPLETE) {
			fprintf(stderr,
				"The callback got a callback_type of %d.\n",
				callback_type);
			break;
		}
		r = getdns_dict_get_list(response,
			"validation_chain", &validation_chain);
		if (r != GETDNS_RETURN_GOOD) {
			fprintf(stderr,
				"Could not get \"validation_chain\" from response:"
				" %d\n", r);
			break;
		}
		r = getdns_dict_get_list(response, "replies_tree", &replies_tree);
		if (r != GETDNS_RETURN_GOOD) {
			fprintf(stderr,
				"Could not get \"replies_tree\" from response:"
				" %d\n", r);
			break;
		}
		r = getdns_list_get_length(replies_tree, &replies_tree_length);
		if (r != GETDNS_RETURN_GOOD) {
			fprintf(stderr,
				"Could not get length of the replies_tree:"
				" %d\n", r);
			break;
		}
		trust_anchors = getdns_root_trust_anchor(NULL);
		if (! trust_anchors) {
			fprintf(stderr,
				"No root trust anchor present:"
				" %d\n", r);
			break;
		}
		for (i = 0; i < replies_tree_length; i++) {
			r = getdns_list_get_dict(replies_tree, i, &reply);
			if (r != GETDNS_RETURN_GOOD) {
				fprintf(stderr,
					"Could not get \"reply\" from replies_tree:"
					" %d\n", r);
				break;
			}
			r = getdns_dict_get_list(reply, "answer", &answer);
			if (r != GETDNS_RETURN_GOOD) {
				fprintf(stderr,
					"Could not get \"answer\" from reply:"
					" %d\n", r);
				break;
			}
			r = getdns_list_get_length(answer, &answer_length);
			if (r != GETDNS_RETURN_GOOD) {
				fprintf(stderr,
					"Could not get length of answer list:"
					" %d\n", r);
				break;
			}
			if (answer_length == 0)
				continue;
			r = getdns_validate_dnssec(answer,
				validation_chain, trust_anchors);
			printf("getdns_validate_dnssec returned: %d\n", r);
		}
		getdns_list_destroy(trust_anchors);
	} while (0);
	getdns_dict_destroy(response);
}
void callbackfn ( struct getdns_context * context , getdns_callback_type_t callback_type , struct getdns_dict * response , void * userarg , getdns_transaction_t transaction_id ) { struct getdns_list * validation_chain ; struct getdns_list * trust_anchors ; struct getdns_list * replies_tree ; size_t replies_tree_length , i ; struct getdns_dict * reply ; struct getdns_list * answer ; size_t answer_length ; getdns_return_t r ; do { if ( callback_type == GETDNS_CALLBACK_CANCEL ) { fprintf ( stderr , " \n " , ( long long unsigned int ) transaction_id ) ; break ; } else if ( callback_type != GETDNS_CALLBACK_COMPLETE ) { fprintf ( stderr , " \n " , callback_type ) ; break ; } r = getdns_dict_get_list ( response , " " , & validation_chain ) ; if ( r != GETDNS_RETURN_GOOD ) { fprintf ( stderr , " \" \" " " \n " , r ) ; break ; } r = getdns_dict_get_list ( response , " " , & replies_tree ) ; if ( r != GETDNS_RETURN_GOOD ) { fprintf ( stderr , " \" \" " " \n " , r ) ; break ; } r = getdns_list_get_length ( replies_tree , & replies_tree_length ) ; if ( r != GETDNS_RETURN_GOOD ) { fprintf ( stderr , " " " \n " , r ) ; break ; } trust_anchors = getdns_root_trust_anchor ( NULL ) ; if ( ! trust_anchors ) { fprintf ( stderr , " " " \n " , r ) ; break ; } for ( i = 0 ; i < replies_tree_length ; i ++ ) { r = getdns_list_get_dict ( replies_tree , i , & reply ) ; if ( r != GETDNS_RETURN_GOOD ) { fprintf ( stderr , " \" \" " " \n " , r ) ; break ; } r = getdns_dict_get_list ( reply , " " , & answer ) ; if ( r != GETDNS_RETURN_GOOD ) { fprintf ( stderr , " \" \" " " \n " , r ) ; break ; } r = getdns_list_get_length ( answer , & answer_length ) ; if ( r != GETDNS_RETURN_GOOD ) { fprintf ( stderr , " " " \n " , r ) ; break ; } if ( answer_length == 0 ) continue ; r = getdns_validate_dnssec ( answer , validation_chain , trust_anchors ) ; printf ( " \n " , r ) ; } getdns_list_destroy ( trust_anchors ) ; } while ( 0 ) ; getdns_dict_destroy ( response ) ; }
Set up the callback function, which will also do the processing of the results
Set up the callback function which will also do the processing of the results