/** * Set the host portion of the SipURI * * @param host host to set. */ public void setHost(String host) throws ParseException { Host h = new Host(host); this.setHost(h); }
public Object clone() { ConnectionAddress retval = (ConnectionAddress) super.clone(); if (this.address != null) retval.address = (Host) this.address.clone(); return retval; }
/** * Convenience function to get the raw IP destination address * of a SIP message as a String. * @return String */ public String getIpAddress() { String rawIpAddress = null; if (hostname == null) return null; if (addressType == HOSTNAME) { try { if (inetAddress == null) inetAddress = InetAddress.getByName(hostname); rawIpAddress = inetAddress.getHostAddress(); } catch (UnknownHostException ex) { dbgPrint("Could not resolve hostname " + ex); } } else { rawIpAddress = hostname; } return rawIpAddress; }
/** * Get the string encoded version of this object * @since v1.0 */ public String encode() { String encoded_string = ""; if (address != null){ encoded_string = address.encode(); //it appears that SDP does not allow square brackets //in the connection address (see RFC4566) so make sure //we lose them if(Host.isIPv6Reference(encoded_string)) { //the isIPv6Reference == true means we have a minimum //of 2 symbols, so substring bravely encoded_string = encoded_string .substring(1, encoded_string.length()-1); } } if (ttl != 0 && port != 0) { encoded_string += Separators.SLASH + ttl + Separators.SLASH + port; } else if (ttl != 0) { encoded_string += Separators.SLASH + ttl; } return encoded_string; }
/** * Generate a key given host and port. */ public static String getKey(HostPort hostPort, String transport) { // http://java.net/jira/browse/JSIP-413 Concurrency issue within MessageChannel.java when using IPv6 addresses String ipAddress = hostPort.getHost().getIpAddress(); if (ipAddress == null) { ipAddress = hostPort.getHost().getHostname(); } return (transport + ":" + ipAddress.replaceAll("[\\[\\]]", "") + ":" + hostPort.getPort()) .toLowerCase(); }
/** * Sets the value of the <code>maddr</code> parameter of this ViaHeader. The * maddr parameter indicates the server address to be contacted for this * user, overriding any address derived from the host field. * * @param mAddr new value of the <code>maddr</code> parameter * @throws ParseException which signals that an error has been reached * unexpectedly while parsing the mAddr value. */ public void setMAddr(String mAddr) throws ParseException { if (mAddr == null) throw new NullPointerException( "JAIN-SIP Exception, " + "Via, setMAddr(), the mAddr parameter is null."); Host host = new Host(); host.setAddress(mAddr); NameValue nameValue = new NameValue(ParameterNames.MADDR, host); setParameter(nameValue); }
/** * Creates a client transaction to handle a new request. Gets the real * message channel from the superclass, and then creates a new client * transaction wrapped around this channel. * * @param nextHop * Hop to create a channel to contact. */ public MessageChannel createMessageChannel(SIPRequest request, MessageProcessor mp, Hop nextHop) throws IOException { // Create a new client transaction around the // superclass' message channel // Create the host/port of the target hop Host targetHost = new Host(); targetHost.setHostname(nextHop.getHost()); HostPort targetHostPort = new HostPort(); targetHostPort.setHost(targetHost); targetHostPort.setPort(nextHop.getPort()); MessageChannel returnChannel = mp.createMessageChannel(targetHostPort); return returnChannel; }
/** * Return the host name in encoded form. * @return String */ public String encode() { return encode(new StringBuilder()).toString(); }
@Override public int hashCode() { return this.getHostname().hashCode(); } }
/** Returns the type of the network for this Connection. * @throws SdpParseException * @return the string network type. */ public String getAddress() throws SdpParseException { Host addr = getHost(); if (addr == null) return null; else return addr.getAddress(); }
/** Return the internet address corresponding to the host. *@throws java.net.UnkownHostException if host name cannot be resolved. *@return the inet address for the host. */ public InetAddress getInetAddress() throws java.net.UnknownHostException { if (host == null) return null; else return host.getInetAddress(); }
@Override public int hashCode() { return this.host.hashCode() + this.port; } }
/** returns true if the two objects are equals, false otherwise. * @param other Object to set * @return boolean */ public boolean equals(Object other) { if (other == null) return false; if (getClass () != other.getClass ()) { return false; } HostPort that = (HostPort) other; return port == that.port && host.equals(that.host); }
/** Sets the type of the address for this Connection. * @param addr string address type. * @throws SdpException if the addr is null */ public void setAddress(String addr) throws SdpException { if (addr == null) throw new SdpException("The addr parameter is null"); else { Host host = getHost(); if (host == null) host = new Host(); host.setAddress(addr); setAddress(host); } }
/** * Get the Via header to assign for this message processor. The topmost via * header of the outoging messages use this. * * @return the ViaHeader to be used by the messages sent via this message processor. */ public Via getViaHeader() { try { Via via = new Via(); if (this.sentByHostPort != null) { via.setSentBy(sentByHostPort); via.setTransport(this.getTransport()); } else { Host host = new Host(); host.setHostname(this.getIpAddress().getHostAddress()); via.setHost(host); via.setPort(this.getPort()); via.setTransport(this.getTransport()); } return via; } catch (ParseException ex) { ex.printStackTrace(); return null; } catch (InvalidArgumentException ex) { ex.printStackTrace(); return null; } } public ListeningPointImpl getListeningPoint() {
addressStr = address.encode(); if(Host.isIPv6Reference(addressStr))
public StringBuilder encode(StringBuilder buffer) { host.encode(buffer); if (port != -1) buffer.append(COLON).append(port); return buffer; }
/** * Returns the host part of this ViaHeader. * * @return the string value of the host */ public String getHost() { if (sentBy == null) return null; else { Host host = sentBy.getHost(); if (host == null) return null; else return host.getHostname(); } }
/** Returns the type of the network for this Connection. * @throws SdpParseException * @return the type of the network */ public String getAddress() throws SdpParseException { ConnectionAddress connectionAddress = getConnectionAddress(); if (connectionAddress == null) return null; else { Host host = connectionAddress.getAddress(); if (host == null) return null; else return host.getAddress(); } }
/** * @param ipAddress the ipAddress to set */ protected void setIpAddress(InetAddress ipAddress) { this.sentByHostPort.setHost( new Host(ipAddress.getHostAddress())); this.ipAddress = ipAddress; }