PcapPlusPlus  23.09
pcpp::TextBasedProtocolMessage Class Referenceabstract

#include <TextBasedProtocol.h>

Inheritance diagram for pcpp::TextBasedProtocolMessage:
pcpp::Layer pcpp::IDataContainer pcpp::HttpMessage pcpp::SdpLayer pcpp::SipLayer pcpp::HttpRequestLayer pcpp::HttpResponseLayer pcpp::SipRequestLayer pcpp::SipResponseLayer

Public Member Functions

HeaderFieldgetFieldByName (std::string fieldName, int index=0) const
 
HeaderFieldgetFirstField () const
 
HeaderFieldgetNextField (HeaderField *prevField) const
 
int getFieldCount () const
 
virtual HeaderFieldaddField (const std::string &fieldName, const std::string &fieldValue)
 
virtual HeaderFieldaddField (const HeaderField &newField)
 
HeaderFieldaddEndOfHeader ()
 
virtual HeaderFieldinsertField (HeaderField *prevField, const std::string &fieldName, const std::string &fieldValue)
 
virtual HeaderFieldinsertField (std::string prevFieldName, const std::string &fieldName, const std::string &fieldValue)
 
virtual HeaderFieldinsertField (HeaderField *prevField, const HeaderField &newField)
 
bool removeField (HeaderField *fieldToRemove)
 
bool removeField (std::string fieldName, int index=0)
 
bool isHeaderComplete () const
 
virtual void parseNextLayer ()
 
size_t getHeaderLen () const
 
virtual void computeCalculateFields ()
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
uint8_t * getData () const
 
size_t getDataLen () const
 
uint8_t * getLayerPayload () const
 
size_t getLayerPayloadSize () const
 
bool isAllocatedToPacket () const
 
void copyData (uint8_t *toArr) const
 
uint8_t * getDataPtr (size_t offset=0) const
 
virtual std::string toString () const =0
 
virtual OsiModelLayer getOsiModelLayer () const =0
 

Detailed Description

An abstract base class that wraps text-based-protocol header layers (both requests and responses). It is the base class for all those layers. This class is not meant to be instantiated, hence the protected c'tor

Member Function Documentation

◆ addEndOfHeader()

HeaderField* pcpp::TextBasedProtocolMessage::addEndOfHeader ( )

Add the special end-of-header field (see the explanation in HeaderField)

Returns
A pointer to the newly created header field, or NULL if the field could not be created

◆ addField() [1/2]

virtual HeaderField* pcpp::TextBasedProtocolMessage::addField ( const std::string &  fieldName,
const std::string &  fieldValue 
)
virtual

Add a new header field to this message. This field will be added last (before the end-of-header field)

Parameters
[in]fieldNameThe field name
[in]fieldValueThe field value
Returns
A pointer to the newly created header field, or NULL if the field could not be created

Reimplemented in pcpp::HttpMessage.

◆ addField() [2/2]

virtual HeaderField* pcpp::TextBasedProtocolMessage::addField ( const HeaderField newField)
virtual

Add a new header field to this message. This field will be added last (before the end-of-header field)

Parameters
[in]newFieldThe header field to add
Returns
A pointer to the newly created header field, or NULL if the field could not be created

Reimplemented in pcpp::HttpMessage.

◆ computeCalculateFields()

virtual void pcpp::TextBasedProtocolMessage::computeCalculateFields ( )
virtual

Does nothing for this class

Implements pcpp::Layer.

Reimplemented in pcpp::SipLayer.

◆ getFieldByName()

HeaderField* pcpp::TextBasedProtocolMessage::getFieldByName ( std::string  fieldName,
int  index = 0 
) const

Get a pointer to a header field by name. The search is case insensitive, meaning if a field with name "Host" exists and the fieldName parameter is "host" (all letter are lower case), this method will return a pointer to "Host" field

