[Pkg-gnupg-commit] [libassuan] 07/437: Allow to store an arbitrary pointer in the context. Added assuan_write_status().

Eric Dorland eric at moszumanska.debian.org
Fri May 22 05:33:15 UTC 2015


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository libassuan.

commit e91d7477572cb1d5f8c5eb8c44870335e9230098
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Nov 19 12:40:30 2001 +0000

    Allow to store an arbitrary pointer in the context.
    Added assuan_write_status().
---
 src/assuan-defs.h    |  2 ++
 src/assuan-handler.c | 40 ++++++++++++++++++++++++++++++++++++++++
 src/assuan-util.c    | 13 +++++++++++++
 src/assuan.h         |  5 +++++
 4 files changed, 60 insertions(+)

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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/libassuan.git



More information about the Pkg-gnupg-commit mailing list