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