]> gitweb.factorcode.org Git - factor.git/commitdiff
Set the dns server based on the platform
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 1 Oct 2010 06:23:31 +0000 (01:23 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 1 Oct 2010 06:23:31 +0000 (01:23 -0500)
extra/dns/dns.factor
extra/dns/unix/authors.txt [new file with mode: 0644]
extra/dns/unix/platforms.txt [new file with mode: 0644]
extra/dns/unix/unix.factor [new file with mode: 0644]
extra/dns/windows/authors.txt [new file with mode: 0644]
extra/dns/windows/platforms.txt [new file with mode: 0644]
extra/dns/windows/windows.factor [new file with mode: 0644]

index 61bdebfedd3c3327add87b4d20bb7758ace0a960..4d14b27e89f1ee1bfe9503cc4f85199dcce0dc07 100644 (file)
@@ -4,11 +4,11 @@ USING: accessors alien.enums alien.syntax arrays assocs
 byte-arrays calendar combinators combinators.smart constructors
 destructors fry grouping io io.binary io.buffers
 io.encodings.binary io.encodings.string io.encodings.utf8
-io.files io.ports io.sockets io.streams.byte-array io.timeouts
-kernel make math math.bitwise math.parser math.ranges
-math.statistics memoize namespaces random sequences
-slots.syntax splitting strings system unicode.categories
-vectors nested-comments io.sockets.private ;
+io.files io.ports io.sockets io.sockets.private
+io.streams.byte-array io.timeouts kernel make math math.bitwise
+math.parser math.ranges math.statistics memoize namespaces
+nested-comments random sequences slots.syntax splitting strings
+system unicode.categories vectors vocabs.loader ;
 IN: dns
 
 GENERIC: stream-peek1 ( stream -- byte/f )
@@ -59,17 +59,6 @@ SYMBOL: dns-servers
 : clear-dns-servers ( -- )
     V{ } clone dns-servers set-global ;
 
-! Google DNS servers
-CONSTANT: initial-dns-servers { "8.8.8.8" "8.8.4.4" }
-
-: load-resolve.conf ( -- seq )
-    "/etc/resolv.conf" utf8 file-lines
-    [ [ blank? ] trim ] map
-    [ "#" head? not ] filter
-    [ [ " " split1 swap ] dip push-at ] sequence>hashtable "nameserver" swap at ;
-
-dns-servers [ initial-dns-servers >vector ] initialize
-
 : >dotted ( domain -- domain' )
     dup "." tail? [ "." append ] unless ;
 
@@ -406,3 +395,12 @@ M: SOA rdata>byte-array
     [ dns-A-query a-message. ]
     [ dns-AAAA-query a-message. ]
     [ dns-MX-query mx-message. ] tri ;
+    
+HOOK: initial-dns-servers os ( -- seq )
+
+{
+    { [ os windows? ] [ "dns.windows" ] }
+    { [ os unix? ] [ "dns.unix" ] }
+} cond require
+    
+dns-servers [ initial-dns-servers >vector ] initialize
diff --git a/extra/dns/unix/authors.txt b/extra/dns/unix/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/dns/unix/platforms.txt b/extra/dns/unix/platforms.txt
new file mode 100644 (file)
index 0000000..509143d
--- /dev/null
@@ -0,0 +1 @@
+unix
diff --git a/extra/dns/unix/unix.factor b/extra/dns/unix/unix.factor
new file mode 100644 (file)
index 0000000..6c5a1b9
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: assocs dns io.encodings.utf8 io.files kernel
+math.statistics sequences splitting system unicode.categories ;
+IN: dns.unix
+
+: load-resolve.conf ( -- seq )
+    "/etc/resolv.conf" utf8 file-lines
+    [ [ blank? ] trim ] map
+    [ "#" head? not ] filter
+    [ [ " " split1 swap ] dip push-at ] sequence>hashtable "nameserver" swap at ;
+
+M: unix initial-dns-servers load-resolve.conf ;
\ No newline at end of file
diff --git a/extra/dns/windows/authors.txt b/extra/dns/windows/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/dns/windows/platforms.txt b/extra/dns/windows/platforms.txt
new file mode 100644 (file)
index 0000000..8e1a559
--- /dev/null
@@ -0,0 +1 @@
+windows
diff --git a/extra/dns/windows/windows.factor b/extra/dns/windows/windows.factor
new file mode 100644 (file)
index 0000000..a43eede
--- /dev/null
@@ -0,0 +1,6 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: dns system windows.iphlpapi ;
+IN: dns.windows
+
+M: windows initial-dns-servers dns-server-ips ;
\ No newline at end of file