[Pkg-gnupg-commit] [gnupg2] 133/166: wks: New callback for the mime parser.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Mar 16 22:33:13 UTC 2017


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

dkg pushed a commit to branch experimental
in repository gnupg2.

commit a2090250829fe8989be2afc8cf41ba2a022072fc
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Feb 23 20:01:30 2017 +0100

    wks: New callback for the mime parser.
    
    * tools/mime-parser.c (mime_parser_context_s): New field 't2body'.
    (parse_message_cb): Call that callback.
    (mime_parser_set_t2body): New.
    --
    
    This callback allows to process header values even on the outer level.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 tools/mime-parser.c | 25 +++++++++++++++++++++++++
 tools/mime-parser.h |  2 ++
 2 files changed, 27 insertions(+)

diff --git a/tools/mime-parser.c b/tools/mime-parser.c
index 264353c..169ea2b 100644
--- a/tools/mime-parser.c
+++ b/tools/mime-parser.c
@@ -49,6 +49,9 @@ struct mime_parser_context_s
 {
   void *cookie;                /* Cookie passed to all callbacks.  */
 
+  /* The callback to announce the transation from header to body.  */
+  gpg_error_t (*t2body) (void *cookie, int level);
+
   /* The callback to announce a new part.  */
   gpg_error_t (*new_part) (void *cookie,
                            const char *mediatype,
@@ -224,6 +227,14 @@ parse_message_cb (void *opaque, rfc822parse_event_t event, rfc822parse_t msg)
 
       ctx->want_part = 0;
       ctx->decode_part = 0;
+
+      if (ctx->t2body)
+        {
+          rc = ctx->t2body (ctx->cookie, ctx->nesting_level);
+          if (rc)
+            goto t2body_leave;
+        }
+
       field = rfc822parse_parse_field (msg, "Content-Type", -1);
       if (field)
         {
@@ -412,6 +423,7 @@ parse_message_cb (void *opaque, rfc822parse_event_t event, rfc822parse_t msg)
             }
         }
 
+    t2body_leave:
       ctx->show.header = 0;
       ctx->show.data = 1;
       ctx->show.n_skip = 1;
@@ -541,6 +553,19 @@ mime_parser_set_verbose (mime_parser_t ctx, int level)
 }
 
 
+/* Set a callback for the transition from header to body.  LEVEL is
+ * the current nesting level, starting with 0.  This callback can be
+ * used to evaluate headers before any other action is done.  Note
+ * that if a new NEW_PART callback needs to be called it is done after
+ * this T2BODY callback.  */
+void
+mime_parser_set_t2body (mime_parser_t ctx,
+                        gpg_error_t (*fnc) (void *cookie, int level))
+{
+  ctx->t2body = fnc;
+}
+
+
 /* Set the callback used to announce a new part.  It will be called
  * with the media type and media subtype of the part.  If no
  * Content-type header was given both values are the empty string.
diff --git a/tools/mime-parser.h b/tools/mime-parser.h
index 37a74a1..b9bb465 100644
--- a/tools/mime-parser.h
+++ b/tools/mime-parser.h
@@ -27,6 +27,8 @@ gpg_error_t mime_parser_new (mime_parser_t *r_ctx, void *cookie);
 void        mime_parser_release (mime_parser_t ctx);
 
 void mime_parser_set_verbose (mime_parser_t ctx, int level);
+void mime_parser_set_t2body (mime_parser_t ctx,
+                             gpg_error_t (*fnc) (void *cookie, int level));
 void mime_parser_set_new_part (mime_parser_t ctx,
                                gpg_error_t (*fnc) (void *cookie,
                                                    const char *mediatype,

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



More information about the Pkg-gnupg-commit mailing list