2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

Merge branch 'ondrej/update-readline-support' into 'main'

Update and cleanup the readline library support

See merge request isc-projects/bind9!3942
This commit is contained in:
Ondřej Surý 2020-08-18 09:05:51 +00:00
commit 62c448beaf
10 changed files with 128 additions and 137 deletions

View File

@ -1,3 +1,6 @@
5490. [func] Refactor the readline support to use pkg-config and
add support for editline library. [GL !3942]
5489. [bug] Named failed to reject some invalid records resulting
in records that, after being printed, could not be
loaded or would result in DNSSEC validation failures

View File

@ -33,6 +33,11 @@ LIBISC_CFLAGS += \
$(LIBXML2_CFLAGS)
endif HAVE_LIBXML2
if HAVE_READLINE
LIBISC_CFLAGS += \
$(READLINE_CFLAGS)
endif HAVE_READLINE
LIBISC_LIBS = $(top_builddir)/lib/isc/libisc.la
LIBDNS_CFLAGS = \

View File

@ -25,6 +25,10 @@ libdighost_la_SOURCES = \
bin_PROGRAMS = dig host nslookup
nslookup_LDADD = \
$(LDADD) \
$(READLINE_LIB)
nslookup_LDADD = \
$(LDADD)
if HAVE_READLINE
nslookup_LDADD += \
$(READLINE_LIBS)
endif HAVE_READLINE

View File

