1: // $Id: dnsutil.i,v 1.22 2001/11/05 03:26:18 jdw Exp $
   2: 
   3: 
   4: /**********************
   5: *                     *
   6: *  COMPILER INCLUDES  *
   7: *                     *
   8: **********************/
   9: 
  10: 
  11: #include <cassert> 
  12: #include <cstring> 
  13: #include <stdexcept> 
  14: 
  15: 
  16: /*********************
  17: *                    *
  18: *  PROJECT INCLUDES  *
  19: *                    *
  20: *********************/
  21: 
  22: 
  23: #include "debugptr.h" 
  24: #include "loghandle.h" 
  25: #include "ex.h" 
  26: 
  27: 
  28: using std::invalid_argument;
  29: using WWWI::IPDump;
  30: 
  31: 
  32: /***********************
  33: *                      *
  34: *  FUNCTIONS FROMBITS  *
  35: *                      *
  36: ***********************/
  37: 
  38: 
  39: inline unsigned char FromBits(bool i_b3, bool i_b2, bool i_b1, bool i_b0) {
  40:   return FromBits(false,false,false,false,i_b3,i_b2,i_b1,i_b0);
  41: }
  42: 
  43: 
  44: inline unsigned char FromBits(bool i_b7, bool i_b6, bool i_b5, bool i_b4, bool i_b3, bool i_b2, bool i_b1, bool i_b0) {
  45:   unsigned char uc = 0;
  46:   if (i_b7) uc+=128;
  47:   if (i_b6) uc+=64;
  48:   if (i_b5) uc+=32;
  49:   if (i_b4) uc+=16;
  50:   if (i_b3) uc+=8;
  51:   if (i_b2) uc+=4;
  52:   if (i_b1) uc+=2;
  53:   if (i_b0) uc+=1;
  54:   return uc;
  55: }
  56: 
  57: 
  58: /************************
  59: *                       *
  60: *  FUNCTION MATCHCLASS  *
  61: *                       *
  62: ************************/
  63: 
  64: 
  65: inline bool MatchClass(RRClass i_cl1, RRClass i_cl2) {
  66:   if (i_cl2==CL_QANY) return true;
  67:   return (i_cl1==i_cl2);
  68: }
  69: 
  70: 
  71: /***********************
  72: *                      *
  73: *  FUNCTION MATCHTYPE  *
  74: *                      *
  75: ***********************/
  76: 
  77: 
  78: // STUB: there are more wildcards that should be handled here.
  79: inline bool MatchType(RRType i_ty1, RRType i_ty2) {
  80:   if (i_ty2==TY_QANY) return true;
  81:   return (i_ty1==i_ty2);
  82: }
  83: 
  84: 
  85: /************************
  86: *                       *
  87: *  FUNCTION SOFTDELETE  *
  88: *                       *
  89: ************************/
  90: 
  91: 
  92: template <class T> void SoftDelete(T* &io_tpr) {
  93:   if (io_tpr==NULL) return;
  94:   delete io_tpr;
  95:   io_tpr = NULL;
  96: }
  97: 
  98: 
  99: #ifdef USE_DEBUG_POINTERS 
 100: template <class T> void SoftDelete(DebugPtr<T> &io_tdp) {
 101:   if (io_tdp==NULL) return;
 102:   io_tdp.Delete();
 103: }
 104: #endif 
 105: 
 106: 
 107: /*****************************
 108: *                            *
 109: *  FUNCTION SOFTDELETEARRAY  *
 110: *                            *
 111: *****************************/
 112: 
 113: 
 114: template <class T> void SoftDeleteArray(T* &io_tpr) {
 115:   if (io_tpr==NULL) return;
 116:   delete[] io_tpr;
 117:   io_tpr = NULL;
 118: }
 119: 
 120: 
 121: