From 11d7f45abd2ab4ba0cc91c6ce946c9ab09f7ddbd Mon Sep 17 00:00:00 2001 From: smorlat Date: Mon, 20 Oct 2008 11:07:58 +0000 Subject: [PATCH] - make readline optional in linphonec. git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@107 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- linphone/console/commands.c | 20 +++-- linphone/console/linphonec.c | 111 ++++++++++++++++++++----- linphone/console/linphonec.h | 3 + linphone/m4/readline.m4 | 57 +++++++------ linphone/mediastreamer2/src/sizeconv.c | 1 - 5 files changed, 136 insertions(+), 56 deletions(-) diff --git a/linphone/console/commands.c b/linphone/console/commands.c index 8ae3a56e3..5191b260d 100644 --- a/linphone/console/commands.c +++ b/linphone/console/commands.c @@ -592,9 +592,13 @@ lpc_cmd_proxy(LinphoneCore *lc, char *args) if (strcmp(arg1,"add")==0) { +#ifdef HAVE_READLINE rl_inhibit_completion=1; +#endif linphonec_proxy_add(lc); +#ifdef HAVE_READLINE rl_inhibit_completion=0; +#endif } else if (strcmp(arg1,"list")==0) { @@ -739,7 +743,7 @@ linphonec_proxy_add(LinphoneCore *lc) */ while (1) { - char *input=readline("Enter proxy sip address: "); + char *input=linphonec_readline("Enter proxy sip address: "); char *clean; if ( ! input ) { @@ -771,7 +775,7 @@ linphonec_proxy_add(LinphoneCore *lc) */ while (1) { - char *input=readline("Your identity for this proxy: "); + char *input=linphonec_readline("Your identity for this proxy: "); char *clean; if ( ! input ) { @@ -803,7 +807,7 @@ linphonec_proxy_add(LinphoneCore *lc) */ while (1) { - char *input=readline("Do you want to register on this proxy (yes/no): "); + char *input=linphonec_readline("Do you want to register on this proxy (yes/no): "); char *clean; if ( ! input ) { @@ -839,7 +843,7 @@ linphonec_proxy_add(LinphoneCore *lc) long int expires=0; while (1) { - char *input=readline("Specify register expiration time" + char *input=linphonec_readline("Specify register expiration time" " in seconds (default is 600): "); if ( ! input ) { @@ -869,7 +873,7 @@ linphonec_proxy_add(LinphoneCore *lc) */ while (1) { - char *input=readline("Specify route if needed: "); + char *input=linphonec_readline("Specify route if needed: "); char *clean; if ( ! input ) { @@ -909,7 +913,7 @@ linphonec_proxy_add(LinphoneCore *lc) printf("--------------------------------------------\n"); linphonec_proxy_display(cfg); printf("--------------------------------------------\n"); - input=readline("Accept the above proxy configuration (yes/no) ?: "); + input=linphonec_readline("Accept the above proxy configuration (yes/no) ?: "); if ( ! input ) { @@ -1214,7 +1218,7 @@ lpc_find_command(const char *name) * * Revision 1.16 2006/01/18 09:25:32 strk * Command completion inhibited in proxy addition and auth request prompts. - * Avoided use of readline's internal filename completion. + * Avoided use of linphonec_readline's internal filename completion. * * Revision 1.15 2006/01/14 13:29:32 strk * Reworked commands interface to use a table structure, @@ -1229,7 +1233,7 @@ lpc_find_command(const char *name) * Added linphonec.h. Code layout change (added comments, forward decl, * globals on top, copyright notices and Logs). Handled out-of-memory * condition on history management. Removed assumption on sizeof(char). - * Fixed bug in authentication prompt (introduced by readline). + * Fixed bug in authentication prompt (introduced by linphonec_readline). * Added support for multiple authentication requests (up to MAX_PENDING_AUTH). * * diff --git a/linphone/console/linphonec.c b/linphone/console/linphonec.c index bfe770437..079444b66 100644 --- a/linphone/console/linphonec.c +++ b/linphone/console/linphonec.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "linphonec.h" @@ -69,13 +70,15 @@ char *lpc_strip_blanks(char *input); static int handle_configfile_migration(void); static int copy_file(const char *from, const char *to); static int linphonec_parse_cmdline(int argc, char **argv); -static int linphonec_initialize_readline(void); -static int linphonec_finish_readline(); static int linphonec_init(int argc, char **argv); static int linphonec_main_loop (LinphoneCore * opm, char * sipAddr); static int linphonec_idle_call (void); +#ifdef HAVE_READLINE +static int linphonec_initialize_readline(void); +static int linphonec_finish_readline(); static char **linephonec_readline_completion(const char *text, int start, int end); +#endif /* These are callback for linphone core */ static void linphonec_call_received(LinphoneCore *lc, const char *from); @@ -95,7 +98,6 @@ static void linphonec_text_received(LinphoneCore *lc, LinphoneChatRoom *cr, static void linphonec_display_status (LinphoneCore * lc, const char *something); static void linphonec_general_state (LinphoneCore * lc, LinphoneGeneralState *gstate); static void print_prompt(LinphoneCore *opm); - /*************************************************************************** * * Global variables @@ -104,8 +106,10 @@ static void print_prompt(LinphoneCore *opm); LinphoneCore linphonec; FILE *mylogfile; +#ifdef HAVE_READLINE static char *histfile_name=NULL; static char last_in_history[256]; +#endif //auto answer (-a) option static bool_t auto_answer=FALSE; static bool_t answer_call=FALSE; @@ -322,6 +326,64 @@ linphonec_general_state (LinphoneCore * lc, LinphoneGeneralState *gstate) } } +#ifndef HAVE_READLINE +static char received_prompt[PROMPT_MAX_LEN]; +static ms_mutex_t prompt_mutex; +static bool_t have_prompt=FALSE; + +static void *prompt_reader_thread(void *arg){ + char *ret; + char tmp[PROMPT_MAX_LEN]; + while ((ret=fgets(tmp,sizeof(tmp),stdin))!=NULL){ + ms_mutex_lock(&prompt_mutex); + strcpy(received_prompt,ret); + have_prompt=TRUE; + ms_mutex_unlock(&prompt_mutex); + } + ms_mutex_lock(&prompt_mutex); + strcpy(received_prompt,"quit"); + have_prompt=TRUE; + ms_mutex_unlock(&prompt_mutex); + return NULL; +} + +static void start_prompt_reader(void){ + ortp_thread_t th; + ms_mutex_init(&prompt_mutex,NULL); + ortp_thread_create(&th,NULL,prompt_reader_thread,NULL); +} + +#endif + +char *linphonec_readline(char *prompt){ +#ifdef HAVE_READLINE + return readline(prompt); +#else + static bool_t prompt_reader_started=FALSE; + if (!prompt_reader_started){ + start_prompt_reader(); + prompt_reader_started=TRUE; + } + fprintf(stdout,prompt); + fflush(stdout); + while(1){ + ms_mutex_lock(&prompt_mutex); + if (have_prompt){ + char *ret=strdup(received_prompt); + have_prompt=FALSE; + ms_mutex_unlock(&prompt_mutex); + return ret; + } + ms_mutex_unlock(&prompt_mutex); + linphonec_idle_call(); +#ifdef WIN32 + Sleep(20); +#else + usleep(20000); +#endif + } +#endif +} /***************************************************************************/ /* @@ -418,11 +480,12 @@ linphonec_init(int argc, char **argv) NULL); linphone_core_enable_video(&linphonec,vcap_enabled,display_enabled); if (!(vcap_enabled || display_enabled)) printf("Warning: video is disabled in linphonec.\n"); +#ifdef HAVE_READLINE /* * Initialize readline */ linphonec_initialize_readline(); - +#endif /* * Initialize signal handlers */ @@ -444,9 +507,9 @@ linphonec_finish(int exit_status) /* Terminate any pending call */ linphonec_parse_command_line(&linphonec, "terminate"); - +#ifdef HAVE_READLINE linphonec_finish_readline(); - +#endif linphone_core_uninit (&linphonec); if (mylogfile != NULL && mylogfile != stdout) @@ -474,15 +537,16 @@ linphonec_prompt_for_auth_final(LinphoneCore *lc) { char *input, *iptr; char auth_prompt[256]; +#ifdef HAVE_READLINE rl_hook_func_t *old_event_hook; - +#endif LinphoneAuthInfo *pending_auth=auth_stack.elem[auth_stack.nitems-1]; snprintf(auth_prompt, 256, "Password for %s on %s: ", pending_auth->username, pending_auth->realm); printf("\n"); - +#ifdef HAVE_READLINE /* * Disable event hook to avoid entering an * infinite loop. This would prevent idle_call @@ -491,10 +555,11 @@ linphonec_prompt_for_auth_final(LinphoneCore *lc) */ old_event_hook=rl_event_hook; rl_event_hook=NULL; +#endif while (1) { - input=readline(auth_prompt); + input=linphonec_readline(auth_prompt); /* * If EOF (^D) is sent you probably don't want @@ -531,15 +596,14 @@ linphonec_prompt_for_auth_final(LinphoneCore *lc) linphone_auth_info_set_passwd(pending_auth, input); linphone_core_add_auth_info(lc, pending_auth); --(auth_stack.nitems); - +#ifdef HAVE_READLINE /* * Reset line_buffer, to avoid the password * to be used again from outer readline */ rl_line_buffer[0]='\0'; - rl_event_hook=old_event_hook; - +#endif return 1; } @@ -590,28 +654,25 @@ linphonec_idle_call () answer_call=FALSE; } -#if 0 /* Automatic exit should be requested with a command line switch */ - /* Quit if autocall mode was on and no call is in progress */ - if ( sipAddr != NULL && opm->call == NULL ) - { - linphonec_parse_command_line(&linphonec, "quit"); - } -#endif - if ( auth_stack.nitems ) { /* * Inhibit command completion * during password prompts */ +#ifdef HAVE_READLINE rl_inhibit_completion=1; +#endif linphonec_prompt_for_auth_final(opm); +#ifdef HAVE_READLINE rl_inhibit_completion=0; +#endif } return 0; } +#ifdef HAVE_READLINE /* * Use globals: * @@ -664,6 +725,8 @@ linphonec_finish_readline() return 0; } +#endif + static void print_prompt(LinphoneCore *opm){ #ifdef IDENTITY_AS_PROMPT snprintf(prompt, PROMPT_MAX_LEN, "%s> ", @@ -690,7 +753,7 @@ linphonec_main_loop (LinphoneCore * opm, char * sipAddr) run=linphonec_parse_command_line(&linphonec, buf); } - while ((input=readline(prompt))) + while ((input=linphonec_readline(prompt))) { char *iptr; /* input and input pointer */ size_t input_len; @@ -710,7 +773,7 @@ linphonec_main_loop (LinphoneCore * opm, char * sipAddr) continue; } - +#ifdef HAVE_READLINE /* * Only add to history if not already * last item in it @@ -721,6 +784,7 @@ linphonec_main_loop (LinphoneCore * opm, char * sipAddr) last_in_history[sizeof(last_in_history)-1]='\0'; add_history(iptr); } +#endif linphonec_parse_command_line(&linphonec, iptr); free(input); @@ -953,6 +1017,7 @@ copy_file(const char *from, const char *to) return 1; } +#ifdef HAVE_READLINE static char ** linephonec_readline_completion(const char *text, int start, int end) { @@ -982,6 +1047,8 @@ linephonec_readline_completion(const char *text, int start, int end) return matches; } +#endif + /* * Strip blanks from a string. * Return a pointer into the provided string. diff --git a/linphone/console/linphonec.h b/linphone/console/linphonec.h index 368d63e0f..e1375b5d7 100644 --- a/linphone/console/linphonec.h +++ b/linphone/console/linphonec.h @@ -27,9 +27,11 @@ #ifdef HAVE_READLINE_H #include +#define HAVE_READLINE #else #ifdef HAVE_READLINE_READLINE_H #include +#define HAVE_READLINE #endif #endif #ifdef HAVE_HISTORY_H @@ -99,6 +101,7 @@ typedef struct { extern int linphonec_parse_command_line(LinphoneCore *lc, char *cl); extern char *linphonec_command_generator(const char *text, int state); extern void linphonec_finish(int exit_status); +extern char *linphonec_readline(char *prompt); #endif /* def LINPHONEC_H */ diff --git a/linphone/m4/readline.m4 b/linphone/m4/readline.m4 index 5293048ab..8c4e18566 100644 --- a/linphone/m4/readline.m4 +++ b/linphone/m4/readline.m4 @@ -5,33 +5,40 @@ AC_DEFUN([LP_CHECK_READLINE],[ AC_ARG_WITH( readline, - [ --with-readline Set prefix where gnu readline headers and libs can be found (ex:/usr, /usr/local) [default=/usr] ], + [ --with-readline Set prefix where gnu readline headers and libs can be found (ex:/usr, /usr/local, none) [default=/usr] ], [ readline_prefix=${withval}],[ readline_prefix="/usr" ]) -if test "$readline_prefix" != "/usr"; then - READLINE_CFLAGS="-I$readline_prefix/include" - READLINE_LIBS="-L$readline_prefix/lib" +if test "$readline_prefix" != "none"; then + + if test "$readline_prefix" != "/usr"; then + READLINE_CFLAGS="-I$readline_prefix/include" + READLINE_LIBS="-L$readline_prefix/lib" + fi + + CPPFLAGS_save=$CPPFLAGS + LIBS_save=$LIBS + CPPFLAGS="$CPPFLAGS $READLINE_CFLAGS" + LIBS="$LIBS $READLINE_LIBS" + AC_CHECK_HEADERS(readline.h readline/readline.h, readline_h_found=yes) + AC_CHECK_HEADERS(history.h readline/history.h) + + AC_CHECK_LIB(readline, readline, [readline_libs_found=yes],[],[-lncurses]) + + LIBS=$LIBS_save + CPPFLAGS=$CPPFLAGS_save + + if test "$readline_libs_found$readline_h_found" != "yesyes" ; then + AC_MSG_WARN("Could not find libreadline headers or library, linphonec will have limited prompt features") + else + READLINE_LIBS="$READLINE_LIBS -lreadline -lncurses" + fi + + + AC_SUBST(READLINE_CFLAGS) + AC_SUBST(READLINE_LIBS) + +else + AC_MSG_NOTICE([Readline support disabled.]) fi -CPPFLAGS_save=$CPPFLAGS -LIBS_save=$LIBS -CPPFLAGS="$CPPFLAGS $READLINE_CFLAGS" -LIBS="$LIBS $READLINE_LIBS" -AC_CHECK_HEADERS(readline.h readline/readline.h, readline_h_found=yes) -AC_CHECK_HEADERS(history.h readline/history.h) - -AC_CHECK_LIB(readline, readline, [readline_libs_found=yes],[],[-lncurses]) - -LIBS=$LIBS_save -CPPFLAGS=$CPPFLAGS_save - -if test "$readline_libs_found$readline_h_found" != "yesyes" ; then - AC_MSG_ERROR("Could not find libreadline headers or library") -fi - -READLINE_LIBS="$READLINE_LIBS -lreadline -lncurses" - - -AC_SUBST(READLINE_CFLAGS) -AC_SUBST(READLINE_LIBS) ]) diff --git a/linphone/mediastreamer2/src/sizeconv.c b/linphone/mediastreamer2/src/sizeconv.c index 9e34ba819..3a74a6b51 100644 --- a/linphone/mediastreamer2/src/sizeconv.c +++ b/linphone/mediastreamer2/src/sizeconv.c @@ -33,7 +33,6 @@ typedef struct SizeConvState{ YuvBuf outbuf; struct SwsContext *sws_ctx; mblk_t *om; - float fps; float start_time; int frame_count;