1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef _MIMEMULT_H_ 7 #define _MIMEMULT_H_ 8 9 #include "mimecont.h" 10 11 /* The MimeMultipart class class implements the objects representing all of 12 the "multipart/" MIME types. In addition to the methods inherited from 13 MimeContainer, it provides the following methods and class variables: 14 15 int create_child (MimeObject *obj) 16 17 When it has been determined that a new sub-part should be created, 18 this method is called to do that. The default value for this method 19 does it in the usual multipart/mixed way. The headers of the object- 20 to-be-created may be found in the `hdrs' slot of the `MimeMultipart' 21 object. 22 23 bool output_child_p (MimeObject *parent, MimeObject *child) 24 25 Whether this child should be output. Default method always says `yes'. 26 27 int parse_child_line (MimeObject *obj, const char *line, int32_t length, 28 bool first_line_p) 29 30 When we have a line which should be handed off to the currently-active 31 child object, this method is called to do that. The `first_line_p' 32 variable will be true only for the very first line handed off to this 33 sub-part. The default method simply passes the line to the most- 34 recently-added child object. 35 36 int close_child (MimeObject *self) 37 38 When we reach the end of a sub-part (a separator line) this method is 39 called to shut down the currently-active child. The default method 40 simply calls `parse_eof' on the most-recently-added child object. 41 42 MimeMultipartBoundaryType check_boundary (MimeObject *obj, 43 const char *line, int32_t length) 44 45 This method is used to examine a line and determine whether it is a 46 part boundary, and if so, what kind. It should return a member of 47 the MimeMultipartBoundaryType describing the line. 48 49 const char *default_part_type 50 51 This is the type which should be assumed for sub-parts which have 52 no explicit type specified. The default is "text/plain", but the 53 "multipart/digest" subclass overrides this to "message/rfc822". 54 */ 55 56 typedef struct MimeMultipartClass MimeMultipartClass; 57 typedef struct MimeMultipart MimeMultipart; 58 59 typedef enum { 60 MimeMultipartPreamble, 61 MimeMultipartHeaders, 62 MimeMultipartPartFirstLine, 63 MimeMultipartPartLine, 64 MimeMultipartEpilogue 65 } MimeMultipartParseState; 66 67 typedef enum { 68 MimeMultipartBoundaryTypeNone, 69 MimeMultipartBoundaryTypeSeparator, 70 MimeMultipartBoundaryTypeTerminator 71 } MimeMultipartBoundaryType; 72 73 struct MimeMultipartClass { 74 MimeContainerClass container; 75 const char* default_part_type; 76 77 int (*create_child)(MimeObject*); 78 bool (*output_child_p)(MimeObject* self, MimeObject* child); 79 int (*close_child)(MimeObject*); 80 int (*parse_child_line)(MimeObject*, const char* line, int32_t length, 81 bool first_line_p); 82 MimeMultipartBoundaryType (*check_boundary)(MimeObject*, const char* line, 83 int32_t length); 84 }; 85 86 extern MimeMultipartClass mimeMultipartClass; 87 88 struct MimeMultipart { 89 MimeContainer container; /* superclass variables */ 90 char* boundary; /* Inter-part delimiter string */ 91 MimeHeaders* hdrs; /* headers of the part currently 92 being parsed, if any */ 93 MimeMultipartParseState state; /* State of parser */ 94 }; 95 96 extern void MimeMultipart_notify_emitter(MimeObject*); 97 98 #define MimeMultipartClassInitializer(ITYPE, CSUPER) \ 99 { MimeContainerClassInitializer(ITYPE, CSUPER) } 100 101 #endif /* _MIMEMULT_H_ */ 102