reSIProcate/stack  9694
Public Member Functions | Protected Member Functions | Private Types | Private Attributes | Friends
resip::LazyParser Class Reference

The base-class for all lazily-parsed SIP grammar elements. More...

#include <LazyParser.hxx>

Inheritance diagram for resip::LazyParser:
Inheritance graph
[legend]
Collaboration diagram for resip::LazyParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LazyParser (const HeaderFieldValue &headerFieldValue)
 LazyParser (const char *buf, int length)
 LazyParser (const HeaderFieldValue &headerFieldValue, HeaderFieldValue::CopyPaddingEnum e)
 LazyParser (const LazyParser &rhs)
 LazyParser (const LazyParser &rhs, HeaderFieldValue::CopyPaddingEnum e)
LazyParseroperator= (const LazyParser &rhs)
virtual ~LazyParser ()
virtual EncodeStreamencodeParsed (EncodeStream &str) const =0
virtual void parse (ParseBuffer &pb)=0
EncodeStreamencode (EncodeStream &str) const
 Encodes this element to a stream, in the fashion it should be represented on the wire.
bool isParsed () const
 Returns true iff a parse has been attempted.
HeaderFieldValuegetHeaderField ()
void checkParsed () const
void checkParsed ()
void doParse () const
void markDirty () const
bool isWellFormed () const
 Returns true iff this element was parsed successfully, according to the implementation of parse().

Protected Member Functions

 LazyParser ()
void clear ()
virtual const DataerrorContext () const =0

Private Types

enum  ParseState { NOT_PARSED, WELL_FORMED, MALFORMED, DIRTY }

Private Attributes

HeaderFieldValue mHeaderField
ParseState mState

Friends

class Contents

Detailed Description

The base-class for all lazily-parsed SIP grammar elements.

