regress_testutils.h revision 290001
1189251Ssam/*
2214734Srpaulo * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson
3214734Srpaulo *
4189251Ssam * Redistribution and use in source and binary forms, with or without
5252726Srpaulo * modification, are permitted provided that the following conditions
6252726Srpaulo * are met:
7189251Ssam * 1. Redistributions of source code must retain the above copyright
8189251Ssam *    notice, this list of conditions and the following disclaimer.
9189251Ssam * 2. Redistributions in binary form must reproduce the above copyright
10189251Ssam *    notice, this list of conditions and the following disclaimer in the
11189251Ssam *    documentation and/or other materials provided with the distribution.
12189251Ssam * 3. The name of the author may not be used to endorse or promote products
13189251Ssam *    derived from this software without specific prior written permission.
14189251Ssam *
15189251Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16189251Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17189251Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18189251Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19189251Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20189251Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21189251Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22189251Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23189251Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24189251Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25189251Ssam */
26189251Ssam
27189251Ssam#ifndef REGRESS_TESTUTILS_H_INCLUDED_
28189251Ssam#define REGRESS_TESTUTILS_H_INCLUDED_
29189251Ssam
30189251Ssam#include "event2/dns.h"
31189251Ssam
32189251Ssamstruct regress_dns_server_table {
33189251Ssam	const char *q;
34189251Ssam	const char *anstype;
35189251Ssam	const char *ans;
36189251Ssam	int seen;
37189251Ssam};
38189251Ssam
39189251Ssamstruct evdns_server_port *
40189251Ssamregress_get_dnsserver(struct event_base *base,
41189251Ssam    ev_uint16_t *portnum,
42189251Ssam    evutil_socket_t *psock,
43189251Ssam    evdns_request_callback_fn_type cb,
44189251Ssam    void *arg);
45189251Ssam
46189251Ssam/* Helper: return the port that a socket is bound on, in host order. */
47189251Ssamint regress_get_socket_port(evutil_socket_t fd);
48189251Ssam
49189251Ssam/* used to look up pre-canned responses in a search table */
50189251Ssamvoid regress_dns_server_cb(
51189251Ssam	struct evdns_server_request *req, void *data);
52189251Ssam
53189251Ssam/* globally allocates a dns server that serves from a search table */
54189251Ssamint regress_dnsserver(struct event_base *base, ev_uint16_t *port,
55189251Ssam    struct regress_dns_server_table *seach_table);
56189251Ssam
57189251Ssam/* clean up the global dns server resources */
58189251Ssamvoid regress_clean_dnsserver(void);
59189251Ssam
60189251Ssamstruct evconnlistener;
61189251Ssamstruct sockaddr;
62189251Ssamint regress_get_listener_addr(struct evconnlistener *lev,
63189251Ssam    struct sockaddr *sa, ev_socklen_t *socklen);
64189251Ssam
65189251Ssam#endif /* REGRESS_TESTUTILS_H_INCLUDED_ */
66189251Ssam
67252726Srpaulo