From adfc060fce214a5e6826e1995ed72698e5efb54b Mon Sep 17 00:00:00 2001 From: jehan Date: Wed, 17 Sep 2008 09:39:48 +0000 Subject: [PATCH] extract legacy proxy to package sipproxy git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@21 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- .../p2pproxy/core/MessageDispatcher.java | 2 +- .../media/jxtaudpproxy/SdpProcessorImpl.java | 10 +++---- .../p2pproxy/core/sipproxy/JxtaSipProxy.java | 19 +++++++++++- .../core/{ => sipproxy}/NetworkResources.java | 4 ++- .../core/sipproxy/RegistrationHandler.java | 29 +++++++++++++++++++ .../core/sipproxy/SipProxyRegistrar.java | 14 +++------ 6 files changed, 60 insertions(+), 18 deletions(-) rename p2pproxy/src/org/linphone/p2pproxy/core/{ => sipproxy}/NetworkResources.java (95%) create mode 100644 p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/RegistrationHandler.java diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/MessageDispatcher.java b/p2pproxy/src/org/linphone/p2pproxy/core/MessageDispatcher.java index da02655d7..21f400244 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/MessageDispatcher.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/MessageDispatcher.java @@ -46,7 +46,7 @@ public class MessageDispatcher implements PipeMsgListener { } } } - synchronized void addPipeMsgListener(PipeMsgListener aPipeMsgListener) { + public synchronized void addPipeMsgListener(PipeMsgListener aPipeMsgListener) { mPipeMsgListenerList.add(aPipeMsgListener); } diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/media/jxtaudpproxy/SdpProcessorImpl.java b/p2pproxy/src/org/linphone/p2pproxy/core/media/jxtaudpproxy/SdpProcessorImpl.java index 19005ccfa..fef3712ed 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/media/jxtaudpproxy/SdpProcessorImpl.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/media/jxtaudpproxy/SdpProcessorImpl.java @@ -30,7 +30,7 @@ import org.apache.log4j.Logger; import org.linphone.p2pproxy.api.P2pProxyException; import org.linphone.p2pproxy.core.Configurator; -import org.linphone.p2pproxy.core.NetworkResources; +import org.linphone.p2pproxy.core.sipproxy.NetworkResources; import org.linphone.p2pproxy.core.sipproxy.SdpProcessor; import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar; import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar.Registration; @@ -164,20 +164,20 @@ public class SdpProcessorImpl implements SdpProcessor { String lMLineName = lMediaDescriptor.getMedia().getMedia(); RtpSessionImpl lRtpSession = null; - if (lRegistration.NetResources.hasRtpSession(lMLineName) == false) { + if (((NetworkResources) lRegistration.NetResources).hasRtpSession(lMLineName) == false) { // first time, just create int lPortStart = Integer.parseInt(mProperties.getProperty(SipProxyRegistrar.UDP_MEDIA_RELAY_PORT_START, "15000")); lRtpSession = new RtpSessionImpl (lPortStart,lMLineName); - lRegistration.NetResources.putRtpSession(lMLineName, lRtpSession); + ((NetworkResources) lRegistration.NetResources).putRtpSession(lMLineName, lRtpSession); } else { - lRtpSession = lRegistration.NetResources.getRtpSession(lMLineName); + lRtpSession = ((NetworkResources) lRegistration.NetResources).getRtpSession(lMLineName); } if (aRemotePipe != null) { lRtpSession.setRemotePipe(aRemotePipe); } } - return lRegistration.NetResources; + return (NetworkResources) lRegistration.NetResources; }catch (Exception e) { throw new P2pProxyException(e); } diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/JxtaSipProxy.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/JxtaSipProxy.java index 1604b69dd..695e767c8 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/JxtaSipProxy.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/JxtaSipProxy.java @@ -22,6 +22,7 @@ package org.linphone.p2pproxy.core.sipproxy; import java.io.IOException; import java.util.Map; +import net.jxta.discovery.DiscoveryService; import net.jxta.document.Advertisement; import net.jxta.endpoint.MessageElement; import net.jxta.endpoint.StringMessageElement; @@ -37,6 +38,7 @@ import org.linphone.p2pproxy.api.P2pProxyUserNotFoundException; import org.linphone.p2pproxy.core.JxtaNetworkManager; import org.linphone.p2pproxy.core.P2pProxyAdvertisementNotFoundException; import org.linphone.p2pproxy.core.media.rtprelay.SdpProcessorImpl; +import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar.Registration; import org.zoolu.sip.address.NameAddress; import org.zoolu.sip.address.SipURL; import org.zoolu.sip.header.MultipleHeader; @@ -46,7 +48,7 @@ import org.zoolu.sip.message.MessageFactory; import org.zoolu.sip.provider.SipProvider; import org.zoolu.sip.transaction.TransactionServer; -public class JxtaSipProxy implements SipProxy, PipeMsgListener { +public class JxtaSipProxy implements SipProxy, PipeMsgListener,RegistrationHandler { private final JxtaNetworkManager mJxtaNetworkManager; private final Map mRegistrationTab; private final SdpProcessor mSdpProcessor; @@ -211,5 +213,20 @@ public class JxtaSipProxy implements SipProxy, PipeMsgListener { mProvider.sendMessage(lSipMessage); // } +public void updateRegistration(Registration aRegistration, Message aRegistrationMessage) throws P2pProxyException { + try { + if (aRegistration.NetResources == null) { + // new registration, create pipe + NetworkResources lRegistration = new NetworkResources(aRegistration.From,mJxtaNetworkManager); + aRegistration.NetResources = lRegistration; + lRegistration.addPipeMsgListener(this); + } + + ((NetworkResources) aRegistration.NetResources).publish(aRegistration.Expiration); + } catch (Exception e) { + throw new P2pProxyException(e); + } + +} } diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/NetworkResources.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/NetworkResources.java similarity index 95% rename from p2pproxy/src/org/linphone/p2pproxy/core/NetworkResources.java rename to p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/NetworkResources.java index 3d1442a44..d7cfb88c2 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/NetworkResources.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/NetworkResources.java @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -package org.linphone.p2pproxy.core; +package org.linphone.p2pproxy.core.sipproxy; import java.io.IOException; @@ -26,6 +26,8 @@ import java.util.Map; import org.apache.log4j.Logger; +import org.linphone.p2pproxy.core.JxtaNetworkManager; +import org.linphone.p2pproxy.core.MessageDispatcher; import org.linphone.p2pproxy.core.media.jxtaudpproxy.RtpSessionImpl; import net.jxta.discovery.DiscoveryService; diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/RegistrationHandler.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/RegistrationHandler.java new file mode 100644 index 000000000..9a86b8a95 --- /dev/null +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/RegistrationHandler.java @@ -0,0 +1,29 @@ +/* +p2pproxy Copyright (C) 2007 Jehan Monnier () + +RegistrationHandler.java - . + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +package org.linphone.p2pproxy.core.sipproxy; + + +import org.linphone.p2pproxy.api.P2pProxyException; +import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar.Registration; +import org.zoolu.sip.message.Message; + +public interface RegistrationHandler { + public void updateRegistration(Registration aRegistration, Message aRegistrationMessage) throws P2pProxyException; +} diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java index 03d8ef628..bcf02bdd4 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java @@ -46,7 +46,6 @@ import org.linphone.p2pproxy.api.P2pProxyUserNotFoundException; import org.linphone.p2pproxy.core.Configurator; import org.linphone.p2pproxy.core.JxtaNetworkManager; -import org.linphone.p2pproxy.core.NetworkResources; import org.linphone.p2pproxy.core.P2pProxyAccountManagementMBean; import org.linphone.p2pproxy.core.P2pProxyAdvertisementNotFoundException; import org.linphone.p2pproxy.core.media.rtprelay.MediaType; @@ -93,7 +92,8 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM public static class Registration { long RegistrationDate; long Expiration; - public NetworkResources NetResources; + //implementation specific context + public Object NetResources; public Map RtpRelays = new HashMap() ; String Contact; final String From; @@ -274,19 +274,13 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM } private void updateRegistration(Registration aRegistration, Message aRegistrationMessage) throws IOException { aRegistration.RegistrationDate = System.currentTimeMillis(); - // default registration periode + // default registration period aRegistration.Expiration = 3600000; if (aRegistrationMessage.getExpiresHeader() != null ) { aRegistration.Expiration = aRegistrationMessage.getExpiresHeader().getDeltaSeconds()*1000; } - if (aRegistration.NetResources == null) { - // new registration, create pipe - aRegistration.NetResources = new NetworkResources(aRegistration.From,mJxtaNetworkManager); - aRegistration.NetResources.addPipeMsgListener(this); - } - - aRegistration.NetResources.publish(aRegistration.Expiration); + //TODO handle registration }