sipxtacklib  Version 3.3
rr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2010 SIPez LLC. All rights reserved.
3  * Licensed to SIPfoundry under a Contributor Agreement.
4  *
5  * Copyright (C) 2010 SIPfoundry Inc.
6  * Licensed by SIPfoundry under the LGPL license.
7  *
8  **********************************************************
9  *
10  * DNS Resource record manipulation routines
11  *
12  * Data structures
13  *
14  * Dave Shield November 1993
15  */
16 
17 #ifndef _Resparse_RR_h_
18 #define _Resparse_RR_h_
19 
20 #include <stdio.h>
21 
22 #ifdef WINCE
23 # include <types.h>
24 #else
25 # include <sys/types.h>
26 #endif
27 
28 #include "resparse/types.h"
29 
30 /* #define RES_PARSE_NAPTR to define the NAPTR record support routines. */
31 #ifdef RES_PARSE_NAPTR
32 #include <regex.h>
33 #endif
34 
35 /* Reordered includes and separated into win/vx --GAT */
36 #if defined(_WIN32)
37 # include <winsock2.h>
38 # include <resparse/wnt/netinet/in.h>
39 # include <resparse/wnt/arpa/inet.h>
41 
42 #elif defined(_VXWORKS)
43 # include <inetLib.h>
44 # include <netdb.h>
45 # include <resolvLib.h>
46 # include <sockLib.h>
47 # include <netinet/in.h>
48 # include <arpa/inet.h>
49 /* Use local lnameser.h for info missing from VxWorks version --GAT */
50 /* lnameser.h is a subset of resparse/wnt/arpa/nameser.h */
51 # include <resolv/nameser.h>
52 # include <resparse/vxw/arpa/lnameser.h>
53 # include <stdlib.h>
54 
55 #elif defined(__pingtel_on_posix__)
56 # include <sys/socket.h>
57 # include <netinet/in.h>
58 # include <arpa/inet.h>
59 # if defined(ANDROID)
60 # include <arpa_nameser.h>
61 # else
62 # include <arpa/nameser_compat.h> /* T_SRV, etc., on recent BIND */
63 # include <arpa/nameser.h>
64 # include <resolv.h>
65 # endif
66 # include <string.h>
67 
68 # define T_NULL_RR T_NULL
69 /* These are from include/resparse/wnt/arpa/nameser.h */
70 # define T_UINFO 100
71 # define T_UID 101
72 # define T_GID 102
73 # define T_UNSPEC 103
74 
75 #else
76 # error Unsupported target platform.
77 #endif
78 
79 # include <ctype.h>
80 
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84 
85 #if defined(ANDROID)
86 void android_res_setDnsSrvTimeouts(int initialTimeoutInSecs, int retries);
87 void android_res_getDnsSrvTimeouts(int* initialTimeoutInSecs, int* retries);
88 
89 // Had to pull this stuff out of bionic/libc/private/resolv_private.h
90 // as there were C++ compiler errors when trying to include it
91 int res_init(void);
92 int res_query(const char *, int, int, u_char *, int);
93 #endif
94 
95  /* Some systems don't define this */
96 #ifndef T_TXT
97 #define T_TXT 16
98 #endif
99 
100 #ifndef T_AFSDB
101 #define T_AFSDB 18
102 #endif
103 #ifndef T_SRV
104 #define T_SRV 33
105 #endif
106 #ifndef T_NAPTR
107 #define T_NAPTR 35
108 #endif
109 
110  /* additional RFC 1183 types */
111 #ifndef T_RP
112 #define T_RP 17
113 #endif
114 #ifndef T_X25
115 #define T_X25 19
116 #endif
117 #ifndef T_ISDN
118 #define T_ISDN 20
119 #endif
120 #ifndef T_RT
121 #define T_RT 21
122 #endif
123 
124  /*
125  * RR-specific data
126  * Structured types - separate structures
127  * Single valued types - use union directly
128  */
129 
130 struct s_SOA
131 {
132  char *mname;
133  char *rname;
134  u_long serial;
135  u_long refresh;
136  u_long retry;
137  u_long expire;
138  u_long minimum;
139 };
140 
141 
142 struct s_NULL
143 {
144  char *anything;
145  u_short length; /* Length of valid data */
146 };
147 
148 
149 struct s_WKS
150 {
151  struct in_addr address;
152  char *bitmap;
153  u_long maplength;
154  u_char protocol;
155 };
156 
157 
158 struct s_HINFO
159 {
160  char *cpu;
161  char *os;
162 };
163 
164 
165 struct s_MINFO
166 {
167  char *rmailbx;
168  char *emailbx;
169 };
170 
171 
172 struct s_MX
173 {
174  char *exchange;
175  u_short preference;
176 };
177 
178 struct s_TXT
179 {
180  char *text;
181  struct s_TXT *next;
182  u_short len;
183 };
184 
185 struct s_SRV
186 {
187  u_short priority;
188  u_short weight;
189  u_short port;
190  char *target;
191 };
192 
193 struct s_NAPTR
194 {
195  u_short order;
196  u_short preference;
197  char *flags;
198  char *services;
199  char *regexp;
200  char *replacement;
201 };
202 
203 
204  /*
205  * New RR types - RFC 1183
206  */
207 
208 struct s_AFSDB /* AFS servers */
209 {
210  u_short subtype;
211  char *hostname;
212 };
213 
214 
215 struct s_RP /* Responsible Person */
216 {
217  char *mbox_dname;
218  char *txt_dname;
219 };
220 
221  /* X25 - Use simple 'string' */
222 
223 struct s_ISDN /* ISDN Address */
224 {
225  char *address;
226  char *sa; /* optional */
227 };
228 
229 struct s_RT /* Route Through */
230 {
231  u_short preference;
232  char *int_host;
233 };
234 
235 
236 
237 
238  /* Generic RDATA RR structure */
239 union u_rdata
240 {
241  char *string; /* Any simple string record */
242  u_long number; /* Any simple numeric record */
243  struct in_addr address; /* Simple address (A record) */
244 
245  /* other structured RR types */
246  struct s_SOA soa;
247  struct s_NULL null;
248  struct s_WKS wks;
249  struct s_HINFO hinfo;
250  struct s_MINFO minfo;
251  struct s_MX mx;
252  struct s_TXT txt;
253  struct s_SRV srv;
254  /* RFC 2915 RR type */
255  struct s_NAPTR naptr;
256  /* RFC 1183 RR types */
257  struct s_AFSDB afsdb;
258  struct s_RP rp;
259  struct s_ISDN isdn;
260  struct s_RT rt;
261 };
262 
263 
264  /* Full RR structure */
265 typedef struct s_rr
266 {
267  char *name;
268  u_short type;
269  u_short rclass;
270  u_long ttl;
271  u_long dlen;
272  union u_rdata rdata;
273 } s_rr;
274 
275  /* DNS Question sctructure */
276 typedef struct s_question
277 {
278  char *qname;
279  u_short qtype;
280  u_short qclass;
281 } s_question;
282 
283 
284  /* Full DNS message structure */
285 typedef struct s_res_response
286 {
289  s_rr **answer;
290  s_rr **authority;
291  s_rr **additional;
292 } res_response ;
293 
294 
295  /* Defined interface */
296 
297 extern void free_rr(s_rr *rrp);
298 void free_response(res_response *resp);
299 extern res_response * res_parse(char *msg);
300 extern res_response * res_copy(res_response *resp);
301 extern void res_print(res_response *resp);
302 extern void res_free(res_response *resp);
303 
304 /* Support functions for NAPTR records */
305 
306 #ifdef RES_PARSE_NAPTR
307 
308 /* Split the 'regexp' field of a NAPTR record into the regexp to match
309  * and the replacement part, as well as test for flag values.
310  * Processes the field according to the rules in RFC 2915 section 3.
311  * Input: field points to a string which is the contents of the NAPTR
312  * regexp field.
313  * Returns: 1 if splitting operation is successful, 0 if not.
314  * (Success includes syntax-checking the replacement field, but not the
315  * match field.)
316  * Outputs: *delim_p will be set to the delimiter character (needed by
317  * res_naptr_replace).
318  * match will have written into it the POSIX extended regexp to match,
319  * with the extra escaping of *delim removed. (match must be at least
320  * as large as field.)
321  * *replace_p will have written into it the pointer to the beginning
322  * of the replacement string within field (needed by res_naptr_replace).
323  * (There is no benefit in de-escaping the replacement string at this point.)
324  * *i_flag_p will be set to 1 if the 'i' (case-insensitive) flag is found,
325  * 0 otherwise.
326  */
327 extern int res_naptr_split_regexp(const char *field,
328  char *delim_p,
329  char *match,
330  const char **replace_p,
331  int *i_flag_p);
332 
333 /* Construct the replacement string after a successful match.
334  * Inputs: replace is the replace string as returned by a successful
335  * call to res_naptr_split_regexp.
336  * delim is the delimiter character, as returned by res_naptr_split_regexp.
337  * match points to regmatch_t[9], as filled by a successful call to
338  * regexec.
339  * original is the string that was matched against.
340  * Return: pointer to malloc'ed character string containing the replacement.
341  * (Must be free'd by caller.)
342  */
343 extern char *res_naptr_replace(const char *replace,
344  char delim,
345  regmatch_t *match,
346  const char *original,
347  int keep_context);
348 
349 #endif /* RES_PARSE_NAPTR */
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 
355 #endif /* _Resparse_RR_h_ */
char * int_host
Definition: rr.h:232
u_short preference
Definition: rr.h:175
Definition: rr.h:142
u_long serial
Definition: rr.h:134
char * mbox_dname
Definition: rr.h:217
u_long retry
Definition: rr.h:136
u_short subtype
Definition: rr.h:210
char * rname
Definition: rr.h:133
Definition: rr.h:239
u_short order
Definition: rr.h:195
Definition: rr.h:193
Definition: rr.h:130
void free_rr(s_rr *rrp)
u_long dlen
Definition: rr.h:271
struct s_TXT * next
Definition: rr.h:181
Definition: rr.h:285
res_response * res_parse(char *msg)
char * regexp
Definition: rr.h:199
Definition: nameser.h:204
u_long number
Definition: rr.h:242
u_long expire
Definition: rr.h:137
void free_response(res_response *resp)
char * target
Definition: rr.h:190
int res_query(const char *, int, int, u_char *, int)
char * services
Definition: rr.h:198
char * cpu
Definition: rr.h:160
char * replacement
Definition: rr.h:200
Definition: rr.h:185
u_short weight
Definition: rr.h:188
char * bitmap
Definition: rr.h:152
char * name
Definition: rr.h:267
char * mname
Definition: rr.h:132
char * text
Definition: rr.h:180
Definition: rr.h:276
u_short len
Definition: rr.h:182
Definition: rr.h:215
void res_print(res_response *resp)
u_char protocol
Definition: rr.h:154
Definition: rr.h:208
Definition: rr.h:149
void res_free(res_response *resp)
Definition: rr.h:178
u_long ttl
Definition: rr.h:270
u_short port
Definition: rr.h:189
char * qname
Definition: rr.h:278
char * os
Definition: rr.h:161
char * sa
Definition: rr.h:226
struct s_res_response res_response
Definition: rr.h:223
res_response * res_copy(res_response *resp)
s_rr ** additional
Definition: rr.h:291
u_long maplength
Definition: rr.h:153
Definition: rr.h:172
char * emailbx
Definition: rr.h:168
char * exchange
Definition: rr.h:174
char * anything
Definition: rr.h:144
u_long refresh
Definition: rr.h:135
char * address
Definition: rr.h:225
Definition: rr.h:165
char * flags
Definition: rr.h:197
u_short priority
Definition: rr.h:187
Definition: rr.h:158
u_short preference
Definition: rr.h:196
char * rmailbx
Definition: rr.h:167
u_short rclass
Definition: rr.h:269
Definition: rr.h:265
u_short length
Definition: rr.h:145
Definition: rr.h:229
s_rr ** authority
Definition: rr.h:290
char * hostname
Definition: rr.h:211
struct s_question s_question
u_short type
Definition: rr.h:268
int res_init(void)
s_question ** question
Definition: rr.h:288
s_rr ** answer
Definition: rr.h:289
char * txt_dname
Definition: rr.h:218
char * string
Definition: rr.h:241
u_long minimum
Definition: rr.h:138
struct s_rr s_rr
HEADER header
Definition: rr.h:287
u_short qclass
Definition: rr.h:280
u_short qtype
Definition: rr.h:279
u_short preference
Definition: rr.h:231

sipXtackLib home page