This section describes how a MIDlet can manage an own registration and how the own registration can be used as the registration context of other requests. See the example code at end of this chapter.
Creation of own registration
A MIDlet has to perform the following steps before sending a REGISTER request:
A MIDlet has to pass the URI of the registrar server as an
argument to the Connector.open()
operation.
A MIDlet has to set ‘To’, ‘From’, and ‘Contact’ headers to the REGISTER request in the case where the MIDlet wants to register a user to the registrar server. The REGISTER request is interpreted to “fetch registrations” request if the MIDlet does not set the ‘Contact’ header to the REGISTER request.
A MIDlet has to pass a SipConnectionNotifier
object
as an argument to the initRequest()
operation. The S60
implementation stores all necessary registration context information to the SipConnectionNotifier
object
in the case that this own registration is used as the registration context
with other requests.
More notes for registration:
The user is always prompted for an access point in the case of own registration.
IOException
is thrown if the ‘To’ header
of the REGISTER
request is equal to the value of the
‘To’ header of any existing profile. ‘To’ header of the profile is defined
in the Public username field in the SIP Settings Tool.
Own registration as registration context of other request
A MIDlet passes a SipConnectionNotifier
object
as the second argument to the initRequest()
operation,
when it wants to use an own registration as the registration context of other
requests. The MIDlet does not set the ‘From’ header to the request in this
situation. Setting a ‘Contact’ is optional in the same way as described in
section Selecting registration
context (from SIP Settings Tool).
The S60 implementation searches the ‘From’ and ‘Contact’ headers to see whether these headers match the corresponding headers of any REGISTER request done by the MIDlet. If the ‘Contact’ header has no semantics in the request (e.g. MESSAGE), then only the ‘From’ header is used to check whether it matches the ‘To’ header of any of the own registrations.
De-registering own registration
A SipClientConnection
object for de-registration
is created in the same way as a SipClientConnection
object
for the original registration, i.e. using Connector.open()
operation.
The ‘To’, ‘From’ and ‘Contact’ headers of de-registration request have to
be equal to the original registration. The REGISTER request is handled as
the original registration if the ‘To’, ‘From’ and ‘Contact’ headers do not
match any existing registration objects.
De-registration can also be done via the SipRefreshHelper
interface.
Example in the code level:
//Creation of own registration. SipConnectionNotifier notifier = ...; SipClientConnection reg = ( SipClientConnection ) Connector.open( "sip:myRegistrar.com:5070" ); reg.initRequest( "REGISTER", notifier ); String contactHdrValue = "sip: UserA@" + notifier.getLocalAddress() + ":" + notifier.getLocalPort() + ";expires=3000"; reg.setHeader( "Contact", contactHdrValue ); reg.setHeader( "To", "sip:[email protected]:5070" ); reg.setHeader( "From", "sip:[email protected]:5070" ); reg.send(); //Handling of the response has been left out from this example. //INVITE request is sent so that own registration is used as a "registration context" //of the INVITE request. SipClientConnection scc = ( SipClientConnection ) Connector.open("sip:[email protected]:5070"); scc.initRequest( "INVITE", notifier ); scc.setHeader( "Accept-Contact", "*;type=\"application/test\"" ); scc.send(); //Handling rest of the dialog has been left out from this example. //Sending de-register request for own registration. SipClientConnection dereg = ( SipClientConnection ) Connector.open( "sip:myRegistrar.com:5070" ); dereg.initRequest( "REGISTER", null ); dereg.setHeader( "Contact", contactHdrValue ); dereg.setHeader( "To", "sip:[email protected]:5070" ); dereg.setHeader( "From", "sip:[email protected]:5070" ); dereg.setHeader( "Expires", "0" ); dereg.send(); //Handling of the response has been left out from this example.
The example code above generates the following INVITE request:
INVITE sip:[email protected]:5070 SIP/2.0 Via: SIP/2.0/UDP 174.22.99.137:5060;branch=z9hG4bKlqh5ad26mthc7hde0klaqpk From: sip: [email protected];tag=j8sqa8eialhc7bd2f4nn To: sip:[email protected] Contact: sip:[email protected]:5060;expires=3000 Accept-Contact: *;type="application/test" CSeq: 1527 INVITE Call-ID: S3Zld0ZUoIf950kGHsrfGO5fODYJqE Max-Forwards: 70