From ced71cd8aff6e82ea0e3f2e6d1253583f4abdcfe Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Tue, 21 Nov 2006 16:28:25 +0000 Subject: [PATCH] Handle OPTIONS requests --- .../impl/protocol/sip/ClientCapabilities.java | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 src/net/java/sip/communicator/impl/protocol/sip/ClientCapabilities.java diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ClientCapabilities.java b/src/net/java/sip/communicator/impl/protocol/sip/ClientCapabilities.java new file mode 100644 index 000000000..590b4db96 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/sip/ClientCapabilities.java @@ -0,0 +1,146 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.sip; + +import javax.sip.*; +import javax.sip.message.*; +import java.text.*; +import net.java.sip.communicator.util.*; +import java.util.*; + +/** + * Handles OPTIONS requests by replying with an OK response containing + * methods that we support. + * + * @author Emil Ivov + */ +public class ClientCapabilities + implements SipListener +{ + private static Logger logger = Logger.getLogger(ClientCapabilities.class); + + /** + * The protocol provider that created us. + */ + private ProtocolProviderServiceSipImpl provider = null; + + public ClientCapabilities(ProtocolProviderServiceSipImpl protocolProvider) + { + this.provider = protocolProvider; + provider.registerMethodProcessor(Request.OPTIONS, this); + } + + /** + * Receives options requests and replies with an OK response containing + * methods that we support. + * + * @param requestEvent the incoming options request. + */ + public void processRequest(RequestEvent requestEvent) + { + Response optionsOK = null; + try + { + optionsOK = provider.getMessageFactory().createResponse( + Response.OK, + requestEvent.getRequest()); + + Iterator supportedMethods + = provider.getSupportedMethods().iterator(); + + //add to the allows header all methods that we support + while(supportedMethods.hasNext()) + { + String method = (String)supportedMethods.next(); + + //don't support REGISTERs + if(method.equals(Request.REGISTER)) + continue; + + optionsOK.addHeader( + provider.getHeaderFactory().createAllowHeader(method)); + + //add a user agent header. + optionsOK.setHeader( provider.getSipCommUserAgentHeader()); + } + } + catch (ParseException ex) + { + //What else could we do apart from logging? + logger.warn("Failed to create an incoming OPTIONS request", ex); + return; + } + + try + { + ServerTransaction sTran = requestEvent.getServerTransaction(); + if (sTran == null) + { + SipProvider sipProvider = (SipProvider)requestEvent.getSource(); + sTran = sipProvider + .getNewServerTransaction(requestEvent.getRequest()); + } + + sTran.sendResponse(optionsOK); + } + catch (InvalidArgumentException ex) + { + //What else could we do apart from logging? + logger.warn("Failed to send an incoming OPTIONS request", ex); + return; + } + catch (SipException ex) + { + //What else could we do apart from logging? + logger.warn("Failed to send an incoming OPTIONS request", ex); + return; + } + } + + /** + * ignore. don't needed. + * @param dialogTerminatedEvent unused + */ + public void processDialogTerminated( + DialogTerminatedEvent dialogTerminatedEvent) + { + + } + + /** + * ignore. don't needed. + * @param exceptionEvent unused + */ + public void processIOException(IOExceptionEvent exceptionEvent) + { + } + + /** + * ignore for the time being + * @param responseEvent unused + */ + public void processResponse(ResponseEvent responseEvent) + { + } + + /** + * ignore for the time being. + * @param timeoutEvent unused + */ + public void processTimeout(TimeoutEvent timeoutEvent) + { + } + + /** + * ignore for the time being. + * @param transactionTerminatedEvent unused + */ + public void processTransactionTerminated( + TransactionTerminatedEvent transactionTerminatedEvent) + { + } +}