-
Notifications
You must be signed in to change notification settings - Fork 22
/
globals.h
99 lines (88 loc) · 3.3 KB
/
globals.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (c) 2014-2020 by Farsight Security, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLOBALS_H_INCLUDED
#define GLOBALS_H_INCLUDED 1
#include <stdarg.h>
#include "defs.h"
#include "deduper.h"
#include "sort.h"
#include "time.h"
#ifdef MAIN_PROGRAM
#define EXTERN
#define INIT(...) = __VA_ARGS__
#else
#define EXTERN extern
#define INIT(...)
#endif
#ifndef MAIN_PROGRAM
extern const struct verb verbs[];
#endif
EXTERN const char id_swclient[] INIT("dnsdbq");
EXTERN const char id_version[] INIT("2.6.8");
EXTERN const char *program_name INIT(NULL);
EXTERN const char path_sort[] INIT("/usr/bin/sort");
EXTERN const char json_header[] INIT("Accept: application/json");
EXTERN const char jsonl_header[] INIT("Accept: application/x-ndjson");
EXTERN const char env_time_fmt[] INIT("DNSDBQ_TIME_FORMAT");
EXTERN const char env_config_file[] INIT("DNSDBQ_CONFIG_FILE");
EXTERN const char env_timeout[] INIT("DNSDBQ_TIMEOUT");
EXTERN const char status_noerror[] INIT("NOERROR");
EXTERN const char status_error[] INIT("ERROR");
EXTERN const char *asinfo_domain INIT("asn.routeviews.org");
EXTERN struct qparam qparam_empty INIT({ .query_limit = -1L,
.explicit_output_limit = -1L, .output_limit = -1L });
EXTERN char *cookie_file INIT(NULL);
EXTERN char *config_file INIT(NULL);
EXTERN verb_ct pverb INIT(NULL);
EXTERN pdns_system_ct psys INIT(NULL);
EXTERN int debug_level INIT(0);
EXTERN bool asinfo_lookup INIT(false);
EXTERN bool donotverify INIT(false);
EXTERN bool quiet INIT(false);
EXTERN bool iso8601 INIT(false);
EXTERN bool multiple INIT(false);
EXTERN bool psys_specified INIT(false);
EXTERN int transforms INIT(0);
EXTERN long max_count INIT(0L);
EXTERN sort_e sorting INIT(no_sort);
EXTERN batch_e batching INIT(batch_none);
EXTERN present_e presentation INIT(pres_none);
EXTERN char *presentation_name INIT(NULL);
EXTERN presenter_ct presenter INIT(NULL);
EXTERN struct timeval startup_time INIT({});
EXTERN int exit_code INIT(0);
EXTERN long curl_ipresolve INIT(CURL_IPRESOLVE_WHATEVER);
EXTERN long curl_timeout INIT(0L);
EXTERN deduper_t minimal_deduper INIT(NULL);
/* deduplication table size. trades memory efficiency (an array of this many
* pointers will be allocated under '-p minimal' conditions) against run time
* efficiency (the string's hash will be modulo this size).
*/
EXTERN const size_t minimal_modulus INIT(10000);
#undef INIT
#undef EXTERN
__attribute__((noreturn)) void my_exit(int);
__attribute__((noreturn)) void my_panic(bool, const char *);
/* my_logf -- annotate to stderr with program name and current time */
static inline void
my_logf(const char *fmtstr, ...) {
va_list ap;
va_start(ap, fmtstr);
fprintf(stderr, "%s [%s]: ", program_name, timeval_str(NULL, true));
vfprintf(stderr, fmtstr, ap);
putc('\n', stderr);
}
#endif /*GLOBALS_H_INCLUDED*/