diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2012-03-26 14:59:55 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2012-03-26 14:59:55 +0000 |
commit | 3b2b9805044b2b9ba55dfae176a7ce1eb1819fff (patch) | |
tree | 1fec62071cb6f3d7d4efa9cf44ef3efd9419b08d /src/net/java/sip/communicator | |
parent | d113358cd6557b466b1cc9de8872f106bae0e427 (diff) | |
download | jitsi-3b2b9805044b2b9ba55dfae176a7ce1eb1819fff.zip jitsi-3b2b9805044b2b9ba55dfae176a7ce1eb1819fff.tar.gz jitsi-3b2b9805044b2b9ba55dfae176a7ce1eb1819fff.tar.bz2 |
Allows JingleUtils to be used as a utility class outside of OSGi.
Diffstat (limited to 'src/net/java/sip/communicator')
5 files changed, 179 insertions, 82 deletions
diff --git a/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java b/src/net/java/sip/communicator/impl/netaddr/NetworkAddressManagerServiceImpl.java index 92ae80f..83d6853 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 class NetworkAddressManagerServiceImpl 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 class NetworkAddressManagerServiceImpl * 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 class NetworkAddressManagerServiceImpl { 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 class NetworkAddressManagerServiceImpl 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 class NetworkAddressManagerServiceImpl 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 class NetworkAddressManagerServiceImpl { //return the first globally routable ipv6 address we find //on the machine (and hope it's a good one) - Enumeration<NetworkInterface> interfaces + boolean done = false; + Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); - while (interfaces.hasMoreElements()) + while (!done && ifaces.hasMoreElements()) { - NetworkInterface iface = interfaces.nextElement(); - Enumeration<InetAddress> addresses = - iface.getInetAddresses(); - while(addresses.hasMoreElements()) + Enumeration<InetAddress> 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 class NetworkAddressManagerServiceImpl // Make sure we got an IPv4 address. if (!(localHost instanceof Inet4Address)) { - // return the first non localhost interface we find. - Enumeration<NetworkInterface> interfaces = - NetworkInterface.getNetworkInterfaces(); + // return the first non-loopback interface we find. + boolean done = false; + Enumeration<NetworkInterface> ifaces + = NetworkInterface.getNetworkInterfaces(); - while (interfaces.hasMoreElements()) + while (!done && ifaces.hasMoreElements()) { - NetworkInterface iface = interfaces.nextElement(); - Enumeration<InetAddress> addresses = iface - .getInetAddresses(); + Enumeration<InetAddress> 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 999e20b..31975c4 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 @@ public abstract class TransportManagerJabberImpl } /** - * Close this transport manager and release resources. + * Releases the resources acquired by this <tt>TransportManager</tt> 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 e33bf4c..d44c6ca 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 @@ -187,6 +187,21 @@ public class CobriConferenceIQ public static final String ELEMENT_NAME = "channel"; /** + * The XML name of the <tt>expire</tt> attribute of a <tt>channel</tt> + * of a <tt>content</tt> of a <tt>conference</tt> IQ which represents + * the value of the <tt>expire</tt> property of + * <tt>CobriConferenceIQ.Channel</tt>. + */ + public static final String EXPIRE_ATTR_NAME = "expire"; + + /** + * The value of the <tt>expire</tt> property of + * <tt>CobriConferenceIQ.Channel</tt> 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 <tt>host</tt> attribute of a <tt>channel</tt> of * a <tt>content</tt> of a <tt>conference</tt> IQ which represents the * value of the <tt>host</tt> property of @@ -219,6 +234,12 @@ public class CobriConferenceIQ public static final String RTP_PORT_ATTR_NAME = "rtpport"; /** + * The number of seconds of inactivity after which the <tt>channel</tt> + * represented by this instance expires. + */ + private int expire = EXPIRE_NOT_SPECIFIED; + + /** * The host of the <tt>channel</tt> represented by this instance. */ private String host; @@ -268,6 +289,18 @@ public class CobriConferenceIQ : payloadTypes.add(payloadType); } + /** + * Gets the number of seconds of inactivity after which the + * <tt>channel</tt> represented by this instance expires. + * + * @return the number of seconds of inactivity after which the + * <tt>channel</tt> represented by this instance expires + */ + public int getExpire() + { + return expire; + } + public String getHost() { return host; @@ -313,6 +346,24 @@ public class CobriConferenceIQ return payloadTypes.remove(payloadType); } + /** + * Sets the number of seconds of inactivity after which the + * <tt>channel</tt> represented by this instance expires. + * + * @param expire the number of seconds of activity after which the + * <tt>channel</tt> represented by this instance expires + * @throws IllegalArgumentException if the value of the specified + * <tt>expire</tt> 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 class CobriConferenceIQ 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<PayloadTypePacketExtension> 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 95484cb..aab8ad3 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 @@ public class CobriIQProvider 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 b8cc809..6edf495 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 @@ import static net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.C * transports. * * @author Emil Ivov + * @author Lyubomir Marinov */ public class JingleUtils { @@ -99,16 +100,46 @@ public class JingleUtils * Returns the {@link MediaFormat} described in the <tt>payloadType</tt> * extension or <tt>null</tt> 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 + * <tt>null</tt> the returned <tt>MediaFormat</tt> is to not be registered + * into a <tt>DynamicPayloadTypeRegistry</tt>. + * + * @return the {@link MediaFormat} described in the <tt>payloadType</tt> + * extension or <tt>null</tt> 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 <tt>payloadType</tt> + * extension or <tt>null</tt> if we don't recognize the format. + * + * @param payloadType the {@link PayloadTypePacketExtension} which is to be + * parsed into a {@link MediaFormat}. + * @param mediaService the <tt>MediaService</tt> implementation which is to + * be used for <tt>MediaFormat</tt>-related factory methods + * @param ptRegistry the {@link DynamicPayloadTypeRegistry} that we would + * use for the registration of possible dynamic payload types or + * <tt>null</tt> the returned <tt>MediaFormat</tt> is to not be registered + * into a <tt>DynamicPayloadTypeRegistry</tt>. * * @return the {@link MediaFormat} described in the <tt>payloadType</tt> * extension or <tt>null</tt> 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 class JingleUtils 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 class JingleUtils * 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 class JingleUtils } /** - * Converts <tt>format</tt> 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 <tt>MediaFormat</tt> 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 <tt>format</tt>'s parameters. + * @return the new <tt>PayloadTypePacketExtension</tt> which contains + * <tt>format</tt>'s parameters. */ public static PayloadTypePacketExtension formatToPayloadType( - MediaFormat format, - DynamicPayloadTypeRegistry ptRegistry) + MediaFormat format, + DynamicPayloadTypeRegistry ptRegistry) { PayloadTypePacketExtension ptExt = new PayloadTypePacketExtension(); @@ -555,7 +584,10 @@ public class JingleUtils ptExt.setClockrate((int)format.getClockRate()); - /* add parameters */ + /* + * Add the format parameters and the advanced attributes (as parameter + * packet extensions). + */ for(Map.Entry<String, String> entry : format.getFormatParameters().entrySet()) { @@ -564,7 +596,6 @@ public class JingleUtils ext.setValue(entry.getValue()); ptExt.addParameter(ext); } - for(Map.Entry<String, String> entry : format.getAdvancedAttributes().entrySet()) { |