Skip to content

Commit

Permalink
allow reproxy of request on cancelled branch
Browse files Browse the repository at this point in the history
  • Loading branch information
TiborBeres committed Nov 22, 2024
1 parent 06d4e61 commit d65cd7a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1195,28 +1195,43 @@ private ProxyBranchImpl createBranch(javax.servlet.sip.URI nextHop,
if(!("sip".equals(nextHop.getScheme()) || "sips".equals(nextHop.getScheme()))){
throw new IllegalArgumentException ("Unsupported Scheme");
}
}
ProxyBranchImpl curBranch = ThreadLocalStorage.getCurrentBranch();
if((curBranch != null) && curBranch.isCancelled()){
throw new IllegalStateException("Cannot create Branches on a canceled proxy branch during doBranchResponse");
}


//if this is a virtual branch we need special treatment
if (isVirtual) {

if (proxy.isVirtualBranchExists()) {
//if the virtual branch exists already, we should throw IllegalStateException
throw new IllegalStateException("Virtual Branch Already exists");
}
}else {
//check that no branch was created for this destination
//this check is relevant only for regular branches

//check that no branch was created for this destination
//this check is relevant only for regular branches
if (proxyBranchExists(nextHop)) {
throw new IllegalStateException("Duplicate Branch - Attempt to proxy message to the same URI again: " + nextHop);
}
}
}

if (PropertiesStore.getInstance().getProperties().getBoolean(CoreProperties.CHECK_STATE_WHEN_CREATING_PROXY_BRANCH)){

ProxyBranchImpl curBranch = ThreadLocalStorage.getCurrentBranch();

if((curBranch != null) && curBranch.isCancelled()){
throw new IllegalStateException("Cannot create Branches on a canceled proxy branch during doBranchResponse");
}

//if this is a virtual branch we need special treatment
if (isVirtual) {

if (proxy.isVirtualBranchExists()) {
//if the virtual branch exists already, we should throw IllegalStateException
throw new IllegalStateException("Virtual Branch Already exists");

}
}
}

if(!PropertiesStore.getInstance().getProperties().getBoolean(CoreProperties.CHECK_STATE_WHEN_CREATING_PROXY_BRANCH)){
if (isVirtual) {
//if the virtual branch exists already, return it
if (proxy.isVirtualBranchExists()) {

return proxy.getVirtualBranch();

}
}
}
// Create a new branch and send the request
ProxyBranchImpl branch =
new ProxyBranchImpl(nextHop, this, proxy, createdViaProxyTo,isVirtual);
Expand Down Expand Up @@ -2015,3 +2030,4 @@ public OutboundInterface getOutboundInterface(InetSocketAddress address) {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ public class CoreProperties
*/
private static final transient LogMgr c_logger = Log
.get(CoreProperties.class);
/**

/**
* Check branch state before creating new branch
*/
public static final String CHECK_STATE_WHEN_CREATING_PROXY_BRANCH = "checkStateWhenCreatingProxyBranch";
public static final boolean CHECK_STATE_WHEN_CREATING_PROXY_BRANCH_DEFAULT = true;

/**
* Maximum sipAppSessions allowed.
*/
public static final String MAX_APP_SESSIONS = "maxAppSessions";
Expand Down

0 comments on commit d65cd7a

Please sign in to comment.