diff --git a/CodingStyle b/CodingStyle new file mode 100644 index 00000000..5eedbc15 --- /dev/null +++ b/CodingStyle @@ -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 . 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 +__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, 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 /* first, */ +#include /* next, */ +#include /* and then the rest, */ +#include /* sorted lexicographically. */ +#include +#include /* Non-local includes in brackets. */ + +/* + * If it's a network program, put the network include files next. + * Group the includes files by subdirectory. + */ +#include +#include +#include +#include +#include + +/* + * Then there's a blank line, followed by the /usr include files. + * The /usr include files should be sorted lexicographically! + */ +#include +#include +#include +#include +#include + +/* + * Global pathnames are defined in /usr/include/paths.h. Pathnames local + * to the program go in pathnames.h in the local directory. + */ +#include + +/* 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 + * , 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 appearing at the top of the file with the + * other include files.) + */ +#include + +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); +} diff --git a/configure.ac b/configure.ac index b47e47eb..a1374f1e 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/doc/getdns_address.3.in b/doc/getdns_address.3.in new file mode 100644 index 00000000..33e41887 --- /dev/null +++ b/doc/getdns_address.3.in @@ -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_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). + diff --git a/doc/libgetdns.3.in b/doc/libgetdns.3.in new file mode 100644 index 00000000..64ddc54a --- /dev/null +++ b/doc/libgetdns.3.in @@ -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 + +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 + diff --git a/src/dict.c b/src/dict.c index 2d78e5f8..5bc38758 100644 --- a/src/dict.c +++ b/src/dict.c @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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 @@ -673,4 +679,4 @@ getdns_pretty_print_dict(struct getdns_dict *dict) return ret; } /* getdns_pretty_print_dict */ -/* getdns_dict.c */ +/* dict.c */ diff --git a/src/dict.h b/src/dict.h index d184cba2..91ca0180 100644 --- a/src/dict.h +++ b/src/dict.h @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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 */ diff --git a/src/general.c b/src/general.c index 2e59af63..f1fe72ce 100644 --- a/src/general.c +++ b/src/general.c @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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. */ /** @@ -195,7 +201,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; @@ -241,9 +248,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 @@ -253,7 +260,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) { @@ -263,6 +272,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, @@ -275,7 +288,6 @@ getdns_general_ub(struct ub_ctx* unbound, } /* getdns_general */ - /* * getdns_address * diff --git a/src/general.h b/src/general.h index 658131eb..7b4c98e8 100644 --- a/src/general.h +++ b/src/general.h @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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_ diff --git a/src/getdns/README b/src/getdns/README new file mode 100644 index 00000000..064d654c --- /dev/null +++ b/src/getdns/README @@ -0,0 +1 @@ +This directory contains the getdns API description that serves as the target of this implementation. diff --git a/src/getdns/getdns.h b/src/getdns/getdns.h index 6ec786c3..727741cb 100644 --- a/src/getdns/getdns.h +++ b/src/getdns/getdns.h @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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; diff --git a/src/list.c b/src/list.c index 5c6ca170..e5398048 100644 --- a/src/list.c +++ b/src/list.c @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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 diff --git a/src/list.h b/src/list.h index a3c3cd58..2fb1b100 100644 --- a/src/list.h +++ b/src/list.h @@ -61,7 +61,7 @@ struct getdns_list { int numalloc; int numinuse; struct getdns_list_item *items; -} getdns_list; +}; #endif diff --git a/src/request-internal.c b/src/request-internal.c index 555a549e..b0e872cd 100644 --- a/src/request-internal.c +++ b/src/request-internal.c @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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" @@ -103,7 +108,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, diff --git a/src/sync.c b/src/sync.c index 3aee6364..f47f7b39 100644 --- a/src/sync.c +++ b/src/sync.c @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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 @@ -148,4 +154,4 @@ getdns_free_sync_request_memory( ) { UNUSED_PARAM(response); } -/* getdns_core_sync.c */ +/* sync.c */ diff --git a/src/types-internal.h b/src/types-internal.h index 822e206b..90093464 100644 --- a/src/types-internal.h +++ b/src/types-internal.h @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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_ @@ -47,6 +52,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 **/ @@ -71,7 +84,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 { @@ -131,3 +145,5 @@ getdns_dns_req* dns_req_new(getdns_context_t context, void dns_req_free(getdns_dns_req* req); #endif + +/* types-internal.h */ diff --git a/src/util-internal.c b/src/util-internal.c index ef28fd73..f5ee94d9 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -1,36 +1,63 @@ /** * - * /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 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 +#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() + */ +getdns_extension_format extformats[] = { + {"dnssec_return_status", t_int}, + {"dnssec_return_only_secure", t_int}, + {"dnssec_return_supporting_responses", t_int}, + {"return_both_v4_and_v6", t_int}, + {"add_opt_parameters", t_dict}, + {"add_warning_for_bad_dns", t_int}, + {"specify_class", t_int}, + {"return_api_information", t_int}, + {"return_call_debugging", t_int}, + {"", t_invalid} +}; + getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name, const char* value) { /* account for the null term */ @@ -462,11 +489,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) { @@ -490,3 +518,42 @@ reverse_address(char *addr_str) ldns_rdf_deep_free(rev_rdf); return rev_str; } + +/*---------------------------------------- validate_extensions */ +getdns_return_t +validate_extensions(getdns_dict *extensions) +{ + int retval = GETDNS_RETURN_GOOD; + int i = 0; + ldns_rbnode_t *node; + + if(extensions == NULL) + return retval; + + node = ldns_rbtree_first(&(extensions->root)); + while(retval == GETDNS_RETURN_GOOD && node != NULL) + { + i = 0; + while(extformats[i].exttype != t_invalid) + { + if(strcmp(extformats[i].extstring, node->key) == 0) + { + if(((struct getdns_dict_item *) node->data)->dtype != extformats[i].exttype) + { + retval = GETDNS_RETURN_EXTENSION_MISFORMAT; + } + break; + } + i++; + } + + if(extformats[i].exttype == t_invalid) + retval = GETDNS_RETURN_NO_SUCH_EXTENSION; + else + node = ldns_rbtree_next(node); + } // while retval && node + + return retval; +} /* validate_extensions */ + +/* util-internal.c */ diff --git a/src/util-internal.h b/src/util-internal.h index 94b95bc3..ef0f89f9 100644 --- a/src/util-internal.h +++ b/src/util-internal.h @@ -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. + * + * 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 nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. * - * 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. + * 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 */