summaryrefslogtreecommitdiffstats
path: root/modules/xmlrpc/doc/xmlrpc-server.html
blob: da18e0f70636fe572ce42f8c0ebb0f07c113fb2f (plain)
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
<HTML
><HEAD
><TITLE
>xmlrpc_server</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.77+"><LINK
REV="MADE"
HREF="edd@usefulinc.com"><LINK
REL="HOME"
TITLE="XML-RPC for PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Class documentation"
HREF="apidocs.html"><LINK
REL="PREVIOUS"
TITLE="xmlrpcval"
HREF="xmlrpcval.html"><LINK
REL="NEXT"
TITLE="Helper functions"
HREF="helpers.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>XML-RPC for PHP: version 1.1</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="xmlrpcval.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 5. Class documentation</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="helpers.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="XMLRPC-SERVER"
></A
>xmlrpc_server</H1
><P
>The current implementation of this class has been
		kept as simple as possible. The constructor for the server
		basically does all the work. Here's a minimal example:</P
><PRE
CLASS="PROGRAMLISTING"
>  function foo ($params) {
     ...
  }

  $s=new xmlrpc_server( array("examples.myFunc" =&#62;
				array("function" =&#62; "foo")));
	  </PRE
><P
>		This performs everything you need to do with a server.  The single
		argument is an associative array from method names to function
		names. The request is parsed and despatched to the relevant function,
		which is reponsible for returning a
		<TT
CLASS="CLASSNAME"
>xmlrpcresp</TT
>
		object, which gets
		serialized back to the caller.  See server.php in this distribution for
		examples of how to do this.
	  </P
><P
>Here is a more detailed look at what the handler function
		<TT
CLASS="FUNCTION"
>foo</TT
> may do:</P
><PRE
CLASS="PROGRAMLISTING"
>&#13;  function foo ($params) {
        global $xmlrpcerruser; // import user errcode value

        // $params is an Array of xmlrpcval objects

        if ($err) {
          // this is an error condition
          return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
           "There's a problem, Captain");
        } else {
          // this is a successful value being returned
          return new xmlrpcresp(new xmlrpcval("All's fine!", "string"));
        }
  }
		</PRE
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN658"
></A
>The dispatch map</H2
><P
>The first argument to the
					<TT
CLASS="FUNCTION"
>xmlrpc_server</TT
> constructor is an array,
					called the <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>dispatch map</I
></SPAN
>.  In this array is the
					information the server needs to service the XML-RPC methods
					you define.</P
><P
>					The dispatch map takes the form of an associative array of
					associative arrays: the outer array has one entry for each
					method, the key being the method name. The corresponding value 
					is another associative array, which can have the following members:
				</P
><P
></P
><UL
><LI
><P
><TT
CLASS="FUNCTION"
>function</TT
> - this entry is
									mandatory. It must be a name of a function in the
									global scope which services the XML-RPC method.</P
></LI
><LI
><P
><TT
CLASS="FUNCTION"
>signature</TT
> - this entry is an
							array containg the possible signatures (see <A
HREF="xmlrpc-server.html#SIGNATURES"
>Signatures</A
>) for the method. If
							this entry is present then the server will check that the
							correct number and type of parameters have been sent for
							this method before dispatching it.
						</P
></LI
><LI
><P
>							<TT
CLASS="FUNCTION"
>docstring</TT
> - this entry is a string
							containing documentation for the method.  The
							documentation may contain HTML markup.
							</P
></LI
></UL
><P
>Look at the <TT
CLASS="FILENAME"
>server.php</TT
> example in the 
					distribution to see what a dispatch map looks like.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="SIGNATURES"
></A
>Method signatures</H2
><P
>A signature is a description of a method's return type and 
					its parameter types.  A method may have more than one
					signature.</P
><P
>Within a server's dispatch map, each method has an array
					of possible signatures. Each signature is an array of
					types. The first entry is the return type. For instance, the
					method <PRE
CLASS="PROGRAMLISTING"
>string examples.getStateName(int)</PRE
> has the signature 
<PRE
CLASS="PROGRAMLISTING"
>array($xmlrpcString, $xmlrpcInt)</PRE
> and, assuming that it the only possible signature for
					the method, might be used like this in server creation:
<PRE
CLASS="PROGRAMLISTING"
>$findstate_sig=array(array($xmlrpcString, $xmlrpcInt));

$findstate_doc='When passed an integer between 1 and 51 returns the
name of a US state, where the integer is the index of that state name
in an alphabetic order.';

$s=new xmlrpc_server( array( "examples.getStateName" =&gt; 
						array("function" =&gt; "findstate",
						"signature" =&gt; $findstate_sig,
						"docstring" =&gt; $findstate_doc)));</PRE
>

				</P
><P
>For convenience the strings representing the XML-RPC types 
					have been encoded as global variables:<PRE
CLASS="PROGRAMLISTING"
>$xmlrpcI4="i4";
$xmlrpcInt="int";
$xmlrpcBoolean="boolean";
$xmlrpcDouble="double";
$xmlrpcString="string";
$xmlrpcDateTime="dateTime.iso8601";
$xmlrpcBase64="base64";
$xmlrpcArray="array";
$xmlrpcStruct="struct";</PRE
></P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN686"
></A
>Delaying the server response</H2
><P
>You may want to construct the server, but for some reason
					not fulfill the request immediately (security verification, for 
				instance). If you pass the constructor a second argument of
					<TT
CLASS="LITERAL"
>0</TT
> this will have the desired effect. You
					can then use the <TT
CLASS="FUNCTION"
>service()</TT
> method of the
					server class to service the request. For example:</P
><PRE
CLASS="PROGRAMLISTING"
>$s=new xmlrpc_server($myDispMap, 0);

// ... some code that does other stuff here

$s-&#62;service();</PRE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN692"
></A
>Fault reporting</H2
><P
>Fault codes for your servers should start at the
		  value indicated by
		  the global <TT
CLASS="LITERAL"
>$xmlrpcerruser</TT
> + 1.</P
><P
>Standard errors returned by the server include:</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>1</TT
> <SPAN
CLASS="phrase"
><SPAN
CLASS="PHRASE"
>Unknown method</SPAN
></SPAN
></DT
><DD
><P
>Returned if the server was asked to dispatch a
				method it didn't know about</P
></DD
><DT
><TT
CLASS="LITERAL"
>2</TT
> <SPAN
CLASS="phrase"
><SPAN
CLASS="PHRASE"
>Invalid return payload</SPAN
></SPAN
></DT
><DD
><P
>This error is actually generated by the client, not
				server, code, but signifies that a server returned
				something it couldn't understand.</P
></DD
><DT
><TT
CLASS="LITERAL"
>3</TT
> <SPAN
CLASS="phrase"
><SPAN
CLASS="PHRASE"
>Incorrect parameters</SPAN
></SPAN
></DT
><DD
><P
>This error is generated when the server has signature(s)
								defined for a method, and the parameters passed by the
								client do not match any of signatures.</P
></DD
><DT
><TT
CLASS="LITERAL"
>4</TT
> <SPAN
CLASS="phrase"
><SPAN
CLASS="PHRASE"
>Can't introspect: method unknown</SPAN
></SPAN
></DT
><DD
><P
>This error is generated by the builtin
								<TT
CLASS="FUNCTION"
>system.*</TT
> methods when any kind of
								introspection is attempted on a method undefined by the
								server.</P
></DD
><DT
><TT
CLASS="LITERAL"
>5</TT
> <SPAN
CLASS="phrase"
><SPAN
CLASS="PHRASE"
>Didn't receive 200 OK from remote server</SPAN
></SPAN
></DT
><DD
><P
>This error is generated by the client when a remote server
								doesn't return HTTP/1.1 200 OK in response to a
								request. A more detailed error report is added onto the
								end of the phrase above.</P
></DD
><DT
><TT
CLASS="LITERAL"
>100-</TT
> <SPAN
CLASS="phrase"
><SPAN
CLASS="PHRASE"
>XML parse errors</SPAN
></SPAN
></DT
><DD
><P
>Returns 100 plus the XML parser error code for the
				fault that occurred.  The
				<TT
CLASS="FUNCTION"
>faultString</TT
> returned explains where 
			  the parse error was in the incoming XML stream.</P
></DD
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="xmlrpcval.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="helpers.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>xmlrpcval</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="apidocs.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Helper functions</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>