WIP - more fixes
[plcapi.git] / demo / server / server.php
1 <?php
2 /**
3  * Demo server for xmlrpc library.
4  *
5  * Implements a lot of webservices, including a suite of services used for
6  * interoperability testing (validator1 methods), and some whose only purpose
7  * is to be used for unit-testing the library.
8  *
9  * Please do not copy this file verbatim into your production server.
10  *
11  **/
12
13 // give user a chance to see the source for this server instead of running the services
14 if ($_SERVER['REQUEST_METHOD'] != 'POST' && isset($_GET['showSource']))
15 {
16     highlight_file(__FILE__);
17     die();
18 }
19
20     include_once(__DIR__."/../../vendor/autoload.php");
21
22     include_once(__DIR__."/../../lib/xmlrpc.inc");
23     include_once(__DIR__."/../../lib/xmlrpcs.inc");
24     include_once(__DIR__."/../../lib/xmlrpc_wrappers.inc");
25
26     /**
27     * Used to test usage of object methods in dispatch maps and in wrapper code
28     */
29     class xmlrpc_server_methods_container
30     {
31         /**
32         * Method used to test logging of php warnings generated by user functions.
33         */
34         function phpwarninggenerator($m)
35         {
36             $a = $b; // this triggers a warning in E_ALL mode, since $b is undefined
37             return new xmlrpcresp(new xmlrpcval(1, 'boolean'));
38         }
39
40         /**
41          * Method used to testcatching of exceptions in the server.
42          */
43         function exceptiongenerator($m)
44         {
45             throw new Exception("it's just a test", 1);
46         }
47
48         /**
49         * a PHP version of the state-number server. Send me an integer and i'll sell you a state
50         * @param integer $s
51         * @return string
52         */
53         static function findstate($s)
54         {
55             return inner_findstate($s);
56         }
57     }
58
59
60     // a PHP version
61     // of the state-number server
62     // send me an integer and i'll sell you a state
63
64     $stateNames = array(
65         "Alabama", "Alaska", "Arizona", "Arkansas", "California",
66         "Colorado", "Columbia", "Connecticut", "Delaware", "Florida",
67         "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas",
68         "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
69         "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
70         "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina",
71         "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
72         "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
73         "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"
74     );
75
76     $findstate_sig=array(array($xmlrpcString, $xmlrpcInt));
77     $findstate_doc='When passed an integer between 1 and 51 returns the
78 name of a US state, where the integer is the index of that state name
79 in an alphabetic order.';
80
81
82     function findstate($m)
83     {
84         global $xmlrpcerruser, $stateNames;
85         $err="";
86         // get the first param
87         $sno=$m->getParam(0);
88
89         // param must be there and of the correct type: server object does the
90         // validation for us
91
92         // extract the value of the state number
93         $snv=$sno->scalarval();
94         // look it up in our array (zero-based)
95         if (isset($stateNames[$snv-1]))
96         {
97             $sname=$stateNames[$snv-1];
98         }
99         else
100         {
101             // not, there so complain
102             $err="I don't have a state for the index '" . $snv . "'";
103         }
104
105         // if we generated an error, create an error return response
106         if ($err)
107         {
108             return new xmlrpcresp(0, $xmlrpcerruser, $err);
109         }
110         else
111         {
112             // otherwise, we create the right response
113             // with the state name
114             return new xmlrpcresp(new xmlrpcval($sname));
115         }
116     }
117
118     /**
119     * Inner code of the state-number server.
120     * Used to test auto-registration of PHP funcions as xmlrpc methods.
121     * @param integer $stateno the state number
122     * @return string the name of the state (or error descrption)
123     */
124     function inner_findstate($stateno)
125     {
126         global $stateNames;
127         if (isset($stateNames[$stateno-1]))
128         {
129             return $stateNames[$stateno-1];
130         }
131         else
132         {
133             // not, there so complain
134             return "I don't have a state for the index '" . $stateno . "'";
135         }
136     }
137     $findstate2_sig = wrap_php_function('inner_findstate');
138
139     $findstate3_sig = wrap_php_function(array('xmlrpc_server_methods_container', 'findstate'));
140
141     $findstate5_sig = wrap_php_function('xmlrpc_server_methods_container::findstate');
142
143     $obj = new xmlrpc_server_methods_container();
144     $findstate4_sig = wrap_php_function(array($obj, 'findstate'));
145
146     $addtwo_sig=array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt));
147     $addtwo_doc='Add two integers together and return the result';
148     function addtwo($m)
149     {
150         $s=$m->getParam(0);
151         $t=$m->getParam(1);
152         return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(),"int"));
153     }
154
155     $addtwodouble_sig=array(array($xmlrpcDouble, $xmlrpcDouble, $xmlrpcDouble));
156     $addtwodouble_doc='Add two doubles together and return the result';
157     function addtwodouble($m)
158     {
159         $s=$m->getParam(0);
160         $t=$m->getParam(1);
161         return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(),"double"));
162     }
163
164     $stringecho_sig=array(array($xmlrpcString, $xmlrpcString));
165     $stringecho_doc='Accepts a string parameter, returns the string.';
166     function stringecho($m)
167     {
168         // just sends back a string
169         $s=$m->getParam(0);
170         $v = $s->scalarval();
171         return new xmlrpcresp(new xmlrpcval($s->scalarval()));
172     }
173
174     $echoback_sig=array(array($xmlrpcString, $xmlrpcString));
175     $echoback_doc='Accepts a string parameter, returns the entire incoming payload';
176     function echoback($m)
177     {
178         // just sends back a string with what i got
179         // sent to me, just escaped, that's all
180         //
181         // $m is an incoming message
182         $s="I got the following message:\n" . $m->serialize();
183         return new xmlrpcresp(new xmlrpcval($s));
184     }
185
186     $echosixtyfour_sig=array(array($xmlrpcString, $xmlrpcBase64));
187     $echosixtyfour_doc='Accepts a base64 parameter and returns it decoded as a string';
188     function echosixtyfour($m)
189     {
190         // accepts an encoded value, but sends it back
191         // as a normal string. this is to test base64 encoding
192         // is working as expected
193         $incoming=$m->getParam(0);
194         return new xmlrpcresp(new xmlrpcval($incoming->scalarval(), "string"));
195     }
196
197     $bitflipper_sig=array(array($xmlrpcArray, $xmlrpcArray));
198     $bitflipper_doc='Accepts an array of booleans, and returns them inverted';
199     function bitflipper($m)
200     {
201         global $xmlrpcArray;
202
203         $v=$m->getParam(0);
204         $sz=$v->arraysize();
205         $rv=new xmlrpcval(array(), $xmlrpcArray);
206
207         for($j=0; $j<$sz; $j++)
208         {
209             $b=$v->arraymem($j);
210             if ($b->scalarval())
211             {
212                 $rv->addScalar(false, "boolean");
213             }
214             else
215             {
216                 $rv->addScalar(true, "boolean");
217             }
218         }
219
220         return new xmlrpcresp($rv);
221     }
222
223     // Sorting demo
224     //
225     // send me an array of structs thus:
226     //
227     // Dave 35
228     // Edd  45
229     // Fred 23
230     // Barney 37
231     //
232     // and I'll return it to you in sorted order
233
234     function agesorter_compare($a, $b)
235     {
236         global $agesorter_arr;
237
238         // don't even ask me _why_ these come padded with
239         // hyphens, I couldn't tell you :p
240         $a=str_replace("-", "", $a);
241         $b=str_replace("-", "", $b);
242
243         if ($agesorter_arr[$a]==$agesorter_arr[$b])
244         {
245             return 0;
246         }
247         return ($agesorter_arr[$a] > $agesorter_arr[$b]) ? -1 : 1;
248     }
249
250     $agesorter_sig=array(array($xmlrpcArray, $xmlrpcArray));
251     $agesorter_doc='Send this method an array of [string, int] structs, eg:
252 <pre>
253  Dave   35
254  Edd    45
255  Fred   23
256  Barney 37
257 </pre>
258 And the array will be returned with the entries sorted by their numbers.
259 ';
260     function agesorter($m)
261     {
262         global $agesorter_arr, $xmlrpcerruser, $s;
263
264         xmlrpc_debugmsg("Entering 'agesorter'");
265         // get the parameter
266         $sno=$m->getParam(0);
267         // error string for [if|when] things go wrong
268         $err="";
269         // create the output value
270         $v=new xmlrpcval();
271         $agar=array();
272
273         if (isset($sno) && $sno->kindOf()=="array")
274         {
275             $max=$sno->arraysize();
276             // TODO: create debug method to print can work once more
277             // print "<!-- found $max array elements -->\n";
278             for($i=0; $i<$max; $i++)
279             {
280                 $rec=$sno->arraymem($i);
281                 if ($rec->kindOf()!="struct")
282                 {
283                     $err="Found non-struct in array at element $i";
284                     break;
285                 }
286                 // extract name and age from struct
287                 $n=$rec->structmem("name");
288                 $a=$rec->structmem("age");
289                 // $n and $a are xmlrpcvals,
290                 // so get the scalarval from them
291                 $agar[$n->scalarval()]=$a->scalarval();
292             }
293
294             $agesorter_arr=$agar;
295             // hack, must make global as uksort() won't
296             // allow us to pass any other auxilliary information
297             uksort($agesorter_arr, agesorter_compare);
298             $outAr=array();
299             while (list( $key, $val ) = each( $agesorter_arr ) )
300             {
301                 // recreate each struct element
302                 $outAr[]=new xmlrpcval(array("name" =>
303                 new xmlrpcval($key),
304                 "age" =>
305                 new xmlrpcval($val, "int")), "struct");
306             }
307             // add this array to the output value
308             $v->addArray($outAr);
309         }
310         else
311         {
312             $err="Must be one parameter, an array of structs";
313         }
314
315         if ($err)
316         {
317             return new xmlrpcresp(0, $xmlrpcerruser, $err);
318         }
319         else
320         {
321             return new xmlrpcresp($v);
322         }
323     }
324
325     // signature and instructions, place these in the dispatch
326     // map
327     $mail_send_sig=array(array(
328         $xmlrpcBoolean, $xmlrpcString, $xmlrpcString,
329         $xmlrpcString, $xmlrpcString, $xmlrpcString,
330         $xmlrpcString, $xmlrpcString
331     ));
332
333     $mail_send_doc='mail.send(recipient, subject, text, sender, cc, bcc, mimetype)<br/>
334 recipient, cc, and bcc are strings, comma-separated lists of email addresses, as described above.<br/>
335 subject is a string, the subject of the message.<br/>
336 sender is a string, it\'s the email address of the person sending the message. This string can not be
337 a comma-separated list, it must contain a single email address only.<br/>
338 text is a string, it contains the body of the message.<br/>
339 mimetype, a string, is a standard MIME type, for example, text/plain.
340 ';
341     // WARNING; this functionality depends on the sendmail -t option
342     // it may not work with Windows machines properly; particularly
343     // the Bcc option. Sneak on your friends at your own risk!
344     function mail_send($m)
345     {
346         global $xmlrpcerruser, $xmlrpcBoolean;
347         $err="";
348
349         $mTo=$m->getParam(0);
350         $mSub=$m->getParam(1);
351         $mBody=$m->getParam(2);
352         $mFrom=$m->getParam(3);
353         $mCc=$m->getParam(4);
354         $mBcc=$m->getParam(5);
355         $mMime=$m->getParam(6);
356
357         if ($mTo->scalarval()=="")
358         {
359             $err="Error, no 'To' field specified";
360         }
361
362         if ($mFrom->scalarval()=="")
363         {
364             $err="Error, no 'From' field specified";
365         }
366
367         $msghdr="From: " . $mFrom->scalarval() . "\n";
368         $msghdr.="To: ". $mTo->scalarval() . "\n";
369
370         if ($mCc->scalarval()!="")
371         {
372             $msghdr.="Cc: " . $mCc->scalarval(). "\n";
373         }
374         if ($mBcc->scalarval()!="")
375         {
376             $msghdr.="Bcc: " . $mBcc->scalarval(). "\n";
377         }
378         if ($mMime->scalarval()!="")
379         {
380             $msghdr.="Content-type: " . $mMime->scalarval() . "\n";
381         }
382         $msghdr.="X-Mailer: XML-RPC for PHP mailer 1.0";
383
384         if ($err=="")
385         {
386             if (!mail("",
387                 $mSub->scalarval(),
388                 $mBody->scalarval(),
389                 $msghdr))
390             {
391                 $err="Error, could not send the mail.";
392             }
393         }
394
395         if ($err)
396         {
397             return new xmlrpcresp(0, $xmlrpcerruser, $err);
398         }
399         else
400         {
401             return new xmlrpcresp(new xmlrpcval("true", $xmlrpcBoolean));
402         }
403     }
404
405     $getallheaders_sig=array(array($xmlrpcStruct));
406     $getallheaders_doc='Returns a struct containing all the HTTP headers received with the request. Provides limited functionality with IIS';
407     function getallheaders_xmlrpc($m)
408     {
409         global $xmlrpcerruser;
410         if (function_exists('getallheaders'))
411         {
412             return new xmlrpcresp(php_xmlrpc_encode(getallheaders()));
413         }
414         else
415         {
416             $headers = array();
417             // IIS: poor man's version of getallheaders
418             foreach ($_SERVER as $key => $val)
419                 if (strpos($key, 'HTTP_') === 0)
420                 {
421                     $key = ucfirst(str_replace('_', '-', strtolower(substr($key, 5))));
422                     $headers[$key] = $val;
423                 }
424             return new xmlrpcresp(php_xmlrpc_encode($headers));
425         }
426     }
427
428     $setcookies_sig=array(array($xmlrpcInt, $xmlrpcStruct));
429     $setcookies_doc='Sends to client a response containing a single \'1\' digit, and sets to it http cookies as received in the request (array of structs describing a cookie)';
430     function setcookies($m)
431     {
432         $m = $m->getParam(0);
433         while(list($name,$value) = $m->structeach())
434         {
435             $cookiedesc = php_xmlrpc_decode($value);
436             setcookie($name, @$cookiedesc['value'], @$cookiedesc['expires'], @$cookiedesc['path'], @$cookiedesc['domain'], @$cookiedesc['secure']);
437         }
438         return new xmlrpcresp(new xmlrpcval(1, 'int'));
439     }
440
441     $getcookies_sig=array(array($xmlrpcStruct));
442     $getcookies_doc='Sends to client a response containing all http cookies as received in the request (as struct)';
443     function getcookies($m)
444     {
445         return new xmlrpcresp(php_xmlrpc_encode($_COOKIE));
446     }
447
448     $v1_arrayOfStructs_sig=array(array($xmlrpcInt, $xmlrpcArray));
449     $v1_arrayOfStructs_doc='This handler takes a single parameter, an array of structs, each of which contains at least three elements named moe, larry and curly, all <i4>s. Your handler must add all the struct elements named curly and return the result.';
450     function v1_arrayOfStructs($m)
451     {
452         $sno=$m->getParam(0);
453         $numcurly=0;
454         for($i=0; $i<$sno->arraysize(); $i++)
455         {
456             $str=$sno->arraymem($i);
457             $str->structreset();
458             while(list($key,$val)=$str->structeach())
459             {
460                 if ($key=="curly")
461                 {
462                     $numcurly+=$val->scalarval();
463                 }
464             }
465         }
466         return new xmlrpcresp(new xmlrpcval($numcurly, "int"));
467     }
468
469     $v1_easyStruct_sig=array(array($xmlrpcInt, $xmlrpcStruct));
470     $v1_easyStruct_doc='This handler takes a single parameter, a struct, containing at least three elements named moe, larry and curly, all &lt;i4&gt;s. Your handler must add the three numbers and return the result.';
471     function v1_easyStruct($m)
472     {
473         $sno=$m->getParam(0);
474         $moe=$sno->structmem("moe");
475         $larry=$sno->structmem("larry");
476         $curly=$sno->structmem("curly");
477         $num=$moe->scalarval() + $larry->scalarval() + $curly->scalarval();
478         return new xmlrpcresp(new xmlrpcval($num, "int"));
479     }
480
481     $v1_echoStruct_sig=array(array($xmlrpcStruct, $xmlrpcStruct));
482     $v1_echoStruct_doc='This handler takes a single parameter, a struct. Your handler must return the struct.';
483     function v1_echoStruct($m)
484     {
485         $sno=$m->getParam(0);
486         return new xmlrpcresp($sno);
487     }
488
489     $v1_manyTypes_sig=array(array(
490         $xmlrpcArray, $xmlrpcInt, $xmlrpcBoolean,
491         $xmlrpcString, $xmlrpcDouble, $xmlrpcDateTime,
492         $xmlrpcBase64
493     ));
494     $v1_manyTypes_doc='This handler takes six parameters, and returns an array containing all the parameters.';
495     function v1_manyTypes($m)
496     {
497         return new xmlrpcresp(new xmlrpcval(array(
498             $m->getParam(0),
499             $m->getParam(1),
500             $m->getParam(2),
501             $m->getParam(3),
502             $m->getParam(4),
503             $m->getParam(5)),
504             "array"
505         ));
506     }
507
508     $v1_moderateSizeArrayCheck_sig=array(array($xmlrpcString, $xmlrpcArray));
509     $v1_moderateSizeArrayCheck_doc='This handler takes a single parameter, which is an array containing between 100 and 200 elements. Each of the items is a string, your handler must return a string containing the concatenated text of the first and last elements.';
510     function v1_moderateSizeArrayCheck($m)
511     {
512         $ar=$m->getParam(0);
513         $sz=$ar->arraysize();
514         $first=$ar->arraymem(0);
515         $last=$ar->arraymem($sz-1);
516         return new xmlrpcresp(new xmlrpcval($first->scalarval() .
517         $last->scalarval(), "string"));
518     }
519
520     $v1_simpleStructReturn_sig=array(array($xmlrpcStruct, $xmlrpcInt));
521     $v1_simpleStructReturn_doc='This handler takes one parameter, and returns a struct containing three elements, times10, times100 and times1000, the result of multiplying the number by 10, 100 and 1000.';
522     function v1_simpleStructReturn($m)
523     {
524         $sno=$m->getParam(0);
525         $v=$sno->scalarval();
526         return new xmlrpcresp(new xmlrpcval(array(
527             "times10"   => new xmlrpcval($v*10, "int"),
528             "times100"  => new xmlrpcval($v*100, "int"),
529             "times1000" => new xmlrpcval($v*1000, "int")),
530             "struct"
531         ));
532     }
533
534     $v1_nestedStruct_sig=array(array($xmlrpcInt, $xmlrpcStruct));
535     $v1_nestedStruct_doc='This handler takes a single parameter, a struct, that models a daily calendar. At the top level, there is one struct for each year. Each year is broken down into months, and months into days. Most of the days are empty in the struct you receive, but the entry for April 1, 2000 contains a least three elements named moe, larry and curly, all &lt;i4&gt;s. Your handler must add the three numbers and return the result.';
536     function v1_nestedStruct($m)
537     {
538         $sno=$m->getParam(0);
539
540         $twoK=$sno->structmem("2000");
541         $april=$twoK->structmem("04");
542         $fools=$april->structmem("01");
543         $curly=$fools->structmem("curly");
544         $larry=$fools->structmem("larry");
545         $moe=$fools->structmem("moe");
546         return new xmlrpcresp(new xmlrpcval($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), "int"));
547     }
548
549     $v1_countTheEntities_sig=array(array($xmlrpcStruct, $xmlrpcString));
550     $v1_countTheEntities_doc='This handler takes a single parameter, a string, that contains any number of predefined entities, namely &lt;, &gt;, &amp; \' and ".<BR>Your handler must return a struct that contains five fields, all numbers: ctLeftAngleBrackets, ctRightAngleBrackets, ctAmpersands, ctApostrophes, ctQuotes.';
551     function v1_countTheEntities($m)
552     {
553         $sno=$m->getParam(0);
554         $str=$sno->scalarval();
555         $gt=0; $lt=0; $ap=0; $qu=0; $amp=0;
556         for($i=0; $i<strlen($str); $i++)
557         {
558             $c=substr($str, $i, 1);
559             switch($c)
560             {
561                 case ">":
562                     $gt++;
563                     break;
564                 case "<":
565                     $lt++;
566                     break;
567                 case "\"":
568                     $qu++;
569                     break;
570                 case "'":
571                     $ap++;
572                     break;
573                 case "&":
574                     $amp++;
575                     break;
576                 default:
577                     break;
578             }
579         }
580         return new xmlrpcresp(new xmlrpcval(array(
581             "ctLeftAngleBrackets"  => new xmlrpcval($lt, "int"),
582             "ctRightAngleBrackets" => new xmlrpcval($gt, "int"),
583             "ctAmpersands"         => new xmlrpcval($amp, "int"),
584             "ctApostrophes"        => new xmlrpcval($ap, "int"),
585             "ctQuotes"             => new xmlrpcval($qu, "int")),
586             "struct"
587         ));
588     }
589
590     // trivial interop tests
591     // http://www.xmlrpc.com/stories/storyReader$1636
592
593     $i_echoString_sig=array(array($xmlrpcString, $xmlrpcString));
594     $i_echoString_doc="Echoes string.";
595
596     $i_echoStringArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
597     $i_echoStringArray_doc="Echoes string array.";
598
599     $i_echoInteger_sig=array(array($xmlrpcInt, $xmlrpcInt));
600     $i_echoInteger_doc="Echoes integer.";
601
602     $i_echoIntegerArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
603     $i_echoIntegerArray_doc="Echoes integer array.";
604
605     $i_echoFloat_sig=array(array($xmlrpcDouble, $xmlrpcDouble));
606     $i_echoFloat_doc="Echoes float.";
607
608     $i_echoFloatArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
609     $i_echoFloatArray_doc="Echoes float array.";
610
611     $i_echoStruct_sig=array(array($xmlrpcStruct, $xmlrpcStruct));
612     $i_echoStruct_doc="Echoes struct.";
613
614     $i_echoStructArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
615     $i_echoStructArray_doc="Echoes struct array.";
616
617     $i_echoValue_doc="Echoes any value back.";
618     $i_echoValue_sig=array(array($xmlrpcValue, $xmlrpcValue));
619
620     $i_echoBase64_sig=array(array($xmlrpcBase64, $xmlrpcBase64));
621     $i_echoBase64_doc="Echoes base64.";
622
623     $i_echoDate_sig=array(array($xmlrpcDateTime, $xmlrpcDateTime));
624     $i_echoDate_doc="Echoes dateTime.";
625
626     function i_echoParam($m)
627     {
628         $s=$m->getParam(0);
629         return new xmlrpcresp($s);
630     }
631
632     function i_echoString($m) { return i_echoParam($m); }
633     function i_echoInteger($m) { return i_echoParam($m); }
634     function i_echoFloat($m) { return i_echoParam($m); }
635     function i_echoStruct($m) { return i_echoParam($m); }
636     function i_echoStringArray($m) { return i_echoParam($m); }
637     function i_echoIntegerArray($m) { return i_echoParam($m); }
638     function i_echoFloatArray($m) { return i_echoParam($m); }
639     function i_echoStructArray($m) { return i_echoParam($m); }
640     function i_echoValue($m) { return i_echoParam($m); }
641     function i_echoBase64($m) { return i_echoParam($m); }
642     function i_echoDate($m) { return i_echoParam($m); }
643
644     $i_whichToolkit_sig=array(array($xmlrpcStruct));
645     $i_whichToolkit_doc="Returns a struct containing the following strings: toolkitDocsUrl, toolkitName, toolkitVersion, toolkitOperatingSystem.";
646
647     function i_whichToolkit($m)
648     {
649         global $xmlrpcName, $xmlrpcVersion,$SERVER_SOFTWARE;
650         $ret=array(
651             "toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/",
652             "toolkitName" => $xmlrpcName,
653             "toolkitVersion" => $xmlrpcVersion,
654             "toolkitOperatingSystem" => isset ($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE']
655         );
656         return new xmlrpcresp ( php_xmlrpc_encode($ret));
657     }
658
659     $o=new xmlrpc_server_methods_container;
660     $a=array(
661         "examples.getStateName" => array(
662             "function" => "findstate",
663             "signature" => $findstate_sig,
664             "docstring" => $findstate_doc
665         ),
666         "examples.sortByAge" => array(
667             "function" => "agesorter",
668             "signature" => $agesorter_sig,
669             "docstring" => $agesorter_doc
670         ),
671         "examples.addtwo" => array(
672             "function" => "addtwo",
673             "signature" => $addtwo_sig,
674             "docstring" => $addtwo_doc
675         ),
676         "examples.addtwodouble" => array(
677             "function" => "addtwodouble",
678             "signature" => $addtwodouble_sig,
679             "docstring" => $addtwodouble_doc
680         ),
681         "examples.stringecho" => array(
682             "function" => "stringecho",
683             "signature" => $stringecho_sig,
684             "docstring" => $stringecho_doc
685         ),
686         "examples.echo" => array(
687             "function" => "echoback",
688             "signature" => $echoback_sig,
689             "docstring" => $echoback_doc
690         ),
691         "examples.decode64" => array(
692             "function" => "echosixtyfour",
693             "signature" => $echosixtyfour_sig,
694             "docstring" => $echosixtyfour_doc
695         ),
696         "examples.invertBooleans" => array(
697             "function" => "bitflipper",
698             "signature" => $bitflipper_sig,
699             "docstring" => $bitflipper_doc
700         ),
701         "examples.generatePHPWarning" => array(
702             "function" => array($o, "phpwarninggenerator")
703             //'function' => 'xmlrpc_server_methods_container::phpwarninggenerator'
704         ),
705         "examples.raiseException" => array(
706             "function" => array($o, "exceptiongenerator")
707         ),
708         "examples.getallheaders" => array(
709             "function" => 'getallheaders_xmlrpc',
710             "signature" => $getallheaders_sig,
711             "docstring" => $getallheaders_doc
712         ),
713         "examples.setcookies" => array(
714             "function" => 'setcookies',
715             "signature" => $setcookies_sig,
716             "docstring" => $setcookies_doc
717         ),
718         "examples.getcookies" => array(
719             "function" => 'getcookies',
720             "signature" => $getcookies_sig,
721             "docstring" => $getcookies_doc
722         ),
723         "mail.send" => array(
724             "function" => "mail_send",
725             "signature" => $mail_send_sig,
726             "docstring" => $mail_send_doc
727         ),
728         "validator1.arrayOfStructsTest" => array(
729             "function" => "v1_arrayOfStructs",
730             "signature" => $v1_arrayOfStructs_sig,
731             "docstring" => $v1_arrayOfStructs_doc
732         ),
733         "validator1.easyStructTest" => array(
734             "function" => "v1_easyStruct",
735             "signature" => $v1_easyStruct_sig,
736             "docstring" => $v1_easyStruct_doc
737         ),
738         "validator1.echoStructTest" => array(
739             "function" => "v1_echoStruct",
740             "signature" => $v1_echoStruct_sig,
741             "docstring" => $v1_echoStruct_doc
742         ),
743         "validator1.manyTypesTest" => array(
744             "function" => "v1_manyTypes",
745             "signature" => $v1_manyTypes_sig,
746             "docstring" => $v1_manyTypes_doc
747         ),
748         "validator1.moderateSizeArrayCheck" => array(
749             "function" => "v1_moderateSizeArrayCheck",
750             "signature" => $v1_moderateSizeArrayCheck_sig,
751             "docstring" => $v1_moderateSizeArrayCheck_doc
752         ),
753         "validator1.simpleStructReturnTest" => array(
754             "function" => "v1_simpleStructReturn",
755             "signature" => $v1_simpleStructReturn_sig,
756             "docstring" => $v1_simpleStructReturn_doc
757         ),
758         "validator1.nestedStructTest" => array(
759             "function" => "v1_nestedStruct",
760             "signature" => $v1_nestedStruct_sig,
761             "docstring" => $v1_nestedStruct_doc
762         ),
763         "validator1.countTheEntities" => array(
764             "function" => "v1_countTheEntities",
765             "signature" => $v1_countTheEntities_sig,
766             "docstring" => $v1_countTheEntities_doc
767         ),
768         "interopEchoTests.echoString" => array(
769             "function" => "i_echoString",
770             "signature" => $i_echoString_sig,
771             "docstring" => $i_echoString_doc
772         ),
773         "interopEchoTests.echoStringArray" => array(
774             "function" => "i_echoStringArray",
775             "signature" => $i_echoStringArray_sig,
776             "docstring" => $i_echoStringArray_doc
777         ),
778         "interopEchoTests.echoInteger" => array(
779             "function" => "i_echoInteger",
780             "signature" => $i_echoInteger_sig,
781             "docstring" => $i_echoInteger_doc
782         ),
783         "interopEchoTests.echoIntegerArray" => array(
784             "function" => "i_echoIntegerArray",
785             "signature" => $i_echoIntegerArray_sig,
786             "docstring" => $i_echoIntegerArray_doc
787         ),
788         "interopEchoTests.echoFloat" => array(
789             "function" => "i_echoFloat",
790             "signature" => $i_echoFloat_sig,
791             "docstring" => $i_echoFloat_doc
792         ),
793         "interopEchoTests.echoFloatArray" => array(
794             "function" => "i_echoFloatArray",
795             "signature" => $i_echoFloatArray_sig,
796             "docstring" => $i_echoFloatArray_doc
797         ),
798         "interopEchoTests.echoStruct" => array(
799             "function" => "i_echoStruct",
800             "signature" => $i_echoStruct_sig,
801             "docstring" => $i_echoStruct_doc
802         ),
803         "interopEchoTests.echoStructArray" => array(
804             "function" => "i_echoStructArray",
805             "signature" => $i_echoStructArray_sig,
806             "docstring" => $i_echoStructArray_doc
807         ),
808         "interopEchoTests.echoValue" => array(
809             "function" => "i_echoValue",
810             "signature" => $i_echoValue_sig,
811             "docstring" => $i_echoValue_doc
812         ),
813         "interopEchoTests.echoBase64" => array(
814             "function" => "i_echoBase64",
815             "signature" => $i_echoBase64_sig,
816             "docstring" => $i_echoBase64_doc
817         ),
818         "interopEchoTests.echoDate" => array(
819             "function" => "i_echoDate",
820             "signature" => $i_echoDate_sig,
821             "docstring" => $i_echoDate_doc
822         ),
823         "interopEchoTests.whichToolkit" => array(
824             "function" => "i_whichToolkit",
825             "signature" => $i_whichToolkit_sig,
826             "docstring" => $i_whichToolkit_doc
827         )
828     );
829
830     if ($findstate2_sig)
831         $a['examples.php.getStateName'] = $findstate2_sig;
832
833     if ($findstate3_sig)
834         $a['examples.php2.getStateName'] = $findstate3_sig;
835
836     if ($findstate4_sig)
837         $a['examples.php3.getStateName'] = $findstate4_sig;
838
839     if ($findstate5_sig)
840         $a['examples.php4.getStateName'] = $findstate5_sig;
841
842     $s=new xmlrpc_server($a, false);
843     $s->setdebug(3);
844     $s->compress_response = true;
845
846     // out-of-band information: let the client manipulate the server operations.
847     // we do this to help the testsuite script: do not reproduce in production!
848     if (isset($_GET['RESPONSE_ENCODING']))
849         $s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
850     if (isset($_GET['EXCEPTION_HANDLING']))
851         $s->exception_handling = $_GET['EXCEPTION_HANDLING'];
852     $s->service();
853     // that should do all we need!