Debian Codegraph @

libmowgli-2/src/libmowgli/dns/dns.h

raw
1 /*
2 * Copyright (c) 2012 Elizabeth J. Myers. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
12 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
16 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
17 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18 * POSSIBILITY OF SUCH DAMAGE.
19 */
20
21 #ifndef MOWGLI_SRC_LIBMOWGLI_DNS_DNS_H_INCLUDE_GUARD
22 #define MOWGLI_SRC_LIBMOWGLI_DNS_DNS_H_INCLUDE_GUARD 1
23
24 #include "eventloop/eventloop.h"
25 #include "vio/vio.h"
26
27 /* Longest hostname we're willing to work with */
28 #define MOWGLI_DNS_RES_HOSTLEN 512
29
30 /* Resolver types */
31 #define MOWGLI_DNS_TYPE_CUSTOM 0
32 #define MOWGLI_DNS_TYPE_ASYNC 1
33 #define MOWGLI_DNS_TYPE_HELPER 2
34
35 /* Lookup types */
36 #define MOWGLI_DNS_T_A 1
37 #define MOWGLI_DNS_T_AAAA 28
38 #define MOWGLI_DNS_T_PTR 12
39 #define MOWGLI_DNS_T_CNAME 5
40 #define MOWGLI_DNS_T_MX 15
41 #define MOWGLI_DNS_T_TXT 16
42 #define MOWGLI_DNS_T_SSHFP 44
43 #define MOWGLI_DNS_T_NULL 10
44
45 /* Return codes */
46 #define MOWGLI_DNS_RES_SUCCESS 0
47 #define MOWGLI_DNS_RES_NXDOMAIN 1
48 #define MOWGLI_DNS_RES_INVALID 2
49 #define MOWGLI_DNS_RES_TIMEOUT 3
50
51 typedef struct _mowgli_dns_t mowgli_dns_t;
52 typedef struct _mowgli_dns_query_t mowgli_dns_query_t;
53 typedef struct _mowgli_dns_reply_t mowgli_dns_reply_t;
54
55 typedef struct
56 {
57 int (*mowgli_dns_init_func_t)(mowgli_dns_t *, mowgli_eventloop_t *);
58 void (*mowgli_dns_fini_func_t)(mowgli_dns_t *);
59 int (*mowgli_dns_restart_func_t)(mowgli_dns_t *);
60 void (*mowgli_dns_delete_query_func_t)(mowgli_dns_t *, const mowgli_dns_query_t *);
61 void (*mowgli_dns_gethost_byname_func_t)(mowgli_dns_t *, const char *, mowgli_dns_query_t *, int);
62 void (*mowgli_dns_gethost_byaddr_func_t)(mowgli_dns_t *, const struct sockaddr_storage *, mowgli_dns_query_t *);
63 } mowgli_dns_ops_t;
64
65 struct _mowgli_dns_reply_t
66 {
67 char *h_name;
68 mowgli_vio_sockaddr_t addr;
69 };
70
71 struct _mowgli_dns_t
72 {
73 int dns_type;
74 const mowgli_dns_ops_t *dns_ops;
75 void *dns_state;
76 };
77
78 struct _mowgli_dns_query_t
79 {
80 void *ptr; /* pointer used by callback to identify request */
81 void (*callback)(mowgli_dns_reply_t *reply, int result, void *vptr); /* callback to call */
82 };
83
84 extern mowgli_dns_t *mowgli_dns_create(mowgli_eventloop_t *eventloop, int implementation);
85 extern int mowgli_dns_init(mowgli_dns_t *dns, mowgli_eventloop_t *eventloop, const mowgli_dns_ops_t *ops);
86 extern void mowgli_dns_destroy(mowgli_dns_t *dns);
87 extern int mowgli_dns_restart(mowgli_dns_t *dns);
88 extern void mowgli_dns_delete_query(mowgli_dns_t *dns, const mowgli_dns_query_t *query);
89 extern void mowgli_dns_gethost_byname(mowgli_dns_t *dns, const char *name, mowgli_dns_query_t *query, int type);
90 extern void mowgli_dns_gethost_byaddr(mowgli_dns_t *dns, const struct sockaddr_storage *addr, mowgli_dns_query_t *query);
91
92 #endif /* MOWGLI_SRC_LIBMOWGLI_DNS_DNS_H_INCLUDE_GUARD */