4 This file is part of, or distributed with, libXMLRPC - a C library for
5 xml-encoded function calls.
7 Author: Dan Libby (dan@libby.com)
8 Epinions.com may be contacted at feedback@epinions-inc.com
12 Copyright 2001 Epinions, Inc.
14 Subject to the following 3 conditions, Epinions, Inc. permits you, free
15 of charge, to (a) use, copy, distribute, modify, perform and display this
16 software and associated documentation files (the "Software"), and (b)
17 permit others to whom the Software is furnished to do so as well.
19 1) The above copyright notice and this permission notice shall be included
20 without modification in all copies or substantial portions of the
23 2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF
24 ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY
25 IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR
26 PURPOSE OR NONINFRINGEMENT.
28 3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
29 SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
30 OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING
31 NEGLIGENCE), EVEN IF EPINIONS, INC. IS AWARE OF THE POSSIBILITY OF SUCH
36 include 'xmlrpc_utils.php';
38 // ensure extension is loaded.
42 * This handler takes a single parameter, an array of structs, each of which
43 * contains at least three elements named moe, larry and curly, all <i4>s.
44 * Your handler must add all the struct elements named curly and return the
47 function validator1_arrayOfStructsTest($method_name, $params, $app_data) {
50 foreach(array_pop($params) as $iter) {
51 $iCurly += $iter["curly"];
58 * This handler takes a single parameter, a string, that contains any number
59 * of predefined entities, namely <, >, &, ' and ".
61 * Your handler must return a struct that contains five fields, all numbers:
62 * ctLeftAngleBrackets, ctRightAngleBrackets, ctAmpersands, ctApostrophes,
65 * To validate, the numbers must be correct.
67 function validator1_countTheEntities ($method_name, $params, $app_data) {
71 $counts = count_chars(array_pop($params), 0);
73 $xStruct["ctLeftAngleBrackets"] = $counts[ord('<')];
74 $xStruct["ctRightAngleBrackets"] = $counts[ord('>')];
75 $xStruct["ctAmpersands"] = $counts[ord('&')];
76 $xStruct["ctApostrophes"] = $counts[ord("'")];
77 $xStruct["ctQuotes"] = $counts[ord('"')];
83 * This handler takes a single parameter, a struct, containing at least three
84 * elements named moe, larry and curly, all <i4>s. Your handler must add the
85 * three numbers and return the result.
87 function validator1_easyStructTest ($method_name, $params, $app_data) {
90 $xStruct = array_pop($params);
92 $iSum += $xStruct[curly];
93 $iSum += $xStruct[moe];
94 $iSum += $xStruct[larry];
101 * This handler takes a single parameter, a struct. Your handler must return
104 function validator1_echoStructTest($method_name, $params, $app_data) {
110 * This handler takes six parameters, and returns an array containing all the
113 function validator1_manyTypesTest ($method_name, $params, $app_data) {
116 foreach($params as $iter) {
117 array_push($xArray, $iter);
125 * This handler takes a single parameter, which is an array containing
126 * between 100 and 200 elements. Each of the items is a string, your handler
127 * must return a string containing the concatenated text of the first and
130 function validator1_moderateSizeArrayCheck ($method_name, $params, $app_data) {
131 $xArray = array_pop($params);
133 $buf = $xArray[0] . $xArray[count($xArray) - 1];
140 * This handler takes a single parameter, a struct, that models a daily
141 * calendar. At the top level, there is one struct for each year. Each year
142 * is broken down into months, and months into days. Most of the days are
143 * empty in the struct you receive, but the entry for April 1, 2000 contains
144 * a least three elements named moe, larry and curly, all <i4>s. Your
145 * handler must add the three numbers and return the result.
147 * Ken MacLeod: "This description isn't clear, I expected '2000.April.1' when
148 * in fact it's '2000.04.01'. Adding a note saying that month and day are
149 * two-digits with leading 0s, and January is 01 would help." Done.
151 function validator1_nestedStructTest ($method_name, $params, $app_data) {
155 $xStruct = array_pop($params);
156 $xYear = $xStruct['2000'];
157 $xMonth = $xYear['04'];
158 $xDay = $xMonth['01'];
160 $iSum += $xDay["larry"];
161 $iSum += $xDay["curly"];
162 $iSum += $xDay["moe"];
168 * This handler takes one parameter, and returns a struct containing three
169 * elements, times10, times100 and times1000, the result of multiplying the
170 * number by 10, 100 and 1000.
172 function validator1_simpleStructReturnTest ($method_name, $params, $app_data) {
175 $iIncoming = array_pop($params);
177 $xStruct["times10"] = $iIncoming * 10;
178 $xStruct["times100"] = $iIncoming * 100;
179 $xStruct["times1000"] = $iIncoming * 1000;
185 /* create a new server object */
186 $server = xmlrpc_server_create();
188 xmlrpc_server_register_method($server, "validator1.arrayOfStructsTest", "validator1_arrayOfStructsTest");
189 xmlrpc_server_register_method($server, "validator1.countTheEntities", "validator1_countTheEntities");
190 xmlrpc_server_register_method($server, "validator1.easyStructTest", "validator1_easyStructTest");
191 xmlrpc_server_register_method($server, "validator1.echoStructTest", "validator1_echoStructTest");
192 xmlrpc_server_register_method($server, "validator1.manyTypesTest", "validator1_manyTypesTest");
193 xmlrpc_server_register_method($server, "validator1.moderateSizeArrayCheck", "validator1_moderateSizeArrayCheck");
194 xmlrpc_server_register_method($server, "validator1.nestedStructTest", "validator1_nestedStructTest");
195 xmlrpc_server_register_method($server, "validator1.simpleStructReturnTest", "validator1_simpleStructReturnTest");
197 // name differently for soap.
198 xmlrpc_server_register_method($server, "arrayOfStructsTest", "validator1_arrayOfStructsTest");
199 xmlrpc_server_register_method($server, "countTheEntities", "validator1_countTheEntities");
200 xmlrpc_server_register_method($server, "easyStructTest", "validator1_easyStructTest");
201 xmlrpc_server_register_method($server, "echoStructTest", "validator1_echoStructTest");
202 xmlrpc_server_register_method($server, "manyTypesTest", "validator1_manyTypesTest");
203 xmlrpc_server_register_method($server, "moderateSizeArrayCheck", "validator1_moderateSizeArrayCheck");
204 xmlrpc_server_register_method($server, "nestedStructTest", "validator1_nestedStructTest");
205 xmlrpc_server_register_method($server, "simpleStructReturnTest", "validator1_simpleStructReturnTest");
208 /* Now, let's get the client's request from the post data.... */
209 $request_xml = $HTTP_RAW_POST_DATA;
211 $request_xml = $HTTP_GET_VARS[xml];
214 echo "<h1>No XML input found!</h1>";
217 /* setup some (optional) output options */
219 if($HTTP_POST_VARS[verbosity]) {
220 $display[verbosity] = $HTTP_POST_VARS[verbosity];
222 if($HTTP_POST_VARS[escaping]) {
223 $display[escaping] = $HTTP_POST_VARS[escaping];
226 $display[escaping] = array("non-ascii", "markup");
228 if($HTTP_POST_VARS[version]) {
229 $display[version] = $HTTP_POST_VARS[version];
231 if($HTTP_POST_VARS[encoding]) {
232 $display[encoding] = $HTTP_POST_VARS[encoding];
234 if($HTTP_POST_VARS[output_type]) {
235 $display[output_type] = $HTTP_POST_VARS[output_type];
238 /* handle the request */
239 $response = xmlrpc_server_call_method($server, $request_xml, $response, $display);
241 if($HTTP_POST_VARS[disp] === "html") {
242 if($HTTP_POST_VARS[output_type] === "php") {
248 echo "<xmp>\n$response\n</xmp>\n";