📄 sipmanager.java
字号:
contactHeader = null;
fromHeader = null;
viaHeaders = null;
maxForwardsHeader = null;
isStarted = true;
}
finally
{
console.logExit();
}
}
/**
* Unregisters listening points, deletes sip providers, and generally
* prepares the stack for a re-start(). This method is meant to be used
* when properties are changed and should be reread by the stack.
* @throws CommunicationsException
*/
public void stop() throws CommunicationsException
{
try
{
console.logEntry();
//Delete SipProvider
int tries = 0;
for (tries = 0; tries < RETRY_OBJECT_DELETES; tries++)
{
try
{
sipStack.deleteSipProvider(sipProvider);
}
catch (ObjectInUseException ex)
{
// System.err.println("Retrying delete of riSipProvider!");
sleep(RETRY_OBJECT_DELETES_AFTER);
continue;
}
break;
}
if (tries >= RETRY_OBJECT_DELETES)
throw new CommunicationsException("Failed to delete the sipProvider!");
//Delete RI ListeningPoint
for (tries = 0; tries < RETRY_OBJECT_DELETES; tries++)
{
try
{
sipStack.deleteListeningPoint(listeningPoint);
}
catch (ObjectInUseException ex)
{
//System.err.println("Retrying delete of riListeningPoint!");
sleep(RETRY_OBJECT_DELETES_AFTER);
continue;
}
break;
}
if (tries >= RETRY_OBJECT_DELETES)
throw new CommunicationsException("Failed to delete a listeningPoint!");
sipProvider = null;
listeningPoint = null;
addressFactory = null;
messageFactory = null;
headerFactory = null;
sipStack = null;
viaHeaders = null;
contactHeader = null;
fromHeader = null;
}finally
{
console.logExit();
}
}
/**
* Waits during _no_less_ than sleepFor milliseconds.
* Had to implement it on top of Thread.sleep() to guarantee minimum
* sleep time.
*
* @param sleepFor the number of miliseconds to wait
*/
protected static void sleep(long sleepFor)
{
try
{
console.logEntry();
long startTime = System.currentTimeMillis();
long haveBeenSleeping = 0;
while (haveBeenSleeping < sleepFor)
{
try
{
Thread.sleep(sleepFor - haveBeenSleeping);
}
catch (InterruptedException ex)
{
//we-ll have to wait again!
}
haveBeenSleeping = (System.currentTimeMillis() - startTime);
}
}finally
{
console.logExit();
}
}
public void setCurrentlyUsedURI(String uri)
{
this.currentlyUsedURI = uri;
}
/**
* Causes the RegisterProcessing object to send a registration request
* to the registrar defined in
* net.java.sip.communicator.sip.REGISTRAR_ADDRESS and to register with
* the address defined in the net.java.sip.communicator.sip.PUBLIC_ADDRESS
* property
*
* @throws CommunicationsException if an exception is thrown by the
* underlying stack. The exception that caused this CommunicationsException
* may be extracted with CommunicationsException.getCause()
*/
public void register() throws CommunicationsException
{
register(currentlyUsedURI);
}
/**
* Registers using the specified public address. If public add
* @param publicAddress
* @throws CommunicationsException
*/
public void register(String publicAddress) throws CommunicationsException
{
try
{
console.logEntry();
if(publicAddress == null || publicAddress.trim().length() == 0)
return; //maybe throw an exception?
//Handle default domain name (i.e. transform 1234 -> 1234@sip.com
String defaultDomainName =
Utils.getProperty("net.java.sip.communicator.sip.DEFAULT_DOMAIN_NAME");
//feature request, Michael Robertson (sipphone.com)
//strip the following chars of their user names: ( - ) <space>
if(publicAddress.toLowerCase().indexOf("sipphone.com") != -1
|| defaultDomainName.indexOf("sipphone.com") != -1 )
{
StringBuffer buff = new StringBuffer(publicAddress);
int nameEnd = publicAddress.indexOf('@');
nameEnd = nameEnd==-1?Integer.MAX_VALUE:nameEnd;
nameEnd = Math.min(nameEnd, buff.length())-1;
int nameStart = publicAddress.indexOf("sip:");
nameStart = nameStart == -1 ? 0 : nameStart + "sip:".length();
for(int i = nameEnd; i >= nameStart; i--)
if(!Character.isLetter( buff.charAt(i) )
&& !Character.isDigit( buff.charAt(i)))
buff.deleteCharAt(i);
publicAddress = buff.toString();
}
// if user didn't provide a domain name in the URL and someone
// has defined the DEFAULT_DOMAIN_NAME property - let's fill in the blank.
if (defaultDomainName != null
&& publicAddress.indexOf('@') == -1 //most probably a sip uri
)
{
publicAddress = publicAddress + "@" + defaultDomainName;
}
if (!publicAddress.trim().toLowerCase().startsWith("sip:"))
{
publicAddress = "sip:" + publicAddress;
}
this.currentlyUsedURI = publicAddress;
registerProcessing.register( registrarAddress, registrarPort,
registrarTransport, registrationsExpiration);
//at this point we are sure we have a sip: prefix in the uri
// we construct our pres: uri by replacing that prefix.
String presenceUri = "pres"
+ publicAddress.substring(publicAddress.indexOf(':'));
}
finally
{
console.logExit();
}
}
public void startRegisterProcess() throws CommunicationsException
{
try
{
console.logEntry();
checkIfStarted();
//Obtain initial credentials
UserCredentials defaultCredentials = new UserCredentials();
//avoid nullpointer exceptions
String uName = Utils.getProperty(
"net.java.sip.communicator.sip.USER_NAME");
defaultCredentials.setUserName(uName == null? "" : uName);
defaultCredentials.setPassword(new char[0]);
String realm = Utils.getProperty(
"net.java.sip.communicator.sip.DEFAULT_AUTHENTICATION_REALM");
realm = realm == null ? "" : realm;
UserCredentials initialCredentials = securityAuthority.obtainCredentials(realm,
defaultCredentials);
register(initialCredentials.getUserName());
//at this point a simple register request has been sent and the global
//from header in SipManager has been set to a valid value by the RegisterProcesing
//class. Use it to extract the valid user name that needs to be cached by
//the security manager together with the user provider password.
initialCredentials.setUserName(((SipURI)getFromHeader().getAddress().getURI()).getUser());
cacheCredentials(realm, initialCredentials);
}
finally
{
console.logExit();
}
}
/**
* Causes the RegisterProcessing object to send a registration request with
* a 0 "expires" interval to the registrar defined in
* net.java.sip.communicator.sip.REGISTRAR_ADDRESS.
*
* @throws CommunicationsException if an exception is thrown by the
* underlying stack. The exception that caused this CommunicationsException
* may be extracted with CommunicationsException.getCause()
*/
public void unregister() throws CommunicationsException
{
try
{
console.logEntry();
if (!isRegistered())
{
return;
}
checkIfStarted();
registerProcessing.unregister();
}
finally
{
console.logExit();
}
}
/**
* Queries the RegisterProcessing object whether the application is registered
* with a registrar.
* @return true if the application is registered with a registrar.
*/
public boolean isRegistered()
{
return (registerProcessing != null && registerProcessing.isRegistered());
}
/**
* Determines whether the SipManager was start()ed.
* @return true if the SipManager was start()ed.
*/
public boolean isStarted()
{
return isStarted;
}
//============================ COMMUNICATION FUNCTIONALITIES =========================
/**
* Causes the CallProcessing object to send an INVITE request to the
* URI specified by <code>callee</code>
* setting sdpContent as message body. The method generates a Call object
* that will represent the resulting call and will be used for later
* references to the same call.
*
* @param callee the URI to send the INVITE to.
* @param sdpContent the sdp session offer.
* @return the Call object that will represent the call resulting
* from invoking this method.
* @throws CommunicationsException if an exception occurs while sending and
* parsing.
*/
public Call establishCall(String callee, String sdpContent) throws
CommunicationsException
{
try
{
console.logEntry();
checkIfStarted();
return callProcessing.invite(callee, sdpContent);
}
finally
{
console.logExit();
}
} //CALL
//------------------ hang up on
/**
* Causes the CallProcessing object to send a terminating request (CANCEL,
* BUSY_HERE or BYE) and thus terminate that call with id <code>callID</code>.
* @param callID the id of the call to terminate.
* @throws CommunicationsException if an exception occurs while invoking this
* method.
*/
public void endCall(int callID) throws CommunicationsException
{
try
{
console.logEntry();
checkIfStarted();
callProcessing.endCall(callID);
}
finally
{
console.logExit();
}
}
/**
* Calls endCall for all currently active calls.
* @throws CommunicationsException if an exception occurs while
*/
public void endAllCalls() throws CommunicationsException
{
try
{
console.logEntry();
if (callProcessing == null)
{
return;
}
Object[] keys = callProcessing.getCallDispatcher().getAllCalls();
for (int i = 0; i < keys.length; i++)
{
endCall( ( (Integer) keys[i]).intValue());
}
}
finally
{
console.logExit();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -