]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/xmlrpc/validate.php
function _PageList_Column* are not private
[SourceForge/phpwiki.git] / tests / xmlrpc / validate.php
1 <?php
2
3 /*
4   This file is part of, or distributed with, libXMLRPC - a C library for
5   xml-encoded function calls.
6
7   Author: Dan Libby (dan@libby.com)
8   Epinions.com may be contacted at feedback@epinions-inc.com
9 */
10
11 /*
12   Copyright 2001 Epinions, Inc.
13
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.
18
19   1) The above copyright notice and this permission notice shall be included
20   without modification in all copies or substantial portions of the
21   Software.
22
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.
27
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
32   DAMAGES.
33
34 */
35
36 include 'xmlrpc_utils.php';
37
38 // ensure extension is loaded.
39 xu_load_extension();
40
41 /*
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
45  * result.
46  */
47 function validator1_arrayOfStructsTest($method_name, $params, $app_data) {
48    $iCurly = 0;
49
50    foreach(array_pop($params) as $iter) {
51       $iCurly += $iter["curly"];
52    }
53
54    return $iCurly;
55 }
56
57 /*
58  * This handler takes a single parameter, a string, that contains any number
59  * of predefined entities, namely <, >, &, ' and ".
60  *
61  * Your handler must return a struct that contains five fields, all numbers:
62  * ctLeftAngleBrackets, ctRightAngleBrackets, ctAmpersands, ctApostrophes,
63  * ctQuotes.
64  *
65  * To validate, the numbers must be correct.
66  */
67 function validator1_countTheEntities ($method_name, $params, $app_data) {
68    $xStruct = array();
69
70    //returns struct
71    $counts = count_chars(array_pop($params), 0);
72
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('"')];
78
79    return $xStruct;
80 }
81
82 /*
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.
86  */
87 function validator1_easyStructTest ($method_name, $params, $app_data) {
88    $iSum = 0;
89
90    $xStruct = array_pop($params);
91    if($xStruct) {
92       $iSum += $xStruct[curly];
93       $iSum += $xStruct[moe];
94       $iSum += $xStruct[larry];
95    }
96
97    return $iSum;
98 }
99
100 /*
101  * This handler takes a single parameter, a struct.  Your handler must return
102  * the struct.
103  */
104 function validator1_echoStructTest($method_name, $params, $app_data) {
105    return $params[0];
106 }
107
108
109 /*
110  * This handler takes six parameters, and returns an array containing all the
111  * parameters.
112  */
113 function validator1_manyTypesTest ($method_name, $params, $app_data) {
114    $xArray = array();
115
116    foreach($params as $iter) {
117      array_push($xArray, $iter);
118    }
119
120
121    return $xArray;
122 }
123
124 /*
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
128  * last elements.
129  */
130 function validator1_moderateSizeArrayCheck ($method_name, $params, $app_data) {
131    $xArray = array_pop($params);
132    if($xArray) {
133       $buf = $xArray[0] . $xArray[count($xArray) - 1];
134    }
135
136    return $buf;
137 }
138
139 /*
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.
146  *
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.
150  */
151 function validator1_nestedStructTest ($method_name, $params, $app_data) {
152
153    $iSum = 0;
154
155    $xStruct = array_pop($params);
156    $xYear   = $xStruct['2000'];
157    $xMonth  = $xYear['04'];
158    $xDay    = $xMonth['01'];
159
160    $iSum += $xDay["larry"];
161    $iSum += $xDay["curly"];
162    $iSum += $xDay["moe"];
163
164    return $iSum;
165 }
166
167 /*
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.
171  */
172 function validator1_simpleStructReturnTest ($method_name, $params, $app_data) {
173    $xStruct = array();
174
175    $iIncoming = array_pop($params);
176
177    $xStruct["times10"] = $iIncoming * 10;
178    $xStruct["times100"] = $iIncoming * 100;
179    $xStruct["times1000"] = $iIncoming * 1000;
180
181    return $xStruct;
182 }
183
184
185    /* create a new server object */
186    $server = xmlrpc_server_create();
187
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");
196
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");
206
207
208    /* Now, let's get the client's request from the post data.... */
209    $request_xml = $HTTP_RAW_POST_DATA;
210    if(!$request_xml) {
211       $request_xml = $HTTP_GET_VARS[xml];
212    }
213    if(!$request_xml) {
214       echo "<h1>No XML input found!</h1>";
215    }
216    else {
217       /* setup some (optional) output options */
218       $display = array();
219       if($HTTP_POST_VARS[verbosity]) {
220          $display[verbosity] = $HTTP_POST_VARS[verbosity];
221       }
222       if($HTTP_POST_VARS[escaping]) {
223          $display[escaping] = $HTTP_POST_VARS[escaping];
224       }
225       else {
226          $display[escaping] = array("non-ascii", "markup");
227       }
228       if($HTTP_POST_VARS[version]) {
229          $display[version] = $HTTP_POST_VARS[version];
230       }
231       if($HTTP_POST_VARS[encoding]) {
232          $display[encoding] = $HTTP_POST_VARS[encoding];
233       }
234       if($HTTP_POST_VARS[output_type]) {
235          $display[output_type] = $HTTP_POST_VARS[output_type];
236       }
237
238       /* handle the request */
239       $response = xmlrpc_server_call_method($server, $request_xml, $response, $display);
240
241       if($HTTP_POST_VARS[disp] === "html") {
242          if($HTTP_POST_VARS[output_type] === "php") {
243             echo "<xmp>\n";
244             var_dump($response);
245             echo "\n</xmp>\n";
246          }
247          else {
248             echo "<xmp>\n$response\n</xmp>\n";
249          }
250       }
251       else {
252          echo "$response";
253       }
254    }