PcapPlusPlus
pcpp::TextBasedProtocolMessage Class Referenceabstract

#include <TextBasedProtocol.h>

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

Public Member Functions

HeaderFieldgetFieldByName (std::string fieldName, int index=0)
 
HeaderFieldgetFirstField ()
 
HeaderFieldgetNextField (HeaderField *prevField)
 
int getFieldCount ()
 
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 ()
 
virtual void parseNextLayer ()
 
size_t getHeaderLen ()
 
virtual void computeCalculateFields ()
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer ()
 
LayergetPrevLayer ()
 
ProtocolType getProtocol ()
 
uint8_t * getData ()
 
size_t getDataLen ()
 
uint8_t * getLayerPayload ()
 
size_t getLayerPayloadSize ()
 
bool isAllocatedToPacket ()
 
void copyData (uint8_t *toArr)
 
virtual std::string toString ()=0
 
virtual OsiModelLayer getOsiModelLayer ()=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

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
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.

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.

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

Does nothing for this class

Implements pcpp::Layer.

Reimplemented in pcpp::SipLayer.

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

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
int pcpp::TextBasedProtocolMessage::getFieldCount ( )
Returns
The number of header fields currently in the layer (not including CRLF at the end of the header)
HeaderField* pcpp::TextBasedProtocolMessage::getFirstField ( )
inline
Returns
A pointer to the first header field exists in this message, or NULL if no such field exists
size_t pcpp::TextBasedProtocolMessage::getHeaderLen ( )
virtual
Returns
The message length

Implements pcpp::Layer.

HeaderField* pcpp::TextBasedProtocolMessage::getNextField ( HeaderField prevField)
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
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.

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
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.

bool pcpp::TextBasedProtocolMessage::isHeaderComplete ( )

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
virtual void pcpp::TextBasedProtocolMessage::parseNextLayer ( )
virtual

Currently set only PayloadLayer for the rest of the data

Implements pcpp::Layer.

Reimplemented in pcpp::SipLayer.

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)
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)