|
reSIProcate/rutil
9694
|
00001 #if defined(HAVE_CONFIG_H) 00002 #include "config.h" 00003 #endif 00004 00005 #include <stdlib.h> 00006 00007 #include "AresCompat.hxx" 00008 00009 #ifndef __CYGWIN__ 00010 #ifndef RRFIXEDSZ 00011 #define RRFIXEDSZ 10 00012 #endif 00013 #ifndef NS_RRFIXEDSZ 00014 #define NS_RRFIXEDSZ 10 00015 #endif 00016 #endif 00017 00018 #include "rutil/Data.hxx" 00019 #include "rutil/Logger.hxx" 00020 #include "rutil/ParseBuffer.hxx" 00021 #include "rutil/BaseException.hxx" 00022 #include "rutil/dns/RROverlay.hxx" 00023 #include "rutil/dns/DnsResourceRecord.hxx" 00024 #include "rutil/dns/DnsNaptrRecord.hxx" 00025 00026 using namespace resip; 00027 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::DNS 00028 00029 DnsNaptrRecord::RegExp::RegExp() 00030 { 00031 } 00032 00033 DnsNaptrRecord::RegExp::RegExp(const Data& data) 00034 { 00035 if (data.size() > 1) 00036 { 00037 ParseBuffer pb(data, "DnsNaptrRecord::RegExp parser"); 00038 00039 const char delim = data[0]; 00040 const char* start = pb.skipChar(delim); 00041 pb.skipToChar(delim); 00042 00043 pb.data(mRegexp, start); 00044 start = pb.skipChar(delim); 00045 pb.skipToChar(delim); 00046 pb.data(mReplacement, start); 00047 start = pb.skipChar(delim); 00048 // .kw. start above is not used -- what is going on here? 00049 // should above code be in #if block below? 00050 00051 #if 0 00052 //pb.data(mFlags, start); 00053 00054 if (regcomp(&mRe, mRegexp.c_str(), REG_EXTENDED) != 0) 00055 { 00056 // couldn't parse input regexp so ignore it 00057 mRegexp.clear(); 00058 } 00059 #endif 00060 } 00061 } 00062 00063 DnsNaptrRecord::RegExp::~RegExp() 00064 { 00065 //regfree(&mRe); 00066 } 00067 00068 00069 bool 00070 DnsNaptrRecord::RegExp::empty() const 00071 { 00072 return mRegexp.empty(); 00073 } 00074 00075 const Data& 00076 DnsNaptrRecord::RegExp::regexp() const 00077 { 00078 return mRegexp; 00079 } 00080 00081 const Data& 00082 DnsNaptrRecord::RegExp::replacement() const 00083 { 00084 return mReplacement; 00085 } 00086 00087 Data 00088 DnsNaptrRecord::RegExp::apply(const Data& input) const 00089 { 00090 // !jf! should be doing a real regexp here 00091 //regmatch_t matches[10]; 00092 //regexec(&mRe, input.c_str(), 10, matches, 0); 00093 00094 return mReplacement; 00095 } 00096 00097 DnsNaptrRecord::DnsNaptrRecord(const RROverlay& overlay) 00098 { 00099 char* name = 0; 00100 long len = 0; 00101 if (ARES_SUCCESS != ares_expand_name(overlay.data()-overlay.nameLength()-RRFIXEDSZ, overlay.msg(), overlay.msgLength(), &name, &len)) 00102 { 00103 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__); 00104 } 00105 mName = name; 00106 free(name); 00107 00108 mOrder = DNS__16BIT(overlay.data()); 00109 mPreference = DNS__16BIT(overlay.data() + 2); 00110 const unsigned char* pPos = overlay.data() + 4; 00111 len = *pPos; 00112 00113 if (pPos + len + 1 > overlay.data() + overlay.dataLength()) 00114 { 00115 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__); 00116 } 00117 00118 mFlags = Data(pPos + 1, len); 00119 pPos += len + 1; 00120 len = *pPos; 00121 00122 if (pPos + len + 1 > overlay.data() + overlay.dataLength()) 00123 { 00124 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__); 00125 } 00126 mService = Data(pPos + 1, len); 00127 pPos += len + 1; 00128 len = *pPos; 00129 00130 if (pPos + len + 1 > overlay.data() + overlay.dataLength()) 00131 { 00132 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__); 00133 } 00134 Data regexp(pPos + 1, len); 00135 pPos += len + 1; 00136 mRegexp = DnsNaptrRecord::RegExp(regexp); 00137 InfoLog (<< "regexp=" << mRegexp.regexp() << " rep=" << mRegexp.replacement()); 00138 00139 if (pPos[0] != 0) 00140 { 00141 if (ARES_SUCCESS != ares_expand_name(pPos, overlay.msg(), overlay.msgLength(), &name, &len)) 00142 { 00143 throw NaptrException("Failed parse of NAPTR record", __FILE__, __LINE__); 00144 } 00145 mReplacement = name; 00146 free(name); 00147 } 00148 } 00149 00150 bool DnsNaptrRecord::isSameValue(const Data& value) const 00151 { 00152 return mReplacement == value; 00153 } 00154 00155 EncodeStream& 00156 DnsNaptrRecord::dump(EncodeStream& strm) const 00157 { 00158 strm << mName << " (NAPTR)--> o=" << mOrder << " p=" << mPreference; 00159 return strm; 00160 } 00161 00162 /* ==================================================================== 00163 * The Vovida Software License, Version 1.0 00164 * 00165 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved. 00166 * 00167 * Redistribution and use in source and binary forms, with or without 00168 * modification, are permitted provided that the following conditions 00169 * are met: 00170 * 00171 * 1. Redistributions of source code must retain the above copyright 00172 * notice, this list of conditions and the following disclaimer. 00173 * 00174 * 2. Redistributions in binary form must reproduce the above copyright 00175 * notice, this list of conditions and the following disclaimer in 00176 * the documentation and/or other materials provided with the 00177 * distribution. 00178 * 00179 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00180 * and "Vovida Open Communication Application Library (VOCAL)" must 00181 * not be used to endorse or promote products derived from this 00182 * software without prior written permission. For written 00183 * permission, please contact vocal@vovida.org. 00184 * 00185 * 4. Products derived from this software may not be called "VOCAL", nor 00186 * may "VOCAL" appear in their name, without prior written 00187 * permission of Vovida Networks, Inc. 00188 * 00189 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00190 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00191 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00192 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00193 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00194 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00195 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00196 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00197 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00198 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00199 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00200 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00201 * DAMAGE. 00202 * 00203 * ==================================================================== 00204 * 00205 * This software consists of voluntary contributions made by Vovida 00206 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00207 * Inc. For more information on Vovida Networks, Inc., please see 00208 * <http://www.vovida.org/>. 00209 * 00210 */ 00211
1.7.5.1