mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
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@gnupg.org>
This commit is contained in:
parent
effa80e0b5
commit
a209025082
@ -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.
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user