Shuffle stuff around.
[adns] / src / adns-internal.h
CommitLineData
a17d3a1d 1/**/
2
3#ifndef ADNS_INTERNAL_H_INCLUDED
4#define ADNS_INTERNAL_H_INCLUDED
5
964344fc 6#include <sys/time.h>
7
a17d3a1d 8#include "adns.h"
9
656b2da9 10/* Configuration and constants */
11
a17d3a1d 12#define MAXSERVERS 5
84fe28db 13#define MAXUDPRETRIES 15
a17d3a1d 14#define UDPRETRYMS 2000
84fe28db 15#define TCPMS 30000
16#define LOCALRESOURCEMS 20
17
656b2da9 18/* Shared data structures */
19
84fe28db 20union adns__align {
21 adns_status status;
22 char *cp;
23 adns_rrtype type;
24 int int;
25 struct in_addr ia;
26 unsigned long ul;
27};
a17d3a1d 28
29struct adns__query {
c6bc2297 30 /* FIXME: make sure this is all init'd properly */
84fe28db 31 adns_query back, next;
32 adns_query parent;
33 struct { adns_query head, tail; } children;
34 struct { adns_query back, next; } siblings;
a17d3a1d 35 adns_rrtype type;
e8c505a5 36 adns_answer *answer;
84fe28db 37 size_t ansalloc; ansused;
38 int id, flags, udpretries; /* udpretries==-1 => _f_usevc or too big for UDP */
39 int nextudpserver;
80917fcc 40 unsigned long sentudp, senttcp; /* bitmaps indexed by server */
a17d3a1d 41 struct timeval timeout;
42 void *context;
350d37d9 43 unsigned char *querymsg;
44 int querylen;
a17d3a1d 45 char owner[1];
80917fcc 46 /* Possible states:
9d95094c 47 * Queue child id answer nextserver sentudp senttcp
48 * tosend null >=0 null any any any
49 * timew null >=0 null any at least 1 bit set any
50 * childw set >=0 partial any any any
51 * output null -1 set/null any any any
80917fcc 52 */
a17d3a1d 53};
54
c6bc2297 55struct adns__vbuf {
56 size_t used, avail;
57 unsigned char *buf;
58};
59
a17d3a1d 60struct adns__state {
c6bc2297 61 /* FIXME: make sure this is all init'd properly */
964344fc 62 adns_initflags iflags;
9d95094c 63 struct { adns_query head, tail; } tosend, timew, childw, output;
80917fcc 64 int nextid, udpsocket;
c6bc2297 65 adns_vbuf rqbuf, tcpsend, tcprecv;
84fe28db 66 int nservers, tcpserver;
c6bc2297 67 enum adns__tcpstate { server_disc, server_connecting, server_ok } tcpstate;
84fe28db 68 int tcpsocket;
69 struct timeval tcptimeout;
80917fcc 70 struct server {
a17d3a1d 71 struct in_addr addr;
a17d3a1d 72 } servers[MAXSERVERS];
73};
74
656b2da9 75/* From setup.c: */
76
77void adns__debug(adns_state ads, const char *fmt, ...) PRINTFFORMAT(2,3);
78void adns__diag(adns_state ads, const char *fmt, ...) PRINTFFORMAT(2,3);
79
80/* From submit.c: */
81
82void adns__query_fail(adns_state ads, adns_query qu, adns_status stat);
83
84/* From query.c: */
85
86void adns__quproc_tosend(adns_state ads, adns_query qu, struct timeval now) {
87
88/* Useful static inline functions: */
89
90static inline void timevaladd(struct timeval *tv_io, long ms) {
91 struct timeval tmp;
92 assert(ms>=0);
93 tmp= *tv_io;
94 tmp.tv_usec += (ms%1000)*1000;
95 tmp.tv_sec += ms/1000;
96 if (tmp.tv_usec >= 1000) { tmp.tv_sec++; tmp.tv_usec -= 1000; }
97 *tv_io= tmp;
98}
99
100/* Useful macros */
101
102#define LIST_UNLINK_PART(list,node,part) \
103 do { \
104 if ((node)->back) (node)->back->part next= (node)->part next; \
105 else (list).head= (node)->part next; \
106 if ((node)->next) (node)->next->part back= (node)->part back; \
107 else (list).tail= (node)->part back; \
108 } while(0)
109
110#define LIST_LINK_TAIL_PART(list,node,part) \
111 do { \
112 (node)->part back= 0; \
113 (node)->part next= (list).tail; \
114 if ((list).tail) (list).tail->part back= (node); else (list).part head= (node); \
115 (list).tail= (node); \
116 } while(0)
117
118#define LIST_UNLINK(list,node) LIST_UNLINK_PART(list,node,)
119#define LIST_LINK_TAIL_PART(list,node) LIST_LINK_TAIL(list,node,)
120
a17d3a1d 121#endif