コード例 #1
0
        public State ParseBuffer(
            byte[] buffer,
            int bytesReady,
            ref int bytesConsumed,
            out ArraySegment <byte> remainingBodyPart,
            out ArraySegment <byte> bodyPart,
            out bool isFinalBodyPart)
        {
            if (buffer == null)
            {
                throw Error.ArgumentNull("buffer");
            }

            State parseStatus = State.NeedMoreData;

            remainingBodyPart = MimeMultipartParser._emptyBodyPart;
            bodyPart          = MimeMultipartParser._emptyBodyPart;
            isFinalBodyPart   = false;

            try
            {
                parseStatus = MimeMultipartParser.ParseBodyPart(
                    buffer,
                    bytesReady,
                    ref bytesConsumed,
                    ref this._bodyPartState,
                    this._maxMessageSize,
                    ref this._totalBytesConsumed,
                    this._currentBoundary);
            }
            catch (Exception)
            {
                parseStatus = State.Invalid;
            }

            remainingBodyPart = this._currentBoundary.GetDiscardedBoundary();
            bodyPart          = this._currentBoundary.BodyPart;
            if (parseStatus == State.BodyPartCompleted)
            {
                isFinalBodyPart = this._currentBoundary.IsFinal;
                this._currentBoundary.ClearAll();
            }
            else
            {
                this._currentBoundary.ClearBodyPart();
            }

            return(parseStatus);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeMultipartBodyPartParser"/> class.
        /// </summary>
        /// <param name="content">An existing <see cref="HttpContent"/> instance to use for the object's content.</param>
        /// <param name="streamProvider">A stream provider providing output streams for where to write body parts as they are parsed.</param>
        /// <param name="maxMessageSize">The max length of the entire MIME multipart message.</param>
        /// <param name="maxBodyPartHeaderSize">The max length of the MIME header within each MIME body part.</param>
        public MimeMultipartBodyPartParser(
            HttpContent content,
            MultipartStreamProvider streamProvider,
            long maxMessageSize,
            int maxBodyPartHeaderSize)
        {
            Contract.Assert(content != null, "content cannot be null.");
            Contract.Assert(streamProvider != null, "streamProvider cannot be null.");

            string boundary = ValidateArguments(content, maxMessageSize, true);

            this._mimeParser = new MimeMultipartParser(boundary, maxMessageSize);
            this._currentBodyPart = new MimeBodyPart(streamProvider, maxBodyPartHeaderSize, content);
            this._content = content;
            this._maxBodyPartHeaderSize = maxBodyPartHeaderSize;

            this._streamProvider = streamProvider;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeMultipartBodyPartParser"/> class.
        /// </summary>
        /// <param name="content">An existing <see cref="HttpContent"/> instance to use for the object's content.</param>
        /// <param name="streamProvider">A stream provider providing output streams for where to write body parts as they are parsed.</param>
        /// <param name="maxMessageSize">The max length of the entire MIME multipart message.</param>
        /// <param name="maxBodyPartHeaderSize">The max length of the MIME header within each MIME body part.</param>
        public MimeMultipartBodyPartParser(
            HttpContent content,
            MultipartStreamProvider streamProvider,
            long maxMessageSize,
            int maxBodyPartHeaderSize)
        {
            Contract.Assert(content != null, "content cannot be null.");
            Contract.Assert(streamProvider != null, "streamProvider cannot be null.");

            string boundary = ValidateArguments(content, maxMessageSize, true);

            this._mimeParser            = new MimeMultipartParser(boundary, maxMessageSize);
            this._currentBodyPart       = new MimeBodyPart(streamProvider, maxBodyPartHeaderSize, content);
            this._content               = content;
            this._maxBodyPartHeaderSize = maxBodyPartHeaderSize;

            this._streamProvider = streamProvider;
        }
コード例 #4
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         this._mimeParser = null;
         this.CleanupCurrentBodyPart();
     }
 }