Ejemplo n.º 1
0
 /**
  * Implements module logic.
  *
  * @param \AppserverIo\DnsServer\Interfaces\DnsRequestInterface  $request        A request object
  * @param \AppserverIo\DnsServer\Interfaces\DnsResponseInterface $response       A response object
  * @param \AppserverIo\Server\Interfaces\RequestContextInterface $requestContext A requests context instance
  *
  * @return void
  */
 public function process(DnsRequestInterface $request, DnsResponseInterface $response, RequestContextInterface $requestContext)
 {
     // load the answer from our DNS database
     $answer = $this->getStackableResolver()->getAnswer($question = $request->getQuestion());
     // merge the flags
     $flags = array_merge($request->getFlags(), array('qr' => 1, 'ra' => 0));
     // prepare the numbers for the encoding
     $ancount = count($answer);
     $qdcount = count($question);
     $nscount = count($authority = $request->getAuthority());
     $arcount = count($additional = $request->getAdditional());
     // prepare the encoded DNS response
     $res = pack('nnnnnn', $request->getData('packet_id'), DnsUtil::singleton()->encodeFlags($flags), $qdcount, $ancount, $nscount, $arcount);
     $res .= DnsUtil::singleton()->encodeQuestionResourceRecord($question, strlen($res));
     $res .= DnsUtil::singleton()->encodeResourceRecord($answer, strlen($res));
     $res .= DnsUtil::singleton()->encodeResourceRecord($authority, strlen($res));
     $res .= DnsUtil::singleton()->encodeResourceRecord($additional, strlen($res));
     // append the response to the body stream
     $response->appendBodyStream($res);
 }
Ejemplo n.º 2
0
 /**
  * Parses the request data from the passed buffer.
  *
  * @param string $buffer The buffer to decode the data from
  *
  * @return void
  */
 public function parse($buffer)
 {
     // create a local copy of the requst
     $request = $this->getRequest();
     // set the raw data in the request
     $request->setRawData($rawData = unpack('npacket_id/nflags/nqdcount/nancount/nnscount/narcount', $buffer));
     // load the offset to start extracting the data
     $offset = $request->getOffset();
     // initialize the request with the extracted DNS values
     $request->setFlags(DnsUtil::singleton()->decodeFlags($rawData['flags']));
     $request->setQuestion(DnsUtil::singleton()->decodeQuestionResourceRecord($buffer, $offset, $rawData['qdcount']));
     $request->setAnswer(DnsUtil::singleton()->decodeResourceRecord($buffer, $offset, $rawData['ancount']));
     $request->setAuthority(DnsUtil::singleton()->decodeResourceRecord($buffer, $offset, $rawData['nscount']));
     $request->setAdditional(DnsUtil::singleton()->decodeResourceRecord($buffer, $offset, $rawData['arcount']));
 }