Added concept of multiple nodes
[hcoop/domtool2.git] / src / plugins / bind.sml
index d358078..4b09b45 100644 (file)
@@ -32,15 +32,14 @@ val () = Slave.registerPreHandler (fn () => (namedChanged := false;
                                             didDomain := ""))
 
 val dns : TextIO.outstream option ref = ref NONE
-fun dnsF () = valOf (!dns)
-
-fun write s = TextIO.output (dnsF (), s)
 
 val _ = Domain.registerBefore
-           (fn _ => dns := SOME (Domain.domainFile "dns"))
+           (fn _ => dns := Option.map (fn node => Domain.domainFile {node = node,
+                                                                     name = "dns"})
+                                      (Domain.dnsMaster ()))
        
 val _ = Domain.registerAfter
-           (fn _ => TextIO.closeOut (dnsF ()))
+           (fn _ => Option.app TextIO.closeOut (!dns))
 
 val dl = ErrorMsg.dummyLoc
 
@@ -67,39 +66,43 @@ val record = fn (EApp ((EApp ((EVar "dnsA", _), e1), _), e2), _) =>
              | _ => NONE
 
 fun writeRecord (evs, r) =
-    let
-       val ttl = Env.env Env.int (evs, "TTL")
-    in
-       case r of
-           A (from, to) => (write from;
-                            write ".";
-                            write (Domain.currentDomain ());
-                            write ".\t";
-                            write (Int.toString ttl);
-                            write "\tIN\tA\t";
-                            write to;
-                            write "\n")
-         | CNAME (from, to) => (write from;
+    case !dns of
+       NONE => print "Warning: DNS directive ignored because no master DNS server is configured for this domain\n"
+      | SOME file =>
+       let
+           fun write s = TextIO.output (file, s)
+           val ttl = Env.env Env.int (evs, "TTL")
+       in
+           case r of
+               A (from, to) => (write from;
                                 write ".";
                                 write (Domain.currentDomain ());
                                 write ".\t";
                                 write (Int.toString ttl);
-                                write "\tIN\tCNAME\t";
+                                write "\tIN\tA\t";
                                 write to;
-                                write ".\n")
-         | MX (num, host) => (write "\t";
-                              write (Int.toString ttl);
-                              write "\tIN\tMX\t";
-                              write (Int.toString num);
-                              write "\t";
-                              write host;
-                              write ".\n")
-         | NS host => (write "\t";
-                       write (Int.toString ttl);
-                       write "\tIN\tNS\t";
-                       write host;
-                       write ".\n")
-    end
+                                write "\n")
+             | CNAME (from, to) => (write from;
+                                    write ".";
+                                    write (Domain.currentDomain ());
+                                    write ".\t";
+                                    write (Int.toString ttl);
+                                    write "\tIN\tCNAME\t";
+                                    write to;
+                                    write ".\n")
+             | MX (num, host) => (write "\t";
+                                  write (Int.toString ttl);
+                                  write "\tIN\tMX\t";
+                                  write (Int.toString num);
+                                  write "\t";
+                                  write host;
+                                  write ".\n")
+             | NS host => (write "\t";
+                           write (Int.toString ttl);
+                           write "\tIN\tNS\t";
+                           write host;
+                           write ".\n")
+       end
 
 val () = Env.actionV_one "dns"
                         ("record", record)