2013-08-16 15:28:21 -05:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* unit tests for getdns_dict helper routines, these should be used to
|
|
|
|
* perform regression tests, output must be unchanged from canonical output
|
|
|
|
* stored with the sources
|
|
|
|
*/
|
|
|
|
/* The MIT License (MIT)
|
|
|
|
* Copyright (c) 2013 Verisign, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "testmessages.h"
|
|
|
|
#include <getdns/getdns.h>
|
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
static void
|
2013-12-06 08:54:06 -06:00
|
|
|
print_response(struct getdns_dict * response)
|
2013-11-05 14:03:44 -06:00
|
|
|
{
|
|
|
|
char *dict_str = getdns_pretty_print_dict(response);
|
|
|
|
if (dict_str) {
|
|
|
|
fprintf(stdout, "The packet %s\n", dict_str);
|
|
|
|
free(dict_str);
|
|
|
|
}
|
2013-08-16 15:28:21 -05:00
|
|
|
}
|
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
int
|
|
|
|
main()
|
2013-08-16 15:28:21 -05:00
|
|
|
{
|
|
|
|
/* Create the DNS context for this call */
|
2013-12-06 08:54:06 -06:00
|
|
|
struct getdns_context *this_context = NULL;
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_return_t context_create_return =
|
2013-12-06 07:10:28 -06:00
|
|
|
getdns_context_create(&this_context, 1);
|
2013-11-05 14:03:44 -06:00
|
|
|
if (context_create_return != GETDNS_RETURN_GOOD) {
|
|
|
|
fprintf(stderr, "Trying to create the context failed: %d",
|
|
|
|
context_create_return);
|
|
|
|
return (GETDNS_RETURN_GENERIC_ERROR);
|
|
|
|
}
|
|
|
|
getdns_context_set_resolution_type(this_context, GETDNS_CONTEXT_STUB);
|
|
|
|
|
2013-12-06 08:54:06 -06:00
|
|
|
struct getdns_dict *response = NULL;
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_return_t ret =
|
2013-11-11 16:10:22 -06:00
|
|
|
getdns_address_sync(this_context, "www.google.com", NULL, &response);
|
2013-11-05 14:03:44 -06:00
|
|
|
|
|
|
|
if (ret != GETDNS_RETURN_GOOD || response == NULL) {
|
|
|
|
fprintf(stderr, "Address sync returned error.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2013-08-16 15:28:21 -05:00
|
|
|
}
|
2013-11-05 14:03:44 -06:00
|
|
|
print_response(response);
|
|
|
|
getdns_dict_destroy(response);
|
|
|
|
|
|
|
|
ret =
|
2013-11-11 16:10:22 -06:00
|
|
|
getdns_service_sync(this_context, "www.google.com", NULL, &response);
|
2013-11-05 14:03:44 -06:00
|
|
|
if (ret != GETDNS_RETURN_GOOD || response == NULL) {
|
|
|
|
fprintf(stderr, "Service sync returned error.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
print_response(response);
|
|
|
|
getdns_dict_destroy(response);
|
|
|
|
|
|
|
|
/* Clean up */
|
2013-08-16 15:28:21 -05:00
|
|
|
getdns_context_destroy(this_context);
|
|
|
|
/* Assuming we get here, leave gracefully */
|
|
|
|
exit(EXIT_SUCCESS);
|
2013-11-05 14:03:44 -06:00
|
|
|
} /* main */
|
2013-08-16 15:28:21 -05:00
|
|
|
|
|
|
|
/* example-simple-answers.c */
|