- fix formatting
This commit is contained in:
parent
520d1a3cfc
commit
f305c555f8
62
bbb-voice/src/main/java/org/zoolu/sip/address/NameAddress.java
Normal file → Executable file
62
bbb-voice/src/main/java/org/zoolu/sip/address/NameAddress.java
Normal file → Executable file
@ -23,39 +23,35 @@
|
||||
|
||||
package org.zoolu.sip.address;
|
||||
|
||||
|
||||
import org.zoolu.sip.provider.SipParser;
|
||||
|
||||
|
||||
/** Class <i>NameAddress</i> is used to rapresent any valid SIP Name Address.
|
||||
* It contains a SIP URI and optionally a display name.
|
||||
* <BR> A SIP Name Address is a string of the form of:
|
||||
* <BR><BLOCKQUOTE><PRE>   [ display-name ] address
|
||||
* <BR>   where address can be a valid SIP URL</PRE></BLOCKQUOTE>
|
||||
*/
|
||||
public class NameAddress
|
||||
{
|
||||
public class NameAddress {
|
||||
String name;
|
||||
SipURL url;
|
||||
|
||||
|
||||
public NameAddress(String displayname, SipURL sipurl)
|
||||
{ name=displayname;
|
||||
public NameAddress(String displayname, SipURL sipurl) {
|
||||
name = displayname;
|
||||
url = sipurl;
|
||||
}
|
||||
|
||||
public NameAddress(SipURL sipurl)
|
||||
{ name=null;
|
||||
public NameAddress(SipURL sipurl) {
|
||||
name = null;
|
||||
url = sipurl;
|
||||
}
|
||||
|
||||
public NameAddress(NameAddress name_address)
|
||||
{ name=name_address.getDisplayName();
|
||||
public NameAddress(NameAddress name_address) {
|
||||
name = name_address.getDisplayName();
|
||||
url = name_address.getAddress();
|
||||
}
|
||||
|
||||
public NameAddress(String naddr)
|
||||
{ SipParser par=new SipParser(naddr);
|
||||
public NameAddress(String naddr) {
|
||||
SipParser par = new SipParser(naddr);
|
||||
NameAddress na = par.getNameAddress();
|
||||
//DEBUG
|
||||
//if (na==null)
|
||||
@ -67,54 +63,54 @@ public class NameAddress
|
||||
}
|
||||
|
||||
/** Creates and returns a copy of NameAddress */
|
||||
public Object clone()
|
||||
{ return new NameAddress(this);
|
||||
public Object clone() {
|
||||
return new NameAddress(this);
|
||||
}
|
||||
|
||||
/** Indicates whether some other Object is "equal to" this NameAddress */
|
||||
public boolean equals(Object obj)
|
||||
{ NameAddress naddr=(NameAddress)obj;
|
||||
public boolean equals(Object obj) {
|
||||
NameAddress naddr = (NameAddress)obj;
|
||||
return url.equals(naddr.getAddress());
|
||||
}
|
||||
|
||||
/** Gets address of NameAddress */
|
||||
public SipURL getAddress()
|
||||
{ return url;
|
||||
public SipURL getAddress() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/** Gets display name of NameAddress (Returns null id display name does not exist) */
|
||||
public String getDisplayName()
|
||||
{ return name;
|
||||
public String getDisplayName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Gets boolean value to indicate if NameAddress has display name */
|
||||
public boolean hasDisplayName()
|
||||
{ return name!=null;
|
||||
public boolean hasDisplayName() {
|
||||
return name!=null;
|
||||
}
|
||||
|
||||
/** Removes display name from NameAddress (if it exists) */
|
||||
public void removeDisplayName()
|
||||
{ name=null;
|
||||
public void removeDisplayName() {
|
||||
name = null;
|
||||
}
|
||||
|
||||
/** Sets address of NameAddress */
|
||||
public void setAddress(SipURL address)
|
||||
{ url=address;
|
||||
public void setAddress(SipURL address) {
|
||||
url = address;
|
||||
}
|
||||
|
||||
/** Sets display name of Header */
|
||||
public void setDisplayName(String displayName)
|
||||
{ name=displayName;
|
||||
public void setDisplayName(String displayName) {
|
||||
name = displayName;
|
||||
}
|
||||
|
||||
/** Whether two NameAddresses are equals */
|
||||
public boolean equals(NameAddress naddr)
|
||||
{ return (name==naddr.name && url==naddr.url);
|
||||
public boolean equals(NameAddress naddr) {
|
||||
return (name == naddr.name && url == naddr.url);
|
||||
}
|
||||
|
||||
/** Gets string representation of NameAddress */
|
||||
public String toString()
|
||||
{ String str;
|
||||
public String toString() {
|
||||
String str;
|
||||
if (hasDisplayName())
|
||||
str = "\"" + name + "\" <" + url +">";
|
||||
else str = "<" + url + ">";
|
||||
|
181
bbb-voice/src/main/java/org/zoolu/sip/address/SipURL.java
Normal file → Executable file
181
bbb-voice/src/main/java/org/zoolu/sip/address/SipURL.java
Normal file → Executable file
@ -23,20 +23,17 @@
|
||||
|
||||
package org.zoolu.sip.address;
|
||||
|
||||
|
||||
import org.zoolu.sip.provider.SipParser;
|
||||
import org.zoolu.tools.Parser;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
<P> Class <i>SipURL</i> implements SIP URLs.
|
||||
<P> A SIP URL is a string of the form of:
|
||||
<BR><BLOCKQUOTE><PRE>   sip:[user@]hostname[:port][;parameters] </PRE></BLOCKQUOTE>
|
||||
<P> If <i>port</i> number is ommitted, -1 is returned
|
||||
*/
|
||||
public class SipURL
|
||||
{
|
||||
public class SipURL {
|
||||
protected String url;
|
||||
|
||||
protected static final String transport_param="transport";
|
||||
@ -45,61 +42,63 @@ public class SipURL
|
||||
protected static final String lr_param="lr";
|
||||
|
||||
/** Creates a new SipURL based on a hostname or on a sip url as sip:[user@]hostname[:port][;param1=value1].. */
|
||||
public SipURL(String sipurl)
|
||||
{ if (sipurl.startsWith("sip:")) url=new String(sipurl);
|
||||
public SipURL(String sipurl) {
|
||||
if (sipurl.startsWith("sip:")) url=new String(sipurl);
|
||||
else url="sip:"+sipurl;
|
||||
}
|
||||
|
||||
/** Creates a new SipURL */
|
||||
public SipURL(String username, String hostname)
|
||||
{ init(username,hostname,-1);
|
||||
public SipURL(String username, String hostname) {
|
||||
init(username,hostname,-1);
|
||||
}
|
||||
|
||||
/** Creates a new SipURL */
|
||||
public SipURL(String hostname, int portnumber)
|
||||
{ init(null,hostname,portnumber);
|
||||
public SipURL(String hostname, int portnumber) {
|
||||
init(null, hostname, portnumber);
|
||||
}
|
||||
|
||||
/** Creates a new SipURL */
|
||||
public SipURL(String username, String hostname, int portnumber)
|
||||
{ init(username,hostname,portnumber);
|
||||
public SipURL(String username, String hostname, int portnumber) {
|
||||
init(username,hostname,portnumber);
|
||||
}
|
||||
|
||||
/** Inits the SipURL */
|
||||
private void init(String username, String hostname, int portnumber)
|
||||
{ StringBuffer sb=new StringBuffer("sip:");
|
||||
private void init(String username, String hostname, int portnumber) {
|
||||
StringBuffer sb = new StringBuffer("sip:");
|
||||
if (username != null) sb.append(username).append('@');
|
||||
sb.append(hostname);
|
||||
|
||||
if (portnumber > 0) sb.append(":" + portnumber);
|
||||
url = sb.toString();
|
||||
}
|
||||
|
||||
/** Creates and returns a copy of the URL */
|
||||
public Object clone()
|
||||
{ return new SipURL(url);
|
||||
public Object clone() {
|
||||
return new SipURL(url);
|
||||
}
|
||||
|
||||
/** Indicates whether some other Object is "equal to" this URL */
|
||||
public boolean equals(Object obj)
|
||||
{ SipURL newurl=(SipURL)obj;
|
||||
public boolean equals(Object obj) {
|
||||
SipURL newurl = (SipURL)obj;
|
||||
return url.toString().equals(newurl.toString());
|
||||
}
|
||||
|
||||
/** Gets user name of SipURL (Returns null if user name does not exist) */
|
||||
public String getUserName()
|
||||
{ int begin=4; // skip "sip:"
|
||||
public String getUserName() {
|
||||
int begin = 4; // skip "sip:"
|
||||
int end = url.indexOf('@',begin);
|
||||
if (end < 0) return null;
|
||||
else return url.substring(begin,end);
|
||||
}
|
||||
|
||||
/** Gets host of SipURL */
|
||||
public String getHost()
|
||||
{ char[] host_terminators={':',';','?'};
|
||||
public String getHost() {
|
||||
char[] host_terminators={':',';','?'};
|
||||
Parser par = new Parser(url);
|
||||
int begin = par.indexOf('@'); // skip "sip:user@"
|
||||
if (begin < 0) begin = 4; // skip "sip:"
|
||||
else begin++; // skip "@"
|
||||
|
||||
par.setPos(begin);
|
||||
int end = par.indexOf(host_terminators);
|
||||
if (end < 0) return url.substring(begin);
|
||||
@ -107,13 +106,13 @@ public class SipURL
|
||||
}
|
||||
|
||||
/** Gets port of SipURL; returns -1 if port is not specidfied */
|
||||
public int getPort()
|
||||
{ char[] port_terminators={';','?'};
|
||||
public int getPort() {
|
||||
char[] port_terminators={';','?'};
|
||||
Parser par = new Parser(url,4); // skip "sip:"
|
||||
int begin = par.indexOf(':');
|
||||
if (begin < 0) return -1;
|
||||
else
|
||||
{ begin++;
|
||||
else {
|
||||
begin++;
|
||||
par.setPos(begin);
|
||||
int end = par.indexOf(port_terminators);
|
||||
if (end < 0) return Integer.parseInt(url.substring(begin));
|
||||
@ -122,80 +121,80 @@ public class SipURL
|
||||
}
|
||||
|
||||
/** Gets boolean value to indicate if SipURL has user name */
|
||||
public boolean hasUserName()
|
||||
{ return getUserName()!=null;
|
||||
public boolean hasUserName() {
|
||||
return getUserName() != null;
|
||||
}
|
||||
|
||||
/** Gets boolean value to indicate if SipURL has port */
|
||||
public boolean hasPort()
|
||||
{ return getPort()>=0;
|
||||
public boolean hasPort() {
|
||||
return getPort() >= 0;
|
||||
}
|
||||
|
||||
/** Whether two SipURLs are equals */
|
||||
public boolean equals(SipURL sip_url)
|
||||
{ return (url==sip_url.url);
|
||||
public boolean equals(SipURL sip_url) {
|
||||
return (url == sip_url.url);
|
||||
}
|
||||
|
||||
|
||||
/** Gets string representation of URL */
|
||||
public String toString()
|
||||
{ return url;
|
||||
public String toString() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/** Gets the value of specified parameter.
|
||||
* @return null if parameter does not exist. */
|
||||
public String getParameter(String name)
|
||||
{ SipParser par=new SipParser(url);
|
||||
public String getParameter(String name) {
|
||||
SipParser par = new SipParser(url);
|
||||
return ((SipParser)par.goTo(';').skipChar()).getParameter(name);
|
||||
}
|
||||
|
||||
|
||||
/** Gets a String Vector of parameter names.
|
||||
* @return null if no parameter is present */
|
||||
public Vector getParameters()
|
||||
{ SipParser par=new SipParser(url);
|
||||
public Vector getParameters() {
|
||||
SipParser par = new SipParser(url);
|
||||
return ((SipParser)par.goTo(';').skipChar()).getParameters();
|
||||
}
|
||||
|
||||
/** Whether there is the specified parameter */
|
||||
public boolean hasParameter(String name)
|
||||
{ SipParser par=new SipParser(url);
|
||||
public boolean hasParameter(String name) {
|
||||
SipParser par = new SipParser(url);
|
||||
return ((SipParser)par.goTo(';').skipChar()).hasParameter(name);
|
||||
}
|
||||
|
||||
/** Whether there are any parameters */
|
||||
public boolean hasParameters()
|
||||
{ if (url!=null && url.indexOf(';')>=0) return true;
|
||||
public boolean hasParameters() {
|
||||
if (url != null && url.indexOf(';') >= 0) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/** Adds a new parameter without a value */
|
||||
public void addParameter(String name)
|
||||
{ url=url+";"+name;
|
||||
public void addParameter(String name) {
|
||||
url = url + ";" + name;
|
||||
}
|
||||
|
||||
/** Adds a new parameter with value */
|
||||
public void addParameter(String name, String value)
|
||||
{ if (value!=null) url=url+";"+name+"="+value;
|
||||
public void addParameter(String name, String value) {
|
||||
if (value != null) url = url + ";" + name + "=" + value;
|
||||
else url = url + ";" + name;
|
||||
}
|
||||
|
||||
/** Removes all parameters (if any) */
|
||||
public void removeParameters()
|
||||
{ int index=url.indexOf(';');
|
||||
public void removeParameters() {
|
||||
int index = url.indexOf(';');
|
||||
if (index >= 0) url = url.substring(0,index);
|
||||
}
|
||||
|
||||
/** Removes specified parameter (if present) */
|
||||
public void removeParameter(String name)
|
||||
{ int index=url.indexOf(';');
|
||||
public void removeParameter(String name) {
|
||||
int index = url.indexOf(';');
|
||||
if (index < 0) return;
|
||||
Parser par = new Parser(url,index);
|
||||
while (par.hasMore())
|
||||
{ int begin_param=par.getPos();
|
||||
while (par.hasMore()) {
|
||||
int begin_param = par.getPos();
|
||||
par.skipChar();
|
||||
if (par.getWord(SipParser.param_separators).equals(name))
|
||||
{ String top=url.substring(0,begin_param);
|
||||
if (par.getWord(SipParser.param_separators).equals(name)) {
|
||||
String top = url.substring(0,begin_param);
|
||||
par.goToSkippingQuoted(';');
|
||||
String bottom = "";
|
||||
if (par.hasMore()) bottom = url.substring(par.getPos());
|
||||
@ -209,56 +208,64 @@ public class SipURL
|
||||
|
||||
/** Gets the value of transport parameter.
|
||||
* @return null if no transport parameter is present. */
|
||||
public String getTransport()
|
||||
{ return getParameter(transport_param);
|
||||
}
|
||||
/** Whether transport parameter is present */
|
||||
public boolean hasTransport()
|
||||
{ return hasParameter(transport_param);
|
||||
}
|
||||
/** Adds transport parameter */
|
||||
public void addTransport(String proto)
|
||||
{ addParameter(transport_param,proto.toLowerCase());
|
||||
public String getTransport() {
|
||||
return getParameter(transport_param);
|
||||
}
|
||||
|
||||
/** Whether transport parameter is present */
|
||||
public boolean hasTransport() {
|
||||
return hasParameter(transport_param);
|
||||
}
|
||||
|
||||
/** Adds transport parameter */
|
||||
public void addTransport(String proto) {
|
||||
addParameter(transport_param,proto.toLowerCase());
|
||||
}
|
||||
|
||||
/** Gets the value of maddr parameter.
|
||||
* @return null if no maddr parameter is present. */
|
||||
public String getMaddr()
|
||||
{ return getParameter(maddr_param);
|
||||
}
|
||||
/** Whether maddr parameter is present */
|
||||
public boolean hasMaddr()
|
||||
{ return hasParameter(maddr_param);
|
||||
}
|
||||
/** Adds maddr parameter */
|
||||
public void addMaddr(String maddr)
|
||||
{ addParameter(maddr_param,maddr);
|
||||
public String getMaddr() {
|
||||
return getParameter(maddr_param);
|
||||
}
|
||||
|
||||
/** Whether maddr parameter is present */
|
||||
public boolean hasMaddr() {
|
||||
return hasParameter(maddr_param);
|
||||
}
|
||||
|
||||
/** Adds maddr parameter */
|
||||
public void addMaddr(String maddr) {
|
||||
addParameter(maddr_param,maddr);
|
||||
}
|
||||
|
||||
/** Gets the value of ttl parameter.
|
||||
* @return 1 if no ttl parameter is present. */
|
||||
public int getTtl()
|
||||
{ try { return Integer.parseInt(getParameter(ttl_param)); } catch (Exception e) { return 1; }
|
||||
public int getTtl() {
|
||||
try {
|
||||
return Integer.parseInt(getParameter(ttl_param));
|
||||
} catch (Exception e) {
|
||||
return 1;
|
||||
}
|
||||
/** Whether ttl parameter is present */
|
||||
public boolean hasTtl()
|
||||
{ return hasParameter(ttl_param);
|
||||
}
|
||||
/** Adds ttl parameter */
|
||||
public void addTtl(int ttl)
|
||||
{ addParameter(ttl_param,Integer.toString(ttl));
|
||||
}
|
||||
|
||||
/** Whether ttl parameter is present */
|
||||
public boolean hasTtl() {
|
||||
return hasParameter(ttl_param);
|
||||
}
|
||||
|
||||
/** Adds ttl parameter */
|
||||
public void addTtl(int ttl) {
|
||||
addParameter(ttl_param,Integer.toString(ttl));
|
||||
}
|
||||
|
||||
/** Whether lr (loose-route) parameter is present */
|
||||
public boolean hasLr()
|
||||
{ return hasParameter(lr_param);
|
||||
public boolean hasLr() {
|
||||
return hasParameter(lr_param);
|
||||
}
|
||||
|
||||
/** Adds lr parameter */
|
||||
public void addLr()
|
||||
{ addParameter(lr_param);
|
||||
public void addLr() {
|
||||
addParameter(lr_param);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,15 +291,17 @@ public class SipProvider implements Configurable, TransportListener, TcpServerLi
|
||||
host_port = port;
|
||||
if (host_port <= 0) host_port = SipStack.default_port;
|
||||
host_ipaddr = null;
|
||||
if (ifaddr!=null && !ifaddr.equalsIgnoreCase(ALL_INTERFACES))
|
||||
{
|
||||
if (ifaddr != null && !ifaddr.equalsIgnoreCase(ALL_INTERFACES)) {
|
||||
try {
|
||||
host_ipaddr = IpAddress.getByName(ifaddr);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); host_ipaddr=null;
|
||||
e.printStackTrace();
|
||||
host_ipaddr = null;
|
||||
}
|
||||
}
|
||||
|
||||
transport_protocols = protocols;
|
||||
|
||||
if (transport_protocols==null) transport_protocols=SipStack.default_transport_protocols;
|
||||
default_transport=transport_protocols[0];
|
||||
for (int i=0; i<transport_protocols.length; i++)
|
||||
|
Loading…
Reference in New Issue
Block a user