public boolean equals(Object other) { if (other==this) return true; if (other instanceof ViaHeader) { final ViaHeader o = (ViaHeader) other; return getProtocol().equalsIgnoreCase( o.getProtocol() ) && getTransport().equalsIgnoreCase( o.getTransport() ) && getHost().equalsIgnoreCase( o.getHost() ) && getPort() == o.getPort() && equalParameters( o ); } return false; }
/** * Get the Via header to assign for this message processor. The topmost via * header of the outoging messages use this. * * @return the ViaHeader to be used by the messages sent via this message processor. */ public Via getViaHeader() { try { Via via = new Via(); if (this.sentByHostPort != null) { via.setSentBy(sentByHostPort); via.setTransport(this.getTransport()); } else { Host host = new Host(); host.setHostname(this.getIpAddress().getHostAddress()); via.setHost(host); via.setPort(this.getPort()); via.setTransport(this.getTransport()); } return via; } catch (ParseException ex) { ex.printStackTrace(); return null; } catch (InvalidArgumentException ex) { ex.printStackTrace(); return null; } } public ListeningPointImpl getListeningPoint() {
public boolean responseBelongsToUs(SIPResponse response) { Via topmostVia = response.getTopmostVia(); String branch = topmostVia.getBranch(); return branch != null && branch.startsWith( SIPConstants.BRANCH_MAGIC_COOKIE + "-" + this.signature); }
/** * Get the Via header for this transport. Note that this does not set a branch identifier. * * @return a via header for outgoing messages sent from this channel. */ public Via getViaHeader() { Via channelViaHeader; channelViaHeader = new Via(); try { channelViaHeader.setTransport(getTransport()); } catch (ParseException ex) { } channelViaHeader.setSentBy(getHostPort()); return channelViaHeader; }
public Object clone() { Via retval = (Via) super.clone(); if (this.sentProtocol != null) retval.sentProtocol = (Protocol) this.sentProtocol.clone(); if (this.sentBy != null) retval.sentBy = (HostPort) this.sentBy.clone(); if ( this.getRPort() != -1) retval.setParameter(RPORT,this.getRPort()); return retval; }
protocol.setProtocolVersion(protocolVersion.getTokenValue()); protocol.setTransport(transport.getTokenValue()); v.setSentProtocol(protocol); v.setSentBy(hostPort); v.setParameter(nameValue); this.lexer.SPorHT(); v.setComment(comment.toString());
.getHop()); this.peerPort = hop.getPort(); this.peerProtocol = topMostVia.getTransport(); boolean hasRPort = topMostVia.hasParameter(Via.RPORT); if(sipStack.isPatchRport()) if(!hasRPort && topMostVia.getPort() != peerPacketSourcePort) { "setting rport since viaPort " + topMostVia.getPort() + " different than peerPacketSourcePort " + peerPacketSourcePort + " so that the response can be routed back"); || !hop.getHost().equals( this.peerAddress.getHostAddress())) { topMostVia.setParameter(Via.RECEIVED, this.peerAddress .getHostAddress()); topMostVia.setParameter(Via.RPORT, Integer .toString(this.peerPacketSourcePort)); this.peerAddress = packet.getAddress(); this.peerPort = packet.getPort(); this.peerProtocol = topMostVia.getTransport();
if (sipRequest.getTopmostVia().getBranch() != null && sipRequest.getTopmostVia().getBranch().startsWith( SIPConstants.BRANCH_MAGIC_COOKIE) && sipStack.findTransaction((SIPRequest) sipRequest, false) != null) { if (sipRequest.getTopmostVia().getBranch() == null || !sipRequest.getTopmostVia().getBranch().startsWith( SIPConstants.BRANCH_MAGIC_COOKIE) || sipStack.checkBranchId() ) { branchId = Utils.getInstance().generateBranchId(); sipRequest.getTopmostVia().setBranch(branchId); if(topmostVia.getTransport() == null) topmostVia.setTransport(transport); if(topmostVia.getPort() == -1) topmostVia.setPort(listeningPoint.getPort()); branchId = sipRequest.getTopmostVia().getBranch();
Via via = new Via(); if (branch != null) via.setBranch(branch); via.setHost(host); via.setPort(port); via.setTransport(transport);
throw new SipException("Transaction exists -- cannot send response statelessly"); String transport = via.getTransport(); String host = via.getReceived(); host = via.getHost(); int port = via.getRPort(); if (port == -1) { port = via.getPort(); if (port == -1) { if (transport.equalsIgnoreCase("TLS")||transport.equalsIgnoreCase("SCTP-TLS"))
lp = (ListeningPointImpl) sipProvider.getListeningPoint(this.lastResponseTopMostVia.getTransport()); logger.logDebug("lastResponseTopMostVia " + lastResponseTopMostVia); via.removeParameters(); if (originalRequest != null && originalRequest.getTopmostVia() != null) { NameValueList originalRequestParameters = originalRequest .getTopmostVia().getParameters(); if (originalRequestParameters != null && originalRequestParameters.size() > 0) { via.setParameters((NameValueList) originalRequestParameters .clone()); via.setBranch(Utils.getInstance().generateBranchId()); // new branch vias.add(via); if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
public Request createRequest(String method) throws SipException { if (method.equals(Request.ACK) || method.equals(Request.PRACK)) { throw new SipException( "Invalid method specified for createRequest:" + method); } if (lastResponseTopMostVia != null) return this.createRequest(method, this.lastResponseTopMostVia .getTransport()); else throw new SipException("Dialog not yet established -- no response!"); }
&& topVia.getBranch() != null && topVia.getBranch().toUpperCase().startsWith( SIPConstants.BRANCH_MAGIC_COOKIE_UPPER_CASE)) { return (topVia.getBranch() + ":" + this.getCSeq().getMethod()).toLowerCase(); else return topVia.getBranch().toLowerCase(); } else { this.cSeqHeader.getMethod()); if (topVia != null) { retval.append("-").append(topVia.getSentBy().encode()); if (!topVia.getSentBy().hasPort()) { retval.append("-").append(5060);
/** * Set the RPort flag parameter */ public void setRPort(){ // Fix for Issue 309 by jorabin try { this.setParameter(Via.RPORT,null); } catch (ParseException e) { e.printStackTrace(); // should not occur } }
/** * Sets the Via branch for CANCEL or ACK requests * * @param via * @param method * @throws ParseException */ private final void setBranch(Via via, String method) { String branch; if (method.equals(Request.ACK)) { if (getLastResponseStatusCode().intValue() >= 300) { branch = lastResponseTopMostVia.getBranch(); // non-2xx ACK uses // same branch } else { branch = Utils.getInstance().generateBranchId(); // 2xx ACK gets // new branch } } else if (method.equals(Request.CANCEL)) { branch = lastResponseTopMostVia.getBranch(); // CANCEL uses same // branch } else return; try { via.setBranch(branch); } catch (ParseException e) { e.printStackTrace(); } }
/** port of the Via Header. * @return true if Port exists. */ public boolean hasPort() { return (getSentBy()).hasPort(); }
public SIPHeader parse() throws ParseException { if (debug) dbg_enter("parse"); try { ViaList viaList = new ViaList(); // The first via header. this.lexer.match(TokenTypes.VIA); this.lexer.SPorHT(); // ignore blanks this.lexer.match(':'); // expect a colon. this.lexer.SPorHT(); // ingore blanks. while (true) { Via v = new Via(); parseVia(v); viaList.add(v); this.lexer.SPorHT(); // eat whitespace. if (this.lexer.lookAhead(0) == ',') { this.lexer.consume(1); // Consume the comma this.lexer.SPorHT(); // Ignore space after. } if (this.lexer.lookAhead(0) == '\n') break; } this.lexer.match('\n'); return viaList; } finally { if (debug) dbg_leave("parse"); } }
cancel.addFirst((Header) this.getTopmostVia().clone()); cancel.setHeader((Header) this.maxForwardsHeader.clone());
protocol.setProtocolVersion(protocolVersion.getTokenValue()); protocol.setTransport(transport.getTokenValue()); v.setSentProtocol(protocol); v.setSentBy(hostPort); v.setParameter(nameValue); this.lexer.SPorHT(); v.setComment(comment.toString());
Via v = (Via) viaList.getFirst(); Hop hop = sipStack.addressResolver.resolveAddress(v.getHop()); this.peerProtocol = v.getTransport(); int hopPort = v.getPort(); if(logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) { logger.logDebug("hop port = " + hopPort + " for request " + sipMessage + " for this channel " + this + " key " + key); boolean hasRPort = v.hasParameter(Via.RPORT); if(!hasRPort && v.getPort() != peerPort) { "setting rport since viaPort " + v.getPort() + " different than peerPacketSourcePort " + peerPort + " so that the response can be routed back"); || !hop.getHost().equals( this.peerAddress.getHostAddress())) { v.setParameter(Via.RECEIVED, this.peerAddress .getHostAddress()); v.setParameter(Via.RPORT, Integer.toString(this.peerPort)); } catch (java.text.ParseException ex) { InternalErrorHandler.handleException(ex);