From f305c555f8f6ff73225fda15a5d4c10268d33ed9 Mon Sep 17 00:00:00 2001 From: Richard Alam Date: Thu, 22 Jul 2010 14:15:52 -0400 Subject: [PATCH] - fix formatting --- .../org/zoolu/sip/address/NameAddress.java | 82 +++--- .../java/org/zoolu/sip/address/SipURL.java | 239 +++++++++--------- .../org/zoolu/sip/provider/SipProvider.java | 18 +- 3 files changed, 172 insertions(+), 167 deletions(-) mode change 100644 => 100755 bbb-voice/src/main/java/org/zoolu/sip/address/NameAddress.java mode change 100644 => 100755 bbb-voice/src/main/java/org/zoolu/sip/address/SipURL.java diff --git a/bbb-voice/src/main/java/org/zoolu/sip/address/NameAddress.java b/bbb-voice/src/main/java/org/zoolu/sip/address/NameAddress.java old mode 100644 new mode 100755 index a568f521a6..3f97b824d9 --- a/bbb-voice/src/main/java/org/zoolu/sip/address/NameAddress.java +++ b/bbb-voice/src/main/java/org/zoolu/sip/address/NameAddress.java @@ -23,101 +23,97 @@ package org.zoolu.sip.address; - import org.zoolu.sip.provider.SipParser; - /** Class NameAddress is used to rapresent any valid SIP Name Address. * It contains a SIP URI and optionally a display name. *
A SIP Name Address is a string of the form of: *
   [ display-name ] address
   * 
   where address can be a valid SIP URL
*/ -public class NameAddress -{ +public class NameAddress { String name; SipURL url; - - public NameAddress(String displayname, SipURL sipurl) - { name=displayname; - url=sipurl; + public NameAddress(String displayname, SipURL sipurl) { + name = displayname; + url = sipurl; } - public NameAddress(SipURL sipurl) - { name=null; - url=sipurl; + public NameAddress(SipURL sipurl) { + name = null; + url = sipurl; } - public NameAddress(NameAddress name_address) - { name=name_address.getDisplayName(); - url=name_address.getAddress(); + public NameAddress(NameAddress name_address) { + name = name_address.getDisplayName(); + url = name_address.getAddress(); } - public NameAddress(String naddr) - { SipParser par=new SipParser(naddr); - NameAddress na=par.getNameAddress(); + public NameAddress(String naddr) { + SipParser par = new SipParser(naddr); + NameAddress na = par.getNameAddress(); //DEBUG //if (na==null) //{ System.out.println("DEBUG: NameAddress: par:\r\n"+par.getWholeString()); // System.exit(0); //} - name=na.name; - url=na.url; + name = na.name; + url = na.url; } /** 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; - return url.equals(naddr.getAddress()); + 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; - if (hasDisplayName()) - str="\""+name+"\" <"+url+">"; - else str="<"+url+">"; + public String toString() { + String str; + if (hasDisplayName()) + str = "\"" + name + "\" <" + url +">"; + else str = "<" + url + ">"; return str; } diff --git a/bbb-voice/src/main/java/org/zoolu/sip/address/SipURL.java b/bbb-voice/src/main/java/org/zoolu/sip/address/SipURL.java old mode 100644 new mode 100755 index 0cfcb66201..0a2a34a240 --- a/bbb-voice/src/main/java/org/zoolu/sip/address/SipURL.java +++ b/bbb-voice/src/main/java/org/zoolu/sip/address/SipURL.java @@ -23,20 +23,17 @@ package org.zoolu.sip.address; - import org.zoolu.sip.provider.SipParser; import org.zoolu.tools.Parser; import java.util.Vector; - /**

Class SipURL implements SIP URLs.

A SIP URL is a string of the form of:

   sip:[user@]hostname[:port][;parameters] 

If port number is ommitted, -1 is returned */ -public class SipURL -{ +public class SipURL { protected String url; protected static final String transport_param="transport"; @@ -45,162 +42,164 @@ 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); - else url="sip:"+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:"); - if (username!=null) sb.append(username).append('@'); - sb.append(hostname); - if (portnumber>0) sb.append(":"+portnumber); - url=sb.toString(); + 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:" - int end=url.indexOf('@',begin); - if (end<0) return null; - else return url.substring(begin,end); + 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={':',';','?'}; - 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); - else return url.substring(begin,end); + 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); + else return url.substring(begin,end); } /** Gets port of SipURL; returns -1 if port is not specidfied */ - 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++; - par.setPos(begin); - int end=par.indexOf(port_terminators); - if (end<0) return Integer.parseInt(url.substring(begin)); - else return Integer.parseInt(url.substring(begin,end)); + 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++; + par.setPos(begin); + int end = par.indexOf(port_terminators); + if (end < 0) return Integer.parseInt(url.substring(begin)); + else return Integer.parseInt(url.substring(begin,end)); } } /** 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); - return ((SipParser)par.goTo(';').skipChar()).getParameters(); + 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); - return ((SipParser)par.goTo(';').skipChar()).hasParameter(name); + 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; - else return false; + 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; - else url=url+";"+name; + 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(';'); - if (index>=0) url=url.substring(0,index); + 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(';'); - if (index<0) return; - Parser par=new Parser(url,index); - 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); - par.goToSkippingQuoted(';'); - String bottom=""; - if (par.hasMore()) bottom=url.substring(par.getPos()); - url=top.concat(bottom); - return; + 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(); + par.skipChar(); + 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()); + url = top.concat(bottom); + return; } par.goTo(';'); } @@ -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); + public String getTransport() { + return getParameter(transport_param); } + /** Whether transport parameter is present */ - public boolean hasTransport() - { return hasParameter(transport_param); + public boolean hasTransport() { + return hasParameter(transport_param); } + /** Adds transport parameter */ - public void addTransport(String proto) - { addParameter(transport_param,proto.toLowerCase()); + 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); + public String getMaddr() { + return getParameter(maddr_param); } + /** Whether maddr parameter is present */ - public boolean hasMaddr() - { return hasParameter(maddr_param); + public boolean hasMaddr() { + return hasParameter(maddr_param); } + /** Adds maddr parameter */ - public void addMaddr(String maddr) - { addParameter(maddr_param,maddr); + 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); + public boolean hasTtl() { + return hasParameter(ttl_param); } + /** Adds ttl parameter */ - public void addTtl(int ttl) - { addParameter(ttl_param,Integer.toString(ttl)); + 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); } } diff --git a/bbb-voice/src/main/java/org/zoolu/sip/provider/SipProvider.java b/bbb-voice/src/main/java/org/zoolu/sip/provider/SipProvider.java index 86182f0535..d2b5ce25d2 100755 --- a/bbb-voice/src/main/java/org/zoolu/sip/provider/SipProvider.java +++ b/bbb-voice/src/main/java/org/zoolu/sip/provider/SipProvider.java @@ -287,19 +287,21 @@ public class SipProvider implements Configurable, TransportListener, TcpServerLi { if (!SipStack.isInit()) SipStack.init(); via_addr = viaddr; - if (via_addr==null || via_addr.equalsIgnoreCase(AUTO_CONFIGURATION)) via_addr=IpAddress.getLocalHostAddress().toString(); + if (via_addr == null || via_addr.equalsIgnoreCase(AUTO_CONFIGURATION)) via_addr = IpAddress.getLocalHostAddress().toString(); host_port = port; - if (host_port<=0) host_port=SipStack.default_port; - host_ipaddr=null; - if (ifaddr!=null && !ifaddr.equalsIgnoreCase(ALL_INTERFACES)) - { + if (host_port <= 0) host_port = SipStack.default_port; + host_ipaddr = null; + if (ifaddr != null && !ifaddr.equalsIgnoreCase(ALL_INTERFACES)) { try { - host_ipaddr=IpAddress.getByName(ifaddr); + host_ipaddr = IpAddress.getByName(ifaddr); } catch (IOException e) { - e.printStackTrace(); host_ipaddr=null; + e.printStackTrace(); + host_ipaddr = null; } } - transport_protocols=protocols; + + transport_protocols = protocols; + if (transport_protocols==null) transport_protocols=SipStack.default_transport_protocols; default_transport=transport_protocols[0]; for (int i=0; i