|
reSIProcate/stack
9694
|
The base-class for all lazily-parsed SIP grammar elements. More...
#include <LazyParser.hxx>


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) | |
| LazyParser & | operator= (const LazyParser &rhs) |
| virtual | ~LazyParser () |
| virtual EncodeStream & | encodeParsed (EncodeStream &str) const =0 |
| virtual void | parse (ParseBuffer &pb)=0 |
| EncodeStream & | encode (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. | |
| HeaderFieldValue & | getHeaderField () |
| 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 Data & | errorContext () const =0 |
Private Types | |
| enum | ParseState { NOT_PARSED, WELL_FORMED, MALFORMED, DIRTY } |
Private Attributes | |
| HeaderFieldValue | mHeaderField |
| ParseState | mState |
Friends | |
| class | Contents |
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.
enum resip::LazyParser::ParseState [private] |
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;
| LazyParser::LazyParser | ( | const HeaderFieldValue & | headerFieldValue | ) | [explicit] |
Definition at line 16 of file LazyParser.cxx.
: mHeaderField(headerFieldValue, HeaderFieldValue::NoOwnership), mState(mHeaderField.getBuffer() == 0 ? DIRTY : NOT_PARSED) { }
| 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();
}

| LazyParser::LazyParser | ( | ) | [protected] |
Definition at line 33 of file LazyParser.cxx.
: mHeaderField(), mState(DIRTY) { }
| 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();
}
}

| 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;
}

| void LazyParser::clear | ( | void | ) | [protected] |
Reimplemented in resip::ParserCategory, resip::Contents, resip::MessageWaitingContents, and resip::MultipartMixedContents.
Definition at line 99 of file LazyParser.cxx.
References resip::HeaderFieldValue::clear(), and mHeaderField.
Referenced by resip::TransportSelector::findTransportByVia(), resip::Helper::makeResponse(), operator=(), resip::DeprecatedDialog::updateRequest(), and ~LazyParser().
{
mHeaderField.clear();
}

| 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;
}

| EncodeStream & LazyParser::encode | ( | EncodeStream & | str | ) | const |
Encodes this element to a stream, in the fashion it should be represented on the wire.
| str | The ostream to encode to. |
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;
}
}

| virtual EncodeStream& resip::LazyParser::encodeParsed | ( | EncodeStream & | str | ) | const [pure virtual] |
Implemented in resip::SdpContents, resip::Uri, resip::DateCategory, resip::NameAddr, resip::Mime, resip::Token, resip::Pidf, resip::RAckCategory, resip::Via, resip::CSeqCategory, resip::MessageWaitingContents, resip::RequestLine, resip::SipFrag, resip::CallID, resip::PrivacyCategory, resip::InvalidContents, resip::MultipartMixedContents, resip::OctetContents, resip::StatusLine, resip::Pkcs7Contents, resip::Pkcs8Contents, resip::WarningCategory, resip::X509Contents, resip::CpimContents, resip::ExpiresCategory, resip::GenericUri, resip::PlainContents, resip::Rlmi, resip::StringCategory, resip::UInt32Category, resip::IntegerCategory, resip::Auth, and resip::StartLine.
Referenced by encode().
| virtual const Data& resip::LazyParser::errorContext | ( | ) | const [protected, pure virtual] |
Implemented in resip::Contents, resip::ParserCategory, resip::RequestLine, resip::StatusLine, and resip::StartLine.
Referenced by doParse().
| HeaderFieldValue& resip::LazyParser::getHeaderField | ( | ) | [inline] |
| bool resip::LazyParser::isParsed | ( | ) | const [inline] |
Returns true iff a parse has been attempted.
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);
}

| void resip::LazyParser::markDirty | ( | ) | const [inline] |
| 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;
}

| virtual void resip::LazyParser::parse | ( | ParseBuffer & | pb | ) | [pure virtual] |
Implemented in resip::SdpContents, resip::Uri, resip::DateCategory, resip::Pidf, resip::MessageWaitingContents, resip::NameAddr, resip::Mime, resip::SipFrag, resip::RAckCategory, resip::Token, resip::Via, resip::CSeqCategory, resip::RequestLine, resip::InvalidContents, resip::MultipartMixedContents, resip::OctetContents, resip::Pkcs7Contents, resip::Pkcs8Contents, resip::X509Contents, resip::CallID, resip::CpimContents, resip::PlainContents, resip::PrivacyCategory, resip::Rlmi, resip::ExpiresCategory, resip::StatusLine, resip::StringCategory, resip::UInt32Category, resip::WarningCategory, resip::GenericUri, resip::IntegerCategory, resip::Auth, and resip::StartLine.
Referenced by doParse().
friend class Contents [friend] |
Definition at line 140 of file LazyParser.hxx.
Definition at line 142 of file LazyParser.hxx.
Referenced by clear(), doParse(), encode(), getHeaderField(), and operator=().
ParseState resip::LazyParser::mState [mutable, private] |
Definition at line 151 of file LazyParser.hxx.
Referenced by checkParsed(), doParse(), encode(), isParsed(), isWellFormed(), markDirty(), and operator=().
1.7.5.1