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