use of javax.sip.address.Hop in project XobotOS by xamarin.
the class SipProviderImpl method transactionErrorEvent.
/**
* Invoked when an error has ocurred with a transaction. Propagate up to the
* listeners.
*
* @param transactionErrorEvent
* Error event.
*/
public void transactionErrorEvent(SIPTransactionErrorEvent transactionErrorEvent) {
SIPTransaction transaction = (SIPTransaction) transactionErrorEvent.getSource();
if (transactionErrorEvent.getErrorID() == SIPTransactionErrorEvent.TRANSPORT_ERROR) {
// There must be a way to inform the TU here!!
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug("TransportError occured on " + transaction);
}
// Treat this like a timeout event. (Suggestion from Christophe).
Object errorObject = transactionErrorEvent.getSource();
Timeout timeout = Timeout.TRANSACTION;
TimeoutEvent ev = null;
if (errorObject instanceof SIPServerTransaction) {
ev = new TimeoutEvent(this, (ServerTransaction) errorObject, timeout);
} else {
SIPClientTransaction clientTx = (SIPClientTransaction) errorObject;
Hop hop = clientTx.getNextHop();
if (sipStack.getRouter() instanceof RouterExt) {
((RouterExt) sipStack.getRouter()).transactionTimeout(hop);
}
ev = new TimeoutEvent(this, (ClientTransaction) errorObject, timeout);
}
// Handling transport error like timeout
this.handleEvent(ev, (SIPTransaction) errorObject);
} else if (transactionErrorEvent.getErrorID() == SIPTransactionErrorEvent.TIMEOUT_ERROR) {
// This is a timeout event.
Object errorObject = transactionErrorEvent.getSource();
Timeout timeout = Timeout.TRANSACTION;
TimeoutEvent ev = null;
if (errorObject instanceof SIPServerTransaction) {
ev = new TimeoutEvent(this, (ServerTransaction) errorObject, timeout);
} else {
SIPClientTransaction clientTx = (SIPClientTransaction) errorObject;
Hop hop = clientTx.getNextHop();
if (sipStack.getRouter() instanceof RouterExt) {
((RouterExt) sipStack.getRouter()).transactionTimeout(hop);
}
ev = new TimeoutEvent(this, (ClientTransaction) errorObject, timeout);
}
this.handleEvent(ev, (SIPTransaction) errorObject);
} else if (transactionErrorEvent.getErrorID() == SIPTransactionErrorEvent.TIMEOUT_RETRANSMIT) {
// This is a timeout retransmit event.
// We should never get this if retransmit filter is
// enabled (ie. in that case the stack should handle.
// all retransmits.
Object errorObject = transactionErrorEvent.getSource();
Transaction tx = (Transaction) errorObject;
if (tx.getDialog() != null)
InternalErrorHandler.handleException("Unexpected event !", this.sipStack.getStackLogger());
Timeout timeout = Timeout.RETRANSMIT;
TimeoutEvent ev = null;
if (errorObject instanceof SIPServerTransaction) {
ev = new TimeoutEvent(this, (ServerTransaction) errorObject, timeout);
} else {
ev = new TimeoutEvent(this, (ClientTransaction) errorObject, timeout);
}
this.handleEvent(ev, (SIPTransaction) errorObject);
}
}
use of javax.sip.address.Hop in project XobotOS by xamarin.
the class TLSMessageChannel method processMessage.
/**
* Gets invoked by the parser as a callback on successful message parsing (i.e. no parser
* errors).
*
* @param sipMessage Message to process (this calls the application for processing the
* message).
*
* Jvb: note that this code is identical to TCPMessageChannel, refactor some day
*/
public void processMessage(SIPMessage sipMessage) throws Exception {
try {
if (sipMessage.getFrom() == null || sipMessage.getTo() == null || sipMessage.getCallId() == null || sipMessage.getCSeq() == null || sipMessage.getViaHeaders() == null) {
String badmsg = sipMessage.encode();
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logError("bad message " + badmsg);
sipStack.getStackLogger().logError(">>> Dropped Bad Msg");
}
return;
}
ViaList viaList = sipMessage.getViaHeaders();
if (sipMessage instanceof SIPRequest) {
Via v = (Via) viaList.getFirst();
// the peer address and tag it appropriately.
Hop hop = sipStack.addressResolver.resolveAddress(v.getHop());
this.peerProtocol = v.getTransport();
try {
this.peerAddress = mySock.getInetAddress();
// JvB: if sender added 'rport', must always set received
if (v.hasParameter(Via.RPORT) || !hop.getHost().equals(this.peerAddress.getHostAddress())) {
v.setParameter(Via.RECEIVED, this.peerAddress.getHostAddress());
}
// @@@ hagai
// JvB: technically, may only do this when Via already contains
// rport
v.setParameter(Via.RPORT, Integer.toString(this.peerPort));
} catch (java.text.ParseException ex) {
InternalErrorHandler.handleException(ex);
}
// Use this for outgoing messages as well.
if (!this.isCached) {
((TLSMessageProcessor) this.messageProcessor).cacheMessageChannel(this);
this.isCached = true;
String key = IOHandler.makeKey(mySock.getInetAddress(), this.peerPort);
sipStack.ioHandler.putSocket(key, mySock);
}
}
// Foreach part of the request header, fetch it and process it
long receptionTime = System.currentTimeMillis();
if (sipMessage instanceof SIPRequest) {
// This is a request - process the request.
SIPRequest sipRequest = (SIPRequest) sipMessage;
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug("----Processing Message---");
}
if (this.sipStack.getStackLogger().isLoggingEnabled(ServerLogger.TRACE_MESSAGES)) {
sipStack.serverLogger.logMessage(sipMessage, this.getPeerHostPort().toString(), this.messageProcessor.getIpAddress().getHostAddress() + ":" + this.messageProcessor.getPort(), false, receptionTime);
}
// if it is too long.
if (sipStack.getMaxMessageSize() > 0 && sipRequest.getSize() + (sipRequest.getContentLength() == null ? 0 : sipRequest.getContentLength().getContentLength()) > sipStack.getMaxMessageSize()) {
SIPResponse sipResponse = sipRequest.createResponse(SIPResponse.MESSAGE_TOO_LARGE);
byte[] resp = sipResponse.encodeAsBytes(this.getTransport());
this.sendMessage(resp, false);
throw new Exception("Message size exceeded");
}
// Stack could not create a new server request interface.
// maybe not enough resources.
ServerRequestInterface sipServerRequest = sipStack.newSIPServerRequest(sipRequest, this);
if (sipServerRequest != null) {
try {
sipServerRequest.processRequest(sipRequest, this);
} finally {
if (sipServerRequest instanceof SIPTransaction) {
SIPServerTransaction sipServerTx = (SIPServerTransaction) sipServerRequest;
if (!sipServerTx.passToListener())
((SIPTransaction) sipServerRequest).releaseSem();
}
}
} else {
SIPResponse response = sipRequest.createResponse(Response.SERVICE_UNAVAILABLE);
RetryAfter retryAfter = new RetryAfter();
// Be a good citizen and send a decent response code back.
try {
retryAfter.setRetryAfter((int) (10 * (Math.random())));
response.setHeader(retryAfter);
this.sendMessage(response);
} catch (Exception e) {
// IGNore
}
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logWarning("Dropping message -- could not acquire semaphore");
}
} else {
SIPResponse sipResponse = (SIPResponse) sipMessage;
try {
sipResponse.checkHeaders();
} catch (ParseException ex) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logError("Dropping Badly formatted response message >>> " + sipResponse);
return;
}
// If it is too large dump it silently.
if (sipStack.getMaxMessageSize() > 0 && sipResponse.getSize() + (sipResponse.getContentLength() == null ? 0 : sipResponse.getContentLength().getContentLength()) > sipStack.getMaxMessageSize()) {
if (sipStack.isLoggingEnabled())
this.sipStack.getStackLogger().logDebug("Message size exceeded");
return;
}
ServerResponseInterface sipServerResponse = sipStack.newSIPServerResponse(sipResponse, this);
if (sipServerResponse != null) {
try {
if (sipServerResponse instanceof SIPClientTransaction && !((SIPClientTransaction) sipServerResponse).checkFromTag(sipResponse)) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logError("Dropping response message with invalid tag >>> " + sipResponse);
return;
}
sipServerResponse.processResponse(sipResponse, this);
} finally {
if (sipServerResponse instanceof SIPTransaction && !((SIPTransaction) sipServerResponse).passToListener()) {
// Note that the semaphore is released in event
// scanner if the
// request is actually processed by the Listener.
((SIPTransaction) sipServerResponse).releaseSem();
}
}
} else {
sipStack.getStackLogger().logWarning("Could not get semaphore... dropping response");
}
}
} finally {
}
}
Aggregations