diff options
Diffstat (limited to 'g10')
-rw-r--r-- | g10/ChangeLog | 14 | ||||
-rw-r--r-- | g10/g10.c | 4 | ||||
-rw-r--r-- | g10/keyedit.c | 2 | ||||
-rw-r--r-- | g10/options.h | 1 | ||||
-rw-r--r-- | g10/status.c | 75 | ||||
-rw-r--r-- | g10/status.h | 5 |
6 files changed, 100 insertions, 1 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog index 5a0647f6c..6d19d7e0e 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,17 @@ +Thu May 18 11:38:54 CEST 2000 Werner Koch <[email protected]> + + * keyedit.c (keyedit_menu): Add a keyword arg to the prompt. + + * status.c, status.h: Added 3 new status tokens. + * status.c (do_get_from_fd): New. + (cpr_enabled,cpr_get,cpr_get_hidden,cpr_kill_prompt, + cpr_get_answer_is_yes,cpr_get_answer_yes_no_quit): Modified to work + with the new function. + * g10.c: Add new option --command-fd. + + * status.c (progress_cb): New. + (set_status_fd): Register progress functions + Fri May 12 14:01:20 CEST 2000 Werner Koch <[email protected]> * delkey.c (delete_key): Add 2 new status messages @@ -133,6 +133,7 @@ enum cmd_and_opt_values { aNull = 0, oDigestAlgo, oCompressAlgo, oPasswdFD, + oCommandFD, oQuickRandom, oNoVerbose, oTrustDBName, @@ -316,6 +317,7 @@ static ARGPARSE_OPTS opts[] = { { aListTrustPath, "list-trust-path",0, "@"}, { oKOption, NULL, 0, "@"}, { oPasswdFD, "passphrase-fd",1, "@" }, + { oCommandFD, "command-fd",1, "@" }, { oQuickRandom, "quick-random", 0, "@"}, { oNoVerbose, "no-verbose", 0, "@"}, { oTrustDBName, "trustdb-name", 2, "@" }, @@ -596,6 +598,7 @@ main( int argc, char **argv ) init_signals(); create_dotlock(NULL); /* register locking cleanup */ i18n_init(); + opt.command_fd = -1; /* no command fd */ opt.compress = -1; /* defaults to standard compress level */ /* note: if you change these lines, look at oOpenPGP */ opt.def_cipher_algo = 0; @@ -873,6 +876,7 @@ main( int argc, char **argv ) break; case oCompress: opt.compress = pargs.r.ret_int; break; case oPasswdFD: pwfd = pargs.r.ret_int; break; + case oCommandFD: opt.command_fd = pargs.r.ret_int; break; case oCipherAlgo: def_cipher_string = m_strdup(pargs.r.ret_str); break; case oDigestAlgo: def_digest_string = m_strdup(pargs.r.ret_str); break; case oNoSecmemWarn: secmem_set_flags( secmem_get_flags() | 1 ); break; diff --git a/g10/keyedit.c b/g10/keyedit.c index 2a1b26af8..cd297db60 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -694,7 +694,7 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands, have_commands = 0; } if( !have_commands ) { - answer = cpr_get("", _("Command> ")); + answer = cpr_get("keyedit.prompt", _("Command> ")); cpr_kill_prompt(); } trim_spaces(answer); diff --git a/g10/options.h b/g10/options.h index c0394f608..b3bdc8a34 100644 --- a/g10/options.h +++ b/g10/options.h @@ -88,6 +88,7 @@ struct { int honor_http_proxy; int fast_list_mode; int ignore_time_conflict; + int command_fd; } opt; diff --git a/g10/status.c b/g10/status.c index 23bb7deca..38f2c145f 100644 --- a/g10/status.c +++ b/g10/status.c @@ -44,6 +44,7 @@ #include "options.h" #include "main.h" #include "i18n.h" +#include "cipher.h" /* for progress functions */ static int fd = -1; #ifdef USE_SHM_COPROCESSING @@ -53,10 +54,29 @@ static int fd = -1; static int shm_is_locked; #endif /*USE_SHM_COPROCESSING*/ + +static void +progress_cb ( void *ctx, int c ) +{ + char buf[50]; + + if ( c == '\n' ) + sprintf ( buf, "%.20s X 100 100", (char*)ctx ); + else + sprintf ( buf, "%.20s %c 0 0", (char*)ctx, c ); + write_status_text ( STATUS_PROGRESS, buf ); +} + + void set_status_fd ( int newfd ) { fd = newfd; + if ( fd != -1 ) { + register_primegen_progress ( progress_cb, "primegen" ); + register_pk_dsa_progress ( progress_cb, "pk_dsa" ); + register_pk_elg_progress ( progress_cb, "pk_elg" ); + } } int @@ -95,6 +115,10 @@ write_status_text ( int no, const char *text) case STATUS_TRUST_MARGINAL : s = "TRUST_MARGINAL\n"; break; case STATUS_TRUST_FULLY : s = "TRUST_FULLY\n"; break; case STATUS_TRUST_ULTIMATE : s = "TRUST_ULTIMATE\n"; break; + case STATUS_GET_BOOL : s = "GET_BOOL\n"; break; + case STATUS_GET_LINE : s = "GET_LINE\n"; break; + case STATUS_GET_HIDDEN : s = "GET_HIDDEN\n"; break; + case STATUS_GOT_IT : s = "GOT_IT\n"; break; case STATUS_SHM_INFO : s = "SHM_INFO\n"; break; case STATUS_SHM_GET : s = "SHM_GET\n"; break; case STATUS_SHM_GET_BOOL : s = "SHM_GET_BOOL\n"; break; @@ -125,6 +149,7 @@ write_status_text ( int no, const char *text) case STATUS_BEGIN_ENCRYPTION:s = "BEGIN_ENCRYPTION\n"; break; case STATUS_END_ENCRYPTION : s = "END_ENCRYPTION\n"; break; case STATUS_DELETE_PROBLEM : s = "DELETE_PROBLEM\n"; break; + case STATUS_PROGRESS : s = "PROGRESS\n"; break; default: s = "?\n"; break; } @@ -276,10 +301,50 @@ do_shm_get( const char *keyword, int hidden, int bool ) #endif /* USE_SHM_COPROCESSING */ +/**************** + * Request a string from the client over the command-fd + * If bool, returns static string on true (do not free) or NULL for false + */ +static char * +do_get_from_fd( const char *keyword, int hidden, int bool ) +{ + int i, len; + char *string; + + write_status_text( bool? STATUS_GET_BOOL : + hidden? STATUS_GET_HIDDEN : STATUS_GET_LINE, keyword ); + + for( string = NULL, i = len = 200; ; i++ ) { + if( i >= len-1 ) { + char *save = string; + len += 100; + string = hidden? m_alloc_secure ( len ) : m_alloc ( len ); + if( save ) + memcpy(string, save, i ); + else + i=0; + } + /* Hmmm: why not use our read_line function here */ + if( read( fd, string+i, 1) != 1 || string[i] == '\n' ) + break; + } + string[i] = 0; + + write_status( STATUS_GOT_IT ); + + if( bool ) /* Fixme: is this correct??? */ + return string[0] == 'Y' ? "" : NULL; + + return string; +} + + int cpr_enabled() { + if( opt.command_fd != -1 ) + return 1; #ifdef USE_SHM_COPROCESSING if( opt.shm_coprocess ) return 1; @@ -292,6 +357,8 @@ cpr_get( const char *keyword, const char *prompt ) { char *p; + if( opt.command_fd != -1 ) + return do_get_from_fd ( keyword, 0, 0 ); #ifdef USE_SHM_COPROCESSING if( opt.shm_coprocess ) return do_shm_get( keyword, 0, 0 ); @@ -325,6 +392,8 @@ cpr_get_hidden( const char *keyword, const char *prompt ) { char *p; + if( opt.command_fd != -1 ) + return do_get_from_fd ( keyword, 1, 0 ); #ifdef USE_SHM_COPROCESSING if( opt.shm_coprocess ) return do_shm_get( keyword, 1, 0 ); @@ -343,6 +412,8 @@ cpr_get_hidden( const char *keyword, const char *prompt ) void cpr_kill_prompt(void) { + if( opt.command_fd != -1 ) + return; #ifdef USE_SHM_COPROCESSING if( opt.shm_coprocess ) return; @@ -357,6 +428,8 @@ cpr_get_answer_is_yes( const char *keyword, const char *prompt ) int yes; char *p; + if( opt.command_fd != -1 ) + return !!do_get_from_fd ( keyword, 0, 1 ); #ifdef USE_SHM_COPROCESSING if( opt.shm_coprocess ) return !!do_shm_get( keyword, 0, 1 ); @@ -383,6 +456,8 @@ cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt ) int yes; char *p; + if( opt.command_fd != -1 ) + return !!do_get_from_fd ( keyword, 0, 1 ); #ifdef USE_SHM_COPROCESSING if( opt.shm_coprocess ) return !!do_shm_get( keyword, 0, 1 ); diff --git a/g10/status.h b/g10/status.h index 3581fd767..667565560 100644 --- a/g10/status.h +++ b/g10/status.h @@ -75,6 +75,11 @@ #define STATUS_END_ENCRYPTION 44 #define STATUS_DELETE_PROBLEM 45 +#define STATUS_GET_BOOL 46 +#define STATUS_GET_LINE 47 +#define STATUS_GET_HIDDEN 48 +#define STATUS_GOT_IT 49 +#define STATUS_PROGRESS 50 /*-- status.c --*/ void set_status_fd ( int fd ); |