(module xmlrpc-cgi mzscheme
(require
(planet "xxexpr.ss" ("lshift" "xxexpr.plt" 1))
(lib "cgi.ss" "net")
"server-core.ss"
"protocol.ss")
(provide (all-from (lib "cgi.ss" "net"))
add-handler
handle-xmlrpc-requests)
(define-syntax handle-xmlrpc-requests
(lambda (stx)
(syntax-case stx ()
[(_)
#`(printf "~a~n~n"
(handle-xmlrpc-request* (get-bindings/post)))])))
(define (cleanup-cgi-request bindings)
(let ([request-string
(car (map (lambda (bpair)
(string-append
(symbol->string (car bpair))
"="
(cdr bpair)))
bindings))])
request-string))
(define (handle-xmlrpc-request* bindings)
(let* ([request-string (cleanup-cgi-request bindings)])
(let ([call (decode-xmlrpc-call request-string)])
(let ([name (rpc-call-name call)]
[args (rpc-call-args call)])
(if (handler-exists? name)
(xxexpr->string (list
'(*pi* xml (version "1.0"))
(invoke-handler name args)))
(make-handler-fault
(format "No handler found on server for '~a'" name)
100))))))
)