2013-08-15 11:33:05 -05:00
|
|
|
/**
|
|
|
|
*
|
2013-11-04 17:37:54 -06:00
|
|
|
* /brief type declarations private to the getdns library
|
2013-08-15 11:33:05 -05:00
|
|
|
*
|
2013-11-04 17:37:54 -06:00
|
|
|
* These type declarations are not meant to be used by applications calling
|
|
|
|
* the public library functions.
|
2013-08-15 11:33:05 -05:00
|
|
|
*/
|
2013-11-04 17:37:54 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
2013-08-15 11:33:05 -05:00
|
|
|
*
|
2013-11-04 17:37:54 -06:00
|
|
|
* 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.
|
2013-08-15 11:33:05 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TYPES_INTERNAL_H_
|
|
|
|
#define TYPES_INTERNAL_H_
|
|
|
|
|
2013-12-08 15:56:34 -06:00
|
|
|
#include <getdns/getdns.h>
|
2013-08-15 11:33:05 -05:00
|
|
|
#include <ldns/ldns.h>
|
2013-12-08 15:56:34 -06:00
|
|
|
struct getdns_context;
|
2013-08-15 11:33:05 -05:00
|
|
|
|
2013-12-03 07:13:10 -06:00
|
|
|
/**
|
|
|
|
* \defgroup strings String Constants
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#define GETDNS_STR_IPV4 "IPv4"
|
|
|
|
#define GETDNS_STR_IPV6 "IPv6"
|
|
|
|
#define GETDNS_STR_ADDRESS_TYPE "address_type"
|
|
|
|
#define GETDNS_STR_ADDRESS_DATA "address_data"
|
|
|
|
#define GETDNS_STR_ADDRESS_STRING "address_string"
|
|
|
|
#define GETDNS_STR_PORT "port"
|
|
|
|
#define GETDNS_STR_EXTENSION_RETURN_BOTH_V4_AND_V6 "return_both_v4_and_v6"
|
|
|
|
|
|
|
|
#define GETDNS_STR_KEY_STATUS "status"
|
|
|
|
#define GETDNS_STR_KEY_REPLIES_TREE "replies_tree"
|
|
|
|
#define GETDNS_STR_KEY_REPLIES_FULL "replies_full"
|
|
|
|
#define GETDNS_STR_KEY_JUST_ADDRS "just_address_answers"
|
|
|
|
#define GETDNS_STR_KEY_CANONICAL_NM "canonical_name"
|
|
|
|
#define GETDNS_STR_KEY_ANSWER_TYPE "answer_type"
|
|
|
|
#define GETDNS_STR_KEY_INTERM_ALIASES "intermediate_aliases"
|
|
|
|
#define GETDNS_STR_KEY_NAME "name"
|
|
|
|
#define GETDNS_STR_KEY_HEADER "header"
|
|
|
|
#define GETDNS_STR_KEY_QUESTION "question"
|
|
|
|
#define GETDNS_STR_KEY_ANSWER "answer"
|
|
|
|
#define GETDNS_STR_KEY_ID "id"
|
|
|
|
#define GETDNS_STR_KEY_QR "qr"
|
|
|
|
#define GETDNS_STR_KEY_OPC "opcode"
|
|
|
|
#define GETDNS_STR_KEY_TYPE "type"
|
|
|
|
#define GETDNS_STR_KEY_CLASS "class"
|
|
|
|
#define GETDNS_STR_KEY_TTL "ttl"
|
|
|
|
#define GETDNS_STR_KEY_RDATA "rdata"
|
|
|
|
#define GETDNS_STR_KEY_V4_ADDR "ipv4_address"
|
|
|
|
#define GETDNS_STR_KEY_V6_ADDR "ipv6_address"
|
|
|
|
#define GETDNS_STR_KEY_RDATA_RAW "rdata_raw"
|
|
|
|
#define GETDNS_STR_KEY_AUTHORITY "authority"
|
|
|
|
#define GETDNS_STR_KEY_ADDITIONAL "additional"
|
|
|
|
#define GETDNS_STR_KEY_QTYPE "qtype"
|
|
|
|
#define GETDNS_STR_KEY_QCLASS "qclass"
|
|
|
|
#define GETDNS_STR_KEY_QNAME "qname"
|
|
|
|
/** @}
|
|
|
|
*/
|
|
|
|
|
2013-08-15 11:33:05 -05:00
|
|
|
/* declarations */
|
|
|
|
struct getdns_dns_req;
|
|
|
|
struct getdns_network_req;
|
2013-10-16 17:33:12 -05:00
|
|
|
struct ub_ctx;
|
2013-10-18 12:55:31 -05:00
|
|
|
struct event;
|
2013-11-05 12:31:29 -06:00
|
|
|
struct event_base;
|
2013-08-15 11:33:05 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
typedef enum network_req_state_enum
|
|
|
|
{
|
|
|
|
NET_REQ_NOT_SENT,
|
|
|
|
NET_REQ_IN_FLIGHT,
|
|
|
|
NET_REQ_FINISHED,
|
|
|
|
NET_REQ_CANCELED
|
2013-10-16 17:33:12 -05:00
|
|
|
} network_req_state;
|
|
|
|
|
2013-11-04 17:37:54 -06:00
|
|
|
/**
|
|
|
|
* structure used by validate_extensions() to check extension formats
|
|
|
|
*/
|
2013-11-05 14:03:44 -06:00
|
|
|
typedef struct getdns_extension_format
|
|
|
|
{
|
|
|
|
char *extstring;
|
|
|
|
getdns_data_type exttype;
|
2013-11-04 17:37:54 -06:00
|
|
|
} getdns_extension_format;
|
|
|
|
|
2013-10-16 17:33:12 -05:00
|
|
|
/**
|
|
|
|
* Request data for unbound
|
|
|
|
**/
|
2013-11-05 14:03:44 -06:00
|
|
|
typedef struct getdns_network_req
|
|
|
|
{
|
2013-10-16 17:33:12 -05:00
|
|
|
/* the async_id from unbound */
|
2013-11-05 14:03:44 -06:00
|
|
|
int unbound_id;
|
|
|
|
/* state var */
|
|
|
|
network_req_state state;
|
|
|
|
/* owner request (contains name) */
|
|
|
|
struct getdns_dns_req *owner;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* request type */
|
|
|
|
uint16_t request_type;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* request class */
|
|
|
|
uint16_t request_class;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* result */
|
|
|
|
ldns_pkt *result;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* next request to issue after this one */
|
|
|
|
struct getdns_network_req *next;
|
2013-08-15 11:33:05 -05:00
|
|
|
} getdns_network_req;
|
|
|
|
|
2013-11-04 17:37:54 -06:00
|
|
|
/**
|
|
|
|
* dns request - manages a number of network requests and
|
2013-10-16 17:33:12 -05:00
|
|
|
* the initial data passed to getdns_general
|
|
|
|
*/
|
2013-11-05 14:03:44 -06:00
|
|
|
typedef struct getdns_dns_req
|
|
|
|
{
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* name */
|
|
|
|
char *name;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* canceled flag */
|
|
|
|
int canceled;
|
2013-10-17 18:45:25 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* current network request */
|
2013-08-15 11:33:05 -05:00
|
|
|
struct getdns_network_req *current_req;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* first request in list */
|
|
|
|
struct getdns_network_req *first_req;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* request timeout event */
|
|
|
|
struct event *timeout;
|
2013-10-18 12:55:31 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* local callback timer */
|
|
|
|
struct event *local_cb_timer;
|
2013-11-05 12:31:29 -06:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* event base this req is scheduled on */
|
|
|
|
struct event_base *ev_base;
|
2013-11-05 12:31:29 -06:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* context that owns the request */
|
2013-12-06 08:54:06 -06:00
|
|
|
struct getdns_context *context;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* ub_ctx issuing the request */
|
|
|
|
struct ub_ctx *unbound;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* request extensions */
|
2013-12-06 08:54:06 -06:00
|
|
|
struct getdns_dict *extensions;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* callback data */
|
|
|
|
getdns_callback_t user_callback;
|
|
|
|
void *user_pointer;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
/* the transaction id */
|
|
|
|
getdns_transaction_t trans_id;
|
2013-10-16 17:33:12 -05:00
|
|
|
|
2013-08-15 11:33:05 -05:00
|
|
|
} getdns_dns_req;
|
|
|
|
|
2013-12-08 15:56:34 -06:00
|
|
|
#define MF_PLAIN ((void *)&plain_mem_funcs_user_arg)
|
|
|
|
extern void *plain_mem_funcs_user_arg;
|
|
|
|
|
2013-12-08 17:52:38 -06:00
|
|
|
typedef union {
|
2013-12-08 17:05:18 -06:00
|
|
|
struct {
|
|
|
|
void *(*malloc)(size_t);
|
|
|
|
void *(*realloc)(void *, size_t);
|
|
|
|
void (*free)(void *);
|
|
|
|
} pln;
|
|
|
|
struct {
|
|
|
|
void *(*malloc)(void *userarg, size_t);
|
|
|
|
void *(*realloc)(void *userarg, void *, size_t);
|
|
|
|
void (*free)(void *userarg, void *);
|
|
|
|
} ext;
|
2013-12-08 17:52:38 -06:00
|
|
|
} mf_union;
|
|
|
|
|
|
|
|
struct mem_funcs {
|
|
|
|
void *mf_arg;
|
|
|
|
mf_union mf;
|
2013-12-08 17:05:18 -06:00
|
|
|
};
|
2013-12-08 15:56:34 -06:00
|
|
|
|
2013-11-12 10:00:19 -06:00
|
|
|
#define GETDNS_XMALLOC(obj, type, count) \
|
2013-12-08 17:05:18 -06:00
|
|
|
((obj).mf_arg == MF_PLAIN \
|
|
|
|
? ((type *)(*(obj).mf.pln.malloc)( (count)*sizeof(type))) \
|
|
|
|
: ((type *)(*(obj).mf.ext.malloc)((obj).mf_arg, (count)*sizeof(type))) \
|
|
|
|
)
|
2013-11-12 10:00:19 -06:00
|
|
|
|
|
|
|
#define GETDNS_XREALLOC(obj, ptr, type, count) \
|
2013-12-08 17:05:18 -06:00
|
|
|
((obj).mf_arg == MF_PLAIN \
|
|
|
|
? ((type *)(*(obj).mf.pln.realloc)( (ptr), (count)*sizeof(type))) \
|
|
|
|
: ((type *)(*(obj).mf.ext.realloc)( (obj).mf_arg \
|
|
|
|
, (ptr), (count)*sizeof(type))) \
|
|
|
|
)
|
2013-12-08 15:56:34 -06:00
|
|
|
|
|
|
|
#define GETDNS_FREE(obj, ptr) \
|
2013-12-08 17:05:18 -06:00
|
|
|
((obj).mf_arg == MF_PLAIN \
|
|
|
|
? ((*(obj).mf.pln.free)( (ptr))) \
|
|
|
|
: ((*(obj).mf.ext.free)((obj).mf_arg, (ptr))) \
|
|
|
|
)
|
2013-11-12 10:00:19 -06:00
|
|
|
|
|
|
|
#define GETDNS_MALLOC(obj, type) GETDNS_XMALLOC(obj, type, 1)
|
|
|
|
#define GETDNS_REALLOC(obj, ptr, type) GETDNS_XREALLOC(obj, ptr, type, 1);
|
|
|
|
|
|
|
|
|
2013-08-15 11:33:05 -05:00
|
|
|
/* utility methods */
|
|
|
|
|
|
|
|
/* network request utilities */
|
2013-11-05 14:03:44 -06:00
|
|
|
void network_req_free(getdns_network_req * net_req);
|
2013-08-15 11:33:05 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
getdns_network_req *network_req_new(getdns_dns_req * owner,
|
|
|
|
uint16_t request_type,
|
|
|
|
uint16_t request_class, struct getdns_dict *extensions);
|
2013-08-15 11:33:05 -05:00
|
|
|
|
|
|
|
/* dns request utils */
|
2013-12-06 08:54:06 -06:00
|
|
|
getdns_dns_req *dns_req_new(struct getdns_context *context,
|
2013-11-05 14:03:44 -06:00
|
|
|
struct ub_ctx *unbound,
|
|
|
|
const char *name, uint16_t request_type, struct getdns_dict *extensions);
|
2013-08-15 11:33:05 -05:00
|
|
|
|
2013-11-05 14:03:44 -06:00
|
|
|
void dns_req_free(getdns_dns_req * req);
|
2013-08-15 11:42:35 -05:00
|
|
|
|
2013-08-15 11:33:05 -05:00
|
|
|
#endif
|
2013-11-04 17:37:54 -06:00
|
|
|
|
|
|
|
/* types-internal.h */
|