diff -ur asterisk-editline/Makefile asterisk-1.2.4.dfsg/Makefile
--- asterisk-editline/Makefile	2005-12-05 08:47:51.000000000 +0200
+++ asterisk-1.2.4.dfsg/Makefile	2006-03-02 21:50:34.000000000 +0200
@@ -302,7 +302,11 @@
 
 endif # WITHOUT_ZAPTEL
 
+USE_READLINE=1
+
+ifdef USE_READLINE
 LIBEDIT=editline/libedit.a
+endif
 
 ifneq ($(wildcard .version),)
   ASTERISKVERSION:=$(shell cat .version)
@@ -398,6 +402,10 @@
   CFLAGS+=$(ASTCFLAGS)
 endif
 
+ifdef USE_READLINE
+CFLAGS+=-DSYSTEM_READLINE
+endif
+
 # This is used when generating the doxygen documentation
 ifneq ($(wildcard /usr/local/bin/dot)$(wildcard /usr/bin/dot),)
   HAVEDOT=yes
@@ -407,6 +415,8 @@
 
 LIBS+=-lssl
 
+LIBS+=-lreadline
+
 INSTALL=install
 
 _all: all
@@ -510,7 +520,7 @@
 cygwin_a:
 	$(MAKE) -C cygwin all
 
-asterisk: $(CYGLOADER) editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
+asterisk: $(CYGLOADER) $(EDITLINE) db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
 	build_tools/make_build_h > include/asterisk/build.h.tmp
 	if cmp -s include/asterisk/build.h.tmp include/asterisk/build.h ; then echo ; else \
 		mv include/asterisk/build.h.tmp include/asterisk/build.h ; \
diff -ur asterisk-editline/asterisk.c asterisk-1.2.4.dfsg/asterisk.c
--- asterisk-editline/asterisk.c	2006-01-25 00:55:32.000000000 +0200
+++ asterisk-1.2.4.dfsg/asterisk.c	2006-02-28 07:36:35.000000000 +0200
@@ -107,7 +107,12 @@
 #include "asterisk/file.h"
 #include "asterisk/io.h"
 #include "asterisk/lock.h"
+#ifdef SYSTEM_READLINE
+#include <readline/readline.h>
+#include <readline/history.h>
+#else
 #include "editline/histedit.h"
+#endif
 #include "asterisk/config.h"
 #include "asterisk/version.h"
 #include "asterisk/linkedlists.h"
@@ -190,17 +195,25 @@
 time_t ast_startuptime;
 time_t ast_lastreloadtime;
 
+#ifdef SYSTEM_READLINE
+int is_rl_initilized = 0;
+#else
 static History *el_hist = NULL;
 static EditLine *el = NULL;
+#endif
 static char *remotehostname;
 
 struct console consoles[AST_MAX_CONNECTS];
 
 char defaultlanguage[MAX_LANGUAGE] = DEFAULT_LANGUAGE;
 
+#ifdef SYSTEM_READLINE
+static inline char* history_filename(char* buf);
+#else
 static int ast_el_add_history(char *);
 static int ast_el_read_history(char *);
 static int ast_el_write_history(char *);
+#endif
 
 char ast_config_AST_CONFIG_DIR[AST_CONFIG_MAX_PATH];
 char ast_config_AST_CONFIG_FILE[AST_CONFIG_MAX_PATH];
@@ -875,6 +888,15 @@
 		}
 	}
 	if (option_console || option_remote) {
+#ifdef SYSTEM_READLINE
+		if (!ast_strlen_zero(history_filename(filename))) {
+			int rc = write_history(filename);
+			if ((rc != 0) && option_verbose && option_console) {
+				ast_verbose("Failed to write history file %s: %s\n",
+					filename, strerror(rc));
+			}
+		}
+#else
 		if (getenv("HOME")) 
 			snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
 		if (!ast_strlen_zero(filename))
@@ -883,6 +905,7 @@
 			el_end(el);
 		if (el_hist != NULL)
 			history_end(el_hist);
+#endif
 	}
 	if (option_verbose)
 		ast_verbose("Executing last minute cleanups\n");
@@ -990,7 +1013,11 @@
 	fflush(stdout);
 	/* Called when readline data is available */
 	if (s && !ast_all_zeros(s))
+#ifdef SYSTEM_READLINE
+		add_history(s);
+#else
 		ast_el_add_history(s);
