From 1dce00882d78e0bb30011067f383583f2b551172 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 14 Oct 2009 11:27:08 +0000 Subject: Add new ducntion assuan_get_command_name. This makes error reporting in the server much easier. --- NEWS | 2 ++ autogen.sh | 4 +++- doc/ChangeLog | 4 ++++ doc/assuan.texi | 9 +++++++++ src/ChangeLog | 7 +++++++ src/assuan-defs.h | 5 +++++ src/assuan-handler.c | 16 +++++++++++++++- src/assuan.c | 2 +- src/assuan.h | 1 + src/libassuan.def | 1 + src/libassuan.vers | 1 + 11 files changed, 49 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 9d72701..46042f2 100644 --- a/NEWS +++ b/NEWS @@ -50,8 +50,10 @@ assuan_init_pipe_server CHANGED: Take ctx arg instead of pointer to ctx. assuan_set_io_hooks REMOVED: Will come back in expanded form. assuan_io_hooks_t REMOVED: Will come back in expanded form. assuan_io_monitor_t CHANGED: Add a hook data argument. +assuan_get_command_name NEW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Noteworthy changes in version 1.0.5 (2008-05-25) ------------------------------------------------ diff --git a/autogen.sh b/autogen.sh index 1c53b0d..1b837c6 100755 --- a/autogen.sh +++ b/autogen.sh @@ -197,4 +197,6 @@ $AUTOMAKE --gnu; echo "Running autoconf${FORCE} ..." $AUTOCONF${FORCE} -echo "You may now run \"./configure --enable-maintainer-mode && make\"." +echo "You may now run + ./configure --enable-maintainer-mode && make +" diff --git a/doc/ChangeLog b/doc/ChangeLog index 95441d5..c567640 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2009-10-14 Werner Koch + + * assuan.texi (Utilities): Describe assuan_get_command_name. + 2009-09-21 Marcus Brinkmann * assuan.texi: Update to new API. diff --git a/doc/assuan.texi b/doc/assuan.texi index a3ec0a3..adfc86d 100644 --- a/doc/assuan.texi +++ b/doc/assuan.texi @@ -1675,6 +1675,15 @@ functions like @code{fdopen} or @code{dup}. @end deftypefun +@deftypefun @w{const char *} assuan_get_command_name (@w{assuan_context_t @var{ctx}}) + +Return the name of the command currently processed by a handler. +The returned string is valid until the next call to an Assuan +function on the same context. Returns @code{NULL} if no handler is +executed or the command is not known. +@end deftypefun + + @deftypefun int assuan_get_input_fd (@w{assuan_context_t @var{ctx}}) Return the file descriptor sent by the client using the last @code{INPUT} diff --git a/src/ChangeLog b/src/ChangeLog index f2ae1e6..c9f2172 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-10-14 Werner Koch + + * assuan-defs.h (assuan_context_s): Add field CURRENT_CMD_NAME. + * assuan-handler.c (dispatch_command): Set this field. + (assuan_get_command_name): New. + * assuan.h, libassuan.vers, libassuan.def: Add new fucntion. + 2009-10-08 Marcus Brinkmann * assuan.h (assuan_get_assuan_log_stream, diff --git a/src/assuan-defs.h b/src/assuan-defs.h index c20cef5..95706d6 100644 --- a/src/assuan-defs.h +++ b/src/assuan-defs.h @@ -200,6 +200,11 @@ struct assuan_context_s struct cmdtbl_s *cmdtbl; size_t cmdtbl_used; /* used entries */ size_t cmdtbl_size; /* allocated size of table */ + + /* The name of the command currently processed by a command handler. + This is a pointer into CMDTBL. NULL if not in a command + handler. */ + const char *current_cmd_name; void (*bye_notify_fnc)(assuan_context_t); void (*reset_notify_fnc)(assuan_context_t); diff --git a/src/assuan-handler.c b/src/assuan-handler.c index da5d4bf..fd41719 100644 --- a/src/assuan-handler.c +++ b/src/assuan-handler.c @@ -330,6 +330,16 @@ assuan_register_command (assuan_context_t ctx, return 0; } +/* Return the name of the command currently processed by a handler. + The string returned is valid until the next call to an assuan + function on the same context. Returns NULL if no handler is + executed or the command is not known. */ +const char * +assuan_get_command_name (assuan_context_t ctx) +{ + return ctx? ctx->current_cmd_name : NULL; +} + gpg_error_t assuan_register_post_cmd_notify (assuan_context_t ctx, void (*fnc)(assuan_context_t, gpg_error_t)) @@ -453,6 +463,7 @@ my_strcasecmp (const char *a, const char *b) static gpg_error_t dispatch_command (assuan_context_t ctx, char *line, int linelen) { + gpg_error_t err; char *p; const char *s; int shift, i; @@ -499,7 +510,10 @@ dispatch_command (assuan_context_t ctx, char *line, int linelen) linelen -= shift; /* fprintf (stderr, "DBG-assuan: processing %s `%s'\n", s, line); */ - return ctx->cmdtbl[i].handler (ctx, line); + ctx->current_cmd_name = ctx->cmdtbl[i].name; + err = ctx->cmdtbl[i].handler (ctx, line); + ctx->current_cmd_name = NULL; + return err; } diff --git a/src/assuan.c b/src/assuan.c index 06b9b8a..4848ec4 100644 --- a/src/assuan.c +++ b/src/assuan.c @@ -160,7 +160,7 @@ _assuan_reset (assuan_context_t ctx) ctx->engine.release = NULL; } - // FIXME: Clean standard commands + /* FIXME: Clean standard commands */ } diff --git a/src/assuan.h b/src/assuan.h index 20de1b0..c0b1fea 100644 --- a/src/assuan.h +++ b/src/assuan.h @@ -288,6 +288,7 @@ gpg_error_t assuan_process_done (assuan_context_t ctx, gpg_error_t rc); int assuan_get_active_fds (assuan_context_t ctx, int what, assuan_fd_t *fdarray, int fdarraysize); +const char *assuan_get_command_name (assuan_context_t ctx); FILE *assuan_get_data_fp (assuan_context_t ctx); gpg_error_t assuan_set_okay_line (assuan_context_t ctx, const char *line); diff --git a/src/libassuan.def b/src/libassuan.def index cc5509e..b2450d8 100644 --- a/src/libassuan.def +++ b/src/libassuan.def @@ -84,6 +84,7 @@ EXPORTS assuan_transact @63 assuan_write_line @64 assuan_write_status @65 + assuan_get_command_name @66 ; END diff --git a/src/libassuan.vers b/src/libassuan.vers index 61eaebd..e4f6a7a 100644 --- a/src/libassuan.vers +++ b/src/libassuan.vers @@ -30,6 +30,7 @@ LIBASSUAN_1.0 { assuan_end_confidential; assuan_get_active_fds; assuan_get_assuan_log_prefix; + assuan_get_command_name; assuan_get_data_fp; assuan_get_flag; assuan_get_input_fd; -- cgit v1.2.1