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