|
iPXE
|
MIME image format. More...
#include <stdint.h>#include <string.h>#include <strings.h>#include <ctype.h>#include <errno.h>#include <ipxe/image.h>#include <ipxe/base64.h>#include <ipxe/mime.h>Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| static const struct mime_type * | mime_type (const char *name) |
| Identify MIME type. | |
| static void | mime_parse_attribute (struct image *image, const char *value, const char *eol, const char *name, struct mime_attribute *attr) |
| Parse MIME attribute. | |
| static void | mime_parse_type (struct image *image, const char *value, const char *eol, struct mime_headers *headers) |
| Parse Content-Type header. | |
| static void | mime_parse_encoding (struct image *image, const char *value, const char *eol __unused, struct mime_headers *headers) |
| Parse Content-Transfer-Encoding header. | |
| static const struct mime_header * | mime_header (const char *line) |
| Identify MIME header. | |
| static int | mime_parse (struct image *image, const char *text, struct mime_headers *headers) |
| Parse MIME headers. | |
| static int | mime_decode_identity (struct image *image, const struct mime_headers *headers, struct image *decoded) |
| Decode MIME entity with identity encoding. | |
| static int | mime_decode_base64 (struct image *image, const struct mime_headers *headers, struct image *decoded) |
| Decode MIME entity with Base64 encoding. | |
| static const struct mime_encoding * | mime_encoding (const char *name) |
| Identify MIME encoding. | |
| static int | mime_extract_entity (struct image *image, const struct mime_headers *headers, struct image *extracted) |
| Extract single MIME entity. | |
| static const char * | mime_part_end (struct image *image, const struct mime_attribute *boundary, const char *pos) |
| Find end of current part in multipart MIME image. | |
| static const char * | mime_part_next (struct image *image, const struct mime_attribute *boundary, const char *pos) |
| Find start of next part in multipart MIME image. | |
| static int | mime_extract_part (struct image *image, const struct mime_headers *headers, struct image *extracted) |
| Extract part from multipart MIME image. | |
| static int | mime_probe (struct image *image) |
| Probe MIME image. | |
| static int | mime_extract (struct image *image, struct image *extracted) |
| Extract MIME image. | |
| struct image_type mime_image_type | __image_type (PROBE_NORMAL) |
| MIME image type. | |
Variables | |
| const struct mime_header | mime_headers [] |
| Recognised MIME headers. | |
| static const struct mime_encoding | mime_encodings [] |
| MIME encodings. | |
| static const struct mime_type | mime_types [] |
| MIME types. | |
MIME image format.
The MIME format is defined in RFC 2045 and RFC 2046 (with reference to RFC 822). We treat it firstly as a simple single-member archive format where the content is extracted using the specified encoding.
We additionally support multipart MIME as an archive format from which we attempt to extract the first body part that has the MIME type "text/x-ipxe". This makes it possible to store both cloud-init configuration and an iPXE boot script in the same user metadata blob for a cloud instance.
Due to its historical origins, MIME is an irritatingly flexible format. We do not attempt to support all possible MIME files: only those that we might reasonably expect to encounter as cloud instance metadata.
Definition in file mime.c.
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
References name.
|
static |
Identify MIME type.
| name | Encoding |
| type | MIME type, or NULL if not recognised |
Definition at line 531 of file mime.c.
References isspace(), len, mime_types, name, NULL, strlen(), strncasecmp(), and type.
Referenced by mime_extract(), and mime_extract_part().
|
static |
Parse MIME attribute.
| image | MIME image |
| value | Header value |
| eol | End of header line |
| name | Attribute name (including terminating equals sign) |
| attr | MIME attribute to update |
Definition at line 66 of file mime.c.
References assert, attr, DBGC2, isspace(), image::name, name, strcasestr(), strlen(), and value.
Referenced by mime_parse_type().
|
static |
Parse Content-Type header.
Definition at line 99 of file mime.c.
References DBGC2, headers, mime_parse_attribute(), image::name, and value.
|
static |
|
static |
Identify MIME header.
| line | Header line |
| header | MIME header, or NULL if not recognised |
Definition at line 148 of file mime.c.
References header, NULL, strlen(), and strncasecmp().
Referenced by mime_parse().
|
static |
Parse MIME headers.
| rc | Return status code |
Definition at line 173 of file mime.c.
References DBGC, EINVAL, header, headers, isspace(), memset(), mime_header(), image::name, next, strchr(), strlen(), and value.
Referenced by mime_extract(), mime_extract_part(), and mime_probe().
|
static |
Decode MIME entity with identity encoding.
| rc | Return status code |
Definition at line 238 of file mime.c.
References image::data, headers, image_set_len(), image::len, len, memcpy(), rc, and image::rwdata.
|
static |
Decode MIME entity with Base64 encoding.
| rc | Return status code |
Definition at line 263 of file mime.c.
References assert, base64_decode(), base64_decoded_max_len(), DBGC, headers, image_set_len(), image::len, len, image::name, rc, image::rwdata, strerror(), and image::text.
|
static |
Identify MIME encoding.
| name | Encoding name, or NULL to use default |
| encoding | MIME encoding, or NULL if not recognised |
Definition at line 321 of file mime.c.
References isspace(), len, mime_encodings, mime_encoding::name, name, NULL, strlen(), and strncasecmp().
Referenced by mime_extract_entity().
|
static |
Extract single MIME entity.
| rc | Return status code |
Definition at line 352 of file mime.c.
References DBGC, mime_encoding::decode, ENOTSUP, headers, mime_encoding(), image::name, mime_encoding::name, and rc.
|
static |
Find end of current part in multipart MIME image.
| image | MIME image |
| boundary | Boundary separator |
| pos | Current position within image |
| end | End of current part, or NULL if not found |
Definition at line 383 of file mime.c.
References DBGC, mime_attribute::len, image::name, NULL, strncmp(), strstr(), and mime_attribute::value.
Referenced by mime_extract_part().
|
static |
Find start of next part in multipart MIME image.
| image | MIME image |
| boundary | Boundary separator |
| pos | End of current part within image |
| next | Start of next part, or NULL if not found |
Definition at line 412 of file mime.c.
References DBGC, isspace(), mime_attribute::len, image::name, NULL, and strcmp().
Referenced by mime_extract_part().
|
static |
Extract part from multipart MIME image.
| rc | Return status code |
Extraction will produce a MIME image containing only the selected part. (We rely on the recursive behaviour of image_extract_exec() to extract the content within the extracted part.)
Definition at line 450 of file mime.c.
References mime_headers::boundary, DBGC, end, ENOENT, headers, image_set_len(), len, memcpy(), mime_parse(), mime_part_end(), mime_part_next(), mime_type(), image::name, rc, image::rwdata, image::text, mime_headers::type, and type.
|
static |
Probe MIME image.
| image | Compressed kernel image |
| rc | Return status code |
Definition at line 502 of file mime.c.
References headers, mime_parse(), rc, and image::text.
Referenced by __image_type().
Extract MIME image.
| image | Compressed kernel image |
| extracted | Extracted image |
| rc | Return status code |
Definition at line 557 of file mime.c.
References DBGC, ENOTSUP, headers, mime_parse(), mime_type(), image::name, rc, image::text, and type.
Referenced by __image_type().
| struct image_type mime_image_type __image_type | ( | PROBE_NORMAL | ) |
MIME image type.
References __image_type, image_extract_exec(), mime_extract(), mime_probe(), and PROBE_NORMAL.
| const struct mime_header mime_headers[] |
Recognised MIME headers.
Definition at line 130 of file mime.c.
|
static |
MIME encodings.
Definition at line 295 of file mime.c.
Referenced by mime_encoding().
|
static |
MIME types.
Definition at line 514 of file mime.c.
Referenced by mime_type().