mirror of
https://github.com/isc-projects/bind9.git
synced 2026-03-03 05:50:39 -05:00
[master] split up main and add callback function pointers to support iOS
4677. [port] Split up the main function in dig to better support the iOS app version. [RT #45508]
This commit is contained in:
parent
4e22c61020
commit
b2bf8de2a3
6 changed files with 154 additions and 44 deletions
3
CHANGES
3
CHANGES
|
|
@ -1,3 +1,6 @@
|
|||
4677. [port] Split up the main function in dig to better support
|
||||
the iOS app version. [RT #45508]
|
||||
|
||||
4676. [cleanup] Allow BIND to be built using OpenSSL 1.0.X with
|
||||
deprecated functions removed. [RT #45706]
|
||||
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ help(void) {
|
|||
/*%
|
||||
* Callback from dighost.c to print the received message.
|
||||
*/
|
||||
void
|
||||
static void
|
||||
received(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
|
||||
isc_uint64_t diff;
|
||||
time_t tnow;
|
||||
|
|
@ -294,7 +294,7 @@ received(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
|
|||
* Not used in dig.
|
||||
* XXX print_trying
|
||||
*/
|
||||
void
|
||||
static void
|
||||
trying(char *frm, dig_lookup_t *lookup) {
|
||||
UNUSED(frm);
|
||||
UNUSED(lookup);
|
||||
|
|
@ -424,7 +424,7 @@ isdotlocal(dns_message_t *msg) {
|
|||
/*
|
||||
* Callback from dighost.c to print the reply from a server
|
||||
*/
|
||||
isc_result_t
|
||||
static isc_result_t
|
||||
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
|
||||
isc_result_t result;
|
||||
dns_messagetextflag_t flags;
|
||||
|
|
@ -2089,8 +2089,8 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
|
|||
* Here, we're possibly reading from a batch file, then shutting down
|
||||
* for real if there's nothing in the batch file to read.
|
||||
*/
|
||||
void
|
||||
dighost_shutdown(void) {
|
||||
static void
|
||||
query_finished(void) {
|
||||
char batchline[MXNAME];
|
||||
int bargc;
|
||||
char *bargv[16];
|
||||
|
|
@ -2136,23 +2136,38 @@ dighost_shutdown(void) {
|
|||
}
|
||||
}
|
||||
|
||||
/*% Main processing routine for dig */
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
void dig_setup(int argc, char **argv)
|
||||
{
|
||||
isc_result_t result;
|
||||
|
||||
ISC_LIST_INIT(lookup_list);
|
||||
ISC_LIST_INIT(server_list);
|
||||
ISC_LIST_INIT(search_list);
|
||||
|
||||
debug("main()");
|
||||
debug("dig_setup()");
|
||||
|
||||
/* setup dighost callbacks */
|
||||
dighost_printmessage = printmessage;
|
||||
dighost_received = received;
|
||||
dighost_trying = trying;
|
||||
dighost_shutdown = query_finished;
|
||||
|
||||
progname = argv[0];
|
||||
preparse_args(argc, argv);
|
||||
|
||||
result = isc_app_start();
|
||||
check_result(result, "isc_app_start");
|
||||
|
||||
setup_libs();
|
||||
setup_system(ipv4only, ipv6only);
|
||||
parse_args(ISC_FALSE, ISC_FALSE, argc, argv);
|
||||
}
|
||||
|
||||
void dig_query_setup(isc_boolean_t is_batchfile, isc_boolean_t config_only,
|
||||
int argc, char **argv)
|
||||
{
|
||||
debug("dig_query_setup");
|
||||
|
||||
parse_args(is_batchfile, config_only, argc, argv);
|
||||
if (keyfile[0] != 0)
|
||||
setup_file_key();
|
||||
else if (keysecret[0] != 0)
|
||||
|
|
@ -2161,9 +2176,25 @@ main(int argc, char **argv) {
|
|||
set_search_domain(domainopt);
|
||||
usesearch = ISC_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void dig_startup() {
|
||||
isc_result_t result;
|
||||
|
||||
debug("dig_startup()");
|
||||
|
||||
result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
|
||||
check_result(result, "isc_app_onrun");
|
||||
isc_app_run();
|
||||
}
|
||||
|
||||
void dig_query_start()
|
||||
{
|
||||
start_lookup();
|
||||
}
|
||||
|
||||
void
|
||||
dig_shutdown() {
|
||||
destroy_lookup(default_lookup);
|
||||
if (batchname != NULL) {
|
||||
if (batchfp != stdin)
|
||||
|
|
@ -2173,5 +2204,16 @@ main(int argc, char **argv) {
|
|||
cancel_all();
|
||||
destroy_libs();
|
||||
isc_app_finish();
|
||||
}
|
||||
|
||||
/*% Main processing routine for dig */
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
|
||||
dig_setup(argc, argv);
|
||||
dig_query_setup(ISC_FALSE, ISC_FALSE, argc, argv);
|
||||
dig_startup();
|
||||
dig_shutdown();
|
||||
|
||||
return (exitcode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,6 +199,23 @@ dig_lookup_t *current_lookup = NULL;
|
|||
"isc_mutex_unlock");\
|
||||
}
|
||||
|
||||
/* dynamic callbacks */
|
||||
|
||||
isc_result_t
|
||||
(*dighost_printmessage)(dig_query_t *query, dns_message_t *msg,
|
||||
isc_boolean_t headers);
|
||||
|
||||
void
|
||||
(*dighost_received)(int bytes, isc_sockaddr_t *from, dig_query_t *query);
|
||||
|
||||
void
|
||||
(*dighost_trying)(char *frm, dig_lookup_t *lookup);
|
||||
|
||||
void
|
||||
(*dighost_shutdown)(void);
|
||||
|
||||
/* forward declarations */
|
||||
|
||||
static void
|
||||
cancel_lookup(dig_lookup_t *lookup);
|
||||
|
||||
|
|
@ -2196,7 +2213,7 @@ setup_lookup(dig_lookup_t *lookup) {
|
|||
}
|
||||
}
|
||||
dns_name_format(lookup->name, store, sizeof(store));
|
||||
trying(store, lookup);
|
||||
dighost_trying(store, lookup);
|
||||
INSIST(dns_name_isabsolute(lookup->name));
|
||||
|
||||
isc_random_get(&id);
|
||||
|
|
@ -2532,8 +2549,8 @@ setup_lookup(dig_lookup_t *lookup) {
|
|||
/* XXX qrflag, print_query, etc... */
|
||||
if (!ISC_LIST_EMPTY(lookup->q) && lookup->qr) {
|
||||
extrabytes = 0;
|
||||
printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg,
|
||||
ISC_TRUE);
|
||||
dighost_printmessage(ISC_LIST_HEAD(lookup->q),
|
||||
lookup->sendmsg, ISC_TRUE);
|
||||
if (lookup->stats)
|
||||
printf(";; QUERY SIZE: %u\n\n",
|
||||
isc_buffer_usedlength(&lookup->renderbuf));
|
||||
|
|
@ -3359,7 +3376,7 @@ check_for_more_data(dig_query_t *query, dns_message_t *msg,
|
|||
launch_next_query(query, ISC_FALSE);
|
||||
return (ISC_FALSE);
|
||||
doexit:
|
||||
received(sevent->n, &sevent->address, query);
|
||||
dighost_received(sevent->n, &sevent->address, query);
|
||||
return (ISC_TRUE);
|
||||
}
|
||||
|
||||
|
|
@ -3861,18 +3878,19 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
|||
if (msg->rcode == dns_rcode_nxdomain &&
|
||||
(l->origin != NULL || l->need_search)) {
|
||||
if (!next_origin(query->lookup) || showsearch) {
|
||||
printmessage(query, msg, ISC_TRUE);
|
||||
received(b->used, &sevent->address, query);
|
||||
dighost_printmessage(query, msg, ISC_TRUE);
|
||||
dighost_received(b->used, &sevent->address,
|
||||
query);
|
||||
}
|
||||
} else if (!l->trace && !l->ns_search_only) {
|
||||
printmessage(query, msg, ISC_TRUE);
|
||||
dighost_printmessage(query, msg, ISC_TRUE);
|
||||
} else if (l->trace) {
|
||||
int nl = 0;
|
||||
int count = msg->counts[DNS_SECTION_ANSWER];
|
||||
|
||||
debug("in TRACE code");
|
||||
if (!l->ns_search_only)
|
||||
printmessage(query, msg, ISC_TRUE);
|
||||
dighost_printmessage(query, msg, ISC_TRUE);
|
||||
|
||||
l->rdtype = l->qrdtype;
|
||||
if (l->trace_root || (l->ns_search_only && count > 0)) {
|
||||
|
|
@ -3903,7 +3921,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
|||
l->trace_root = ISC_FALSE;
|
||||
usesearch = ISC_FALSE;
|
||||
} else {
|
||||
printmessage(query, msg, ISC_TRUE);
|
||||
dighost_printmessage(query, msg, ISC_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3929,7 +3947,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
|||
} else {
|
||||
|
||||
if (msg->rcode == dns_rcode_noerror || l->origin == NULL) {
|
||||
received(b->used, &sevent->address, query);
|
||||
dighost_received(b->used, &sevent->address, query);
|
||||
}
|
||||
|
||||
if (!query->lookup->ns_search_only)
|
||||
|
|
|
|||
|
|
@ -163,12 +163,12 @@ show_usage(void) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
dighost_shutdown(void) {
|
||||
isc_app_shutdown();
|
||||
static void
|
||||
host_shutdown(void) {
|
||||
(void) isc_app_shutdown();
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
received(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
|
||||
isc_time_t now;
|
||||
int diff;
|
||||
|
|
@ -183,7 +183,7 @@ received(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
trying(char *frm, dig_lookup_t *lookup) {
|
||||
UNUSED(lookup);
|
||||
|
||||
|
|
@ -403,7 +403,7 @@ chase_cnamechain(dns_message_t *msg, dns_name_t *qname) {
|
|||
}
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
static isc_result_t
|
||||
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
|
||||
isc_boolean_t did_flag = ISC_FALSE;
|
||||
dns_rdataset_t *opt, *tsig = NULL;
|
||||
|
|
@ -890,6 +890,12 @@ main(int argc, char **argv) {
|
|||
idnoptions = IDN_ASCCHECK;
|
||||
#endif
|
||||
|
||||
/* setup dighost callbacks */
|
||||
dighost_printmessage = printmessage;
|
||||
dighost_received = received;
|
||||
dighost_trying = trying;
|
||||
dighost_shutdown = host_shutdown;
|
||||
|
||||
debug("main()");
|
||||
progname = argv[0];
|
||||
pre_parse_args(argc, argv);
|
||||
|
|
|
|||
|
|
@ -356,37 +356,73 @@ destroy_libs(void);
|
|||
void
|
||||
set_search_domain(char *domain);
|
||||
|
||||
char *
|
||||
next_token(char **stringp, const char *delim);
|
||||
|
||||
/*
|
||||
* Routines to be defined in dig.c, host.c, and nslookup.c.
|
||||
* Routines to be defined in dig.c, host.c, and nslookup.c. and
|
||||
* then assigned to the appropriate function pointer
|
||||
*/
|
||||
isc_result_t
|
||||
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
|
||||
extern isc_result_t
|
||||
(*dighost_printmessage)(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
|
||||
/*%<
|
||||
* Print the final result of the lookup.
|
||||
*/
|
||||
|
||||
void
|
||||
received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
|
||||
extern void
|
||||
(*dighost_received)(int bytes, isc_sockaddr_t *from, dig_query_t *query);
|
||||
/*%<
|
||||
* Print a message about where and when the response
|
||||
* was received from, like the final comment in the
|
||||
* output of "dig".
|
||||
*/
|
||||
|
||||
void
|
||||
trying(char *frm, dig_lookup_t *lookup);
|
||||
extern void
|
||||
(*dighost_trying)(char *frm, dig_lookup_t *lookup);
|
||||
|
||||
void
|
||||
dighost_shutdown(void);
|
||||
|
||||
char *
|
||||
next_token(char **stringp, const char *delim);
|
||||
extern void
|
||||
(*dighost_shutdown)(void);
|
||||
|
||||
void save_opt(dig_lookup_t *lookup, char *code, char *value);
|
||||
|
||||
void setup_file_key(void);
|
||||
void setup_text_key(void);
|
||||
|
||||
/*
|
||||
* Routines exported from dig.c for use by dig for iOS
|
||||
*/
|
||||
|
||||
/*%<
|
||||
* Call once only to set up libraries, parse global
|
||||
* parameters and initial command line query parameters
|
||||
*/
|
||||
void
|
||||
dig_setup(int argc, char **argv);
|
||||
|
||||
/*%<
|
||||
* Call to supply new parameters for the next lookup
|
||||
*/
|
||||
void
|
||||
dig_query_setup(isc_boolean_t, isc_boolean_t, int argc, char **argv);
|
||||
|
||||
/*%<
|
||||
* set the main application event cycle running
|
||||
*/
|
||||
void
|
||||
dig_startup(void);
|
||||
|
||||
/*%<
|
||||
* Initiates the next lookup cycle
|
||||
*/
|
||||
void
|
||||
dig_query_start(void);
|
||||
|
||||
/*%<
|
||||
* Cleans up the application
|
||||
*/
|
||||
void
|
||||
dig_shutdown(void);
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -156,8 +156,8 @@ rcode_totext(dns_rcode_t rcode)
|
|||
return totext.deconsttext;
|
||||
}
|
||||
|
||||
void
|
||||
dighost_shutdown(void) {
|
||||
static void
|
||||
query_finished(void) {
|
||||
isc_event_t *event = global_event;
|
||||
|
||||
flush_lookup_list();
|
||||
|
|
@ -386,7 +386,7 @@ detailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
|||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
received(int bytes, isc_sockaddr_t *from, dig_query_t *query)
|
||||
{
|
||||
UNUSED(bytes);
|
||||
|
|
@ -394,11 +394,10 @@ received(int bytes, isc_sockaddr_t *from, dig_query_t *query)
|
|||
UNUSED(query);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
trying(char *frm, dig_lookup_t *lookup) {
|
||||
UNUSED(frm);
|
||||
UNUSED(lookup);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -426,7 +425,7 @@ chase_cnamechain(dns_message_t *msg, dns_name_t *qname) {
|
|||
}
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
static isc_result_t
|
||||
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
|
||||
char servtext[ISC_SOCKADDR_FORMATSIZE];
|
||||
|
||||
|
|
@ -973,6 +972,12 @@ main(int argc, char **argv) {
|
|||
|
||||
check_ra = ISC_TRUE;
|
||||
|
||||
/* setup dighost callbacks */
|
||||
dighost_printmessage = printmessage;
|
||||
dighost_received = received;
|
||||
dighost_trying = trying;
|
||||
dighost_shutdown = query_finished;
|
||||
|
||||
result = isc_app_start();
|
||||
check_result(result, "isc_app_start");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue