use of javax.sip.SipException in project XobotOS by xamarin.
the class SipHelper method sendInvite.
public ClientTransaction sendInvite(SipProfile caller, SipProfile callee, String sessionDescription, String tag, ReferredByHeader referredBy, String replaces) throws SipException {
try {
Request request = createRequest(Request.INVITE, caller, callee, tag);
if (referredBy != null)
request.addHeader(referredBy);
if (replaces != null) {
request.addHeader(mHeaderFactory.createHeader(ReplacesHeader.NAME, replaces));
}
request.setContent(sessionDescription, mHeaderFactory.createContentTypeHeader("application", "sdp"));
ClientTransaction clientTransaction = mSipProvider.getNewClientTransaction(request);
if (DEBUG)
Log.d(TAG, "send INVITE: " + request);
clientTransaction.sendRequest();
return clientTransaction;
} catch (ParseException e) {
throw new SipException("sendInvite()", e);
}
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SipService method onConnectivityChanged.
private synchronized void onConnectivityChanged(NetworkInfo info) {
// respect it. Otherwise get a new one from getActiveNetworkInfo().
if (info == null || info.isConnected() || !info.getTypeName().equals(mNetworkType)) {
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
info = cm.getActiveNetworkInfo();
}
// Some devices limit SIP on Wi-Fi. In this case, if we are not on
// Wi-Fi, treat it as a DISCONNECTED event.
boolean connected = (info != null && info.isConnected() && (!mSipOnWifiOnly || info.getType() == ConnectivityManager.TYPE_WIFI));
String networkType = connected ? info.getTypeName() : "null";
// Ignore the event if the current active network is not changed.
if (connected == mConnected && networkType.equals(mNetworkType)) {
return;
}
if (DEBUG) {
Log.d(TAG, "onConnectivityChanged(): " + mNetworkType + " -> " + networkType);
}
try {
if (mConnected) {
mLocalIp = null;
stopPortMappingMeasurement();
for (SipSessionGroupExt group : mSipGroups.values()) {
group.onConnectivityChanged(false);
}
}
mConnected = connected;
mNetworkType = networkType;
if (connected) {
mLocalIp = determineLocalIp();
mKeepAliveInterval = -1;
mLastGoodKeepAliveInterval = DEFAULT_KEEPALIVE_INTERVAL;
for (SipSessionGroupExt group : mSipGroups.values()) {
group.onConnectivityChanged(true);
}
// If we are on Wi-Fi, grab the WifiLock. Otherwise release it.
if (info.getType() == ConnectivityManager.TYPE_WIFI) {
mWifiLock.acquire();
} else {
mWifiLock.release();
}
} else {
// Always grab the WifiLock when we are disconnected, so the
// system will keep trying to reconnect. We will release it
// if we eventually connect via something else.
mWifiLock.acquire();
// in case there's a leak
mMyWakeLock.reset();
}
} catch (SipException e) {
Log.e(TAG, "onConnectivityChanged()", e);
}
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SipService method createGroup.
private SipSessionGroupExt createGroup(SipProfile localProfile) throws SipException {
String key = localProfile.getUriString();
SipSessionGroupExt group = mSipGroups.get(key);
if (group == null) {
group = new SipSessionGroupExt(localProfile, null, null);
mSipGroups.put(key, group);
notifyProfileAdded(localProfile);
} else if (!isCallerCreator(group)) {
throw new SipException("only creator can access the profile");
}
return group;
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SipProviderImpl method getNewClientTransaction.
/*
* (non-Javadoc)
*
* @see javax.sip.SipProvider#getNewClientTransaction(javax.sip.message.Request)
*/
public ClientTransaction getNewClientTransaction(Request request) throws TransactionUnavailableException {
if (request == null)
throw new NullPointerException("null request");
if (!sipStack.isAlive())
throw new TransactionUnavailableException("Stack is stopped");
SIPRequest sipRequest = (SIPRequest) request;
if (sipRequest.getTransaction() != null)
throw new TransactionUnavailableException("Transaction already assigned to request");
if (sipRequest.getMethod().equals(Request.ACK)) {
throw new TransactionUnavailableException("Cannot create client transaction for " + Request.ACK);
}
// sloppy
if (sipRequest.getTopmostVia() == null) {
ListeningPointImpl lp = (ListeningPointImpl) this.getListeningPoint("udp");
Via via = lp.getViaHeader();
request.setHeader(via);
}
// Give the request a quick check to see if all headers are assigned.
try {
sipRequest.checkHeaders();
} catch (ParseException ex) {
throw new TransactionUnavailableException(ex.getMessage(), ex);
}
/*
* User decided to give us his own via header branch. Lets see if it
* results in a clash. If so reject the request.
*/
if (sipRequest.getTopmostVia().getBranch() != null && sipRequest.getTopmostVia().getBranch().startsWith(SIPConstants.BRANCH_MAGIC_COOKIE) && sipStack.findTransaction((SIPRequest) request, false) != null) {
throw new TransactionUnavailableException("Transaction already exists!");
}
if (request.getMethod().equalsIgnoreCase(Request.CANCEL)) {
SIPClientTransaction ct = (SIPClientTransaction) sipStack.findCancelTransaction((SIPRequest) request, false);
if (ct != null) {
ClientTransaction retval = sipStack.createClientTransaction((SIPRequest) request, ct.getMessageChannel());
((SIPTransaction) retval).addEventListener(this);
sipStack.addTransaction((SIPClientTransaction) retval);
if (ct.getDialog() != null) {
((SIPClientTransaction) retval).setDialog((SIPDialog) ct.getDialog(), sipRequest.getDialogId(false));
}
return retval;
}
}
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("could not find existing transaction for " + ((SIPRequest) request).getFirstLine() + " creating a new one ");
// Could not find a dialog or the route is not set in dialog.
Hop hop = null;
try {
hop = sipStack.getNextHop((SIPRequest) request);
if (hop == null)
throw new TransactionUnavailableException("Cannot resolve next hop -- transaction unavailable");
} catch (SipException ex) {
throw new TransactionUnavailableException("Cannot resolve next hop -- transaction unavailable", ex);
}
String transport = hop.getTransport();
ListeningPointImpl listeningPoint = (ListeningPointImpl) this.getListeningPoint(transport);
String dialogId = sipRequest.getDialogId(false);
SIPDialog dialog = sipStack.getDialog(dialogId);
if (dialog != null && dialog.getState() == DialogState.TERMINATED) {
// throw new TransactionUnavailableException
// ("Found a terminated dialog -- possible re-use of old tag
// parameters");
sipStack.removeDialog(dialog);
}
try {
// Set the brannch id before you ask for a tx.
// If the user has set his own branch Id and the
// branch id starts with a valid prefix, then take it.
// otherwise, generate one. If branch ID checking has
// been requested, set the branch ID.
String branchId = null;
if (sipRequest.getTopmostVia().getBranch() == null || !sipRequest.getTopmostVia().getBranch().startsWith(SIPConstants.BRANCH_MAGIC_COOKIE) || sipStack.checkBranchId()) {
branchId = Utils.getInstance().generateBranchId();
sipRequest.getTopmostVia().setBranch(branchId);
}
Via topmostVia = sipRequest.getTopmostVia();
//set port and transport if user hasn't already done this.
if (topmostVia.getTransport() == null)
topmostVia.setTransport(transport);
if (topmostVia.getPort() == -1)
topmostVia.setPort(listeningPoint.getPort());
branchId = sipRequest.getTopmostVia().getBranch();
SIPClientTransaction ct = (SIPClientTransaction) sipStack.createMessageChannel(sipRequest, listeningPoint.getMessageProcessor(), hop);
if (ct == null)
throw new TransactionUnavailableException("Cound not create tx");
ct.setNextHop(hop);
ct.setOriginalRequest(sipRequest);
ct.setBranch(branchId);
// if the stack supports dialogs then
if (sipStack.isDialogCreated(request.getMethod())) {
// (but noticed by Brad Templeton)
if (dialog != null)
ct.setDialog(dialog, sipRequest.getDialogId(false));
else if (this.isAutomaticDialogSupportEnabled()) {
SIPDialog sipDialog = sipStack.createDialog(ct);
ct.setDialog(sipDialog, sipRequest.getDialogId(false));
}
} else {
if (dialog != null) {
ct.setDialog(dialog, sipRequest.getDialogId(false));
}
}
// The provider is the event listener for all transactions.
ct.addEventListener(this);
return (ClientTransaction) ct;
} catch (IOException ex) {
throw new TransactionUnavailableException("Could not resolve next hop or listening point unavailable! ", ex);
} catch (java.text.ParseException ex) {
InternalErrorHandler.handleException(ex);
throw new TransactionUnavailableException("Unexpected Exception FIXME! ", ex);
} catch (InvalidArgumentException ex) {
InternalErrorHandler.handleException(ex);
throw new TransactionUnavailableException("Unexpected Exception FIXME! ", ex);
}
}
use of javax.sip.SipException in project XobotOS by xamarin.
the class SipProviderImpl method sendResponse.
/*
* (non-Javadoc)
*
* @see javax.sip.SipProvider#sendResponse(javax.sip.message.Response)
*/
public void sendResponse(Response response) throws SipException {
if (!sipStack.isAlive())
throw new SipException("Stack is stopped");
SIPResponse sipResponse = (SIPResponse) response;
Via via = sipResponse.getTopmostVia();
if (via == null)
throw new SipException("No via header in response!");
SIPServerTransaction st = (SIPServerTransaction) sipStack.findTransaction((SIPMessage) response, true);
if (st != null && st.getState() != TransactionState.TERMINATED && this.isAutomaticDialogSupportEnabled()) {
throw new SipException("Transaction exists -- cannot send response statelessly");
}
String transport = via.getTransport();
// check to see if Via has "received paramaeter". If so
// set the host to the via parameter. Else set it to the
// Via host.
String host = via.getReceived();
if (host == null)
host = via.getHost();
// Symmetric nat support
int port = via.getRPort();
if (port == -1) {
port = via.getPort();
if (port == -1) {
if (transport.equalsIgnoreCase("TLS"))
port = 5061;
else
port = 5060;
}
}
// for correct management of IPv6 addresses.
if (host.indexOf(":") > 0)
if (host.indexOf("[") < 0)
host = "[" + host + "]";
Hop hop = sipStack.getAddressResolver().resolveAddress(new HopImpl(host, port, transport));
try {
ListeningPointImpl listeningPoint = (ListeningPointImpl) this.getListeningPoint(transport);
if (listeningPoint == null)
throw new SipException("whoopsa daisy! no listening point found for transport " + transport);
MessageChannel messageChannel = sipStack.createRawMessageChannel(this.getListeningPoint(hop.getTransport()).getIPAddress(), listeningPoint.port, hop);
messageChannel.sendMessage(sipResponse);
} catch (IOException ex) {
throw new SipException(ex.getMessage());
}
}
Aggregations