Merge branch 'develop' of github.com:verisign/getdns into develop

This commit is contained in:
Neel Goyal 2013-11-05 13:31:44 -05:00
commit eb14f1212d
26 changed files with 4802 additions and 253 deletions

481
CodingStyle Normal file
View File

@ -0,0 +1,481 @@
/* $NetBSD: style,v 1.51 2013/03/08 16:50:02 christos Exp $ */
/*
* The revision control tag appears first, with a blank line after it.
* Copyright text appears after the revision control tag.
*/
/*
* The NetBSD source code style guide.
* (Previously known as KNF - Kernel Normal Form).
*
* from: @(#)style 1.12 (Berkeley) 3/18/94
*/
/*
* An indent(1) profile approximating the style outlined in
* this document lives in /usr/share/misc/indent.pro. It is a
* useful tool to assist in converting code to KNF, but indent(1)
* output generated using this profile must not be considered to
* be an authoritative reference.
*/
/*
* Source code revision control identifiers appear after any copyright
* text. Use the appropriate macros from <sys/cdefs.h>. Usually only one
* source file per program contains a __COPYRIGHT() section.
* Historic Berkeley code may also have an __SCCSID() section.
* Only one instance of each of these macros can occur in each file.
* Don't use newlines in the identifiers.
*/
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: style,v 1.51 2013/03/08 16:50:02 christos Exp $");
/*
* VERY important single-line comments look like this.
*/
/* Most single-line comments look like this. */
/*
* Multi-line comments look like this. Make them real sentences. Fill
* them so they look like real paragraphs.
*/
/*
* Attempt to wrap lines longer than 80 characters appropriately.
* Refer to the examples below for more information.
*/
/*
* EXAMPLE HEADER FILE:
*
* A header file should protect itself against multiple inclusion.
* E.g, <sys/socket.h> would contain something like:
*/
#ifndef _SYS_SOCKET_H_
#define _SYS_SOCKET_H_
/*
* Contents of #include file go between the #ifndef and the #endif at the end.
*/
#endif /* !_SYS_SOCKET_H_ */
/*
* END OF EXAMPLE HEADER FILE.
*/
/*
* If a header file requires structures, defines, typedefs, etc. from
* another header file it should include that header file and not depend
* on the including file for that header including both. If there are
* exceptions to this for specific headers it should be clearly documented
* in the headers and, if appropriate, the documentation. Nothing in this
* rule should suggest relaxation of the multiple inclusion rule and the
* application programmer should be free to include both regardless.
*/
/*
* Kernel include files come first.
*/
#include <sys/param.h> /* <sys/param.h> first, */
#include <sys/types.h> /* <sys/types.h> next, */
#include <sys/ioctl.h> /* and then the rest, */
#include <sys/socket.h> /* sorted lexicographically. */
#include <sys/stat.h>
#include <sys/wait.h> /* Non-local includes in brackets. */
/*
* If it's a network program, put the network include files next.
* Group the includes files by subdirectory.
*/
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <netinet/in.h>
#include <protocols/rwhod.h>
/*
* Then there's a blank line, followed by the /usr include files.
* The /usr include files should be sorted lexicographically!
*/
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
/*
* Global pathnames are defined in /usr/include/paths.h. Pathnames local
* to the program go in pathnames.h in the local directory.
*/
#include <paths.h>
/* Then, there's a blank line, and the user include files. */
#include "pathnames.h" /* Local includes in double quotes. */
/*
* ANSI function declarations for private functions (i.e. functions not used
* elsewhere) and the main() function go at the top of the source module.
* Don't associate a name with the types. I.e. use:
* void function(int);
* Use your discretion on indenting between the return type and the name, and
* how to wrap a prototype too long for a single line. In the latter case,
* lining up under the initial left parenthesis may be more readable.
* In any case, consistency is important!
*/
static char *function(int, int, float, int);
static int dirinfo(const char *, struct stat *, struct dirent *,
struct statfs *, int *, char **[]);
static void usage(void) __dead; /* declare functions that don't return dead */
/*
* Macros are capitalized, parenthesized, and should avoid side-effects.
* Spacing before and after the macro name may be any whitespace, though
* use of TABs should be consistent through a file.
* If they are an inline expansion of a function, the function is defined
* all in lowercase, the macro has the same name all in uppercase.
* If the macro is an expression, wrap the expression in parenthesis.
* If the macro is more than a single statement, use ``do { ... } while (0)'',
* so that a trailing semicolon works. Right-justify the backslashes; it
* makes it easier to read. The CONSTCOND comment is to satisfy lint(1).
*/
#define MACRO(v, w, x, y) \
do { \
v = (x) + (y); \
w = (y) + 2; \
} while (/* CONSTCOND */ 0)
#define DOUBLE(x) ((x) * 2)
/* Enum types are capitalized. No comma on the last element. */
enum enumtype {
ONE,
TWO
} et;
/*
* When declaring variables in structures, declare them organized by use in
* a manner to attempt to minimize memory wastage because of compiler alignment
* issues, then by size, and then by alphabetical order. E.g, don't use
* ``int a; char *b; int c; char *d''; use ``int a; int b; char *c; char *d''.
* Each variable gets its own type and line, although an exception can be made
* when declaring bitfields (to clarify that it's part of the one bitfield).
* Note that the use of bitfields in general is discouraged.
*
* Major structures should be declared at the top of the file in which they
* are used, or in separate header files, if they are used in multiple
* source files. Use of the structures should be by separate declarations
* and should be "extern" if they are declared in a header file.
*
* It may be useful to use a meaningful prefix for each member name.
* E.g, for ``struct softc'' the prefix could be ``sc_''.
*/
struct foo {
struct foo *next; /* List of active foo */
struct mumble amumble; /* Comment for mumble */
int bar;
unsigned int baz:1, /* Bitfield; line up entries if desired */
fuz:5,
zap:2;
uint8_t flag;
};
struct foo *foohead; /* Head of global foo list */
/* Make the structure name match the typedef. */
typedef struct BAR {
int level;
} BAR;
/* C99 uintN_t is preferred over u_intN_t. */
uint32_t zero;
/*
* All major routines should have a comment briefly describing what
* they do. The comment before the "main" routine should describe
* what the program does.
*/
int
main(int argc, char *argv[])
{
long num;
int ch;
char *ep;
/*
* At the start of main(), call setprogname() to set the program
* name. This does nothing on NetBSD, but increases portability
* to other systems.
*/
setprogname(argv[0]);
/*
* For consistency, getopt should be used to parse options.
* Options should be sorted in the getopt call and the switch
* statement, unless parts of the switch cascade. For the
* sorting order, see the usage() example below. Don't forget
* to add option descriptions to the usage and the manpage.
* Elements in a switch statement that cascade should have a
* FALLTHROUGH comment. Numerical arguments should be checked
* for accuracy. Code that cannot be reached should have a
* NOTREACHED comment.
*/
while ((ch = getopt(argc, argv, "abn:")) != -1) {
switch (ch) { /* Indent the switch. */
case 'a': /* Don't indent the case. */
aflag = 1;
/* FALLTHROUGH */
case 'b':
bflag = 1;
break;
case 'n':
errno = 0;
num = strtol(optarg, &ep, 10);
if (num <= 0 || *ep != '\0' || (errno == ERANGE &&
(num == LONG_MAX || num == LONG_MIN)) )
errx(1, "illegal number -- %s", optarg);
break;
case '?':
default:
usage();
/* NOTREACHED */
}
}
argc -= optind;
argv += optind;
/*
* Space after keywords (while, for, return, switch). No braces are
* required for control statements with only a single statement,
* unless it's a long statement.
*
* Forever loops are done with for's, not while's.
*/
for (p = buf; *p != '\0'; ++p)
continue; /* Explicit no-op */
for (;;)
stmt;
/*
* Braces are required for control statements with a single statement
* that may expand to nothing.
*/
#ifdef DEBUG_FOO
#define DPRINTF(a) printf a
#else
#define DPRINTF(a)
#endif
if (broken) {
DPRINTF(("broken is %d\n", broken));
}
/*
* Parts of a for loop may be left empty. Don't put declarations
* inside blocks unless the routine is unusually complicated.
*/
for (; cnt < 15; cnt++) {
stmt1;
stmt2;
}
/* Second level indents are four spaces. */
while (cnt < 20)
z = a + really + long + statement + that + needs + two + lines +
gets + indented + four + spaces + on + the + second +
and + subsequent + lines;
/*
* Closing and opening braces go on the same line as the else.
* Don't add braces that aren't necessary except in cases where
* there are ambiguity or readability issues.
*/
if (test) {
/*
* I have a long comment here.
*/
#ifdef zorro
z = 1;
#else
b = 3;
#endif
} else if (bar) {
stmt;
stmt;
} else
stmt;
/* No spaces after function names. */
if ((result = function(a1, a2, a3, a4)) == NULL)
exit(1);
/*
* Unary operators don't require spaces, binary operators do.
* Don't excessively use parenthesis, but they should be used if
* statement is really confusing without them, such as:
* a = b->c[0] + ~d == (e || f) || g && h ? i : j >> 1;
*/
a = ((b->c[0] + ~d == (e || f)) || (g && h)) ? i : (j >> 1);
k = !(l & FLAGS);
/*
* Exits should be EXIT_SUCCESS on success, and EXIT_FAILURE on
* failure. Don't denote all the possible exit points, using the
* integers 1 through 127. Avoid obvious comments such as "Exit
* 0 on success.". Since main is a function that returns an int,
* prefer returning from it, than calling exit.
*/
return EXIT_SUCCESS;
}
/*
* The function type must be declared on a line by itself
* preceding the function.
*/
static char *
function(int a1, int a2, float fl, int a4)
{
/*
* When declaring variables in functions declare them sorted by size,
* then in alphabetical order; multiple ones per line are okay.
* Function prototypes should go in the include file "extern.h".
* If a line overflows reuse the type keyword.
*
* DO NOT initialize variables in the declarations.
*/
extern u_char one;
extern char two;
struct foo three, *four;
double five;
int *six, seven;
char *eight, *nine, ten, eleven, twelve, thirteen;
char fourteen, fifteen, sixteen;
/*
* Casts and sizeof's are not followed by a space. NULL is any
* pointer type, and doesn't need to be cast, so use NULL instead
* of (struct foo *)0 or (struct foo *)NULL. Also, test pointers
* against NULL. I.e. use:
*
* (p = f()) == NULL
* not:
* !(p = f())
*
* The notable exception here is variadic functions. Since our
* code is designed to compile and work on different environments
* where we don't have control over the NULL definition (on NetBSD
* it is defined as ((void *)0), but on other systems it can be
* defined as (0) and both definitions are valid under ANSI C), it
* it advised to cast NULL to a pointer on varyadic functions,
* because on machines where sizeof(pointer) != sizeof(int) and in
* the absence of a prototype in scope, passing an un-casted NULL,
* will result in passing an int on the stack instead of a pointer.
*
* Don't use `!' for tests unless it's a boolean.
* E.g. use "if (*p == '\0')", not "if (!*p)".
*
* Routines returning ``void *'' should not have their return
* values cast to more specific pointer types.
*
* Prefer sizeof(*var) over sizeof(type) because if type changes,
* the change needs to be done in one place.
*
* Use err/warn(3), don't roll your own!
*/
if ((four = malloc(sizeof(*four))) == NULL)
err(1, NULL);
if ((six = (int *)overflow()) == NULL)
errx(1, "Number overflowed.");
/* No parentheses are needed around the return value. */
return eight;
}
/*
* Use ANSI function declarations. ANSI function braces look like
* old-style (K&R) function braces.
* As per the wrapped prototypes, use your discretion on how to format
* the subsequent lines.
*/
static int
dirinfo(const char *p, struct stat *sb, struct dirent *de, struct statfs *sf,
int *rargc, char **rargv[])
{ /* Insert an empty line if the function has no local variables. */
/*
* In system libraries, catch obviously invalid function arguments
* using _DIAGASSERT(3).
*/
_DIAGASSERT(p != NULL);
_DIAGASSERT(filedesc != -1);
if (stat(p, sb) < 0)
err(1, "Unable to stat %s", p);
/*
* To printf quantities that might be larger that "long", include
* <inttypes.h>, cast quantities to intmax_t or uintmax_t and use
* PRI?MAX constants.
*/
(void)printf("The size of %s is %" PRIdMAX " (%#" PRIxMAX ")\n", p,
(intmax_t)sb->st_size, (uintmax_t)sb->st_size);
/*
* To printf quantities of known bit-width, use the corresponding
* defines (generally only done within NetBSD for quantities that
* exceed 32-bits).
*/
(void)printf("%s uses %" PRId64 " blocks and has flags %#" PRIx32 "\n",
p, sb->st_blocks, sb->st_flags);
/*
* There are similar constants that should be used with the *scanf(3)
* family of functions: SCN?MAX, SCN?64, etc.
*/
}
/*
* Functions that support variable numbers of arguments should look like this.
* (With the #include <stdarg.h> appearing at the top of the file with the
* other include files.)
*/
#include <stdarg.h>
void
vaf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
STUFF;
va_end(ap);
/* No return needed for void functions. */
}
static void
usage(void)
{
/*
* Use printf(3), not fputs/puts/putchar/whatever, it's faster and
* usually cleaner, not to mention avoiding stupid bugs.
* Use snprintf(3) or strlcpy(3)/strlcat(3) instead of sprintf(3);
* again to avoid stupid bugs.
*
* Usage statements should look like the manual pages.
* Options w/o operands come first, in alphabetical order
* inside a single set of braces, upper case before lower case
* (AaBbCc...). Next are options with operands, in the same
* order, each in braces. Then required arguments in the
* order they are specified, followed by optional arguments in
* the order they are specified. A bar (`|') separates
* either/or options/arguments, and multiple options/arguments
* which are specified together are placed in a single set of
* braces.
*
* Use getprogname() instead of hardcoding the program name.
*
* "usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\n"
* "usage: f [-a | -b] [-c [-de] [-n number]]\n"
*/
(void)fprintf(stderr, "usage: %s [-ab]\n", getprogname());
exit(EXIT_FAILURE);
}

