pike.git / lib / modules / Protocols.pmod / DNS.pmod

version» Context lines:

pike.git/lib/modules/Protocols.pmod/DNS.pmod:804:    result_available = 1;    send_reply(r, q, m, udp);    }    }       protected void handle_response(mapping r, mapping m, Stdio.UDP udp)    {    // This is a stub intended to simplify servers which allow recursion    }    +  //! Report a failure to decode a DNS request. +  //! +  //! The default implementation writes a backtrace to stderr. This +  //! method exists so that derived servers can replace it with more +  //! appropriate error handling for their environment. +  protected void report_decode_error(mixed err, mapping m, Stdio.UDP udp) +  { +  werror("DNS: Failed to read UDP packet.\n%s\n", +  describe_backtrace(err)); +  } +  +  //! Respond to a query that cannot be decoded. +  //! +  //! This method exists so that servers can override the default behaviour. +  protected void handle_decode_error(mapping err, mapping m, Stdio.UDP udp) +  { +  if(m && m->data && sizeof(m->data)>=2) +  send_reply((["rcode":1]), +  mkmapping(({"id"}), array_sscanf(m->data, "%2c")), m, udp); +  } +     protected private void rec_data(mapping m, Stdio.UDP udp)    {    mixed err;    mapping q;    if (err = catch {    q=decode_res(m->data);    }) { -  werror("DNS: Failed to read UDP packet.\n%s\n", -  describe_backtrace(err)); -  if(m && m->data && sizeof(m->data)>=2) -  send_reply((["rcode":1]), -  mkmapping(({"id"}), array_sscanf(m->data, "%2c")), m, udp); +  report_decode_error(err, m, udp); +  handle_decode_error(err, m, udp);    }    else if(q->qr)    handle_response(q, m, udp);    else    handle_query(q, m, udp);    }       //! @decl void create()    //! @decl void create(int port)    //! @decl void create(string ip)