Subclasses of this are parse-on-access; the parse will be carried out (if it hasn't already) the first time one of the members is accessed. Right now, all header field values and SIP bodies are lazily parsed.

Application writers are expected to make consistent use of isWellFormed() in order to determine whether an element is parseable. Using a try/catch block around accesses will not work as expected, since an exception will only be thrown the _first_ time an access is made, and it is determined that the element isn't parseable.

Definition at line 34 of file LazyParser.hxx.


Member Enumeration Documentation

Enumerator:
NOT_PARSED 
WELL_FORMED 
MALFORMED 
DIRTY 

Definition at line 144 of file LazyParser.hxx.

      {
         NOT_PARSED,
         WELL_FORMED, // Parsed, well-formed, but underlying buffer is still valid
         MALFORMED, // Parsed, malformed, underlying buffer is still valid
         DIRTY // Well-formed, and underlying buffer is invalid
      } ParseState;

Constructor & Destructor Documentation

LazyParser::LazyParser ( const HeaderFieldValue headerFieldValue) [explicit]

Definition at line 16 of file LazyParser.cxx.

LazyParser::LazyParser ( const char *  buf,
int  length 
)

Definition at line 28 of file LazyParser.cxx.

                                                  :
   mHeaderField(buf, length),
   mState(buf == 0 ? DIRTY : NOT_PARSED)
{}
LazyParser::LazyParser ( const HeaderFieldValue headerFieldValue,
HeaderFieldValue::CopyPaddingEnum  e 
)

Definition at line 22 of file LazyParser.cxx.

   : mHeaderField(headerFieldValue, e), // Causes ownership to be taken. Oh well
      mState(mHeaderField.getBuffer() == 0 ? DIRTY : NOT_PARSED)
{}
LazyParser::LazyParser ( const LazyParser rhs)

Definition at line 39 of file LazyParser.cxx.

   : mHeaderField((rhs.mState==DIRTY ? HeaderFieldValue::Empty : rhs.mHeaderField)), // Pretty cheap when rhs is DIRTY
      mState(rhs.mState)
{}
LazyParser::LazyParser ( const LazyParser rhs,
HeaderFieldValue::CopyPaddingEnum  e 
)

Definition at line 44 of file LazyParser.cxx.

   :  mHeaderField((rhs.mState==DIRTY ? HeaderFieldValue::Empty : rhs.mHeaderField), e), // Pretty cheap when rhs is DIRTY
      mState(rhs.mState)
{}
LazyParser::~LazyParser ( ) [virtual]

Definition at line 50 of file LazyParser.cxx.

References clear().

{
   clear();
}

Here is the call graph for this function:

LazyParser::LazyParser ( ) [protected]

Definition at line 33 of file LazyParser.cxx.


Member Function Documentation

void resip::LazyParser::checkParsed ( ) const [inline]

Definition at line 102 of file LazyParser.hxx.

References doParse(), mState, and NOT_PARSED.

Referenced by resip::Uri::aorEqual(), checkParsed(), resip::WarningCategory::code(), resip::UInt32Category::comment(), resip::IntegerCategory::comment(), resip::RAckCategory::cSequence(), resip::DateCategory::dayOfMonth(), resip::DateCategory::dayOfWeek(), resip::NameAddr::displayName(), resip::Uri::embedded(), resip::GenericUri::exists(), resip::Auth::exists(), resip::ExpiresCategory::exists(), resip::UInt32Category::exists(), resip::CallID::exists(), resip::Via::exists(), resip::Token::exists(), resip::Mime::exists(), resip::MessageWaitingContents::exists(), resip::NameAddr::exists(), resip::Contents::exists(), resip::ParserCategory::exists(), resip::Uri::exists(), resip::Rlmi::get(), resip::Uri::getAorAsUri(), resip::Uri::getAorInternal(), resip::Contents::getBodyData(), resip::Pidf::getEntity(), resip::RequestLine::getMethod(), resip::Pidf::getNumTuples(), resip::Pidf::getSimpleStatus(), resip::StatusLine::getSipVersion(), resip::RequestLine::getSipVersion(), resip::Pidf::getTuples(), resip::Uri::hasEmbedded(), resip::MessageWaitingContents::hasMessages(), resip::MessageWaitingContents::header(), resip::Contents::header(), resip::Uri::host(), resip::WarningCategory::hostname(), resip::DateCategory::hour(), resip::NameAddr::isAllContacts(), resip::Uri::isEnumSearchable(), isWellFormed(), main(), resip::SipFrag::message(), resip::CSeqCategory::method(), resip::RAckCategory::method(), resip::RequestLine::method(), resip::DateCategory::minute(), resip::DateCategory::month(), resip::OctetContents::octets(), resip::Uri::opaque(), resip::Uri::operator<(), resip::Uri::operator==(), resip::ParserCategory::param(), resip::SipMessage::parseAllHeaders(), resip::MultipartMixedContents::parts(), resip::Uri::password(), resip::Uri::port(), resip::Via::protocolName(), resip::Via::protocolVersion(), resip::StatusLine::reason(), resip::GenericUri::remove(), resip::Auth::remove(), resip::ExpiresCategory::remove(), resip::UInt32Category::remove(), resip::CallID::remove(), resip::Via::remove(), resip::Token::remove(), resip::Mime::remove(), resip::NameAddr::remove(), resip::MessageWaitingContents::remove(), resip::ParserCategory::remove(), resip::Uri::remove(), resip::Uri::removeEmbedded(), resip::ParserCategory::removeParametersExcept(), resip::StatusLine::responseCode(), resip::RAckCategory::rSequence(), resip::Auth::scheme(), resip::Uri::scheme(), resip::DateCategory::second(), resip::Via::sentHost(), resip::Via::sentPort(), resip::CSeqCategory::sequence(), resip::SdpContents::session(), resip::SipMessage::setBody(), resip::Pidf::setEntity(), resip::Pidf::setSimpleId(), resip::Pidf::setSimpleStatus(), resip::StatusLine::statusCode(), resip::Mime::subType(), resip::PlainContents::text(), resip::X509Contents::text(), resip::Pkcs8Contents::text(), resip::CpimContents::text(), resip::WarningCategory::text(), resip::InvalidContents::text(), resip::Pidf::text(), resip::Via::transport(), resip::Mime::type(), resip::CSeqCategory::unknownMethodName(), resip::RAckCategory::unknownMethodName(), resip::RequestLine::unknownMethodName(), resip::RequestLine::uri(), resip::GenericUri::uri(), resip::NameAddr::uri(), resip::Uri::user(), resip::Uri::userParameters(), resip::CallID::value(), resip::PrivacyCategory::value(), resip::IntegerCategory::value(), resip::UInt32Category::value(), resip::StringCategory::value(), resip::Token::value(), resip::ExpiresCategory::value(), and resip::DateCategory::year().

      {
         if (mState==NOT_PARSED)
         {
            doParse();
         }
      }

Here is the call graph for this function:

void resip::LazyParser::checkParsed ( ) [inline]

Definition at line 109 of file LazyParser.hxx.

References checkParsed(), DIRTY, and mState.

      {
         const LazyParser* constThis = const_cast<const LazyParser*>(this);
         constThis->checkParsed();
         mState=DIRTY;
      }

Here is the call graph for this function:

void LazyParser::clear ( void  ) [protected]
void LazyParser::doParse ( ) const

Definition at line 73 of file LazyParser.cxx.

References errorContext(), resip::HeaderFieldValue::getBuffer(), resip::HeaderFieldValue::getLength(), MALFORMED, mHeaderField, mState, parse(), and WELL_FORMED.

Referenced by checkParsed().

{
   LazyParser* ncThis = const_cast<LazyParser*>(this);
   // .bwc. We assume the worst, and if the parse succeeds, we update.
   ncThis->mState = MALFORMED;
   ParseBuffer pb(mHeaderField.getBuffer(), mHeaderField.getLength(), errorContext());
   ncThis->parse(pb);
   // .bwc. If we get this far without throwing, the parse has succeeded.
   ncThis->mState = WELL_FORMED;
}

Here is the call graph for this function:

EncodeStream & LazyParser::encode ( EncodeStream str) const

Encodes this element to a stream, in the fashion it should be represented on the wire.

Parameters:
strThe ostream to encode to.
Returns:
A reference to str.

Definition at line 105 of file LazyParser.cxx.

References DIRTY, resip::HeaderFieldValue::encode(), encodeParsed(), mHeaderField, and mState.

Referenced by resip::ParserContainerBase::HeaderKit::encode(), resip::SipMessage::encode(), resip::SipMessage::encodeEmbedded(), resip::Pidf::encodeParsed(), resip::SipMessage::getCanonicalIdentityString(), main(), resip::Uri::setUriPasswordEncoding(), and resip::Uri::setUriUserEncoding().

{
   if (mState == DIRTY)
   {
      return encodeParsed(str);
   }
   else
   {
      mHeaderField.encode(str);
      return str;
   }
}

Here is the call graph for this function:

virtual EncodeStream& resip::LazyParser::encodeParsed ( EncodeStream str) const [pure virtual]
virtual const Data& resip::LazyParser::errorContext ( ) const [protected, pure virtual]
HeaderFieldValue& resip::LazyParser::getHeaderField ( ) [inline]

Definition at line 96 of file LazyParser.hxx.

References mHeaderField.

{ return mHeaderField; }
bool resip::LazyParser::isParsed ( ) const [inline]

Returns true iff a parse has been attempted.

Note:
This means that this will return true if a parse failed earlier.

Definition at line 91 of file LazyParser.hxx.

References mState, and NOT_PARSED.

Referenced by resip::ParserCategory::operator=(), and resip::ParserCategory::ParserCategory().

{return (mState!=NOT_PARSED);}
bool LazyParser::isWellFormed ( ) const

Returns true iff this element was parsed successfully, according to the implementation of parse().

App writers are expected to use this extensively, since a failure in the parse-on-access will throw an exception the _first_ time access is made, but nothing will happen on subsequent accesses. (Writing a try/catch block when you try to inspect the members of a subclass will only work as intended if the subclass hasn't been accessed before.)

Definition at line 85 of file LazyParser.cxx.

References checkParsed(), MALFORMED, and mState.

Referenced by resip::SipMessage::getContents(), main(), resip::Helper::makeResponse(), resip::Helper::massageRoute(), resip::TransactionState::process(), resip::TransactionState::saveOriginalContactAndVia(), resip::TransactionState::sendToTU(), resip::TransportSelector::transmit(), and resip::Helper::validateMessage().

{
   try
   {
      checkParsed();
   }
   catch(resip::ParseException&)
   {
   }
   
   return (mState!=MALFORMED);
}

Here is the call graph for this function:

void resip::LazyParser::markDirty ( ) const [inline]

Definition at line 116 of file LazyParser.hxx.

References DIRTY, and mState.

LazyParser & LazyParser::operator= ( const LazyParser rhs)

Definition at line 56 of file LazyParser.cxx.

References clear(), DIRTY, mHeaderField, and mState.

{
   assert( &rhs != 0 );
   
   if (this != &rhs)
   {
      clear();
      mState = rhs.mState;
      if (rhs.mState!=DIRTY)
      {
         mHeaderField=rhs.mHeaderField;
      }
   }
   return *this;
}

Here is the call graph for this function:

virtual void resip::LazyParser::parse ( ParseBuffer pb) [pure virtual]

Friends And Related Function Documentation

friend class Contents [friend]

Definition at line 140 of file LazyParser.hxx.


Member Data Documentation

Definition at line 142 of file LazyParser.hxx.

Referenced by clear(), doParse(), encode(), getHeaderField(), and operator=().

Definition at line 151 of file LazyParser.hxx.

Referenced by checkParsed(), doParse(), encode(), isParsed(), isWellFormed(), markDirty(), and operator=().


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