diff --git a/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java b/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java index 92ae80f35..83d685341 100644 --- a/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java +++ b/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java @@ -129,11 +129,15 @@ public synchronized InetAddress getLocalHost( InetAddress intendedDestination) { InetAddress localHost = null; - String osVersion = System.getProperty("os.version"); if(logger.isTraceEnabled()) + { logger.trace( - "Querying a localhost addr for dst=" + intendedDestination); + "Querying for a localhost address" + + " for intended destination '" + + intendedDestination + + "'"); + } /* use native code (JNI) to find source address for a specific * destination address on Windows XP SP1 and over. @@ -143,14 +147,18 @@ public synchronized InetAddress getLocalHost( * on Windows is because its socket implementation returns the any * address... */ - if(OSUtils.IS_WINDOWS && - !osVersion.startsWith("4") && /* 95/98/Me/NT */ - !osVersion.startsWith("5.0")) /* 2000 */ + String osVersion; + + if (OSUtils.IS_WINDOWS + && !(osVersion = System.getProperty("os.version")).startsWith( + "4") /* 95/98/Me/NT */ + && !osVersion.startsWith("5.0")) /* 2000 */ { - byte[] src = Win32LocalhostRetriever.getSourceForDestination( - intendedDestination.getAddress()); + byte[] src + = Win32LocalhostRetriever.getSourceForDestination( + intendedDestination.getAddress()); - if(src == null) + if (src == null) { logger.warn("Failed to get localhost "); } @@ -160,9 +168,9 @@ public synchronized InetAddress getLocalHost( { localHost = InetAddress.getByAddress(src); } - catch(UnknownHostException e) + catch(UnknownHostException uhe) { - logger.warn("Failed to get localhost ", e); + logger.warn("Failed to get localhost", uhe); } } } @@ -176,10 +184,10 @@ public synchronized InetAddress getLocalHost( localHost = localHostFinderSocket.getLocalAddress(); localHostFinderSocket.disconnect(); } + //windows socket implementations return the any address so we need to //find something else here ... InetAddress.getLocalHost seems to work - //better on windows so lets hope it'll do the trick. - + //better on windows so let's hope it'll do the trick. if (localHost == null) { try @@ -191,11 +199,14 @@ public synchronized InetAddress getLocalHost( logger.warn("Failed to get localhost ", e); } } - if( localHost.isAnyLocalAddress()) + if (localHost.isAnyLocalAddress()) { if (logger.isTraceEnabled()) - logger.trace("Socket returned the AnyLocalAddress. "+ - "Trying a workaround."); + { + logger.trace( + "Socket returned the ANY local address." + + " Trying a workaround."); + } try { //all that's inside the if is an ugly IPv6 hack @@ -204,32 +215,28 @@ public synchronized InetAddress getLocalHost( { //return the first globally routable ipv6 address we find //on the machine (and hope it's a good one) - Enumeration interfaces + boolean done = false; + Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); - while (interfaces.hasMoreElements()) + while (!done && ifaces.hasMoreElements()) { - NetworkInterface iface = interfaces.nextElement(); - Enumeration addresses = - iface.getInetAddresses(); - while(addresses.hasMoreElements()) + Enumeration addresses + = ifaces.nextElement().getInetAddresses(); + + while (addresses.hasMoreElements()) { - InetAddress address - = addresses.nextElement(); - if(address instanceof Inet6Address) - { - if(!address.isAnyLocalAddress() + InetAddress address = addresses.nextElement(); + + if ((address instanceof Inet6Address) + && !address.isAnyLocalAddress() && !address.isLinkLocalAddress() - && !address.isSiteLocalAddress() - && !address.isLoopbackAddress()) - { - if(logger.isTraceEnabled()) - { - logger.trace("will return ipv6 addr " - + address); - } - return address; - } + && !address.isLoopbackAddress() + && !address.isSiteLocalAddress()) + { + localHost = address; + done = true; + break; } } } @@ -243,47 +250,41 @@ public synchronized InetAddress getLocalHost( // Make sure we got an IPv4 address. if (!(localHost instanceof Inet4Address)) { - // return the first non localhost interface we find. - Enumeration interfaces = - NetworkInterface.getNetworkInterfaces(); + // return the first non-loopback interface we find. + boolean done = false; + Enumeration ifaces + = NetworkInterface.getNetworkInterfaces(); - while (interfaces.hasMoreElements()) + while (!done && ifaces.hasMoreElements()) { - NetworkInterface iface = interfaces.nextElement(); - Enumeration addresses = iface - .getInetAddresses(); + Enumeration addresses + = ifaces.nextElement().getInetAddresses(); + while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); - if (address instanceof Inet4Address) + + if ((address instanceof Inet4Address) + && !address.isLoopbackAddress()) { - if (!address.isLoopbackAddress()) - { - if (logger.isTraceEnabled()) - { - logger.trace( - "will return ipv6 addr " - + address); - } - return address; - } + localHost = address; + done = true; + break; } } } } } } - catch (Exception ex) + catch (Exception e) { //sigh ... ok return 0.0.0.0 - logger.warn("Failed to get localhost ", ex); + logger.warn("Failed to get localhost", e); } } - if(logger.isTraceEnabled()) - { - logger.trace("Will return the following localhost address: " - + localHost); - } + + if (logger.isTraceEnabled()) + logger.trace("Returning the localhost address '" + localHost + "'"); return localHost; } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/TransportManagerJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/TransportManagerJabberImpl.java index 999e20b77..31975c4c5 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/TransportManagerJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/TransportManagerJabberImpl.java @@ -306,7 +306,8 @@ protected ContentPacketExtension removeContent( } /** - * Close this transport manager and release resources. + * Releases the resources acquired by this TransportManager and + * prepares it for garbage collection. */ public void close() { diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/cobri/CobriConferenceIQ.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/cobri/CobriConferenceIQ.java index e33bf4c7c..d44c6ca74 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/cobri/CobriConferenceIQ.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/cobri/CobriConferenceIQ.java @@ -186,6 +186,21 @@ public static class Channel */ public static final String ELEMENT_NAME = "channel"; + /** + * The XML name of the expire attribute of a channel + * of a content of a conference IQ which represents + * the value of the expire property of + * CobriConferenceIQ.Channel. + */ + public static final String EXPIRE_ATTR_NAME = "expire"; + + /** + * The value of the expire property of + * CobriConferenceIQ.Channel which indicates that no actual + * value has been specified for the property in question. + */ + public static final int EXPIRE_NOT_SPECIFIED = -1; + /** * The XML name of the host attribute of a channel of * a content of a conference IQ which represents the @@ -218,6 +233,12 @@ public static class Channel */ public static final String RTP_PORT_ATTR_NAME = "rtpport"; + /** + * The number of seconds of inactivity after which the channel + * represented by this instance expires. + */ + private int expire = EXPIRE_NOT_SPECIFIED; + /** * The host of the channel represented by this instance. */ @@ -268,6 +289,18 @@ public boolean addPayloadType(PayloadTypePacketExtension payloadType) : payloadTypes.add(payloadType); } + /** + * Gets the number of seconds of inactivity after which the + * channel represented by this instance expires. + * + * @return the number of seconds of inactivity after which the + * channel represented by this instance expires + */ + public int getExpire() + { + return expire; + } + public String getHost() { return host; @@ -313,6 +346,24 @@ public boolean removePayloadType(PayloadTypePacketExtension payloadType) return payloadTypes.remove(payloadType); } + /** + * Sets the number of seconds of inactivity after which the + * channel represented by this instance expires. + * + * @param expire the number of seconds of activity after which the + * channel represented by this instance expires + * @throws IllegalArgumentException if the value of the specified + * expire is other than {@link #EXPIRE_NOT_SPECIFIED} and + * negative + */ + public void setExpire(int expire) + { + if ((expire != EXPIRE_NOT_SPECIFIED) && (expire < 0)) + throw new IllegalArgumentException("expire"); + + this.expire = expire; + } + public void setHost(String host) { this.host = host; @@ -366,6 +417,12 @@ public void toXML(StringBuilder xml) xml.append(' ').append(RTCP_PORT_ATTR_NAME).append("='") .append(rtcpPort).append('\''); + int expire = getExpire(); + + if (expire >= 0) + xml.append(' ').append(EXPIRE_ATTR_NAME).append("='") + .append(expire).append('\''); + List payloadTypes = getPayloadTypes(); if (payloadTypes.size() == 0) diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/cobri/CobriIQProvider.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/cobri/CobriIQProvider.java index 95484cbf4..aab8ad35c 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/cobri/CobriIQProvider.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/cobri/CobriIQProvider.java @@ -121,6 +121,13 @@ else if (CobriConferenceIQ.Content.ELEMENT_NAME if ((rtcpPort != null) && (rtcpPort.length() != 0)) channel.setRTCPPort(Integer.parseInt(rtcpPort)); + String expire + = parser.getAttributeValue( + "", + CobriConferenceIQ.Channel.EXPIRE_ATTR_NAME); + + if ((expire != null) && (expire.length() != 0)) + channel.setExpire(Integer.parseInt(expire)); } else if (CobriConferenceIQ.Content.ELEMENT_NAME .equals(name)) diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/jinglesdp/JingleUtils.java b/src/net/java/sip/communicator/impl/protocol/jabber/jinglesdp/JingleUtils.java index b8cc80940..6edf49551 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/jinglesdp/JingleUtils.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/jinglesdp/JingleUtils.java @@ -24,6 +24,7 @@ * transports. * * @author Emil Ivov + * @author Lyubomir Marinov */ public class JingleUtils { @@ -99,16 +100,46 @@ public static List extractFormats( * Returns the {@link MediaFormat} described in the payloadType * extension or null if we don't recognize the format. * - * @param payloadType the {@link PayloadTypePacketExtension} that we'd like - * to parse into a {@link MediaFormat}. + * @param payloadType the {@link PayloadTypePacketExtension} which is to be + * parsed into a {@link MediaFormat}. * @param ptRegistry the {@link DynamicPayloadTypeRegistry} that we would - * use for the registration of possible dynamic payload types. + * use for the registration of possible dynamic payload types or + * null the returned MediaFormat is to not be registered + * into a DynamicPayloadTypeRegistry. + * + * @return the {@link MediaFormat} described in the payloadType + * extension or null if we don't recognize the format. + */ + public static MediaFormat payloadTypeToMediaFormat( + PayloadTypePacketExtension payloadType, + DynamicPayloadTypeRegistry ptRegistry) + { + return + payloadTypeToMediaFormat( + payloadType, + JabberActivator.getMediaService(), + ptRegistry); + } + + /** + * Returns the {@link MediaFormat} described in the payloadType + * extension or null if we don't recognize the format. + * + * @param payloadType the {@link PayloadTypePacketExtension} which is to be + * parsed into a {@link MediaFormat}. + * @param mediaService the MediaService implementation which is to + * be used for MediaFormat-related factory methods + * @param ptRegistry the {@link DynamicPayloadTypeRegistry} that we would + * use for the registration of possible dynamic payload types or + * null the returned MediaFormat is to not be registered + * into a DynamicPayloadTypeRegistry. * * @return the {@link MediaFormat} described in the payloadType * extension or null if we don't recognize the format. */ public static MediaFormat payloadTypeToMediaFormat( PayloadTypePacketExtension payloadType, + MediaService mediaService, DynamicPayloadTypeRegistry ptRegistry) { byte pt = (byte)payloadType.getID(); @@ -127,19 +158,15 @@ public static MediaFormat payloadTypeToMediaFormat( paramsMap.put(param.getName(), param.getValue()); } - // video related attribute in payload type element + // video-related attributes in payload-type element for(String attr : payloadType.getAttributeNames()) { if(attr.equals("width") || attr.equals("height")) - { - paramsMap.put(attr, payloadType.getAttributeAsString( - attr)); - } + paramsMap.put(attr, payloadType.getAttributeAsString(attr)); } //now create the format. - MediaFormatFactory formatFactory - = JabberActivator.getMediaService().getFormatFactory(); + MediaFormatFactory formatFactory = mediaService.getFormatFactory(); MediaFormat format = formatFactory.createMediaFormat( pt, @@ -169,14 +196,15 @@ public static MediaFormat payloadTypeToMediaFormat( * re-map a payloadType in its answer to a different MediaFormat * than the one we've specified in our offer? */ - if ((pt >= MediaFormat.MIN_DYNAMIC_PAYLOAD_TYPE) + if ((ptRegistry != null) + && (pt >= MediaFormat.MIN_DYNAMIC_PAYLOAD_TYPE) && (pt <= MediaFormat.MAX_DYNAMIC_PAYLOAD_TYPE) && (ptRegistry.findFormat(pt) == null)) { ptRegistry.addMapping(format, pt); } - return (unknown == false) ? format : null; + return unknown ? null : format; } /** @@ -527,18 +555,19 @@ public static ContentPacketExtension createDescription( } /** - * Converts format into a {@link PayloadTypePacketExtension} instance. + * Converts a specific {@link MediaFormat} into a new + * {@link PayloadTypePacketExtension} instance. * - * @param format the {@link MediaFormat} we'd like to convert. + * @param format the MediaFormat we'd like to convert. * @param ptRegistry the {@link DynamicPayloadTypeRegistry} to use for * formats that don't have a static pt number. * - * @return the newly created {@link PayloadTypePacketExtension} that - * contains format's parameters. + * @return the new PayloadTypePacketExtension which contains + * format's parameters. */ public static PayloadTypePacketExtension formatToPayloadType( - MediaFormat format, - DynamicPayloadTypeRegistry ptRegistry) + MediaFormat format, + DynamicPayloadTypeRegistry ptRegistry) { PayloadTypePacketExtension ptExt = new PayloadTypePacketExtension(); @@ -555,7 +584,10 @@ public static PayloadTypePacketExtension formatToPayloadType( ptExt.setClockrate((int)format.getClockRate()); - /* add parameters */ + /* + * Add the format parameters and the advanced attributes (as parameter + * packet extensions). + */ for(Map.Entry entry : format.getFormatParameters().entrySet()) { @@ -564,7 +596,6 @@ public static PayloadTypePacketExtension formatToPayloadType( ext.setValue(entry.getValue()); ptExt.addParameter(ext); } - for(Map.Entry entry : format.getAdvancedAttributes().entrySet()) {