Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.sip
Class SipRegistrarConnection

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.sip.MethodProcessorAdapter
      extended by net.java.sip.communicator.impl.protocol.sip.SipRegistrarConnection
All Implemented Interfaces:
MethodProcessor
Direct Known Subclasses:
SipRegistrarlessConnection

public class SipRegistrarConnection
extends MethodProcessorAdapter

Contains all functionality that has anything to do with registering and maintaining registrations with a SIP Registrar.

Author:
Emil Ivov

Field Summary
(package private)  javax.sip.ClientTransaction regTrans
          The client transaction that we used for sending the last REGISTER request.
 
Constructor Summary
protected SipRegistrarConnection()
          Empty constructor that we only have in order to allow for classes like SipRegistrarlessConnection to extend this class.
  SipRegistrarConnection(String registrarName, int registrarPort, String registrationTransport, ProtocolProviderServiceSipImpl sipProviderCallback)
          Creates a new instance of this class.
 
Method Summary
 javax.sip.address.Address getAddressOfRecord()
          Returns the address of record that we are using to register against our registrar or null if this is a fake or "Registrarless" connection.
 javax.sip.SipProvider getJainSipProvider()
          Returns the JAIN SIP provider that should be used for communication with our current registrar.
 javax.sip.address.SipURI getRegistrarURI()
          The registrar URI we use for registrar connection.
 RegistrationState getRegistrationState()
          Returns the state of this connection.
 String getTransport()
          Returns the transport that this connection is currently using to communicate with the Registrar.
 boolean isRegistrarless()
          Returns true if this is a fake connection that is not actually using a registrar.
 boolean isRequestFromSameConnection(javax.sip.message.Request request)
          Checks a particular request is it coming from the same proxy we are currently using.
 boolean isRouteHeaderEnabled()
          Determines whether Register requests should be using a route header.
 boolean processIOException(javax.sip.IOExceptionEvent exceptionEvent)
          Process an asynchronously reported IO Exception.
 void processNotImplemented(javax.sip.ClientTransaction transatcion, javax.sip.message.Response response)
          Handles a NOT_IMPLEMENTED response sent in reply of our register request.
 void processOK(javax.sip.ClientTransaction clientTransatcion, javax.sip.message.Response response)
          An ok here means that our registration has been accepted or terminated (depending on the corresponding REGISTER request).
 boolean processRequest(javax.sip.RequestEvent requestEvent)
          Processes a Request received on a SipProvider upon which this SipListener is registered.
 boolean processResponse(javax.sip.ResponseEvent responseEvent)
          Analyzes the incoming responseEvent and then forwards it to the proper event handler.
 boolean processTimeout(javax.sip.TimeoutEvent timeoutEvent)
          Processes a retransmit or expiration Timeout of an underlying Transactionhandled by this SipListener.
(package private)  void register()
          Sends the REGISTER request to the server specified in the constructor.
(package private)  void setRegistrationState(RegistrationState newState, int reasonCode, String reason)
          Sets our registration state to newState and dispatches an event through the protocol provider service impl.
(package private)  void setTransport(String newRegistrationTransport)
          Changes transport of registrar connection and recreates registrar URI.
 String toString()
          Returns a string representation of this connection instance instance including information that would permit to distinguish it among other sip listeners when reading a log file.
 void unregister()
          Sends a unregistered request to the registrar thus ending our registration.
 
Methods inherited from class net.java.sip.communicator.impl.protocol.sip.MethodProcessorAdapter
processDialogTerminated, processTransactionTerminated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

regTrans

javax.sip.ClientTransaction regTrans
The client transaction that we used for sending the last REGISTER request.

Constructor Detail

SipRegistrarConnection

public SipRegistrarConnection(String registrarName,
                              int registrarPort,
                              String registrationTransport,
                              ProtocolProviderServiceSipImpl sipProviderCallback)
Creates a new instance of this class.

Parameters:
registrarName - the FQDN of the registrar we will be registering with.
registrarPort - the port of the registrar we will be registering with.
registrationTransport - the transport to use when sending our REGISTER request to the server.
sipProviderCallback - a reference to the ProtocolProviderServiceSipImpl instance that created us.

SipRegistrarConnection

protected SipRegistrarConnection()
Empty constructor that we only have in order to allow for classes like SipRegistrarlessConnection to extend this class.

Method Detail

setTransport

void setTransport(String newRegistrationTransport)
Changes transport of registrar connection and recreates registrar URI.

Parameters:
newRegistrationTransport - the new transport.

register

void register()
        throws OperationFailedException
Sends the REGISTER request to the server specified in the constructor.

Throws:
OperationFailedException - with the corresponding error code if registration or construction of the Register request fail.

processOK

public void processOK(javax.sip.ClientTransaction clientTransatcion,
                      javax.sip.message.Response response)
An ok here means that our registration has been accepted or terminated (depending on the corresponding REGISTER request). We change state notify listeners and (in the case of a new registration) schedule reregistration.

Parameters:
clientTransatcion - the ClientTransaction that we created when sending the register request.
response - the OK Response that we've just received.

isRequestFromSameConnection

