(module xmlrpc-servlet mzscheme
(require (lib "unitsig.ss")
(lib "servlet-sig.ss" "web-server")
(file "server-core.ss")
(file "protocol.ss"))
(provide (all-from (lib "unitsig.ss"))
(all-from (lib "servlet-sig.ss" "web-server"))
add-handler
handle-xmlrpc-requests
handle-xmlrpc-request*)
(define-syntax handle-xmlrpc-requests
(lambda (stx)
(syntax-case stx ()
[(_)
#`(unit/sig ()
(import servlet^)
(handle-xmlrpc-request* initial-request))])))
(define (extract-xmlrpc-bindings request)
(let ([raw-bindings (request-bindings/raw request)])
(apply string-append
(map (lambda (b)
(format "~a~a"
(binding-id b)
(binding:form-value b)))
raw-bindings))))
(define gc-count 1)
(define gc-interval 10)
(define (handle-xmlrpc-request* request)
(let ([call (decode-xmlrpc-call
(extract-xmlrpc-bindings request))])
(set! gc-count (modulo (add1 gc-count) gc-interval))
(if (zero? gc-count) (collect-garbage))
(let ([name (rpc-call-name call)]
[args (rpc-call-args call)])
(if (handler-exists? name)
(invoke-handler name args)
(make-handler-fault
(format "No handler found on server for '~a'" name)
100)))))
)