View File

@ -6,7 +6,7 @@
#
AC_PREREQ([2.68])
AC_INIT([getdns], [0.320], [melinda.shore@nomountain.net])
AC_INIT([getdns], [0.1.0], [melinda.shore@nomountain.net])
AC_CONFIG_SRCDIR([src/getdns/getdns.h])
# AM_INIT_AUTOMAKE
# LT_INIT
@ -60,10 +60,10 @@ AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_CONFIG_FILES([Makefile src/Makefile src/getdns/Makefile src/example/Makefile src/test/Makefile])
AC_CONFIG_FILES([Makefile src/Makefile src/getdns/Makefile src/example/Makefile src/test/Makefile doc/Makefile])
if [ test -n "$DOXYGEN" ]
then AC_CONFIG_FILES([src/Doxyfile])
fi
AC_CONFIG_SUBDIRS([src/ src/getdns/ src/example/ src/test/])
AC_CONFIG_SUBDIRS([src/ src/getdns/ src/example/ src/test/ doc/])
AC_OUTPUT

46
doc/getdns_address.3.in Normal file
View File

@ -0,0 +1,46 @@
.TH libgetdns 3 "November 2013" "getdns 0.0.0" getdns
.SH NAME
getdns_address
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
.SH SYNOPSIS
#include <getdns.h>
getdns_return_t
.br
.B getdns_address
(getdns_context_t context, const char *name, struct getdns_dict *extensions, void *userarg, getdns_transaction_t *transaction_id, getdns_callback_t callbackfn);
.SH DESCRIPTION
.LP
THIS IS A WORK IN PROGRESS - MUCH TO ADD
.LP
The getdns_address(3) and getdns_address_sync functions provide public entry points into the getdns API library to retrieve the address given a host name. It always returns both IPv4 and IPv6 addresses.
.SH FILES
.br
/etc/hosts
.br
/etc/resolv.conf
.SH EXAMPLES
TBD
.SH DIAGNOSTICS
TBD
.SH SEE ALSO
.BR libgetdns (3),
.BR getdns_address_sync (3),
.BR getdns_general (3),
.BR getdns_general_sync (3),
.BR getdns_hostname (3),
.BR getdns_hostname_sync (3),
.BR getdns_service (3),
.BR getdns_service_sync (3).

70
doc/libgetdns.3.in Normal file
View File

@ -0,0 +1,70 @@
.TH libgetdns 3 "November 2013" "getdns 0.0.0" getdns
.SH NAME
libgetdns
.Sh LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
.SH SYNOPSIS
.Lb libgetdns
#include <getdns.h>
THe public entry points are captured in separate man pages.
.SH DESCRIPTION
.LP
THIS IS A WORK IN PROGRESS - LOTS TO ADD
.LP
This document describes a modern asynchronous DNS API. This new API is intended to be useful to application developers and operating system distributors as a way of making all types of DNS information easily available in many types of programs. The major features of this new API are:
.RS 3
Full support for event-driven programming
Supports DNSSEC in multiple ways
Mirroring of the resolution in getaddrinfo()
Easily supports all RRtypes, even those yet to be defined
.RE
.LP
This implementation of the getdns API is licensed under the BSD license.
.SH FILES
.br /etc/hosts
.br /etc/resolv.conf
.SH EXAMPLES
TBD
.SH DIAGNOSTICS
TBD
.SH "SEE ALSO"
.BR getdns_address (3),
.BR getdns_address_sync (3),
.BR getdns_general (3),
.BR getdns_general_sync (3),
.BR getdns_hostname (3),
.BR getdns_hostname_sync (3),
.BR getdns_service (3),
.BR getdns_service_sync (3).
.SH REPORTING PROBLEMS
Bug reports should be sent to the getdns-bugs@getdns.net
.SH AUTHORS
The getdns API was documented by Paul Hoffman. This implementation of the getdns API was written by:
.LP
.RS 3
.br
Neel Goyal, Verisign Inc.
.br
Melinda Shore, No Mountain Software, LLC
.br
Willem Toorop, NLNet Labs
.br
Wouter Wijngaards, NLNet Labs
.br
Glen Wiley, Verisign Inc.
.RE

View File