Parameters
[in]fieldNameThe field name
[in]indexOptional parameter. If the field name appears more than once, this parameter will indicate which field to get. The default value is 0 (get the first appearance of the field name as appears on the packet)
Returns
A pointer to an HeaderField instance, or NULL if field doesn't exist

◆ getFieldCount()

int pcpp::TextBasedProtocolMessage::getFieldCount ( ) const
Returns
The number of header fields currently in the layer (not including CRLF at the end of the header)

◆ getFirstField()

HeaderField* pcpp::TextBasedProtocolMessage::getFirstField ( ) const
inline
Returns
A pointer to the first header field exists in this message, or NULL if no such field exists

◆ getHeaderLen()

size_t pcpp::TextBasedProtocolMessage::getHeaderLen ( ) const
virtual
Returns
The message length

Implements pcpp::Layer.

◆ getNextField()

HeaderField* pcpp::TextBasedProtocolMessage::getNextField ( HeaderField prevField) const
inline

Get the field which appears after a certain field

Parameters
[in]prevFieldA pointer to the field
Returns
The field after prevField or NULL if prevField is the last field. If prevField is NULL, this method will return NULL

◆ insertField() [1/3]

virtual HeaderField* pcpp::TextBasedProtocolMessage::insertField ( HeaderField prevField,
const std::string &  fieldName,
const std::string &  fieldValue 
)
virtual

Insert a new field after an existing field

Parameters
[in]prevFieldA pointer to the existing field. If it's NULL the new field will be added as first field
[in]fieldNameThe field name
[in]fieldValueThe field value
Returns
A pointer to the newly created header field, or NULL if the field could not be created

Reimplemented in pcpp::HttpMessage.

◆ insertField() [2/3]

virtual HeaderField* pcpp::TextBasedProtocolMessage::insertField ( std::string  prevFieldName,
const std::string &  fieldName,
const std::string &  fieldValue 
)
virtual

Insert a new field after an existing field

Parameters
[in]prevFieldNameA name of an existing field. If the field doesn't exist NULL will be returned. If field name is empty ('') the new field will be added as first field
[in]fieldNameThe field name
[in]fieldValueThe field value
Returns
A pointer to the newly created header field, or NULL if the field could not be created

◆ insertField() [3/3]

virtual HeaderField* pcpp::TextBasedProtocolMessage::insertField ( HeaderField prevField,
const HeaderField newField 
)
virtual

Insert a new field after an existing field

Parameters
[in]prevFieldA pointer to the existing field
[in]newFieldThe header field to add
Returns
A pointer to the newly created header field, or NULL if the field could not be created

Reimplemented in pcpp::HttpMessage.

◆ isHeaderComplete()

bool pcpp::TextBasedProtocolMessage::isHeaderComplete ( ) const

Indicate whether the header is complete (ending with end-of-header "\r\n\r\n" or "\n\n") or spread over more packets

Returns
True if the header is complete or false if not

◆ parseNextLayer()

virtual void pcpp::TextBasedProtocolMessage::parseNextLayer ( )
virtual

Currently set only PayloadLayer for the rest of the data

Implements pcpp::Layer.

Reimplemented in pcpp::SipLayer.

◆ removeField() [1/2]

bool pcpp::TextBasedProtocolMessage::removeField ( HeaderField fieldToRemove)

Remove a field from the message

Parameters
[in]fieldToRemoveA pointer to the field that should be removed
Returns
True if the field was removed successfully, or false otherwise (for example: if fieldToRemove is NULL, if it doesn't exist in the message, or if the removal failed)

◆ removeField() [2/2]

bool pcpp::TextBasedProtocolMessage::removeField ( std::string  fieldName,
int  index = 0 
)

Remove a field from the message

Parameters
[in]fieldNameThe name of the field that should be removed
[in]indexOptional parameter. If the field name appears more than once, this parameter will indicate which field to remove. The default value is 0 (remove the first appearance of the field name as appears on the packet)
Returns
True if the field was removed successfully, or false otherwise (for example: if fieldName doesn't exist in the message, or if the removal failed)