|
reSIProcate/DialogUsageManager
9694
|
#include "resip/dum/DialogUsageManager.hxx"#include "resip/dum/ClientRegistration.hxx"#include "resip/dum/ClientInviteSession.hxx"#include "resip/dum/ServerInviteSession.hxx"#include "resip/dum/ClientAuthManager.hxx"#include "resip/dum/RegistrationHandler.hxx"#include "resip/dum/InviteSessionHandler.hxx"#include "resip/dum/DumShutdownHandler.hxx"#include "resip/dum/MasterProfile.hxx"#include "resip/stack/ShutdownMessage.hxx"#include "resip/stack/SdpContents.hxx"#include "resip/stack/Pkcs7Contents.hxx"#include "resip/stack/MultipartSignedContents.hxx"#include "resip/stack/MultipartAlternativeContents.hxx"#include "resip/stack/Mime.hxx"#include "resip/stack/SecurityAttributes.hxx"#include "resip/stack/Helper.hxx"#include "rutil/FdPoll.hxx"#include "rutil/Log.hxx"#include "rutil/Logger.hxx"#include "resip/stack/ssl/Security.hxx"#include "TestDumHandlers.hxx"#include <time.h>#include <sstream>
Go to the source code of this file.
Classes | |
| class | TestSMIMEInviteHandler |
Defines | |
| #define | RESIPROCATE_SUBSYSTEM Subsystem::TEST |
Functions | |
| int | main (int argc, char **argv) |
| #define RESIPROCATE_SUBSYSTEM Subsystem::TEST |
Definition at line 45 of file testSMIMEInvite.cxx.
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Definition at line 232 of file testSMIMEInvite.cxx.
References TestSMIMEInviteHandler::generateBody(), TestSMIMEInviteHandler::handles, resip::Uri::host(), InfoLog, TestSMIMEInviteHandler::isCallFailed(), TestSMIMEInviteHandler::isConnected(), TestSMIMEInviteHandler::isDone(), TestSMIMEInviteHandler::isDumShutDown(), TestSMIMEInviteHandler::isRegistered(), resipMin(), TestSMIMEInviteHandler::sis, TCP, TLS, UDP, resip::NameAddr::uri(), resip::Uri::user(), V4, and V6.
{
if ( argc < 5 ) {
cout << "usage: " << argv[0] << " sip:user1 passwd1 sip:user2 passwd2" << endl;
return 1;
}
Log::initialize(Log::Cout, Log::Debug, argv[0]);
NameAddr clientAor(argv[1]);
Data clientPasswd(argv[2]);
NameAddr serverAor(argv[3]);
Data serverPasswd(argv[4]);
#ifdef WIN32
Security* security = new WinSecurity;
#else
Security* security = new Security;
#endif
TestSMIMEInviteHandler handler(security);
// Shared FdPollGrp
std::auto_ptr<FdPollGrp> pollGrp(FdPollGrp::create());
// set up UAC
SipStack clientStack(security,
DnsStub::EmptyNameserverList,
0,
false,
0,
0,
pollGrp.get());
DialogUsageManager clientDum(clientStack);
srand(time(NULL));
clientDum.addTransport(UDP, 0, V4);
clientDum.addTransport(TCP, 0, V4);
clientDum.addTransport(TLS, 0, V4);
#ifdef USE_IPV6
clientDum.addTransport(UDP, 0, V6);
clientDum.addTransport(TCP, 0, V6);
clientDum.addTransport(TLS, 0, V6);
#endif
SharedPtr<MasterProfile> clientProfile(new MasterProfile);
auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager());
clientDum.setClientAuthManager(clientAuth);
clientDum.setClientRegistrationHandler(&handler);
clientDum.setInviteSessionHandler(&handler);
clientProfile->setDefaultFrom(clientAor);
clientProfile->setDigestCredential(clientAor.uri().host(),clientAor.uri().user(),clientPasswd);
clientProfile->setDefaultRegistrationTime(60);
clientProfile->addSupportedMethod(INVITE);
clientProfile->addSupportedMimeType(INVITE, Mime("application", "pkcs7-mime"));
clientProfile->addSupportedMimeType(INVITE, Mime("multipart", "signed"));
clientProfile->addSupportedMimeType(INVITE, Mime("multipart", "alternative"));
clientDum.setMasterProfile(clientProfile);
//set up UAS
SipStack serverStack(security,
DnsStub::EmptyNameserverList,
0,
false,
0,
0,
pollGrp.get());
DialogUsageManager serverDum(serverStack);
//serverDum.addTransport(UDP, 0, V4);
serverDum.addTransport(TCP, 0, V4);
//serverDum.addTransport(TLS, 0, V4);
SharedPtr<MasterProfile> serverProfile(new MasterProfile);
std::auto_ptr<ClientAuthManager> serverAuth(new ClientAuthManager);
serverDum.setClientAuthManager(serverAuth);
serverDum.setClientRegistrationHandler(&handler);
serverDum.setInviteSessionHandler(&handler);
serverProfile->setDefaultFrom(serverAor);
serverProfile->setDigestCredential(serverAor.uri().host(),serverAor.uri().user(),serverPasswd);
serverProfile->setDefaultRegistrationTime(60);
serverProfile->addSupportedMethod(INVITE);
serverProfile->addSupportedMimeType(INVITE, Mime("application", "pkcs7-mime"));
serverProfile->addSupportedMimeType(INVITE, Mime("multipart", "signed"));
serverProfile->addSupportedMimeType(INVITE, Mime("multipart", "alternative"));
serverDum.setMasterProfile(serverProfile);
enum
{
Registering,
Inviting,
Waiting,
HangingUp,
Unregistering,
ShuttingDown,
Finished
} state;
time_t endTime=0;
// register client and server
SharedPtr<SipMessage> clientRegMessage = clientDum.makeRegistration(clientAor);
clientDum.send(clientRegMessage);
SharedPtr<SipMessage> serverRegMessage = serverDum.makeRegistration(serverAor);
serverDum.send(serverRegMessage);
state = Registering;
while (state != Finished)
{
// This waits on IO for both stacks; this is the canonical way to drive
// multiple stacks with the same thread. We could make two calls to
// process(), but this requires more calls to epoll_wait/select.
pollGrp->waitAndProcess(resipMin(clientStack.getTimeTillNextProcessMS(),
serverStack.getTimeTillNextProcessMS()));
clientStack.processTimers();
serverStack.processTimers();
while(clientDum.process() || serverDum.process());
switch (state)
{
case Registering:
{
if (handler.isRegistered())
{
InfoLog( << "Sending INVITE request" );
clientDum.send(clientDum.makeInviteSession(serverAor,
handler.generateBody()));
state = Inviting;
}
break;
}
case Inviting:
{
if (handler.isConnected())
{
InfoLog( << "Starting timer, waiting for 5 seconds" );
endTime = time(NULL) + 5;
state = Waiting;
}
break;
}
case Waiting:
{
if (handler.isCallFailed())
{
InfoLog( << "Call Failed" );
for (std::vector<ClientRegistrationHandle>::iterator it = handler.handles.begin();
it != handler.handles.end(); it++)
{
(*it)->end();
}
state = Unregistering;
}
if (time(NULL) > endTime)
{
InfoLog( << "Timer expired, hanging up" );
handler.sis->end();
state = HangingUp;
}
break;
}
case HangingUp:
{
if (handler.isDone())
{
for (std::vector<ClientRegistrationHandle>::iterator it = handler.handles.begin();
it != handler.handles.end(); it++)
{
(*it)->end();
}
state = Unregistering;
}
break;
}
case Unregistering:
{
if (handler.isRegistered())
{
InfoLog( << "Shutting down" );
serverDum.shutdown(&handler);
clientDum.shutdown(&handler);
state = ShuttingDown;
}
break;
}
case ShuttingDown:
{
if (handler.isDumShutDown())
{
InfoLog( << "Finished" );
state = Finished;
}
break;
}
default:
{
InfoLog( << "Unrecognised state" );
assert(0);
}
}
}
return 0;
}

1.7.5.1