Class SIP

java.lang.Object
javaforce.voip.SIP
Direct Known Subclasses:
SIPClient, SIPServer

public abstract class SIP extends Object
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 Details

    • transport

      protected Transport transport
    • useragent

      protected static String 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

      protected boolean send(InetAddress remote, int remoteport, String datastr)
      Sends a packet out on the UDP port.
    • split

      public static String[] split(String x)
      Splits a To: or From: field in a SIP message into parts.
    • join

      public static String join(String[] x)
      Joins a To: or From: field after it was split into parts.
    • getFlag2

      public static String getFlag2(String[] fields, String flg)
      Returns a flag in a To: From: field.
    • setFlag2

      public static String[] setFlag2(String[] fields, String flg, String value)
      Sets/adds a flag in a To: From: field.
    • getbranch

      public String getbranch()
      Returns a random SIP branch id. TODO : Implement RFC 3261 section 8.1.1.7 (z9hG4bK)
    • getbranch

      protected String getbranch(String[] msg)
      Returns branch in first Via line
    • ishold

      protected boolean ishold(String[] msg)
      Determines if a SIP message is on hold.
    • getvialist

      protected String[] getvialist(String[] msg)
      Returns the Via: list in a SIP message as an array.
    • getroutelist

      protected String[] getroutelist(String[] msg)
      Returns the Record-Route: list in a SIP message as an array.
    • getrinstance

      protected String getrinstance()
      Returns a random generated rinstance id.
    • gettupleid

      protected String gettupleid()
      Returns a random generated tuple id.
    • geturi

      protected String geturi(String[] msg)
      Returns the URI part of a SIP message.
    • generatetag

      public static String 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

      public static String[] replacetag(String[] fields, String newfield)
      Replaces the 'tag' field from 'newfield' into 'fields'.
    • removetag

      public static String[] removetag(String[] fields)
      Removes the 'tag' field from 'fields'.
    • gettag

      public static String gettag(String[] fields)
      Returns the 'tag' field from 'fields'.
    • getcallid

      public String 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

      protected String getnonce()
      Returns a random nonce variable used in SIP authorization.
    • getSDP

      public static SDP getSDP(String[] msg)
      Parses the SDP content.
    • hasCodec

      public static boolean hasCodec(Codec[] codecs, Codec codec)
      Determines if codecs[] contains codec. NOTE:This checks the name field, not the id which could by dynamic.
    • addCodec

      public static Codec[] addCodec(Codec[] codecs, Codec codec)
      Adds a codec to a list of codecs.
    • delCodec

      public static Codec[] delCodec(Codec[] codecs, Codec codec)
      Removes a codec from a list of codecs.
    • getCodec

      public static Codec getCodec(Codec[] codecs, Codec codec)
      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

      protected String getRequest(String[] msg)
      Returns the requested operation of a SIP message. (INVITE, BYE, etc.)
    • getURI

      protected String getURI(String[] msg)
      Returns URI in SIP msg. (INVITE "uri" SIP/2.0)
    • getResponseType

      protected int getResponseType(String[] msg)
      Returns the response number from a SIP reply message. (100, 200, 401, etc.)
    • getHeader

      public static String getHeader(String header, String[] msg)
      Returns a specific header (field) from a SIP message.
    • getHeaders

      public static String[] getHeaders(String header, String[] msg)
      Returns a set of specific headers (fields) from a SIP message.
    • getcseq

      protected int getcseq(String[] msg)
      Returns the cseq of a SIP message.
    • getcseqcmd

      protected String getcseqcmd(String[] msg)
      Returns the command at the end of the cseq header in a SIP message.
    • getContent

      protected String getContent(String[] msg)
      Get Content from 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

      protected String getremotertphost(String[] msg)
      Returns the remote RTP host in a SIP/SDP packet.
    • getremotertpport

      protected int getremotertpport(String[] msg)
      Returns the remote RTP port in a SIP/SDP packet.
    • getremoteVrtpport

      protected int getremoteVrtpport(String[] msg)
      Returns the remote Video RTP port in a SIP/SDP packet.
    • geto

      protected long geto(String[] msg, int idx)
      Returns the 'o' counts in a SIP/SDP packet. idx can be 1 or 2.
    • getexpires

      public int getexpires(String[] msg)
      Returns "expires" field from SIP headers.
    • getlocalRTPhost

      public abstract String getlocalRTPhost(CallDetails cd)
    • buildsdp

      public void buildsdp(CallDetails cd, CallDetails.SideDetails cdsd)
      Builds SDP packet. (RFC 2327)
    • setResolver

      public static void setResolver()
      Set resolver to system DNS client.
    • setResolver

      public static void setResolver(int transport, String server)
      Set resolver to custom DNS Server.
      Parameters:
      transport - = javaforce.DNS.TRANSPORT_...
      server - = DNS Server host/IP.
    • setremoteport

      public void setremoteport(int port)
    • resolve

      public String resolve(String host)
      Resolve hostname to IP address. Keeps a cache to improve performance.