Replaced posix regexp strings by sre expressions.
This commit is contained in:
parent
2442e88ab7
commit
cbb4609c3a
|
@ -264,7 +264,8 @@
|
||||||
(if *debug* (display "name->octets\n"))
|
(if *debug* (display "name->octets\n"))
|
||||||
(let loop ((s s))
|
(let loop ((s s))
|
||||||
(cond
|
(cond
|
||||||
((regexp-search (posix-string->regexp "^([^.]*)\\.(.*)") s)
|
((regexp-search (rx (: bos (submatch (* (~ "."))) "." (submatch (* any))))
|
||||||
|
s)
|
||||||
=> (lambda (match)
|
=> (lambda (match)
|
||||||
(append
|
(append
|
||||||
(encode-portion (match:substring match 1))
|
(encode-portion (match:substring match 1))
|
||||||
|
@ -276,6 +277,7 @@
|
||||||
(encode-portion s)
|
(encode-portion s)
|
||||||
(list *nul*)))))))
|
(list *nul*)))))))
|
||||||
|
|
||||||
|
|
||||||
;; for tcp: message has to be tagged with its length
|
;; for tcp: message has to be tagged with its length
|
||||||
(define (add-size-tag m)
|
(define (add-size-tag m)
|
||||||
(if *debug* (display "add-size-tag\n"))
|
(if *debug* (display "add-size-tag\n"))
|
||||||
|
@ -322,17 +324,25 @@
|
||||||
(char->ascii (list-ref s 2))
|
(char->ascii (list-ref s 2))
|
||||||
(char->ascii (list-ref s 3))))
|
(char->ascii (list-ref s 3))))
|
||||||
|
|
||||||
|
(define ip-string-regexp (rx (: bos
|
||||||
|
(submatch (** 1 3 digit)) "."
|
||||||
|
(submatch (** 1 3 digit)) "."
|
||||||
|
(submatch (** 1 3 digit)) "."
|
||||||
|
(submatch (** 1 3 digit))
|
||||||
|
eos)))
|
||||||
|
|
||||||
;; converts an ip-string to octets
|
;; converts an ip-string to octets
|
||||||
(define (string->octet-ip s)
|
(define (string->octet-ip s)
|
||||||
(if *debug* (display "string->octet-ip\n"))
|
(cond
|
||||||
(let loop ((s s)
|
((regexp-search ip-string-regexp s)
|
||||||
(result '()))
|
=> (lambda (match)
|
||||||
(cond
|
(list
|
||||||
((regexp-search (posix-string->regexp "^([^.]*)\\.(.*)") s)
|
(ascii->char (string->number (match:substring match 1)))
|
||||||
=> (lambda (match)
|
(ascii->char (string->number (match:substring match 2)))
|
||||||
(loop (match:substring match 2) (append result (list (ascii->char (string->number (match:substring match 1))))))))
|
(ascii->char (string->number (match:substring match 3)))
|
||||||
(else
|
(ascii->char (string->number (match:substring match 4))))))
|
||||||
(append result (list (ascii->char (string->number s))))))))
|
(else
|
||||||
|
(error "invalid ip-string" s))))
|
||||||
|
|
||||||
;; calculates a "random" number, needed for message-ids
|
;; calculates a "random" number, needed for message-ids
|
||||||
(define random
|
(define random
|
||||||
|
@ -344,24 +354,21 @@
|
||||||
|
|
||||||
;; checks if a string is a ip
|
;; checks if a string is a ip
|
||||||
(define (ip-string? s)
|
(define (ip-string? s)
|
||||||
(if *debug* (display "ip-string->in-addr\n"))
|
(define (byte-as-string? string)
|
||||||
(let loop ((s s)
|
(let ((number (string->number string)))
|
||||||
(count 0))
|
(and number
|
||||||
(cond
|
(>= number 0)
|
||||||
((regexp-search (posix-string->regexp "^([^.]*)\\.(.*)") s)
|
(< number 256))))
|
||||||
=> (lambda (match)
|
(cond
|
||||||
(let* ((portion (match:substring match 1))
|
((regexp-search ip-string-regexp s)
|
||||||
(number (string->number portion)))
|
=> (lambda (match)
|
||||||
(if (and number (< number 256))
|
(and (byte-as-string? (match:substring match 1))
|
||||||
(loop (match:substring match 2) (+ count 1))
|
(byte-as-string? (match:substring match 2))
|
||||||
#f))))
|
(byte-as-string? (match:substring match 3))
|
||||||
(else
|
(byte-as-string? (match:substring match 4)))))
|
||||||
(let ((number (string->number s)))
|
(else #f)))
|
||||||
(and number
|
|
||||||
(< number 256)
|
|
||||||
(= count 3)
|
|
||||||
#t))))))
|
|
||||||
|
|
||||||
|
|
||||||
;; checks if v is a address32
|
;; checks if v is a address32
|
||||||
(define (address32? v)
|
(define (address32? v)
|
||||||
(and (number? v)
|
(and (number? v)
|
||||||
|
@ -369,25 +376,17 @@
|
||||||
|
|
||||||
;; returns a in-addr.arpa name-string or #f (needed to resolve hostname by ip)
|
;; returns a in-addr.arpa name-string or #f (needed to resolve hostname by ip)
|
||||||
(define (ip-string->in-addr s)
|
(define (ip-string->in-addr s)
|
||||||
(if *debug* (display "ip-string->in-addr\n"))
|
(cond
|
||||||
(let loop ((s s)
|
((regexp-search ip-string-regexp s)
|
||||||
(count 0)
|
=> (lambda (match)
|
||||||
(result ""))
|
(string-append
|
||||||
(cond
|
(match:substring match 4) "."
|
||||||
((regexp-search (posix-string->regexp "^([^.]*)\\.(.*)") s)
|
(match:substring match 3) "."
|
||||||
=> (lambda (match)
|
(match:substring match 2) "."
|
||||||
(let* ((portion (match:substring match 1))
|
(match:substring match 1) "."
|
||||||
(number (string->number portion)))
|
"in-addr.arpa")))
|
||||||
(if (and number (< number 256))
|
(else #f)))
|
||||||
(loop (match:substring match 2) (+ count 1) (string-append portion "." result))
|
|
||||||
#f))))
|
|
||||||
(else
|
|
||||||
(let ((number (string->number s)))
|
|
||||||
(and number
|
|
||||||
(< number 256)
|
|
||||||
(= count 3)
|
|
||||||
(string-append s "." result "in-addr.arpa")))))))
|
|
||||||
|
|
||||||
;; filters types in a list of rrs
|
;; filters types in a list of rrs
|
||||||
(define (filter-type list type)
|
(define (filter-type list type)
|
||||||
(if *debug* (display "ip-string->in-addr\n"))
|
(if *debug* (display "ip-string->in-addr\n"))
|
||||||
|
@ -1045,9 +1044,11 @@
|
||||||
(if (null? ns)
|
(if (null? ns)
|
||||||
(dns-error 'no-nameservers)
|
(dns-error 'no-nameservers)
|
||||||
ns))
|
ns))
|
||||||
((regexp-search
|
((regexp-search
|
||||||
(posix-string->regexp
|
(rx (: "nameserver" (+ (| " " "\t")
|
||||||
"nameserver[ ]+([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)") l)
|
(submatch (** 1 3 digit)
|
||||||
|
(= 3 (: "." (** 1 3 digit)))))))
|
||||||
|
l)
|
||||||
=> (lambda (match)
|
=> (lambda (match)
|
||||||
(loop (append ns (list (ip-string->address32 (match:substring match 1)))))))
|
(loop (append ns (list (ip-string->address32 (match:substring match 1)))))))
|
||||||
(else
|
(else
|
||||||
|
|
Loading…
Reference in New Issue