From 39d3769df808e50c305775c25c6c0c7239be5aaf Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Fri, 6 Jun 2008 19:49:42 -0500 Subject: [PATCH 1/2] Add dns.server --- extra/dns/server/server.factor | 139 +++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 extra/dns/server/server.factor diff --git a/extra/dns/server/server.factor b/extra/dns/server/server.factor new file mode 100644 index 0000000000..7c33265d39 --- /dev/null +++ b/extra/dns/server/server.factor @@ -0,0 +1,139 @@ + +USING: kernel + combinators + sequences + math + io.sockets + unicode.case + accessors + combinators.cleave + newfx + dns ; + +IN: dns.server + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: records ( -- vector ) V{ } ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: filter-by-name ( records name -- records ) swap [ name>> = ] with filter ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: {name-type-class} ( obj -- array ) + { [ name>> >lower ] [ type>> ] [ class>> ] } ; + +: rr=query? ( obj obj -- ? ) [ {name-type-class} ] bi@ = ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: matching-rrs ( query -- rrs ) records [ rr=query? ] with filter ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: matching-rrs? ( query -- query rrs/f ? ) dup matching-rrs dup empty? not ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: matching-cname? ( query -- query rr/f ? ) + dup clone CNAME >>type matching-rrs + dup empty? [ drop f f ] [ 1st t ] if ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +DEFER: query->rrs + +: query-canonical ( query rr -- rrs ) + tuck [ clone ] [ rdata>> ] bi* >>name query->rrs prefix-on ; + +: query->rrs ( query -- rrs/f ) + { + { [ matching-rrs? ] [ nip ] } + { [ drop matching-cname? ] [ query-canonical ] } + { [ drop t ] [ drop f ] } + } + cond ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: cdr-name ( name -- name ) dup CHAR: . index 1+ tail ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: delegate-servers? ( name -- name rrs ? ) + dup NS IN query boa matching-rrs dup empty? not ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: delegate-servers ( name -- rrs ) + { + { [ dup "" = ] [ drop { } ] } + { [ delegate-servers? ] [ nip ] } + { [ drop t ] [ cdr-name delegate-servers ] } + } + cond ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: delegate-addresses ( rrs-ns -- rrs-a ) + [ rdata>> A IN query boa matching-rrs ] map concat ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: have-delegates? ( query -- query rrs-ns ? ) + dup name>> delegate-servers dup empty? not ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: fill-additional ( message -- message ) + dup authority-section>> delegate-addresses >>additional-section ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: no-records-with-name? ( query -- query ? ) + dup name>> records [ name>> = ] with filter empty? ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: find-answer ( message -- message ) + dup message-query ! message query + { + { [ dup query->rrs dup ] [ nip >>answer-section 1 >>aa ] } + { [ drop have-delegates? ] [ nip >>authority-section fill-additional ] } + { [ drop no-records-with-name? ] [ drop NAME-ERROR >>rcode ] } + { [ drop t ] [ ] } + } + cond ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: (socket) ( -- vec ) V{ f } ; + +: socket ( -- socket ) (socket) 1st ; + +: init-socket-on-port ( port -- ) + f swap 0 (socket) as-mutate ; + +: init-socket ( -- ) 53 init-socket-on-port ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: loop ( -- ) + socket receive + swap + parse-message + find-answer + message->ba + swap + socket send + loop ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: start ( -- ) init-socket loop ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +MAIN: start \ No newline at end of file From b1e761509eae5d75b94c56cc5545eafae0de193f Mon Sep 17 00:00:00 2001 From: Matthew Willis Date: Fri, 6 Jun 2008 20:12:16 -0700 Subject: [PATCH 2/2] pango.cairo.samples failed to load --- extra/pango/cairo/samples/samples.factor | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/extra/pango/cairo/samples/samples.factor b/extra/pango/cairo/samples/samples.factor index 644d731d70..f081650943 100644 --- a/extra/pango/cairo/samples/samples.factor +++ b/extra/pango/cairo/samples/samples.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: prettyprint sequences ui.gadgets.panes pango.cairo.gadgets math kernel cairo cairo.ffi -pango.cairo tools.time namespaces assocs +pango.cairo pango.gadgets tools.time namespaces assocs threads io.backend io.encodings.utf8 io.files ; IN: pango.cairo.samples @@ -10,14 +10,9 @@ IN: pango.cairo.samples : hello-pango ( -- ) "monospace 10" "resource:extra/pango/cairo/gadgets/gadgets.factor" normalize-path utf8 file-contents - gadget. ; + gadget. ; : time-pango ( -- ) [ hello-pango ] time ; -! clear the caches, for testing. -: clear-pango ( -- ) - dims get clear-assoc - textures get clear-assoc ; - MAIN: time-pango