use of gov.nist.javax.sip.header.From in project XobotOS by xamarin.
the class FromParser method parse.
public SIPHeader parse() throws ParseException {
From from = new From();
this.lexer.match(TokenTypes.FROM);
this.lexer.SPorHT();
this.lexer.match(':');
this.lexer.SPorHT();
super.parse(from);
this.lexer.match('\n');
return from;
}
use of gov.nist.javax.sip.header.From in project XobotOS by xamarin.
the class SIPResponse method getDialogId.
public String getDialogId(boolean isServer, String toTag) {
CallID cid = (CallID) this.getCallId();
From from = (From) this.getFrom();
StringBuffer retval = new StringBuffer(cid.getCallId());
if (!isServer) {
//retval.append(COLON).append(from.getUserAtHostPort());
if (from.getTag() != null) {
retval.append(COLON);
retval.append(from.getTag());
}
//retval.append(COLON).append(to.getUserAtHostPort());
if (toTag != null) {
retval.append(COLON);
retval.append(toTag);
}
} else {
//retval.append(COLON).append(to.getUserAtHostPort());
if (toTag != null) {
retval.append(COLON);
retval.append(toTag);
}
//retval.append(COLON).append(from.getUserAtHostPort());
if (from.getTag() != null) {
retval.append(COLON);
retval.append(from.getTag());
}
}
return retval.toString().toLowerCase();
}
use of gov.nist.javax.sip.header.From in project XobotOS by xamarin.
the class SIPResponse method getDialogId.
/** Get a dialog identifier.
* Generates a string that can be used as a dialog identifier.
*
* @param isServer is set to true if this is the UAS
* and set to false if this is the UAC
*/
public String getDialogId(boolean isServer) {
CallID cid = (CallID) this.getCallId();
From from = (From) this.getFrom();
To to = (To) this.getTo();
StringBuffer retval = new StringBuffer(cid.getCallId());
if (!isServer) {
//retval.append(COLON).append(from.getUserAtHostPort());
if (from.getTag() != null) {
retval.append(COLON);
retval.append(from.getTag());
}
//retval.append(COLON).append(to.getUserAtHostPort());
if (to.getTag() != null) {
retval.append(COLON);
retval.append(to.getTag());
}
} else {
//retval.append(COLON).append(to.getUserAtHostPort());
if (to.getTag() != null) {
retval.append(COLON);
retval.append(to.getTag());
}
//retval.append(COLON).append(from.getUserAtHostPort());
if (from.getTag() != null) {
retval.append(COLON);
retval.append(from.getTag());
}
}
return retval.toString().toLowerCase();
}
use of gov.nist.javax.sip.header.From in project XobotOS by xamarin.
the class SIPResponse method createRequest.
/**
* Generate a request from a response.
*
* @param requestURI -- the request URI to assign to the request.
* @param via -- the Via header to assign to the request
* @param cseq -- the CSeq header to assign to the request
* @param from -- the From header to assign to the request
* @param to -- the To header to assign to the request
* @return -- the newly generated sip request.
*/
public SIPRequest createRequest(SipUri requestURI, Via via, CSeq cseq, From from, To to) {
SIPRequest newRequest = new SIPRequest();
String method = cseq.getMethod();
newRequest.setMethod(method);
newRequest.setRequestURI(requestURI);
this.setBranch(via, method);
newRequest.setHeader(via);
newRequest.setHeader(cseq);
Iterator headerIterator = getHeaders();
while (headerIterator.hasNext()) {
SIPHeader nextHeader = (SIPHeader) headerIterator.next();
// Some headers do not belong in a Request ....
if (SIPMessage.isResponseHeader(nextHeader) || nextHeader instanceof ViaList || nextHeader instanceof CSeq || nextHeader instanceof ContentType || nextHeader instanceof ContentLength || nextHeader instanceof RecordRouteList || nextHeader instanceof RequireList || // JvB: added
nextHeader instanceof ContactList || nextHeader instanceof ContentLength || nextHeader instanceof ServerHeader || nextHeader instanceof ReasonHeader || nextHeader instanceof SessionExpires || nextHeader instanceof ReasonList) {
continue;
}
if (nextHeader instanceof To)
nextHeader = (SIPHeader) to;
else if (nextHeader instanceof From)
nextHeader = (SIPHeader) from;
try {
newRequest.attachHeader(nextHeader, false);
} catch (SIPDuplicateHeaderException e) {
//Should not happen!
e.printStackTrace();
}
}
try {
// JvB: all requests need a Max-Forwards
newRequest.attachHeader(new MaxForwards(70), false);
} catch (Exception d) {
}
if (MessageFactoryImpl.getDefaultUserAgentHeader() != null) {
newRequest.setHeader(MessageFactoryImpl.getDefaultUserAgentHeader());
}
return newRequest;
}
use of gov.nist.javax.sip.header.From in project XobotOS by xamarin.
the class SIPMessage method getTransactionId.
/**
* Generate (compute) a transaction ID for this SIP message.
*
* @return A string containing the concatenation of various portions of the From,To,Via and
* RequestURI portions of this message as specified in RFC 2543: All responses to a
* request contain the same values in the Call-ID, CSeq, To, and From fields (with the
* possible addition of a tag in the To field (section 10.43)). This allows responses
* to be matched with requests. Incorporates a bug fix for a bug sent in by Gordon
* Ledgard of IPera for generating transactionIDs when no port is present in the via
* header. Incorporates a bug fix for a bug report sent in by Chris Mills of Nortel
* Networks (converts to lower case when returning the transaction identifier).
*
* @return a string that can be used as a transaction identifier for this message. This can be
* used for matching responses and requests (i.e. an outgoing request and its matching
* response have the same computed transaction identifier).
*/
public String getTransactionId() {
Via topVia = null;
if (!this.getViaHeaders().isEmpty()) {
topVia = (Via) this.getViaHeaders().getFirst();
}
// Branch Id prefix is not case sensitive.
if (topVia != null && topVia.getBranch() != null && topVia.getBranch().toUpperCase().startsWith(SIPConstants.BRANCH_MAGIC_COOKIE_UPPER_CASE)) {
// identifier.
if (this.getCSeq().getMethod().equals(Request.CANCEL))
return (topVia.getBranch() + ":" + this.getCSeq().getMethod()).toLowerCase();
else
return topVia.getBranch().toLowerCase();
} else {
// Old style client so construct the transaction identifier
// from various fields of the request.
StringBuffer retval = new StringBuffer();
From from = (From) this.getFrom();
To to = (To) this.getTo();
// retval.append(hpFrom).append(":");
if (from.hasTag())
retval.append(from.getTag()).append("-");
// String hpTo = to.getUserAtHostPort();
// retval.append(hpTo).append(":");
String cid = this.callIdHeader.getCallId();
retval.append(cid).append("-");
retval.append(this.cSeqHeader.getSequenceNumber()).append("-").append(this.cSeqHeader.getMethod());
if (topVia != null) {
retval.append("-").append(topVia.getSentBy().encode());
if (!topVia.getSentBy().hasPort()) {
retval.append("-").append(5060);
}
}
if (this.getCSeq().getMethod().equals(Request.CANCEL)) {
retval.append(Request.CANCEL);
}
return retval.toString().toLowerCase().replace(":", "-").replace("@", "-") + Utils.getSignature();
}
}
Aggregations