1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-17 00:39:50 +02:00

Allow to store an arbitrary pointer in the context.

Added assuan_write_status().
This commit is contained in:
Werner Koch 2001-11-19 12:40:30 +00:00
parent 2b2a800a77
commit f375790d24
4 changed files with 60 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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);