diff options
author | Werner Koch <wk@gnupg.org> | 2001-11-19 12:40:30 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2001-11-19 12:40:30 +0000 |
commit | e91d7477572cb1d5f8c5eb8c44870335e9230098 (patch) | |
tree | 8facfb3db0eefb418969d54e2331278d1fc5abff | |
parent | 4a06ed3bfbfdbedd776d7023493e2ae1ae3a5af7 (diff) | |
download | libassuan-e91d7477572cb1d5f8c5eb8c44870335e9230098.tar.gz |
Allow to store an arbitrary pointer in the context.
Added assuan_write_status().
-rw-r--r-- | src/assuan-defs.h | 2 | ||||
-rw-r--r-- | src/assuan-handler.c | 40 | ||||
-rw-r--r-- | src/assuan-util.c | 13 | ||||
-rw-r--r-- | src/assuan.h | 5 |
4 files changed, 60 insertions, 0 deletions
diff --git a/src/assuan-defs.h b/src/assuan-defs.h index 72f6eb4..96e8a4a 100644 --- a/src/assuan-defs.h +++ b/src/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/src/assuan-handler.c b/src/assuan-handler.c index cebb786..90f170a 100644 --- a/src/assuan-handler.c +++ b/src/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/src/assuan-util.c b/src/assuan-util.c index 3a9496e..3eeee9a 100644 --- a/src/assuan-util.c +++ b/src/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/src/assuan.h b/src/assuan.h index 3806d5d..02a8fda 100644 --- a/src/assuan.h +++ b/src/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); |