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