5c69ba7ed7807b5cc578d3e60fbfd4c791433dfd
[plcapi.git] / doc / manual / phpxmlrpc_manual.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <?xml-stylesheet href="css-docbook/driver.css" type="text/css"?>
3 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
4 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
5 <!--
6 PHP-XMLRPC User manual
7 -->
8 <book lang="en">
9   <title>XML-RPC for PHP</title>
10
11   <subtitle>version 3.0.0</subtitle>
12
13   <bookinfo>
14     <date>June 15, 2014</date>
15
16     <authorgroup>
17       <author>
18         <firstname>Edd</firstname>
19
20         <surname>Dumbill</surname>
21       </author>
22
23       <author>
24         <firstname>Gaetano</firstname>
25
26         <surname>Giunta</surname>
27       </author>
28
29       <author>
30         <firstname>Miles</firstname>
31
32         <surname>Lott</surname>
33       </author>
34
35       <author>
36         <firstname>Justin R.</firstname>
37
38         <surname>Miller</surname>
39       </author>
40
41       <author>
42         <firstname>Andres</firstname>
43
44         <surname>Salomon</surname>
45       </author>
46     </authorgroup>
47
48     <copyright>
49       <year>1999,2000,2001</year>
50
51       <holder>Edd Dumbill, Useful Information Company</holder>
52     </copyright>
53
54     <legalnotice>
55       <para>All rights reserved.</para>
56
57       <para>Redistribution and use in source and binary forms, with or without
58       modification, are permitted provided that the following conditions are
59       met:</para>
60
61       <para><itemizedlist>
62           <listitem>
63             <para>Redistributions of source code must retain the above
64             copyright notice, this list of conditions and the following
65             disclaimer.</para>
66           </listitem>
67
68           <listitem>
69             <para>Redistributions in binary form must reproduce the above
70             copyright notice, this list of conditions and the following
71             disclaimer in the documentation and/or other materials provided
72             with the distribution.</para>
73           </listitem>
74
75           <listitem>
76             <para>Neither the name of the "XML-RPC for PHP" nor the names of
77             its contributors may be used to endorse or promote products
78             derived from this software without specific prior written
79             permission.</para>
80           </listitem>
81         </itemizedlist></para>
82
83       <para>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
84       CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
85       BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
86       FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
87       REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
88       SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
89       TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90       PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
91       LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
92       NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
93       SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</para>
94     </legalnotice>
95   </bookinfo>
96
97   <chapter id="introduction">
98     <title>Introduction</title>
99
100     <para>XML-RPC is a format devised by <ulink
101     url="http://www.userland.com/">Userland Software</ulink> for achieving
102     remote procedure call via XML using HTTP as the transport. XML-RPC has its
103     own web site, <ulink
104     url="http://www.xmlrpc.com/">www.xmlrpc.com</ulink></para>
105
106     <para>This collection of PHP classes provides a framework for writing
107     XML-RPC clients and servers in PHP.</para>
108
109     <para>Main goals of the project are ease of use, flexibility and
110     completeness.</para>
111
112     <para>The original author is Edd Dumbill of <ulink
113     url="http://usefulinc.com/">Useful Information Company</ulink>. As of the
114     1.0 stable release, the project was opened to wider involvement and moved
115     to <ulink
116     url="http://phpxmlrpc.sourceforge.net/">SourceForge</ulink>; later, to <ulink
117     url="https://github.com/">Github</ulink></para>
118
119     <para>A list of XML-RPC implementations for other languages such as Perl
120     and Python can be found on the <ulink
121     url="http://www.xmlrpc.com/">www.xmlrpc.com</ulink> site.</para>
122
123     <sect1>
124       <title>Acknowledgements</title>
125
126       <para>Daniel E. Baumann</para>
127
128       <para>James Bercegay</para>
129
130       <para>Leon Blackwell</para>
131
132       <para>Stephane Bortzmeyer</para>
133
134       <para>Daniel Convissor</para>
135
136       <para>Geoffrey T. Dairiki</para>
137
138       <para>Stefan Esser</para>
139
140       <para>James Flemer</para>
141
142       <para>Ernst de Haan</para>
143
144       <para>Tom Knight</para>
145
146       <para>Axel Kollmorgen</para>
147
148       <para>Peter Kocks</para>
149
150       <para>Daniel Krippner</para>
151
152       <para>S. Kuip</para>
153
154       <para>A. Lambert</para>
155
156       <para>Frederic Lecointre</para>
157
158       <para>Dan Libby</para>
159
160       <para>Arnaud Limbourg</para>
161
162       <para>Ernest MacDougal Campbell III</para>
163
164       <para>Lukasz Mach</para>
165
166       <para>Kjartan Mannes</para>
167
168       <para>Ben Margolin</para>
169
170       <para>Nicolay Mausz</para>
171
172       <para>Justin Miller</para>
173
174       <para>Jan Pfeifer</para>
175
176       <para>Giancarlo Pinerolo</para>
177
178       <para>Peter Russel</para>
179
180       <para>Jean-Jacques Sarton</para>
181
182       <para>Viliam Simko</para>
183
184       <para>Idan Sofer</para>
185
186       <para>Douglas Squirrel</para>
187
188       <para>Heiko Stübner</para>
189
190       <para>Anatoly Techtonik</para>
191
192       <para>Tommaso Trani</para>
193
194       <para>Eric van der Vlist</para>
195
196       <para>Christian Wenz</para>
197
198       <para>Jim Winstead</para>
199
200       <para>Przemyslaw Wroblewski</para>
201
202       <para>Bruno Zanetti Melotti</para>
203     </sect1>
204   </chapter>
205
206   <chapter id="news">
207     <title>What's new</title>
208
209     <para><emphasis>Note:</emphasis> not all items the following list have
210     (yet) been fully documented, and some might not be present in any other
211     chapter in the manual. To find a more detailed description of new
212     functions and methods please take a look at the source code of the
213     library, which is quite thoroughly commented in javadoc-like form.</para>
214
215     <sect1>
216       <title>3.0.0</title>
217
218       <para><emphasis>Note:</emphasis> this is the last release of the library that will support PHP 5.1 and up.
219       Future releases will target php 5.3 as minimum supported version.</para>
220
221       <para><itemizedlist>
222       <listitem>
223         <para>when using curl and keepalive, reset curl handle if we did not get back an http 200 response (eg a 302)</para>
224       </listitem>
225
226       <listitem>
227         <para>omit port on http 'Host' header if it is 80</para>
228       </listitem>
229
230       <listitem>
231         <para>test suite allows interrogating https servers ignoring their certs</para>
232       </listitem>
233
234       <listitem>
235         <para>method setAcceptedCompression was failing to disable reception of compressed responses if the
236          client supported them</para>
237       </listitem>
238
239       </itemizedlist></para>
240     </sect1>
241
242     <sect1>
243       <title>3.0.0 beta</title>
244
245       <para>This is the first release of the library to only support PHP 5.
246       Some legacy code has been removed, and support for features such as
247       exceptions and dateTime objects introduced.</para>
248
249       <para>The "beta" tag is meant to indicate the fact that the refactoring
250       has been more widespread than in precedent releases and that more
251       changes are likely to be introduced with time - the library is still
252       considered to be production quality.</para>
253
254       <para><itemizedlist>
255           <listitem>
256             <para>improved: removed all usage of php functions deprecated in
257             php 5.3, usage of assign-by-ref when creating new objects
258             etc...</para>
259           </listitem>
260
261           <listitem>
262             <para>improved: add support for the &lt;ex:nil/&gt; tag used by
263             the apache library, both in input and output</para>
264           </listitem>
265
266           <listitem>
267             <para>improved: add support for <classname>dateTime</classname>
268             objects in both in <function>php_xmlrpc_encode</function> and as
269             parameter for constructor of
270             <classname>xmlrpcval</classname></para>
271           </listitem>
272
273           <listitem>
274             <para>improved: add support for timestamps as parameter for
275             constructor of <classname>xmlrpcval</classname></para>
276           </listitem>
277
278           <listitem>
279             <para>improved: add option 'dates_as_objects' to
280             <function>php_xmlrpc_decode</function> to return
281             <classname>dateTime</classname> objects for xmlrpc
282             datetimes</para>
283           </listitem>
284
285           <listitem>
286             <para>improved: add new method
287             <methodname>SetCurlOptions</methodname> to
288             <classname>xmrlpc_client</classname> to allow extra flexibility in
289             tweaking http config, such as explicitly binding to an ip
290             address</para>
291           </listitem>
292
293           <listitem>
294             <para>improved: add new method
295             <methodname>SetUserAgent</methodname> to
296             <classname>xmrlpc_client</classname> to to allow having different
297             user-agent http headers</para>
298           </listitem>
299
300           <listitem>
301             <para>improved: add a new member variable in server class to allow
302             fine-tuning of the encoding of returned values when the server is
303             in 'phpvals' mode</para>
304           </listitem>
305
306           <listitem>
307             <para>improved: allow servers in 'xmlrpcvals' mode to also
308             register plain php functions by defining them in the dispatch map
309             with an added option</para>
310           </listitem>
311
312           <listitem>
313             <para>improved: catch exceptions thrown during execution of php
314             functions exposed as methods by the server</para>
315           </listitem>
316
317           <listitem>
318             <para>fixed: bad encoding if same object is encoded twice using
319             php_xmlrpc_encode</para>
320           </listitem>
321         </itemizedlist></para>
322     </sect1>
323
324     <sect1>
325       <title>2.2.2</title>
326
327       <para><emphasis>Note:</emphasis> this might the last release of the
328       library that will support PHP 4. Future releases (if any) should target
329       php 5.0 as minimum supported version.</para>
330
331       <para><itemizedlist>
332           <listitem>
333             <para>fixed: encoding of utf-8 characters outside of the BMP
334             plane</para>
335           </listitem>
336
337           <listitem>
338             <para>fixed: character set declarations surrounded by double
339             quotes were not recognized in http headers</para>
340           </listitem>
341
342           <listitem>
343             <para>fixed: be more tolerant in detection of charset in http
344             headers</para>
345           </listitem>
346
347           <listitem>
348             <para>fixed: fix detection of zlib.output_compression</para>
349           </listitem>
350
351           <listitem>
352             <para>fixed: use feof() to test if socket connections are to be
353             closed instead of the number of bytes read (rare bug when
354             communicating with some servers)</para>
355           </listitem>
356
357           <listitem>
358             <para>fixed: format floating point values using the correct
359             decimal separator even when php locale is set to one that uses
360             comma</para>
361           </listitem>
362
363           <listitem>
364             <para>fixed: improve robustness of the debugger when parsing weird
365             results from non-compliant servers</para>
366           </listitem>
367
368           <listitem>
369             <para>php warning when receiving 'false' in a bool value</para>
370           </listitem>
371
372           <listitem>
373             <para>improved: allow the add_to_map server method to add docs for
374             single params too</para>
375           </listitem>
376
377           <listitem>
378             <para>improved: added the possibility to wrap for exposure as
379             xmlrpc methods plain php class methods, object methods and even
380             whole classes</para>
381           </listitem>
382         </itemizedlist></para>
383     </sect1>
384
385     <sect1>
386       <title>2.2.1</title>
387
388       <itemizedlist>
389         <listitem>
390           <para>fixed: work aroung bug in php 5.2.2 which broke support of
391           HTTP_RAW_POST_DATA</para>
392         </listitem>
393
394         <listitem>
395           <para>fixed: is_dir parameter of setCaCertificate() method is
396           reversed</para>
397         </listitem>
398
399         <listitem>
400           <para>fixed: a php warning in xmlrpc_client creator method</para>
401         </listitem>
402
403         <listitem>
404           <para>fixed: parsing of '1e+1' as valid float</para>
405         </listitem>
406
407         <listitem>
408           <para>fixed: allow errorlevel 3 to work when prev. error handler was
409           a static method</para>
410         </listitem>
411
412         <listitem>
413           <para>fixed: usage of client::setcookie() for multiple cookies in
414           non-ssl mode</para>
415         </listitem>
416
417         <listitem>
418           <para>improved: support for CP1252 charset is not part or the
419           library but almost possible</para>
420         </listitem>
421
422         <listitem>
423           <para>improved: more info when curl is enabled and debug mode is
424           on</para>
425         </listitem>
426       </itemizedlist>
427     </sect1>
428
429     <sect1>
430       <title>2.2</title>
431
432       <itemizedlist>
433         <listitem>
434           <para>fixed: debugger errors on php installs with magic_quotes_gpc
435           on</para>
436         </listitem>
437
438         <listitem>
439           <para>fixed: support for https connections via proxy</para>
440         </listitem>
441
442         <listitem>
443           <para>fixed: wrap_xmlrpc_method() generated code failed to properly
444           encode php objects</para>
445         </listitem>
446
447         <listitem>
448           <para>improved: slightly faster encoding of data which is internally
449           UTF-8</para>
450         </listitem>
451
452         <listitem>
453           <para>improved: debugger always generates a 'null' id for jsonrpc if
454           user omits it</para>
455         </listitem>
456
457         <listitem>
458           <para>new: debugger can take advantage of a graphical value builder
459           (it has to be downloaded separately, as part of jsxmlrpc package.
460           See Appendix D for more details)</para>
461         </listitem>
462
463         <listitem>
464           <para>new: support for the &lt;NIL/&gt; xmlrpc extension. see below
465           for more details</para>
466         </listitem>
467
468         <listitem>
469           <para>new: server support for the system.getCapabilities xmlrpc
470           extension</para>
471         </listitem>
472
473         <listitem>
474           <para>new: <function><link
475           linkend="wrap_xmlrpc_method">wrap_xmlrpc_method()</link></function>
476           accepts two new options: debug and return_on_fault</para>
477         </listitem>
478       </itemizedlist>
479     </sect1>
480
481     <sect1>
482       <title>2.1</title>
483
484       <para><itemizedlist>
485           <listitem>
486             <para>The <function>wrap_php_function</function> and
487             <function>wrap_xmlrpc_method</function> functions have been moved
488             out of the base library file <filename>xmlrpc.inc</filename> into
489             a file of their own: <filename>xmlrpc_wrappers.php</filename>. You
490             will have to include() / require() it in your scripts if you have
491             been using those functions. For increased security, the automatic
492             rebuilding of php object instances out of received xmlrpc structs
493             in <function>wrap_xmlrpc_method()</function> has been disabled
494             (but it can be optionally re-enabled). Both
495             <function>wrap_php_function()</function> and
496             <function>wrap_xmlrpc_method()</function> functions accept many
497             more options to fine tune their behaviour, including one to return
498             the php code to be saved and later used as standalone php
499             script</para>
500           </listitem>
501
502           <listitem>
503             <para>The constructor of xmlrpcval() values has seen some internal
504             changes, and it will not throw a php warning anymore when invoked
505             using an unknown xmlrpc type: the error will only be written to
506             php error log. Also <code>new xmlrpcval('true', 'boolean')</code>
507             is not supported anymore</para>
508           </listitem>
509
510           <listitem>
511             <para>The new function
512             <function>php_xmlrpc_decode_xml()</function> will take the xml
513             representation of either an xmlrpc request, response or single
514             value and return the corresponding php-xmlrpc object
515             instance</para>
516           </listitem>
517
518           <listitem>
519             <para>A new function <function>wrap_xmlrpc_server()</function>has
520             been added, to wrap all (or some) of the methods exposed by a
521             remote xmlrpc server into a php class</para>
522           </listitem>
523
524           <listitem>
525             <para>A new file has been added:
526             <filename>verify_compat.php</filename>, to help users diagnose the
527             level of compliance of their php installation with the
528             library</para>
529           </listitem>
530
531           <listitem>
532             <para>Restored compatibility with php 4.0.5 (for those poor souls
533             still stuck on it)</para>
534           </listitem>
535
536           <listitem>
537             <para>Method <methodname>xmlrpc_server-&gt;service()</methodname>
538             now returns a value: either the response payload or xmlrpcresp
539             object instance</para>
540           </listitem>
541
542           <listitem>
543             <para>Method
544             <methodname>xmlrpc_server-&gt;add_to_map()</methodname> now
545             accepts xmlrpc methods with no param definitions</para>
546           </listitem>
547
548           <listitem>
549             <para>Documentation for single parameters of exposed methods can
550             be added to the dispatch map (and turned into html docs in
551             conjunction with a future release of the 'extras' package)</para>
552           </listitem>
553
554           <listitem>
555             <para>Full response payload is saved into xmlrpcresp object for
556             further debugging</para>
557           </listitem>
558
559           <listitem>
560             <para>The debugger can now generate code that wraps a remote
561             method into a php function (works for jsonrpc, too); it also has
562             better support for being activated via a single GET call (e.g. for
563             integration into other tools)</para>
564           </listitem>
565
566           <listitem>
567             <para>Stricter parsing of incoming xmlrpc messages: two more
568             invalid cases are now detected (double <literal>data</literal>
569             element inside <literal>array</literal> and
570             <literal>struct</literal>/<literal>array</literal> after scalar
571             inside <literal>value</literal> element)</para>
572           </listitem>
573
574           <listitem>
575             <para>More logging of errors in a lot of situations</para>
576           </listitem>
577
578           <listitem>
579             <para>Javadoc documentation of lib files (almost) complete</para>
580           </listitem>
581
582           <listitem>
583             <para>Many performance tweaks and code cleanups, plus the usual
584             crop of bugs fixed (see NEWS file for complete list of
585             bugs)</para>
586           </listitem>
587
588           <listitem>
589             <para>Lib internals have been modified to provide better support
590             for grafting extra functionality on top of it. Stay tuned for
591             future releases of the EXTRAS package (or go read Appendix
592             B)...</para>
593           </listitem>
594         </itemizedlist></para>
595     </sect1>
596
597     <sect1>
598       <title>2.0 final</title>
599
600       <para><itemizedlist>
601           <listitem>
602             <para>Added to the client class the possibility to use Digest and
603             NTLM authentication methods (when using the CURL library) for
604             connecting to servers and NTLM for connecting to proxies</para>
605           </listitem>
606
607           <listitem>
608             <para>Added to the client class the possibility to specify
609             alternate certificate files/directories for authenticating the
610             peer with when using HTTPS communication</para>
611           </listitem>
612
613           <listitem>
614             <para>Reviewed all examples and added a new demo file, containing
615             a proxy to forward xmlrpc requests to other servers (useful e.g.
616             for ajax coding)</para>
617           </listitem>
618
619           <listitem>
620             <para>The debugger has been upgraded to reflect the new client
621             capabilities</para>
622           </listitem>
623
624           <listitem>
625             <para>All known bugs have been squashed, and the lib is more
626             tolerant than ever of commonly-found mistakes</para>
627           </listitem>
628         </itemizedlist></para>
629     </sect1>
630
631     <sect1>
632       <title>2.0 Release candidate 3</title>
633
634       <para><itemizedlist>
635           <listitem>
636             <para>Added to server class the property
637             <property>functions_parameters_type</property>, that allows the
638             server to register plain php functions as xmlrpc methods (i.e.
639             functions that do not take an xmlrpcmsg object as unique
640             param)</para>
641           </listitem>
642
643           <listitem>
644             <para>let server and client objects serialize calls using a
645             specified character set encoding for the produced xml instead of
646             US-ASCII (ISO-8859-1 and UTF-8 supported)</para>
647           </listitem>
648
649           <listitem>
650             <para>let php_xmlrpc_decode accept xmlrpcmsg objects as valid
651             input</para>
652           </listitem>
653
654           <listitem>
655             <para>'class::method' syntax is now accepted in the server
656             dispatch map</para>
657           </listitem>
658
659           <listitem>
660             <para><function>xmlrpc_clent::SetDebug()</function> accepts
661             integer values instead of a boolean value, with debugging level 2
662             adding to the information printed to screen the complete client
663             request</para>
664           </listitem>
665         </itemizedlist></para>
666     </sect1>
667
668     <sect1>
669       <title>2.0 Release candidate 2</title>
670
671       <para><itemizedlist>
672           <listitem>
673             <para>Added a new property of the client object:
674             <code>xmlrpc_client-&gt;return_type</code>, indicating whether
675             calls to the send() method will return xmlrpcresp objects whose
676             value() is an xmlrpcval object, a php value (automatically
677             decoded) or the raw xml received from the server.</para>
678           </listitem>
679
680           <listitem>
681             <para>Added in the extras dir. two new library file:
682             <filename>jsonrpc.inc</filename> and
683             <filename>jsonrpcs.inc</filename> containing new classes that
684             implement support for the json-rpc protocol (alpha quality
685             code)</para>
686           </listitem>
687
688           <listitem>
689             <para>Added a new client method: <code>setKey($key,
690             $keypass)</code> to be used in HTTPS connections</para>
691           </listitem>
692
693           <listitem>
694             <para>Added a new file containing some benchmarks in the testsuite
695             directory</para>
696           </listitem>
697         </itemizedlist></para>
698     </sect1>
699
700     <sect1>
701       <title>2.0 Release candidate 1</title>
702
703       <itemizedlist>
704         <listitem>
705           <para>Support for HTTP proxies (new method:
706           <code>xmlrpc_client::setProxy()</code>)</para>
707         </listitem>
708
709         <listitem>
710           <para>Support HTTP compression of both requests and responses.
711           Clients can specify what kind of compression they accept for
712           responses between deflate/gzip/any, and whether to compress the
713           requests. Servers by default compress responses to clients that
714           explicitly declare support for compression (new methods:
715           <code>xmlrpc_client::setAcceptedCompression()</code>,
716           <code>xmlrpc_client::setRequestCompression()</code>). Note that the
717           ZLIB php extension needs to be enabled in PHP to support
718           compression.</para>
719         </listitem>
720
721         <listitem>
722           <para>Implement HTTP 1.1 connections, but only if CURL is enabled
723           (added an extra parameter to
724           <code>xmlrpc_client::xmlrpc_client</code> to set the desired HTTP
725           protocol at creation time and a new supported value for the last
726           parameter of <code>xmlrpc_client::send</code>, which now can be
727           safely omitted if it has been specified at creation time)</para>
728
729           <para>With PHP versions greater than 4.3.8 keep-alives are enabled
730           by default for HTTP 1.1 connections. This should yield faster
731           execution times when making multiple calls in sequence to the same
732           xml-rpc server from a single client.</para>
733         </listitem>
734
735         <listitem>
736           <para>Introduce support for cookies. Cookies to be sent to the
737           server with a request can be set using
738           <code>xmlrpc_client::setCookie()</code>, while cookies received from
739           the server are found in <code>xmlrpcresp::cookies()</code>. It is
740           left to the user to check for validity of received cookies and
741           decide whether they apply to successive calls or not.</para>
742         </listitem>
743
744         <listitem>
745           <para>Better support for detecting different character set encodings
746           of xml-rpc requests and responses: both client and server objects
747           will correctly detect the charset encoding of received xml, and use
748           an appropriate xml parser.</para>
749
750           <para>Supported encodings are US-ASCII, UTF-8 and ISO-8859-1.</para>
751         </listitem>
752
753         <listitem>
754           <para>Added one new xmlrpcmsg constructor syntax, allowing usage of
755           a single string with the complete URL of the target server</para>
756         </listitem>
757
758         <listitem>
759           <para>Convert xml-rpc boolean values into native php values instead
760           of 0 and 1</para>
761         </listitem>
762
763         <listitem>
764           <para>Force the <code>php_xmlrpc_encode</code> function to properly
765           encode numerically indexed php arrays into xml-rpc arrays
766           (numerically indexed php arrays always start with a key of 0 and
767           increment keys by values of 1)</para>
768         </listitem>
769
770         <listitem>
771           <para>Prevent the <code>php_xmlrpc_encode</code> function from
772           further re-encoding any objects of class <code>xmlrpcval</code> that
773           are passed to it. This allows to call the function with arguments
774           consisting of mixed php values / xmlrpcval objects.</para>
775         </listitem>
776
777         <listitem>
778           <para>Allow a server to NOT respond to system.* method calls
779           (setting the <code>$server-&gt;allow_system_funcs</code>
780           property).</para>
781         </listitem>
782
783         <listitem>
784           <para>Implement a new xmlrpcval method to determine if a value of
785           type struct has a member of a given name without having to loop
786           trough all members: <code>xmlrpcval::structMemExists()</code></para>
787         </listitem>
788
789         <listitem>
790           <para>Expand methods <code>xmlrpcval::addArray</code>,
791           <code>addScalar</code> and <code>addStruct</code> allowing extra php
792           values to be added to xmlrpcval objects already formed.</para>
793         </listitem>
794
795         <listitem>
796           <para>Let the <code>xmlrpc_client::send</code> method accept an XML
797           string for sending instead of an xmlrpcmsg object, to facilitate
798           debugging and integration with the php native xmlrpc
799           extension</para>
800         </listitem>
801
802         <listitem>
803           <para>Extend the <code>php_xmlrpc_encode</code> and
804           <code>php_xmlrpc_decode</code> functions to allow serialization and
805           rebuilding of PHP objects. To successfully rebuild a serialized
806           object, the object class must be defined in the deserializing end of
807           the transfer. Note that object members of type resource will be
808           deserialized as NULL values.</para>
809
810           <para>Note that his has been implemented adding a "php_class"
811           attribute to xml representation of xmlrpcval of STRUCT type, which,
812           strictly speaking, breaks the xml-rpc spec. Other xmlrpc
813           implementations are supposed to ignore such an attribute (unless
814           they implement a brain-dead custom xml parser...), so it should be
815           safe enabling it in heterogeneous environments. The activation of
816           this feature is done by usage of an option passed as second
817           parameter to both <code>php_xmlrpc_encode</code> and
818           <code>php_xmlrpc_decode</code>.</para>
819         </listitem>
820
821         <listitem>
822           <para>Extend the <code>php_xmlrpc_encode</code> function to allow
823           automatic serialization of iso8601-conforming php strings as
824           datetime.iso8601 xmlrpcvals, by usage of an optional
825           parameter</para>
826         </listitem>
827
828         <listitem>
829           <para>Added an automatic stub code generator for converting xmlrpc
830           methods to php functions and vice-versa.</para>
831
832           <para>This is done via two new functions:
833           <code>wrap_php_function</code> and <code>wrap_xmlrpc_method</code>,
834           and has many caveats, with php being a typeless language and
835           all...</para>
836         </listitem>
837
838         <listitem>
839           <para>Allow object methods to be used in server dispatch map</para>
840         </listitem>
841
842         <listitem>
843           <para>Added a complete debugger solution, in the
844           <filename>debugger</filename> folder</para>
845         </listitem>
846
847         <listitem>
848           <para>Added configurable server-side debug messages, controlled by
849           the new method <code>xmlrpc_server::SetDebug()</code>. At level 0,
850           no debug messages are sent to the client; level 1 is the same as the
851           old behaviour; at level 2 a lot more info is echoed back to the
852           client, regarding the received call; at level 3 all warnings raised
853           during server processing are trapped (this prevents breaking the xml
854           to be echoed back to the client) and added to the debug info sent
855           back to the client</para>
856         </listitem>
857
858         <listitem>
859           <para>New XML parsing code, yields smaller memory footprint and
860           faster execution times, not to mention complete elimination of the
861           dreaded <filename>eval()</filename> construct, so prone to code
862           injection exploits</para>
863         </listitem>
864
865         <listitem>
866           <para>Rewritten most of the error messages, making text more
867           explicative</para>
868         </listitem>
869       </itemizedlist>
870     </sect1>
871   </chapter>
872
873   <chapter id="requirements">
874     <title>System Requirements</title>
875
876     <para>The library has been designed with goals of scalability and backward
877     compatibility. As such, it supports a wide range of PHP installs. Note
878     that not all features of the lib are available in every
879     configuration.</para>
880
881     <para>The <emphasis>minimum supported</emphasis> PHP version is
882     5.3.</para>
883
884     <para>If you wish to use SSL or HTTP 1.1 to communicate with remote
885     servers, you need the "curl" extension compiled into your PHP
886     installation.</para>
887
888     <para>The "xmlrpc" native extension is not required to be compiled into
889     your PHP installation, but if it is, there will be no interference with
890     the operation of this library.</para>
891   </chapter>
892
893   <chapter id="manifest">
894     <title>Files in the distribution</title>
895
896     <glosslist>
897       <glossentry>
898         <glossterm>lib/xmlrpc.inc</glossterm>
899
900         <glossdef>
901           <para>the XML-RPC classes. <function>include()</function> this in
902           your PHP files to use the classes.</para>
903         </glossdef>
904       </glossentry>
905
906       <glossentry>
907         <glossterm>lib/xmlrpcs.inc</glossterm>
908
909         <glossdef>
910           <para>the XML-RPC server class. <function>include()</function> this
911           in addition to xmlrpc.inc to get server functionality</para>
912         </glossdef>
913       </glossentry>
914
915       <glossentry>
916         <glossterm>lib/xmlrpc_wrappers.php</glossterm>
917
918         <glossdef>
919           <para>helper functions to "automagically" convert plain php
920           functions to xmlrpc services and vice versa</para>
921         </glossdef>
922       </glossentry>
923
924       <glossentry>
925         <glossterm>demo/server/proxy.php</glossterm>
926
927         <glossdef>
928           <para>a sample server implementing xmlrpc proxy
929           functionality.</para>
930         </glossdef>
931       </glossentry>
932
933       <glossentry>
934         <glossterm>demo/server/server.php</glossterm>
935
936         <glossdef>
937           <para>a sample server hosting various demo functions, as well as a
938           full suite of functions used for interoperability testing. It is
939           used by testsuite.php (see below) for unit testing the library, and
940           is not to be copied literally into your production servers</para>
941         </glossdef>
942       </glossentry>
943
944       <glossentry>
945         <glossterm>demo/client/client.php, demo/client/agesort.php,
946         demo/client/which.php</glossterm>
947
948         <glossdef>
949           <para>client code to exercise some of the functions in server.php,
950           including the <function>interopEchoTests.whichToolkit</function>
951           method.</para>
952         </glossdef>
953       </glossentry>
954
955       <glossentry>
956         <glossterm>demo/client/wrap.php</glossterm>
957
958         <glossdef>
959           <para>client code to illustrate 'wrapping' of remote methods into
960           php functions.</para>
961         </glossdef>
962       </glossentry>
963
964       <glossentry>
965         <glossterm>demo/client/introspect.php</glossterm>
966
967         <glossdef>
968           <para>client code to illustrate usage of introspection capabilities
969           offered by server.php.</para>
970         </glossdef>
971       </glossentry>
972
973       <glossentry>
974         <glossterm>demo/client/mail.php</glossterm>
975
976         <glossdef>
977           <para>client code to illustrate usage of an xmlrpc-to-email gateway
978           using Dave Winer's XML-RPC server at userland.com.</para>
979         </glossdef>
980       </glossentry>
981
982       <glossentry>
983         <glossterm>demo/client/zopetest.php</glossterm>
984
985         <glossdef>
986           <para>example client code that queries an xmlrpc server built in
987           Zope.</para>
988         </glossdef>
989       </glossentry>
990
991       <glossentry>
992         <glossterm>demo/vardemo.php</glossterm>
993
994         <glossdef>
995           <para>examples of how to construct xmlrpcval types</para>
996         </glossdef>
997       </glossentry>
998
999       <glossentry>
1000         <glossterm>demo/demo1.xml, demo/demo2.xml, demo/demo3.xml</glossterm>
1001
1002         <glossdef>
1003           <para>XML-RPC responses captured in a file for testing purposes (you
1004           can use these to test the
1005           <function>xmlrpcmsg-&gt;parseResponse()</function> method).</para>
1006         </glossdef>
1007       </glossentry>
1008
1009       <glossentry>
1010         <glossterm>demo/server/discuss.php,
1011         demo/client/comment.php</glossterm>
1012
1013         <glossdef>
1014           <para>Software used in the PHP chapter of <xref
1015           linkend="jellyfish" /> to provide a comment server and allow the
1016           attachment of comments to stories from Meerkat's data store.</para>
1017         </glossdef>
1018       </glossentry>
1019
1020       <glossentry>
1021         <glossterm>test/testsuite.php, test/parse_args.php</glossterm>
1022
1023         <glossdef>
1024           <para>A unit test suite for this software package. If you do
1025           development on this software, please consider submitting tests for
1026           this suite.</para>
1027         </glossdef>
1028       </glossentry>
1029
1030       <glossentry>
1031         <glossterm>test/benchmark.php</glossterm>
1032
1033         <glossdef>
1034           <para>A (very limited) benchmarking suite for this software package.
1035           If you do development on this software, please consider submitting
1036           benchmarks for this suite.</para>
1037         </glossdef>
1038       </glossentry>
1039
1040       <glossentry>
1041         <glossterm>test/phpunit.php, test/PHPUnit/*.php</glossterm>
1042
1043         <glossdef>
1044           <para>An (incomplete) version PEAR's unit test framework for PHP.
1045           The complete package can be found at <ulink
1046           url="http://pear.php.net/package/PHPUnit">http://pear.php.net/package/PHPUnit</ulink></para>
1047         </glossdef>
1048       </glossentry>
1049
1050       <glossentry>
1051         <glossterm>test/verify_compat.php</glossterm>
1052
1053         <glossdef>
1054           <para>Script designed to help the user to verify the level of
1055           compatibility of the library with the current php install</para>
1056         </glossdef>
1057       </glossentry>
1058
1059       <glossentry>
1060         <glossterm>extras/test.pl, extras/test.py</glossterm>
1061
1062         <glossdef>
1063           <para>Perl and Python programs to exercise server.php to test that
1064           some of the methods work.</para>
1065         </glossdef>
1066       </glossentry>
1067
1068       <glossentry>
1069         <glossterm>extras/workspace.testPhpServer.fttb</glossterm>
1070
1071         <glossdef>
1072           <para>Frontier scripts to exercise the demo server. Thanks to Dave
1073           Winer for permission to include these. See <ulink
1074           url="http://www.xmlrpc.com/discuss/msgReader$853">Dave's
1075           announcement of these.</ulink></para>
1076         </glossdef>
1077       </glossentry>
1078
1079       <glossentry>
1080         <glossterm>extras/rsakey.pem</glossterm>
1081
1082         <glossdef>
1083           <para>A test certificate key for the SSL support, which can be used
1084           to generate dummy certificates. It has the passphrase "test."</para>
1085         </glossdef>
1086       </glossentry>
1087     </glosslist>
1088   </chapter>
1089
1090   <chapter id="bugs">
1091     <title>Known bugs and limitations</title>
1092
1093     <para>This started out as a bare framework. Many "nice" bits haven't been
1094     put in yet. Specifically, very little type validation or coercion has been
1095     put in. PHP being a loosely-typed language, this is going to have to be
1096     done explicitly (in other words: you can call a lot of library functions
1097     passing them arguments of the wrong type and receive an error message only
1098     much further down the code, where it will be difficult to
1099     understand).</para>
1100
1101     <para>dateTime.iso8601 is supported opaquely. It can't be done natively as
1102     the XML-RPC specification explicitly forbids passing of timezone
1103     specifiers in ISO8601 format dates. You can, however, use the <xref
1104     linkend="iso8601encode" /> and <xref linkend="iso8601decode" /> functions
1105     to do the encoding and decoding for you.</para>
1106
1107     <para>Very little HTTP response checking is performed (e.g. HTTP redirects
1108     are not followed and the Content-Length HTTP header, mandated by the
1109     xml-rpc spec, is not validated); cookie support still involves quite a bit
1110     of coding on the part of the user.</para>
1111
1112     <para>If a specific character set encoding other than US-ASCII, ISO-8859-1
1113     or UTF-8 is received in the HTTP header or XML prologue of xml-rpc request
1114     or response messages then it will be ignored for the moment, and the
1115     content will be parsed as if it had been encoded using the charset defined
1116     by <xref linkend="xmlrpc-defencoding" /></para>
1117
1118     <para>Support for receiving from servers version 1 cookies (i.e.
1119     conforming to RFC 2965) is quite incomplete, and might cause unforeseen
1120     errors.</para>
1121   </chapter>
1122
1123   <chapter id="support">
1124     <title>Support</title>
1125
1126     <sect1>
1127       <title>Online Support</title>
1128
1129       <para>XML-RPC for PHP is offered "as-is" without any warranty or
1130       commitment to support. However, informal advice and help is available
1131       via the XML-RPC for PHP website and mailing list and from
1132       XML-RPC.com.</para>
1133
1134       <itemizedlist>
1135         <listitem>
1136           <para>The <emphasis>XML-RPC for PHP</emphasis> development is hosted
1137           on <ulink
1138           url="https://github.com/gggeek/phpxmlrpc">github.com/gggeek/phpxmlrpc</ulink>.
1139           Bugs, feature requests and patches can be posted to the <ulink
1140           url="https://github.com/gggeek/phpxmlrpc/issues">project's
1141           website</ulink>.</para>
1142         </listitem>
1143
1144         <listitem>
1145           <para>The <emphasis>PHP XML-RPC interest mailing list</emphasis> is
1146           run by the author. More details <ulink
1147           url="http://lists.gnomehack.com/mailman/listinfo/phpxmlrpc">can be
1148           found here</ulink>.</para>
1149         </listitem>
1150
1151         <listitem>
1152           <para>For more general XML-RPC questions, there is a Yahoo! Groups
1153           <ulink url="http://groups.yahoo.com/group/xml-rpc/">XML-RPC mailing
1154           list</ulink>.</para>
1155         </listitem>
1156
1157         <listitem>
1158           <para>The <ulink
1159           url="http://www.xmlrpc.com/discuss">XML-RPC.com</ulink> discussion
1160           group is a useful place to get help with using XML-RPC. This group
1161           is also gatewayed into the Yahoo! Groups mailing list.</para>
1162         </listitem>
1163       </itemizedlist>
1164     </sect1>
1165
1166     <sect1 id="jellyfish" xreflabel="The Jellyfish Book">
1167       <title>The Jellyfish Book</title>
1168
1169       <para><graphic align="right" depth="190" fileref="images/progxmlrpc.s.gif"
1170       format="GIF" width="145" />Together with Simon St.Laurent and Joe
1171       Johnston, Edd Dumbill wrote a book on XML-RPC for O'Reilly and
1172       Associates on XML-RPC. It features a rather fetching jellyfish on the
1173       cover.</para>
1174
1175       <para>Complete details of the book are <ulink
1176       url="http://www.oreilly.com/catalog/progxmlrpc/">available from
1177       O'Reilly's web site.</ulink></para>
1178
1179       <para>Edd is responsible for the chapter on PHP, which includes a worked
1180       example of creating a forum server, and hooking it up the O'Reilly's
1181       <ulink url="http://meerkat.oreillynet.com/">Meerkat</ulink> service in
1182       order to allow commenting on news stories from around the Web.</para>
1183
1184       <para>If you've benefited from the effort that has been put into writing
1185       this software, then please consider buying the book!</para>
1186     </sect1>
1187   </chapter>
1188
1189   <chapter id="apidocs">
1190     <title>Class documentation</title>
1191
1192     <sect1 id="xmlrpcval" xreflabel="xmlrpcval">
1193       <title>xmlrpcval</title>
1194
1195       <para>This is where a lot of the hard work gets done. This class enables
1196       the creation and encapsulation of values for XML-RPC.</para>
1197
1198       <para>Ensure you've read the XML-RPC spec at <ulink
1199       url="http://www.xmlrpc.com/stories/storyReader$7">http://www.xmlrpc.com/stories/storyReader$7</ulink>
1200       before reading on as it will make things clearer.</para>
1201
1202       <para>The <classname>xmlrpcval</classname> class can store arbitrarily
1203       complicated values using the following types: <literal>i4 int boolean
1204       string double dateTime.iso8601 base64 array struct</literal>
1205       <literal>null</literal>. You should refer to the <ulink
1206       url="http://www.xmlrpc.com/spec">spec</ulink> for more information on
1207       what each of these types mean.</para>
1208
1209       <sect2>
1210         <title>Notes on types</title>
1211
1212         <sect3>
1213           <title>int</title>
1214
1215           <para>The type <classname>i4</classname> is accepted as a synonym
1216           for <classname>int</classname> when creating xmlrpcval objects. The
1217           xml parsing code will always convert <classname>i4</classname> to
1218           <classname>int</classname>: <classname>int</classname> is regarded
1219           by this implementation as the canonical name for this type.</para>
1220         </sect3>
1221
1222         <sect3>
1223           <title>base64</title>
1224
1225           <para>Base 64 encoding is performed transparently to the caller when
1226           using this type. Decoding is also transparent. Therefore you ought
1227           to consider it as a "binary" data type, for use when you want to
1228           pass data that is not 7-bit clean.</para>
1229         </sect3>
1230
1231         <sect3>
1232           <title>boolean</title>
1233
1234           <para>The php values <literal>true</literal> and
1235           <literal>1</literal> map to <literal>true</literal>. All other
1236           values (including the empty string) are converted to
1237           <literal>false</literal>.</para>
1238         </sect3>
1239
1240         <sect3>
1241           <title>string</title>
1242
1243           <para>Characters &lt;, &gt;, ', ", &amp;, are encoded using their
1244           entity reference as &amp;lt; &amp;gt; &amp;apos; &amp;quot; and
1245           &amp;amp; All other characters outside of the ASCII range are
1246           encoded using their character reference representation (e.g.
1247           &amp;#200 for é). The XML-RPC spec recommends only encoding
1248           <literal>&lt; &amp;</literal> but this implementation goes further,
1249           for reasons explained by <ulink
1250           url="http://www.w3.org/TR/REC-xml#syntax">the XML 1.0
1251           recommendation</ulink>. In particular, using character reference
1252           representation has the advantage of producing XML that is valid
1253           independently of the charset encoding assumed.</para>
1254         </sect3>
1255
1256         <sect3>
1257           <title>null</title>
1258
1259           <para>There is no support for encoding <literal>null</literal>
1260           values in the XML-RPC spec, but at least a couple of extensions (and
1261           many toolkits) do support it. Before using <literal>null</literal>
1262           values in your messages, make sure that the responding party accepts
1263           them, and uses the same encoding convention (see ...).</para>
1264         </sect3>
1265       </sect2>
1266
1267       <sect2 id="xmlrpcval-creation" xreflabel="xmlrpcval constructors">
1268         <title>Creation</title>
1269
1270         <para>The constructor is the normal way to create an
1271         <classname>xmlrpcval</classname>. The constructor can take these
1272         forms:</para>
1273
1274         <funcsynopsis>
1275           <funcprototype>
1276             <funcdef><type>xmlrpcval</type>new
1277             <function>xmlrpcval</function></funcdef>
1278
1279             <void />
1280           </funcprototype>
1281
1282           <funcprototype>
1283             <funcdef><type>xmlrpcval</type>new
1284             <function>xmlrpcval</function></funcdef>
1285
1286             <paramdef><type>string</type><parameter>$stringVal</parameter></paramdef>
1287           </funcprototype>
1288
1289           <funcprototype>
1290             <funcdef><type>xmlrpcval</type>new
1291             <function>xmlrpcval</function></funcdef>
1292
1293             <paramdef><type>mixed</type><parameter>$scalarVal</parameter></paramdef>
1294
1295             <paramdef><type>string</type><parameter>$scalartyp</parameter></paramdef>
1296           </funcprototype>
1297
1298           <funcprototype>
1299             <funcdef><type>xmlrpcval</type>new
1300             <function>xmlrpcval</function></funcdef>
1301
1302             <paramdef><type>array</type><parameter>$arrayVal</parameter></paramdef>
1303
1304             <paramdef><type>string</type><parameter>$arraytyp</parameter></paramdef>
1305           </funcprototype>
1306         </funcsynopsis>
1307
1308         <para>The first constructor creates an empty value, which must be
1309         altered using the methods <function>addScalar</function>,
1310         <function>addArray</function> or <function>addStruct</function> before
1311         it can be used.</para>
1312
1313         <para>The second constructor creates a simple string value.</para>
1314
1315         <para>The third constructor is used to create a scalar value. The
1316         second parameter must be a name of an XML-RPC type. Valid types are:
1317         "<literal>int</literal>", "<literal>boolean</literal>",
1318         "<literal>string</literal>", "<literal>double</literal>",
1319         "<literal>dateTime.iso8601</literal>", "<literal>base64</literal>" or
1320         "null".</para>
1321
1322         <para>Examples:</para>
1323
1324         <programlisting language="php">
1325 $myInt = new xmlrpcval(1267, "int");
1326 $myString = new xmlrpcval("Hello, World!", "string");
1327 $myBool = new xmlrpcval(1, "boolean");
1328 $myString2 = new xmlrpcval(1.24, "string"); // note: this will serialize a php float value as xmlrpc string
1329 </programlisting>
1330
1331         <para>The fourth constructor form can be used to compose complex
1332         XML-RPC values. The first argument is either a simple array in the
1333         case of an XML-RPC <classname>array</classname> or an associative
1334         array in the case of a <classname>struct</classname>. The elements of
1335         the array <emphasis>must be <classname>xmlrpcval</classname> objects
1336         themselves</emphasis>.</para>
1337
1338         <para>The second parameter must be either "<literal>array</literal>"
1339         or "<literal>struct</literal>".</para>
1340
1341         <para>Examples:</para>
1342
1343         <programlisting language="php">
1344 $myArray = new xmlrpcval(
1345   array(
1346     new xmlrpcval("Tom"),
1347     new xmlrpcval("Dick"),
1348     new xmlrpcval("Harry")
1349   ),
1350   "array");
1351
1352 // recursive struct
1353 $myStruct = new xmlrpcval(
1354   array(
1355     "name" =&gt; new xmlrpcval("Tom", "string"),
1356     "age" =&gt; new xmlrpcval(34, "int"),
1357     "address" =&gt; new xmlrpcval(
1358       array(
1359         "street" =&gt; new xmlrpcval("Fifht Ave", "string"),
1360         "city" =&gt; new xmlrpcval("NY", "string")
1361       ),
1362       "struct")
1363   ),
1364   "struct");
1365 </programlisting>
1366
1367         <para>See the file <literal>vardemo.php</literal> in this distribution
1368         for more examples.</para>
1369       </sect2>
1370
1371       <sect2 id="xmlrpcval-methods" xreflabel="xmlrpcval methods">
1372         <title>Methods</title>
1373
1374         <sect3>
1375           <title>addScalar</title>
1376
1377           <funcsynopsis>
1378             <funcprototype>
1379               <funcdef><type>int</type><function>addScalar</function></funcdef>
1380
1381               <paramdef><type>string</type><parameter>$stringVal</parameter></paramdef>
1382             </funcprototype>
1383
1384             <funcprototype>
1385               <funcdef><type>int</type><function>addScalar</function></funcdef>
1386
1387               <paramdef><type>mixed</type><parameter>$scalarVal</parameter></paramdef>
1388
1389               <paramdef><type>string</type><parameter>$scalartyp</parameter></paramdef>
1390             </funcprototype>
1391           </funcsynopsis>
1392
1393           <para>If <parameter>$val</parameter> is an empty
1394           <classname>xmlrpcval</classname> this method makes it a scalar
1395           value, and sets that value.</para>
1396
1397           <para>If <parameter>$val</parameter> is already a scalar value, then
1398           no more scalars can be added and <literal>0</literal> is
1399           returned.</para>
1400
1401           <para>If <parameter>$val</parameter> is an xmlrpcval of type array,
1402           the php value <parameter>$scalarval</parameter> is added as its last
1403           element.</para>
1404
1405           <para>If all went OK, <literal>1</literal> is returned, otherwise
1406           <literal>0</literal>.</para>
1407         </sect3>
1408
1409         <sect3>
1410           <title>addArray</title>
1411
1412           <funcsynopsis>
1413             <funcprototype>
1414               <funcdef><type>int</type><function>addArray</function></funcdef>
1415
1416               <paramdef><type>array</type><parameter>$arrayVal</parameter></paramdef>
1417             </funcprototype>
1418           </funcsynopsis>
1419
1420           <para>The argument is a simple (numerically indexed) array. The
1421           elements of the array <emphasis>must be
1422           <classname>xmlrpcval</classname> objects
1423           themselves</emphasis>.</para>
1424
1425           <para>Turns an empty <classname>xmlrpcval</classname> into an
1426           <classname>array</classname> with contents as specified by
1427           <parameter>$arrayVal</parameter>.</para>
1428
1429           <para>If <parameter>$val</parameter> is an xmlrpcval of type array,
1430           the elements of <parameter>$arrayVal</parameter> are appended to the
1431           existing ones.</para>
1432
1433           <para>See the fourth constructor form for more information.</para>
1434
1435           <para>If all went OK, <literal>1</literal> is returned, otherwise
1436           <literal>0</literal>.</para>
1437         </sect3>
1438
1439         <sect3>
1440           <title>addStruct</title>
1441
1442           <funcsynopsis>
1443             <funcprototype>
1444               <funcdef><type>int</type><function>addStruct</function></funcdef>
1445
1446               <paramdef><type>array</type><parameter>$assocArrayVal</parameter></paramdef>
1447             </funcprototype>
1448           </funcsynopsis>
1449
1450           <para>The argument is an associative array. The elements of the
1451           array <emphasis>must be <classname>xmlrpcval</classname> objects
1452           themselves</emphasis>.</para>
1453
1454           <para>Turns an empty <classname>xmlrpcval</classname> into a
1455           <classname>struct</classname> with contents as specified by
1456           <parameter>$assocArrayVal</parameter>.</para>
1457
1458           <para>If <parameter>$val</parameter> is an xmlrpcval of type struct,
1459           the elements of <parameter>$arrayVal</parameter> are merged with the
1460           existing ones.</para>
1461
1462           <para>See the fourth constructor form for more information.</para>
1463
1464           <para>If all went OK, <literal>1</literal> is returned, otherwise
1465           <literal>0</literal>.</para>
1466         </sect3>
1467
1468         <sect3>
1469           <title>kindOf</title>
1470
1471           <funcsynopsis>
1472             <funcprototype>
1473               <funcdef><type>string</type><function>kindOf</function></funcdef>
1474
1475               <void />
1476             </funcprototype>
1477           </funcsynopsis>
1478
1479           <para>Returns a string containing "struct", "array" or "scalar"
1480           describing the base type of the value. If it returns "undef" it
1481           means that the value hasn't been initialised.</para>
1482         </sect3>
1483
1484         <sect3>
1485           <title>serialize</title>
1486
1487           <funcsynopsis>
1488             <funcprototype>
1489               <funcdef><type>string</type><function>serialize</function></funcdef>
1490
1491               <void />
1492             </funcprototype>
1493           </funcsynopsis>
1494
1495           <para>Returns a string containing the XML-RPC representation of this
1496           value.</para>
1497         </sect3>
1498
1499         <sect3>
1500           <title>scalarVal</title>
1501
1502           <funcsynopsis>
1503             <funcprototype>
1504               <funcdef><type>mixed</type><function>scalarVal</function></funcdef>
1505
1506               <void />
1507             </funcprototype>
1508           </funcsynopsis>
1509
1510           <para>If <function>$val-&gt;kindOf() == "scalar"</function>, this
1511           method returns the actual PHP-language value of the scalar (base 64
1512           decoding is automatically handled here).</para>
1513         </sect3>
1514
1515         <sect3>
1516           <title>scalarTyp</title>
1517
1518           <funcsynopsis>
1519             <funcprototype>
1520               <funcdef><type>string</type><function>scalarTyp</function></funcdef>
1521
1522               <void />
1523             </funcprototype>
1524           </funcsynopsis>
1525
1526           <para>If <function>$val-&gt;kindOf() == "scalar"</function>, this
1527           method returns a string denoting the type of the scalar. As
1528           mentioned before, <literal>i4</literal> is always coerced to
1529           <literal>int</literal>.</para>
1530         </sect3>
1531
1532         <sect3>
1533           <title>arrayMem</title>
1534
1535           <funcsynopsis>
1536             <funcprototype>
1537               <funcdef><type>xmlrpcval</type><function>arrayMem</function></funcdef>
1538
1539               <paramdef><type>int</type><parameter>$n</parameter></paramdef>
1540             </funcprototype>
1541           </funcsynopsis>
1542
1543           <para>If <function>$val-&gt;kindOf() == "array"</function>, returns
1544           the <parameter>$n</parameter>th element in the array represented by
1545           the value <parameter>$val</parameter>. The value returned is an
1546           <classname>xmlrpcval</classname> object.</para>
1547
1548           <para><programlisting language="php">
1549 // iterating over values of an array object
1550 for ($i = 0; $i &lt; $val-&gt;arraySize(); $i++)
1551 {
1552   $v = $val-&gt;arrayMem($i);
1553   echo "Element $i of the array is of type ".$v-&gt;kindOf();
1554 }
1555 </programlisting></para>
1556         </sect3>
1557
1558         <sect3>
1559           <title>arraySize</title>
1560
1561           <funcsynopsis>
1562             <funcprototype>
1563               <funcdef><type>int</type><function>arraySize</function></funcdef>
1564
1565               <void />
1566             </funcprototype>
1567           </funcsynopsis>
1568
1569           <para>If <parameter>$val</parameter> is an
1570           <classname>array</classname>, returns the number of elements in that
1571           array.</para>
1572         </sect3>
1573
1574         <sect3>
1575           <title>structMem</title>
1576
1577           <funcsynopsis>
1578             <funcprototype>
1579               <funcdef><type>xmlrpcval</type><function>structMem</function></funcdef>
1580
1581               <paramdef><type>string</type><parameter>$memberName</parameter></paramdef>
1582             </funcprototype>
1583           </funcsynopsis>
1584
1585           <para>If <function>$val-&gt;kindOf() == "struct"</function>, returns
1586           the element called <parameter>$memberName</parameter> from the
1587           struct represented by the value <parameter>$val</parameter>. The
1588           value returned is an <classname>xmlrpcval</classname> object.</para>
1589         </sect3>
1590
1591         <sect3>
1592           <title>structEach</title>
1593
1594           <funcsynopsis>
1595             <funcprototype>
1596               <funcdef><type>array</type><function>structEach</function></funcdef>
1597
1598               <void />
1599             </funcprototype>
1600           </funcsynopsis>
1601
1602           <para>Returns the next (key, value) pair from the struct, when
1603           <parameter>$val</parameter> is a struct.
1604           <parameter>$value</parameter> is an xmlrpcval itself. See also <xref
1605           linkend="structreset" />.</para>
1606
1607           <para><programlisting language="php">
1608 // iterating over all values of a struct object
1609 $val-&gt;structreset();
1610 while (list($key, $v) = $val-&gt;structEach())
1611 {
1612   echo "Element $key of the struct is of type ".$v-&gt;kindOf();
1613 }
1614 </programlisting></para>
1615         </sect3>
1616
1617         <sect3 id="structreset" xreflabel="structreset()">
1618           <title>structReset</title>
1619
1620           <funcsynopsis>
1621             <funcprototype>
1622               <funcdef><type>void</type><function>structReset</function></funcdef>
1623
1624               <void />
1625             </funcprototype>
1626           </funcsynopsis>
1627
1628           <para>Resets the internal pointer for
1629           <function>structEach()</function> to the beginning of the struct,
1630           where <parameter>$val</parameter> is a struct.</para>
1631         </sect3>
1632
1633         <sect3 id="structmemexists" xreflabel="structmemexists()">
1634           <title>structMemExists</title>
1635
1636           <funcsynopsis>
1637             <funcprototype>
1638               <funcdef><type>bool</type><function>structMemExsists</function></funcdef>
1639
1640               <paramdef><type>string</type><parameter>$memberName</parameter></paramdef>
1641             </funcprototype>
1642           </funcsynopsis>
1643
1644           <para>Returns <constant>TRUE</constant> or
1645           <constant>FALSE</constant> depending on whether a member of the
1646           given name exists in the struct.</para>
1647         </sect3>
1648       </sect2>
1649     </sect1>
1650
1651     <sect1 id="xmlrpcmsg" xreflabel="xmlrpcmsg">
1652       <title>xmlrpcmsg</title>
1653
1654       <para>This class provides a representation for a request to an XML-RPC
1655       server. A client sends an <classname>xmlrpcmsg</classname> to a server,
1656       and receives back an <classname>xmlrpcresp</classname> (see <xref
1657       linkend="xmlrpc-client-send" />).</para>
1658
1659       <sect2>
1660         <title>Creation</title>
1661
1662         <para>The constructor takes the following forms:</para>
1663
1664         <funcsynopsis>
1665           <funcprototype>
1666             <funcdef><type>xmlrpcmsg</type>new
1667             <function>xmlrpcmsg</function></funcdef>
1668
1669             <paramdef><type>string</type><parameter>$methodName</parameter></paramdef>
1670
1671             <paramdef><type>array</type><parameter>$parameterArray</parameter><initializer>null</initializer></paramdef>
1672           </funcprototype>
1673         </funcsynopsis>
1674
1675         <para>Where <parameter>methodName</parameter> is a string indicating
1676         the name of the method you wish to invoke, and
1677         <parameter>parameterArray</parameter> is a simple php
1678         <classname>Array</classname> of <classname>xmlrpcval</classname>
1679         objects. Here's an example message to the <emphasis>US state
1680         name</emphasis> server:</para>
1681
1682         <programlisting language="php">
1683 $msg = new xmlrpcmsg("examples.getStateName", array(new xmlrpcval(23, "int")));
1684 </programlisting>
1685
1686         <para>This example requests the name of state number 23. For more
1687         information on <classname>xmlrpcval</classname> objects, see <xref
1688         linkend="xmlrpcval" />.</para>
1689
1690         <para>Note that the <parameter>parameterArray</parameter> parameter is
1691         optional and can be omitted for methods that take no input parameters
1692         or if you plan to add parameters one by one.</para>
1693       </sect2>
1694
1695       <sect2>
1696         <title>Methods</title>
1697
1698         <sect3>
1699           <title>addParam</title>
1700
1701           <funcsynopsis>
1702             <funcprototype>
1703               <funcdef><type>bool</type><function>addParam</function></funcdef>
1704
1705               <paramdef><type>xmlrpcval</type><parameter>$xmlrpcVal</parameter></paramdef>
1706             </funcprototype>
1707           </funcsynopsis>
1708
1709           <para>Adds the <classname>xmlrpcval</classname>
1710           <parameter>xmlrpcVal</parameter> to the parameter list for this
1711           method call. Returns TRUE or FALSE on error.</para>
1712         </sect3>
1713
1714         <sect3>
1715           <title>getNumParams</title>
1716
1717           <funcsynopsis>
1718             <funcprototype>
1719               <funcdef><type>int</type><function>getNumParams</function></funcdef>
1720
1721               <void />
1722             </funcprototype>
1723           </funcsynopsis>
1724
1725           <para>Returns the number of parameters attached to this
1726           message.</para>
1727         </sect3>
1728
1729         <sect3>
1730           <title>getParam</title>
1731
1732           <funcsynopsis>
1733             <funcprototype>
1734               <funcdef><type>xmlrpcval</type><function>getParam</function></funcdef>
1735
1736               <paramdef><type>int</type><parameter>$n</parameter></paramdef>
1737             </funcprototype>
1738           </funcsynopsis>
1739
1740           <para>Gets the <parameter>n</parameter>th parameter in the message
1741           (with the index zero-based). Use this method in server
1742           implementations to retrieve the values sent by the client.</para>
1743         </sect3>
1744
1745         <sect3>
1746           <title>method</title>
1747
1748           <funcsynopsis>
1749             <funcprototype>
1750               <funcdef><type>string</type><function>method</function></funcdef>
1751
1752               <void />
1753             </funcprototype>
1754
1755             <funcprototype>
1756               <funcdef><type>string</type><function>method</function></funcdef>
1757
1758               <paramdef><type>string</type><parameter>$methName</parameter></paramdef>
1759             </funcprototype>
1760           </funcsynopsis>
1761
1762           <para>Gets or sets the method contained in the XML-RPC
1763           message.</para>
1764         </sect3>
1765
1766         <sect3>
1767           <title>parseResponse</title>
1768
1769           <funcsynopsis>
1770             <funcprototype>
1771               <funcdef><type>xmlrpcresp</type><function>parseResponse</function></funcdef>
1772
1773               <paramdef><type>string</type><parameter>$xmlString</parameter></paramdef>
1774             </funcprototype>
1775           </funcsynopsis>
1776
1777           <para>Given an incoming XML-RPC server response contained in the
1778           string <parameter>$xmlString</parameter>, this method constructs an
1779           <classname>xmlrpcresp</classname> response object and returns it,
1780           setting error codes as appropriate (see <xref
1781           linkend="xmlrpc-client-send" />).</para>
1782
1783           <para>This method processes any HTTP/MIME headers it finds.</para>
1784         </sect3>
1785
1786         <sect3>
1787           <title>parseResponseFile</title>
1788
1789           <funcsynopsis>
1790             <funcprototype>
1791               <funcdef><type>xmlrpcresp</type><function>parseResponseFile</function></funcdef>
1792
1793               <paramdef><type>file handle
1794               resource</type><parameter>$fileHandle</parameter></paramdef>
1795             </funcprototype>
1796           </funcsynopsis>
1797
1798           <para>Given an incoming XML-RPC server response on the open file
1799           handle <parameter>fileHandle</parameter>, this method reads all the
1800           data it finds and passes it to
1801           <function>parseResponse.</function></para>
1802
1803           <para>This method is useful to construct responses from pre-prepared
1804           files (see files <literal>demo1.xml, demo2.xml, demo3.xml</literal>
1805           in this distribution). It processes any HTTP headers it finds, and
1806           does not close the file handle.</para>
1807         </sect3>
1808
1809         <sect3>
1810           <title>serialize</title>
1811
1812           <funcsynopsis>
1813             <funcprototype>
1814               <funcdef><type>string
1815               </type><function>serialize</function></funcdef>
1816
1817               <void />
1818             </funcprototype>
1819           </funcsynopsis>
1820
1821           <para>Returns the an XML string representing the XML-RPC
1822           message.</para>
1823         </sect3>
1824       </sect2>
1825     </sect1>
1826
1827     <sect1 id="xmlrpc-client" xreflabel="xmlrpc_client">
1828       <title>xmlrpc_client</title>
1829
1830       <para>This is the basic class used to represent a client of an XML-RPC
1831       server.</para>
1832
1833       <sect2>
1834         <title>Creation</title>
1835
1836         <para>The constructor accepts one of two possible syntaxes:</para>
1837
1838         <funcsynopsis>
1839           <funcprototype>
1840             <funcdef><type>xmlrpc_client</type>new
1841             <function>xmlrpc_client</function></funcdef>
1842
1843             <paramdef><type>string</type><parameter>$server_url</parameter></paramdef>
1844           </funcprototype>
1845
1846           <funcprototype>
1847             <funcdef><type>xmlrpc_client</type>new
1848             <function>xmlrpc_client</function></funcdef>
1849
1850             <paramdef><type>string</type><parameter>$server_path</parameter></paramdef>
1851
1852             <paramdef><type>string</type><parameter>$server_hostname</parameter></paramdef>
1853
1854             <paramdef><type>int</type><parameter>$server_port</parameter><initializer>80</initializer></paramdef>
1855
1856             <paramdef><type>string</type><parameter>$transport</parameter><initializer>'http'</initializer></paramdef>
1857           </funcprototype>
1858         </funcsynopsis>
1859
1860         <para>Here are a couple of usage examples of the first form:</para>
1861
1862         <programlisting language="php">
1863 $client = new xmlrpc_client("http://phpxmlrpc.sourceforge.net/server.php");
1864 $another_client = new xmlrpc_client("https://james:bond@secret.service.com:443/xmlrpcserver?agent=007");
1865 </programlisting>
1866
1867         <para>The second syntax does not allow to express a username and
1868         password to be used for basic HTTP authorization as in the second
1869         example above, but instead it allows to choose whether xmlrpc calls
1870         will be made using the HTTP 1.0 or 1.1 protocol.</para>
1871
1872         <para>Here's another example client set up to query Userland's XML-RPC
1873         server at <emphasis>betty.userland.com</emphasis>:</para>
1874
1875         <programlisting language="php">
1876 $client = new xmlrpc_client("/RPC2", "betty.userland.com", 80);
1877 </programlisting>
1878
1879         <para>The <parameter>server_port</parameter> parameter is optional,
1880         and if omitted will default to 80 when using HTTP and 443 when using
1881         HTTPS (see the <xref linkend="xmlrpc-client-send" /> method
1882         below).</para>
1883
1884         <para>The <parameter>transport</parameter> parameter is optional, and
1885         if omitted will default to 'http'. Allowed values are either
1886         '<symbol>http'</symbol>, '<symbol>https</symbol>' or
1887         '<symbol>http11'</symbol>. Its value can be overridden with every call
1888         to the <methodname>send</methodname> method. See the
1889         <methodname>send</methodname> method below for more details about the
1890         meaning of the different values.</para>
1891       </sect2>
1892
1893       <sect2>
1894         <title>Methods</title>
1895
1896         <para>This class supports the following methods.</para>
1897
1898         <sect3 id="xmlrpc-client-send" xreflabel="xmlrpc_client-&gt;send">
1899           <title>send</title>
1900
1901           <para>This method takes the forms:</para>
1902
1903           <funcsynopsis>
1904             <funcprototype>
1905               <funcdef><type>xmlrpcresp</type><function>send</function></funcdef>
1906
1907               <paramdef><type>xmlrpcmsg</type><parameter>$xmlrpc_message</parameter></paramdef>
1908
1909               <paramdef><type>int</type><parameter>$timeout</parameter></paramdef>
1910
1911               <paramdef><type>string</type><parameter>$transport</parameter></paramdef>
1912             </funcprototype>
1913
1914             <funcprototype>
1915               <funcdef><type>array</type><function>send</function></funcdef>
1916
1917               <paramdef><type>array</type><parameter>$xmlrpc_messages</parameter></paramdef>
1918
1919               <paramdef><type>int</type><parameter>$timeout</parameter></paramdef>
1920
1921               <paramdef><type>string</type><parameter>$transport</parameter></paramdef>
1922             </funcprototype>
1923
1924             <funcprototype>
1925               <funcdef><type>xmlrpcresp</type><function>send</function></funcdef>
1926
1927               <paramdef><type>string</type><parameter>$xml_payload</parameter></paramdef>
1928
1929               <paramdef><type>int</type><parameter>$timeout</parameter></paramdef>
1930
1931               <paramdef><type>string</type><parameter>$transport</parameter></paramdef>
1932             </funcprototype>
1933           </funcsynopsis>
1934
1935           <para>Where <parameter>xmlrpc_message</parameter> is an instance of
1936           <classname>xmlrpcmsg</classname> (see <xref linkend="xmlrpcmsg" />),
1937           and <parameter>response</parameter> is an instance of
1938           <classname>xmlrpcresp</classname> (see <xref
1939           linkend="xmlrpcresp" />).</para>
1940
1941           <para><parameter>If xmlrpc_messages</parameter> is an array of
1942           message instances, <code>responses</code> will be an array of
1943           response instances. The client will try to make use of a single
1944           <code>system.multicall</code> xml-rpc method call to forward to the
1945           server all the messages in a single HTTP round trip, unless
1946           <code>$client-&gt;no_multicall</code> has been previously set to
1947           <code>TRUE</code> (see the multicall method below), in which case
1948           many consecutive xmlrpc requests will be sent.</para>
1949
1950           <para>The third syntax allows to build by hand (or any other means)
1951           a complete xmlrpc request message, and send it to the server.
1952           <parameter>xml_payload</parameter> should be a string containing the
1953           complete xml representation of the request. It is e.g. useful when,
1954           for maximal speed of execution, the request is serialized into a
1955           string using the native php xmlrpc functions (see <ulink
1956           url="http://www.php.net/xmlrpc">the php manual on
1957           xmlrpc</ulink>).</para>
1958
1959           <para>The <parameter>timeout</parameter> is optional, and will be
1960           set to <literal>0</literal> (wait for platform-specific predefined
1961           timeout) if omitted. This timeout value is passed to
1962           <function>fsockopen()</function>. It is also used for detecting
1963           server timeouts during communication (i.e. if the server does not
1964           send anything to the client for <parameter>timeout</parameter>
1965           seconds, the connection will be closed).</para>
1966
1967           <para>The <parameter>transport</parameter> parameter is optional,
1968           and if omitted will default to the transport set using instance
1969           creator or 'http' if omitted. The only other valid values are
1970           'https', which will use an SSL HTTP connection to connect to the
1971           remote server, and 'http11'. Note that your PHP must have the "curl"
1972           extension compiled in order to use both these features. Note that
1973           when using SSL you should normally set your port number to 443,
1974           unless the SSL server you are contacting runs at any other
1975           port.</para>
1976
1977           <warning>
1978             <para>PHP 4.0.6 has a bug which prevents SSL working.</para>
1979           </warning>
1980
1981           <para>In addition to low-level errors, the XML-RPC server you were
1982           querying may return an error in the
1983           <classname>xmlrpcresp</classname> object. See <xref
1984           linkend="xmlrpcresp" /> for details of how to handle these
1985           errors.</para>
1986         </sect3>
1987
1988         <sect3 id="multicall" xreflabel="xmlrpc_client-&gt;multicall">
1989           <title>multiCall</title>
1990
1991           <para>This method takes the form:</para>
1992
1993           <funcsynopsis>
1994             <funcprototype>
1995               <funcdef><type>array</type><function>multiCall</function></funcdef>
1996
1997               <paramdef><type>array</type><parameter>$messages</parameter></paramdef>
1998
1999               <paramdef><type>int</type><parameter>$timeout</parameter></paramdef>
2000
2001               <paramdef><type>string</type><parameter>$transport</parameter></paramdef>
2002
2003               <paramdef><type>bool</type><parameter>$fallback</parameter></paramdef>
2004             </funcprototype>
2005           </funcsynopsis>
2006
2007           <para>This method is used to boxcar many method calls in a single
2008           xml-rpc request. It will try first to make use of the
2009           <code>system.multicall</code> xml-rpc method call, and fall back to
2010           executing many separate requests if the server returns any
2011           error.</para>
2012
2013           <para><parameter>msgs</parameter> is an array of
2014           <classname>xmlrpcmsg</classname> objects (see <xref
2015           linkend="xmlrpcmsg" />), and <parameter>response</parameter> is an
2016           array of <classname>xmlrpcresp</classname> objects (see <xref
2017           linkend="xmlrpcresp" />).</para>
2018
2019           <para>The <parameter>timeout</parameter> and
2020           <parameter>transport</parameter> parameters are optional, and behave
2021           as in the <methodname>send</methodname> method above.</para>
2022
2023           <para>The <parameter>fallback</parameter> parameter is optional, and
2024           defaults to <constant>TRUE</constant>. When set to
2025           <constant>FALSE</constant> it will prevent the client to try using
2026           many single method calls in case of failure of the first multicall
2027           request. It should be set only when the server is known to support
2028           the multicall extension.</para>
2029         </sect3>
2030
2031         <sect3>
2032           <title>setAcceptedCompression</title>
2033
2034           <funcsynopsis>
2035             <funcprototype>
2036               <funcdef><type>void</type><function>setAcceptedCompression</function></funcdef>
2037
2038               <paramdef><type>string</type><parameter>$compressionmethod</parameter></paramdef>
2039             </funcprototype>
2040           </funcsynopsis>
2041
2042           <para>This method defines whether the client will accept compressed
2043           xml payload forming the bodies of the xmlrpc responses received from
2044           servers. Note that enabling reception of compressed responses merely
2045           adds some standard http headers to xmlrpc requests. It is up to the
2046           xmlrpc server to return compressed responses when receiving such
2047           requests. Allowed values for
2048           <parameter>compressionmethod</parameter> are: 'gzip', 'deflate',
2049           'any' or null (with any meaning either gzip or deflate).</para>
2050
2051           <para>This requires the "zlib" extension to be enabled in your php
2052           install. If it is, by default <classname>xmlrpc_client</classname>
2053           instances will enable reception of compressed content.</para>
2054         </sect3>
2055
2056         <sect3>
2057           <title>setCaCertificate</title>
2058
2059           <funcsynopsis>
2060             <funcprototype>
2061               <funcdef><type>void</type><function>setCaCertificate</function></funcdef>
2062
2063               <paramdef><type>string</type><parameter>$certificate</parameter></paramdef>
2064
2065               <paramdef><type>bool</type><parameter>$is_dir</parameter></paramdef>
2066             </funcprototype>
2067           </funcsynopsis>
2068
2069           <para>This method sets an optional certificate to be used in
2070           SSL-enabled communication to validate a remote server with (when the
2071           <parameter>server_method</parameter> is set to 'https' in the
2072           client's construction or in the send method and
2073           <methodname>SetSSLVerifypeer</methodname> has been set to
2074           <constant>TRUE</constant>).</para>
2075
2076           <para>The <parameter>certificate</parameter> parameter must be the
2077           filename of a PEM formatted certificate, or a directory containing
2078           multiple certificate files. The <parameter>is_dir</parameter>
2079           parameter defaults to <constant>FALSE</constant>, set it to
2080           <constant>TRUE</constant> to specify that
2081           <parameter>certificate</parameter> indicates a directory instead of
2082           a single file.</para>
2083
2084           <para>This requires the "curl" extension to be compiled into your
2085           installation of PHP. For more details see the man page for the
2086           <function>curl_setopt</function> function.</para>
2087         </sect3>
2088
2089         <sect3>
2090           <title>setCertificate</title>
2091
2092           <funcsynopsis>
2093             <funcprototype>
2094               <funcdef><type>void</type><function>setCertificate</function></funcdef>
2095
2096               <paramdef><type>string</type><parameter>$certificate</parameter></paramdef>
2097
2098               <paramdef><type>string</type><parameter>$passphrase</parameter></paramdef>
2099             </funcprototype>
2100           </funcsynopsis>
2101
2102           <para>This method sets the optional certificate and passphrase used
2103           in SSL-enabled communication with a remote server (when the
2104           <parameter>server_method</parameter> is set to 'https' in the
2105           client's construction or in the send method).</para>
2106
2107           <para>The <parameter>certificate</parameter> parameter must be the
2108           filename of a PEM formatted certificate. The
2109           <parameter>passphrase</parameter> parameter must contain the
2110           password required to use the certificate.</para>
2111
2112           <para>This requires the "curl" extension to be compiled into your
2113           installation of PHP. For more details see the man page for the
2114           <function>curl_setopt</function> function.</para>
2115
2116           <para>Note: to retrieve information about the client certificate on
2117           the server side, you will need to look into the environment
2118           variables which are set up by the webserver. Different webservers
2119           will typically set up different variables.</para>
2120         </sect3>
2121
2122         <sect3>
2123           <title>setCookie</title>
2124
2125           <funcsynopsis>
2126             <funcprototype>
2127               <funcdef><type>void</type><function>setCookie</function></funcdef>
2128
2129               <paramdef><type>string</type><parameter>$name</parameter></paramdef>
2130
2131               <paramdef><type>string</type><parameter>$value</parameter></paramdef>
2132
2133               <paramdef><type>string</type><parameter>$path</parameter></paramdef>
2134
2135               <paramdef><type>string</type><parameter>$domain</parameter></paramdef>
2136
2137               <paramdef><type>int</type><parameter>$port</parameter></paramdef>
2138             </funcprototype>
2139           </funcsynopsis>
2140
2141           <para>This method sets a cookie that will be sent to the xmlrpc
2142           server along with every further request (useful e.g. for keeping
2143           session info outside of the xml-rpc payload).</para>
2144
2145           <para><parameter>$value</parameter> is optional, and defaults to
2146           null.</para>
2147
2148           <para><parameter>$path, $domain and $port</parameter> are optional,
2149           and will be omitted from the cookie header if unspecified. Note that
2150           setting any of these values will turn the cookie into a 'version 1'
2151           cookie, that might not be fully supported by the server (see RFC2965
2152           for more details).</para>
2153         </sect3>
2154
2155         <sect3>
2156           <title>setCredentials</title>
2157
2158           <funcsynopsis>
2159             <funcprototype>
2160               <funcdef><type>void</type><function>setCredentials</function></funcdef>
2161
2162               <paramdef><type>string</type><parameter>$username</parameter></paramdef>
2163
2164               <paramdef><type>string</type><parameter>$password</parameter></paramdef>
2165
2166               <paramdef><type>int</type><parameter>$authtype</parameter></paramdef>
2167             </funcprototype>
2168           </funcsynopsis>
2169
2170           <para>This method sets the username and password for authorizing the
2171           client to a server. With the default (HTTP) transport, this
2172           information is used for HTTP Basic authorization. Note that username
2173           and password can also be set using the class constructor. With HTTP
2174           1.1 and HTTPS transport, NTLM and Digest authentication protocols
2175           are also supported. To enable them use the constants
2176           <constant>CURLAUTH_DIGEST</constant> and
2177           <constant>CURLAUTH_NTLM</constant> as values for the authtype
2178           parameter.</para>
2179         </sect3>
2180
2181         <sect3>
2182           <title>setCurlOptions</title>
2183
2184           <para><funcsynopsis>
2185               <funcprototype>
2186                 <funcdef><type>void</type><function>setCurlOptions</function></funcdef>
2187
2188                 <paramdef><type>array</type><parameter>$options</parameter></paramdef>
2189               </funcprototype>
2190             </funcsynopsis>This method allows to directly set any desired
2191           option to manipulate the usage of the cURL client (when in cURL
2192           mode). It can be used eg. to explicitly bind to an outgoing ip
2193           address when the server is multihomed</para>
2194         </sect3>
2195
2196         <sect3>
2197           <title>setDebug</title>
2198
2199           <funcsynopsis>
2200             <funcprototype>
2201               <funcdef><type>void</type><function>setDebug</function></funcdef>
2202
2203               <paramdef><type>int</type><parameter>$debugLvl</parameter></paramdef>
2204             </funcprototype>
2205           </funcsynopsis>
2206
2207           <para><parameter>debugLvl</parameter> is either <literal>0,
2208           1</literal> or 2 depending on whether you require the client to
2209           print debugging information to the browser. The default is not to
2210           output this information (0).</para>
2211
2212           <para>The debugging information at level 1includes the raw data
2213           returned from the XML-RPC server it was querying (including bot HTTP
2214           headers and the full XML payload), and the PHP value the client
2215           attempts to create to represent the value returned by the server. At
2216           level2, the complete payload of the xmlrpc request is also printed,
2217           before being sent t the server.</para>
2218
2219           <para>This option can be very useful when debugging servers as it
2220           allows you to see exactly what the client sends and the server
2221           returns.</para>
2222         </sect3>
2223
2224         <sect3>
2225           <title>setKey</title>
2226
2227           <funcsynopsis>
2228             <funcprototype>
2229               <funcdef><type>void</type><function>setKey</function></funcdef>
2230
2231               <paramdef><type>int</type><parameter>$key</parameter></paramdef>
2232
2233               <paramdef><type>int</type><parameter>$keypass</parameter></paramdef>
2234             </funcprototype>
2235           </funcsynopsis>
2236
2237           <para>This method sets the optional certificate key and passphrase
2238           used in SSL-enabled communication with a remote server (when the
2239           <parameter>transport</parameter> is set to 'https' in the client's
2240           construction or in the send method).</para>
2241
2242           <para>This requires the "curl" extension to be compiled into your
2243           installation of PHP. For more details see the man page for the
2244           <function>curl_setopt</function> function.</para>
2245         </sect3>
2246
2247         <sect3>
2248           <title>setProxy</title>
2249
2250           <funcsynopsis>
2251             <funcprototype>
2252               <funcdef><type>void</type><function>setProxy</function></funcdef>
2253
2254               <paramdef><type>string</type><parameter>$proxyhost</parameter></paramdef>
2255
2256               <paramdef><type>int</type><parameter>$proxyport</parameter></paramdef>
2257
2258               <paramdef><type>string</type><parameter>$proxyusername</parameter></paramdef>
2259
2260               <paramdef><type>string</type><parameter>$proxypassword</parameter></paramdef>
2261
2262               <paramdef><type>int</type><parameter>$authtype</parameter></paramdef>
2263             </funcprototype>
2264           </funcsynopsis>
2265
2266           <para>This method enables calling servers via an HTTP proxy. The
2267           <parameter>proxyusername</parameter>,<parameter>
2268           proxypassword</parameter> and <parameter>authtype</parameter>
2269           parameters are optional. <parameter>Authtype</parameter> defaults to
2270           <constant>CURLAUTH_BASIC</constant> (Basic authentication protocol);
2271           the only other valid value is the constant
2272           <constant>CURLAUTH_NTLM</constant>, and has effect only when the
2273           client uses the HTTP 1.1 protocol.</para>
2274
2275           <para>NB: CURL versions before 7.11.10 cannot use a proxy to
2276           communicate with https servers.</para>
2277         </sect3>
2278
2279         <sect3>
2280           <title>setRequestCompression</title>
2281
2282           <funcsynopsis>
2283             <funcprototype>
2284               <funcdef><type>void</type><function>setRequestCompression</function></funcdef>
2285
2286               <paramdef><type>string</type><parameter>$compressionmethod</parameter></paramdef>
2287             </funcprototype>
2288           </funcsynopsis>
2289
2290           <para>This method defines whether the xml payload forming the
2291           request body will be sent to the server in compressed format, as per
2292           the HTTP specification. This is particularly useful for large
2293           request parameters and over slow network connections. Allowed values
2294           for <parameter>compressionmethod</parameter> are: 'gzip', 'deflate',
2295           'any' or null (with any meaning either gzip or deflate). Note that
2296           there is no automatic fallback mechanism in place for errors due to
2297           servers not supporting receiving compressed request bodies, so make
2298           sure that the particular server you are querying does accept
2299           compressed requests before turning it on.</para>
2300
2301           <para>This requires the "zlib" extension to be enabled in your php
2302           install.</para>
2303         </sect3>
2304
2305         <sect3>
2306           <title>setSSLVerifyHost</title>
2307
2308           <funcsynopsis>
2309             <funcprototype>
2310               <funcdef><type>void</type><function>setSSLVerifyHost</function></funcdef>
2311
2312               <paramdef><type>int</type><parameter>$i</parameter></paramdef>
2313             </funcprototype>
2314           </funcsynopsis>
2315
2316           <para>This method defines whether connections made to XML-RPC
2317           backends via HTTPS should verify the remote host's SSL certificate's
2318           common name (CN). By default, only the existence of a CN is checked.
2319           <parameter><parameter>$i</parameter></parameter> should be an
2320           integer value; 0 to not check the CN at all, 1 to merely check for
2321           its existence, and 2 to check that the CN on the certificate matches
2322           the hostname that is being connected to.</para>
2323         </sect3>
2324
2325         <sect3>
2326           <title>setSSLVerifyPeer</title>
2327
2328           <funcsynopsis>
2329             <funcprototype>
2330               <funcdef><type>void</type><function>setSSLVerifyPeer</function></funcdef>
2331
2332               <paramdef><type>bool</type><parameter>$i</parameter></paramdef>
2333             </funcprototype>
2334           </funcsynopsis>
2335
2336           <para>This method defines whether connections made to XML-RPC
2337           backends via HTTPS should verify the remote host's SSL certificate,
2338           and cause the connection to fail if the cert verification fails.
2339           <parameter><parameter>$i</parameter></parameter> should be a boolean
2340           value. Default value: <constant>TRUE</constant>. To specify custom
2341           SSL certificates to validate the server with, use the
2342           <methodname>setCaCertificate</methodname> method.</para>
2343         </sect3>
2344
2345         <sect3>
2346           <title>setUserAgent</title>
2347
2348           <para><funcsynopsis>
2349               <funcprototype>
2350                 <funcdef><type>void</type><function>Useragent</function></funcdef>
2351
2352                 <paramdef><type>string</type><parameter>$useragent</parameter></paramdef>
2353               </funcprototype>
2354             </funcsynopsis>This method sets a custom user-agent that will be
2355           used by the client in the http headers sent with the request. The
2356           default value is built using the library name and version
2357           constants.</para>
2358         </sect3>
2359       </sect2>
2360
2361       <sect2>
2362         <title>Variables</title>
2363
2364         <para>NB: direct manipulation of these variables is only recommended
2365         for advanced users.</para>
2366
2367         <sect3>
2368           <title>no_multicall</title>
2369
2370           <para>This member variable determines whether the multicall() method
2371           will try to take advantage of the system.multicall xmlrpc method to
2372           dispatch to the server an array of requests in a single http
2373           roundtrip or simply execute many consecutive http calls. Defaults to
2374           FALSE, but it will be enabled automatically on the first failure of
2375           execution of system.multicall.</para>
2376         </sect3>
2377
2378         <sect3>
2379           <title>request_charset_encoding</title>
2380
2381           <para>This is the charset encoding that will be used for serializing
2382           request sent by the client.</para>
2383
2384           <para>If defaults to NULL, which means using US-ASCII and encoding
2385           all characters outside of the ASCII range using their xml character
2386           entity representation (this has the benefit that line end characters
2387           will not be mangled in the transfer, a CR-LF will be preserved as
2388           well as a singe LF).</para>
2389
2390           <para>Valid values are 'US-ASCII', 'UTF-8' and 'ISO-8859-1'</para>
2391         </sect3>
2392
2393         <sect3 id="return-type" xreflabel="return_type">
2394           <title>return_type</title>
2395
2396           <para>This member variable determines whether the value returned
2397           inside an xmlrpcresp object as results of calls to the send() and
2398           multicall() methods will be an xmlrpcval object, a plain php value
2399           or a raw xml string. Allowed values are 'xmlrpcvals' (the default),
2400           'phpvals' and 'xml'. To allow the user to differentiate between a
2401           correct and a faulty response, fault responses will be returned as
2402           xmlrpcresp objects in any case. Note that the 'phpvals' setting will
2403           yield faster execution times, but some of the information from the
2404           original response will be lost. It will be e.g. impossible to tell
2405           whether a particular php string value was sent by the server as an
2406           xmlrpc string or base64 value.</para>
2407
2408           <para>Example usage:</para>
2409
2410           <programlisting language="php">
2411 $client = new xmlrpc_client("phpxmlrpc.sourceforge.net/server.php");
2412 $client-&gt;return_type = 'phpvals';
2413 $message = new xmlrpcmsg("examples.getStateName", array(new xmlrpcval(23, "int")));
2414 $resp = $client-&gt;send($message);
2415 if ($resp-&gt;faultCode()) echo 'KO. Error: '.$resp-&gt;faultString(); else echo 'OK: got '.$resp-&gt;value();
2416 </programlisting>
2417
2418           <para>For more details about usage of the 'xml' value, see Appendix
2419           A.</para>
2420         </sect3>
2421       </sect2>
2422     </sect1>
2423
2424     <sect1 id="xmlrpcresp" xreflabel="xmlrpcresp">
2425       <title>xmlrpcresp</title>
2426
2427       <para>This class is used to contain responses to XML-RPC requests. A
2428       server method handler will construct an
2429       <classname>xmlrpcresp</classname> and pass it as a return value. This
2430       same value will be returned by the result of an invocation of the
2431       <function>send</function> method of the
2432       <classname>xmlrpc_client</classname> class.</para>
2433
2434       <sect2>
2435         <title>Creation</title>
2436
2437         <funcsynopsis>
2438           <funcprototype>
2439             <funcdef><type>xmlrpcresp</type>new
2440             <function>xmlrpcresp</function></funcdef>
2441
2442             <paramdef><type>xmlrpcval</type><parameter>$xmlrpcval</parameter></paramdef>
2443           </funcprototype>
2444
2445           <funcprototype>
2446             <funcdef><type>xmlrpcresp</type>new
2447             <function>xmlrpcresp</function></funcdef>
2448
2449             <paramdef><parameter>0</parameter></paramdef>
2450
2451             <paramdef><type>int</type><parameter>$errcode</parameter></paramdef>
2452
2453             <paramdef><type>string</type><parameter>$err_string</parameter></paramdef>
2454           </funcprototype>
2455         </funcsynopsis>
2456
2457         <para>The first syntax is used when execution has happened without
2458         difficulty: <parameter>$xmlrpcval</parameter> is an
2459         <classname>xmlrpcval</classname> value with the result of the method
2460         execution contained in it. Alternatively it can be a string containing
2461         the xml serialization of the single xml-rpc value result of method
2462         execution.</para>
2463
2464         <para>The second type of constructor is used in case of failure.
2465         <parameter>errcode</parameter> and <parameter>err_string</parameter>
2466         are used to provide indication of what has gone wrong. See <xref
2467         linkend="xmlrpc-server" /> for more information on passing error
2468         codes.</para>
2469       </sect2>
2470
2471       <sect2>
2472         <title>Methods</title>
2473
2474         <sect3>
2475           <title>faultCode</title>
2476
2477           <funcsynopsis>
2478             <funcprototype>
2479               <funcdef><type>int</type><function>faultCode</function></funcdef>
2480
2481               <void />
2482             </funcprototype>
2483           </funcsynopsis>
2484
2485           <para>Returns the integer fault code return from the XML-RPC
2486           response. A zero value indicates success, any other value indicates
2487           a failure response.</para>
2488         </sect3>
2489
2490         <sect3>
2491           <title>faultString</title>
2492
2493           <funcsynopsis>
2494             <funcprototype>
2495               <funcdef><type>string</type><function>faultString</function></funcdef>
2496
2497               <void />
2498             </funcprototype>
2499           </funcsynopsis>
2500
2501           <para>Returns the human readable explanation of the fault indicated
2502           by <function>$resp-&gt;faultCode</function>().</para>
2503         </sect3>
2504
2505         <sect3>
2506           <title>value</title>
2507
2508           <funcsynopsis>
2509             <funcprototype>
2510               <funcdef><type>xmlrpcval</type><function>value</function></funcdef>
2511
2512               <void />
2513             </funcprototype>
2514           </funcsynopsis>
2515
2516           <para>Returns an <classname>xmlrpcval</classname> object containing
2517           the return value sent by the server. If the response's
2518           <function>faultCode</function> is non-zero then the value returned
2519           by this method should not be used (it may not even be an
2520           object).</para>
2521
2522           <para>Note: if the xmlrpcresp instance in question has been created
2523           by an <classname>xmlrpc_client</classname> object whose
2524           <varname>return_type</varname> was set to 'phpvals', then a plain
2525           php value will be returned instead of an
2526           <classname>xmlrpcval</classname> object. If the
2527           <varname>return_type</varname> was set to 'xml', an xml string will
2528           be returned (see the return_type member var above for more
2529           details).</para>
2530         </sect3>
2531
2532         <sect3>
2533           <title>serialize</title>
2534
2535           <funcsynopsis>
2536             <funcprototype>
2537               <funcdef><type>string</type><function>serialize</function></funcdef>
2538
2539               <void />
2540             </funcprototype>
2541           </funcsynopsis>
2542
2543           <para>Returns an XML string representation of the response (xml
2544           prologue not included).</para>
2545         </sect3>
2546       </sect2>
2547     </sect1>
2548
2549     <sect1 id="xmlrpc-server" xreflabel="xmlrpc_server">
2550       <title>xmlrpc_server</title>
2551
2552       <para>The implementation of this class has been kept as simple to use as
2553       possible. The constructor for the server basically does all the work.
2554       Here's a minimal example:</para>
2555
2556       <programlisting language="php">
2557   function foo ($xmlrpcmsg) {
2558     ...
2559     return new xmlrpcresp($some_xmlrpc_val);
2560   }
2561
2562   class bar {
2563     function foobar($xmlrpcmsg) {
2564       ...
2565       return new xmlrpcresp($some_xmlrpc_val);
2566     }
2567   }
2568
2569   $s = new xmlrpc_server(
2570     array(
2571       "examples.myFunc1" =&gt; array("function" =&gt; "foo"),
2572       "examples.myFunc2" =&gt; array("function" =&gt; "bar::foobar"),
2573     ));
2574 </programlisting>
2575
2576       <para>This performs everything you need to do with a server. The single
2577       constructor argument is an associative array from xmlrpc method names to
2578       php function names. The incoming request is parsed and dispatched to the
2579       relevant php function, which is responsible for returning a
2580       <classname>xmlrpcresp</classname> object, that will be serialized back
2581       to the caller.</para>
2582
2583       <sect2>
2584         <title>Method handler functions</title>
2585
2586         <para>Both php functions and class methods can be registered as xmlrpc
2587         method handlers.</para>
2588
2589         <para>The synopsis of a method handler function is:</para>
2590
2591         <para><synopsis>xmlrpcresp $resp = function (xmlrpcmsg $msg)</synopsis></para>
2592
2593         <para>No text should be echoed 'to screen' by the handler function, or
2594         it will break the xml response sent back to the client. This applies
2595         also to error and warning messages that PHP prints to screen unless
2596         the appropriate parameters have been set in the php.in file. Another
2597         way to prevent echoing of errors inside the response and facilitate
2598         debugging is to use the server SetDebug method with debug level 3 (see
2599         ...). Exceptions thrown duting execution of handler functions are
2600         caught by default and a XML-RPC error reponse is generated instead.
2601         This behaviour can be finetuned by usage of the
2602         <varname>exception_handling</varname> member variable (see
2603         ...).</para>
2604
2605         <para>Note that if you implement a method with a name prefixed by
2606         <code>system.</code> the handler function will be invoked by the
2607         server with two parameters, the first being the server itself and the
2608         second being the <classname>xmlrpcmsg</classname> object.</para>
2609
2610         <para>The same php function can be registered as handler of multiple
2611         xmlrpc methods.</para>
2612
2613         <para>Here is a more detailed example of what the handler function
2614         <function>foo</function> may do:</para>
2615
2616         <programlisting language="php">
2617   function foo ($xmlrpcmsg) {
2618     global $xmlrpcerruser; // import user errcode base value
2619
2620     $meth = $xmlrpcmsg-&gt;method(); // retrieve method name
2621     $par = $xmlrpcmsg-&gt;getParam(0); // retrieve value of first parameter - assumes at least one param received
2622     $val = $par-&gt;scalarval(); // decode value of first parameter - assumes it is a scalar value
2623
2624     ...
2625
2626     if ($err) {
2627       // this is an error condition
2628       return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
2629         "There's a problem, Captain");
2630     } else {
2631       // this is a successful value being returned
2632       return new xmlrpcresp(new xmlrpcval("All's fine!", "string"));
2633     }
2634   }
2635 </programlisting>
2636
2637         <para>See <filename>server.php</filename> in this distribution for
2638         more examples of how to do this.</para>
2639
2640         <para>Since release 2.0RC3 there is a new, even simpler way of
2641         registering php functions with the server. See section 5.7
2642         below</para>
2643       </sect2>
2644
2645       <sect2>
2646         <title>The dispatch map</title>
2647
2648         <para>The first argument to the <function>xmlrpc_server</function>
2649         constructor is an array, called the <emphasis>dispatch map</emphasis>.
2650         In this array is the information the server needs to service the
2651         XML-RPC methods you define.</para>
2652
2653         <para>The dispatch map takes the form of an associative array of
2654         associative arrays: the outer array has one entry for each method, the
2655         key being the method name. The corresponding value is another
2656         associative array, which can have the following members:</para>
2657
2658         <itemizedlist>
2659           <listitem>
2660             <para><function><literal>function</literal></function> - this
2661             entry is mandatory. It must be either a name of a function in the
2662             global scope which services the XML-RPC method, or an array
2663             containing an instance of an object and a static method name (for
2664             static class methods the 'class::method' syntax is also
2665             supported).</para>
2666           </listitem>
2667
2668           <listitem>
2669             <para><function><literal>signature</literal></function> - this
2670             entry is an array containing the possible signatures (see <xref
2671             linkend="signatures" />) for the method. If this entry is present
2672             then the server will check that the correct number and type of
2673             parameters have been sent for this method before dispatching
2674             it.</para>
2675           </listitem>
2676
2677           <listitem>
2678             <para><function><literal>docstring</literal></function> - this
2679             entry is a string containing documentation for the method. The
2680             documentation may contain HTML markup.</para>
2681           </listitem>
2682
2683           <listitem>
2684             <para><literal>signature_docs</literal> - this entry can be used
2685             to provide documentation for the single parameters. It must match
2686             in structure the 'signature' member. By default, only the
2687             <classname>documenting_xmlrpc_server</classname> class in the
2688             extras package will take advantage of this, since the
2689             "system.methodHelp" protocol does not support documenting method
2690             parameters individually.</para>
2691           </listitem>
2692
2693           <listitem>
2694             <para><literal>parameters_type</literal> - this entry can be used
2695             when the server is working in 'xmlrpcvals' mode (see ...) to
2696             define one or more entries in the dispatch map as being functions
2697             that follow the 'phpvals' calling convention. The only useful
2698             value is currently the string <literal>phpvals</literal>.</para>
2699           </listitem>
2700         </itemizedlist>
2701
2702         <para>Look at the <filename>server.php</filename> example in the
2703         distribution to see what a dispatch map looks like.</para>
2704       </sect2>
2705
2706       <sect2 id="signatures" xreflabel="Signatures">
2707         <title>Method signatures</title>
2708
2709         <para>A signature is a description of a method's return type and its
2710         parameter types. A method may have more than one signature.</para>
2711
2712         <para>Within a server's dispatch map, each method has an array of
2713         possible signatures. Each signature is an array of types. The first
2714         entry is the return type. For instance, the method <programlisting
2715         language="php">string examples.getStateName(int)
2716 </programlisting> has the signature <programlisting language="php">array($xmlrpcString, $xmlrpcInt)
2717 </programlisting> and, assuming that it is the only possible signature for the
2718         method, it might be used like this in server creation: <programlisting
2719         language="php">
2720 $findstate_sig = array(array($xmlrpcString, $xmlrpcInt));
2721
2722 $findstate_doc = 'When passed an integer between 1 and 51 returns the
2723 name of a US state, where the integer is the index of that state name
2724 in an alphabetic order.';
2725
2726 $s = new xmlrpc_server( array(
2727   "examples.getStateName" =&gt; array(
2728     "function" =&gt; "findstate",
2729     "signature" =&gt; $findstate_sig,
2730     "docstring" =&gt; $findstate_doc
2731   )));
2732 </programlisting></para>
2733
2734         <para>Note that method signatures do not allow to check nested
2735         parameters, e.g. the number, names and types of the members of a
2736         struct param cannot be validated.</para>
2737
2738         <para>If a method that you want to expose has a definite number of
2739         parameters, but each of those parameters could reasonably be of
2740         multiple types, the array of acceptable signatures will easily grow
2741         into a combinatorial explosion. To avoid such a situation, the lib
2742         defines the global var <varname>$xmlrpcValue</varname>, which can be
2743         used in method signatures as a placeholder for 'any xmlrpc
2744         type':</para>
2745
2746         <para><programlisting language="php">
2747 $echoback_sig = array(array($xmlrpcValue, $xmlrpcValue));
2748
2749 $findstate_doc = 'Echoes back to the client the received value, regardless of its type';
2750
2751 $s = new xmlrpc_server( array(
2752   "echoBack" =&gt; array(
2753     "function" =&gt; "echoback",
2754     "signature" =&gt; $echoback_sig, // this sig guarantees that the method handler will be called with one and only one parameter
2755     "docstring" =&gt; $echoback_doc
2756   )));
2757 </programlisting></para>
2758
2759         <para>Methods <methodname>system.listMethods</methodname>,
2760         <methodname>system.methodHelp</methodname>,
2761         <methodname>system.methodSignature</methodname> and
2762         <methodname>system.multicall</methodname> are already defined by the
2763         server, and should not be reimplemented (see Reserved Methods
2764         below).</para>
2765       </sect2>
2766
2767       <sect2>
2768         <title>Delaying the server response</title>
2769
2770         <para>You may want to construct the server, but for some reason not
2771         fulfill the request immediately (security verification, for instance).
2772         If you omit to pass to the constructor the dispatch map or pass it a
2773         second argument of <literal>0</literal> this will have the desired
2774         effect. You can then use the <function>service()</function> method of
2775         the server class to service the request. For example:</para>
2776
2777         <programlisting language="php">
2778 $s = new xmlrpc_server($myDispMap, 0); // second parameter = 0 prevents automatic servicing of request
2779
2780 // ... some code that does other stuff here
2781
2782 $s-&gt;service();
2783 </programlisting>
2784
2785         <para>Note that the <methodname>service</methodname> method will print
2786         the complete result payload to screen and send appropriate HTTP
2787         headers back to the client, but also return the response object. This
2788         permits further manipulation of the response, possibly in combination
2789         with output buffering.</para>
2790
2791         <para>To prevent the server from sending HTTP headers back to the
2792         client, you can pass a second parameter with a value of
2793         <literal>TRUE</literal> to the <methodname>service</methodname>
2794         method. In this case, the response payload will be returned instead of
2795         the response object.</para>
2796
2797         <para>Xmlrpc requests retrieved by other means than HTTP POST bodies
2798         can also be processed. For example:</para>
2799
2800         <programlisting language="php">
2801 $s = new xmlrpc_server(); // not passing a dispatch map prevents automatic servicing of request
2802
2803 // ... some code that does other stuff here, including setting dispatch map into server object
2804
2805 $resp = $s-&gt;service($xmlrpc_request_body, true); // parse a variable instead of POST body, retrieve response payload
2806
2807 // ... some code that does other stuff with xml response $resp here
2808 </programlisting>
2809       </sect2>
2810
2811       <sect2>
2812         <title>Modifying the server behaviour</title>
2813
2814         <para>A couple of methods / class variables are available to modify
2815         the behaviour of the server. The only way to take advantage of their
2816         existence is by usage of a delayed server response (see above)</para>
2817
2818         <sect3>
2819           <title>setDebug()</title>
2820
2821           <para>This function controls weather the server is going to echo
2822           debugging messages back to the client as comments in response body.
2823           Valid values: 0,1,2,3, with 1 being the default. At level 0, no
2824           debug info is returned to the client. At level 2, the complete
2825           client request is added to the response, as part of the xml
2826           comments. At level 3, a new PHP error handler is set when executing
2827           user functions exposed as server methods, and all non-fatal errors
2828           are trapped and added as comments into the response.</para>
2829         </sect3>
2830
2831         <sect3>
2832           <title>allow_system_funcs</title>
2833
2834           <para>Default_value: TRUE. When set to FALSE, disables support for
2835           <methodname>System.xxx</methodname> functions in the server. It
2836           might be useful e.g. if you do not wish the server to respond to
2837           requests to <methodname>System.ListMethods</methodname>.</para>
2838         </sect3>
2839
2840         <sect3>
2841           <title>compress_response</title>
2842
2843           <para>When set to TRUE, enables the server to take advantage of HTTP
2844           compression, otherwise disables it. Responses will be transparently
2845           compressed, but only when an xmlrpc-client declares its support for
2846           compression in the HTTP headers of the request.</para>
2847
2848           <para>Note that the ZLIB php extension must be installed for this to
2849           work. If it is, <varname>compress_response</varname> will default to
2850           TRUE.</para>
2851         </sect3>
2852
2853         <sect3>
2854           <title>exception_handling</title>
2855
2856           <para>This variable controls the behaviour of the server when an
2857           exception is thrown by a method handler php function. Valid values:
2858           0,1,2, with 0 being the default. At level 0, the server catches the
2859           exception and return an 'internal error' xmlrpc response; at 1 it
2860           catches the exceptions and return an xmlrpc response with the error
2861           code and error message corresponding to the exception that was
2862           thron; at 2 = the exception is floated to the upper layers in the
2863           code</para>
2864         </sect3>
2865
2866         <sect3>
2867           <title>response_charset_encoding</title>
2868
2869           <para>Charset encoding to be used for response (only affects string
2870           values).</para>
2871
2872           <para>If it can, the server will convert the generated response from
2873           internal_encoding to the intended one.</para>
2874
2875           <para>Valid values are: a supported xml encoding (only UTF-8 and
2876           ISO-8859-1 at present, unless mbstring is enabled), null (leave
2877           charset unspecified in response and convert output stream to
2878           US_ASCII), 'default' (use xmlrpc library default as specified in
2879           xmlrpc.inc, convert output stream if needed), or 'auto' (use
2880           client-specified charset encoding or same as request if request
2881           headers do not specify it (unless request is US-ASCII: then use
2882           library default anyway).</para>
2883         </sect3>
2884       </sect2>
2885
2886       <sect2>
2887         <title>Fault reporting</title>
2888
2889         <para>Fault codes for your servers should start at the value indicated
2890         by the global <literal>$xmlrpcerruser</literal> + 1.</para>
2891
2892         <para>Standard errors returned by the server include:</para>
2893
2894         <variablelist>
2895           <varlistentry>
2896             <term><literal>1</literal> <phrase>Unknown method</phrase></term>
2897
2898             <listitem>
2899               <para>Returned if the server was asked to dispatch a method it
2900               didn't know about</para>
2901             </listitem>
2902           </varlistentry>
2903
2904           <varlistentry>
2905             <term><literal>2</literal> <phrase>Invalid return
2906             payload</phrase></term>
2907
2908             <listitem>
2909               <para>This error is actually generated by the client, not
2910               server, code, but signifies that a server returned something it
2911               couldn't understand. A more detailed error report is sometimes
2912               added onto the end of the phrase above.</para>
2913             </listitem>
2914           </varlistentry>
2915
2916           <varlistentry>
2917             <term><literal>3</literal> <phrase>Incorrect
2918             parameters</phrase></term>
2919
2920             <listitem>
2921               <para>This error is generated when the server has signature(s)
2922               defined for a method, and the parameters passed by the client do
2923               not match any of signatures.</para>
2924             </listitem>
2925           </varlistentry>
2926
2927           <varlistentry>
2928             <term><literal>4</literal> <phrase>Can't introspect: method
2929             unknown</phrase></term>
2930
2931             <listitem>
2932               <para>This error is generated by the builtin
2933               <function>system.*</function> methods when any kind of
2934               introspection is attempted on a method undefined by the
2935               server.</para>
2936             </listitem>
2937           </varlistentry>
2938
2939           <varlistentry>
2940             <term><literal>5</literal> <phrase>Didn't receive 200 OK from
2941             remote server</phrase></term>
2942
2943             <listitem>
2944               <para>This error is generated by the client when a remote server
2945               doesn't return HTTP/1.1 200 OK in response to a request. A more
2946               detailed error report is added onto the end of the phrase
2947               above.</para>
2948             </listitem>
2949           </varlistentry>
2950
2951           <varlistentry>
2952             <term><literal>6</literal> <phrase>No data received from
2953             server</phrase></term>
2954
2955             <listitem>
2956               <para>This error is generated by the client when a remote server
2957               returns HTTP/1.1 200 OK in response to a request, but no
2958               response body follows the HTTP headers.</para>
2959             </listitem>
2960           </varlistentry>
2961
2962           <varlistentry>
2963             <term><literal>7</literal> <phrase>No SSL support compiled
2964             in</phrase></term>
2965
2966             <listitem>
2967               <para>This error is generated by the client when trying to send
2968               a request with HTTPS and the CURL extension is not available to
2969               PHP.</para>
2970             </listitem>
2971           </varlistentry>
2972
2973           <varlistentry>
2974             <term><literal>8</literal> <phrase>CURL error</phrase></term>
2975
2976             <listitem>
2977               <para>This error is generated by the client when trying to send
2978               a request with HTTPS and the HTTPS communication fails.</para>
2979             </listitem>
2980           </varlistentry>
2981
2982           <varlistentry>
2983             <term><literal>9-14</literal> <phrase>multicall
2984             errors</phrase></term>
2985
2986             <listitem>
2987               <para>These errors are generated by the server when something
2988               fails inside a system.multicall request.</para>
2989             </listitem>
2990           </varlistentry>
2991
2992           <varlistentry>
2993             <term><literal>100-</literal> <phrase>XML parse
2994             errors</phrase></term>
2995
2996             <listitem>
2997               <para>Returns 100 plus the XML parser error code for the fault
2998               that occurred. The <function>faultString</function> returned
2999               explains where the parse error was in the incoming XML
3000               stream.</para>
3001             </listitem>
3002           </varlistentry>
3003         </variablelist>
3004       </sect2>
3005
3006       <sect2>
3007         <title>'New style' servers</title>
3008
3009         <para>In the same spirit of simplification that inspired the
3010         <varname>xmlrpc_client::return_type</varname> class variable, a new
3011         class variable has been added to the server class:
3012         <varname>functions_parameters_type</varname>. When set to 'phpvals',
3013         the functions registered in the server dispatch map will be called
3014         with plain php values as parameters, instead of a single xmlrpcmsg
3015         instance parameter. The return value of those functions is expected to
3016         be a plain php value, too. An example is worth a thousand
3017         words:<programlisting language="php">
3018   function foo($usr_id, $out_lang='en') {
3019     global $xmlrpcerruser;
3020
3021     ...
3022
3023     if ($someErrorCondition)
3024       return new xmlrpcresp(0, $xmlrpcerruser+1, 'DOH!');
3025     else
3026       return array(
3027         'name' =&gt; 'Joe',
3028         'age' =&gt; 27,
3029         'picture' =&gt; new xmlrpcval(file_get_contents($picOfTheGuy), 'base64')
3030       );
3031   }
3032
3033   $s = new xmlrpc_server(
3034     array(
3035       "examples.myFunc" =&gt; array(
3036         "function" =&gt; "bar::foobar",
3037         "signature" =&gt; array(
3038           array($xmlrpcString, $xmlrpcInt),
3039           array($xmlrpcString, $xmlrpcInt, $xmlrpcString)
3040         )
3041       )
3042     ), false);
3043   $s-&gt;functions_parameters_type = 'phpvals';
3044   $s-&gt;service();
3045 </programlisting>There are a few things to keep in mind when using this
3046         simplified syntax:</para>
3047
3048         <para>to return an xmlrpc error, the method handler function must
3049         return an instance of <classname>xmlrpcresp</classname>. The only
3050         other way for the server to know when an error response should be
3051         served to the client is to throw an exception and set the server's
3052         <varname>exception_handling</varname> memeber var to 1;</para>
3053
3054         <para>to return a base64 value, the method handler function must
3055         encode it on its own, creating an instance of an xmlrpcval
3056         object;</para>
3057
3058         <para>the method handler function cannot determine the name of the
3059         xmlrpc method it is serving, unlike standard handler functions that
3060         can retrieve it from the message object;</para>
3061
3062         <para>when receiving nested parameters, the method handler function
3063         has no way to distinguish a php string that was sent as base64 value
3064         from one that was sent as a string value;</para>
3065
3066         <para>this has a direct consequence on the support of
3067         system.multicall: a method whose signature contains datetime or base64
3068         values will not be available to multicall calls;</para>
3069
3070         <para>last but not least, the direct parsing of xml to php values is
3071         much faster than using xmlrpcvals, and allows the library to handle
3072         much bigger messages without allocating all available server memory or
3073         smashing PHP recursive call stack.</para>
3074       </sect2>
3075     </sect1>
3076   </chapter>
3077
3078   <chapter id="globalvars">
3079     <title>Global variables</title>
3080
3081     <para>Many global variables are defined in the xmlrpc.inc file. Some of
3082     those are meant to be used as constants (and modifying their value might
3083     cause unpredictable behaviour), while some others can be modified in your
3084     php scripts to alter the behaviour of the xml-rpc client and
3085     server.</para>
3086
3087     <sect1>
3088       <title>"Constant" variables</title>
3089
3090       <sect2>
3091         <title>$xmlrpcerruser</title>
3092
3093         <para><fieldsynopsis>
3094             <varname>$xmlrpcerruser</varname>
3095
3096             <initializer>800</initializer>
3097           </fieldsynopsis>The minimum value for errors reported by user
3098         implemented XML-RPC servers. Error numbers lower than that are
3099         reserved for library usage.</para>
3100       </sect2>
3101
3102       <sect2>
3103         <title>$xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble,
3104         $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray,
3105         $xmlrpcStruct, $xmlrpcValue, $xmlrpcNull</title>
3106
3107         <para>For convenience the strings representing the XML-RPC types have
3108         been encoded as global variables:<programlisting language="php">
3109 $xmlrpcI4="i4";
3110 $xmlrpcInt="int";
3111 $xmlrpcBoolean="boolean";
3112 $xmlrpcDouble="double";
3113 $xmlrpcString="string";
3114 $xmlrpcDateTime="dateTime.iso8601";
3115 $xmlrpcBase64="base64";
3116 $xmlrpcArray="array";
3117 $xmlrpcStruct="struct";
3118 $xmlrpcValue="undefined";
3119 $xmlrpcNull="null";
3120 </programlisting></para>
3121       </sect2>
3122
3123       <sect2>
3124         <title>$xmlrpcTypes, $xmlrpc_valid_parents, $xmlrpcerr, $xmlrpcstr,
3125         $xmlrpcerrxml, $xmlrpc_backslash, $_xh, $xml_iso88591_Entities,
3126         $xmlEntities, $xmlrpcs_capabilities</title>
3127
3128         <para>Reserved for internal usage.</para>
3129       </sect2>
3130     </sect1>
3131
3132     <sect1>
3133       <title>Variables whose value can be modified</title>
3134
3135       <sect2 id="xmlrpc-defencoding" xreflabel="xmlrpc_defencoding">
3136         <title xreflabel="">xmlrpc_defencoding</title>
3137
3138         <fieldsynopsis>
3139           <varname>$xmlrpc_defencoding</varname>
3140
3141           <initializer>"UTF8"</initializer>
3142         </fieldsynopsis>
3143
3144         <para>This variable defines the character set encoding that will be
3145         used by the xml-rpc client and server to decode the received messages,
3146         when a specific charset declaration is not found (in the messages sent
3147         non-ascii chars are always encoded using character references, so that
3148         the produced xml is valid regardless of the charset encoding
3149         assumed).</para>
3150
3151         <para>Allowed values: <literal>"UTF8"</literal>,
3152         <literal>"ISO-8859-1"</literal>, <literal>"ASCII".</literal></para>
3153
3154         <para>Note that the appropriate RFC actually mandates that XML
3155         received over HTTP without indication of charset encoding be treated
3156         as US-ASCII, but many servers and clients 'in the wild' violate the
3157         standard, and assume the default encoding is UTF-8.</para>
3158       </sect2>
3159
3160       <sect2>
3161         <title>xmlrpc_internalencoding</title>
3162
3163         <para><fieldsynopsis>
3164             <varname>$xmlrpc_internalencoding</varname>
3165
3166             <initializer>"ISO-8859-1"</initializer>
3167           </fieldsynopsis>This variable defines the character set encoding
3168         that the library uses to transparently encode into valid XML the
3169         xml-rpc values created by the user and to re-encode the received
3170         xml-rpc values when it passes them to the PHP application. It only
3171         affects xml-rpc values of string type. It is a separate value from
3172         xmlrpc_defencoding, allowing e.g. to send/receive xml messages encoded
3173         on-the-wire in US-ASCII and process them as UTF-8. It defaults to the
3174         character set used internally by PHP (unless you are running an
3175         MBString-enabled installation), so you should change it only in
3176         special situations, if e.g. the string values exchanged in the xml-rpc
3177         messages are directly inserted into / fetched from a database
3178         configured to return UTF8 encoded strings to PHP. Example
3179         usage:</para>
3180
3181         <para><programlisting language="php">
3182 &lt;?php
3183
3184 include('xmlrpc.inc');
3185 $xmlrpc_internalencoding = 'UTF-8'; // this has to be set after the inclusion above
3186 $v = new xmlrpcval('κόÏ\83με'); // This xmlrpc value will be correctly serialized as the greek word 'kosme'
3187 </programlisting></para>
3188       </sect2>
3189
3190       <sect2>
3191         <title>xmlrpcName</title>
3192
3193         <para><fieldsynopsis>
3194             <varname>$xmlrpcName</varname>
3195
3196             <initializer>"XML-RPC for PHP"</initializer>
3197           </fieldsynopsis>The string representation of the name of the XML-RPC
3198         for PHP library. It is used by the client for building the User-Agent
3199         HTTP header that is sent with every request to the server. You can
3200         change its value if you need to customize the User-Agent
3201         string.</para>
3202       </sect2>
3203
3204       <sect2>
3205         <title>xmlrpcVersion</title>
3206
3207         <para><fieldsynopsis>
3208             <varname>$xmlrpcVersion</varname>
3209
3210             <initializer>"2.2"</initializer>
3211           </fieldsynopsis>The string representation of the version number of
3212         the XML-RPC for PHP library in use. It is used by the client for
3213         building the User-Agent HTTP header that is sent with every request to
3214         the server. You can change its value if you need to customize the
3215         User-Agent string.</para>
3216       </sect2>
3217
3218       <sect2>
3219         <title>xmlrpc_null_extension</title>
3220
3221         <para>When set to <constant>TRUE</constant>, the lib will enable
3222         support for the &lt;NIL/&gt; (and &lt;EX:NIL/&gt;) xmlrpc value, as
3223         per the extension to the standard proposed here. This means that
3224         &lt;NIL/&gt; and &lt;EX:NIL/&gt; tags received will be parsed as valid
3225         xmlrpc, and the corresponding xmlrpcvals will return "null" for
3226         <methodname>scalarTyp()</methodname>.</para>
3227       </sect2>
3228
3229       <sect2>
3230         <title>xmlrpc_null_apache_encoding</title>
3231
3232         <para>When set to <literal>TRUE</literal>, php NULL values encoded
3233         into <classname>xmlrpcval</classname> objects get serialized using the
3234         <literal>&lt;EX:NIL/&gt;</literal> tag instead of
3235         <literal>&lt;NIL/&gt;</literal>. Please note that both forms are
3236         always accepted as input regardless of the value of this
3237         variable.</para>
3238       </sect2>
3239     </sect1>
3240   </chapter>
3241
3242   <chapter id="helpers">
3243     <title>Helper functions</title>
3244
3245     <para>XML-RPC for PHP contains some helper functions which you can use to
3246     make processing of XML-RPC requests easier.</para>
3247
3248     <sect1>
3249       <title>Date functions</title>
3250
3251       <para>The XML-RPC specification has this to say on dates:</para>
3252
3253       <blockquote>
3254         <para id="wrap_xmlrpc_method">Don't assume a timezone. It should be
3255         specified by the server in its documentation what assumptions it makes
3256         about timezones.</para>
3257       </blockquote>
3258
3259       <para>Unfortunately, this means that date processing isn't
3260       straightforward. Although XML-RPC uses ISO 8601 format dates, it doesn't
3261       use the timezone specifier.</para>
3262
3263       <para>We strongly recommend that in every case where you pass dates in
3264       XML-RPC calls, you use UTC (GMT) as your timezone. Most computer
3265       languages include routines for handling GMT times natively, and you
3266       won't have to translate between timezones.</para>
3267
3268       <para>For more information about dates, see <ulink
3269       url="http://www.uic.edu/year2000/datefmt.html">ISO 8601: The Right
3270       Format for Dates</ulink>, which has a handy link to a PDF of the ISO
3271       8601 specification. Note that XML-RPC uses exactly one of the available
3272       representations: CCYYMMDDTHH:MM:SS.</para>
3273
3274       <sect2 id="iso8601encode" xreflabel="iso8601_encode()">
3275         <title>iso8601_encode</title>
3276
3277         <funcsynopsis>
3278           <funcprototype>
3279             <funcdef><type>string</type><function>iso8601_encode</function></funcdef>
3280
3281             <paramdef><type>string</type><parameter>$time_t</parameter></paramdef>
3282
3283             <paramdef
3284             choice="opt"><type>int</type><parameter>$utc</parameter><initializer>0</initializer></paramdef>
3285           </funcprototype>
3286         </funcsynopsis>
3287
3288         <para>Returns an ISO 8601 formatted date generated from the UNIX
3289         timestamp <parameter>$time_t</parameter>, as returned by the PHP
3290         function <function>time()</function>.</para>
3291
3292         <para>The argument <parameter>$utc</parameter> can be omitted, in
3293         which case it defaults to <literal>0</literal>. If it is set to
3294         <literal>1</literal>, then the function corrects the time passed in
3295         for UTC. Example: if you're in the GMT-6:00 timezone and set
3296         <parameter>$utc</parameter>, you will receive a date representation
3297         six hours ahead of your local time.</para>
3298
3299         <para>The included demo program <filename>vardemo.php</filename>
3300         includes a demonstration of this function.</para>
3301       </sect2>
3302
3303       <sect2 id="iso8601decode" xreflabel="iso8601_decode()">
3304         <title>iso8601_decode</title>
3305
3306         <funcsynopsis>
3307           <funcprototype>
3308             <funcdef><type>int</type><function>iso8601_decode</function></funcdef>
3309
3310             <paramdef><type>string</type><parameter>$isoString</parameter></paramdef>
3311
3312             <paramdef><type>int</type><parameter>$utc</parameter><initializer>0</initializer></paramdef>
3313           </funcprototype>
3314         </funcsynopsis>
3315
3316         <para>Returns a UNIX timestamp from an ISO 8601 encoded time and date
3317         string passed in. If <parameter>$utc</parameter> is
3318         <literal>1</literal> then <parameter>$isoString</parameter> is assumed
3319         to be in the UTC timezone, and thus the result is also UTC: otherwise,
3320         the timezone is assumed to be your local timezone and you receive a
3321         local timestamp.</para>
3322       </sect2>
3323     </sect1>
3324
3325     <sect1 id="arrayuse">
3326       <title>Easy use with nested PHP values</title>
3327
3328       <para>Dan Libby was kind enough to contribute two helper functions that
3329       make it easier to translate to and from PHP values. This makes it easier
3330       to deal with complex structures. At the moment support is limited to
3331       <type>int</type>, <type>double</type>, <type>string</type>,
3332       <type>array</type>, <type>datetime</type> and <type>struct</type>
3333       datatypes; note also that all PHP arrays are encoded as structs, except
3334       arrays whose keys are integer numbers starting with 0 and incremented by
3335       1.</para>
3336
3337       <para>These functions reside in <filename>xmlrpc.inc</filename>.</para>
3338
3339       <sect2 id="phpxmlrpcdecode">
3340         <title>php_xmlrpc_decode</title>
3341
3342         <funcsynopsis>
3343           <funcprototype>
3344             <funcdef><type>mixed</type><function>php_xmlrpc_decode</function></funcdef>
3345
3346             <paramdef><type>xmlrpcval</type><parameter>$xmlrpc_val</parameter></paramdef>
3347
3348             <paramdef><type>array</type><parameter>$options</parameter></paramdef>
3349           </funcprototype>
3350
3351           <funcprototype>
3352             <funcdef><type>array</type><function>php_xmlrpc_decode</function></funcdef>
3353
3354             <paramdef><type>xmlrpcmsg</type><parameter>$xmlrpcmsg_val</parameter></paramdef>
3355
3356             <paramdef><type>string</type><parameter>$options</parameter></paramdef>
3357           </funcprototype>
3358         </funcsynopsis>
3359
3360         <para>Returns a native PHP value corresponding to the values found in
3361         the <type>xmlrpcval</type> <parameter>$xmlrpc_val</parameter>,
3362         translated into PHP types. Base-64 and datetime values are
3363         automatically decoded to strings.</para>
3364
3365         <para>In the second form, returns an array containing the parameters
3366         of the given
3367         <parameter><classname>xmlrpcmsg</classname>_val</parameter>, decoded
3368         to php types.</para>
3369
3370         <para>The <parameter>options</parameter> parameter is optional. If
3371         specified, it must consist of an array of options to be enabled in the
3372         decoding process. At the moment the only valid option are
3373         <symbol>decode_php_objs</symbol> and
3374         <literal>dates_as_objects</literal>. When the first is set, php
3375         objects that have been converted to xml-rpc structs using the
3376         <function>php_xmlrpc_encode</function> function and a corresponding
3377         encoding option will be converted back into object values instead of
3378         arrays (provided that the class definition is available at
3379         reconstruction time). When the second is set, XML-RPC datetime values
3380         will be converted into native <classname>dateTime</classname> objects
3381         instead of strings.</para>
3382
3383         <para><emphasis><emphasis>WARNING</emphasis>:</emphasis> please take
3384         extreme care before enabling the <symbol>decode_php_objs</symbol>
3385         option: when php objects are rebuilt from the received xml, their
3386         constructor function will be silently invoked. This means that you are
3387         allowing the remote end to trigger execution of uncontrolled PHP code
3388         on your server, opening the door to code injection exploits. Only
3389         enable this option when you have complete trust of the remote
3390         server/client.</para>
3391
3392         <para>Example:<programlisting language="php">
3393 // wrapper to expose an existing php function as xmlrpc method handler
3394 function foo_wrapper($m)
3395 {
3396   $params = php_xmlrpc_decode($m);
3397   $retval = call_user_func_array('foo', $params);
3398   return new xmlrpcresp(new xmlrpcval($retval)); // foo return value will be serialized as string
3399 }
3400
3401 $s = new xmlrpc_server(array(
3402    "examples.myFunc1" =&gt; array(
3403      "function" =&gt; "foo_wrapper",
3404      "signatures" =&gt; ...
3405   )));
3406 </programlisting></para>
3407       </sect2>
3408
3409       <sect2 id="phpxmlrpcencode">
3410         <title>php_xmlrpc_encode</title>
3411
3412         <funcsynopsis>
3413           <funcprototype>
3414             <funcdef><type>xmlrpcval</type><function>php_xmlrpc_encode</function></funcdef>
3415
3416             <paramdef><type>mixed</type><parameter>$phpval</parameter></paramdef>
3417
3418             <paramdef><type>array</type><parameter>$options</parameter></paramdef>
3419           </funcprototype>
3420         </funcsynopsis>
3421
3422         <para>Returns an <type>xmlrpcval</type> object populated with the PHP
3423         values in <parameter>$phpval</parameter>. Works recursively on arrays
3424         and objects, encoding numerically indexed php arrays into array-type
3425         xmlrpcval objects and non numerically indexed php arrays into
3426         struct-type xmlrpcval objects. Php objects are encoded into
3427         struct-type xmlrpcvals, excepted for php values that are already
3428         instances of the xmlrpcval class or descendants thereof, which will
3429         not be further encoded. Note that there's no support for encoding php
3430         values into base-64 values. Encoding of date-times is optionally
3431         carried on on php strings with the correct format.</para>
3432
3433         <para>The <parameter>options</parameter> parameter is optional. If
3434         specified, it must consist of an array of options to be enabled in the
3435         encoding process. At the moment the only valid options are
3436         <symbol>encode_php_objs</symbol>, <literal>null_extension</literal>
3437         and <symbol>auto_dates</symbol>.</para>
3438
3439         <para>The first will enable the creation of 'particular' xmlrpcval
3440         objects out of php objects, that add a "php_class" xml attribute to
3441         their serialized representation. This attribute allows the function
3442         php_xmlrpc_decode to rebuild the native php objects (provided that the
3443         same class definition exists on both sides of the communication). The
3444         second allows to encode php <literal>NULL</literal> values to the
3445         <literal>&lt;NIL/&gt;</literal> (or
3446         <literal>&lt;EX:NIL/&gt;</literal>, see ...) tag. The last encodes any
3447         string that matches the ISO8601 format into an XML-RPC
3448         datetime.</para>
3449
3450         <para>Example:<programlisting language="php">
3451 // the easy way to build a complex xml-rpc struct, showing nested base64 value and datetime values
3452 $val = php_xmlrpc_encode(array(
3453   'first struct_element: an int' =&gt; 666,
3454   'second: an array' =&gt; array ('apple', 'orange', 'banana'),
3455   'third: a base64 element' =&gt; new xmlrpcval('hello world', 'base64'),
3456   'fourth: a datetime' =&gt; '20060107T01:53:00'
3457   ), array('auto_dates'));
3458 </programlisting></para>
3459       </sect2>
3460
3461       <sect2>
3462         <title>php_xmlrpc_decode_xml</title>
3463
3464         <funcsynopsis>
3465           <funcprototype>
3466             <funcdef><type>xmlrpcval | xmlrpcresp |
3467             xmlrpcmsg</type><function>php_xmlrpc_decode_xml</function></funcdef>
3468
3469             <paramdef><type>string</type><parameter>$xml</parameter></paramdef>
3470
3471             <paramdef><type>array</type><parameter>$options</parameter></paramdef>
3472           </funcprototype>
3473         </funcsynopsis>
3474
3475         <para>Decodes the xml representation of either an xmlrpc request,
3476         response or single value, returning the corresponding php-xmlrpc
3477         object, or <literal>FALSE</literal> in case of an error.</para>
3478
3479         <para>The <parameter>options</parameter> parameter is optional. If
3480         specified, it must consist of an array of options to be enabled in the
3481         decoding process. At the moment, no option is supported.</para>
3482
3483         <para>Example:<programlisting language="php">
3484 $text = '&lt;value&gt;&lt;array&gt;&lt;data&gt;&lt;value&gt;Hello world&lt;/value&gt;&lt;/data&gt;&lt;/array&gt;&lt;/value&gt;';
3485 $val = php_xmlrpc_decode_xml($text);
3486 if ($val) echo 'Found a value of type '.$val-&gt;kindOf(); else echo 'Found invalid xml';
3487 </programlisting></para>
3488       </sect2>
3489     </sect1>
3490
3491     <sect1>
3492       <title>Automatic conversion of php functions into xmlrpc methods (and
3493       vice versa)</title>
3494
3495       <para>For the extremely lazy coder, helper functions have been added
3496       that allow to convert a php function into an xmlrpc method, and a
3497       remotely exposed xmlrpc method into a local php function - or a set of
3498       methods into a php class. Note that these comes with many caveat.</para>
3499
3500       <sect2>
3501         <title>wrap_xmlrpc_method</title>
3502
3503         <funcsynopsis>
3504           <funcprototype>
3505             <funcdef><type>string</type><function>wrap_xmlrpc_method</function></funcdef>
3506
3507             <paramdef>$client</paramdef>
3508
3509             <paramdef>$methodname</paramdef>
3510
3511             <paramdef>$extra_options</paramdef>
3512           </funcprototype>
3513
3514           <funcprototype>
3515             <funcdef><type>string</type><function>wrap_xmlrpc_method</function></funcdef>
3516
3517             <paramdef>$client</paramdef>
3518
3519             <paramdef>$methodname</paramdef>
3520
3521             <paramdef>$signum</paramdef>
3522
3523             <paramdef>$timeout</paramdef>
3524
3525             <paramdef>$protocol</paramdef>
3526
3527             <paramdef>$funcname</paramdef>
3528           </funcprototype>
3529         </funcsynopsis>
3530
3531         <para>Given an xmlrpc server and a method name, creates a php wrapper
3532         function that will call the remote method and return results using
3533         native php types for both params and results. The generated php
3534         function will return an xmlrpcresp object for failed xmlrpc
3535         calls.</para>
3536
3537         <para>The second syntax is deprecated, and is listed here only for
3538         backward compatibility.</para>
3539
3540         <para>The server must support the
3541         <methodname>system.methodSignature</methodname> xmlrpc method call for
3542         this function to work.</para>
3543
3544         <para>The <parameter>client</parameter> param must be a valid
3545         xmlrpc_client object, previously created with the address of the
3546         target xmlrpc server, and to which the preferred communication options
3547         have been set.</para>
3548
3549         <para>The optional parameters can be passed as array key,value pairs
3550         in the <parameter>extra_options</parameter> param.</para>
3551
3552         <para>The <parameter>signum</parameter> optional param has the purpose
3553         of indicating which method signature to use, if the given server
3554         method has multiple signatures (defaults to 0).</para>
3555
3556         <para>The <parameter>timeout</parameter> and
3557         <parameter>protocol</parameter> optional params are the same as in the
3558         <methodname>xmlrpc_client::send()</methodname> method.</para>
3559
3560         <para>If set, the optional <parameter>new_function_name</parameter>
3561         parameter indicates which name should be used for the generated
3562         function. In case it is not set the function name will be
3563         auto-generated.</para>
3564
3565         <para>If the <literal>return_source</literal> optional parameter is
3566         set, the function will return the php source code to build the wrapper
3567         function, instead of evaluating it (useful to save the code and use it
3568         later as stand-alone xmlrpc client).</para>
3569
3570         <para>If the <literal>encode_php_objs</literal> optional parameter is
3571         set, instances of php objects later passed as parameters to the newly
3572         created function will receive a 'special' treatment that allows the
3573         server to rebuild them as php objects instead of simple arrays. Note
3574         that this entails using a "slightly augmented" version of the xmlrpc
3575         protocol (ie. using element attributes), which might not be understood
3576         by xmlrpc servers implemented using other libraries.</para>
3577
3578         <para>If the <literal>decode_php_objs</literal> optional parameter is
3579         set, instances of php objects that have been appropriately encoded by
3580         the server using a coordinate option will be deserialized as php
3581         objects instead of simple arrays (the same class definition should be
3582         present server side and client side).</para>
3583
3584         <para><emphasis>Note that this might pose a security risk</emphasis>,
3585         since in order to rebuild the object instances their constructor
3586         method has to be invoked, and this means that the remote server can
3587         trigger execution of unforeseen php code on the client: not really a
3588         code injection, but almost. Please enable this option only when you
3589         trust the remote server.</para>
3590
3591         <para>In case of an error during generation of the wrapper function,
3592         FALSE is returned, otherwise the name (or source code) of the new
3593         function.</para>
3594
3595         <para>Known limitations: server must support
3596         <methodname>system.methodsignature</methodname> for the wanted xmlrpc
3597         method; for methods that expose multiple signatures, only one can be
3598         picked; for remote calls with nested xmlrpc params, the caller of the
3599         generated php function has to encode on its own the params passed to
3600         the php function if these are structs or arrays whose (sub)members
3601         include values of type base64.</para>
3602
3603         <para>Note: calling the generated php function 'might' be slow: a new
3604         xmlrpc client is created on every invocation and an xmlrpc-connection
3605         opened+closed. An extra 'debug' param is appended to the parameter
3606         list of the generated php function, useful for debugging
3607         purposes.</para>
3608
3609         <para>Example usage:</para>
3610
3611         <programlisting language="php">
3612 $c = new xmlrpc_client('http://phpxmlrpc.sourceforge.net/server.php');
3613
3614 $function = wrap_xmlrpc_method($client, 'examples.getStateName');
3615
3616 if (!$function)
3617   die('Cannot introspect remote method');
3618 else {
3619   $stateno = 15;
3620   $statename = $function($a);
3621   if (is_a($statename, 'xmlrpcresp')) // call failed
3622   {
3623     echo 'Call failed: '.$statename-&gt;faultCode().'. Calling again with debug on';
3624     $function($a, true);
3625   }
3626   else
3627     echo "OK, state nr. $stateno is $statename";
3628 }
3629 </programlisting>
3630       </sect2>
3631
3632       <sect2 id="wrap_php_function">
3633         <title>wrap_php_function</title>
3634
3635         <funcsynopsis>
3636           <funcprototype>
3637             <funcdef><type>array</type><function>wrap_php_function</function></funcdef>
3638
3639             <paramdef><type>string</type><parameter>$funcname</parameter></paramdef>
3640
3641             <paramdef><type>string</type><parameter>$wrapper_function_name</parameter></paramdef>
3642
3643             <paramdef><type>array</type><parameter>$extra_options</parameter></paramdef>
3644           </funcprototype>
3645         </funcsynopsis>
3646
3647         <para>Given a user-defined PHP function, create a PHP 'wrapper'
3648         function that can be exposed as xmlrpc method from an xmlrpc_server
3649         object and called from remote clients, and return the appropriate
3650         definition to be added to a server's dispatch map.</para>
3651
3652         <para>The optional <parameter>$wrapper_function_name</parameter>
3653         specifies the name that will be used for the auto-generated
3654         function.</para>
3655
3656         <para>Since php is a typeless language, to infer types of input and
3657         output parameters, it relies on parsing the javadoc-style comment
3658         block associated with the given function. Usage of xmlrpc native types
3659         (such as datetime.dateTime.iso8601 and base64) in the docblock @param
3660         tag is also allowed, if you need the php function to receive/send data
3661         in that particular format (note that base64 encoding/decoding is
3662         transparently carried out by the lib, while datetime vals are passed
3663         around as strings).</para>
3664
3665         <para>Known limitations: only works for
3666         user-defined functions, not for PHP internal functions (reflection
3667         does not support retrieving number/type of params for those); the
3668         wrapped php function will not be able to programmatically return an
3669         xmlrpc error response.</para>
3670
3671         <para>If the <literal>return_source</literal> optional parameter is
3672         set, the function will return the php source code to build the wrapper
3673         function, instead of evaluating it (useful to save the code and use it
3674         later in a stand-alone xmlrpc server). It will be in the stored in the
3675         <literal>source</literal> member of the returned array.</para>
3676
3677         <para>If the <literal>suppress_warnings</literal> optional parameter
3678         is set, any runtime warning generated while processing the
3679         user-defined php function will be catched and not be printed in the
3680         generated xml response.</para>
3681
3682         <para>If the <parameter>extra_options</parameter> array contains the
3683         <literal>encode_php_objs</literal> value, wrapped functions returning
3684         php objects will generate "special" xmlrpc responses: when the xmlrpc
3685         decoding of those responses is carried out by this same lib, using the
3686         appropriate param in php_xmlrpc_decode(), the objects will be
3687         rebuilt.</para>
3688
3689         <para>In short: php objects can be serialized, too (except for their
3690         resource members), using this function. Other libs might choke on the
3691         very same xml that will be generated in this case (i.e. it has a
3692         nonstandard attribute on struct element tags)</para>
3693
3694         <para>If the <literal>decode_php_objs</literal> optional parameter is
3695         set, instances of php objects that have been appropriately encoded by
3696         the client using a coordinate option will be deserialized and passed
3697         to the user function as php objects instead of simple arrays (the same
3698         class definition should be present server side and client
3699         side).</para>
3700
3701         <para><emphasis>Note that this might pose a security risk</emphasis>,
3702         since in order to rebuild the object instances their constructor
3703         method has to be invoked, and this means that the remote client can
3704         trigger execution of unforeseen php code on the server: not really a
3705         code injection, but almost. Please enable this option only when you
3706         trust the remote clients.</para>
3707
3708         <para>Example usage:</para>
3709
3710         <para><programlisting language="php">/**
3711 * State name from state number decoder. NB: do NOT remove this comment block.
3712 * @param integer $stateno the state number
3713 * @return string the name of the state (or error description)
3714 */
3715 function findstate($stateno)
3716 {
3717   global $stateNames;
3718   if (isset($stateNames[$stateno-1]))
3719   {
3720     return $stateNames[$stateno-1];
3721   }
3722   else
3723   {
3724     return "I don't have a state for the index '" . $stateno . "'";
3725   }
3726 }
3727
3728 // wrap php function, build xmlrpc server
3729 $methods = array();
3730 $findstate_sig = wrap_php_function('findstate');
3731 if ($findstate_sig)
3732   $methods['examples.getStateName'] = $findstate_sig;
3733 $srv = new xmlrpc_server($methods);
3734 </programlisting></para>
3735       </sect2>
3736     </sect1>
3737
3738     <sect1 id="deprecated">
3739       <title>Functions removed from the library</title>
3740
3741       <para>The following two functions have been deprecated in version 1.1 of
3742       the library, and removed in version 2, in order to avoid conflicts with
3743       the EPI xml-rpc library, which also defines two functions with the same
3744       names.</para>
3745
3746       <para>To ease the transition to the new naming scheme and avoid breaking
3747       existing implementations, the following scheme has been adopted:
3748       <itemizedlist>
3749           <listitem>
3750             <para>If EPI-XMLRPC is not active in the current PHP installation,
3751             the constant <literal>XMLRPC_EPI_ENABLED</literal> will be set to
3752             <literal>'0'</literal></para>
3753           </listitem>
3754
3755           <listitem>
3756             <para>If EPI-XMLRPC is active in the current PHP installation, the
3757             constant <literal>XMLRPC_EPI_ENABLED</literal> will be set to
3758             <literal>'1'</literal></para>
3759           </listitem>
3760         </itemizedlist></para>
3761
3762       <para>The following documentation is kept for historical
3763       reference:</para>
3764
3765       <sect2 id="xmlrpcdecode">
3766         <title>xmlrpc_decode</title>
3767
3768         <funcsynopsis>
3769           <funcprototype>
3770             <funcdef><type>mixed</type><function>xmlrpc_decode</function></funcdef>
3771
3772             <paramdef><type>xmlrpcval</type><parameter>$xmlrpc_val</parameter></paramdef>
3773           </funcprototype>
3774         </funcsynopsis>
3775
3776         <para>Alias for php_xmlrpc_decode.</para>
3777       </sect2>
3778
3779       <sect2 id="xmlrpcencode">
3780         <title>xmlrpc_encode</title>
3781
3782         <funcsynopsis>
3783           <funcprototype>
3784             <funcdef><type>xmlrpcval</type><function>xmlrpc_encode</function></funcdef>
3785
3786             <paramdef><type>mixed</type><parameter>$phpval</parameter></paramdef>
3787           </funcprototype>
3788         </funcsynopsis>
3789
3790         <para>Alias for php_xmlrpc_encode.</para>
3791       </sect2>
3792     </sect1>
3793
3794     <sect1 id="debugging">
3795       <title>Debugging aids</title>
3796
3797       <sect2>
3798         <title>xmlrpc_debugmsg</title>
3799
3800         <funcsynopsis>
3801           <funcprototype>
3802             <funcdef><type>void</type><function>xmlrpc_debugmsg</function></funcdef>
3803
3804             <paramdef><type>string</type><parameter>$debugstring</parameter></paramdef>
3805           </funcprototype>
3806         </funcsynopsis>
3807
3808         <para>Sends the contents of <parameter>$debugstring</parameter> in XML
3809         comments in the server return payload. If a PHP client has debugging
3810         turned on, the user will be able to see server debug
3811         information.</para>
3812
3813         <para>Use this function in your methods so you can pass back
3814         diagnostic information. It is only available from
3815         <filename>xmlrpcs.inc</filename>.</para>
3816       </sect2>
3817     </sect1>
3818   </chapter>
3819
3820   <chapter id="reserved" xreflabel="Reserved methods">
3821     <title>Reserved methods</title>
3822
3823     <para>In order to extend the functionality offered by XML-RPC servers
3824     without impacting on the protocol, reserved methods are supported in this
3825     release.</para>
3826
3827     <para>All methods starting with <function>system.</function> are
3828     considered reserved by the server. PHP for XML-RPC itself provides four
3829     special methods, detailed in this chapter.</para>
3830
3831     <para>Note that all server objects will automatically respond to clients
3832     querying these methods, unless the property
3833     <property>allow_system_funcs</property> has been set to
3834     <constant>false</constant> before calling the
3835     <methodname>service()</methodname> method. This might pose a security risk
3836     if the server is exposed to public access, e.g. on the internet.</para>
3837
3838     <sect1>
3839       <title>system.getCapabilities</title>
3840
3841       <para></para>
3842     </sect1>
3843
3844     <sect1>
3845       <title>system.listMethods</title>
3846
3847       <para>This method may be used to enumerate the methods implemented by
3848       the XML-RPC server.</para>
3849
3850       <para>The <function>system.listMethods</function> method requires no
3851       parameters. It returns an array of strings, each of which is the name of
3852       a method implemented by the server.</para>
3853     </sect1>
3854
3855     <sect1 id="sysmethodsig">
3856       <title>system.methodSignature</title>
3857
3858       <para>This method takes one parameter, the name of a method implemented
3859       by the XML-RPC server.</para>
3860
3861       <para>It returns an array of possible signatures for this method. A
3862       signature is an array of types. The first of these types is the return
3863       type of the method, the rest are parameters.</para>
3864
3865       <para>Multiple signatures (i.e. overloading) are permitted: this is the
3866       reason that an array of signatures are returned by this method.</para>
3867
3868       <para>Signatures themselves are restricted to the top level parameters
3869       expected by a method. For instance if a method expects one array of
3870       structs as a parameter, and it returns a string, its signature is simply
3871       "string, array". If it expects three integers, its signature is "string,
3872       int, int, int".</para>
3873
3874       <para>For parameters that can be of more than one type, the "undefined"
3875       string is supported.</para>
3876
3877       <para>If no signature is defined for the method, a not-array value is
3878       returned. Therefore this is the way to test for a non-signature, if
3879       <parameter>$resp</parameter> below is the response object from a method
3880       call to <function>system.methodSignature</function>:</para>
3881
3882       <programlisting language="php">
3883 $v = $resp-&gt;value();
3884 if ($v-&gt;kindOf() != "array") {
3885   // then the method did not have a signature defined
3886 }
3887 </programlisting>
3888
3889       <para>See the <filename>introspect.php</filename> demo included in this
3890       distribution for an example of using this method.</para>
3891     </sect1>
3892
3893     <sect1 id="sysmethhelp">
3894       <title>system.methodHelp</title>
3895
3896       <para>This method takes one parameter, the name of a method implemented
3897       by the XML-RPC server.</para>
3898
3899       <para>It returns a documentation string describing the use of that
3900       method. If no such string is available, an empty string is
3901       returned.</para>
3902
3903       <para>The documentation string may contain HTML markup.</para>
3904     </sect1>
3905
3906     <sect1>
3907       <title>system.multicall</title>
3908
3909       <para>This method takes one parameter, an array of 'request' struct
3910       types. Each request struct must contain a
3911       <parameter>methodName</parameter> member of type string and a
3912       <parameter>params</parameter> member of type array, and corresponds to
3913       the invocation of the corresponding method.</para>
3914
3915       <para>It returns a response of type array, with each value of the array
3916       being either an error struct (containing the faultCode and faultString
3917       members) or the successful response value of the corresponding single
3918       method call.</para>
3919     </sect1>
3920   </chapter>
3921
3922   <chapter id="examples" xreflabel="Examples">
3923     <title>Examples</title>
3924
3925     <para>The best examples are to be found in the sample files included with
3926     the distribution. Some are included here.</para>
3927
3928     <sect1 id="statename">
3929       <title>XML-RPC client: state name query</title>
3930
3931       <para>Code to get the corresponding state name from a number (1-50) from
3932       the demo server available on SourceForge</para>
3933
3934       <programlisting language="php">
3935   $m = new xmlrpcmsg('examples.getStateName',
3936     array(new xmlrpcval($HTTP_POST_VARS["stateno"], "int")));
3937   $c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
3938   $r = $c-&gt;send($m);
3939   if (!$r-&gt;faultCode()) {
3940       $v = $r-&gt;value();
3941       print "State number " . htmlentities($HTTP_POST_VARS["stateno"]) . " is " .
3942         htmlentities($v-&gt;scalarval()) . "&lt;BR&gt;";
3943       print "&lt;HR&gt;I got this value back&lt;BR&gt;&lt;PRE&gt;" .
3944         htmlentities($r-&gt;serialize()) . "&lt;/PRE&gt;&lt;HR&gt;\n";
3945   } else {
3946       print "Fault &lt;BR&gt;";
3947       print "Code: " . htmlentities($r-&gt;faultCode()) . "&lt;BR&gt;" .
3948             "Reason: '" . htmlentities($r-&gt;faultString()) . "'&lt;BR&gt;";
3949   }
3950 </programlisting>
3951     </sect1>
3952
3953     <sect1>
3954       <title>Executing a multicall call</title>
3955
3956       <para>To be documented...</para>
3957     </sect1>
3958   </chapter>
3959
3960   <chapter id="faq">
3961     <title>Frequently Asked Questions</title>
3962
3963     <sect1>
3964       <title>How to send custom XML as payload of a method call</title>
3965
3966       <para>Unfortunately, at the time the XML-RPC spec was designed, support
3967       for namespaces in XML was not as ubiquitous as it is now. As a
3968       consequence, no support was provided in the protocol for embedding XML
3969       elements from other namespaces into an xmlrpc request.</para>
3970
3971       <para>To send an XML "chunk" as payload of a method call or response,
3972       two options are available: either send the complete XML block as a
3973       string xmlrpc value, or as a base64 value. Since the '&lt;' character in
3974       string values is encoded as '&amp;lt;' in the xml payload of the method
3975       call, the XML string will not break the surrounding xmlrpc, unless
3976       characters outside of the assumed character set are used. The second
3977       method has the added benefits of working independently of the charset
3978       encoding used for the xml to be transmitted, and preserving exactly
3979       whitespace, whilst incurring in some extra message length and cpu load
3980       (for carrying out the base64 encoding/decoding).</para>
3981     </sect1>
3982
3983     <sect1>
3984       <title>Is there any limitation on the size of the requests / responses
3985       that can be successfully sent?</title>
3986
3987       <para>Yes. But I have no hard figure to give; it most likely will depend
3988       on the version of PHP in usage and its configuration.</para>
3989
3990       <para>Keep in mind that this library is not optimized for speed nor for
3991       memory usage. Better alternatives exist when there are strict
3992       requirements on throughput or resource usage, such as the php native
3993       xmlrpc extension (see the PHP manual for more information).</para>
3994
3995       <para>Keep in mind also that HTTP is probably not the best choice in
3996       such a situation, and XML is a deadly enemy. CSV formatted data over
3997       socket would be much more efficient.</para>
3998
3999       <para>If you really need to move a massive amount of data around, and
4000       you are crazy enough to do it using phpxmlrpc, your best bet is to
4001       bypass usage of the xmlrpcval objects, at least in the decoding phase,
4002       and have the server (or client) object return to the calling function
4003       directly php values (see <varname>xmlrpc_client::return_type</varname>
4004       and <varname>xmlrpc_server::functions_parameters_type</varname> for more
4005       details).</para>
4006     </sect1>
4007
4008     <sect1>
4009       <title>My server (client) returns an error whenever the client (server)
4010       returns accented characters</title>
4011
4012       <para>To be documented...</para>
4013     </sect1>
4014
4015     <sect1>
4016       <title>How to enable long-lasting method calls</title>
4017
4018       <para>To be documented...</para>
4019     </sect1>
4020
4021     <sect1>
4022       <title>My client returns "XML-RPC Fault #2: Invalid return payload:
4023       enable debugging to examine incoming payload": what should I do?</title>
4024
4025       <para>The response you are seeing is a default error response that the
4026       client object returns to the php application when the server did not
4027       respond to the call with a valid xmlrpc response.</para>
4028
4029       <para>The most likely cause is that you are not using the correct URL
4030       when creating the client object, or you do not have appropriate access
4031       rights to the web page you are requesting, or some other common http
4032       misconfiguration.</para>
4033
4034       <para>To find out what the server is really returning to your client,
4035       you have to enable the debug mode of the client, using
4036       $client-&gt;setdebug(1);</para>
4037     </sect1>
4038
4039     <sect1>
4040       <title>How can I save to a file the xml of the xmlrpc responses received
4041       from servers?</title>
4042
4043       <para>If what you need is to save the responses received from the server
4044       as xml, you have two options:</para>
4045
4046       <para>1- use the serialize() method on the response object.</para>
4047
4048       <programlisting language="php">
4049 $resp = $client-&gt;send($msg);
4050 if (!$resp-&gt;faultCode())
4051   $data_to_be_saved = $resp-&gt;serialize();
4052 </programlisting>
4053
4054       <para>Note that this will not be 100% accurate, since the xml generated
4055       by the response object can be different from the xml received,
4056       especially if there is some character set conversion involved, or such
4057       (eg. if you receive an empty string tag as &lt;string/&gt;, serialize()
4058       will output &lt;string&gt;&lt;/string&gt;), or if the server sent back
4059       as response something invalid (in which case the xml generated client
4060       side using serialize() will correspond to the error response generated
4061       internally by the lib).</para>
4062
4063       <para>2 - set the client object to return the raw xml received instead
4064       of the decoded objects:</para>
4065
4066       <programlisting language="php">
4067 $client = new xmlrpc_client($url);
4068 $client-&gt;return_type = 'xml';
4069 $resp = $client-&gt;send($msg);
4070 if (!$resp-&gt;faultCode())
4071   $data_to_be_saved = $resp-&gt;value();
4072 </programlisting>
4073
4074       <para>Note that using this method the xml response response will not be
4075       parsed at all by the library, only the http communication protocol will
4076       be checked. This means that xmlrpc responses sent by the server that
4077       would have generated an error response on the client (eg. malformed xml,
4078       responses that have faultcode set, etc...) now will not be flagged as
4079       invalid, and you might end up saving not valid xml but random
4080       junk...</para>
4081     </sect1>
4082
4083     <sect1>
4084       <title>Can I use the ms windows character set?</title>
4085
4086       <para>If the data your application is using comes from a Microsoft
4087       application, there are some chances that the character set used to
4088       encode it is CP1252 (the same might apply to data received from an
4089       external xmlrpc server/client, but it is quite rare to find xmlrpc
4090       toolkits that encode to CP1252 instead of UTF8). It is a character set
4091       which is "almost" compatible with ISO 8859-1, but for a few extra
4092       characters.</para>
4093
4094       <para>PHP-XMLRPC only supports the ISO 8859-1 and UTF8 character sets.
4095       The net result of this situation is that those extra characters will not
4096       be properly encoded, and will be received at the other end of the
4097       XML-RPC transmission as "garbled data". Unfortunately the library cannot
4098       provide real support for CP1252 because of limitations in the PHP 4 xml
4099       parser. Luckily, we tried our best to support this character set anyway,
4100       and, since version 2.2.1, there is some form of support, left commented
4101       in the code.</para>
4102
4103       <para>To properly encode outgoing data that is natively in CP1252, you
4104       will have to uncomment all relative code in the file
4105       <filename>xmlrpc.inc</filename> (you can search for the string "1252"),
4106       then set <code>$GLOBALS['xmlrpc_internalencoding']='CP1252';</code>
4107       Please note that all incoming data will then be fed to your application
4108       as UTF-8 to avoid any potential data loss.</para>
4109     </sect1>
4110
4111     <sect1>
4112       <title>Does the library support using cookies / http sessions?</title>
4113
4114       <para>In short: yes, but a little coding is needed to make it
4115       happen.</para>
4116
4117       <para>The code below uses sessions to e.g. let the client store a value
4118       on the server and retrieve it later.</para>
4119
4120       <para><programlisting>
4121 $resp = $client-&gt;send(new xmlrpcmsg('registervalue', array(new xmlrpcval('foo'), new xmlrpcval('bar'))));
4122 if (!$resp-&gt;faultCode())
4123 {
4124   $cookies = $resp-&gt;cookies();
4125   if (array_key_exists('PHPSESSID', $cookies)) // nb: make sure to use the correct session cookie name
4126   {
4127     $session_id = $cookies['PHPSESSID']['value'];
4128
4129     // do some other stuff here...
4130
4131     $client-&gt;setcookie('PHPSESSID', $session_id);
4132     $val = $client-&gt;send(new xmlrpcmsg('getvalue', array(new xmlrpcval('foo')));
4133   }
4134 }
4135 </programlisting>Server-side sessions are handled normally like in any other
4136       php application. Please see the php manual for more information about
4137       sessions.</para>
4138
4139       <para>NB: unlike web browsers, not all xmlrpc clients support usage of
4140       http cookies. If you have troubles with sessions and control only the
4141       server side of the communication, please check with the makers of the
4142       xmlrpc client in use.</para>
4143     </sect1>
4144   </chapter>
4145
4146   <appendix id="integration">
4147     <title>Integration with the PHP xmlrpc extension</title>
4148
4149     <para>To be documented more...</para>
4150
4151     <para>In short: for the fastest execution possible, you can enable the php
4152     native xmlrpc extension, and use it in conjunction with phpxmlrpc. The
4153     following code snippet gives an example of such integration</para>
4154
4155     <programlisting language="php">
4156 /*** client side ***/
4157 $c = new xmlrpc_client('http://phpxmlrpc.sourceforge.net/server.php');
4158
4159 // tell the client to return raw xml as response value
4160 $c-&gt;return_type = 'xml';
4161
4162 // let the native xmlrpc extension take care of encoding request parameters
4163 $r = $c-&gt;send(xmlrpc_encode_request('examples.getStateName', $_POST['stateno']));
4164
4165 if ($r-&gt;faultCode())
4166   // HTTP transport error
4167   echo 'Got error '.$r-&gt;faultCode();
4168 else
4169 {
4170   // HTTP request OK, but XML returned from server not parsed yet
4171   $v = xmlrpc_decode($r-&gt;value());
4172   // check if we got a valid xmlrpc response from server
4173   if ($v === NULL)
4174     echo 'Got invalid response';
4175   else
4176   // check if server sent a fault response
4177   if (xmlrpc_is_fault($v))
4178     echo 'Got xmlrpc fault '.$v['faultCode'];
4179   else
4180     echo'Got response: '.htmlentities($v);
4181 }
4182 </programlisting>
4183   </appendix>
4184
4185   <appendix id="substitution">
4186     <title>Substitution of the PHP xmlrpc extension</title>
4187
4188     <para>Yet another interesting situation is when you are using a ready-made
4189     php application, that provides support for the XMLRPC protocol via the
4190     native php xmlrpc extension, but the extension is not available on your
4191     php install (e.g. because of shared hosting constraints).</para>
4192
4193     <para>Since version 2.1, the PHP-XMLRPC library provides a compatibility
4194     layer that aims to be 100% compliant with the xmlrpc extension API. This
4195     means that any code written to run on the extension should obtain the
4196     exact same results, albeit using more resources and a longer processing
4197     time, using the PHP-XMLRPC library and the extension compatibility module.
4198     The module is part of the EXTRAS package, available as a separate download
4199     from the sourceforge.net website, since version 0.2</para>
4200   </appendix>
4201
4202   <appendix id="enough">
4203     <title>'Enough of xmlrpcvals!': new style library usage</title>
4204
4205     <para>To be documented...</para>
4206
4207     <para>In the meantime, see docs about xmlrpc_client::return_type and
4208     xmlrpc_server::functions_parameters_types, as well as php_xmlrpc_encode,
4209     php_xmlrpc_decode and php_xmlrpc_decode_xml</para>
4210   </appendix>
4211
4212   <appendix id="debugger">
4213     <title>Usage of the debugger</title>
4214
4215     <para>A webservice debugger is included in the library to help during
4216     development and testing.</para>
4217
4218     <para>The interface should be self-explicative enough to need little
4219     documentation.</para>
4220
4221     <para><graphic align="center" fileref="images/debugger.gif"
4222     format="GIF" /></para>
4223
4224     <para>The most useful feature of the debugger is without doubt the "Show
4225     debug info" option. It allows to have a screen dump of the complete http
4226     communication between client and server, including the http headers as
4227     well as the request and response payloads, and is invaluable when
4228     troubleshooting problems with charset encoding, authentication or http
4229     compression.</para>
4230
4231     <para>The debugger can take advantage of the JSONRPC library extension, to
4232     allow debugging of JSON-RPC webservices, and of the JS-XMLRPC library
4233     visual editor to allow easy mouse-driven construction of the payload for
4234     remote methods. Both components have to be downloaded separately from the
4235     sourceforge.net web pages and copied to the debugger directory to enable
4236     the extra functionality:</para>
4237
4238     <para><itemizedlist>
4239         <listitem>
4240           <para>to enable jsonrpc functionality, download the PHP-XMLRPC
4241           EXTRAS package, and copy the file <filename>jsonrpc.inc</filename>
4242           either to the same directory as the debugger or somewhere in your
4243           php include path</para>
4244         </listitem>
4245       </itemizedlist><itemizedlist>
4246         <listitem>
4247           <para>to enable the visual value editing dialog, download the
4248           JS-XMLRPC library, and copy somewhere in the web root files
4249           <filename>visualeditor.php</filename>,
4250           <filename>visualeditor.css</filename> and the folders
4251           <filename>yui</filename> and <filename>img</filename>. Then edit the
4252           debugger file <filename>controller.php</filename> and set
4253           appropriately the variable <varname>$editorpath</varname>.</para>
4254         </listitem>
4255       </itemizedlist></para>
4256   </appendix>
4257 </book>
4258 <!-- Keep this comment at the end of the file
4259 Local variables:
4260 mode: sgml
4261 sgml-omittag:nil
4262 sgml-shorttag:t
4263 sgml-minimize-attributes:nil
4264 sgml-always-quote-attributes:t
4265 sgml-indent-step:2
4266 sgml-indent-data:t
4267 sgml-parent-document:nil
4268 sgml-exposed-tags:nil
4269 sgml-local-catalogs:nil
4270 sgml-local-ecat-files:nil
4271 sgml-namecase-general:t
4272 sgml-general-insert-case:lower
4273 End:
4274 -->