reSIProcate/stack  9694
Defines | Functions
dumpTls.cxx File Reference
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
#include <memory>
#include <sys/ioctl.h>
#include <signal.h>
#include "rutil/DnsUtil.hxx"
#include "rutil/Inserter.hxx"
#include "rutil/Logger.hxx"
#include "resip/stack/Helper.hxx"
#include "resip/stack/SipMessage.hxx"
#include "resip/stack/SipStack.hxx"
#include "resip/stack/Uri.hxx"
#include "resip/stack/ShutdownMessage.hxx"
#include "resip/stack/ssl/Security.hxx"
Include dependency graph for dumpTls.cxx:

Go to the source code of this file.

Defines

#define RESIPROCATE_SUBSYSTEM   Subsystem::SIP

Functions

int main (int argc, char *argv[])

Define Documentation

#define RESIPROCATE_SUBSYSTEM   Subsystem::SIP

Definition at line 38 of file dumpTls.cxx.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 41 of file dumpTls.cxx.

References resip::SipStack::addTransport(), resip::SipStack::buildFdSet(), context, DebugLog, ErrLog, errno, resip::RequestLine::getMethod(), resip::SipMessage::header(), resip::Uri::host(), InfoLog, resip::Log::initialize(), resip::SipMessage::isRequest(), resip::SipMessage::isResponse(), resip::Helper::makeRegister(), resip::Helper::makeResponse(), resip::RequestLine::method(), resip::ParserCategory::param(), resip::Uri::port(), resip::SipStack::process(), resip::SipStack::receive(), resip::Uri::scheme(), resip::FdSet::selectMilliSeconds(), resip::SipStack::send(), resip::StunDisabled, resip::TLS, resip::NameAddr::uri(), resip::Uri::user(), and resip::V4.

Referenced by main().

{
#ifdef USE_SSL
   const char *logType = "cerr";
   const char *logLevel = "DEBUG";
   const char *certPath = ".";
   int  clientPort = 15001;
   int  serverPort = 5061;
   const char *clientDomain = "example.net";
   const char *serverDomain = "example.com";

#if defined(HAVE_POPT_H)
   struct poptOption table[] = {
      {"log-type",     'l', POPT_ARG_STRING, &logType,       0, "where to send logging messages", "syslog|cerr|cout"},
      {"log-level",    'v', POPT_ARG_STRING, &logLevel,      0, "specify the default log level", "DEBUG|INFO|WARNING|ALERT"},
      {"cert-path",    'p', POPT_ARG_STRING, &certPath,      0, "path to the server certificates", "."},
      {"client-port",  'f', POPT_ARG_INT,    &clientPort,    0, "client port (send request from)", "15001"},
      {"server-port",  't', POPT_ARG_INT,    &serverPort,    0, "server port (send request to)", "5061"},
      {"client-domain",'c', POPT_ARG_STRING, &clientDomain,  0, "client domain", "example.net"},
      {"server-domain",'s', POPT_ARG_STRING, &serverDomain,  0, "server domain", "example.com"},
      POPT_AUTOHELP
      { NULL, 0, 0, NULL, 0 }
   };
   
   poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0);
   poptGetNextOpt(context);
#endif

   Log::initialize(logType, logLevel, argv[0]);

   DebugLog(<< "Logs initialized");
   DebugLog(<< "logLevel = " << logLevel);
   DebugLog(<< "certPath = " << certPath);

   DebugLog(<< "Starting ssldump");
   
   int dumpPid = fork();

   if (dumpPid==-1)
   {
     DebugLog(<< "Can't fork to run ssldump"); exit(-1);
   }

   if (dumpPid==0)
   {
     // todo - make this something that can come on the command line
     const char *args[] = { "ssldump","-A","-i","lo0",NULL };
     // .kw. execvp takes a 'char* const *' -- for some reason it doesn't
     // promise to not modify the strings. Thus shouldn't use static string
     // initializers above!
     int ret = execvp("ssldump",const_cast<char**>(args));
     ErrLog(<< "Can't execvp: return is " << ret <<" errno is " << errno);
     exit(-1);
   }

   DebugLog(<< "ssldump's pid is " << dumpPid);
 
   IpVersion version = V4;
   Data bindInterface;
   //bindInterface = Data( "127.0.0.1" );
         
   SipStack* clientStack;
   SipStack* serverStack;

   Security* clientSecurity = new Security(certPath);
   Security* serverSecurity = new Security(certPath);
   clientStack = new SipStack(clientSecurity);
   serverStack = new SipStack(serverSecurity);

   clientStack->addTransport(TLS, clientPort, version, StunDisabled, bindInterface, clientDomain);
   serverStack->addTransport(TLS, serverPort, version, StunDisabled, bindInterface, serverDomain);
 
   NameAddr target;
   target.uri().scheme() = "sip";
   target.uri().user() = "fluffy";
   target.uri().host() = serverDomain;
   target.uri().port() = serverPort;
   target.uri().param(p_transport) = "tls";

   NameAddr contact;
   contact.uri().scheme() = "sip";
   contact.uri().user() = "fluffy";
   contact.uri().host() = clientDomain;
   contact.uri().port() = clientPort;

   NameAddr from = target;
   from.uri().port() = clientPort;
   
   InfoLog (<< "Starting" );

   SipMessage* msg = Helper::makeRegister( target, from, contact);
   clientStack->send(*msg);
   delete msg;
      
   bool done=false;
   int rundown = 0;
   while ( (!done) || (rundown-- > 0) )
   {

      FdSet fdset; 

      clientStack->buildFdSet(fdset);
      serverStack->buildFdSet(fdset);

      fdset.selectMilliSeconds(100); 


      serverStack->process(fdset);
      SipMessage *msg = serverStack->receive();
      if ( !msg ) 
      {
          clientStack->process(fdset);
          msg = clientStack->receive();
      }
   
      if ( msg )
      {
         if ( msg->isRequest() )
         {  
            assert(msg->isRequest());
            assert(msg->header(h_RequestLine).getMethod() == REGISTER);
            
            SipMessage* response = Helper::makeResponse(*msg, 200);
            serverStack->send(*response);
            delete response;
            delete msg;
         }
         else
         { 
            assert(msg->isResponse());
            assert(msg->header(h_CSeq).method() == REGISTER);
            if (msg->header(h_StatusLine).statusCode() < 200)
            {
              DebugLog(<<"Provisional response to a REGISTER - you're kidding me, right?");
            }
            else
            {
              done = true;
              rundown = 100;
            }
            delete msg;
         }
      }
   }
   InfoLog (<< "Finished " );
   
#if defined(HAVE_POPT_H)
   poptFreeContext(context);
#endif
   sleep(2);
   delete serverStack; //btw - this deletes the security object
   delete clientStack;
   sleep(5);

   if (dumpPid>0)

   {
     DebugLog( << "Trying to kill process id " << dumpPid);
     int ret = kill(dumpPid, SIGINT); // ssldump catches INT and does an fflush
     DebugLog( << "Kill returned: " << ret);
   }


#endif
   return 0;
}

Here is the call graph for this function: