reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
DnsNaptrRecord.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"
19#include "rutil/Logger.hxx"
20#include "rutil/ParseBuffer.hxx"
25
26using namespace resip;
27#define RESIPROCATE_SUBSYSTEM resip::Subsystem::DNS
28
32
34{
35 if (data.size() > 1)
36 {
37 ParseBuffer pb(data, "DnsNaptrRecord::RegExp parser");
38
39 const char delim = data[0];
40 const char* start = pb.skipChar(delim);
41 pb.skipToChar(delim);
42
43 pb.data(mRegexp, start);
44 start = pb.skipChar(delim);
45 pb.skipToChar(delim);
46 pb.data(mReplacement, start);
47 start = pb.skipChar(delim);
48 // .kw. start above is not used -- what is going on here?
49 // should above code be in #if block below?
50
51#if 0
52 //pb.data(mFlags, start);
53
54 if (regcomp(&mRe, mRegexp.c_str(), REG_EXTENDED) != 0)
55 {
56 // couldn't parse input regexp so ignore it
57 mRegexp.clear();
58 }
59#endif
60 }
61}
62
64{
65 //regfree(&mRe);
66}
67
68
69bool
71{
72 return mRegexp.empty();
73}
74
75const Data&
77{
78 return mRegexp;
79}
80
81const Data&
83{
84 return mReplacement;
85}
86
87Data
89{
90 // !jf! should be doing a real regexp here
91 //regmatch_t matches[10];
92 //regexec(&mRe, input.c_str(), 10, matches, 0);
93
94 return mReplacement;
95}
96
98{
99 char* name = 0;
100 long len = 0;
101 if (ARES_SUCCESS != ares_expand_name(overlay.data()-overlay.nameLength()-RRFIXEDSZ, overlay.msg(), overlay.msgLength(), &name, &len))
102 {
103 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__);
104 }
105 mName = name;
106 free(name);
107 mTTL = overlay.ttl();
108
109 // order and preference, followed by the flags length
110 if (overlay.dataLength() < 5)
111 {
112 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__);
113 }
114
115 mOrder = DNS__16BIT(overlay.data());
116 mPreference = DNS__16BIT(overlay.data() + 2);
117 const unsigned char* pPos = overlay.data() + 4;
118 len = *pPos;
119
120 // flags, service and regexp are each followed by at least one more byte:
121 // the next length, or the replacement
122 if (pPos + len + 1 >= overlay.data() + overlay.dataLength())
123 {
124 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__);
125 }
126
127 mFlags = Data(pPos + 1, len);
128 pPos += len + 1;
129 len = *pPos;
130
131 if (pPos + len + 1 >= overlay.data() + overlay.dataLength())
132 {
133 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__);
134 }
135 mService = Data(pPos + 1, len);
136 pPos += len + 1;
137 len = *pPos;
138
139 if (pPos + len + 1 >= overlay.data() + overlay.dataLength())
140 {
141 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__);
142 }
143 Data regexp(pPos + 1, len);
144 pPos += len + 1;
146 InfoLog (<< "regexp=" << mRegexp.regexp() << " rep=" << mRegexp.replacement());
147
148 if (pPos[0] != 0)
149 {
150 if (ARES_SUCCESS != ares_expand_name(pPos, overlay.msg(), overlay.msgLength(), &name, &len))
151 {
152 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__);
153 }
154 mReplacement = name;
155 free(name);
156
157 // ares_expand_name stops at the end of the message, not the record
158 if (pPos + len > overlay.data() + overlay.dataLength())
159 {
160 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__);
161 }
162 }
163}
164
165bool DnsNaptrRecord::isSameValue(const Data& value) const
166{
167 return mReplacement == value;
168}
169
171DnsNaptrRecord::dump(EncodeStream& strm) const
172{
173 strm << mName << " (NAPTR)--> o=" << mOrder << " p=" << mPreference << " s=" << mService << " ttl=" << mTTL;
174 return strm;
175}
176
177/* ====================================================================
178 * The Vovida Software License, Version 1.0
179 *
180 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
181 *
182 * Redistribution and use in source and binary forms, with or without
183 * modification, are permitted provided that the following conditions
184 * are met:
185 *
186 * 1. Redistributions of source code must retain the above copyright
187 * notice, this list of conditions and the following disclaimer.
188 *
189 * 2. Redistributions in binary form must reproduce the above copyright
190 * notice, this list of conditions and the following disclaimer in
191 * the documentation and/or other materials provided with the
192 * distribution.
193 *
194 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
195 * and "Vovida Open Communication Application Library (VOCAL)" must
196 * not be used to endorse or promote products derived from this
197 * software without prior written permission. For written
198 * permission, please contact vocal@vovida.org.
199 *
200 * 4. Products derived from this software may not be called "VOCAL", nor
201 * may "VOCAL" appear in their name, without prior written
202 * permission of Vovida Networks, Inc.
203 *
204 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
205 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
206 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
207 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
208 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
209 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
210 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
211 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
212 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
213 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
214 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
215 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
216 * DAMAGE.
217 *
218 * ====================================================================
219 *
220 * This software consists of voluntary contributions made by Vovida
221 * Networks, Inc. and many individuals on behalf of Vovida Networks,
222 * Inc. For more information on Vovida Networks, Inc., please see
223 * <http://www.vovida.org/>.
224 *
225 */
226
#define InfoLog(args_)
Definition Logger.hxx:131
#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
size_type size() const noexcept
Returns the number of bytes in this Data.
Definition Data.hxx:599
Data apply(const Data &input) const
const Data & replacement() const
const RegExp & regexp() const
virtual const Data & name() const
virtual EncodeStream & dump(EncodeStream &strm) const
virtual bool isSameValue(const Data &value) const
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToChar(char c)
CurrentPosition skipChar()
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
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