forked from mirrors/linphone-iphone
add jni interface for get proxy/registrar address
git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@73 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
This commit is contained in:
parent
7825117d58
commit
5648f98db5
12 changed files with 449 additions and 9 deletions
|
|
@ -111,7 +111,22 @@ int p2pproxy_accountmgt_deleteAccount(const char* user_name) {
|
|||
return (*p2pproxy_application_jnienv)->CallStaticIntMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, deleteAccountMethod, applicationArg);
|
||||
}
|
||||
|
||||
|
||||
int p2pproxy_resourcelocation_get_sip_proxyregistrar_uri(char* aStringArray, size_t aSize) {
|
||||
jmethodID getSipProxyRegistrarUriMethod;
|
||||
jstring lJStringResult;
|
||||
const jbyte* lString;
|
||||
jboolean lIsCopy;
|
||||
|
||||
getSipProxyRegistrarUriMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, "getSipProxyRegistrarUriMethod", "()[java/lang/String;");
|
||||
jstring lJStringResult = (*p2pproxy_application_jnienv)->CallStaticObjectMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, getSipProxyRegistrarUriMethod);
|
||||
if (lJStringResult == 0) {
|
||||
return P2PPROXY_ERROR_RESOURCELOCATOR_SERVER_NOT_FOUND;
|
||||
}
|
||||
lString = GetStringUTFChars(p2pproxy_application_jnienv, lJStringResult, &lIsCopy);
|
||||
strcpy(aStringArray,lString,aSize);
|
||||
ReleaseStringUTFChars(p2pproxy_application_jnienv, lJStringResult, lString);
|
||||
return P2PPROXY_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#ifndef P2PPROXY_LAUNCHER_H_
|
||||
#define P2PPROXY_LAUNCHER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef SWIG
|
||||
%module P2pProxylauncher
|
||||
%javaconst(1);
|
||||
|
|
@ -38,6 +39,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#define P2PPROXY_ERROR_APPLICATION_ALREADY_STARTED -3
|
||||
#define P2PPROXY_ERROR_ACCOUNTMGT_USER_ALREADY_EXIST -4
|
||||
#define P2PPROXY_ERROR_ACCOUNTMGT_BAD_SIP_URI -5
|
||||
#define P2PPROXY_ERROR_RESOURCELOCATOR_SERVER_NOT_FOUND -6
|
||||
|
||||
#ifndef SWIG
|
||||
/**
|
||||
|
|
@ -80,6 +82,17 @@ int p2pproxy_accountmgt_isValidAccount(const char* user_name);
|
|||
*/
|
||||
int p2pproxy_accountmgt_deleteAccount(const char* user_name);
|
||||
|
||||
/***************************/
|
||||
/***resource location******/
|
||||
/***************************/
|
||||
/**
|
||||
* access a proxy registrar sip addreess
|
||||
* @param buffer allocated by the user
|
||||
* @param size buffer size
|
||||
* @return status code P2PPROXY_NO_ERROR, P2PPROXY_ERROR_RESOURCELOCATOR_SERVER_NOT_FOUND
|
||||
*/
|
||||
int p2pproxy_resourcelocation_get_sip_proxyregistrar_uri(char* string_buffer,size_t size) ;
|
||||
|
||||
#endif /*SWIG*/
|
||||
|
||||
#endif /*P2PPROXY_LAUNCHER_H_*/
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
package org.linphone.p2pproxy.api;
|
||||
|
||||
|
||||
public interface P2pProxyManagement extends P2pProxyNetworkProbe,P2pProxyRtpRelayManagement {
|
||||
public interface P2pProxyManagement extends P2pProxyNetworkProbe,P2pProxyRtpRelayManagement,P2pProxySipProxyRegistrarManagement {
|
||||
|
||||
/**
|
||||
* test if according both to local peer capabilities and supeer peer election polity this peer should become a super peer
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
p2pproxy
|
||||
Copyright (C) 2007 Jehan Monnier ()
|
||||
|
||||
P2pProxyUserNotFoundException.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.api;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class P2pProxyNotReadyException extends P2pProxyException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public P2pProxyNotReadyException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param arg0
|
||||
* @param arg1
|
||||
*/
|
||||
public P2pProxyNotReadyException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param arg0
|
||||
*/
|
||||
public P2pProxyNotReadyException(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param arg0
|
||||
*/
|
||||
public P2pProxyNotReadyException(Throwable arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
p2pproxy Copyright (C) 2007 Jehan Monnier ()
|
||||
|
||||
P2pProxySipProxyRegistrarManagement.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.api;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public interface P2pProxySipProxyRegistrarManagement {
|
||||
/**
|
||||
*
|
||||
* @return the SIP uri of an available sip proxy registrar
|
||||
*/
|
||||
public String getSipProxyRegistrarUri() throws P2pProxyException ;
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@ import javax.security.cert.CertificateException;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.linphone.p2pproxy.api.P2pProxyException;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrarAdvertisement;
|
||||
import org.linphone.p2pproxy.core.sipproxy.superpeers.P2pUserRegistrationAdvertisement;
|
||||
|
||||
|
||||
|
|
@ -201,11 +202,11 @@ public class JxtaNetworkManager {
|
|||
|
||||
// The following step is required and only need to be done once,
|
||||
// without this step the AdvertisementFactory has no means of
|
||||
// associating an advertisement name space with the proper obect
|
||||
// associating an advertisement name space with the proper object
|
||||
// in this cast the AdvertisementTutorial
|
||||
AdvertisementFactory.registerAdvertisementInstance(P2pUserProfileAdvertisement.getAdvertisementType(),new P2pUserProfileAdvertisement.Instantiator());
|
||||
AdvertisementFactory.registerAdvertisementInstance(P2pUserRegistrationAdvertisement.getAdvertisementType(),new P2pUserRegistrationAdvertisement.Instantiator());
|
||||
|
||||
AdvertisementFactory.registerAdvertisementInstance(SipProxyRegistrarAdvertisement.getAdvertisementType(),new SipProxyRegistrarAdvertisement.Instantiator());
|
||||
|
||||
mRendezVousService = mNetworkPeerGroup.getRendezVousService();
|
||||
mLog.info("Node PeerID ["+mNetworkPeerGroup.getPeerID()+"]");
|
||||
|
|
@ -338,12 +339,13 @@ public class JxtaNetworkManager {
|
|||
mLog.info("Connected to rdv ["+lRdvPeerId+"]");
|
||||
lExit=true;
|
||||
} else {
|
||||
if (System.currentTimeMillis() - lStartTime > aTimeout) {
|
||||
return false;
|
||||
}
|
||||
mLog.info("waiting to rdv connection");
|
||||
Thread.sleep(500);
|
||||
}
|
||||
if (System.currentTimeMillis() - lStartTime > aTimeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import org.apache.log4j.Logger;
|
|||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.linphone.p2pproxy.api.P2pProxyException;
|
||||
import org.linphone.p2pproxy.api.P2pProxyManagement;
|
||||
import org.linphone.p2pproxy.api.P2pProxyNotReadyException;
|
||||
import org.linphone.p2pproxy.api.P2pProxyUserAlreadyExistException;
|
||||
import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayService;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar;
|
||||
|
|
@ -369,10 +370,20 @@ public static void staticLoadTraceConfigFile() throws P2pProxyException {
|
|||
}
|
||||
}
|
||||
|
||||
private static void isReady() throws P2pProxyNotReadyException {
|
||||
try {
|
||||
if (mJxtaNetworkManager!=null && mJxtaNetworkManager.isConnectedToRendezVous(0) == false) {
|
||||
throw new P2pProxyNotReadyException("not connected to any rdv");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new P2pProxyNotReadyException(e);
|
||||
}
|
||||
}
|
||||
/* p2pproxy.h implementation*/
|
||||
|
||||
public static int createAccount(String aUserName) {
|
||||
try {
|
||||
isReady();
|
||||
mP2pProxyAccountManagement.createAccount(aUserName);
|
||||
} catch (P2pProxyUserAlreadyExistException e) {
|
||||
return P2pProxylauncherConstants.P2PPROXY_ACCOUNTMGT_USER_EXIST;
|
||||
|
|
@ -383,6 +394,7 @@ public static int createAccount(String aUserName) {
|
|||
}
|
||||
public static int deleteAccount(String aUserName) {
|
||||
try {
|
||||
isReady();
|
||||
mP2pProxyAccountManagement.deleteAccount(aUserName);
|
||||
} catch (P2pProxyException e) {
|
||||
return P2pProxylauncherConstants.P2PPROXY_ERROR;
|
||||
|
|
@ -392,6 +404,7 @@ public static int deleteAccount(String aUserName) {
|
|||
}
|
||||
public static int isValidAccount(String aUserName){
|
||||
try {
|
||||
isReady();
|
||||
if (mP2pProxyAccountManagement.isValidAccount(aUserName)) {
|
||||
return P2pProxylauncherConstants.P2PPROXY_ACCOUNTMGT_USER_EXIST;
|
||||
} else {
|
||||
|
|
@ -401,4 +414,12 @@ public static int isValidAccount(String aUserName){
|
|||
return P2pProxylauncherConstants.P2PPROXY_ERROR;
|
||||
}
|
||||
}
|
||||
public static String getSipProxyRegistrarUri() {
|
||||
try {
|
||||
isReady();
|
||||
return mP2pProxyManagement.getSipProxyRegistrarUri();
|
||||
} catch (P2pProxyException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,9 +19,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
package org.linphone.p2pproxy.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -31,6 +33,7 @@ import org.linphone.p2pproxy.api.P2pProxyManagement;
|
|||
import org.linphone.p2pproxy.core.media.rtprelay.MediaType;
|
||||
import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayServiceClient;
|
||||
import org.linphone.p2pproxy.core.rdvautoconfig.PeerInfoServiceClient;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrarAdvertisement;
|
||||
|
||||
public abstract class P2pProxyManagementImpl implements ServiceProvider,P2pProxyManagement {
|
||||
protected final JxtaNetworkManager mJxtaNetworkManager;
|
||||
|
|
@ -74,6 +77,14 @@ public abstract class P2pProxyManagementImpl implements ServiceProvider,P2pProxy
|
|||
public Map<MediaType, InetSocketAddress> getAddresses() throws P2pProxyException {
|
||||
return mRtpRelayServiceClient.getAddresses();
|
||||
}
|
||||
public String getSipProxyRegistrarUri() throws P2pProxyException {
|
||||
try {
|
||||
SipProxyRegistrarAdvertisement lSipProxyRegistrarAdvertisement = (SipProxyRegistrarAdvertisement) (mJxtaNetworkManager.getAdvertisement(null, SipProxyRegistrarAdvertisement.NAME, true));
|
||||
return lSipProxyRegistrarAdvertisement.getAddress();
|
||||
}catch (Exception e) {
|
||||
throw new P2pProxyException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,10 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import net.jxta.document.Advertisement;
|
||||
import net.jxta.document.AdvertisementFactory;
|
||||
import net.jxta.endpoint.MessageElement;
|
||||
import net.jxta.endpoint.StringMessageElement;
|
||||
import net.jxta.id.IDFactory;
|
||||
import net.jxta.pipe.OutputPipe;
|
||||
import net.jxta.pipe.PipeMsgEvent;
|
||||
import net.jxta.pipe.PipeMsgListener;
|
||||
|
|
@ -51,6 +53,7 @@ import org.linphone.p2pproxy.core.P2pProxyAccountManagementMBean;
|
|||
import org.linphone.p2pproxy.core.P2pProxyAdvertisementNotFoundException;
|
||||
import org.linphone.p2pproxy.core.media.rtprelay.MediaType;
|
||||
import org.linphone.p2pproxy.core.media.rtprelay.SdpProcessorImpl;
|
||||
import org.linphone.p2pproxy.core.sipproxy.superpeers.P2pUserRegistrationAdvertisement;
|
||||
import org.linphone.p2pproxy.core.sipproxy.superpeers.SuperPeerProxy;
|
||||
import org.zoolu.sip.address.NameAddress;
|
||||
import org.zoolu.sip.address.SipURL;
|
||||
|
|
@ -86,6 +89,7 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM
|
|||
private final P2pProxyAccountManagementMBean mP2pProxyAccountManagement;
|
||||
private final Configurator mProperties;
|
||||
private final SuperPeerProxy mSuperPeerProxy;
|
||||
private final SipProxyRegistrarAdvertisement mProxyRegistrationAdvertisement;
|
||||
|
||||
//private long mNumberOfEstablishedCall;
|
||||
private long mNumberOfRefusedRegistration;
|
||||
|
|
@ -176,7 +180,7 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM
|
|||
|
||||
}
|
||||
|
||||
public SipProxyRegistrar(Configurator lProperties,JxtaNetworkManager aJxtaNetworkManager,P2pProxyAccountManagementMBean aP2pProxyAccountManagement,P2pProxyRtpRelayManagement aP2pProxyRtpRelayManagement) {
|
||||
public SipProxyRegistrar(Configurator lProperties,JxtaNetworkManager aJxtaNetworkManager,P2pProxyAccountManagementMBean aP2pProxyAccountManagement,P2pProxyRtpRelayManagement aP2pProxyRtpRelayManagement) throws IOException {
|
||||
mJxtaNetworkManager = aJxtaNetworkManager;
|
||||
mP2pProxyAccountManagement = aP2pProxyAccountManagement;
|
||||
mProperties = lProperties;
|
||||
|
|
@ -189,7 +193,11 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM
|
|||
mProvider.addSipProviderListener(SipProvider.PROMISQUE,this);
|
||||
mPool = Executors.newCachedThreadPool();
|
||||
mSuperPeerProxy = new SuperPeerProxy(aJxtaNetworkManager, "sip:"+mProvider.getViaAddress()+":"+mProvider.getPort(),mRegistrationTab);
|
||||
|
||||
mProxyRegistrationAdvertisement = (SipProxyRegistrarAdvertisement) AdvertisementFactory.newAdvertisement(SipProxyRegistrarAdvertisement.getAdvertisementType());
|
||||
mProxyRegistrationAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID(), mSuperPeerProxy.getSipProxyRegistrarAddress().toString().getBytes()));
|
||||
mProxyRegistrationAdvertisement.setAddress(mSuperPeerProxy.getSipProxyRegistrarAddress());
|
||||
mJxtaNetworkManager.getPeerGroup().getDiscoveryService().publish(mProxyRegistrationAdvertisement,60000,30000);
|
||||
mLog.info(mProxyRegistrationAdvertisement + "published");
|
||||
}
|
||||
public void onReceivedMessage(SipProvider aProvider, Message aMessage) {
|
||||
if (aProvider.getListeners().containsKey(aMessage.getTransactionId())) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,263 @@
|
|||
/*
|
||||
p2pproxy
|
||||
Copyright (C) 2007 Jehan Monnier ()
|
||||
|
||||
P2pUserRegistrationAdvertisement.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 java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
import net.jxta.document.Advertisement;
|
||||
import net.jxta.document.AdvertisementFactory;
|
||||
import net.jxta.document.Attributable;
|
||||
import net.jxta.document.Document;
|
||||
import net.jxta.document.Element;
|
||||
import net.jxta.document.ExtendableAdvertisement;
|
||||
import net.jxta.document.MimeMediaType;
|
||||
import net.jxta.document.StructuredDocument;
|
||||
import net.jxta.document.StructuredDocumentFactory;
|
||||
import net.jxta.document.TextElement;
|
||||
import net.jxta.id.ID;
|
||||
import net.jxta.id.IDFactory;
|
||||
|
||||
/**
|
||||
* derivated from jxta Advertisement tutorial
|
||||
* <pre>
|
||||
* <?xml version="1.0"?>
|
||||
* <!DOCTYPE jxta:System>
|
||||
* <jxta:System xmlns:jxta="http://jxta.org">
|
||||
* <id> </id>
|
||||
* <Name> </Name>
|
||||
* <address>address where a sip endpoint can join</registrar-address>
|
||||
* </jxta:System>
|
||||
* </pre>
|
||||
*/
|
||||
public class SipProxyRegistrarAdvertisement extends ExtendableAdvertisement implements Comparable, Cloneable, Serializable {
|
||||
/**
|
||||
* Instantiator
|
||||
*/
|
||||
public static class Instantiator implements AdvertisementFactory.Instantiator {
|
||||
|
||||
/**
|
||||
* Returns the identifying type of this Advertisement.
|
||||
*
|
||||
* @return String the type of advertisement
|
||||
*/
|
||||
public String getAdvertisementType() {
|
||||
return SipProxyRegistrarAdvertisement.getAdvertisementType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <CODE>Advertisement</CODE> matching the
|
||||
* type specified by the <CODE>advertisementType</CODE> parameter.
|
||||
*
|
||||
* @return The instance of <CODE>Advertisement</CODE> or null if it
|
||||
* could not be created.
|
||||
*/
|
||||
public Advertisement newInstance() {
|
||||
return new SipProxyRegistrarAdvertisement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <CODE>Advertisement</CODE> matching the
|
||||
* type specified by the <CODE>advertisementType</CODE> parameter.
|
||||
*
|
||||
* @param root Specifies a portion of a StructuredDocument which will
|
||||
* be converted into an Advertisement.
|
||||
* @return The instance of <CODE>Advertisement</CODE> or null if it
|
||||
* could not be created.
|
||||
*/
|
||||
public Advertisement newInstance(net.jxta.document.Element root) {
|
||||
return new SipProxyRegistrarAdvertisement(root);
|
||||
}
|
||||
}
|
||||
private ID mId ;;
|
||||
private String mAddress;
|
||||
public final static String ADDRESS_TAG = "address";
|
||||
private final static String ID_TAG = "ID";
|
||||
final static String NAME_TAG = "Name";
|
||||
public final static String NAME = "p2p-proxy-proxyregistrar";
|
||||
private final static String[] mIndexs = {NAME_TAG};
|
||||
private final static Logger mLog = Logger.getLogger(SipProxyRegistrarAdvertisement.class);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SipProxyRegistrarAdvertisement(Element root) {
|
||||
|
||||
TextElement doc = (TextElement) root;
|
||||
|
||||
if (!getAdvertisementType().equals(doc.getName())) {
|
||||
throw new IllegalArgumentException("Could not construct : " + getClass().getName() + "from doc containing a " + doc.getName());
|
||||
}
|
||||
initialize(doc);
|
||||
|
||||
}
|
||||
public SipProxyRegistrarAdvertisement() {
|
||||
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see net.jxta.document.ExtendableAdvertisement#getDocument(net.jxta.document.MimeMediaType)
|
||||
*/
|
||||
@Override
|
||||
public Document getDocument(MimeMediaType asMimeType) {
|
||||
|
||||
StructuredDocument adv = StructuredDocumentFactory.newStructuredDocument(asMimeType,
|
||||
getAdvertisementType());
|
||||
if (adv instanceof Attributable) {
|
||||
((Attributable) adv).addAttribute("xmlns:jxta", "http://jxta.org");
|
||||
}
|
||||
Element e;
|
||||
e = adv.createElement(ID_TAG, getID().toString());
|
||||
adv.appendChild(e);
|
||||
e = adv.createElement(NAME_TAG, getName().toString());
|
||||
adv.appendChild(e);
|
||||
e = adv.createElement(ADDRESS_TAG, getAddress().trim());
|
||||
adv.appendChild(e);
|
||||
return adv;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
@Override
|
||||
public ID getID() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getIndexFields() {
|
||||
return mIndexs;
|
||||
}
|
||||
public static String getAdvertisementType() {
|
||||
return "jxta:" +NAME;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see net.jxta.document.Advertisement#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO Auto-generated method stub
|
||||
return super.toString();
|
||||
}
|
||||
public int compareTo(Object other) {
|
||||
return getID().toString().compareTo(other.toString());
|
||||
}
|
||||
/**
|
||||
* Intialize a System advertisement from a portion of a structured document.
|
||||
*
|
||||
* @param root document root
|
||||
*/
|
||||
protected void initialize(Element root) {
|
||||
if (!TextElement.class.isInstance(root)) {
|
||||
throw new IllegalArgumentException(getClass().getName() +
|
||||
" only supports TextElement");
|
||||
}
|
||||
TextElement doc = (TextElement) root;
|
||||
if (!doc.getName().equals(getAdvertisementType())) {
|
||||
throw new IllegalArgumentException("Could not construct : "
|
||||
+ getClass().getName() + "from doc containing a " +
|
||||
doc.getName());
|
||||
}
|
||||
Enumeration elements = doc.getChildren();
|
||||
while (elements.hasMoreElements()) {
|
||||
TextElement elem = (TextElement) elements.nextElement();
|
||||
if (!handleElement(elem)) {
|
||||
mLog.warn("Unhandleded element \'" + elem.getName() + "\' in " + doc.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Process an individual element from the document.
|
||||
*
|
||||
* @param elem the element to be processed.
|
||||
* @return true if the element was recognized, otherwise false.
|
||||
*/
|
||||
protected boolean handleElement(TextElement elem) {
|
||||
if (elem.getName().equals(ID_TAG)) {
|
||||
try {
|
||||
URI id = new URI(elem.getTextValue());
|
||||
setID(IDFactory.fromURI(id));
|
||||
} catch (URISyntaxException badID) {
|
||||
throw new IllegalArgumentException("unknown ID format in advertisement: " +
|
||||
elem.getTextValue());
|
||||
}
|
||||
catch (ClassCastException badID) {
|
||||
throw new IllegalArgumentException("Id is not a known id type: " +
|
||||
elem.getTextValue());
|
||||
}
|
||||
return true;
|
||||
} else if (elem.getName().equals(ADDRESS_TAG)) {
|
||||
setAddress(elem.getTextValue());
|
||||
return true;
|
||||
} else if (elem.getName().equals(NAME_TAG)) {
|
||||
//nop, name is static
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void setID(ID id) {
|
||||
mId = id;
|
||||
}
|
||||
@Override
|
||||
public String getBaseAdvType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @return Returns the address as a sip uri.
|
||||
*/
|
||||
public String getAddress() {
|
||||
return mAddress;
|
||||
}
|
||||
/**
|
||||
* @param name The mName to set.
|
||||
*/
|
||||
public void setAddress(String anAddress) {
|
||||
mAddress = anAddress;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof SipProxyRegistrarAdvertisement) {
|
||||
SipProxyRegistrarAdvertisement adv = (SipProxyRegistrarAdvertisement) obj;
|
||||
return getID().equals(adv.getID());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -109,4 +109,7 @@ public class SuperPeerProxy implements SipProxy, RegistrationHandler {
|
|||
|
||||
((JxtaNetworkResources) aRegistration.NetResources).publish(aRegistration.Expiration);
|
||||
}
|
||||
public String getSipProxyRegistrarAddress() {
|
||||
return mRegistrarAddress;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
package org.linphone.p2pproxy.test;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
|
||||
import net.jxta.discovery.DiscoveryEvent;
|
||||
import net.jxta.discovery.DiscoveryListener;
|
||||
import net.jxta.discovery.DiscoveryService;
|
||||
import net.jxta.document.Advertisement;
|
||||
import net.jxta.protocol.DiscoveryResponseMsg;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.linphone.p2pproxy.api.P2pProxyInstance;
|
||||
|
|
@ -33,6 +41,7 @@ import org.linphone.p2pproxy.core.P2pProxyAccountManagement;
|
|||
import org.linphone.p2pproxy.core.P2pProxyAccountManagementMBean;
|
||||
import org.linphone.p2pproxy.core.P2pProxyInstanceImpl;
|
||||
import org.linphone.p2pproxy.core.P2pProxyMain;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrarAdvertisement;
|
||||
import org.linphone.p2pproxy.test.utils.DefaultCallListener;
|
||||
import org.linphone.p2pproxy.test.utils.SipClient;
|
||||
import org.zoolu.sip.address.NameAddress;
|
||||
|
|
@ -97,6 +106,16 @@ public class P2pProxyTester extends TestCase {
|
|||
protected void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void testGetRegistrarAdress() {
|
||||
try {
|
||||
SipProxyRegistrarAdvertisement lSipProxyRegistrarAdvertisement = (SipProxyRegistrarAdvertisement) (((JxtaNetworkManager)mP2pProxyInstance.getOpaqueNetworkManager()).getAdvertisement(null, SipProxyRegistrarAdvertisement.NAME, true));
|
||||
mLog.info("testGetRegistrarAdress ok ["+lSipProxyRegistrarAdvertisement.getAddress()+"]");
|
||||
} catch (Exception e) {
|
||||
mLog.error("testGetRegistrarAdress ko",e);
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
public void testSipRegisterUnregister() {
|
||||
try {
|
||||
//register
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue