reSIProcate/stack  9694
testSipStack1.cxx
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <memory>
00003 
00004 #ifndef WIN32
00005 #include <sys/time.h>
00006 #include <sys/types.h>
00007 #include <unistd.h>
00008 #endif
00009 
00010 #include "rutil/Socket.hxx"
00011 #include "rutil/Logger.hxx"
00012 
00013 #include "resip/stack/SipStack.hxx"
00014 #include "resip/stack/SipMessage.hxx"
00015 #include "resip/stack/Uri.hxx"
00016 #include "resip/stack/Helper.hxx"
00017 #include "resip/stack/Transport.hxx"
00018 #include "resip/stack/ParserCategories.hxx"
00019 
00020 
00021 using namespace resip;
00022 using namespace std;
00023 
00024 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
00025 
00026 int
00027 main(int argc, char* argv[])
00028 {
00029     Log::Level l = Log::Debug;
00030     
00031     if (argc > 1)
00032     {
00033         switch(*argv[1])
00034         {
00035             case 'd': l = Log::Debug;
00036                 break;
00037             case 'i': l = Log::Info;
00038                 break;
00039             case 's': l = Log::Stack;
00040                 break;
00041             case 'c': l = Log::Crit;
00042                 break;
00043         }
00044         
00045     }
00046     
00047     Log::initialize(Log::Cout, l, argv[0]);
00048     CritLog(<<"Test Driver Starting");
00049 
00050    initNetwork();
00051         
00052    try
00053    {
00054       SipStack sipStack;
00055       SipMessage* msg=NULL;
00056 
00057       InfoLog ( << "Try to send a message" );
00058               
00059       NameAddr dest;
00060       NameAddr from;
00061       NameAddr contact;
00062       from.uri().scheme() = "sip";
00063       from.uri().user() = "fluffy";
00064       from.uri().host() = "localhost";
00065       from.uri().port() = 5060;
00066             
00067       dest = from;
00068       contact = from;
00069             
00070       auto_ptr<SipMessage> message = auto_ptr<SipMessage>(Helper::makeInvite( dest, from, contact));
00071       DebugLog ( << "Sending msg:" << *message );
00072       sipStack.send( *message );
00073 
00074       while (1)
00075       {
00076          //DebugLog ( << "Try TO PROCESS " );
00077          sipStack.process(25);
00078 
00079          //DebugLog ( << "Try TO receive " );
00080          msg = sipStack.receive();
00081          if ( msg )
00082          {
00083             DebugLog ( << "got message: " << *msg);
00084             msg->encode(resipCout);       
00085          }
00086       }
00087    }
00088    catch (Transport::Exception& e)
00089    {
00090       InfoLog (<< "Failed to create sip stack" << e);
00091       exit(-1);
00092    }
00093    return 0;
00094 
00095 }
00096 
00097 
00098 /* ====================================================================
00099  * The Vovida Software License, Version 1.0 
00100  * 
00101  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00102  * 
00103  * Redistribution and use in source and binary forms, with or without
00104  * modification, are permitted provided that the following conditions
00105  * are met:
00106  * 
00107  * 1. Redistributions of source code must retain the above copyright
00108  *    notice, this list of conditions and the following disclaimer.
00109  * 
00110  * 2. Redistributions in binary form must reproduce the above copyright
00111  *    notice, this list of conditions and the following disclaimer in
00112  *    the documentation and/or other materials provided with the
00113  *    distribution.
00114  * 
00115  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00116  *    and "Vovida Open Communication Application Library (VOCAL)" must
00117  *    not be used to endorse or promote products derived from this
00118  *    software without prior written permission. For written
00119  *    permission, please contact vocal@vovida.org.
00120  *
00121  * 4. Products derived from this software may not be called "VOCAL", nor
00122  *    may "VOCAL" appear in their name, without prior written
00123  *    permission of Vovida Networks, Inc.
00124  * 
00125  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00126  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00127  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00128  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00129  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00130  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00131  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00132  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00133  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00134  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00135  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00136  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00137  * DAMAGE.
00138  * 
00139  * ====================================================================
00140  * 
00141  * This software consists of voluntary contributions made by Vovida
00142  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00143  * Inc.  For more information on Vovida Networks, Inc., please see
00144  * <http://www.vovida.org/>.
00145  *
00146  */