| 1 | /* |
| 2 | * This file is part of DisOrder |
| 3 | * Copyright (C) 2005, 2007 Richard Kettlewell |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 18 | * USA |
| 19 | */ |
| 20 | /** @file lib/mime.h |
| 21 | * @brief Support for MIME and allied protocols |
| 22 | */ |
| 23 | |
| 24 | #ifndef MIME_H |
| 25 | #define MIME_H |
| 26 | |
| 27 | int mime_content_type(const char *s, |
| 28 | char **typep, |
| 29 | char **parameternamep, |
| 30 | char **parametervaluep); |
| 31 | /* Parse a content-type value. returns 0 on success, -1 on error. |
| 32 | * paramaternamep and parametervaluep are only set if present. |
| 33 | * type and parametername are forced to lower case. |
| 34 | */ |
| 35 | |
| 36 | const char *mime_parse(const char *s, |
| 37 | int (*callback)(const char *name, const char *value, |
| 38 | void *u), |
| 39 | void *u); |
| 40 | /* Parse a MIME message. Calls CALLBACK for each header field, then returns a |
| 41 | * pointer to the decoded body (might or might not point back into the original |
| 42 | * string). */ |
| 43 | |
| 44 | int mime_multipart(const char *s, |
| 45 | int (*callback)(const char *s, void *u), |
| 46 | const char *boundary, |
| 47 | void *u); |
| 48 | /* call CALLBACK with each part of multipart document [s,s+n) */ |
| 49 | |
| 50 | int mime_rfc2388_content_disposition(const char *s, |
| 51 | char **dispositionp, |
| 52 | char **parameternamep, |
| 53 | char **parametervaluep); |
| 54 | /* Parse an RFC2388-style content-disposition field */ |
| 55 | |
| 56 | char *mime_qp(const char *s); |
| 57 | char *mime_base64(const char *s, size_t *nsp); |
| 58 | char *mime_to_base64(const uint8_t *s, size_t ns); |
| 59 | /* convert quoted-printable or base64 data */ |
| 60 | |
| 61 | /** @brief Parsed form of an HTTP Cookie: header field */ |
| 62 | struct cookiedata { |
| 63 | /** @brief @c $Version or NULL if not set */ |
| 64 | char *version; |
| 65 | |
| 66 | /** @brief List of cookies */ |
| 67 | struct cookie *cookies; |
| 68 | |
| 69 | /** @brief Number of cookies */ |
| 70 | int ncookies; |
| 71 | }; |
| 72 | |
| 73 | /** @brief A parsed cookie */ |
| 74 | struct cookie { |
| 75 | /** @brief Cookie name */ |
| 76 | char *name; |
| 77 | |
| 78 | /** @brief Cookie value */ |
| 79 | char *value; |
| 80 | |
| 81 | /** @brief Cookie path */ |
| 82 | char *path; |
| 83 | |
| 84 | /** @brief Cookie domain */ |
| 85 | char *domain; |
| 86 | |
| 87 | }; |
| 88 | |
| 89 | int parse_cookie(const char *s, |
| 90 | struct cookiedata *cd); |
| 91 | const struct cookie *find_cookie(const struct cookiedata *cd, |
| 92 | const char *name); |
| 93 | |
| 94 | |
| 95 | #endif /* MIME_H */ |
| 96 | |
| 97 | /* |
| 98 | Local Variables: |
| 99 | c-basic-offset:2 |
| 100 | comment-column:40 |
| 101 | fill-column:79 |
| 102 | End: |
| 103 | */ |