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