+#endif
 	/* Give the console access to the shell */
 	if (s) {
 		/* The real handler for bang */
@@ -1010,7 +1037,11 @@
 	int ret = 0;
 	/* Called when readline data is available */
 	if (s && !ast_all_zeros(s))
+#ifdef SYSTEM_READLINE
+		add_history(s);
+#else
 		ast_el_add_history(s);
+#endif
 	/* Give the console access to the shell */
 	if (s) {
 		/* The real handler for bang */
@@ -1242,7 +1273,7 @@
 #endif /* ! LOW_MEMORY */
 };
 
-static int ast_el_read_char(EditLine *el, char *cp)
+static int read_char(char *cp)
 {
 	int num_read=0;
 	int lastpos=0;
@@ -1309,7 +1340,11 @@
 				write(STDOUT_FILENO, "\r", 1);
 			write(STDOUT_FILENO, buf, res);
 			if ((buf[res-1] == '\n') || (buf[res-2] == '\n')) {
+#ifdef SYSTEM_READLINE
+				rl_redisplay(); /* TODO: too many refresh-s? */
+#else
 				*cp = CC_REFRESH;
+#endif
 				return(1);
 			} else {
 				lastpos = 1;
@@ -1321,7 +1356,13 @@
 	return (0);
 }
 
-static char *cli_prompt(EditLine *el)
+#ifndef SYSTEM_READLINE
+static int ast_el_read_char(EditLine *el, char *cp) {
+	return read_char(cp);
+}
+#endif
+
+static char *cli_prompt(void)
 {
 	static char prompt[200];
 	char *pfmt;
@@ -1466,6 +1507,7 @@
 	return(prompt);	
 }
 
+#ifndef SYSTEM_READLINE
 static char **ast_el_strtoarr(char *buf)
 {
 	char **match_list = NULL, *retstr;
@@ -1743,6 +1785,46 @@
 
 	return ret;
 }
+#endif
+
+/***********************************
+ * Readline functions
+ * ********************************/
+
+#define FILENAME_LEN 80
+/* returns the history filename. Caller should allocate buffer 
+ *
+ * filename is set to "" in case of an empty $HOME
+ * */
+static inline char* history_filename(char* buf)
+{
+	if (getenv("HOME")) {
+		snprintf(buf, FILENAME_LEN, "%s/.asterisk_history", getenv("HOME"));
+	} else {
+		buf[0] = '\0';
+	}
+	return buf;
+}
+
+/* Initilize all readline-related  Does nothing if called after first init
+ * and thus can safely be called again (once the first one has ended)
+ *
+ * TODO: where can it fail? return an error? */
+static int init_readline(void)
+{
+	static int is_init = 0; /* Did we get here already? */
+	char filename[FILENAME_LEN];
+	
+	if (is_init)
+		return is_init;
+
+	using_history();
+	read_history(history_filename(filename));
+	
+	is_init = 1;
+	
+	return is_init;
+}
 
 static void ast_remotecontrol(char * data)
 {
@@ -1780,6 +1862,9 @@
 	fdprint(ast_consock, tmp);
 	ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid);
 	remotehostname = hostname;
+#ifdef SYSTEM_READLINE
+	init_readline();
+#else
 	if (getenv("HOME")) 
 		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
 	if (el_hist == NULL || el == NULL)
@@ -1789,6 +1874,7 @@
 
 	if (!ast_strlen_zero(filename))
 		ast_el_read_history(filename);
+#endif
 
 	if (option_exec && data) {  /* hack to print output then exit if asterisk -rx is used */
 		char tempchar;
@@ -1797,12 +1883,16 @@
 		fds[0].events = POLLIN;
 		fds[0].revents = 0;
 		while(poll(fds, 1, 100) > 0) {
-			ast_el_read_char(el, &tempchar);
+			read_char(&tempchar);
 		}
 		return;
 	}
 	for(;;) {
+#ifdef SYSTEM_READLINE
+		ebuf = readline(cli_prompt());
+#else
 		ebuf = (char *)el_gets(el, &num);
+#endif
 
 		if (!ast_strlen_zero(ebuf)) {
 			if (ebuf[strlen(ebuf)-1] == '\n')
@@ -2221,11 +2311,15 @@
 	
 
 	if (option_console) {
+#ifdef SYSTEM_READLINE
+		init_readline();
+#else
 		if (el_hist == NULL || el == NULL)
 			ast_el_initialize();
 
 		if (!ast_strlen_zero(filename))
 			ast_el_read_history(filename);
+#endif
 	}
 
 	if (ast_tryconnect()) {
@@ -2400,7 +2494,11 @@
 		set_title(title);
 
 		for (;;) {
+#ifdef SYSTEM_READLINE
+			buf = readline(cli_prompt());
+#else
 			buf = (char *)el_gets(el, &num);
+#endif
 			if (buf) {
 				if (buf[strlen(buf)-1] == '\n')
 					buf[strlen(buf)-1] = '\0';
diff -ur asterisk-editline/cli.c asterisk-1.2.4.dfsg/cli.c
--- asterisk-editline/cli.c	2005-12-26 20:19:12.000000000 +0200
+++ asterisk-1.2.4.dfsg/cli.c	2006-02-26 21:34:35.000000000 +0200
@@ -44,7 +44,11 @@
 #include "asterisk/utils.h"
 #include "asterisk/lock.h"
 /* For rl_filename_completion */
+#ifdef SYSTEM_READLINE
+#include <readline/readline.h>
+#else
 #include "editline/readline/readline.h"
+#endif
 /* For module directory */
 #include "asterisk/version.h"
 
