summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVivien Kraus <vivien@planete-kraus.eu>2021-06-25 17:04:07 +0200
committerVivien Kraus <vivien@planete-kraus.eu>2021-06-27 00:19:34 +0200
commit225749ff12fb1e78ae956296c9b42eca10489615 (patch)
treef23b80b5653f14ca8e8eb1c2551741368a7b50af
parent636476eb01d93e222a22b55152a5eef1bb3329d3 (diff)
Paths: parse auxiliary path types
-rw-r--r--src/scm/webid-oidc/server/resource/path.scm58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/scm/webid-oidc/server/resource/path.scm b/src/scm/webid-oidc/server/resource/path.scm
index 59ec9e0..8dc2dec 100644
--- a/src/scm/webid-oidc/server/resource/path.scm
+++ b/src/scm/webid-oidc/server/resource/path.scm
@@ -20,6 +20,15 @@
read-path
update-path
+ base-path
+
+ derive-path
+
+ auxiliary-path?
+ acl-path?
+ container-path?
+ root-path?
+
))
(define (default-dir)
@@ -195,3 +204,52 @@
(for-each
delete
(hash-map->list (lambda (garbage false) garbage) garbage))))
+
+(define (base-path path)
+ (define (check-suffix suffix type)
+ (let ((total-length (string-length path))
+ (suffix-length (string-length suffix)))
+ (if (string-suffix? suffix path)
+ (values
+ (substring path 0 (- total-length suffix-length))
+ type)
+ (values #f #f))))
+ (define (all-checks candidates)
+ (if (null? candidates)
+ (values path #f)
+ (receive (base type)
+ (check-suffix (caar candidates) (cdar candidates))
+ (if base
+ (values base type)
+ (all-checks (cdr candidates))))))
+ (all-checks
+ `((".acl"
+ . ,(string->uri "http://www.w3.org/ns/auth/acl#accessControl"))
+ (".meta"
+ . ,(string->uri "https://www.w3.org/ns/iana/link-relations/relation#describedby")))))
+
+(define (derive-path path type)
+ (receive (base base-type)
+ (base-path path)
+ (cond
+ ((equal? type (string->uri "http://www.w3.org/ns/auth/acl#accessControl"))
+ (string-append base ".acl"))
+ ((equal? type (string->uri "https://www.w3.org/ns/iana/link-relations/relation#describedby"))
+ (string-append base ".meta")))))
+
+(define (auxiliary-path? path)
+ (receive (base type)
+ (base-path path)
+ (values type base)))
+
+(define (acl-path? path)
+ (receive (base type)
+ (base-path path)
+ (and type
+ (equal? type (string->uri "http://www.w3.org/ns/auth/acl#accessControl")))))
+
+(define (container-path? path)
+ (string-suffix? "/" path))
+
+(define (root-path? path)
+ (equal? path "/"))