Yate
SIPMessage Class Reference

A container and parser for SIP messages. More...

#include <yatesip.h>

Inheritance diagram for SIPMessage:
RefObject GenObject

Public Types

enum  Flags {
  Defaults = 0 , NotReqRport = 0x0001 , NotAddAllow = 0x0002 , NotAddAgent = 0x0004 ,
  RportAfterBranch = 0x0008 , NotSetRport = 0x0010 , NotSetReceived = 0x0020 , NoConnReuse = 0x0040 ,
  NoTagFailure = 0x0080
}
 

Public Member Functions

 SIPMessage (const SIPMessage &original)
 
 SIPMessage (const char *_method, const char *_uri, const char *_version="SIP/2.0")
 
 SIPMessage (SIPParty *ep, const char *buf, int len=-1, unsigned int *bodyLen=0)
 
 SIPMessage (const SIPMessage *message, int _code, const char *_reason=0)
 
 SIPMessage (const SIPMessage *original, const SIPMessage *answer)
 
virtual ~SIPMessage ()
 
void buildBody (const char *buf, int len=-1)
 
void complete (SIPEngine *engine, const char *user=0, const char *domain=0, const char *dlgTag=0, int flags=-1)
 
bool copyHeader (const SIPMessage *message, const char *name, const char *newName=0)
 
int copyAllHeaders (const SIPMessage *message, const char *name, const char *newName=0)
 
SIPPartygetParty () const
 
void setParty (SIPParty *ep=0)
 
bool isValid () const
 
bool isAnswer () const
 
bool isOutgoing () const
 
bool isACK () const
 
bool isReliable () const
 
int32_t getCSeq () const
 
void setCSeq (int32_t cseq)
 
int getFlags () const
 
bool dontSend () const
 
void dontSend (bool val)
 
const MimeHeaderLine * getHeader (const char *name) const
 
const MimeHeaderLine * getLastHeader (const char *name) const
 
int countHeaders (const char *name) const
 
const NamedStringgetParam (const char *name, const char *param, bool last=false) const
 
const StringgetHeaderValue (const char *name, bool last=false) const
 
const StringgetParamValue (const char *name, const char *param, bool last=false) const
 
void addHeader (const char *name, const char *value=0)
 
void addHeader (MimeHeaderLine *line)
 
void clearHeaders (const char *name)
 
void setHeader (const char *name, const char *value=0)
 
MimeAuthLine * buildAuth (const String &username, const String &password, const String &meth, const String &uri, bool proxy=false, SIPEngine *engine=0) const
 
MimeAuthLine * buildAuth (const SIPMessage &original, SIPEngine *engine=0) const
 
void setAutoAuth (const char *username=0, const char *password=0)
 
const StringgetAuthUsername () const
 
const StringgetAuthPassword () const
 
ObjListgetRoutes () const
 
void addRoutes (const ObjList *routes)
 
SIPSequencegetSequence () const
 
void setSequence (SIPSequence *seq)
 
const DataBlockgetBuffer () const
 
const StringgetHeaders () const
 
void setBody (MimeBody *newbody=0)
 
const StringtraceId () const
 
- Public Member Functions inherited from RefObject
 RefObject ()
 
virtual ~RefObject ()
 
virtual void * getObject (const String &name) const
 
virtual bool alive () const
 
bool ref ()
 
bool deref ()
 
int refcount () const
 
virtual void destruct ()
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual const StringtoString () const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Static Public Member Functions

static SIPMessagefromParsing (SIPParty *ep, const char *buf, int len=-1, unsigned int *bodyLen=0)
 
- Static Public Member Functions inherited from RefObject
static bool alive (const RefObject *obj)
 
static bool efficientIncDec ()
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

Public Attributes

String version
 
String method
 
String uri
 
int code
 
String reason
 
ObjList header
 
MimeBody * body
 
String msgTraceId
 
bool msgPrint
 

Protected Member Functions

bool parse (const char *buf, int len, unsigned int *bodyLen)
 
bool parseFirst (String &line)
 
- Protected Member Functions inherited from RefObject
virtual void zeroRefs ()
 
bool resurrect ()
 
virtual void destroyed ()
 

Protected Attributes

SIPPartym_ep
 
RefPointer< SIPSequencem_seq
 
bool m_valid
 
bool m_answer
 
bool m_outgoing
 
bool m_ack
 
int32_t m_cseq
 
int m_flags
 
String m_string
 
DataBlock m_data
 
String m_authUser
 
String m_authPass
 
bool m_dontSend
 

Detailed Description

A container and parser for SIP messages.

An object that holds the sip message parsed into this library model. This class can be used to parse a sip message from a text buffer, or it can be used to create a text buffer from a sip message.

Member Enumeration Documentation

◆ Flags

enum Flags

Various message flags

Constructor & Destructor Documentation

◆ SIPMessage() [1/5]

SIPMessage ( const SIPMessage & original)

◆ SIPMessage() [2/5]

