Branch: Tag:

1998-09-13

1998-09-13 19:18:04 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added async_client()->get_mx() and async_client()->get_mx_all().
Changed behaviour of private function generic_get() somewhat.

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

573:    static private void generic_get(string d,    mapping answer,    int multi, +  int all, +  int type,    string field,    string domain,    function callback,
586:    callback(domain,0,@args);    } else {    // Multiple domain request. Try the next one... -  do_query(domain+"."+domains[multi], C_IN, T_A, -  generic_get, ++multi, "a", domain, callback, @args); +  do_query(domain+"."+domains[multi], C_IN, type, +  generic_get, ++multi, all, type, field, domain, +  callback, @args);    }    } else { -  +  if (all) { +  callback(domain, answer->an, @args); +  } else {    foreach(answer->an, array an)    if(an[field])    { -  callback(domain,an[field],@args); +  callback(domain, an[field], @args);    return;    }    callback(domain,0,@args);    return;    }    } -  +  }       void host_to_ip(string host, function callback, mixed ... args)    {    if(sizeof(domains) && host[-1] != '.' && sizeof(host/".") < 3) {    do_query(host, C_IN, T_A, -  generic_get, 0, "a", host, callback, @args ); +  generic_get, 0, 0, T_A, "a", host, callback, @args );    } else {    do_query(host, C_IN, T_A, -  generic_get, -1, "a", +  generic_get, -1, 0, "a",    host, callback, @args);    }    }
616:    void ip_to_host(string ip, function callback, mixed ... args)    {    do_query(arpa_from_ip(ip), C_IN, T_PTR, -  generic_get, -1, "ptr", +  generic_get, -1, 0, T_PTR, "ptr",    ip, callback,    @args);    }    -  +  void get_mx_all(string host, function callback, mixed ... args) +  { +  mapping m; +  if(sizeof(domains) && host[-1] != '.' && sizeof(host/".") < 3) { +  do_query(host, C_IN, T_MX, +  generic_get, 0, 1, T_MX, "mx", host, callback, @args); +  } else { +  do_query(host, C_IN, T_MX, +  generic_get, -1, 1, T_MX, "mx", host, callback, @args); +  } +  } +  +  void get_mx(string host, function callback, mixed ... args) +  { +  get_mx_all(host, +  lambda(string domain, array(mapping) mx, +  function callback, mixed ... args) { +  array a; +  if (mx) { +  a = column(mx, "mx"); +  sort(column(mx, "preference"), a); +  } +  callback(a, @args); +  }, callback, args); +  } +     void create(void|string|array(string) server, void|string|array(string) domain)    {    if(!udp::bind(0))