Author: hannes
Date: Thu Sep 8 20:47:32 2005
New Revision: 9963
Modified:
trunk/libraries/koala/sources/examples/buddha/buddha.dylan
trunk/libraries/koala/sources/examples/buddha/cidr.dylan
trunk/libraries/koala/sources/examples/buddha/class-browser.dylan
trunk/libraries/koala/sources/examples/buddha/host.dylan
trunk/libraries/koala/sources/examples/buddha/ipv4.dylan
trunk/libraries/koala/sources/examples/buddha/mac.dylan
trunk/libraries/koala/sources/examples/buddha/network.dylan
trunk/libraries/koala/sources/examples/buddha/subnet.dylan
trunk/libraries/koala/sources/examples/buddha/util.dylan
trunk/libraries/koala/sources/examples/buddha/zone.dylan
Log:
Bug: 7257
*implemented <wrapper-sequence> and <mutable-wrapper-sequence>
*used them as superclass of <ip-address> and <mac-address>
*more error checking when adding a host
*unbreak adding zones via web interface
*removed network-hosts slot from <network>, doesn't make sense,
hosts only need to be known in <subnet> and <zone>
Modified: trunk/libraries/koala/sources/examples/buddha/buddha.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/buddha.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/buddha.dylan Thu Sep 8
20:47:32 2005
@@ -381,9 +381,11 @@
tr { th("Name"), th("IP"), th("Net"), th("Mac"), th("Zone") },
do(let res = make(<list>);
for (net in *config*.config-nets)
- do(method(x)
- res := add!(res, gen-xml(x));
- end, net.network-hosts);
+ for (subnet in net.network-subnets)
+ do(method(x)
+ res := add!(res, gen-xml(x));
+ end, subnet.subnet-hosts);
+ end;
end;
reverse(res))
},
@@ -446,6 +448,8 @@
input(type => "text", name => "hostmaster"),
text("Serial"),
input(type => "text", name => "serial"),
+ text("Refresh"),
+ input(type => "text", name => "refresh"),
text("Retry"),
input(type => "text", name => "retry"),
text("Expire"),
@@ -646,7 +650,7 @@
time-to-live: time-to-live,
nameserver: list(nameserver),
mail-exchange: list(mail-exchange),
- txt: txt);
+ txt: list(txt));
*config*.config-zones :=
sort!(add!(*config*.config-zones, zone));
#t;
@@ -655,14 +659,14 @@
define method respond-to-post
(page == #"host", request :: <request>, response :: <response>)
let name = get-query-value("name");
- let ip = make(<ip-address>, ip: get-query-value("ip"));
+ let ip = make(<ip-address>, data: get-query-value("ip"));
let mac = get-query-value("mac");
let zone = get-query-value("zone");
- let network = find-network(*config*, ip);
+ let network = find-network(find-network(*config*, ip), ip);
let host = make(<host>,
name: name,
ip: ip,
- net: find-network(network, ip),
+ net: network,
mac: parse-mac(mac),
zone: find-zone(*config*, zone));
add-host(network, host);
@@ -692,14 +696,6 @@
end;
begin
- let dood
- = make(<dood>,
- locator:
concatenate("/home/hannes/dylan/libraries/koala/www/buddha/",
- base64-encode("foo")),
- direction: #"input");
- *config* := dood-root(dood);
- dood-close(dood);
-
main();
end;
Modified: trunk/libraries/koala/sources/examples/buddha/cidr.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/cidr.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/cidr.dylan Thu Sep 8
20:47:32 2005
@@ -23,7 +23,7 @@
network-address := address-and-mask[0];
netmask := address-and-mask[1];
end if;
- network-address := make(<ip-address>, ip: network-address);
+ network-address := make(<ip-address>, data: network-address);
end;
if (instance?(netmask, <string>))
if (any?(method(x) x = '.' end, netmask))
@@ -56,20 +56,20 @@
define method base-network-address (cidr :: <cidr>)
=> (ip-address :: <ip-address>)
make(<ip-address>,
- ip: map(logand,
- ip(netmask-address(cidr)),
- ip(network-address(cidr))));
+ data: map(logand,
+ netmask-address(cidr),
+ network-address(cidr)))
end;
define method broadcast-address (cidr :: <cidr>)
=> (ip-address :: <ip-address>)
let mask = map(method(x)
logand(255, lognot(x));
- end, ip(netmask-address(cidr)));
+ end, netmask-address(cidr));
make(<ip-address>,
- ip: map(logior,
- ip(network-address(cidr)),
- mask));
+ data: map(logior,
+ network-address(cidr),
+ mask));
end;
define method network-address (cidr :: <cidr>)
Modified: trunk/libraries/koala/sources/examples/buddha/class-browser.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/class-browser.dylan
(original)
+++ trunk/libraries/koala/sources/examples/buddha/class-browser.dylan Thu Sep
8 20:47:32 2005
@@ -24,6 +24,12 @@
end)
end;
+define method show (object :: <mac-address>, slot-name :: <string>)
+ list(with-xml()
+ li(concatenate(slot-name, ":", as(<string>, object)))
+ end)
+end;
+
define method show (object :: <cidr>, slot-name :: <string>)
list(with-xml()
li(concatenate(slot-name, ":", as(<string>, object)))
Modified: trunk/libraries/koala/sources/examples/buddha/host.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/host.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/host.dylan Thu Sep 8
20:47:32 2005
@@ -17,7 +17,7 @@
let args = rest;
if (instance?(ip, <string>))
args := exclude(args, #"ip");
- ip := make(<ip-address>, ip: ip);
+ ip := make(<ip-address>, data: ip);
end;
apply(next-method, host, ip: ip, args);
end method;
@@ -27,7 +27,7 @@
format(stream, "Host %s Zone %s Mac %s\n",
host.host-name,
host.host-zone.zone-name,
- mac-to-string(host.host-mac));
+ as(<string>, host.host-mac));
format(stream, "IP %s Net %s\n",
as(<string>, host.host-ipv4-address),
as(<string>, host.host-net.network-cidr));
@@ -44,7 +44,7 @@
td(host.host-name),
td(as(<string>, host.host-ipv4-address)),
td(as(<string>, host.host-net.network-cidr)),
- td(mac-to-string(host.host-mac)),
+ td(as(<string>, host.host-mac)),
td(host.host-zone.zone-name)
}
end;
@@ -53,7 +53,7 @@
define method print-isc-dhcpd-file (host :: <host>, stream :: <stream>)
=> ()
format(stream, "host %s {\n", host.host-name);
- format(stream, "\thardware ethernet %s;\n", mac-to-string(host.host-mac));
+ format(stream, "\thardware ethernet %s;\n", as(<string>, host.host-mac));
format(stream, "\tfixed-address %s;\n", as(<string>,
host.host-ipv4-address));
format(stream, "}\n\n");
end;
Modified: trunk/libraries/koala/sources/examples/buddha/ipv4.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/ipv4.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/ipv4.dylan Thu Sep 8
20:47:32 2005
@@ -1,20 +1,18 @@
module: buddha
author: Hannes Mehnert <hannes@xxxxxxxxxxx>
-define class <ip-address> (<object>)
- slot ip :: <byte-vector>, init-keyword: ip:;
+define class <ip-address> (<mutable-wrapper-sequence>)
end;
define method make (ip-address == <ip-address>,
#next next-method,
#rest rest,
- #key ip,
+ #key data,
#all-keys) => (res :: <ip-address>)
- let args = rest;
- if (instance?(ip, <string>))
- ip := as(<ip-address>, ip);
+ if (instance?(data, <string>))
+ as(<ip-address>, data);
else
- apply(next-method, ip-address, ip: ip, args);
+ apply(next-method, ip-address, rest);
end if;
end;
@@ -30,14 +28,14 @@
=> (res :: <ip-address>)
let rem :: <integer> = b;
let res = make(<byte-vector>, size: 4, fill: 0);
- for (ele in reverse(a.ip),
+ for (ele in reverse(a),
i from 3 by -1)
let (quotient, remainder) = truncate/(ele + rem, 256);
res[i] := remainder;
rem := quotient;
//format-out("rem %= res[i] %=\n", rem, res[i]);
end;
- res := make(<ip-address>, ip: res);
+ res := make(<ip-address>, data: res);
//format-out("%= + %= = %=\n", a, b, res);
res;
end;
@@ -51,7 +49,7 @@
=> (res :: <ip-address>)
let rem :: <integer> = b;
let res = make(<byte-vector>, size: 4, fill: 0);
- for (ele in reverse(a.ip),
+ for (ele in reverse(a),
i from 3 by -1)
if (ele - rem < 0)
//format-out("ele - rem < 0 (%= - %= < %=)\n", ele, rem, ele - rem);
@@ -63,7 +61,7 @@
end;
//format-out("rem %= res[i] %=\n", rem, res[i]);
end;
- res := make(<ip-address>, ip: res);
+ res := make(<ip-address>, data: res);
//format-out("%= - %= = %=\n", a, b, res);
res;
end;
@@ -71,8 +69,8 @@
define method \< (a :: <ip-address>, b :: <ip-address>)
=> (res :: <boolean>)
block(done)
- for (ele1 in a.ip,
- ele2 in b.ip)
+ for (ele1 in a,
+ ele2 in b)
if (ele1 < ele2)
done(#t);
elseif (ele1 > ele2)
@@ -86,8 +84,8 @@
define method \= (a :: <ip-address>, b :: <ip-address>)
=> (res :: <boolean>)
block(done)
- for (ele1 in a.ip,
- ele2 in b.ip)
+ for (ele1 in a,
+ ele2 in b)
unless (ele1 = ele2)
done(#f);
end;
@@ -101,7 +99,7 @@
define method as (class == <string>, ip-address :: <ip-address>)
=> (res :: <string>)
let strings = make(<list>);
- for (ele in ip-address.ip)
+ for (ele in ip-address)
strings := add(strings, integer-to-string(ele));
end;
reduce1(method(x, y)
@@ -120,7 +118,7 @@
res[i] := logand(255, ash(255, 8 - mask));
end if
end for;
- make(<ip-address>, ip: res);
+ make(<ip-address>, data: res);
end;
define method as (class == <ip-address>, string :: <string>)
@@ -131,14 +129,14 @@
for (i from 0 below res.size)
res[i] := as(<byte>, ints[i]);
end;
- make(<ip-address>, ip: res);
+ make(<ip-address>, data: res);
end;
define method string-to-netmask (string :: <string>)
=> (netmask :: <integer>)
//"255.255.255.0"
- let vec = reverse(as(<ip-address>, string).ip);
+ let vec = reverse(as(<ip-address>, string));
//0, 255, 255, 255
let mask = 32;
block (not-zero)
Modified: trunk/libraries/koala/sources/examples/buddha/mac.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/mac.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/mac.dylan Thu Sep 8
20:47:32 2005
@@ -1,7 +1,8 @@
module: buddha
author: Hannes Mehnert <hannes@xxxxxxxxxxx>
-define constant <mac-address> = <list>;
+define class <mac-address> (<wrapper-sequence>)
+end;
define method parse-mac (mac :: <string>)
=> (res :: false-or(<mac-address>))
@@ -26,11 +27,11 @@
end unless;
end for;
end for;
- let res = make(<mac-address>, size: 6);
+ let res = make(<list>, size: 6);
for (i from 0 below res.size)
res[i] := fields[i];
end;
- res;
+ make(<mac-address>, data: res);
elseif (size(mac) = 12)
//assume xxxxxxxxxxxx
for(ele in mac)
@@ -38,7 +39,7 @@
parse-error(#f);
end unless;
end for;
- string-to-mac(mac);
+ as(<mac-address>, mac);
else
//something completely different
parse-error(#f);
@@ -46,16 +47,32 @@
end block;
end;
-define method string-to-mac (string :: <string>) => (mac :: <mac-address>)
+define method \= (a :: mac-address>, b :: <mac-address>)
+ => (res :: <boolean)
+ block(done)
+ for (ele1 in a,
+ ele2 in b)
+ unless (ele1 = ele2)
+ done(#f);
+ end;
+ end;
+ done(#t);
+ end;
+end;
+
+define method as (class == <mac-address>, string :: <string>)
+ => (res :: <mac-address>)
//we are sure string is a correct mac-address (12 hex digits)
- let mac = make(<mac-address>, size: 6);
+ let mac = make(<list>, size: 6);
for (i from 0 below string.size by 2,
j from 0)
mac[j] := copy-sequence(string, start: i, end: i + 2);
end;
- mac;
+ make(<mac-address>,
+ data: mac);
end;
-define method mac-to-string (mac :: <mac-address>) => (string :: <string>)
- reduce1(method(a,b) concatenate(a, ":", b) end, mac);
+define method as (class == <string>, mac :: <mac-address>)
+ => (string :: <string>)
+ reduce1(method(a,b) concatenate(a, ":", b) end, mac.data);
end;
Modified: trunk/libraries/koala/sources/examples/buddha/network.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/network.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/network.dylan Thu Sep 8
20:47:32 2005
@@ -4,7 +4,6 @@
define class <network> (<object>)
slot network-cidr :: <cidr>, required-init-keyword: cidr:;
slot network-subnets :: <list> = #(), init-keyword: subnets:;
- slot network-hosts :: <list> = #(), init-keyword: hosts:;
slot dhcp? :: <boolean> = #t, init-keyword: dhcp?:;
slot dhcp-default-lease-time :: false-or(<integer>) = #f,
init-keyword: dhcp-default-lease-time:;
@@ -110,15 +109,6 @@
res;
end;
-define method add-host (network :: <network>, host :: <host>)
- => ()
- network.network-hosts := sort!(add!(network.network-hosts, host));
- host.host-net.network-hosts
- := sort!(add!(host.host-net.network-hosts, host));
- host.host-zone.zone-hosts
- := sort!(add!(host.host-zone.zone-hosts, host));
-end;
-
define method add-subnet (network :: <network>, subnet :: <subnet>)
=> ()
if (subnet-in-net?(network, subnet))
@@ -136,15 +126,6 @@
end;
end;
-define method remove-host (network :: <network>, host :: <host>)
- => ()
- network.network-hosts := remove!(network.network-hosts, host);
- host.host-net.network-hosts
- := remove!(host.host-net.network-hosts, host);
- host.host-zone.zone-hosts
- := remove!(host.host-zone.zone-hosts, host);
-end;
-
define method remove-subnet (network :: <network>, subnet :: <subnet>)
=> ()
network.network-subnets := remove!(network.network-subnets,
@@ -169,9 +150,6 @@
end, network.dhcp-options);
for (subnet in network.network-subnets)
print-isc-dhcpd-file(subnet, stream);
- end;
- for (host in network.network-hosts)
- print-isc-dhcpd-file(host, stream);
end;
end if;
end;
Modified: trunk/libraries/koala/sources/examples/buddha/subnet.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/subnet.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/subnet.dylan Thu Sep 8
20:47:32 2005
@@ -3,6 +3,7 @@
define class <subnet> (<network>)
slot subnet-vlan :: false-or(<vlan>) = #f, init-keyword: vlan:;
+ slot subnet-hosts :: <list> = #(), init-keyword: hosts:;
slot dhcp-start :: <ip-address>, init-keyword: dhcp-start:;
slot dhcp-end :: <ip-address>, init-keyword: dhcp-end:;
slot dhcp-router :: false-or(<ip-address>) = #f,
@@ -69,6 +70,45 @@
end;
end;
+define method add-host (subnet :: <subnet>, host :: <host>)
+ => ()
+ if ((host.host-ipv4-address = network-address(subnet.network-cidr)) |
+ (host.host-ipv4-address = broadcast-address(subnet.network-cidr)))
+ format-out("Host can't have the network or broadcast address as IP %=\n",
+ host);
+ elseif (member?(host,
+ subnet.subnet-hosts,
+ test: method(x, y)
+ x.host-ipv4-address = y.host-ipv4-address;
+ end))
+ format-out("Host with same IP already exists: %=\n", host);
+ elseif (member?(host,
+ host.host-zone.zone-hosts,
+ test: method(x, y)
+ x.host-name = y.host-name
+ end))
+ format-out("Host with same name already exists: %=\n", host);
+ elseif (member?(host,
+ subnet.subnet-hosts,
+ test: method(x, y)
+ x.host-mac = y.host-mac
+ end))
+ format-out("Host with same mac already exists in this subnet: %=\n", host);
+ else
+ subnet.subnet-hosts := sort!(add!(subnet.subnet-hosts, host));
+ host.host-zone.zone-hosts
+ := sort!(add!(host.host-zone.zone-hosts, host));
+ end;
+end;
+
+define method remove-host (subnet :: <subnet>, host :: <host>)
+ => ()
+ subnet.subnet-hosts := remove!(subnet.subnet-hosts, host);
+ host.host-zone.zone-hosts
+ := remove!(host.host-zone.zone-hosts, host);
+end;
+
+
define method print-isc-dhcpd-file (subnet :: <subnet>, stream :: <stream>)
=> ()
if (subnet.dhcp?)
@@ -96,6 +136,9 @@
as(<string>, tail(x)));
end, generate-dhcp-ranges(subnet));
format(stream, "}\n\n");
+ for (host in subnet.subnet-hosts)
+ print-isc-dhcpd-file(host, stream);
+ end;
end if;
end;
@@ -104,7 +147,7 @@
let start-ip :: <ip-address> = subnet.dhcp-start;
let end-ip :: <ip-address> = subnet.dhcp-end;
let res = make(<list>);
- for (host in subnet.network-hosts)
+ for (host in subnet.subnet-hosts)
let host-ip = host.host-ipv4-address;
if ((host-ip > start-ip) & (host-ip < end-ip))
res := add!(res, pair(start-ip, host-ip - 1));
Modified: trunk/libraries/koala/sources/examples/buddha/util.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/util.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/util.dylan Thu Sep 8
20:47:32 2005
@@ -37,3 +37,64 @@
end;
apply(values, result)
end;
+
+define class <wrapper-sequence> (<sequence>)
+ slot data :: <sequence>, init-keyword: data:;
+end;
+
+define inline method forward-iteration-protocol
+ (seq :: <wrapper-sequence>)
+ => (initial-state,
+ limit,
+ next-state :: <function>,
+ finished-state? :: <function>,
+ current-key :: <function>,
+ current-element :: <function>,
+ current-element-setter :: <function>,
+ copy-state :: <function>)
+ let (data-initial-state, data-limit, data-next-state,
+ data-finished-state?, data-current-key, data-current-element,
+ data-current-element-setter, data-copy-state)
+ = forward-iteration-protocol(seq.data);
+ values(data-initial-state,
+ data-limit,
+ method(col, state)
+ data-next-state(col.data, state)
+ end,
+ method(col, state, limit)
+ data-finished-state?(col.data, state, limit)
+ end,
+ method(col, state)
+ data-current-key(col.data, state)
+ end,
+ method(col, state)
+ data-current-element(col.data, state)
+ end,
+ method(value, col, state)
+ data-current-element-setter(value, col.data, state)
+ end,
+ method(col, state)
+ data-copy-state(col.data, state)
+ end);
+end;
+
+define method element
+ (seq :: <wrapper-sequence>, key, #key default = unsupplied())
+ => (res)
+ element(seq.data, key, default: default);
+end;
+
+define class <mutable-wrapper-sequence> (<wrapper-sequence>,
<mutable-sequence>)
+end;
+
+define method element-setter (new-value,
+ seq :: <mutable-wrapper-sequence>,
+ key) => (res)
+ seq.data[key] := new-value;
+end;
+
+define method type-for-copy (seq :: <wrapper-sequence>)
+ => (res :: <type>)
+ //<byte-vector>
+ type-for-copy(seq.data);
+end;
Modified: trunk/libraries/koala/sources/examples/buddha/zone.dylan
==============================================================================
--- trunk/libraries/koala/sources/examples/buddha/zone.dylan (original)
+++ trunk/libraries/koala/sources/examples/buddha/zone.dylan Thu Sep 8
20:47:32 2005
@@ -15,7 +15,7 @@
slot zone-minimum :: <integer>, init-keyword: minimum:;
slot zone-nameserver :: <list>, init-keyword: nameserver:;
slot zone-mail-exchange :: <list>, init-keyword: mail-exchange:;
- slot zone-text :: <list>, init-keyword: txt:;
+ slot zone-text :: <list> = #(), init-keyword: txt:;
end class;
define method print-object (zone :: <zone>, stream :: <stream>)
@@ -44,7 +44,7 @@
end, zone.zone-nameserver);
do(method(x)
format(stream, "%d\tIN\tPTR\n%s.%s.\n",
- x.host-ipv4-address.ip[3],
+ x.host-ipv4-address[3],
x.host-name,
zone.zone-name)
end, zone.zone-hosts);
--
Gd-chatter mailing list
Gd-chatter@xxxxxxxxxxxxxxxx
https://gauss.gwydiondylan.org/mailman/listinfo/gd-chatter
|