reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
DnsSrvRecord.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5#include <stdlib.h>
6
7#include "AresCompat.hxx"
8
9#ifndef __CYGWIN__
10#ifndef RRFIXEDSZ
11#define RRFIXEDSZ 10
12#endif
13#ifndef NS_RRFIXEDSZ
14#define NS_RRFIXEDSZ 10
15#endif
16#endif
17
18#include "rutil/Data.hxx"
20#include "RROverlay.hxx"
21#include "DnsResourceRecord.hxx"
22#include "DnsSrvRecord.hxx"
23
24using namespace resip;
25
27{
28 char* name = 0;
29 long len = 0;
30 if (ARES_SUCCESS != ares_expand_name(overlay.data()-overlay.nameLength()-RRFIXEDSZ, overlay.msg(), overlay.msgLength(), &name, &len))
31 {
32 throw SrvException("Failed parse of SRV record", __FILE__, __LINE__);
33 }
34 mName = name;
35 free(name);
36 mTTL = overlay.ttl();
37
38 // priority, weight and port, followed by at least one byte of target
39 if (overlay.dataLength() < 7)
40 {
41 throw SrvException("Failed parse of SRV record", __FILE__, __LINE__);
42 }
43
44 mPriority = DNS__16BIT(overlay.data());
45 mWeight = DNS__16BIT(overlay.data() + 2);
46 mPort = DNS__16BIT(overlay.data() + 4);
47
48 if (ARES_SUCCESS != ares_expand_name(overlay.data() + 6, overlay.msg(), overlay.msgLength(), &name, &len))
49 {
50 throw SrvException("Failed parse of SRV record", __FILE__, __LINE__);
51 }
52 mTarget = name;
53 free(name);
54
55 // ares_expand_name stops at the end of the message, not the record
56 if (6 + len > overlay.dataLength())
57 {
58 throw SrvException("Failed parse of SRV record", __FILE__, __LINE__);
59 }
60}
61
62bool DnsSrvRecord::isSameValue(const Data& value) const
63{
64 return value == (mTarget + ":" + Data(mPort));
65}
66
68DnsSrvRecord::dump(EncodeStream& strm) const
69{
70 strm << mName << " (SRV) --> p=" << mPriority << " w=" << mWeight << " " << mTarget << ":" << mPort << " ttl=" << mTTL;
71 return strm;
72}
73
74/* ====================================================================
75 * The Vovida Software License, Version 1.0
76 *
77 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
78 *
79 * Redistribution and use in source and binary forms, with or without
80 * modification, are permitted provided that the following conditions
81 * are met:
82 *
83 * 1. Redistributions of source code must retain the above copyright
84 * notice, this list of conditions and the following disclaimer.
85 *
86 * 2. Redistributions in binary form must reproduce the above copyright
87 * notice, this list of conditions and the following disclaimer in
88 * the documentation and/or other materials provided with the
89 * distribution.
90 *
91 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
92 * and "Vovida Open Communication Application Library (VOCAL)" must
93 * not be used to endorse or promote products derived from this
94 * software without prior written permission. For written
95 * permission, please contact vocal@vovida.org.
96 *
97 * 4. Products derived from this software may not be called "VOCAL", nor
98 * may "VOCAL" appear in their name, without prior written
99 * permission of Vovida Networks, Inc.
100 *
101 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
102 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
103 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
104 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
105 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
106 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
107 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
108 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
109 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
110 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
111 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
112 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
113 * DAMAGE.
114 *
115 * ====================================================================
116 *
117 * This software consists of voluntary contributions made by Vovida
118 * Networks, Inc. and many individuals on behalf of Vovida Networks,
119 * Inc. For more information on Vovida Networks, Inc., please see
120 * <http://www.vovida.org/>.
121 *
122 */
123
#define ARES_SUCCESS
Definition ares.h:79
int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf, int alen, char **s, long *enclen)
#define DNS__16BIT(p)
Definition ares.h:45
#define RRFIXEDSZ
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
virtual bool isSameValue(const Data &value) const
virtual EncodeStream & dump(EncodeStream &strm) const
virtual const Data & name() const
DnsSrvRecord(const RROverlay &)
int msgLength() const
Definition RROverlay.hxx:40
int dataLength() const
Definition RROverlay.hxx:41
const unsigned char * msg() const
Definition RROverlay.hxx:39
int nameLength() const
Definition RROverlay.hxx:42
const unsigned char * data() const
Definition RROverlay.hxx:38
int ttl() const
Definition RROverlay.hxx:43
dcm! – add UnusedChecking(_enum) below;
#define EncodeStream