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