Completed
Push — php51 ( f9fab3...0b9f5a )
by Gaetano
31s queued 29s
created
demo/client/simple_call.php 4 patches
Doc Comments   -3 removed lines patch added patch discarded remove patch
@@ -24,9 +24,6 @@
 block discarded – undo
24 24
 	 *
25 25
 	 * @param xmlrpc_client client object, properly set up to connect to server
26 26
 	 * @param string remote function name
27
-	 * @param mixed $parameter1
28
-	 * @param mixed $parameter2
29
-	 * @param mixed $parameter3 ...
30 27
 	 * @return xmlrpcresp or false on error
31 28
 	 */
32 29
 	function xmlrpccall_simple()
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -6,53 +6,53 @@
 block discarded – undo
6 6
  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
7 7
  */
8 8
 
9
-	/**
10
-	 * Takes a client object, a remote method name, and a variable numbers of
11
-	 * php values, and calls the method with the supplied parameters. The
12
-	 * parameters are native php values and the result is an xmlrpcresp object.
13
-	 *
14
-	 * Notes:
15
-	 * The function encodes the received parameters using php_xmlrpc_encode:
16
-	 * the limitations of automatic encoding apply to this function too);
17
-	 *
18
-	 * the type of the value returned by the function can be changed setting
19
-	 * beforehand the 'return_type' member of the client object to 'phpvals' -
20
-	 * see the manual for more details about this capability).
21
-	 *
22
-	 *
23
-	 * @author Toth Istvan
24
-	 *
25
-	 * @param xmlrpc_client client object, properly set up to connect to server
26
-	 * @param string remote function name
27
-	 * @param mixed $parameter1
28
-	 * @param mixed $parameter2
29
-	 * @param mixed $parameter3 ...
30
-	 * @return xmlrpcresp or false on error
31
-	 */
32
-	function xmlrpccall_simple()
33
-	{
34
-		if(func_num_args() < 2)
35
-		{
36
-			// Incorrect
37
-			return false;
38
-		}
39
-		else
40
-		{
41
-			$varargs = func_get_args();
42
-			$client = array_shift($varargs);
43
-			$remote_function_name = array_shift($varargs);
44
-			if (!is_a($client, 'xmlrpc_client') || !is_string($remote_function_name))
45
-			{
46
-				return false;
47
-			}
9
+    /**
10
+     * Takes a client object, a remote method name, and a variable numbers of
11
+     * php values, and calls the method with the supplied parameters. The
12
+     * parameters are native php values and the result is an xmlrpcresp object.
13
+     *
14
+     * Notes:
15
+     * The function encodes the received parameters using php_xmlrpc_encode:
16
+     * the limitations of automatic encoding apply to this function too);
17
+     *
18
+     * the type of the value returned by the function can be changed setting
19
+     * beforehand the 'return_type' member of the client object to 'phpvals' -
20
+     * see the manual for more details about this capability).
21
+     *
22
+     *
23
+     * @author Toth Istvan
24
+     *
25
+     * @param xmlrpc_client client object, properly set up to connect to server
26
+     * @param string remote function name
27
+     * @param mixed $parameter1
28
+     * @param mixed $parameter2
29
+     * @param mixed $parameter3 ...
30
+     * @return xmlrpcresp or false on error
31
+     */
32
+    function xmlrpccall_simple()
33
+    {
34
+        if(func_num_args() < 2)
35
+        {
36
+            // Incorrect
37
+            return false;
38
+        }
39
+        else
40
+        {
41
+            $varargs = func_get_args();
42
+            $client = array_shift($varargs);
43
+            $remote_function_name = array_shift($varargs);
44
+            if (!is_a($client, 'xmlrpc_client') || !is_string($remote_function_name))
45
+            {
46
+                return false;
47
+            }
48 48
 
49
-			$xmlrpcval_array = array();
50
-			foreach($varargs as $parameter)
51
-			{
52
-				$xmlrpcval_array[] = php_xmlrpc_encode($parameter);
53
-			}
49
+            $xmlrpcval_array = array();
50
+            foreach($varargs as $parameter)
51
+            {
52
+                $xmlrpcval_array[] = php_xmlrpc_encode($parameter);
53
+            }
54 54
 
55
-			return $client->send(new xmlrpcmsg($remote_function_name, $xmlrpcval_array));
56
-		}
57
-	}
55
+            return $client->send(new xmlrpcmsg($remote_function_name, $xmlrpcval_array));
56
+        }
57
+    }
58 58
 ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	function xmlrpccall_simple()
33 33
 	{
34
-		if(func_num_args() < 2)
34
+		if (func_num_args()<2)
35 35
 		{
36 36
 			// Incorrect
37 37
 			return false;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 			}
48 48
 
49 49
 			$xmlrpcval_array = array();
50
-			foreach($varargs as $parameter)
50
+			foreach ($varargs as $parameter)
51 51
 			{
52 52
 				$xmlrpcval_array[] = php_xmlrpc_encode($parameter);
53 53
 			}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,8 +35,7 @@
 block discarded – undo
35 35
 		{
36 36
 			// Incorrect
37 37
 			return false;
38
-		}
39
-		else
38
+		} else
40 39
 		{
41 40
 			$varargs = func_get_args();
42 41
 			$client = array_shift($varargs);
Please login to merge, or discard this patch.
lib/xmlrpc_wrappers.inc 4 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 	*
537 537
 	* @param xmlrpc_client $client     an xmlrpc client set up correctly to communicate with target server
538 538
 	* @param string        $methodname the xmlrpc method to be mapped to a php function
539
-	* @param array         $extra_options array of options that specify conversion details. valid options include
539
+	* @param integer         $extra_options array of options that specify conversion details. valid options include
540 540
 	*        integer       signum      the index of the method signature to use in mapping (if method exposes many sigs)
541 541
 	*        integer       timeout     timeout (in secs) to be used when executing function/calling remote method
542 542
 	*        string        protocol    'http' (default), 'http11' or 'https'
@@ -805,6 +805,8 @@  discard block
 block discarded – undo
805 805
 	* valid php code is emitted.
806 806
 	* Note: real spaghetti code follows...
807 807
 	* @access private
808
+	* @param xmlrpc_client $client
809
+	* @param string $methodname
808 810
 	*/
809 811
 	function build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname,
810 812
 		$msig, $mdesc='', $timeout=0, $protocol='', $client_copy_mode=0, $prefix='xmlrpc',
Please login to merge, or discard this patch.
Indentation   +917 added lines, -917 removed lines patch added patch discarded remove patch
@@ -14,921 +14,921 @@
 block discarded – undo
14 14
  * @todo implement self-parsing of php code for PHP <= 4
15 15
  */
16 16
 
17
-	// requires: xmlrpc.inc
18
-
19
-	/**
20
-	* Given a string defining a php type or phpxmlrpc type (loosely defined: strings
21
-	* accepted come from javadoc blocks), return corresponding phpxmlrpc type.
22
-	* NB: for php 'resource' types returns empty string, since resources cannot be serialized;
23
-	* for php class names returns 'struct', since php objects can be serialized as xmlrpc structs
24
-	* for php arrays always return array, even though arrays sometiles serialize as json structs
25
-	* @param string $phptype
26
-	* @return string
27
-	*/
28
-	function php_2_xmlrpc_type($phptype)
29
-	{
30
-		switch(strtolower($phptype))
31
-		{
32
-			case 'string':
33
-				return $GLOBALS['xmlrpcString'];
34
-			case 'integer':
35
-			case $GLOBALS['xmlrpcInt']: // 'int'
36
-			case $GLOBALS['xmlrpcI4']:
37
-				return $GLOBALS['xmlrpcInt'];
38
-			case 'double':
39
-				return $GLOBALS['xmlrpcDouble'];
40
-			case 'boolean':
41
-				return $GLOBALS['xmlrpcBoolean'];
42
-			case 'array':
43
-				return $GLOBALS['xmlrpcArray'];
44
-			case 'object':
45
-				return $GLOBALS['xmlrpcStruct'];
46
-			case $GLOBALS['xmlrpcBase64']:
47
-			case $GLOBALS['xmlrpcStruct']:
48
-				return strtolower($phptype);
49
-			case 'resource':
50
-				return '';
51
-			default:
52
-				if(class_exists($phptype))
53
-				{
54
-					return $GLOBALS['xmlrpcStruct'];
55
-				}
56
-				else
57
-				{
58
-					// unknown: might be any 'extended' xmlrpc type
59
-					return $GLOBALS['xmlrpcValue'];
60
-				}
61
-		}
62
-	}
63
-
64
-	/**
65
-	* Given a string defining a phpxmlrpc type return corresponding php type.
66
-	* @param string $xmlrpctype
67
-	* @return string
68
-	*/
69
-	function xmlrpc_2_php_type($xmlrpctype)
70
-	{
71
-		switch(strtolower($xmlrpctype))
72
-		{
73
-			case 'base64':
74
-			case 'datetime.iso8601':
75
-			case 'string':
76
-				return $GLOBALS['xmlrpcString'];
77
-			case 'int':
78
-			case 'i4':
79
-				return 'integer';
80
-			case 'struct':
81
-			case 'array':
82
-				return 'array';
83
-			case 'double':
84
-				return 'float';
85
-			case 'undefined':
86
-				return 'mixed';
87
-			case 'boolean':
88
-			case 'null':
89
-			default:
90
-				// unknown: might be any xmlrpc type
91
-				return strtolower($xmlrpctype);
92
-		}
93
-	}
94
-
95
-	/**
96
-	* Given a user-defined PHP function, create a PHP 'wrapper' function that can
97
-	* be exposed as xmlrpc method from an xmlrpc_server object and called from remote
98
-	* clients (as well as its corresponding signature info).
99
-	*
100
-	* Since php is a typeless language, to infer types of input and output parameters,
101
-	* it relies on parsing the javadoc-style comment block associated with the given
102
-	* function. Usage of xmlrpc native types (such as datetime.dateTime.iso8601 and base64)
103
-	* in the @param tag is also allowed, if you need the php function to receive/send
104
-	* data in that particular format (note that base64 encoding/decoding is transparently
105
-	* carried out by the lib, while datetime vals are passed around as strings)
106
-	*
107
-	* Known limitations:
108
-	* - only works for user-defined functions, not for PHP internal functions
109
-	*   (reflection does not support retrieving number/type of params for those)
110
-	* - functions returning php objects will generate special xmlrpc responses:
111
-	*   when the xmlrpc decoding of those responses is carried out by this same lib, using
112
-	*   the appropriate param in php_xmlrpc_decode, the php objects will be rebuilt.
113
-	*   In short: php objects can be serialized, too (except for their resource members),
114
-	*   using this function.
115
-	*   Other libs might choke on the very same xml that will be generated in this case
116
-	*   (i.e. it has a nonstandard attribute on struct element tags)
117
-	* - usage of javadoc @param tags using param names in a different order from the
118
-	*   function prototype is not considered valid (to be fixed?)
119
-	*
120
-	* Note that since rel. 2.0RC3 the preferred method to have the server call 'standard'
121
-	* php functions (ie. functions not expecting a single xmlrpcmsg obj as parameter)
122
-	* is by making use of the functions_parameters_type class member.
123
-	*
124
-	* @param string $funcname the name of the PHP user function to be exposed as xmlrpc method; array($obj, 'methodname') and array('class', 'methodname') are ok too
125
-	* @param string $newfuncname (optional) name for function to be created
126
-	* @param array $extra_options (optional) array of options for conversion. valid values include:
127
-	*        bool  return_source when true, php code w. function definition will be returned, not evaluated
128
-	*        bool  encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
129
-	*        bool  decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
130
-	*        bool  suppress_warnings  remove from produced xml any runtime warnings due to the php function being invoked
131
-	* @return false on error, or an array containing the name of the new php function,
132
-	*         its signature and docs, to be used in the server dispatch map
133
-	*
134
-	* @todo decide how to deal with params passed by ref: bomb out or allow?
135
-	* @todo finish using javadoc info to build method sig if all params are named but out of order
136
-	* @todo add a check for params of 'resource' type
137
-	* @todo add some trigger_errors / error_log when returning false?
138
-	* @todo what to do when the PHP function returns NULL? we are currently returning an empty string value...
139
-	* @todo add an option to suppress php warnings in invocation of user function, similar to server debug level 3?
140
-	* @todo if $newfuncname is empty, we could use create_user_func instead of eval, as it is possibly faster
141
-	* @todo add a verbatim_object_copy parameter to allow avoiding the same obj instance?
142
-	*/
143
-	function wrap_php_function($funcname, $newfuncname='', $extra_options=array())
144
-	{
145
-		$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
146
-		$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
147
-		$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
148
-		$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
149
-		$catch_warnings = isset($extra_options['suppress_warnings']) && $extra_options['suppress_warnings'] ? '@' : '';
150
-
151
-		$exists = false;
152
-		if (is_string($funcname) && strpos($funcname, '::') !== false)
153
-		{
154
-			$funcname = explode('::', $funcname);
155
-		}
156
-		if(is_array($funcname))
157
-		{
158
-			if(count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0])))
159
-			{
160
-				error_log('XML-RPC: syntax for function to be wrapped is wrong');
161
-				return false;
162
-			}
163
-			if(is_string($funcname[0]))
164
-			{
165
-				$plainfuncname = implode('::', $funcname);
166
-			}
167
-			elseif(is_object($funcname[0]))
168
-			{
169
-				$plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];
170
-			}
171
-			$exists = method_exists($funcname[0], $funcname[1]);
172
-		}
173
-		else
174
-		{
175
-			$plainfuncname = $funcname;
176
-			$exists = function_exists($funcname);
177
-		}
178
-
179
-		if(!$exists)
180
-		{
181
-			error_log('XML-RPC: function to be wrapped is not defined: '.$plainfuncname);
182
-			return false;
183
-		}
184
-		else
185
-		{
186
-			// determine name of new php function
187
-			if($newfuncname == '')
188
-			{
189
-				if(is_array($funcname))
190
-				{
191
-					if(is_string($funcname[0]))
192
-						$xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);
193
-					else
194
-						$xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];
195
-				}
196
-				else
197
-				{
198
-					$xmlrpcfuncname = "{$prefix}_$funcname";
199
-				}
200
-			}
201
-			else
202
-			{
203
-				$xmlrpcfuncname = $newfuncname;
204
-			}
205
-			while($buildit && function_exists($xmlrpcfuncname))
206
-			{
207
-				$xmlrpcfuncname .= 'x';
208
-			}
209
-
210
-			// start to introspect PHP code
211
-			if(is_array($funcname))
212
-			{
213
-				$func = new ReflectionMethod($funcname[0], $funcname[1]);
214
-				if($func->isPrivate())
215
-				{
216
-					error_log('XML-RPC: method to be wrapped is private: '.$plainfuncname);
217
-					return false;
218
-				}
219
-				if($func->isProtected())
220
-				{
221
-					error_log('XML-RPC: method to be wrapped is protected: '.$plainfuncname);
222
-					return false;
223
-				}
224
-	 			if($func->isConstructor())
225
-				{
226
-					error_log('XML-RPC: method to be wrapped is the constructor: '.$plainfuncname);
227
-					return false;
228
-				}
229
-				if($func->isDestructor())
230
-				{
231
-					error_log('XML-RPC: method to be wrapped is the destructor: '.$plainfuncname);
232
-					return false;
233
-				}
234
-				if($func->isAbstract())
235
-				{
236
-					error_log('XML-RPC: method to be wrapped is abstract: '.$plainfuncname);
237
-					return false;
238
-				}
239
-				/// @todo add more checks for static vs. nonstatic?
240
-			}
241
-			else
242
-			{
243
-				$func = new ReflectionFunction($funcname);
244
-			}
245
-			if($func->isInternal())
246
-			{
247
-				// Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs
248
-				// instead of getparameters to fully reflect internal php functions ?
249
-				error_log('XML-RPC: function to be wrapped is internal: '.$plainfuncname);
250
-				return false;
251
-			}
252
-
253
-			// retrieve parameter names, types and description from javadoc comments
254
-
255
-			// function description
256
-			$desc = '';
257
-			// type of return val: by default 'any'
258
-			$returns = $GLOBALS['xmlrpcValue'];
259
-			// desc of return val
260
-			$returnsDocs = '';
261
-			// type + name of function parameters
262
-			$paramDocs = array();
263
-
264
-			$docs = $func->getDocComment();
265
-			if($docs != '')
266
-			{
267
-				$docs = explode("\n", $docs);
268
-				$i = 0;
269
-				foreach($docs as $doc)
270
-				{
271
-					$doc = trim($doc, " \r\t/*");
272
-					if(strlen($doc) && strpos($doc, '@') !== 0 && !$i)
273
-					{
274
-						if($desc)
275
-						{
276
-							$desc .= "\n";
277
-						}
278
-						$desc .= $doc;
279
-					}
280
-					elseif(strpos($doc, '@param') === 0)
281
-					{
282
-						// syntax: @param type [$name] desc
283
-						if(preg_match('/@param\s+(\S+)(\s+\$\S+)?\s+(.+)/', $doc, $matches))
284
-						{
285
-							if(strpos($matches[1], '|'))
286
-							{
287
-								//$paramDocs[$i]['type'] = explode('|', $matches[1]);
288
-								$paramDocs[$i]['type'] = 'mixed';
289
-							}
290
-							else
291
-							{
292
-								$paramDocs[$i]['type'] = $matches[1];
293
-							}
294
-							$paramDocs[$i]['name'] = trim($matches[2]);
295
-							$paramDocs[$i]['doc'] = $matches[3];
296
-						}
297
-						$i++;
298
-					}
299
-					elseif(strpos($doc, '@return') === 0)
300
-					{
301
-						// syntax: @return type desc
302
-						//$returns = preg_split('/\s+/', $doc);
303
-						if(preg_match('/@return\s+(\S+)\s+(.+)/', $doc, $matches))
304
-						{
305
-							$returns = php_2_xmlrpc_type($matches[1]);
306
-							if(isset($matches[2]))
307
-							{
308
-								$returnsDocs = $matches[2];
309
-							}
310
-						}
311
-					}
312
-				}
313
-			}
314
-
315
-			// execute introspection of actual function prototype
316
-			$params = array();
317
-			$i = 0;
318
-			foreach($func->getParameters() as $paramobj)
319
-			{
320
-				$params[$i] = array();
321
-				$params[$i]['name'] = '$'.$paramobj->getName();
322
-				$params[$i]['isoptional'] = $paramobj->isOptional();
323
-				$i++;
324
-			}
325
-
326
-
327
-			// start  building of PHP code to be eval'd
328
-			$innercode = '';
329
-			$i = 0;
330
-			$parsvariations = array();
331
-			$pars = array();
332
-			$pnum = count($params);
333
-			foreach($params as $param)
334
-			{
335
-				if (isset($paramDocs[$i]['name']) && $paramDocs[$i]['name'] && strtolower($paramDocs[$i]['name']) != strtolower($param['name']))
336
-				{
337
-					// param name from phpdoc info does not match param definition!
338
-					$paramDocs[$i]['type'] = 'mixed';
339
-				}
340
-
341
-				if($param['isoptional'])
342
-				{
343
-					// this particular parameter is optional. save as valid previous list of parameters
344
-					$innercode .= "if (\$paramcount > $i) {\n";
345
-					$parsvariations[] = $pars;
346
-				}
347
-				$innercode .= "\$p$i = \$msg->getParam($i);\n";
348
-				if ($decode_php_objects)
349
-				{
350
-					$innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i, array('decode_php_objs'));\n";
351
-				}
352
-				else
353
-				{
354
-					$innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i);\n";
355
-				}
356
-
357
-				$pars[] = "\$p$i";
358
-				$i++;
359
-				if($param['isoptional'])
360
-				{
361
-					$innercode .= "}\n";
362
-				}
363
-				if($i == $pnum)
364
-				{
365
-					// last allowed parameters combination
366
-					$parsvariations[] = $pars;
367
-				}
368
-			}
369
-
370
-			$sigs = array();
371
-			$psigs = array();
372
-			if(count($parsvariations) == 0)
373
-			{
374
-				// only known good synopsis = no parameters
375
-				$parsvariations[] = array();
376
-				$minpars = 0;
377
-			}
378
-			else
379
-			{
380
-				$minpars = count($parsvariations[0]);
381
-			}
382
-
383
-			if($minpars)
384
-			{
385
-				// add to code the check for min params number
386
-				// NB: this check needs to be done BEFORE decoding param values
387
-				$innercode = "\$paramcount = \$msg->getNumParams();\n" .
388
-				"if (\$paramcount < $minpars) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}');\n" . $innercode;
389
-			}
390
-			else
391
-			{
392
-				$innercode = "\$paramcount = \$msg->getNumParams();\n" . $innercode;
393
-			}
394
-
395
-			$innercode .= "\$np = false;\n";
396
-			// since there are no closures in php, if we are given an object instance,
397
-			// we store a pointer to it in a global var...
398
-			if ( is_array($funcname) && is_object($funcname[0]) )
399
-			{
400
-				$GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];
401
-				$innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";
402
-				$realfuncname = '$obj->'.$funcname[1];
403
-			}
404
-			else
405
-			{
406
-				$realfuncname = $plainfuncname;
407
-			}
408
-			foreach($parsvariations as $pars)
409
-			{
410
-				$innercode .= "if (\$paramcount == " . count($pars) . ") \$retval = {$catch_warnings}$realfuncname(" . implode(',', $pars) . "); else\n";
411
-				// build a 'generic' signature (only use an appropriate return type)
412
-				$sig = array($returns);
413
-				$psig = array($returnsDocs);
414
-				for($i=0; $i < count($pars); $i++)
415
-				{
416
-					if (isset($paramDocs[$i]['type']))
417
-					{
418
-						$sig[] = php_2_xmlrpc_type($paramDocs[$i]['type']);
419
-					}
420
-					else
421
-					{
422
-						$sig[] = $GLOBALS['xmlrpcValue'];
423
-					}
424
-					$psig[] = isset($paramDocs[$i]['doc']) ? $paramDocs[$i]['doc'] : '';
425
-				}
426
-				$sigs[] = $sig;
427
-				$psigs[] = $psig;
428
-			}
429
-			$innercode .= "\$np = true;\n";
430
-			$innercode .= "if (\$np) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}'); else {\n";
431
-			//$innercode .= "if (\$_xmlrpcs_error_occurred) return new xmlrpcresp(0, $GLOBALS['xmlrpcerr']user, \$_xmlrpcs_error_occurred); else\n";
432
-			$innercode .= "if (is_a(\$retval, '{$prefix}resp')) return \$retval; else\n";
433
-			if($returns == $GLOBALS['xmlrpcDateTime'] || $returns == $GLOBALS['xmlrpcBase64'])
434
-			{
435
-				$innercode .= "return new {$prefix}resp(new {$prefix}val(\$retval, '$returns'));";
436
-			}
437
-			else
438
-			{
439
-				if ($encode_php_objects)
440
-					$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval, array('encode_php_objs')));\n";
441
-				else
442
-					$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval));\n";
443
-			}
444
-			// shall we exclude functions returning by ref?
445
-			// if($func->returnsReference())
446
-			// 	return false;
447
-			$code = "function $xmlrpcfuncname(\$msg) {\n" . $innercode . "}\n}";
448
-			//print_r($code);
449
-			if ($buildit)
450
-			{
451
-				$allOK = 0;
452
-				eval($code.'$allOK=1;');
453
-				// alternative
454
-				//$xmlrpcfuncname = create_function('$m', $innercode);
455
-
456
-				if(!$allOK)
457
-				{
458
-					error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap php function '.$plainfuncname);
459
-					return false;
460
-				}
461
-			}
462
-
463
-			/// @todo examine if $paramDocs matches $parsvariations and build array for
464
-			/// usage as method signature, plus put together a nice string for docs
465
-
466
-			$ret = array('function' => $xmlrpcfuncname, 'signature' => $sigs, 'docstring' => $desc, 'signature_docs' => $psigs, 'source' => $code);
467
-			return $ret;
468
-		}
469
-	}
470
-
471
-	/**
472
-	* Given a user-defined PHP class or php object, map its methods onto a list of
473
-	* PHP 'wrapper' functions that can be exposed as xmlrpc methods from an xmlrpc_server
474
-	* object and called from remote clients (as well as their corresponding signature info).
475
-	*
476
-	* @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class
477
-	* @param array $extra_options see the docs for wrap_php_method for more options
478
-	*        string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance
479
-	* @return array or false on failure
480
-	*
481
-	* @todo get_class_methods will return both static and non-static methods.
482
-	*       we have to differentiate the action, depending on whether we received a class name or object
483
-	*/
484
-	function wrap_php_class($classname, $extra_options=array())
485
-	{
486
-		$methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
487
-		$methodtype = isset($extra_options['method_type']) ? $extra_options['method_type'] : 'auto';
488
-
489
-		$result = array();
490
-		$mlist = get_class_methods($classname);
491
-		foreach($mlist as $mname)
492
-		{
493
-			if ($methodfilter == '' || preg_match($methodfilter, $mname))
494
-			{
495
-				// echo $mlist."\n";
496
-				$func = new ReflectionMethod($classname, $mname);
497
-				if(!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())
498
-				{
499
-					if(($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||
500
-						(!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))))
501
-					{
502
-						$methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);
503
-						if ( $methodwrap )
504
-						{
505
-							$result[$methodwrap['function']] = $methodwrap['function'];
506
-						}
507
-					}
508
-				}
509
-			}
510
-		}
511
-		return $result;
512
-	}
513
-
514
-	/**
515
-	* Given an xmlrpc client and a method name, register a php wrapper function
516
-	* that will call it and return results using native php types for both
517
-	* params and results. The generated php function will return an xmlrpcresp
518
-	* object for failed xmlrpc calls
519
-	*
520
-	* Known limitations:
521
-	* - server must support system.methodsignature for the wanted xmlrpc method
522
-	* - for methods that expose many signatures, only one can be picked (we
523
-	*   could in principle check if signatures differ only by number of params
524
-	*   and not by type, but it would be more complication than we can spare time)
525
-	* - nested xmlrpc params: the caller of the generated php function has to
526
-	*   encode on its own the params passed to the php function if these are structs
527
-	*   or arrays whose (sub)members include values of type datetime or base64
528
-	*
529
-	* Notes: the connection properties of the given client will be copied
530
-	* and reused for the connection used during the call to the generated
531
-	* php function.
532
-	* Calling the generated php function 'might' be slow: a new xmlrpc client
533
-	* is created on every invocation and an xmlrpc-connection opened+closed.
534
-	* An extra 'debug' param is appended to param list of xmlrpc method, useful
535
-	* for debugging purposes.
536
-	*
537
-	* @param xmlrpc_client $client     an xmlrpc client set up correctly to communicate with target server
538
-	* @param string        $methodname the xmlrpc method to be mapped to a php function
539
-	* @param array         $extra_options array of options that specify conversion details. valid options include
540
-	*        integer       signum      the index of the method signature to use in mapping (if method exposes many sigs)
541
-	*        integer       timeout     timeout (in secs) to be used when executing function/calling remote method
542
-	*        string        protocol    'http' (default), 'http11' or 'https'
543
-	*        string        new_function_name the name of php function to create. If unspecified, lib will pick an appropriate name
544
-	*        string        return_source if true return php code w. function definition instead fo function name
545
-	*        bool          encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
546
-	*        bool          decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
547
-	*        mixed         return_on_fault a php value to be returned when the xmlrpc call fails/returns a fault response (by default the xmlrpcresp object is returned in this case). If a string is used, '%faultCode%' and '%faultString%' tokens will be substituted with actual error values
548
-	*        bool          debug        set it to 1 or 2 to see debug results of querying server for method synopsis
549
-	* @return string                   the name of the generated php function (or false) - OR AN ARRAY...
550
-	*/
551
-	function wrap_xmlrpc_method($client, $methodname, $extra_options=0, $timeout=0, $protocol='', $newfuncname='')
552
-	{
553
-		// mind numbing: let caller use sane calling convention (as per javadoc, 3 params),
554
-		// OR the 2.0 calling convention (no options) - we really love backward compat, don't we?
555
-		if (!is_array($extra_options))
556
-		{
557
-			$signum = $extra_options;
558
-			$extra_options = array();
559
-		}
560
-		else
561
-		{
562
-			$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
563
-			$timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
564
-			$protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
565
-			$newfuncname = isset($extra_options['new_function_name']) ? $extra_options['new_function_name'] : '';
566
-		}
567
-		//$encode_php_objects = in_array('encode_php_objects', $extra_options);
568
-		//$verbatim_client_copy = in_array('simple_client_copy', $extra_options) ? 1 :
569
-		//	in_array('build_class_code', $extra_options) ? 2 : 0;
570
-
571
-		$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
572
-		$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
573
-		// it seems like the meaning of 'simple_client_copy' here is swapped wrt client_copy_mode later on...
574
-		$simple_client_copy = isset($extra_options['simple_client_copy']) ? (int)($extra_options['simple_client_copy']) : 0;
575
-		$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
576
-		$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
577
-		if (isset($extra_options['return_on_fault']))
578
-		{
579
-			$decode_fault = true;
580
-			$fault_response = $extra_options['return_on_fault'];
581
-		}
582
-		else
583
-		{
584
-			$decode_fault = false;
585
-			$fault_response = '';
586
-		}
587
-		$debug = isset($extra_options['debug']) ? ($extra_options['debug']) : 0;
588
-
589
-		$msgclass = $prefix.'msg';
590
-		$valclass = $prefix.'val';
591
-		$decodefunc = 'php_'.$prefix.'_decode';
592
-
593
-		$msg = new $msgclass('system.methodSignature');
594
-		$msg->addparam(new $valclass($methodname));
595
-		$client->setDebug($debug);
596
-		$response =& $client->send($msg, $timeout, $protocol);
597
-		if($response->faultCode())
598
-		{
599
-			error_log('XML-RPC: could not retrieve method signature from remote server for method '.$methodname);
600
-			return false;
601
-		}
602
-		else
603
-		{
604
-			$msig = $response->value();
605
-			if ($client->return_type != 'phpvals')
606
-			{
607
-				$msig = $decodefunc($msig);
608
-			}
609
-			if(!is_array($msig) || count($msig) <= $signum)
610
-			{
611
-				error_log('XML-RPC: could not retrieve method signature nr.'.$signum.' from remote server for method '.$methodname);
612
-				return false;
613
-			}
614
-			else
615
-			{
616
-				// pick a suitable name for the new function, avoiding collisions
617
-				if($newfuncname != '')
618
-				{
619
-					$xmlrpcfuncname = $newfuncname;
620
-				}
621
-				else
622
-				{
623
-					// take care to insure that methodname is translated to valid
624
-					// php function name
625
-					$xmlrpcfuncname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
626
-						array('_', ''), $methodname);
627
-				}
628
-				while($buildit && function_exists($xmlrpcfuncname))
629
-				{
630
-					$xmlrpcfuncname .= 'x';
631
-				}
632
-
633
-				$msig = $msig[$signum];
634
-				$mdesc = '';
635
-				// if in 'offline' mode, get method description too.
636
-				// in online mode, favour speed of operation
637
-				if(!$buildit)
638
-				{
639
-					$msg = new $msgclass('system.methodHelp');
640
-					$msg->addparam(new $valclass($methodname));
641
-					$response =& $client->send($msg, $timeout, $protocol);
642
-					if (!$response->faultCode())
643
-					{
644
-						$mdesc = $response->value();
645
-						if ($client->return_type != 'phpvals')
646
-						{
647
-							$mdesc = $mdesc->scalarval();
648
-						}
649
-					}
650
-				}
651
-
652
-				$results = build_remote_method_wrapper_code($client, $methodname,
653
-					$xmlrpcfuncname, $msig, $mdesc, $timeout, $protocol, $simple_client_copy,
654
-					$prefix, $decode_php_objects, $encode_php_objects, $decode_fault,
655
-					$fault_response);
656
-
657
-				//print_r($code);
658
-				if ($buildit)
659
-				{
660
-					$allOK = 0;
661
-					eval($results['source'].'$allOK=1;');
662
-					// alternative
663
-					//$xmlrpcfuncname = create_function('$m', $innercode);
664
-					if($allOK)
665
-					{
666
-						return $xmlrpcfuncname;
667
-					}
668
-					else
669
-					{
670
-						error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap remote method '.$methodname);
671
-						return false;
672
-					}
673
-				}
674
-				else
675
-				{
676
-					$results['function'] = $xmlrpcfuncname;
677
-					return $results;
678
-				}
679
-			}
680
-		}
681
-	}
682
-
683
-	/**
684
-	* Similar to wrap_xmlrpc_method, but will generate a php class that wraps
685
-	* all xmlrpc methods exposed by the remote server as own methods.
686
-	* For more details see wrap_xmlrpc_method.
687
-	* @param xmlrpc_client $client the client obj all set to query the desired server
688
-	* @param array $extra_options list of options for wrapped code
689
-	* @return mixed false on error, the name of the created class if all ok or an array with code, class name and comments (if the appropriatevoption is set in extra_options)
690
-	*/
691
-	function wrap_xmlrpc_server($client, $extra_options=array())
692
-	{
693
-		$methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
694
-		//$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
695
-		$timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
696
-		$protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
697
-		$newclassname = isset($extra_options['new_class_name']) ? $extra_options['new_class_name'] : '';
698
-		$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
699
-		$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
700
-		$verbatim_client_copy = isset($extra_options['simple_client_copy']) ? !($extra_options['simple_client_copy']) : true;
701
-		$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
702
-		$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
703
-
704
-		$msgclass = $prefix.'msg';
705
-		//$valclass = $prefix.'val';
706
-		$decodefunc = 'php_'.$prefix.'_decode';
707
-
708
-		$msg = new $msgclass('system.listMethods');
709
-		$response =& $client->send($msg, $timeout, $protocol);
710
-		if($response->faultCode())
711
-		{
712
-			error_log('XML-RPC: could not retrieve method list from remote server');
713
-			return false;
714
-		}
715
-		else
716
-		{
717
-			$mlist = $response->value();
718
-			if ($client->return_type != 'phpvals')
719
-			{
720
-				$mlist = $decodefunc($mlist);
721
-			}
722
-			if(!is_array($mlist) || !count($mlist))
723
-			{
724
-				error_log('XML-RPC: could not retrieve meaningful method list from remote server');
725
-				return false;
726
-			}
727
-			else
728
-			{
729
-				// pick a suitable name for the new function, avoiding collisions
730
-				if($newclassname != '')
731
-				{
732
-					$xmlrpcclassname = $newclassname;
733
-				}
734
-				else
735
-				{
736
-					$xmlrpcclassname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
737
-						array('_', ''), $client->server).'_client';
738
-				}
739
-				while($buildit && class_exists($xmlrpcclassname))
740
-				{
741
-					$xmlrpcclassname .= 'x';
742
-				}
743
-
744
-				/// @todo add function setdebug() to new class, to enable/disable debugging
745
-				$source = "class $xmlrpcclassname\n{\nvar \$client;\n\n";
746
-				$source .= "function $xmlrpcclassname()\n{\n";
747
-				$source .= build_client_wrapper_code($client, $verbatim_client_copy, $prefix);
748
-				$source .= "\$this->client =& \$client;\n}\n\n";
749
-				$opts = array('simple_client_copy' => 2, 'return_source' => true,
750
-					'timeout' => $timeout, 'protocol' => $protocol,
751
-					'encode_php_objs' => $encode_php_objects, 'prefix' => $prefix,
752
-					'decode_php_objs' => $decode_php_objects
753
-					);
754
-				/// @todo build javadoc for class definition, too
755
-				foreach($mlist as $mname)
756
-				{
757
-					if ($methodfilter == '' || preg_match($methodfilter, $mname))
758
-					{
759
-						$opts['new_function_name'] = preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
760
-							array('_', ''), $mname);
761
-						$methodwrap = wrap_xmlrpc_method($client, $mname, $opts);
762
-						if ($methodwrap)
763
-						{
764
-							if (!$buildit)
765
-							{
766
-								$source .= $methodwrap['docstring'];
767
-							}
768
-							$source .= $methodwrap['source']."\n";
769
-						}
770
-						else
771
-						{
772
-							error_log('XML-RPC: will not create class method to wrap remote method '.$mname);
773
-						}
774
-					}
775
-				}
776
-				$source .= "}\n";
777
-				if ($buildit)
778
-				{
779
-					$allOK = 0;
780
-					eval($source.'$allOK=1;');
781
-					// alternative
782
-					//$xmlrpcfuncname = create_function('$m', $innercode);
783
-					if($allOK)
784
-					{
785
-						return $xmlrpcclassname;
786
-					}
787
-					else
788
-					{
789
-						error_log('XML-RPC: could not create class '.$xmlrpcclassname.' to wrap remote server '.$client->server);
790
-						return false;
791
-					}
792
-				}
793
-				else
794
-				{
795
-					return array('class' => $xmlrpcclassname, 'code' => $source, 'docstring' => '');
796
-				}
797
-			}
798
-		}
799
-	}
800
-
801
-	/**
802
-	* Given the necessary info, build php code that creates a new function to
803
-	* invoke a remote xmlrpc method.
804
-	* Take care that no full checking of input parameters is done to ensure that
805
-	* valid php code is emitted.
806
-	* Note: real spaghetti code follows...
807
-	* @access private
808
-	*/
809
-	function build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname,
810
-		$msig, $mdesc='', $timeout=0, $protocol='', $client_copy_mode=0, $prefix='xmlrpc',
811
-		$decode_php_objects=false, $encode_php_objects=false, $decode_fault=false,
812
-		$fault_response='')
813
-	{
814
-		$code = "function $xmlrpcfuncname (";
815
-		if ($client_copy_mode < 2)
816
-		{
817
-			// client copy mode 0 or 1 == partial / full client copy in emitted code
818
-			$innercode = build_client_wrapper_code($client, $client_copy_mode, $prefix);
819
-			$innercode .= "\$client->setDebug(\$debug);\n";
820
-			$this_ = '';
821
-		}
822
-		else
823
-		{
824
-			// client copy mode 2 == no client copy in emitted code
825
-			$innercode = '';
826
-			$this_ = 'this->';
827
-		}
828
-		$innercode .= "\$msg = new {$prefix}msg('$methodname');\n";
829
-
830
-		if ($mdesc != '')
831
-		{
832
-			// take care that PHP comment is not terminated unwillingly by method description
833
-			$mdesc = "/**\n* ".str_replace('*/', '* /', $mdesc)."\n";
834
-		}
835
-		else
836
-		{
837
-			$mdesc = "/**\nFunction $xmlrpcfuncname\n";
838
-		}
839
-
840
-		// param parsing
841
-		$plist = array();
842
-		$pcount = count($msig);
843
-		for($i = 1; $i < $pcount; $i++)
844
-		{
845
-			$plist[] = "\$p$i";
846
-			$ptype = $msig[$i];
847
-			if($ptype == 'i4' || $ptype == 'int' || $ptype == 'boolean' || $ptype == 'double' ||
848
-				$ptype == 'string' || $ptype == 'dateTime.iso8601' || $ptype == 'base64' || $ptype == 'null')
849
-			{
850
-				// only build directly xmlrpcvals when type is known and scalar
851
-				$innercode .= "\$p$i = new {$prefix}val(\$p$i, '$ptype');\n";
852
-			}
853
-			else
854
-			{
855
-				if ($encode_php_objects)
856
-				{
857
-					$innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i, array('encode_php_objs'));\n";
858
-				}
859
-				else
860
-				{
861
-					$innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i);\n";
862
-				}
863
-			}
864
-			$innercode .= "\$msg->addparam(\$p$i);\n";
865
-			$mdesc .= '* @param '.xmlrpc_2_php_type($ptype)." \$p$i\n";
866
-		}
867
-		if ($client_copy_mode < 2)
868
-		{
869
-			$plist[] = '$debug=0';
870
-			$mdesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n";
871
-		}
872
-		$plist = implode(', ', $plist);
873
-		$mdesc .= '* @return '.xmlrpc_2_php_type($msig[0])." (or an {$prefix}resp obj instance if call fails)\n*/\n";
874
-
875
-		$innercode .= "\$res =& \${$this_}client->send(\$msg, $timeout, '$protocol');\n";
876
-		if ($decode_fault)
877
-		{
878
-			if (is_string($fault_response) && ((strpos($fault_response, '%faultCode%') !== false) || (strpos($fault_response, '%faultString%') !== false)))
879
-			{
880
-				$respcode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '".str_replace("'", "''", $fault_response)."')";
881
-			}
882
-			else
883
-			{
884
-				$respcode = var_export($fault_response, true);
885
-			}
886
-		}
887
-		else
888
-		{
889
-			$respcode = '$res';
890
-		}
891
-		if ($decode_php_objects)
892
-		{
893
-			$innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value(), array('decode_php_objs'));";
894
-		}
895
-		else
896
-		{
897
-			$innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value());";
898
-		}
899
-
900
-		$code = $code . $plist. ") {\n" . $innercode . "\n}\n";
901
-
902
-		return array('source' => $code, 'docstring' => $mdesc);
903
-	}
904
-
905
-	/**
906
-	* Given necessary info, generate php code that will rebuild a client object
907
-	* Take care that no full checking of input parameters is done to ensure that
908
-	* valid php code is emitted.
909
-	* @access private
910
-	*/
911
-	function build_client_wrapper_code($client, $verbatim_client_copy, $prefix='xmlrpc')
912
-	{
913
-		$code = "\$client = new {$prefix}_client('".str_replace("'", "\'", $client->path).
914
-			"', '" . str_replace("'", "\'", $client->server) . "', $client->port);\n";
915
-
916
-		// copy all client fields to the client that will be generated runtime
917
-		// (this provides for future expansion or subclassing of client obj)
918
-		if ($verbatim_client_copy)
919
-		{
920
-			foreach($client as $fld => $val)
921
-			{
922
-				if($fld != 'debug' && $fld != 'return_type')
923
-				{
924
-					$val = var_export($val, true);
925
-					$code .= "\$client->$fld = $val;\n";
926
-				}
927
-			}
928
-		}
929
-		// only make sure that client always returns the correct data type
930
-		$code .= "\$client->return_type = '{$prefix}vals';\n";
931
-		//$code .= "\$client->setDebug(\$debug);\n";
932
-		return $code;
933
-	}
17
+    // requires: xmlrpc.inc
18
+
19
+    /**
20
+     * Given a string defining a php type or phpxmlrpc type (loosely defined: strings
21
+     * accepted come from javadoc blocks), return corresponding phpxmlrpc type.
22
+     * NB: for php 'resource' types returns empty string, since resources cannot be serialized;
23
+     * for php class names returns 'struct', since php objects can be serialized as xmlrpc structs
24
+     * for php arrays always return array, even though arrays sometiles serialize as json structs
25
+     * @param string $phptype
26
+     * @return string
27
+     */
28
+    function php_2_xmlrpc_type($phptype)
29
+    {
30
+        switch(strtolower($phptype))
31
+        {
32
+            case 'string':
33
+                return $GLOBALS['xmlrpcString'];
34
+            case 'integer':
35
+            case $GLOBALS['xmlrpcInt']: // 'int'
36
+            case $GLOBALS['xmlrpcI4']:
37
+                return $GLOBALS['xmlrpcInt'];
38
+            case 'double':
39
+                return $GLOBALS['xmlrpcDouble'];
40
+            case 'boolean':
41
+                return $GLOBALS['xmlrpcBoolean'];
42
+            case 'array':
43
+                return $GLOBALS['xmlrpcArray'];
44
+            case 'object':
45
+                return $GLOBALS['xmlrpcStruct'];
46
+            case $GLOBALS['xmlrpcBase64']:
47
+            case $GLOBALS['xmlrpcStruct']:
48
+                return strtolower($phptype);
49
+            case 'resource':
50
+                return '';
51
+            default:
52
+                if(class_exists($phptype))
53
+                {
54
+                    return $GLOBALS['xmlrpcStruct'];
55
+                }
56
+                else
57
+                {
58
+                    // unknown: might be any 'extended' xmlrpc type
59
+                    return $GLOBALS['xmlrpcValue'];
60
+                }
61
+        }
62
+    }
63
+
64
+    /**
65
+     * Given a string defining a phpxmlrpc type return corresponding php type.
66
+     * @param string $xmlrpctype
67
+     * @return string
68
+     */
69
+    function xmlrpc_2_php_type($xmlrpctype)
70
+    {
71
+        switch(strtolower($xmlrpctype))
72
+        {
73
+            case 'base64':
74
+            case 'datetime.iso8601':
75
+            case 'string':
76
+                return $GLOBALS['xmlrpcString'];
77
+            case 'int':
78
+            case 'i4':
79
+                return 'integer';
80
+            case 'struct':
81
+            case 'array':
82
+                return 'array';
83
+            case 'double':
84
+                return 'float';
85
+            case 'undefined':
86
+                return 'mixed';
87
+            case 'boolean':
88
+            case 'null':
89
+            default:
90
+                // unknown: might be any xmlrpc type
91
+                return strtolower($xmlrpctype);
92
+        }
93
+    }
94
+
95
+    /**
96
+     * Given a user-defined PHP function, create a PHP 'wrapper' function that can
97
+     * be exposed as xmlrpc method from an xmlrpc_server object and called from remote
98
+     * clients (as well as its corresponding signature info).
99
+     *
100
+     * Since php is a typeless language, to infer types of input and output parameters,
101
+     * it relies on parsing the javadoc-style comment block associated with the given
102
+     * function. Usage of xmlrpc native types (such as datetime.dateTime.iso8601 and base64)
103
+     * in the @param tag is also allowed, if you need the php function to receive/send
104
+     * data in that particular format (note that base64 encoding/decoding is transparently
105
+     * carried out by the lib, while datetime vals are passed around as strings)
106
+     *
107
+     * Known limitations:
108
+     * - only works for user-defined functions, not for PHP internal functions
109
+     *   (reflection does not support retrieving number/type of params for those)
110
+     * - functions returning php objects will generate special xmlrpc responses:
111
+     *   when the xmlrpc decoding of those responses is carried out by this same lib, using
112
+     *   the appropriate param in php_xmlrpc_decode, the php objects will be rebuilt.
113
+     *   In short: php objects can be serialized, too (except for their resource members),
114
+     *   using this function.
115
+     *   Other libs might choke on the very same xml that will be generated in this case
116
+     *   (i.e. it has a nonstandard attribute on struct element tags)
117
+     * - usage of javadoc @param tags using param names in a different order from the
118
+     *   function prototype is not considered valid (to be fixed?)
119
+     *
120
+     * Note that since rel. 2.0RC3 the preferred method to have the server call 'standard'
121
+     * php functions (ie. functions not expecting a single xmlrpcmsg obj as parameter)
122
+     * is by making use of the functions_parameters_type class member.
123
+     *
124
+     * @param string $funcname the name of the PHP user function to be exposed as xmlrpc method; array($obj, 'methodname') and array('class', 'methodname') are ok too
125
+     * @param string $newfuncname (optional) name for function to be created
126
+     * @param array $extra_options (optional) array of options for conversion. valid values include:
127
+     *        bool  return_source when true, php code w. function definition will be returned, not evaluated
128
+     *        bool  encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
129
+     *        bool  decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
130
+     *        bool  suppress_warnings  remove from produced xml any runtime warnings due to the php function being invoked
131
+     * @return false on error, or an array containing the name of the new php function,
132
+     *         its signature and docs, to be used in the server dispatch map
133
+     *
134
+     * @todo decide how to deal with params passed by ref: bomb out or allow?
135
+     * @todo finish using javadoc info to build method sig if all params are named but out of order
136
+     * @todo add a check for params of 'resource' type
137
+     * @todo add some trigger_errors / error_log when returning false?
138
+     * @todo what to do when the PHP function returns NULL? we are currently returning an empty string value...
139
+     * @todo add an option to suppress php warnings in invocation of user function, similar to server debug level 3?
140
+     * @todo if $newfuncname is empty, we could use create_user_func instead of eval, as it is possibly faster
141
+     * @todo add a verbatim_object_copy parameter to allow avoiding the same obj instance?
142
+     */
143
+    function wrap_php_function($funcname, $newfuncname='', $extra_options=array())
144
+    {
145
+        $buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
146
+        $prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
147
+        $encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
148
+        $decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
149
+        $catch_warnings = isset($extra_options['suppress_warnings']) && $extra_options['suppress_warnings'] ? '@' : '';
150
+
151
+        $exists = false;
152
+        if (is_string($funcname) && strpos($funcname, '::') !== false)
153
+        {
154
+            $funcname = explode('::', $funcname);
155
+        }
156
+        if(is_array($funcname))
157
+        {
158
+            if(count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0])))
159
+            {
160
+                error_log('XML-RPC: syntax for function to be wrapped is wrong');
161
+                return false;
162
+            }
163
+            if(is_string($funcname[0]))
164
+            {
165
+                $plainfuncname = implode('::', $funcname);
166
+            }
167
+            elseif(is_object($funcname[0]))
168
+            {
169
+                $plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];
170
+            }
171
+            $exists = method_exists($funcname[0], $funcname[1]);
172
+        }
173
+        else
174
+        {
175
+            $plainfuncname = $funcname;
176
+            $exists = function_exists($funcname);
177
+        }
178
+
179
+        if(!$exists)
180
+        {
181
+            error_log('XML-RPC: function to be wrapped is not defined: '.$plainfuncname);
182
+            return false;
183
+        }
184
+        else
185
+        {
186
+            // determine name of new php function
187
+            if($newfuncname == '')
188
+            {
189
+                if(is_array($funcname))
190
+                {
191
+                    if(is_string($funcname[0]))
192
+                        $xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);
193
+                    else
194
+                        $xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];
195
+                }
196
+                else
197
+                {
198
+                    $xmlrpcfuncname = "{$prefix}_$funcname";
199
+                }
200
+            }
201
+            else
202
+            {
203
+                $xmlrpcfuncname = $newfuncname;
204
+            }
205
+            while($buildit && function_exists($xmlrpcfuncname))
206
+            {
207
+                $xmlrpcfuncname .= 'x';
208
+            }
209
+
210
+            // start to introspect PHP code
211
+            if(is_array($funcname))
212
+            {
213
+                $func = new ReflectionMethod($funcname[0], $funcname[1]);
214
+                if($func->isPrivate())
215
+                {
216
+                    error_log('XML-RPC: method to be wrapped is private: '.$plainfuncname);
217
+                    return false;
218
+                }
219
+                if($func->isProtected())
220
+                {
221
+                    error_log('XML-RPC: method to be wrapped is protected: '.$plainfuncname);
222
+                    return false;
223
+                }
224
+                    if($func->isConstructor())
225
+                {
226
+                    error_log('XML-RPC: method to be wrapped is the constructor: '.$plainfuncname);
227
+                    return false;
228
+                }
229
+                if($func->isDestructor())
230
+                {
231
+                    error_log('XML-RPC: method to be wrapped is the destructor: '.$plainfuncname);
232
+                    return false;
233
+                }
234
+                if($func->isAbstract())
235
+                {
236
+                    error_log('XML-RPC: method to be wrapped is abstract: '.$plainfuncname);
237
+                    return false;
238
+                }
239
+                /// @todo add more checks for static vs. nonstatic?
240
+            }
241
+            else
242
+            {
243
+                $func = new ReflectionFunction($funcname);
244
+            }
245
+            if($func->isInternal())
246
+            {
247
+                // Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs
248
+                // instead of getparameters to fully reflect internal php functions ?
249
+                error_log('XML-RPC: function to be wrapped is internal: '.$plainfuncname);
250
+                return false;
251
+            }
252
+
253
+            // retrieve parameter names, types and description from javadoc comments
254
+
255
+            // function description
256
+            $desc = '';
257
+            // type of return val: by default 'any'
258
+            $returns = $GLOBALS['xmlrpcValue'];
259
+            // desc of return val
260
+            $returnsDocs = '';
261
+            // type + name of function parameters
262
+            $paramDocs = array();
263
+
264
+            $docs = $func->getDocComment();
265
+            if($docs != '')
266
+            {
267
+                $docs = explode("\n", $docs);
268
+                $i = 0;
269
+                foreach($docs as $doc)
270
+                {
271
+                    $doc = trim($doc, " \r\t/*");
272
+                    if(strlen($doc) && strpos($doc, '@') !== 0 && !$i)
273
+                    {
274
+                        if($desc)
275
+                        {
276
+                            $desc .= "\n";
277
+                        }
278
+                        $desc .= $doc;
279
+                    }
280
+                    elseif(strpos($doc, '@param') === 0)
281
+                    {
282
+                        // syntax: @param type [$name] desc
283
+                        if(preg_match('/@param\s+(\S+)(\s+\$\S+)?\s+(.+)/', $doc, $matches))
284
+                        {
285
+                            if(strpos($matches[1], '|'))
286
+                            {
287
+                                //$paramDocs[$i]['type'] = explode('|', $matches[1]);
288
+                                $paramDocs[$i]['type'] = 'mixed';
289
+                            }
290
+                            else
291
+                            {
292
+                                $paramDocs[$i]['type'] = $matches[1];
293
+                            }
294
+                            $paramDocs[$i]['name'] = trim($matches[2]);
295
+                            $paramDocs[$i]['doc'] = $matches[3];
296
+                        }
297
+                        $i++;
298
+                    }
299
+                    elseif(strpos($doc, '@return') === 0)
300
+                    {
301
+                        // syntax: @return type desc
302
+                        //$returns = preg_split('/\s+/', $doc);
303
+                        if(preg_match('/@return\s+(\S+)\s+(.+)/', $doc, $matches))
304
+                        {
305
+                            $returns = php_2_xmlrpc_type($matches[1]);
306
+                            if(isset($matches[2]))
307
+                            {
308
+                                $returnsDocs = $matches[2];
309
+                            }
310
+                        }
311
+                    }
312
+                }
313
+            }
314
+
315
+            // execute introspection of actual function prototype
316
+            $params = array();
317
+            $i = 0;
318
+            foreach($func->getParameters() as $paramobj)
319
+            {
320
+                $params[$i] = array();
321
+                $params[$i]['name'] = '$'.$paramobj->getName();
322
+                $params[$i]['isoptional'] = $paramobj->isOptional();
323
+                $i++;
324
+            }
325
+
326
+
327
+            // start  building of PHP code to be eval'd
328
+            $innercode = '';
329
+            $i = 0;
330
+            $parsvariations = array();
331
+            $pars = array();
332
+            $pnum = count($params);
333
+            foreach($params as $param)
334
+            {
335
+                if (isset($paramDocs[$i]['name']) && $paramDocs[$i]['name'] && strtolower($paramDocs[$i]['name']) != strtolower($param['name']))
336
+                {
337
+                    // param name from phpdoc info does not match param definition!
338
+                    $paramDocs[$i]['type'] = 'mixed';
339
+                }
340
+
341
+                if($param['isoptional'])
342
+                {
343
+                    // this particular parameter is optional. save as valid previous list of parameters
344
+                    $innercode .= "if (\$paramcount > $i) {\n";
345
+                    $parsvariations[] = $pars;
346
+                }
347
+                $innercode .= "\$p$i = \$msg->getParam($i);\n";
348
+                if ($decode_php_objects)
349
+                {
350
+                    $innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i, array('decode_php_objs'));\n";
351
+                }
352
+                else
353
+                {
354
+                    $innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i);\n";
355
+                }
356
+
357
+                $pars[] = "\$p$i";
358
+                $i++;
359
+                if($param['isoptional'])
360
+                {
361
+                    $innercode .= "}\n";
362
+                }
363
+                if($i == $pnum)
364
+                {
365
+                    // last allowed parameters combination
366
+                    $parsvariations[] = $pars;
367
+                }
368
+            }
369
+
370
+            $sigs = array();
371
+            $psigs = array();
372
+            if(count($parsvariations) == 0)
373
+            {
374
+                // only known good synopsis = no parameters
375
+                $parsvariations[] = array();
376
+                $minpars = 0;
377
+            }
378
+            else
379
+            {
380
+                $minpars = count($parsvariations[0]);
381
+            }
382
+
383
+            if($minpars)
384
+            {
385
+                // add to code the check for min params number
386
+                // NB: this check needs to be done BEFORE decoding param values
387
+                $innercode = "\$paramcount = \$msg->getNumParams();\n" .
388
+                "if (\$paramcount < $minpars) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}');\n" . $innercode;
389
+            }
390
+            else
391
+            {
392
+                $innercode = "\$paramcount = \$msg->getNumParams();\n" . $innercode;
393
+            }
394
+
395
+            $innercode .= "\$np = false;\n";
396
+            // since there are no closures in php, if we are given an object instance,
397
+            // we store a pointer to it in a global var...
398
+            if ( is_array($funcname) && is_object($funcname[0]) )
399
+            {
400
+                $GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];
401
+                $innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";
402
+                $realfuncname = '$obj->'.$funcname[1];
403
+            }
404
+            else
405
+            {
406
+                $realfuncname = $plainfuncname;
407
+            }
408
+            foreach($parsvariations as $pars)
409
+            {
410
+                $innercode .= "if (\$paramcount == " . count($pars) . ") \$retval = {$catch_warnings}$realfuncname(" . implode(',', $pars) . "); else\n";
411
+                // build a 'generic' signature (only use an appropriate return type)
412
+                $sig = array($returns);
413
+                $psig = array($returnsDocs);
414
+                for($i=0; $i < count($pars); $i++)
415
+                {
416
+                    if (isset($paramDocs[$i]['type']))
417
+                    {
418
+                        $sig[] = php_2_xmlrpc_type($paramDocs[$i]['type']);
419
+                    }
420
+                    else
421
+                    {
422
+                        $sig[] = $GLOBALS['xmlrpcValue'];
423
+                    }
424
+                    $psig[] = isset($paramDocs[$i]['doc']) ? $paramDocs[$i]['doc'] : '';
425
+                }
426
+                $sigs[] = $sig;
427
+                $psigs[] = $psig;
428
+            }
429
+            $innercode .= "\$np = true;\n";
430
+            $innercode .= "if (\$np) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}'); else {\n";
431
+            //$innercode .= "if (\$_xmlrpcs_error_occurred) return new xmlrpcresp(0, $GLOBALS['xmlrpcerr']user, \$_xmlrpcs_error_occurred); else\n";
432
+            $innercode .= "if (is_a(\$retval, '{$prefix}resp')) return \$retval; else\n";
433
+            if($returns == $GLOBALS['xmlrpcDateTime'] || $returns == $GLOBALS['xmlrpcBase64'])
434
+            {
435
+                $innercode .= "return new {$prefix}resp(new {$prefix}val(\$retval, '$returns'));";
436
+            }
437
+            else
438
+            {
439
+                if ($encode_php_objects)
440
+                    $innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval, array('encode_php_objs')));\n";
441
+                else
442
+                    $innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval));\n";
443
+            }
444
+            // shall we exclude functions returning by ref?
445
+            // if($func->returnsReference())
446
+            // 	return false;
447
+            $code = "function $xmlrpcfuncname(\$msg) {\n" . $innercode . "}\n}";
448
+            //print_r($code);
449
+            if ($buildit)
450
+            {
451
+                $allOK = 0;
452
+                eval($code.'$allOK=1;');
453
+                // alternative
454
+                //$xmlrpcfuncname = create_function('$m', $innercode);
455
+
456
+                if(!$allOK)
457
+                {
458
+                    error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap php function '.$plainfuncname);
459
+                    return false;
460
+                }
461
+            }
462
+
463
+            /// @todo examine if $paramDocs matches $parsvariations and build array for
464
+            /// usage as method signature, plus put together a nice string for docs
465
+
466
+            $ret = array('function' => $xmlrpcfuncname, 'signature' => $sigs, 'docstring' => $desc, 'signature_docs' => $psigs, 'source' => $code);
467
+            return $ret;
468
+        }
469
+    }
470
+
471
+    /**
472
+     * Given a user-defined PHP class or php object, map its methods onto a list of
473
+     * PHP 'wrapper' functions that can be exposed as xmlrpc methods from an xmlrpc_server
474
+     * object and called from remote clients (as well as their corresponding signature info).
475
+     *
476
+     * @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class
477
+     * @param array $extra_options see the docs for wrap_php_method for more options
478
+     *        string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance
479
+     * @return array or false on failure
480
+     *
481
+     * @todo get_class_methods will return both static and non-static methods.
482
+     *       we have to differentiate the action, depending on whether we received a class name or object
483
+     */
484
+    function wrap_php_class($classname, $extra_options=array())
485
+    {
486
+        $methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
487
+        $methodtype = isset($extra_options['method_type']) ? $extra_options['method_type'] : 'auto';
488
+
489
+        $result = array();
490
+        $mlist = get_class_methods($classname);
491
+        foreach($mlist as $mname)
492
+        {
493
+            if ($methodfilter == '' || preg_match($methodfilter, $mname))
494
+            {
495
+                // echo $mlist."\n";
496
+                $func = new ReflectionMethod($classname, $mname);
497
+                if(!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())
498
+                {
499
+                    if(($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||
500
+                        (!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))))
501
+                    {
502
+                        $methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);
503
+                        if ( $methodwrap )
504
+                        {
505
+                            $result[$methodwrap['function']] = $methodwrap['function'];
506
+                        }
507
+                    }
508
+                }
509
+            }
510
+        }
511
+        return $result;
512
+    }
513
+
514
+    /**
515
+     * Given an xmlrpc client and a method name, register a php wrapper function
516
+     * that will call it and return results using native php types for both
517
+     * params and results. The generated php function will return an xmlrpcresp
518
+     * object for failed xmlrpc calls
519
+     *
520
+     * Known limitations:
521
+     * - server must support system.methodsignature for the wanted xmlrpc method
522
+     * - for methods that expose many signatures, only one can be picked (we
523
+     *   could in principle check if signatures differ only by number of params
524
+     *   and not by type, but it would be more complication than we can spare time)
525
+     * - nested xmlrpc params: the caller of the generated php function has to
526
+     *   encode on its own the params passed to the php function if these are structs
527
+     *   or arrays whose (sub)members include values of type datetime or base64
528
+     *
529
+     * Notes: the connection properties of the given client will be copied
530
+     * and reused for the connection used during the call to the generated
531
+     * php function.
532
+     * Calling the generated php function 'might' be slow: a new xmlrpc client
533
+     * is created on every invocation and an xmlrpc-connection opened+closed.
534
+     * An extra 'debug' param is appended to param list of xmlrpc method, useful
535
+     * for debugging purposes.
536
+     *
537
+     * @param xmlrpc_client $client     an xmlrpc client set up correctly to communicate with target server
538
+     * @param string        $methodname the xmlrpc method to be mapped to a php function
539
+     * @param array         $extra_options array of options that specify conversion details. valid options include
540
+     *        integer       signum      the index of the method signature to use in mapping (if method exposes many sigs)
541
+     *        integer       timeout     timeout (in secs) to be used when executing function/calling remote method
542
+     *        string        protocol    'http' (default), 'http11' or 'https'
543
+     *        string        new_function_name the name of php function to create. If unspecified, lib will pick an appropriate name
544
+     *        string        return_source if true return php code w. function definition instead fo function name
545
+     *        bool          encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
546
+     *        bool          decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
547
+     *        mixed         return_on_fault a php value to be returned when the xmlrpc call fails/returns a fault response (by default the xmlrpcresp object is returned in this case). If a string is used, '%faultCode%' and '%faultString%' tokens will be substituted with actual error values
548
+     *        bool          debug        set it to 1 or 2 to see debug results of querying server for method synopsis
549
+     * @return string                   the name of the generated php function (or false) - OR AN ARRAY...
550
+     */
551
+    function wrap_xmlrpc_method($client, $methodname, $extra_options=0, $timeout=0, $protocol='', $newfuncname='')
552
+    {
553
+        // mind numbing: let caller use sane calling convention (as per javadoc, 3 params),
554
+        // OR the 2.0 calling convention (no options) - we really love backward compat, don't we?
555
+        if (!is_array($extra_options))
556
+        {
557
+            $signum = $extra_options;
558
+            $extra_options = array();
559
+        }
560
+        else
561
+        {
562
+            $signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
563
+            $timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
564
+            $protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
565
+            $newfuncname = isset($extra_options['new_function_name']) ? $extra_options['new_function_name'] : '';
566
+        }
567
+        //$encode_php_objects = in_array('encode_php_objects', $extra_options);
568
+        //$verbatim_client_copy = in_array('simple_client_copy', $extra_options) ? 1 :
569
+        //	in_array('build_class_code', $extra_options) ? 2 : 0;
570
+
571
+        $encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
572
+        $decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
573
+        // it seems like the meaning of 'simple_client_copy' here is swapped wrt client_copy_mode later on...
574
+        $simple_client_copy = isset($extra_options['simple_client_copy']) ? (int)($extra_options['simple_client_copy']) : 0;
575
+        $buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
576
+        $prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
577
+        if (isset($extra_options['return_on_fault']))
578
+        {
579
+            $decode_fault = true;
580
+            $fault_response = $extra_options['return_on_fault'];
581
+        }
582
+        else
583
+        {
584
+            $decode_fault = false;
585
+            $fault_response = '';
586
+        }
587
+        $debug = isset($extra_options['debug']) ? ($extra_options['debug']) : 0;
588
+
589
+        $msgclass = $prefix.'msg';
590
+        $valclass = $prefix.'val';
591
+        $decodefunc = 'php_'.$prefix.'_decode';
592
+
593
+        $msg = new $msgclass('system.methodSignature');
594
+        $msg->addparam(new $valclass($methodname));
595
+        $client->setDebug($debug);
596
+        $response =& $client->send($msg, $timeout, $protocol);
597
+        if($response->faultCode())
598
+        {
599
+            error_log('XML-RPC: could not retrieve method signature from remote server for method '.$methodname);
600
+            return false;
601
+        }
602
+        else
603
+        {
604
+            $msig = $response->value();
605
+            if ($client->return_type != 'phpvals')
606
+            {
607
+                $msig = $decodefunc($msig);
608
+            }
609
+            if(!is_array($msig) || count($msig) <= $signum)
610
+            {
611
+                error_log('XML-RPC: could not retrieve method signature nr.'.$signum.' from remote server for method '.$methodname);
612
+                return false;
613
+            }
614
+            else
615
+            {
616
+                // pick a suitable name for the new function, avoiding collisions
617
+                if($newfuncname != '')
618
+                {
619
+                    $xmlrpcfuncname = $newfuncname;
620
+                }
621
+                else
622
+                {
623
+                    // take care to insure that methodname is translated to valid
624
+                    // php function name
625
+                    $xmlrpcfuncname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
626
+                        array('_', ''), $methodname);
627
+                }
628
+                while($buildit && function_exists($xmlrpcfuncname))
629
+                {
630
+                    $xmlrpcfuncname .= 'x';
631
+                }
632
+
633
+                $msig = $msig[$signum];
634
+                $mdesc = '';
635
+                // if in 'offline' mode, get method description too.
636
+                // in online mode, favour speed of operation
637
+                if(!$buildit)
638
+                {
639
+                    $msg = new $msgclass('system.methodHelp');
640
+                    $msg->addparam(new $valclass($methodname));
641
+                    $response =& $client->send($msg, $timeout, $protocol);
642
+                    if (!$response->faultCode())
643
+                    {
644
+                        $mdesc = $response->value();
645
+                        if ($client->return_type != 'phpvals')
646
+                        {
647
+                            $mdesc = $mdesc->scalarval();
648
+                        }
649
+                    }
650
+                }
651
+
652
+                $results = build_remote_method_wrapper_code($client, $methodname,
653
+                    $xmlrpcfuncname, $msig, $mdesc, $timeout, $protocol, $simple_client_copy,
654
+                    $prefix, $decode_php_objects, $encode_php_objects, $decode_fault,
655
+                    $fault_response);
656
+
657
+                //print_r($code);
658
+                if ($buildit)
659
+                {
660
+                    $allOK = 0;
661
+                    eval($results['source'].'$allOK=1;');
662
+                    // alternative
663
+                    //$xmlrpcfuncname = create_function('$m', $innercode);
664
+                    if($allOK)
665
+                    {
666
+                        return $xmlrpcfuncname;
667
+                    }
668
+                    else
669
+                    {
670
+                        error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap remote method '.$methodname);
671
+                        return false;
672
+                    }
673
+                }
674
+                else
675
+                {
676
+                    $results['function'] = $xmlrpcfuncname;
677
+                    return $results;
678
+                }
679
+            }
680
+        }
681
+    }
682
+
683
+    /**
684
+     * Similar to wrap_xmlrpc_method, but will generate a php class that wraps
685
+     * all xmlrpc methods exposed by the remote server as own methods.
686
+     * For more details see wrap_xmlrpc_method.
687
+     * @param xmlrpc_client $client the client obj all set to query the desired server
688
+     * @param array $extra_options list of options for wrapped code
689
+     * @return mixed false on error, the name of the created class if all ok or an array with code, class name and comments (if the appropriatevoption is set in extra_options)
690
+     */
691
+    function wrap_xmlrpc_server($client, $extra_options=array())
692
+    {
693
+        $methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
694
+        //$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
695
+        $timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
696
+        $protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
697
+        $newclassname = isset($extra_options['new_class_name']) ? $extra_options['new_class_name'] : '';
698
+        $encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
699
+        $decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
700
+        $verbatim_client_copy = isset($extra_options['simple_client_copy']) ? !($extra_options['simple_client_copy']) : true;
701
+        $buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
702
+        $prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
703
+
704
+        $msgclass = $prefix.'msg';
705
+        //$valclass = $prefix.'val';
706
+        $decodefunc = 'php_'.$prefix.'_decode';
707
+
708
+        $msg = new $msgclass('system.listMethods');
709
+        $response =& $client->send($msg, $timeout, $protocol);
710
+        if($response->faultCode())
711
+        {
712
+            error_log('XML-RPC: could not retrieve method list from remote server');
713
+            return false;
714
+        }
715
+        else
716
+        {
717
+            $mlist = $response->value();
718
+            if ($client->return_type != 'phpvals')
719
+            {
720
+                $mlist = $decodefunc($mlist);
721
+            }
722
+            if(!is_array($mlist) || !count($mlist))
723
+            {
724
+                error_log('XML-RPC: could not retrieve meaningful method list from remote server');
725
+                return false;
726
+            }
727
+            else
728
+            {
729
+                // pick a suitable name for the new function, avoiding collisions
730
+                if($newclassname != '')
731
+                {
732
+                    $xmlrpcclassname = $newclassname;
733
+                }
734
+                else
735
+                {
736
+                    $xmlrpcclassname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
737
+                        array('_', ''), $client->server).'_client';
738
+                }
739
+                while($buildit && class_exists($xmlrpcclassname))
740
+                {
741
+                    $xmlrpcclassname .= 'x';
742
+                }
743
+
744
+                /// @todo add function setdebug() to new class, to enable/disable debugging
745
+                $source = "class $xmlrpcclassname\n{\nvar \$client;\n\n";
746
+                $source .= "function $xmlrpcclassname()\n{\n";
747
+                $source .= build_client_wrapper_code($client, $verbatim_client_copy, $prefix);
748
+                $source .= "\$this->client =& \$client;\n}\n\n";
749
+                $opts = array('simple_client_copy' => 2, 'return_source' => true,
750
+                    'timeout' => $timeout, 'protocol' => $protocol,
751
+                    'encode_php_objs' => $encode_php_objects, 'prefix' => $prefix,
752
+                    'decode_php_objs' => $decode_php_objects
753
+                    );
754
+                /// @todo build javadoc for class definition, too
755
+                foreach($mlist as $mname)
756
+                {
757
+                    if ($methodfilter == '' || preg_match($methodfilter, $mname))
758
+                    {
759
+                        $opts['new_function_name'] = preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
760
+                            array('_', ''), $mname);
761
+                        $methodwrap = wrap_xmlrpc_method($client, $mname, $opts);
762
+                        if ($methodwrap)
763
+                        {
764
+                            if (!$buildit)
765
+                            {
766
+                                $source .= $methodwrap['docstring'];
767
+                            }
768
+                            $source .= $methodwrap['source']."\n";
769
+                        }
770
+                        else
771
+                        {
772
+                            error_log('XML-RPC: will not create class method to wrap remote method '.$mname);
773
+                        }
774
+                    }
775
+                }
776
+                $source .= "}\n";
777
+                if ($buildit)
778
+                {
779
+                    $allOK = 0;
780
+                    eval($source.'$allOK=1;');
781
+                    // alternative
782
+                    //$xmlrpcfuncname = create_function('$m', $innercode);
783
+                    if($allOK)
784
+                    {
785
+                        return $xmlrpcclassname;
786
+                    }
787
+                    else
788
+                    {
789
+                        error_log('XML-RPC: could not create class '.$xmlrpcclassname.' to wrap remote server '.$client->server);
790
+                        return false;
791
+                    }
792
+                }
793
+                else
794
+                {
795
+                    return array('class' => $xmlrpcclassname, 'code' => $source, 'docstring' => '');
796
+                }
797
+            }
798
+        }
799
+    }
800
+
801
+    /**
802
+     * Given the necessary info, build php code that creates a new function to
803
+     * invoke a remote xmlrpc method.
804
+     * Take care that no full checking of input parameters is done to ensure that
805
+     * valid php code is emitted.
806
+     * Note: real spaghetti code follows...
807
+     * @access private
808
+     */
809
+    function build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname,
810
+        $msig, $mdesc='', $timeout=0, $protocol='', $client_copy_mode=0, $prefix='xmlrpc',
811
+        $decode_php_objects=false, $encode_php_objects=false, $decode_fault=false,
812
+        $fault_response='')
813
+    {
814
+        $code = "function $xmlrpcfuncname (";
815
+        if ($client_copy_mode < 2)
816
+        {
817
+            // client copy mode 0 or 1 == partial / full client copy in emitted code
818
+            $innercode = build_client_wrapper_code($client, $client_copy_mode, $prefix);
819
+            $innercode .= "\$client->setDebug(\$debug);\n";
820
+            $this_ = '';
821
+        }
822
+        else
823
+        {
824
+            // client copy mode 2 == no client copy in emitted code
825
+            $innercode = '';
826
+            $this_ = 'this->';
827
+        }
828
+        $innercode .= "\$msg = new {$prefix}msg('$methodname');\n";
829
+
830
+        if ($mdesc != '')
831
+        {
832
+            // take care that PHP comment is not terminated unwillingly by method description
833
+            $mdesc = "/**\n* ".str_replace('*/', '* /', $mdesc)."\n";
834
+        }
835
+        else
836
+        {
837
+            $mdesc = "/**\nFunction $xmlrpcfuncname\n";
838
+        }
839
+
840
+        // param parsing
841
+        $plist = array();
842
+        $pcount = count($msig);
843
+        for($i = 1; $i < $pcount; $i++)
844
+        {
845
+            $plist[] = "\$p$i";
846
+            $ptype = $msig[$i];
847
+            if($ptype == 'i4' || $ptype == 'int' || $ptype == 'boolean' || $ptype == 'double' ||
848
+                $ptype == 'string' || $ptype == 'dateTime.iso8601' || $ptype == 'base64' || $ptype == 'null')
849
+            {
850
+                // only build directly xmlrpcvals when type is known and scalar
851
+                $innercode .= "\$p$i = new {$prefix}val(\$p$i, '$ptype');\n";
852
+            }
853
+            else
854
+            {
855
+                if ($encode_php_objects)
856
+                {
857
+                    $innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i, array('encode_php_objs'));\n";
858
+                }
859
+                else
860
+                {
861
+                    $innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i);\n";
862
+                }
863
+            }
864
+            $innercode .= "\$msg->addparam(\$p$i);\n";
865
+            $mdesc .= '* @param '.xmlrpc_2_php_type($ptype)." \$p$i\n";
866
+        }
867
+        if ($client_copy_mode < 2)
868
+        {
869
+            $plist[] = '$debug=0';
870
+            $mdesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n";
871
+        }
872
+        $plist = implode(', ', $plist);
873
+        $mdesc .= '* @return '.xmlrpc_2_php_type($msig[0])." (or an {$prefix}resp obj instance if call fails)\n*/\n";
874
+
875
+        $innercode .= "\$res =& \${$this_}client->send(\$msg, $timeout, '$protocol');\n";
876
+        if ($decode_fault)
877
+        {
878
+            if (is_string($fault_response) && ((strpos($fault_response, '%faultCode%') !== false) || (strpos($fault_response, '%faultString%') !== false)))
879
+            {
880
+                $respcode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '".str_replace("'", "''", $fault_response)."')";
881
+            }
882
+            else
883
+            {
884
+                $respcode = var_export($fault_response, true);
885
+            }
886
+        }
887
+        else
888
+        {
889
+            $respcode = '$res';
890
+        }
891
+        if ($decode_php_objects)
892
+        {
893
+            $innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value(), array('decode_php_objs'));";
894
+        }
895
+        else
896
+        {
897
+            $innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value());";
898
+        }
899
+
900
+        $code = $code . $plist. ") {\n" . $innercode . "\n}\n";
901
+
902
+        return array('source' => $code, 'docstring' => $mdesc);
903
+    }
904
+
905
+    /**
906
+     * Given necessary info, generate php code that will rebuild a client object
907
+     * Take care that no full checking of input parameters is done to ensure that
908
+     * valid php code is emitted.
909
+     * @access private
910
+     */
911
+    function build_client_wrapper_code($client, $verbatim_client_copy, $prefix='xmlrpc')
912
+    {
913
+        $code = "\$client = new {$prefix}_client('".str_replace("'", "\'", $client->path).
914
+            "', '" . str_replace("'", "\'", $client->server) . "', $client->port);\n";
915
+
916
+        // copy all client fields to the client that will be generated runtime
917
+        // (this provides for future expansion or subclassing of client obj)
918
+        if ($verbatim_client_copy)
919
+        {
920
+            foreach($client as $fld => $val)
921
+            {
922
+                if($fld != 'debug' && $fld != 'return_type')
923
+                {
924
+                    $val = var_export($val, true);
925
+                    $code .= "\$client->$fld = $val;\n";
926
+                }
927
+            }
928
+        }
929
+        // only make sure that client always returns the correct data type
930
+        $code .= "\$client->return_type = '{$prefix}vals';\n";
931
+        //$code .= "\$client->setDebug(\$debug);\n";
932
+        return $code;
933
+    }
934 934
 ?>
935 935
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	*/
28 28
 	function php_2_xmlrpc_type($phptype)
29 29
 	{
30
-		switch(strtolower($phptype))
30
+		switch (strtolower($phptype))
31 31
 		{
32 32
 			case 'string':
33 33
 				return $GLOBALS['xmlrpcString'];
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 			case 'resource':
50 50
 				return '';
51 51
 			default:
52
-				if(class_exists($phptype))
52
+				if (class_exists($phptype))
53 53
 				{
54 54
 					return $GLOBALS['xmlrpcStruct'];
55 55
 				}
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	*/
69 69
 	function xmlrpc_2_php_type($xmlrpctype)
70 70
 	{
71
-		switch(strtolower($xmlrpctype))
71
+		switch (strtolower($xmlrpctype))
72 72
 		{
73 73
 			case 'base64':
74 74
 			case 'datetime.iso8601':
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	* @todo if $newfuncname is empty, we could use create_user_func instead of eval, as it is possibly faster
141 141
 	* @todo add a verbatim_object_copy parameter to allow avoiding the same obj instance?
142 142
 	*/
143
-	function wrap_php_function($funcname, $newfuncname='', $extra_options=array())
143
+	function wrap_php_function($funcname, $newfuncname = '', $extra_options = array())
144 144
 	{
145 145
 		$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
146 146
 		$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
147
-		$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
148
-		$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
147
+		$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool) $extra_options['encode_php_objs'] : false;
148
+		$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool) $extra_options['decode_php_objs'] : false;
149 149
 		$catch_warnings = isset($extra_options['suppress_warnings']) && $extra_options['suppress_warnings'] ? '@' : '';
150 150
 
151 151
 		$exists = false;
@@ -153,20 +153,20 @@  discard block
 block discarded – undo
153 153
 		{
154 154
 			$funcname = explode('::', $funcname);
155 155
 		}
156
-		if(is_array($funcname))
156
+		if (is_array($funcname))
157 157
 		{
158
-			if(count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0])))
158
+			if (count($funcname)<2 || (!is_string($funcname[0]) && !is_object($funcname[0])))
159 159
 			{
160 160
 				error_log('XML-RPC: syntax for function to be wrapped is wrong');
161 161
 				return false;
162 162
 			}
163
-			if(is_string($funcname[0]))
163
+			if (is_string($funcname[0]))
164 164
 			{
165 165
 				$plainfuncname = implode('::', $funcname);
166 166
 			}
167
-			elseif(is_object($funcname[0]))
167
+			elseif (is_object($funcname[0]))
168 168
 			{
169
-				$plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];
169
+				$plainfuncname = get_class($funcname[0]).'->'.$funcname[1];
170 170
 			}
171 171
 			$exists = method_exists($funcname[0], $funcname[1]);
172 172
 		}
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 			$exists = function_exists($funcname);
177 177
 		}
178 178
 
179
-		if(!$exists)
179
+		if (!$exists)
180 180
 		{
181 181
 			error_log('XML-RPC: function to be wrapped is not defined: '.$plainfuncname);
182 182
 			return false;
@@ -184,14 +184,14 @@  discard block
 block discarded – undo
184 184
 		else
185 185
 		{
186 186
 			// determine name of new php function
187
-			if($newfuncname == '')
187
+			if ($newfuncname == '')
188 188
 			{
189
-				if(is_array($funcname))
189
+				if (is_array($funcname))
190 190
 				{
191
-					if(is_string($funcname[0]))
191
+					if (is_string($funcname[0]))
192 192
 						$xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);
193 193
 					else
194
-						$xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];
194
+						$xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]).'_'.$funcname[1];
195 195
 				}
196 196
 				else
197 197
 				{
@@ -202,36 +202,36 @@  discard block
 block discarded – undo
202 202
 			{
203 203
 				$xmlrpcfuncname = $newfuncname;
204 204
 			}
205
-			while($buildit && function_exists($xmlrpcfuncname))
205
+			while ($buildit && function_exists($xmlrpcfuncname))
206 206
 			{
207 207
 				$xmlrpcfuncname .= 'x';
208 208
 			}
209 209
 
210 210
 			// start to introspect PHP code
211
-			if(is_array($funcname))
211
+			if (is_array($funcname))
212 212
 			{
213 213
 				$func = new ReflectionMethod($funcname[0], $funcname[1]);
214
-				if($func->isPrivate())
214
+				if ($func->isPrivate())
215 215
 				{
216 216
 					error_log('XML-RPC: method to be wrapped is private: '.$plainfuncname);
217 217
 					return false;
218 218
 				}
219
-				if($func->isProtected())
219
+				if ($func->isProtected())
220 220
 				{
221 221
 					error_log('XML-RPC: method to be wrapped is protected: '.$plainfuncname);
222 222
 					return false;
223 223
 				}
224
-	 			if($func->isConstructor())
224
+	 			if ($func->isConstructor())
225 225
 				{
226 226
 					error_log('XML-RPC: method to be wrapped is the constructor: '.$plainfuncname);
227 227
 					return false;
228 228
 				}
229
-				if($func->isDestructor())
229
+				if ($func->isDestructor())
230 230
 				{
231 231
 					error_log('XML-RPC: method to be wrapped is the destructor: '.$plainfuncname);
232 232
 					return false;
233 233
 				}
234
-				if($func->isAbstract())
234
+				if ($func->isAbstract())
235 235
 				{
236 236
 					error_log('XML-RPC: method to be wrapped is abstract: '.$plainfuncname);
237 237
 					return false;
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 			{
243 243
 				$func = new ReflectionFunction($funcname);
244 244
 			}
245
-			if($func->isInternal())
245
+			if ($func->isInternal())
246 246
 			{
247 247
 				// Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs
248 248
 				// instead of getparameters to fully reflect internal php functions ?
@@ -262,27 +262,27 @@  discard block
 block discarded – undo
262 262
 			$paramDocs = array();
263 263
 
264 264
 			$docs = $func->getDocComment();
265
-			if($docs != '')
265
+			if ($docs != '')
266 266
 			{
267 267
 				$docs = explode("\n", $docs);
268 268
 				$i = 0;
269
-				foreach($docs as $doc)
269
+				foreach ($docs as $doc)
270 270
 				{
271 271
 					$doc = trim($doc, " \r\t/*");
272
-					if(strlen($doc) && strpos($doc, '@') !== 0 && !$i)
272
+					if (strlen($doc) && strpos($doc, '@') !== 0 && !$i)
273 273
 					{
274
-						if($desc)
274
+						if ($desc)
275 275
 						{
276 276
 							$desc .= "\n";
277 277
 						}
278 278
 						$desc .= $doc;
279 279
 					}
280
-					elseif(strpos($doc, '@param') === 0)
280
+					elseif (strpos($doc, '@param') === 0)
281 281
 					{
282 282
 						// syntax: @param type [$name] desc
283
-						if(preg_match('/@param\s+(\S+)(\s+\$\S+)?\s+(.+)/', $doc, $matches))
283
+						if (preg_match('/@param\s+(\S+)(\s+\$\S+)?\s+(.+)/', $doc, $matches))
284 284
 						{
285
-							if(strpos($matches[1], '|'))
285
+							if (strpos($matches[1], '|'))
286 286
 							{
287 287
 								//$paramDocs[$i]['type'] = explode('|', $matches[1]);
288 288
 								$paramDocs[$i]['type'] = 'mixed';
@@ -296,14 +296,14 @@  discard block
 block discarded – undo
296 296
 						}
297 297
 						$i++;
298 298
 					}
299
-					elseif(strpos($doc, '@return') === 0)
299
+					elseif (strpos($doc, '@return') === 0)
300 300
 					{
301 301
 						// syntax: @return type desc
302 302
 						//$returns = preg_split('/\s+/', $doc);
303
-						if(preg_match('/@return\s+(\S+)\s+(.+)/', $doc, $matches))
303
+						if (preg_match('/@return\s+(\S+)\s+(.+)/', $doc, $matches))
304 304
 						{
305 305
 							$returns = php_2_xmlrpc_type($matches[1]);
306
-							if(isset($matches[2]))
306
+							if (isset($matches[2]))
307 307
 							{
308 308
 								$returnsDocs = $matches[2];
309 309
 							}
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 			// execute introspection of actual function prototype
316 316
 			$params = array();
317 317
 			$i = 0;
318
-			foreach($func->getParameters() as $paramobj)
318
+			foreach ($func->getParameters() as $paramobj)
319 319
 			{
320 320
 				$params[$i] = array();
321 321
 				$params[$i]['name'] = '$'.$paramobj->getName();
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 			$parsvariations = array();
331 331
 			$pars = array();
332 332
 			$pnum = count($params);
333
-			foreach($params as $param)
333
+			foreach ($params as $param)
334 334
 			{
335 335
 				if (isset($paramDocs[$i]['name']) && $paramDocs[$i]['name'] && strtolower($paramDocs[$i]['name']) != strtolower($param['name']))
336 336
 				{
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 					$paramDocs[$i]['type'] = 'mixed';
339 339
 				}
340 340
 
341
-				if($param['isoptional'])
341
+				if ($param['isoptional'])
342 342
 				{
343 343
 					// this particular parameter is optional. save as valid previous list of parameters
344 344
 					$innercode .= "if (\$paramcount > $i) {\n";
@@ -356,11 +356,11 @@  discard block
 block discarded – undo
356 356
 
357 357
 				$pars[] = "\$p$i";
358 358
 				$i++;
359
-				if($param['isoptional'])
359
+				if ($param['isoptional'])
360 360
 				{
361 361
 					$innercode .= "}\n";
362 362
 				}
363
-				if($i == $pnum)
363
+				if ($i == $pnum)
364 364
 				{
365 365
 					// last allowed parameters combination
366 366
 					$parsvariations[] = $pars;
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 
370 370
 			$sigs = array();
371 371
 			$psigs = array();
372
-			if(count($parsvariations) == 0)
372
+			if (count($parsvariations) == 0)
373 373
 			{
374 374
 				// only known good synopsis = no parameters
375 375
 				$parsvariations[] = array();
@@ -380,24 +380,24 @@  discard block
 block discarded – undo
380 380
 				$minpars = count($parsvariations[0]);
381 381
 			}
382 382
 
383
-			if($minpars)
383
+			if ($minpars)
384 384
 			{
385 385
 				// add to code the check for min params number
386 386
 				// NB: this check needs to be done BEFORE decoding param values
387
-				$innercode = "\$paramcount = \$msg->getNumParams();\n" .
388
-				"if (\$paramcount < $minpars) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}');\n" . $innercode;
387
+				$innercode = "\$paramcount = \$msg->getNumParams();\n".
388
+				"if (\$paramcount < $minpars) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}');\n".$innercode;
389 389
 			}
390 390
 			else
391 391
 			{
392
-				$innercode = "\$paramcount = \$msg->getNumParams();\n" . $innercode;
392
+				$innercode = "\$paramcount = \$msg->getNumParams();\n".$innercode;
393 393
 			}
394 394
 
395 395
 			$innercode .= "\$np = false;\n";
396 396
 			// since there are no closures in php, if we are given an object instance,
397 397
 			// we store a pointer to it in a global var...
398
-			if ( is_array($funcname) && is_object($funcname[0]) )
398
+			if (is_array($funcname) && is_object($funcname[0]))
399 399
 			{
400
-				$GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];
400
+				$GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] = & $funcname[0];
401 401
 				$innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";
402 402
 				$realfuncname = '$obj->'.$funcname[1];
403 403
 			}
@@ -405,13 +405,13 @@  discard block
 block discarded – undo
405 405
 			{
406 406
 				$realfuncname = $plainfuncname;
407 407
 			}
408
-			foreach($parsvariations as $pars)
408
+			foreach ($parsvariations as $pars)
409 409
 			{
410
-				$innercode .= "if (\$paramcount == " . count($pars) . ") \$retval = {$catch_warnings}$realfuncname(" . implode(',', $pars) . "); else\n";
410
+				$innercode .= "if (\$paramcount == ".count($pars).") \$retval = {$catch_warnings}$realfuncname(".implode(',', $pars)."); else\n";
411 411
 				// build a 'generic' signature (only use an appropriate return type)
412 412
 				$sig = array($returns);
413 413
 				$psig = array($returnsDocs);
414
-				for($i=0; $i < count($pars); $i++)
414
+				for ($i = 0; $i<count($pars); $i++)
415 415
 				{
416 416
 					if (isset($paramDocs[$i]['type']))
417 417
 					{
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 			$innercode .= "if (\$np) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}'); else {\n";
431 431
 			//$innercode .= "if (\$_xmlrpcs_error_occurred) return new xmlrpcresp(0, $GLOBALS['xmlrpcerr']user, \$_xmlrpcs_error_occurred); else\n";
432 432
 			$innercode .= "if (is_a(\$retval, '{$prefix}resp')) return \$retval; else\n";
433
-			if($returns == $GLOBALS['xmlrpcDateTime'] || $returns == $GLOBALS['xmlrpcBase64'])
433
+			if ($returns == $GLOBALS['xmlrpcDateTime'] || $returns == $GLOBALS['xmlrpcBase64'])
434 434
 			{
435 435
 				$innercode .= "return new {$prefix}resp(new {$prefix}val(\$retval, '$returns'));";
436 436
 			}
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 			// shall we exclude functions returning by ref?
445 445
 			// if($func->returnsReference())
446 446
 			// 	return false;
447
-			$code = "function $xmlrpcfuncname(\$msg) {\n" . $innercode . "}\n}";
447
+			$code = "function $xmlrpcfuncname(\$msg) {\n".$innercode."}\n}";
448 448
 			//print_r($code);
449 449
 			if ($buildit)
450 450
 			{
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 				// alternative
454 454
 				//$xmlrpcfuncname = create_function('$m', $innercode);
455 455
 
456
-				if(!$allOK)
456
+				if (!$allOK)
457 457
 				{
458 458
 					error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap php function '.$plainfuncname);
459 459
 					return false;
@@ -481,26 +481,26 @@  discard block
 block discarded – undo
481 481
 	* @todo get_class_methods will return both static and non-static methods.
482 482
 	*       we have to differentiate the action, depending on whether we received a class name or object
483 483
 	*/
484
-	function wrap_php_class($classname, $extra_options=array())
484
+	function wrap_php_class($classname, $extra_options = array())
485 485
 	{
486 486
 		$methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
487 487
 		$methodtype = isset($extra_options['method_type']) ? $extra_options['method_type'] : 'auto';
488 488
 
489 489
 		$result = array();
490 490
 		$mlist = get_class_methods($classname);
491
-		foreach($mlist as $mname)
491
+		foreach ($mlist as $mname)
492 492
 		{
493 493
 			if ($methodfilter == '' || preg_match($methodfilter, $mname))
494 494
 			{
495 495
 				// echo $mlist."\n";
496 496
 				$func = new ReflectionMethod($classname, $mname);
497
-				if(!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())
497
+				if (!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract())
498 498
 				{
499
-					if(($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||
499
+					if (($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) ||
500 500
 						(!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))))
501 501
 					{
502 502
 						$methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);
503
-						if ( $methodwrap )
503
+						if ($methodwrap)
504 504
 						{
505 505
 							$result[$methodwrap['function']] = $methodwrap['function'];
506 506
 						}
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 	*        bool          debug        set it to 1 or 2 to see debug results of querying server for method synopsis
549 549
 	* @return string                   the name of the generated php function (or false) - OR AN ARRAY...
550 550
 	*/
551
-	function wrap_xmlrpc_method($client, $methodname, $extra_options=0, $timeout=0, $protocol='', $newfuncname='')
551
+	function wrap_xmlrpc_method($client, $methodname, $extra_options = 0, $timeout = 0, $protocol = '', $newfuncname = '')
552 552
 	{
553 553
 		// mind numbing: let caller use sane calling convention (as per javadoc, 3 params),
554 554
 		// OR the 2.0 calling convention (no options) - we really love backward compat, don't we?
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 		}
560 560
 		else
561 561
 		{
562
-			$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
563
-			$timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
562
+			$signum = isset($extra_options['signum']) ? (int) $extra_options['signum'] : 0;
563
+			$timeout = isset($extra_options['timeout']) ? (int) $extra_options['timeout'] : 0;
564 564
 			$protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
565 565
 			$newfuncname = isset($extra_options['new_function_name']) ? $extra_options['new_function_name'] : '';
566 566
 		}
@@ -568,10 +568,10 @@  discard block
 block discarded – undo
568 568
 		//$verbatim_client_copy = in_array('simple_client_copy', $extra_options) ? 1 :
569 569
 		//	in_array('build_class_code', $extra_options) ? 2 : 0;
570 570
 
571
-		$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
572
-		$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
571
+		$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool) $extra_options['encode_php_objs'] : false;
572
+		$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool) $extra_options['decode_php_objs'] : false;
573 573
 		// it seems like the meaning of 'simple_client_copy' here is swapped wrt client_copy_mode later on...
574
-		$simple_client_copy = isset($extra_options['simple_client_copy']) ? (int)($extra_options['simple_client_copy']) : 0;
574
+		$simple_client_copy = isset($extra_options['simple_client_copy']) ? (int) ($extra_options['simple_client_copy']) : 0;
575 575
 		$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
576 576
 		$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
577 577
 		if (isset($extra_options['return_on_fault']))
@@ -593,8 +593,8 @@  discard block
 block discarded – undo
593 593
 		$msg = new $msgclass('system.methodSignature');
594 594
 		$msg->addparam(new $valclass($methodname));
595 595
 		$client->setDebug($debug);
596
-		$response =& $client->send($msg, $timeout, $protocol);
597
-		if($response->faultCode())
596
+		$response = & $client->send($msg, $timeout, $protocol);
597
+		if ($response->faultCode())
598 598
 		{
599 599
 			error_log('XML-RPC: could not retrieve method signature from remote server for method '.$methodname);
600 600
 			return false;
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 			{
607 607
 				$msig = $decodefunc($msig);
608 608
 			}
609
-			if(!is_array($msig) || count($msig) <= $signum)
609
+			if (!is_array($msig) || count($msig)<=$signum)
610 610
 			{
611 611
 				error_log('XML-RPC: could not retrieve method signature nr.'.$signum.' from remote server for method '.$methodname);
612 612
 				return false;
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 			else
615 615
 			{
616 616
 				// pick a suitable name for the new function, avoiding collisions
617
-				if($newfuncname != '')
617
+				if ($newfuncname != '')
618 618
 				{
619 619
 					$xmlrpcfuncname = $newfuncname;
620 620
 				}
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 					$xmlrpcfuncname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
626 626
 						array('_', ''), $methodname);
627 627
 				}
628
-				while($buildit && function_exists($xmlrpcfuncname))
628
+				while ($buildit && function_exists($xmlrpcfuncname))
629 629
 				{
630 630
 					$xmlrpcfuncname .= 'x';
631 631
 				}
@@ -634,11 +634,11 @@  discard block
 block discarded – undo
634 634
 				$mdesc = '';
635 635
 				// if in 'offline' mode, get method description too.
636 636
 				// in online mode, favour speed of operation
637
-				if(!$buildit)
637
+				if (!$buildit)
638 638
 				{
639 639
 					$msg = new $msgclass('system.methodHelp');
640 640
 					$msg->addparam(new $valclass($methodname));
641
-					$response =& $client->send($msg, $timeout, $protocol);
641
+					$response = & $client->send($msg, $timeout, $protocol);
642 642
 					if (!$response->faultCode())
643 643
 					{
644 644
 						$mdesc = $response->value();
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
 					eval($results['source'].'$allOK=1;');
662 662
 					// alternative
663 663
 					//$xmlrpcfuncname = create_function('$m', $innercode);
664
-					if($allOK)
664
+					if ($allOK)
665 665
 					{
666 666
 						return $xmlrpcfuncname;
667 667
 					}
@@ -688,15 +688,15 @@  discard block
 block discarded – undo
688 688
 	* @param array $extra_options list of options for wrapped code
689 689
 	* @return mixed false on error, the name of the created class if all ok or an array with code, class name and comments (if the appropriatevoption is set in extra_options)
690 690
 	*/
691
-	function wrap_xmlrpc_server($client, $extra_options=array())
691
+	function wrap_xmlrpc_server($client, $extra_options = array())
692 692
 	{
693 693
 		$methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
694 694
 		//$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
695
-		$timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
695
+		$timeout = isset($extra_options['timeout']) ? (int) $extra_options['timeout'] : 0;
696 696
 		$protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : '';
697 697
 		$newclassname = isset($extra_options['new_class_name']) ? $extra_options['new_class_name'] : '';
698
-		$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false;
699
-		$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false;
698
+		$encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool) $extra_options['encode_php_objs'] : false;
699
+		$decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool) $extra_options['decode_php_objs'] : false;
700 700
 		$verbatim_client_copy = isset($extra_options['simple_client_copy']) ? !($extra_options['simple_client_copy']) : true;
701 701
 		$buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true;
702 702
 		$prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc';
@@ -706,8 +706,8 @@  discard block
 block discarded – undo
706 706
 		$decodefunc = 'php_'.$prefix.'_decode';
707 707
 
708 708
 		$msg = new $msgclass('system.listMethods');
709
-		$response =& $client->send($msg, $timeout, $protocol);
710
-		if($response->faultCode())
709
+		$response = & $client->send($msg, $timeout, $protocol);
710
+		if ($response->faultCode())
711 711
 		{
712 712
 			error_log('XML-RPC: could not retrieve method list from remote server');
713 713
 			return false;
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 			{
720 720
 				$mlist = $decodefunc($mlist);
721 721
 			}
722
-			if(!is_array($mlist) || !count($mlist))
722
+			if (!is_array($mlist) || !count($mlist))
723 723
 			{
724 724
 				error_log('XML-RPC: could not retrieve meaningful method list from remote server');
725 725
 				return false;
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 			else
728 728
 			{
729 729
 				// pick a suitable name for the new function, avoiding collisions
730
-				if($newclassname != '')
730
+				if ($newclassname != '')
731 731
 				{
732 732
 					$xmlrpcclassname = $newclassname;
733 733
 				}
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
 					$xmlrpcclassname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
737 737
 						array('_', ''), $client->server).'_client';
738 738
 				}
739
-				while($buildit && class_exists($xmlrpcclassname))
739
+				while ($buildit && class_exists($xmlrpcclassname))
740 740
 				{
741 741
 					$xmlrpcclassname .= 'x';
742 742
 				}
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 					'decode_php_objs' => $decode_php_objects
753 753
 					);
754 754
 				/// @todo build javadoc for class definition, too
755
-				foreach($mlist as $mname)
755
+				foreach ($mlist as $mname)
756 756
 				{
757 757
 					if ($methodfilter == '' || preg_match($methodfilter, $mname))
758 758
 					{
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
 					eval($source.'$allOK=1;');
781 781
 					// alternative
782 782
 					//$xmlrpcfuncname = create_function('$m', $innercode);
783
-					if($allOK)
783
+					if ($allOK)
784 784
 					{
785 785
 						return $xmlrpcclassname;
786 786
 					}
@@ -807,12 +807,12 @@  discard block
 block discarded – undo
807 807
 	* @access private
808 808
 	*/
809 809
 	function build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname,
810
-		$msig, $mdesc='', $timeout=0, $protocol='', $client_copy_mode=0, $prefix='xmlrpc',
811
-		$decode_php_objects=false, $encode_php_objects=false, $decode_fault=false,
812
-		$fault_response='')
810
+		$msig, $mdesc = '', $timeout = 0, $protocol = '', $client_copy_mode = 0, $prefix = 'xmlrpc',
811
+		$decode_php_objects = false, $encode_php_objects = false, $decode_fault = false,
812
+		$fault_response = '')
813 813
 	{
814 814
 		$code = "function $xmlrpcfuncname (";
815
-		if ($client_copy_mode < 2)
815
+		if ($client_copy_mode<2)
816 816
 		{
817 817
 			// client copy mode 0 or 1 == partial / full client copy in emitted code
818 818
 			$innercode = build_client_wrapper_code($client, $client_copy_mode, $prefix);
@@ -840,11 +840,11 @@  discard block
 block discarded – undo
840 840
 		// param parsing
841 841
 		$plist = array();
842 842
 		$pcount = count($msig);
843
-		for($i = 1; $i < $pcount; $i++)
843
+		for ($i = 1; $i<$pcount; $i++)
844 844
 		{
845 845
 			$plist[] = "\$p$i";
846 846
 			$ptype = $msig[$i];
847
-			if($ptype == 'i4' || $ptype == 'int' || $ptype == 'boolean' || $ptype == 'double' ||
847
+			if ($ptype == 'i4' || $ptype == 'int' || $ptype == 'boolean' || $ptype == 'double' ||
848 848
 				$ptype == 'string' || $ptype == 'dateTime.iso8601' || $ptype == 'base64' || $ptype == 'null')
849 849
 			{
850 850
 				// only build directly xmlrpcvals when type is known and scalar
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
 			$innercode .= "\$msg->addparam(\$p$i);\n";
865 865
 			$mdesc .= '* @param '.xmlrpc_2_php_type($ptype)." \$p$i\n";
866 866
 		}
867
-		if ($client_copy_mode < 2)
867
+		if ($client_copy_mode<2)
868 868
 		{
869 869
 			$plist[] = '$debug=0';
870 870
 			$mdesc .= "* @param int \$debug when 1 (or 2) will enable debugging of the underlying {$prefix} call (defaults to 0)\n";
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 			$innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value());";
898 898
 		}
899 899
 
900
-		$code = $code . $plist. ") {\n" . $innercode . "\n}\n";
900
+		$code = $code.$plist.") {\n".$innercode."\n}\n";
901 901
 
902 902
 		return array('source' => $code, 'docstring' => $mdesc);
903 903
 	}
@@ -908,18 +908,18 @@  discard block
 block discarded – undo
908 908
 	* valid php code is emitted.
909 909
 	* @access private
910 910
 	*/
911
-	function build_client_wrapper_code($client, $verbatim_client_copy, $prefix='xmlrpc')
911
+	function build_client_wrapper_code($client, $verbatim_client_copy, $prefix = 'xmlrpc')
912 912
 	{
913 913
 		$code = "\$client = new {$prefix}_client('".str_replace("'", "\'", $client->path).
914
-			"', '" . str_replace("'", "\'", $client->server) . "', $client->port);\n";
914
+			"', '".str_replace("'", "\'", $client->server)."', $client->port);\n";
915 915
 
916 916
 		// copy all client fields to the client that will be generated runtime
917 917
 		// (this provides for future expansion or subclassing of client obj)
918 918
 		if ($verbatim_client_copy)
919 919
 		{
920
-			foreach($client as $fld => $val)
920
+			foreach ($client as $fld => $val)
921 921
 			{
922
-				if($fld != 'debug' && $fld != 'return_type')
922
+				if ($fld != 'debug' && $fld != 'return_type')
923 923
 				{
924 924
 					$val = var_export($val, true);
925 925
 					$code .= "\$client->$fld = $val;\n";
Please login to merge, or discard this patch.
Braces   +46 added lines, -80 removed lines patch added patch discarded remove patch
@@ -52,8 +52,7 @@  discard block
 block discarded – undo
52 52
 				if(class_exists($phptype))
53 53
 				{
54 54
 					return $GLOBALS['xmlrpcStruct'];
55
-				}
56
-				else
55
+				} else
57 56
 				{
58 57
 					// unknown: might be any 'extended' xmlrpc type
59 58
 					return $GLOBALS['xmlrpcValue'];
@@ -163,14 +162,12 @@  discard block
 block discarded – undo
163 162
 			if(is_string($funcname[0]))
164 163
 			{
165 164
 				$plainfuncname = implode('::', $funcname);
166
-			}
167
-			elseif(is_object($funcname[0]))
165
+			} elseif(is_object($funcname[0]))
168 166
 			{
169 167
 				$plainfuncname = get_class($funcname[0]) . '->' . $funcname[1];
170 168
 			}
171 169
 			$exists = method_exists($funcname[0], $funcname[1]);
172
-		}
173
-		else
170
+		} else
174 171
 		{
175 172
 			$plainfuncname = $funcname;
176 173
 			$exists = function_exists($funcname);
@@ -180,25 +177,23 @@  discard block
 block discarded – undo
180 177
 		{
181 178
 			error_log('XML-RPC: function to be wrapped is not defined: '.$plainfuncname);
182 179
 			return false;
183
-		}
184
-		else
180
+		} else
185 181
 		{
186 182
 			// determine name of new php function
187 183
 			if($newfuncname == '')
188 184
 			{
189 185
 				if(is_array($funcname))
190 186
 				{
191
-					if(is_string($funcname[0]))
192
-						$xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);
193
-					else
194
-						$xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];
195
-				}
196
-				else
187
+					if(is_string($funcname[0])) {
188
+											$xmlrpcfuncname = "{$prefix}_".implode('_', $funcname);
189
+					} else {
190
+											$xmlrpcfuncname = "{$prefix}_".get_class($funcname[0]) . '_' . $funcname[1];
191
+					}
192
+				} else
197 193
 				{
198 194
 					$xmlrpcfuncname = "{$prefix}_$funcname";
199 195
 				}
200
-			}
201
-			else
196
+			} else
202 197
 			{
203 198
 				$xmlrpcfuncname = $newfuncname;
204 199
 			}
@@ -237,8 +232,7 @@  discard block
 block discarded – undo
237 232
 					return false;
238 233
 				}
239 234
 				/// @todo add more checks for static vs. nonstatic?
240
-			}
241
-			else
235
+			} else
242 236
 			{
243 237
 				$func = new ReflectionFunction($funcname);
244 238
 			}
@@ -276,8 +270,7 @@  discard block
 block discarded – undo
276 270
 							$desc .= "\n";
277 271
 						}
278 272
 						$desc .= $doc;
279
-					}
280
-					elseif(strpos($doc, '@param') === 0)
273
+					} elseif(strpos($doc, '@param') === 0)
281 274
 					{
282 275
 						// syntax: @param type [$name] desc
283 276
 						if(preg_match('/@param\s+(\S+)(\s+\$\S+)?\s+(.+)/', $doc, $matches))
@@ -286,8 +279,7 @@  discard block
 block discarded – undo
286 279
 							{
287 280
 								//$paramDocs[$i]['type'] = explode('|', $matches[1]);
288 281
 								$paramDocs[$i]['type'] = 'mixed';
289
-							}
290
-							else
282
+							} else
291 283
 							{
292 284
 								$paramDocs[$i]['type'] = $matches[1];
293 285
 							}
@@ -295,8 +287,7 @@  discard block
 block discarded – undo
295 287
 							$paramDocs[$i]['doc'] = $matches[3];
296 288
 						}
297 289
 						$i++;
298
-					}
299
-					elseif(strpos($doc, '@return') === 0)
290
+					} elseif(strpos($doc, '@return') === 0)
300 291
 					{
301 292
 						// syntax: @return type desc
302 293
 						//$returns = preg_split('/\s+/', $doc);
@@ -348,8 +339,7 @@  discard block
 block discarded – undo
348 339
 				if ($decode_php_objects)
349 340
 				{
350 341
 					$innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i, array('decode_php_objs'));\n";
351
-				}
352
-				else
342
+				} else
353 343
 				{
354 344
 					$innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = php_{$prefix}_decode(\$p$i);\n";
355 345
 				}
@@ -374,8 +364,7 @@  discard block
 block discarded – undo
374 364
 				// only known good synopsis = no parameters
375 365
 				$parsvariations[] = array();
376 366
 				$minpars = 0;
377
-			}
378
-			else
367
+			} else
379 368
 			{
380 369
 				$minpars = count($parsvariations[0]);
381 370
 			}
@@ -386,8 +375,7 @@  discard block
 block discarded – undo
386 375
 				// NB: this check needs to be done BEFORE decoding param values
387 376
 				$innercode = "\$paramcount = \$msg->getNumParams();\n" .
388 377
 				"if (\$paramcount < $minpars) return new {$prefix}resp(0, {$GLOBALS['xmlrpcerr']['incorrect_params']}, '{$GLOBALS['xmlrpcstr']['incorrect_params']}');\n" . $innercode;
389
-			}
390
-			else
378
+			} else
391 379
 			{
392 380
 				$innercode = "\$paramcount = \$msg->getNumParams();\n" . $innercode;
393 381
 			}
@@ -400,8 +388,7 @@  discard block
 block discarded – undo
400 388
 				$GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] =& $funcname[0];
401 389
 				$innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n";
402 390
 				$realfuncname = '$obj->'.$funcname[1];
403
-			}
404
-			else
391
+			} else
405 392
 			{
406 393
 				$realfuncname = $plainfuncname;
407 394
 			}
@@ -416,8 +403,7 @@  discard block
 block discarded – undo
416 403
 					if (isset($paramDocs[$i]['type']))
417 404
 					{
418 405
 						$sig[] = php_2_xmlrpc_type($paramDocs[$i]['type']);
419
-					}
420
-					else
406
+					} else
421 407
 					{
422 408
 						$sig[] = $GLOBALS['xmlrpcValue'];
423 409
 					}
@@ -433,13 +419,13 @@  discard block
 block discarded – undo
433 419
 			if($returns == $GLOBALS['xmlrpcDateTime'] || $returns == $GLOBALS['xmlrpcBase64'])
434 420
 			{
435 421
 				$innercode .= "return new {$prefix}resp(new {$prefix}val(\$retval, '$returns'));";
436
-			}
437
-			else
422
+			} else
438 423
 			{
439
-				if ($encode_php_objects)
440
-					$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval, array('encode_php_objs')));\n";
441
-				else
442
-					$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval));\n";
424
+				if ($encode_php_objects) {
425
+									$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval, array('encode_php_objs')));\n";
426
+				} else {
427
+									$innercode .= "return new {$prefix}resp(php_{$prefix}_encode(\$retval));\n";
428
+				}
443 429
 			}
444 430
 			// shall we exclude functions returning by ref?
445 431
 			// if($func->returnsReference())
@@ -556,8 +542,7 @@  discard block
 block discarded – undo
556 542
 		{
557 543
 			$signum = $extra_options;
558 544
 			$extra_options = array();
559
-		}
560
-		else
545
+		} else
561 546
 		{
562 547
 			$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0;
563 548
 			$timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0;
@@ -578,8 +563,7 @@  discard block
 block discarded – undo
578 563
 		{
579 564
 			$decode_fault = true;
580 565
 			$fault_response = $extra_options['return_on_fault'];
581
-		}
582
-		else
566
+		} else
583 567
 		{
584 568
 			$decode_fault = false;
585 569
 			$fault_response = '';
@@ -598,8 +582,7 @@  discard block
 block discarded – undo
598 582
 		{
599 583
 			error_log('XML-RPC: could not retrieve method signature from remote server for method '.$methodname);
600 584
 			return false;
601
-		}
602
-		else
585
+		} else
603 586
 		{
604 587
 			$msig = $response->value();
605 588
 			if ($client->return_type != 'phpvals')
@@ -610,15 +593,13 @@  discard block
 block discarded – undo
610 593
 			{
611 594
 				error_log('XML-RPC: could not retrieve method signature nr.'.$signum.' from remote server for method '.$methodname);
612 595
 				return false;
613
-			}
614
-			else
596
+			} else
615 597
 			{
616 598
 				// pick a suitable name for the new function, avoiding collisions
617 599
 				if($newfuncname != '')
618 600
 				{
619 601
 					$xmlrpcfuncname = $newfuncname;
620
-				}
621
-				else
602
+				} else
622 603
 				{
623 604
 					// take care to insure that methodname is translated to valid
624 605
 					// php function name
@@ -664,14 +645,12 @@  discard block
 block discarded – undo
664 645
 					if($allOK)
665 646
 					{
666 647
 						return $xmlrpcfuncname;
667
-					}
668
-					else
648
+					} else
669 649
 					{
670 650
 						error_log('XML-RPC: could not create function '.$xmlrpcfuncname.' to wrap remote method '.$methodname);
671 651
 						return false;
672 652
 					}
673
-				}
674
-				else
653
+				} else
675 654
 				{
676 655
 					$results['function'] = $xmlrpcfuncname;
677 656
 					return $results;
@@ -711,8 +690,7 @@  discard block
 block discarded – undo
711 690
 		{
712 691
 			error_log('XML-RPC: could not retrieve method list from remote server');
713 692
 			return false;
714
-		}
715
-		else
693
+		} else
716 694
 		{
717 695
 			$mlist = $response->value();
718 696
 			if ($client->return_type != 'phpvals')
@@ -723,15 +701,13 @@  discard block
 block discarded – undo
723 701
 			{
724 702
 				error_log('XML-RPC: could not retrieve meaningful method list from remote server');
725 703
 				return false;
726
-			}
727
-			else
704
+			} else
728 705
 			{
729 706
 				// pick a suitable name for the new function, avoiding collisions
730 707
 				if($newclassname != '')
731 708
 				{
732 709
 					$xmlrpcclassname = $newclassname;
733
-				}
734
-				else
710
+				} else
735 711
 				{
736 712
 					$xmlrpcclassname = $prefix.'_'.preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'),
737 713
 						array('_', ''), $client->server).'_client';
@@ -766,8 +742,7 @@  discard block
 block discarded – undo
766 742
 								$source .= $methodwrap['docstring'];
767 743
 							}
768 744
 							$source .= $methodwrap['source']."\n";
769
-						}
770
-						else
745
+						} else
771 746
 						{
772 747
 							error_log('XML-RPC: will not create class method to wrap remote method '.$mname);
773 748
 						}
@@ -783,14 +758,12 @@  discard block
 block discarded – undo
783 758
 					if($allOK)
784 759
 					{
785 760
 						return $xmlrpcclassname;
786
-					}
787
-					else
761
+					} else
788 762
 					{
789 763
 						error_log('XML-RPC: could not create class '.$xmlrpcclassname.' to wrap remote server '.$client->server);
790 764
 						return false;
791 765
 					}
792
-				}
793
-				else
766
+				} else
794 767
 				{
795 768
 					return array('class' => $xmlrpcclassname, 'code' => $source, 'docstring' => '');
796 769
 				}
@@ -818,8 +791,7 @@  discard block
 block discarded – undo
818 791
 			$innercode = build_client_wrapper_code($client, $client_copy_mode, $prefix);
819 792
 			$innercode .= "\$client->setDebug(\$debug);\n";
820 793
 			$this_ = '';
821
-		}
822
-		else
794
+		} else
823 795
 		{
824 796
 			// client copy mode 2 == no client copy in emitted code
825 797
 			$innercode = '';
@@ -831,8 +803,7 @@  discard block
 block discarded – undo
831 803
 		{
832 804
 			// take care that PHP comment is not terminated unwillingly by method description
833 805
 			$mdesc = "/**\n* ".str_replace('*/', '* /', $mdesc)."\n";
834
-		}
835
-		else
806
+		} else
836 807
 		{
837 808
 			$mdesc = "/**\nFunction $xmlrpcfuncname\n";
838 809
 		}
@@ -849,14 +820,12 @@  discard block
 block discarded – undo
849 820
 			{
850 821
 				// only build directly xmlrpcvals when type is known and scalar
851 822
 				$innercode .= "\$p$i = new {$prefix}val(\$p$i, '$ptype');\n";
852
-			}
853
-			else
823
+			} else
854 824
 			{
855 825
 				if ($encode_php_objects)
856 826
 				{
857 827
 					$innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i, array('encode_php_objs'));\n";
858
-				}
859
-				else
828
+				} else
860 829
 				{
861 830
 					$innercode .= "\$p$i =& php_{$prefix}_encode(\$p$i);\n";
862 831
 				}
@@ -878,21 +847,18 @@  discard block
 block discarded – undo
878 847
 			if (is_string($fault_response) && ((strpos($fault_response, '%faultCode%') !== false) || (strpos($fault_response, '%faultString%') !== false)))
879 848
 			{
880 849
 				$respcode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '".str_replace("'", "''", $fault_response)."')";
881
-			}
882
-			else
850
+			} else
883 851
 			{
884 852
 				$respcode = var_export($fault_response, true);
885 853
 			}
886
-		}
887
-		else
854
+		} else
888 855
 		{
889 856
 			$respcode = '$res';
890 857
 		}
891 858
 		if ($decode_php_objects)
892 859
 		{
893 860
 			$innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value(), array('decode_php_objs'));";
894
-		}
895
-		else
861
+		} else
896 862
 		{
897 863
 			$innercode .= "if (\$res->faultcode()) return $respcode; else return php_{$prefix}_decode(\$res->value());";
898 864
 		}
Please login to merge, or discard this patch.
debugger/common.php 3 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 // work around magic quotes
12
-  if (get_magic_quotes_gpc())
13
-  {
12
+    if (get_magic_quotes_gpc())
13
+    {
14 14
     function stripslashes_deep($value)
15 15
     {
16 16
         $value = is_array($value) ?
@@ -20,64 +20,64 @@  discard block
 block discarded – undo
20 20
         return $value;
21 21
     }
22 22
     $_GET = array_map('stripslashes_deep', $_GET);
23
-  }
23
+    }
24 24
 
25
-  $preferredEncodings = 'UTF-8, ASCII, ISO-8859-1, UTF-7, EUC-JP, SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP';
26
-  $inputcharset = mb_detect_encoding(urldecode($_SERVER['REQUEST_URI']), $preferredEncodings);
25
+    $preferredEncodings = 'UTF-8, ASCII, ISO-8859-1, UTF-7, EUC-JP, SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP';
26
+    $inputcharset = mb_detect_encoding(urldecode($_SERVER['REQUEST_URI']), $preferredEncodings);
27 27
 
28
-  if ( isset( $_GET['usepost'] ) && $_GET['usepost'] === 'true' )
29
-  {
30
-      $_GET = $_POST;
31
-      $inputcharset = mb_detect_encoding(implode('', $_GET), $preferredEncodings);
32
-  }
28
+    if ( isset( $_GET['usepost'] ) && $_GET['usepost'] === 'true' )
29
+    {
30
+        $_GET = $_POST;
31
+        $inputcharset = mb_detect_encoding(implode('', $_GET), $preferredEncodings);
32
+    }
33 33
 
34 34
 // recover input parameters
35
-  $debug = false;
36
-  $protocol = 0;
37
-  $run = false;
38
-  $wstype = 0;
39
-  $id = '';
40
-  if (isset($_GET['action']))
41
-  {
35
+    $debug = false;
36
+    $protocol = 0;
37
+    $run = false;
38
+    $wstype = 0;
39
+    $id = '';
40
+    if (isset($_GET['action']))
41
+    {
42 42
     if (isset($_GET['wstype']) && $_GET['wstype'] == '1')
43 43
     {
44
-      $wstype = 1;
45
-      if (isset($_GET['id']))
44
+        $wstype = 1;
45
+        if (isset($_GET['id']))
46 46
         $id = $_GET['id'];
47 47
     }
48 48
     $host = isset($_GET['host']) ? $_GET['host'] : 'localhost'; // using '' will trigger an xmlrpc error...
49 49
     if (isset($_GET['protocol']) && ($_GET['protocol'] == '1' || $_GET['protocol'] == '2'))
50
-      $protocol = $_GET['protocol'];
50
+        $protocol = $_GET['protocol'];
51 51
     if (strpos($host, 'http://') === 0)
52
-      $host = substr($host, 7);
52
+        $host = substr($host, 7);
53 53
     else if (strpos($host, 'https://') === 0)
54 54
     {
55
-      $host = substr($host, 8);
56
-      $protocol = 2;
55
+        $host = substr($host, 8);
56
+        $protocol = 2;
57 57
     }
58 58
     $port = isset($_GET['port']) ? $_GET['port'] : '';
59 59
     $path = isset($_GET['path']) ? $_GET['path'] : '';
60 60
     // in case user forgot initial '/' in xmlrpc server path, add it back
61 61
     if ($path && ($path[0]) != '/')
62
-      $path = '/'.$path;
62
+        $path = '/'.$path;
63 63
 
64 64
     if (isset($_GET['debug']) && ($_GET['debug'] == '1' || $_GET['debug'] == '2'))
65
-      $debug = $_GET['debug'];
65
+        $debug = $_GET['debug'];
66 66
 
67 67
     $verifyhost = (isset($_GET['verifyhost']) && ($_GET['verifyhost'] == '1' || $_GET['verifyhost'] == '2')) ? $_GET['verifyhost'] : 0;
68 68
     if (isset($_GET['verifypeer']) && $_GET['verifypeer'] == '1')
69
-      $verifypeer = true;
69
+        $verifypeer = true;
70 70
     else
71
-      $verifypeer = false;
71
+        $verifypeer = false;
72 72
     $cainfo= isset($_GET['cainfo']) ? $_GET['cainfo'] : '';
73 73
     $proxy = isset($_GET['proxy']) ? $_GET['proxy'] : 0;
74 74
     if (strpos($proxy, 'http://') === 0)
75
-      $proxy = substr($proxy, 7);
75
+        $proxy = substr($proxy, 7);
76 76
     $proxyuser= isset($_GET['proxyuser']) ? $_GET['proxyuser'] : '';
77 77
     $proxypwd = isset($_GET['proxypwd']) ? $_GET['proxypwd'] : '';
78 78
     $timeout = isset($_GET['timeout']) ? $_GET['timeout'] : 0;
79 79
     if (!is_numeric($timeout))
80
-      $timeout = 0;
80
+        $timeout = 0;
81 81
     $action = $_GET['action'];
82 82
 
83 83
     $method = isset($_GET['method']) ? $_GET['method'] : '';
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     $alt_payload = isset($_GET['altmethodpayload']) ? $_GET['altmethodpayload'] : '';
87 87
 
88 88
     if (isset($_GET['run']) && $_GET['run'] == 'now')
89
-      $run = true;
89
+        $run = true;
90 90
 
91 91
     $username = isset($_GET['username']) ? $_GET['username'] : '';
92 92
     $password = isset($_GET['password']) ? $_GET['password'] : '';
@@ -94,18 +94,18 @@  discard block
 block discarded – undo
94 94
     $authtype = (isset($_GET['authtype']) && ($_GET['authtype'] == '2' || $_GET['authtype'] == '8')) ? $_GET['authtype'] : 1;
95 95
 
96 96
     if (isset($_GET['requestcompression']) && ($_GET['requestcompression'] == '1' || $_GET['requestcompression'] == '2'))
97
-      $requestcompression = $_GET['requestcompression'];
97
+        $requestcompression = $_GET['requestcompression'];
98 98
     else
99
-      $requestcompression = 0;
99
+        $requestcompression = 0;
100 100
     if (isset($_GET['responsecompression']) && ($_GET['responsecompression'] == '1' || $_GET['responsecompression'] == '2' || $_GET['responsecompression'] == '3'))
101
-      $responsecompression = $_GET['responsecompression'];
101
+        $responsecompression = $_GET['responsecompression'];
102 102
     else
103
-      $responsecompression = 0;
103
+        $responsecompression = 0;
104 104
 
105 105
     $clientcookies = isset($_GET['clientcookies']) ? $_GET['clientcookies'] : '';
106
-  }
107
-  else
108
-  {
106
+    }
107
+    else
108
+    {
109 109
     $host = '';
110 110
     $port = '';
111 111
     $path = '';
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
     $requestcompression = 0;
128 128
     $responsecompression = 0;
129 129
     $clientcookies = '';
130
-  }
130
+    }
131 131
 
132
-  // check input for known XMLRPC attacks against this or other libs
133
-  function payload_is_safe($input)
134
-  {
135
-      return true;
136
-  }
132
+    // check input for known XMLRPC attacks against this or other libs
133
+    function payload_is_safe($input)
134
+    {
135
+        return true;
136
+    }
137 137
 ?>
138 138
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,8 +14,7 @@  discard block
 block discarded – undo
14 14
     function stripslashes_deep($value)
15 15
     {
16 16
         $value = is_array($value) ?
17
-                    array_map('stripslashes_deep', $value) :
18
-                    stripslashes($value);
17
+                    array_map('stripslashes_deep', $value) : stripslashes($value);
19 18
 
20 19
         return $value;
21 20
     }
@@ -25,7 +24,7 @@  discard block
 block discarded – undo
25 24
   $preferredEncodings = 'UTF-8, ASCII, ISO-8859-1, UTF-7, EUC-JP, SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP';
26 25
   $inputcharset = mb_detect_encoding(urldecode($_SERVER['REQUEST_URI']), $preferredEncodings);
27 26
 
28
-  if ( isset( $_GET['usepost'] ) && $_GET['usepost'] === 'true' )
27
+  if (isset($_GET['usepost']) && $_GET['usepost'] === 'true')
29 28
   {
30 29
       $_GET = $_POST;
31 30
       $inputcharset = mb_detect_encoding(implode('', $_GET), $preferredEncodings);
@@ -69,11 +68,11 @@  discard block
 block discarded – undo
69 68
       $verifypeer = true;
70 69
     else
71 70
       $verifypeer = false;
72
-    $cainfo= isset($_GET['cainfo']) ? $_GET['cainfo'] : '';
71
+    $cainfo = isset($_GET['cainfo']) ? $_GET['cainfo'] : '';
73 72
     $proxy = isset($_GET['proxy']) ? $_GET['proxy'] : 0;
74 73
     if (strpos($proxy, 'http://') === 0)
75 74
       $proxy = substr($proxy, 7);
76
-    $proxyuser= isset($_GET['proxyuser']) ? $_GET['proxyuser'] : '';
75
+    $proxyuser = isset($_GET['proxyuser']) ? $_GET['proxyuser'] : '';
77 76
     $proxypwd = isset($_GET['proxypwd']) ? $_GET['proxypwd'] : '';
78 77
     $timeout = isset($_GET['timeout']) ? $_GET['timeout'] : 0;
79 78
     if (!is_numeric($timeout))
Please login to merge, or discard this patch.
Braces   +40 added lines, -31 removed lines patch added patch discarded remove patch
@@ -42,15 +42,17 @@  discard block
 block discarded – undo
42 42
     if (isset($_GET['wstype']) && $_GET['wstype'] == '1')
43 43
     {
44 44
       $wstype = 1;
45
-      if (isset($_GET['id']))
46
-        $id = $_GET['id'];
45
+      if (isset($_GET['id'])) {
46
+              $id = $_GET['id'];
47
+      }
47 48
     }
48 49
     $host = isset($_GET['host']) ? $_GET['host'] : 'localhost'; // using '' will trigger an xmlrpc error...
49
-    if (isset($_GET['protocol']) && ($_GET['protocol'] == '1' || $_GET['protocol'] == '2'))
50
-      $protocol = $_GET['protocol'];
51
-    if (strpos($host, 'http://') === 0)
52
-      $host = substr($host, 7);
53
-    else if (strpos($host, 'https://') === 0)
50
+    if (isset($_GET['protocol']) && ($_GET['protocol'] == '1' || $_GET['protocol'] == '2')) {
51
+          $protocol = $_GET['protocol'];
52
+    }
53
+    if (strpos($host, 'http://') === 0) {
54
+          $host = substr($host, 7);
55
+    } else if (strpos($host, 'https://') === 0)
54 56
     {
55 57
       $host = substr($host, 8);
56 58
       $protocol = 2;
@@ -58,26 +60,31 @@  discard block
 block discarded – undo
58 60
     $port = isset($_GET['port']) ? $_GET['port'] : '';
59 61
     $path = isset($_GET['path']) ? $_GET['path'] : '';
60 62
     // in case user forgot initial '/' in xmlrpc server path, add it back
61
-    if ($path && ($path[0]) != '/')
62
-      $path = '/'.$path;
63
+    if ($path && ($path[0]) != '/') {
64
+          $path = '/'.$path;
65
+    }
63 66
 
64
-    if (isset($_GET['debug']) && ($_GET['debug'] == '1' || $_GET['debug'] == '2'))
65
-      $debug = $_GET['debug'];
67
+    if (isset($_GET['debug']) && ($_GET['debug'] == '1' || $_GET['debug'] == '2')) {
68
+          $debug = $_GET['debug'];
69
+    }
66 70
 
67 71
     $verifyhost = (isset($_GET['verifyhost']) && ($_GET['verifyhost'] == '1' || $_GET['verifyhost'] == '2')) ? $_GET['verifyhost'] : 0;
68
-    if (isset($_GET['verifypeer']) && $_GET['verifypeer'] == '1')
69
-      $verifypeer = true;
70
-    else
71
-      $verifypeer = false;
72
+    if (isset($_GET['verifypeer']) && $_GET['verifypeer'] == '1') {
73
+          $verifypeer = true;
74
+    } else {
75
+          $verifypeer = false;
76
+    }
72 77
     $cainfo= isset($_GET['cainfo']) ? $_GET['cainfo'] : '';
73 78
     $proxy = isset($_GET['proxy']) ? $_GET['proxy'] : 0;
74
-    if (strpos($proxy, 'http://') === 0)
75
-      $proxy = substr($proxy, 7);
79
+    if (strpos($proxy, 'http://') === 0) {
80
+          $proxy = substr($proxy, 7);
81
+    }
76 82
     $proxyuser= isset($_GET['proxyuser']) ? $_GET['proxyuser'] : '';
77 83
     $proxypwd = isset($_GET['proxypwd']) ? $_GET['proxypwd'] : '';
78 84
     $timeout = isset($_GET['timeout']) ? $_GET['timeout'] : 0;
79
-    if (!is_numeric($timeout))
80
-      $timeout = 0;
85
+    if (!is_numeric($timeout)) {
86
+          $timeout = 0;
87
+    }
81 88
     $action = $_GET['action'];
82 89
 
83 90
     $method = isset($_GET['method']) ? $_GET['method'] : '';
@@ -85,26 +92,28 @@  discard block
 block discarded – undo
85 92
     $payload = isset($_GET['methodpayload']) ? $_GET['methodpayload'] : '';
86 93
     $alt_payload = isset($_GET['altmethodpayload']) ? $_GET['altmethodpayload'] : '';
87 94
 
88
-    if (isset($_GET['run']) && $_GET['run'] == 'now')
89
-      $run = true;
95
+    if (isset($_GET['run']) && $_GET['run'] == 'now') {
96
+          $run = true;
97
+    }
90 98
 
91 99
     $username = isset($_GET['username']) ? $_GET['username'] : '';
92 100
     $password = isset($_GET['password']) ? $_GET['password'] : '';
93 101
 
94 102
     $authtype = (isset($_GET['authtype']) && ($_GET['authtype'] == '2' || $_GET['authtype'] == '8')) ? $_GET['authtype'] : 1;
95 103
 
96
-    if (isset($_GET['requestcompression']) && ($_GET['requestcompression'] == '1' || $_GET['requestcompression'] == '2'))
97
-      $requestcompression = $_GET['requestcompression'];
98
-    else
99
-      $requestcompression = 0;
100
-    if (isset($_GET['responsecompression']) && ($_GET['responsecompression'] == '1' || $_GET['responsecompression'] == '2' || $_GET['responsecompression'] == '3'))
101
-      $responsecompression = $_GET['responsecompression'];
102
-    else
103
-      $responsecompression = 0;
104
+    if (isset($_GET['requestcompression']) && ($_GET['requestcompression'] == '1' || $_GET['requestcompression'] == '2')) {
105
+          $requestcompression = $_GET['requestcompression'];
106
+    } else {
107
+          $requestcompression = 0;
108
+    }
109
+    if (isset($_GET['responsecompression']) && ($_GET['responsecompression'] == '1' || $_GET['responsecompression'] == '2' || $_GET['responsecompression'] == '3')) {
110
+          $responsecompression = $_GET['responsecompression'];
111
+    } else {
112
+          $responsecompression = 0;
113
+    }
104 114
 
105 115
     $clientcookies = isset($_GET['clientcookies']) ? $_GET['clientcookies'] : '';
106
-  }
107
-  else
116
+  } else
108 117
   {
109 118
     $host = '';
110 119
     $port = '';
Please login to merge, or discard this patch.
debugger/action.php 3 patches
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -36,101 +36,101 @@  discard block
 block discarded – undo
36 36
 <body>
37 37
 <?php
38 38
 
39
-  include(dirname(__FILE__).'/common.php');
40
-  if ($action)
41
-  {
39
+    include(dirname(__FILE__).'/common.php');
40
+    if ($action)
41
+    {
42 42
 
43 43
     // make sure the script waits long enough for the call to complete...
44 44
     if ($timeout)
45
-      set_time_limit($timeout+10);
45
+        set_time_limit($timeout+10);
46 46
 
47 47
     include('xmlrpc.inc');
48 48
     if ($wstype == 1)
49 49
     {
50
-      @include('jsonrpc.inc');
51
-      if (!class_exists('jsonrpc_client'))
52
-      {
50
+        @include('jsonrpc.inc');
51
+        if (!class_exists('jsonrpc_client'))
52
+        {
53 53
         die('Error: to debug the jsonrpc protocol the jsonrpc.inc file is needed');
54
-      }
55
-      $clientclass = 'jsonrpc_client';
56
-      $msgclass = 'jsonrpcmsg';
57
-      $protoname = 'JSONRPC';
54
+        }
55
+        $clientclass = 'jsonrpc_client';
56
+        $msgclass = 'jsonrpcmsg';
57
+        $protoname = 'JSONRPC';
58 58
     }
59 59
     else
60 60
     {
61
-      $clientclass = 'xmlrpc_client';
62
-      $msgclass = 'xmlrpcmsg';
63
-      $protoname = 'XMLRPC';
61
+        $clientclass = 'xmlrpc_client';
62
+        $msgclass = 'xmlrpcmsg';
63
+        $protoname = 'XMLRPC';
64 64
     }
65 65
 
66 66
     if ($port != "")
67 67
     {
68
-      $client = new $clientclass($path, $host, $port);
69
-      $server = "$host:$port$path";
68
+        $client = new $clientclass($path, $host, $port);
69
+        $server = "$host:$port$path";
70 70
     } else {
71
-      $client = new $clientclass($path, $host);
72
-      $server = "$host$path";
71
+        $client = new $clientclass($path, $host);
72
+        $server = "$host$path";
73 73
     }
74 74
     if ($protocol == 2)
75 75
     {
76
-      $server = 'https://'.$server;
76
+        $server = 'https://'.$server;
77 77
     }
78 78
     else
79 79
     {
80
-      $server = 'http://'.$server;
80
+        $server = 'http://'.$server;
81 81
     }
82 82
     if ($proxy != '') {
83
-      $pproxy = explode(':', $proxy);
84
-      if (count($pproxy) > 1)
83
+        $pproxy = explode(':', $proxy);
84
+        if (count($pproxy) > 1)
85 85
         $pport = $pproxy[1];
86
-      else
86
+        else
87 87
         $pport = 8080;
88
-      $client->setProxy($pproxy[0], $pport, $proxyuser, $proxypwd);
88
+        $client->setProxy($pproxy[0], $pport, $proxyuser, $proxypwd);
89 89
     }
90 90
 
91 91
     if ($protocol == 2)
92 92
     {
93
-      $client->setSSLVerifyPeer($verifypeer);
94
-      $client->setSSLVerifyHost($verifyhost);
95
-      if ($cainfo)
96
-      {
93
+        $client->setSSLVerifyPeer($verifypeer);
94
+        $client->setSSLVerifyHost($verifyhost);
95
+        if ($cainfo)
96
+        {
97 97
         $client->setCaCertificate($cainfo);
98
-      }
99
-      $httpprotocol = 'https';
98
+        }
99
+        $httpprotocol = 'https';
100 100
     }
101 101
     else if ($protocol == 1)
102
-      $httpprotocol = 'http11';
102
+        $httpprotocol = 'http11';
103 103
     else
104
-      $httpprotocol = 'http';
104
+        $httpprotocol = 'http';
105 105
 
106 106
     if ($username)
107
-      $client->setCredentials($username, $password, $authtype);
107
+        $client->setCredentials($username, $password, $authtype);
108 108
 
109 109
     $client->setDebug($debug);
110 110
 
111 111
     switch ($requestcompression) {
112
-      case 0:
112
+        case 0:
113 113
         $client->request_compression = '';
114 114
         break;
115
-      case 1:
115
+        case 1:
116 116
         $client->request_compression = 'gzip';
117 117
         break;
118
-      case 2:
118
+        case 2:
119 119
         $client->request_compression = 'deflate';
120 120
         break;
121 121
     }
122 122
 
123 123
     switch ($responsecompression) {
124
-      case 0:
124
+        case 0:
125 125
         $client->accepted_compression = '';
126 126
         break;
127
-      case 1:
127
+        case 1:
128 128
         $client->accepted_compression = array('gzip');
129 129
         break;
130
-      case 2:
130
+        case 2:
131 131
         $client->accepted_compression = array('deflate');
132 132
         break;
133
-      case 3:
133
+        case 3:
134 134
         $client->accepted_compression = array('gzip', 'deflate');
135 135
         break;
136 136
     }
@@ -138,24 +138,24 @@  discard block
 block discarded – undo
138 138
     $cookies = explode(',', $clientcookies);
139 139
     foreach ($cookies as $cookie)
140 140
     {
141
-      if (strpos($cookie, '='))
142
-      {
141
+        if (strpos($cookie, '='))
142
+        {
143 143
         $cookie = explode('=', $cookie);
144 144
         $client->setCookie(trim($cookie[0]), trim(@$cookie[1]));
145
-      }
145
+        }
146 146
     }
147 147
 
148 148
     $msg = array();
149 149
     switch ($action) {
150 150
 
151
-      case 'wrap':
151
+        case 'wrap':
152 152
         @include('xmlrpc_wrappers.inc');
153 153
         if (!function_exists('build_remote_method_wrapper_code'))
154 154
         {
155
-          die('Error: to enable creation of method stubs the xmlrpc_wrappers.inc file is needed');
155
+            die('Error: to enable creation of method stubs the xmlrpc_wrappers.inc file is needed');
156 156
         }
157 157
         // fall thru intentionally
158
-      case 'describe':
158
+        case 'describe':
159 159
       case 'wrap':
160 160
         $msg[0] = new $msgclass('system.methodHelp', null, $id);
161 161
         $msg[0]->addparam(new xmlrpcval($method));
@@ -163,18 +163,18 @@  discard block
 block discarded – undo
163 163
         $msg[1]->addparam(new xmlrpcval($method));
164 164
         $actionname = 'Description of method "'.$method.'"';
165 165
         break;
166
-      case 'list':
166
+        case 'list':
167 167
         $msg[0] = new $msgclass('system.listMethods', null, $id);
168 168
         $actionname = 'List of available methods';
169 169
         break;
170
-      case 'execute':
170
+        case 'execute':
171 171
         if (!payload_is_safe($payload))
172
-          die("Tsk tsk tsk, please stop it or I will have to call in the cops!");
172
+            die("Tsk tsk tsk, please stop it or I will have to call in the cops!");
173 173
         $msg[0] = new $msgclass($method, null, $id);
174 174
         // hack! build xml payload by hand
175 175
         if ($wstype == 1)
176 176
         {
177
-          $msg[0]->payload = "{\n".
177
+            $msg[0]->payload = "{\n".
178 178
             '"method": "' . $method . "\",\n\"params\": [" .
179 179
             $payload .
180 180
             "\n],\n\"id\": ";
@@ -185,24 +185,24 @@  discard block
 block discarded – undo
185 185
             }
186 186
             else
187 187
             {
188
-              if (is_numeric($id) || $id == 'false' || $id == 'true' || $id == 'null')
189
-              {
188
+                if (is_numeric($id) || $id == 'false' || $id == 'true' || $id == 'null')
189
+                {
190 190
                 $msg[0]->payload .= "$id\n}";
191
-              }
192
-              else
193
-              {
191
+                }
192
+                else
193
+                {
194 194
                 $msg[0]->payload .= "\"$id\"\n}";
195
-              }
195
+                }
196 196
             }
197 197
         }
198 198
         else
199
-          $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
199
+            $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
200 200
             '<methodName>' . $method . "</methodName>\n<params>" .
201 201
             $payload .
202 202
             "</params>\n" . $msg[0]->xml_footer();
203 203
         $actionname = 'Execution of method '.$method;
204 204
         break;
205
-      default: // give a warning
205
+        default: // give a warning
206 206
         $actionname = '[ERROR: unknown action] "'.$action.'"';
207 207
     }
208 208
 
@@ -214,81 +214,81 @@  discard block
 block discarded – undo
214 214
     $response = null;
215 215
     // execute method(s)
216 216
     if ($debug)
217
-      echo '<div class="dbginfo"><h2>Debug info:</h2>';  /// @todo use ob_start instead
217
+        echo '<div class="dbginfo"><h2>Debug info:</h2>';  /// @todo use ob_start instead
218 218
     $resp = array();
219 219
     $mtime = explode(' ',microtime());
220 220
     $time = (float)$mtime[0] + (float)$mtime[1];
221 221
     foreach ($msg as $message)
222 222
     {
223
-      // catch errors: for older xmlrpc libs, send does not return by ref
224
-      @$response =& $client->send($message, $timeout, $httpprotocol);
225
-      $resp[] = $response;
226
-      if (!$response || $response->faultCode())
223
+        // catch errors: for older xmlrpc libs, send does not return by ref
224
+        @$response =& $client->send($message, $timeout, $httpprotocol);
225
+        $resp[] = $response;
226
+        if (!$response || $response->faultCode())
227 227
         break;
228 228
     }
229 229
     $mtime = explode(' ',microtime());
230 230
     $time = (float)$mtime[0] + (float)$mtime[1] - $time;
231 231
     if ($debug)
232
-      echo "</div>\n";
232
+        echo "</div>\n";
233 233
 
234 234
     if ($response)
235 235
     {
236 236
 
237 237
     if ($response->faultCode())
238 238
     {
239
-      // call failed! echo out error msg!
240
-      //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
241
-      echo "<h3>$protoname call FAILED!</h3>\n";
242
-      echo "<p>Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) .
239
+        // call failed! echo out error msg!
240
+        //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
241
+        echo "<h3>$protoname call FAILED!</h3>\n";
242
+        echo "<p>Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) .
243 243
         "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) . "'</p>\n";
244
-      echo (strftime("%d/%b/%Y:%H:%M:%S\n"));
244
+        echo (strftime("%d/%b/%Y:%H:%M:%S\n"));
245 245
     }
246 246
     else
247 247
     {
248
-      // call succeeded: parse results
249
-      //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
250
-      printf ("<h3>%s call(s) OK (%.2f secs.)</h3>\n", $protoname, $time);
251
-      echo (strftime("%d/%b/%Y:%H:%M:%S\n"));
248
+        // call succeeded: parse results
249
+        //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
250
+        printf ("<h3>%s call(s) OK (%.2f secs.)</h3>\n", $protoname, $time);
251
+        echo (strftime("%d/%b/%Y:%H:%M:%S\n"));
252 252
 
253
-      switch ($action)
254
-      {
253
+        switch ($action)
254
+        {
255 255
         case 'list':
256 256
 
257 257
         $v = $response->value();
258 258
         if ($v->kindOf()=="array")
259 259
         {
260
-          $max = $v->arraysize();
261
-          echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
262
-          echo "<thead>\n<tr><th>Method</th><th>Description</th></tr>\n</thead>\n<tbody>\n";
263
-          for($i=0; $i < $max; $i++)
264
-          {
260
+            $max = $v->arraysize();
261
+            echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
262
+            echo "<thead>\n<tr><th>Method</th><th>Description</th></tr>\n</thead>\n<tbody>\n";
263
+            for($i=0; $i < $max; $i++)
264
+            {
265 265
             $rec = $v->arraymem($i);
266 266
             if ($i%2) $class=' class="oddrow"'; else $class = ' class="evenrow"';
267 267
             echo ("<tr><td$class>".htmlspecialchars($rec->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding'])."</td><td$class><form action=\"controller.php\" method=\"get\" target=\"frmcontroller\">".
268
-              "<input type=\"hidden\" name=\"host\" value=\"".htmlspecialchars($host, ENT_COMPAT, $inputcharset)."\" />".
269
-              "<input type=\"hidden\" name=\"port\" value=\"".htmlspecialchars($port, ENT_COMPAT, $inputcharset)."\" />".
270
-              "<input type=\"hidden\" name=\"path\" value=\"".htmlspecialchars($path, ENT_COMPAT, $inputcharset)."\" />".
271
-              "<input type=\"hidden\" name=\"id\" value=\"".htmlspecialchars($id, ENT_COMPAT, $inputcharset)."\" />".
272
-              "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />".
273
-              "<input type=\"hidden\" name=\"username\" value=\"".htmlspecialchars($username, ENT_COMPAT, $inputcharset)."\" />".
274
-              "<input type=\"hidden\" name=\"password\" value=\"".htmlspecialchars($password, ENT_COMPAT, $inputcharset)."\" />".
275
-              "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />".
276
-              "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />".
277
-              "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />".
278
-              "<input type=\"hidden\" name=\"cainfo\" value=\"".htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset)."\" />".
279
-              "<input type=\"hidden\" name=\"proxy\" value=\"".htmlspecialchars($proxy, ENT_COMPAT, $inputcharset)."\" />".
280
-              "<input type=\"hidden\" name=\"proxyuser\" value=\"".htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset)."\" />".
281
-              "<input type=\"hidden\" name=\"proxypwd\" value=\"".htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset)."\" />".
282
-              "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />".
283
-              "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />".
284
-              "<input type=\"hidden\" name=\"clientcookies\" value=\"".htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset)."\" />".
285
-              "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />".
286
-              "<input type=\"hidden\" name=\"timeout\" value=\"".htmlspecialchars($timeout, ENT_COMPAT, $inputcharset)."\" />".
287
-              "<input type=\"hidden\" name=\"method\" value=\"".$rec->scalarval()."\" />".
288
-              "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />".
289
-              "<input type=\"hidden\" name=\"action\" value=\"describe\" />".
290
-              "<input type=\"hidden\" name=\"run\" value=\"now\" />".
291
-              "<input type=\"submit\" value=\"Describe\" /></form></td>");
268
+                "<input type=\"hidden\" name=\"host\" value=\"".htmlspecialchars($host, ENT_COMPAT, $inputcharset)."\" />".
269
+                "<input type=\"hidden\" name=\"port\" value=\"".htmlspecialchars($port, ENT_COMPAT, $inputcharset)."\" />".
270
+                "<input type=\"hidden\" name=\"path\" value=\"".htmlspecialchars($path, ENT_COMPAT, $inputcharset)."\" />".
271
+                "<input type=\"hidden\" name=\"id\" value=\"".htmlspecialchars($id, ENT_COMPAT, $inputcharset)."\" />".
272
+                "<input type=\"hidden\" name=\"debug\" value=\"$debug\" />".
273
+                "<input type=\"hidden\" name=\"username\" value=\"".htmlspecialchars($username, ENT_COMPAT, $inputcharset)."\" />".
274
+                "<input type=\"hidden\" name=\"password\" value=\"".htmlspecialchars($password, ENT_COMPAT, $inputcharset)."\" />".
275
+                "<input type=\"hidden\" name=\"authtype\" value=\"$authtype\" />".
276
+                "<input type=\"hidden\" name=\"verifyhost\" value=\"$verifyhost\" />".
277
+                "<input type=\"hidden\" name=\"verifypeer\" value=\"$verifypeer\" />".
278
+                "<input type=\"hidden\" name=\"cainfo\" value=\"".htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset)."\" />".
279
+                "<input type=\"hidden\" name=\"proxy\" value=\"".htmlspecialchars($proxy, ENT_COMPAT, $inputcharset)."\" />".
280
+                "<input type=\"hidden\" name=\"proxyuser\" value=\"".htmlspecialchars($proxyuser, ENT_COMPAT, $inputcharset)."\" />".
281
+                "<input type=\"hidden\" name=\"proxypwd\" value=\"".htmlspecialchars($proxypwd, ENT_COMPAT, $inputcharset)."\" />".
282
+                "<input type=\"hidden\" name=\"responsecompression\" value=\"$responsecompression\" />".
283
+                "<input type=\"hidden\" name=\"requestcompression\" value=\"$requestcompression\" />".
284
+                "<input type=\"hidden\" name=\"clientcookies\" value=\"".htmlspecialchars($clientcookies, ENT_COMPAT, $inputcharset)."\" />".
285
+                "<input type=\"hidden\" name=\"protocol\" value=\"$protocol\" />".
286
+                "<input type=\"hidden\" name=\"timeout\" value=\"".htmlspecialchars($timeout, ENT_COMPAT, $inputcharset)."\" />".
287
+                "<input type=\"hidden\" name=\"method\" value=\"".$rec->scalarval()."\" />".
288
+                "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />".
289
+                "<input type=\"hidden\" name=\"action\" value=\"describe\" />".
290
+                "<input type=\"hidden\" name=\"run\" value=\"now\" />".
291
+                "<input type=\"submit\" value=\"Describe\" /></form></td>");
292 292
             //echo("</tr>\n");
293 293
 
294 294
             // generate lo scheletro per il method payload per eventuali test
@@ -303,10 +303,10 @@  discard block
 block discarded – undo
303 303
               "<input type=\"hidden\" name=\"action\" value=\"execute\" />".
304 304
               "<input type=\"submit\" value=\"Test\" /></td></form>");*/
305 305
             echo("</tr>\n");
306
-          }
307
-          echo "</tbody>\n</table>";
306
+            }
307
+            echo "</tbody>\n</table>";
308 308
         }
309
-          break;
309
+            break;
310 310
 
311 311
         case 'describe':
312 312
 
@@ -317,46 +317,46 @@  discard block
 block discarded – undo
317 317
         echo "<thead>\n<tr><th>Method</th><th>".htmlspecialchars($method, ENT_COMPAT, $inputcharset)."</th><th>&nbsp;</th><th>&nbsp;</th></tr>\n</thead>\n<tbody>\n";
318 318
         $desc = htmlspecialchars($r1->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']);
319 319
         if ($desc == "")
320
-          $desc = "-";
320
+            $desc = "-";
321 321
         echo "<tr><td class=\"evenrow\">Description</td><td colspan=\"3\" class=\"evenrow\">$desc</td></tr>\n";
322 322
         $payload="";
323 323
         $alt_payload="";
324 324
         if ($r2->kindOf()!="array")
325
-          echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\">&nbsp;</td></tr>\n";
325
+            echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\">&nbsp;</td></tr>\n";
326 326
         else
327 327
         {
328
-          for($i=0; $i < $r2->arraysize(); $i++)
329
-          {
328
+            for($i=0; $i < $r2->arraysize(); $i++)
329
+            {
330 330
             if ($i+1%2) $class=' class="oddrow"'; else $class = ' class="evenrow"';
331 331
             echo "<tr><td$class>Signature&nbsp;".($i+1)."</td><td$class>";
332 332
             $x = $r2->arraymem($i);
333 333
             if ($x->kindOf()=="array")
334 334
             {
335
-              $ret = $x->arraymem(0);
336
-              echo "<code>OUT:&nbsp;" . htmlspecialchars($ret->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) . "<br />IN: (";
337
-              if ($x->arraysize() > 1)
338
-              {
335
+                $ret = $x->arraymem(0);
336
+                echo "<code>OUT:&nbsp;" . htmlspecialchars($ret->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) . "<br />IN: (";
337
+                if ($x->arraysize() > 1)
338
+                {
339 339
                 for($k = 1; $k < $x->arraysize(); $k++)
340 340
                 {
341
-                  $y = $x->arraymem($k);
342
-                  echo $y->scalarval();
343
-                  if ($wstype != 1)
344
-                  {
341
+                    $y = $x->arraymem($k);
342
+                    echo $y->scalarval();
343
+                    if ($wstype != 1)
344
+                    {
345 345
                     $payload = $payload . '<param><value><'.htmlspecialchars($y->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']).'></'.htmlspecialchars($y->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding'])."></value></param>\n";
346
-                  }
347
-                  $alt_payload .= $y->scalarval();
348
-                  if ($k < $x->arraysize()-1)
349
-                  {
346
+                    }
347
+                    $alt_payload .= $y->scalarval();
348
+                    if ($k < $x->arraysize()-1)
349
+                    {
350 350
                     $alt_payload .= ';';
351 351
                     echo ", ";
352
-                  }
352
+                    }
353 353
                 }
354
-              }
355
-              echo ")</code>";
354
+                }
355
+                echo ")</code>";
356 356
             }
357 357
             else
358 358
             {
359
-              echo 'Unknown';
359
+                echo 'Unknown';
360 360
             }
361 361
             echo '</td>';
362 362
             //bottone per testare questo metodo
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
             "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />".
388 388
             "<input type=\"hidden\" name=\"action\" value=\"execute\" />";
389 389
             if ($wstype != 1)
390
-              echo "<input type=\"submit\" value=\"Load method synopsis\" />";
390
+                echo "<input type=\"submit\" value=\"Load method synopsis\" />";
391 391
             echo "</form></td>\n";
392 392
 
393 393
             echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">".
@@ -420,66 +420,66 @@  discard block
 block discarded – undo
420 420
             "<input type=\"submit\" value=\"Generate method call stub code\" />";
421 421
             echo "</form></td></tr>\n";
422 422
 
423
-          }
423
+            }
424 424
         }
425 425
         echo "</tbody>\n</table>";
426 426
 
427
-          break;
427
+            break;
428 428
 
429 429
         case 'wrap':
430 430
           $r1 = $resp[0]->value();
431
-          $r2 = $resp[1]->value();
432
-          if ($r2->kindOf()!="array" || $r2->arraysize() <= $methodsig)
431
+            $r2 = $resp[1]->value();
432
+            if ($r2->kindOf()!="array" || $r2->arraysize() <= $methodsig)
433 433
             echo "Error: signature unknown\n";
434
-          else
435
-          {
436
-          $mdesc = $r1->scalarval();
437
-          $msig = php_xmlrpc_decode($r2);
438
-          $msig = $msig[$methodsig];
439
-          $proto = $protocol == 2 ? 'https' : $protocol == 1 ? 'http11' : '';
440
-          if ($proxy  == '' && $username == '' && !$requestcompression && !$responsecompression &&
434
+            else
435
+            {
436
+            $mdesc = $r1->scalarval();
437
+            $msig = php_xmlrpc_decode($r2);
438
+            $msig = $msig[$methodsig];
439
+            $proto = $protocol == 2 ? 'https' : $protocol == 1 ? 'http11' : '';
440
+            if ($proxy  == '' && $username == '' && !$requestcompression && !$responsecompression &&
441 441
             $clientcookies == '')
442
-          {
442
+            {
443 443
             $opts = 0; // simple client copy in stub code
444
-          }
445
-          else
446
-          {
444
+            }
445
+            else
446
+            {
447 447
             $opts = 1; // complete client copy in stub code
448
-          }
449
-          if ($wstype == 1)
450
-          {
448
+            }
449
+            if ($wstype == 1)
450
+            {
451 451
             $prefix = 'jsonrpc';
452
-          }
453
-          else
454
-          {
452
+            }
453
+            else
454
+            {
455 455
             $prefix = 'xmlrpc';
456
-          }
457
-          //$code = wrap_xmlrpc_method($client, $method, $methodsig, 0, $proto, '', $opts);
458
-          $code = build_remote_method_wrapper_code($client, $method, str_replace('.', '_', $prefix.'_'.$method), $msig, $mdesc, $timeout, $proto, $opts, $prefix);
459
-          //if ($code)
460
-          //{
461
-              echo "<div id=\"phpcode\">\n";
456
+            }
457
+            //$code = wrap_xmlrpc_method($client, $method, $methodsig, 0, $proto, '', $opts);
458
+            $code = build_remote_method_wrapper_code($client, $method, str_replace('.', '_', $prefix.'_'.$method), $msig, $mdesc, $timeout, $proto, $opts, $prefix);
459
+            //if ($code)
460
+            //{
461
+                echo "<div id=\"phpcode\">\n";
462 462
             highlight_string("<?php\n".$code['docstring'].$code['source'].'?>');
463 463
             echo "\n</div>";
464
-          //}
465
-          //else
466
-          //{
467
-          //  echo 'Error while building php code stub...';
468
-          }
464
+            //}
465
+            //else
466
+            //{
467
+            //  echo 'Error while building php code stub...';
468
+            }
469 469
 
470
-          break;
470
+            break;
471 471
 
472 472
         case 'execute':
473 473
           echo '<div id="response"><h2>Response:</h2>'.htmlspecialchars($response->serialize(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']).'</div>';
474
-          break;
474
+            break;
475 475
 
476 476
         default: // give a warning
477 477
       }
478 478
     } // if !$response->faultCode()
479 479
     } // if $response
480
-  }
481
-  else
482
-  {
480
+    }
481
+    else
482
+    {
483 483
     // no action taken yet: give some instructions on debugger usage
484 484
 ?>
485 485
 
@@ -490,10 +490,10 @@  discard block
 block discarded – undo
490 490
 <li>To run method: click on 'load method synopsis' for desired method. This will load a skeleton for method call parameters in the form above. Complete all xmlrpc values with appropriate data and click 'Execute'</li>
491 491
 </ol>
492 492
 <?php
493
-  if (!extension_loaded('curl'))
494
-  {
495
-      echo "<p class=\"evidence\">You will need to enable the CURL extension to use the HTTPS and HTTP 1.1 transports</p>\n";
496
-  }
493
+    if (!extension_loaded('curl'))
494
+    {
495
+        echo "<p class=\"evidence\">You will need to enable the CURL extension to use the HTTPS and HTTP 1.1 transports</p>\n";
496
+    }
497 497
 ?>
498 498
 
499 499
 <h3>Example:</h3>
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 <li>2005-06-24: fixed error with calling methods having parameters...</li>
522 522
 </ul>
523 523
 <?php
524
-  }
524
+    }
525 525
 ?>
526 526
 </body>
527 527
 </html>
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     }
82 82
     if ($proxy != '') {
83 83
       $pproxy = explode(':', $proxy);
84
-      if (count($pproxy) > 1)
84
+      if (count($pproxy)>1)
85 85
         $pport = $pproxy[1];
86 86
       else
87 87
         $pport = 8080;
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
         if ($wstype == 1)
176 176
         {
177 177
           $msg[0]->payload = "{\n".
178
-            '"method": "' . $method . "\",\n\"params\": [" .
179
-            $payload .
178
+            '"method": "'.$method."\",\n\"params\": [".
179
+            $payload.
180 180
             "\n],\n\"id\": ";
181 181
             // fix: if user gave an empty string, use NULL, or we'll break json syntax
182 182
             if ($id == "")
@@ -196,10 +196,10 @@  discard block
 block discarded – undo
196 196
             }
197 197
         }
198 198
         else
199
-          $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
200
-            '<methodName>' . $method . "</methodName>\n<params>" .
201
-            $payload .
202
-            "</params>\n" . $msg[0]->xml_footer();
199
+          $msg[0]->payload = $msg[0]->xml_header($inputcharset).
200
+            '<methodName>'.$method."</methodName>\n<params>".
201
+            $payload.
202
+            "</params>\n".$msg[0]->xml_footer();
203 203
         $actionname = 'Execution of method '.$method;
204 204
         break;
205 205
       default: // give a warning
@@ -214,20 +214,20 @@  discard block
 block discarded – undo
214 214
     $response = null;
215 215
     // execute method(s)
216 216
     if ($debug)
217
-      echo '<div class="dbginfo"><h2>Debug info:</h2>';  /// @todo use ob_start instead
217
+      echo '<div class="dbginfo"><h2>Debug info:</h2>'; /// @todo use ob_start instead
218 218
     $resp = array();
219
-    $mtime = explode(' ',microtime());
220
-    $time = (float)$mtime[0] + (float)$mtime[1];
219
+    $mtime = explode(' ', microtime());
220
+    $time = (float) $mtime[0]+(float) $mtime[1];
221 221
     foreach ($msg as $message)
222 222
     {
223 223
       // catch errors: for older xmlrpc libs, send does not return by ref
224
-      @$response =& $client->send($message, $timeout, $httpprotocol);
224
+      @$response = & $client->send($message, $timeout, $httpprotocol);
225 225
       $resp[] = $response;
226 226
       if (!$response || $response->faultCode())
227 227
         break;
228 228
     }
229
-    $mtime = explode(' ',microtime());
230
-    $time = (float)$mtime[0] + (float)$mtime[1] - $time;
229
+    $mtime = explode(' ', microtime());
230
+    $time = (float) $mtime[0]+(float) $mtime[1]-$time;
231 231
     if ($debug)
232 232
       echo "</div>\n";
233 233
 
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
       // call failed! echo out error msg!
240 240
       //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
241 241
       echo "<h3>$protoname call FAILED!</h3>\n";
242
-      echo "<p>Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) .
243
-        "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) . "'</p>\n";
242
+      echo "<p>Fault code: [".htmlspecialchars($response->faultCode(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']).
243
+        "] Reason: '".htmlspecialchars($response->faultString(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding'])."'</p>\n";
244 244
       echo (strftime("%d/%b/%Y:%H:%M:%S\n"));
245 245
     }
246 246
     else
247 247
     {
248 248
       // call succeeded: parse results
249 249
       //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
250
-      printf ("<h3>%s call(s) OK (%.2f secs.)</h3>\n", $protoname, $time);
250
+      printf("<h3>%s call(s) OK (%.2f secs.)</h3>\n", $protoname, $time);
251 251
       echo (strftime("%d/%b/%Y:%H:%M:%S\n"));
252 252
 
253 253
       switch ($action)
@@ -255,15 +255,15 @@  discard block
 block discarded – undo
255 255
         case 'list':
256 256
 
257 257
         $v = $response->value();
258
-        if ($v->kindOf()=="array")
258
+        if ($v->kindOf() == "array")
259 259
         {
260 260
           $max = $v->arraysize();
261 261
           echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
262 262
           echo "<thead>\n<tr><th>Method</th><th>Description</th></tr>\n</thead>\n<tbody>\n";
263
-          for($i=0; $i < $max; $i++)
263
+          for ($i = 0; $i<$max; $i++)
264 264
           {
265 265
             $rec = $v->arraymem($i);
266
-            if ($i%2) $class=' class="oddrow"'; else $class = ' class="evenrow"';
266
+            if ($i % 2) $class = ' class="oddrow"'; else $class = ' class="evenrow"';
267 267
             echo ("<tr><td$class>".htmlspecialchars($rec->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding'])."</td><td$class><form action=\"controller.php\" method=\"get\" target=\"frmcontroller\">".
268 268
               "<input type=\"hidden\" name=\"host\" value=\"".htmlspecialchars($host, ENT_COMPAT, $inputcharset)."\" />".
269 269
               "<input type=\"hidden\" name=\"port\" value=\"".htmlspecialchars($port, ENT_COMPAT, $inputcharset)."\" />".
@@ -319,33 +319,33 @@  discard block
 block discarded – undo
319 319
         if ($desc == "")
320 320
           $desc = "-";
321 321
         echo "<tr><td class=\"evenrow\">Description</td><td colspan=\"3\" class=\"evenrow\">$desc</td></tr>\n";
322
-        $payload="";
323
-        $alt_payload="";
324
-        if ($r2->kindOf()!="array")
322
+        $payload = "";
323
+        $alt_payload = "";
324
+        if ($r2->kindOf() != "array")
325 325
           echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\">&nbsp;</td></tr>\n";
326 326
         else
327 327
         {
328
-          for($i=0; $i < $r2->arraysize(); $i++)
328
+          for ($i = 0; $i<$r2->arraysize(); $i++)
329 329
           {
330
-            if ($i+1%2) $class=' class="oddrow"'; else $class = ' class="evenrow"';
330
+            if ($i+1 % 2) $class = ' class="oddrow"'; else $class = ' class="evenrow"';
331 331
             echo "<tr><td$class>Signature&nbsp;".($i+1)."</td><td$class>";
332 332
             $x = $r2->arraymem($i);
333
-            if ($x->kindOf()=="array")
333
+            if ($x->kindOf() == "array")
334 334
             {
335 335
               $ret = $x->arraymem(0);
336
-              echo "<code>OUT:&nbsp;" . htmlspecialchars($ret->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) . "<br />IN: (";
337
-              if ($x->arraysize() > 1)
336
+              echo "<code>OUT:&nbsp;".htmlspecialchars($ret->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding'])."<br />IN: (";
337
+              if ($x->arraysize()>1)
338 338
               {
339
-                for($k = 1; $k < $x->arraysize(); $k++)
339
+                for ($k = 1; $k<$x->arraysize(); $k++)
340 340
                 {
341 341
                   $y = $x->arraymem($k);
342 342
                   echo $y->scalarval();
343 343
                   if ($wstype != 1)
344 344
                   {
345
-                    $payload = $payload . '<param><value><'.htmlspecialchars($y->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']).'></'.htmlspecialchars($y->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding'])."></value></param>\n";
345
+                    $payload = $payload.'<param><value><'.htmlspecialchars($y->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']).'></'.htmlspecialchars($y->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding'])."></value></param>\n";
346 346
                   }
347 347
                   $alt_payload .= $y->scalarval();
348
-                  if ($k < $x->arraysize()-1)
348
+                  if ($k<$x->arraysize()-1)
349 349
                   {
350 350
                     $alt_payload .= ';';
351 351
                     echo ", ";
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         case 'wrap':
430 430
           $r1 = $resp[0]->value();
431 431
           $r2 = $resp[1]->value();
432
-          if ($r2->kindOf()!="array" || $r2->arraysize() <= $methodsig)
432
+          if ($r2->kindOf() != "array" || $r2->arraysize()<=$methodsig)
433 433
             echo "Error: signature unknown\n";
434 434
           else
435 435
           {
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
           $msig = php_xmlrpc_decode($r2);
438 438
           $msig = $msig[$methodsig];
439 439
           $proto = $protocol == 2 ? 'https' : $protocol == 1 ? 'http11' : '';
440
-          if ($proxy  == '' && $username == '' && !$requestcompression && !$responsecompression &&
440
+          if ($proxy == '' && $username == '' && !$requestcompression && !$responsecompression &&
441 441
             $clientcookies == '')
442 442
           {
443 443
             $opts = 0; // simple client copy in stub code
Please login to merge, or discard this patch.
Braces   +62 added lines, -53 removed lines patch added patch discarded remove patch
@@ -41,8 +41,9 @@  discard block
 block discarded – undo
41 41
   {
42 42
 
43 43
     // make sure the script waits long enough for the call to complete...
44
-    if ($timeout)
45
-      set_time_limit($timeout+10);
44
+    if ($timeout) {
45
+          set_time_limit($timeout+10);
46
+    }
46 47
 
47 48
     include('xmlrpc.inc');
48 49
     if ($wstype == 1)
@@ -55,8 +56,7 @@  discard block
 block discarded – undo
55 56
       $clientclass = 'jsonrpc_client';
56 57
       $msgclass = 'jsonrpcmsg';
57 58
       $protoname = 'JSONRPC';
58
-    }
59
-    else
59
+    } else
60 60
     {
61 61
       $clientclass = 'xmlrpc_client';
62 62
       $msgclass = 'xmlrpcmsg';
@@ -74,17 +74,17 @@  discard block
 block discarded – undo
74 74
     if ($protocol == 2)
75 75
     {
76 76
       $server = 'https://'.$server;
77
-    }
78
-    else
77
+    } else
79 78
     {
80 79
       $server = 'http://'.$server;
81 80
     }
82 81
     if ($proxy != '') {
83 82
       $pproxy = explode(':', $proxy);
84
-      if (count($pproxy) > 1)
85
-        $pport = $pproxy[1];
86
-      else
87
-        $pport = 8080;
83
+      if (count($pproxy) > 1) {
84
+              $pport = $pproxy[1];
85
+      } else {
86
+              $pport = 8080;
87
+      }
88 88
       $client->setProxy($pproxy[0], $pport, $proxyuser, $proxypwd);
89 89
     }
90 90
 
@@ -97,14 +97,15 @@  discard block
 block discarded – undo
97 97
         $client->setCaCertificate($cainfo);
98 98
       }
99 99
       $httpprotocol = 'https';
100
+    } else if ($protocol == 1) {
101
+          $httpprotocol = 'http11';
102
+    } else {
103
+          $httpprotocol = 'http';
100 104
     }
101
-    else if ($protocol == 1)
102
-      $httpprotocol = 'http11';
103
-    else
104
-      $httpprotocol = 'http';
105 105
 
106
-    if ($username)
107
-      $client->setCredentials($username, $password, $authtype);
106
+    if ($username) {
107
+          $client->setCredentials($username, $password, $authtype);
108
+    }
108 109
 
109 110
     $client->setDebug($debug);
110 111
 
@@ -168,8 +169,9 @@  discard block
 block discarded – undo
168 169
         $actionname = 'List of available methods';
169 170
         break;
170 171
       case 'execute':
171
-        if (!payload_is_safe($payload))
172
-          die("Tsk tsk tsk, please stop it or I will have to call in the cops!");
172
+        if (!payload_is_safe($payload)) {
173
+                  die("Tsk tsk tsk, please stop it or I will have to call in the cops!");
174
+        }
173 175
         $msg[0] = new $msgclass($method, null, $id);
174 176
         // hack! build xml payload by hand
175 177
         if ($wstype == 1)
@@ -182,24 +184,22 @@  discard block
 block discarded – undo
182 184
             if ($id == "")
183 185
             {
184 186
                 $msg[0]->payload .= "null\n}";
185
-            }
186
-            else
187
+            } else
187 188
             {
188 189
               if (is_numeric($id) || $id == 'false' || $id == 'true' || $id == 'null')
189 190
               {
190 191
                 $msg[0]->payload .= "$id\n}";
191
-              }
192
-              else
192
+              } else
193 193
               {
194 194
                 $msg[0]->payload .= "\"$id\"\n}";
195 195
               }
196 196
             }
197
-        }
198
-        else
199
-          $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
197
+        } else {
198
+                  $msg[0]->payload = $msg[0]->xml_header($inputcharset) .
200 199
             '<methodName>' . $method . "</methodName>\n<params>" .
201 200
             $payload .
202 201
             "</params>\n" . $msg[0]->xml_footer();
202
+        }
203 203
         $actionname = 'Execution of method '.$method;
204 204
         break;
205 205
       default: // give a warning
@@ -213,8 +213,10 @@  discard block
 block discarded – undo
213 213
 
214 214
     $response = null;
215 215
     // execute method(s)
216
-    if ($debug)
217
-      echo '<div class="dbginfo"><h2>Debug info:</h2>';  /// @todo use ob_start instead
216
+    if ($debug) {
217
+          echo '<div class="dbginfo"><h2>Debug info:</h2>';
218
+    }
219
+    /// @todo use ob_start instead
218 220
     $resp = array();
219 221
     $mtime = explode(' ',microtime());
220 222
     $time = (float)$mtime[0] + (float)$mtime[1];
@@ -223,13 +225,15 @@  discard block
 block discarded – undo
223 225
       // catch errors: for older xmlrpc libs, send does not return by ref
224 226
       @$response =& $client->send($message, $timeout, $httpprotocol);
225 227
       $resp[] = $response;
226
-      if (!$response || $response->faultCode())
227
-        break;
228
+      if (!$response || $response->faultCode()) {
229
+              break;
230
+      }
228 231
     }
229 232
     $mtime = explode(' ',microtime());
230 233
     $time = (float)$mtime[0] + (float)$mtime[1] - $time;
231
-    if ($debug)
232
-      echo "</div>\n";
234
+    if ($debug) {
235
+          echo "</div>\n";
236
+    }
233 237
 
234 238
     if ($response)
235 239
     {
@@ -242,8 +246,7 @@  discard block
 block discarded – undo
242 246
       echo "<p>Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) .
243 247
         "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']) . "'</p>\n";
244 248
       echo (strftime("%d/%b/%Y:%H:%M:%S\n"));
245
-    }
246
-    else
249
+    } else
247 250
     {
248 251
       // call succeeded: parse results
249 252
       //echo '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
@@ -263,7 +266,11 @@  discard block
 block discarded – undo
263 266
           for($i=0; $i < $max; $i++)
264 267
           {
265 268
             $rec = $v->arraymem($i);
266
-            if ($i%2) $class=' class="oddrow"'; else $class = ' class="evenrow"';
269
+            if ($i%2) {
270
+                $class=' class="oddrow"';
271
+            } else {
272
+                $class = ' class="evenrow"';
273
+            }
267 274
             echo ("<tr><td$class>".htmlspecialchars($rec->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding'])."</td><td$class><form action=\"controller.php\" method=\"get\" target=\"frmcontroller\">".
268 275
               "<input type=\"hidden\" name=\"host\" value=\"".htmlspecialchars($host, ENT_COMPAT, $inputcharset)."\" />".
269 276
               "<input type=\"hidden\" name=\"port\" value=\"".htmlspecialchars($port, ENT_COMPAT, $inputcharset)."\" />".
@@ -316,18 +323,23 @@  discard block
 block discarded – undo
316 323
         echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
317 324
         echo "<thead>\n<tr><th>Method</th><th>".htmlspecialchars($method, ENT_COMPAT, $inputcharset)."</th><th>&nbsp;</th><th>&nbsp;</th></tr>\n</thead>\n<tbody>\n";
318 325
         $desc = htmlspecialchars($r1->scalarval(), ENT_COMPAT, $GLOBALS['xmlrpc_internalencoding']);
319
-        if ($desc == "")
320
-          $desc = "-";
326
+        if ($desc == "") {
327
+                  $desc = "-";
328
+        }
321 329
         echo "<tr><td class=\"evenrow\">Description</td><td colspan=\"3\" class=\"evenrow\">$desc</td></tr>\n";
322 330
         $payload="";
323 331
         $alt_payload="";
324
-        if ($r2->kindOf()!="array")
325
-          echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\">&nbsp;</td></tr>\n";
326
-        else
332
+        if ($r2->kindOf()!="array") {
333
+                  echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\">&nbsp;</td></tr>\n";
334
+        } else
327 335
         {
328 336
           for($i=0; $i < $r2->arraysize(); $i++)
329 337
           {
330
-            if ($i+1%2) $class=' class="oddrow"'; else $class = ' class="evenrow"';
338
+            if ($i+1%2) {
339
+                $class=' class="oddrow"';
340
+            } else {
341
+                $class = ' class="evenrow"';
342
+            }
331 343
             echo "<tr><td$class>Signature&nbsp;".($i+1)."</td><td$class>";
332 344
             $x = $r2->arraymem($i);
333 345
             if ($x->kindOf()=="array")
@@ -353,8 +365,7 @@  discard block
 block discarded – undo
353 365
                 }
354 366
               }
355 367
               echo ")</code>";
356
-            }
357
-            else
368
+            } else
358 369
             {
359 370
               echo 'Unknown';
360 371
             }
@@ -386,8 +397,9 @@  discard block
 block discarded – undo
386 397
             "<input type=\"hidden\" name=\"altmethodpayload\" value=\"".htmlspecialchars($alt_payload, ENT_COMPAT, $inputcharset)."\" />".
387 398
             "<input type=\"hidden\" name=\"wstype\" value=\"$wstype\" />".
388 399
             "<input type=\"hidden\" name=\"action\" value=\"execute\" />";
389
-            if ($wstype != 1)
390
-              echo "<input type=\"submit\" value=\"Load method synopsis\" />";
400
+            if ($wstype != 1) {
401
+                          echo "<input type=\"submit\" value=\"Load method synopsis\" />";
402
+            }
391 403
             echo "</form></td>\n";
392 404
 
393 405
             echo "<td$class><form action=\"controller.php\" target=\"frmcontroller\" method=\"get\">".
@@ -429,9 +441,9 @@  discard block
 block discarded – undo
429 441
         case 'wrap':
430 442
           $r1 = $resp[0]->value();
431 443
           $r2 = $resp[1]->value();
432
-          if ($r2->kindOf()!="array" || $r2->arraysize() <= $methodsig)
433
-            echo "Error: signature unknown\n";
434
-          else
444
+          if ($r2->kindOf()!="array" || $r2->arraysize() <= $methodsig) {
445
+                      echo "Error: signature unknown\n";
446
+          } else
435 447
           {
436 448
           $mdesc = $r1->scalarval();
437 449
           $msig = php_xmlrpc_decode($r2);
@@ -441,16 +453,14 @@  discard block
 block discarded – undo
441 453
             $clientcookies == '')
442 454
           {
443 455
             $opts = 0; // simple client copy in stub code
444
-          }
445
-          else
456
+          } else
446 457
           {
447 458
             $opts = 1; // complete client copy in stub code
448 459
           }
449 460
           if ($wstype == 1)
450 461
           {
451 462
             $prefix = 'jsonrpc';
452
-          }
453
-          else
463
+          } else
454 464
           {
455 465
             $prefix = 'xmlrpc';
456 466
           }
@@ -477,8 +487,7 @@  discard block
 block discarded – undo
477 487
       }
478 488
     } // if !$response->faultCode()
479 489
     } // if $response
480
-  }
481
-  else
490
+  } else
482 491
   {
483 492
     // no action taken yet: give some instructions on debugger usage
484 493
 ?>
Please login to merge, or discard this patch.
debugger/index.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@
 block discarded – undo
1 1
 <?php
2
-  $query = '';
3
-  if (isset($_GET['run']))
4
-  {
2
+    $query = '';
3
+    if (isset($_GET['run']))
4
+    {
5 5
     $path = parse_url($_GET['run']);
6 6
     if (isset($path['query']))
7
-      $query = '?'.$path['query'];
8
-  }
7
+        $query = '?'.$path['query'];
8
+    }
9 9
 ?>
10 10
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
11 11
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,9 @@
 block discarded – undo
3 3
   if (isset($_GET['run']))
4 4
   {
5 5
     $path = parse_url($_GET['run']);
6
-    if (isset($path['query']))
7
-      $query = '?'.$path['query'];
6
+    if (isset($path['query'])) {
7
+          $query = '?'.$path['query'];
8
+    }
8 9
   }
9 10
 ?>
10 11
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
Please login to merge, or discard this patch.
debugger/controller.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@
 block discarded – undo
13 13
  * @todo add http no-cache headers
14 14
  **/
15 15
 
16
-  include(dirname(__FILE__).'/common.php');
17
-  if ($action == '')
16
+    include(dirname(__FILE__).'/common.php');
17
+    if ($action == '')
18 18
     $action = 'list';
19 19
 
20
-  // relative path to the visual xmlrpc editing dialog
21
-  $editorpath = '../../javascript/debugger/';
22
-  $editorlibs = '../../javascript/lib/';
20
+    // relative path to the visual xmlrpc editing dialog
21
+    $editorpath = '../../javascript/debugger/';
22
+    $editorlibs = '../../javascript/lib/';
23 23
 ?>
24 24
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
25 25
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 //-->
215 215
 </script>
216 216
 </head>
217
-<body onload="switchtransport(<?php echo $wstype;?>); switchaction(); switchssl(); switchauth(); swicthcainfo();<?php if ($run) echo ' document.forms[2].submit();'; ?>">
217
+<body onload="switchtransport(<?php echo $wstype; ?>); switchaction(); switchssl(); switchauth(); swicthcainfo();<?php if ($run) echo ' document.forms[2].submit();'; ?>">
218 218
 <h1>XMLRPC <form name="frmxmlrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(0);"/></form>
219 219
 /<form name="frmjsonrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(1);"/></form>JSONRPC Debugger (based on the <a href="http://phpxmlrpc.sourceforge.net">PHP-XMLRPC</a> library)</h1>
220 220
 <form name="frmaction" method="get" action="action.php" target="frmaction" onSubmit="switchFormMethod();"
@@ -232,10 +232,10 @@  discard block
 block discarded – undo
232 232
 <table id="actionblock">
233 233
 <tr>
234 234
 <td><h2>Action</h2></td>
235
-<td>List available methods<input type="radio" name="action" value="list"<?php if ($action=='list') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
236
-<td>Describe method<input type="radio" name="action" value="describe"<?php if ($action=='describe') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
237
-<td>Execute method<input type="radio" name="action" value="execute"<?php if ($action=='execute') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
238
-<td>Generate stub for method call<input type="radio" name="action" value="wrap"<?php if ($action=='wrap') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
235
+<td>List available methods<input type="radio" name="action" value="list"<?php if ($action == 'list') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
236
+<td>Describe method<input type="radio" name="action" value="describe"<?php if ($action == 'describe') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
237
+<td>Execute method<input type="radio" name="action" value="execute"<?php if ($action == 'execute') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
238
+<td>Generate stub for method call<input type="radio" name="action" value="wrap"<?php if ($action == 'wrap') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
239 239
 </tr>
240 240
 </table>
241 241
 <input type="hidden" name="methodsig" value="<?php echo htmlspecialchars($methodsig, ENT_COMPAT, $inputcharset); ?>" />
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 <td class="labelcell">Name:</td><td><input type="text" name="method" value="<?php echo htmlspecialchars($method, ENT_COMPAT, $inputcharset); ?>" /></td>
247 247
 <td class="labelcell">Payload:<br/><div id="methodpayloadbtn"></div></td><td><textarea id="methodpayload" name="methodpayload" rows="1" cols="40"><?php echo htmlspecialchars($payload, ENT_COMPAT, $inputcharset); ?></textarea></td>
248 248
 <td class="labelcell" id="idcell">Msg id: <input type="text" name="id" size="3" value="<?php echo htmlspecialchars($id, ENT_COMPAT, $inputcharset); ?>"/></td>
249
-<td><input type="hidden" name="wstype" value="<?php echo $wstype;?>" />
249
+<td><input type="hidden" name="wstype" value="<?php echo $wstype; ?>" />
250 250
 <input type="submit" value="Execute" onclick="return verifyserver();"/></td>
251 251
 </tr>
252 252
 </table>
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 <option value="2"<?php if ($debug == 2) echo ' selected="selected"'; ?>>More</option>
261 261
 </select>
262 262
 </td>
263
-<td class="labelcell">Timeout:</td><td><input type="text" name="timeout" size="3" value="<?php if ($timeout > 0) echo $timeout; ?>" /></td>
263
+<td class="labelcell">Timeout:</td><td><input type="text" name="timeout" size="3" value="<?php if ($timeout>0) echo $timeout; ?>" /></td>
264 264
 <td class="labelcell">Protocol:</td><td><select name="protocol" onchange="switchssl(); switchauth(); swicthcainfo();">
265 265
 <option value="0"<?php if ($protocol == 0) echo ' selected="selected"'; ?>>HTTP 1.0</option>
266 266
 <option value="1"<?php if ($protocol == 1) echo ' selected="selected"'; ?>>HTTP 1.1</option>
Please login to merge, or discard this patch.
Braces   +107 added lines, -28 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  **/
15 15
 
16 16
   include(dirname(__FILE__).'/common.php');
17
-  if ($action == '')
18
-    $action = 'list';
17
+  if ($action == '') {
18
+      $action = 'list';
19
+  }
19 20
 
20 21
   // relative path to the visual xmlrpc editing dialog
21 22
   $editorpath = '../../javascript/debugger/';
@@ -214,7 +215,10 @@  discard block
 block discarded – undo
214 215
 //-->
215 216
 </script>
216 217
 </head>
217
-<body onload="switchtransport(<?php echo $wstype;?>); switchaction(); switchssl(); switchauth(); swicthcainfo();<?php if ($run) echo ' document.forms[2].submit();'; ?>">
218
+<body onload="switchtransport(<?php echo $wstype;?>); switchaction(); switchssl(); switchauth(); swicthcainfo();<?php if ($run) {
219
+    echo ' document.forms[2].submit();';
220
+}
221
+?>">
218 222
 <h1>XMLRPC <form name="frmxmlrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(0);"/></form>
219 223
 /<form name="frmjsonrpc" style="display: inline;" action="."><input name="yes" type="radio" onclick="switchtransport(1);"/></form>JSONRPC Debugger (based on the <a href="http://phpxmlrpc.sourceforge.net">PHP-XMLRPC</a> library)</h1>
220 224
 <form name="frmaction" method="get" action="action.php" target="frmaction" onSubmit="switchFormMethod();"
@@ -232,10 +236,22 @@  discard block
 block discarded – undo
232 236
 <table id="actionblock">
233 237
 <tr>
234 238
 <td><h2>Action</h2></td>
235
-<td>List available methods<input type="radio" name="action" value="list"<?php if ($action=='list') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
236
-<td>Describe method<input type="radio" name="action" value="describe"<?php if ($action=='describe') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
237
-<td>Execute method<input type="radio" name="action" value="execute"<?php if ($action=='execute') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
238
-<td>Generate stub for method call<input type="radio" name="action" value="wrap"<?php if ($action=='wrap') echo ' checked="checked"'; ?> onclick="switchaction();" /></td>
239
+<td>List available methods<input type="radio" name="action" value="list"<?php if ($action=='list') {
240
+    echo ' checked="checked"';
241
+}
242
+?> onclick="switchaction();" /></td>
243
+<td>Describe method<input type="radio" name="action" value="describe"<?php if ($action=='describe') {
244
+    echo ' checked="checked"';
245
+}
246
+?> onclick="switchaction();" /></td>
247
+<td>Execute method<input type="radio" name="action" value="execute"<?php if ($action=='execute') {
248
+    echo ' checked="checked"';
249
+}
250
+?> onclick="switchaction();" /></td>
251
+<td>Generate stub for method call<input type="radio" name="action" value="wrap"<?php if ($action=='wrap') {
252
+    echo ' checked="checked"';
253
+}
254
+?> onclick="switchaction();" /></td>
239 255
 </tr>
240 256
 </table>
241 257
 <input type="hidden" name="methodsig" value="<?php echo htmlspecialchars($methodsig, ENT_COMPAT, $inputcharset); ?>" />
@@ -255,16 +271,37 @@  discard block
 block discarded – undo
255 271
 <tr>
256 272
 <td><h2>Client options</h2></td>
257 273
 <td class="labelcell">Show debug info:</td><td><select name="debug">
258
-<option value="0"<?php if ($debug == 0) echo ' selected="selected"'; ?>>No</option>
259
-<option value="1"<?php if ($debug == 1) echo ' selected="selected"'; ?>>Yes</option>
260
-<option value="2"<?php if ($debug == 2) echo ' selected="selected"'; ?>>More</option>
274
+<option value="0"<?php if ($debug == 0) {
275
+    echo ' selected="selected"';
276
+}
277
+?>>No</option>
278
+<option value="1"<?php if ($debug == 1) {
279
+    echo ' selected="selected"';
280
+}
281
+?>>Yes</option>
282
+<option value="2"<?php if ($debug == 2) {
283
+    echo ' selected="selected"';
284
+}
285
+?>>More</option>
261 286
 </select>
262 287
 </td>
263
-<td class="labelcell">Timeout:</td><td><input type="text" name="timeout" size="3" value="<?php if ($timeout > 0) echo $timeout; ?>" /></td>
288
+<td class="labelcell">Timeout:</td><td><input type="text" name="timeout" size="3" value="<?php if ($timeout > 0) {
289
+    echo $timeout;
290
+}
291
+?>" /></td>
264 292
 <td class="labelcell">Protocol:</td><td><select name="protocol" onchange="switchssl(); switchauth(); swicthcainfo();">
265
-<option value="0"<?php if ($protocol == 0) echo ' selected="selected"'; ?>>HTTP 1.0</option>
266
-<option value="1"<?php if ($protocol == 1) echo ' selected="selected"'; ?>>HTTP 1.1</option>
267
-<option value="2"<?php if ($protocol == 2) echo ' selected="selected"'; ?>>HTTPS</option>
293
+<option value="0"<?php if ($protocol == 0) {
294
+    echo ' selected="selected"';
295
+}
296
+?>>HTTP 1.0</option>
297
+<option value="1"<?php if ($protocol == 1) {
298
+    echo ' selected="selected"';
299
+}
300
+?>>HTTP 1.1</option>
301
+<option value="2"<?php if ($protocol == 2) {
302
+    echo ' selected="selected"';
303
+}
304
+?>>HTTPS</option>
268 305
 </select></td>
269 306
 </tr>
270 307
 <tr>
@@ -272,20 +309,41 @@  discard block
 block discarded – undo
272 309
 <td class="labelcell">Username:</td><td><input type="text" name="username" value="<?php echo htmlspecialchars($username, ENT_COMPAT, $inputcharset); ?>" /></td>
273 310
 <td class="labelcell">Pwd:</td><td><input type="password" name="password" value="<?php echo htmlspecialchars($password, ENT_COMPAT, $inputcharset); ?>" /></td>
274 311
 <td class="labelcell">Type</td><td><select name="authtype">
275
-<option value="1"<?php if ($authtype == 1) echo ' selected="selected"'; ?>>Basic</option>
276
-<option value="2"<?php if ($authtype == 2) echo ' selected="selected"'; ?>>Digest</option>
277
-<option value="8"<?php if ($authtype == 8) echo ' selected="selected"'; ?>>NTLM</option>
312
+<option value="1"<?php if ($authtype == 1) {
313
+    echo ' selected="selected"';
314
+}
315
+?>>Basic</option>
316
+<option value="2"<?php if ($authtype == 2) {
317
+    echo ' selected="selected"';
318
+}
319
+?>>Digest</option>
320
+<option value="8"<?php if ($authtype == 8) {
321
+    echo ' selected="selected"';
322
+}
323
+?>>NTLM</option>
278 324
 </select></td>
279 325
 <td></td>
280 326
 </tr>
281 327
 <tr>
282 328
 <td class="labelcell">SSL:</td>
283 329
 <td class="labelcell">Verify Host's CN:</td><td><select name="verifyhost">
284
-<option value="0"<?php if ($verifyhost == 0) echo ' selected="selected"'; ?>>No</option>
285
-<option value="1"<?php if ($verifyhost == 1) echo ' selected="selected"'; ?>>Check CN existance</option>
286
-<option value="2"<?php if ($verifyhost == 2) echo ' selected="selected"'; ?>>Check CN match</option>
330
+<option value="0"<?php if ($verifyhost == 0) {
331
+    echo ' selected="selected"';
332
+}
333
+?>>No</option>
334
+<option value="1"<?php if ($verifyhost == 1) {
335
+    echo ' selected="selected"';
336
+}
337
+?>>Check CN existance</option>
338
+<option value="2"<?php if ($verifyhost == 2) {
339
+    echo ' selected="selected"';
340
+}
341
+?>>Check CN match</option>
287 342
 </select></td>
288
-<td class="labelcell">Verify Cert:</td><td><input type="checkbox" value="1" name="verifypeer" onclick="swicthcainfo();"<?php if ($verifypeer) echo ' checked="checked"'; ?> /></td>
343
+<td class="labelcell">Verify Cert:</td><td><input type="checkbox" value="1" name="verifypeer" onclick="swicthcainfo();"<?php if ($verifypeer) {
344
+    echo ' checked="checked"';
345
+}
346
+?> /></td>
289 347
 <td class="labelcell">CA Cert file:</td><td><input type="text" name="cainfo" value="<?php echo htmlspecialchars($cainfo, ENT_COMPAT, $inputcharset); ?>" /></td>
290 348
 </tr>
291 349
 <tr>
@@ -297,15 +355,36 @@  discard block
 block discarded – undo
297 355
 <tr>
298 356
 <td class="labelcell">COMPRESSION:</td>
299 357
 <td class="labelcell">Request:</td><td><select name="requestcompression">
300
-<option value="0"<?php if ($requestcompression == 0) echo ' selected="selected"'; ?>>None</option>
301
-<option value="1"<?php if ($requestcompression == 1) echo ' selected="selected"'; ?>>Gzip</option>
302
-<option value="2"<?php if ($requestcompression == 2) echo ' selected="selected"'; ?>>Deflate</option>
358
+<option value="0"<?php if ($requestcompression == 0) {
359
+    echo ' selected="selected"';
360
+}
361
+?>>None</option>
362
+<option value="1"<?php if ($requestcompression == 1) {
363
+    echo ' selected="selected"';
364
+}
365
+?>>Gzip</option>
366
+<option value="2"<?php if ($requestcompression == 2) {
367
+    echo ' selected="selected"';
368
+}
369
+?>>Deflate</option>
303 370
 </select></td>
304 371
 <td class="labelcell">Response:</td><td><select name="responsecompression">
305
-<option value="0"<?php if ($responsecompression == 0) echo ' selected="selected"'; ?>>None</option>
306
-<option value="1"<?php if ($responsecompression == 1) echo ' selected="selected"'; ?>>Gzip</option>
307
-<option value="2"<?php if ($responsecompression == 2) echo ' selected="selected"'; ?>>Deflate</option>
308
-<option value="3"<?php if ($responsecompression == 3) echo ' selected="selected"'; ?>>Any</option>
372
+<option value="0"<?php if ($responsecompression == 0) {
373
+    echo ' selected="selected"';
374
+}
375
+?>>None</option>
376
+<option value="1"<?php if ($responsecompression == 1) {
377
+    echo ' selected="selected"';
378
+}
379
+?>>Gzip</option>
380
+<option value="2"<?php if ($responsecompression == 2) {
381
+    echo ' selected="selected"';
382
+}
383
+?>>Deflate</option>
384
+<option value="3"<?php if ($responsecompression == 3) {
385
+    echo ' selected="selected"';
386
+}
387
+?>>Any</option>
309 388
 </select></td>
310 389
 <td></td>
311 390
 </tr>
Please login to merge, or discard this patch.
demo/server/proxy.php 2 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -9,77 +9,77 @@
 block discarded – undo
9 9
  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
10 10
  */
11 11
 
12
-	include("xmlrpc.inc");
13
-	include("xmlrpcs.inc");
12
+    include("xmlrpc.inc");
13
+    include("xmlrpcs.inc");
14 14
 
15
-	/**
16
-	* Forward an xmlrpc request to another server, and return to client the response received.
17
-	* @param xmlrpcmsg $m (see method docs below for a description of the expected parameters)
18
-	* @return xmlrpcresp
19
-	*/
20
-	function forward_request($m)
21
-	{
22
-		// create client
23
-		$timeout = 0;
24
-		$url = php_xmlrpc_decode($m->getParam(0));
25
-		$c = new xmlrpc_client($url);
26
-		if ($m->getNumParams() > 3)
27
-		{
28
-			// we have to set some options onto the client.
29
-			// Note that if we do not untaint the received values, warnings might be generated...
30
-			$options = php_xmlrpc_decode($m->getParam(3));
31
-			foreach($options as $key => $val)
32
-			{
33
-				switch($key)
34
-				{
35
-					case 'Cookie':
36
-						break;
37
-					case 'Credentials':
38
-						break;
39
-					case 'RequestCompression':
40
-						$c->setRequestCompression($val);
41
-						break;
42
-					case 'SSLVerifyHost':
43
-						$c->setSSLVerifyHost($val);
44
-						break;
45
-					case 'SSLVerifyPeer':
46
-						$c->setSSLVerifyPeer($val);
47
-						break;
48
-					case 'Timeout':
49
-						$timeout = (integer) $val;
50
-						break;
51
-				} // switch
52
-			}
53
-		}
15
+    /**
16
+     * Forward an xmlrpc request to another server, and return to client the response received.
17
+     * @param xmlrpcmsg $m (see method docs below for a description of the expected parameters)
18
+     * @return xmlrpcresp
19
+     */
20
+    function forward_request($m)
21
+    {
22
+        // create client
23
+        $timeout = 0;
24
+        $url = php_xmlrpc_decode($m->getParam(0));
25
+        $c = new xmlrpc_client($url);
26
+        if ($m->getNumParams() > 3)
27
+        {
28
+            // we have to set some options onto the client.
29
+            // Note that if we do not untaint the received values, warnings might be generated...
30
+            $options = php_xmlrpc_decode($m->getParam(3));
31
+            foreach($options as $key => $val)
32
+            {
33
+                switch($key)
34
+                {
35
+                    case 'Cookie':
36
+                        break;
37
+                    case 'Credentials':
38
+                        break;
39
+                    case 'RequestCompression':
40
+                        $c->setRequestCompression($val);
41
+                        break;
42
+                    case 'SSLVerifyHost':
43
+                        $c->setSSLVerifyHost($val);
44
+                        break;
45
+                    case 'SSLVerifyPeer':
46
+                        $c->setSSLVerifyPeer($val);
47
+                        break;
48
+                    case 'Timeout':
49
+                        $timeout = (integer) $val;
50
+                        break;
51
+                } // switch
52
+            }
53
+        }
54 54
 
55
-		// build call for remote server
56
-		/// @todo find a weay to forward client info (such as IP) to server, either
57
-		/// - as xml comments in the payload, or
58
-		/// - using std http header conventions, such as X-forwarded-for...
59
-		$method = php_xmlrpc_decode($m->getParam(1));
60
-		$pars = $m->getParam(2);
61
-		$m = new xmlrpcmsg($method);
62
-		for ($i = 0; $i < $pars->arraySize(); $i++)
63
-		{
64
-			$m->addParam($pars->arraymem($i));
65
-		}
55
+        // build call for remote server
56
+        /// @todo find a weay to forward client info (such as IP) to server, either
57
+        /// - as xml comments in the payload, or
58
+        /// - using std http header conventions, such as X-forwarded-for...
59
+        $method = php_xmlrpc_decode($m->getParam(1));
60
+        $pars = $m->getParam(2);
61
+        $m = new xmlrpcmsg($method);
62
+        for ($i = 0; $i < $pars->arraySize(); $i++)
63
+        {
64
+            $m->addParam($pars->arraymem($i));
65
+        }
66 66
 
67
-		// add debug info into response we give back to caller
68
-		xmlrpc_debugmsg("Sending to server $url the payload: ".$m->serialize());
69
-		return $c->send($m, $timeout);
70
-	}
67
+        // add debug info into response we give back to caller
68
+        xmlrpc_debugmsg("Sending to server $url the payload: ".$m->serialize());
69
+        return $c->send($m, $timeout);
70
+    }
71 71
 
72
-	// run the server
73
-	$server = new xmlrpc_server(
74
-		array(
75
-			'xmlrpcproxy.call' => array(
76
-				'function' => 'forward_request',
77
-				'signature' => array(
78
-					array('mixed', 'string', 'string', 'array'),
79
-					array('mixed', 'string', 'string', 'array', 'stuct'),
80
-				),
81
-				'docstring' => 'forwards xmlrpc calls to remote servers. Returns remote method\'s response. Accepts params: remote server url (might include basic auth credentials), method name, array of params, and (optionally) a struct containing call options'
82
-			)
83
-		)
84
-	);
72
+    // run the server
73
+    $server = new xmlrpc_server(
74
+        array(
75
+            'xmlrpcproxy.call' => array(
76
+                'function' => 'forward_request',
77
+                'signature' => array(
78
+                    array('mixed', 'string', 'string', 'array'),
79
+                    array('mixed', 'string', 'string', 'array', 'stuct'),
80
+                ),
81
+                'docstring' => 'forwards xmlrpc calls to remote servers. Returns remote method\'s response. Accepts params: remote server url (might include basic auth credentials), method name, array of params, and (optionally) a struct containing call options'
82
+            )
83
+        )
84
+    );
85 85
 ?>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 		$timeout = 0;
24 24
 		$url = php_xmlrpc_decode($m->getParam(0));
25 25
 		$c = new xmlrpc_client($url);
26
-		if ($m->getNumParams() > 3)
26
+		if ($m->getNumParams()>3)
27 27
 		{
28 28
 			// we have to set some options onto the client.
29 29
 			// Note that if we do not untaint the received values, warnings might be generated...
30 30
 			$options = php_xmlrpc_decode($m->getParam(3));
31
-			foreach($options as $key => $val)
31
+			foreach ($options as $key => $val)
32 32
 			{
33
-				switch($key)
33
+				switch ($key)
34 34
 				{
35 35
 					case 'Cookie':
36 36
 						break;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		$method = php_xmlrpc_decode($m->getParam(1));
60 60
 		$pars = $m->getParam(2);
61 61
 		$m = new xmlrpcmsg($method);
62
-		for ($i = 0; $i < $pars->arraySize(); $i++)
62
+		for ($i = 0; $i<$pars->arraySize(); $i++)
63 63
 		{
64 64
 			$m->addParam($pars->arraymem($i));
65 65
 		}
Please login to merge, or discard this patch.
demo/server/discuss.php 3 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -1,124 +1,124 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	include("xmlrpc.inc");
4
-	include("xmlrpcs.inc");
3
+    include("xmlrpc.inc");
4
+    include("xmlrpcs.inc");
5 5
 
6
-	$addcomment_sig=array(array($xmlrpcInt, $xmlrpcString, $xmlrpcString, $xmlrpcString));
6
+    $addcomment_sig=array(array($xmlrpcInt, $xmlrpcString, $xmlrpcString, $xmlrpcString));
7 7
 
8
-	$addcomment_doc='Adds a comment to an item. The first parameter
8
+    $addcomment_doc='Adds a comment to an item. The first parameter
9 9
 is the item ID, the second the name of the commenter, and the third
10 10
 is the comment itself. Returns the number of comments against that
11 11
 ID.';
12 12
 
13
-	function addcomment($m)
14
-	{
15
-		global $xmlrpcerruser;
16
-		$err="";
17
-		// since validation has already been carried out for us,
18
-		// we know we got exactly 3 string values
19
-		$n = php_xmlrpc_decode($m);
20
-		$msgID = $n[0];
21
-		$name  = $n[1];
22
-		$comment = $n[2];
13
+    function addcomment($m)
14
+    {
15
+        global $xmlrpcerruser;
16
+        $err="";
17
+        // since validation has already been carried out for us,
18
+        // we know we got exactly 3 string values
19
+        $n = php_xmlrpc_decode($m);
20
+        $msgID = $n[0];
21
+        $name  = $n[1];
22
+        $comment = $n[2];
23 23
 
24
-		$dbh=dba_open("/tmp/comments.db", "c", "db2");
25
-		if($dbh)
26
-		{
27
-			$countID="${msgID}_count";
28
-			if(dba_exists($countID, $dbh))
29
-			{
30
-				$count=dba_fetch($countID, $dbh);
31
-			}
32
-			else
33
-			{
34
-				$count=0;
35
-			}
36
-			// add the new comment in
37
-			dba_insert($msgID . "_comment_${count}", $comment, $dbh);
38
-			dba_insert($msgID . "_name_${count}", $name, $dbh);
39
-			$count++;
40
-			dba_replace($countID, $count, $dbh);
41
-			dba_close($dbh);
42
-		}
43
-		else
44
-		{
45
-			$err="Unable to open comments database.";
46
-		}
47
-		// if we generated an error, create an error return response
48
-		if($err)
49
-		{
50
-			return new xmlrpcresp(0, $xmlrpcerruser, $err);
51
-		}
52
-		else
53
-		{
54
-			// otherwise, we create the right response
55
-			// with the state name
56
-			return new xmlrpcresp(new xmlrpcval($count, "int"));
57
-		}
58
-	}
24
+        $dbh=dba_open("/tmp/comments.db", "c", "db2");
25
+        if($dbh)
26
+        {
27
+            $countID="${msgID}_count";
28
+            if(dba_exists($countID, $dbh))
29
+            {
30
+                $count=dba_fetch($countID, $dbh);
31
+            }
32
+            else
33
+            {
34
+                $count=0;
35
+            }
36
+            // add the new comment in
37
+            dba_insert($msgID . "_comment_${count}", $comment, $dbh);
38
+            dba_insert($msgID . "_name_${count}", $name, $dbh);
39
+            $count++;
40
+            dba_replace($countID, $count, $dbh);
41
+            dba_close($dbh);
42
+        }
43
+        else
44
+        {
45
+            $err="Unable to open comments database.";
46
+        }
47
+        // if we generated an error, create an error return response
48
+        if($err)
49
+        {
50
+            return new xmlrpcresp(0, $xmlrpcerruser, $err);
51
+        }
52
+        else
53
+        {
54
+            // otherwise, we create the right response
55
+            // with the state name
56
+            return new xmlrpcresp(new xmlrpcval($count, "int"));
57
+        }
58
+    }
59 59
 
60
-	$getcomments_sig=array(array($xmlrpcArray, $xmlrpcString));
60
+    $getcomments_sig=array(array($xmlrpcArray, $xmlrpcString));
61 61
 
62
-	$getcomments_doc='Returns an array of comments for a given ID, which
62
+    $getcomments_doc='Returns an array of comments for a given ID, which
63 63
 is the sole argument. Each array item is a struct containing name
64 64
 and comment text.';
65 65
 
66
-	function getcomments($m)
67
-	{
68
-		global $xmlrpcerruser;
69
-		$err="";
70
-		$ra=array();
71
-		// get the first param
72
-		if(XMLRPC_EPI_ENABLED == '1')
73
-		{
74
-			$msgID=xmlrpc_decode($m->getParam(0));
75
-		}
76
-		else
77
-		{
78
-			$msgID=php_xmlrpc_decode($m->getParam(0));
79
-		}
80
-		$dbh=dba_open("/tmp/comments.db", "r", "db2");
81
-		if($dbh)
82
-		{
83
-			$countID="${msgID}_count";
84
-			if(dba_exists($countID, $dbh))
85
-			{
86
-				$count=dba_fetch($countID, $dbh);
87
-				for($i=0; $i<$count; $i++)
88
-				{
89
-					$name=dba_fetch("${msgID}_name_${i}", $dbh);
90
-					$comment=dba_fetch("${msgID}_comment_${i}", $dbh);
91
-					// push a new struct onto the return array
92
-					$ra[] = array(
93
-						"name" => $name,
94
-						"comment" => $comment
95
-						);
96
-				}
97
-			}
98
-		}
99
-		// if we generated an error, create an error return response
100
-		if($err)
101
-		{
102
-			return new xmlrpcresp(0, $xmlrpcerruser, $err);
103
-		}
104
-		else
105
-		{
106
-			// otherwise, we create the right response
107
-			// with the state name
108
-			return new xmlrpcresp(php_xmlrpc_encode($ra));
109
-		}
110
-	}
66
+    function getcomments($m)
67
+    {
68
+        global $xmlrpcerruser;
69
+        $err="";
70
+        $ra=array();
71
+        // get the first param
72
+        if(XMLRPC_EPI_ENABLED == '1')
73
+        {
74
+            $msgID=xmlrpc_decode($m->getParam(0));
75
+        }
76
+        else
77
+        {
78
+            $msgID=php_xmlrpc_decode($m->getParam(0));
79
+        }
80
+        $dbh=dba_open("/tmp/comments.db", "r", "db2");
81
+        if($dbh)
82
+        {
83
+            $countID="${msgID}_count";
84
+            if(dba_exists($countID, $dbh))
85
+            {
86
+                $count=dba_fetch($countID, $dbh);
87
+                for($i=0; $i<$count; $i++)
88
+                {
89
+                    $name=dba_fetch("${msgID}_name_${i}", $dbh);
90
+                    $comment=dba_fetch("${msgID}_comment_${i}", $dbh);
91
+                    // push a new struct onto the return array
92
+                    $ra[] = array(
93
+                        "name" => $name,
94
+                        "comment" => $comment
95
+                        );
96
+                }
97
+            }
98
+        }
99
+        // if we generated an error, create an error return response
100
+        if($err)
101
+        {
102
+            return new xmlrpcresp(0, $xmlrpcerruser, $err);
103
+        }
104
+        else
105
+        {
106
+            // otherwise, we create the right response
107
+            // with the state name
108
+            return new xmlrpcresp(php_xmlrpc_encode($ra));
109
+        }
110
+    }
111 111
 
112
-	$s = new xmlrpc_server(array(
113
-		"discuss.addComment" => array(
114
-			"function" => "addcomment",
115
-			"signature" => $addcomment_sig,
116
-			"docstring" => $addcomment_doc
117
-		),
118
-		"discuss.getComments" => array(
119
-			"function" => "getcomments",
120
-			"signature" => $getcomments_sig,
121
-			"docstring" => $getcomments_doc
122
-		)
123
-	));
112
+    $s = new xmlrpc_server(array(
113
+        "discuss.addComment" => array(
114
+            "function" => "addcomment",
115
+            "signature" => $addcomment_sig,
116
+            "docstring" => $addcomment_doc
117
+        ),
118
+        "discuss.getComments" => array(
119
+            "function" => "getcomments",
120
+            "signature" => $getcomments_sig,
121
+            "docstring" => $getcomments_doc
122
+        )
123
+    ));
124 124
 ?>
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@  discard block
 block discarded – undo
3 3
 	include("xmlrpc.inc");
4 4
 	include("xmlrpcs.inc");
5 5
 
6
-	$addcomment_sig=array(array($xmlrpcInt, $xmlrpcString, $xmlrpcString, $xmlrpcString));
6
+	$addcomment_sig = array(array($xmlrpcInt, $xmlrpcString, $xmlrpcString, $xmlrpcString));
7 7
 
8
-	$addcomment_doc='Adds a comment to an item. The first parameter
8
+	$addcomment_doc = 'Adds a comment to an item. The first parameter
9 9
 is the item ID, the second the name of the commenter, and the third
10 10
 is the comment itself. Returns the number of comments against that
11 11
 ID.';
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 	function addcomment($m)
14 14
 	{
15 15
 		global $xmlrpcerruser;
16
-		$err="";
16
+		$err = "";
17 17
 		// since validation has already been carried out for us,
18 18
 		// we know we got exactly 3 string values
19 19
 		$n = php_xmlrpc_decode($m);
@@ -21,31 +21,31 @@  discard block
 block discarded – undo
21 21
 		$name  = $n[1];
22 22
 		$comment = $n[2];
23 23
 
24
-		$dbh=dba_open("/tmp/comments.db", "c", "db2");
25
-		if($dbh)
24
+		$dbh = dba_open("/tmp/comments.db", "c", "db2");
25
+		if ($dbh)
26 26
 		{
27
-			$countID="${msgID}_count";
28
-			if(dba_exists($countID, $dbh))
27
+			$countID = "${msgID}_count";
28
+			if (dba_exists($countID, $dbh))
29 29
 			{
30
-				$count=dba_fetch($countID, $dbh);
30
+				$count = dba_fetch($countID, $dbh);
31 31
 			}
32 32
 			else
33 33
 			{
34
-				$count=0;
34
+				$count = 0;
35 35
 			}
36 36
 			// add the new comment in
37
-			dba_insert($msgID . "_comment_${count}", $comment, $dbh);
38
-			dba_insert($msgID . "_name_${count}", $name, $dbh);
37
+			dba_insert($msgID."_comment_${count}", $comment, $dbh);
38
+			dba_insert($msgID."_name_${count}", $name, $dbh);
39 39
 			$count++;
40 40
 			dba_replace($countID, $count, $dbh);
41 41
 			dba_close($dbh);
42 42
 		}
43 43
 		else
44 44
 		{
45
-			$err="Unable to open comments database.";
45
+			$err = "Unable to open comments database.";
46 46
 		}
47 47
 		// if we generated an error, create an error return response
48
-		if($err)
48
+		if ($err)
49 49
 		{
50 50
 			return new xmlrpcresp(0, $xmlrpcerruser, $err);
51 51
 		}
@@ -57,37 +57,37 @@  discard block
 block discarded – undo
57 57
 		}
58 58
 	}
59 59
 
60
-	$getcomments_sig=array(array($xmlrpcArray, $xmlrpcString));
60
+	$getcomments_sig = array(array($xmlrpcArray, $xmlrpcString));
61 61
 
62
-	$getcomments_doc='Returns an array of comments for a given ID, which
62
+	$getcomments_doc = 'Returns an array of comments for a given ID, which
63 63
 is the sole argument. Each array item is a struct containing name
64 64
 and comment text.';
65 65
 
66 66
 	function getcomments($m)
67 67
 	{
68 68
 		global $xmlrpcerruser;
69
-		$err="";
70
-		$ra=array();
69
+		$err = "";
70
+		$ra = array();
71 71
 		// get the first param
72
-		if(XMLRPC_EPI_ENABLED == '1')
72
+		if (XMLRPC_EPI_ENABLED == '1')
73 73
 		{
74
-			$msgID=xmlrpc_decode($m->getParam(0));
74
+			$msgID = xmlrpc_decode($m->getParam(0));
75 75
 		}
76 76
 		else
77 77
 		{
78
-			$msgID=php_xmlrpc_decode($m->getParam(0));
78
+			$msgID = php_xmlrpc_decode($m->getParam(0));
79 79
 		}
80
-		$dbh=dba_open("/tmp/comments.db", "r", "db2");
81
-		if($dbh)
80
+		$dbh = dba_open("/tmp/comments.db", "r", "db2");
81
+		if ($dbh)
82 82
 		{
83
-			$countID="${msgID}_count";
84
-			if(dba_exists($countID, $dbh))
83
+			$countID = "${msgID}_count";
84
+			if (dba_exists($countID, $dbh))
85 85
 			{
86
-				$count=dba_fetch($countID, $dbh);
87
-				for($i=0; $i<$count; $i++)
86
+				$count = dba_fetch($countID, $dbh);
87
+				for ($i = 0; $i<$count; $i++)
88 88
 				{
89
-					$name=dba_fetch("${msgID}_name_${i}", $dbh);
90
-					$comment=dba_fetch("${msgID}_comment_${i}", $dbh);
89
+					$name = dba_fetch("${msgID}_name_${i}", $dbh);
90
+					$comment = dba_fetch("${msgID}_comment_${i}", $dbh);
91 91
 					// push a new struct onto the return array
92 92
 					$ra[] = array(
93 93
 						"name" => $name,
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 			}
98 98
 		}
99 99
 		// if we generated an error, create an error return response
100
-		if($err)
100
+		if ($err)
101 101
 		{
102 102
 			return new xmlrpcresp(0, $xmlrpcerruser, $err);
103 103
 		}
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,8 +28,7 @@  discard block
 block discarded – undo
28 28
 			if(dba_exists($countID, $dbh))
29 29
 			{
30 30
 				$count=dba_fetch($countID, $dbh);
31
-			}
32
-			else
31
+			} else
33 32
 			{
34 33
 				$count=0;
35 34
 			}
@@ -48,8 +47,7 @@  discard block
 block discarded – undo
48 47
 		if($err)
49 48
 		{
50 49
 			return new xmlrpcresp(0, $xmlrpcerruser, $err);
51
-		}
52
-		else
50
+		} else
53 51
 		{
54 52
 			// otherwise, we create the right response
55 53
 			// with the state name
@@ -72,8 +70,7 @@  discard block
 block discarded – undo
72 70
 		if(XMLRPC_EPI_ENABLED == '1')
73 71
 		{
74 72
 			$msgID=xmlrpc_decode($m->getParam(0));
75
-		}
76
-		else
73
+		} else
77 74
 		{
78 75
 			$msgID=php_xmlrpc_decode($m->getParam(0));
79 76
 		}
@@ -100,8 +97,7 @@  discard block
 block discarded – undo
100 97
 		if($err)
101 98
 		{
102 99
 			return new xmlrpcresp(0, $xmlrpcerruser, $err);
103
-		}
104
-		else
100
+		} else
105 101
 		{
106 102
 			// otherwise, we create the right response
107 103
 			// with the state name
Please login to merge, or discard this patch.
demo/server/server.php 3 patches
Indentation   +811 added lines, -811 removed lines patch added patch discarded remove patch
@@ -13,240 +13,240 @@  discard block
 block discarded – undo
13 13
 // give user a chance to see the source for this server instead of running the services
14 14
 if ($_SERVER['REQUEST_METHOD'] != 'POST' && isset($_GET['showSource']))
15 15
 {
16
-	highlight_file(__FILE__);
17
-	die();
16
+    highlight_file(__FILE__);
17
+    die();
18 18
 }
19 19
 
20
-	include("xmlrpc.inc");
21
-	include("xmlrpcs.inc");
22
-	include("xmlrpc_wrappers.inc");
23
-
24
-	/**
25
-	* Used to test usage of object methods in dispatch maps and in wrapper code
26
-	*/
27
-	class xmlrpc_server_methods_container
28
-	{
29
-		/**
30
-		* Method used to test logging of php warnings generated by user functions.
31
-		*/
32
-		function phpwarninggenerator($m)
33
-		{
34
-			$a = $b; // this triggers a warning in E_ALL mode, since $b is undefined
35
-			return new xmlrpcresp(new xmlrpcval(1, 'boolean'));
36
-		}
37
-
38
-	    /**
39
-	     * Method used to testcatching of exceptions in the server.
40
-	     */
41
-	    function exceptiongenerator($m)
42
-	    {
43
-	        throw new Exception("it's just a test", 1);
44
-	    }
45
-
46
-		/**
47
-		* a PHP version of the state-number server. Send me an integer and i'll sell you a state
48
-		* @param integer $s
49
-		* @return string
50
-		*/
51
-		static function findstate($s)
52
-		{
53
-			return inner_findstate($s);
54
-		}
55
-	}
56
-
57
-
58
-	// a PHP version
59
-	// of the state-number server
60
-	// send me an integer and i'll sell you a state
61
-
62
-	$stateNames = array(
63
-		"Alabama", "Alaska", "Arizona", "Arkansas", "California",
64
-		"Colorado", "Columbia", "Connecticut", "Delaware", "Florida",
65
-		"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas",
66
-		"Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
67
-		"Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
68
-		"New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina",
69
-		"North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
70
-		"South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
71
-		"Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"
72
-	);
73
-
74
-	$findstate_sig=array(array($xmlrpcString, $xmlrpcInt));
75
-	$findstate_doc='When passed an integer between 1 and 51 returns the
20
+    include("xmlrpc.inc");
21
+    include("xmlrpcs.inc");
22
+    include("xmlrpc_wrappers.inc");
23
+
24
+    /**
25
+     * Used to test usage of object methods in dispatch maps and in wrapper code
26
+     */
27
+    class xmlrpc_server_methods_container
28
+    {
29
+        /**
30
+         * Method used to test logging of php warnings generated by user functions.
31
+         */
32
+        function phpwarninggenerator($m)
33
+        {
34
+            $a = $b; // this triggers a warning in E_ALL mode, since $b is undefined
35
+            return new xmlrpcresp(new xmlrpcval(1, 'boolean'));
36
+        }
37
+
38
+        /**
39
+         * Method used to testcatching of exceptions in the server.
40
+         */
41
+        function exceptiongenerator($m)
42
+        {
43
+            throw new Exception("it's just a test", 1);
44
+        }
45
+
46
+        /**
47
+         * a PHP version of the state-number server. Send me an integer and i'll sell you a state
48
+         * @param integer $s
49
+         * @return string
50
+         */
51
+        static function findstate($s)
52
+        {
53
+            return inner_findstate($s);
54
+        }
55
+    }
56
+
57
+
58
+    // a PHP version
59
+    // of the state-number server
60
+    // send me an integer and i'll sell you a state
61
+
62
+    $stateNames = array(
63
+        "Alabama", "Alaska", "Arizona", "Arkansas", "California",
64
+        "Colorado", "Columbia", "Connecticut", "Delaware", "Florida",
65
+        "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas",
66
+        "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
67
+        "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
68
+        "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina",
69
+        "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
70
+        "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
71
+        "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"
72
+    );
73
+
74
+    $findstate_sig=array(array($xmlrpcString, $xmlrpcInt));
75
+    $findstate_doc='When passed an integer between 1 and 51 returns the
76 76
 name of a US state, where the integer is the index of that state name
77 77
 in an alphabetic order.';
78 78
 
79 79
 
80
-	function findstate($m)
81
-	{
82
-		global $xmlrpcerruser, $stateNames;
83
-		$err="";
84
-		// get the first param
85
-		$sno=$m->getParam(0);
86
-
87
-		// param must be there and of the correct type: server object does the
88
-		// validation for us
89
-
90
-		// extract the value of the state number
91
-		$snv=$sno->scalarval();
92
-		// look it up in our array (zero-based)
93
-		if (isset($stateNames[$snv-1]))
94
-		{
95
-			$sname=$stateNames[$snv-1];
96
-		}
97
-		else
98
-		{
99
-			// not, there so complain
100
-			$err="I don't have a state for the index '" . $snv . "'";
101
-		}
102
-
103
-		// if we generated an error, create an error return response
104
-		if ($err)
105
-		{
106
-			return new xmlrpcresp(0, $xmlrpcerruser, $err);
107
-		}
108
-		else
109
-		{
110
-			// otherwise, we create the right response
111
-			// with the state name
112
-			return new xmlrpcresp(new xmlrpcval($sname));
113
-		}
114
-	}
115
-
116
-	/**
117
-	* Inner code of the state-number server.
118
-	* Used to test auto-registration of PHP funcions as xmlrpc methods.
119
-	* @param integer $stateno the state number
120
-	* @return string the name of the state (or error descrption)
121
-	*/
122
-	function inner_findstate($stateno)
123
-	{
124
-		global $stateNames;
125
-		if (isset($stateNames[$stateno-1]))
126
-		{
127
-			return $stateNames[$stateno-1];
128
-		}
129
-		else
130
-		{
131
-			// not, there so complain
132
-			return "I don't have a state for the index '" . $stateno . "'";
133
-		}
134
-	}
135
-	$findstate2_sig = wrap_php_function('inner_findstate');
136
-
137
-	$findstate3_sig = wrap_php_function(array('xmlrpc_server_methods_container', 'findstate'));
138
-
139
-	$findstate5_sig = wrap_php_function('xmlrpc_server_methods_container::findstate');
140
-
141
-	$obj = new xmlrpc_server_methods_container();
142
-	$findstate4_sig = wrap_php_function(array($obj, 'findstate'));
143
-
144
-	$addtwo_sig=array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt));
145
-	$addtwo_doc='Add two integers together and return the result';
146
-	function addtwo($m)
147
-	{
148
-		$s=$m->getParam(0);
149
-		$t=$m->getParam(1);
150
-		return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(),"int"));
151
-	}
152
-
153
-	$addtwodouble_sig=array(array($xmlrpcDouble, $xmlrpcDouble, $xmlrpcDouble));
154
-	$addtwodouble_doc='Add two doubles together and return the result';
155
-	function addtwodouble($m)
156
-	{
157
-		$s=$m->getParam(0);
158
-		$t=$m->getParam(1);
159
-		return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(),"double"));
160
-	}
161
-
162
-	$stringecho_sig=array(array($xmlrpcString, $xmlrpcString));
163
-	$stringecho_doc='Accepts a string parameter, returns the string.';
164
-	function stringecho($m)
165
-	{
166
-		// just sends back a string
167
-		$s=$m->getParam(0);
168
-		$v = $s->scalarval();
169
-		return new xmlrpcresp(new xmlrpcval($s->scalarval()));
170
-	}
171
-
172
-	$echoback_sig=array(array($xmlrpcString, $xmlrpcString));
173
-	$echoback_doc='Accepts a string parameter, returns the entire incoming payload';
174
-	function echoback($m)
175
-	{
176
-		// just sends back a string with what i got
177
-		// sent to me, just escaped, that's all
178
-		//
179
-		// $m is an incoming message
180
-		$s="I got the following message:\n" . $m->serialize();
181
-		return new xmlrpcresp(new xmlrpcval($s));
182
-	}
183
-
184
-	$echosixtyfour_sig=array(array($xmlrpcString, $xmlrpcBase64));
185
-	$echosixtyfour_doc='Accepts a base64 parameter and returns it decoded as a string';
186
-	function echosixtyfour($m)
187
-	{
188
-		// accepts an encoded value, but sends it back
189
-		// as a normal string. this is to test base64 encoding
190
-		// is working as expected
191
-		$incoming=$m->getParam(0);
192
-		return new xmlrpcresp(new xmlrpcval($incoming->scalarval(), "string"));
193
-	}
194
-
195
-	$bitflipper_sig=array(array($xmlrpcArray, $xmlrpcArray));
196
-	$bitflipper_doc='Accepts an array of booleans, and returns them inverted';
197
-	function bitflipper($m)
198
-	{
199
-		global $xmlrpcArray;
200
-
201
-		$v=$m->getParam(0);
202
-		$sz=$v->arraysize();
203
-		$rv=new xmlrpcval(array(), $xmlrpcArray);
204
-
205
-		for($j=0; $j<$sz; $j++)
206
-		{
207
-			$b=$v->arraymem($j);
208
-			if ($b->scalarval())
209
-			{
210
-				$rv->addScalar(false, "boolean");
211
-			}
212
-			else
213
-			{
214
-				$rv->addScalar(true, "boolean");
215
-			}
216
-		}
217
-
218
-		return new xmlrpcresp($rv);
219
-	}
220
-
221
-	// Sorting demo
222
-	//
223
-	// send me an array of structs thus:
224
-	//
225
-	// Dave 35
226
-	// Edd  45
227
-	// Fred 23
228
-	// Barney 37
229
-	//
230
-	// and I'll return it to you in sorted order
231
-
232
-	function agesorter_compare($a, $b)
233
-	{
234
-		global $agesorter_arr;
235
-
236
-		// don't even ask me _why_ these come padded with
237
-		// hyphens, I couldn't tell you :p
238
-		$a=str_replace("-", "", $a);
239
-		$b=str_replace("-", "", $b);
240
-
241
-		if ($agesorter_arr[$a]==$agesorter[$b])
242
-		{
243
-			return 0;
244
-		}
245
-		return ($agesorter_arr[$a] > $agesorter_arr[$b]) ? -1 : 1;
246
-	}
247
-
248
-	$agesorter_sig=array(array($xmlrpcArray, $xmlrpcArray));
249
-	$agesorter_doc='Send this method an array of [string, int] structs, eg:
80
+    function findstate($m)
81
+    {
82
+        global $xmlrpcerruser, $stateNames;
83
+        $err="";
84
+        // get the first param
85
+        $sno=$m->getParam(0);
86
+
87
+        // param must be there and of the correct type: server object does the
88
+        // validation for us
89
+
90
+        // extract the value of the state number
91
+        $snv=$sno->scalarval();
92
+        // look it up in our array (zero-based)
93
+        if (isset($stateNames[$snv-1]))
94
+        {
95
+            $sname=$stateNames[$snv-1];
96
+        }
97
+        else
98
+        {
99
+            // not, there so complain
100
+            $err="I don't have a state for the index '" . $snv . "'";
101
+        }
102
+
103
+        // if we generated an error, create an error return response
104
+        if ($err)
105
+        {
106
+            return new xmlrpcresp(0, $xmlrpcerruser, $err);
107
+        }
108
+        else
109
+        {
110
+            // otherwise, we create the right response
111
+            // with the state name
112
+            return new xmlrpcresp(new xmlrpcval($sname));
113
+        }
114
+    }
115
+
116
+    /**
117
+     * Inner code of the state-number server.
118
+     * Used to test auto-registration of PHP funcions as xmlrpc methods.
119
+     * @param integer $stateno the state number
120
+     * @return string the name of the state (or error descrption)
121
+     */
122
+    function inner_findstate($stateno)
123
+    {
124
+        global $stateNames;
125
+        if (isset($stateNames[$stateno-1]))
126
+        {
127
+            return $stateNames[$stateno-1];
128
+        }
129
+        else
130
+        {
131
+            // not, there so complain
132
+            return "I don't have a state for the index '" . $stateno . "'";
133
+        }
134
+    }
135
+    $findstate2_sig = wrap_php_function('inner_findstate');
136
+
137
+    $findstate3_sig = wrap_php_function(array('xmlrpc_server_methods_container', 'findstate'));
138
+
139
+    $findstate5_sig = wrap_php_function('xmlrpc_server_methods_container::findstate');
140
+
141
+    $obj = new xmlrpc_server_methods_container();
142
+    $findstate4_sig = wrap_php_function(array($obj, 'findstate'));
143
+
144
+    $addtwo_sig=array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt));
145
+    $addtwo_doc='Add two integers together and return the result';
146
+    function addtwo($m)
147
+    {
148
+        $s=$m->getParam(0);
149
+        $t=$m->getParam(1);
150
+        return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(),"int"));
151
+    }
152
+
153
+    $addtwodouble_sig=array(array($xmlrpcDouble, $xmlrpcDouble, $xmlrpcDouble));
154
+    $addtwodouble_doc='Add two doubles together and return the result';
155
+    function addtwodouble($m)
156
+    {
157
+        $s=$m->getParam(0);
158
+        $t=$m->getParam(1);
159
+        return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(),"double"));
160
+    }
161
+
162
+    $stringecho_sig=array(array($xmlrpcString, $xmlrpcString));
163
+    $stringecho_doc='Accepts a string parameter, returns the string.';
164
+    function stringecho($m)
165
+    {
166
+        // just sends back a string
167
+        $s=$m->getParam(0);
168
+        $v = $s->scalarval();
169
+        return new xmlrpcresp(new xmlrpcval($s->scalarval()));
170
+    }
171
+
172
+    $echoback_sig=array(array($xmlrpcString, $xmlrpcString));
173
+    $echoback_doc='Accepts a string parameter, returns the entire incoming payload';
174
+    function echoback($m)
175
+    {
176
+        // just sends back a string with what i got
177
+        // sent to me, just escaped, that's all
178
+        //
179
+        // $m is an incoming message
180
+        $s="I got the following message:\n" . $m->serialize();
181
+        return new xmlrpcresp(new xmlrpcval($s));
182
+    }
183
+
184
+    $echosixtyfour_sig=array(array($xmlrpcString, $xmlrpcBase64));
185
+    $echosixtyfour_doc='Accepts a base64 parameter and returns it decoded as a string';
186
+    function echosixtyfour($m)
187
+    {
188
+        // accepts an encoded value, but sends it back
189
+        // as a normal string. this is to test base64 encoding
190
+        // is working as expected
191
+        $incoming=$m->getParam(0);
192
+        return new xmlrpcresp(new xmlrpcval($incoming->scalarval(), "string"));
193
+    }
194
+
195
+    $bitflipper_sig=array(array($xmlrpcArray, $xmlrpcArray));
196
+    $bitflipper_doc='Accepts an array of booleans, and returns them inverted';
197
+    function bitflipper($m)
198
+    {
199
+        global $xmlrpcArray;
200
+
201
+        $v=$m->getParam(0);
202
+        $sz=$v->arraysize();
203
+        $rv=new xmlrpcval(array(), $xmlrpcArray);
204
+
205
+        for($j=0; $j<$sz; $j++)
206
+        {
207
+            $b=$v->arraymem($j);
208
+            if ($b->scalarval())
209
+            {
210
+                $rv->addScalar(false, "boolean");
211
+            }
212
+            else
213
+            {
214
+                $rv->addScalar(true, "boolean");
215
+            }
216
+        }
217
+
218
+        return new xmlrpcresp($rv);
219
+    }
220
+
221
+    // Sorting demo
222
+    //
223
+    // send me an array of structs thus:
224
+    //
225
+    // Dave 35
226
+    // Edd  45
227
+    // Fred 23
228
+    // Barney 37
229
+    //
230
+    // and I'll return it to you in sorted order
231
+
232
+    function agesorter_compare($a, $b)
233
+    {
234
+        global $agesorter_arr;
235
+
236
+        // don't even ask me _why_ these come padded with
237
+        // hyphens, I couldn't tell you :p
238
+        $a=str_replace("-", "", $a);
239
+        $b=str_replace("-", "", $b);
240
+
241
+        if ($agesorter_arr[$a]==$agesorter[$b])
242
+        {
243
+            return 0;
244
+        }
245
+        return ($agesorter_arr[$a] > $agesorter_arr[$b]) ? -1 : 1;
246
+    }
247
+
248
+    $agesorter_sig=array(array($xmlrpcArray, $xmlrpcArray));
249
+    $agesorter_doc='Send this method an array of [string, int] structs, eg:
250 250
 <pre>
251 251
  Dave   35
252 252
  Edd	45
@@ -255,80 +255,80 @@  discard block
 block discarded – undo
255 255
 </pre>
256 256
 And the array will be returned with the entries sorted by their numbers.
257 257
 ';
258
-	function agesorter($m)
259
-	{
260
-		global $agesorter_arr, $xmlrpcerruser, $s;
261
-
262
-		xmlrpc_debugmsg("Entering 'agesorter'");
263
-		// get the parameter
264
-		$sno=$m->getParam(0);
265
-		// error string for [if|when] things go wrong
266
-		$err="";
267
-		// create the output value
268
-		$v=new xmlrpcval();
269
-		$agar=array();
270
-
271
-		if (isset($sno) && $sno->kindOf()=="array")
272
-		{
273
-			$max=$sno->arraysize();
274
-			// TODO: create debug method to print can work once more
275
-			// print "<!-- found $max array elements -->\n";
276
-			for($i=0; $i<$max; $i++)
277
-			{
278
-				$rec=$sno->arraymem($i);
279
-				if ($rec->kindOf()!="struct")
280
-				{
281
-					$err="Found non-struct in array at element $i";
282
-					break;
283
-				}
284
-				// extract name and age from struct
285
-				$n=$rec->structmem("name");
286
-				$a=$rec->structmem("age");
287
-				// $n and $a are xmlrpcvals,
288
-				// so get the scalarval from them
289
-				$agar[$n->scalarval()]=$a->scalarval();
290
-			}
291
-
292
-			$agesorter_arr=$agar;
293
-			// hack, must make global as uksort() won't
294
-			// allow us to pass any other auxilliary information
295
-			uksort($agesorter_arr, agesorter_compare);
296
-			$outAr=array();
297
-			while (list( $key, $val ) = each( $agesorter_arr ) )
298
-			{
299
-				// recreate each struct element
300
-				$outAr[]=new xmlrpcval(array("name" =>
301
-				new xmlrpcval($key),
302
-				"age" =>
303
-				new xmlrpcval($val, "int")), "struct");
304
-			}
305
-			// add this array to the output value
306
-			$v->addArray($outAr);
307
-		}
308
-		else
309
-		{
310
-			$err="Must be one parameter, an array of structs";
311
-		}
312
-
313
-		if ($err)
314
-		{
315
-			return new xmlrpcresp(0, $xmlrpcerruser, $err);
316
-		}
317
-		else
318
-		{
319
-			return new xmlrpcresp($v);
320
-		}
321
-	}
322
-
323
-	// signature and instructions, place these in the dispatch
324
-	// map
325
-	$mail_send_sig=array(array(
326
-		$xmlrpcBoolean, $xmlrpcString, $xmlrpcString,
327
-		$xmlrpcString, $xmlrpcString, $xmlrpcString,
328
-		$xmlrpcString, $xmlrpcString
329
-	));
330
-
331
-	$mail_send_doc='mail.send(recipient, subject, text, sender, cc, bcc, mimetype)<br/>
258
+    function agesorter($m)
259
+    {
260
+        global $agesorter_arr, $xmlrpcerruser, $s;
261
+
262
+        xmlrpc_debugmsg("Entering 'agesorter'");
263
+        // get the parameter
264
+        $sno=$m->getParam(0);
265
+        // error string for [if|when] things go wrong
266
+        $err="";
267
+        // create the output value
268
+        $v=new xmlrpcval();
269
+        $agar=array();
270
+
271
+        if (isset($sno) && $sno->kindOf()=="array")
272
+        {
273
+            $max=$sno->arraysize();
274
+            // TODO: create debug method to print can work once more
275
+            // print "<!-- found $max array elements -->\n";
276
+            for($i=0; $i<$max; $i++)
277
+            {
278
+                $rec=$sno->arraymem($i);
279
+                if ($rec->kindOf()!="struct")
280
+                {
281
+                    $err="Found non-struct in array at element $i";
282
+                    break;
283
+                }
284
+                // extract name and age from struct
285
+                $n=$rec->structmem("name");
286
+                $a=$rec->structmem("age");
287
+                // $n and $a are xmlrpcvals,
288
+                // so get the scalarval from them
289
+                $agar[$n->scalarval()]=$a->scalarval();
290
+            }
291
+
292
+            $agesorter_arr=$agar;
293
+            // hack, must make global as uksort() won't
294
+            // allow us to pass any other auxilliary information
295
+            uksort($agesorter_arr, agesorter_compare);
296
+            $outAr=array();
297
+            while (list( $key, $val ) = each( $agesorter_arr ) )
298
+            {
299
+                // recreate each struct element
300
+                $outAr[]=new xmlrpcval(array("name" =>
301
+                new xmlrpcval($key),
302
+                "age" =>
303
+                new xmlrpcval($val, "int")), "struct");
304
+            }
305
+            // add this array to the output value
306
+            $v->addArray($outAr);
307
+        }
308
+        else
309
+        {
310
+            $err="Must be one parameter, an array of structs";
311
+        }
312
+
313
+        if ($err)
314
+        {
315
+            return new xmlrpcresp(0, $xmlrpcerruser, $err);
316
+        }
317
+        else
318
+        {
319
+            return new xmlrpcresp($v);
320
+        }
321
+    }
322
+
323
+    // signature and instructions, place these in the dispatch
324
+    // map
325
+    $mail_send_sig=array(array(
326
+        $xmlrpcBoolean, $xmlrpcString, $xmlrpcString,
327
+        $xmlrpcString, $xmlrpcString, $xmlrpcString,
328
+        $xmlrpcString, $xmlrpcString
329
+    ));
330
+
331
+    $mail_send_doc='mail.send(recipient, subject, text, sender, cc, bcc, mimetype)<br/>
332 332
 recipient, cc, and bcc are strings, comma-separated lists of email addresses, as described above.<br/>
333 333
 subject is a string, the subject of the message.<br/>
334 334
 sender is a string, it\'s the email address of the person sending the message. This string can not be
@@ -336,517 +336,517 @@  discard block
 block discarded – undo
336 336
 text is a string, it contains the body of the message.<br/>
337 337
 mimetype, a string, is a standard MIME type, for example, text/plain.
338 338
 ';
339
-	// WARNING; this functionality depends on the sendmail -t option
340
-	// it may not work with Windows machines properly; particularly
341
-	// the Bcc option. Sneak on your friends at your own risk!
342
-	function mail_send($m)
343
-	{
344
-		global $xmlrpcerruser, $xmlrpcBoolean;
345
-		$err="";
346
-
347
-		$mTo=$m->getParam(0);
348
-		$mSub=$m->getParam(1);
349
-		$mBody=$m->getParam(2);
350
-		$mFrom=$m->getParam(3);
351
-		$mCc=$m->getParam(4);
352
-		$mBcc=$m->getParam(5);
353
-		$mMime=$m->getParam(6);
354
-
355
-		if ($mTo->scalarval()=="")
356
-		{
357
-			$err="Error, no 'To' field specified";
358
-		}
359
-
360
-		if ($mFrom->scalarval()=="")
361
-		{
362
-			$err="Error, no 'From' field specified";
363
-		}
364
-
365
-		$msghdr="From: " . $mFrom->scalarval() . "\n";
366
-		$msghdr.="To: ". $mTo->scalarval() . "\n";
367
-
368
-		if ($mCc->scalarval()!="")
369
-		{
370
-			$msghdr.="Cc: " . $mCc->scalarval(). "\n";
371
-		}
372
-		if ($mBcc->scalarval()!="")
373
-		{
374
-			$msghdr.="Bcc: " . $mBcc->scalarval(). "\n";
375
-		}
376
-		if ($mMime->scalarval()!="")
377
-		{
378
-			$msghdr.="Content-type: " . $mMime->scalarval() . "\n";
379
-		}
380
-		$msghdr.="X-Mailer: XML-RPC for PHP mailer 1.0";
381
-
382
-		if ($err=="")
383
-		{
384
-			if (!mail("",
385
-				$mSub->scalarval(),
386
-				$mBody->scalarval(),
387
-				$msghdr))
388
-			{
389
-				$err="Error, could not send the mail.";
390
-			}
391
-		}
392
-
393
-		if ($err)
394
-		{
395
-			return new xmlrpcresp(0, $xmlrpcerruser, $err);
396
-		}
397
-		else
398
-		{
399
-			return new xmlrpcresp(new xmlrpcval("true", $xmlrpcBoolean));
400
-		}
401
-	}
402
-
403
-	$getallheaders_sig=array(array($xmlrpcStruct));
404
-	$getallheaders_doc='Returns a struct containing all the HTTP headers received with the request. Provides limited functionality with IIS';
405
-	function getallheaders_xmlrpc($m)
406
-	{
407
-		global $xmlrpcerruser;
408
-		if (function_exists('getallheaders'))
409
-		{
410
-			return new xmlrpcresp(php_xmlrpc_encode(getallheaders()));
411
-		}
412
-		else
413
-		{
414
-			$headers = array();
415
-			// IIS: poor man's version of getallheaders
416
-			foreach ($_SERVER as $key => $val)
417
-				if (strpos($key, 'HTTP_') === 0)
418
-				{
419
-					$key = ucfirst(str_replace('_', '-', strtolower(substr($key, 5))));
420
-					$headers[$key] = $val;
421
-				}
422
-			return new xmlrpcresp(php_xmlrpc_encode($headers));
423
-		}
424
-	}
425
-
426
-	$setcookies_sig=array(array($xmlrpcInt, $xmlrpcStruct));
427
-	$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)';
428
-	function setcookies($m)
429
-	{
430
-		$m = $m->getParam(0);
431
-		while(list($name,$value) = $m->structeach())
432
-		{
433
-			$cookiedesc = php_xmlrpc_decode($value);
434
-			setcookie($name, @$cookiedesc['value'], @$cookiedesc['expires'], @$cookiedesc['path'], @$cookiedesc['domain'], @$cookiedesc['secure']);
435
-		}
436
-		return new xmlrpcresp(new xmlrpcval(1, 'int'));
437
-	}
438
-
439
-	$getcookies_sig=array(array($xmlrpcStruct));
440
-	$getcookies_doc='Sends to client a response containing all http cookies as received in the request (as struct)';
441
-	function getcookies($m)
442
-	{
443
-		return new xmlrpcresp(php_xmlrpc_encode($_COOKIE));
444
-	}
445
-
446
-	$v1_arrayOfStructs_sig=array(array($xmlrpcInt, $xmlrpcArray));
447
-	$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.';
448
-	function v1_arrayOfStructs($m)
449
-	{
450
-		$sno=$m->getParam(0);
451
-		$numcurly=0;
452
-		for($i=0; $i<$sno->arraysize(); $i++)
453
-		{
454
-			$str=$sno->arraymem($i);
455
-			$str->structreset();
456
-			while(list($key,$val)=$str->structeach())
457
-			{
458
-				if ($key=="curly")
459
-				{
460
-					$numcurly+=$val->scalarval();
461
-				}
462
-			}
463
-		}
464
-		return new xmlrpcresp(new xmlrpcval($numcurly, "int"));
465
-	}
466
-
467
-	$v1_easyStruct_sig=array(array($xmlrpcInt, $xmlrpcStruct));
468
-	$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.';
469
-	function v1_easyStruct($m)
470
-	{
471
-		$sno=$m->getParam(0);
472
-		$moe=$sno->structmem("moe");
473
-		$larry=$sno->structmem("larry");
474
-		$curly=$sno->structmem("curly");
475
-		$num=$moe->scalarval() + $larry->scalarval() + $curly->scalarval();
476
-		return new xmlrpcresp(new xmlrpcval($num, "int"));
477
-	}
478
-
479
-	$v1_echoStruct_sig=array(array($xmlrpcStruct, $xmlrpcStruct));
480
-	$v1_echoStruct_doc='This handler takes a single parameter, a struct. Your handler must return the struct.';
481
-	function v1_echoStruct($m)
482
-	{
483
-		$sno=$m->getParam(0);
484
-		return new xmlrpcresp($sno);
485
-	}
486
-
487
-	$v1_manyTypes_sig=array(array(
488
-		$xmlrpcArray, $xmlrpcInt, $xmlrpcBoolean,
489
-		$xmlrpcString, $xmlrpcDouble, $xmlrpcDateTime,
490
-		$xmlrpcBase64
491
-	));
492
-	$v1_manyTypes_doc='This handler takes six parameters, and returns an array containing all the parameters.';
493
-	function v1_manyTypes($m)
494
-	{
495
-		return new xmlrpcresp(new xmlrpcval(array(
496
-			$m->getParam(0),
497
-			$m->getParam(1),
498
-			$m->getParam(2),
499
-			$m->getParam(3),
500
-			$m->getParam(4),
501
-			$m->getParam(5)),
502
-			"array"
503
-		));
504
-	}
505
-
506
-	$v1_moderateSizeArrayCheck_sig=array(array($xmlrpcString, $xmlrpcArray));
507
-	$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.';
508
-	function v1_moderateSizeArrayCheck($m)
509
-	{
510
-		$ar=$m->getParam(0);
511
-		$sz=$ar->arraysize();
512
-		$first=$ar->arraymem(0);
513
-		$last=$ar->arraymem($sz-1);
514
-		return new xmlrpcresp(new xmlrpcval($first->scalarval() .
515
-		$last->scalarval(), "string"));
516
-	}
517
-
518
-	$v1_simpleStructReturn_sig=array(array($xmlrpcStruct, $xmlrpcInt));
519
-	$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.';
520
-	function v1_simpleStructReturn($m)
521
-	{
522
-		$sno=$m->getParam(0);
523
-		$v=$sno->scalarval();
524
-		return new xmlrpcresp(new xmlrpcval(array(
525
-			"times10"   => new xmlrpcval($v*10, "int"),
526
-			"times100"  => new xmlrpcval($v*100, "int"),
527
-			"times1000" => new xmlrpcval($v*1000, "int")),
528
-			"struct"
529
-		));
530
-	}
531
-
532
-	$v1_nestedStruct_sig=array(array($xmlrpcInt, $xmlrpcStruct));
533
-	$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.';
534
-	function v1_nestedStruct($m)
535
-	{
536
-		$sno=$m->getParam(0);
537
-
538
-		$twoK=$sno->structmem("2000");
539
-		$april=$twoK->structmem("04");
540
-		$fools=$april->structmem("01");
541
-		$curly=$fools->structmem("curly");
542
-		$larry=$fools->structmem("larry");
543
-		$moe=$fools->structmem("moe");
544
-		return new xmlrpcresp(new xmlrpcval($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), "int"));
545
-	}
546
-
547
-	$v1_countTheEntities_sig=array(array($xmlrpcStruct, $xmlrpcString));
548
-	$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.';
549
-	function v1_countTheEntities($m)
550
-	{
551
-		$sno=$m->getParam(0);
552
-		$str=$sno->scalarval();
553
-		$gt=0; $lt=0; $ap=0; $qu=0; $amp=0;
554
-		for($i=0; $i<strlen($str); $i++)
555
-		{
556
-			$c=substr($str, $i, 1);
557
-			switch($c)
558
-			{
559
-				case ">":
560
-					$gt++;
561
-					break;
562
-				case "<":
563
-					$lt++;
564
-					break;
565
-				case "\"":
566
-					$qu++;
567
-					break;
568
-				case "'":
569
-					$ap++;
570
-					break;
571
-				case "&":
572
-					$amp++;
573
-					break;
574
-				default:
575
-					break;
576
-			}
577
-		}
578
-		return new xmlrpcresp(new xmlrpcval(array(
579
-			"ctLeftAngleBrackets"  => new xmlrpcval($lt, "int"),
580
-			"ctRightAngleBrackets" => new xmlrpcval($gt, "int"),
581
-			"ctAmpersands"		 => new xmlrpcval($amp, "int"),
582
-			"ctApostrophes"		=> new xmlrpcval($ap, "int"),
583
-			"ctQuotes"			 => new xmlrpcval($qu, "int")),
584
-			"struct"
585
-		));
586
-	}
587
-
588
-	// trivial interop tests
589
-	// http://www.xmlrpc.com/stories/storyReader$1636
590
-
591
-	$i_echoString_sig=array(array($xmlrpcString, $xmlrpcString));
592
-	$i_echoString_doc="Echoes string.";
593
-
594
-	$i_echoStringArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
595
-	$i_echoStringArray_doc="Echoes string array.";
596
-
597
-	$i_echoInteger_sig=array(array($xmlrpcInt, $xmlrpcInt));
598
-	$i_echoInteger_doc="Echoes integer.";
599
-
600
-	$i_echoIntegerArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
601
-	$i_echoIntegerArray_doc="Echoes integer array.";
602
-
603
-	$i_echoFloat_sig=array(array($xmlrpcDouble, $xmlrpcDouble));
604
-	$i_echoFloat_doc="Echoes float.";
605
-
606
-	$i_echoFloatArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
607
-	$i_echoFloatArray_doc="Echoes float array.";
608
-
609
-	$i_echoStruct_sig=array(array($xmlrpcStruct, $xmlrpcStruct));
610
-	$i_echoStruct_doc="Echoes struct.";
611
-
612
-	$i_echoStructArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
613
-	$i_echoStructArray_doc="Echoes struct array.";
614
-
615
-	$i_echoValue_doc="Echoes any value back.";
616
-	$i_echoValue_sig=array(array($xmlrpcValue, $xmlrpcValue));
617
-
618
-	$i_echoBase64_sig=array(array($xmlrpcBase64, $xmlrpcBase64));
619
-	$i_echoBase64_doc="Echoes base64.";
620
-
621
-	$i_echoDate_sig=array(array($xmlrpcDateTime, $xmlrpcDateTime));
622
-	$i_echoDate_doc="Echoes dateTime.";
623
-
624
-	function i_echoParam($m)
625
-	{
626
-		$s=$m->getParam(0);
627
-		return new xmlrpcresp($s);
628
-	}
629
-
630
-	function i_echoString($m) { return i_echoParam($m); }
631
-	function i_echoInteger($m) { return i_echoParam($m); }
632
-	function i_echoFloat($m) { return i_echoParam($m); }
633
-	function i_echoStruct($m) { return i_echoParam($m); }
634
-	function i_echoStringArray($m) { return i_echoParam($m); }
635
-	function i_echoIntegerArray($m) { return i_echoParam($m); }
636
-	function i_echoFloatArray($m) { return i_echoParam($m); }
637
-	function i_echoStructArray($m) { return i_echoParam($m); }
638
-	function i_echoValue($m) { return i_echoParam($m); }
639
-	function i_echoBase64($m) { return i_echoParam($m); }
640
-	function i_echoDate($m) { return i_echoParam($m); }
641
-
642
-	$i_whichToolkit_sig=array(array($xmlrpcStruct));
643
-	$i_whichToolkit_doc="Returns a struct containing the following strings: toolkitDocsUrl, toolkitName, toolkitVersion, toolkitOperatingSystem.";
644
-
645
-	function i_whichToolkit($m)
646
-	{
647
-		global $xmlrpcName, $xmlrpcVersion,$SERVER_SOFTWARE;
648
-		$ret=array(
649
-			"toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/",
650
-			"toolkitName" => $xmlrpcName,
651
-			"toolkitVersion" => $xmlrpcVersion,
652
-			"toolkitOperatingSystem" => isset ($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE']
653
-		);
654
-		return new xmlrpcresp ( php_xmlrpc_encode($ret));
655
-	}
656
-
657
-	$o=new xmlrpc_server_methods_container;
658
-	$a=array(
659
-		"examples.getStateName" => array(
660
-			"function" => "findstate",
661
-			"signature" => $findstate_sig,
662
-			"docstring" => $findstate_doc
663
-		),
664
-		"examples.sortByAge" => array(
665
-			"function" => "agesorter",
666
-			"signature" => $agesorter_sig,
667
-			"docstring" => $agesorter_doc
668
-		),
669
-		"examples.addtwo" => array(
670
-			"function" => "addtwo",
671
-			"signature" => $addtwo_sig,
672
-			"docstring" => $addtwo_doc
673
-		),
674
-		"examples.addtwodouble" => array(
675
-			"function" => "addtwodouble",
676
-			"signature" => $addtwodouble_sig,
677
-			"docstring" => $addtwodouble_doc
678
-		),
679
-		"examples.stringecho" => array(
680
-			"function" => "stringecho",
681
-			"signature" => $stringecho_sig,
682
-			"docstring" => $stringecho_doc
683
-		),
684
-		"examples.echo" => array(
685
-			"function" => "echoback",
686
-			"signature" => $echoback_sig,
687
-			"docstring" => $echoback_doc
688
-		),
689
-		"examples.decode64" => array(
690
-			"function" => "echosixtyfour",
691
-			"signature" => $echosixtyfour_sig,
692
-			"docstring" => $echosixtyfour_doc
693
-		),
694
-		"examples.invertBooleans" => array(
695
-			"function" => "bitflipper",
696
-			"signature" => $bitflipper_sig,
697
-			"docstring" => $bitflipper_doc
698
-		),
699
-		"examples.generatePHPWarning" => array(
700
-			"function" => array($o, "phpwarninggenerator")
701
-			//'function' => 'xmlrpc_server_methods_container::phpwarninggenerator'
702
-		),
703
-		"examples.raiseException" => array(
704
-			"function" => array($o, "exceptiongenerator")
705
-		),
706
-		"examples.getallheaders" => array(
707
-			"function" => 'getallheaders_xmlrpc',
708
-			"signature" => $getallheaders_sig,
709
-			"docstring" => $getallheaders_doc
710
-		),
711
-		"examples.setcookies" => array(
712
-			"function" => 'setcookies',
713
-			"signature" => $setcookies_sig,
714
-			"docstring" => $setcookies_doc
715
-		),
716
-		"examples.getcookies" => array(
717
-			"function" => 'getcookies',
718
-			"signature" => $getcookies_sig,
719
-			"docstring" => $getcookies_doc
720
-		),
721
-		"mail.send" => array(
722
-			"function" => "mail_send",
723
-			"signature" => $mail_send_sig,
724
-			"docstring" => $mail_send_doc
725
-		),
726
-		"validator1.arrayOfStructsTest" => array(
727
-			"function" => "v1_arrayOfStructs",
728
-			"signature" => $v1_arrayOfStructs_sig,
729
-			"docstring" => $v1_arrayOfStructs_doc
730
-		),
731
-		"validator1.easyStructTest" => array(
732
-			"function" => "v1_easyStruct",
733
-			"signature" => $v1_easyStruct_sig,
734
-			"docstring" => $v1_easyStruct_doc
735
-		),
736
-		"validator1.echoStructTest" => array(
737
-			"function" => "v1_echoStruct",
738
-			"signature" => $v1_echoStruct_sig,
739
-			"docstring" => $v1_echoStruct_doc
740
-		),
741
-		"validator1.manyTypesTest" => array(
742
-			"function" => "v1_manyTypes",
743
-			"signature" => $v1_manyTypes_sig,
744
-			"docstring" => $v1_manyTypes_doc
745
-		),
746
-		"validator1.moderateSizeArrayCheck" => array(
747
-			"function" => "v1_moderateSizeArrayCheck",
748
-			"signature" => $v1_moderateSizeArrayCheck_sig,
749
-			"docstring" => $v1_moderateSizeArrayCheck_doc
750
-		),
751
-		"validator1.simpleStructReturnTest" => array(
752
-			"function" => "v1_simpleStructReturn",
753
-			"signature" => $v1_simpleStructReturn_sig,
754
-			"docstring" => $v1_simpleStructReturn_doc
755
-		),
756
-		"validator1.nestedStructTest" => array(
757
-			"function" => "v1_nestedStruct",
758
-			"signature" => $v1_nestedStruct_sig,
759
-			"docstring" => $v1_nestedStruct_doc
760
-		),
761
-		"validator1.countTheEntities" => array(
762
-			"function" => "v1_countTheEntities",
763
-			"signature" => $v1_countTheEntities_sig,
764
-			"docstring" => $v1_countTheEntities_doc
765
-		),
766
-		"interopEchoTests.echoString" => array(
767
-			"function" => "i_echoString",
768
-			"signature" => $i_echoString_sig,
769
-			"docstring" => $i_echoString_doc
770
-		),
771
-		"interopEchoTests.echoStringArray" => array(
772
-			"function" => "i_echoStringArray",
773
-			"signature" => $i_echoStringArray_sig,
774
-			"docstring" => $i_echoStringArray_doc
775
-		),
776
-		"interopEchoTests.echoInteger" => array(
777
-			"function" => "i_echoInteger",
778
-			"signature" => $i_echoInteger_sig,
779
-			"docstring" => $i_echoInteger_doc
780
-		),
781
-		"interopEchoTests.echoIntegerArray" => array(
782
-			"function" => "i_echoIntegerArray",
783
-			"signature" => $i_echoIntegerArray_sig,
784
-			"docstring" => $i_echoIntegerArray_doc
785
-		),
786
-		"interopEchoTests.echoFloat" => array(
787
-			"function" => "i_echoFloat",
788
-			"signature" => $i_echoFloat_sig,
789
-			"docstring" => $i_echoFloat_doc
790
-		),
791
-		"interopEchoTests.echoFloatArray" => array(
792
-			"function" => "i_echoFloatArray",
793
-			"signature" => $i_echoFloatArray_sig,
794
-			"docstring" => $i_echoFloatArray_doc
795
-		),
796
-		"interopEchoTests.echoStruct" => array(
797
-			"function" => "i_echoStruct",
798
-			"signature" => $i_echoStruct_sig,
799
-			"docstring" => $i_echoStruct_doc
800
-		),
801
-		"interopEchoTests.echoStructArray" => array(
802
-			"function" => "i_echoStructArray",
803
-			"signature" => $i_echoStructArray_sig,
804
-			"docstring" => $i_echoStructArray_doc
805
-		),
806
-		"interopEchoTests.echoValue" => array(
807
-			"function" => "i_echoValue",
808
-			"signature" => $i_echoValue_sig,
809
-			"docstring" => $i_echoValue_doc
810
-		),
811
-		"interopEchoTests.echoBase64" => array(
812
-			"function" => "i_echoBase64",
813
-			"signature" => $i_echoBase64_sig,
814
-			"docstring" => $i_echoBase64_doc
815
-		),
816
-		"interopEchoTests.echoDate" => array(
817
-			"function" => "i_echoDate",
818
-			"signature" => $i_echoDate_sig,
819
-			"docstring" => $i_echoDate_doc
820
-		),
821
-		"interopEchoTests.whichToolkit" => array(
822
-			"function" => "i_whichToolkit",
823
-			"signature" => $i_whichToolkit_sig,
824
-			"docstring" => $i_whichToolkit_doc
825
-		)
826
-	);
827
-
828
-	if ($findstate2_sig)
829
-		$a['examples.php.getStateName'] = $findstate2_sig;
830
-
831
-	if ($findstate3_sig)
832
-		$a['examples.php2.getStateName'] = $findstate3_sig;
833
-
834
-	if ($findstate4_sig)
835
-		$a['examples.php3.getStateName'] = $findstate4_sig;
339
+    // WARNING; this functionality depends on the sendmail -t option
340
+    // it may not work with Windows machines properly; particularly
341
+    // the Bcc option. Sneak on your friends at your own risk!
342
+    function mail_send($m)
343
+    {
344
+        global $xmlrpcerruser, $xmlrpcBoolean;
345
+        $err="";
346
+
347
+        $mTo=$m->getParam(0);
348
+        $mSub=$m->getParam(1);
349
+        $mBody=$m->getParam(2);
350
+        $mFrom=$m->getParam(3);
351
+        $mCc=$m->getParam(4);
352
+        $mBcc=$m->getParam(5);
353
+        $mMime=$m->getParam(6);
354
+
355
+        if ($mTo->scalarval()=="")
356
+        {
357
+            $err="Error, no 'To' field specified";
358
+        }
359
+
360
+        if ($mFrom->scalarval()=="")
361
+        {
362
+            $err="Error, no 'From' field specified";
363
+        }
364
+
365
+        $msghdr="From: " . $mFrom->scalarval() . "\n";
366
+        $msghdr.="To: ". $mTo->scalarval() . "\n";
367
+
368
+        if ($mCc->scalarval()!="")
369
+        {
370
+            $msghdr.="Cc: " . $mCc->scalarval(). "\n";
371
+        }
372
+        if ($mBcc->scalarval()!="")
373
+        {
374
+            $msghdr.="Bcc: " . $mBcc->scalarval(). "\n";
375
+        }
376
+        if ($mMime->scalarval()!="")
377
+        {
378
+            $msghdr.="Content-type: " . $mMime->scalarval() . "\n";
379
+        }
380
+        $msghdr.="X-Mailer: XML-RPC for PHP mailer 1.0";
381
+
382
+        if ($err=="")
383
+        {
384
+            if (!mail("",
385
+                $mSub->scalarval(),
386
+                $mBody->scalarval(),
387
+                $msghdr))
388
+            {
389
+                $err="Error, could not send the mail.";
390
+            }
391
+        }
392
+
393
+        if ($err)
394
+        {
395
+            return new xmlrpcresp(0, $xmlrpcerruser, $err);
396
+        }
397
+        else
398
+        {
399
+            return new xmlrpcresp(new xmlrpcval("true", $xmlrpcBoolean));
400
+        }
401
+    }
402
+
403
+    $getallheaders_sig=array(array($xmlrpcStruct));
404
+    $getallheaders_doc='Returns a struct containing all the HTTP headers received with the request. Provides limited functionality with IIS';
405
+    function getallheaders_xmlrpc($m)
406
+    {
407
+        global $xmlrpcerruser;
408
+        if (function_exists('getallheaders'))
409
+        {
410
+            return new xmlrpcresp(php_xmlrpc_encode(getallheaders()));
411
+        }
412
+        else
413
+        {
414
+            $headers = array();
415
+            // IIS: poor man's version of getallheaders
416
+            foreach ($_SERVER as $key => $val)
417
+                if (strpos($key, 'HTTP_') === 0)
418
+                {
419
+                    $key = ucfirst(str_replace('_', '-', strtolower(substr($key, 5))));
420
+                    $headers[$key] = $val;
421
+                }
422
+            return new xmlrpcresp(php_xmlrpc_encode($headers));
423
+        }
424
+    }
425
+
426
+    $setcookies_sig=array(array($xmlrpcInt, $xmlrpcStruct));
427
+    $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)';
428
+    function setcookies($m)
429
+    {
430
+        $m = $m->getParam(0);
431
+        while(list($name,$value) = $m->structeach())
432
+        {
433
+            $cookiedesc = php_xmlrpc_decode($value);
434
+            setcookie($name, @$cookiedesc['value'], @$cookiedesc['expires'], @$cookiedesc['path'], @$cookiedesc['domain'], @$cookiedesc['secure']);
435
+        }
436
+        return new xmlrpcresp(new xmlrpcval(1, 'int'));
437
+    }
438
+
439
+    $getcookies_sig=array(array($xmlrpcStruct));
440
+    $getcookies_doc='Sends to client a response containing all http cookies as received in the request (as struct)';
441
+    function getcookies($m)
442
+    {
443
+        return new xmlrpcresp(php_xmlrpc_encode($_COOKIE));
444
+    }
445
+
446
+    $v1_arrayOfStructs_sig=array(array($xmlrpcInt, $xmlrpcArray));
447
+    $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.';
448
+    function v1_arrayOfStructs($m)
449
+    {
450
+        $sno=$m->getParam(0);
451
+        $numcurly=0;
452
+        for($i=0; $i<$sno->arraysize(); $i++)
453
+        {
454
+            $str=$sno->arraymem($i);
455
+            $str->structreset();
456
+            while(list($key,$val)=$str->structeach())
457
+            {
458
+                if ($key=="curly")
459
+                {
460
+                    $numcurly+=$val->scalarval();
461
+                }
462
+            }
463
+        }
464
+        return new xmlrpcresp(new xmlrpcval($numcurly, "int"));
465
+    }
466
+
467
+    $v1_easyStruct_sig=array(array($xmlrpcInt, $xmlrpcStruct));
468
+    $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.';
469
+    function v1_easyStruct($m)
470
+    {
471
+        $sno=$m->getParam(0);
472
+        $moe=$sno->structmem("moe");
473
+        $larry=$sno->structmem("larry");
474
+        $curly=$sno->structmem("curly");
475
+        $num=$moe->scalarval() + $larry->scalarval() + $curly->scalarval();
476
+        return new xmlrpcresp(new xmlrpcval($num, "int"));
477
+    }
478
+
479
+    $v1_echoStruct_sig=array(array($xmlrpcStruct, $xmlrpcStruct));
480
+    $v1_echoStruct_doc='This handler takes a single parameter, a struct. Your handler must return the struct.';
481
+    function v1_echoStruct($m)
482
+    {
483
+        $sno=$m->getParam(0);
484
+        return new xmlrpcresp($sno);
485
+    }
486
+
487
+    $v1_manyTypes_sig=array(array(
488
+        $xmlrpcArray, $xmlrpcInt, $xmlrpcBoolean,
489
+        $xmlrpcString, $xmlrpcDouble, $xmlrpcDateTime,
490
+        $xmlrpcBase64
491
+    ));
492
+    $v1_manyTypes_doc='This handler takes six parameters, and returns an array containing all the parameters.';
493
+    function v1_manyTypes($m)
494
+    {
495
+        return new xmlrpcresp(new xmlrpcval(array(
496
+            $m->getParam(0),
497
+            $m->getParam(1),
498
+            $m->getParam(2),
499
+            $m->getParam(3),
500
+            $m->getParam(4),
501
+            $m->getParam(5)),
502
+            "array"
503
+        ));
504
+    }
505
+
506
+    $v1_moderateSizeArrayCheck_sig=array(array($xmlrpcString, $xmlrpcArray));
507
+    $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.';
508
+    function v1_moderateSizeArrayCheck($m)
509
+    {
510
+        $ar=$m->getParam(0);
511
+        $sz=$ar->arraysize();
512
+        $first=$ar->arraymem(0);
513
+        $last=$ar->arraymem($sz-1);
514
+        return new xmlrpcresp(new xmlrpcval($first->scalarval() .
515
+        $last->scalarval(), "string"));
516
+    }
517
+
518
+    $v1_simpleStructReturn_sig=array(array($xmlrpcStruct, $xmlrpcInt));
519
+    $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.';
520
+    function v1_simpleStructReturn($m)
521
+    {
522
+        $sno=$m->getParam(0);
523
+        $v=$sno->scalarval();
524
+        return new xmlrpcresp(new xmlrpcval(array(
525
+            "times10"   => new xmlrpcval($v*10, "int"),
526
+            "times100"  => new xmlrpcval($v*100, "int"),
527
+            "times1000" => new xmlrpcval($v*1000, "int")),
528
+            "struct"
529
+        ));
530
+    }
531
+
532
+    $v1_nestedStruct_sig=array(array($xmlrpcInt, $xmlrpcStruct));
533
+    $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.';
534
+    function v1_nestedStruct($m)
535
+    {
536
+        $sno=$m->getParam(0);
537
+
538
+        $twoK=$sno->structmem("2000");
539
+        $april=$twoK->structmem("04");
540
+        $fools=$april->structmem("01");
541
+        $curly=$fools->structmem("curly");
542
+        $larry=$fools->structmem("larry");
543
+        $moe=$fools->structmem("moe");
544
+        return new xmlrpcresp(new xmlrpcval($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), "int"));
545
+    }
546
+
547
+    $v1_countTheEntities_sig=array(array($xmlrpcStruct, $xmlrpcString));
548
+    $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.';
549
+    function v1_countTheEntities($m)
550
+    {
551
+        $sno=$m->getParam(0);
552
+        $str=$sno->scalarval();
553
+        $gt=0; $lt=0; $ap=0; $qu=0; $amp=0;
554
+        for($i=0; $i<strlen($str); $i++)
555
+        {
556
+            $c=substr($str, $i, 1);
557
+            switch($c)
558
+            {
559
+                case ">":
560
+                    $gt++;
561
+                    break;
562
+                case "<":
563
+                    $lt++;
564
+                    break;
565
+                case "\"":
566
+                    $qu++;
567
+                    break;
568
+                case "'":
569
+                    $ap++;
570
+                    break;
571
+                case "&":
572
+                    $amp++;
573
+                    break;
574
+                default:
575
+                    break;
576
+            }
577
+        }
578
+        return new xmlrpcresp(new xmlrpcval(array(
579
+            "ctLeftAngleBrackets"  => new xmlrpcval($lt, "int"),
580
+            "ctRightAngleBrackets" => new xmlrpcval($gt, "int"),
581
+            "ctAmpersands"		 => new xmlrpcval($amp, "int"),
582
+            "ctApostrophes"		=> new xmlrpcval($ap, "int"),
583
+            "ctQuotes"			 => new xmlrpcval($qu, "int")),
584
+            "struct"
585
+        ));
586
+    }
587
+
588
+    // trivial interop tests
589
+    // http://www.xmlrpc.com/stories/storyReader$1636
590
+
591
+    $i_echoString_sig=array(array($xmlrpcString, $xmlrpcString));
592
+    $i_echoString_doc="Echoes string.";
593
+
594
+    $i_echoStringArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
595
+    $i_echoStringArray_doc="Echoes string array.";
596
+
597
+    $i_echoInteger_sig=array(array($xmlrpcInt, $xmlrpcInt));
598
+    $i_echoInteger_doc="Echoes integer.";
599
+
600
+    $i_echoIntegerArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
601
+    $i_echoIntegerArray_doc="Echoes integer array.";
602
+
603
+    $i_echoFloat_sig=array(array($xmlrpcDouble, $xmlrpcDouble));
604
+    $i_echoFloat_doc="Echoes float.";
605
+
606
+    $i_echoFloatArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
607
+    $i_echoFloatArray_doc="Echoes float array.";
608
+
609
+    $i_echoStruct_sig=array(array($xmlrpcStruct, $xmlrpcStruct));
610
+    $i_echoStruct_doc="Echoes struct.";
611
+
612
+    $i_echoStructArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
613
+    $i_echoStructArray_doc="Echoes struct array.";
614
+
615
+    $i_echoValue_doc="Echoes any value back.";
616
+    $i_echoValue_sig=array(array($xmlrpcValue, $xmlrpcValue));
617
+
618
+    $i_echoBase64_sig=array(array($xmlrpcBase64, $xmlrpcBase64));
619
+    $i_echoBase64_doc="Echoes base64.";
620
+
621
+    $i_echoDate_sig=array(array($xmlrpcDateTime, $xmlrpcDateTime));
622
+    $i_echoDate_doc="Echoes dateTime.";
623
+
624
+    function i_echoParam($m)
625
+    {
626
+        $s=$m->getParam(0);
627
+        return new xmlrpcresp($s);
628
+    }
629
+
630
+    function i_echoString($m) { return i_echoParam($m); }
631
+    function i_echoInteger($m) { return i_echoParam($m); }
632
+    function i_echoFloat($m) { return i_echoParam($m); }
633
+    function i_echoStruct($m) { return i_echoParam($m); }
634
+    function i_echoStringArray($m) { return i_echoParam($m); }
635
+    function i_echoIntegerArray($m) { return i_echoParam($m); }
636
+    function i_echoFloatArray($m) { return i_echoParam($m); }
637
+    function i_echoStructArray($m) { return i_echoParam($m); }
638
+    function i_echoValue($m) { return i_echoParam($m); }
639
+    function i_echoBase64($m) { return i_echoParam($m); }
640
+    function i_echoDate($m) { return i_echoParam($m); }
641
+
642
+    $i_whichToolkit_sig=array(array($xmlrpcStruct));
643
+    $i_whichToolkit_doc="Returns a struct containing the following strings: toolkitDocsUrl, toolkitName, toolkitVersion, toolkitOperatingSystem.";
644
+
645
+    function i_whichToolkit($m)
646
+    {
647
+        global $xmlrpcName, $xmlrpcVersion,$SERVER_SOFTWARE;
648
+        $ret=array(
649
+            "toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/",
650
+            "toolkitName" => $xmlrpcName,
651
+            "toolkitVersion" => $xmlrpcVersion,
652
+            "toolkitOperatingSystem" => isset ($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE']
653
+        );
654
+        return new xmlrpcresp ( php_xmlrpc_encode($ret));
655
+    }
656
+
657
+    $o=new xmlrpc_server_methods_container;
658
+    $a=array(
659
+        "examples.getStateName" => array(
660
+            "function" => "findstate",
661
+            "signature" => $findstate_sig,
662
+            "docstring" => $findstate_doc
663
+        ),
664
+        "examples.sortByAge" => array(
665
+            "function" => "agesorter",
666
+            "signature" => $agesorter_sig,
667
+            "docstring" => $agesorter_doc
668
+        ),
669
+        "examples.addtwo" => array(
670
+            "function" => "addtwo",
671
+            "signature" => $addtwo_sig,
672
+            "docstring" => $addtwo_doc
673
+        ),
674
+        "examples.addtwodouble" => array(
675
+            "function" => "addtwodouble",
676
+            "signature" => $addtwodouble_sig,
677
+            "docstring" => $addtwodouble_doc
678
+        ),
679
+        "examples.stringecho" => array(
680
+            "function" => "stringecho",
681
+            "signature" => $stringecho_sig,
682
+            "docstring" => $stringecho_doc
683
+        ),
684
+        "examples.echo" => array(
685
+            "function" => "echoback",
686
+            "signature" => $echoback_sig,
687
+            "docstring" => $echoback_doc
688
+        ),
689
+        "examples.decode64" => array(
690
+            "function" => "echosixtyfour",
691
+            "signature" => $echosixtyfour_sig,
692
+            "docstring" => $echosixtyfour_doc
693
+        ),
694
+        "examples.invertBooleans" => array(
695
+            "function" => "bitflipper",
696
+            "signature" => $bitflipper_sig,
697
+            "docstring" => $bitflipper_doc
698
+        ),
699
+        "examples.generatePHPWarning" => array(
700
+            "function" => array($o, "phpwarninggenerator")
701
+            //'function' => 'xmlrpc_server_methods_container::phpwarninggenerator'
702
+        ),
703
+        "examples.raiseException" => array(
704
+            "function" => array($o, "exceptiongenerator")
705
+        ),
706
+        "examples.getallheaders" => array(
707
+            "function" => 'getallheaders_xmlrpc',
708
+            "signature" => $getallheaders_sig,
709
+            "docstring" => $getallheaders_doc
710
+        ),
711
+        "examples.setcookies" => array(
712
+            "function" => 'setcookies',
713
+            "signature" => $setcookies_sig,
714
+            "docstring" => $setcookies_doc
715
+        ),
716
+        "examples.getcookies" => array(
717
+            "function" => 'getcookies',
718
+            "signature" => $getcookies_sig,
719
+            "docstring" => $getcookies_doc
720
+        ),
721
+        "mail.send" => array(
722
+            "function" => "mail_send",
723
+            "signature" => $mail_send_sig,
724
+            "docstring" => $mail_send_doc
725
+        ),
726
+        "validator1.arrayOfStructsTest" => array(
727
+            "function" => "v1_arrayOfStructs",
728
+            "signature" => $v1_arrayOfStructs_sig,
729
+            "docstring" => $v1_arrayOfStructs_doc
730
+        ),
731
+        "validator1.easyStructTest" => array(
732
+            "function" => "v1_easyStruct",
733
+            "signature" => $v1_easyStruct_sig,
734
+            "docstring" => $v1_easyStruct_doc
735
+        ),
736
+        "validator1.echoStructTest" => array(
737
+            "function" => "v1_echoStruct",
738
+            "signature" => $v1_echoStruct_sig,
739
+            "docstring" => $v1_echoStruct_doc
740
+        ),
741
+        "validator1.manyTypesTest" => array(
742
+            "function" => "v1_manyTypes",
743
+            "signature" => $v1_manyTypes_sig,
744
+            "docstring" => $v1_manyTypes_doc
745
+        ),
746
+        "validator1.moderateSizeArrayCheck" => array(
747
+            "function" => "v1_moderateSizeArrayCheck",
748
+            "signature" => $v1_moderateSizeArrayCheck_sig,
749
+            "docstring" => $v1_moderateSizeArrayCheck_doc
750
+        ),
751
+        "validator1.simpleStructReturnTest" => array(
752
+            "function" => "v1_simpleStructReturn",
753
+            "signature" => $v1_simpleStructReturn_sig,
754
+            "docstring" => $v1_simpleStructReturn_doc
755
+        ),
756
+        "validator1.nestedStructTest" => array(
757
+            "function" => "v1_nestedStruct",
758
+            "signature" => $v1_nestedStruct_sig,
759
+            "docstring" => $v1_nestedStruct_doc
760
+        ),
761
+        "validator1.countTheEntities" => array(
762
+            "function" => "v1_countTheEntities",
763
+            "signature" => $v1_countTheEntities_sig,
764
+            "docstring" => $v1_countTheEntities_doc
765
+        ),
766
+        "interopEchoTests.echoString" => array(
767
+            "function" => "i_echoString",
768
+            "signature" => $i_echoString_sig,
769
+            "docstring" => $i_echoString_doc
770
+        ),
771
+        "interopEchoTests.echoStringArray" => array(
772
+            "function" => "i_echoStringArray",
773
+            "signature" => $i_echoStringArray_sig,
774
+            "docstring" => $i_echoStringArray_doc
775
+        ),
776
+        "interopEchoTests.echoInteger" => array(
777
+            "function" => "i_echoInteger",
778
+            "signature" => $i_echoInteger_sig,
779
+            "docstring" => $i_echoInteger_doc
780
+        ),
781
+        "interopEchoTests.echoIntegerArray" => array(
782
+            "function" => "i_echoIntegerArray",
783
+            "signature" => $i_echoIntegerArray_sig,
784
+            "docstring" => $i_echoIntegerArray_doc
785
+        ),
786
+        "interopEchoTests.echoFloat" => array(
787
+            "function" => "i_echoFloat",
788
+            "signature" => $i_echoFloat_sig,
789
+            "docstring" => $i_echoFloat_doc
790
+        ),
791
+        "interopEchoTests.echoFloatArray" => array(
792
+            "function" => "i_echoFloatArray",
793
+            "signature" => $i_echoFloatArray_sig,
794
+            "docstring" => $i_echoFloatArray_doc
795
+        ),
796
+        "interopEchoTests.echoStruct" => array(
797
+            "function" => "i_echoStruct",
798
+            "signature" => $i_echoStruct_sig,
799
+            "docstring" => $i_echoStruct_doc
800
+        ),
801
+        "interopEchoTests.echoStructArray" => array(
802
+            "function" => "i_echoStructArray",
803
+            "signature" => $i_echoStructArray_sig,
804
+            "docstring" => $i_echoStructArray_doc
805
+        ),
806
+        "interopEchoTests.echoValue" => array(
807
+            "function" => "i_echoValue",
808
+            "signature" => $i_echoValue_sig,
809
+            "docstring" => $i_echoValue_doc
810
+        ),
811
+        "interopEchoTests.echoBase64" => array(
812
+            "function" => "i_echoBase64",
813
+            "signature" => $i_echoBase64_sig,
814
+            "docstring" => $i_echoBase64_doc
815
+        ),
816
+        "interopEchoTests.echoDate" => array(
817
+            "function" => "i_echoDate",
818
+            "signature" => $i_echoDate_sig,
819
+            "docstring" => $i_echoDate_doc
820
+        ),
821
+        "interopEchoTests.whichToolkit" => array(
822
+            "function" => "i_whichToolkit",
823
+            "signature" => $i_whichToolkit_sig,
824
+            "docstring" => $i_whichToolkit_doc
825
+        )
826
+    );
827
+
828
+    if ($findstate2_sig)
829
+        $a['examples.php.getStateName'] = $findstate2_sig;
830
+
831
+    if ($findstate3_sig)
832
+        $a['examples.php2.getStateName'] = $findstate3_sig;
833
+
834
+    if ($findstate4_sig)
835
+        $a['examples.php3.getStateName'] = $findstate4_sig;
836 836
 
837 837
     if ($findstate5_sig)
838 838
         $a['examples.php4.getStateName'] = $findstate5_sig;
839 839
 
840
-	$s=new xmlrpc_server($a, false);
841
-	$s->setdebug(3);
842
-	$s->compress_response = true;
843
-
844
-	// out-of-band information: let the client manipulate the server operations.
845
-	// we do this to help the testsuite script: do not reproduce in production!
846
-	if (isset($_GET['RESPONSE_ENCODING']))
847
-		$s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
848
-	if (isset($_GET['EXCEPTION_HANDLING']))
849
-		$s->exception_handling = $_GET['EXCEPTION_HANDLING'];
850
-	$s->service();
851
-	// that should do all we need!
840
+    $s=new xmlrpc_server($a, false);
841
+    $s->setdebug(3);
842
+    $s->compress_response = true;
843
+
844
+    // out-of-band information: let the client manipulate the server operations.
845
+    // we do this to help the testsuite script: do not reproduce in production!
846
+    if (isset($_GET['RESPONSE_ENCODING']))
847
+        $s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
848
+    if (isset($_GET['EXCEPTION_HANDLING']))
849
+        $s->exception_handling = $_GET['EXCEPTION_HANDLING'];
850
+    $s->service();
851
+    // that should do all we need!
852 852
 ?>
853 853
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 		"Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"
72 72
 	);
73 73
 
74
-	$findstate_sig=array(array($xmlrpcString, $xmlrpcInt));
75
-	$findstate_doc='When passed an integer between 1 and 51 returns the
74
+	$findstate_sig = array(array($xmlrpcString, $xmlrpcInt));
75
+	$findstate_doc = 'When passed an integer between 1 and 51 returns the
76 76
 name of a US state, where the integer is the index of that state name
77 77
 in an alphabetic order.';
78 78
 
@@ -80,24 +80,24 @@  discard block
 block discarded – undo
80 80
 	function findstate($m)
81 81
 	{
82 82
 		global $xmlrpcerruser, $stateNames;
83
-		$err="";
83
+		$err = "";
84 84
 		// get the first param
85
-		$sno=$m->getParam(0);
85
+		$sno = $m->getParam(0);
86 86
 
87 87
 		// param must be there and of the correct type: server object does the
88 88
 		// validation for us
89 89
 
90 90
 		// extract the value of the state number
91
-		$snv=$sno->scalarval();
91
+		$snv = $sno->scalarval();
92 92
 		// look it up in our array (zero-based)
93 93
 		if (isset($stateNames[$snv-1]))
94 94
 		{
95
-			$sname=$stateNames[$snv-1];
95
+			$sname = $stateNames[$snv-1];
96 96
 		}
97 97
 		else
98 98
 		{
99 99
 			// not, there so complain
100
-			$err="I don't have a state for the index '" . $snv . "'";
100
+			$err = "I don't have a state for the index '".$snv."'";
101 101
 		}
102 102
 
103 103
 		// if we generated an error, create an error return response
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		else
130 130
 		{
131 131
 			// not, there so complain
132
-			return "I don't have a state for the index '" . $stateno . "'";
132
+			return "I don't have a state for the index '".$stateno."'";
133 133
 		}
134 134
 	}
135 135
 	$findstate2_sig = wrap_php_function('inner_findstate');
@@ -141,70 +141,70 @@  discard block
 block discarded – undo
141 141
 	$obj = new xmlrpc_server_methods_container();
142 142
 	$findstate4_sig = wrap_php_function(array($obj, 'findstate'));
143 143
 
144
-	$addtwo_sig=array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt));
145
-	$addtwo_doc='Add two integers together and return the result';
144
+	$addtwo_sig = array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt));
145
+	$addtwo_doc = 'Add two integers together and return the result';
146 146
 	function addtwo($m)
147 147
 	{
148
-		$s=$m->getParam(0);
149
-		$t=$m->getParam(1);
150
-		return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(),"int"));
148
+		$s = $m->getParam(0);
149
+		$t = $m->getParam(1);
150
+		return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(), "int"));
151 151
 	}
152 152
 
153
-	$addtwodouble_sig=array(array($xmlrpcDouble, $xmlrpcDouble, $xmlrpcDouble));
154
-	$addtwodouble_doc='Add two doubles together and return the result';
153
+	$addtwodouble_sig = array(array($xmlrpcDouble, $xmlrpcDouble, $xmlrpcDouble));
154
+	$addtwodouble_doc = 'Add two doubles together and return the result';
155 155
 	function addtwodouble($m)
156 156
 	{
157
-		$s=$m->getParam(0);
158
-		$t=$m->getParam(1);
159
-		return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(),"double"));
157
+		$s = $m->getParam(0);
158
+		$t = $m->getParam(1);
159
+		return new xmlrpcresp(new xmlrpcval($s->scalarval()+$t->scalarval(), "double"));
160 160
 	}
161 161
 
162
-	$stringecho_sig=array(array($xmlrpcString, $xmlrpcString));
163
-	$stringecho_doc='Accepts a string parameter, returns the string.';
162
+	$stringecho_sig = array(array($xmlrpcString, $xmlrpcString));
163
+	$stringecho_doc = 'Accepts a string parameter, returns the string.';
164 164
 	function stringecho($m)
165 165
 	{
166 166
 		// just sends back a string
167
-		$s=$m->getParam(0);
167
+		$s = $m->getParam(0);
168 168
 		$v = $s->scalarval();
169 169
 		return new xmlrpcresp(new xmlrpcval($s->scalarval()));
170 170
 	}
171 171
 
172
-	$echoback_sig=array(array($xmlrpcString, $xmlrpcString));
173
-	$echoback_doc='Accepts a string parameter, returns the entire incoming payload';
172
+	$echoback_sig = array(array($xmlrpcString, $xmlrpcString));
173
+	$echoback_doc = 'Accepts a string parameter, returns the entire incoming payload';
174 174
 	function echoback($m)
175 175
 	{
176 176
 		// just sends back a string with what i got
177 177
 		// sent to me, just escaped, that's all
178 178
 		//
179 179
 		// $m is an incoming message
180
-		$s="I got the following message:\n" . $m->serialize();
180
+		$s = "I got the following message:\n".$m->serialize();
181 181
 		return new xmlrpcresp(new xmlrpcval($s));
182 182
 	}
183 183
 
184
-	$echosixtyfour_sig=array(array($xmlrpcString, $xmlrpcBase64));
185
-	$echosixtyfour_doc='Accepts a base64 parameter and returns it decoded as a string';
184
+	$echosixtyfour_sig = array(array($xmlrpcString, $xmlrpcBase64));
185
+	$echosixtyfour_doc = 'Accepts a base64 parameter and returns it decoded as a string';
186 186
 	function echosixtyfour($m)
187 187
 	{
188 188
 		// accepts an encoded value, but sends it back
189 189
 		// as a normal string. this is to test base64 encoding
190 190
 		// is working as expected
191
-		$incoming=$m->getParam(0);
191
+		$incoming = $m->getParam(0);
192 192
 		return new xmlrpcresp(new xmlrpcval($incoming->scalarval(), "string"));
193 193
 	}
194 194
 
195
-	$bitflipper_sig=array(array($xmlrpcArray, $xmlrpcArray));
196
-	$bitflipper_doc='Accepts an array of booleans, and returns them inverted';
195
+	$bitflipper_sig = array(array($xmlrpcArray, $xmlrpcArray));
196
+	$bitflipper_doc = 'Accepts an array of booleans, and returns them inverted';
197 197
 	function bitflipper($m)
198 198
 	{
199 199
 		global $xmlrpcArray;
200 200
 
201
-		$v=$m->getParam(0);
202
-		$sz=$v->arraysize();
203
-		$rv=new xmlrpcval(array(), $xmlrpcArray);
201
+		$v = $m->getParam(0);
202
+		$sz = $v->arraysize();
203
+		$rv = new xmlrpcval(array(), $xmlrpcArray);
204 204
 
205
-		for($j=0; $j<$sz; $j++)
205
+		for ($j = 0; $j<$sz; $j++)
206 206
 		{
207
-			$b=$v->arraymem($j);
207
+			$b = $v->arraymem($j);
208 208
 			if ($b->scalarval())
209 209
 			{
210 210
 				$rv->addScalar(false, "boolean");
@@ -235,18 +235,18 @@  discard block
 block discarded – undo
235 235
 
236 236
 		// don't even ask me _why_ these come padded with
237 237
 		// hyphens, I couldn't tell you :p
238
-		$a=str_replace("-", "", $a);
239
-		$b=str_replace("-", "", $b);
238
+		$a = str_replace("-", "", $a);
239
+		$b = str_replace("-", "", $b);
240 240
 
241
-		if ($agesorter_arr[$a]==$agesorter[$b])
241
+		if ($agesorter_arr[$a] == $agesorter[$b])
242 242
 		{
243 243
 			return 0;
244 244
 		}
245
-		return ($agesorter_arr[$a] > $agesorter_arr[$b]) ? -1 : 1;
245
+		return ($agesorter_arr[$a]>$agesorter_arr[$b]) ? -1 : 1;
246 246
 	}
247 247
 
248
-	$agesorter_sig=array(array($xmlrpcArray, $xmlrpcArray));
249
-	$agesorter_doc='Send this method an array of [string, int] structs, eg:
248
+	$agesorter_sig = array(array($xmlrpcArray, $xmlrpcArray));
249
+	$agesorter_doc = 'Send this method an array of [string, int] structs, eg:
250 250
 <pre>
251 251
  Dave   35
252 252
  Edd	45
@@ -261,43 +261,43 @@  discard block
 block discarded – undo
261 261
 
262 262
 		xmlrpc_debugmsg("Entering 'agesorter'");
263 263
 		// get the parameter
264
-		$sno=$m->getParam(0);
264
+		$sno = $m->getParam(0);
265 265
 		// error string for [if|when] things go wrong
266
-		$err="";
266
+		$err = "";
267 267
 		// create the output value
268
-		$v=new xmlrpcval();
269
-		$agar=array();
268
+		$v = new xmlrpcval();
269
+		$agar = array();
270 270
 
271
-		if (isset($sno) && $sno->kindOf()=="array")
271
+		if (isset($sno) && $sno->kindOf() == "array")
272 272
 		{
273
-			$max=$sno->arraysize();
273
+			$max = $sno->arraysize();
274 274
 			// TODO: create debug method to print can work once more
275 275
 			// print "<!-- found $max array elements -->\n";
276
-			for($i=0; $i<$max; $i++)
276
+			for ($i = 0; $i<$max; $i++)
277 277
 			{
278
-				$rec=$sno->arraymem($i);
279
-				if ($rec->kindOf()!="struct")
278
+				$rec = $sno->arraymem($i);
279
+				if ($rec->kindOf() != "struct")
280 280
 				{
281
-					$err="Found non-struct in array at element $i";
281
+					$err = "Found non-struct in array at element $i";
282 282
 					break;
283 283
 				}
284 284
 				// extract name and age from struct
285
-				$n=$rec->structmem("name");
286
-				$a=$rec->structmem("age");
285
+				$n = $rec->structmem("name");
286
+				$a = $rec->structmem("age");
287 287
 				// $n and $a are xmlrpcvals,
288 288
 				// so get the scalarval from them
289
-				$agar[$n->scalarval()]=$a->scalarval();
289
+				$agar[$n->scalarval()] = $a->scalarval();
290 290
 			}
291 291
 
292
-			$agesorter_arr=$agar;
292
+			$agesorter_arr = $agar;
293 293
 			// hack, must make global as uksort() won't
294 294
 			// allow us to pass any other auxilliary information
295 295
 			uksort($agesorter_arr, agesorter_compare);
296
-			$outAr=array();
297
-			while (list( $key, $val ) = each( $agesorter_arr ) )
296
+			$outAr = array();
297
+			while (list($key, $val) = each($agesorter_arr))
298 298
 			{
299 299
 				// recreate each struct element
300
-				$outAr[]=new xmlrpcval(array("name" =>
300
+				$outAr[] = new xmlrpcval(array("name" =>
301 301
 				new xmlrpcval($key),
302 302
 				"age" =>
303 303
 				new xmlrpcval($val, "int")), "struct");
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 		}
308 308
 		else
309 309
 		{
310
-			$err="Must be one parameter, an array of structs";
310
+			$err = "Must be one parameter, an array of structs";
311 311
 		}
312 312
 
313 313
 		if ($err)
@@ -322,13 +322,13 @@  discard block
 block discarded – undo
322 322
 
323 323
 	// signature and instructions, place these in the dispatch
324 324
 	// map
325
-	$mail_send_sig=array(array(
325
+	$mail_send_sig = array(array(
326 326
 		$xmlrpcBoolean, $xmlrpcString, $xmlrpcString,
327 327
 		$xmlrpcString, $xmlrpcString, $xmlrpcString,
328 328
 		$xmlrpcString, $xmlrpcString
329 329
 	));
330 330
 
331
-	$mail_send_doc='mail.send(recipient, subject, text, sender, cc, bcc, mimetype)<br/>
331
+	$mail_send_doc = 'mail.send(recipient, subject, text, sender, cc, bcc, mimetype)<br/>
332 332
 recipient, cc, and bcc are strings, comma-separated lists of email addresses, as described above.<br/>
333 333
 subject is a string, the subject of the message.<br/>
334 334
 sender is a string, it\'s the email address of the person sending the message. This string can not be
@@ -342,51 +342,51 @@  discard block
 block discarded – undo
342 342
 	function mail_send($m)
343 343
 	{
344 344
 		global $xmlrpcerruser, $xmlrpcBoolean;
345
-		$err="";
345
+		$err = "";
346 346
 
347
-		$mTo=$m->getParam(0);
348
-		$mSub=$m->getParam(1);
349
-		$mBody=$m->getParam(2);
350
-		$mFrom=$m->getParam(3);
351
-		$mCc=$m->getParam(4);
352
-		$mBcc=$m->getParam(5);
353
-		$mMime=$m->getParam(6);
347
+		$mTo = $m->getParam(0);
348
+		$mSub = $m->getParam(1);
349
+		$mBody = $m->getParam(2);
350
+		$mFrom = $m->getParam(3);
351
+		$mCc = $m->getParam(4);
352
+		$mBcc = $m->getParam(5);
353
+		$mMime = $m->getParam(6);
354 354
 
355
-		if ($mTo->scalarval()=="")
355
+		if ($mTo->scalarval() == "")
356 356
 		{
357
-			$err="Error, no 'To' field specified";
357
+			$err = "Error, no 'To' field specified";
358 358
 		}
359 359
 
360
-		if ($mFrom->scalarval()=="")
360
+		if ($mFrom->scalarval() == "")
361 361
 		{
362
-			$err="Error, no 'From' field specified";
362
+			$err = "Error, no 'From' field specified";
363 363
 		}
364 364
 
365
-		$msghdr="From: " . $mFrom->scalarval() . "\n";
366
-		$msghdr.="To: ". $mTo->scalarval() . "\n";
365
+		$msghdr = "From: ".$mFrom->scalarval()."\n";
366
+		$msghdr .= "To: ".$mTo->scalarval()."\n";
367 367
 
368
-		if ($mCc->scalarval()!="")
368
+		if ($mCc->scalarval() != "")
369 369
 		{
370
-			$msghdr.="Cc: " . $mCc->scalarval(). "\n";
370
+			$msghdr .= "Cc: ".$mCc->scalarval()."\n";
371 371
 		}
372
-		if ($mBcc->scalarval()!="")
372
+		if ($mBcc->scalarval() != "")
373 373
 		{
374
-			$msghdr.="Bcc: " . $mBcc->scalarval(). "\n";
374
+			$msghdr .= "Bcc: ".$mBcc->scalarval()."\n";
375 375
 		}
376
-		if ($mMime->scalarval()!="")
376
+		if ($mMime->scalarval() != "")
377 377
 		{
378
-			$msghdr.="Content-type: " . $mMime->scalarval() . "\n";
378
+			$msghdr .= "Content-type: ".$mMime->scalarval()."\n";
379 379
 		}
380
-		$msghdr.="X-Mailer: XML-RPC for PHP mailer 1.0";
380
+		$msghdr .= "X-Mailer: XML-RPC for PHP mailer 1.0";
381 381
 
382
-		if ($err=="")
382
+		if ($err == "")
383 383
 		{
384 384
 			if (!mail("",
385 385
 				$mSub->scalarval(),
386 386
 				$mBody->scalarval(),
387 387
 				$msghdr))
388 388
 			{
389
-				$err="Error, could not send the mail.";
389
+				$err = "Error, could not send the mail.";
390 390
 			}
391 391
 		}
392 392
 
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
 		}
401 401
 	}
402 402
 
403
-	$getallheaders_sig=array(array($xmlrpcStruct));
404
-	$getallheaders_doc='Returns a struct containing all the HTTP headers received with the request. Provides limited functionality with IIS';
403
+	$getallheaders_sig = array(array($xmlrpcStruct));
404
+	$getallheaders_doc = 'Returns a struct containing all the HTTP headers received with the request. Provides limited functionality with IIS';
405 405
 	function getallheaders_xmlrpc($m)
406 406
 	{
407 407
 		global $xmlrpcerruser;
@@ -423,12 +423,12 @@  discard block
 block discarded – undo
423 423
 		}
424 424
 	}
425 425
 
426
-	$setcookies_sig=array(array($xmlrpcInt, $xmlrpcStruct));
427
-	$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)';
426
+	$setcookies_sig = array(array($xmlrpcInt, $xmlrpcStruct));
427
+	$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)';
428 428
 	function setcookies($m)
429 429
 	{
430 430
 		$m = $m->getParam(0);
431
-		while(list($name,$value) = $m->structeach())
431
+		while (list($name, $value) = $m->structeach())
432 432
 		{
433 433
 			$cookiedesc = php_xmlrpc_decode($value);
434 434
 			setcookie($name, @$cookiedesc['value'], @$cookiedesc['expires'], @$cookiedesc['path'], @$cookiedesc['domain'], @$cookiedesc['secure']);
@@ -436,60 +436,60 @@  discard block
 block discarded – undo
436 436
 		return new xmlrpcresp(new xmlrpcval(1, 'int'));
437 437
 	}
438 438
 
439
-	$getcookies_sig=array(array($xmlrpcStruct));
440
-	$getcookies_doc='Sends to client a response containing all http cookies as received in the request (as struct)';
439
+	$getcookies_sig = array(array($xmlrpcStruct));
440
+	$getcookies_doc = 'Sends to client a response containing all http cookies as received in the request (as struct)';
441 441
 	function getcookies($m)
442 442
 	{
443 443
 		return new xmlrpcresp(php_xmlrpc_encode($_COOKIE));
444 444
 	}
445 445
 
446
-	$v1_arrayOfStructs_sig=array(array($xmlrpcInt, $xmlrpcArray));
447
-	$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.';
446
+	$v1_arrayOfStructs_sig = array(array($xmlrpcInt, $xmlrpcArray));
447
+	$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.';
448 448
 	function v1_arrayOfStructs($m)
449 449
 	{
450
-		$sno=$m->getParam(0);
451
-		$numcurly=0;
452
-		for($i=0; $i<$sno->arraysize(); $i++)
450
+		$sno = $m->getParam(0);
451
+		$numcurly = 0;
452
+		for ($i = 0; $i<$sno->arraysize(); $i++)
453 453
 		{
454
-			$str=$sno->arraymem($i);
454
+			$str = $sno->arraymem($i);
455 455
 			$str->structreset();
456
-			while(list($key,$val)=$str->structeach())
456
+			while (list($key, $val) = $str->structeach())
457 457
 			{
458
-				if ($key=="curly")
458
+				if ($key == "curly")
459 459
 				{
460
-					$numcurly+=$val->scalarval();
460
+					$numcurly += $val->scalarval();
461 461
 				}
462 462
 			}
463 463
 		}
464 464
 		return new xmlrpcresp(new xmlrpcval($numcurly, "int"));
465 465
 	}
466 466
 
467
-	$v1_easyStruct_sig=array(array($xmlrpcInt, $xmlrpcStruct));
468
-	$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.';
467
+	$v1_easyStruct_sig = array(array($xmlrpcInt, $xmlrpcStruct));
468
+	$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.';
469 469
 	function v1_easyStruct($m)
470 470
 	{
471
-		$sno=$m->getParam(0);
472
-		$moe=$sno->structmem("moe");
473
-		$larry=$sno->structmem("larry");
474
-		$curly=$sno->structmem("curly");
475
-		$num=$moe->scalarval() + $larry->scalarval() + $curly->scalarval();
471
+		$sno = $m->getParam(0);
472
+		$moe = $sno->structmem("moe");
473
+		$larry = $sno->structmem("larry");
474
+		$curly = $sno->structmem("curly");
475
+		$num = $moe->scalarval()+$larry->scalarval()+$curly->scalarval();
476 476
 		return new xmlrpcresp(new xmlrpcval($num, "int"));
477 477
 	}
478 478
 
479
-	$v1_echoStruct_sig=array(array($xmlrpcStruct, $xmlrpcStruct));
480
-	$v1_echoStruct_doc='This handler takes a single parameter, a struct. Your handler must return the struct.';
479
+	$v1_echoStruct_sig = array(array($xmlrpcStruct, $xmlrpcStruct));
480
+	$v1_echoStruct_doc = 'This handler takes a single parameter, a struct. Your handler must return the struct.';
481 481
 	function v1_echoStruct($m)
482 482
 	{
483
-		$sno=$m->getParam(0);
483
+		$sno = $m->getParam(0);
484 484
 		return new xmlrpcresp($sno);
485 485
 	}
486 486
 
487
-	$v1_manyTypes_sig=array(array(
487
+	$v1_manyTypes_sig = array(array(
488 488
 		$xmlrpcArray, $xmlrpcInt, $xmlrpcBoolean,
489 489
 		$xmlrpcString, $xmlrpcDouble, $xmlrpcDateTime,
490 490
 		$xmlrpcBase64
491 491
 	));
492
-	$v1_manyTypes_doc='This handler takes six parameters, and returns an array containing all the parameters.';
492
+	$v1_manyTypes_doc = 'This handler takes six parameters, and returns an array containing all the parameters.';
493 493
 	function v1_manyTypes($m)
494 494
 	{
495 495
 		return new xmlrpcresp(new xmlrpcval(array(
@@ -503,58 +503,58 @@  discard block
 block discarded – undo
503 503
 		));
504 504
 	}
505 505
 
506
-	$v1_moderateSizeArrayCheck_sig=array(array($xmlrpcString, $xmlrpcArray));
507
-	$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.';
506
+	$v1_moderateSizeArrayCheck_sig = array(array($xmlrpcString, $xmlrpcArray));
507
+	$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.';
508 508
 	function v1_moderateSizeArrayCheck($m)
509 509
 	{
510
-		$ar=$m->getParam(0);
511
-		$sz=$ar->arraysize();
512
-		$first=$ar->arraymem(0);
513
-		$last=$ar->arraymem($sz-1);
514
-		return new xmlrpcresp(new xmlrpcval($first->scalarval() .
510
+		$ar = $m->getParam(0);
511
+		$sz = $ar->arraysize();
512
+		$first = $ar->arraymem(0);
513
+		$last = $ar->arraymem($sz-1);
514
+		return new xmlrpcresp(new xmlrpcval($first->scalarval().
515 515
 		$last->scalarval(), "string"));
516 516
 	}
517 517
 
518
-	$v1_simpleStructReturn_sig=array(array($xmlrpcStruct, $xmlrpcInt));
519
-	$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.';
518
+	$v1_simpleStructReturn_sig = array(array($xmlrpcStruct, $xmlrpcInt));
519
+	$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.';
520 520
 	function v1_simpleStructReturn($m)
521 521
 	{
522
-		$sno=$m->getParam(0);
523
-		$v=$sno->scalarval();
522
+		$sno = $m->getParam(0);
523
+		$v = $sno->scalarval();
524 524
 		return new xmlrpcresp(new xmlrpcval(array(
525
-			"times10"   => new xmlrpcval($v*10, "int"),
526
-			"times100"  => new xmlrpcval($v*100, "int"),
527
-			"times1000" => new xmlrpcval($v*1000, "int")),
525
+			"times10"   => new xmlrpcval($v * 10, "int"),
526
+			"times100"  => new xmlrpcval($v * 100, "int"),
527
+			"times1000" => new xmlrpcval($v * 1000, "int")),
528 528
 			"struct"
529 529
 		));
530 530
 	}
531 531
 
532
-	$v1_nestedStruct_sig=array(array($xmlrpcInt, $xmlrpcStruct));
533
-	$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.';
532
+	$v1_nestedStruct_sig = array(array($xmlrpcInt, $xmlrpcStruct));
533
+	$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.';
534 534
 	function v1_nestedStruct($m)
535 535
 	{
536
-		$sno=$m->getParam(0);
537
-
538
-		$twoK=$sno->structmem("2000");
539
-		$april=$twoK->structmem("04");
540
-		$fools=$april->structmem("01");
541
-		$curly=$fools->structmem("curly");
542
-		$larry=$fools->structmem("larry");
543
-		$moe=$fools->structmem("moe");
544
-		return new xmlrpcresp(new xmlrpcval($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), "int"));
536
+		$sno = $m->getParam(0);
537
+
538
+		$twoK = $sno->structmem("2000");
539
+		$april = $twoK->structmem("04");
540
+		$fools = $april->structmem("01");
541
+		$curly = $fools->structmem("curly");
542
+		$larry = $fools->structmem("larry");
543
+		$moe = $fools->structmem("moe");
544
+		return new xmlrpcresp(new xmlrpcval($curly->scalarval()+$larry->scalarval()+$moe->scalarval(), "int"));
545 545
 	}
546 546
 
547
-	$v1_countTheEntities_sig=array(array($xmlrpcStruct, $xmlrpcString));
548
-	$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.';
547
+	$v1_countTheEntities_sig = array(array($xmlrpcStruct, $xmlrpcString));
548
+	$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.';
549 549
 	function v1_countTheEntities($m)
550 550
 	{
551
-		$sno=$m->getParam(0);
552
-		$str=$sno->scalarval();
553
-		$gt=0; $lt=0; $ap=0; $qu=0; $amp=0;
554
-		for($i=0; $i<strlen($str); $i++)
551
+		$sno = $m->getParam(0);
552
+		$str = $sno->scalarval();
553
+		$gt = 0; $lt = 0; $ap = 0; $qu = 0; $amp = 0;
554
+		for ($i = 0; $i<strlen($str); $i++)
555 555
 		{
556
-			$c=substr($str, $i, 1);
557
-			switch($c)
556
+			$c = substr($str, $i, 1);
557
+			switch ($c)
558 558
 			{
559 559
 				case ">":
560 560
 					$gt++;
@@ -588,42 +588,42 @@  discard block
 block discarded – undo
588 588
 	// trivial interop tests
589 589
 	// http://www.xmlrpc.com/stories/storyReader$1636
590 590
 
591
-	$i_echoString_sig=array(array($xmlrpcString, $xmlrpcString));
592
-	$i_echoString_doc="Echoes string.";
591
+	$i_echoString_sig = array(array($xmlrpcString, $xmlrpcString));
592
+	$i_echoString_doc = "Echoes string.";
593 593
 
594
-	$i_echoStringArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
595
-	$i_echoStringArray_doc="Echoes string array.";
594
+	$i_echoStringArray_sig = array(array($xmlrpcArray, $xmlrpcArray));
595
+	$i_echoStringArray_doc = "Echoes string array.";
596 596
 
597
-	$i_echoInteger_sig=array(array($xmlrpcInt, $xmlrpcInt));
598
-	$i_echoInteger_doc="Echoes integer.";
597
+	$i_echoInteger_sig = array(array($xmlrpcInt, $xmlrpcInt));
598
+	$i_echoInteger_doc = "Echoes integer.";
599 599
 
600
-	$i_echoIntegerArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
601
-	$i_echoIntegerArray_doc="Echoes integer array.";
600
+	$i_echoIntegerArray_sig = array(array($xmlrpcArray, $xmlrpcArray));
601
+	$i_echoIntegerArray_doc = "Echoes integer array.";
602 602
 
603
-	$i_echoFloat_sig=array(array($xmlrpcDouble, $xmlrpcDouble));
604
-	$i_echoFloat_doc="Echoes float.";
603
+	$i_echoFloat_sig = array(array($xmlrpcDouble, $xmlrpcDouble));
604
+	$i_echoFloat_doc = "Echoes float.";
605 605
 
606
-	$i_echoFloatArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
607
-	$i_echoFloatArray_doc="Echoes float array.";
606
+	$i_echoFloatArray_sig = array(array($xmlrpcArray, $xmlrpcArray));
607
+	$i_echoFloatArray_doc = "Echoes float array.";
608 608
 
609
-	$i_echoStruct_sig=array(array($xmlrpcStruct, $xmlrpcStruct));
610
-	$i_echoStruct_doc="Echoes struct.";
609
+	$i_echoStruct_sig = array(array($xmlrpcStruct, $xmlrpcStruct));
610
+	$i_echoStruct_doc = "Echoes struct.";
611 611
 
612
-	$i_echoStructArray_sig=array(array($xmlrpcArray, $xmlrpcArray));
613
-	$i_echoStructArray_doc="Echoes struct array.";
612
+	$i_echoStructArray_sig = array(array($xmlrpcArray, $xmlrpcArray));
613
+	$i_echoStructArray_doc = "Echoes struct array.";
614 614
 
615
-	$i_echoValue_doc="Echoes any value back.";
616
-	$i_echoValue_sig=array(array($xmlrpcValue, $xmlrpcValue));
615
+	$i_echoValue_doc = "Echoes any value back.";
616
+	$i_echoValue_sig = array(array($xmlrpcValue, $xmlrpcValue));
617 617
 
618
-	$i_echoBase64_sig=array(array($xmlrpcBase64, $xmlrpcBase64));
619
-	$i_echoBase64_doc="Echoes base64.";
618
+	$i_echoBase64_sig = array(array($xmlrpcBase64, $xmlrpcBase64));
619
+	$i_echoBase64_doc = "Echoes base64.";
620 620
 
621
-	$i_echoDate_sig=array(array($xmlrpcDateTime, $xmlrpcDateTime));
622
-	$i_echoDate_doc="Echoes dateTime.";
621
+	$i_echoDate_sig = array(array($xmlrpcDateTime, $xmlrpcDateTime));
622
+	$i_echoDate_doc = "Echoes dateTime.";
623 623
 
624 624
 	function i_echoParam($m)
625 625
 	{
626
-		$s=$m->getParam(0);
626
+		$s = $m->getParam(0);
627 627
 		return new xmlrpcresp($s);
628 628
 	}
629 629
 
@@ -639,23 +639,23 @@  discard block
 block discarded – undo
639 639
 	function i_echoBase64($m) { return i_echoParam($m); }
640 640
 	function i_echoDate($m) { return i_echoParam($m); }
641 641
 
642
-	$i_whichToolkit_sig=array(array($xmlrpcStruct));
643
-	$i_whichToolkit_doc="Returns a struct containing the following strings: toolkitDocsUrl, toolkitName, toolkitVersion, toolkitOperatingSystem.";
642
+	$i_whichToolkit_sig = array(array($xmlrpcStruct));
643
+	$i_whichToolkit_doc = "Returns a struct containing the following strings: toolkitDocsUrl, toolkitName, toolkitVersion, toolkitOperatingSystem.";
644 644
 
645 645
 	function i_whichToolkit($m)
646 646
 	{
647
-		global $xmlrpcName, $xmlrpcVersion,$SERVER_SOFTWARE;
648
-		$ret=array(
647
+		global $xmlrpcName, $xmlrpcVersion, $SERVER_SOFTWARE;
648
+		$ret = array(
649 649
 			"toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/",
650 650
 			"toolkitName" => $xmlrpcName,
651 651
 			"toolkitVersion" => $xmlrpcVersion,
652 652
 			"toolkitOperatingSystem" => isset ($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE']
653 653
 		);
654
-		return new xmlrpcresp ( php_xmlrpc_encode($ret));
654
+		return new xmlrpcresp(php_xmlrpc_encode($ret));
655 655
 	}
656 656
 
657
-	$o=new xmlrpc_server_methods_container;
658
-	$a=array(
657
+	$o = new xmlrpc_server_methods_container;
658
+	$a = array(
659 659
 		"examples.getStateName" => array(
660 660
 			"function" => "findstate",
661 661
 			"signature" => $findstate_sig,
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
     if ($findstate5_sig)
838 838
         $a['examples.php4.getStateName'] = $findstate5_sig;
839 839
 
840
-	$s=new xmlrpc_server($a, false);
840
+	$s = new xmlrpc_server($a, false);
841 841
 	$s->setdebug(3);
842 842
 	$s->compress_response = true;
843 843
 
Please login to merge, or discard this patch.
Braces   +29 added lines, -30 removed lines patch added patch discarded remove patch
@@ -93,8 +93,7 @@  discard block
 block discarded – undo
93 93
 		if (isset($stateNames[$snv-1]))
94 94
 		{
95 95
 			$sname=$stateNames[$snv-1];
96
-		}
97
-		else
96
+		} else
98 97
 		{
99 98
 			// not, there so complain
100 99
 			$err="I don't have a state for the index '" . $snv . "'";
@@ -104,8 +103,7 @@  discard block
 block discarded – undo
104 103
 		if ($err)
105 104
 		{
106 105
 			return new xmlrpcresp(0, $xmlrpcerruser, $err);
107
-		}
108
-		else
106
+		} else
109 107
 		{
110 108
 			// otherwise, we create the right response
111 109
 			// with the state name
@@ -125,8 +123,7 @@  discard block
 block discarded – undo
125 123
 		if (isset($stateNames[$stateno-1]))
126 124
 		{
127 125
 			return $stateNames[$stateno-1];
128
-		}
129
-		else
126
+		} else
130 127
 		{
131 128
 			// not, there so complain
132 129
 			return "I don't have a state for the index '" . $stateno . "'";
@@ -208,8 +205,7 @@  discard block
 block discarded – undo
208 205
 			if ($b->scalarval())
209 206
 			{
210 207
 				$rv->addScalar(false, "boolean");
211
-			}
212
-			else
208
+			} else
213 209
 			{
214 210
 				$rv->addScalar(true, "boolean");
215 211
 			}
@@ -304,8 +300,7 @@  discard block
 block discarded – undo
304 300
 			}
305 301
 			// add this array to the output value
306 302
 			$v->addArray($outAr);
307
-		}
308
-		else
303
+		} else
309 304
 		{
310 305
 			$err="Must be one parameter, an array of structs";
311 306
 		}
@@ -313,8 +308,7 @@  discard block
 block discarded – undo
313 308
 		if ($err)
314 309
 		{
315 310
 			return new xmlrpcresp(0, $xmlrpcerruser, $err);
316
-		}
317
-		else
311
+		} else
318 312
 		{
319 313
 			return new xmlrpcresp($v);
320 314
 		}
@@ -393,8 +387,7 @@  discard block
 block discarded – undo
393 387
 		if ($err)
394 388
 		{
395 389
 			return new xmlrpcresp(0, $xmlrpcerruser, $err);
396
-		}
397
-		else
390
+		} else
398 391
 		{
399 392
 			return new xmlrpcresp(new xmlrpcval("true", $xmlrpcBoolean));
400 393
 		}
@@ -408,15 +401,15 @@  discard block
 block discarded – undo
408 401
 		if (function_exists('getallheaders'))
409 402
 		{
410 403
 			return new xmlrpcresp(php_xmlrpc_encode(getallheaders()));
411
-		}
412
-		else
404
+		} else
413 405
 		{
414 406
 			$headers = array();
415 407
 			// IIS: poor man's version of getallheaders
416
-			foreach ($_SERVER as $key => $val)
417
-				if (strpos($key, 'HTTP_') === 0)
408
+			foreach ($_SERVER as $key => $val) {
409
+							if (strpos($key, 'HTTP_') === 0)
418 410
 				{
419 411
 					$key = ucfirst(str_replace('_', '-', strtolower(substr($key, 5))));
412
+			}
420 413
 					$headers[$key] = $val;
421 414
 				}
422 415
 			return new xmlrpcresp(php_xmlrpc_encode($headers));
@@ -825,17 +818,21 @@  discard block
 block discarded – undo
825 818
 		)
826 819
 	);
827 820
 
828
-	if ($findstate2_sig)
829
-		$a['examples.php.getStateName'] = $findstate2_sig;
821
+	if ($findstate2_sig) {
822
+			$a['examples.php.getStateName'] = $findstate2_sig;
823
+	}
830 824
 
831
-	if ($findstate3_sig)
832
-		$a['examples.php2.getStateName'] = $findstate3_sig;
825
+	if ($findstate3_sig) {
826
+			$a['examples.php2.getStateName'] = $findstate3_sig;
827
+	}
833 828
 
834
-	if ($findstate4_sig)
835
-		$a['examples.php3.getStateName'] = $findstate4_sig;
829
+	if ($findstate4_sig) {
830
+			$a['examples.php3.getStateName'] = $findstate4_sig;
831
+	}
836 832
 
837
-    if ($findstate5_sig)
838
-        $a['examples.php4.getStateName'] = $findstate5_sig;
833
+    if ($findstate5_sig) {
834
+            $a['examples.php4.getStateName'] = $findstate5_sig;
835
+    }
839 836
 
840 837
 	$s=new xmlrpc_server($a, false);
841 838
 	$s->setdebug(3);
@@ -843,10 +840,12 @@  discard block
 block discarded – undo
843 840
 
844 841
 	// out-of-band information: let the client manipulate the server operations.
845 842
 	// we do this to help the testsuite script: do not reproduce in production!
846
-	if (isset($_GET['RESPONSE_ENCODING']))
847
-		$s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
848
-	if (isset($_GET['EXCEPTION_HANDLING']))
849
-		$s->exception_handling = $_GET['EXCEPTION_HANDLING'];
843
+	if (isset($_GET['RESPONSE_ENCODING'])) {
844
+			$s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
845
+	}
846
+	if (isset($_GET['EXCEPTION_HANDLING'])) {
847
+			$s->exception_handling = $_GET['EXCEPTION_HANDLING'];
848
+	}
850 849
 	$s->service();
851 850
 	// that should do all we need!
852 851
 ?>
853 852
\ No newline at end of file
Please login to merge, or discard this patch.