[reSIProcate] I sek advice on how I can un-register, or logout from SIP proxy
Hi,
I believe I have sucessfully registered with our SIP server, according to
the logs, and the fact that my OnSucess handler got called back.
I need to now have the ability to logout, or UnRegister from the SIP
server. I already wrote the code, but just not sure if I'm
supposed to release the memory allocation of my DUM subclass,
or just keep it around in case I need it.... The test code in the release
obviously cannot show how this is done, I can't figure out how
from just looking at the source code modules.
Here is what I do...
First time startup
--------------------
Log::initialize(Log::Cout, resip::Log::Debug, "SipPhone", "/tmp/siplog");
Which does NOT write the logs into "/tmp/siplog", BTW.. instead it
writes logs into Console, which is also OK with me so far. Is this a
bug?
I'm not showing any error checking in this posting, just the relevant
SIP stack calls. I included the type declarations, and also indicated
which are instance variables.
A little details on my approach. I have a SipBridge object which
contains a combination of Objective C and C++. Methods in Objective
C can reference C++ Objects by pointer only, same the other way.
I also have SipHandlers.cpp file, which is also a Combination C++
and Obj C file.
First time INIT
SipStack *stack = new SipStack; // 'stack' is an instance variable
in my SipBridge class.
ClientAuthManager *clientAuth = new ClientAuthManager; //
'clientAuth' ptr is instance variable
MasterProfile *profile = new MasterProfile; // 'profile' ptr is an
instance variable in same class
Now, here is what I'm not sure of. Right now, I can move this into
the Register function,
but can just keep it here and make the DUM (clientDum) in first-time
initialization.
clientDum = new DialogUsageManager(*stack); // Do I do this in
FIRST TIME init, or in 'register'
clientDum->setMasterProfile(profile); // tell client DUM where my
profile is.
clientDum->setClientAuthManager(
std::auto_ptr<ClientAuthManager>(clientAuth) );
// Normally, I would build this string from the GUI, but because for
some
// reason, I think the DSN is fucked: sip:u354@xxxxxxxxxxxxxx,
goes to web server
// below, it resolves to 213.167.79.10 instead of what you see below,
// So I presume ares needs some attention, but for now, I hard code
it. It works.
NameAddr *from = new NameAddr("sip:u354@xxxxxxxxxxxxx"); // 'from'
ptr is instance var.
clientDum->addTransport(UDP, 5060);
clientDum->getMasterProfile()->setDefaultRegistrationTime(70);
// NOTE: I'm told that if I set this "RegistrationTime" to 0, it
would unRegister,
// IS THAT So?
regHandler = new myRegHandler; // I make my regHandler, but don't
register yet.
// Again, not sure if I need one reghandler per DUM, or if I want to
move this into
// my REGISTER code as shown below.
regHandler->SetDelegate(self); // I need to tell the regHandler
who I am
// so this is a method I added, and not associated with resip. I did
it this way,
// when my attempt to pass in 'self' during construction failed... IE:
// regHandler = new myRegHandler(self); won't compile
clientDum->setClientRegistrationHandler(regHandler); // tell the DUM
where the handler is.
-------------- end of first time initialization --------------
Register code
=============
Below is the code I call when I want to register, or logon to the SIP
proxy..
InfoLog ( << "Register button pressed "); // to let me know I got here
// I do some mac stuff to get Host, UserID, and PW into more
permenent place
strcpy(host, tmphost);
strcpy(userID, tmpuserID);
strcpy(pw, tmppw);
// SetDigestCredential (host, userID, pw)
profile->setDigestCredential(host, userID, pw);
// start the threads.
stackthread = new StackThread(*stack);
stackthread->run();
dumthread = new DumThread(*clientDum);
dumthread->run();
// create our register message
SipMessage & regMessage = clientDum->makeRegistration(*from, new
RegisterAppDialogSet(*clientDum));
InfoLog( << regMessage << "Generated register: " << endl <<
regMessage ); // let me look at it.
clientDum->send( regMessage ); // Now send the register message.
============== Handlers ==============
// ------------------------------------------------------------------------
// Handle sucess conditions. for now, we just log it
// ------------------------------------------------------------------------
void
myRegHandler::onSuccess(ClientRegistrationHandle h, const SipMessage&
response)
{
InfoLog( << "Client::Success: " << endl << response );
// Store our reg handle for later use.
regHandle = h;
// set our state flag to indicate sucessful register.
registered = true;
// Save the registration response.
regResponse = response;
// Now we tell the bridge we are registered. This is that really
funny looking stuff
// called Objctive C, so please don't be offended by such
profanity... :-)
[mBridge weRegistered];
}
============= All of the above works, as far as I can tell
================
Now, here is where things can get confusing.... When I unregister, Do
I still
keep the DUM around, or can I "ditch it" but I would have to
instantiate the
DUM in my REGISTER command.... I prefer to keep the DUM Instance around
which appears to work. I'm just not sure... Ok, so now I have all
these
things... response, original register message, DUM, profile, and
other objects.
What do I do to Unregister.... So far, none of these work, so here
was my
last try, and I ask others to please guide me on usage of this...
This Objective C Method below is in SipBridge
// ----------------------------------------------------------------
// un register me, and log out of the SIP server.
// ----------------------------------------------------------------
- (void)unRegisterMe
{
if (regHandler != NULL) {
ClientRegistrationHandle h = regHandler->getRegHandle();
h->removeAll(); // Does this un-register?
}
}
Is this the proper way to unregister? and if I do this, will this
following regHandler method get called?
// ------------------------------------------------------------------------
// onRemoved handled here.
// ------------------------------------------------------------------------
void
myRegHandler::onRemoved(ClientRegistrationHandle)
{
InfoLog ( << "Client::onRemoved ");
registered = false;
// now we notify the Bridge we unregistered.
[mBridge weUnRegistered];
}
At this point, what happens? Are the duties of the DUM completed? Is
the DUM Still around? What, exactly is being removed? The DUM? The
RegisterMessage? The Response?
Anyway, onRemove is not getting called after I call UnregisterMe method
above, and I need to know in what conditions will cause my "onRemoved"
handler callback to be called.
Regards
John D.