reSIProcate/stack  9694
testDtlsTransport.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #include <sys/types.h>
00006 #include <iostream>
00007 #include <memory>
00008 
00009 #include "rutil/DnsUtil.hxx"
00010 #include "rutil/Inserter.hxx"
00011 #include "rutil/Logger.hxx"
00012 #include "resip/stack/Helper.hxx"
00013 #include "resip/stack/SipMessage.hxx"
00014 #include "resip/stack/SipStack.hxx"
00015 #include "resip/stack/Uri.hxx"
00016 #ifdef USE_SSL
00017 #include "resip/stack/ssl/Security.hxx"
00018 #endif
00019 
00020 using namespace resip;
00021 using namespace std;
00022 
00023 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
00024 
00025 
00026 int
00027 main(int argc, char* argv[])
00028 {
00029    Log::initialize(Log::Cout, Log::Info ,"testDtlsTransport");   
00030 
00031 #ifdef USE_DTLS
00032    Security* serverSecurity = new Security();
00033    SipStack serverStack(serverSecurity);
00034 
00035    serverStack.addTransport(DTLS, 15060, V4, StunDisabled, Data::Empty, "127.0.0.1");
00036    SipStack clientStack(serverSecurity);
00037    clientStack.addTransport(DTLS, 25060, V4);
00038    
00039    NameAddr target("sip:bob@127.0.0.1:15060;transport=dtls");
00040    NameAddr from("sip:alice@127.0.0.1");
00041    NameAddr contact;
00042    contact.uri().user() = "alice";
00043    
00044    SipMessage * msg = Helper::makeRequest(target, from, contact, INVITE);
00045    clientStack.send(*msg);
00046    delete msg;
00047    
00048    while(true)
00049    {
00050       {
00051          FdSet fdset; 
00052          serverStack.buildFdSet(fdset);
00053          fdset.selectMilliSeconds(50);
00054          serverStack.process(fdset);
00055       }
00056       
00057       SipMessage* msg = serverStack.receive();
00058       if (msg && msg->isRequest())
00059       {
00060          SipMessage* resp = Helper::makeResponse(*msg, 400);
00061          serverStack.send(*resp);
00062          InfoLog( << "Generated 400 to: " << msg->brief());
00063          delete resp;
00064       }
00065       delete msg;
00066       
00067       {
00068          FdSet fdset; 
00069          clientStack.buildFdSet(fdset);
00070          fdset.selectMilliSeconds(50);
00071          clientStack.process(fdset);
00072       }
00073 
00074       msg = clientStack.receive();
00075       if (msg)
00076       {
00077          InfoLog( << "Got from server: " << msg->brief());
00078          break;         
00079       }
00080    }
00081 #endif
00082    return 0;
00083 }
00084 /* ====================================================================
00085  * The Vovida Software License, Version 1.0 
00086  * 
00087  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00088  * 
00089  * Redistribution and use in source and binary forms, with or without
00090  * modification, are permitted provided that the following conditions
00091  * are met:
00092  * 
00093  * 1. Redistributions of source code must retain the above copyright
00094  *    notice, this list of conditions and the following disclaimer.
00095  * 
00096  * 2. Redistributions in binary form must reproduce the above copyright
00097  *    notice, this list of conditions and the following disclaimer in
00098  *    the documentation and/or other materials provided with the
00099  *    distribution.
00100  * 
00101  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00102  *    and "Vovida Open Communication Application Library (VOCAL)" must
00103  *    not be used to endorse or promote products derived from this
00104  *    software without prior written permission. For written
00105  *    permission, please contact vocal@vovida.org.
00106  *
00107  * 4. Products derived from this software may not be called "VOCAL", nor
00108  *    may "VOCAL" appear in their name, without prior written
00109  *    permission of Vovida Networks, Inc.
00110  * 
00111  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00112  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00113  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00114  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00115  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00116  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00117  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00118  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00119  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00120  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00121  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00122  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00123  * DAMAGE.
00124  * 
00125  * ====================================================================
00126  * 
00127  * This software consists of voluntary contributions made by Vovida
00128  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00129  * Inc.  For more information on Vovida Networks, Inc., please see
00130  * <http://www.vovida.org/>.
00131  *
00132  */