@ -22,6 +22,7 @@
#include <isc/netaddr.h>
#include <isc/parseint.h>
#include <isc/print.h>
#include <isc/readline.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/util.h>
@ -38,27 +39,6 @@
#include "dighost.h"
#if defined(HAVE_READLINE)
#if defined(HAVE_EDIT_READLINE_READLINE_H)
#include <edit/readline/readline.h>
#if defined(HAVE_EDIT_READLINE_HISTORY_H)
#include <edit/readline/history.h>
#endif /* if defined(HAVE_EDIT_READLINE_HISTORY_H) */
#elif defined(HAVE_EDITLINE_READLINE_H)
#include <editline/readline.h>
#elif defined(HAVE_READLINE_READLINE_H)
/* Prevent deprecated functions being declared. */
#define _FUNCTION_DEF 1
/* Ensure rl_message() gets prototype. */
#define USE_VARARGS 1
#define PREFER_STDARG 1
#include <readline/readline.h>
#if defined(HAVE_READLINE_HISTORY_H)
#include <readline/history.h>
#endif /* if defined(HAVE_READLINE_HISTORY_H) */
#endif /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
#endif /* if defined(HAVE_READLINE) */
static bool short_form = true, tcpmode = false, tcpmode_set = false,
identify = false, stats = true, comments = true,
section_question = true, section_answer = true,
@ -853,38 +833,27 @@ do_next_command(char *input) {
static void
get_next_command(void) {
char *buf;
char *ptr;
char cmdlinebuf[COMMSIZE];
char *cmdline, *ptr = NULL;
fflush(stdout);
buf = isc_mem_allocate(mctx, COMMSIZE);
isc_app_block();
if (interactive) {
#ifdef HAVE_READLINE
ptr = readline("> ");
if (ptr != NULL) {
cmdline = ptr = readline("> ");
if (ptr != NULL && *ptr != 0) {
add_history(ptr);
}
#else /* ifdef HAVE_READLINE */
fprintf(stderr, "> ");
fflush(stderr);
ptr = fgets(buf, COMMSIZE, stdin);
#endif /* ifdef HAVE_READLINE */
} else {
ptr = fgets(buf, COMMSIZE, stdin);
cmdline = fgets(cmdlinebuf, COMMSIZE, stdin);
}
isc_app_unblock();
if (ptr == NULL) {
if (cmdline == NULL) {
in_use = false;
} else {
do_next_command(ptr);
do_next_command(cmdline);
}
#ifdef HAVE_READLINE
if (interactive) {
if (ptr != NULL) {
free(ptr);
}
#endif /* ifdef HAVE_READLINE */
isc_mem_free(mctx, buf);
}
ISC_NORETURN static void

View File

@ -18,8 +18,12 @@ LDADD = \
$(LIBISCCFG_LIBS) \
$(LIBIRS_LIBS) \
$(LIBBIND9_LIBS) \
$(READLINE_LIB) \
$(GSSAPI_LIBS) \
$(KRB5_LIBS)
if HAVE_READLINE
LDADD += \
$(READLINE_LIBS)
endif
bin_PROGRAMS = nsupdate

View File

@ -36,6 +36,7 @@
#include <isc/portset.h>
#include <isc/print.h>
#include <isc/random.h>
#include <isc/readline.h>
#include <isc/region.h>
#include <isc/sockaddr.h>
#include <isc/socket.h>
@ -94,25 +95,6 @@
#include <bind9/getaddresses.h>
#if defined(HAVE_READLINE)
#if defined(HAVE_EDIT_READLINE_READLINE_H)
#include <edit/readline/readline.h>
#if defined(HAVE_EDIT_READLINE_HISTORY_H)
#include <edit/readline/history.h>
#endif /* if defined(HAVE_EDIT_READLINE_HISTORY_H) */
#elif defined(HAVE_EDITLINE_READLINE_H)
#include <editline/readline.h>
#else /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
/* Prevent deprecated functions being declared. */
#define _FUNCTION_DEF 1
/* Ensure rl_message() gets prototype. */
#define USE_VARARGS 1
#define PREFER_STDARG 1
#include <readline/history.h>
#include <readline/readline.h>
#endif /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
#endif /* if defined(HAVE_READLINE) */
#define MAXCMD (128 * 1024)
#define MAXWIRE (64 * 1024)
#define PACKETSIZE ((64 * 1024) - 1)
@ -2295,20 +2277,14 @@ static uint16_t
get_next_command(void) {
uint16_t result = STATUS_QUIT;
char cmdlinebuf[MAXCMD];
char *cmdline;
char *cmdline = NULL, *ptr = NULL;
isc_app_block();
if (interactive) {
#ifdef HAVE_READLINE
cmdline = readline("> ");
if (cmdline != NULL) {
add_history(cmdline);
cmdline = ptr = readline("> ");
if (ptr != NULL && *ptr != 0) {
add_history(ptr);
}
#else /* ifdef HAVE_READLINE */
fprintf(stdout, "> ");
fflush(stdout);
cmdline = fgets(cmdlinebuf, MAXCMD, input);
#endif /* ifdef HAVE_READLINE */
} else {
cmdline = fgets(cmdlinebuf, MAXCMD, input);
}
@ -2324,11 +2300,10 @@ get_next_command(void) {
(void)nsu_strsep(&tmp, "\r\n");
result = do_next_command(cmdline);
}
#ifdef HAVE_READLINE
if (interactive) {
free(cmdline);
if (ptr != NULL) {
free(ptr);
}
#endif /* ifdef HAVE_READLINE */
return (result);
}

View File

@ -976,66 +976,39 @@ AS_IF([test "$enable_tcp_fastopen" = "yes"],
#
AC_CHECK_FUNCS([strlcpy strlcat])
AC_SUBST(READLINE_LIB)
AC_ARG_WITH(readline,
AS_HELP_STRING([--with-readline[=LIBSPEC]],
[specify readline library [default auto]]),
use_readline="$withval", use_readline="auto")
case "$use_readline" in
no) ;;
*)
saved_LIBS="$LIBS"
case "$use_readline" in
yes|auto) try_readline="-ledit"; or_readline="-lreadline" ;;
*) try_readline="$use_readline"
esac
for readline in "$try_readline" $or_readline
do
LIBS="$readline"
AC_MSG_NOTICE(checking for readline with $readline)
AC_CHECK_FUNCS(readline)
if test "yes" = "$ac_cv_func_readline"
then
READLINE_LIB="$readline"
break
fi
for lib in -lterminfo -ltermcap -lncurses -lcurses
do
AC_MSG_NOTICE(checking for readline with $readline $lib)
unset ac_cv_func_readline
LIBS="$readline $lib"
AC_CHECK_FUNCS(readline)
if test "yes" = "$ac_cv_func_readline"
then
READLINE_LIB="$readline $lib"
break
fi
done
if test "yes" = "$ac_cv_func_readline"
then
break
fi
done
if test "auto" != "$use_readline" &&
test "X$READLINE_LIB" = "X"
then
AC_MSG_ERROR([The readline library was not found.])
fi
LIBS="$saved_LIBS"
;;
esac
if test "yes" = "$ac_cv_func_readline"
then
case "$READLINE_LIB" in
*edit*)
AC_CHECK_HEADERS(editline/readline.h)
AC_CHECK_HEADERS(edit/readline/readline.h)
AC_CHECK_HEADERS(edit/readline/history.h)
;;
esac
AC_CHECK_HEADERS(readline/readline.h)
AC_CHECK_HEADERS(readline/history.h)
fi
#
# Check for readline support
#
AC_ARG_WITH([readline],
[AS_HELP_STRING([--with-readline=yes|no|libedit|readline],
[specify readline library [default auto]])],
[], [with_readline="auto"])
AS_CASE([$with_readline],
[no],[],
[auto],
[PKG_CHECK_MODULES([READLINE], [libedit],
[AC_DEFINE([HAVE_READLINE_LIBEDIT], [1], [Build with libedit support])],
[PKG_CHECK_MODULES([READLINE], [editline],
[AC_DEFINE([HAVE_READLINE_EDITLINE], [1], [Build with editline support.])],
[PKG_CHECK_MODULES([READLINE], [readline],
[AC_DEFINE([HAVE_READLINE_READLINE], [1], [Build with readline support.])],
[AS_IF([test "$with_readline" = "yes"],
[AC_MSG_ERROR([readline support requested, but none of the libraries have been found.])])])])])],
[libedit],
[PKG_CHECK_MODULES([READLINE], [libedit],
[AC_DEFINE([HAVE_READLINE_LIBEDIT], [1], [Build with libedit support])])],
[editline],
[PKG_CHECK_MODULES([READLINE], [editline],
[AC_DEFINE([HAVE_READLINE_EDITLINE], [1], [Build with editline support])])],
[readline],
[PKG_CHECK_MODULES([READLINE], [readline],
[AC_DEFINE([HAVE_READLINE_READLINE], [1], [Build with readline support])])],
[AC_MSG_ERROR([Unknown readline '$with_readline' library requested.])])
AM_CONDITIONAL([HAVE_READLINE], [test -n "$READLINE_LIBS"])
AC_SUBST([READLINE_CFLAGS])
AC_SUBST([READLINE_LIBS])
#
# Security Stuff

View File

@ -66,6 +66,7 @@ libisc_la_HEADERS = \
include/isc/radix.h \
include/isc/random.h \
include/isc/ratelimiter.h \
include/isc/readline.h \
include/isc/refcount.h \
include/isc/regex.h \
include/isc/region.h \

View File

@ -0,0 +1,56 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#pragma once
/*
* A little wrapper around readline(), add_history() and free() to make using
* the readline code simpler.
*/
#if defined(HAVE_READLINE_LIBEDIT)
#include <editline/readline.h>
#elif defined(HAVE_READLINE_EDITLINE)
#include <editline.h>
#elif defined(HAVE_READLINE_READLINE)
/* Prevent deprecated functions being declared. */
#define _FUNCTION_DEF 1
/* Ensure rl_message() gets prototype. */
#define USE_VARARGS 1
#define PREFER_STDARG 1
#include <readline/history.h>
#include <readline/readline.h>
#endif
#if !defined(HAVE_READLINE_LIBEDIT) && !defined(HAVE_READLINE_EDITLINE) && \
!defined(HAVE_READLINE_READLINE)
#include <stdio.h>
#include <stdlib.h>
#define RL_MAXCMD (128 * 1024)
static inline char *
readline(const char *prompt) {
char *line, *buf = malloc(RL_MAXCMD);
fprintf(stdout, "%s", prompt);
fflush(stdout);
line = fgets(buf, RL_MAXCMD, stdin);
if (line == NULL) {
free(buf);
return (NULL);
}
return (buf);
};
#define add_history(line)
#endif

View File

@ -1832,6 +1832,7 @@
./lib/isc/include/isc/radix.h C 2007,2008,2013,2014,2016,2018,2019,2020
./lib/isc/include/isc/random.h C 1999,2000,2001,2004,2005,2006,2007,2009,2014,2016,2017,2018,2019,2020
./lib/isc/include/isc/ratelimiter.h C 1999,2000,2001,2002,2004,2005,2006,2007,2009,2014,2016,2018,2019,2020
./lib/isc/include/isc/readline.h C 2020
./lib/isc/include/isc/refcount.h C 2001,2003,2004,2005,2006,2007,2009,2016,2017,2018,2019,2020
./lib/isc/include/isc/regex.h C 2013,2016,2018,2019,2020
./lib/isc/include/isc/region.h C 1998,1999,2000,2001,2002,2004,2005,2006,2007,2013,2016,2018,2019,2020