@ -0,0 +1,297 @@
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <getdns_libevent.h>
#define UNUSED_PARAM(x) ((void)(x))
/* The return values */
getdns_return_t retregular;
char * retcharstar;
/* The args */
bool boolarg;
char * charstararg;
getdns_callback_t callbackarg;
uint16_t regulararg;
uint16_t *regularptrarg;
getdns_transaction_t txidarg;
getdns_transaction_t * txidptrarg;
getdns_data_type * datatypeptrarg;
struct getdns_bindata ** bindataptrarg;
struct getdns_dict * dictarg;
struct getdns_bindata * bindataarg;
struct getdns_list * listarg;
struct getdns_dict ** dictptrarg;
struct getdns_list ** listptrarg;
size_t sizetarg;
size_t * sizetptrarg;
getdns_context_t contextarg = NULL;
uint8_t uint8arg;
uint16_t uint16arg;
uint32_t uint32arg;
uint8_t * uint8ptrarg;
uint16_t * uint16ptrarg;
uint32_t * uint32ptrarg;
void * arrayarg;
void allocfunctionarg(size_t foo) {UNUSED_PARAM(foo);}
void deallocfunctionarg(void* foo) {UNUSED_PARAM(foo);}
void setcallbackfunctionarg(struct getdns_context_t *foo1, uint16_t foo2)
{UNUSED_PARAM(foo1);UNUSED_PARAM(foo2);}
int main()
{
retregular = getdns_general(
contextarg,
charstararg,
uint16arg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_address(
contextarg,
charstararg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_hostname(
contextarg,
dictarg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_service(
contextarg,
charstararg,
dictarg,
arrayarg,
txidptrarg,
callbackarg
);
retregular = getdns_context_create(
&contextarg,
boolarg
);
getdns_context_destroy(
contextarg
);
retregular = getdns_cancel_callback(
contextarg,
txidarg
);
retregular = getdns_general_sync(
contextarg,
charstararg,
uint16arg,
dictarg,
uint32ptrarg,
dictarg
);
retregular = getdns_address_sync(
contextarg,
charstararg,
dictarg,
uint32ptrarg,
dictarg
);
retregular = getdns_hostname_sync(
contextarg,
dictarg,
dictarg,
uint32ptrarg,
dictarg
);
retregular = getdns_service_sync(
contextarg,
charstararg,
dictarg,
uint32ptrarg,
dictarg
);
getdns_free_sync_request_memory(
dictarg
);
retregular = getdns_list_get_length(listarg, sizetptrarg);
retregular = getdns_list_get_data_type(listarg, sizetarg, datatypeptrarg);
retregular = getdns_list_get_dict(listarg, sizetarg, dictptrarg);
retregular = getdns_list_get_list(listarg, sizetarg, listptrarg);
retregular = getdns_list_get_bindata(listarg, sizetarg, bindataptrarg);
retregular = getdns_list_get_int(listarg, sizetarg, uint32ptrarg);
retregular = getdns_dict_get_names(dictarg, listptrarg);
retregular = getdns_dict_get_data_type(dictarg, charstararg, datatypeptrarg);
retregular = getdns_dict_get_dict(dictarg, charstararg, dictptrarg);
retregular = getdns_dict_get_list(dictarg, charstararg, listptrarg);
retregular = getdns_dict_get_bindata(dictarg, charstararg, bindataptrarg);
retregular = getdns_dict_get_int(dictarg, charstararg, uint32ptrarg);
listarg = getdns_list_create();
getdns_list_destroy(listarg);
retregular = getdns_list_set_dict(listarg, sizetarg, dictarg);
retregular = getdns_list_set_list(listarg, sizetarg, listarg);
retregular = getdns_list_set_bindata(listarg, sizetarg, bindataarg);
retregular = getdns_list_set_int(listarg, sizetarg, uint32arg);
dictarg = getdns_dict_create();
getdns_dict_destroy(dictarg);
retregular = getdns_dict_set_dict(dictarg, charstararg, dictarg);
retregular = getdns_dict_set_list(dictarg, charstararg, listarg);
retregular = getdns_dict_set_bindata(dictarg, charstararg, bindataarg);
retregular = getdns_dict_set_int(dictarg, charstararg, uint32arg);
retcharstar = getdns_convert_fqdn_to_dns_name(
charstararg
);
retcharstar = getdns_convert_dns_name_to_fqdn(
charstararg
);
retcharstar = getdns_convert_ulabel_to_alabel(
charstararg
);
retcharstar = getdns_convert_alabel_to_ulabel(
charstararg
);
retregular = getdns_validate_dnssec(
bindataarg,
listarg,
listarg
);
retcharstar = getdns_pretty_print_dict(
dictarg
);
retcharstar = getdns_display_ip_address(
bindataarg
);
retregular = getdns_context_set_context_update_callback(
contextarg,
setcallbackfunctionarg
);
retregular = getdns_context_set_resolution_type(
contextarg,
regulararg
);
retregular = getdns_context_set_namespaces(
contextarg,
sizetarg,
regularptrarg
);
retregular = getdns_context_set_dns_transport(
contextarg,
regulararg
);
retregular = getdns_context_set_limit_outstanding_queries(
contextarg,
uint16arg
);
retregular = getdns_context_set_timeout(
contextarg,
uint16arg
);
retregular = getdns_context_set_follow_redirects(
contextarg,
regulararg
);
retregular = getdns_context_set_dns_root_servers(
contextarg,
listarg
);
retregular = getdns_context_set_append_name(
contextarg,
regulararg
);
retregular = getdns_context_set_suffix(
contextarg,
listarg
);
retregular = getdns_context_set_dnssec_trust_anchors(
contextarg,
listarg
);
retregular = getdns_context_set_dnssec_allowed_skew(
contextarg,
uint16arg
);
retregular = getdns_context_set_stub_resolution(
contextarg,
listarg
);
retregular = getdns_context_set_edns_maximum_udp_payload_size(
contextarg,
uint16arg
);
retregular = getdns_context_set_edns_extended_rcode(
contextarg,
uint8arg
);
retregular = getdns_context_set_edns_version(
contextarg,
uint8arg
);
retregular = getdns_context_set_edns_do_bit(
contextarg,
uint8arg
);
retregular = getdns_context_set_memory_allocator(
contextarg,
allocfunctionarg
);
retregular = getdns_context_set_memory_deallocator(
contextarg,
deallocfunctionarg
);
retregular = getdns_context_set_memory_reallocator(
contextarg,
deallocfunctionarg
);
return(0); } /* End of main() */

View File

@ -0,0 +1,99 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_libevent.h>
#define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */
void this_callbackfn(struct getdns_context_t *this_context,
uint16_t this_callback_type,
struct getdns_dict *this_response,
void *this_userarg,
getdns_transaction_t this_transaction_id)
{
UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */
UNUSED_PARAM(this_context); /* Not looking at the context for this example */
getdns_return_t this_ret; /* Holder for all function returns */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */
{
/* Be sure the search returned something */
uint32_t * this_error = NULL;
this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error
if (*this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error);
return;
}
struct getdns_list * just_the_addresses_ptr;
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr);
if (this_ret != GETDNS_RETURN_GOOD) // This check is really not needed, but prevents a compiler error under "pedantic"
{
fprintf(stderr, "Trying to get the answers failed: %d", this_ret);
return;
}
size_t * num_addresses_ptr = NULL;
this_ret = getdns_list_get_length(just_the_addresses_ptr, num_addresses_ptr); // Ignore any error
/* Go through each record */
for ( size_t rec_count = 0; rec_count <= *num_addresses_ptr; ++rec_count )
{
struct getdns_dict * this_address;
this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error
/* Just print the address */
struct getdns_bindata * this_address_data;
this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error
printf("The address is %s", getdns_display_ip_address(this_address_data));
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type);
}
int main()
{
/* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
}
/* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base;
this_event_base = event_base_new();
if (this_event_base == NULL)
{
fprintf(stderr, "Trying to create the event base failed.");
return(GETDNS_RETURN_GENERIC_ERROR);
}
(void)getdns_extension_set_libevent_base(this_context, this_event_base);
/* Set up the getdns call */
const char * this_name = "www.example.com";
char* this_userarg = "somestring"; // Could add things here to help identify this call
getdns_transaction_t this_transaction_id = 0;
/* Make the call */
getdns_return_t dns_request_return = getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
/* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return);
// TODO: check the return value above
}
/* Clean up */
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
}

View File

@ -0,0 +1,71 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_core_only.h>
int main()
{
getdns_return_t this_ret; /* Holder for all function returns */
/* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
}
/* Set up the getdns_sync_request call */
const char * this_name = "www.example.com";
uint8_t this_request_type = GETDNS_RRTYPE_A;
/* Get the A and AAAA records */
struct getdns_dict * this_extensions = getdns_dict_create();
this_ret = getdns_dict_set_int(this_extensions, "return_both_v4_and_v6", GETDNS_EXTENSION_TRUE);
if (this_ret != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to set an extension do both IPv4 and IPv6 failed: %d", this_ret);
return(GETDNS_RETURN_GENERIC_ERROR);
}
uint32_t this_response_length;
struct getdns_dict * this_response = NULL;
/* Make the call */
getdns_return_t dns_request_return = getdns_general_sync(this_context, this_name, this_request_type,
this_extensions, &this_response_length, this_response);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
/* Be sure the search returned something */
uint32_t * this_error = NULL;
this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error
if (*this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error);
return(GETDNS_RETURN_GENERIC_ERROR);
}
struct getdns_list * just_the_addresses_ptr;
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr); // Ignore any error
size_t * num_addresses_ptr = NULL;
this_ret = getdns_list_get_length(just_the_addresses_ptr, num_addresses_ptr); // Ignore any error
/* Go through each record */
for ( size_t rec_count = 0; rec_count <= *num_addresses_ptr; ++rec_count )
{
struct getdns_dict * this_address;
this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error
/* Just print the address */
struct getdns_bindata * this_address_data;
this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error
printf("The address is %s", getdns_display_ip_address(this_address_data));
}
}
/* Clean up */
getdns_context_destroy(this_context);
getdns_free_sync_request_memory(this_response);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
}

138
spec/example-tree.c Normal file
View File

