Add max code size option
This commit is contained in:
parent
fe5c6e6fc8
commit
80ddd7a8b5
@ -339,6 +339,7 @@
|
|||||||
;;; Web page handler
|
;;; Web page handler
|
||||||
;;;
|
;;;
|
||||||
(define (make-page-handler host root index-file
|
(define (make-page-handler host root index-file
|
||||||
|
max-code-size
|
||||||
vvp-exe iverilog-exe)
|
vvp-exe iverilog-exe)
|
||||||
(let* ((root-path (split-and-decode-uri-path root))
|
(let* ((root-path (split-and-decode-uri-path root))
|
||||||
(root (encode-and-join-uri-path root-path))
|
(root (encode-and-join-uri-path root-path))
|
||||||
@ -357,16 +358,24 @@
|
|||||||
(ref-stor (if ref (get-storage-path (cdr ref) root) ""))
|
(ref-stor (if ref (get-storage-path (cdr ref) root) ""))
|
||||||
(ref-stor (if (and (valid-storage-path ref-stor)
|
(ref-stor (if (and (valid-storage-path ref-stor)
|
||||||
(storage-exists ref-stor))
|
(storage-exists ref-stor))
|
||||||
ref-stor #f)))
|
ref-stor #f))
|
||||||
|
(code (if request-body (utf8->string request-body) ""))
|
||||||
|
(code (if (or (zero? max-code-size)
|
||||||
|
(<= (string-length code) max-code-size))
|
||||||
|
code
|
||||||
|
(substring code 0 max-code-size))))
|
||||||
|
|
||||||
(printlog "-- path: ~a" path)
|
(printlog "-- path: ~a" path)
|
||||||
(printlog "-- ref-stor: ~a" ref-stor)
|
(printlog "-- ref-stor: ~a" ref-stor)
|
||||||
|
(printlog "-- length: ~a/~a"
|
||||||
|
(request-content-length request)
|
||||||
|
(string-length code))
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
;; Iverilog
|
;; Iverilog
|
||||||
((equal? path iverilog-path)
|
((equal? path iverilog-path)
|
||||||
(printlog "-- Request simulate")
|
(printlog "-- Request simulate")
|
||||||
|
|
||||||
(let ((code (utf8->string request-body)))
|
|
||||||
(when ref-stor
|
(when ref-stor
|
||||||
(save-to-storage ref-stor code))
|
(save-to-storage ref-stor code))
|
||||||
|
|
||||||
@ -375,14 +384,14 @@
|
|||||||
(sanitize-verilog code)
|
(sanitize-verilog code)
|
||||||
#:vvp-exe vvp-exe
|
#:vvp-exe vvp-exe
|
||||||
#:iverilog-exe iverilog-exe)
|
#:iverilog-exe iverilog-exe)
|
||||||
#:type 'text/plain)))
|
#:type 'text/plain))
|
||||||
|
|
||||||
;; Save code
|
;; Save code
|
||||||
((equal? path savecode-path)
|
((equal? path savecode-path)
|
||||||
(printlog "-- Request save code")
|
(printlog "-- Request save code")
|
||||||
(let ((storage (or ref-stor
|
(let ((storage (or ref-stor
|
||||||
(mkdtemp (format "~a-XXXXXX" (current-time))))))
|
(mkdtemp (format "~a-XXXXXX" (current-time))))))
|
||||||
(save-to-storage storage (utf8->string request-body))
|
(save-to-storage storage code)
|
||||||
(make-response
|
(make-response
|
||||||
(encode-and-join-uri-path
|
(encode-and-join-uri-path
|
||||||
(append root-path `(,storage))))))
|
(append root-path `(,storage))))))
|
||||||
@ -435,6 +444,7 @@
|
|||||||
(-> " -r, --root URN Service location root. Default: ''")
|
(-> " -r, --root URN Service location root. Default: ''")
|
||||||
(-> " --ivverilog-exe PATH Set Icarus Verilog compiler executable. Default: iverilog")
|
(-> " --ivverilog-exe PATH Set Icarus Verilog compiler executable. Default: iverilog")
|
||||||
(-> " --vvp-exe PATH Set Icarus Verilog interpreter executable. Default: vvp")
|
(-> " --vvp-exe PATH Set Icarus Verilog interpreter executable. Default: vvp")
|
||||||
|
(-> " --max-len LEN Set maximum code size in symbols. Default: 0 (infinite)")
|
||||||
(-> " -h, --help Print this message and exit")
|
(-> " -h, --help Print this message and exit")
|
||||||
(-> "")
|
(-> "")
|
||||||
(-> "Source code and issue tracker: <https://github.com/punzik/>")))))
|
(-> "Source code and issue tracker: <https://github.com/punzik/>")))))
|
||||||
@ -450,6 +460,7 @@
|
|||||||
'(("root" #\r) required)
|
'(("root" #\r) required)
|
||||||
'(("vvp-exe") required)
|
'(("vvp-exe") required)
|
||||||
'(("iverilog-exe") required)
|
'(("iverilog-exe") required)
|
||||||
|
'(("max-len") required)
|
||||||
'(("help" #\h) none))))
|
'(("help" #\h) none))))
|
||||||
|
|
||||||
(let ((addr (string-trim (or (option-get opts "addr") "127.0.0.1")))
|
(let ((addr (string-trim (or (option-get opts "addr") "127.0.0.1")))
|
||||||
@ -457,7 +468,8 @@
|
|||||||
(host (string-trim (or (option-get opts "host") "http://127.0.0.1:8080")))
|
(host (string-trim (or (option-get opts "host") "http://127.0.0.1:8080")))
|
||||||
(root (string-trim (or (option-get opts "root") "")))
|
(root (string-trim (or (option-get opts "root") "")))
|
||||||
(vvp (string-trim (or (option-get opts "vvp-exe") "vvp")))
|
(vvp (string-trim (or (option-get opts "vvp-exe") "vvp")))
|
||||||
(iverilog (string-trim (or (option-get opts "iverilog-exe") "iverilog"))))
|
(iverilog (string-trim (or (option-get opts "iverilog-exe") "iverilog")))
|
||||||
|
(max-code-size (string->number (string-trim (or (option-get opts "max-len") "0")))))
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
(err
|
(err
|
||||||
@ -472,7 +484,8 @@
|
|||||||
(else
|
(else
|
||||||
(printlog "Listen on '~a' port '~a'" addr port)
|
(printlog "Listen on '~a' port '~a'" addr port)
|
||||||
(printlog "Server URL: '~a/~a'" host root)
|
(printlog "Server URL: '~a/~a'" host root)
|
||||||
|
(printlog "Max code size: ~a" max-code-size)
|
||||||
|
|
||||||
(run-server
|
(run-server
|
||||||
(make-page-handler host root INDEX-FILE vvp iverilog)
|
(make-page-handler host root INDEX-FILE max-code-size vvp iverilog)
|
||||||
'http `(#:host ,addr #:port ,port)))))))
|
'http `(#:host ,addr #:port ,port)))))))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user