+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]
/*%
* 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;
* Not used in dig.
* XXX print_trying
*/
-void
+static void
trying(char *frm, dig_lookup_t *lookup) {
UNUSED(frm);
UNUSED(lookup);
/*
* 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;
* 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];
}
}
-/*% 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)
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)
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);
}
"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);
}
}
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);
/* 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));
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);
}
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)) {
l->trace_root = ISC_FALSE;
usesearch = ISC_FALSE;
} else {
- printmessage(query, msg, ISC_TRUE);
+ dighost_printmessage(query, msg, ISC_TRUE);
}
}
}
} 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)
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;
}
}
-void
+static void
trying(char *frm, dig_lookup_t *lookup) {
UNUSED(lookup);
}
}
-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;
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);
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
return totext.deconsttext;
}
-void
-dighost_shutdown(void) {
+static void
+query_finished(void) {
isc_event_t *event = global_event;
flush_lookup_list();
return (ISC_R_SUCCESS);
}
-void
+static void
received(int bytes, isc_sockaddr_t *from, dig_query_t *query)
{
UNUSED(bytes);
UNUSED(query);
}
-void
+static void
trying(char *frm, dig_lookup_t *lookup) {
UNUSED(frm);
UNUSED(lookup);
-
}
static void
}
}
-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];
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");