static int MimeMultipartAlternative_create_child(MimeObject *obj) { MimeMultipart *mult = (MimeMultipart *) obj; MimeMultipartAlternative *malt = (MimeMultipartAlternative *) obj; bool displayable = MimeMultipartAlternative_display_part_p (obj, mult->hdrs); MimeMultipartAlternative_flush_children(obj, false, displayable); mult->state = MimeMultipartPartFirstLine; int32_t i = malt->pending_parts++; if (malt->pending_parts > malt->max_parts) { malt->max_parts = malt->pending_parts; malt->buffered_hdrs = (MimeHeaders **) PR_REALLOC(malt->buffered_hdrs, malt->max_parts * sizeof *malt->buffered_hdrs); if (! malt->buffered_hdrs) return MIME_OUT_OF_MEMORY; malt->part_buffers = (MimePartBufferData **) PR_REALLOC(malt->part_buffers, malt->max_parts * sizeof *malt->part_buffers); if (! malt->part_buffers) return MIME_OUT_OF_MEMORY; } malt->buffered_hdrs[i] = MimeHeaders_copy(mult->hdrs); if (!malt->buffered_hdrs[i]) return MIME_OUT_OF_MEMORY; malt->part_buffers[i] = MimePartBufferCreate(); if (!malt->part_buffers[i]) return MIME_OUT_OF_MEMORY; return 0; }
static int MimeEncrypted_close_headers (MimeObject *obj) { MimeEncrypted *enc = (MimeEncrypted *) obj; if (enc->part_buffer) return -1; enc->part_buffer = MimePartBufferCreate(); if (!enc->part_buffer) return MIME_OUT_OF_MEMORY; return 0; }
static int MimeMultipartSigned_parse_child_line (MimeObject *obj, const char *line, PRInt32 length, bool first_line_p) { MimeMultipartSigned *sig = (MimeMultipartSigned *) obj; MimeContainer *cont = (MimeContainer *) obj; int status = 0; /* Shouldn't have made any sub-parts yet. */ PR_ASSERT(cont->nchildren == 0); if (cont->nchildren != 0) return -1; switch (sig->state) { case MimeMultipartSignedPreamble: case MimeMultipartSignedBodyFirstHeader: case MimeMultipartSignedBodyHeaders: // How'd we get here? Oh well, fall through. NS_ERROR("wrong state in parse child line"); case MimeMultipartSignedBodyFirstLine: PR_ASSERT(first_line_p); if (!sig->part_buffer) { sig->part_buffer = MimePartBufferCreate(); if (!sig->part_buffer) return MIME_OUT_OF_MEMORY; } /* fall through */ case MimeMultipartSignedBodyLine: { /* This is the first part; we are buffering it, and will emit it all at the end (so that we know whether the signature matches before showing anything to the user.) */ /* The newline issues here are tricky, since both the newlines before and after the boundary string are to be considered part of the boundary: this is so that a part can be specified such that it does not end in a trailing newline. To implement this, we send a newline *before* each line instead of after, except for the first line, which is not preceeded by a newline. */ /* Remove the trailing newline... */ if (length > 0 && line[length-1] == '\n') length--; if (length > 0 && line[length-1] == '\r') length--; PR_ASSERT(sig->part_buffer); PR_ASSERT(first_line_p == (sig->state == MimeMultipartSignedBodyFirstLine)); if (!first_line_p) { /* Push out a preceeding newline... */ char nl[] = MSG_LINEBREAK; status = MimePartBufferWrite (sig->part_buffer, nl, MSG_LINEBREAK_LEN); if (status < 0) return status; } /* Now push out the line sans trailing newline. */ if (length > 0) status = MimePartBufferWrite (sig->part_buffer, line, length); if (status < 0) return status; } break; case MimeMultipartSignedSignatureHeaders: // How'd we get here? Oh well, fall through. NS_ERROR("should have already parse sig hdrs"); case MimeMultipartSignedSignatureFirstLine: case MimeMultipartSignedSignatureLine: /* Nothing to do here -- hashing of the signature part is handled up in MimeMultipartSigned_parse_line(). */ break; case MimeMultipartSignedEpilogue: /* Too many kids? MimeMultipartSigned_create_child() should have prevented us from getting here. */ NS_ERROR("too many kids?"); return -1; break; default: /* bad state */ NS_ERROR("bad state in multipart signed parse line"); return -1; break; } return status; }