Back to index

enigmail  1.4.3
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes
nsPipeFilterListener Class Reference

#include <nsPipeFilterListener.h>

Inheritance diagram for nsPipeFilterListener:
Inheritance graph
[legend]
Collaboration diagram for nsPipeFilterListener:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIPIPEFILTERLISTENER
NS_DECL_NSIINPUTSTREAM 
nsPipeFilterListener ()
virtual ~nsPipeFilterListener ()
void init (in nsIStreamListener listener, in nsISupports ctxt, in string startDelimiter, in string endDelimiter, in unsigned long skipCount, in boolean keepDelimiters, in boolean mimeMultipart, in nsIStreamListener tailListener)
 Initializes filtering stream.
void write (in string buf, in unsigned long count, in nsIRequest request, in nsISupports ctxt)

Static Public Member Functions

static NS_METHOD Create (nsISupports *aOuter, REFNSIID aIID, void **aResult)

Public Attributes

readonly attribute ACString startDelimiter
readonly attribute ACString endDelimiter
readonly attribute ACString startLine
 contains the matched start delimiter up to the end of the line, including the trailing linebreak (but not the preceding linebreak)
readonly attribute ACString endLine
 contains the matched end delimiter up to the end of the line, including the preceding and trailing linebreaks

Protected Member Functions

NS_METHOD TransmitData (const char *buf, PRUint32 count, nsIStreamListener *listener, nsIRequest *aRequest, nsISupports *aContext)
NS_METHOD EndRequest (nsIRequest *aRequest, nsISupports *aContext)
PRInt32 MatchDelimiter (const char *buf, PRUint32 bufLen, LineMatchStatus &delim, nsCString &delimStr, nsCString &delimLine)
PRUint32 MatchString (const char *buf, PRUint32 count, const char *str, PRUint32 length, PRUint32 &strOffset)
nsresult HeaderSearch (const char *buf, PRUint32 count, PRUint32 *headerOffset)
nsresult ParseMimeHeaders (const char *mimeHeaders, PRUint32 count, PRInt32 *retval)
nsresult ParseHeader (const char *header, PRUint32 count)

Protected Attributes

EMBool mInitialized
EMBool mRequestStarted
EMBool mRequestEnded
EMBool mTailRequestStarted
nsCString mStartDelimiter
nsCString mEndDelimiter
nsCString mStartLine
nsCString mEndLine
LineMatchStatus mStart
LineMatchStatus mEnd
EMBool mKeepDelimiters
EMBool mMimeMultipart
EMBool mAutoMimeBoundary
EMBool mFirstMatch
EMBool mLastMatch
EMBool mSavePartMatch
nsCString mOldPartMatch
nsCString mPartMatch
PRUint32 mLinebreak
const char * mStreamBuf
PRUint32 mStreamOffset
PRUint32 mStreamLength
nsCOMPtr< nsIStreamListener > mListener
nsCOMPtr< nsIStreamListener > mTailListener
nsCOMPtr< nsISupports > mContext

Static Protected Attributes

static const char *const LineBreaks [3]

Detailed Description

Definition at line 58 of file nsPipeFilterListener.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSISTREAMLISTENER NS_DECL_NSIPIPEFILTERLISTENER NS_DECL_NSIINPUTSTREAM nsPipeFilterListener::nsPipeFilterListener ( )

Definition at line 133 of file nsPipeFilterListener.cpp.

{
  nsresult rv;
#ifdef FORCE_PR_LOG
  nsCOMPtr<nsIThread> myThread;
  rv = ENIG_GET_THREAD(myThread);
  DEBUG_LOG(("nsPipeFilterListener:: >>>>>>>>> DTOR(%p): myThread=%p\n",
         this, myThread.get()));
#endif

  // Release owning refs
  mListener = nsnull;
  mTailListener = nsnull;
  mContext = nsnull;
}

Member Function Documentation

static NS_METHOD nsPipeFilterListener::Create ( nsISupports *  aOuter,
REFNSIID  aIID,
void **  aResult 
) [static]
NS_IMETHODIMP nsPipeFilterListener::EndRequest ( nsIRequest *  aRequest,
nsISupports *  aContext 
) [protected]

