public class SipProvider extends java.lang.Object implements Configurable, SipTransportListener
Any SipProvider user can send SIP messages through method sendMessage()
and receive incoming SIP messages by setting itself as message listener through the method
addSelectiveListener() (specifing also the type of messages it wants to listen to)
and by implementing the callback method onReceivedMessage()
defined by the interface
SipProviderListener.
If a SipProvider user wants to capture ALL incoming messages regardless of any other
concurrent listening users, it may use the addPromiscuousListener()
method.
SipProvider implements also multiplexing/demultiplexing service allowing a listener
to be bound to a specific type of SIP messages through the
addSelectiveListener(identifier,listener)
method, where:
- identifier is a message identifier specifying the kind of messages the listener has to be associated to,
- listener is the listener that received messages will be passed to.
The identifier, together with the SIP provider transport protocols, port numbers and IP addresses, may be viewed as SIP Service Access Point (SAP) identifier at receiving side.
The message identifier can be of one of the three following types: transaction_id, dialog_id,
or method_id. These types of identifiers characterize respectively:
- messages within a specific transaction,
- messages within a specific dialog,
- messages related to a specific SIP method.
It is also possible to use the message identifier MethodId.ANY
to select
- all messages that are out of any transactions, dialogs, or method types
already specified.
When receiving a message, the SipProvider passes the message to any active listeners
added in promiscuous mode thorugh method addPromiscuousListener()
.
Then the message is passed to the eventual selective listeners added
thorugh method addSelectiveListener() and matching the given message.
For this purpose the SipProvider first tries to look for a matching
transaction-id, then looks for a matching dialog-id, then for a matching method-id,
and finally for a default listener (i.e. that with id "ANY").
For the matched SipProviderListener, the method onReceivedMessage()
is fired.
Note: no 482 (Loop Detected) nor 501 (Not Implemented) responses are generated for requests that does not properly match any active transactions, dialogs, nor method types.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ALL_INTERFACES
String value "auto-configuration" used for auto configuration of the host address
|
static java.lang.String |
AUTO_CONFIGURATION
String value "auto-configuration" used for auto configuration of the host address
|
protected Logger |
event_logger
Event logger
|
protected Logger |
message_logger
Message logger
|
static java.lang.String |
PROTO_DTLS
DTLS protocol type
|
static java.lang.String |
PROTO_SCTP
SCTP protocol type
|
static java.lang.String |
PROTO_TCP
TCP protocol type
|
static java.lang.String |
PROTO_TLS
TLS protocol type
|
static java.lang.String |
PROTO_UDP
UDP protocol type
|
protected java.util.Hashtable |
sip_transports
Table of supported transport layers for SIP (Hashtable of protocol (
String ), transport (SipTransport )) |
Constructor and Description |
---|
SipProvider(java.lang.String file)
Creates a new SipProvider.
|
SipProvider(java.lang.String via_addr,
int host_port)
Creates a new SipProvider.
|
SipProvider(java.lang.String via_addr,
int host_port,
SipTransport[] sip_transports)
Creates a new SipProvider.
|
SipProvider(java.lang.String via_addr,
int host_port,
java.lang.String[] transport_protocols)
Creates a new SipProvider.
|
SipProvider(java.lang.String via_addr,
int host_port,
java.lang.String[] transport_protocols,
int[] transport_ports)
Creates a new SipProvider.
|
SipProvider(java.lang.String via_addr,
int host_port,
java.lang.String[] transport_protocols,
int[] transport_ports,
java.lang.String binding_addr)
Creates a new SipProvider.
|
SipProvider(java.lang.String via_addr,
int host_port,
java.lang.String[] transport_protocols,
java.lang.String binding_addr)
Creates a new SipProvider.
|
Modifier and Type | Method and Description |
---|---|
void |
addExceptionListener(SipProviderExceptionListener listener)
Adds a SipProviderExceptionListener.
|
void |
addPromiscuousListener(SipProviderListener listener)
Adds a SipProvider listener for caputering any message in promiscuous mode.
|
void |
addSelectiveListener(SipId id,
SipProviderListener listener)
Sets a SipProvider listener for a target type of method, transaction, or dialog messages.
|
IpAddress |
getBindingIpAddress()
Gets the binding IP address.
|
NameAddress |
getContactAddress()
Gets a valid SIP or SIPS contact address.
|
NameAddress |
getContactAddress(boolean secure)
Gets a valid SIP or SIPS contact address.
|
NameAddress |
getContactAddress(java.lang.String user)
Gets a valid SIP or SIPS contact address.
|
NameAddress |
getContactAddress(java.lang.String user,
boolean secure)
Gets a valid SIP or SIPS contact address.
|
java.lang.String |
getDefaultTransport()
Gets the default transport protocol.
|
java.util.Hashtable |
getListeners()
Returns the table of active listeners as Hastable:(SipId)IDs-->(SipListener)listener.
|
Logger |
getLogger()
Gets event logger.
|
int |
getNMaxConnections()
Gets the max number of (contemporary) open connections.
|
SipURI |
getOutboundProxy()
Gets the outbound proxy.
|
int |
getPort()
Gets host port.
|
SipURI |
getTelGateway()
Gets the tel gateway.
|
int |
getTlsPort()
Gets tls port.
|
java.lang.String[] |
getTransportProtocols()
Gets array of transport protocols.
|
java.lang.String |
getViaAddress()
Gets via address.
|
void |
halt()
Stops the SipProviders.
|
boolean |
hasOutboundProxy()
Whether has outbound proxy.
|
boolean |
hasSecureTransport()
Whether it has TLS or DTLS transport protocol.
|
boolean |
hasTelGateway()
Whether has tel gateway.
|
boolean |
hasTransport(java.lang.String proto)
Whether it has the given transport protocol.
|
boolean |
isAllInterfaces()
Whether binding the sip provider to all interfaces or only on the specified host address.
|
boolean |
isForceRportSet()
Whether using 'force-rport' mode.
|
boolean |
isForceSentBySet()
Whether "force-sent-by" mode is set.
|
boolean |
isReliableTransport(java.lang.String proto)
Whether the given transport protocol is supported and reliable.
|
boolean |
isRportSet()
Whether using rport.
|
static boolean |
isSecureTransport(java.lang.String proto)
Whether the given transport protocol is secure (TLS or DTLS) or not (UDP, TCP, SCTP, etc.).
|
boolean |
isSupportedTransport(java.lang.String proto)
Whether the given transport protocol is supported.
|
void |
onIncomingTransportConnection(SipTransport transport,
SocketAddress remote_soaddr)
When a new incoming transport connection is established.
|
void |
onReceivedMessage(SipTransport transport,
SipMessage msg)
From SipTransportListener.
|
void |
onTransportConnectionTerminated(SipTransport transport,
SocketAddress remote_soaddr,
java.lang.Exception error)
When a transport connection terminates.
|
void |
onTransportTerminated(SipTransport transport,
java.lang.Exception error)
From SipTransportListener.
|
void |
parseLine(java.lang.String line)
From Configurable.
|
static java.lang.String |
pickBranch()
Picks a fresh branch value.
|
java.lang.String |
pickBranch(SipMessage msg)
Picks an unique branch value based on a SIP message.
|
java.lang.String |
pickCallId()
Picks a new call-id.
|
static java.lang.String |
pickCallId(java.lang.String hostaddr)
Picks a new call-id.
|
static int |
pickInitialCSeq()
picks an initial CSeq
|
static java.lang.String |
pickTag()
Picks a new tag.
|
static java.lang.String |
pickTag(SipMessage req)
Picks a new tag.
|
void |
removeExceptionListener(SipProviderExceptionListener listener)
Removes a SipProviderExceptionListener.
|
void |
removePromiscuousListener(SipProviderListener listener)
Removes a SipProviderListener in promiscuous mode.
|
void |
removeSelectiveListener(SipId id)
Removes a SipProviderListener.
|
void |
removeSipTransport(java.lang.String proto)
Removes a specific transport protocol.
|
ConnectionId |
sendMessage(SipMessage msg)
Sends the msg message.
|
ConnectionId |
sendMessage(SipMessage msg,
java.lang.String proto,
java.lang.String dest_addr,
int dest_port,
int ttl)
Sends the msg message, specifing the transport portocol, nexthop address and port.
|
ConnectionId |
sendRawMessage(SipMessage msg,
java.lang.String proto,
java.lang.String dest_addr,
int dest_port,
int ttl)
Sends the msg message, specifing the transport portocol, nexthop address and port.
|
void |
setDefaultTransport(java.lang.String proto)
Gets the default transport protocol.
|
void |
setForceRport(boolean flag)
Sets 'force-rport' mode.
|
void |
setForceSentBy(boolean force_sent_by)
Whether setting the Via protocol, sent-by, and port values according to the transport connection.
|
void |
setNMaxConnections(int n)
Sets the max number of (contemporary) open connections.
|
void |
setOutboundProxy(SipURI uri)
Sets the outbound proxy.
|
void |
setRport(boolean flag)
Sets rport support.
|
void |
setTelGateway(SipURI uri)
Sets the tel gateway.
|
void |
setTransport(SipTransport transport)
Sets a specific transport protocol.
|
protected java.lang.String |
toLines()
Converts the entire object into lines (to be saved into the config file)
|
java.lang.String |
toString()
Gets a String value for this object.
|
static void |
updateViaHeader(SipMessage msg,
java.lang.String proto,
java.lang.String via_addr,
int host_port)
Updates the top Via header field of a SIP message, according to the given transport information.
|
static void |
updateViaHeader(SipMessage msg,
java.lang.String proto,
java.lang.String via_addr,
int host_port,
java.lang.String maddr,
int ttl)
Updates the top Via header field of a SIP message, according to the given transport information.
|
public static final java.lang.String PROTO_UDP
public static final java.lang.String PROTO_TCP
public static final java.lang.String PROTO_TLS
public static final java.lang.String PROTO_DTLS
public static final java.lang.String PROTO_SCTP
public static final java.lang.String AUTO_CONFIGURATION
public static final java.lang.String ALL_INTERFACES
protected Logger event_logger
protected Logger message_logger
protected java.util.Hashtable sip_transports
String
), transport (SipTransport
))public SipProvider(java.lang.String via_addr, int host_port)
via_addr
- SIP local via addresshost_port
- SIP local portpublic SipProvider(java.lang.String via_addr, int host_port, java.lang.String[] transport_protocols)
via_addr
- SIP local via addresshost_port
- SIP local porttransport_protocols
- array of active transport protocolspublic SipProvider(java.lang.String via_addr, int host_port, java.lang.String[] transport_protocols, java.lang.String binding_addr)
via_addr
- SIP local via addresshost_port
- SIP local porttransport_protocols
- array of active transport protocolsbinding_addr
- local IP address to which the SIP provider has to be bound topublic SipProvider(java.lang.String via_addr, int host_port, java.lang.String[] transport_protocols, int[] transport_ports)
via_addr
- SIP local via addresstransport_protocols
- array of active transport protocolstransport_ports
- array of transport port used for the corresponding transport protocolspublic SipProvider(java.lang.String via_addr, int host_port, java.lang.String[] transport_protocols, int[] transport_ports, java.lang.String binding_addr)
via_addr
- SIP local via addresstransport_protocols
- array of active transport protocolstransport_ports
- array of transport port used for the corresponding transport protocolsbinding_addr
- local IP address to which the SIP provider has to be bound topublic SipProvider(java.lang.String via_addr, int host_port, SipTransport[] sip_transports)
via_addr
- SIP local via addresshost_port
- SIP local portsip_transports
- array of active transport services (SipTransport)public SipProvider(java.lang.String file)
file
- file where all configuration parameters are read from.public static boolean isSecureTransport(java.lang.String proto)
public void setTransport(SipTransport transport)
public void removeSipTransport(java.lang.String proto)
public void halt()
public void parseLine(java.lang.String line)
parseLine
in interface Configurable
protected java.lang.String toLines()
public boolean hasTransport(java.lang.String proto)
public boolean hasSecureTransport()
public java.lang.String getViaAddress()
public int getPort()
public int getTlsPort()
public NameAddress getContactAddress()
public NameAddress getContactAddress(java.lang.String user)
public NameAddress getContactAddress(boolean secure)
secure
- whether returning a SIPS or SIP URI (true=SIPS, false=SIP)public NameAddress getContactAddress(java.lang.String user, boolean secure)
user
- local user's namesecure
- whether returning a SIPS or SIP URI (true=SIPS, false=SIP)public boolean isAllInterfaces()
public IpAddress getBindingIpAddress()
public java.lang.String[] getTransportProtocols()
public boolean isSupportedTransport(java.lang.String proto)
public boolean isReliableTransport(java.lang.String proto)
public java.lang.String getDefaultTransport()
public void setDefaultTransport(java.lang.String proto)
public void setRport(boolean flag)
public boolean isRportSet()
public void setForceRport(boolean flag)
public boolean isForceRportSet()
public void setForceSentBy(boolean force_sent_by)
force_sent_by
- whether setting Via protocol, sent-by, and port values according to the transport connectionpublic boolean isForceSentBySet()
public boolean hasOutboundProxy()
public SipURI getOutboundProxy()
public void setOutboundProxy(SipURI uri)
public boolean hasTelGateway()
public SipURI getTelGateway()
public void setTelGateway(SipURI uri)
public int getNMaxConnections()
public void setNMaxConnections(int n)
public Logger getLogger()
public java.util.Hashtable getListeners()
public void addSelectiveListener(SipId id, SipProviderListener listener)
id
- specifies the kind of messages that the listener
as to be associated to. It may identify a method, a transaction, or a dialog, or all messages.
Use MethodId.ANY to capture all messages.listener
- is the SipProviderListener that the specified type of messages has to be passed to.public void removeSelectiveListener(SipId id)
id
- specifies the messages that the listener was associated to.public void addPromiscuousListener(SipProviderListener listener)
When a SipProviderListener captures messages in promiscuous mode
messages are passed to this listener before passing them to other specific listener.
More that one SipProviderListener can be active in promiscuous mode at the same time;
in that case the same message is passed to all promiscuous SipProviderListeners.
listener
- is the SipProviderListener.public void removePromiscuousListener(SipProviderListener listener)
listener
- is the SipProviderListener to be removed.public void addExceptionListener(SipProviderExceptionListener listener)
listener
- is the SipProviderExceptionListener.public void removeExceptionListener(SipProviderExceptionListener listener)
listener
- is the SipProviderExceptionListener to be removed.public ConnectionId sendMessage(SipMessage msg)
The destination for the request is computed as follows:
- if outbound_addr is set, outbound_addr and
outbound_port are used, otherwise
- if message has Route header with lr option parameter (i.e. RFC3261 compliant),
the first Route address is used, otherwise
- the request's Request-URI is considered.
The destination for the response is computed based on the sent-by parameter in the Via header field (RFC3261 compliant).
If a Via header field is already present, the specified transport protocol is used. Otherwise the default transport protocol is used.
In case of connection-oriented transport:
- if an already established connection is found matching the destination
end point (socket), such connection is used, otherwise;
- a new connection is established.
public static void updateViaHeader(SipMessage msg, java.lang.String proto, java.lang.String via_addr, int host_port)
msg
- the message to be updatedproto
- the transport protocolvia_addr
- the sent-by address of the viahost_port
- the host portpublic static void updateViaHeader(SipMessage msg, java.lang.String proto, java.lang.String via_addr, int host_port, java.lang.String maddr, int ttl)
msg
- the message to be updatedproto
- the transport protocolvia_addr
- the sent-by address of the viahost_port
- the host portmaddr
- the IP multicast address (if applicable) or nullttl
- the TTL for multicast (used only when parameter maddr is set)public ConnectionId sendMessage(SipMessage msg, java.lang.String proto, java.lang.String dest_addr, int dest_port, int ttl)
This is a low level method and forces the message to be routed to a specific nexthop address, port and transport, regardless whatever the Via, Route, or request-uri, address to.
In case of connection-oriented transport, the connection is selected as follows:
- if an existing connection is found matching the destination
end point (destination socket), such connection is used, otherwise
- a new connection is established.
public ConnectionId sendRawMessage(SipMessage msg, java.lang.String proto, java.lang.String dest_addr, int dest_port, int ttl)
sendMessage(SipMessage,String,String,int,int)
, but no via address is added (if not already present) in request messages.public void onReceivedMessage(SipTransport transport, SipMessage msg)
onReceivedMessage
in interface SipTransportListener
public void onTransportTerminated(SipTransport transport, java.lang.Exception error)
onTransportTerminated
in interface SipTransportListener
public void onIncomingTransportConnection(SipTransport transport, SocketAddress remote_soaddr)
onIncomingTransportConnection
in interface SipTransportListener
public void onTransportConnectionTerminated(SipTransport transport, SocketAddress remote_soaddr, java.lang.Exception error)
onTransportConnectionTerminated
in interface SipTransportListener
public static java.lang.String pickBranch()
public java.lang.String pickBranch(SipMessage msg)
public static java.lang.String pickTag()
public static java.lang.String pickTag(SipMessage req)
public java.lang.String pickCallId()
public static java.lang.String pickCallId(java.lang.String hostaddr)
public static int pickInitialCSeq()
public java.lang.String toString()
toString
in class java.lang.Object