mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 05:30:17 +01:00
cli: Provide optional support for libedit instead of readline
The libreadline starting from version 6 is licensed as GPLv3. For some use cases it is not acceptable to use this license. In the NetworkManager the libreadline is used by nmcli. This change allows using libedit instead of libreadline. Following adjustments were made: 1. The history_set_history_state() is not supported in the libedit. Instead, the where_history() with remove_history() were used to remove the history content if needed. 2. rl_complete_with_tilde_expansion - it is the binary flag used only when one wants to have the expansion support. The libedit is not supporting and hence exporting this flag.
This commit is contained in:
parent
823445021a
commit
d1dad6ae27
5 changed files with 42 additions and 4 deletions
|
|
@ -7,9 +7,12 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if HAVE_EDITLINE_READLINE
|
||||
#include <editline/readline.h>
|
||||
#else
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
#endif
|
||||
#include "common.h"
|
||||
#include "utils.h"
|
||||
#include "libnmc-base/nm-secret-agent-simple.h"
|
||||
|
|
|
|||
|
|
@ -10,9 +10,12 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <readline/readline.h>
|
||||
#if HAVE_EDITLINE_READLINE
|
||||
#include <editline/readline.h>
|
||||
#else
|
||||
#include <readline/history.h>
|
||||
|
||||
#include <readline/readline.h>
|
||||
#endif
|
||||
#include "libnm-client-aux-extern/nm-libnm-aux.h"
|
||||
|
||||
#include "libnmc-base/nm-vpn-helpers.h"
|
||||
|
|
@ -1007,10 +1010,14 @@ nmc_readline_echo(const NmcConfig *nmc_config, gboolean echo_on, const char *pro
|
|||
va_list args;
|
||||
gs_free char *prompt = NULL;
|
||||
char * str;
|
||||
#if HAVE_READLINE_HISTORY
|
||||
nm_auto_free HISTORY_STATE *saved_history = NULL;
|
||||
HISTORY_STATE passwd_history = {
|
||||
0,
|
||||
};
|
||||
#else
|
||||
int start, curpos;
|
||||
#endif
|
||||
|
||||
va_start(args, prompt_fmt);
|
||||
prompt = g_strdup_vprintf(prompt_fmt, args);
|
||||
|
|
@ -1020,8 +1027,12 @@ nmc_readline_echo(const NmcConfig *nmc_config, gboolean echo_on, const char *pro
|
|||
|
||||
/* Hide the actual password */
|
||||
if (!echo_on) {
|
||||
#if HAVE_READLINE_HISTORY
|
||||
saved_history = history_get_history_state();
|
||||
history_set_history_state(&passwd_history);
|
||||
#else
|
||||
start = where_history();
|
||||
#endif
|
||||
/* stifling history is important as it tells readline to
|
||||
* not store anything, otherwise sensitive data could be
|
||||
* leaked */
|
||||
|
|
@ -1034,7 +1045,13 @@ nmc_readline_echo(const NmcConfig *nmc_config, gboolean echo_on, const char *pro
|
|||
/* Restore the non-hiding behavior */
|
||||
if (!echo_on) {
|
||||
rl_redisplay_function = rl_redisplay;
|
||||
#if HAVE_READLINE_HISTORY
|
||||
history_set_history_state(saved_history);
|
||||
#else
|
||||
curpos = where_history();
|
||||
while (curpos > start)
|
||||
remove_history(curpos--);
|
||||
#endif
|
||||
}
|
||||
|
||||
return str;
|
||||
|
|
|
|||
|
|
@ -11,8 +11,12 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#if HAVE_EDITLINE_READLINE
|
||||
#include <editline/readline.h>
|
||||
#else
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "libnm-glib-aux/nm-dbus-aux.h"
|
||||
|
|
@ -6453,8 +6457,10 @@ gen_property_values(const char *text, int state)
|
|||
return nmc_rl_gen_func_basic(text, state, avals);
|
||||
}
|
||||
|
||||
#if !HAVE_EDITLINE_READLINE
|
||||
/* from readline */
|
||||
extern int rl_complete_with_tilde_expansion;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Attempt to complete on the contents of TEXT. START and END show the
|
||||
|
|
@ -6482,8 +6488,10 @@ nmcli_editor_tab_completion(const char *text, int start, int end)
|
|||
/* Disable default filename completion */
|
||||
rl_attempted_completion_over = 1;
|
||||
|
||||
#if !HAVE_EDITLINE_READLINE
|
||||
/* Enable tilde expansion when filenames are completed */
|
||||
rl_complete_with_tilde_expansion = 1;
|
||||
#endif
|
||||
|
||||
/* Filter out possible ANSI color escape sequences */
|
||||
prompt_tmp = nmc_filter_out_colors((const char *) rl_prompt);
|
||||
|
|
@ -9617,8 +9625,10 @@ nmcli_con_tab_completion(const char *text, int start, int end)
|
|||
nmc_tab_completion.words = _meta_abstract_complete(info, text);
|
||||
generator_func = _meta_abstract_generator;
|
||||
} else if (nm_streq0(rl_prompt, PROMPT_IMPORT_FILE)) {
|
||||
rl_attempted_completion_over = 0;
|
||||
rl_attempted_completion_over = 0;
|
||||
#if !HAVE_EDITLINE_READLINE
|
||||
rl_complete_with_tilde_expansion = 1;
|
||||
#endif
|
||||
} else if (nm_streq0(rl_prompt, PROMPT_VPN_CONNECTION)) {
|
||||
generator_func = gen_vpn_ids;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,11 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if HAVE_EDITLINE_READLINE
|
||||
#include <editline/readline.h>
|
||||
#else
|
||||
#include <readline/readline.h>
|
||||
#endif
|
||||
#include <linux/if_ether.h>
|
||||
|
||||
#include "libnm-glib-aux/nm-secret-utils.h"
|
||||
|
|
|
|||
|
|
@ -14,8 +14,12 @@
|
|||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <locale.h>
|
||||
#if HAVE_EDITLINE_READLINE
|
||||
#include <editline/readline.h>
|
||||
#else
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#endif
|
||||
|
||||
#include "libnmc-base/nm-client-utils.h"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue