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