-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.txt
194 lines (137 loc) · 6.08 KB
/
doc.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
_XML-RPC_ Library
==============
By Matt Jadud and Noel Welsh
An Untyped Production
Time-stamp: <06/01/04 15:34:39 nhw>
Keywords: _xml_, _xmlrpc_, _xml-rpc_
Current version: 1.4
Requires PLT Version: 359.100 or greater.
Introduction
============
This library implements the XML-RPC protocol as specified at
http://www.xmlrpc.com/spec
XML-RPC is a popular protocol for interface to Internet
services such as blog engines.
The client-side library can be required in to your programs using:
(require (planet "xmlrpc.ss" ("schematics" "xmlrpc.plt" 2 1)))
Basic Types
===========
> struct (exn:xmlrpc exn) : ()
A subtype of exn, this exception is raised whenever the XML-RPC library
encounters an error.
> struct (exn:xmlrpc exn) : code
A subtype of exn:xmlrpc, this exception is raised when the XML-RPC
server responds to the client with a fault. The code is an integer
containing the fault code returned by the server. The fault message
returned by the server is contained in the exception message (which is
a field in the exn type).
Client-side Functions
=====================
To use the library, require:
(require (planet "xmlrpc.ss" ("schematics" "xmlrpc.plt" 2 1)))
The client library provides a few forms for defining servers and
their supported endpoints.
> xmlrpc-server : string integer string -> (string -> (any ... -> any))
> xmlrpc-server : url -> (string -> (any ... -> any))
Returns a function configured to make XML-RPC requests to the given
URL. The function accepts a string, the name of the method, and
returns a function of any arguments which calls the method with the
given arguments.
Example:
This example calls the examples.getStateName method on the server
betty.userland.com
> (define betty (xmlrpc-server "betty.userland.com" 80 "RPC2"))
> (define get-state-name (betty "examples.getStateName"))
> (get-state-name 42)
"Tennessee"
PLT Servlet Functions
=====================
To use the Untyped XML-RPC library to build a servlet, include
"xmlrpc-module-servlet.ss".
> add-handler : symbol (any ... -> any) -> void
An XML-RPC servlet defines one or more endpoints that can be invoked by
a remote client. The simple act of defining a Scheme function does not
automatically provide it to the outside world; this would be
fundamentally unsafe. Each function to be exposed externally must be
mappend onto a name by which it can be called.
For example:
(define (add x y) (+ x y))
(add-handler 'math.add add)
These two lines of code define a Scheme function ('add') and provide it
to an outside client under the name 'math.add'. The same function can
be provided under multiple names:
(define (add x y) (+ x y))
(add-handler 'math.add add)
(add-handler 'addFun add)
'case-lambda', 'match-lambda', and functions of
variable argument can be bound in the same way.
A complete XML-RPC handler therefore looks like:
--------
(module add mzscheme
(require (planet "xmlrpc-module-servlet.ss"
("schematics" "xmlrpc.plt" 2)))
;; Provided by the library; must be re-exported
;; to the web server.
(provide interface-version manager timeout start)
(define (add x y) (+ x y))
(add-handler 'math.add add)
)
--------
The 'provide' statement provides a start, timeout, and continuation
manager to the webserver for your XML-RPC servlet. These are defined in
the Untyped XML-RPC module-based servlet library.
PLT CGI Functions
=====================
The XML-RPC library can also be used for implementing CGI-based
endpoints under a server like Apache. These endpoints are significantly
slower at this time, as each XML-RPC call requires Apache to launch an
entire MzScheme instance to handle the call. Servlet handlers are
roughly two orders of magnitude faster.
Typically, CGIs are executed as a user other than the author of the CGI
(eg. 'nobody' or 'www'). This presents a problem, as the PLaneT request
to include the XML-RPC library will likely fail, causing your CGI to
fail as well.
There are many solutions to this problem. One is to execute the CGIs in
a SuExec'd environment. Or, you could ask your systems administrator to
install the PLaneT package for the XML-RPC library in a globally
accessible location. Below, we've demonstrated how you might make the
library work for you in an environment where this is not an option.
(Note: I have found this to be non-trivial in the past, and would
encourage you to ask questions on the PLT Scheme mailing list if you
end up taking this approach and run into trouble. --MCJ)
--------
#!/path/to/mzscheme -gqr
(require (lib "config.ss" "planet"))
(PLANET-DIR "/path/to/writable/planet-dir")
(CACHE-DIR "/path/to/writable/planet-cache")
(LINKAGE-FILE "/path/to/writeable/planet-linkage")
(LOG-FILE #f)
(require (planet "xmlrpc-cgi.ss"
("schematics" "xmlrpc.plt" 1 3)))
(add-handler 'add (lambda (a b) (+ a b)))
(output-http-headers)
(handle-xmlrpc-requests)
--------
First, we require the configuration library for PLaneT. We then define
PLaneT-writable directories for all of its files: these will need to be
locations writable by the webserver (eg. owned/writable by 'nobody',
'www', or whatever user your webserver runs as). Then, include the
XML-RPC library, and from there, add your handlers.
Before you handle your XML-RPC requests, you will need to output HTTP
headers. This may change in the future; Apache CGI support is new, and
currently a moving target.
COMPATABILITY
===================
As of this release, the server-side of the XML-RPC library has not been
thoroughly tested. This means we have not written a test suite in a
variety of other languages to test against our server.
The following clients are suspected to work against the Untyped XML-RPC
server running as either a servlet or Apache CGI process:
* The Untyped XML-RPC client (Scheme)
* The Python native XML-RPC client (Python)
* Ecto, a popular blogging package for OSX (Cocoa)
* Apache XML-RPC v2 (Java)
These tests, however, were not exhaustive. Your milage may vary. Please
report any difficulties or patches to jadudm at gmail dot com. Or, if
you prefer, you may also post questions to the PLT Scheme mailing list,
where all of the library contributors participate.