diff options
author | Werner Koch <wk@gnupg.org> | 2001-11-19 13:40:30 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2001-11-19 13:40:30 +0100 |
commit | f375790d242780fdf8e5d973622e2014470bfc84 (patch) | |
tree | 5f6045a86766d37ce7ac6959c7c28f845576ec10 /assuan | |
parent | * assuan-connect.c (assuan_pipe_connect): New function. (diff) | |
download | gnupg2-f375790d242780fdf8e5d973622e2014470bfc84.tar.xz gnupg2-f375790d242780fdf8e5d973622e2014470bfc84.zip |
Allow to store an arbitrary pointer in the context.
Added assuan_write_status().
Diffstat (limited to 'assuan')
-rw-r--r-- | assuan/assuan-defs.h | 2 | ||||
-rw-r--r-- | assuan/assuan-handler.c | 40 | ||||
-rw-r--r-- | assuan/assuan-util.c | 13 | ||||
-rw-r--r-- | assuan/assuan.h | 5 |
4 files changed, 60 insertions, 0 deletions
diff --git a/assuan/assuan-defs.h b/assuan/assuan-defs.h index 72f6eb422..96e8a4a26 100644 --- a/assuan/assuan-defs.h +++ b/assuan/assuan-defs.h @@ -35,6 +35,8 @@ struct cmdtbl_s { struct assuan_context_s { AssuanError err_no; const char *err_str; + + void *user_pointer; /* for assuan_[gs]et_pointer () */ struct { int fd; diff --git a/assuan/assuan-handler.c b/assuan/assuan-handler.c index cebb78643..90f170aea 100644 --- a/assuan/assuan-handler.c +++ b/assuan/assuan-handler.c @@ -354,5 +354,45 @@ assuan_process (ASSUAN_CONTEXT ctx) } +void +assuan_write_status (ASSUAN_CONTEXT ctx, const char *keyword, const char *text) +{ + char buffer[256]; + char *helpbuf; + size_t n; + + if ( !ctx || !keyword) + return; + if (!text) + text = ""; + + n = 2 + strlen (keyword) + 1 + strlen (text) + 1; + if (n < sizeof (buffer)) + { + strcpy (buffer, "S "); + strcat (buffer, keyword); + if (*text) + { + strcat (buffer, " "); + strcat (buffer, text); + } + _assuan_write_line (ctx, buffer); + } + else if ( (helpbuf = xtrymalloc (n)) ) + { + strcpy (helpbuf, "S "); + strcat (helpbuf, keyword); + if (*text) + { + strcat (helpbuf, " "); + strcat (helpbuf, text); + } + _assuan_write_line (ctx, helpbuf); + xfree (helpbuf); + } +} + + + diff --git a/assuan/assuan-util.c b/assuan/assuan-util.c index 3a9496e41..3eeee9ab9 100644 --- a/assuan/assuan-util.c +++ b/assuan/assuan-util.c @@ -83,3 +83,16 @@ assuan_set_error (ASSUAN_CONTEXT ctx, int err, const char *text) return err; } +void +assuan_set_pointer (ASSUAN_CONTEXT ctx, void *pointer) +{ + if (ctx) + ctx->user_pointer = pointer; +} + +void * +assuan_get_pointer (ASSUAN_CONTEXT ctx) +{ + return ctx? ctx->user_pointer : NULL; +} + diff --git a/assuan/assuan.h b/assuan/assuan.h index 3806d5d40..02a8fdacd 100644 --- a/assuan/assuan.h +++ b/assuan/assuan.h @@ -80,6 +80,8 @@ int assuan_register_command (ASSUAN_CONTEXT ctx, int cmd_id, const char *cmd_string, int (*handler)(ASSUAN_CONTEXT, char *)); int assuan_process (ASSUAN_CONTEXT ctx); +void assuan_write_status (ASSUAN_CONTEXT ctx, + const char *keyword, const char *text); /*-- assuan-listen.c --*/ @@ -98,6 +100,9 @@ void assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n), void *(*new_realloc_func)(void *p, size_t n), void (*new_free_func)(void*) ); int assuan_set_error (ASSUAN_CONTEXT ctx, int err, const char *text); +void assuan_set_pointer (ASSUAN_CONTEXT ctx, void *pointer); +void *assuan_get_pointer (ASSUAN_CONTEXT ctx); + /*-- assuan-errors.c (built) --*/ const char *assuan_strerror (AssuanError err); |