reSIProcate/rutil  9694
AresDns.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_ARES_DNS_HXX)
00002 #define RESIP_ARES_DNS_HXX
00003 
00004 #include "rutil/FdSetIOObserver.hxx"
00005 #include "rutil/GenericIPAddress.hxx"
00006 #include "rutil/dns/ExternalDns.hxx"
00007 
00008 extern "C"
00009 {
00010 struct ares_channeldata;
00011 }
00012 
00013 //struct fd_set;
00014 
00015 extern "C" {
00016   void resip_AresDns_aresCallback(void *arg, int status, unsigned char* abuf, int alen);
00017   void resip_AresDns_caresCallback(void *arg, int status, int timeouts, unsigned char* abuf, int alen);
00018 }
00019 
00020 namespace resip
00021 {
00022 class AresDnsPollItem;
00023 class FdPollGrp;
00024 
00025 class AresDns : public ExternalDns, public FdSetIOObserver
00026 {
00027    friend class AresDnsPollItem;
00028    public:
00029       AresDns() {mChannel = 0; mFeatures = 0; mPollGrp=NULL;}
00030       virtual ~AresDns();
00031 
00032       virtual int init(const std::vector<GenericIPAddress>& additionalNameservers,
00033                        AfterSocketCreationFuncPtr socketfunc, int timeout=0, int tries=0, unsigned int features=0);
00034 
00035       int internalInit(const std::vector<GenericIPAddress>& additionalNameservers,
00036                        AfterSocketCreationFuncPtr socketfunc, unsigned int features=0, ares_channeldata** channel = 0, int timeout=0, int tries=0);
00037 
00038       virtual bool checkDnsChange();
00039 
00040       virtual unsigned int getTimeTillNextProcessMS();
00041       virtual void process(FdSet& fdset);
00042       virtual void buildFdSet(FdSet& fdset);
00043 
00044       virtual void buildFdSet(fd_set& read, fd_set& write, int& size);
00045       virtual void process(fd_set& read, fd_set& write);
00046 
00047       virtual void setPollGrp(FdPollGrp *pollGrp);
00048       virtual void processTimers();
00049 
00050       //?dcm?  I believe these need to do nothing in the ARES case.
00051       virtual void freeResult(ExternalDnsRawResult /* res */) {}
00052       virtual void freeResult(ExternalDnsHostResult /* res */) {}
00053 
00054       virtual char* errorMessage(long errorCode);
00055 
00056       void lookup(const char* target, unsigned short type, ExternalDnsHandler* handler, void* userData);
00057 
00058       virtual bool hostFileLookup(const char* target, in_addr &addr);
00059       virtual bool hostFileLookupLookupOnlyMode() { return mHostFileLookupOnlyMode; }
00060       static void enableHostFileLookupOnlyMode(bool enable) { mHostFileLookupOnlyMode = enable; }
00061 
00062       friend void ::resip_AresDns_aresCallback(void *arg, int status, unsigned char* abuf, int alen);
00063       friend void ::resip_AresDns_caresCallback(void *arg, int status, int timeouts, unsigned char* abuf, int alen);
00064 
00065       // used for epoll() interface to ares lib
00066       // time_t mNow;
00067 
00068    private:
00069 
00070       typedef std::pair<ExternalDnsHandler*, void*> Payload;
00071       static ExternalDnsRawResult makeRawResult(void *arg, int status, unsigned char *abuf, int alen);
00072       static ExternalDnsHandler* getHandler(void* arg);
00073       struct ares_channeldata* mChannel;
00074       std::vector<GenericIPAddress> mAdditionalNameservers;
00075       unsigned int mFeatures;
00076       volatile static bool mHostFileLookupOnlyMode;
00077 
00078       FdPollGrp*        mPollGrp;
00079       std::vector<AresDnsPollItem*> mPollItems;
00080 
00081 };
00082 
00083 }
00084 
00085 
00086 #endif
00087 
00088 /* ====================================================================
00089  * The Vovida Software License, Version 1.0
00090  *
00091  * Copyright (c) 2000-2005 Vovida Networks, Inc.  All rights reserved.
00092  *
00093  * Redistribution and use in source and binary forms, with or without
00094  * modification, are permitted provided that the following conditions
00095  * are met:
00096  *
00097  * 1. Redistributions of source code must retain the above copyright
00098  *    notice, this list of conditions and the following disclaimer.
00099  *
00100  * 2. Redistributions in binary form must reproduce the above copyright
00101  *    notice, this list of conditions and the following disclaimer in
00102  *    the documentation and/or other materials provided with the
00103  *    distribution.
00104  *
00105  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00106  *    and "Vovida Open Communication Application Library (VOCAL)" must
00107  *    not be used to endorse or promote products derived from this
00108  *    software without prior written permission. For written
00109  *    permission, please contact vocal@vovida.org.
00110  *
00111  * 4. Products derived from this software may not be called "VOCAL", nor
00112  *    may "VOCAL" appear in their name, without prior written
00113  *    permission of Vovida Networks, Inc.
00114  *
00115  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00116  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00117  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00118  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00119  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00120  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00121  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00122  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00123  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00124  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00125  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00126  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00127  * DAMAGE.
00128  *
00129  * ====================================================================
00130  *
00131  * This software consists of voluntary contributions made by Vovida
00132  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00133  * Inc.  For more information on Vovida Networks, Inc., please see
00134  * <http://www.vovida.org/>.
00135  *
00136  * vi: set shiftwidth=3 expandtab:
00137  */