use of gov.nist.core.NameValueList in project XobotOS by xamarin.
the class SIPDialog method createAck.
/*
* (non-Javadoc) The UAC core MUST generate an ACK request for each 2xx received from the
* transaction layer. The header fields of the ACK are constructed in the same way as for any
* request sent within a dialog (see Section 12) with the exception of the CSeq and the header
* fields related to authentication. The sequence number of the CSeq header field MUST be the
* same as the INVITE being acknowledged, but the CSeq method MUST be ACK. The ACK MUST
* contain the same credentials as the INVITE. If the 2xx contains an offer (based on the
* rules above), the ACK MUST carry an answer in its body. If the offer in the 2xx response is
* not acceptable, the UAC core MUST generate a valid answer in the ACK and then send a BYE
* immediately.
*
* Note that for the case of forked requests, you can create multiple outgoing invites each
* with a different cseq and hence you need to supply the invite.
*
* @see javax.sip.Dialog#createAck(long)
*/
public Request createAck(long cseqno) throws InvalidArgumentException, SipException {
// then send INVITE+ACK later on
if (!method.equals(Request.INVITE))
throw new SipException("Dialog was not created with an INVITE" + method);
if (cseqno <= 0)
throw new InvalidArgumentException("bad cseq <= 0 ");
else if (cseqno > ((((long) 1) << 32) - 1))
throw new InvalidArgumentException("bad cseq > " + ((((long) 1) << 32) - 1));
if (this.remoteTarget == null) {
throw new SipException("Cannot create ACK - no remote Target!");
}
if (this.sipStack.isLoggingEnabled()) {
this.sipStack.getStackLogger().logDebug("createAck " + this + " cseqno " + cseqno);
}
// out of order ACK sending. Old ACKs seqno's can always be ACKed.
if (lastInviteOkReceived < cseqno) {
if (sipStack.isLoggingEnabled()) {
this.sipStack.getStackLogger().logDebug("WARNING : Attempt to crete ACK without OK " + this);
this.sipStack.getStackLogger().logDebug("LAST RESPONSE = " + this.lastResponse);
}
throw new SipException("Dialog not yet established -- no OK response!");
}
try {
// JvB: Transport from first entry in route set, or remote Contact
// if none
// Only used to find correct LP & create correct Via
SipURI uri4transport = null;
if (this.routeList != null && !this.routeList.isEmpty()) {
Route r = (Route) this.routeList.getFirst();
uri4transport = ((SipURI) r.getAddress().getURI());
} else {
// should be !=null, checked above
uri4transport = ((SipURI) this.remoteTarget.getURI());
}
String transport = uri4transport.getTransportParam();
if (transport == null) {
// JvB fix: also support TLS
transport = uri4transport.isSecure() ? ListeningPoint.TLS : ListeningPoint.UDP;
}
ListeningPointImpl lp = (ListeningPointImpl) sipProvider.getListeningPoint(transport);
if (lp == null) {
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logError("remoteTargetURI " + this.remoteTarget.getURI());
sipStack.getStackLogger().logError("uri4transport = " + uri4transport);
sipStack.getStackLogger().logError("No LP found for transport=" + transport);
}
throw new SipException("Cannot create ACK - no ListeningPoint for transport towards next hop found:" + transport);
}
SIPRequest sipRequest = new SIPRequest();
sipRequest.setMethod(Request.ACK);
sipRequest.setRequestURI((SipUri) getRemoteTarget().getURI().clone());
sipRequest.setCallId(this.callIdHeader);
sipRequest.setCSeq(new CSeq(cseqno, Request.ACK));
List<Via> vias = new ArrayList<Via>();
// Via via = lp.getViaHeader();
// The user may have touched the sentby for the response.
// so use the via header extracted from the response for the ACK =>
// https://jain-sip.dev.java.net/issues/show_bug.cgi?id=205
// strip the params from the via of the response and use the params from the
// original request
Via via = this.lastResponse.getTopmostVia();
via.removeParameters();
if (originalRequest != null && originalRequest.getTopmostVia() != null) {
NameValueList originalRequestParameters = originalRequest.getTopmostVia().getParameters();
if (originalRequestParameters != null && originalRequestParameters.size() > 0) {
via.setParameters((NameValueList) originalRequestParameters.clone());
}
}
// new branch
via.setBranch(Utils.getInstance().generateBranchId());
vias.add(via);
sipRequest.setVia(vias);
From from = new From();
from.setAddress(this.localParty);
from.setTag(this.myTag);
sipRequest.setFrom(from);
To to = new To();
to.setAddress(this.remoteParty);
if (hisTag != null)
to.setTag(this.hisTag);
sipRequest.setTo(to);
sipRequest.setMaxForwards(new MaxForwards(70));
if (this.originalRequest != null) {
Authorization authorization = this.originalRequest.getAuthorization();
if (authorization != null)
sipRequest.setHeader(authorization);
}
// ACKs for 2xx responses
// use the Route values learned from the Record-Route of the 2xx
// responses.
this.updateRequest(sipRequest);
return sipRequest;
} catch (Exception ex) {
InternalErrorHandler.handleException(ex);
throw new SipException("unexpected exception ", ex);
}
}
use of gov.nist.core.NameValueList in project XobotOS by xamarin.
the class URLParser method local_phone_number.
private TelephoneNumber local_phone_number(boolean inBrackets) throws ParseException {
if (debug)
dbg_enter("local_phone_number");
TelephoneNumber tn = new TelephoneNumber();
tn.setGlobal(false);
NameValueList nv = null;
String b = null;
try {
b = local_number();
tn.setPhoneNumber(b);
if (lexer.hasMoreChars()) {
Token tok = this.lexer.peekNextToken();
switch(tok.getTokenType()) {
case SEMICOLON:
{
if (inBrackets) {
this.lexer.consume(1);
nv = tel_parameters();
tn.setParameters(nv);
}
break;
}
default:
{
break;
}
}
}
} finally {
if (debug)
dbg_leave("local_phone_number");
}
return tn;
}
use of gov.nist.core.NameValueList in project XobotOS by xamarin.
the class URLParser method global_phone_number.
private final TelephoneNumber global_phone_number(boolean inBrackets) throws ParseException {
if (debug)
dbg_enter("global_phone_number");
try {
TelephoneNumber tn = new TelephoneNumber();
tn.setGlobal(true);
NameValueList nv = null;
this.lexer.match(PLUS);
String b = base_phone_number();
tn.setPhoneNumber(b);
if (lexer.hasMoreChars()) {
char tok = lexer.lookAhead(0);
if (tok == ';' && inBrackets) {
this.lexer.consume(1);
nv = tel_parameters();
tn.setParameters(nv);
}
}
return tn;
} finally {
if (debug)
dbg_leave("global_phone_number");
}
}
use of gov.nist.core.NameValueList in project XobotOS by xamarin.
the class URLParser method tel_parameters.
private NameValueList tel_parameters() throws ParseException {
NameValueList nvList = new NameValueList();
// JvB: Need to handle 'phone-context' specially
// 'isub' (or 'ext') MUST appear first, but we accept any order here
NameValue nv;
while (true) {
String pname = paramNameOrValue();
// Handle 'phone-context' specially, it may start with '+'
if (pname.equalsIgnoreCase("phone-context")) {
nv = phone_context();
} else {
if (lexer.lookAhead(0) == '=') {
lexer.consume(1);
String value = paramNameOrValue();
nv = new NameValue(pname, value, false);
} else {
// flag param
nv = new NameValue(pname, "", true);
}
}
nvList.set(nv);
if (lexer.lookAhead(0) == ';') {
lexer.consume(1);
} else {
return nvList;
}
}
}
Aggregations