1 /*
2  * Copyright (c) 2014-2020 by Farsight Security, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef DEFS_H_INCLUDED
18 #define DEFS_H_INCLUDED 1
19 
20 #include <stdarg.h>
21 #include <stdbool.h>
22 #include <stdio.h>
23 #include <string.h>
24 
25 /* Note that cygwin has a crippled libresolv that does not
26  * include the not so recent ns_initparse() function, etc.
27  * This AS info functionality is thus not available
28  * in cygwin.
29  */
30 #ifdef __CYGWIN__
31 #define CRIPPLED_LIBC 1
32 #endif /* __CYGWIN__ */
33 
34 #if WANT_PDNS_DNSDB
35 #define DEFAULT_SYS "dnsdb2"
36 #elif WANT_PDNS_CIRL
37 #define DEFAULT_SYS "circl"
38 #else
39 #error "No passive DNS system defined"
40 #endif
41 #define DEFAULT_VERB 0
42 
43 /* maximum number of concurrent fetches.
44  * must not be greater than any pDNS system's concurrent connection limit.
45  */
46 #define	MAX_FETCHES 8
47 
48 #define DNSDBQ_SYSTEM "DNSDBQ_SYSTEM"
49 
50 #define CREATE(p, s) if ((p) != NULL) { my_panic(false, "non-NULL ptr"); } \
51 	else if (((p) = malloc(s)) == NULL) { my_panic(true, "malloc"); } \
52 	else { memset((p), 0, s); }
53 #define DESTROY(p) { if ((p) != NULL) { free(p); (p) = NULL; } }
54 #define DEBUG(ge, ...) { if (debug_level >= (ge)) debug(__VA_ARGS__); }
55 
56 typedef enum { pres_none, pres_text, pres_json, pres_csv, pres_minimal }
57 	present_e;
58 typedef enum { batch_none, batch_terse, batch_verbose } batch_e;
59 
60 #define TRANS_REVERSE	0x01
61 #define TRANS_DATEFIX	0x02
62 #define TRANS_CHOMP	0x04
63 
64 /* or_else -- return one pointer or else the other.
65  */
66 static inline const char *
or_else(const char * p,const char * or_else)67 or_else(const char *p, const char *or_else) {
68 	if (p != NULL)
69 		return p;
70 	return or_else;
71 }
72 
73 /* debug -- at the moment, dump to stderr.
74  */
75 static inline void
debug(bool want_header,const char * fmtstr,...)76 debug(bool want_header, const char *fmtstr, ...) {
77 	va_list ap;
78 
79 	va_start(ap, fmtstr);
80 	if (want_header)
81 		fputs("debug: ", stderr);
82 	vfprintf(stderr, fmtstr, ap);
83 	va_end(ap);
84 }
85 
86 /* a query mode. not all pdns systems support all of these. */
87 typedef enum { no_mode = 0, rrset_mode, name_mode, ip_mode,
88 	       raw_rrset_mode, raw_name_mode } mode_e;
89 
90 #endif /*DEFS_H_INCLUDED*/
91