From eb24d8b751750cf96cb200f80b45ed3806648883 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 27 Jan 2004 16:40:42 +0000 Subject: Some minor bug fixes, new test utilities and started support for other smartcard applications. --- tools/rfc822parse.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tools/rfc822parse.h (limited to 'tools/rfc822parse.h') diff --git a/tools/rfc822parse.h b/tools/rfc822parse.h new file mode 100644 index 000000000..1293117ac --- /dev/null +++ b/tools/rfc822parse.h @@ -0,0 +1,79 @@ +/* rfc822parse.h - Simple mail and MIME parser + * Copyright (C) 1999 Werner Koch, Duesseldorf + * Copyright (C) 2003, g10 Code GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef RFC822PARSE_H +#define RFC822PARSE_H + +struct rfc822parse_context; +typedef struct rfc822parse_context *rfc822parse_t; + +typedef enum + { + RFC822PARSE_OPEN = 1, + RFC822PARSE_CLOSE, + RFC822PARSE_CANCEL, + RFC822PARSE_T2BODY, + RFC822PARSE_FINISH, + RFC822PARSE_RCVD_SEEN, + RFC822PARSE_LEVEL_DOWN, + RFC822PARSE_LEVEL_UP, + RFC822PARSE_BOUNDARY, + RFC822PARSE_LAST_BOUNDARY, + RFC822PARSE_BEGIN_HEADER, + RFC822PARSE_PREAMBLE, + RFC822PARSE_EPILOGUE + } +rfc822parse_event_t; + +struct rfc822parse_field_context; +typedef struct rfc822parse_field_context *rfc822parse_field_t; + + +typedef int (*rfc822parse_cb_t) (void *opaque, + rfc822parse_event_t event, + rfc822parse_t msg); + + +rfc822parse_t rfc822parse_open (rfc822parse_cb_t cb, void *opaque_value); + +void rfc822parse_close (rfc822parse_t msg); + +void rfc822parse_cancel (rfc822parse_t msg); +int rfc822parse_finish (rfc822parse_t msg); + +int rfc822parse_insert (rfc822parse_t msg, + const unsigned char *line, size_t length); + +char *rfc822parse_get_field (rfc822parse_t msg, const char *name, int which); + +const char *rfc822parse_enum_header_lines (rfc822parse_t msg, void **context); + +rfc822parse_field_t rfc822parse_parse_field (rfc822parse_t msg, + const char *name, + int which); + +void rfc822parse_release_field (rfc822parse_field_t field); + +const char *rfc822parse_query_parameter (rfc822parse_field_t ctx, + const char *attr, int lower_value); + +const char *rfc822parse_query_media_type (rfc822parse_field_t ctx, + const char **subtype); + +#endif /*RFC822PARSE_H */ -- cgit From 224da037849fd7dd30a221db9e1c6eba037c5689 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 20 Jul 2004 11:21:53 +0000 Subject: * rfc822parse.c (rfc822parse_get_field): Add arg VALUEOFF. --- tools/ChangeLog | 4 ++++ tools/rfc822parse.c | 25 ++++++++++++++++++++++--- tools/rfc822parse.h | 3 ++- 3 files changed, 28 insertions(+), 4 deletions(-) (limited to 'tools/rfc822parse.h') diff --git a/tools/ChangeLog b/tools/ChangeLog index a81a2d301..e4862bc38 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,3 +1,7 @@ +2004-06-16 Werner Koch + + * rfc822parse.c (rfc822parse_get_field): Add arg VALUEOFF. + 2004-06-14 Werner Koch * no-libgcrypt.c (gcry_realloc, gcry_xmalloc, gcry_xcalloc): New. diff --git a/tools/rfc822parse.c b/tools/rfc822parse.c index be1cf4a47..3379886de 100644 --- a/tools/rfc822parse.c +++ b/tools/rfc822parse.c @@ -1,6 +1,6 @@ /* rfc822parse.c - Simple mail and MIME parser * 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 * 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 * 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; * i.e. the regular mail headers or the MIME headers of the current * part. @@ -521,9 +521,13 @@ rfc822parse_finish (rfc822parse_t msg) * 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 * available. + * + * If VALUEOFF is not NULL it will receive the offset of the first non + * space character in th value of the line. */ 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; char *buf, *p; @@ -552,6 +556,21 @@ rfc822parse_get_field (rfc822parse_t msg, const char *name, int which) } 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; } diff --git a/tools/rfc822parse.h b/tools/rfc822parse.h index 1293117ac..a7ed5b4ec 100644 --- a/tools/rfc822parse.h +++ b/tools/rfc822parse.h @@ -60,7 +60,8 @@ int rfc822parse_finish (rfc822parse_t msg); int rfc822parse_insert (rfc822parse_t msg, 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); -- cgit From 12f7e943cca25caffa5969fdd13f2a3009f7bbe4 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 6 Sep 2005 10:25:41 +0000 Subject: Changed license of this parser to LPGL. --- tools/ChangeLog | 4 ++++ tools/rfc822parse.c | 48 ++++++++++++++++++++++++------------------------ tools/rfc822parse.h | 25 +++++++++++++------------ 3 files changed, 41 insertions(+), 36 deletions(-) (limited to 'tools/rfc822parse.h') diff --git a/tools/ChangeLog b/tools/ChangeLog index 7dc6d512e..027289ea7 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,3 +1,7 @@ +2005-09-06 Werner Koch + + * rfc822parse.c, rfc822parse.h: Changed license to LGPL. + 2005-08-01 Werner Koch * gpgsm-gencert.sh: Allow entering a keygrip to generate a CSR from diff --git a/tools/rfc822parse.c b/tools/rfc822parse.c index 3379886de..61377e7e6 100644 --- a/tools/rfc822parse.c +++ b/tools/rfc822parse.c @@ -3,31 +3,31 @@ * Copyright (C) 2003, 2004 g10 Code GmbH * * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is is distributed in the hope that it will be useful, + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. */ -/* According to RFC822 binary 0 are allowed at many places. We - * do not handle this correct especially in the field parsing code. It - * should be easy to fix and the API provides a interfcaes which returns - * the length but in addition makes sure that returned strings are always - * ended by a \0. +/* According to RFC822 binary zeroes are allowed at many places. We do + * not handle this correct especially in the field parsing code. It + * should be easy to fix and the API provides a interfaces which + * returns the length but in addition makes sure that returned strings + * are always ended by a \0. * * Furthermore, the case of field names is changed and thus it is not * always a good idea to use these modified header * lines (e.g. signatures may break). - * */ #ifdef HAVE_CONFIG_H @@ -44,13 +44,13 @@ #include "rfc822parse.h" enum token_type -{ - tSPACE, - tATOM, - tQUOTED, - tDOMAINLIT, - tSPECIAL -}; + { + tSPACE, + tATOM, + tQUOTED, + tDOMAINLIT, + tSPECIAL + }; /* For now we directly use our TOKEN as the parse context */ typedef struct rfc822parse_field_context *TOKEN; diff --git a/tools/rfc822parse.h b/tools/rfc822parse.h index a7ed5b4ec..8a56c51cb 100644 --- a/tools/rfc822parse.h +++ b/tools/rfc822parse.h @@ -3,18 +3,19 @@ * Copyright (C) 2003, g10 Code GmbH * * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. */ #ifndef RFC822PARSE_H -- cgit