public abstract class SipPacketImpl extends AbstractPacket implements SipPacket
| Constructor and Description |
|---|
SipPacketImpl(TransportPacket parent,
SipMessage msg) |
| Modifier and Type | Method and Description |
|---|---|
abstract SipPacket |
clone() |
long |
getArrivalTime()
The arrival time of this packet in microseconds relative to epoch
(midnight UTC of January 1, 1970).
|
CallIdHeader |
getCallIDHeader()
Convenience method for fetching the call-id-header
|
ContactHeader |
getContactHeader()
Get the
ContactHeader |
Object |
getContent()
|
ContentTypeHeader |
getContentTypeHeader()
Get the
ContentTypeHeader for this message. |
CSeqHeader |
getCSeqHeader()
Convenience method for fetching the CSeq header
|
FromHeader |
getFromHeader()
Convenience method for fetching the from-header
|
Optional<SipHeader> |
getHeader(Buffer headerName)
Get the header as a buffer
|
Optional<SipHeader> |
getHeader(String headerName)
Same as
#getHeader(Buffers.wrap(keyParameter). |
List<SipHeader> |
getHeaders()
Get all headers as a list of
SipHeader |
Map<String,List<SipHeader>> |
getHeaderValues()
Get all headers as keyed by header name
|
Buffer |
getInitialLine()
The first line of a sip message, which is either a request or a response
line
|
MaxForwardsHeader |
getMaxForwards() |
Buffer |
getMethod()
Get the method of this sip message
|
Packet |
getNextPacket()
Get the next frame, or null if there is none.
|
Buffer |
getPayload()
Get the payload of the frame.
|
Buffer |
getRawContent()
Get the content as a
Buffer. |
RecordRouteHeader |
getRecordRouteHeader()
Get the top-most
RecordRouteHeader header if present. |
List<RecordRouteHeader> |
getRecordRouteHeaders()
Get all the RecordRoute-headers in this
SipMessage. |
RouteHeader |
getRouteHeader()
Get the top-most
RouteHeader header if present. |
List<RouteHeader> |
getRouteHeaders()
Get all the Route-headers in this
SipMessage. |
protected SipMessage |
getSipMessage() |
ToHeader |
getToHeader()
Convenience method for fetching the to-header
|
protected TransportPacket |
getTransportPacket() |
ViaHeader |
getViaHeader()
Get the top-most
ViaHeader if present. |
List<ViaHeader> |
getViaHeaders()
Get all the Via-headers in this
SipMessage. |
boolean |
hasContent()
Checks whether this
SipPacket is carrying anything in its message
body. |
boolean |
isAck()
Convenience method for determining whether the method of this message is
an ACK or not.
|
boolean |
isBye()
Convenience method for determining whether the method of this message is
a BYE or not.
|
boolean |
isCancel()
Convenience method for determining whether the method of this message is
a CANCEL or not
|
boolean |
isInfo()
Convenience method for determining whether the method of this message is
a INFO or not.
|
boolean |
isInitial()
Checks whether or not this request is considered to be an "initial"
request, i.e., a request that does not go within a dialog.
|
boolean |
isInvite()
Convenience method for determining whether the method of this message is
an INVITE or not.
|
boolean |
isMessage()
Convenience method for determining whether the method of this message is
a MESSAGE or not.
|
boolean |
isOptions()
Convenience method for determining whether the method of this message is
a OPTIONS or not.
|
boolean |
isRequest()
Check whether this sip message is a request or not
|
boolean |
isResponse()
Check whether this sip message is a response or not
|
Buffer |
toBuffer()
|
SipRequestPacket |
toRequest()
Got tired of casting the
SipPacket into a
SipRequestPacket so you can use this method instead. |
SipResponsePacket |
toResponse()
Got tired of casting the
SipPacket into a
SipResponsePacket so you can use this method instead. |
String |
toString() |
void |
verify()
Calling this method will force the packet to completely parse its data
and check so that all the information conforms to whatever rules this
packet needs to follow.
|
void |
write(OutputStream out,
Buffer payload)
Writes this packet to the
OutputStream with the supplied payload. |
checkParent, getName, getPacket, getParentPacket, getProtocol, hasProtocol, writeequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetName, getPacket, getParentPacket, getProtocol, hasProtocol, writepublic SipPacketImpl(TransportPacket parent, SipMessage msg)
protected TransportPacket getTransportPacket()
protected SipMessage getSipMessage()
public long getArrivalTime()
PacketSimpleDateFormat but it can
only handle milliseconds precision (you will have to write your own date
formatter if you want microseconds).
Here is a snippet illustrating how to turn the arrival time of the packet
into a human readable date
Packet p = ...;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS");
Date date = new Date(p.getArrivalTime() / 1000);
System.out.println("Arrival time: " + formatter.format(date));
Note how an integer devision is performed on the arrival time to
"cut off" the microseconds from the time stampgetArrivalTime in interface Packetpublic void write(OutputStream out, Buffer payload) throws IOException
PacketOutputStream with the supplied payload.
You can use this method to e.g. write a raw UDPPacket to the
stream with this payload. Note, if the UDPPacket already had a
payload it will be ignored so use this method with care.write in interface PacketIOExceptionpublic Buffer getInitialLine()
SipPacketgetInitialLine in interface SipPacketpublic SipRequestPacket toRequest() throws ClassCastException
SipPacketSipPacket into a
SipRequestPacket so you can use this method instead. Just a short
cut for:
(SipRequest)sipMessage;
toRequest in interface SipPacketSipRequestPacketClassCastException - in case this SipPacket is actually a
SipResponsePacket.public SipResponsePacket toResponse() throws ClassCastException
SipPacketSipPacket into a
SipResponsePacket so you can use this method instead. Just a
short cut for:
(SipResponse)sipMessage;
toResponse in interface SipPacketSipResponsePacketClassCastException - in case this SipPacket is actually a
SipResponsePacket.public boolean isResponse()
SipPacketisResponse in interface SipPacketpublic boolean isRequest()
SipPacketpublic Object getContent() throws SipPacketParseException
SipPacketSipPacket as an
Object. If the ContentTypeHeader indicates a content type
that is known (such as an sdp) then an attempt to parse the content into
that type is made. If the payload is unknown then a Buffer
representing the payload will be returned.getContent in interface SipPacketSipPacketParseException - in case anything goes wrong when trying to frame the content
in any way.public Buffer getRawContent()
SipPacketBuffer.getRawContent in interface SipPacketpublic boolean hasContent()
SipPacketSipPacket is carrying anything in its message
body.hasContent in interface SipPacketSipPacket has a message body, false
otherwise.public Buffer getMethod() throws SipPacketParseException
SipPacketgetMethod in interface SipPacketSipPacketParseExceptionpublic List<SipHeader> getHeaders()
SipHeadergetHeaders in interface SipPacketSipHeaderpublic Map<String,List<SipHeader>> getHeaderValues()
getHeaderValues in interface SipPacketSipHeaderpublic Optional<SipHeader> getHeader(Buffer headerName) throws SipPacketParseException
SipPacketgetHeader in interface SipPacketheaderName - the name of the header we wish to fetchSipHeader or null if not foundSipPacketParseExceptionpublic Optional<SipHeader> getHeader(String headerName) throws SipPacketParseException
SipPacket#getHeader(Buffers.wrap(keyParameter).getHeader in interface SipPacketheaderName - the name of the header we wish to fetchSipHeaderSipPacketParseExceptionpublic FromHeader getFromHeader() throws SipPacketParseException
SipPacketgetFromHeader in interface SipPacketSipPacketParseException - TODOpublic ToHeader getToHeader() throws SipPacketParseException
SipPacketgetToHeader in interface SipPacketSipPacketParseExceptionpublic ViaHeader getViaHeader() throws SipPacketParseException
SipPacketViaHeader if present. If this is a request that
has been sent then there should always be a ViaHeader present.
However, you just created a SipPacket yourself then this method
may return null so please check for it.getViaHeader in interface SipPacketViaHeader or null if there are no
ViaHeaders on this message just yet.SipPacketParseExceptionpublic List<ViaHeader> getViaHeaders() throws SipPacketParseException
SipPacketSipMessage. If this is a request
that just was created then this may return an empty list.getViaHeaders in interface SipPacketSipPacketParseExceptionpublic MaxForwardsHeader getMaxForwards() throws SipPacketParseException
getMaxForwards in interface SipPacketSipPacketParseExceptionpublic RecordRouteHeader getRecordRouteHeader() throws SipPacketParseException
SipPacketRecordRouteHeader header if present.getRecordRouteHeader in interface SipPacketRecordRouteHeader header or null if there
are no RecordRouteHeader headers found in this
SipPacket.SipPacketParseExceptionpublic List<RecordRouteHeader> getRecordRouteHeaders() throws SipPacketParseException
SipPacketSipMessage. If there are
no RecordRouteHeaders in this SipMessage then an empty
list will be returned.getRecordRouteHeaders in interface SipPacketSipPacketParseExceptionpublic RouteHeader getRouteHeader() throws SipPacketParseException
SipPacketRouteHeader header if present.getRouteHeader in interface SipPacketRouteHeader header or null if there are no
RouteHeader headers found in this SipPacket.SipPacketParseExceptionpublic List<RouteHeader> getRouteHeaders() throws SipPacketParseException
SipPacketSipMessage. If there are no
RouteHeaders in this SipMessage then an empty list will
be returned.getRouteHeaders in interface SipPacketSipPacketParseExceptionpublic ContactHeader getContactHeader() throws SipPacketParseException
SipPacketContactHeadergetContactHeader in interface SipPacketSipPacketParseExceptionpublic ContentTypeHeader getContentTypeHeader() throws SipPacketParseException
SipPacketContentTypeHeader for this message. If there is no
Content-Type header in this SIP message then null will be returned.getContentTypeHeader in interface SipPacketContentTypeHeader or null if there is none.SipPacketParseExceptionpublic CallIdHeader getCallIDHeader() throws SipPacketParseException
SipPacketgetCallIDHeader in interface SipPacketSipPacketParseExceptionpublic CSeqHeader getCSeqHeader() throws SipPacketParseException
SipPacketgetCSeqHeader in interface SipPacketSipPacketParseExceptionpublic boolean isInvite()
throws SipPacketParseException
SipPacketisInvite in interface SipPacketSipPacketParseException - in case the method could not be parsed out of the underlying
buffer.public boolean isBye()
throws SipPacketParseException
SipPacketisBye in interface SipPacketSipPacketParseException - in case the method could not be parsed out of the underlying
buffer.public boolean isAck()
throws SipPacketParseException
SipPacketisAck in interface SipPacketSipPacketParseException - in case the method could not be parsed out of the underlying
buffer.public boolean isOptions()
throws SipPacketParseException
SipPacketisOptions in interface SipPacketSipPacketParseException - in case the method could not be parsed out of the underlying
buffer.public boolean isMessage()
throws SipPacketParseException
SipPacketisMessage in interface SipPacketSipPacketParseException - in case the method could not be parsed out of the underlying
buffer.public boolean isInfo()
throws SipPacketParseException
SipPacketisInfo in interface SipPacketSipPacketParseException - in case the method could not be parsed out of the underlying
buffer.public boolean isCancel()
throws SipPacketParseException
SipPacketisCancel in interface SipPacketSipPacketParseException - in case the method could not be parsed out of the underlying
buffer.public boolean isInitial()
throws SipPacketParseException
SipPacketisInitial in interface SipPacketSipPacketParseExceptionpublic void verify()
PacketIPPacket, hardly does anything
in this method but more complex protocols such as SIP (once again), HTTP
etc can spend quite some time verifying everything, which is why you
don't want to do it unless you really have to.
In general, yajpcap has the philosophy of
"assume that everything is ok until things blow up and then deal with it"public Buffer toBuffer()
SipPacketBuffer that is representing this SipPacket. Note,
the data behind the buffer is shared with the actual SipPacket so
any changes to the Buffer will affect this SipPacket.
Hence, by changing this buffer directly, you bypass all checks for valid
inputs and the end-result of doing so is undefined (most likely you will
either blow up at some point or you will end up sending garbage across
the network).public abstract SipPacket clone()
public Packet getNextPacket() throws IOException
PacketgetNextPacket in interface PacketIOExceptionpublic Buffer getPayload()
PacketgetPayload in interface PacketgetPayload in class AbstractPacketCopyright © 2021. All Rights Reserved.