Esempio n. 1
0
static int
MimeHandleDecryptedOutputLine (char *line, PRInt32 length, MimeObject *obj)
{
  /* Largely the same as MimeMessage_parse_line (the other MIME container
	 type which contains exactly one child.)
   */
  MimeEncrypted *enc = (MimeEncrypted *) obj;
  int status = 0;

  if (!line || !*line) return -1;

  /* If we're supposed to write this object, but aren't supposed to convert
	 it to HTML, simply pass it through unaltered. */
  if (obj->output_p &&
	  obj->options &&
	  !obj->options->write_html_p &&
	  obj->options->output_fn)
	return MimeObject_write(obj, line, length, PR_TRUE);

  /* If we already have a child object in the buffer, then we're done parsing
	 headers, and all subsequent lines get passed to the inferior object
	 without further processing by us.  (Our parent will stop feeding us
	 lines when this MimeMessage part is out of data.)
   */
  if (enc->part_buffer)
	return MimePartBufferWrite (enc->part_buffer, line, length);

  /* Otherwise we don't yet have a child object in the buffer, which means
	 we're not done parsing our headers yet.
   */
  if (!enc->hdrs)
	{
	  enc->hdrs = MimeHeaders_new();
	  if (!enc->hdrs) return MIME_OUT_OF_MEMORY;
	}

  status = MimeHeaders_parse_line(line, length, enc->hdrs);
  if (status < 0) return status;

  /* If this line is blank, we're now done parsing headers, and should
	 examine our content-type to create our "body" part.
   */
  if (*line == nsCRT::CR || *line == nsCRT::LF)
	{
	  status = MimeEncrypted_close_headers(obj);
	  if (status < 0) return status;
	}

  return 0;
}
static int
MimeMultipartAlternative_parse_child_line (MimeObject *obj,
                       const char *line, int32_t length,
                       bool first_line_p)
{
  MimeMultipartAlternative *malt = (MimeMultipartAlternative *) obj;

  NS_ASSERTION(malt->pending_parts, "should be pending parts, but there aren't");
  if (!malt->pending_parts)
    return -1;
  int32_t i = malt->pending_parts - 1;

  /* Push this line into the buffer for later retrieval. */
  return MimePartBufferWrite (malt->part_buffers[i], line, length);
}
Esempio n. 3
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;
}