public boolean unregister ( String contact , long timeout ) { initErrorInfo ( ) ; // TODO - need to support multiple server(s)/registrations // simultaneously? // then return registration() object to user (w/lastregrequest) and // receive // it here, get rid of lastRegistrationRequest if ( lastRegistrationRequest == null ) { return true ; } Request msg = ( Request ) lastRegistrationRequest . clone ( ) ; try { ExpiresHeader expires = parent . getHeaderFactory ( ) . createExpiresHeader ( 0 ) ; msg . setExpires ( expires ) ; cseq . setSeqNumber ( cseq . getSeqNumber ( ) + 1 ) ; cseq . setMethod ( Request . REGISTER ) ; msg . setHeader ( cseq ) ; // set contact header if ( contact != null ) { ContactHeader contact_hdr ; if ( ! contact . equals ( "*" ) ) { URI contact_uri = parent . getAddressFactory ( ) . createURI ( contact ) ; Address contact_address = parent . getAddressFactory ( ) . createAddress ( contact_uri ) ; contact_hdr = parent . getHeaderFactory ( ) . createContactHeader ( contact_address ) ; } else { contact_hdr = parent . getHeaderFactory ( ) . createContactHeader ( ) ; } msg . setHeader ( contact_hdr ) ; } // send the REGISTRATION request and get the response Response response = sendRegistrationMessage ( msg , null , null , 30000 ) ; if ( response == null ) { return false ; } // clear out authorizations accumulated for this Call-ID clearAuthorizations ( myRegistrationId ) ; // should we drop any calls in progress? lastRegistrationRequest = null ; return true ; } catch ( Exception ex ) { setReturnCode ( EXCEPTION_ENCOUNTERED ) ; setErrorMessage ( "Exception: " + ex . getClass ( ) . getName ( ) + ": " + ex . getMessage ( ) ) ; return false ; } }
This method performs the SIP unregistration process . It returns true if unregistration was successful or no unregistration was needed and false otherwise . Any authorization headers required for the last registration are cleared out . If there was no previous registration this method does not send any messages .