@ -0,0 +1,138 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <getdns_libevent.h>
#define UNUSED_PARAM(x) ((void)(x))
/* Set up the callback function, which will also do the processing of the results */
void this_callbackfn(struct getdns_context_t *this_context,
getdns_return_t this_callback_type,
struct getdns_dict *this_response,
void *this_userarg,
getdns_transaction_t this_transaction_id)
{
UNUSED_PARAM(this_userarg); /* Not looking at the userarg for this example */
UNUSED_PARAM(this_context); /* Not looking at the context for this example */
getdns_return_t this_ret; /* Holder for all function returns */
if (this_callback_type == GETDNS_CALLBACK_COMPLETE) /* This is a callback with data */
{
/* Be sure the search returned something */
uint32_t * this_error = NULL;
this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error
if (*this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
{
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error);
return;
}
/* Find all the answers returned */
struct getdns_list * these_answers;
this_ret = getdns_dict_get_list(this_response, "replies-tree", &these_answers);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME)
{
fprintf(stderr, "Weird: the response had no error, but also no replies-tree. Exiting.");
return;
}
size_t * num_answers_ptr = NULL;
this_ret = getdns_list_get_length(these_answers, num_answers_ptr);
/* Go through each answer */
for ( size_t rec_count = 0; rec_count <= *num_answers_ptr; ++rec_count )
{
struct getdns_dict * this_record;
this_ret = getdns_list_get_dict(these_answers, rec_count, &this_record); // Ignore any error
/* Get the answer section */
struct getdns_list * this_answer;
this_ret = getdns_dict_get_list(this_record, "answer", &this_answer); // Ignore any error
/* Get each RR in the answer section */
size_t * num_rrs_ptr = NULL;
this_ret = getdns_list_get_length(this_answer, num_rrs_ptr);
for ( size_t rr_count = 0; rr_count <= *num_rrs_ptr; ++rr_count )
{
struct getdns_dict * this_rr = NULL;
this_ret = getdns_list_get_dict(this_answer, rr_count, &this_rr); // Ignore any error
/* Get the RDATA */
struct getdns_dict * this_rdata = NULL;
this_ret = getdns_dict_get_dict(this_rr, "rdata", &this_rdata); // Ignore any error
/* Get the RDATA type */
uint32_t * this_type = NULL;
this_ret = getdns_dict_get_int(this_rdata, "type", this_type); // Ignore any error
/* If it is type A or AAAA, print the value */
if (*this_type == GETDNS_RRTYPE_A)
{
struct getdns_bindata * this_a_record = NULL;
this_ret = getdns_dict_get_bindata(this_rdata, "ipv4_address", &this_a_record);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME)
{
fprintf(stderr, "Weird: the A record at %d in record at %d had no address. Exiting.",
(int) rr_count, (int) rec_count);
return;
}
printf("The IPv4 address is %s", getdns_display_ip_address(this_a_record));
}
else if (*this_type == GETDNS_RRTYPE_AAAA)
{
struct getdns_bindata * this_aaaa_record = NULL;
this_ret = getdns_dict_get_bindata(this_rdata, "ipv6_address", &this_aaaa_record);
if (this_ret == GETDNS_RETURN_NO_SUCH_DICT_NAME)
{
fprintf(stderr, "Weird: the AAAA record at %d in record at %d had no address. Exiting.",
(int) rr_count, (int) rec_count);
return;
}
printf("The IPv6 address is %s", getdns_display_ip_address(this_aaaa_record));
}
}
}
}
else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr, "The callback with ID %"PRIu64" was cancelled. Exiting.", this_transaction_id);
else
fprintf(stderr, "The callback got a callback_type of %d. Exiting.", this_callback_type);
}
int main()
{
/* Create the DNS context for this call */
struct getdns_context_t *this_context = NULL;
getdns_return_t context_create_return = getdns_context_create(&this_context, true);
if (context_create_return != GETDNS_RETURN_GOOD)
{
fprintf(stderr, "Trying to create the context failed: %d", context_create_return);
return(GETDNS_RETURN_GENERIC_ERROR);
}
/* Create an event base and put it in the context using the unknown function name */
struct event_base *this_event_base;
this_event_base = event_base_new();
if (this_event_base == NULL)
{
fprintf(stderr, "Trying to create the event base failed.");
return(GETDNS_RETURN_GENERIC_ERROR);
}
(void)getdns_extension_set_libevent_base(this_context, this_event_base);
/* Set up the getdns call */
const char * this_name = "www.example.com";
char* this_userarg = "somestring"; // Could add things here to help identify this call
getdns_transaction_t this_transaction_id = 0;
/* Make the call */
getdns_return_t dns_request_return = getdns_address(this_context, this_name,
NULL, this_userarg, &this_transaction_id, this_callbackfn);
if (dns_request_return == GETDNS_RETURN_BAD_DOMAIN_NAME)
{
fprintf(stderr, "A bad domain name was used: %s. Exiting.", this_name);
return(GETDNS_RETURN_GENERIC_ERROR);
}
else
{
/* Call the event loop */
int dispatch_return = event_base_dispatch(this_event_base);
UNUSED_PARAM(dispatch_return);
// TODO: check the return value above
}
/* Clean up */
getdns_context_destroy(this_context);
/* Assuming we get here, leave gracefully */
exit(EXIT_SUCCESS);
}

403
spec/getdns_core_only.c Normal file
View File