public boolean isRequestFromSameConnection(javax.sip.message.Request request)
Checks a particular request is it coming from the same proxy we are currently using. A check for security reasons, preventing injection of other messages in the PP.

Parameters:
request - the request to check.
Returns:
false if the request doesn't belong to our register or if we cannot decide we keep the old behaviour.

unregister

public void unregister()
                throws OperationFailedException
Sends a unregistered request to the registrar thus ending our registration.

Throws:
OperationFailedException - with the corresponding code if sending or constructing the request fails.

getRegistrationState

public RegistrationState getRegistrationState()
Returns the state of this connection.

Returns:
a RegistrationState instance indicating the state of our registration with the corresponding registrar.

setRegistrationState

void setRegistrationState(RegistrationState newState,
                          int reasonCode,
                          String reason)
Sets our registration state to newState and dispatches an event through the protocol provider service impl.

Parameters:
newState - a reference to the RegistrationState that we're currently detaining.
reasonCode - one of the REASON_XXX error codes specified in RegistrationStateChangeEvent.
reason - a reason String further explaining the reasonCode.

processNotImplemented

public void processNotImplemented(javax.sip.ClientTransaction transatcion,
                                  javax.sip.message.Response response)
Handles a NOT_IMPLEMENTED response sent in reply of our register request.

Parameters:
transatcion - the transaction that our initial register request belongs to.
response - our initial register request.

getJainSipProvider

public javax.sip.SipProvider getJainSipProvider()
Returns the JAIN SIP provider that should be used for communication with our current registrar.

Returns:
the JAIN SIP provider that should be used for communication with our current registrar.

getTransport

public String getTransport()
Returns the transport that this connection is currently using to communicate with the Registrar.

Returns:
the transport that this connection is using.

processResponse

public boolean processResponse(javax.sip.ResponseEvent responseEvent)
Analyzes the incoming responseEvent and then forwards it to the proper event handler.

Specified by:
processResponse in interface MethodProcessor
Overrides:
processResponse in class MethodProcessorAdapter
Parameters:
responseEvent - the responseEvent that we received ProtocolProviderService.
Returns:
true if the specified event has been handled by this processor and shouldn't be offered to other processors registered for the same method; false, otherwise

processRequest

public boolean processRequest(javax.sip.RequestEvent requestEvent)
Processes a Request received on a SipProvider upon which this SipListener is registered.

Specified by:
processRequest in interface MethodProcessor
Overrides:
processRequest in class MethodProcessorAdapter
Parameters:
requestEvent - requestEvent fired from the SipProvider to the SipListener representing a Request received from the network.
Returns:
true if the specified event has been handled by this processor and shouldn't be offered to other processors registered for the same method; false, otherwise

processTimeout

public boolean processTimeout(javax.sip.TimeoutEvent timeoutEvent)
Processes a retransmit or expiration Timeout of an underlying Transactionhandled by this SipListener.

Specified by:
processTimeout in interface MethodProcessor
Overrides:
processTimeout in class MethodProcessorAdapter
Parameters:
timeoutEvent - the timeoutEvent received indicating either the message retransmit or transaction timed out.
Returns:
true if the specified event has been handled by this processor and shouldn't be offered to other processors registered for the same method; false, otherwise

processIOException

public boolean processIOException(javax.sip.IOExceptionEvent exceptionEvent)
Process an asynchronously reported IO Exception.

Specified by:
processIOException in interface MethodProcessor
Overrides:
processIOException in class MethodProcessorAdapter
Parameters:
exceptionEvent - The Exception event that is reported to the application.
Returns:
true if the specified event has been handled by this processor and shouldn't be offered to other processors registered for the same method; false, otherwise

toString

public String toString()
Returns a string representation of this connection instance instance including information that would permit to distinguish it among other sip listeners when reading a log file.

Overrides:
toString in class Object
Returns:
a string representation of this operation set.

isRouteHeaderEnabled

public boolean isRouteHeaderEnabled()
Determines whether Register requests should be using a route header. The return value of this method is specified by the REGISTERS_USE_ROUTE account property. Jeroen van Bemmel: The reason this may needed, is that standards- compliant registrars check the domain in the request URI. If it contains an IP address, some registrars are unable to match/process it (they may forward instead, and get into a forwarding loop)

Returns:
true if we should be using a route header.

isRegistrarless

public boolean isRegistrarless()
Returns true if this is a fake connection that is not actually using a registrar. This method should be overridden in SipRegistrarlessConnection and return true in there.

Returns:
true if this connection is really using a registrar and false if it is a fake connection that doesn't really use a registrar.

getRegistrarURI

public javax.sip.address.SipURI getRegistrarURI()
                                         throws ParseException
The registrar URI we use for registrar connection.

Returns:
the registrar URI. * @throws ParseException in case the specified registrar address is not a valid registrar address.
Throws:
ParseException

getAddressOfRecord

public javax.sip.address.Address getAddressOfRecord()
Returns the address of record that we are using to register against our registrar or null if this is a fake or "Registrarless" connection. If our are trying to obtain an address to put in your from header and don't no what to do in the case of registrarless accounts - think about using ProtocolProviderServiceSipImpl.createAddressOfRecord().

Returns:
our Address Of Record

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.