/[resiprocate]/main/resip/stack/test/testDnsStub.cxx
ViewVC logotype

Annotation of /main/resip/stack/test/testDnsStub.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5283 - (hide annotations) (download)
Fri Aug 19 01:27:14 2005 UTC (14 years, 3 months ago) by derek
Original Path: branches/b-directory-reorg/resip/stack/test/testDnsStub.cxx
File size: 8325 byte(s)
finished resip/sip -> resip/stack rename
1 daniel 5136 #if defined(HAVE_CONFIG_H)
2 derek 5283 #include "resip/stack/config.hxx"
3 daniel 5136 #endif
4    
5     #if defined (HAVE_POPT_H)
6     #include <popt.h>
7     #else
8     #ifndef WIN32
9     #warning "will not work very well without libpopt"
10     #endif
11     #endif
12    
13     #include <iostream>
14     #include <list>
15    
16 jason 5276 #include "rutil/Lock.hxx"
17     #include "rutil/Mutex.hxx"
18     #include "rutil/Socket.hxx"
19     #include "rutil/Logger.hxx"
20     #include "rutil/ThreadIf.hxx"
21     #include "rutil/DnsUtil.hxx"
22 derek 5283 #include "resip/stack/DnsResult.hxx"
23     #include "resip/stack/SipStack.hxx"
24 jason 5276 #include "rutil/dns/RRVip.hxx"
25     #include "rutil/dns/QueryTypes.hxx"
26     #include "rutil/dns/DnsStub.hxx"
27 daniel 5136
28     using namespace std;
29    
30    
31     #define RESIPROCATE_SUBSYSTEM resip::Subsystem::TEST
32    
33     const char bf[] = "\033[01;34m";
34     const char gf[] = "\033[01;32m";
35     const char rf[] = "\033[01;31m";
36     const char ub[] = "\033[01;00m";
37    
38     bool gComplete = false;
39    
40     #ifdef WIN32
41     #define usleep(x) Sleep(x/1000)
42     #define sleep(x) Sleep(x)
43     #endif
44    
45     namespace resip
46     {
47    
48     class MyDnsSink : public DnsResultSink
49     {
50     public:
51     void onDnsResult(const DNSResult<DnsHostRecord>&);
52     #ifdef USE_IPV6
53     void onDnsResult(const DNSResult<DnsAAAARecord>&);
54     #endif
55     void onDnsResult(const DNSResult<DnsSrvRecord>&);
56     void onDnsResult(const DNSResult<DnsNaptrRecord>&);
57     void onDnsResult(const DNSResult<DnsCnameRecord>&);
58     };
59    
60     void MyDnsSink::onDnsResult(const DNSResult<DnsHostRecord>& result)
61     {
62     cout << "A records" << endl;
63     cout << "Status: " << result.status << endl;
64     cout << "Domain: " << result.domain << endl;
65     if (result.status == 0)
66     {
67     for (vector<DnsHostRecord>::const_iterator it = result.records.begin(); it != result.records.end(); ++it)
68     {
69     cout << (*it).host() << endl;
70     }
71     }
72     else
73     {
74     cout << "Dns look up failed:" << result.msg << endl;
75     }
76     gComplete = true;
77     }
78    
79     void MyDnsSink::onDnsResult(const DNSResult<DnsNaptrRecord>& result)
80     {
81     cout << "Naptr records" << endl;
82     cout << "Status: " << result.status << endl;
83     cout << "Domain: " << result.domain << endl;
84     if (result.status == 0)
85     {
86     for (vector<DnsNaptrRecord>::const_iterator it = result.records.begin(); it != result.records.end(); ++it)
87     {
88     cout << (*it).name() << endl;
89     }
90     }
91     else
92     {
93     cout << "Dns look up failed:" << result.msg << endl;
94     }
95     gComplete = true;
96     }
97    
98     void MyDnsSink::onDnsResult(const DNSResult<DnsCnameRecord>& result)
99     {
100     cout << "CNAME records" << endl;
101     cout << "Status: " << result.status << endl;
102     cout << "Domain: " << result.domain << endl;
103     if (result.status == 0)
104     {
105     for (vector<DnsCnameRecord>::const_iterator it = result.records.begin(); it != result.records.end(); ++it)
106     {
107     cout << (*it).cname() << endl;
108     }
109     }
110     else
111     {
112     cout << "Dns look up failed:" << result.msg << endl;
113     }
114     gComplete = true;
115     }
116    
117     void MyDnsSink::onDnsResult(const DNSResult<DnsSrvRecord>& result)
118     {
119     cout << "SRV records" << endl;
120     cout << "Status: " << result.status << endl;
121     cout << "Domain: " << result.domain << endl;
122     if (result.status == 0)
123     {
124     for (vector<DnsSrvRecord>::const_iterator it = result.records.begin(); it != result.records.end(); ++it)
125     {
126     cout << "Name: " << (*it).name() << endl;
127     cout << "Priority: " << (*it).priority() << endl;
128     cout << "Weight: " << (*it).weight() << endl;
129     cout << "Port: " << (*it).port() << endl;
130     cout << "Target: " << (*it).target() << endl;
131     }
132     }
133     else
134     {
135     cout << "Dns look up failed:" << result.msg << endl;
136     }
137     gComplete = true;
138     }
139    
140     #ifdef USE_IPV6
141     void MyDnsSink::onDnsResult(const DNSResult<DnsAAAARecord>& result)
142     {
143     gComplete = true;
144     }
145     #endif
146    
147     class TestDns : public ThreadIf, public DnsStub
148     {
149     public:
150     TestDns()
151     {
152     }
153    
154     void thread()
155     {
156     while (!waitForShutdown(100))
157     {
158     FdSet fdset;
159     buildFdSet(fdset);
160     fdset.selectMilliSeconds(1);
161     process(fdset);
162     }
163     }
164     };
165    
166     }
167    
168     using namespace resip;
169    
170     int
171     main(int argc, const char** argv)
172     {
173     if (argc < 3)
174     {
175     cout << "usage: " << argv[0] << " target" << " type" << endl;
176     cout << "Valid type values: " << endl;
177     cout << "A Record - 1" << endl;
178     cout << "CNAME - 5" << endl;
179     cout << "SRV - 33" << endl;
180     cout << "NAPTR - 35" << endl;
181     cout << "AAAA - 28" << endl;
182     return 0;
183     }
184    
185     char* logType = "cout";
186     //char* logLevel = "STACK";
187     char* logLevel = "INFO";
188    
189     #if defined(HAVE_POPT_H)
190     struct poptOption table[] = {
191     {"log-type", 'l', POPT_ARG_STRING, &logType, 0, "where to send logging messages", "syslog|cerr|cout"},
192     {"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, "specify the default log level", "DEBUG|INFO|WARNING|ALERT"},
193     POPT_AUTOHELP
194     { NULL, 0, 0, NULL, 0 }
195     };
196    
197     poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0);
198     poptGetNextOpt(context);
199     #endif
200    
201     Log::initialize(logType, logLevel, argv[0]);
202     initNetwork();
203     TestDns dns;
204     dns.run();
205     cerr << "Starting" << endl;
206     #if defined(HAVE_POPT_H)
207     const char** args = poptGetArgs(context);
208     #else
209     const char** args = argv;
210     #endif
211    
212     MyDnsSink sink;
213    
214     switch (atoi(argv[2]))
215     {
216     case 1:
217     dns.lookup<RR_A>(argv[1], Protocol::Sip, &sink);
218     break;
219     case 5:
220     dns.lookup<RR_CNAME>(argv[1], Protocol::Sip, &sink);
221     break;
222     #ifdef USE_IPV6
223     case 28:
224     dns.lookup<RR_AAAA>(argv[1], Protocol::Sip, &sink);
225     break;
226     #endif
227     case 33:
228     dns.lookup<RR_SRV>(argv[1], Protocol::Sip, &sink);
229     break;
230     case 35:
231     dns.lookup<RR_NAPTR>(argv[1], Protocol::Sip, &sink);
232     break;
233     default:
234     cout << "Invalid Dns type" << endl;
235     return 0;
236     }
237    
238     while (!gComplete)
239     {
240     #ifdef WIN32
241     sleep(100);
242     #else
243     sleep(1);
244     #endif
245     }
246    
247     dns.shutdown();
248     dns.join();
249    
250     return 0;
251     }
252    
253    
254     /* ====================================================================
255     * The Vovida Software License, Version 1.0
256     *
257     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
258     *
259     * Redistribution and use in source and binary forms, with or without
260     * modification, are permitted provided that the following conditions
261     * are met:
262     *
263     * 1. Redistributions of source code must retain the above copyright
264     * notice, this list of conditions and the following disclaimer.
265     *
266     * 2. Redistributions in binary form must reproduce the above copyright
267     * notice, this list of conditions and the following disclaimer in
268     * the documentation and/or other materials provided with the
269     * distribution.
270     *
271     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
272     * and "Vovida Open Communication Application Library (VOCAL)" must
273     * not be used to endorse or promote products derived from this
274     * software without prior written permission. For written
275     * permission, please contact vocal@vovida.org.
276     *
277     * 4. Products derived from this software may not be called "VOCAL", nor
278     * may "VOCAL" appear in their name, without prior written
279     * permission of Vovida Networks, Inc.
280     *
281     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
282     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
283     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
284     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
285     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
286     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
287     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
288     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
289     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
290     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
292     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
293     * DAMAGE.
294     *
295     * ====================================================================
296     *
297     * This software consists of voluntary contributions made by Vovida
298     * Networks, Inc. and many individuals on behalf of Vovida Networks,
299     * Inc. For more information on Vovida Networks, Inc., please see
300     * <http://www.vovida.org/>.
301     *
302     */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27