* rfc822parse.c (rfc822parse_get_field): Add arg VALUEOFF.

This commit is contained in:
Werner Koch 2004-07-20 11:21:53 +00:00
parent 08b98804e4
commit 224da03784
3 changed files with 28 additions and 4 deletions

View File

@ -1,3 +1,7 @@
2004-06-16 Werner Koch <wk@gnupg.org>
* rfc822parse.c (rfc822parse_get_field): Add arg VALUEOFF.
2004-06-14 Werner Koch <wk@gnupg.org> 2004-06-14 Werner Koch <wk@gnupg.org>
* no-libgcrypt.c (gcry_realloc, gcry_xmalloc, gcry_xcalloc): New. * no-libgcrypt.c (gcry_realloc, gcry_xmalloc, gcry_xcalloc): New.

View File

@ -1,6 +1,6 @@
/* rfc822parse.c - Simple mail and MIME parser /* rfc822parse.c - Simple mail and MIME parser
* Copyright (C) 1999, 2000 Werner Koch, Duesseldorf * Copyright (C) 1999, 2000 Werner Koch, Duesseldorf
* Copyright (C) 2003, g10 Code GmbH * Copyright (C) 2003, 2004 g10 Code GmbH
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@ -509,7 +509,7 @@ rfc822parse_finish (rfc822parse_t msg)
/**************** /****************
* Get a copy of a header line. The line is returned as one long * Get a copy of a header line. The line is returned as one long
* string with LF to separate the continuation line. Caller must free * string with LF to separate the continuation line. Caller must free
* the return buffer. which may be used to enumerate over all lines. * the return buffer. WHICH may be used to enumerate over all lines.
* Wildcards are allowed. This function works on the current headers; * Wildcards are allowed. This function works on the current headers;
* i.e. the regular mail headers or the MIME headers of the current * i.e. the regular mail headers or the MIME headers of the current
* part. * part.
@ -521,9 +521,13 @@ rfc822parse_finish (rfc822parse_t msg)
* Returns a newly allocated buffer or NULL on error. errno is set in * Returns a newly allocated buffer or NULL on error. errno is set in
* case of a memory failure or set to 0 if the requested field is not * case of a memory failure or set to 0 if the requested field is not
* available. * available.
*
* If VALUEOFF is not NULL it will receive the offset of the first non
* space character in th value of the line.
*/ */
char * char *
rfc822parse_get_field (rfc822parse_t msg, const char *name, int which) rfc822parse_get_field (rfc822parse_t msg, const char *name, int which,
size_t *valueoff)
{ {
HDR_LINE h, h2; HDR_LINE h, h2;
char *buf, *p; char *buf, *p;
@ -552,6 +556,21 @@ rfc822parse_get_field (rfc822parse_t msg, const char *name, int which)
} }
p[-1] = 0; p[-1] = 0;
} }
if (valueoff)
{
p = strchr (buf, ':');
if (!p)
*valueoff = 0; /* Oops: should never happen. */
else
{
p++;
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
p++;
*valueoff = p - buf;
}
}
return buf; return buf;
} }

View File

@ -60,7 +60,8 @@ int rfc822parse_finish (rfc822parse_t msg);
int rfc822parse_insert (rfc822parse_t msg, int rfc822parse_insert (rfc822parse_t msg,
const unsigned char *line, size_t length); const unsigned char *line, size_t length);
char *rfc822parse_get_field (rfc822parse_t msg, const char *name, int which); char *rfc822parse_get_field (rfc822parse_t msg, const char *name, int which,
size_t *valueoff);
const char *rfc822parse_enum_header_lines (rfc822parse_t msg, void **context); const char *rfc822parse_enum_header_lines (rfc822parse_t msg, void **context);