@ -0,0 +1,403 @@
#include <getdns_libevent.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
int main(){ return(0); }
/* Function definitions */
getdns_return_t
getdns_general(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback
)
{ UNUSED_PARAM(context); UNUSED_PARAM(name); UNUSED_PARAM(request_type); UNUSED_PARAM(extensions); UNUSED_PARAM(userarg);
UNUSED_PARAM(transaction_id); UNUSED_PARAM(callback); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_address(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback
)
{ UNUSED_PARAM(context); UNUSED_PARAM(name); UNUSED_PARAM(extensions); UNUSED_PARAM(userarg);
UNUSED_PARAM(transaction_id); UNUSED_PARAM(callback); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_hostname(
getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback
)
{ UNUSED_PARAM(context); UNUSED_PARAM(address); UNUSED_PARAM(extensions); UNUSED_PARAM(userarg);
UNUSED_PARAM(transaction_id); UNUSED_PARAM(callback); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_service(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback
)
{ UNUSED_PARAM(context); UNUSED_PARAM(name); UNUSED_PARAM(extensions); UNUSED_PARAM(userarg);
UNUSED_PARAM(transaction_id); UNUSED_PARAM(callback); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_create(
getdns_context_t *context,
bool set_from_os
)
{ UNUSED_PARAM(context); UNUSED_PARAM(set_from_os); return GETDNS_RETURN_GOOD; }
void
getdns_context_destroy(
getdns_context_t context
)
{ UNUSED_PARAM(context); }
getdns_return_t
getdns_cancel_callback(
getdns_context_t context,
getdns_transaction_t transaction_id
)
{ UNUSED_PARAM(context); UNUSED_PARAM(transaction_id); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_general_sync(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(name); UNUSED_PARAM(request_type); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_address_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(name); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_hostname_sync(
getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(address); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_service_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(name); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
void
getdns_free_sync_request_memory(
struct getdns_dict *response
)
{ UNUSED_PARAM(response); }
getdns_return_t getdns_list_get_length(struct getdns_list *this_list, size_t *answer)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_list_get_data_type(struct getdns_list *this_list, size_t index, getdns_data_type *answer)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(index); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_list_get_dict(struct getdns_list *this_list, size_t index, struct getdns_dict **answer)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(index); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_list_get_list(struct getdns_list *this_list, size_t index, struct getdns_list **answer)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(index); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_list_get_bindata(struct getdns_list *this_list, size_t index, struct getdns_bindata **answer)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(index); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_list_get_int(struct getdns_list *this_list, size_t index, uint32_t *answer)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(index); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_dict_get_names(struct getdns_dict *this_dict, struct getdns_list **answer)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_dict_get_data_type(struct getdns_dict *this_dict, char *name, getdns_data_type *answer)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(name); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_dict_get_dict(struct getdns_dict *this_dict, char *name, struct getdns_dict **answer)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(name); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_dict_get_list(struct getdns_dict *this_dict, char *name, struct getdns_list **answer)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(name); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_dict_get_bindata(struct getdns_dict *this_dict, char *name, struct getdns_bindata **answer)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(name); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_dict_get_int(struct getdns_dict *this_dict, char *name, uint32_t *answer)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(name); UNUSED_PARAM(answer); return GETDNS_RETURN_GOOD; }
struct getdns_list * getdns_list_create()
{ return NULL; }
void getdns_list_destroy(struct getdns_list *this_list)
{ UNUSED_PARAM(this_list); }
getdns_return_t getdns_list_set_dict(struct getdns_list *this_list, size_t index, struct getdns_dict *child_dict)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(index); UNUSED_PARAM(child_dict); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_list_set_list(struct getdns_list *this_list, size_t index, struct getdns_list *child_list)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(index); UNUSED_PARAM(child_list); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_list_set_bindata(struct getdns_list *this_list, size_t index, struct getdns_bindata *child_bindata)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(index); UNUSED_PARAM(child_bindata); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_list_set_int(struct getdns_list *this_list, size_t index, uint32_t child_uint32)
{ UNUSED_PARAM(this_list); UNUSED_PARAM(index); UNUSED_PARAM(child_uint32); return GETDNS_RETURN_GOOD; }
struct getdns_dict * getdns_dict_create()
{ return NULL; }
void getdns_dict_destroy(struct getdns_dict *this_dict)
{ UNUSED_PARAM(this_dict); }
getdns_return_t getdns_dict_set_dict(struct getdns_dict *this_dict, char *name, struct getdns_dict *child_dict)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(name); UNUSED_PARAM(child_dict); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_dict_set_list(struct getdns_dict *this_dict, char *name, struct getdns_list *child_list)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(name); UNUSED_PARAM(child_list); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_dict_set_bindata(struct getdns_dict *this_dict, char *name, struct getdns_bindata *child_bindata)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(name); UNUSED_PARAM(child_bindata); return GETDNS_RETURN_GOOD; }
getdns_return_t getdns_dict_set_int(struct getdns_dict *this_dict, char *name, uint32_t child_uint32)
{ UNUSED_PARAM(this_dict); UNUSED_PARAM(name); UNUSED_PARAM(child_uint32); return GETDNS_RETURN_GOOD; }
char *
getdns_convert_dns_name_to_fqdn(
char *name_from_dns_response
)
{ UNUSED_PARAM(name_from_dns_response); return NULL; }
char *
getdns_convert_fqdn_to_dns_name(
char *fqdn_as_string
)
{ UNUSED_PARAM(fqdn_as_string); return NULL; }
char *
getdns_convert_ulabel_to_alabel(
char *ulabel
)
{ UNUSED_PARAM(ulabel); return NULL; }
char *
getdns_convert_alabel_to_ulabel(
char *alabel
)
{ UNUSED_PARAM(alabel); return NULL; }
getdns_return_t
getdns_validate_dnssec(
struct getdns_bindata *record_to_validate,
struct getdns_list *bundle_of_support_records,
struct getdns_list *trust_anchor_rdatas
)
{ UNUSED_PARAM(record_to_validate); UNUSED_PARAM(bundle_of_support_records); UNUSED_PARAM(trust_anchor_rdatas);
return GETDNS_RETURN_GOOD; }
char *
getdns_pretty_print_dict(
struct getdns_dict *some_dict
)
{ UNUSED_PARAM(some_dict); return NULL; }
char *
getdns_display_ip_address(
struct getdns_bindata *bindata_of_ipv4_or_ipv6_address
)
{ UNUSED_PARAM(bindata_of_ipv4_or_ipv6_address); return NULL; }
getdns_return_t
getdns_context_set_context_update_callback(
getdns_context_t context,
void (*value)(getdns_context_t context, uint16_t changed_item)
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_context_update(
getdns_context_t context,
uint16_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_resolution_type(
getdns_context_t context,
uint16_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_namespaces(
getdns_context_t context,
size_t namespace_count,
uint16_t *namespaces
)
{ UNUSED_PARAM(context); UNUSED_PARAM(namespace_count); UNUSED_PARAM(namespaces);
return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_dns_transport(
getdns_context_t context,
uint16_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_limit_outstanding_queries(
getdns_context_t context,
uint16_t limit
)
{ UNUSED_PARAM(context); UNUSED_PARAM(limit); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_timeout(
getdns_context_t context,
uint16_t timeout
)
{ UNUSED_PARAM(context); UNUSED_PARAM(timeout); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_follow_redirects(
getdns_context_t context,
uint16_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_dns_root_servers(
getdns_context_t context,
struct getdns_list *addresses
)
{ UNUSED_PARAM(context); UNUSED_PARAM(addresses); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_append_name(
getdns_context_t context,
uint16_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_suffix(
getdns_context_t context,
struct getdns_list *value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_dnssec_trust_anchors(
getdns_context_t context,
struct getdns_list *value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_dnssec_allowed_skew(
getdns_context_t context,
uint16_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_stub_resolution(
getdns_context_t context,
struct getdns_list *upstream_list
)
{ UNUSED_PARAM(context); UNUSED_PARAM(upstream_list); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_edns_maximum_udp_payload_size(
getdns_context_t context,
uint16_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_edns_extended_rcode(
getdns_context_t context,
uint8_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_edns_version(
getdns_context_t context,
uint8_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_edns_do_bit(
getdns_context_t context,
uint8_t value
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_memory_allocator(
getdns_context_t context,
void (*value)(size_t somesize)
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_memory_deallocator(
getdns_context_t context,
void (*value)(void*)
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_context_set_memory_reallocator(
getdns_context_t context,
void (*value)(void*)
)
{ UNUSED_PARAM(context); UNUSED_PARAM(value); return GETDNS_RETURN_GOOD; }
getdns_return_t
getdns_extension_set_libevent_base(
getdns_context_t context,
struct event_base *this_event_base
)
{ UNUSED_PARAM(context); UNUSED_PARAM(this_event_base); return GETDNS_RETURN_GOOD; }

558
spec/getdns_core_only.h Normal file
View File

@ -0,0 +1,558 @@
/* Created at 2013-04-02-16-59-04*/
#ifndef GETDNS_H
#define GETDNS_H
#include <stdint.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <stdbool.h>
#define GETDNS_COMPILATION_COMMENT The API implementation should fill in something here, such as a compilation version string and date, and change it each time the API is compiled.
/* Return values */
#define GETDNS_RETURN_GOOD 0
#define GETDNS_RETURN_GOOD_TEXT Good
#define GETDNS_RETURN_GENERIC_ERROR 1
#define GETDNS_RETURN_GENERIC_ERROR_TEXT Generic error
#define GETDNS_RETURN_BAD_DOMAIN_NAME 300
#define GETDNS_RETURN_BAD_DOMAIN_NAME_TEXT Badly-formed domain name in first argument
#define GETDNS_RETURN_BAD_CONTEXT 301
#define GETDNS_RETURN_BAD_CONTEXT_TEXT Bad value for a context type
#define GETDNS_RETURN_CONTEXT_UPDATE_FAIL 302
#define GETDNS_RETURN_CONTEXT_UPDATE_FAIL_TEXT Did not update the context
#define GETDNS_RETURN_UNKNOWN_TRANSACTION 303
#define GETDNS_RETURN_UNKNOWN_TRANSACTION_TEXT An attempt was made to cancel a callback with a transaction_id that is not recognized
#define GETDNS_RETURN_NO_SUCH_LIST_ITEM 304
#define GETDNS_RETURN_NO_SUCH_LIST_ITEM_TEXT A helper function for lists had an index argument that was too high.
#define GETDNS_RETURN_NO_SUCH_DICT_NAME 305
#define GETDNS_RETURN_NO_SUCH_DICT_NAME_TEXT A helper function for dicts had a name argument that for a name that is not in the dict.
#define GETDNS_RETURN_WRONG_TYPE_REQUESTED 306
#define GETDNS_RETURN_WRONG_TYPE_REQUESTED_TEXT A helper function was supposed to return a certain type for an item, but the wrong type was given.
#define GETDNS_RETURN_NO_SUCH_EXTENSION 307
#define GETDNS_RETURN_NO_SUCH_EXTENSION_TEXT A name in the extensions dict is not a valid extension.
#define GETDNS_RETURN_EXTENSION_MISFORMAT 308
#define GETDNS_RETURN_EXTENSION_MISFORMAT_TEXT One or more of the extensions is has a bad format.
#define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED 309
#define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED_TEXT A query was made with a context that is using stub resolution and a DNSSEC extension specified.
/* DNSSEC values */
#define GETDNS_DNSSEC_SECURE 400
#define GETDNS_DNSSEC_SECURE_TEXT The record was determined to be secure in DNSSEC
#define GETDNS_DNSSEC_BOGUS 401
#define GETDNS_DNSSEC_BOGUS_TEXT The record was determined to be bogus in DNSSEC
#define GETDNS_DNSSEC_INDETERMINATE 402
#define GETDNS_DNSSEC_INDETERMINATE_TEXT The record was not determined to be any state in DNSSEC
#define GETDNS_DNSSEC_INSECURE 403
#define GETDNS_DNSSEC_INSECURE_TEXT The record was determined to be insecure in DNSSEC
#define GETDNS_DNSSEC_NOT_PERFORMED 404
#define GETDNS_DNSSEC_NOT_PERFORMED_TEXT DNSSEC validation was not performed (only used for debugging)
/* Context Variables */
#define GETDNS_CONTEXT_NAMESPACE_DNS 500
#define GETDNS_CONTEXT_NAMESPACE_DNS_TEXT See getdns_context_set_namespaces()
#define GETDNS_CONTEXT_NAMESPACE_LOCALNAMES 501
#define GETDNS_CONTEXT_NAMESPACE_LOCALNAMES_TEXT See getdns_context_set_namespaces()
#define GETDNS_CONTEXT_NAMESPACE_NETBIOS 502
#define GETDNS_CONTEXT_NAMESPACE_NETBIOS_TEXT See getdns_context_set_namespaces()
#define GETDNS_CONTEXT_NAMESPACE_MDNS 503
#define GETDNS_CONTEXT_NAMESPACE_MDNS_TEXT See getdns_context_set_namespaces()
#define GETDNS_CONTEXT_NAMESPACE_NIS 504
#define GETDNS_CONTEXT_NAMESPACE_NIS_TEXT See getdns_context_set_namespaces()
#define GETDNS_CONTEXT_STUB 505
#define GETDNS_CONTEXT_STUB_TEXT See getdns_context_set_resolution_type()
#define GETDNS_CONTEXT_RECURSING 506
#define GETDNS_CONTEXT_RECURSING_TEXT See getdns_context_set_resolution_type()
#define GETDNS_CONTEXT_FOLLOW_REDIRECTS 507
#define GETDNS_CONTEXT_FOLLOW_REDIRECTS_TEXT See getdns_context_set_follow_redirects()
#define GETDNS_CONTEXT_DO_NOT_FOLLOW_REDIRECTS 508
#define GETDNS_CONTEXT_DO_NOT_FOLLOW_REDIRECTS_TEXT See getdns_context_set_follow_redirects()
#define GETDNS_CONTEXT_UDP_FIRST_AND_FALL_BACK_TO_TCP 509
#define GETDNS_CONTEXT_UDP_FIRST_AND_FALL_BACK_TO_TCP_TEXT See getdns_context_set_use_udp_tcp()
#define GETDNS_CONTEXT_UDP_ONLY 510
#define GETDNS_CONTEXT_UDP_ONLY_TEXT See getdns_context_set_use_udp_tcp()
#define GETDNS_CONTEXT_TCP_ONLY 511
#define GETDNS_CONTEXT_TCP_ONLY_TEXT See getdns_context_set_use_udp_tcp()
#define GETDNS_CONTEXT_TCP_ONLY_KEEP_CONNECTIONS_OPEN 512
#define GETDNS_CONTEXT_TCP_ONLY_KEEP_CONNECTIONS_OPEN_TEXT See getdns_context_set_use_udp_tcp()
#define GETDNS_CONTEXT_APPEND_NAME_ALWAYS 513
#define GETDNS_CONTEXT_APPEND_NAME_ALWAYS_TEXT See getdns_context_set_append_name()
#define GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE 514
#define GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE_TEXT See getdns_context_set_append_name()
#define GETDNS_CONTEXT_GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE 515
#define GETDNS_CONTEXT_GETDNS_CONTEXT_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE_TEXT See getdns_context_set_append_name()
#define GETDNS_CONTEXT_DO_NOT_APPEND_NAMES 516
#define GETDNS_CONTEXT_DO_NOT_APPEND_NAMES_TEXT See getdns_context_set_append_name()
/* Context codes */
#define GETDNS_CONTEXT_CODE_NAMESPACES 600
#define GETDNS_CONTEXT_CODE_NAMESPACES_TEXT Change related to getdns_context_set_namespaces
#define GETDNS_CONTEXT_CODE_RESOLUTION_TYPE 601
#define GETDNS_CONTEXT_CODE_RESOLUTION_TYPE_TEXT Change related to getdns_context_set_resolution_type
#define GETDNS_CONTEXT_CODE_FOLLOW_REDIRECTS 602
#define GETDNS_CONTEXT_CODE_FOLLOW_REDIRECTS_TEXT Change related to getdns_context_set_follow_redirects
#define GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS 603
#define GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS_TEXT Change related to getdns_context_set_upstream_recursive_servers
#define GETDNS_CONTEXT_CODE_DNS_ROOT_SERVERS 604
#define GETDNS_CONTEXT_CODE_DNS_ROOT_SERVERS_TEXT Change related to getdns_context_set_dns_root_servers
#define GETDNS_CONTEXT_CODE_USE_UDP_TCP 605
#define GETDNS_CONTEXT_CODE_USE_UDP_TCP_TEXT Change related to getdns_context_set_use_udp_tcp
#define GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES 606
#define GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES_TEXT Change related to getdns_context_set_limit_outstanding_queries
#define GETDNS_CONTEXT_CODE_APPEND_NAME 607
#define GETDNS_CONTEXT_CODE_APPEND_NAME_TEXT Change related to getdns_context_set_append_name
#define GETDNS_CONTEXT_CODE_SUFFIX 608
#define GETDNS_CONTEXT_CODE_SUFFIX_TEXT Change related to getdns_context_set_suffix
#define GETDNS_CONTEXT_CODE_DNSSEC_TRUST_ANCHORS 609
#define GETDNS_CONTEXT_CODE_DNSSEC_TRUST_ANCHORS_TEXT Change related to getdns_context_set_dnssec_trust_anchors
#define GETDNS_CONTEXT_CODE_EDNS_MAXIMUM_UDP_PAYLOAD_SIZE 610
#define GETDNS_CONTEXT_CODE_EDNS_MAXIMUM_UDP_PAYLOAD_SIZE_TEXT Change related to getdns_context_set_edns_maximum_udp_payload_size
#define GETDNS_CONTEXT_CODE_EDNS_EXTENDED_RCODE 611
#define GETDNS_CONTEXT_CODE_EDNS_EXTENDED_RCODE_TEXT Change related to getdns_context_set_edns_extended_rcode
#define GETDNS_CONTEXT_CODE_EDNS_VERSION 612
#define GETDNS_CONTEXT_CODE_EDNS_VERSION_TEXT Change related to getdns_context_set_edns_version
#define GETDNS_CONTEXT_CODE_EDNS_DO_BIT 613
#define GETDNS_CONTEXT_CODE_EDNS_DO_BIT_TEXT Change related to getdns_context_set_edns_do_bit
#define GETDNS_CONTEXT_CODE_DNSSEC_ALLOWED_SKEW 614
#define GETDNS_CONTEXT_CODE_DNSSEC_ALLOWED_SKEW_TEXT Change related to getdns_context_set_dnssec_allowed_skew
#define GETDNS_CONTEXT_CODE_MEMORY_ALLOCATOR 615
#define GETDNS_CONTEXT_CODE_MEMORY_ALLOCATOR_TEXT Change related to getdns_context_set_memory_allocator
#define GETDNS_CONTEXT_CODE_MEMORY_DEALLOCATOR 616
#define GETDNS_CONTEXT_CODE_MEMORY_DEALLOCATOR_TEXT Change related to getdns_context_set_memory_deallocator
#define GETDNS_CONTEXT_CODE_MEMORY_REALLOCATOR 617
#define GETDNS_CONTEXT_CODE_MEMORY_REALLOCATOR_TEXT Change related to getdns_context_set_memory_reallocator
/* Callback Type Variables */
#define GETDNS_CALLBACK_COMPLETE 700
#define GETDNS_CALLBACK_COMPLETE_TEXT The response has the requested data in it
#define GETDNS_CALLBACK_CANCEL 701
#define GETDNS_CALLBACK_CANCEL_TEXT The calling program cancelled the callback; response is NULL
#define GETDNS_CALLBACK_TIMEOUT 702
#define GETDNS_CALLBACK_TIMEOUT_TEXT The requested action timed out; response is NULL
#define GETDNS_CALLBACK_ERROR 703
#define GETDNS_CALLBACK_ERROR_TEXT The requested action had an error; response is NULL
/* Type Of Name Services */
#define GETDNS_NAMETYPE_DNS 800
#define GETDNS_NAMETYPE_DNS_TEXT Normal DNS (RFC 1035)
#define GETDNS_NAMETYPE_WINS 801
#define GETDNS_NAMETYPE_WINS_TEXT The WINS name service (some reference needed)
/* Status Codes for Responses */
#define GETDNS_RESPSTATUS_GOOD 900
#define GETDNS_RESPSTATUS_GOOD_TEXT At least one response was returned
#define GETDNS_RESPSTATUS_NO_NAME 901
#define GETDNS_RESPSTATUS_NO_NAME_TEXT Queries for the name yielded all negative responses
#define GETDNS_RESPSTATUS_ALL_TIMEOUT 902
#define GETDNS_RESPSTATUS_ALL_TIMEOUT_TEXT All queries for the name timed out
#define GETDNS_RESPSTATUS_NO_SECURE_ANSWERS 903
#define GETDNS_RESPSTATUS_NO_SECURE_ANSWERS_TEXT The context setting for getting only secure responses was specified, and at least one DNS response was received, but no DNS response was determined to be secure through DNSSEC.
/* Values Associated With Extensions */
#define GETDNS_EXTENSION_TRUE 1000
#define GETDNS_EXTENSION_TRUE_TEXT Turn on the extension
#define GETDNS_EXTENSION_FALSE 1001
#define GETDNS_EXTENSION_FALSE_TEXT Do not turn on the extension
/* Values Associated With DNS Errors Found By The API */
#define GETDNS_BAD_DNS_CNAME_IN_TARGET 1100
#define GETDNS_BAD_DNS_CNAME_IN_TARGET_TEXT A DNS query type that does not allow a target to be a CNAME pointed to a CNAME
#define GETDNS_BAD_DNS_ALL_NUMERIC_LABEL 1101
#define GETDNS_BAD_DNS_ALL_NUMERIC_LABEL_TEXT One or more labels in a returned domain name is all-numeric; this is not legal for a hostname
#define GETDNS_BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE 1102
#define GETDNS_BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE_TEXT A DNS query for a type other than CNAME returned a CNAME response
/* Defines for RRtypes (from 2012-12) */
#define GETDNS_RRTYPE_A 1
#define GETDNS_RRTYPE_NS 2
#define GETDNS_RRTYPE_MD 3
#define GETDNS_RRTYPE_MF 4
#define GETDNS_RRTYPE_CNAME 5
#define GETDNS_RRTYPE_SOA 6
#define GETDNS_RRTYPE_MB 7
#define GETDNS_RRTYPE_MG 8
#define GETDNS_RRTYPE_MR 9
#define GETDNS_RRTYPE_NULL 10
#define GETDNS_RRTYPE_WKS 11
#define GETDNS_RRTYPE_PTR 12
#define GETDNS_RRTYPE_HINFO 13
#define GETDNS_RRTYPE_MINFO 14
#define GETDNS_RRTYPE_MX 15
#define GETDNS_RRTYPE_TXT 16
#define GETDNS_RRTYPE_RP 17
#define GETDNS_RRTYPE_AFSDB 18
#define GETDNS_RRTYPE_X25 19
#define GETDNS_RRTYPE_ISDN 20
#define GETDNS_RRTYPE_RT 21
#define GETDNS_RRTYPE_NSAP 22
#define GETDNS_RRTYPE_SIG 24
#define GETDNS_RRTYPE_KEY 25
#define GETDNS_RRTYPE_PX 26
#define GETDNS_RRTYPE_GPOS 27
#define GETDNS_RRTYPE_AAAA 28
#define GETDNS_RRTYPE_LOC 29
#define GETDNS_RRTYPE_NXT 30
#define GETDNS_RRTYPE_EID 31
#define GETDNS_RRTYPE_NIMLOC 32
#define GETDNS_RRTYPE_SRV 33
#define GETDNS_RRTYPE_ATMA 34
#define GETDNS_RRTYPE_NAPTR 35
#define GETDNS_RRTYPE_KX 36
#define GETDNS_RRTYPE_CERT 37
#define GETDNS_RRTYPE_A6 38
#define GETDNS_RRTYPE_DNAME 39
#define GETDNS_RRTYPE_SINK 40
#define GETDNS_RRTYPE_OPT 41
#define GETDNS_RRTYPE_APL 42
#define GETDNS_RRTYPE_DS 43
#define GETDNS_RRTYPE_SSHFP 44
#define GETDNS_RRTYPE_IPSECKEY 45
#define GETDNS_RRTYPE_RRSIG 46
#define GETDNS_RRTYPE_NSEC 47
#define GETDNS_RRTYPE_DNSKEY 48
#define GETDNS_RRTYPE_DHCID 49
#define GETDNS_RRTYPE_NSEC3 50
#define GETDNS_RRTYPE_NSEC3PARAM 51
#define GETDNS_RRTYPE_TLSA 52
#define GETDNS_RRTYPE_HIP 55
#define GETDNS_RRTYPE_NINFO 56
#define GETDNS_RRTYPE_RKEY 57
#define GETDNS_RRTYPE_TALINK 58
#define GETDNS_RRTYPE_CDS 59
#define GETDNS_RRTYPE_SPF 99
#define GETDNS_RRTYPE_UINFO 100
#define GETDNS_RRTYPE_UID 101
#define GETDNS_RRTYPE_GID 102
#define GETDNS_RRTYPE_UNSPEC 103
#define GETDNS_RRTYPE_NID 104
#define GETDNS_RRTYPE_L32 105
#define GETDNS_RRTYPE_L64 106
#define GETDNS_RRTYPE_LP 107
#define GETDNS_RRTYPE_TKEY 249
#define GETDNS_RRTYPE_TSIG 250
#define GETDNS_RRTYPE_IXFR 251
#define GETDNS_RRTYPE_AXFR 252
#define GETDNS_RRTYPE_MAILB 253
#define GETDNS_RRTYPE_MAILA 254
#define GETDNS_RRTYPE_URI 256
#define GETDNS_RRTYPE_CAA 257
#define GETDNS_RRTYPE_TA 32768
#define GETDNS_RRTYPE_DLV 32769
/* Various typedefs */
typedef struct getdns_context_t *getdns_context_t;
typedef uint16_t getdns_return_t;
typedef uint64_t getdns_transaction_t;
typedef enum some_data_type {
t_dict, t_list, t_int, t_bindata
} getdns_data_type;
typedef struct getdns_bindata {
size_t size;
uint8_t *binary_stuff;
} some_bindata;
typedef struct getdns_dict some_dict;
typedef struct getdns_list some_list;
/* Helper functions for data structures */
/* Lists: get the length, get the data_type of the value at a given
position, and get the data at a given position */
getdns_return_t getdns_list_get_length(struct getdns_list *this_list, size_t *answer);
getdns_return_t getdns_list_get_data_type(struct getdns_list *this_list, size_t index, getdns_data_type *answer);
getdns_return_t getdns_list_get_dict(struct getdns_list *this_list, size_t index, struct getdns_dict **answer);
getdns_return_t getdns_list_get_list(struct getdns_list *this_list, size_t index, struct getdns_list **answer);
getdns_return_t getdns_list_get_bindata(struct getdns_list *this_list, size_t index, struct getdns_bindata **answer);
getdns_return_t getdns_list_get_int(struct getdns_list *this_list, size_t index, uint32_t *answer);
/* Dicts: get the list of names, get the data_type of the
value at a given name, and get the data at a given name */
getdns_return_t getdns_dict_get_names(struct getdns_dict *this_dict, struct getdns_list **answer);
getdns_return_t getdns_dict_get_data_type(struct getdns_dict *this_dict, char *name, getdns_data_type *answer);
getdns_return_t getdns_dict_get_dict(struct getdns_dict *this_dict, char *name, struct getdns_dict **answer);
getdns_return_t getdns_dict_get_list(struct getdns_dict *this_dict, char *name, struct getdns_list **answer);
getdns_return_t getdns_dict_get_bindata(struct getdns_dict *this_dict, char *name, struct getdns_bindata **answer);
getdns_return_t getdns_dict_get_int(struct getdns_dict *this_dict, char *name, uint32_t *answer);
/* Lists: create, destroy, and set the data at a given position */
struct getdns_list * getdns_list_create();
void getdns_list_destroy(struct getdns_list *this_list);
getdns_return_t getdns_list_set_dict(struct getdns_list *this_list, size_t index, struct getdns_dict *child_dict);
getdns_return_t getdns_list_set_list(struct getdns_list *this_list, size_t index, struct getdns_list *child_list);
getdns_return_t getdns_list_set_bindata(struct getdns_list *this_list, size_t index, struct getdns_bindata *child_bindata);
getdns_return_t getdns_list_set_int(struct getdns_list *this_list, size_t index, uint32_t child_uint32);
/* Dicts: create, destroy, and set the data at a given name */
struct getdns_dict * getdns_dict_create();
void getdns_dict_destroy(struct getdns_dict *this_dict);
getdns_return_t getdns_dict_set_dict(struct getdns_dict *this_dict, char *name, struct getdns_dict *child_dict);
getdns_return_t getdns_dict_set_list(struct getdns_dict *this_dict, char *name, struct getdns_list *child_list);
getdns_return_t getdns_dict_set_bindata(struct getdns_dict *this_dict, char *name, struct getdns_bindata *child_bindata);
getdns_return_t getdns_dict_set_int(struct getdns_dict *this_dict, char *name, uint32_t child_uint32);
/* Callback arguments */
typedef void (*getdns_callback_t)(
getdns_context_t context,
uint16_t callback_type,
struct getdns_dict *response,
void *userarg,
getdns_transaction_t transaction_id);
/* Function definitions */
getdns_return_t
getdns_general(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn
);
getdns_return_t
getdns_address(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn
);
getdns_return_t
getdns_hostname(
getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn
);
getdns_return_t
getdns_service(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn
);
getdns_return_t
getdns_context_create(
getdns_context_t *context,
bool set_from_os
);
void
getdns_context_destroy(
getdns_context_t context
);
getdns_return_t
getdns_cancel_callback(
getdns_context_t context,
getdns_transaction_t transaction_id
);
getdns_return_t
getdns_general_sync(
getdns_context_t context,
const char *name,
uint16_t request_type,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
);
getdns_return_t
getdns_address_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
);
getdns_return_t
getdns_hostname_sync(
getdns_context_t context,
struct getdns_dict *address,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
);
getdns_return_t
getdns_service_sync(
getdns_context_t context,
const char *name,
struct getdns_dict *extensions,
uint32_t *response_length,
struct getdns_dict *response
);
void
getdns_free_sync_request_memory(
struct getdns_dict *response
);
char *
getdns_convert_dns_name_to_fqdn(
char *name_from_dns_response
);
char *
getdns_convert_fqdn_to_dns_name(
char *fqdn_as_string
);
char *
getdns_convert_ulabel_to_alabel(
char *ulabel
);
char *
getdns_convert_alabel_to_ulabel(
char *alabel
);
getdns_return_t
getdns_validate_dnssec(
struct getdns_bindata *record_to_validate,
struct getdns_list *bundle_of_support_records,
struct getdns_list *trust_anchor_rdatas
);
char *
getdns_pretty_print_dict(
struct getdns_dict *some_dict
);
char *
getdns_display_ip_address(
struct getdns_bindata *bindata_of_ipv4_or_ipv6_address
);
getdns_return_t
getdns_context_set_context_update_callback(
getdns_context_t context,
void (*value)(getdns_context_t context, uint16_t changed_item)
);
getdns_return_t
getdns_context_set_resolution_type(
getdns_context_t context,
uint16_t value
);
getdns_return_t
getdns_context_set_namespaces(
getdns_context_t context,
size_t namespace_count,
uint16_t *namespaces
);
getdns_return_t
getdns_context_set_dns_transport(
getdns_context_t context,
uint16_t value
);
getdns_return_t
getdns_context_set_limit_outstanding_queries(
getdns_context_t context,
uint16_t limit
);
getdns_return_t
getdns_context_set_timeout(
getdns_context_t context,
uint16_t timeout
);
getdns_return_t
getdns_context_set_follow_redirects(
getdns_context_t context,
uint16_t value
);
getdns_return_t
getdns_context_set_dns_root_servers(
getdns_context_t context,
struct getdns_list *addresses
);
getdns_return_t
getdns_context_set_append_name(
getdns_context_t context,
uint16_t value
);
getdns_return_t
getdns_context_set_suffix(
getdns_context_t context,
struct getdns_list *value
);
getdns_return_t
getdns_context_set_dnssec_trust_anchors(
getdns_context_t context,
struct getdns_list *value
);
getdns_return_t
getdns_context_set_dnssec_allowed_skew(
getdns_context_t context,
uint16_t value
);
getdns_return_t
getdns_context_set_stub_resolution(
getdns_context_t context,
struct getdns_list *upstream_list
);
getdns_return_t
getdns_context_set_edns_maximum_udp_payload_size(
getdns_context_t context,
uint16_t value
);
getdns_return_t
getdns_context_set_edns_extended_rcode(
getdns_context_t context,
uint8_t value
);
getdns_return_t
getdns_context_set_edns_version(
getdns_context_t context,
uint8_t value
);
getdns_return_t
getdns_context_set_edns_do_bit(
getdns_context_t context,
uint8_t value
);
getdns_return_t
getdns_context_set_memory_allocator(
getdns_context_t context,
void (*value)(size_t somesize)
);
getdns_return_t
getdns_context_set_memory_deallocator(
getdns_context_t context,
void (*value)(void*)
);
getdns_return_t
getdns_context_set_memory_reallocator(
getdns_context_t context,
void (*value)(void*)
);
#endif /* GETDNS_H */

9
spec/getdns_libevent.h Normal file
View File

@ -0,0 +1,9 @@
#include <event2/event.h>
#include <getdns_core_only.h>
/* For libevent, which we are using for these examples */
getdns_return_t
getdns_extension_set_libevent_base(
getdns_context_t context,
struct event_base *this_event_base
);

2182
spec/index.html Normal file

File diff suppressed because it is too large Load Diff

22
spec/make-examples-linux.sh Executable file
View File

@ -0,0 +1,22 @@
rm -rf *.o *.dylib
gcc -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c getdns_core_only.c
gcc -std=c89 -shared -fPIC -levent_core -o libgetdns.so getdns_core_only.o
gcc -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-all-functions.c
gcc -std=c89 -fPIC -L./ example-all-functions.o -levent_core -lgetdns -o example-all-functions
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-simple-answers.c
gcc -std=c99 -fPIC -L./ example-simple-answers.o -levent_core -lgetdns -o example-simple-answers
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-tree.c
gcc -std=c99 -fPIC -L./ example-tree.o -levent_core -lgetdns -o example-tree
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-synchronous.c
gcc -std=c99 -fPIC -L./ example-synchronous.o -levent_core -lgetdns -o example-synchronous
rm -rf *.o *.dylib
clang -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c getdns_core_only.c
clang -std=c89 -shared -fPIC -levent_core -o libgetdns.so getdns_core_only.o
clang -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-all-functions.c
clang -std=c89 -fPIC -L./ example-all-functions.o -levent_core -lgetdns -o example-all-functions
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-simple-answers.c
clang -std=c99 -fPIC -L./ example-simple-answers.o -levent_core -lgetdns -o example-simple-answers
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-tree.c
clang -std=c99 -fPIC -L./ example-tree.o -levent_core -lgetdns -o example-tree
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-synchronous.c
clang -std=c99 -fPIC -L./ example-synchronous.o -levent_core -lgetdns -o example-synchronous

22
spec/make-examples-mac.sh Executable file
View File

@ -0,0 +1,22 @@
rm -rf *.o *.dylib
gcc -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c getdns_core_only.c
gcc -std=c89 -dynamiclib -fPIC -levent_core -o libgetdns.dylib getdns_core_only.o
gcc -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-all-functions.c
gcc -std=c89 -fPIC -L./ example-all-functions.o -levent_core -lgetdns -o example-all-functions
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-simple-answers.c
gcc -std=c99 -fPIC -L./ example-simple-answers.o -levent_core -lgetdns -o example-simple-answers
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-tree.c
gcc -std=c99 -fPIC -L./ example-tree.o -levent_core -lgetdns -o example-tree
gcc -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-synchronous.c
gcc -std=c99 -fPIC -L./ example-synchronous.o -levent_core -lgetdns -o example-synchronous
rm -rf *.o *.dylib
clang -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c getdns_core_only.c
clang -std=c89 -dynamiclib -fPIC -levent_core -o libgetdns.dylib getdns_core_only.o
clang -std=c89 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-all-functions.c
clang -std=c89 -fPIC -L./ example-all-functions.o -levent_core -lgetdns -o example-all-functions
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-simple-answers.c
clang -std=c99 -fPIC -L./ example-simple-answers.o -levent_core -lgetdns -o example-simple-answers
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-tree.c
clang -std=c99 -fPIC -L./ example-tree.o -levent_core -lgetdns -o example-tree
clang -std=c99 -c -fPIC -pedantic -g -I./ -Werror -Wall -Wextra -c example-synchronous.c
clang -std=c99 -fPIC -L./ example-synchronous.o -levent_core -lgetdns -o example-synchronous

View File

@ -7,26 +7,32 @@
* Interfaces originally taken from the getdns API description pseudo implementation.
*
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
@ -677,4 +683,4 @@ getdns_pretty_print_dict(struct getdns_dict *dict)
return ret;
} /* getdns_pretty_print_dict */
/* getdns_dict.c */
/* dict.c */

View File

@ -1,32 +1,37 @@
/**
*
* /brief getdns contect management functions
* /brief getdns dict data type management functions
*
* This is the meat of the API
* Originally taken from the getdns API description pseudo implementation.
*
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, NLNet Labs, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GETDNS_DICT_H_
#define _GETDNS_DICT_H_
@ -63,3 +68,4 @@ struct getdns_dict {
#endif
/* dict.h */

View File

@ -1,31 +1,37 @@
/**
*
* /brief getdns core functions
*
* This is the meat of the API
* Originally taken from the getdns API description pseudo implementation.
* /brief getdns_general and related support functions
*
* The getdns_general function is called by most of the other public entry
* points to the library. Private support functions are also included in this
* file where they are directly logically related to the getdns_general implementation.
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
@ -231,7 +237,8 @@ getdns_general_ub(struct ub_ctx* unbound,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callbackfn) {
getdns_callback_t callbackfn)
{
/* timeout */
struct timeval tv;
getdns_return_t gr;
@ -283,9 +290,9 @@ getdns_general_ub(struct ub_ctx* unbound,
return GETDNS_RETURN_GENERIC_ERROR;
}
return GETDNS_RETURN_GOOD;
}
} /* getdns_general_ub */
/*
/**
* getdns_general
*/
getdns_return_t
@ -295,7 +302,9 @@ getdns_general_ub(struct ub_ctx* unbound,
struct getdns_dict *extensions,
void *userarg,
getdns_transaction_t *transaction_id,
getdns_callback_t callback) {
getdns_callback_t callback)
{
int extcheck = GETDNS_RETURN_GOOD;
if (!context || !context->event_base_async ||
callback == NULL) {
@ -305,6 +314,10 @@ getdns_general_ub(struct ub_ctx* unbound,
return GETDNS_RETURN_BAD_CONTEXT;
}
extcheck = validate_extensions(extensions);
if(extcheck != GETDNS_RETURN_GOOD)
return extcheck;
return getdns_general_ub(context->unbound_async,
context->event_base_async,
context,
@ -317,7 +330,6 @@ getdns_general_ub(struct ub_ctx* unbound,
} /* getdns_general */
/*
* getdns_address
*

View File

@ -6,27 +6,33 @@
* Originally taken from the getdns API description pseudo implementation.
*
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GETDNS_GENERAL_H_
#define _GETDNS_GENERAL_H_

1
src/getdns/README Normal file
View File

@ -0,0 +1 @@
This directory contains the getdns API description that serves as the target of this implementation.

View File

@ -1,30 +1,36 @@
/**
* \file
* \brief Public interfaces to getdns - include this in your application to use getdns API.
* \brief Public interfaces to getdns, include in your application to use getdns API.
*
* This source was taken from the original pseudo-implementation by
* Paul Hoffman.
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, NLNet Labs, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GETDNS_H
@ -64,7 +70,7 @@ struct event_base;
#define GETDNS_RETURN_NO_SUCH_EXTENSION 307
#define GETDNS_RETURN_NO_SUCH_EXTENSION_TEXT A name in the extensions dict is not a valid extension.
#define GETDNS_RETURN_EXTENSION_MISFORMAT 308
#define GETDNS_RETURN_EXTENSION_MISFORMAT_TEXT One or more of the extensions is has a bad format.
#define GETDNS_RETURN_EXTENSION_MISFORMAT_TEXT One or more of the extensions has a bad format.
#define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED 309
#define GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED_TEXT A query was made with a context that is using stub resolution and a DNSSEC extension specified.
@ -278,12 +284,6 @@ struct event_base;
#define GETDNS_STR_KEY_QTYPE "qtype"
#define GETDNS_STR_KEY_QCLASS "qclass"
#define GETDNS_STR_KEY_QNAME "qname"
/** @}
*/
@ -372,6 +372,9 @@ struct event_base;
typedef struct getdns_context_t *getdns_context_t;
typedef uint16_t getdns_return_t;
typedef uint64_t getdns_transaction_t;
/**
* used to check data types within complex types (dict, list)
*/
typedef enum getdns_data_type {
t_dict, t_list, t_int, t_bindata, t_invalid
} getdns_data_type;

View File

@ -6,26 +6,32 @@
* Originally taken from the getdns API description pseudo implementation.
*
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>

View File

@ -6,26 +6,31 @@
* Originally taken from the getdns API description pseudo implementation.
*
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "types-internal.h"
@ -108,7 +113,8 @@ void dns_req_free(getdns_dns_req* req) {
}
/* create a new dns req to be submitted */
getdns_dns_req* dns_req_new(getdns_context_t context,
getdns_dns_req*
dns_req_new(getdns_context_t context,
struct ub_ctx* unbound,
const char* name,
uint16_t request_type,

View File

@ -5,26 +5,32 @@
* Originally taken from the getdns API description pseudo implementation.
*
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <getdns/getdns.h>
@ -59,12 +65,16 @@ getdns_general_sync(
{
getdns_return_t response_status;
response_status = getdns_general_ub(context->unbound_sync, context->event_base_sync,
context, name, request_type, extensions,
(void *)response, NULL, sync_callback_func);
event_base_dispatch(context->event_base_sync);
response_status = validate_extensions(extensions);
if (response_status == GETDNS_RETURN_GOOD) {
response_status = getdns_general_ub(context->unbound_sync,
context->event_base_sync,
context, name, request_type,
extensions, (void *)response,
NULL, sync_callback_func);
event_base_dispatch(context->event_base_sync);
}
return response_status;
}

View File

@ -1,31 +1,36 @@
/**
*
* /brief getdns contect management functions
*
* This is the meat of the API
* Originally taken from the getdns API description pseudo implementation.
* /brief type declarations private to the getdns library
*
* These type declarations are not meant to be used by applications calling
* the public library functions.
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TYPES_INTERNAL_H_
@ -48,6 +53,14 @@ typedef enum network_req_state_enum {
NET_REQ_CANCELED
} network_req_state;
/**
* structure used by validate_extensions() to check extension formats
*/
typedef struct getdns_extension_format {
char *extstring;
getdns_data_type exttype;
} getdns_extension_format;
/**
* Request data for unbound
**/
@ -72,7 +85,8 @@ typedef struct getdns_network_req {
struct getdns_network_req* next;
} getdns_network_req;
/* dns request - manages a number of network requests and
/**
* dns request - manages a number of network requests and
* the initial data passed to getdns_general
*/
typedef struct getdns_dns_req {
@ -138,3 +152,5 @@ getdns_dns_req* dns_req_new(getdns_context_t context,
void dns_req_free(getdns_dns_req* req);
#endif
/* types-internal.h */

View File

@ -1,36 +1,64 @@
/**
*
* /brief getdns contect management functions
* /file
* /brief private library routines
*
* This is the meat of the API
* Originally taken from the getdns API description pseudo implementation.
* These routines are not intended to be used by applications calling into
* the library.
*
*/
/* 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.
*/
/*
* Copyright (c) 2013, Versign, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "getdns/getdns.h"
#include <ldns/rbtree.h>
#include "dict.h"
#include "util-internal.h"
#include "types-internal.h"
/**
* this is a comprehensive list of extensions and their data types
* used by validate_extensions()
* The list has to be in sorted order for bsearch lookup in function
* validate_extensions.
*/
getdns_extension_format extformats[] = {
{"add_opt_parameters", t_dict},
{"add_warning_for_bad_dns", t_int},
{"dnssec_return_only_secure", t_int},
{"dnssec_return_status", t_int},
{"dnssec_return_supporting_responses", t_int},
{"return_api_information", t_int},
{"return_both_v4_and_v6", t_int},
{"return_call_debugging", t_int},
{"specify_class", t_int},
};
getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name,
const char* value) {
/* account for the null term */
@ -464,11 +492,12 @@ getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) {
return result;
}
/*
* reverse an IP address for PTR lookup
/**
* reverse an IP address for PTR lookup
* @param addr_str dotted notation of IP address to reverse
* @return NULL on allocation failure
* @return reversed string on success, caller must free storage via call to free()
*/
char *
reverse_address(char *addr_str)
{
@ -492,3 +521,35 @@ reverse_address(char *addr_str)
ldns_rdf_deep_free(rev_rdf);
return rev_str;
}
static int extformatcmp(const void *a, const void *b)
{
return strcmp(((getdns_extension_format *)a)->extstring,
((getdns_extension_format *)b)->extstring);
}
/*---------------------------------------- validate_extensions */
getdns_return_t
validate_extensions(getdns_dict *extensions)
{
struct getdns_dict_item *item;
getdns_extension_format *extformat;
if(extensions)
LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(extensions->root)) {
getdns_extension_format key;
key.extstring = (char *)item->node.key;
extformat = bsearch(&key, extformats,
sizeof(extformats) /
sizeof(getdns_extension_format),
sizeof(getdns_extension_format), extformatcmp);
if (! extformat)
return GETDNS_RETURN_NO_SUCH_EXTENSION;
if (item->dtype != extformat->exttype)
return GETDNS_RETURN_EXTENSION_MISFORMAT;
}
return GETDNS_RETURN_GOOD;
} /* validate_extensions */
/* util-internal.c */

View File

@ -6,26 +6,32 @@
* Originally taken from the getdns API description pseudo implementation.
*
*/
/* The MIT License (MIT)
* Copyright (c) 2013 Verisign, Inc.
/*
* Copyright (c) 2013, Versign, Inc.
* All rights reserved.
*
* 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:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
@ -52,3 +58,15 @@ getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name,
getdns_return_t getdns_dict_util_get_string(getdns_dict* dict, char* name,
char** result);
char *reverse_address(char *addr_str);
/**
* detect unrecognized extension strings or invalid extension formats
* TODO: this could be optimized by searching a sorted list
* @param extensions dictionary of valid extension strings and values
* @return GETDNS_RETURN_GOOD if each extension string is valid and the format matches the API specification
* @return GETDNS_RETURN_NO_SUCH_EXTENSION A name in the extensions dict is not a valid extension.
* @return GETDNS_RETURN_EXTENSION_MISFORMAT One or more of the extensions has a bad format.
*/
getdns_return_t validate_extensions(getdns_dict *extensions);
/* util-internal.h */