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
37 include("xmlrpc_utils.php");
39 // ensure extension is loaded.
43 * This handler takes a single parameter, an array of structs, each of which
44 * contains at least three elements named moe, larry and curly, all <i4>s.
45 * Your handler must add all the struct elements named curly and return the
48 function validator1_arrayOfStructsTest($method_name, $params, $app_data) {
51 foreach(array_pop($params) as $iter) {
52 $iCurly += $iter["curly"];
59 * This handler takes a single parameter, a string, that contains any number
60 * of predefined entities, namely <, >, &, ' and ".
62 * Your handler must return a struct that contains five fields, all numbers:
63 * ctLeftAngleBrackets, ctRightAngleBrackets, ctAmpersands, ctApostrophes,
66 * To validate, the numbers must be correct.
68 function validator1_countTheEntities ($method_name, $params, $app_data) {
72 $counts = count_chars(array_pop($params), 0);
74 $xStruct["ctLeftAngleBrackets"] = $counts[ord('<')];
75 $xStruct["ctRightAngleBrackets"] = $counts[ord('>')];
76 $xStruct["ctAmpersands"] = $counts[ord('&')];
77 $xStruct["ctApostrophes"] = $counts[ord("'")];
78 $xStruct["ctQuotes"] = $counts[ord('"')];
84 * This handler takes a single parameter, a struct, containing at least three
85 * elements named moe, larry and curly, all <i4>s. Your handler must add the
86 * three numbers and return the result.
88 function validator1_easyStructTest ($method_name, $params, $app_data) {
91 $xStruct = array_pop($params);
93 $iSum += $xStruct[curly];
94 $iSum += $xStruct[moe];
95 $iSum += $xStruct[larry];
102 * This handler takes a single parameter, a struct. Your handler must return
105 function validator1_echoStructTest($method_name, $params, $app_data) {
111 * This handler takes six parameters, and returns an array containing all the
114 function validator1_manyTypesTest ($method_name, $params, $app_data) {
117 foreach($params as $iter) {
118 array_push($xArray, $iter);
126 * This handler takes a single parameter, which is an array containing
127 * between 100 and 200 elements. Each of the items is a string, your handler
128 * must return a string containing the concatenated text of the first and
131 function validator1_moderateSizeArrayCheck ($method_name, $params, $app_data) {
132 $xArray = array_pop($params);
134 $buf = $xArray[0] . $xArray[count($xArray) - 1];
141 * This handler takes a single parameter, a struct, that models a daily
142 * calendar. At the top level, there is one struct for each year. Each year
143 * is broken down into months, and months into days. Most of the days are
144 * empty in the struct you receive, but the entry for April 1, 2000 contains
145 * a least three elements named moe, larry and curly, all <i4>s. Your
146 * handler must add the three numbers and return the result.
148 * Ken MacLeod: "This description isn't clear, I expected '2000.April.1' when
149 * in fact it's '2000.04.01'. Adding a note saying that month and day are
150 * two-digits with leading 0s, and January is 01 would help." Done.
152 function validator1_nestedStructTest ($method_name, $params, $app_data) {
156 $xStruct = array_pop($params);
157 $xYear = $xStruct['2000'];
158 $xMonth = $xYear['04'];
159 $xDay = $xMonth['01'];
161 $iSum += $xDay["larry"];
162 $iSum += $xDay["curly"];
163 $iSum += $xDay["moe"];
169 * This handler takes one parameter, and returns a struct containing three
170 * elements, times10, times100 and times1000, the result of multiplying the
171 * number by 10, 100 and 1000.
173 function validator1_simpleStructReturnTest ($method_name, $params, $app_data) {
176 $iIncoming = array_pop($params);
178 $xStruct["times10"] = $iIncoming * 10;
179 $xStruct["times100"] = $iIncoming * 100;
180 $xStruct["times1000"] = $iIncoming * 1000;
186 /* create a new server object */
187 $server = xmlrpc_server_create();
189 xmlrpc_server_register_method($server, "validator1.arrayOfStructsTest", "validator1_arrayOfStructsTest");
190 xmlrpc_server_register_method($server, "validator1.countTheEntities", "validator1_countTheEntities");
191 xmlrpc_server_register_method($server, "validator1.easyStructTest", "validator1_easyStructTest");
192 xmlrpc_server_register_method($server, "validator1.echoStructTest", "validator1_echoStructTest");
193 xmlrpc_server_register_method($server, "validator1.manyTypesTest", "validator1_manyTypesTest");
194 xmlrpc_server_register_method($server, "validator1.moderateSizeArrayCheck", "validator1_moderateSizeArrayCheck");
195 xmlrpc_server_register_method($server, "validator1.nestedStructTest", "validator1_nestedStructTest");
196 xmlrpc_server_register_method($server, "validator1.simpleStructReturnTest", "validator1_simpleStructReturnTest");
198 // name differently for soap.
199 xmlrpc_server_register_method($server, "arrayOfStructsTest", "validator1_arrayOfStructsTest");
200 xmlrpc_server_register_method($server, "countTheEntities", "validator1_countTheEntities");
201 xmlrpc_server_register_method($server, "easyStructTest", "validator1_easyStructTest");
202 xmlrpc_server_register_method($server, "echoStructTest", "validator1_echoStructTest");
203 xmlrpc_server_register_method($server, "manyTypesTest", "validator1_manyTypesTest");
204 xmlrpc_server_register_method($server, "moderateSizeArrayCheck", "validator1_moderateSizeArrayCheck");
205 xmlrpc_server_register_method($server, "nestedStructTest", "validator1_nestedStructTest");
206 xmlrpc_server_register_method($server, "simpleStructReturnTest", "validator1_simpleStructReturnTest");
209 /* Now, let's get the client's request from the post data.... */
210 $request_xml = $HTTP_RAW_POST_DATA;
212 $request_xml = $HTTP_GET_VARS[xml];
215 echo "<h1>No XML input found!</h1>";
218 /* setup some (optional) output options */
220 if($HTTP_POST_VARS[verbosity]) {
221 $display[verbosity] = $HTTP_POST_VARS[verbosity];
223 if($HTTP_POST_VARS[escaping]) {
224 $display[escaping] = $HTTP_POST_VARS[escaping];
227 $display[escaping] = array("non-ascii", "markup");
229 if($HTTP_POST_VARS[version]) {
230 $display[version] = $HTTP_POST_VARS[version];
232 if($HTTP_POST_VARS[encoding]) {
233 $display[encoding] = $HTTP_POST_VARS[encoding];
235 if($HTTP_POST_VARS[output_type]) {
236 $display[output_type] = $HTTP_POST_VARS[output_type];
239 /* handle the request */
240 $response = xmlrpc_server_call_method($server, $request_xml, $response, $display);
242 if($HTTP_POST_VARS[disp] === "html") {
243 if($HTTP_POST_VARS[output_type] === "php") {
249 echo "<xmp>\n$response\n</xmp>\n";