reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
resip::ParserCategory Class Referenceabstract

Base class for all SIP grammar elements that can have parameters. More...

#include <ParserCategory.hxx>

Inheritance diagram for resip::ParserCategory:
[legend]

Classes

class  Exception
 Exception class used by ParserCategory. More...
 

Public Types

enum  { UnknownParserCategory = -1 }
 
enum  CommaHandlingMode { NoCommaTokenizing = 0 , CommasAllowedOutputMulti = 1 , CommasAllowedOutputCommas = 3 }
 
typedef std::set< ParameterTypes::Type > ParameterTypeSet
 

Public Member Functions

 ParserCategory (const HeaderFieldValue &headerFieldValue, Headers::Type type, PoolBase *pool=0)
 
 ParserCategory (const char *buf, int length, Headers::Type type, PoolBase *pool=0)
 
 ParserCategory (const ParserCategory &rhs, PoolBase *pool=0)
 
ParserCategory & operator= (const ParserCategory &rhs)
 
virtual ~ParserCategory ()
 
virtual ParserCategory * clone () const =0
 
virtual Parameter * createParam (ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)
 
virtual ParserCategory * clone (void *location) const =0
 
virtual ParserCategory * clone (PoolBase *pool) const =0
 
bool exists (const ParamBase &paramType) const
 Checks for the existence of a natively supported parameter.
 
void remove (const ParamBase &paramType)
 Removes a natively supported parameter, if the parameter is present.
 
const Data & param (const ExtensionParameter &param) const
 Const accessor for non-natively-supported parameter types.
 
Data & param (const ExtensionParameter &param)
 Accessor for non-natively-supported parameter types.
 
void remove (const ExtensionParameter &param)
 Removes a non-natively-supported parameter, if the parameter is present.
 
bool exists (const ExtensionParameter &param) const
 Checks for the existence of a non-natively-supported parameter.
 
void removeParametersExcept (const ParameterTypeSet &set=EmptyParameterTypeSet)
 Removes all known parameters except those that are specified in set.
 
void clearUnknownParameters ()
 
void parseParameters (ParseBuffer &pb)
 
EncodeStream & encodeParameters (EncodeStream &str) const
 Encodes parameters as they should appear on the wire.
 
Data commutativeParameterHash () const
 
Parameter * getParameterByEnum (ParameterTypes::Type type) const
 
void removeParameterByEnum (ParameterTypes::Type type)
 
void setParameter (const Parameter *parameter)
 
int numKnownParams () const
 Returns the number of known (natively supported) parameters.
 
int numUnknownParams () const
 Returns the number of unknown parameters.
 
- Public Member Functions inherited from resip::LazyParser
 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().
 

Static Public Attributes

static const ParameterTypeSet EmptyParameterTypeSet
 

Protected Types

typedef std::vector< Parameter *, StlPoolAllocator< Parameter *, PoolBase > > ParameterList
 

Protected Member Functions

 ParserCategory (PoolBase *pool=0)
 
bool addParameter (Parameter *param)
 
bool addParameter (UnknownParameter *unknownParam)
 
Parameter * getParameterByData (const Data &data) const
 
void removeParameterByData (const Data &data)
 
PoolBase * getPool ()
 
void freeParameter (Parameter *p)
 
virtual const Data & errorContext () const
 
- Protected Member Functions inherited from resip::LazyParser
 LazyParser ()
 
void clear ()
 

Protected Attributes

ParameterList mParameters
 
ParameterList mUnknownParameters
 
PoolBase * mPool
 
Headers::Type mHeaderType
 

Friends

class NameAddr
 
EncodeStream & operator<< (EncodeStream &, const ParserCategory &)
 

Detailed Description

Base class for all SIP grammar elements that can have parameters.

The pattern for accessing the parameters in a ParserCategory is very similar to accessing headers in a SipMessage. Each parameter type has an access token class (a subclass of ParamBase), and a corresponding ParserCategory::param() function that takes an instance of that subclass as an argument, and returns the correct type for that parameter. Common examples of access-token include p_tag, p_q, p_lr, p_expires, p_branch, etc.

NameAddr& contact = sip.header(h_Contacts).front();
if(contact.exists(p_q))
{
QValueParameter& q = contact.param(p_q);
// do stuff with q
}
NameAddr& to = sip.header(h_To);
if(to.exists(p_tag))
{
DataParameter& toTag = to.param(p_tag);
// do stuff with toTag
}
Via& topVia = sip.header(h_Vias).front();
if(topVia.exists(p_branch))
{
BranchParameter& branch = topVia.param(p_branch);
// do stuff with branch
}
Generically represents miscellaneous parameter data.
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
bool exists(const Param< NameAddr > &paramType) const
Definition NameAddr.cxx:477
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
Represents the "q" parameter value of the RFC 3261 grammar.

