⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 limpc.cxx

📁 这是国外的resip协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
      else if (!strcmp(argv[i],"-prefTls"))      {         prefTls = true;      }      else if (!strcmp(argv[i],"-prefUdp"))      {         prefUdp = true;      }      else if (!strcmp(argv[i],"-noV6"))      {         noV6 = true;      }      else if (!strcmp(argv[i],"-noV4"))      {         noV4 = true;      }      else if (!strcmp(argv[i],"-port"))      {         i++;         assert( i<argc );         port = atoi( argv[i] );      }       else if (!strcmp(argv[i],"-tlsPort"))      {         i++;         assert( i<argc );         tlsPort = atoi( argv[i] );      }      else if (!strcmp(argv[i],"-dtlsPort"))      {	 i++;	 assert( i<argc );	 dtlsPort = atoi( argv[i] );      }      else if (!strcmp(argv[i],"-aor"))      {         i++;         assert( i<argc );         try         {            aor = Uri(Data(argv[i]));         }         catch (...)         {            ErrLog( <<"AOR URI is not valid - must start with sip: ");            exit(-1);         }         haveAor=true;      }       else if (!strcmp(argv[i],"-outbound"))      {         i++;         assert( i<argc );	 try         {            outbound = Uri(Data(argv[i]));         }	 catch (...)	 {	    ErrLog( <<"Outbound URI is not valid - must start with sip: ");	    exit(-1);         }      }       else if (!strcmp(argv[i],"-send"))      {         i++;         assert( i<argc );         sendMsg = Data(argv[i]);      }       else if (!strcmp(argv[i],"-contact"))      {         i++;         assert( i<argc );         try         {            contact = Uri(Data(argv[i]));         }         catch (...)         {            ErrLog( <<"Contact URI is not valid - must start with sip: ");            exit(-1);         }         haveContact=true;      }       else if (!strcmp(argv[i],"-add"))      {         i++;         assert( i<argc );         addList[numAdd++] = Data(argv[i]);         assert( numAdd < 100 );          try         {            // CJ TODO FIX             //Uri uri( Data(argv[i]) );         }         catch (...)         {            ErrLog( <<"URI in -add is not valid - must start with sip: ");            exit(-1);         }      }       else if (!strcmp(argv[i],"-pub"))      {         i++;         assert( i<argc );         pubList[numPub++] = Data(argv[i]);         assert( numPub < 100 );          try         {            // CJ TODO FIX             //Uri uri(Data(argv[i]));         }         catch (...)         {            ErrLog( <<"Pub URI is not valid - must start with sip: ");            exit(-1);         }      }       else if (!strcmp(argv[i],"-aorPassword"))      {         i++;         assert( i<argc );         aorPassword = Data(argv[i]);      }       else if (!strcmp(argv[i],"-to"))      {         i++;         assert( i<argc );         try         {            dest = Uri(Data(argv[i]));          }         catch (...)         {            ErrLog( <<"To URI is not valid - must start with sip: ");            exit(-1);         }      }       else if (!strcmp(argv[i],"-key"))      {         i++;         assert( i<argc );         key = Data(argv[i]);      }       else      {          clog <<"Bad command line opion: " << argv[i] << endl;         clog <<"options are: " << endl              << "\t [-v] [-vv] [-tls] [-port 5060] [-tlsport 5061]" << endl              << "\t [-aor sip:alice@example.com] [-aorPassword password]" << endl              << "\t [-to sip:friend@example.com] [-add sip:buddy@example.com]" << endl              << "\t [-sign] [-encrypt] [-key secret]" << endl              << "\t [-contact sip:me@example.com] " << endl              << "\t [-outbound \"sip:example.com;lr\"] " << endl              << "\t [-noRegister] " << endl              << "\t [-pub sip:foo.com] " << endl              << "\t [-tlsDomain foo.com] " << endl              << "\t [-send myMessage] " << endl;          clog << endl              << " -v is verbose" << endl              << " -vv is very verbose" << endl              << " -noV6 don't use IPv6" << endl              << " -noV4 don't use IPv4" << endl              << " -noUdp don't use UDP" << endl              << " -noTcp don't use TCP" << endl              << " -noTls don't use TLS" << endl              << " -prefUdp prefer UDP" << endl              << " -prefTcp prefer TCP" << endl              << " -prefTls prefer TLS" << endl              << " -port sets the UDP and TCP port to listen on" << endl              << " -tlsPort sets the port to listen for TLS on" << endl              << " -tlsDomain domainName - sets tls and dtls to act as tls server instead of client" << endl              << " -ssl - use ssl instead of tls" << endl              << " -aor sets the proxy and user name to register with" << endl              << " -aorPassword sets the password to use for registration" << endl              << " -noRegister causes it not to register - by default the AOR is registered" << endl              << " -to sets initial location to send messages to" << endl              << " -outbound sets the outbound proxy" << endl              << " -add adds a budy who's presence will be monitored" << endl              << " -pub adds a State Agent to send publishes too" << endl              << " -sign signs message you send and -encryp encrypt them " << endl              << " -send takes a string (needs to be quoted if it has spaces) "               <<                                      "and sends it as an IM " << endl              << "\t(You need PKI certs for this to work)" << endl              << " -key allows you to enter a secret used to load your private key."<< endl              << "  If you set the secret to - the system will querry you for it."<< endl              << " -contact overrides your SIP contact - can be used for NAT games" << endl              << "\t there can be many -add " << endl              << " -genUserCert - generate a new user cert" << endl              << " " << endl              << "Examples" << endl              << "An example command line for a user with account name alice at example.com is:" << endl              << "\t" << argv[0] << " -aor \"alice@example.com\" -aorPassword \"secret\"" << endl              << "to watch the presence of bob and charlie add" << endl              << "\t-add \"sip:bob@bilboxi.com\" -add \"charlie@example.com\" " << endl              << "If Alice was behind a NAT that had a public address of 1.2.3.4 and had forwarded" << endl              << "port 5070 on this NAT to the machine Alice was using, then the following " << endl              << "options would be added" << endl              << "\t-contact \"sip:alice@1.2.3.4:5070\" -port 5070" << endl              << "" << endl              << endl;         exit(1);      }   }      //InfoLog( << "Using port " << port );  #ifdef USE_SSL   InfoLog( << "Setting up Security" );   Security* security=NULL;   try   {      char cert_dir[ 1024 ] ;      char *home_dir = getenv( "HOME" ) ;      cert_dir[ 0 ] = '\0' ;      ::strcat( cert_dir, home_dir ) ;      ::strcat( cert_dir, "/.sipCerts/" ) ;      security = new Security( cert_dir ) ;      //  ::free( home_dir ) ; // CJ TODO mem leak    }   catch( ... )   {      security = NULL;      ErrLog( << "Got a exception setting up Security" );   }   SipStack sipStack( security );  #else   SipStack sipStack( false /*multihtread*/ );  #endif   if ( key == Data("-") )   {      clog << "Please enter password to use to load your private key: ";      char buf[1024];      cin.get(buf,1024);      key = Data(buf);      InfoLog( << "Certificate key set to <" << key << ">" );   }   #ifdef USE_SSL   try   {      Security* security = sipStack.getSecurity();      assert(security != 0);   }   catch( ... )   {      ErrLog( << "Got an exception creating security object " );   }   try   {      assert(security != 0);      security->preload();   }   catch( ... )   {      ErrLog( << "Got a exception pre loading certificates" );   }   if (genUserCert)   {      assert( security );      security->generateUserCert(aor.getAor());   }#endif   DebugLog( << "About to add the transports " );      if (port!=0)   {      if ( noUdp != true )      {         if (!noV4) sipStack.addTransport(UDP, port, V4);#ifdef USE_IPV6         if (!noV6) sipStack.addTransport(UDP, port, V6);#endif      }      if ( noTcp != true )      {         if (!noV4) sipStack.addTransport(TCP, port, V4);#ifdef USE_IPV6         if (!noV6) sipStack.addTransport(TCP, port, V6);#endif      }   }#if USE_SSL   if ( tlsPort != 0 )   {      if ( noTls != true )      {         if (!noV4)          {            sipStack.addTransport(TLS, tlsPort, V4, StunDisabled, Data::Empty, tlsDomain );         }	 //if (!noV6) sipStack.addTlsTransport(tlsPort,Data::Empty,Data::Empty,Data::Empty,V6);      }   }#if USE_DTLS   if ( dtlsPort != 0 )   {      if ( noTls != true )      {         if (!noV4)          {            sipStack.addTransport(DTLS, dtlsPort, V4, Data::Empty, tlsDomain );         }      }   }#endif#endif   DebugLog( << "Done adding the transports " );      if (!haveContact)   {      // contact.port() = port;      // contact.host() = sipStack.getHostname();   }      if ( haveAor )   {      if (!haveContact)      {         contact.user() = aor.user();#if USE_SSL         if ( aor.scheme() == "sips" )         {            contact.scheme() = aor.scheme();            //contact.port() = tlsPort;         }#endif      }   }   else   {      aor.port() = port;      aor.host() = sipStack.getHostname();      aor.user() = Data("user");   }   InfoLog( << "aor is " << aor );   InfoLog( << "contact is " << contact );   TestCallback callback;   tuIM = new TuIM(&sipStack,aor,contact,&callback);   Data name("SIPimp.org/0.2.5 (curses)");   tuIM->setUAName( name );         if ( !outbound.host().empty() )   {      tuIM->setOutboundProxy( outbound );   }   // setup prefered outbound transport    if ( prefUdp )   {      tuIM->setDefaultProtocol( UDP );   }   if ( prefTcp )   {      tuIM->setDefaultProtocol( TCP );   }   if ( prefTls )   {      tuIM->setDefaultProtocol( TLS );   }   if ( prefDtls )   {      tuIM->setDefaultProtocol( DTLS );   }   if ( haveAor )   {      if ( !noRegister )      {         tuIM->registerAor( aor, aorPassword );      }   }      initscr();    cbreak();    noecho();   nonl();   intrflush(stdscr, FALSE);   keypad(stdscr, TRUE);   int rows=0;   int cols=0;   getmaxyx(stdscr,rows,cols);		/* get the number of rows and columns */           commandWin = newwin(2,cols,rows-2,0);   scrollok(commandWin, TRUE);   wmove(commandWin,0,0);        textWin = newwin(rows-3,cols*3/4,0,0);   scrollok(textWin, TRUE);   wmove(textWin,0,0);        statusWin = newwin(rows-3,cols-(cols*3/4)-1,0,1+cols*3/4);   scrollok(statusWin, FALSE);   wmove(statusWin,0,0);   mvhline(rows-3,0,ACS_HLINE,cols);   mvvline(0,(cols*3/4),ACS_VLINE,rows-3);   refresh();   for ( int i=0; i<numAdd; i++ )   {       Uri uri(addList[i]);      tuIM->addBuddy( uri, Data::Empty );   }   for ( int i=0; i<numPub; i++ )   {       Uri uri(pubList[i]);      tuIM->addStateAgent( uri );   }   displayPres();    waddstr(textWin,"Use -help on the command line to view options\n");   waddstr(textWin,"To set where your messages will get sent type\n");   waddstr(textWin,"    to: sip:alice@example.com \n");   waddstr(textWin,"To monitores someeone presence type\n");   waddstr(textWin,"    add: sip:buddy@example.com \n");   waddstr(textWin,"To change you online status type\n");   waddstr(textWin,"    status: in meeting\n");   waddstr(textWin,"To set yourself to offline type\n");   waddstr(textWin,"   status:\n");   waddstr(textWin,"To exit type a single period\n");   waddstr(textWin,"\n");   wrefresh(textWin);        if ( !sendMsg.empty() )   {         tuIM->sendPage( sendMsg , dest, sign , (encryp) ?                         (dest.getAorNoPort()) : (Data::Empty) );   }      while (1)   {      FdSet fdset;       sipStack.buildFdSet(fdset);      int time = sipStack.getTimeTillNextProcessMS();      fdset.setRead( fileno(stdin) );            //cerr << time << endl;      int  err = fdset.selectMilliSeconds( time );      if ( err == -1 )      {         int e = errno;         switch (e)         {            case 0:               break;            default:               //InfoLog(<< "Error " << e << " " << strerror(e) << " in select");               break;         }      }      if ( err == 0 )      {         //cerr << "select timed out" << endl;      }      if ( err > 0 )      {         //cerr << "select has " << err << " fd ready" << endl;      }            ////InfoLog(<< "Select returned");             if ( fdset.readyToRead( fileno(stdin) ) )      {         bool keepGoing = processStdin(&dest,sign,encryp);         if (!keepGoing)          {            break;         }       }             // //DebugLog ( << "Try TO PROCESS " );      try      {         sipStack.process(fdset);      }      catch (...)      {         ErrLog( << "Got a exception from sipStack::process" );      }            try      {         tuIM->process();             }      catch (...)      {         ErrLog( << "Got a exception passed from TuIM::process" );      }   }   return 0;}/* ==================================================================== * The Vovida Software License, Version 1.0  *  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. *  * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. *  * 3. The names "VOCAL", "Vovida Open Communication Application Library", *    and "Vovida Open Communication Application Library (VOCAL)" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor *    may "VOCAL" appear in their name, without prior written *    permission of Vovida Networks, Inc. *  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *  * ==================================================================== *  * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc.  For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -