Package javaforce.voip
Class SIP
java.lang.Object
javaforce.voip.SIP
- All Implemented Interfaces:
TransportInterface
Base class for SIP communications (Session Initiation Protocol).
Opens the UDP port and passes any received packets thru the SIPInterface.
Direct Known subclasses : SIPClient, SIPServer.
RFC 3261 (2543) - SIP
See also:
http://www.iana.org/assignments/sip-parameters/sip-parameters.xhtml#sip-parameters-2
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Codec[]Adds a codec to a list of codecs.String[]buildsdp(CallDetails cd, CallDetails.SideDetails cdsd) Builds SDP packet.static String[]convertParameters(String ln, char delimit) Converts xml style parameters to HTTP style parameters while removing quotes around value.static Codec[]Removes a codec from a list of codecs.static StringReturns a random generated tag for the To: or From: parts of a SIP message.protected StringgetAuthResponse(CallDetails cd, String user, String pass, String remote, String cmd, String header) Generates a complete header response to a SIP authorization challenge.Returns a random SIP branch id.protected StringReturns branch in first Via lineReturns a random callid for a SIP message (a unique id for each call, not to be confused with caller id).static CodecReturns a codec from a list of codecs.static StringgetCodecName(int id) Returns string name of codec based on payload id (except dynamic ids 96-127).protected intReturns the cseq of a SIP message.protected Stringgetcseqcmd(String[] msg) Returns the command at the end of the cseq header in a SIP message.intgetexpires(String[] msg) Returns "expires" field from SIP headers.static StringReturns a flag in a To: From: field.abstract Stringprotected Stringgetnonce()Returns a random nonce variable used in SIP authorization.protected longgetNow()Returns current time in seconds.protected intgetremote_audio_rtp_port(String[] msg) Returns the remote RTP port in a SIP/SDP packet.protected intgetremote_video_rtp_port(String[] msg) Returns the remote Video RTP port in a SIP/SDP packet.protected Stringgetremotertphost(String[] msg) Returns the remote RTP host in a SIP/SDP packet.protected StringgetRequest(String[] msg) Returns the requested operation of a SIP message.protected StringgetResponse(String user, String pass, String realm, String cmd, String uri, String nonce, String qop, String nc, String cnonce) Generates a response to a SIP authorization challenge.protected intgetResponseType(String[] msg) Returns the response number from a SIP reply message.protected StringReturns a random generated rinstance id.protected String[]getroutelist(String[] msg) Returns the Record-Route: list in a SIP message as an array.static SDPstatic StringReturns the 'tag' field from 'fields'.protected StringReturns a random generated tuple id.protected StringReturns the URI part of a SIP message.protected StringReturns URI in SIP msg.protected String[]getvialist(String[] msg) Returns the Via: list in a SIP message as an array.static booleanDetermines if codecs[] contains codec.protected booleaninit(String localhost, int localport, SIPInterface iface, boolean server, TransportType type) Opens the transport and sets the SIPInterface callback.protected booleanDetermines if a SIP message is on hold.static StringJoins a To: or From: field after it was split into parts.voidvoidonDisconnect(String host, int port) static String[]Removes the 'tag' field from 'fields'.static String[]replacetag(String[] fields, String newfield) Replaces the 'tag' field from 'newfield' into 'fields'.Resolve hostname to IP address.protected booleansend(InetAddress remote, int remoteport, String datastr) Sends a packet out on the UDP port.static String[]Sets/adds a flag in a To: From: field.voidsetremoteport(int port) static voidSet resolver to system DNS client.static voidsetResolver(int transport, String server) Set resolver to custom DNS Server.static String[]Splits a To: or From: field in a SIP message into parts.protected voiduninit()Closes the UDP port and frees resources.
-
Field Details
-
transport
-
useragent
-
-
Constructor Details
-
SIP
public SIP()
-
-
Method Details
-
init
protected boolean init(String localhost, int localport, SIPInterface iface, boolean server, TransportType type) throws Exception Opens the transport and sets the SIPInterface callback.- Throws:
Exception
-
uninit
protected void uninit()Closes the UDP port and frees resources. -
send
Sends a packet out on the UDP port. -
split
Splits a To: or From: field in a SIP message into parts. General format : "display name" <sip:user@host;flags>flags [0] = "display name" [1] = user [2] = host/server [...] flags inside brackets [x] = : [...] flags outside brackets -
join
Joins a To: or From: field after it was split into parts. See split() for general form. -
getFlag2
Returns a flag in a To: From: field. -
setFlag2
Sets/adds a flag in a To: From: field. -
getbranch
Returns a random SIP branch id. TODO : Implement RFC 3261 section 8.1.1.7 (z9hG4bK) -
getbranch
Returns branch in first Via line -
ishold
Determines if a SIP message is on hold. -
getvialist
Returns the Via: list in a SIP message as an array. -
getroutelist
Returns the Record-Route: list in a SIP message as an array. -
getrinstance
Returns a random generated rinstance id. -
gettupleid
Returns a random generated tuple id. -
geturi
Returns the URI part of a SIP message. -
generatetag
Returns a random generated tag for the To: or From: parts of a SIP message. This function is used by replacetag() so it must resemble a To: or From: field. -
replacetag
Replaces the 'tag' field from 'newfield' into 'fields'. -
removetag
Removes the 'tag' field from 'fields'. -
gettag
Returns the 'tag' field from 'fields'. -
getcallid
Returns a random callid for a SIP message (a unique id for each call, not to be confused with caller id). -
getNow
protected long getNow()Returns current time in seconds. -
getnonce
Returns a random nonce variable used in SIP authorization. -
getCodecName
Returns string name of codec based on payload id (except dynamic ids 96-127). -
getSDP
-
hasCodec
Determines if codecs[] contains codec. NOTE:This checks the name field, not the id which could by dynamic. -
addCodec
Adds a codec to a list of codecs. -
delCodec
Removes a codec from a list of codecs. -
getCodec
Returns a codec from a list of codecs. Comparison is done by name only. The returned codec 'id' may be different than provided codec. -
getRequest
Returns the requested operation of a SIP message. (INVITE, BYE, etc.) -
getURI
Returns URI in SIP msg. (INVITE "uri" SIP/2.0) -
getResponseType
Returns the response number from a SIP reply message. (100, 200, 401, etc.) -
getcseq
Returns the cseq of a SIP message. -
getcseqcmd
Returns the command at the end of the cseq header in a SIP message. -
getResponse
protected String getResponse(String user, String pass, String realm, String cmd, String uri, String nonce, String qop, String nc, String cnonce) Generates a response to a SIP authorization challenge. -
getAuthResponse
protected String getAuthResponse(CallDetails cd, String user, String pass, String remote, String cmd, String header) Generates a complete header response to a SIP authorization challenge. -
getremotertphost
Returns the remote RTP host in a SIP/SDP packet. -
getremote_audio_rtp_port
Returns the remote RTP port in a SIP/SDP packet. -
getremote_video_rtp_port
Returns the remote Video RTP port in a SIP/SDP packet. -
getexpires
Returns "expires" field from SIP headers. -
getlocalRTPhost
-
buildsdp
Builds SDP packet. (RFC 2327) -
setResolver
public static void setResolver()Set resolver to system DNS client. -
setResolver
Set resolver to custom DNS Server.- Parameters:
transport- = javaforce.DNS.TRANSPORT_...server- = DNS Server host/IP.
-
setremoteport
public void setremoteport(int port) -
resolve
Resolve hostname to IP address. Keeps a cache to improve performance. -
convertParameters
Converts xml style parameters to HTTP style parameters while removing quotes around value. example in: key1="value1" key2="value2" ... example out: [key1: value1] [key2: value2] -
onConnect
- Specified by:
onConnectin interfaceTransportInterface
-
onDisconnect
- Specified by:
onDisconnectin interfaceTransportInterface
-