~ubuntu-branches/ubuntu/saucy/resiprocate/saucy-proposed

« back to all changes in this revision

Viewing changes to resip/stack/test/testDtlsTransport.cxx

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2012-05-17 19:29:59 UTC
  • Revision ID: package-import@ubuntu.com-20120517192959-vv00m77isztdy64q
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if defined(HAVE_CONFIG_H)
 
2
#include "config.h"
 
3
#endif
 
4
 
 
5
#include <sys/types.h>
 
6
#include <iostream>
 
7
#include <memory>
 
8
 
 
9
#include "rutil/DnsUtil.hxx"
 
10
#include "rutil/Inserter.hxx"
 
11
#include "rutil/Logger.hxx"
 
12
#include "resip/stack/Helper.hxx"
 
13
#include "resip/stack/SipMessage.hxx"
 
14
#include "resip/stack/SipStack.hxx"
 
15
#include "resip/stack/Uri.hxx"
 
16
#ifdef USE_SSL
 
17
#include "resip/stack/ssl/Security.hxx"
 
18
#endif
 
19
 
 
20
using namespace resip;
 
21
using namespace std;
 
22
 
 
23
#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
 
24
 
 
25
 
 
26
int
 
27
main(int argc, char* argv[])
 
28
{
 
29
   Log::initialize(Log::Cout, Log::Info ,"testDtlsTransport");   
 
30
 
 
31
#ifdef USE_DTLS
 
32
   Security* serverSecurity = new Security();
 
33
   SipStack serverStack(serverSecurity);
 
34
 
 
35
   serverStack.addTransport(DTLS, 15060, V4, StunDisabled, Data::Empty, "127.0.0.1");
 
36
   SipStack clientStack(serverSecurity);
 
37
   clientStack.addTransport(DTLS, 25060, V4);
 
38
   
 
39
   NameAddr target("sip:bob@127.0.0.1:15060;transport=dtls");
 
40
   NameAddr from("sip:alice@127.0.0.1");
 
41
   NameAddr contact;
 
42
   contact.uri().user() = "alice";
 
43
   
 
44
   SipMessage * msg = Helper::makeRequest(target, from, contact, INVITE);
 
45
   clientStack.send(*msg);
 
46
   delete msg;
 
47
   
 
48
   while(true)
 
49
   {
 
50
      {
 
51
         FdSet fdset; 
 
52
         serverStack.buildFdSet(fdset);
 
53
         fdset.selectMilliSeconds(50);
 
54
         serverStack.process(fdset);
 
55
      }
 
56
      
 
57
      SipMessage* msg = serverStack.receive();
 
58
      if (msg && msg->isRequest())
 
59
      {
 
60
         SipMessage* resp = Helper::makeResponse(*msg, 400);
 
61
         serverStack.send(*resp);
 
62
         InfoLog( << "Generated 400 to: " << msg->brief());
 
63
         delete resp;
 
64
      }
 
65
      delete msg;
 
66
      
 
67
      {
 
68
         FdSet fdset; 
 
69
         clientStack.buildFdSet(fdset);
 
70
         fdset.selectMilliSeconds(50);
 
71
         clientStack.process(fdset);
 
72
      }
 
73
 
 
74
      msg = clientStack.receive();
 
75
      if (msg)
 
76
      {
 
77
         InfoLog( << "Got from server: " << msg->brief());
 
78
         break;         
 
79
      }
 
80
   }
 
81
#endif
 
82
   return 0;
 
83
}
 
84
/* ====================================================================
 
85
 * The Vovida Software License, Version 1.0 
 
86
 * 
 
87
 * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
 
88
 * 
 
89
 * Redistribution and use in source and binary forms, with or without
 
90
 * modification, are permitted provided that the following conditions
 
91
 * are met:
 
92
 * 
 
93
 * 1. Redistributions of source code must retain the above copyright
 
94
 *    notice, this list of conditions and the following disclaimer.
 
95
 * 
 
96
 * 2. Redistributions in binary form must reproduce the above copyright
 
97
 *    notice, this list of conditions and the following disclaimer in
 
98
 *    the documentation and/or other materials provided with the
 
99
 *    distribution.
 
100
 * 
 
101
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
 
102
 *    and "Vovida Open Communication Application Library (VOCAL)" must
 
103
 *    not be used to endorse or promote products derived from this
 
104
 *    software without prior written permission. For written
 
105
 *    permission, please contact vocal@vovida.org.
 
106
 *
 
107
 * 4. Products derived from this software may not be called "VOCAL", nor
 
108
 *    may "VOCAL" appear in their name, without prior written
 
109
 *    permission of Vovida Networks, Inc.
 
110
 * 
 
111
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
 
112
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
113
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
 
114
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
 
115
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
 
116
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
 
117
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
118
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
119
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
120
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
121
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 
122
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 
123
 * DAMAGE.
 
124
 * 
 
125
 * ====================================================================
 
126
 * 
 
127
 * This software consists of voluntary contributions made by Vovida
 
128
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
 
129
 * Inc.  For more information on Vovida Networks, Inc., please see
 
130
 * <http://www.vovida.org/>.
 
131
 *
 
132
 */