1: 
   2: 
   3: /**********************
   4: *                     *
   5: *  COMPILER INCLUDES  *
   6: *                     *
   7: **********************/
   8: 
   9: 
  10: #include <cassert> 
  11: 
  12: 
  13: /*********************
  14: *                    *
  15: *  PROJECT INCLUDES  *
  16: *                    *
  17: *********************/
  18: 
  19: 
  20: //#include "requesttable.h"
  21: #include "requestworker.h" 
  22: #include "watchptr.h" 
  23: 
  24: 
  25: using WWWI::IPDump;
  26: 
  27: 
  28: /******************************
  29: *                             *
  30: *  REQUESTWORKER CONSTRUCTOR  *
  31: *                             *
  32: ******************************/
  33: 
  34: 
  35: RequestWorker::RequestWorker(DNSSocketPtr i_dspClients) {
  36:   m_rvp = GetSingleton<Resolver>();
  37:   m_dspClients = i_dspClients;
  38: }
  39: 
  40: 
  41: /****************
  42: *               *
  43: *  METHOD WAIT  *
  44: *               *
  45: ****************/
  46: 
  47: 
  48: bool RequestWorker::Wait() {
  49:   //m_dppClient = m_dspClients->RecvPacketTimed(1000);
  50:   m_dppClient = m_dspClients->RecvPacket();
  51:   if (m_dppClient==NULL) return false;
  52:   return true;
  53: }
  54: 
  55: 
  56: /****************
  57: *               *
  58: *  METHOD WORK  *
  59: *               *
  60: ****************/
  61: 
  62: 
  63: void RequestWorker::Work() {
  64:   unsigned short usID;
  65:   RequestPtr rqpClient;
  66:   ResponsePtr rspClient;
  67:   SockAddrIn *sipClient;
  68:   LogHandle lh(LF_MISC,LY_DEBUG);
  69:   WatchPtr<RequestPtr> watch1(rqpClient);
  70:   WatchPtr<ResponsePtr> watch2(rspClient);
  71:   WatchPtr<DNSPacketPtr> watch3(m_dppClient);
  72: 
  73:   sipClient = m_dppClient->RemoveAddr();
  74:   m_dppClient->Parse(usID,rqpClient,rspClient);
  75:   SoftDelete(m_dppClient);
  76: 
  77:   assert(rspClient==NULL);
  78:   if (rspClient!=NULL) {
  79:     lh << LY_INFO << "unsolicited response from ";
  80:     IPDump(lh,sipClient);
  81:     lh << " will be ignored."; lh();
  82:     return;
  83:   }
  84: 
  85:   assert(rqpClient->GetQuestionCount()==1);
  86:   if ((rspClient!=NULL)||
  87:       (rqpClient->GetQuestionCount()!=1)) {
  88:     SoftDelete(rspClient);
  89:     rspClient = new Response(RCODE_FORMERR);
  90:     goto processResponse;
  91:   }
  92: 
  93:   if ((rqpClient->GetOpcode()!=OPCODE_QUERY)||
  94:       (rqpClient->GetQuestion()->GetClass()!=CL_IN)) {
  95:     rspClient = new Response(RCODE_NOTIMP);
  96:     goto processResponse;
  97:   }
  98: 
  99:   lh << "received request from ";
 100:   IPDump(lh,sipClient);
 101:   lh << " " << endl;
 102:   lh << LY_EXTRA_DEBUG << "Request:" << endl << *rqpClient << endl; lh();
 103:   rspClient = m_rvp->QueryRecursive(rqpClient->GetQuestion(),32);
 104:   lh << "sending response to ";
 105:   IPDump(lh,sipClient);
 106:   lh << " " << endl;
 107:   lh << LY_EXTRA_DEBUG << "Response:" << endl << *rspClient << "(response ends)" << endl; lh();
 108: 
 109: processResponse:
 110:   m_dppClient = new DNSPacket(sipClient,usID,rqpClient,rspClient);
 111:   m_dspClients->SendPacket(m_dppClient);
 112:   //GetSingleton<RRCache>()->Walk();
 113:   //GetSingleton<RRCache>()->Expire(); // STUB: move this to its own thread
 114: 
 115:   SoftDelete(m_dppClient);
 116:   SoftDelete(rspClient);
 117:   SoftDelete(rqpClient);
 118: 
 119: }
 120: 
 121: 
 122: