/src/xmlrpc-3.0/demo/server/server.php

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