Note the calls to ParserCategory::exists() in the code above; calling ParserCategory::param() when the relevant parameter doesn't exist will either cause the parameter to be created, or an exception to be thrown (if you're working with a const reference).

In some cases, you will need to access parameter-types that are not natively supported by the stack (ie, don't have an access-token). ExtensionParameter will allow you to construct an access-token at runtime that will retrieve the parameter as a raw Data. Here's an example:

// We need to access the foo parameter on the Request-Uri
RequestLine& rLine = sip.header(h_RequestLine);
static ExtensionParameter p_foo("foo");
if(rLine.uri().exists(p_foo))
{
Data& foo = rLine.uri().param(p_foo);
}
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
Represents the "Request-Line" element in the RFC 3261 grammar.
const Uri & uri() const
bool exists(const Param< Uri > &paramType) const
Definition Uri.cxx:1701
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
static void foo()
RequestLineType h_RequestLine
Definition Headers.cxx:347
Todo:
Maybe a better name? IHaveParams? ElemWithParams?

Definition at line 84 of file ParserCategory.hxx.

Member Typedef Documentation

◆ ParameterList

Definition at line 308 of file ParserCategory.hxx.

◆ ParameterTypeSet

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
UnknownParserCategory 

Definition at line 87 of file ParserCategory.hxx.

◆ CommaHandlingMode

Enumerator
NoCommaTokenizing 
CommasAllowedOutputMulti 
CommasAllowedOutputCommas 

Definition at line 95 of file ParserCategory.hxx.

Constructor & Destructor Documentation

◆ ParserCategory() [1/4]

ParserCategory::ParserCategory ( const HeaderFieldValue &  headerFieldValue,
Headers::Type  type,
PoolBase *  pool = 0 
)

Definition at line 30 of file ParserCategory.cxx.

◆ ParserCategory() [2/4]

ParserCategory::ParserCategory ( const char *  buf,
int  length,
Headers::Type  type,
PoolBase *  pool = 0 
)

Definition at line 41 of file ParserCategory.cxx.

◆ ParserCategory() [3/4]

ParserCategory::ParserCategory ( const ParserCategory &  rhs,
PoolBase *  pool = 0 
)

Definition at line 61 of file ParserCategory.cxx.

◆ ~ParserCategory()

ParserCategory::~ParserCategory ( )
virtual

Definition at line 128 of file ParserCategory.cxx.

◆ ParserCategory() [4/4]

ParserCategory::ParserCategory ( PoolBase *  pool = 0)
protected

Definition at line 52 of file ParserCategory.cxx.

Member Function Documentation

◆ addParameter() [1/2]

bool ParserCategory::addParameter ( Parameter *  param)
protected

Definition at line 263 of file ParserCategory.cxx.

◆ addParameter() [2/2]

bool ParserCategory::addParameter ( UnknownParameter *  unknownParam)
protected

Definition at line 283 of file ParserCategory.cxx.

◆ clearUnknownParameters()

void ParserCategory::clearUnknownParameters ( )

Definition at line 201 of file ParserCategory.cxx.

◆ clone() [1/3]

◆ clone() [2/3]

◆ clone() [3/3]

◆ commutativeParameterHash()

Data ParserCategory::commutativeParameterHash ( ) const

Definition at line 473 of file ParserCategory.cxx.

◆ createParam()

Parameter * ParserCategory::createParam ( ParameterTypes::Type  type,
ParseBuffer &  pb,
const std::bitset< 256 > &  terminators,
PoolBase *  pool 
)
virtual

◆ encodeParameters()

EncodeStream & ParserCategory::encodeParameters ( EncodeStream &  str) const

Encodes parameters as they should appear on the wire.

Parameters
strThe ostream to encode to.
Returns
str

Definition at line 312 of file ParserCategory.cxx.

◆ errorContext()

const Data & ParserCategory::errorContext ( ) const
protectedvirtual

Implements resip::LazyParser.

Definition at line 504 of file ParserCategory.cxx.

◆ exists() [1/2]

bool ParserCategory::exists ( const ExtensionParameter &  param) const

Checks for the existence of a non-natively-supported parameter.

Parameters
paramThe runtime constructed accessor token.
Returns
true iff the parameter is present.

Definition at line 175 of file ParserCategory.cxx.

◆ exists() [2/2]

bool resip::ParserCategory::exists ( const ParamBase &  paramType) const
inline

Checks for the existence of a natively supported parameter.

Parameters
paramTypeThe accessor token for the parameter.
Returns
true iff the parameter is present.

Definition at line 145 of file ParserCategory.hxx.

◆ freeParameter()

void resip::ParserCategory::freeParameter ( Parameter *  p)
inlineprotected

Definition at line 292 of file ParserCategory.hxx.

◆ getParameterByData()

Parameter * ParserCategory::getParameterByData ( const Data &  data) const
protected

Definition at line 440 of file ParserCategory.cxx.

◆ getParameterByEnum()

Parameter * ParserCategory::getParameterByEnum ( ParameterTypes::Type  type) const

Definition at line 385 of file ParserCategory.cxx.

◆ getPool()

PoolBase * resip::ParserCategory::getPool ( )
inlineprotected

Definition at line 287 of file ParserCategory.hxx.

◆ numKnownParams()

int resip::ParserCategory::numKnownParams ( ) const
inline

Returns the number of known (natively supported) parameters.

Definition at line 259 of file ParserCategory.hxx.

◆ numUnknownParams()

int resip::ParserCategory::numUnknownParams ( ) const
inline

Returns the number of unknown parameters.

Definition at line 264 of file ParserCategory.hxx.

◆ operator=()

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

Definition at line 76 of file ParserCategory.cxx.

◆ param() [1/2]

Data & ParserCategory::param ( const ExtensionParameter &  param)

Accessor for non-natively-supported parameter types.

Will create the parameter if it does not exist.

Parameters
paramThe runtime constructed parameter accessor.
Returns
The parameter, as a raw Data.

Definition at line 147 of file ParserCategory.cxx.

◆ param() [2/2]

const Data & ParserCategory::param ( const ExtensionParameter &  param) const

Const accessor for non-natively-supported parameter types.

Exceptions
ParserCategory::Exceptionif this parameter doesn't exist.
Parameters
paramThe runtime constructed parameter accessor.
Returns
The parameter, as a raw Data.

Definition at line 134 of file ParserCategory.cxx.

◆ parseParameters()

void ParserCategory::parseParameters ( ParseBuffer &  pb)

dlb! @ here?

Definition at line 212 of file ParserCategory.cxx.

◆ remove() [1/2]

void ParserCategory::remove ( const ExtensionParameter &  param)

Removes a non-natively-supported parameter, if the parameter is present.

Parameters
paramThe accessor token for the parameter.

Definition at line 168 of file ParserCategory.cxx.

◆ remove() [2/2]

void ParserCategory::remove ( const ParamBase &  paramType)

Removes a natively supported parameter, if the parameter is present.

Parameters
paramTypeThe accessor token for the parameter.

Definition at line 161 of file ParserCategory.cxx.

◆ removeParameterByData()

void ParserCategory::removeParameterByData ( const Data &  data)
protected

Definition at line 454 of file ParserCategory.cxx.

◆ removeParameterByEnum()

void ParserCategory::removeParameterByEnum ( ParameterTypes::Type  type)

Definition at line 421 of file ParserCategory.cxx.

◆ removeParametersExcept()

void ParserCategory::removeParametersExcept ( const ParameterTypeSet &  set = EmptyParameterTypeSet)

Removes all known parameters except those that are specified in set.

Parameters
setThe set of parameters to retain, as an enum.
Note
This does not remove unknown parameters.

Definition at line 182 of file ParserCategory.cxx.

◆ setParameter()

void ParserCategory::setParameter ( const Parameter *  parameter)

Definition at line 399 of file ParserCategory.cxx.

Friends And Related Symbol Documentation

◆ NameAddr

friend class NameAddr
friend

Definition at line 317 of file ParserCategory.hxx.

◆ operator<<

EncodeStream & operator<< ( EncodeStream &  ,
const ParserCategory &   
)
friend

Member Data Documentation

◆ EmptyParameterTypeSet

const ParserCategory::ParameterTypeSet ParserCategory::EmptyParameterTypeSet
static

Definition at line 191 of file ParserCategory.hxx.

◆ mHeaderType

Headers::Type resip::ParserCategory::mHeaderType
protected

Definition at line 312 of file ParserCategory.hxx.

◆ mParameters

ParameterList resip::ParserCategory::mParameters
protected

Definition at line 309 of file ParserCategory.hxx.

◆ mPool

PoolBase* resip::ParserCategory::mPool
protected

Definition at line 311 of file ParserCategory.hxx.

◆ mUnknownParameters

ParameterList resip::ParserCategory::mUnknownParameters
protected

Definition at line 310 of file ParserCategory.hxx.


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