SIPMessage ( const char * _method,
const char * _uri,
const char * _version = "SIP/2.0" )

Creates a new, empty, outgoing SIPMessage.

◆ SIPMessage() [3/5]

SIPMessage ( SIPParty * ep,
const char * buf,
int len = -1,
unsigned int * bodyLen = 0 )

Creates a new SIPMessage from parsing a text buffer.

Parameters
epParty to set in message
bufBuffer to parse
lenOptional buffer length
bodyLenPointer to body length to be set if the message was received on a stream transport. If not 0 the buffer must contain the message without its body

◆ SIPMessage() [4/5]

SIPMessage ( const SIPMessage * message,
int _code,
const char * _reason = 0 )

Creates a new SIPMessage as answer to another message.

References SIPMessage().

◆ SIPMessage() [5/5]

SIPMessage ( const SIPMessage * original,
const SIPMessage * answer )

Creates an ACK message from an original message and a response.

References SIPMessage().

◆ ~SIPMessage()

virtual ~SIPMessage ( )
virtual

Destroy the message and all

Member Function Documentation

◆ addHeader() [1/2]

void addHeader ( const char * name,
const char * value = 0 )
inline

Append a new header line constructed from name and content

Parameters
nameName of the header to add
valueContent of the new header line

References header.

Referenced by setHeader().

◆ addHeader() [2/2]

void addHeader ( MimeHeaderLine * line)
inline

Append an already constructed header line

Parameters
lineHeader line to add

References header.

◆ addRoutes()

void addRoutes ( const ObjList * routes)

Add Route: headers to an outgoing message

Parameters
routesList of MimeHeaderLine representing SIP routes

◆ buildAuth() [1/2]

MimeAuthLine * buildAuth ( const SIPMessage & original,
SIPEngine * engine = 0 ) const

Construct a new authorization line based on this answer and original message

Parameters
originalOrigianl outgoing message
engineOptional engine processing this message
Returns
A new authorization line to be used in a new transaction

References SIPMessage().

◆ buildAuth() [2/2]

MimeAuthLine * buildAuth ( const String & username,
const String & password,
const String & meth,
const String & uri,
bool proxy = false,
SIPEngine * engine = 0 ) const

Construct a new authorization line based on credentials and challenge

Parameters
usernameUser account name
passwordClear text password for the account
methMethod to include in the authorization digest
uriURI to include in the authorization digest
proxySet to true to authenticate to a proxy, false to a server
engineOptional engine processing this message
Returns
A new authorization line to be used in a new transaction

References uri.

◆ buildBody()

void buildBody ( const char * buf,
int len = -1 )

Build message's body. Reset it before. This method should be called after parsing a partial message (headers only)

Parameters
bufBuffer to parse
lenOptional buffer length

◆ clearHeaders()

void clearHeaders ( const char * name)

Clear all header lines that match a name

Parameters
nameName of the header to clear

Referenced by setHeader().

◆ complete()

void complete ( SIPEngine * engine,
const char * user = 0,
const char * domain = 0,
const char * dlgTag = 0,
int flags = -1 )

Complete missing fields with defaults taken from a SIP engine

Parameters
enginePointer to the SIP engine to use for extra parameters
userUsername to set in the From header instead of that in rURI
domainDomain to use in From instead of the local IP address
dlgTagValue of dialog tag parameter to set in To header
flagsMiscellaneous completion flags, -1 to take them from engine

◆ copyAllHeaders()

int copyAllHeaders ( const SIPMessage * message,
const char * name,
const char * newName = 0 )

Copy multiple header lines (including all parameters) from another message

Parameters
messagePointer to the message to copy the header from
nameName of the headers to copy
newNameNew name to force in headers, NULL to just copy
Returns
Number of headers found and copied

References SIPMessage().

◆ copyHeader()

bool copyHeader ( const SIPMessage * message,
const char * name,
const char * newName = 0 )

Copy an entire header line (including all parameters) from another message

Parameters
messagePointer to the message to copy the header from
nameName of the header to copy
newNameNew name to force in headers, NULL to just copy
Returns
True if the header was found and copied

References SIPMessage().

◆ countHeaders()

int countHeaders ( const char * name) const

Count the header lines matching a specific name

Parameters
nameName of the header to locate
Returns
Number of matching header lines

◆ dontSend() [1/2]

bool dontSend ( ) const
inline

Get value of flag that specifies the message is not to be sent on wire

Returns
The value of the flag

◆ dontSend() [2/2]

void dontSend ( bool val)
inline

Set flag that specifies the message is not to be sent on wire

Parameters
valValue of the flag to send

◆ fromParsing()

static SIPMessage * fromParsing ( SIPParty * ep,
const char * buf,
int len = -1,
unsigned int * bodyLen = 0 )
static

Construct a new SIP message by parsing a text buffer

Parameters
epParty to set in message
bufBuffer to parse
lenOptional buffer length
bodyLenPointer to body length to be set if the message was received on a stream transport. If not 0 the buffer must contain the message without its body
Returns
A pointer to a valid new message or NULL

