|
reSIProcate/rutil
9694
|
00001 #if !defined(RESIP_EXTERNAL_DNS_HXX) 00002 #define RESIP_EXTERNAL_DNS_HXX 00003 00004 #include <vector> 00005 00006 #include "rutil/AsyncID.hxx" 00007 #include "rutil/GenericIPAddress.hxx" 00008 00009 struct hostent; 00010 00011 namespace resip 00012 { 00013 class ExternalDnsHandler; 00014 class ExternalDnsRawResult; 00015 class ExternalDnsHostResult; 00016 class FdPollGrp; 00017 00018 //used by the asynchronous executive 00019 class ExternalDns 00020 { 00021 public: 00022 enum Features 00023 { 00024 None = 0, 00025 TryServersOfNextNetworkUponRcode3 = 1 << 0 // 'No such name' 00026 }; 00027 00028 //returns Success, BuildMismatch, otherwise ExternalDns specific 00029 //error message can be pulled from errorMessage 00030 enum InitResult 00031 { 00032 Success = 0, 00033 BuildMismatch = 4777 00034 }; 00035 00036 00037 // 00038 virtual int init(const std::vector<GenericIPAddress>& additionalNameservers, 00039 AfterSocketCreationFuncPtr, 00040 int dnsTimeout = 0, 00041 int dnsTries = 0, 00042 unsigned int features = 0) = 0; // bit mask of Features 00043 00044 //returns 'true' only is there are changes in the DNS server list 00045 virtual bool checkDnsChange() = 0; 00046 00047 //For use in select timeout 00048 virtual unsigned int getTimeTillNextProcessMS() = 0; 00049 00050 //this is scary on windows; the standard way to get a bigger fd_set is to 00051 //redefine FD_SETSIZE befor each inclusion of winsock2.h, so make sure 00052 //external libraries have been properly configured 00053 // MUST not be called when pollGrp (below) is active 00054 virtual void buildFdSet(fd_set& read, fd_set& write, int& size) = 0; 00055 virtual void process(fd_set& read, fd_set& write) = 0; 00056 00057 virtual void setPollGrp(FdPollGrp *grp) = 0; 00058 00059 // called by DnsStub to process timers requested by getTimeTillNext...() 00060 // only used when poll group is active 00061 virtual void processTimers() = 0; 00062 00063 virtual void freeResult(ExternalDnsRawResult res) = 0; 00064 virtual void freeResult(ExternalDnsHostResult res) = 0; 00065 00066 //caller must clean up memory 00067 virtual char* errorMessage(long errorCode) = 0; 00068 00069 virtual ~ExternalDns() {} 00070 00071 virtual void lookup(const char* target, unsigned short type, ExternalDnsHandler* handler, void* userData) = 0; 00072 00073 virtual bool hostFileLookup(const char* target, in_addr &addr) = 0; 00074 virtual bool hostFileLookupLookupOnlyMode() = 0; 00075 }; 00076 00077 class ExternalDnsResult : public AsyncResult 00078 { 00079 public: 00080 ExternalDnsResult(long errorCode, void* uData) : AsyncResult(errorCode) , userData(uData) {} 00081 ExternalDnsResult(void* uData) : userData(uData) {} 00082 void* userData; 00083 }; 00084 00085 //should this be nested? 00086 class ExternalDnsRawResult : public ExternalDnsResult 00087 { 00088 public: 00089 ExternalDnsRawResult(unsigned char* buf, int len, void* uData) : 00090 ExternalDnsResult(uData), 00091 00092 abuf(buf), 00093 alen(len) 00094 {} 00095 ExternalDnsRawResult(long errorCode, unsigned char* buf, int len, void* uData) : 00096 ExternalDnsResult(errorCode, uData), 00097 abuf(buf), 00098 alen(len) 00099 {} 00100 00101 unsigned char* abuf; 00102 int alen; 00103 }; 00104 00105 class ExternalDnsHostResult : public ExternalDnsResult 00106 { 00107 public: 00108 ExternalDnsHostResult(hostent* h, void* uData) : 00109 ExternalDnsResult(uData), 00110 host(h) 00111 {} 00112 ExternalDnsHostResult(long errorCode, void* uData) : ExternalDnsResult(errorCode, uData) {} 00113 00114 hostent* host; 00115 }; 00116 00117 class ExternalDnsHandler 00118 { 00119 public: 00120 //underscores are against convention, but pretty impossible to read 00121 //otherwise. ?dcm? -- results stack or heap? 00122 //the free routines can be dealt w/ iheritence instead if pointers are used 00123 //virtual void handle_NAPTR(ExternalDnsRawResult res) = 0; 00124 //virtual void handle_SRV(ExternalDnsRawResult res) = 0; 00125 //virtual void handle_AAAA(ExternalDnsRawResult res) = 0; 00126 //virtual void handle_host(ExternalDnsHostResult res) = 0; 00127 00128 // new version 00129 virtual ~ExternalDnsHandler() {} 00130 virtual void handleDnsRaw(ExternalDnsRawResult res) = 0; 00131 }; 00132 00133 } 00134 00135 #endif 00136 00137 00138 /* ==================================================================== 00139 * The Vovida Software License, Version 1.0 00140 * 00141 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00142 * 00143 * Redistribution and use in source and binary forms, with or without 00144 * modification, are permitted provided that the following conditions 00145 * are met: 00146 * 00147 * 1. Redistributions of source code must retain the above copyright 00148 * notice, this list of conditions and the following disclaimer. 00149 * 00150 * 2. Redistributions in binary form must reproduce the above copyright 00151 * notice, this list of conditions and the following disclaimer in 00152 * the documentation and/or other materials provided with the 00153 * distribution. 00154 * 00155 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00156 * and "Vovida Open Communication Application Library (VOCAL)" must 00157 * not be used to endorse or promote products derived from this 00158 * software without prior written permission. For written 00159 * permission, please contact vocal@vovida.org. 00160 * 00161 * 4. Products derived from this software may not be called "VOCAL", nor 00162 * may "VOCAL" appear in their name, without prior written 00163 * permission of Vovida Networks, Inc. 00164 * 00165 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00166 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00167 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00168 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00169 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00170 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00171 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00172 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00173 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00174 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00175 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00176 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00177 * DAMAGE. 00178 * 00179 * ==================================================================== 00180 * 00181 * This software consists of voluntary contributions made by Vovida 00182 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00183 * Inc. For more information on Vovida Networks, Inc., please see 00184 * <http://www.vovida.org/>. 00185 * 00186 */
1.7.5.1