diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-10 03:05:58 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-10 03:06:09 +0200 |
commit | 8fbfe00c892b8e64fc0131952d0c2c58128e9790 (patch) | |
tree | 1b015d7b9139c194f4310f7c795b3fcae188d216 /module/calp | |
parent | Add TODO about better way to get CPU count. (diff) | |
download | calp-8fbfe00c892b8e64fc0131952d0c2c58128e9790.tar.gz calp-8fbfe00c892b8e64fc0131952d0c2c58128e9790.tar.xz |
Better structuring between webdav modules.
Diffstat (limited to 'module/calp')
-rw-r--r-- | module/calp/server/webdav.scm | 28 | ||||
-rw-r--r-- | module/calp/webdav/util.scm | 40 |
2 files changed, 41 insertions, 27 deletions
diff --git a/module/calp/server/webdav.scm b/module/calp/server/webdav.scm index 781a85d9..7cbdd32e 100644 --- a/module/calp/server/webdav.scm +++ b/module/calp/server/webdav.scm @@ -26,6 +26,7 @@ :use-module (calp webdav property) :use-module (calp webdav propfind) :use-module (calp webdav proppatch) + :use-module (calp webdav util) :use-module (oop goops) :export (; run-run run-propfind @@ -156,33 +157,6 @@ -(define (parse-dav-line str) - (map (lambda (item) - (cond ((string-match "^[0-9]+$" item) - => (lambda (m) (number->string (match:substring m)))) - ((string-match "^<(.*)>$" item) - => (lambda (m) (string->uri (match:substring m 1)))) - (else (string->symbol item)))) - (map string-trim-both (string-split str #\,)))) - -(define (validate-dav-line lst) - (every (lambda (item) - (or (and (number? item) (<= 1 item 3)) - (uri? item) - ;; Possibly check against list of valid tokens - (symbol? item))) - lst)) - -(define (write-dav-line lst port) - (display - (string-join (map (lambda (item) - (cond ((number? item) (number->string item)) - ((uri? item) (string-append "<" (uri->string item) ">")) - (else (symbol->string item)))) - lst) - ", " 'infix) - port)) - (declare-header! "DAV" parse-dav-line validate-dav-line diff --git a/module/calp/webdav/util.scm b/module/calp/webdav/util.scm new file mode 100644 index 00000000..e65ecfc5 --- /dev/null +++ b/module/calp/webdav/util.scm @@ -0,0 +1,40 @@ +(define-module (calp webdav util) + :use-module (srfi srfi-1) + :use-module (ice-9 regex) + :use-module (web uri) + :export (parse-dav-line + validate-dav-line + write-dav-line) + ) + +;;; Parse a DAV HTTP header's content as specified in RFC 4918 §10.1 +;;; For example: +;;; DAV: 1, 2, access-control, calendar-access +(define (parse-dav-line str) + (map (lambda (item) + (cond ((string-match "^[0-9]+$" item) + => (lambda (m) (string->number (match:substring m)))) + ((string-match "^<(.*)>$" item) + => (lambda (m) (string->uri (match:substring m 1)))) + (else (string->symbol item)))) + (map string-trim-both (string-split str #\,)))) + +(define (validate-dav-line lst) + (every (lambda (item) + (or (and (number? item) (<= 1 item 3)) + (uri? item) + ;; Possibly check against list of valid tokens + (symbol? item))) + lst)) + + + +(define (write-dav-line lst port) + (display + (string-join (map (lambda (item) + (cond ((number? item) (number->string item)) + ((uri? item) (string-append "<" (uri->string item) ">")) + (else (symbol->string item)))) + lst) + ", " 'infix) + port)) |