Definition at line 575 of file nsPipeFilterListener.cpp.

{
  nsresult rv;
  DEBUG_LOG(("nsPipeFilterListener::EndRequest:(%p)\n", this));

  mRequestEnded = PR_TRUE;

  if (mListener) {
    if (!mRequestStarted) {
      mRequestStarted = PR_TRUE;

      rv = mListener->OnStartRequest(aRequest,
                                     mContext ? mContext.get() : aContext);
      NS_ENSURE_SUCCESS(rv, rv);

      if (mKeepDelimiters && !mStartLine.IsEmpty()) {
        rv = TransmitData(mStartLine.get(), mStartLine.Length(),
                          mListener, aRequest, aContext);
        NS_ENSURE_SUCCESS(rv, rv);
      }
    }

    if (!mPartMatch.IsEmpty()) {
      // Transmit any partially matched line
      DEBUG_LOG(("nsPipeFilterListener::EndRequest: PARTIALLY MATCHED LINE '%s'\n", mPartMatch.get()));
      rv = TransmitData(mPartMatch.get(), mPartMatch.Length(),
                        mListener, aRequest, aContext);
      NS_ENSURE_SUCCESS(rv, rv);

      mPartMatch = "";
    }

    if (mKeepDelimiters && !mEndLine.IsEmpty()) {
      rv = TransmitData(mEndLine.get(), mEndLine.Length(),
                        mListener, aRequest, aContext);
      NS_ENSURE_SUCCESS(rv, rv);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsPipeFilterListener::HeaderSearch ( const char *  buf,
PRUint32  count,
PRUint32 *  headerOffset 
) [protected]
void nsIPipeFilterListener::init ( in nsIStreamListener  listener,
in nsISupports  ctxt,
in string  startDelimiter,
in string  endDelimiter,
in unsigned long  skipCount,
in boolean  keepDelimiters,
in boolean  mimeMultipart,
in nsIStreamListener  tailListener 
) [inherited]

Initializes filtering stream.

PRInt32 nsPipeFilterListener::MatchDelimiter ( const char *  buf,
PRUint32  bufLen,
LineMatchStatus delim,
nsCString &  delimStr,
nsCString &  delimLine 
) [protected]

Definition at line 377 of file nsPipeFilterListener.cpp.

{
  //DEBUG_LOG(("nsPipeFilterListener::MatchDelimiter: bufLen=%d\n", bufLen));

  PRUint32 count = bufLen;

  while ((count > 0) && (delim.matchCount <= delim.skipCount)) {

    if (delim.matchOffset < delimStr.Length()) {
      PRUint32 consumed = MatchString(buf, count, delimStr.get(),
                                      delimStr.Length(),
                                      delim.matchOffset);
      //DEBUG_LOG(("nsPipeFilterListener::MatchDelimiter: consumed=%d\n", consumed));
      if (!consumed) {
          ERROR_LOG(("nsPipeFilterListener::MatchDelimiter: consumed=%d\n", consumed));
        return -1;
      }

      buf   += consumed;
      count -= consumed;

      if (delim.matchOffset >= delimStr.Length()) {
        DEBUG_LOG(("nsPipeFilterListener::MatchDelimiter: delimStr='%s'\n", delimStr.get()));
        if (mLastMatch) {
          delimLine = mPartMatch;
          mPartMatch = "";
        } else {
          delimLine = delimStr;
        }
        mLinebreak = 0;
      }

      if (!count)
        return bufLen;

      if (delim.matchOffset < delimStr.Length()) {
        ERROR_LOG(("nsPipeFilterListener::MatchDelimiter: count=%d, delim.matchOffset=%d, delimStr='%s'\n", count, delim.matchOffset, delimStr.get() ));
        return -1;
      }
    }

    // Match to end of line
    while (count > 0) {
      char ch = buf[0];

      if (delim.matchedCR) {
        // Already matched a CR

        if (ch == '\n') {
          // Consume LF following CR
          delimLine.Append(ch);
          buf++;
          count--;
        }

        delim.matchedLine = PR_TRUE;
        break;
      }

      delimLine.Append(ch);
      buf++;
      count--;

      if (ch == '\n') {
        delim.matchedLine = PR_TRUE;
        break;
      }

      if (ch == '\r') {
        delim.matchedCR = PR_TRUE;
      }
    }

    if (delim.matchedLine) {
      delim.matchCount++;
      delim.matchOffset = 0;
      delim.matchedCR = PR_FALSE;
      delim.matchedLine = PR_FALSE;

      DEBUG_LOG(("nsPipeFilterListener::MatchDelimiter: delimLine(%d)='%s'\n", delimLine.Length(), delimLine.get()));
      DEBUG_LOG(("nsPipeFilterListener::MatchDelimiter: matchCount=%d\n", delim.matchCount));

      if (mAutoMimeBoundary) {
        // Eliminate all trailing whitespace (including linebreaks) for delimiter
        mAutoMimeBoundary = PR_FALSE;
        mStartDelimiter = mStartLine;
        mStartDelimiter.Trim(" \t\r\n", PR_FALSE, PR_TRUE);
        mEndDelimiter = mStartDelimiter;
        DEBUG_LOG(("nsPipeFilterListener::MatchDelimiter: Mime Boundary='%s'\n", mStartDelimiter.get()));
      }

    }
  }

  return bufLen - count;
}

Here is the call graph for this function:

PRUint32 nsPipeFilterListener::MatchString ( const char *  buf,
PRUint32  count,
const char *  str,
PRUint32  length,
PRUint32 &  strOffset 
) [protected]

Definition at line 487 of file nsPipeFilterListener.cpp.

{
  //DEBUG_LOG(("nsPipeFilterListener::MatchString: strOffset=%d, length=%d\n", strOffset, length));

  if (strOffset >= length) {
    // Complete match
    return 0;
  }

  PRUint32 consumed = count;

  PRUint32 j;
  char ch;
  for (j=0; j < count; j++) {

    ch = buf[j];
    if ( (ch == str[strOffset]) &&
         ((strOffset > 0) || (mLinebreak > 0) || (mFirstMatch && (j == 0)) )) {
      // Extend match
      strOffset++;
      if (mLastMatch)
        mPartMatch += ch;

      if (strOffset >= length) {
        // Complete match
        consumed = j+1;
        break;
      }

    } else {
      // Match again from beginning of string
      strOffset = 0;

      if ((mLinebreak == 1) && (ch == '\n')) {
        mLinebreak = 2;
        if (mLastMatch)
          mPartMatch += '\n';

      } else {
        if (mLastMatch && mSavePartMatch) {
          mOldPartMatch = mPartMatch;
          mSavePartMatch = PR_FALSE;
        }

        if (ch == '\r') {
          mLinebreak = 1;
          if (mLastMatch)
            mPartMatch = '\r';

        } else if (ch == '\n') {
          mLinebreak = 3;
          if (mLastMatch)
            mPartMatch = '\n';

        } else if (mLinebreak > 0) {
          mLinebreak = 0;
          if (mLastMatch)
            mPartMatch = "";
        }
      }
    }
  }

  mFirstMatch = PR_FALSE;

  return consumed;
}

Here is the caller graph for this function:

nsresult nsPipeFilterListener::ParseHeader ( const char *  header,
PRUint32  count 
) [protected]
nsresult nsPipeFilterListener::ParseMimeHeaders ( const char *  mimeHeaders,
PRUint32  count,
PRInt32 *  retval 
) [protected]
NS_IMETHODIMP nsPipeFilterListener::TransmitData ( const char *  buf,
PRUint32  count,
nsIStreamListener *  listener,
nsIRequest *  aRequest,
nsISupports *  aContext 
) [protected]

Definition at line 201 of file nsPipeFilterListener.cpp.

{
  nsresult rv;

  DEBUG_LOG(("nsPipeFilterListener::TransmitData: (%p) %d\n", this, count));

  if (!listener)
    return NS_OK;

  mStreamBuf = buf;
  mStreamOffset = 0;
  mStreamLength = count;

  rv = listener->OnDataAvailable(aRequest,
                                 mContext ? mContext.get() : aContext,
                                 (nsIInputStream*)(this),
                                 0, count);
  if (NS_FAILED(rv)) {
    DEBUG_LOG(("nsPipeFilterListener::TransmitData: (%p) rv=%p\n", this, rv));
    return rv;
  }

  Close();

  return NS_OK;
}

Here is the caller graph for this function:

void nsIPipeFilterListener::write ( in string  buf,
in unsigned long  count,
in nsIRequest  request,
in nsISupports  ctxt 
) [inherited]

Member Data Documentation

readonly attribute ACString nsIPipeFilterListener::endDelimiter [inherited]

Definition at line 57 of file nsIPipeFilterListener.idl.

readonly attribute ACString nsIPipeFilterListener::endLine [inherited]

contains the matched end delimiter up to the end of the line, including the preceding and trailing linebreaks

Definition at line 69 of file nsIPipeFilterListener.idl.

const char *const nsPipeFilterListener::LineBreaks [static, protected]
Initial value:
 {
  "\r",
  "\r\n",
  "\n"
}

Definition at line 99 of file nsPipeFilterListener.h.

Definition at line 118 of file nsPipeFilterListener.h.

nsCOMPtr<nsISupports> nsPipeFilterListener::mContext [protected]

Definition at line 134 of file nsPipeFilterListener.h.

Definition at line 113 of file nsPipeFilterListener.h.

nsCString nsPipeFilterListener::mEndDelimiter [protected]

Definition at line 107 of file nsPipeFilterListener.h.

nsCString nsPipeFilterListener::mEndLine [protected]

Definition at line 110 of file nsPipeFilterListener.h.

Definition at line 119 of file nsPipeFilterListener.h.

Definition at line 101 of file nsPipeFilterListener.h.

Definition at line 115 of file nsPipeFilterListener.h.

Definition at line 120 of file nsPipeFilterListener.h.

PRUint32 nsPipeFilterListener::mLinebreak [protected]

Definition at line 125 of file nsPipeFilterListener.h.

nsCOMPtr<nsIStreamListener> nsPipeFilterListener::mListener [protected]

Definition at line 132 of file nsPipeFilterListener.h.

Definition at line 116 of file nsPipeFilterListener.h.

nsCString nsPipeFilterListener::mOldPartMatch [protected]

Definition at line 123 of file nsPipeFilterListener.h.

nsCString nsPipeFilterListener::mPartMatch [protected]

Definition at line 124 of file nsPipeFilterListener.h.

Definition at line 103 of file nsPipeFilterListener.h.

Definition at line 102 of file nsPipeFilterListener.h.

Definition at line 121 of file nsPipeFilterListener.h.

Definition at line 112 of file nsPipeFilterListener.h.

Definition at line 106 of file nsPipeFilterListener.h.

nsCString nsPipeFilterListener::mStartLine [protected]

Definition at line 109 of file nsPipeFilterListener.h.

const char* nsPipeFilterListener::mStreamBuf [protected]

Definition at line 127 of file nsPipeFilterListener.h.

Definition at line 129 of file nsPipeFilterListener.h.

Definition at line 128 of file nsPipeFilterListener.h.

nsCOMPtr<nsIStreamListener> nsPipeFilterListener::mTailListener [protected]

Definition at line 133 of file nsPipeFilterListener.h.

Definition at line 104 of file nsPipeFilterListener.h.

readonly attribute ACString nsIPipeFilterListener::startDelimiter [inherited]

Definition at line 55 of file nsIPipeFilterListener.idl.

readonly attribute ACString nsIPipeFilterListener::startLine [inherited]

contains the matched start delimiter up to the end of the line, including the trailing linebreak (but not the preceding linebreak)

Definition at line 63 of file nsIPipeFilterListener.idl.


The documentation for this class was generated from the following files: