3 #ifndef ADNS_INTERNAL_H_INCLUDED
4 #define ADNS_INTERNAL_H_INCLUDED
10 /* Configuration and constants */
13 #define MAXUDPRETRIES 15
14 #define UDPRETRYMS 2000
16 #define LOCALRESOURCEMS 20
17 #define UDPMAXDGRAM 512
20 /* Shared data structures */
32 /* FIXME: make sure this is all init'd properly */
33 adns_query back
, next
;
35 struct { adns_query head
, tail
; } children
;
36 struct { adns_query back
, next
; } siblings
;
39 size_t ansalloc
; ansused
;
40 int id
, flags
, udpretries
; /* udpretries==-1 => _f_usevc or too big for UDP */
41 int nextudpserver
, senttcpserver
;
42 unsigned long sentudp
; /* bitmap indexed by server */
43 struct timeval timeout
;
45 unsigned char *querymsg
;
49 * Queue child id answer nextserver sentudp senttcp
50 * tosend null >=0 null any any any
51 * timew null >=0 null any at least 1 bit set any
52 * childw set >=0 partial any any any
53 * output null -1 set/null any any any
63 /* FIXME: make sure this is all init'd properly */
64 adns_initflags iflags
;
66 struct { adns_query head
, tail
; } tosend
, timew
, childw
, output
;
67 int nextid
, udpsocket
;
68 adns_vbuf rqbuf
, tcpsend
, tcprecv
;
69 int nservers
, tcpserver
;
70 enum adns__tcpstate
{ server_disconnected
, server_connecting
, server_ok
} tcpstate
;
72 struct timeval tcptimeout
;
75 } servers
[MAXSERVERS
];
80 void adns__vdiag(adns_state ads
, adns_initflags prevent
, const char *pfx
,
81 int serv
, const char *fmt
, va_list al
);
82 void adns__debug(adns_state ads
, int serv
, const char *fmt
, ...) PRINTFFORMAT(3,4);
83 void adns__warn(adns_state ads
, int serv
, const char *fmt
, ...) PRINTFFORMAT(3,4);
84 void adns__diag(adns_state ads
, int serv
, const char *fmt
, ...) PRINTFFORMAT(3,4);
88 void adns__query_fail(adns_state ads
, adns_query qu
, adns_status stat
);
92 void adns__quproc_tosend(adns_state ads
, adns_query qu
, struct timeval now
);
95 void adns__tcp_broken(adns_state ads
, const char *what
, const char *why
);
96 void adns__tcp_tryconnect(adns_state ads
);
98 /* Useful static inline functions: */
100 static inline void timevaladd(struct timeval
*tv_io
, long ms
) {
104 tmp
.tv_usec
+= (ms
%1000)*1000;
105 tmp
.tv_sec
+= ms
/1000;
106 if (tmp
.tv_usec
>= 1000) { tmp
.tv_sec
++; tmp
.tv_usec
-= 1000; }
110 static inline int ctype_whitespace(int c
) { return c
==' ' || c
=='\n' || c
=='\t'; }
111 static inline int ctype_digit(int c
) { return c
>='0' && c
<='9'; }
115 #define LIST_UNLINK_PART(list,node,part) \
117 if ((node)->back) (node)->back->part next= (node)->part next; \
118 else (list).head= (node)->part next; \
119 if ((node)->next) (node)->next->part back= (node)->part back; \
120 else (list).tail= (node)->part back; \
123 #define LIST_LINK_TAIL_PART(list,node,part) \
125 (node)->part back= 0; \
126 (node)->part next= (list).tail; \
127 if ((list).tail) (list).tail->part back= (node); else (list).part head= (node); \
128 (list).tail= (node); \
131 #define LIST_UNLINK(list,node) LIST_UNLINK_PART(list,node,)
132 #define LIST_LINK_TAIL_PART(list,node) LIST_LINK_TAIL(list,node,)