69b2971997-06-09Henrik Grubbström (Grubba) /*
bf4e941997-06-09Henrik Grubbström (Grubba)  * $Id: module.pmod.in,v 1.7 1997/06/09 21:25:28 grubba Exp $
69b2971997-06-09Henrik Grubbström (Grubba)  * * YP (NIS) Functionality for Pike * * Per Hedbor & Henrik Grubbström 1996-1997 */
bca3001997-06-09Henrik Grubbström (Grubba) inherit @module@;
bf4e941997-06-09Henrik Grubbström (Grubba) constant __Domain = Domain; // Work-around for scope bug.
bca3001997-06-09Henrik Grubbström (Grubba) // Usual nicknames constant nicknames = ([
20ef1c1997-06-09Henrik Grubbström (Grubba)  "passwd":"passwd.byname", "group":"group.byname", "networks":"networks.byaddr", "hosts":"hosts.byname", "protocols":"protocols.bynumber", "services":"services.byname", "aliases":"mail.aliases",
bca3001997-06-09Henrik Grubbström (Grubba)  "ethers":"ethers.byname" ]);
69b2971997-06-09Henrik Grubbström (Grubba) 
63d9661997-06-09Henrik Grubbström (Grubba) class Map {
bf4e941997-06-09Henrik Grubbström (Grubba)  object(__Domain) domain;
69b2971997-06-09Henrik Grubbström (Grubba)  string ypmap; void create(string map,string|void d) { if (d) {
bf4e941997-06-09Henrik Grubbström (Grubba)  domain = __Domain(d);
69b2971997-06-09Henrik Grubbström (Grubba)  } else {
bf4e941997-06-09Henrik Grubbström (Grubba)  domain = __Domain();
69b2971997-06-09Henrik Grubbström (Grubba)  } ypmap = map;
bca3001997-06-09Henrik Grubbström (Grubba)  array err; do { // Force an error if the map does not exist. err = catch{ domain->match(ypmap, "foo"); return; }; } while (ypmap = nicknames[ypmap]); throw(err);
69b2971997-06-09Henrik Grubbström (Grubba)  } string match(string key) { return(domain->match(ypmap, key)); } string `[](string key) {
7d014c1997-06-09Henrik Grubbström (Grubba)  return(domain->match(ypmap, key));
69b2971997-06-09Henrik Grubbström (Grubba)  } mapping all() { return(domain->all(ypmap)); } mapping cast_to_mapping() { return(domain->all(ypmap)); } void map(function(string,string:void)|array(function(string,string:void)) fn) {
bca3001997-06-09Henrik Grubbström (Grubba)  domain->map(ypmap, fn);
69b2971997-06-09Henrik Grubbström (Grubba)  } string server() {
fdd03d1997-06-09Henrik Grubbström (Grubba)  return(domain->server(ypmap));
69b2971997-06-09Henrik Grubbström (Grubba)  } int order() { return(domain->order(ypmap)); }
bca3001997-06-09Henrik Grubbström (Grubba)  int _sizeof()
69b2971997-06-09Henrik Grubbström (Grubba)  {
bca3001997-06-09Henrik Grubbström (Grubba)  return(sizeof(indices(domain->all(ypmap))));
69b2971997-06-09Henrik Grubbström (Grubba)  }
bca3001997-06-09Henrik Grubbström (Grubba)  array(string) _indices()
69b2971997-06-09Henrik Grubbström (Grubba)  { return(indices(domain->all(ypmap))); }
bca3001997-06-09Henrik Grubbström (Grubba)  array(string) _values()
69b2971997-06-09Henrik Grubbström (Grubba)  {
7d014c1997-06-09Henrik Grubbström (Grubba)  return(values(domain->all(ypmap))); } mixed cast(string type) { switch(type) { case "mapping": return(cast_to_mapping()); default: throw(({ "Yp.YpDomain: Cast to " + type + " not supported.\n", backtrace() })); }
69b2971997-06-09Henrik Grubbström (Grubba)  } };