Merge branch 'master' of git://onigirihouse.com/git/yuuki

db4
Slava Pestov 2008-06-07 04:36:58 -05:00
commit fe451ac1e4
2 changed files with 141 additions and 7 deletions

View File

@ -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>> ] } <arr> ;
: 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 <inet4> <datagram> 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

View File

@ -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
<pango-gadget> gadget. ;
<pango> gadget. ;
: time-pango ( -- )
[ hello-pango ] time ;
! clear the caches, for testing.
: clear-pango ( -- )
dims get clear-assoc
textures get clear-assoc ;
MAIN: time-pango