Branch: Tag:

1997-12-11

1997-12-11 00:30:53 by David Hedbor <david@hedbor.org>

Now uses search and domain if present - both with sync and async calls.

Rev: lib/modules/Protocols.pmod/DNS.pmod:1.5

212:    inherit protocol;       string nameserver; -  +  array search = ({});    void create(void|string server)    {    if(!server)    { -  +  string domain;    foreach(Stdio.read_file("/etc/resolv.conf")/"\n", string line)    {    string rest;
229:    switch(line)    {    case "domain": +  // Save domain for later. +  domain = rest; +  break;    case "search": -  break; // Not yet implemented +  rest = replace(rest, "\t", " "); +  foreach(rest / " " - ({""}), string dom) +  search += ({dom}); +  break;       case "nameserver":    nameserver=rest;    break;    }    } -  }else{ +  if(domain) +  search = ({ domain }) + search; +  } else {    nameserver=server;    }    }
262:    // Warning: NO TIMEOUT    mixed *gethostbyname(string s)    { -  mapping m=do_sync_query(mkquery(s, C_IN, T_A)); +  mapping m; +  if(sizeof(search) && s[-1] != '.' && sizeof(s/".") < 3) { +  m=do_sync_query(mkquery(s, C_IN, T_A)); +  if(!m || !m->an || !sizeof(m->an)) +  foreach(search, string domain) +  { +  m=do_sync_query(mkquery(s+"."+domain, C_IN, T_A)); +  if(m && m->an && sizeof(m->an)) +  break; +  } +  } else { +  m=do_sync_query(mkquery(s, C_IN, T_A)); +  } +     string *names=({});    string *ips=({});    foreach(m->an, mapping x)
314:       string get_primary_mx(string host)    { -  mapping m=do_sync_query(mkquery(host,C_IN,T_MX)); +  mapping m; +  if(sizeof(search) && host[-1] != '.' && sizeof(host/".") < 3) { +  m=do_sync_query(mkquery(host, C_IN, T_MX)); +  if(!m || !m->an || !sizeof(m->an)) +  foreach(search, string domain) +  { +  m=do_sync_query(mkquery(host+"."+domain, C_IN, T_MX)); +  if(m && m->an && sizeof(m->an)) +  break; +  } +  } else { +  m=do_sync_query(mkquery(host, C_IN, T_MX)); +  }    int minpref=29372974;    string ret;    foreach(m->an, mapping m2)
379:       if(requests[id])    throw(({"Cannot find an empty request slot.\n",backtrace()})); -  +     object r=Request();    r->req=req;    r->domain=domain;
404:       static private void generic_get(string d,    mapping answer, +  int multi,    string field,    string domain,    function callback,
411:    {    if(!answer || !answer->an || !sizeof(answer->an))    { +  if(multi == -1 || sizeof(search) < multi) { +  // Either a request without multi (ip, or FQDN) or we have tried all +  // domains.    callback(domain,0,@args); -  }else{ +  } else { +  // Multiple domain request. Try the next one... +  do_query(domain+"."+search[multi], C_IN, T_A, +  generic_get, ++multi, "a", domain, callback, @args); +  } +  } else {    foreach(answer->an, array an)    if(an[field])    {
426:       void host_to_ip(string host, function callback, mixed ... args)    { +  if(sizeof(search) && host[-1] != '.' && sizeof(host/".") < 3) {    do_query(host, C_IN, T_A, -  generic_get,"a", -  host, callback, -  @args ); +  generic_get, 0, "a", host, callback, @args ); +  } else { +  do_query(host, C_IN, T_A, +  generic_get, -1, "a", +  host, callback, @args);    } -  +  }       void ip_to_host(string ip, function callback, mixed ... args)    {    do_query(arpa_from_ip(ip), C_IN, T_PTR, -  generic_get, "ptr", +  generic_get, -1, "ptr",    ip, callback,    @args);    }