References SIPMessage().

◆ getAuthPassword()

const String & getAuthPassword ( ) const
inline

Retrieve the password to be used for auto authentication

Returns
Password for auto authentication

◆ getAuthUsername()

const String & getAuthUsername ( ) const
inline

Retrieve the username to be used for auto authentication

Returns
Username for auto authentication

◆ getBuffer()

const DataBlock & getBuffer ( ) const

Creates a binary buffer from a SIPMessage.

◆ getCSeq()

int32_t getCSeq ( ) const
inline

Get the Command Sequence number from this message

Returns
Number part of CSEQ in this message

Referenced by SIPDialog::adjustCSeq().

◆ getFlags()

int getFlags ( ) const
inline

Get the last flags used by this message

Returns
Flags last used, ORed together

◆ getHeader()

const MimeHeaderLine * getHeader ( const char * name) const

Find a header line by name

Parameters
nameName of the header to locate
Returns
A pointer to the first matching header line or 0 if not found

◆ getHeaders()

const String & getHeaders ( ) const

Creates a text buffer from the headers.

◆ getHeaderValue()

const String & getHeaderValue ( const char * name,
bool last = false ) const

Get a string value (without parameters) from a header line

Parameters
nameName of the header to locate
lastFind the last header with that name instead of first
Returns
The value hold in the header or an empty String

◆ getLastHeader()

const MimeHeaderLine * getLastHeader ( const char * name) const

Find the last header line that matches a given name name

Parameters
nameName of the header to locate
Returns
A pointer to the last matching header line or 0 if not found

◆ getParam()

const NamedString * getParam ( const char * name,
const char * param,
bool last = false ) const

Find a header parameter by name

Parameters
nameName of the header to locate
paramName of the parameter to locate in the tag
lastFind the last header with that name instead of first
Returns
A pointer to the first matching header line or 0 if not found

◆ getParamValue()

const String & getParamValue ( const char * name,
const char * param,
bool last = false ) const

Get a string value from a parameter in a header line

Parameters
nameName of the header to locate
paramName of the parameter to locate in the tag
lastFind the last header with that name instead of first
Returns
The value hold in the parameter or an empty String

◆ getParty()

SIPParty * getParty ( ) const
inline

Get the endpoint this message uses

Returns
Pointer to the endpoint of this message

◆ getRoutes()

ObjList * getRoutes ( ) const

Extract routes from Record-Route: headers

Returns
A list of MimeHeaderLine representing SIP routes

◆ getSequence()

SIPSequence * getSequence ( ) const
inline

Get the Command Sequence Number generator

Returns
Pointer to the CSeq generator of this message

◆ isACK()

bool isACK ( ) const
inline

Check if this message is an ACK message

Returns
True if this message has an ACK method

◆ isAnswer()

bool isAnswer ( ) const
inline

Check if this message is an answer or a request

◆ isOutgoing()

bool isOutgoing ( ) const
inline

Check if this message is an outgoing message

Returns
True if this message should be sent to remote

◆ isReliable()

bool isReliable ( ) const
inline

Check if this message is handled by a reliable protocol

Returns
True if a reliable protocol (TCP, SCTP) is used

◆ isValid()

bool isValid ( ) const
inline

Check if this message is valid as result of the parsing

◆ setAutoAuth()

void setAutoAuth ( const char * username = 0,
const char * password = 0 )
inline

Prepare the message for automatic client transaction authentication.

Parameters
usernameUsername for auto authentication
passwordPassword for auto authentication

◆ setBody()

void setBody ( MimeBody * newbody = 0)

Set a new body for this message

◆ setCSeq()

void setCSeq ( int32_t cseq)
inline

Set the Command Sequence number for this message

Parameters
cseqSequence number for this message

◆ setHeader()

void setHeader ( const char * name,
const char * value = 0 )
inline

Set a header line constructed from name and content

References addHeader(), and clearHeaders().

◆ setParty()

void setParty ( SIPParty * ep = 0)

Set the endpoint this message uses

Parameters
epPointer to the endpoint of this message

◆ setSequence()

void setSequence ( SIPSequence * seq)
inline

Set the Command Sequence Number generator

Parameters
seqPointer to the new CSeq generator of this message

◆ traceId()

const String & traceId ( ) const
inlinevirtual

Get trace ID of the message

Returns
The trace ID

Reimplemented from GenObject.

References msgTraceId.

Member Data Documentation

◆ body

MimeBody* body

All the body related things should be here, including the entire body and the parsed body.

◆ code

int code

Status code

◆ header

ObjList header

All the headers should be in this list.

Referenced by addHeader(), and addHeader().

◆ method

String method

This holds the method name of the message.

◆ msgPrint

bool msgPrint

Message print in debug

◆ msgTraceId

String msgTraceId

Trace ID of the message

Referenced by traceId().

◆ reason

String reason

Reason Phrase

◆ uri

String uri

URI of the request

Referenced by buildAuth().

◆ version

String version

Sip Version


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