Completed
Push — php51 ( 617621...a4e868 )
by Gaetano
16:05 queued 06:04
created
lib/xmlrpcs.inc 4 patches
Braces   +58 added lines, -89 removed lines patch added patch discarded remove patch
@@ -106,16 +106,14 @@  discard block
 block discarded – undo
106 106
 		{
107 107
 			$methName=$m->getParam(0);
108 108
 			$methName=$methName->scalarval();
109
-		}
110
-		else
109
+		} else
111 110
 		{
112 111
 			$methName=$m;
113 112
 		}
114 113
 		if(strpos($methName, "system.") === 0)
115 114
 		{
116 115
 			$dmap=$GLOBALS['_xmlrpcs_dmap']; $sysCall=1;
117
-		}
118
-		else
116
+		} else
119 117
 		{
120 118
 			$dmap=$server->dmap; $sysCall=0;
121 119
 		}
@@ -134,15 +132,13 @@  discard block
 block discarded – undo
134 132
 					$sigs[]=new xmlrpcval($cursig, 'array');
135 133
 				}
136 134
 				$r=new xmlrpcresp(new xmlrpcval($sigs, 'array'));
137
-			}
138
-			else
135
+			} else
139 136
 			{
140 137
 				// NB: according to the official docs, we should be returning a
141 138
 				// "none-array" here, which means not-an-array
142 139
 				$r=new xmlrpcresp(new xmlrpcval('undef', 'string'));
143 140
 			}
144
-		}
145
-		else
141
+		} else
146 142
 		{
147 143
 			$r=new xmlrpcresp(0,$GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
148 144
 		}
@@ -159,16 +155,14 @@  discard block
 block discarded – undo
159 155
 		{
160 156
 			$methName=$m->getParam(0);
161 157
 			$methName=$methName->scalarval();
162
-		}
163
-		else
158
+		} else
164 159
 		{
165 160
 			$methName=$m;
166 161
 		}
167 162
 		if(strpos($methName, "system.") === 0)
168 163
 		{
169 164
 			$dmap=$GLOBALS['_xmlrpcs_dmap']; $sysCall=1;
170
-		}
171
-		else
165
+		} else
172 166
 		{
173 167
 			$dmap=$server->dmap; $sysCall=0;
174 168
 		}
@@ -177,13 +171,11 @@  discard block
 block discarded – undo
177 171
 			if(isset($dmap[$methName]['docstring']))
178 172
 			{
179 173
 				$r=new xmlrpcresp(new xmlrpcval($dmap[$methName]['docstring']), 'string');
180
-			}
181
-			else
174
+			} else
182 175
 			{
183 176
 				$r=new xmlrpcresp(new xmlrpcval('', 'string'));
184 177
 			}
185
-		}
186
-		else
178
+		} else
187 179
 		{
188 180
 			$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
189 181
 		}
@@ -295,8 +287,9 @@  discard block
 block discarded – undo
295 287
 		// base64 or datetime values, but they will be listed as strings here...
296 288
 		$numParams = count($call['params']);
297 289
 		$pt = array();
298
-		foreach($call['params'] as $val)
299
-			$pt[] = php_2_xmlrpc_type(gettype($val));
290
+		foreach($call['params'] as $val) {
291
+					$pt[] = php_2_xmlrpc_type(gettype($val));
292
+		}
300 293
 
301 294
 		$result = $server->execute($call['methodName'], $call['params'], $pt);
302 295
 
@@ -321,8 +314,7 @@  discard block
 block discarded – undo
321 314
 				$call = $calls->arraymem($i);
322 315
 				$result[$i] = _xmlrpcs_multicall_do_call($server, $call);
323 316
 			}
324
-		}
325
-		else
317
+		} else
326 318
 		{
327 319
 			$numCalls=count($m);
328 320
 			for($i = 0; $i < $numCalls; $i++)
@@ -377,8 +369,9 @@  discard block
 block discarded – undo
377 369
 	function _xmlrpcs_errorHandler($errcode, $errstring, $filename=null, $lineno=null, $context=null)
378 370
 	{
379 371
 		// obey the @ protocol
380
-		if (error_reporting() == 0)
381
-			return;
372
+		if (error_reporting() == 0) {
373
+					return;
374
+		}
382 375
 
383 376
 		//if($errcode != E_NOTICE && $errcode != E_WARNING && $errcode != E_USER_NOTICE && $errcode != E_USER_WARNING)
384 377
 		if($errcode != E_STRICT)
@@ -395,8 +388,7 @@  discard block
 block discarded – undo
395 388
 			{
396 389
 				error_log($errstring);
397 390
 			}
398
-		}
399
-		else
391
+		} else
400 392
 		{
401 393
 			// Pass control on to previous error handler, trying to avoid loops...
402 394
 			if($GLOBALS['_xmlrpcs_prev_ehandler'] != '_xmlrpcs_errorHandler')
@@ -406,8 +398,7 @@  discard block
 block discarded – undo
406 398
 				{
407 399
 					// the following works both with static class methods and plain object methods as error handler
408 400
 					call_user_func_array($GLOBALS['_xmlrpcs_prev_ehandler'], array($errcode, $errstring, $filename, $lineno, $context));
409
-				}
410
-				else
401
+				} else
411 402
 				{
412 403
 					$GLOBALS['_xmlrpcs_prev_ehandler']($errcode, $errstring, $filename, $lineno, $context);
413 404
 				}
@@ -663,8 +654,7 @@  discard block
 block discarded – undo
663 654
 						$payload = gzencode($payload);
664 655
 						header("Content-Encoding: gzip");
665 656
 						header("Vary: Accept-Encoding");
666
-					}
667
-					elseif (strpos($resp_encoding, 'deflate') !== false)
657
+					} elseif (strpos($resp_encoding, 'deflate') !== false)
668 658
 					{
669 659
 						$payload = gzcompress($payload);
670 660
 						header("Content-Encoding: deflate");
@@ -678,8 +668,7 @@  discard block
 block discarded – undo
678 668
 				{
679 669
 					header('Content-Length: ' . (int)strlen($payload));
680 670
 				}
681
-			}
682
-			else
671
+			} else
683 672
 			{
684 673
 				error_log('XML-RPC: '.__METHOD__.': http headers already sent before response is fully generated. Check for php warning or error messages');
685 674
 			}
@@ -728,8 +717,7 @@  discard block
 block discarded – undo
728 717
 			if (is_object($in))
729 718
 			{
730 719
 				$numParams = $in->getNumParams();
731
-			}
732
-			else
720
+			} else
733 721
 			{
734 722
 				$numParams = count($in);
735 723
 			}
@@ -746,13 +734,11 @@  discard block
 block discarded – undo
746 734
 							if($p->kindOf() == 'scalar')
747 735
 							{
748 736
 								$pt=$p->scalartyp();
749
-							}
750
-							else
737
+							} else
751 738
 							{
752 739
 								$pt=$p->kindOf();
753 740
 							}
754
-						}
755
-						else
741
+						} else
756 742
 						{
757 743
 							$pt= $in[$n] == 'i4' ? 'int' : strtolower($in[$n]); // dispatch maps never use i4...
758 744
 						}
@@ -813,8 +799,7 @@  discard block
 block discarded – undo
813 799
 			if(isset($_SERVER['HTTP_CONTENT_ENCODING']))
814 800
 			{
815 801
 				$content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']);
816
-			}
817
-			else
802
+			} else
818 803
 			{
819 804
 				$content_encoding = '';
820 805
 			}
@@ -834,20 +819,18 @@  discard block
 block discarded – undo
834 819
 							{
835 820
 								$this->debugmsg("\n+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
836 821
 							}
837
-						}
838
-						elseif($content_encoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
822
+						} elseif($content_encoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
839 823
 						{
840 824
 							$data = $degzdata;
841
-							if($this->debug > 1)
842
-								$this->debugmsg("+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
843
-						}
844
-						else
825
+							if($this->debug > 1) {
826
+															$this->debugmsg("+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
827
+							}
828
+						} else
845 829
 						{
846 830
 							$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_decompress_fail'], $GLOBALS['xmlrpcstr']['server_decompress_fail']);
847 831
 							return $r;
848 832
 						}
849
-					}
850
-					else
833
+					} else
851 834
 					{
852 835
 						//error_log('The server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
853 836
 						$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_cannot_decompress'], $GLOBALS['xmlrpcstr']['server_cannot_decompress']);
@@ -871,18 +854,19 @@  discard block
 block discarded – undo
871 854
 					$known_charsets = array($GLOBALS['xmlrpc_internalencoding'], 'UTF-8', 'ISO-8859-1', 'US-ASCII');
872 855
 					foreach ($known_charsets as $charset)
873 856
 					{
874
-						foreach ($client_accepted_charsets as $accepted)
875
-							if (strpos($accepted, $charset) === 0)
857
+						foreach ($client_accepted_charsets as $accepted) {
858
+													if (strpos($accepted, $charset) === 0)
876 859
 							{
877
-								$resp_encoding = $charset;
860
+								$resp_encoding = $charset;
861
+						}
878 862
 								break;
879 863
 							}
880
-						if ($resp_encoding)
881
-							break;
864
+						if ($resp_encoding) {
865
+													break;
866
+						}
882 867
 					}
883 868
 				}
884
-			}
885
-			else
869
+			} else
886 870
 			{
887 871
 				$resp_encoding = $this->response_charset_encoding;
888 872
 			}
@@ -890,8 +874,7 @@  discard block
 block discarded – undo
890 874
 			if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
891 875
 			{
892 876
 				$resp_compression = $_SERVER['HTTP_ACCEPT_ENCODING'];
893
-			}
894
-			else
877
+			} else
895 878
 			{
896 879
 				$resp_compression = '';
897 880
 			}
@@ -968,16 +951,16 @@  discard block
 block discarded – undo
968 951
 			if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
969 952
 			{
970 953
 				xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
971
-			}
972
-			else
954
+			} else
973 955
 			{
974 956
 				xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
975 957
 			}
976 958
 
977
-			if ($this->functions_parameters_type != 'xmlrpcvals')
978
-				xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast');
979
-			else
980
-				xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
959
+			if ($this->functions_parameters_type != 'xmlrpcvals') {
960
+							xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast');
961
+			} else {
962
+							xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
963
+			}
981 964
 			xml_set_character_data_handler($parser, 'xmlrpc_cd');
982 965
 			xml_set_default_handler($parser, 'xmlrpc_dh');
983 966
 			if(!xml_parse($parser, $data, 1))
@@ -989,15 +972,13 @@  discard block
 block discarded – undo
989 972
 					xml_error_string(xml_get_error_code($parser)),
990 973
 					xml_get_current_line_number($parser), xml_get_current_column_number($parser)));
991 974
 				xml_parser_free($parser);
992
-			}
993
-			elseif ($GLOBALS['_xh']['isf'])
975
+			} elseif ($GLOBALS['_xh']['isf'])
994 976
 			{
995 977
 				xml_parser_free($parser);
996 978
 				$r=new xmlrpcresp(0,
997 979
 					$GLOBALS['xmlrpcerr']['invalid_request'],
998 980
 					$GLOBALS['xmlrpcstr']['invalid_request'] . ' ' . $GLOBALS['_xh']['isf_reason']);
999
-			}
1000
-			else
981
+			} else
1001 982
 			{
1002 983
 				xml_parser_free($parser);
1003 984
 				// small layering violation in favor of speed and memory usage:
@@ -1011,8 +992,7 @@  discard block
 block discarded – undo
1011 992
 						$this->debugmsg("\n+++PARSED+++\n".var_export($GLOBALS['_xh']['params'], true)."\n+++END+++");
1012 993
 					}
1013 994
 					$r = $this->execute($GLOBALS['_xh']['method'], $GLOBALS['_xh']['params'], $GLOBALS['_xh']['pt']);
1014
-				}
1015
-				else
995
+				} else
1016 996
 				{
1017 997
 					// build an xmlrpcmsg object with data parsed from xml
1018 998
 					$m=new xmlrpcmsg($GLOBALS['_xh']['method']);
@@ -1045,8 +1025,7 @@  discard block
 block discarded – undo
1045 1025
 			if (is_object($m))
1046 1026
 			{
1047 1027
 				$methName = $m->method();
1048
-			}
1049
-			else
1028
+			} else
1050 1029
 			{
1051 1030
 				$methName = $m;
1052 1031
 			}
@@ -1068,8 +1047,7 @@  discard block
 block discarded – undo
1068 1047
 				if (is_object($m))
1069 1048
 				{
1070 1049
 					list($ok, $errstr) = $this->verifySignature($m, $sig);
1071
-				}
1072
-				else
1050
+				} else
1073 1051
 				{
1074 1052
 					list($ok, $errstr) = $this->verifySignature($paramtypes, $sig);
1075 1053
 				}
@@ -1115,8 +1093,7 @@  discard block
 block discarded – undo
1115 1093
 					if($sysCall)
1116 1094
 					{
1117 1095
 						$r = call_user_func($func, $this, $m);
1118
-					}
1119
-					else
1096
+					} else
1120 1097
 					{
1121 1098
 						$r = call_user_func($func, $m);
1122 1099
 					}
@@ -1126,8 +1103,7 @@  discard block
 block discarded – undo
1126 1103
 						if (is_a($r, 'xmlrpcval'))
1127 1104
 						{
1128 1105
 							$r = new xmlrpcresp($r);
1129
-						}
1130
-						else
1106
+						} else
1131 1107
 						{
1132 1108
 							$r = new xmlrpcresp(
1133 1109
 								0,
@@ -1136,16 +1112,14 @@  discard block
 block discarded – undo
1136 1112
 							);
1137 1113
 						}
1138 1114
 					}
1139
-				}
1140
-				else
1115
+				} else
1141 1116
 				{
1142 1117
 					// call a 'plain php' function
1143 1118
 					if($sysCall)
1144 1119
 					{
1145 1120
 						array_unshift($params, $this);
1146 1121
 						$r = call_user_func_array($func, $params);
1147
-					}
1148
-					else
1122
+					} else
1149 1123
 					{
1150 1124
 						// 3rd API convention for method-handling functions: EPI-style
1151 1125
 						if ($this->functions_parameters_type == 'epivals')
@@ -1156,15 +1130,13 @@  discard block
 block discarded – undo
1156 1130
 							if (is_array($r) && array_key_exists('faultCode', $r) && array_key_exists('faultString', $r))
1157 1131
 							{
1158 1132
 								$r = new xmlrpcresp(0, (integer)$r['faultCode'], (string)$r['faultString']);
1159
-							}
1160
-							else
1133
+							} else
1161 1134
 							{
1162 1135
 								// functions using EPI api should NOT return resp objects,
1163 1136
 								// so make sure we encode the return type correctly
1164 1137
 								$r = new xmlrpcresp(php_xmlrpc_encode($r, array('extension_api')));
1165 1138
 							}
1166
-						}
1167
-						else
1139
+						} else
1168 1140
 						{
1169 1141
 							$r = call_user_func_array($func, $params);
1170 1142
 						}
@@ -1177,8 +1149,7 @@  discard block
 block discarded – undo
1177 1149
 						$r = new xmlrpcresp(php_xmlrpc_encode($r, $this->phpvals_encoding_options));
1178 1150
 					}
1179 1151
 				}
1180
-			}
1181
-			catch(Exception $e)
1152
+			} catch(Exception $e)
1182 1153
 			{
1183 1154
 				// (barring errors in the lib) an uncatched exception happened
1184 1155
 				// in the called function, we wrap it in a proper error-response
@@ -1201,8 +1172,7 @@  discard block
 block discarded – undo
1201 1172
 				if($GLOBALS['_xmlrpcs_prev_ehandler'])
1202 1173
 				{
1203 1174
 					set_error_handler($GLOBALS['_xmlrpcs_prev_ehandler']);
1204
-				}
1205
-				else
1175
+				} else
1206 1176
 				{
1207 1177
 					restore_error_handler();
1208 1178
 				}
@@ -1228,8 +1198,7 @@  discard block
 block discarded – undo
1228 1198
 			if ($charset_encoding != '')
1229 1199
 			{
1230 1200
 				return "<?xml version=\"1.0\" encoding=\"$charset_encoding\"?" . ">\n";
1231
-			}
1232
-			else
1201
+			} else
1233 1202
 			{
1234 1203
 				return "<?xml version=\"1.0\"?" . ">\n";
1235 1204
 			}
Please login to merge, or discard this patch.
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -494,8 +494,8 @@  discard block
 block discarded – undo
494 494
 		var $user_data = null;
495 495
 
496 496
 		/**
497
-		* @param array $dispmap the dispatch map with definition of exposed services
498
-		* @param boolean $servicenow set to false to prevent the server from running upon construction
497
+		* @param array $dispMap the dispatch map with definition of exposed services
498
+		* @param boolean $serviceNow set to false to prevent the server from running upon construction
499 499
 		*/
500 500
 		function __construct($dispMap=null, $serviceNow=true)
501 501
 		{
@@ -785,7 +785,8 @@  discard block
 block discarded – undo
785 785
 
786 786
 		/**
787 787
 		* Parse http headers received along with xmlrpc request. If needed, inflate request
788
-		* @return mixed null on success or an xmlrpcresp
788
+		* @param string $data
789
+		* @return xmlrpcresp|null null on success or an xmlrpcresp
789 790
 		* @access private
790 791
 		*/
791 792
 		function parseRequestHeaders(&$data, &$req_encoding, &$resp_encoding, &$resp_compression)
Please login to merge, or discard this patch.
Indentation   +1208 added lines, -1208 removed lines patch added patch discarded remove patch
@@ -34,1215 +34,1215 @@
 block discarded – undo
34 34
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35 35
 // OF THE POSSIBILITY OF SUCH DAMAGE.
36 36
 
37
-	// XML RPC Server class
38
-	// requires: xmlrpc.inc
39
-
40
-	$GLOBALS['xmlrpcs_capabilities'] = array(
41
-		// xmlrpc spec: always supported
42
-		'xmlrpc' => new xmlrpcval(array(
43
-			'specUrl' => new xmlrpcval('http://www.xmlrpc.com/spec', 'string'),
44
-			'specVersion' => new xmlrpcval(1, 'int')
45
-		), 'struct'),
46
-		// if we support system.xxx functions, we always support multicall, too...
47
-		// Note that, as of 2006/09/17, the following URL does not respond anymore
48
-		'system.multicall' => new xmlrpcval(array(
49
-			'specUrl' => new xmlrpcval('http://www.xmlrpc.com/discuss/msgReader$1208', 'string'),
50
-			'specVersion' => new xmlrpcval(1, 'int')
51
-		), 'struct'),
52
-		// introspection: version 2! we support 'mixed', too
53
-		'introspection' => new xmlrpcval(array(
54
-			'specUrl' => new xmlrpcval('http://phpxmlrpc.sourceforge.net/doc-2/ch10.html', 'string'),
55
-			'specVersion' => new xmlrpcval(2, 'int')
56
-		), 'struct')
57
-	);
58
-
59
-	/* Functions that implement system.XXX methods of xmlrpc servers */
60
-	$_xmlrpcs_getCapabilities_sig=array(array($GLOBALS['xmlrpcStruct']));
61
-	$_xmlrpcs_getCapabilities_doc='This method lists all the capabilites that the XML-RPC server has: the (more or less standard) extensions to the xmlrpc spec that it adheres to';
62
-	$_xmlrpcs_getCapabilities_sdoc=array(array('list of capabilities, described as structs with a version number and url for the spec'));
63
-	function _xmlrpcs_getCapabilities($server, $m=null)
64
-	{
65
-		$outAr = $GLOBALS['xmlrpcs_capabilities'];
66
-		// NIL extension
67
-		if ($GLOBALS['xmlrpc_null_extension']) {
68
-			$outAr['nil'] = new xmlrpcval(array(
69
-				'specUrl' => new xmlrpcval('http://www.ontosys.com/xml-rpc/extensions.php', 'string'),
70
-				'specVersion' => new xmlrpcval(1, 'int')
71
-			), 'struct');
72
-		}
73
-		return new xmlrpcresp(new xmlrpcval($outAr, 'struct'));
74
-	}
75
-
76
-	// listMethods: signature was either a string, or nothing.
77
-	// The useless string variant has been removed
78
-	$_xmlrpcs_listMethods_sig=array(array($GLOBALS['xmlrpcArray']));
79
-	$_xmlrpcs_listMethods_doc='This method lists all the methods that the XML-RPC server knows how to dispatch';
80
-	$_xmlrpcs_listMethods_sdoc=array(array('list of method names'));
81
-	function _xmlrpcs_listMethods($server, $m=null) // if called in plain php values mode, second param is missing
82
-	{
83
-
84
-		$outAr=array();
85
-		foreach($server->dmap as $key => $val)
86
-		{
87
-			$outAr[]=new xmlrpcval($key, 'string');
88
-		}
89
-		if($server->allow_system_funcs)
90
-		{
91
-			foreach($GLOBALS['_xmlrpcs_dmap'] as $key => $val)
92
-			{
93
-				$outAr[]=new xmlrpcval($key, 'string');
94
-			}
95
-		}
96
-		return new xmlrpcresp(new xmlrpcval($outAr, 'array'));
97
-	}
98
-
99
-	$_xmlrpcs_methodSignature_sig=array(array($GLOBALS['xmlrpcArray'], $GLOBALS['xmlrpcString']));
100
-	$_xmlrpcs_methodSignature_doc='Returns an array of known signatures (an array of arrays) for the method name passed. If no signatures are known, returns a none-array (test for type != array to detect missing signature)';
101
-	$_xmlrpcs_methodSignature_sdoc=array(array('list of known signatures, each sig being an array of xmlrpc type names', 'name of method to be described'));
102
-	function _xmlrpcs_methodSignature($server, $m)
103
-	{
104
-		// let accept as parameter both an xmlrpcval or string
105
-		if (is_object($m))
106
-		{
107
-			$methName=$m->getParam(0);
108
-			$methName=$methName->scalarval();
109
-		}
110
-		else
111
-		{
112
-			$methName=$m;
113
-		}
114
-		if(strpos($methName, "system.") === 0)
115
-		{
116
-			$dmap=$GLOBALS['_xmlrpcs_dmap']; $sysCall=1;
117
-		}
118
-		else
119
-		{
120
-			$dmap=$server->dmap; $sysCall=0;
121
-		}
122
-		if(isset($dmap[$methName]))
123
-		{
124
-			if(isset($dmap[$methName]['signature']))
125
-			{
126
-				$sigs=array();
127
-				foreach($dmap[$methName]['signature'] as $inSig)
128
-				{
129
-					$cursig=array();
130
-					foreach($inSig as $sig)
131
-					{
132
-						$cursig[]=new xmlrpcval($sig, 'string');
133
-					}
134
-					$sigs[]=new xmlrpcval($cursig, 'array');
135
-				}
136
-				$r=new xmlrpcresp(new xmlrpcval($sigs, 'array'));
137
-			}
138
-			else
139
-			{
140
-				// NB: according to the official docs, we should be returning a
141
-				// "none-array" here, which means not-an-array
142
-				$r=new xmlrpcresp(new xmlrpcval('undef', 'string'));
143
-			}
144
-		}
145
-		else
146
-		{
147
-			$r=new xmlrpcresp(0,$GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
148
-		}
149
-		return $r;
150
-	}
151
-
152
-	$_xmlrpcs_methodHelp_sig=array(array($GLOBALS['xmlrpcString'], $GLOBALS['xmlrpcString']));
153
-	$_xmlrpcs_methodHelp_doc='Returns help text if defined for the method passed, otherwise returns an empty string';
154
-	$_xmlrpcs_methodHelp_sdoc=array(array('method description', 'name of the method to be described'));
155
-	function _xmlrpcs_methodHelp($server, $m)
156
-	{
157
-		// let accept as parameter both an xmlrpcval or string
158
-		if (is_object($m))
159
-		{
160
-			$methName=$m->getParam(0);
161
-			$methName=$methName->scalarval();
162
-		}
163
-		else
164
-		{
165
-			$methName=$m;
166
-		}
167
-		if(strpos($methName, "system.") === 0)
168
-		{
169
-			$dmap=$GLOBALS['_xmlrpcs_dmap']; $sysCall=1;
170
-		}
171
-		else
172
-		{
173
-			$dmap=$server->dmap; $sysCall=0;
174
-		}
175
-		if(isset($dmap[$methName]))
176
-		{
177
-			if(isset($dmap[$methName]['docstring']))
178
-			{
179
-				$r=new xmlrpcresp(new xmlrpcval($dmap[$methName]['docstring']), 'string');
180
-			}
181
-			else
182
-			{
183
-				$r=new xmlrpcresp(new xmlrpcval('', 'string'));
184
-			}
185
-		}
186
-		else
187
-		{
188
-			$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
189
-		}
190
-		return $r;
191
-	}
192
-
193
-	$_xmlrpcs_multicall_sig = array(array($GLOBALS['xmlrpcArray'], $GLOBALS['xmlrpcArray']));
194
-	$_xmlrpcs_multicall_doc = 'Boxcar multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details';
195
-	$_xmlrpcs_multicall_sdoc = array(array('list of response structs, where each struct has the usual members', 'list of calls, with each call being represented as a struct, with members "methodname" and "params"'));
196
-	function _xmlrpcs_multicall_error($err)
197
-	{
198
-		if(is_string($err))
199
-		{
200
-			$str = $GLOBALS['xmlrpcstr']["multicall_${err}"];
201
-			$code = $GLOBALS['xmlrpcerr']["multicall_${err}"];
202
-		}
203
-		else
204
-		{
205
-			$code = $err->faultCode();
206
-			$str = $err->faultString();
207
-		}
208
-		$struct = array();
209
-		$struct['faultCode'] = new xmlrpcval($code, 'int');
210
-		$struct['faultString'] = new xmlrpcval($str, 'string');
211
-		return new xmlrpcval($struct, 'struct');
212
-	}
213
-
214
-	function _xmlrpcs_multicall_do_call($server, $call)
215
-	{
216
-		if($call->kindOf() != 'struct')
217
-		{
218
-			return _xmlrpcs_multicall_error('notstruct');
219
-		}
220
-		$methName = @$call->structmem('methodName');
221
-		if(!$methName)
222
-		{
223
-			return _xmlrpcs_multicall_error('nomethod');
224
-		}
225
-		if($methName->kindOf() != 'scalar' || $methName->scalartyp() != 'string')
226
-		{
227
-			return _xmlrpcs_multicall_error('notstring');
228
-		}
229
-		if($methName->scalarval() == 'system.multicall')
230
-		{
231
-			return _xmlrpcs_multicall_error('recursion');
232
-		}
233
-
234
-		$params = @$call->structmem('params');
235
-		if(!$params)
236
-		{
237
-			return _xmlrpcs_multicall_error('noparams');
238
-		}
239
-		if($params->kindOf() != 'array')
240
-		{
241
-			return _xmlrpcs_multicall_error('notarray');
242
-		}
243
-		$numParams = $params->arraysize();
244
-
245
-		$msg = new xmlrpcmsg($methName->scalarval());
246
-		for($i = 0; $i < $numParams; $i++)
247
-		{
248
-			if(!$msg->addParam($params->arraymem($i)))
249
-			{
250
-				$i++;
251
-				return _xmlrpcs_multicall_error(new xmlrpcresp(0,
252
-					$GLOBALS['xmlrpcerr']['incorrect_params'],
253
-					$GLOBALS['xmlrpcstr']['incorrect_params'] . ": probable xml error in param " . $i));
254
-			}
255
-		}
256
-
257
-		$result = $server->execute($msg);
258
-
259
-		if($result->faultCode() != 0)
260
-		{
261
-			return _xmlrpcs_multicall_error($result);		// Method returned fault.
262
-		}
263
-
264
-		return new xmlrpcval(array($result->value()), 'array');
265
-	}
266
-
267
-	function _xmlrpcs_multicall_do_call_phpvals($server, $call)
268
-	{
269
-		if(!is_array($call))
270
-		{
271
-			return _xmlrpcs_multicall_error('notstruct');
272
-		}
273
-		if(!array_key_exists('methodName', $call))
274
-		{
275
-			return _xmlrpcs_multicall_error('nomethod');
276
-		}
277
-		if (!is_string($call['methodName']))
278
-		{
279
-			return _xmlrpcs_multicall_error('notstring');
280
-		}
281
-		if($call['methodName'] == 'system.multicall')
282
-		{
283
-			return _xmlrpcs_multicall_error('recursion');
284
-		}
285
-		if(!array_key_exists('params', $call))
286
-		{
287
-			return _xmlrpcs_multicall_error('noparams');
288
-		}
289
-		if(!is_array($call['params']))
290
-		{
291
-			return _xmlrpcs_multicall_error('notarray');
292
-		}
293
-
294
-		// this is a real dirty and simplistic hack, since we might have received a
295
-		// base64 or datetime values, but they will be listed as strings here...
296
-		$numParams = count($call['params']);
297
-		$pt = array();
298
-		foreach($call['params'] as $val)
299
-			$pt[] = php_2_xmlrpc_type(gettype($val));
300
-
301
-		$result = $server->execute($call['methodName'], $call['params'], $pt);
302
-
303
-		if($result->faultCode() != 0)
304
-		{
305
-			return _xmlrpcs_multicall_error($result);		// Method returned fault.
306
-		}
307
-
308
-		return new xmlrpcval(array($result->value()), 'array');
309
-	}
310
-
311
-	function _xmlrpcs_multicall($server, $m)
312
-	{
313
-		$result = array();
314
-		// let accept a plain list of php parameters, beside a single xmlrpc msg object
315
-		if (is_object($m))
316
-		{
317
-			$calls = $m->getParam(0);
318
-			$numCalls = $calls->arraysize();
319
-			for($i = 0; $i < $numCalls; $i++)
320
-			{
321
-				$call = $calls->arraymem($i);
322
-				$result[$i] = _xmlrpcs_multicall_do_call($server, $call);
323
-			}
324
-		}
325
-		else
326
-		{
327
-			$numCalls=count($m);
328
-			for($i = 0; $i < $numCalls; $i++)
329
-			{
330
-				$result[$i] = _xmlrpcs_multicall_do_call_phpvals($server, $m[$i]);
331
-			}
332
-		}
333
-
334
-		return new xmlrpcresp(new xmlrpcval($result, 'array'));
335
-	}
336
-
337
-	$GLOBALS['_xmlrpcs_dmap']=array(
338
-		'system.listMethods' => array(
339
-			'function' => '_xmlrpcs_listMethods',
340
-			'signature' => $_xmlrpcs_listMethods_sig,
341
-			'docstring' => $_xmlrpcs_listMethods_doc,
342
-			'signature_docs' => $_xmlrpcs_listMethods_sdoc),
343
-		'system.methodHelp' => array(
344
-			'function' => '_xmlrpcs_methodHelp',
345
-			'signature' => $_xmlrpcs_methodHelp_sig,
346
-			'docstring' => $_xmlrpcs_methodHelp_doc,
347
-			'signature_docs' => $_xmlrpcs_methodHelp_sdoc),
348
-		'system.methodSignature' => array(
349
-			'function' => '_xmlrpcs_methodSignature',
350
-			'signature' => $_xmlrpcs_methodSignature_sig,
351
-			'docstring' => $_xmlrpcs_methodSignature_doc,
352
-			'signature_docs' => $_xmlrpcs_methodSignature_sdoc),
353
-		'system.multicall' => array(
354
-			'function' => '_xmlrpcs_multicall',
355
-			'signature' => $_xmlrpcs_multicall_sig,
356
-			'docstring' => $_xmlrpcs_multicall_doc,
357
-			'signature_docs' => $_xmlrpcs_multicall_sdoc),
358
-		'system.getCapabilities' => array(
359
-			'function' => '_xmlrpcs_getCapabilities',
360
-			'signature' => $_xmlrpcs_getCapabilities_sig,
361
-			'docstring' => $_xmlrpcs_getCapabilities_doc,
362
-			'signature_docs' => $_xmlrpcs_getCapabilities_sdoc)
363
-	);
364
-
365
-	$GLOBALS['_xmlrpcs_occurred_errors'] = '';
366
-	$GLOBALS['_xmlrpcs_prev_ehandler'] = '';
367
-
368
-	/**
369
-	* Error handler used to track errors that occur during server-side execution of PHP code.
370
-	* This allows to report back to the client whether an internal error has occurred or not
371
-	* using an xmlrpc response object, instead of letting the client deal with the html junk
372
-	* that a PHP execution error on the server generally entails.
373
-	*
374
-	* NB: in fact a user defined error handler can only handle WARNING, NOTICE and USER_* errors.
375
-	*
376
-	*/
377
-	function _xmlrpcs_errorHandler($errcode, $errstring, $filename=null, $lineno=null, $context=null)
378
-	{
379
-		// obey the @ protocol
380
-		if (error_reporting() == 0)
381
-			return;
382
-
383
-		//if($errcode != E_NOTICE && $errcode != E_WARNING && $errcode != E_USER_NOTICE && $errcode != E_USER_WARNING)
384
-		if($errcode != E_STRICT)
385
-		{
386
-			$GLOBALS['_xmlrpcs_occurred_errors'] = $GLOBALS['_xmlrpcs_occurred_errors'] . $errstring . "\n";
387
-		}
388
-		// Try to avoid as much as possible disruption to the previous error handling
389
-		// mechanism in place
390
-		if($GLOBALS['_xmlrpcs_prev_ehandler'] == '')
391
-		{
392
-			// The previous error handler was the default: all we should do is log error
393
-			// to the default error log (if level high enough)
394
-			if(ini_get('log_errors') && (intval(ini_get('error_reporting')) & $errcode))
395
-			{
396
-				error_log($errstring);
397
-			}
398
-		}
399
-		else
400
-		{
401
-			// Pass control on to previous error handler, trying to avoid loops...
402
-			if($GLOBALS['_xmlrpcs_prev_ehandler'] != '_xmlrpcs_errorHandler')
403
-			{
404
-				// NB: this code will NOT work on php < 4.0.2: only 2 params were used for error handlers
405
-				if(is_array($GLOBALS['_xmlrpcs_prev_ehandler']))
406
-				{
407
-					// the following works both with static class methods and plain object methods as error handler
408
-					call_user_func_array($GLOBALS['_xmlrpcs_prev_ehandler'], array($errcode, $errstring, $filename, $lineno, $context));
409
-				}
410
-				else
411
-				{
412
-					$GLOBALS['_xmlrpcs_prev_ehandler']($errcode, $errstring, $filename, $lineno, $context);
413
-				}
414
-			}
415
-		}
416
-	}
417
-
418
-	$GLOBALS['_xmlrpc_debuginfo']='';
419
-
420
-	/**
421
-	* Add a string to the debug info that can be later seralized by the server
422
-	* as part of the response message.
423
-	* Note that for best compatibility, the debug string should be encoded using
424
-	* the $GLOBALS['xmlrpc_internalencoding'] character set.
425
-	* @param string $m
426
-	* @access public
427
-	*/
428
-	function xmlrpc_debugmsg($m)
429
-	{
430
-		$GLOBALS['_xmlrpc_debuginfo'] .= $m . "\n";
431
-	}
432
-
433
-	class xmlrpc_server
434
-	{
435
-		/**
436
-		* Array defining php functions exposed as xmlrpc methods by this server
437
-		* @access private
438
-		*/
439
-		var $dmap=array();
440
-		/**
441
-		* Defines how functions in dmap will be invoked: either using an xmlrpc msg object
442
-		* or plain php values.
443
-		* valid strings are 'xmlrpcvals', 'phpvals' or 'epivals'
444
-		*/
445
-		var $functions_parameters_type='xmlrpcvals';
446
-		/**
447
-		* Option used for fine-tuning the encoding the php values returned from
448
-		* functions registered in the dispatch map when the functions_parameters_types
449
-		* member is set to 'phpvals'
450
-		* @see php_xmlrpc_encode for a list of values
451
-		*/
452
-		var $phpvals_encoding_options = array( 'auto_dates' );
453
-		/// controls whether the server is going to echo debugging messages back to the client as comments in response body. valid values: 0,1,2,3
454
-		var $debug = 1;
455
-		/**
456
-		* Controls behaviour of server when invoked user function throws an exception:
457
-		* 0 = catch it and return an 'internal error' xmlrpc response (default)
458
-		* 1 = catch it and return an xmlrpc response with the error corresponding to the exception
459
-		* 2 = allow the exception to float to the upper layers
460
-		*/
461
-		var $exception_handling = 0;
462
-		/**
463
-		* When set to true, it will enable HTTP compression of the response, in case
464
-		* the client has declared its support for compression in the request.
465
-		*/
466
-		var $compress_response = false;
467
-		/**
468
-		* List of http compression methods accepted by the server for requests.
469
-		* NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib
470
-		*/
471
-		var $accepted_compression = array();
472
-		/// shall we serve calls to system.* methods?
473
-		var $allow_system_funcs = true;
474
-		/// list of charset encodings natively accepted for requests
475
-		var $accepted_charset_encodings = array();
476
-		/**
477
-		* charset encoding to be used for response.
478
-		* NB: if we can, we will convert the generated response from internal_encoding to the intended one.
479
-		* can be: a supported xml encoding (only UTF-8 and ISO-8859-1 at present, unless mbstring is enabled),
480
-		* null (leave unspecified in response, convert output stream to US_ASCII),
481
-		* 'default' (use xmlrpc library default as specified in xmlrpc.inc, convert output stream if needed),
482
-		* or 'auto' (use client-specified charset encoding or same as request if request headers do not specify it (unless request is US-ASCII: then use library default anyway).
483
-		* NB: pretty dangerous if you accept every charset and do not have mbstring enabled)
484
-		*/
485
-		var $response_charset_encoding = '';
486
-		/**
487
-		* Storage for internal debug info
488
-		* @access private
489
-		*/
490
-		var $debug_info = '';
491
-		/**
492
-		* Extra data passed at runtime to method handling functions. Used only by EPI layer
493
-		*/
494
-		var $user_data = null;
495
-
496
-		/**
497
-		* @param array $dispmap the dispatch map with definition of exposed services
498
-		* @param boolean $servicenow set to false to prevent the server from running upon construction
499
-		*/
500
-		function __construct($dispMap=null, $serviceNow=true)
501
-		{
502
-			// if ZLIB is enabled, let the server by default accept compressed requests,
503
-			// and compress responses sent to clients that support them
504
-			if(function_exists('gzinflate'))
505
-			{
506
-				$this->accepted_compression = array('gzip', 'deflate');
507
-				$this->compress_response = true;
508
-			}
509
-
510
-			// by default the xml parser can support these 3 charset encodings
511
-			$this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
512
-
513
-			// dispMap is a dispatch array of methods
514
-			// mapped to function names and signatures
515
-			// if a method
516
-			// doesn't appear in the map then an unknown
517
-			// method error is generated
518
-			/* milosch - changed to make passing dispMap optional.
37
+    // XML RPC Server class
38
+    // requires: xmlrpc.inc
39
+
40
+    $GLOBALS['xmlrpcs_capabilities'] = array(
41
+        // xmlrpc spec: always supported
42
+        'xmlrpc' => new xmlrpcval(array(
43
+            'specUrl' => new xmlrpcval('http://www.xmlrpc.com/spec', 'string'),
44
+            'specVersion' => new xmlrpcval(1, 'int')
45
+        ), 'struct'),
46
+        // if we support system.xxx functions, we always support multicall, too...
47
+        // Note that, as of 2006/09/17, the following URL does not respond anymore
48
+        'system.multicall' => new xmlrpcval(array(
49
+            'specUrl' => new xmlrpcval('http://www.xmlrpc.com/discuss/msgReader$1208', 'string'),
50
+            'specVersion' => new xmlrpcval(1, 'int')
51
+        ), 'struct'),
52
+        // introspection: version 2! we support 'mixed', too
53
+        'introspection' => new xmlrpcval(array(
54
+            'specUrl' => new xmlrpcval('http://phpxmlrpc.sourceforge.net/doc-2/ch10.html', 'string'),
55
+            'specVersion' => new xmlrpcval(2, 'int')
56
+        ), 'struct')
57
+    );
58
+
59
+    /* Functions that implement system.XXX methods of xmlrpc servers */
60
+    $_xmlrpcs_getCapabilities_sig=array(array($GLOBALS['xmlrpcStruct']));
61
+    $_xmlrpcs_getCapabilities_doc='This method lists all the capabilites that the XML-RPC server has: the (more or less standard) extensions to the xmlrpc spec that it adheres to';
62
+    $_xmlrpcs_getCapabilities_sdoc=array(array('list of capabilities, described as structs with a version number and url for the spec'));
63
+    function _xmlrpcs_getCapabilities($server, $m=null)
64
+    {
65
+        $outAr = $GLOBALS['xmlrpcs_capabilities'];
66
+        // NIL extension
67
+        if ($GLOBALS['xmlrpc_null_extension']) {
68
+            $outAr['nil'] = new xmlrpcval(array(
69
+                'specUrl' => new xmlrpcval('http://www.ontosys.com/xml-rpc/extensions.php', 'string'),
70
+                'specVersion' => new xmlrpcval(1, 'int')
71
+            ), 'struct');
72
+        }
73
+        return new xmlrpcresp(new xmlrpcval($outAr, 'struct'));
74
+    }
75
+
76
+    // listMethods: signature was either a string, or nothing.
77
+    // The useless string variant has been removed
78
+    $_xmlrpcs_listMethods_sig=array(array($GLOBALS['xmlrpcArray']));
79
+    $_xmlrpcs_listMethods_doc='This method lists all the methods that the XML-RPC server knows how to dispatch';
80
+    $_xmlrpcs_listMethods_sdoc=array(array('list of method names'));
81
+    function _xmlrpcs_listMethods($server, $m=null) // if called in plain php values mode, second param is missing
82
+    {
83
+
84
+        $outAr=array();
85
+        foreach($server->dmap as $key => $val)
86
+        {
87
+            $outAr[]=new xmlrpcval($key, 'string');
88
+        }
89
+        if($server->allow_system_funcs)
90
+        {
91
+            foreach($GLOBALS['_xmlrpcs_dmap'] as $key => $val)
92
+            {
93
+                $outAr[]=new xmlrpcval($key, 'string');
94
+            }
95
+        }
96
+        return new xmlrpcresp(new xmlrpcval($outAr, 'array'));
97
+    }
98
+
99
+    $_xmlrpcs_methodSignature_sig=array(array($GLOBALS['xmlrpcArray'], $GLOBALS['xmlrpcString']));
100
+    $_xmlrpcs_methodSignature_doc='Returns an array of known signatures (an array of arrays) for the method name passed. If no signatures are known, returns a none-array (test for type != array to detect missing signature)';
101
+    $_xmlrpcs_methodSignature_sdoc=array(array('list of known signatures, each sig being an array of xmlrpc type names', 'name of method to be described'));
102
+    function _xmlrpcs_methodSignature($server, $m)
103
+    {
104
+        // let accept as parameter both an xmlrpcval or string
105
+        if (is_object($m))
106
+        {
107
+            $methName=$m->getParam(0);
108
+            $methName=$methName->scalarval();
109
+        }
110
+        else
111
+        {
112
+            $methName=$m;
113
+        }
114
+        if(strpos($methName, "system.") === 0)
115
+        {
116
+            $dmap=$GLOBALS['_xmlrpcs_dmap']; $sysCall=1;
117
+        }
118
+        else
119
+        {
120
+            $dmap=$server->dmap; $sysCall=0;
121
+        }
122
+        if(isset($dmap[$methName]))
123
+        {
124
+            if(isset($dmap[$methName]['signature']))
125
+            {
126
+                $sigs=array();
127
+                foreach($dmap[$methName]['signature'] as $inSig)
128
+                {
129
+                    $cursig=array();
130
+                    foreach($inSig as $sig)
131
+                    {
132
+                        $cursig[]=new xmlrpcval($sig, 'string');
133
+                    }
134
+                    $sigs[]=new xmlrpcval($cursig, 'array');
135
+                }
136
+                $r=new xmlrpcresp(new xmlrpcval($sigs, 'array'));
137
+            }
138
+            else
139
+            {
140
+                // NB: according to the official docs, we should be returning a
141
+                // "none-array" here, which means not-an-array
142
+                $r=new xmlrpcresp(new xmlrpcval('undef', 'string'));
143
+            }
144
+        }
145
+        else
146
+        {
147
+            $r=new xmlrpcresp(0,$GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
148
+        }
149
+        return $r;
150
+    }
151
+
152
+    $_xmlrpcs_methodHelp_sig=array(array($GLOBALS['xmlrpcString'], $GLOBALS['xmlrpcString']));
153
+    $_xmlrpcs_methodHelp_doc='Returns help text if defined for the method passed, otherwise returns an empty string';
154
+    $_xmlrpcs_methodHelp_sdoc=array(array('method description', 'name of the method to be described'));
155
+    function _xmlrpcs_methodHelp($server, $m)
156
+    {
157
+        // let accept as parameter both an xmlrpcval or string
158
+        if (is_object($m))
159
+        {
160
+            $methName=$m->getParam(0);
161
+            $methName=$methName->scalarval();
162
+        }
163
+        else
164
+        {
165
+            $methName=$m;
166
+        }
167
+        if(strpos($methName, "system.") === 0)
168
+        {
169
+            $dmap=$GLOBALS['_xmlrpcs_dmap']; $sysCall=1;
170
+        }
171
+        else
172
+        {
173
+            $dmap=$server->dmap; $sysCall=0;
174
+        }
175
+        if(isset($dmap[$methName]))
176
+        {
177
+            if(isset($dmap[$methName]['docstring']))
178
+            {
179
+                $r=new xmlrpcresp(new xmlrpcval($dmap[$methName]['docstring']), 'string');
180
+            }
181
+            else
182
+            {
183
+                $r=new xmlrpcresp(new xmlrpcval('', 'string'));
184
+            }
185
+        }
186
+        else
187
+        {
188
+            $r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
189
+        }
190
+        return $r;
191
+    }
192
+
193
+    $_xmlrpcs_multicall_sig = array(array($GLOBALS['xmlrpcArray'], $GLOBALS['xmlrpcArray']));
194
+    $_xmlrpcs_multicall_doc = 'Boxcar multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details';
195
+    $_xmlrpcs_multicall_sdoc = array(array('list of response structs, where each struct has the usual members', 'list of calls, with each call being represented as a struct, with members "methodname" and "params"'));
196
+    function _xmlrpcs_multicall_error($err)
197
+    {
198
+        if(is_string($err))
199
+        {
200
+            $str = $GLOBALS['xmlrpcstr']["multicall_${err}"];
201
+            $code = $GLOBALS['xmlrpcerr']["multicall_${err}"];
202
+        }
203
+        else
204
+        {
205
+            $code = $err->faultCode();
206
+            $str = $err->faultString();
207
+        }
208
+        $struct = array();
209
+        $struct['faultCode'] = new xmlrpcval($code, 'int');
210
+        $struct['faultString'] = new xmlrpcval($str, 'string');
211
+        return new xmlrpcval($struct, 'struct');
212
+    }
213
+
214
+    function _xmlrpcs_multicall_do_call($server, $call)
215
+    {
216
+        if($call->kindOf() != 'struct')
217
+        {
218
+            return _xmlrpcs_multicall_error('notstruct');
219
+        }
220
+        $methName = @$call->structmem('methodName');
221
+        if(!$methName)
222
+        {
223
+            return _xmlrpcs_multicall_error('nomethod');
224
+        }
225
+        if($methName->kindOf() != 'scalar' || $methName->scalartyp() != 'string')
226
+        {
227
+            return _xmlrpcs_multicall_error('notstring');
228
+        }
229
+        if($methName->scalarval() == 'system.multicall')
230
+        {
231
+            return _xmlrpcs_multicall_error('recursion');
232
+        }
233
+
234
+        $params = @$call->structmem('params');
235
+        if(!$params)
236
+        {
237
+            return _xmlrpcs_multicall_error('noparams');
238
+        }
239
+        if($params->kindOf() != 'array')
240
+        {
241
+            return _xmlrpcs_multicall_error('notarray');
242
+        }
243
+        $numParams = $params->arraysize();
244
+
245
+        $msg = new xmlrpcmsg($methName->scalarval());
246
+        for($i = 0; $i < $numParams; $i++)
247
+        {
248
+            if(!$msg->addParam($params->arraymem($i)))
249
+            {
250
+                $i++;
251
+                return _xmlrpcs_multicall_error(new xmlrpcresp(0,
252
+                    $GLOBALS['xmlrpcerr']['incorrect_params'],
253
+                    $GLOBALS['xmlrpcstr']['incorrect_params'] . ": probable xml error in param " . $i));
254
+            }
255
+        }
256
+
257
+        $result = $server->execute($msg);
258
+
259
+        if($result->faultCode() != 0)
260
+        {
261
+            return _xmlrpcs_multicall_error($result);		// Method returned fault.
262
+        }
263
+
264
+        return new xmlrpcval(array($result->value()), 'array');
265
+    }
266
+
267
+    function _xmlrpcs_multicall_do_call_phpvals($server, $call)
268
+    {
269
+        if(!is_array($call))
270
+        {
271
+            return _xmlrpcs_multicall_error('notstruct');
272
+        }
273
+        if(!array_key_exists('methodName', $call))
274
+        {
275
+            return _xmlrpcs_multicall_error('nomethod');
276
+        }
277
+        if (!is_string($call['methodName']))
278
+        {
279
+            return _xmlrpcs_multicall_error('notstring');
280
+        }
281
+        if($call['methodName'] == 'system.multicall')
282
+        {
283
+            return _xmlrpcs_multicall_error('recursion');
284
+        }
285
+        if(!array_key_exists('params', $call))
286
+        {
287
+            return _xmlrpcs_multicall_error('noparams');
288
+        }
289
+        if(!is_array($call['params']))
290
+        {
291
+            return _xmlrpcs_multicall_error('notarray');
292
+        }
293
+
294
+        // this is a real dirty and simplistic hack, since we might have received a
295
+        // base64 or datetime values, but they will be listed as strings here...
296
+        $numParams = count($call['params']);
297
+        $pt = array();
298
+        foreach($call['params'] as $val)
299
+            $pt[] = php_2_xmlrpc_type(gettype($val));
300
+
301
+        $result = $server->execute($call['methodName'], $call['params'], $pt);
302
+
303
+        if($result->faultCode() != 0)
304
+        {
305
+            return _xmlrpcs_multicall_error($result);		// Method returned fault.
306
+        }
307
+
308
+        return new xmlrpcval(array($result->value()), 'array');
309
+    }
310
+
311
+    function _xmlrpcs_multicall($server, $m)
312
+    {
313
+        $result = array();
314
+        // let accept a plain list of php parameters, beside a single xmlrpc msg object
315
+        if (is_object($m))
316
+        {
317
+            $calls = $m->getParam(0);
318
+            $numCalls = $calls->arraysize();
319
+            for($i = 0; $i < $numCalls; $i++)
320
+            {
321
+                $call = $calls->arraymem($i);
322
+                $result[$i] = _xmlrpcs_multicall_do_call($server, $call);
323
+            }
324
+        }
325
+        else
326
+        {
327
+            $numCalls=count($m);
328
+            for($i = 0; $i < $numCalls; $i++)
329
+            {
330
+                $result[$i] = _xmlrpcs_multicall_do_call_phpvals($server, $m[$i]);
331
+            }
332
+        }
333
+
334
+        return new xmlrpcresp(new xmlrpcval($result, 'array'));
335
+    }
336
+
337
+    $GLOBALS['_xmlrpcs_dmap']=array(
338
+        'system.listMethods' => array(
339
+            'function' => '_xmlrpcs_listMethods',
340
+            'signature' => $_xmlrpcs_listMethods_sig,
341
+            'docstring' => $_xmlrpcs_listMethods_doc,
342
+            'signature_docs' => $_xmlrpcs_listMethods_sdoc),
343
+        'system.methodHelp' => array(
344
+            'function' => '_xmlrpcs_methodHelp',
345
+            'signature' => $_xmlrpcs_methodHelp_sig,
346
+            'docstring' => $_xmlrpcs_methodHelp_doc,
347
+            'signature_docs' => $_xmlrpcs_methodHelp_sdoc),
348
+        'system.methodSignature' => array(
349
+            'function' => '_xmlrpcs_methodSignature',
350
+            'signature' => $_xmlrpcs_methodSignature_sig,
351
+            'docstring' => $_xmlrpcs_methodSignature_doc,
352
+            'signature_docs' => $_xmlrpcs_methodSignature_sdoc),
353
+        'system.multicall' => array(
354
+            'function' => '_xmlrpcs_multicall',
355
+            'signature' => $_xmlrpcs_multicall_sig,
356
+            'docstring' => $_xmlrpcs_multicall_doc,
357
+            'signature_docs' => $_xmlrpcs_multicall_sdoc),
358
+        'system.getCapabilities' => array(
359
+            'function' => '_xmlrpcs_getCapabilities',
360
+            'signature' => $_xmlrpcs_getCapabilities_sig,
361
+            'docstring' => $_xmlrpcs_getCapabilities_doc,
362
+            'signature_docs' => $_xmlrpcs_getCapabilities_sdoc)
363
+    );
364
+
365
+    $GLOBALS['_xmlrpcs_occurred_errors'] = '';
366
+    $GLOBALS['_xmlrpcs_prev_ehandler'] = '';
367
+
368
+    /**
369
+     * Error handler used to track errors that occur during server-side execution of PHP code.
370
+     * This allows to report back to the client whether an internal error has occurred or not
371
+     * using an xmlrpc response object, instead of letting the client deal with the html junk
372
+     * that a PHP execution error on the server generally entails.
373
+     *
374
+     * NB: in fact a user defined error handler can only handle WARNING, NOTICE and USER_* errors.
375
+     *
376
+     */
377
+    function _xmlrpcs_errorHandler($errcode, $errstring, $filename=null, $lineno=null, $context=null)
378
+    {
379
+        // obey the @ protocol
380
+        if (error_reporting() == 0)
381
+            return;
382
+
383
+        //if($errcode != E_NOTICE && $errcode != E_WARNING && $errcode != E_USER_NOTICE && $errcode != E_USER_WARNING)
384
+        if($errcode != E_STRICT)
385
+        {
386
+            $GLOBALS['_xmlrpcs_occurred_errors'] = $GLOBALS['_xmlrpcs_occurred_errors'] . $errstring . "\n";
387
+        }
388
+        // Try to avoid as much as possible disruption to the previous error handling
389
+        // mechanism in place
390
+        if($GLOBALS['_xmlrpcs_prev_ehandler'] == '')
391
+        {
392
+            // The previous error handler was the default: all we should do is log error
393
+            // to the default error log (if level high enough)
394
+            if(ini_get('log_errors') && (intval(ini_get('error_reporting')) & $errcode))
395
+            {
396
+                error_log($errstring);
397
+            }
398
+        }
399
+        else
400
+        {
401
+            // Pass control on to previous error handler, trying to avoid loops...
402
+            if($GLOBALS['_xmlrpcs_prev_ehandler'] != '_xmlrpcs_errorHandler')
403
+            {
404
+                // NB: this code will NOT work on php < 4.0.2: only 2 params were used for error handlers
405
+                if(is_array($GLOBALS['_xmlrpcs_prev_ehandler']))
406
+                {
407
+                    // the following works both with static class methods and plain object methods as error handler
408
+                    call_user_func_array($GLOBALS['_xmlrpcs_prev_ehandler'], array($errcode, $errstring, $filename, $lineno, $context));
409
+                }
410
+                else
411
+                {
412
+                    $GLOBALS['_xmlrpcs_prev_ehandler']($errcode, $errstring, $filename, $lineno, $context);
413
+                }
414
+            }
415
+        }
416
+    }
417
+
418
+    $GLOBALS['_xmlrpc_debuginfo']='';
419
+
420
+    /**
421
+     * Add a string to the debug info that can be later seralized by the server
422
+     * as part of the response message.
423
+     * Note that for best compatibility, the debug string should be encoded using
424
+     * the $GLOBALS['xmlrpc_internalencoding'] character set.
425
+     * @param string $m
426
+     * @access public
427
+     */
428
+    function xmlrpc_debugmsg($m)
429
+    {
430
+        $GLOBALS['_xmlrpc_debuginfo'] .= $m . "\n";
431
+    }
432
+
433
+    class xmlrpc_server
434
+    {
435
+        /**
436
+         * Array defining php functions exposed as xmlrpc methods by this server
437
+         * @access private
438
+         */
439
+        var $dmap=array();
440
+        /**
441
+         * Defines how functions in dmap will be invoked: either using an xmlrpc msg object
442
+         * or plain php values.
443
+         * valid strings are 'xmlrpcvals', 'phpvals' or 'epivals'
444
+         */
445
+        var $functions_parameters_type='xmlrpcvals';
446
+        /**
447
+         * Option used for fine-tuning the encoding the php values returned from
448
+         * functions registered in the dispatch map when the functions_parameters_types
449
+         * member is set to 'phpvals'
450
+         * @see php_xmlrpc_encode for a list of values
451
+         */
452
+        var $phpvals_encoding_options = array( 'auto_dates' );
453
+        /// controls whether the server is going to echo debugging messages back to the client as comments in response body. valid values: 0,1,2,3
454
+        var $debug = 1;
455
+        /**
456
+         * Controls behaviour of server when invoked user function throws an exception:
457
+         * 0 = catch it and return an 'internal error' xmlrpc response (default)
458
+         * 1 = catch it and return an xmlrpc response with the error corresponding to the exception
459
+         * 2 = allow the exception to float to the upper layers
460
+         */
461
+        var $exception_handling = 0;
462
+        /**
463
+         * When set to true, it will enable HTTP compression of the response, in case
464
+         * the client has declared its support for compression in the request.
465
+         */
466
+        var $compress_response = false;
467
+        /**
468
+         * List of http compression methods accepted by the server for requests.
469
+         * NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib
470
+         */
471
+        var $accepted_compression = array();
472
+        /// shall we serve calls to system.* methods?
473
+        var $allow_system_funcs = true;
474
+        /// list of charset encodings natively accepted for requests
475
+        var $accepted_charset_encodings = array();
476
+        /**
477
+         * charset encoding to be used for response.
478
+         * NB: if we can, we will convert the generated response from internal_encoding to the intended one.
479
+         * can be: a supported xml encoding (only UTF-8 and ISO-8859-1 at present, unless mbstring is enabled),
480
+         * null (leave unspecified in response, convert output stream to US_ASCII),
481
+         * 'default' (use xmlrpc library default as specified in xmlrpc.inc, convert output stream if needed),
482
+         * or 'auto' (use client-specified charset encoding or same as request if request headers do not specify it (unless request is US-ASCII: then use library default anyway).
483
+         * NB: pretty dangerous if you accept every charset and do not have mbstring enabled)
484
+         */
485
+        var $response_charset_encoding = '';
486
+        /**
487
+         * Storage for internal debug info
488
+         * @access private
489
+         */
490
+        var $debug_info = '';
491
+        /**
492
+         * Extra data passed at runtime to method handling functions. Used only by EPI layer
493
+         */
494
+        var $user_data = null;
495
+
496
+        /**
497
+         * @param array $dispmap the dispatch map with definition of exposed services
498
+         * @param boolean $servicenow set to false to prevent the server from running upon construction
499
+         */
500
+        function __construct($dispMap=null, $serviceNow=true)
501
+        {
502
+            // if ZLIB is enabled, let the server by default accept compressed requests,
503
+            // and compress responses sent to clients that support them
504
+            if(function_exists('gzinflate'))
505
+            {
506
+                $this->accepted_compression = array('gzip', 'deflate');
507
+                $this->compress_response = true;
508
+            }
509
+
510
+            // by default the xml parser can support these 3 charset encodings
511
+            $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
512
+
513
+            // dispMap is a dispatch array of methods
514
+            // mapped to function names and signatures
515
+            // if a method
516
+            // doesn't appear in the map then an unknown
517
+            // method error is generated
518
+            /* milosch - changed to make passing dispMap optional.
519 519
 			 * instead, you can use the class add_to_map() function
520 520
 			 * to add functions manually (borrowed from SOAPX4)
521 521
 			 */
522
-			if($dispMap)
523
-			{
524
-				$this->dmap = $dispMap;
525
-				if($serviceNow)
526
-				{
527
-					$this->service();
528
-				}
529
-			}
530
-		}
531
-
532
-		/**
533
-		* @deprecated
534
-		*/
535
-		function xmlrpc_client($dispMap=null, $serviceNow=true)
536
-		{
537
-			self::__construct($dispMap, $serviceNow);
538
-		}
539
-
540
-		/**
541
-		* Set debug level of server.
542
-		* @param integer $in debug lvl: determines info added to xmlrpc responses (as xml comments)
543
-		* 0 = no debug info,
544
-		* 1 = msgs set from user with debugmsg(),
545
-		* 2 = add complete xmlrpc request (headers and body),
546
-		* 3 = add also all processing warnings happened during method processing
547
-		* (NB: this involves setting a custom error handler, and might interfere
548
-		* with the standard processing of the php function exposed as method. In
549
-		* particular, triggering an USER_ERROR level error will not halt script
550
-		* execution anymore, but just end up logged in the xmlrpc response)
551
-		* Note that info added at level 2 and 3 will be base64 encoded
552
-		* @access public
553
-		*/
554
-		function setDebug($in)
555
-		{
556
-			$this->debug=$in;
557
-		}
558
-
559
-		/**
560
-		* Return a string with the serialized representation of all debug info
561
-		* @param string $charset_encoding the target charset encoding for the serialization
562
-		* @return string an XML comment (or two)
563
-		*/
564
-		function serializeDebug($charset_encoding='')
565
-		{
566
-			// Tough encoding problem: which internal charset should we assume for debug info?
567
-			// It might contain a copy of raw data received from client, ie with unknown encoding,
568
-			// intermixed with php generated data and user generated data...
569
-			// so we split it: system debug is base 64 encoded,
570
-			// user debug info should be encoded by the end user using the INTERNAL_ENCODING
571
-			$out = '';
572
-			if ($this->debug_info != '')
573
-			{
574
-				$out .= "<!-- SERVER DEBUG INFO (BASE64 ENCODED):\n".base64_encode($this->debug_info)."\n-->\n";
575
-			}
576
-			if($GLOBALS['_xmlrpc_debuginfo']!='')
577
-			{
578
-
579
-				$out .= "<!-- DEBUG INFO:\n" . xmlrpc_encode_entitites(str_replace('--', '_-', $GLOBALS['_xmlrpc_debuginfo']), $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "\n-->\n";
580
-				// NB: a better solution MIGHT be to use CDATA, but we need to insert it
581
-				// into return payload AFTER the beginning tag
582
-				//$out .= "<![CDATA[ DEBUG INFO:\n\n" . str_replace(']]>', ']_]_>', $GLOBALS['_xmlrpc_debuginfo']) . "\n]]>\n";
583
-			}
584
-			return $out;
585
-		}
586
-
587
-		/**
588
-		* Execute the xmlrpc request, printing the response
589
-		* @param string $data the request body. If null, the http POST request will be examined
590
-		* @return xmlrpcresp the response object (usually not used by caller...)
591
-		* @access public
592
-		*/
593
-		function service($data=null, $return_payload=false)
594
-		{
595
-			if ($data === null)
596
-			{
597
-				// workaround for a known bug in php ver. 5.2.2 that broke $HTTP_RAW_POST_DATA
598
-				$data = file_get_contents('php://input');
599
-			}
600
-			$raw_data = $data;
601
-
602
-			// reset internal debug info
603
-			$this->debug_info = '';
604
-
605
-			// Echo back what we received, before parsing it
606
-			if($this->debug > 1)
607
-			{
608
-				$this->debugmsg("+++GOT+++\n" . $data . "\n+++END+++");
609
-			}
610
-
611
-			$r = $this->parseRequestHeaders($data, $req_charset, $resp_charset, $resp_encoding);
612
-			if (!$r)
613
-			{
614
-				$r=$this->parseRequest($data, $req_charset);
615
-			}
616
-
617
-			// save full body of request into response, for more debugging usages
618
-			$r->raw_data = $raw_data;
619
-
620
-			if($this->debug > 2 && $GLOBALS['_xmlrpcs_occurred_errors'])
621
-			{
622
-				$this->debugmsg("+++PROCESSING ERRORS AND WARNINGS+++\n" .
623
-					$GLOBALS['_xmlrpcs_occurred_errors'] . "+++END+++");
624
-			}
625
-
626
-			$payload=$this->xml_header($resp_charset);
627
-			if($this->debug > 0)
628
-			{
629
-				$payload = $payload . $this->serializeDebug($resp_charset);
630
-			}
631
-
632
-			// G. Giunta 2006-01-27: do not create response serialization if it has
633
-			// already happened. Helps building json magic
634
-			if (empty($r->payload))
635
-			{
636
-				$r->serialize($resp_charset);
637
-			}
638
-			$payload = $payload . $r->payload;
639
-
640
-			if ($return_payload)
641
-			{
642
-				return $payload;
643
-			}
644
-
645
-			// if we get a warning/error that has output some text before here, then we cannot
646
-			// add a new header. We cannot say we are sending xml, either...
647
-			if(!headers_sent())
648
-			{
649
-				header('Content-Type: '.$r->content_type);
650
-				// we do not know if client actually told us an accepted charset, but if he did
651
-				// we have to tell him what we did
652
-				header("Vary: Accept-Charset");
653
-
654
-				// http compression of output: only
655
-				// if we can do it, and we want to do it, and client asked us to,
656
-				// and php ini settings do not force it already
657
-				$php_no_self_compress = !ini_get('zlib.output_compression') && (ini_get('output_handler') != 'ob_gzhandler');
658
-				if($this->compress_response && function_exists('gzencode') && $resp_encoding != ''
659
-					&& $php_no_self_compress)
660
-				{
661
-					if(strpos($resp_encoding, 'gzip') !== false)
662
-					{
663
-						$payload = gzencode($payload);
664
-						header("Content-Encoding: gzip");
665
-						header("Vary: Accept-Encoding");
666
-					}
667
-					elseif (strpos($resp_encoding, 'deflate') !== false)
668
-					{
669
-						$payload = gzcompress($payload);
670
-						header("Content-Encoding: deflate");
671
-						header("Vary: Accept-Encoding");
672
-					}
673
-				}
674
-
675
-				// do not ouput content-length header if php is compressing output for us:
676
-				// it will mess up measurements
677
-				if($php_no_self_compress)
678
-				{
679
-					header('Content-Length: ' . (int)strlen($payload));
680
-				}
681
-			}
682
-			else
683
-			{
684
-				error_log('XML-RPC: '.__METHOD__.': http headers already sent before response is fully generated. Check for php warning or error messages');
685
-			}
686
-
687
-			print $payload;
688
-
689
-			// return request, in case subclasses want it
690
-			return $r;
691
-		}
692
-
693
-		/**
694
-		* Add a method to the dispatch map
695
-		* @param string $methodname the name with which the method will be made available
696
-		* @param string $function the php function that will get invoked
697
-		* @param array $sig the array of valid method signatures
698
-		* @param string $doc method documentation
699
-		* @param array $sigdoc the array of valid method signatures docs (one string per param, one for return type)
700
-		* @access public
701
-		*/
702
-		function add_to_map($methodname,$function,$sig=null,$doc=false,$sigdoc=false)
703
-		{
704
-			$this->dmap[$methodname] = array(
705
-				'function'	=> $function,
706
-				'docstring' => $doc
707
-			);
708
-			if ($sig)
709
-			{
710
-				$this->dmap[$methodname]['signature'] = $sig;
711
-			}
712
-			if ($sigdoc)
713
-			{
714
-				$this->dmap[$methodname]['signature_docs'] = $sigdoc;
715
-			}
716
-		}
717
-
718
-		/**
719
-		* Verify type and number of parameters received against a list of known signatures
720
-		* @param array $in array of either xmlrpcval objects or xmlrpc type definitions
721
-		* @param array $sig array of known signatures to match against
722
-		* @return array
723
-		* @access private
724
-		*/
725
-		function verifySignature($in, $sig)
726
-		{
727
-			// check each possible signature in turn
728
-			if (is_object($in))
729
-			{
730
-				$numParams = $in->getNumParams();
731
-			}
732
-			else
733
-			{
734
-				$numParams = count($in);
735
-			}
736
-			foreach($sig as $cursig)
737
-			{
738
-				if(count($cursig)==$numParams+1)
739
-				{
740
-					$itsOK=1;
741
-					for($n=0; $n<$numParams; $n++)
742
-					{
743
-						if (is_object($in))
744
-						{
745
-							$p=$in->getParam($n);
746
-							if($p->kindOf() == 'scalar')
747
-							{
748
-								$pt=$p->scalartyp();
749
-							}
750
-							else
751
-							{
752
-								$pt=$p->kindOf();
753
-							}
754
-						}
755
-						else
756
-						{
757
-							$pt= $in[$n] == 'i4' ? 'int' : strtolower($in[$n]); // dispatch maps never use i4...
758
-						}
759
-
760
-						// param index is $n+1, as first member of sig is return type
761
-						if($pt != $cursig[$n+1] && $cursig[$n+1] != $GLOBALS['xmlrpcValue'])
762
-						{
763
-							$itsOK=0;
764
-							$pno=$n+1;
765
-							$wanted=$cursig[$n+1];
766
-							$got=$pt;
767
-							break;
768
-						}
769
-					}
770
-					if($itsOK)
771
-					{
772
-						return array(1,'');
773
-					}
774
-				}
775
-			}
776
-			if(isset($wanted))
777
-			{
778
-				return array(0, "Wanted ${wanted}, got ${got} at param ${pno}");
779
-			}
780
-			else
781
-			{
782
-				return array(0, "No method signature matches number of parameters");
783
-			}
784
-		}
785
-
786
-		/**
787
-		* Parse http headers received along with xmlrpc request. If needed, inflate request
788
-		* @return mixed null on success or an xmlrpcresp
789
-		* @access private
790
-		*/
791
-		function parseRequestHeaders(&$data, &$req_encoding, &$resp_encoding, &$resp_compression)
792
-		{
793
-			// check if $_SERVER is populated: it might have been disabled via ini file
794
-			// (this is true even when in CLI mode)
795
-			if (count($_SERVER) == 0)
796
-			{
797
-				error_log('XML-RPC: '.__METHOD__.': cannot parse request headers as $_SERVER is not populated');
798
-			}
799
-
800
-			if($this->debug > 1)
801
-			{
802
-				if(function_exists('getallheaders'))
803
-				{
804
-					$this->debugmsg(''); // empty line
805
-					foreach(getallheaders() as $name => $val)
806
-					{
807
-						$this->debugmsg("HEADER: $name: $val");
808
-					}
809
-				}
810
-
811
-			}
812
-
813
-			if(isset($_SERVER['HTTP_CONTENT_ENCODING']))
814
-			{
815
-				$content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']);
816
-			}
817
-			else
818
-			{
819
-				$content_encoding = '';
820
-			}
821
-
822
-			// check if request body has been compressed and decompress it
823
-			if($content_encoding != '' && strlen($data))
824
-			{
825
-				if($content_encoding == 'deflate' || $content_encoding == 'gzip')
826
-				{
827
-					// if decoding works, use it. else assume data wasn't gzencoded
828
-					if(function_exists('gzinflate') && in_array($content_encoding, $this->accepted_compression))
829
-					{
830
-						if($content_encoding == 'deflate' && $degzdata = @gzuncompress($data))
831
-						{
832
-							$data = $degzdata;
833
-							if($this->debug > 1)
834
-							{
835
-								$this->debugmsg("\n+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
836
-							}
837
-						}
838
-						elseif($content_encoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
839
-						{
840
-							$data = $degzdata;
841
-							if($this->debug > 1)
842
-								$this->debugmsg("+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
843
-						}
844
-						else
845
-						{
846
-							$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_decompress_fail'], $GLOBALS['xmlrpcstr']['server_decompress_fail']);
847
-							return $r;
848
-						}
849
-					}
850
-					else
851
-					{
852
-						//error_log('The server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
853
-						$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_cannot_decompress'], $GLOBALS['xmlrpcstr']['server_cannot_decompress']);
854
-						return $r;
855
-					}
856
-				}
857
-			}
858
-
859
-			// check if client specified accepted charsets, and if we know how to fulfill
860
-			// the request
861
-			if ($this->response_charset_encoding == 'auto')
862
-			{
863
-				$resp_encoding = '';
864
-				if (isset($_SERVER['HTTP_ACCEPT_CHARSET']))
865
-				{
866
-					// here we should check if we can match the client-requested encoding
867
-					// with the encodings we know we can generate.
868
-					/// @todo we should parse q=0.x preferences instead of getting first charset specified...
869
-					$client_accepted_charsets = explode(',', strtoupper($_SERVER['HTTP_ACCEPT_CHARSET']));
870
-					// Give preference to internal encoding
871
-					$known_charsets = array($GLOBALS['xmlrpc_internalencoding'], 'UTF-8', 'ISO-8859-1', 'US-ASCII');
872
-					foreach ($known_charsets as $charset)
873
-					{
874
-						foreach ($client_accepted_charsets as $accepted)
875
-							if (strpos($accepted, $charset) === 0)
876
-							{
877
-								$resp_encoding = $charset;
878
-								break;
879
-							}
880
-						if ($resp_encoding)
881
-							break;
882
-					}
883
-				}
884
-			}
885
-			else
886
-			{
887
-				$resp_encoding = $this->response_charset_encoding;
888
-			}
889
-
890
-			if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
891
-			{
892
-				$resp_compression = $_SERVER['HTTP_ACCEPT_ENCODING'];
893
-			}
894
-			else
895
-			{
896
-				$resp_compression = '';
897
-			}
898
-
899
-			// 'guestimate' request encoding
900
-			/// @todo check if mbstring is enabled and automagic input conversion is on: it might mingle with this check???
901
-			$req_encoding = guess_encoding(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '',
902
-				$data);
903
-
904
-			return null;
905
-		}
906
-
907
-		/**
908
-		* Parse an xml chunk containing an xmlrpc request and execute the corresponding
909
-		* php function registered with the server
910
-		* @param string $data the xml request
911
-		* @param string $req_encoding (optional) the charset encoding of the xml request
912
-		* @return xmlrpcresp
913
-		* @access private
914
-		*/
915
-		function parseRequest($data, $req_encoding='')
916
-		{
917
-			// 2005/05/07 commented and moved into caller function code
918
-			//if($data=='')
919
-			//{
920
-			//	$data=$GLOBALS['HTTP_RAW_POST_DATA'];
921
-			//}
922
-
923
-			// G. Giunta 2005/02/13: we do NOT expect to receive html entities
924
-			// so we do not try to convert them into xml character entities
925
-			//$data = xmlrpc_html_entity_xlate($data);
926
-
927
-			$GLOBALS['_xh']=array();
928
-			$GLOBALS['_xh']['ac']='';
929
-			$GLOBALS['_xh']['stack']=array();
930
-			$GLOBALS['_xh']['valuestack'] = array();
931
-			$GLOBALS['_xh']['params']=array();
932
-			$GLOBALS['_xh']['pt']=array();
933
-			$GLOBALS['_xh']['isf']=0;
934
-			$GLOBALS['_xh']['isf_reason']='';
935
-			$GLOBALS['_xh']['method']=false; // so we can check later if we got a methodname or not
936
-			$GLOBALS['_xh']['rt']='';
937
-
938
-			// decompose incoming XML into request structure
939
-
940
-			if ($req_encoding != '')
941
-			{
942
-				// Since parsing will fail if charset is not specified in the xml prologue,
943
-				// the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
944
-				// The following code might be better for mb_string enabled installs, but
945
-				// makes the lib about 200% slower...
946
-				//if (!is_valid_charset($req_encoding, array('UTF-8')))
947
-				if (!in_array($req_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($data)) {
948
-					if ($req_encoding == 'ISO-8859-1') {
949
-						$data = utf8_encode($data);
950
-					} else {
951
-						if (extension_loaded('mbstring')) {
952
-							$data = mb_convert_encoding($data, 'UTF-8', $req_encoding);
953
-						} else {
954
-							error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $req_encoding);
955
-						}
956
-					}
957
-				}
958
-			}
959
-
960
-			$parser = xml_parser_create();
961
-			xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
962
-			// G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell
963
-			// the xml parser to give us back data in the expected charset
964
-			// What if internal encoding is not in one of the 3 allowed?
965
-			// we use the broadest one, ie. utf8
966
-			// This allows to send data which is native in various charset,
967
-			// by extending xmlrpc_encode_entitites() and setting xmlrpc_internalencoding
968
-			if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
969
-			{
970
-				xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
971
-			}
972
-			else
973
-			{
974
-				xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
975
-			}
976
-
977
-			if ($this->functions_parameters_type != 'xmlrpcvals')
978
-				xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast');
979
-			else
980
-				xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
981
-			xml_set_character_data_handler($parser, 'xmlrpc_cd');
982
-			xml_set_default_handler($parser, 'xmlrpc_dh');
983
-			if(!xml_parse($parser, $data, 1))
984
-			{
985
-				// return XML error as a faultCode
986
-				$r=new xmlrpcresp(0,
987
-				$GLOBALS['xmlrpcerrxml']+xml_get_error_code($parser),
988
-				sprintf('XML error: %s at line %d, column %d',
989
-					xml_error_string(xml_get_error_code($parser)),
990
-					xml_get_current_line_number($parser), xml_get_current_column_number($parser)));
991
-				xml_parser_free($parser);
992
-			}
993
-			elseif ($GLOBALS['_xh']['isf'])
994
-			{
995
-				xml_parser_free($parser);
996
-				$r=new xmlrpcresp(0,
997
-					$GLOBALS['xmlrpcerr']['invalid_request'],
998
-					$GLOBALS['xmlrpcstr']['invalid_request'] . ' ' . $GLOBALS['_xh']['isf_reason']);
999
-			}
1000
-			else
1001
-			{
1002
-				xml_parser_free($parser);
1003
-				// small layering violation in favor of speed and memory usage:
1004
-				// we should allow the 'execute' method handle this, but in the
1005
-				// most common scenario (xmlrpcvals type server with some methods
1006
-				// registered as phpvals) that would mean a useless encode+decode pass
1007
-				if ($this->functions_parameters_type != 'xmlrpcvals' || (isset($this->dmap[$GLOBALS['_xh']['method']]['parameters_type']) && ($this->dmap[$GLOBALS['_xh']['method']]['parameters_type'] == 'phpvals')))
1008
-				{
1009
-					if($this->debug > 1)
1010
-					{
1011
-						$this->debugmsg("\n+++PARSED+++\n".var_export($GLOBALS['_xh']['params'], true)."\n+++END+++");
1012
-					}
1013
-					$r = $this->execute($GLOBALS['_xh']['method'], $GLOBALS['_xh']['params'], $GLOBALS['_xh']['pt']);
1014
-				}
1015
-				else
1016
-				{
1017
-					// build an xmlrpcmsg object with data parsed from xml
1018
-					$m=new xmlrpcmsg($GLOBALS['_xh']['method']);
1019
-					// now add parameters in
1020
-					for($i=0; $i<count($GLOBALS['_xh']['params']); $i++)
1021
-					{
1022
-						$m->addParam($GLOBALS['_xh']['params'][$i]);
1023
-					}
1024
-
1025
-					if($this->debug > 1)
1026
-					{
1027
-						$this->debugmsg("\n+++PARSED+++\n".var_export($m, true)."\n+++END+++");
1028
-					}
1029
-					$r = $this->execute($m);
1030
-				}
1031
-			}
1032
-			return $r;
1033
-		}
1034
-
1035
-		/**
1036
-		* Execute a method invoked by the client, checking parameters used
1037
-		* @param mixed $m either an xmlrpcmsg obj or a method name
1038
-		* @param array $params array with method parameters as php types (if m is method name only)
1039
-		* @param array $paramtypes array with xmlrpc types of method parameters (if m is method name only)
1040
-		* @return xmlrpcresp
1041
-		* @access private
1042
-		*/
1043
-		function execute($m, $params=null, $paramtypes=null)
1044
-		{
1045
-			if (is_object($m))
1046
-			{
1047
-				$methName = $m->method();
1048
-			}
1049
-			else
1050
-			{
1051
-				$methName = $m;
1052
-			}
1053
-			$sysCall = $this->allow_system_funcs && (strpos($methName, "system.") === 0);
1054
-			$dmap = $sysCall ? $GLOBALS['_xmlrpcs_dmap'] : $this->dmap;
1055
-
1056
-			if(!isset($dmap[$methName]['function']))
1057
-			{
1058
-				// No such method
1059
-				return new xmlrpcresp(0,
1060
-					$GLOBALS['xmlrpcerr']['unknown_method'],
1061
-					$GLOBALS['xmlrpcstr']['unknown_method']);
1062
-			}
1063
-
1064
-			// Check signature
1065
-			if(isset($dmap[$methName]['signature']))
1066
-			{
1067
-				$sig = $dmap[$methName]['signature'];
1068
-				if (is_object($m))
1069
-				{
1070
-					list($ok, $errstr) = $this->verifySignature($m, $sig);
1071
-				}
1072
-				else
1073
-				{
1074
-					list($ok, $errstr) = $this->verifySignature($paramtypes, $sig);
1075
-				}
1076
-				if(!$ok)
1077
-				{
1078
-					// Didn't match.
1079
-					return new xmlrpcresp(
1080
-						0,
1081
-						$GLOBALS['xmlrpcerr']['incorrect_params'],
1082
-						$GLOBALS['xmlrpcstr']['incorrect_params'] . ": ${errstr}"
1083
-					);
1084
-				}
1085
-			}
1086
-
1087
-			$func = $dmap[$methName]['function'];
1088
-			// let the 'class::function' syntax be accepted in dispatch maps
1089
-			if(is_string($func) && strpos($func, '::'))
1090
-			{
1091
-				$func = explode('::', $func);
1092
-			}
1093
-			// verify that function to be invoked is in fact callable
1094
-			if(!is_callable($func))
1095
-			{
1096
-				error_log("XML-RPC: ".__METHOD__.": function $func registered as method handler is not callable");
1097
-				return new xmlrpcresp(
1098
-					0,
1099
-					$GLOBALS['xmlrpcerr']['server_error'],
1100
-					$GLOBALS['xmlrpcstr']['server_error'] . ": no function matches method"
1101
-				);
1102
-			}
1103
-
1104
-			// If debug level is 3, we should catch all errors generated during
1105
-			// processing of user function, and log them as part of response
1106
-			if($this->debug > 2)
1107
-			{
1108
-				$GLOBALS['_xmlrpcs_prev_ehandler'] = set_error_handler('_xmlrpcs_errorHandler');
1109
-			}
1110
-			try
1111
-			{
1112
-				// Allow mixed-convention servers
1113
-				if (is_object($m))
1114
-				{
1115
-					if($sysCall)
1116
-					{
1117
-						$r = call_user_func($func, $this, $m);
1118
-					}
1119
-					else
1120
-					{
1121
-						$r = call_user_func($func, $m);
1122
-					}
1123
-					if (!is_a($r, 'xmlrpcresp'))
1124
-					{
1125
-						error_log("XML-RPC: ".__METHOD__.": function $func registered as method handler does not return an xmlrpcresp object");
1126
-						if (is_a($r, 'xmlrpcval'))
1127
-						{
1128
-							$r = new xmlrpcresp($r);
1129
-						}
1130
-						else
1131
-						{
1132
-							$r = new xmlrpcresp(
1133
-								0,
1134
-								$GLOBALS['xmlrpcerr']['server_error'],
1135
-								$GLOBALS['xmlrpcstr']['server_error'] . ": function does not return xmlrpcresp object"
1136
-							);
1137
-						}
1138
-					}
1139
-				}
1140
-				else
1141
-				{
1142
-					// call a 'plain php' function
1143
-					if($sysCall)
1144
-					{
1145
-						array_unshift($params, $this);
1146
-						$r = call_user_func_array($func, $params);
1147
-					}
1148
-					else
1149
-					{
1150
-						// 3rd API convention for method-handling functions: EPI-style
1151
-						if ($this->functions_parameters_type == 'epivals')
1152
-						{
1153
-							$r = call_user_func_array($func, array($methName, $params, $this->user_data));
1154
-							// mimic EPI behaviour: if we get an array that looks like an error, make it
1155
-							// an eror response
1156
-							if (is_array($r) && array_key_exists('faultCode', $r) && array_key_exists('faultString', $r))
1157
-							{
1158
-								$r = new xmlrpcresp(0, (integer)$r['faultCode'], (string)$r['faultString']);
1159
-							}
1160
-							else
1161
-							{
1162
-								// functions using EPI api should NOT return resp objects,
1163
-								// so make sure we encode the return type correctly
1164
-								$r = new xmlrpcresp(php_xmlrpc_encode($r, array('extension_api')));
1165
-							}
1166
-						}
1167
-						else
1168
-						{
1169
-							$r = call_user_func_array($func, $params);
1170
-						}
1171
-					}
1172
-					// the return type can be either an xmlrpcresp object or a plain php value...
1173
-					if (!is_a($r, 'xmlrpcresp'))
1174
-					{
1175
-						// what should we assume here about automatic encoding of datetimes
1176
-						// and php classes instances???
1177
-						$r = new xmlrpcresp(php_xmlrpc_encode($r, $this->phpvals_encoding_options));
1178
-					}
1179
-				}
1180
-			}
1181
-			catch(Exception $e)
1182
-			{
1183
-				// (barring errors in the lib) an uncatched exception happened
1184
-				// in the called function, we wrap it in a proper error-response
1185
-				switch($this->exception_handling)
1186
-				{
1187
-					case 2:
1188
-						throw $e;
1189
-						break;
1190
-					case 1:
1191
-						$r = new xmlrpcresp(0, $e->getCode(), $e->getMessage());
1192
-						break;
1193
-					default:
1194
-						$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_error'], $GLOBALS['xmlrpcstr']['server_error']);
1195
-				}
1196
-			}
1197
-			if($this->debug > 2)
1198
-			{
1199
-				// note: restore the error handler we found before calling the
1200
-				// user func, even if it has been changed inside the func itself
1201
-				if($GLOBALS['_xmlrpcs_prev_ehandler'])
1202
-				{
1203
-					set_error_handler($GLOBALS['_xmlrpcs_prev_ehandler']);
1204
-				}
1205
-				else
1206
-				{
1207
-					restore_error_handler();
1208
-				}
1209
-			}
1210
-			return $r;
1211
-		}
1212
-
1213
-		/**
1214
-		* add a string to the 'internal debug message' (separate from 'user debug message')
1215
-		* @param string $string
1216
-		* @access private
1217
-		*/
1218
-		function debugmsg($string)
1219
-		{
1220
-			$this->debug_info .= $string."\n";
1221
-		}
1222
-
1223
-		/**
1224
-		* @access private
1225
-		*/
1226
-		function xml_header($charset_encoding='')
1227
-		{
1228
-			if ($charset_encoding != '')
1229
-			{
1230
-				return "<?xml version=\"1.0\" encoding=\"$charset_encoding\"?" . ">\n";
1231
-			}
1232
-			else
1233
-			{
1234
-				return "<?xml version=\"1.0\"?" . ">\n";
1235
-			}
1236
-		}
1237
-
1238
-		/**
1239
-		* A debugging routine: just echoes back the input packet as a string value
1240
-		* DEPRECATED!
1241
-		*/
1242
-		function echoInput()
1243
-		{
1244
-			$r=new xmlrpcresp(new xmlrpcval( "'Aha said I: '" . $GLOBALS['HTTP_RAW_POST_DATA'], 'string'));
1245
-			print $r->serialize();
1246
-		}
1247
-	}
522
+            if($dispMap)
523
+            {
524
+                $this->dmap = $dispMap;
525
+                if($serviceNow)
526
+                {
527
+                    $this->service();
528
+                }
529
+            }
530
+        }
531
+
532
+        /**
533
+         * @deprecated
534
+         */
535
+        function xmlrpc_client($dispMap=null, $serviceNow=true)
536
+        {
537
+            self::__construct($dispMap, $serviceNow);
538
+        }
539
+
540
+        /**
541
+         * Set debug level of server.
542
+         * @param integer $in debug lvl: determines info added to xmlrpc responses (as xml comments)
543
+         * 0 = no debug info,
544
+         * 1 = msgs set from user with debugmsg(),
545
+         * 2 = add complete xmlrpc request (headers and body),
546
+         * 3 = add also all processing warnings happened during method processing
547
+         * (NB: this involves setting a custom error handler, and might interfere
548
+         * with the standard processing of the php function exposed as method. In
549
+         * particular, triggering an USER_ERROR level error will not halt script
550
+         * execution anymore, but just end up logged in the xmlrpc response)
551
+         * Note that info added at level 2 and 3 will be base64 encoded
552
+         * @access public
553
+         */
554
+        function setDebug($in)
555
+        {
556
+            $this->debug=$in;
557
+        }
558
+
559
+        /**
560
+         * Return a string with the serialized representation of all debug info
561
+         * @param string $charset_encoding the target charset encoding for the serialization
562
+         * @return string an XML comment (or two)
563
+         */
564
+        function serializeDebug($charset_encoding='')
565
+        {
566
+            // Tough encoding problem: which internal charset should we assume for debug info?
567
+            // It might contain a copy of raw data received from client, ie with unknown encoding,
568
+            // intermixed with php generated data and user generated data...
569
+            // so we split it: system debug is base 64 encoded,
570
+            // user debug info should be encoded by the end user using the INTERNAL_ENCODING
571
+            $out = '';
572
+            if ($this->debug_info != '')
573
+            {
574
+                $out .= "<!-- SERVER DEBUG INFO (BASE64 ENCODED):\n".base64_encode($this->debug_info)."\n-->\n";
575
+            }
576
+            if($GLOBALS['_xmlrpc_debuginfo']!='')
577
+            {
578
+
579
+                $out .= "<!-- DEBUG INFO:\n" . xmlrpc_encode_entitites(str_replace('--', '_-', $GLOBALS['_xmlrpc_debuginfo']), $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "\n-->\n";
580
+                // NB: a better solution MIGHT be to use CDATA, but we need to insert it
581
+                // into return payload AFTER the beginning tag
582
+                //$out .= "<![CDATA[ DEBUG INFO:\n\n" . str_replace(']]>', ']_]_>', $GLOBALS['_xmlrpc_debuginfo']) . "\n]]>\n";
583
+            }
584
+            return $out;
585
+        }
586
+
587
+        /**
588
+         * Execute the xmlrpc request, printing the response
589
+         * @param string $data the request body. If null, the http POST request will be examined
590
+         * @return xmlrpcresp the response object (usually not used by caller...)
591
+         * @access public
592
+         */
593
+        function service($data=null, $return_payload=false)
594
+        {
595
+            if ($data === null)
596
+            {
597
+                // workaround for a known bug in php ver. 5.2.2 that broke $HTTP_RAW_POST_DATA
598
+                $data = file_get_contents('php://input');
599
+            }
600
+            $raw_data = $data;
601
+
602
+            // reset internal debug info
603
+            $this->debug_info = '';
604
+
605
+            // Echo back what we received, before parsing it
606
+            if($this->debug > 1)
607
+            {
608
+                $this->debugmsg("+++GOT+++\n" . $data . "\n+++END+++");
609
+            }
610
+
611
+            $r = $this->parseRequestHeaders($data, $req_charset, $resp_charset, $resp_encoding);
612
+            if (!$r)
613
+            {
614
+                $r=$this->parseRequest($data, $req_charset);
615
+            }
616
+
617
+            // save full body of request into response, for more debugging usages
618
+            $r->raw_data = $raw_data;
619
+
620
+            if($this->debug > 2 && $GLOBALS['_xmlrpcs_occurred_errors'])
621
+            {
622
+                $this->debugmsg("+++PROCESSING ERRORS AND WARNINGS+++\n" .
623
+                    $GLOBALS['_xmlrpcs_occurred_errors'] . "+++END+++");
624
+            }
625
+
626
+            $payload=$this->xml_header($resp_charset);
627
+            if($this->debug > 0)
628
+            {
629
+                $payload = $payload . $this->serializeDebug($resp_charset);
630
+            }
631
+
632
+            // G. Giunta 2006-01-27: do not create response serialization if it has
633
+            // already happened. Helps building json magic
634
+            if (empty($r->payload))
635
+            {
636
+                $r->serialize($resp_charset);
637
+            }
638
+            $payload = $payload . $r->payload;
639
+
640
+            if ($return_payload)
641
+            {
642
+                return $payload;
643
+            }
644
+
645
+            // if we get a warning/error that has output some text before here, then we cannot
646
+            // add a new header. We cannot say we are sending xml, either...
647
+            if(!headers_sent())
648
+            {
649
+                header('Content-Type: '.$r->content_type);
650
+                // we do not know if client actually told us an accepted charset, but if he did
651
+                // we have to tell him what we did
652
+                header("Vary: Accept-Charset");
653
+
654
+                // http compression of output: only
655
+                // if we can do it, and we want to do it, and client asked us to,
656
+                // and php ini settings do not force it already
657
+                $php_no_self_compress = !ini_get('zlib.output_compression') && (ini_get('output_handler') != 'ob_gzhandler');
658
+                if($this->compress_response && function_exists('gzencode') && $resp_encoding != ''
659
+                    && $php_no_self_compress)
660
+                {
661
+                    if(strpos($resp_encoding, 'gzip') !== false)
662
+                    {
663
+                        $payload = gzencode($payload);
664
+                        header("Content-Encoding: gzip");
665
+                        header("Vary: Accept-Encoding");
666
+                    }
667
+                    elseif (strpos($resp_encoding, 'deflate') !== false)
668
+                    {
669
+                        $payload = gzcompress($payload);
670
+                        header("Content-Encoding: deflate");
671
+                        header("Vary: Accept-Encoding");
672
+                    }
673
+                }
674
+
675
+                // do not ouput content-length header if php is compressing output for us:
676
+                // it will mess up measurements
677
+                if($php_no_self_compress)
678
+                {
679
+                    header('Content-Length: ' . (int)strlen($payload));
680
+                }
681
+            }
682
+            else
683
+            {
684
+                error_log('XML-RPC: '.__METHOD__.': http headers already sent before response is fully generated. Check for php warning or error messages');
685
+            }
686
+
687
+            print $payload;
688
+
689
+            // return request, in case subclasses want it
690
+            return $r;
691
+        }
692
+
693
+        /**
694
+         * Add a method to the dispatch map
695
+         * @param string $methodname the name with which the method will be made available
696
+         * @param string $function the php function that will get invoked
697
+         * @param array $sig the array of valid method signatures
698
+         * @param string $doc method documentation
699
+         * @param array $sigdoc the array of valid method signatures docs (one string per param, one for return type)
700
+         * @access public
701
+         */
702
+        function add_to_map($methodname,$function,$sig=null,$doc=false,$sigdoc=false)
703
+        {
704
+            $this->dmap[$methodname] = array(
705
+                'function'	=> $function,
706
+                'docstring' => $doc
707
+            );
708
+            if ($sig)
709
+            {
710
+                $this->dmap[$methodname]['signature'] = $sig;
711
+            }
712
+            if ($sigdoc)
713
+            {
714
+                $this->dmap[$methodname]['signature_docs'] = $sigdoc;
715
+            }
716
+        }
717
+
718
+        /**
719
+         * Verify type and number of parameters received against a list of known signatures
720
+         * @param array $in array of either xmlrpcval objects or xmlrpc type definitions
721
+         * @param array $sig array of known signatures to match against
722
+         * @return array
723
+         * @access private
724
+         */
725
+        function verifySignature($in, $sig)
726
+        {
727
+            // check each possible signature in turn
728
+            if (is_object($in))
729
+            {
730
+                $numParams = $in->getNumParams();
731
+            }
732
+            else
733
+            {
734
+                $numParams = count($in);
735
+            }
736
+            foreach($sig as $cursig)
737
+            {
738
+                if(count($cursig)==$numParams+1)
739
+                {
740
+                    $itsOK=1;
741
+                    for($n=0; $n<$numParams; $n++)
742
+                    {
743
+                        if (is_object($in))
744
+                        {
745
+                            $p=$in->getParam($n);
746
+                            if($p->kindOf() == 'scalar')
747
+                            {
748
+                                $pt=$p->scalartyp();
749
+                            }
750
+                            else
751
+                            {
752
+                                $pt=$p->kindOf();
753
+                            }
754
+                        }
755
+                        else
756
+                        {
757
+                            $pt= $in[$n] == 'i4' ? 'int' : strtolower($in[$n]); // dispatch maps never use i4...
758
+                        }
759
+
760
+                        // param index is $n+1, as first member of sig is return type
761
+                        if($pt != $cursig[$n+1] && $cursig[$n+1] != $GLOBALS['xmlrpcValue'])
762
+                        {
763
+                            $itsOK=0;
764
+                            $pno=$n+1;
765
+                            $wanted=$cursig[$n+1];
766
+                            $got=$pt;
767
+                            break;
768
+                        }
769
+                    }
770
+                    if($itsOK)
771
+                    {
772
+                        return array(1,'');
773
+                    }
774
+                }
775
+            }
776
+            if(isset($wanted))
777
+            {
778
+                return array(0, "Wanted ${wanted}, got ${got} at param ${pno}");
779
+            }
780
+            else
781
+            {
782
+                return array(0, "No method signature matches number of parameters");
783
+            }
784
+        }
785
+
786
+        /**
787
+         * Parse http headers received along with xmlrpc request. If needed, inflate request
788
+         * @return mixed null on success or an xmlrpcresp
789
+         * @access private
790
+         */
791
+        function parseRequestHeaders(&$data, &$req_encoding, &$resp_encoding, &$resp_compression)
792
+        {
793
+            // check if $_SERVER is populated: it might have been disabled via ini file
794
+            // (this is true even when in CLI mode)
795
+            if (count($_SERVER) == 0)
796
+            {
797
+                error_log('XML-RPC: '.__METHOD__.': cannot parse request headers as $_SERVER is not populated');
798
+            }
799
+
800
+            if($this->debug > 1)
801
+            {
802
+                if(function_exists('getallheaders'))
803
+                {
804
+                    $this->debugmsg(''); // empty line
805
+                    foreach(getallheaders() as $name => $val)
806
+                    {
807
+                        $this->debugmsg("HEADER: $name: $val");
808
+                    }
809
+                }
810
+
811
+            }
812
+
813
+            if(isset($_SERVER['HTTP_CONTENT_ENCODING']))
814
+            {
815
+                $content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']);
816
+            }
817
+            else
818
+            {
819
+                $content_encoding = '';
820
+            }
821
+
822
+            // check if request body has been compressed and decompress it
823
+            if($content_encoding != '' && strlen($data))
824
+            {
825
+                if($content_encoding == 'deflate' || $content_encoding == 'gzip')
826
+                {
827
+                    // if decoding works, use it. else assume data wasn't gzencoded
828
+                    if(function_exists('gzinflate') && in_array($content_encoding, $this->accepted_compression))
829
+                    {
830
+                        if($content_encoding == 'deflate' && $degzdata = @gzuncompress($data))
831
+                        {
832
+                            $data = $degzdata;
833
+                            if($this->debug > 1)
834
+                            {
835
+                                $this->debugmsg("\n+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
836
+                            }
837
+                        }
838
+                        elseif($content_encoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
839
+                        {
840
+                            $data = $degzdata;
841
+                            if($this->debug > 1)
842
+                                $this->debugmsg("+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
843
+                        }
844
+                        else
845
+                        {
846
+                            $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_decompress_fail'], $GLOBALS['xmlrpcstr']['server_decompress_fail']);
847
+                            return $r;
848
+                        }
849
+                    }
850
+                    else
851
+                    {
852
+                        //error_log('The server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
853
+                        $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_cannot_decompress'], $GLOBALS['xmlrpcstr']['server_cannot_decompress']);
854
+                        return $r;
855
+                    }
856
+                }
857
+            }
858
+
859
+            // check if client specified accepted charsets, and if we know how to fulfill
860
+            // the request
861
+            if ($this->response_charset_encoding == 'auto')
862
+            {
863
+                $resp_encoding = '';
864
+                if (isset($_SERVER['HTTP_ACCEPT_CHARSET']))
865
+                {
866
+                    // here we should check if we can match the client-requested encoding
867
+                    // with the encodings we know we can generate.
868
+                    /// @todo we should parse q=0.x preferences instead of getting first charset specified...
869
+                    $client_accepted_charsets = explode(',', strtoupper($_SERVER['HTTP_ACCEPT_CHARSET']));
870
+                    // Give preference to internal encoding
871
+                    $known_charsets = array($GLOBALS['xmlrpc_internalencoding'], 'UTF-8', 'ISO-8859-1', 'US-ASCII');
872
+                    foreach ($known_charsets as $charset)
873
+                    {
874
+                        foreach ($client_accepted_charsets as $accepted)
875
+                            if (strpos($accepted, $charset) === 0)
876
+                            {
877
+                                $resp_encoding = $charset;
878
+                                break;
879
+                            }
880
+                        if ($resp_encoding)
881
+                            break;
882
+                    }
883
+                }
884
+            }
885
+            else
886
+            {
887
+                $resp_encoding = $this->response_charset_encoding;
888
+            }
889
+
890
+            if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
891
+            {
892
+                $resp_compression = $_SERVER['HTTP_ACCEPT_ENCODING'];
893
+            }
894
+            else
895
+            {
896
+                $resp_compression = '';
897
+            }
898
+
899
+            // 'guestimate' request encoding
900
+            /// @todo check if mbstring is enabled and automagic input conversion is on: it might mingle with this check???
901
+            $req_encoding = guess_encoding(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '',
902
+                $data);
903
+
904
+            return null;
905
+        }
906
+
907
+        /**
908
+         * Parse an xml chunk containing an xmlrpc request and execute the corresponding
909
+         * php function registered with the server
910
+         * @param string $data the xml request
911
+         * @param string $req_encoding (optional) the charset encoding of the xml request
912
+         * @return xmlrpcresp
913
+         * @access private
914
+         */
915
+        function parseRequest($data, $req_encoding='')
916
+        {
917
+            // 2005/05/07 commented and moved into caller function code
918
+            //if($data=='')
919
+            //{
920
+            //	$data=$GLOBALS['HTTP_RAW_POST_DATA'];
921
+            //}
922
+
923
+            // G. Giunta 2005/02/13: we do NOT expect to receive html entities
924
+            // so we do not try to convert them into xml character entities
925
+            //$data = xmlrpc_html_entity_xlate($data);
926
+
927
+            $GLOBALS['_xh']=array();
928
+            $GLOBALS['_xh']['ac']='';
929
+            $GLOBALS['_xh']['stack']=array();
930
+            $GLOBALS['_xh']['valuestack'] = array();
931
+            $GLOBALS['_xh']['params']=array();
932
+            $GLOBALS['_xh']['pt']=array();
933
+            $GLOBALS['_xh']['isf']=0;
934
+            $GLOBALS['_xh']['isf_reason']='';
935
+            $GLOBALS['_xh']['method']=false; // so we can check later if we got a methodname or not
936
+            $GLOBALS['_xh']['rt']='';
937
+
938
+            // decompose incoming XML into request structure
939
+
940
+            if ($req_encoding != '')
941
+            {
942
+                // Since parsing will fail if charset is not specified in the xml prologue,
943
+                // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
944
+                // The following code might be better for mb_string enabled installs, but
945
+                // makes the lib about 200% slower...
946
+                //if (!is_valid_charset($req_encoding, array('UTF-8')))
947
+                if (!in_array($req_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($data)) {
948
+                    if ($req_encoding == 'ISO-8859-1') {
949
+                        $data = utf8_encode($data);
950
+                    } else {
951
+                        if (extension_loaded('mbstring')) {
952
+                            $data = mb_convert_encoding($data, 'UTF-8', $req_encoding);
953
+                        } else {
954
+                            error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $req_encoding);
955
+                        }
956
+                    }
957
+                }
958
+            }
959
+
960
+            $parser = xml_parser_create();
961
+            xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
962
+            // G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell
963
+            // the xml parser to give us back data in the expected charset
964
+            // What if internal encoding is not in one of the 3 allowed?
965
+            // we use the broadest one, ie. utf8
966
+            // This allows to send data which is native in various charset,
967
+            // by extending xmlrpc_encode_entitites() and setting xmlrpc_internalencoding
968
+            if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
969
+            {
970
+                xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
971
+            }
972
+            else
973
+            {
974
+                xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
975
+            }
976
+
977
+            if ($this->functions_parameters_type != 'xmlrpcvals')
978
+                xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast');
979
+            else
980
+                xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
981
+            xml_set_character_data_handler($parser, 'xmlrpc_cd');
982
+            xml_set_default_handler($parser, 'xmlrpc_dh');
983
+            if(!xml_parse($parser, $data, 1))
984
+            {
985
+                // return XML error as a faultCode
986
+                $r=new xmlrpcresp(0,
987
+                $GLOBALS['xmlrpcerrxml']+xml_get_error_code($parser),
988
+                sprintf('XML error: %s at line %d, column %d',
989
+                    xml_error_string(xml_get_error_code($parser)),
990
+                    xml_get_current_line_number($parser), xml_get_current_column_number($parser)));
991
+                xml_parser_free($parser);
992
+            }
993
+            elseif ($GLOBALS['_xh']['isf'])
994
+            {
995
+                xml_parser_free($parser);
996
+                $r=new xmlrpcresp(0,
997
+                    $GLOBALS['xmlrpcerr']['invalid_request'],
998
+                    $GLOBALS['xmlrpcstr']['invalid_request'] . ' ' . $GLOBALS['_xh']['isf_reason']);
999
+            }
1000
+            else
1001
+            {
1002
+                xml_parser_free($parser);
1003
+                // small layering violation in favor of speed and memory usage:
1004
+                // we should allow the 'execute' method handle this, but in the
1005
+                // most common scenario (xmlrpcvals type server with some methods
1006
+                // registered as phpvals) that would mean a useless encode+decode pass
1007
+                if ($this->functions_parameters_type != 'xmlrpcvals' || (isset($this->dmap[$GLOBALS['_xh']['method']]['parameters_type']) && ($this->dmap[$GLOBALS['_xh']['method']]['parameters_type'] == 'phpvals')))
1008
+                {
1009
+                    if($this->debug > 1)
1010
+                    {
1011
+                        $this->debugmsg("\n+++PARSED+++\n".var_export($GLOBALS['_xh']['params'], true)."\n+++END+++");
1012
+                    }
1013
+                    $r = $this->execute($GLOBALS['_xh']['method'], $GLOBALS['_xh']['params'], $GLOBALS['_xh']['pt']);
1014
+                }
1015
+                else
1016
+                {
1017
+                    // build an xmlrpcmsg object with data parsed from xml
1018
+                    $m=new xmlrpcmsg($GLOBALS['_xh']['method']);
1019
+                    // now add parameters in
1020
+                    for($i=0; $i<count($GLOBALS['_xh']['params']); $i++)
1021
+                    {
1022
+                        $m->addParam($GLOBALS['_xh']['params'][$i]);
1023
+                    }
1024
+
1025
+                    if($this->debug > 1)
1026
+                    {
1027
+                        $this->debugmsg("\n+++PARSED+++\n".var_export($m, true)."\n+++END+++");
1028
+                    }
1029
+                    $r = $this->execute($m);
1030
+                }
1031
+            }
1032
+            return $r;
1033
+        }
1034
+
1035
+        /**
1036
+         * Execute a method invoked by the client, checking parameters used
1037
+         * @param mixed $m either an xmlrpcmsg obj or a method name
1038
+         * @param array $params array with method parameters as php types (if m is method name only)
1039
+         * @param array $paramtypes array with xmlrpc types of method parameters (if m is method name only)
1040
+         * @return xmlrpcresp
1041
+         * @access private
1042
+         */
1043
+        function execute($m, $params=null, $paramtypes=null)
1044
+        {
1045
+            if (is_object($m))
1046
+            {
1047
+                $methName = $m->method();
1048
+            }
1049
+            else
1050
+            {
1051
+                $methName = $m;
1052
+            }
1053
+            $sysCall = $this->allow_system_funcs && (strpos($methName, "system.") === 0);
1054
+            $dmap = $sysCall ? $GLOBALS['_xmlrpcs_dmap'] : $this->dmap;
1055
+
1056
+            if(!isset($dmap[$methName]['function']))
1057
+            {
1058
+                // No such method
1059
+                return new xmlrpcresp(0,
1060
+                    $GLOBALS['xmlrpcerr']['unknown_method'],
1061
+                    $GLOBALS['xmlrpcstr']['unknown_method']);
1062
+            }
1063
+
1064
+            // Check signature
1065
+            if(isset($dmap[$methName]['signature']))
1066
+            {
1067
+                $sig = $dmap[$methName]['signature'];
1068
+                if (is_object($m))
1069
+                {
1070
+                    list($ok, $errstr) = $this->verifySignature($m, $sig);
1071
+                }
1072
+                else
1073
+                {
1074
+                    list($ok, $errstr) = $this->verifySignature($paramtypes, $sig);
1075
+                }
1076
+                if(!$ok)
1077
+                {
1078
+                    // Didn't match.
1079
+                    return new xmlrpcresp(
1080
+                        0,
1081
+                        $GLOBALS['xmlrpcerr']['incorrect_params'],
1082
+                        $GLOBALS['xmlrpcstr']['incorrect_params'] . ": ${errstr}"
1083
+                    );
1084
+                }
1085
+            }
1086
+
1087
+            $func = $dmap[$methName]['function'];
1088
+            // let the 'class::function' syntax be accepted in dispatch maps
1089
+            if(is_string($func) && strpos($func, '::'))
1090
+            {
1091
+                $func = explode('::', $func);
1092
+            }
1093
+            // verify that function to be invoked is in fact callable
1094
+            if(!is_callable($func))
1095
+            {
1096
+                error_log("XML-RPC: ".__METHOD__.": function $func registered as method handler is not callable");
1097
+                return new xmlrpcresp(
1098
+                    0,
1099
+                    $GLOBALS['xmlrpcerr']['server_error'],
1100
+                    $GLOBALS['xmlrpcstr']['server_error'] . ": no function matches method"
1101
+                );
1102
+            }
1103
+
1104
+            // If debug level is 3, we should catch all errors generated during
1105
+            // processing of user function, and log them as part of response
1106
+            if($this->debug > 2)
1107
+            {
1108
+                $GLOBALS['_xmlrpcs_prev_ehandler'] = set_error_handler('_xmlrpcs_errorHandler');
1109
+            }
1110
+            try
1111
+            {
1112
+                // Allow mixed-convention servers
1113
+                if (is_object($m))
1114
+                {
1115
+                    if($sysCall)
1116
+                    {
1117
+                        $r = call_user_func($func, $this, $m);
1118
+                    }
1119
+                    else
1120
+                    {
1121
+                        $r = call_user_func($func, $m);
1122
+                    }
1123
+                    if (!is_a($r, 'xmlrpcresp'))
1124
+                    {
1125
+                        error_log("XML-RPC: ".__METHOD__.": function $func registered as method handler does not return an xmlrpcresp object");
1126
+                        if (is_a($r, 'xmlrpcval'))
1127
+                        {
1128
+                            $r = new xmlrpcresp($r);
1129
+                        }
1130
+                        else
1131
+                        {
1132
+                            $r = new xmlrpcresp(
1133
+                                0,
1134
+                                $GLOBALS['xmlrpcerr']['server_error'],
1135
+                                $GLOBALS['xmlrpcstr']['server_error'] . ": function does not return xmlrpcresp object"
1136
+                            );
1137
+                        }
1138
+                    }
1139
+                }
1140
+                else
1141
+                {
1142
+                    // call a 'plain php' function
1143
+                    if($sysCall)
1144
+                    {
1145
+                        array_unshift($params, $this);
1146
+                        $r = call_user_func_array($func, $params);
1147
+                    }
1148
+                    else
1149
+                    {
1150
+                        // 3rd API convention for method-handling functions: EPI-style
1151
+                        if ($this->functions_parameters_type == 'epivals')
1152
+                        {
1153
+                            $r = call_user_func_array($func, array($methName, $params, $this->user_data));
1154
+                            // mimic EPI behaviour: if we get an array that looks like an error, make it
1155
+                            // an eror response
1156
+                            if (is_array($r) && array_key_exists('faultCode', $r) && array_key_exists('faultString', $r))
1157
+                            {
1158
+                                $r = new xmlrpcresp(0, (integer)$r['faultCode'], (string)$r['faultString']);
1159
+                            }
1160
+                            else
1161
+                            {
1162
+                                // functions using EPI api should NOT return resp objects,
1163
+                                // so make sure we encode the return type correctly
1164
+                                $r = new xmlrpcresp(php_xmlrpc_encode($r, array('extension_api')));
1165
+                            }
1166
+                        }
1167
+                        else
1168
+                        {
1169
+                            $r = call_user_func_array($func, $params);
1170
+                        }
1171
+                    }
1172
+                    // the return type can be either an xmlrpcresp object or a plain php value...
1173
+                    if (!is_a($r, 'xmlrpcresp'))
1174
+                    {
1175
+                        // what should we assume here about automatic encoding of datetimes
1176
+                        // and php classes instances???
1177
+                        $r = new xmlrpcresp(php_xmlrpc_encode($r, $this->phpvals_encoding_options));
1178
+                    }
1179
+                }
1180
+            }
1181
+            catch(Exception $e)
1182
+            {
1183
+                // (barring errors in the lib) an uncatched exception happened
1184
+                // in the called function, we wrap it in a proper error-response
1185
+                switch($this->exception_handling)
1186
+                {
1187
+                    case 2:
1188
+                        throw $e;
1189
+                        break;
1190
+                    case 1:
1191
+                        $r = new xmlrpcresp(0, $e->getCode(), $e->getMessage());
1192
+                        break;
1193
+                    default:
1194
+                        $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_error'], $GLOBALS['xmlrpcstr']['server_error']);
1195
+                }
1196
+            }
1197
+            if($this->debug > 2)
1198
+            {
1199
+                // note: restore the error handler we found before calling the
1200
+                // user func, even if it has been changed inside the func itself
1201
+                if($GLOBALS['_xmlrpcs_prev_ehandler'])
1202
+                {
1203
+                    set_error_handler($GLOBALS['_xmlrpcs_prev_ehandler']);
1204
+                }
1205
+                else
1206
+                {
1207
+                    restore_error_handler();
1208
+                }
1209
+            }
1210
+            return $r;
1211
+        }
1212
+
1213
+        /**
1214
+         * add a string to the 'internal debug message' (separate from 'user debug message')
1215
+         * @param string $string
1216
+         * @access private
1217
+         */
1218
+        function debugmsg($string)
1219
+        {
1220
+            $this->debug_info .= $string."\n";
1221
+        }
1222
+
1223
+        /**
1224
+         * @access private
1225
+         */
1226
+        function xml_header($charset_encoding='')
1227
+        {
1228
+            if ($charset_encoding != '')
1229
+            {
1230
+                return "<?xml version=\"1.0\" encoding=\"$charset_encoding\"?" . ">\n";
1231
+            }
1232
+            else
1233
+            {
1234
+                return "<?xml version=\"1.0\"?" . ">\n";
1235
+            }
1236
+        }
1237
+
1238
+        /**
1239
+         * A debugging routine: just echoes back the input packet as a string value
1240
+         * DEPRECATED!
1241
+         */
1242
+        function echoInput()
1243
+        {
1244
+            $r=new xmlrpcresp(new xmlrpcval( "'Aha said I: '" . $GLOBALS['HTTP_RAW_POST_DATA'], 'string'));
1245
+            print $r->serialize();
1246
+        }
1247
+    }
1248 1248
 ?>
1249 1249
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -57,10 +57,10 @@  discard block
 block discarded – undo
57 57
 	);
58 58
 
59 59
 	/* Functions that implement system.XXX methods of xmlrpc servers */
60
-	$_xmlrpcs_getCapabilities_sig=array(array($GLOBALS['xmlrpcStruct']));
61
-	$_xmlrpcs_getCapabilities_doc='This method lists all the capabilites that the XML-RPC server has: the (more or less standard) extensions to the xmlrpc spec that it adheres to';
62
-	$_xmlrpcs_getCapabilities_sdoc=array(array('list of capabilities, described as structs with a version number and url for the spec'));
63
-	function _xmlrpcs_getCapabilities($server, $m=null)
60
+	$_xmlrpcs_getCapabilities_sig = array(array($GLOBALS['xmlrpcStruct']));
61
+	$_xmlrpcs_getCapabilities_doc = 'This method lists all the capabilites that the XML-RPC server has: the (more or less standard) extensions to the xmlrpc spec that it adheres to';
62
+	$_xmlrpcs_getCapabilities_sdoc = array(array('list of capabilities, described as structs with a version number and url for the spec'));
63
+	function _xmlrpcs_getCapabilities($server, $m = null)
64 64
 	{
65 65
 		$outAr = $GLOBALS['xmlrpcs_capabilities'];
66 66
 		// NIL extension
@@ -75,117 +75,117 @@  discard block
 block discarded – undo
75 75
 
76 76
 	// listMethods: signature was either a string, or nothing.
77 77
 	// The useless string variant has been removed
78
-	$_xmlrpcs_listMethods_sig=array(array($GLOBALS['xmlrpcArray']));
79
-	$_xmlrpcs_listMethods_doc='This method lists all the methods that the XML-RPC server knows how to dispatch';
80
-	$_xmlrpcs_listMethods_sdoc=array(array('list of method names'));
81
-	function _xmlrpcs_listMethods($server, $m=null) // if called in plain php values mode, second param is missing
78
+	$_xmlrpcs_listMethods_sig = array(array($GLOBALS['xmlrpcArray']));
79
+	$_xmlrpcs_listMethods_doc = 'This method lists all the methods that the XML-RPC server knows how to dispatch';
80
+	$_xmlrpcs_listMethods_sdoc = array(array('list of method names'));
81
+	function _xmlrpcs_listMethods($server, $m = null) // if called in plain php values mode, second param is missing
82 82
 	{
83 83
 
84
-		$outAr=array();
85
-		foreach($server->dmap as $key => $val)
84
+		$outAr = array();
85
+		foreach ($server->dmap as $key => $val)
86 86
 		{
87
-			$outAr[]=new xmlrpcval($key, 'string');
87
+			$outAr[] = new xmlrpcval($key, 'string');
88 88
 		}
89
-		if($server->allow_system_funcs)
89
+		if ($server->allow_system_funcs)
90 90
 		{
91
-			foreach($GLOBALS['_xmlrpcs_dmap'] as $key => $val)
91
+			foreach ($GLOBALS['_xmlrpcs_dmap'] as $key => $val)
92 92
 			{
93
-				$outAr[]=new xmlrpcval($key, 'string');
93
+				$outAr[] = new xmlrpcval($key, 'string');
94 94
 			}
95 95
 		}
96 96
 		return new xmlrpcresp(new xmlrpcval($outAr, 'array'));
97 97
 	}
98 98
 
99
-	$_xmlrpcs_methodSignature_sig=array(array($GLOBALS['xmlrpcArray'], $GLOBALS['xmlrpcString']));
100
-	$_xmlrpcs_methodSignature_doc='Returns an array of known signatures (an array of arrays) for the method name passed. If no signatures are known, returns a none-array (test for type != array to detect missing signature)';
101
-	$_xmlrpcs_methodSignature_sdoc=array(array('list of known signatures, each sig being an array of xmlrpc type names', 'name of method to be described'));
99
+	$_xmlrpcs_methodSignature_sig = array(array($GLOBALS['xmlrpcArray'], $GLOBALS['xmlrpcString']));
100
+	$_xmlrpcs_methodSignature_doc = 'Returns an array of known signatures (an array of arrays) for the method name passed. If no signatures are known, returns a none-array (test for type != array to detect missing signature)';
101
+	$_xmlrpcs_methodSignature_sdoc = array(array('list of known signatures, each sig being an array of xmlrpc type names', 'name of method to be described'));
102 102
 	function _xmlrpcs_methodSignature($server, $m)
103 103
 	{
104 104
 		// let accept as parameter both an xmlrpcval or string
105 105
 		if (is_object($m))
106 106
 		{
107
-			$methName=$m->getParam(0);
108
-			$methName=$methName->scalarval();
107
+			$methName = $m->getParam(0);
108
+			$methName = $methName->scalarval();
109 109
 		}
110 110
 		else
111 111
 		{
112
-			$methName=$m;
112
+			$methName = $m;
113 113
 		}
114
-		if(strpos($methName, "system.") === 0)
114
+		if (strpos($methName, "system.") === 0)
115 115
 		{
116
-			$dmap=$GLOBALS['_xmlrpcs_dmap']; $sysCall=1;
116
+			$dmap = $GLOBALS['_xmlrpcs_dmap']; $sysCall = 1;
117 117
 		}
118 118
 		else
119 119
 		{
120
-			$dmap=$server->dmap; $sysCall=0;
120
+			$dmap = $server->dmap; $sysCall = 0;
121 121
 		}
122
-		if(isset($dmap[$methName]))
122
+		if (isset($dmap[$methName]))
123 123
 		{
124
-			if(isset($dmap[$methName]['signature']))
124
+			if (isset($dmap[$methName]['signature']))
125 125
 			{
126
-				$sigs=array();
127
-				foreach($dmap[$methName]['signature'] as $inSig)
126
+				$sigs = array();
127
+				foreach ($dmap[$methName]['signature'] as $inSig)
128 128
 				{
129
-					$cursig=array();
130
-					foreach($inSig as $sig)
129
+					$cursig = array();
130
+					foreach ($inSig as $sig)
131 131
 					{
132
-						$cursig[]=new xmlrpcval($sig, 'string');
132
+						$cursig[] = new xmlrpcval($sig, 'string');
133 133
 					}
134
-					$sigs[]=new xmlrpcval($cursig, 'array');
134
+					$sigs[] = new xmlrpcval($cursig, 'array');
135 135
 				}
136
-				$r=new xmlrpcresp(new xmlrpcval($sigs, 'array'));
136
+				$r = new xmlrpcresp(new xmlrpcval($sigs, 'array'));
137 137
 			}
138 138
 			else
139 139
 			{
140 140
 				// NB: according to the official docs, we should be returning a
141 141
 				// "none-array" here, which means not-an-array
142
-				$r=new xmlrpcresp(new xmlrpcval('undef', 'string'));
142
+				$r = new xmlrpcresp(new xmlrpcval('undef', 'string'));
143 143
 			}
144 144
 		}
145 145
 		else
146 146
 		{
147
-			$r=new xmlrpcresp(0,$GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
147
+			$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
148 148
 		}
149 149
 		return $r;
150 150
 	}
151 151
 
152
-	$_xmlrpcs_methodHelp_sig=array(array($GLOBALS['xmlrpcString'], $GLOBALS['xmlrpcString']));
153
-	$_xmlrpcs_methodHelp_doc='Returns help text if defined for the method passed, otherwise returns an empty string';
154
-	$_xmlrpcs_methodHelp_sdoc=array(array('method description', 'name of the method to be described'));
152
+	$_xmlrpcs_methodHelp_sig = array(array($GLOBALS['xmlrpcString'], $GLOBALS['xmlrpcString']));
153
+	$_xmlrpcs_methodHelp_doc = 'Returns help text if defined for the method passed, otherwise returns an empty string';
154
+	$_xmlrpcs_methodHelp_sdoc = array(array('method description', 'name of the method to be described'));
155 155
 	function _xmlrpcs_methodHelp($server, $m)
156 156
 	{
157 157
 		// let accept as parameter both an xmlrpcval or string
158 158
 		if (is_object($m))
159 159
 		{
160
-			$methName=$m->getParam(0);
161
-			$methName=$methName->scalarval();
160
+			$methName = $m->getParam(0);
161
+			$methName = $methName->scalarval();
162 162
 		}
163 163
 		else
164 164
 		{
165
-			$methName=$m;
165
+			$methName = $m;
166 166
 		}
167
-		if(strpos($methName, "system.") === 0)
167
+		if (strpos($methName, "system.") === 0)
168 168
 		{
169
-			$dmap=$GLOBALS['_xmlrpcs_dmap']; $sysCall=1;
169
+			$dmap = $GLOBALS['_xmlrpcs_dmap']; $sysCall = 1;
170 170
 		}
171 171
 		else
172 172
 		{
173
-			$dmap=$server->dmap; $sysCall=0;
173
+			$dmap = $server->dmap; $sysCall = 0;
174 174
 		}
175
-		if(isset($dmap[$methName]))
175
+		if (isset($dmap[$methName]))
176 176
 		{
177
-			if(isset($dmap[$methName]['docstring']))
177
+			if (isset($dmap[$methName]['docstring']))
178 178
 			{
179
-				$r=new xmlrpcresp(new xmlrpcval($dmap[$methName]['docstring']), 'string');
179
+				$r = new xmlrpcresp(new xmlrpcval($dmap[$methName]['docstring']), 'string');
180 180
 			}
181 181
 			else
182 182
 			{
183
-				$r=new xmlrpcresp(new xmlrpcval('', 'string'));
183
+				$r = new xmlrpcresp(new xmlrpcval('', 'string'));
184 184
 			}
185 185
 		}
186 186
 		else
187 187
 		{
188
-			$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
188
+			$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['introspect_unknown'], $GLOBALS['xmlrpcstr']['introspect_unknown']);
189 189
 		}
190 190
 		return $r;
191 191
 	}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	$_xmlrpcs_multicall_sdoc = array(array('list of response structs, where each struct has the usual members', 'list of calls, with each call being represented as a struct, with members "methodname" and "params"'));
196 196
 	function _xmlrpcs_multicall_error($err)
197 197
 	{
198
-		if(is_string($err))
198
+		if (is_string($err))
199 199
 		{
200 200
 			$str = $GLOBALS['xmlrpcstr']["multicall_${err}"];
201 201
 			$code = $GLOBALS['xmlrpcerr']["multicall_${err}"];
@@ -213,52 +213,52 @@  discard block
 block discarded – undo
213 213
 
214 214
 	function _xmlrpcs_multicall_do_call($server, $call)
215 215
 	{
216
-		if($call->kindOf() != 'struct')
216
+		if ($call->kindOf() != 'struct')
217 217
 		{
218 218
 			return _xmlrpcs_multicall_error('notstruct');
219 219
 		}
220 220
 		$methName = @$call->structmem('methodName');
221
-		if(!$methName)
221
+		if (!$methName)
222 222
 		{
223 223
 			return _xmlrpcs_multicall_error('nomethod');
224 224
 		}
225
-		if($methName->kindOf() != 'scalar' || $methName->scalartyp() != 'string')
225
+		if ($methName->kindOf() != 'scalar' || $methName->scalartyp() != 'string')
226 226
 		{
227 227
 			return _xmlrpcs_multicall_error('notstring');
228 228
 		}
229
-		if($methName->scalarval() == 'system.multicall')
229
+		if ($methName->scalarval() == 'system.multicall')
230 230
 		{
231 231
 			return _xmlrpcs_multicall_error('recursion');
232 232
 		}
233 233
 
234 234
 		$params = @$call->structmem('params');
235
-		if(!$params)
235
+		if (!$params)
236 236
 		{
237 237
 			return _xmlrpcs_multicall_error('noparams');
238 238
 		}
239
-		if($params->kindOf() != 'array')
239
+		if ($params->kindOf() != 'array')
240 240
 		{
241 241
 			return _xmlrpcs_multicall_error('notarray');
242 242
 		}
243 243
 		$numParams = $params->arraysize();
244 244
 
245 245
 		$msg = new xmlrpcmsg($methName->scalarval());
246
-		for($i = 0; $i < $numParams; $i++)
246
+		for ($i = 0; $i<$numParams; $i++)
247 247
 		{
248
-			if(!$msg->addParam($params->arraymem($i)))
248
+			if (!$msg->addParam($params->arraymem($i)))
249 249
 			{
250 250
 				$i++;
251 251
 				return _xmlrpcs_multicall_error(new xmlrpcresp(0,
252 252
 					$GLOBALS['xmlrpcerr']['incorrect_params'],
253
-					$GLOBALS['xmlrpcstr']['incorrect_params'] . ": probable xml error in param " . $i));
253
+					$GLOBALS['xmlrpcstr']['incorrect_params'].": probable xml error in param ".$i));
254 254
 			}
255 255
 		}
256 256
 
257 257
 		$result = $server->execute($msg);
258 258
 
259
-		if($result->faultCode() != 0)
259
+		if ($result->faultCode() != 0)
260 260
 		{
261
-			return _xmlrpcs_multicall_error($result);		// Method returned fault.
261
+			return _xmlrpcs_multicall_error($result); // Method returned fault.
262 262
 		}
263 263
 
264 264
 		return new xmlrpcval(array($result->value()), 'array');
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
266 266
 
267 267
 	function _xmlrpcs_multicall_do_call_phpvals($server, $call)
268 268
 	{
269
-		if(!is_array($call))
269
+		if (!is_array($call))
270 270
 		{
271 271
 			return _xmlrpcs_multicall_error('notstruct');
272 272
 		}
273
-		if(!array_key_exists('methodName', $call))
273
+		if (!array_key_exists('methodName', $call))
274 274
 		{
275 275
 			return _xmlrpcs_multicall_error('nomethod');
276 276
 		}
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
 		{
279 279
 			return _xmlrpcs_multicall_error('notstring');
280 280
 		}
281
-		if($call['methodName'] == 'system.multicall')
281
+		if ($call['methodName'] == 'system.multicall')
282 282
 		{
283 283
 			return _xmlrpcs_multicall_error('recursion');
284 284
 		}
285
-		if(!array_key_exists('params', $call))
285
+		if (!array_key_exists('params', $call))
286 286
 		{
287 287
 			return _xmlrpcs_multicall_error('noparams');
288 288
 		}
289
-		if(!is_array($call['params']))
289
+		if (!is_array($call['params']))
290 290
 		{
291 291
 			return _xmlrpcs_multicall_error('notarray');
292 292
 		}
@@ -295,14 +295,14 @@  discard block
 block discarded – undo
295 295
 		// base64 or datetime values, but they will be listed as strings here...
296 296
 		$numParams = count($call['params']);
297 297
 		$pt = array();
298
-		foreach($call['params'] as $val)
298
+		foreach ($call['params'] as $val)
299 299
 			$pt[] = php_2_xmlrpc_type(gettype($val));
300 300
 
301 301
 		$result = $server->execute($call['methodName'], $call['params'], $pt);
302 302
 
303
-		if($result->faultCode() != 0)
303
+		if ($result->faultCode() != 0)
304 304
 		{
305
-			return _xmlrpcs_multicall_error($result);		// Method returned fault.
305
+			return _xmlrpcs_multicall_error($result); // Method returned fault.
306 306
 		}
307 307
 
308 308
 		return new xmlrpcval(array($result->value()), 'array');
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		{
317 317
 			$calls = $m->getParam(0);
318 318
 			$numCalls = $calls->arraysize();
319
-			for($i = 0; $i < $numCalls; $i++)
319
+			for ($i = 0; $i<$numCalls; $i++)
320 320
 			{
321 321
 				$call = $calls->arraymem($i);
322 322
 				$result[$i] = _xmlrpcs_multicall_do_call($server, $call);
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
 		}
325 325
 		else
326 326
 		{
327
-			$numCalls=count($m);
328
-			for($i = 0; $i < $numCalls; $i++)
327
+			$numCalls = count($m);
328
+			for ($i = 0; $i<$numCalls; $i++)
329 329
 			{
330 330
 				$result[$i] = _xmlrpcs_multicall_do_call_phpvals($server, $m[$i]);
331 331
 			}
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 		return new xmlrpcresp(new xmlrpcval($result, 'array'));
335 335
 	}
336 336
 
337
-	$GLOBALS['_xmlrpcs_dmap']=array(
337
+	$GLOBALS['_xmlrpcs_dmap'] = array(
338 338
 		'system.listMethods' => array(
339 339
 			'function' => '_xmlrpcs_listMethods',
340 340
 			'signature' => $_xmlrpcs_listMethods_sig,
@@ -374,24 +374,24 @@  discard block
 block discarded – undo
374 374
 	* NB: in fact a user defined error handler can only handle WARNING, NOTICE and USER_* errors.
375 375
 	*
376 376
 	*/
377
-	function _xmlrpcs_errorHandler($errcode, $errstring, $filename=null, $lineno=null, $context=null)
377
+	function _xmlrpcs_errorHandler($errcode, $errstring, $filename = null, $lineno = null, $context = null)
378 378
 	{
379 379
 		// obey the @ protocol
380 380
 		if (error_reporting() == 0)
381 381
 			return;
382 382
 
383 383
 		//if($errcode != E_NOTICE && $errcode != E_WARNING && $errcode != E_USER_NOTICE && $errcode != E_USER_WARNING)
384
-		if($errcode != E_STRICT)
384
+		if ($errcode != E_STRICT)
385 385
 		{
386
-			$GLOBALS['_xmlrpcs_occurred_errors'] = $GLOBALS['_xmlrpcs_occurred_errors'] . $errstring . "\n";
386
+			$GLOBALS['_xmlrpcs_occurred_errors'] = $GLOBALS['_xmlrpcs_occurred_errors'].$errstring."\n";
387 387
 		}
388 388
 		// Try to avoid as much as possible disruption to the previous error handling
389 389
 		// mechanism in place
390
-		if($GLOBALS['_xmlrpcs_prev_ehandler'] == '')
390
+		if ($GLOBALS['_xmlrpcs_prev_ehandler'] == '')
391 391
 		{
392 392
 			// The previous error handler was the default: all we should do is log error
393 393
 			// to the default error log (if level high enough)
394
-			if(ini_get('log_errors') && (intval(ini_get('error_reporting')) & $errcode))
394
+			if (ini_get('log_errors') && (intval(ini_get('error_reporting')) & $errcode))
395 395
 			{
396 396
 				error_log($errstring);
397 397
 			}
@@ -399,10 +399,10 @@  discard block
 block discarded – undo
399 399
 		else
400 400
 		{
401 401
 			// Pass control on to previous error handler, trying to avoid loops...
402
-			if($GLOBALS['_xmlrpcs_prev_ehandler'] != '_xmlrpcs_errorHandler')
402
+			if ($GLOBALS['_xmlrpcs_prev_ehandler'] != '_xmlrpcs_errorHandler')
403 403
 			{
404 404
 				// NB: this code will NOT work on php < 4.0.2: only 2 params were used for error handlers
405
-				if(is_array($GLOBALS['_xmlrpcs_prev_ehandler']))
405
+				if (is_array($GLOBALS['_xmlrpcs_prev_ehandler']))
406 406
 				{
407 407
 					// the following works both with static class methods and plain object methods as error handler
408 408
 					call_user_func_array($GLOBALS['_xmlrpcs_prev_ehandler'], array($errcode, $errstring, $filename, $lineno, $context));
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 		}
416 416
 	}
417 417
 
418
-	$GLOBALS['_xmlrpc_debuginfo']='';
418
+	$GLOBALS['_xmlrpc_debuginfo'] = '';
419 419
 
420 420
 	/**
421 421
 	* Add a string to the debug info that can be later seralized by the server
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 	*/
428 428
 	function xmlrpc_debugmsg($m)
429 429
 	{
430
-		$GLOBALS['_xmlrpc_debuginfo'] .= $m . "\n";
430
+		$GLOBALS['_xmlrpc_debuginfo'] .= $m."\n";
431 431
 	}
432 432
 
433 433
 	class xmlrpc_server
@@ -436,20 +436,20 @@  discard block
 block discarded – undo
436 436
 		* Array defining php functions exposed as xmlrpc methods by this server
437 437
 		* @access private
438 438
 		*/
439
-		var $dmap=array();
439
+		var $dmap = array();
440 440
 		/**
441 441
 		* Defines how functions in dmap will be invoked: either using an xmlrpc msg object
442 442
 		* or plain php values.
443 443
 		* valid strings are 'xmlrpcvals', 'phpvals' or 'epivals'
444 444
 		*/
445
-		var $functions_parameters_type='xmlrpcvals';
445
+		var $functions_parameters_type = 'xmlrpcvals';
446 446
 		/**
447 447
 		* Option used for fine-tuning the encoding the php values returned from
448 448
 		* functions registered in the dispatch map when the functions_parameters_types
449 449
 		* member is set to 'phpvals'
450 450
 		* @see php_xmlrpc_encode for a list of values
451 451
 		*/
452
-		var $phpvals_encoding_options = array( 'auto_dates' );
452
+		var $phpvals_encoding_options = array('auto_dates');
453 453
 		/// controls whether the server is going to echo debugging messages back to the client as comments in response body. valid values: 0,1,2,3
454 454
 		var $debug = 1;
455 455
 		/**
@@ -497,11 +497,11 @@  discard block
 block discarded – undo
497 497
 		* @param array $dispmap the dispatch map with definition of exposed services
498 498
 		* @param boolean $servicenow set to false to prevent the server from running upon construction
499 499
 		*/
500
-		function __construct($dispMap=null, $serviceNow=true)
500
+		function __construct($dispMap = null, $serviceNow = true)
501 501
 		{
502 502
 			// if ZLIB is enabled, let the server by default accept compressed requests,
503 503
 			// and compress responses sent to clients that support them
504
-			if(function_exists('gzinflate'))
504
+			if (function_exists('gzinflate'))
505 505
 			{
506 506
 				$this->accepted_compression = array('gzip', 'deflate');
507 507
 				$this->compress_response = true;
@@ -519,10 +519,10 @@  discard block
 block discarded – undo
519 519
 			 * instead, you can use the class add_to_map() function
520 520
 			 * to add functions manually (borrowed from SOAPX4)
521 521
 			 */
522
-			if($dispMap)
522
+			if ($dispMap)
523 523
 			{
524 524
 				$this->dmap = $dispMap;
525
-				if($serviceNow)
525
+				if ($serviceNow)
526 526
 				{
527 527
 					$this->service();
528 528
 				}
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 		/**
533 533
 		* @deprecated
534 534
 		*/
535
-		function xmlrpc_client($dispMap=null, $serviceNow=true)
535
+		function xmlrpc_client($dispMap = null, $serviceNow = true)
536 536
 		{
537 537
 			self::__construct($dispMap, $serviceNow);
538 538
 		}
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 		*/
554 554
 		function setDebug($in)
555 555
 		{
556
-			$this->debug=$in;
556
+			$this->debug = $in;
557 557
 		}
558 558
 
559 559
 		/**
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 		* @param string $charset_encoding the target charset encoding for the serialization
562 562
 		* @return string an XML comment (or two)
563 563
 		*/
564
-		function serializeDebug($charset_encoding='')
564
+		function serializeDebug($charset_encoding = '')
565 565
 		{
566 566
 			// Tough encoding problem: which internal charset should we assume for debug info?
567 567
 			// It might contain a copy of raw data received from client, ie with unknown encoding,
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
 			{
574 574
 				$out .= "<!-- SERVER DEBUG INFO (BASE64 ENCODED):\n".base64_encode($this->debug_info)."\n-->\n";
575 575
 			}
576
-			if($GLOBALS['_xmlrpc_debuginfo']!='')
576
+			if ($GLOBALS['_xmlrpc_debuginfo'] != '')
577 577
 			{
578 578
 
579
-				$out .= "<!-- DEBUG INFO:\n" . xmlrpc_encode_entitites(str_replace('--', '_-', $GLOBALS['_xmlrpc_debuginfo']), $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "\n-->\n";
579
+				$out .= "<!-- DEBUG INFO:\n".xmlrpc_encode_entitites(str_replace('--', '_-', $GLOBALS['_xmlrpc_debuginfo']), $GLOBALS['xmlrpc_internalencoding'], $charset_encoding)."\n-->\n";
580 580
 				// NB: a better solution MIGHT be to use CDATA, but we need to insert it
581 581
 				// into return payload AFTER the beginning tag
582 582
 				//$out .= "<![CDATA[ DEBUG INFO:\n\n" . str_replace(']]>', ']_]_>', $GLOBALS['_xmlrpc_debuginfo']) . "\n]]>\n";
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 		* @return xmlrpcresp the response object (usually not used by caller...)
591 591
 		* @access public
592 592
 		*/
593
-		function service($data=null, $return_payload=false)
593
+		function service($data = null, $return_payload = false)
594 594
 		{
595 595
 			if ($data === null)
596 596
 			{
@@ -603,30 +603,30 @@  discard block
 block discarded – undo
603 603
 			$this->debug_info = '';
604 604
 
605 605
 			// Echo back what we received, before parsing it
606
-			if($this->debug > 1)
606
+			if ($this->debug>1)
607 607
 			{
608
-				$this->debugmsg("+++GOT+++\n" . $data . "\n+++END+++");
608
+				$this->debugmsg("+++GOT+++\n".$data."\n+++END+++");
609 609
 			}
610 610
 
611 611
 			$r = $this->parseRequestHeaders($data, $req_charset, $resp_charset, $resp_encoding);
612 612
 			if (!$r)
613 613
 			{
614
-				$r=$this->parseRequest($data, $req_charset);
614
+				$r = $this->parseRequest($data, $req_charset);
615 615
 			}
616 616
 
617 617
 			// save full body of request into response, for more debugging usages
618 618
 			$r->raw_data = $raw_data;
619 619
 
620
-			if($this->debug > 2 && $GLOBALS['_xmlrpcs_occurred_errors'])
620
+			if ($this->debug>2 && $GLOBALS['_xmlrpcs_occurred_errors'])
621 621
 			{
622
-				$this->debugmsg("+++PROCESSING ERRORS AND WARNINGS+++\n" .
623
-					$GLOBALS['_xmlrpcs_occurred_errors'] . "+++END+++");
622
+				$this->debugmsg("+++PROCESSING ERRORS AND WARNINGS+++\n".
623
+					$GLOBALS['_xmlrpcs_occurred_errors']."+++END+++");
624 624
 			}
625 625
 
626
-			$payload=$this->xml_header($resp_charset);
627
-			if($this->debug > 0)
626
+			$payload = $this->xml_header($resp_charset);
627
+			if ($this->debug>0)
628 628
 			{
629
-				$payload = $payload . $this->serializeDebug($resp_charset);
629
+				$payload = $payload.$this->serializeDebug($resp_charset);
630 630
 			}
631 631
 
632 632
 			// G. Giunta 2006-01-27: do not create response serialization if it has
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 			{
636 636
 				$r->serialize($resp_charset);
637 637
 			}
638
-			$payload = $payload . $r->payload;
638
+			$payload = $payload.$r->payload;
639 639
 
640 640
 			if ($return_payload)
641 641
 			{
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 
645 645
 			// if we get a warning/error that has output some text before here, then we cannot
646 646
 			// add a new header. We cannot say we are sending xml, either...
647
-			if(!headers_sent())
647
+			if (!headers_sent())
648 648
 			{
649 649
 				header('Content-Type: '.$r->content_type);
650 650
 				// we do not know if client actually told us an accepted charset, but if he did
@@ -655,10 +655,10 @@  discard block
 block discarded – undo
655 655
 				// if we can do it, and we want to do it, and client asked us to,
656 656
 				// and php ini settings do not force it already
657 657
 				$php_no_self_compress = !ini_get('zlib.output_compression') && (ini_get('output_handler') != 'ob_gzhandler');
658
-				if($this->compress_response && function_exists('gzencode') && $resp_encoding != ''
658
+				if ($this->compress_response && function_exists('gzencode') && $resp_encoding != ''
659 659
 					&& $php_no_self_compress)
660 660
 				{
661
-					if(strpos($resp_encoding, 'gzip') !== false)
661
+					if (strpos($resp_encoding, 'gzip') !== false)
662 662
 					{
663 663
 						$payload = gzencode($payload);
664 664
 						header("Content-Encoding: gzip");
@@ -674,9 +674,9 @@  discard block
 block discarded – undo
674 674
 
675 675
 				// do not ouput content-length header if php is compressing output for us:
676 676
 				// it will mess up measurements
677
-				if($php_no_self_compress)
677
+				if ($php_no_self_compress)
678 678
 				{
679
-					header('Content-Length: ' . (int)strlen($payload));
679
+					header('Content-Length: '.(int) strlen($payload));
680 680
 				}
681 681
 			}
682 682
 			else
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
 		* @param array $sigdoc the array of valid method signatures docs (one string per param, one for return type)
700 700
 		* @access public
701 701
 		*/
702
-		function add_to_map($methodname,$function,$sig=null,$doc=false,$sigdoc=false)
702
+		function add_to_map($methodname, $function, $sig = null, $doc = false, $sigdoc = false)
703 703
 		{
704 704
 			$this->dmap[$methodname] = array(
705 705
 				'function'	=> $function,
@@ -733,47 +733,47 @@  discard block
 block discarded – undo
733 733
 			{
734 734
 				$numParams = count($in);
735 735
 			}
736
-			foreach($sig as $cursig)
736
+			foreach ($sig as $cursig)
737 737
 			{
738
-				if(count($cursig)==$numParams+1)
738
+				if (count($cursig) == $numParams+1)
739 739
 				{
740
-					$itsOK=1;
741
-					for($n=0; $n<$numParams; $n++)
740
+					$itsOK = 1;
741
+					for ($n = 0; $n<$numParams; $n++)
742 742
 					{
743 743
 						if (is_object($in))
744 744
 						{
745
-							$p=$in->getParam($n);
746
-							if($p->kindOf() == 'scalar')
745
+							$p = $in->getParam($n);
746
+							if ($p->kindOf() == 'scalar')
747 747
 							{
748
-								$pt=$p->scalartyp();
748
+								$pt = $p->scalartyp();
749 749
 							}
750 750
 							else
751 751
 							{
752
-								$pt=$p->kindOf();
752
+								$pt = $p->kindOf();
753 753
 							}
754 754
 						}
755 755
 						else
756 756
 						{
757
-							$pt= $in[$n] == 'i4' ? 'int' : strtolower($in[$n]); // dispatch maps never use i4...
757
+							$pt = $in[$n] == 'i4' ? 'int' : strtolower($in[$n]); // dispatch maps never use i4...
758 758
 						}
759 759
 
760 760
 						// param index is $n+1, as first member of sig is return type
761
-						if($pt != $cursig[$n+1] && $cursig[$n+1] != $GLOBALS['xmlrpcValue'])
761
+						if ($pt != $cursig[$n+1] && $cursig[$n+1] != $GLOBALS['xmlrpcValue'])
762 762
 						{
763
-							$itsOK=0;
764
-							$pno=$n+1;
765
-							$wanted=$cursig[$n+1];
766
-							$got=$pt;
763
+							$itsOK = 0;
764
+							$pno = $n+1;
765
+							$wanted = $cursig[$n+1];
766
+							$got = $pt;
767 767
 							break;
768 768
 						}
769 769
 					}
770
-					if($itsOK)
770
+					if ($itsOK)
771 771
 					{
772
-						return array(1,'');
772
+						return array(1, '');
773 773
 					}
774 774
 				}
775 775
 			}
776
-			if(isset($wanted))
776
+			if (isset($wanted))
777 777
 			{
778 778
 				return array(0, "Wanted ${wanted}, got ${got} at param ${pno}");
779 779
 			}
@@ -797,12 +797,12 @@  discard block
 block discarded – undo
797 797
 				error_log('XML-RPC: '.__METHOD__.': cannot parse request headers as $_SERVER is not populated');
798 798
 			}
799 799
 
800
-			if($this->debug > 1)
800
+			if ($this->debug>1)
801 801
 			{
802
-				if(function_exists('getallheaders'))
802
+				if (function_exists('getallheaders'))
803 803
 				{
804 804
 					$this->debugmsg(''); // empty line
805
-					foreach(getallheaders() as $name => $val)
805
+					foreach (getallheaders() as $name => $val)
806 806
 					{
807 807
 						$this->debugmsg("HEADER: $name: $val");
808 808
 					}
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 
811 811
 			}
812 812
 
813
-			if(isset($_SERVER['HTTP_CONTENT_ENCODING']))
813
+			if (isset($_SERVER['HTTP_CONTENT_ENCODING']))
814 814
 			{
815 815
 				$content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']);
816 816
 			}
@@ -820,26 +820,26 @@  discard block
 block discarded – undo
820 820
 			}
821 821
 
822 822
 			// check if request body has been compressed and decompress it
823
-			if($content_encoding != '' && strlen($data))
823
+			if ($content_encoding != '' && strlen($data))
824 824
 			{
825
-				if($content_encoding == 'deflate' || $content_encoding == 'gzip')
825
+				if ($content_encoding == 'deflate' || $content_encoding == 'gzip')
826 826
 				{
827 827
 					// if decoding works, use it. else assume data wasn't gzencoded
828
-					if(function_exists('gzinflate') && in_array($content_encoding, $this->accepted_compression))
828
+					if (function_exists('gzinflate') && in_array($content_encoding, $this->accepted_compression))
829 829
 					{
830
-						if($content_encoding == 'deflate' && $degzdata = @gzuncompress($data))
830
+						if ($content_encoding == 'deflate' && $degzdata = @gzuncompress($data))
831 831
 						{
832 832
 							$data = $degzdata;
833
-							if($this->debug > 1)
833
+							if ($this->debug>1)
834 834
 							{
835
-								$this->debugmsg("\n+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
835
+								$this->debugmsg("\n+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n".$data."\n+++END+++");
836 836
 							}
837 837
 						}
838
-						elseif($content_encoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
838
+						elseif ($content_encoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
839 839
 						{
840 840
 							$data = $degzdata;
841
-							if($this->debug > 1)
842
-								$this->debugmsg("+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n" . $data . "\n+++END+++");
841
+							if ($this->debug>1)
842
+								$this->debugmsg("+++INFLATED REQUEST+++[".strlen($data)." chars]+++\n".$data."\n+++END+++");
843 843
 						}
844 844
 						else
845 845
 						{
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
 		* @return xmlrpcresp
913 913
 		* @access private
914 914
 		*/
915
-		function parseRequest($data, $req_encoding='')
915
+		function parseRequest($data, $req_encoding = '')
916 916
 		{
917 917
 			// 2005/05/07 commented and moved into caller function code
918 918
 			//if($data=='')
@@ -924,16 +924,16 @@  discard block
 block discarded – undo
924 924
 			// so we do not try to convert them into xml character entities
925 925
 			//$data = xmlrpc_html_entity_xlate($data);
926 926
 
927
-			$GLOBALS['_xh']=array();
928
-			$GLOBALS['_xh']['ac']='';
929
-			$GLOBALS['_xh']['stack']=array();
927
+			$GLOBALS['_xh'] = array();
928
+			$GLOBALS['_xh']['ac'] = '';
929
+			$GLOBALS['_xh']['stack'] = array();
930 930
 			$GLOBALS['_xh']['valuestack'] = array();
931
-			$GLOBALS['_xh']['params']=array();
932
-			$GLOBALS['_xh']['pt']=array();
933
-			$GLOBALS['_xh']['isf']=0;
934
-			$GLOBALS['_xh']['isf_reason']='';
935
-			$GLOBALS['_xh']['method']=false; // so we can check later if we got a methodname or not
936
-			$GLOBALS['_xh']['rt']='';
931
+			$GLOBALS['_xh']['params'] = array();
932
+			$GLOBALS['_xh']['pt'] = array();
933
+			$GLOBALS['_xh']['isf'] = 0;
934
+			$GLOBALS['_xh']['isf_reason'] = '';
935
+			$GLOBALS['_xh']['method'] = false; // so we can check later if we got a methodname or not
936
+			$GLOBALS['_xh']['rt'] = '';
937 937
 
938 938
 			// decompose incoming XML into request structure
939 939
 
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
 						if (extension_loaded('mbstring')) {
952 952
 							$data = mb_convert_encoding($data, 'UTF-8', $req_encoding);
953 953
 						} else {
954
-							error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $req_encoding);
954
+							error_log('XML-RPC: '.__METHOD__.': invalid charset encoding of received request: '.$req_encoding);
955 955
 						}
956 956
 					}
957 957
 				}
@@ -980,10 +980,10 @@  discard block
 block discarded – undo
980 980
 				xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
981 981
 			xml_set_character_data_handler($parser, 'xmlrpc_cd');
982 982
 			xml_set_default_handler($parser, 'xmlrpc_dh');
983
-			if(!xml_parse($parser, $data, 1))
983
+			if (!xml_parse($parser, $data, 1))
984 984
 			{
985 985
 				// return XML error as a faultCode
986
-				$r=new xmlrpcresp(0,
986
+				$r = new xmlrpcresp(0,
987 987
 				$GLOBALS['xmlrpcerrxml']+xml_get_error_code($parser),
988 988
 				sprintf('XML error: %s at line %d, column %d',
989 989
 					xml_error_string(xml_get_error_code($parser)),
@@ -993,9 +993,9 @@  discard block
 block discarded – undo
993 993
 			elseif ($GLOBALS['_xh']['isf'])
994 994
 			{
995 995
 				xml_parser_free($parser);
996
-				$r=new xmlrpcresp(0,
996
+				$r = new xmlrpcresp(0,
997 997
 					$GLOBALS['xmlrpcerr']['invalid_request'],
998
-					$GLOBALS['xmlrpcstr']['invalid_request'] . ' ' . $GLOBALS['_xh']['isf_reason']);
998
+					$GLOBALS['xmlrpcstr']['invalid_request'].' '.$GLOBALS['_xh']['isf_reason']);
999 999
 			}
1000 1000
 			else
1001 1001
 			{
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
 				// registered as phpvals) that would mean a useless encode+decode pass
1007 1007
 				if ($this->functions_parameters_type != 'xmlrpcvals' || (isset($this->dmap[$GLOBALS['_xh']['method']]['parameters_type']) && ($this->dmap[$GLOBALS['_xh']['method']]['parameters_type'] == 'phpvals')))
1008 1008
 				{
1009
-					if($this->debug > 1)
1009
+					if ($this->debug>1)
1010 1010
 					{
1011 1011
 						$this->debugmsg("\n+++PARSED+++\n".var_export($GLOBALS['_xh']['params'], true)."\n+++END+++");
1012 1012
 					}
@@ -1015,14 +1015,14 @@  discard block
 block discarded – undo
1015 1015
 				else
1016 1016
 				{
1017 1017
 					// build an xmlrpcmsg object with data parsed from xml
1018
-					$m=new xmlrpcmsg($GLOBALS['_xh']['method']);
1018
+					$m = new xmlrpcmsg($GLOBALS['_xh']['method']);
1019 1019
 					// now add parameters in
1020
-					for($i=0; $i<count($GLOBALS['_xh']['params']); $i++)
1020
+					for ($i = 0; $i<count($GLOBALS['_xh']['params']); $i++)
1021 1021
 					{
1022 1022
 						$m->addParam($GLOBALS['_xh']['params'][$i]);
1023 1023
 					}
1024 1024
 
1025
-					if($this->debug > 1)
1025
+					if ($this->debug>1)
1026 1026
 					{
1027 1027
 						$this->debugmsg("\n+++PARSED+++\n".var_export($m, true)."\n+++END+++");
1028 1028
 					}
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
 		* @return xmlrpcresp
1041 1041
 		* @access private
1042 1042
 		*/
1043
-		function execute($m, $params=null, $paramtypes=null)
1043
+		function execute($m, $params = null, $paramtypes = null)
1044 1044
 		{
1045 1045
 			if (is_object($m))
1046 1046
 			{
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
 			$sysCall = $this->allow_system_funcs && (strpos($methName, "system.") === 0);
1054 1054
 			$dmap = $sysCall ? $GLOBALS['_xmlrpcs_dmap'] : $this->dmap;
1055 1055
 
1056
-			if(!isset($dmap[$methName]['function']))
1056
+			if (!isset($dmap[$methName]['function']))
1057 1057
 			{
1058 1058
 				// No such method
1059 1059
 				return new xmlrpcresp(0,
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
 			}
1063 1063
 
1064 1064
 			// Check signature
1065
-			if(isset($dmap[$methName]['signature']))
1065
+			if (isset($dmap[$methName]['signature']))
1066 1066
 			{
1067 1067
 				$sig = $dmap[$methName]['signature'];
1068 1068
 				if (is_object($m))
@@ -1073,37 +1073,37 @@  discard block
 block discarded – undo
1073 1073
 				{
1074 1074
 					list($ok, $errstr) = $this->verifySignature($paramtypes, $sig);
1075 1075
 				}
1076
-				if(!$ok)
1076
+				if (!$ok)
1077 1077
 				{
1078 1078
 					// Didn't match.
1079 1079
 					return new xmlrpcresp(
1080 1080
 						0,
1081 1081
 						$GLOBALS['xmlrpcerr']['incorrect_params'],
1082
-						$GLOBALS['xmlrpcstr']['incorrect_params'] . ": ${errstr}"
1082
+						$GLOBALS['xmlrpcstr']['incorrect_params'].": ${errstr}"
1083 1083
 					);
1084 1084
 				}
1085 1085
 			}
1086 1086
 
1087 1087
 			$func = $dmap[$methName]['function'];
1088 1088
 			// let the 'class::function' syntax be accepted in dispatch maps
1089
-			if(is_string($func) && strpos($func, '::'))
1089
+			if (is_string($func) && strpos($func, '::'))
1090 1090
 			{
1091 1091
 				$func = explode('::', $func);
1092 1092
 			}
1093 1093
 			// verify that function to be invoked is in fact callable
1094
-			if(!is_callable($func))
1094
+			if (!is_callable($func))
1095 1095
 			{
1096 1096
 				error_log("XML-RPC: ".__METHOD__.": function $func registered as method handler is not callable");
1097 1097
 				return new xmlrpcresp(
1098 1098
 					0,
1099 1099
 					$GLOBALS['xmlrpcerr']['server_error'],
1100
-					$GLOBALS['xmlrpcstr']['server_error'] . ": no function matches method"
1100
+					$GLOBALS['xmlrpcstr']['server_error'].": no function matches method"
1101 1101
 				);
1102 1102
 			}
1103 1103
 
1104 1104
 			// If debug level is 3, we should catch all errors generated during
1105 1105
 			// processing of user function, and log them as part of response
1106
-			if($this->debug > 2)
1106
+			if ($this->debug>2)
1107 1107
 			{
1108 1108
 				$GLOBALS['_xmlrpcs_prev_ehandler'] = set_error_handler('_xmlrpcs_errorHandler');
1109 1109
 			}
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
 				// Allow mixed-convention servers
1113 1113
 				if (is_object($m))
1114 1114
 				{
1115
-					if($sysCall)
1115
+					if ($sysCall)
1116 1116
 					{
1117 1117
 						$r = call_user_func($func, $this, $m);
1118 1118
 					}
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
 							$r = new xmlrpcresp(
1133 1133
 								0,
1134 1134
 								$GLOBALS['xmlrpcerr']['server_error'],
1135
-								$GLOBALS['xmlrpcstr']['server_error'] . ": function does not return xmlrpcresp object"
1135
+								$GLOBALS['xmlrpcstr']['server_error'].": function does not return xmlrpcresp object"
1136 1136
 							);
1137 1137
 						}
1138 1138
 					}
@@ -1140,7 +1140,7 @@  discard block
 block discarded – undo
1140 1140
 				else
1141 1141
 				{
1142 1142
 					// call a 'plain php' function
1143
-					if($sysCall)
1143
+					if ($sysCall)
1144 1144
 					{
1145 1145
 						array_unshift($params, $this);
1146 1146
 						$r = call_user_func_array($func, $params);
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 							// an eror response
1156 1156
 							if (is_array($r) && array_key_exists('faultCode', $r) && array_key_exists('faultString', $r))
1157 1157
 							{
1158
-								$r = new xmlrpcresp(0, (integer)$r['faultCode'], (string)$r['faultString']);
1158
+								$r = new xmlrpcresp(0, (integer) $r['faultCode'], (string) $r['faultString']);
1159 1159
 							}
1160 1160
 							else
1161 1161
 							{
@@ -1178,11 +1178,11 @@  discard block
 block discarded – undo
1178 1178
 					}
1179 1179
 				}
1180 1180
 			}
1181
-			catch(Exception $e)
1181
+			catch (Exception $e)
1182 1182
 			{
1183 1183
 				// (barring errors in the lib) an uncatched exception happened
1184 1184
 				// in the called function, we wrap it in a proper error-response
1185
-				switch($this->exception_handling)
1185
+				switch ($this->exception_handling)
1186 1186
 				{
1187 1187
 					case 2:
1188 1188
 						throw $e;
@@ -1194,11 +1194,11 @@  discard block
 block discarded – undo
1194 1194
 						$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_error'], $GLOBALS['xmlrpcstr']['server_error']);
1195 1195
 				}
1196 1196
 			}
1197
-			if($this->debug > 2)
1197
+			if ($this->debug>2)
1198 1198
 			{
1199 1199
 				// note: restore the error handler we found before calling the
1200 1200
 				// user func, even if it has been changed inside the func itself
1201
-				if($GLOBALS['_xmlrpcs_prev_ehandler'])
1201
+				if ($GLOBALS['_xmlrpcs_prev_ehandler'])
1202 1202
 				{
1203 1203
 					set_error_handler($GLOBALS['_xmlrpcs_prev_ehandler']);
1204 1204
 				}
@@ -1223,15 +1223,15 @@  discard block
 block discarded – undo
1223 1223
 		/**
1224 1224
 		* @access private
1225 1225
 		*/
1226
-		function xml_header($charset_encoding='')
1226
+		function xml_header($charset_encoding = '')
1227 1227
 		{
1228 1228
 			if ($charset_encoding != '')
1229 1229
 			{
1230
-				return "<?xml version=\"1.0\" encoding=\"$charset_encoding\"?" . ">\n";
1230
+				return "<?xml version=\"1.0\" encoding=\"$charset_encoding\"?".">\n";
1231 1231
 			}
1232 1232
 			else
1233 1233
 			{
1234
-				return "<?xml version=\"1.0\"?" . ">\n";
1234
+				return "<?xml version=\"1.0\"?".">\n";
1235 1235
 			}
1236 1236
 		}
1237 1237
 
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
 		*/
1242 1242
 		function echoInput()
1243 1243
 		{
1244
-			$r=new xmlrpcresp(new xmlrpcval( "'Aha said I: '" . $GLOBALS['HTTP_RAW_POST_DATA'], 'string'));
1244
+			$r = new xmlrpcresp(new xmlrpcval("'Aha said I: '".$GLOBALS['HTTP_RAW_POST_DATA'], 'string'));
1245 1245
 			print $r->serialize();
1246 1246
 		}
1247 1247
 	}
Please login to merge, or discard this patch.
lib/xmlrpc.inc 4 patches
Braces   +176 added lines, -250 removed lines patch added patch discarded remove patch
@@ -403,14 +403,12 @@  discard block
 block discarded – undo
403 403
 					$GLOBALS['_xh']['isf'] = 2;
404 404
 					$GLOBALS['_xh']['isf_reason'] = 'missing top level xmlrpc element';
405 405
 					return;
406
-				}
407
-				else
406
+				} else
408 407
 				{
409 408
 					$GLOBALS['_xh']['rt'] = strtolower($name);
410 409
 					$GLOBALS['_xh']['rt'] = strtolower($name);
411 410
 				}
412
-			}
413
-			else
411
+			} else
414 412
 			{
415 413
 				// not top level element: see if parent is OK
416 414
 				$parent = end($GLOBALS['_xh']['stack']);
@@ -566,21 +564,20 @@  discard block
 block discarded – undo
566 564
 						$temp = new xmlrpcval($GLOBALS['_xh']['value'], $GLOBALS['_xh']['vt']);
567 565
 						// in case we got info about underlying php class, save it
568 566
 						// in the object we're rebuilding
569
-						if (isset($GLOBALS['_xh']['php_class']))
570
-							$temp->_php_class = $GLOBALS['_xh']['php_class'];
567
+						if (isset($GLOBALS['_xh']['php_class'])) {
568
+													$temp->_php_class = $GLOBALS['_xh']['php_class'];
569
+						}
571 570
 						// check if we are inside an array or struct:
572 571
 						// if value just built is inside an array, let's move it into array on the stack
573 572
 						$vscount = count($GLOBALS['_xh']['valuestack']);
574 573
 						if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type']=='ARRAY')
575 574
 						{
576 575
 							$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][] = $temp;
577
-						}
578
-						else
576
+						} else
579 577
 						{
580 578
 							$GLOBALS['_xh']['value'] = $temp;
581 579
 						}
582
-					}
583
-					else
580
+					} else
584 581
 					{
585 582
 						/// @todo this needs to treat correctly php-serialized objects,
586 583
 						/// since std deserializing is done by php_xmlrpc_decode,
@@ -611,8 +608,7 @@  discard block
 block discarded – undo
611 608
 					if ($name=='STRING')
612 609
 					{
613 610
 						$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
614
-					}
615
-					elseif ($name=='DATETIME.ISO8601')
611
+					} elseif ($name=='DATETIME.ISO8601')
616 612
 					{
617 613
 						if (!preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $GLOBALS['_xh']['ac']))
618 614
 						{
@@ -620,13 +616,11 @@  discard block
 block discarded – undo
620 616
 						}
621 617
 						$GLOBALS['_xh']['vt']=$GLOBALS['xmlrpcDateTime'];
622 618
 						$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
623
-					}
624
-					elseif ($name=='BASE64')
619
+					} elseif ($name=='BASE64')
625 620
 					{
626 621
 						/// @todo check for failure of base64 decoding / catch warnings
627 622
 						$GLOBALS['_xh']['value']=base64_decode($GLOBALS['_xh']['ac']);
628
-					}
629
-					elseif ($name=='BOOLEAN')
623
+					} elseif ($name=='BOOLEAN')
630 624
 					{
631 625
 						// special case here: we translate boolean 1 or 0 into PHP
632 626
 						// constants true or false.
@@ -637,16 +631,15 @@  discard block
 block discarded – undo
637 631
 						if ($GLOBALS['_xh']['ac']=='1' || strcasecmp($GLOBALS['_xh']['ac'], 'true') == 0)
638 632
 						{
639 633
 							$GLOBALS['_xh']['value']=true;
640
-						}
641
-						else
634
+						} else
642 635
 						{
643 636
 							// log if receiveing something strange, even though we set the value to false anyway
644
-							if ($GLOBALS['_xh']['ac']!='0' && strcasecmp($GLOBALS['_xh']['ac'], 'false') != 0)
645
-								error_log('XML-RPC: invalid value received in BOOLEAN: '.$GLOBALS['_xh']['ac']);
637
+							if ($GLOBALS['_xh']['ac']!='0' && strcasecmp($GLOBALS['_xh']['ac'], 'false') != 0) {
638
+															error_log('XML-RPC: invalid value received in BOOLEAN: '.$GLOBALS['_xh']['ac']);
639
+							}
646 640
 							$GLOBALS['_xh']['value']=false;
647 641
 						}
648
-					}
649
-					elseif ($name=='DOUBLE')
642
+					} elseif ($name=='DOUBLE')
650 643
 					{
651 644
 						// we have a DOUBLE
652 645
 						// we must check that only 0123456789-.<space> are characters here
@@ -656,14 +649,12 @@  discard block
 block discarded – undo
656 649
 							/// @todo: find a better way of throwing an error than this!
657 650
 							error_log('XML-RPC: non numeric value received in DOUBLE: '.$GLOBALS['_xh']['ac']);
658 651
 							$GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
659
-						}
660
-						else
652
+						} else
661 653
 						{
662 654
 							// it's ok, add it on
663 655
 							$GLOBALS['_xh']['value']=(double)$GLOBALS['_xh']['ac'];
664 656
 						}
665
-					}
666
-					else
657
+					} else
667 658
 					{
668 659
 						// we have an I4/INT
669 660
 						// we must check that only 0123456789-<space> are characters here
@@ -672,8 +663,7 @@  discard block
 block discarded – undo
672 663
 							/// @todo find a better way of throwing an error than this!
673 664
 							error_log('XML-RPC: non numeric value received in INT: '.$GLOBALS['_xh']['ac']);
674 665
 							$GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
675
-						}
676
-						else
666
+						} else
677 667
 						{
678 668
 							// it's ok, add it on
679 669
 							$GLOBALS['_xh']['value']=(int)$GLOBALS['_xh']['ac'];
@@ -693,8 +683,9 @@  discard block
 block discarded – undo
693 683
 					{
694 684
 						$vscount = count($GLOBALS['_xh']['valuestack']);
695 685
 						$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][$GLOBALS['_xh']['valuestack'][$vscount-1]['name']] = $GLOBALS['_xh']['value'];
696
-					} else
697
-						error_log('XML-RPC: missing VALUE inside STRUCT in received xml');
686
+					} else {
687
+											error_log('XML-RPC: missing VALUE inside STRUCT in received xml');
688
+					}
698 689
 					break;
699 690
 				case 'DATA':
700 691
 					//$GLOBALS['_xh']['ac']=''; // is this necessary?
@@ -718,9 +709,9 @@  discard block
 block discarded – undo
718 709
 					{
719 710
 						$GLOBALS['_xh']['params'][]=$GLOBALS['_xh']['value'];
720 711
 						$GLOBALS['_xh']['pt'][]=$GLOBALS['_xh']['vt'];
721
-					}
722
-					else
723
-						error_log('XML-RPC: missing VALUE inside PARAM in received xml');
712
+					} else {
713
+											error_log('XML-RPC: missing VALUE inside PARAM in received xml');
714
+					}
724 715
 					break;
725 716
 				case 'METHODNAME':
726 717
 					$GLOBALS['_xh']['method']=preg_replace('/^[\n\r\t ]+/', '', $GLOBALS['_xh']['ac']);
@@ -916,8 +907,7 @@  discard block
 block discarded – undo
916 907
 			if($path == '' || $path[0] != '/')
917 908
 			{
918 909
 				$this->path='/'.$path;
919
-			}
920
-			else
910
+			} else
921 911
 			{
922 912
 				$this->path=$path;
923 913
 			}
@@ -998,8 +988,7 @@  discard block
 block discarded – undo
998 988
 			if ($is_dir)
999 989
 			{
1000 990
 				$this->cacertdir = $cacert;
1001
-			}
1002
-			else
991
+			} else
1003 992
 			{
1004 993
 				$this->cacert = $cacert;
1005 994
 			}
@@ -1067,13 +1056,14 @@  discard block
 block discarded – undo
1067 1056
 		*/
1068 1057
 		function setAcceptedCompression($compmethod)
1069 1058
 		{
1070
-			if ($compmethod == 'any')
1071
-				$this->accepted_compression = array('gzip', 'deflate');
1072
-			else
1073
-				if ($compmethod == false )
1074
-					$this->accepted_compression = array();
1075
-				else
1076
-					$this->accepted_compression = array($compmethod);
1059
+			if ($compmethod == 'any') {
1060
+							$this->accepted_compression = array('gzip', 'deflate');
1061
+			} else
1062
+				if ($compmethod == false ) {
1063
+									$this->accepted_compression = array();
1064
+				} else {
1065
+									$this->accepted_compression = array($compmethod);
1066
+				}
1077 1067
 		}
1078 1068
 
1079 1069
 		/**
@@ -1110,8 +1100,7 @@  discard block
 block discarded – undo
1110 1100
 				$this->cookies[$name]['domain'] = $domain;
1111 1101
 				$this->cookies[$name]['port'] = $port;
1112 1102
 				$this->cookies[$name]['version'] = 1;
1113
-			}
1114
-			else
1103
+			} else
1115 1104
 			{
1116 1105
 				$this->cookies[$name]['version'] = 0;
1117 1106
 			}
@@ -1158,8 +1147,7 @@  discard block
 block discarded – undo
1158 1147
 				// $msg is an array of xmlrpcmsg's
1159 1148
 				$r = $this->multicall($msg, $timeout, $method);
1160 1149
 				return $r;
1161
-			}
1162
-			elseif(is_string($msg))
1150
+			} elseif(is_string($msg))
1163 1151
 			{
1164 1152
 				$n = new xmlrpcmsg('');
1165 1153
 				$n->payload = $msg;
@@ -1192,8 +1180,7 @@  discard block
 block discarded – undo
1192 1180
 					$this->key,
1193 1181
 					$this->keypass
1194 1182
 				);
1195
-			}
1196
-			elseif($method == 'http11')
1183
+			} elseif($method == 'http11')
1197 1184
 			{
1198 1185
 				$r =& $this->sendPayloadCURL(
1199 1186
 					$msg,
@@ -1215,8 +1202,7 @@  discard block
 block discarded – undo
1215 1202
 					'http',
1216 1203
 					$this->keepalive
1217 1204
 				);
1218
-			}
1219
-			else
1205
+			} else
1220 1206
 			{
1221 1207
 				$r =& $this->sendPayloadHTTP10(
1222 1208
 					$msg,
@@ -1267,8 +1253,7 @@  discard block
 block discarded – undo
1267 1253
 						$payload = $a;
1268 1254
 						$encoding_hdr = "Content-Encoding: gzip\r\n";
1269 1255
 					}
1270
-				}
1271
-				else
1256
+				} else
1272 1257
 				{
1273 1258
 					$a = @gzcompress($payload);
1274 1259
 					if($a)
@@ -1277,8 +1262,7 @@  discard block
 block discarded – undo
1277 1262
 						$encoding_hdr = "Content-Encoding: deflate\r\n";
1278 1263
 					}
1279 1264
 				}
1280
-			}
1281
-			else
1265
+			} else
1282 1266
 			{
1283 1267
 				$encoding_hdr = '';
1284 1268
 			}
@@ -1318,8 +1302,7 @@  discard block
 block discarded – undo
1318 1302
 					}
1319 1303
 					$proxy_credentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyusername.':'.$proxypassword) . "\r\n";
1320 1304
 				}
1321
-			}
1322
-			else
1305
+			} else
1323 1306
 			{
1324 1307
 				$connectserver = $server;
1325 1308
 				$connectport = $port;
@@ -1338,14 +1321,16 @@  discard block
 block discarded – undo
1338 1321
 					{
1339 1322
 						$version = ' $Version="' . $cookie['version'] . '";';
1340 1323
 						$cookieheader .= ' ' . $name . '="' . $cookie['value'] . '";';
1341
-						if ($cookie['path'])
1342
-							$cookieheader .= ' $Path="' . $cookie['path'] . '";';
1343
-						if ($cookie['domain'])
1344
-							$cookieheader .= ' $Domain="' . $cookie['domain'] . '";';
1345
-						if ($cookie['port'])
1346
-							$cookieheader .= ' $Port="' . $cookie['port'] . '";';
1347
-					}
1348
-					else
1324
+						if ($cookie['path']) {
1325
+													$cookieheader .= ' $Path="' . $cookie['path'] . '";';
1326
+						}
1327
+						if ($cookie['domain']) {
1328
+													$cookieheader .= ' $Domain="' . $cookie['domain'] . '";';
1329
+						}
1330
+						if ($cookie['port']) {
1331
+													$cookieheader .= ' $Port="' . $cookie['port'] . '";';
1332
+						}
1333
+					} else
1349 1334
 					{
1350 1335
 						$cookieheader .= ' ' . $name . '=' . $cookie['value'] . ";";
1351 1336
 					}
@@ -1379,8 +1364,7 @@  discard block
 block discarded – undo
1379 1364
 			if($timeout>0)
1380 1365
 			{
1381 1366
 				$fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout);
1382
-			}
1383
-			else
1367
+			} else
1384 1368
 			{
1385 1369
 				$fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr);
1386 1370
 			}
@@ -1390,8 +1374,7 @@  discard block
 block discarded – undo
1390 1374
 				{
1391 1375
 					stream_set_timeout($fp, $timeout);
1392 1376
 				}
1393
-			}
1394
-			else
1377
+			} else
1395 1378
 			{
1396 1379
 				$this->errstr='Connect error: '.$this->errstr;
1397 1380
 				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr . ' (' . $this->errno . ')');
@@ -1404,8 +1387,7 @@  discard block
 block discarded – undo
1404 1387
 				$this->errstr='Write error';
1405 1388
 				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr);
1406 1389
 				return $r;
1407
-			}
1408
-			else
1390
+			} else
1409 1391
 			{
1410 1392
 				// reset errno and errstr on successful socket connection
1411 1393
 				$this->errstr = '';
@@ -1472,8 +1454,7 @@  discard block
 block discarded – undo
1472 1454
 				if($method == 'http')
1473 1455
 				{
1474 1456
 					$port = 80;
1475
-				}
1476
-				else
1457
+				} else
1477 1458
 				{
1478 1459
 					$port = 443;
1479 1460
 				}
@@ -1497,8 +1478,7 @@  discard block
 block discarded – undo
1497 1478
 						$payload = $a;
1498 1479
 						$encoding_hdr = 'Content-Encoding: gzip';
1499 1480
 					}
1500
-				}
1501
-				else
1481
+				} else
1502 1482
 				{
1503 1483
 					$a = @gzcompress($payload);
1504 1484
 					if($a)
@@ -1507,8 +1487,7 @@  discard block
 block discarded – undo
1507 1487
 						$encoding_hdr = 'Content-Encoding: deflate';
1508 1488
 					}
1509 1489
 				}
1510
-			}
1511
-			else
1490
+			} else
1512 1491
 			{
1513 1492
 				$encoding_hdr = '';
1514 1493
 			}
@@ -1527,8 +1506,7 @@  discard block
 block discarded – undo
1527 1506
 				{
1528 1507
 					$this->xmlrpc_curl_handle = $curl;
1529 1508
 				}
1530
-			}
1531
-			else
1509
+			} else
1532 1510
 			{
1533 1511
 				$curl = $this->xmlrpc_curl_handle;
1534 1512
 			}
@@ -1559,9 +1537,9 @@  discard block
 block discarded – undo
1559 1537
 				if (count($this->accepted_compression) == 1)
1560 1538
 				{
1561 1539
 					curl_setopt($curl, CURLOPT_ENCODING, $this->accepted_compression[0]);
1562
-				}
1563
-				else
1564
-					curl_setopt($curl, CURLOPT_ENCODING, '');
1540
+				} else {
1541
+									curl_setopt($curl, CURLOPT_ENCODING, '');
1542
+				}
1565 1543
 			}
1566 1544
 			// extra headers
1567 1545
 			$headers = array('Content-Type: ' . $msg->content_type , 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings));
@@ -1589,8 +1567,7 @@  discard block
 block discarded – undo
1589 1567
 				if (defined('CURLOPT_HTTPAUTH'))
1590 1568
 				{
1591 1569
 					curl_setopt($curl, CURLOPT_HTTPAUTH, $authtype);
1592
-				}
1593
-				else if ($authtype != 1)
1570
+				} else if ($authtype != 1)
1594 1571
 				{
1595 1572
 					error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported by the current PHP/curl install');
1596 1573
 				}
@@ -1655,8 +1632,7 @@  discard block
 block discarded – undo
1655 1632
 					if (defined('CURLOPT_PROXYAUTH'))
1656 1633
 					{
1657 1634
 						curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyauthtype);
1658
-					}
1659
-					else if ($proxyauthtype != 1)
1635
+					} else if ($proxyauthtype != 1)
1660 1636
 					{
1661 1637
 						error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
1662 1638
 					}
@@ -1698,17 +1674,18 @@  discard block
 block discarded – undo
1698 1674
 				print "---END---\n</PRE>";
1699 1675
 			}
1700 1676
 
1701
-			if(!$result) /// @todo we should use a better check here - what if we get back '' or '0'?
1677
+			if(!$result) {
1678
+			    /// @todo we should use a better check here - what if we get back '' or '0'?
1702 1679
 			{
1703
-				$this->errstr='no response';
1680
+				$this->errstr='no response';
1681
+			}
1704 1682
 				$resp=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['curl_fail'], $GLOBALS['xmlrpcstr']['curl_fail']. ': '. curl_error($curl));
1705 1683
 				curl_close($curl);
1706 1684
 				if($keepalive)
1707 1685
 				{
1708 1686
 					$this->xmlrpc_curl_handle = null;
1709 1687
 				}
1710
-			}
1711
-			else
1688
+			} else
1712 1689
 			{
1713 1690
 				if(!$keepalive)
1714 1691
 				{
@@ -1760,8 +1737,7 @@  discard block
 block discarded – undo
1760 1737
 				{
1761 1738
 					// System.multicall succeeded
1762 1739
 					return $results;
1763
-				}
1764
-				else
1740
+				} else
1765 1741
 				{
1766 1742
 					// either system.multicall is unsupported by server,
1767 1743
 					// or call failed for some other reason.
@@ -1769,21 +1745,18 @@  discard block
 block discarded – undo
1769 1745
 					{
1770 1746
 						// Don't try it next time...
1771 1747
 						$this->no_multicall = true;
1772
-					}
1773
-					else
1748
+					} else
1774 1749
 					{
1775 1750
 						if (is_a($results, 'xmlrpcresp'))
1776 1751
 						{
1777 1752
 							$result = $results;
1778
-						}
1779
-						else
1753
+						} else
1780 1754
 						{
1781 1755
 							$result = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['multicall_error'], $GLOBALS['xmlrpcstr']['multicall_error']);
1782 1756
 						}
1783 1757
 					}
1784 1758
 				}
1785
-			}
1786
-			else
1759
+			} else
1787 1760
 			{
1788 1761
 				// override fallback, in case careless user tries to do two
1789 1762
 				// opposite things at the same time
@@ -1799,8 +1772,7 @@  discard block
 block discarded – undo
1799 1772
 				{
1800 1773
 					$results[] =& $this->send($msg, $timeout, $method);
1801 1774
 				}
1802
-			}
1803
-			else
1775
+			} else
1804 1776
 			{
1805 1777
 				// user does NOT want to fallback on many single calls:
1806 1778
 				// since we should always return an array of responses,
@@ -1853,8 +1825,7 @@  discard block
 block discarded – undo
1853 1825
 			if ($this->return_type == 'xml')
1854 1826
 			{
1855 1827
 					return $rets;
1856
-			}
1857
-			else if ($this->return_type == 'phpvals')
1828
+			} else if ($this->return_type == 'phpvals')
1858 1829
 			{
1859 1830
 				///@todo test this code branch...
1860 1831
 				$rets = $result->value();
@@ -1904,8 +1875,7 @@  discard block
 block discarded – undo
1904 1875
 					}
1905 1876
 				}
1906 1877
 				return $response;
1907
-			}
1908
-			else // return type == 'xmlrpcvals'
1878
+			} else // return type == 'xmlrpcvals'
1909 1879
 			{
1910 1880
 				$rets = $result->value();
1911 1881
 				if($rets->kindOf() != 'array')
@@ -1992,8 +1962,7 @@  discard block
 block discarded – undo
1992 1962
 				$this->errno = $fcode;
1993 1963
 				$this->errstr = $fstr;
1994 1964
 				//$this->errstr = htmlspecialchars($fstr); // XXX: encoding probably shouldn't be done here; fix later.
1995
-			}
1996
-			else
1965
+			} else
1997 1966
 			{
1998 1967
 				// successful response
1999 1968
 				$this->val = $val;
@@ -2003,18 +1972,15 @@  discard block
 block discarded – undo
2003 1972
 					if (is_object($this->val) && is_a($this->val, 'xmlrpcval'))
2004 1973
 					{
2005 1974
 						$this->valtyp = 'xmlrpcvals';
2006
-					}
2007
-					else if (is_string($this->val))
1975
+					} else if (is_string($this->val))
2008 1976
 					{
2009 1977
 						$this->valtyp = 'xml';
2010 1978
 
2011
-					}
2012
-					else
1979
+					} else
2013 1980
 					{
2014 1981
 						$this->valtyp = 'phpvals';
2015 1982
 					}
2016
-				}
2017
-				else
1983
+				} else
2018 1984
 				{
2019 1985
 					// user declares type of resp value: believe him
2020 1986
 					$this->valtyp = $valtyp;
@@ -2076,15 +2042,15 @@  discard block
 block discarded – undo
2076 2042
 		*/
2077 2043
 		function serialize($charset_encoding='')
2078 2044
 		{
2079
-			if ($charset_encoding != '')
2080
-				$this->content_type = 'text/xml; charset=' . $charset_encoding;
2081
-			else
2082
-				$this->content_type = 'text/xml';
2045
+			if ($charset_encoding != '') {
2046
+							$this->content_type = 'text/xml; charset=' . $charset_encoding;
2047
+			} else {
2048
+							$this->content_type = 'text/xml';
2049
+			}
2083 2050
 			if ($GLOBALS['xmlrpc_null_apache_encoding'])
2084 2051
 			{
2085 2052
 				$result = "<methodResponse xmlns:ex=\"".$GLOBALS['xmlrpc_null_apache_encoding_ns']."\">\n";
2086
-			}
2087
-			else
2053
+			} else
2088 2054
 			{
2089 2055
 			$result = "<methodResponse>\n";
2090 2056
 			}
@@ -2097,8 +2063,7 @@  discard block
 block discarded – undo
2097 2063
 "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
2098 2064
 xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</string></value>\n</member>\n" .
2099 2065
 "</struct>\n</value>\n</fault>";
2100
-			}
2101
-			else
2066
+			} else
2102 2067
 			{
2103 2068
 				if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
2104 2069
 				{
@@ -2107,14 +2072,12 @@  discard block
 block discarded – undo
2107 2072
 						$result .= "<params>\n<param>\n" .
2108 2073
 							$this->val .
2109 2074
 							"</param>\n</params>";
2110
-					}
2111
-					else
2075
+					} else
2112 2076
 					{
2113 2077
 						/// @todo try to build something serializable?
2114 2078
 						die('cannot serialize xmlrpcresp objects whose content is native php values');
2115 2079
 					}
2116
-				}
2117
-				else
2080
+				} else
2118 2081
 				{
2119 2082
 					$result .= "<params>\n<param>\n" .
2120 2083
 						$this->val->serialize($charset_encoding) .
@@ -2167,8 +2130,7 @@  discard block
 block discarded – undo
2167 2130
 			if ($charset_encoding != '')
2168 2131
 			{
2169 2132
 				return "<?xml version=\"1.0\" encoding=\"$charset_encoding\" ?" . ">\n<methodCall>\n";
2170
-			}
2171
-			else
2133
+			} else
2172 2134
 			{
2173 2135
 				return "<?xml version=\"1.0\"?" . ">\n<methodCall>\n";
2174 2136
 			}
@@ -2195,10 +2157,11 @@  discard block
 block discarded – undo
2195 2157
 		*/
2196 2158
 		function createPayload($charset_encoding='')
2197 2159
 		{
2198
-			if ($charset_encoding != '')
2199
-				$this->content_type = 'text/xml; charset=' . $charset_encoding;
2200
-			else
2201
-				$this->content_type = 'text/xml';
2160
+			if ($charset_encoding != '') {
2161
+							$this->content_type = 'text/xml; charset=' . $charset_encoding;
2162
+			} else {
2163
+							$this->content_type = 'text/xml';
2164
+			}
2202 2165
 			$this->payload=$this->xml_header($charset_encoding);
2203 2166
 			$this->payload.='<methodName>' . xmlrpc_encode_entitites($this->methodname, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</methodName>\n";
2204 2167
 			$this->payload.="<params>\n";
@@ -2252,8 +2215,7 @@  discard block
 block discarded – undo
2252 2215
 			{
2253 2216
 				$this->params[]=$par;
2254 2217
 				return true;
2255
-			}
2256
-			else
2218
+			} else
2257 2219
 			{
2258 2220
 				return false;
2259 2221
 			}
@@ -2314,15 +2276,13 @@  discard block
 block discarded – undo
2314 2276
 					if($pos || is_int($pos))
2315 2277
 					{
2316 2278
 						$bd = $pos+4;
2317
-					}
2318
-					else
2279
+					} else
2319 2280
 					{
2320 2281
 						$pos = strpos($data,"\n\n");
2321 2282
 						if($pos || is_int($pos))
2322 2283
 						{
2323 2284
 							$bd = $pos+2;
2324
-						}
2325
-						else
2285
+						} else
2326 2286
 						{
2327 2287
 							// No separation between response headers and body: fault?
2328 2288
 							$bd = 0;
@@ -2333,8 +2293,7 @@  discard block
 block discarded – undo
2333 2293
 						// this filters out all http headers from proxy.
2334 2294
 						// maybe we could take them into account, too?
2335 2295
 						$data = substr($data, $bd);
2336
-					}
2337
-					else
2296
+					} else
2338 2297
 					{
2339 2298
 						error_log('XML-RPC: '.__METHOD__.': HTTPS via proxy error, tunnel connection possibly failed');
2340 2299
 						$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $GLOBALS['xmlrpcstr']['http_error']. ' (HTTPS via proxy error, tunnel connection possibly failed)');
@@ -2348,9 +2307,11 @@  discard block
 block discarded – undo
2348 2307
 					$pos = strpos($data, 'HTTP', 12);
2349 2308
 					// server sent a Continue header without any (valid) content following...
2350 2309
 					// give the client a chance to know it
2351
-					if(!$pos && !is_int($pos)) // works fine in php 3, 4 and 5
2310
+					if(!$pos && !is_int($pos)) {
2311
+					    // works fine in php 3, 4 and 5
2352 2312
 					{
2353
-						break;
2313
+						break;
2314
+					}
2354 2315
 					}
2355 2316
 					$data = substr($data, $pos);
2356 2317
 				}
@@ -2371,15 +2332,13 @@  discard block
 block discarded – undo
2371 2332
 				if($pos || is_int($pos))
2372 2333
 				{
2373 2334
 					$bd = $pos+4;
2374
-				}
2375
-				else
2335
+				} else
2376 2336
 				{
2377 2337
 					$pos = strpos($data,"\n\n");
2378 2338
 					if($pos || is_int($pos))
2379 2339
 					{
2380 2340
 						$bd = $pos+2;
2381
-					}
2382
-					else
2341
+					} else
2383 2342
 					{
2384 2343
 						// No separation between response headers and body: fault?
2385 2344
 						// we could take some action here instead of going on...
@@ -2406,8 +2365,7 @@  discard block
 block discarded – undo
2406 2365
 								// version 2 cookies:
2407 2366
 								// there could be many cookies on one line, comma separated
2408 2367
 								$cookies = explode(',', $arr[1]);
2409
-							}
2410
-							else
2368
+							} else
2411 2369
 							{
2412 2370
 								$cookies = array($arr[1]);
2413 2371
 							}
@@ -2415,10 +2373,11 @@  discard block
 block discarded – undo
2415 2373
 							{
2416 2374
 								// glue together all received cookies, using a comma to separate them
2417 2375
 								// (same as php does with getallheaders())
2418
-								if (isset($GLOBALS['_xh']['headers'][$header_name]))
2419
-									$GLOBALS['_xh']['headers'][$header_name] .= ', ' . trim($cookie);
2420
-								else
2421
-									$GLOBALS['_xh']['headers'][$header_name] = trim($cookie);
2376
+								if (isset($GLOBALS['_xh']['headers'][$header_name])) {
2377
+																	$GLOBALS['_xh']['headers'][$header_name] .= ', ' . trim($cookie);
2378
+								} else {
2379
+																	$GLOBALS['_xh']['headers'][$header_name] = trim($cookie);
2380
+								}
2422 2381
 								// parse cookie attributes, in case user wants to correctly honour them
2423 2382
 								// feature creep: only allow rfc-compliant cookie attributes?
2424 2383
 								// @todo support for server sending multiple time cookie with same name, but using different PATHs
@@ -2434,8 +2393,7 @@  discard block
 block discarded – undo
2434 2393
 										$cookiename = $tag;
2435 2394
 										$GLOBALS['_xh']['cookies'][$tag] = array();
2436 2395
 										$GLOBALS['_xh']['cookies'][$cookiename]['value'] = urldecode($val);
2437
-									}
2438
-									else
2396
+									} else
2439 2397
 									{
2440 2398
 										if ($tag != 'value')
2441 2399
 										{
@@ -2444,13 +2402,11 @@  discard block
 block discarded – undo
2444 2402
 									}
2445 2403
 								}
2446 2404
 							}
2447
-						}
2448
-						else
2405
+						} else
2449 2406
 						{
2450 2407
 							$GLOBALS['_xh']['headers'][$header_name] = trim($arr[1]);
2451 2408
 						}
2452
-					}
2453
-					elseif(isset($header_name))
2409
+					} elseif(isset($header_name))
2454 2410
 					{
2455 2411
 						///	@todo version1 cookies might span multiple lines, thus breaking the parsing above
2456 2412
 						$GLOBALS['_xh']['headers'][$header_name] .= ' ' . trim($line);
@@ -2501,23 +2457,22 @@  discard block
 block discarded – undo
2501 2457
 								if($GLOBALS['_xh']['headers']['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data))
2502 2458
 								{
2503 2459
 									$data = $degzdata;
2504
-									if($this->debug)
2505
-									print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2506
-								}
2507
-								elseif($GLOBALS['_xh']['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
2460
+									if($this->debug) {
2461
+																		print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2462
+									}
2463
+								} elseif($GLOBALS['_xh']['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
2508 2464
 								{
2509 2465
 									$data = $degzdata;
2510
-									if($this->debug)
2511
-									print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2512
-								}
2513
-								else
2466
+									if($this->debug) {
2467
+																		print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2468
+									}
2469
+								} else
2514 2470
 								{
2515 2471
 									error_log('XML-RPC: '.__METHOD__.': errors occurred when trying to decode the deflated data received from server');
2516 2472
 									$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['decompress_fail'], $GLOBALS['xmlrpcstr']['decompress_fail']);
2517 2473
 									return $r;
2518 2474
 								}
2519
-							}
2520
-							else
2475
+							} else
2521 2476
 							{
2522 2477
 								error_log('XML-RPC: '.__METHOD__.': the server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
2523 2478
 								$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['cannot_decompress'], $GLOBALS['xmlrpcstr']['cannot_decompress']);
@@ -2570,8 +2525,7 @@  discard block
 block discarded – undo
2570 2525
 					$r->raw_data = $data;
2571 2526
 					return $r;
2572 2527
 				}
2573
-			}
2574
-			else
2528
+			} else
2575 2529
 			{
2576 2530
 				$GLOBALS['_xh']['headers'] = array();
2577 2531
 				$GLOBALS['_xh']['cookies'] = array();
@@ -2651,8 +2605,7 @@  discard block
 block discarded – undo
2651 2605
 			if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
2652 2606
 			{
2653 2607
 				xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
2654
-			}
2655
-			else
2608
+			} else
2656 2609
 			{
2657 2610
 				xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
2658 2611
 			}
@@ -2660,8 +2613,7 @@  discard block
 block discarded – undo
2660 2613
 			if ($return_type == 'phpvals')
2661 2614
 			{
2662 2615
 				xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast');
2663
-			}
2664
-			else
2616
+			} else
2665 2617
 			{
2666 2618
 				xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
2667 2619
 			}
@@ -2676,8 +2628,7 @@  discard block
 block discarded – undo
2676 2628
 				if((xml_get_current_line_number($parser)) == 1)
2677 2629
 				{
2678 2630
 					$errstr = 'XML error at line 1, check URL';
2679
-				}
2680
-				else
2631
+				} else
2681 2632
 				{
2682 2633
 					$errstr = sprintf('XML error: %s at line %d, column %d',
2683 2634
 						xml_error_string(xml_get_error_code($parser)),
@@ -2716,8 +2667,7 @@  discard block
 block discarded – undo
2716 2667
 				// indicating something odd went on
2717 2668
 				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'],
2718 2669
 					$GLOBALS['xmlrpcstr']['invalid_return']);
2719
-			}
2720
-			else
2670
+			} else
2721 2671
 			{
2722 2672
 				if ($this->debug)
2723 2673
 				{
@@ -2741,8 +2691,7 @@  discard block
 block discarded – undo
2741 2691
 						$errstr_v = $v->structmem('faultString');
2742 2692
 						$errno = $errno_v->scalarval();
2743 2693
 						$errstr = $errstr_v->scalarval();
2744
-					}
2745
-					else
2694
+					} else
2746 2695
 					{
2747 2696
 						$errno = $v['faultCode'];
2748 2697
 						$errstr = $v['faultString'];
@@ -2755,8 +2704,7 @@  discard block
 block discarded – undo
2755 2704
 					}
2756 2705
 
2757 2706
 					$r = new xmlrpcresp(0, $errno, $errstr);
2758
-				}
2759
-				else
2707
+				} else
2760 2708
 				{
2761 2709
 					$r=new xmlrpcresp($v, 0, '', $return_type);
2762 2710
 				}
@@ -2864,8 +2812,7 @@  discard block
 block discarded – undo
2864 2812
 				if(strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false')))
2865 2813
 				{
2866 2814
 					$val=true;
2867
-				}
2868
-				else
2815
+				} else
2869 2816
 				{
2870 2817
 					$val=false;
2871 2818
 				}
@@ -2910,14 +2857,12 @@  discard block
 block discarded – undo
2910 2857
 				$this->mytype=$GLOBALS['xmlrpcTypes']['array'];
2911 2858
 				$this->me['array']=$vals;
2912 2859
 				return 1;
2913
-			}
2914
-			elseif($this->mytype==2)
2860
+			} elseif($this->mytype==2)
2915 2861
 			{
2916 2862
 				// we're adding to an array here
2917 2863
 				$this->me['array'] = array_merge($this->me['array'], $vals);
2918 2864
 				return 1;
2919
-			}
2920
-			else
2865
+			} else
2921 2866
 			{
2922 2867
 				error_log('XML-RPC: '.__METHOD__.': already initialized as a [' . $this->kindOf() . ']');
2923 2868
 				return 0;
@@ -2939,14 +2884,12 @@  discard block
 block discarded – undo
2939 2884
 				$this->mytype=$GLOBALS['xmlrpcTypes']['struct'];
2940 2885
 				$this->me['struct']=$vals;
2941 2886
 				return 1;
2942
-			}
2943
-			elseif($this->mytype==3)
2887
+			} elseif($this->mytype==3)
2944 2888
 			{
2945 2889
 				// we're adding to a struct here
2946 2890
 				$this->me['struct'] = array_merge($this->me['struct'], $vals);
2947 2891
 				return 1;
2948
-			}
2949
-			else
2892
+			} else
2950 2893
 			{
2951 2894
 				error_log('XML-RPC: '.__METHOD__.': already initialized as a [' . $this->kindOf() . ']');
2952 2895
 				return 0;
@@ -3050,8 +2993,7 @@  discard block
 block discarded – undo
3050 2993
 							if ($GLOBALS['xmlrpc_null_apache_encoding'])
3051 2994
 							{
3052 2995
 								$rs.="<ex:nil/>";
3053
-							}
3054
-							else
2996
+							} else
3055 2997
 							{
3056 2998
 								$rs.="<nil/>";
3057 2999
 							}
@@ -3067,8 +3009,7 @@  discard block
 block discarded – undo
3067 3009
 					if ($this->_php_class)
3068 3010
 					{
3069 3011
 						$rs.='<struct php_class="' . $this->_php_class . "\">\n";
3070
-					}
3071
-					else
3012
+					} else
3072 3013
 					{
3073 3014
 						$rs.="<struct>\n";
3074 3015
 					}
@@ -3296,16 +3237,14 @@  discard block
 block discarded – undo
3296 3237
 		if(!$utc)
3297 3238
 		{
3298 3239
 			$t=strftime("%Y%m%dT%H:%M:%S", $timet);
3299
-		}
3300
-		else
3240
+		} else
3301 3241
 		{
3302 3242
 			if(function_exists('gmstrftime'))
3303 3243
 			{
3304 3244
 				// gmstrftime doesn't exist in some versions
3305 3245
 				// of PHP
3306 3246
 				$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
3307
-			}
3308
-			else
3247
+			} else
3309 3248
 			{
3310 3249
 				$t=strftime("%Y%m%dT%H:%M:%S", $timet-date('Z'));
3311 3250
 			}
@@ -3327,8 +3266,7 @@  discard block
 block discarded – undo
3327 3266
 			if($utc)
3328 3267
 			{
3329 3268
 				$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3330
-			}
3331
-			else
3269
+			} else
3332 3270
 			{
3333 3271
 				$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3334 3272
 			}
@@ -3396,8 +3334,7 @@  discard block
 block discarded – undo
3396 3334
 						$result = new Datetime();
3397 3335
 						$result->setTimestamp($out);
3398 3336
 						return $result;
3399
-					}
3400
-					elseif (is_a($out, 'Datetime'))
3337
+					} elseif (is_a($out, 'Datetime'))
3401 3338
 					{
3402 3339
 						return $out;
3403 3340
 					}
@@ -3426,8 +3363,7 @@  discard block
 block discarded – undo
3426 3363
 						$obj->$key = php_xmlrpc_decode($value, $options);
3427 3364
 					}
3428 3365
 					return $obj;
3429
-				}
3430
-				else
3366
+				} else
3431 3367
 				{
3432 3368
 					$arr = array();
3433 3369
 					while(list($key,$value)=$xmlrpc_val->structeach())
@@ -3453,8 +3389,7 @@  discard block
 block discarded – undo
3453 3389
 	if(function_exists('xmlrpc_decode'))
3454 3390
 	{
3455 3391
 		define('XMLRPC_EPI_ENABLED','1');
3456
-	}
3457
-	else
3392
+	} else
3458 3393
 	{
3459 3394
 		define('XMLRPC_EPI_ENABLED','0');
3460 3395
 	}
@@ -3482,10 +3417,11 @@  discard block
 block discarded – undo
3482 3417
 		switch($type)
3483 3418
 		{
3484 3419
 			case 'string':
3485
-				if (in_array('auto_dates', $options) && preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $php_val))
3486
-					$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcDateTime']);
3487
-				else
3488
-					$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcString']);
3420
+				if (in_array('auto_dates', $options) && preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $php_val)) {
3421
+									$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcDateTime']);
3422
+				} else {
3423
+									$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcString']);
3424
+				}
3489 3425
 				break;
3490 3426
 			case 'integer':
3491 3427
 				$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcInt']);
@@ -3520,8 +3456,7 @@  discard block
 block discarded – undo
3520 3456
 				if($ko)
3521 3457
 				{
3522 3458
 					$xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcStruct']);
3523
-				}
3524
-				else
3459
+				} else
3525 3460
 				{
3526 3461
 					$xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcArray']);
3527 3462
 				}
@@ -3530,12 +3465,10 @@  discard block
 block discarded – undo
3530 3465
 				if(is_a($php_val, 'xmlrpcval'))
3531 3466
 				{
3532 3467
 					$xmlrpc_val = $php_val;
3533
-				}
3534
-				else if(is_a($php_val, 'DateTime'))
3468
+				} else if(is_a($php_val, 'DateTime'))
3535 3469
 				{
3536 3470
 					$xmlrpc_val = new xmlrpcval($php_val->format('Ymd\TH:i:s'), $GLOBALS['xmlrpcStruct']);
3537
-				}
3538
-				else
3471
+				} else
3539 3472
 				{
3540 3473
 					$arr = array();
3541 3474
 					reset($php_val);
@@ -3556,12 +3489,10 @@  discard block
 block discarded – undo
3556 3489
 				if (in_array('extension_api', $options))
3557 3490
 				{
3558 3491
 					$xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcString']);
3559
-				}
3560
-				else if (in_array('null_extension', $options))
3492
+				} else if (in_array('null_extension', $options))
3561 3493
 				{
3562 3494
 					$xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcNull']);
3563
-				}
3564
-				else
3495
+				} else
3565 3496
 				{
3566 3497
 					$xmlrpc_val = new xmlrpcval();
3567 3498
 				}
@@ -3570,8 +3501,7 @@  discard block
 block discarded – undo
3570 3501
 				if (in_array('extension_api', $options))
3571 3502
 				{
3572 3503
 					$xmlrpc_val = new xmlrpcval((int)$php_val, $GLOBALS['xmlrpcInt']);
3573
-				}
3574
-				else
3504
+				} else
3575 3505
 				{
3576 3506
 					$xmlrpc_val = new xmlrpcval();
3577 3507
 				}
@@ -3633,8 +3563,7 @@  discard block
 block discarded – undo
3633 3563
 		if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
3634 3564
 		{
3635 3565
 			xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
3636
-		}
3637
-		else
3566
+		} else
3638 3567
 		{
3639 3568
 			xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
3640 3569
 		}
@@ -3651,9 +3580,11 @@  discard block
 block discarded – undo
3651 3580
 			return false;
3652 3581
 		}
3653 3582
 		xml_parser_free($parser);
3654
-		if ($GLOBALS['_xh']['isf'] > 1) // test that $GLOBALS['_xh']['value'] is an obj, too???
3583
+		if ($GLOBALS['_xh']['isf'] > 1) {
3584
+		    // test that $GLOBALS['_xh']['value'] is an obj, too???
3655 3585
 		{
3656
-			error_log($GLOBALS['_xh']['isf_reason']);
3586
+			error_log($GLOBALS['_xh']['isf_reason']);
3587
+		}
3657 3588
 			return false;
3658 3589
 		}
3659 3590
 		switch ($GLOBALS['_xh']['rt'])
@@ -3665,8 +3596,7 @@  discard block
 block discarded – undo
3665 3596
 					$vc = $v->structmem('faultCode');
3666 3597
 					$vs = $v->structmem('faultString');
3667 3598
 					$r = new xmlrpcresp(0, $vc->scalarval(), $vs->scalarval());
3668
-				}
3669
-				else
3599
+				} else
3670 3600
 				{
3671 3601
 					$r = new xmlrpcresp($v);
3672 3602
 				}
@@ -3787,12 +3717,10 @@  discard block
 block discarded – undo
3787 3717
 		if(preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlchunk))
3788 3718
 		{
3789 3719
 			return 'UCS-4';
3790
-		}
3791
-		elseif(preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlchunk))
3720
+		} elseif(preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlchunk))
3792 3721
 		{
3793 3722
 			return 'UTF-16';
3794
-		}
3795
-		elseif(preg_match('/^(\xEF\xBB\xBF)/', $xmlchunk))
3723
+		} elseif(preg_match('/^(\xEF\xBB\xBF)/', $xmlchunk))
3796 3724
 		{
3797 3725
 			return 'UTF-8';
3798 3726
 		}
@@ -3815,8 +3743,7 @@  discard block
 block discarded – undo
3815 3743
 			if($encoding_prefs)
3816 3744
 			{
3817 3745
 				$enc = mb_detect_encoding($xmlchunk, $encoding_prefs);
3818
-			}
3819
-			else
3746
+			} else
3820 3747
 			{
3821 3748
 				$enc = mb_detect_encoding($xmlchunk);
3822 3749
 			}
@@ -3827,8 +3754,7 @@  discard block
 block discarded – undo
3827 3754
 				$enc = 'US-'.$enc;
3828 3755
 			}
3829 3756
 			return $enc;
3830
-		}
3831
-		else
3757
+		} else
3832 3758
 		{
3833 3759
 			// no encoding specified: as per HTTP1.1 assume it is iso-8859-1?
3834 3760
 			// Both RFC 2616 (HTTP 1.1) and 1945 (HTTP 1.0) clearly state that for text/xxx content types
@@ -3851,12 +3777,10 @@  discard block
 block discarded – undo
3851 3777
 		if (preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlChunk))
3852 3778
 		{
3853 3779
 			return true;
3854
-		}
3855
-		elseif (preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlChunk))
3780
+		} elseif (preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlChunk))
3856 3781
 		{
3857 3782
 			return true;
3858
-		}
3859
-		elseif (preg_match('/^(\xEF\xBB\xBF)/', $xmlChunk))
3783
+		} elseif (preg_match('/^(\xEF\xBB\xBF)/', $xmlChunk))
3860 3784
 		{
3861 3785
 			return true;
3862 3786
 		}
@@ -3891,16 +3815,18 @@  discard block
 block discarded – undo
3891 3815
 				'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'UTF-8',
3892 3816
 				'EUC-JP', 'EUC-', 'EUC-KR', 'EUC-CN')
3893 3817
 		);
3894
-		if (is_string($validlist))
3895
-			$validlist = explode(',', $validlist);
3896
-		if (@in_array(strtoupper($encoding), $validlist))
3897
-			return true;
3898
-		else
3899
-		{
3900
-			if (array_key_exists($encoding, $charset_supersets))
3901
-				foreach ($validlist as $allowed)
3818
+		if (is_string($validlist)) {
3819
+					$validlist = explode(',', $validlist);
3820
+		}
3821
+		if (@in_array(strtoupper($encoding), $validlist)) {
3822
+					return true;
3823
+		} else
3824
+		{
3825
+			if (array_key_exists($encoding, $charset_supersets)) {
3826
+							foreach ($validlist as $allowed)
3902 3827
 					if (in_array($allowed, $charset_supersets[$encoding]))
3903
-						return true;
3828
+						return true;
3829
+			}
3904 3830
 			return false;
3905 3831
 		}
3906 3832
 	}
Please login to merge, or discard this patch.
Doc Comments   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1239,6 +1239,7 @@  discard block
 block discarded – undo
1239 1239
 
1240 1240
 		/**
1241 1241
 		* @access private
1242
+		* @param integer $port
1242 1243
 		*/
1243 1244
 		function &sendPayloadHTTP10($msg, $server, $port, $timeout=0,
1244 1245
 			$username='', $password='', $authtype=1, $proxyhost='',
@@ -1427,6 +1428,7 @@  discard block
 block discarded – undo
1427 1428
 
1428 1429
 		/**
1429 1430
 		* @access private
1431
+		* @param integer $port
1430 1432
 		*/
1431 1433
 		function &sendPayloadHTTPS($msg, $server, $port, $timeout=0, $username='',
1432 1434
 			$password='', $authtype=1, $cert='',$certpass='', $cacert='', $cacertdir='',
@@ -1818,6 +1820,8 @@  discard block
 block discarded – undo
1818 1820
 		* Returns either an array of xmlrpcreponses, an xmlrpc error response
1819 1821
 		* or false (when received response does not respect valid multicall syntax)
1820 1822
 		* @access private
1823
+		* @param integer $timeout
1824
+		* @param string $method
1821 1825
 		*/
1822 1826
 		function _try_multicall($msgs, $timeout, $method)
1823 1827
 		{
@@ -2044,7 +2048,7 @@  discard block
 block discarded – undo
2044 2048
 
2045 2049
 		/**
2046 2050
 		* Returns the value received by the server.
2047
-		* @return mixed the xmlrpcval object returned by the server. Might be an xml string or php value if the response has been created by specially configured xmlrpc_client objects
2051
+		* @return integer the xmlrpcval object returned by the server. Might be an xml string or php value if the response has been created by specially configured xmlrpc_client objects
2048 2052
 		* @access public
2049 2053
 		*/
2050 2054
 		function value()
@@ -2137,7 +2141,7 @@  discard block
 block discarded – undo
2137 2141
 
2138 2142
 		/**
2139 2143
 		* @param string $meth the name of the method to invoke
2140
-		* @param array $pars array of parameters to be passed to the method (xmlrpcval objects)
2144
+		* @param integer $pars array of parameters to be passed to the method (xmlrpcval objects)
2141 2145
 		*/
2142 2146
 		function __construct($meth, $pars=0)
2143 2147
 		{
@@ -2302,6 +2306,7 @@  discard block
 block discarded – undo
2302 2306
 		/**
2303 2307
 		* Parses HTTP headers and separates them from data.
2304 2308
 		* @access private
2309
+		* @param string $data
2305 2310
 		*/
2306 2311
 		function &parseResponseHeaders(&$data, $headers_processed=false)
2307 2312
 		{
@@ -2776,7 +2781,7 @@  discard block
 block discarded – undo
2776 2781
 		var $_php_class=null;
2777 2782
 
2778 2783
 		/**
2779
-		* @param mixed $val
2784
+		* @param integer $val
2780 2785
 		* @param string $type any valid xmlrpc type name (lowercase). If null, 'string' is assumed
2781 2786
 		*/
2782 2787
 		function __construct($val=-1, $type='')
@@ -2843,7 +2848,7 @@  discard block
 block discarded – undo
2843 2848
 
2844 2849
 		/**
2845 2850
 		* Add a single php value to an (unitialized) xmlrpcval
2846
-		* @param mixed $val
2851
+		* @param boolean $val
2847 2852
 		* @param string $type
2848 2853
 		* @return int 1 or 0 on failure
2849 2854
 		*/
Please login to merge, or discard this patch.
Indentation   +3815 added lines, -3815 removed lines patch added patch discarded remove patch
@@ -34,98 +34,98 @@  discard block
 block discarded – undo
34 34
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35 35
 // OF THE POSSIBILITY OF SUCH DAMAGE.
36 36
 
37
-	if(!function_exists('xml_parser_create'))
38
-	{
39
-		// For PHP 4 onward, XML functionality is always compiled-in on windows:
40
-		// no more need to dl-open it. It might have been compiled out on *nix...
41
-		if(strtoupper(substr(PHP_OS, 0, 3) != 'WIN'))
42
-		{
43
-			dl('xml.so');
44
-		}
45
-	}
46
-
47
-	// G. Giunta 2005/01/29: declare global these variables,
48
-	// so that xmlrpc.inc will work even if included from within a function
49
-	// Milosch: 2005/08/07 - explicitly request these via $GLOBALS where used.
50
-	$GLOBALS['xmlrpcI4']='i4';
51
-	$GLOBALS['xmlrpcInt']='int';
52
-	$GLOBALS['xmlrpcBoolean']='boolean';
53
-	$GLOBALS['xmlrpcDouble']='double';
54
-	$GLOBALS['xmlrpcString']='string';
55
-	$GLOBALS['xmlrpcDateTime']='dateTime.iso8601';
56
-	$GLOBALS['xmlrpcBase64']='base64';
57
-	$GLOBALS['xmlrpcArray']='array';
58
-	$GLOBALS['xmlrpcStruct']='struct';
59
-	$GLOBALS['xmlrpcValue']='undefined';
60
-
61
-	$GLOBALS['xmlrpcTypes']=array(
62
-		$GLOBALS['xmlrpcI4']       => 1,
63
-		$GLOBALS['xmlrpcInt']      => 1,
64
-		$GLOBALS['xmlrpcBoolean']  => 1,
65
-		$GLOBALS['xmlrpcString']   => 1,
66
-		$GLOBALS['xmlrpcDouble']   => 1,
67
-		$GLOBALS['xmlrpcDateTime'] => 1,
68
-		$GLOBALS['xmlrpcBase64']   => 1,
69
-		$GLOBALS['xmlrpcArray']    => 2,
70
-		$GLOBALS['xmlrpcStruct']   => 3
71
-	);
72
-
73
-	$GLOBALS['xmlrpc_valid_parents'] = array(
74
-		'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT'),
75
-		'BOOLEAN' => array('VALUE'),
76
-		'I4' => array('VALUE'),
77
-		'INT' => array('VALUE'),
78
-		'STRING' => array('VALUE'),
79
-		'DOUBLE' => array('VALUE'),
80
-		'DATETIME.ISO8601' => array('VALUE'),
81
-		'BASE64' => array('VALUE'),
82
-		'MEMBER' => array('STRUCT'),
83
-		'NAME' => array('MEMBER'),
84
-		'DATA' => array('ARRAY'),
85
-		'ARRAY' => array('VALUE'),
86
-		'STRUCT' => array('VALUE'),
87
-		'PARAM' => array('PARAMS'),
88
-		'METHODNAME' => array('METHODCALL'),
89
-		'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
90
-		'FAULT' => array('METHODRESPONSE'),
91
-		'NIL' => array('VALUE'), // only used when extension activated
92
-		'EX:NIL' => array('VALUE') // only used when extension activated
93
-	);
94
-
95
-	// define extra types for supporting NULL (useful for json or <NIL/>)
96
-	$GLOBALS['xmlrpcNull']='null';
97
-	$GLOBALS['xmlrpcTypes']['null']=1;
98
-
99
-	// Not in use anymore since 2.0. Shall we remove it?
100
-	/// @deprecated
101
-	$GLOBALS['xmlEntities']=array(
102
-		'amp'  => '&',
103
-		'quot' => '"',
104
-		'lt'   => '<',
105
-		'gt'   => '>',
106
-		'apos' => "'"
107
-	);
108
-
109
-	// tables used for transcoding different charsets into us-ascii xml
110
-
111
-	$GLOBALS['xml_iso88591_Entities']=array();
112
-	$GLOBALS['xml_iso88591_Entities']['in'] = array();
113
-	$GLOBALS['xml_iso88591_Entities']['out'] = array();
114
-	for ($i = 0; $i < 32; $i++)
115
-	{
116
-		$GLOBALS['xml_iso88591_Entities']['in'][] = chr($i);
117
-		$GLOBALS['xml_iso88591_Entities']['out'][] = '&#'.$i.';';
118
-	}
119
-	for ($i = 160; $i < 256; $i++)
120
-	{
121
-		$GLOBALS['xml_iso88591_Entities']['in'][] = chr($i);
122
-		$GLOBALS['xml_iso88591_Entities']['out'][] = '&#'.$i.';';
123
-	}
124
-
125
-	/// @todo add to iso table the characters from cp_1252 range, i.e. 128 to 159?
126
-	/// These will NOT be present in true ISO-8859-1, but will save the unwary
127
-	/// windows user from sending junk (though no luck when reciving them...)
128
-  /*
37
+    if(!function_exists('xml_parser_create'))
38
+    {
39
+        // For PHP 4 onward, XML functionality is always compiled-in on windows:
40
+        // no more need to dl-open it. It might have been compiled out on *nix...
41
+        if(strtoupper(substr(PHP_OS, 0, 3) != 'WIN'))
42
+        {
43
+            dl('xml.so');
44
+        }
45
+    }
46
+
47
+    // G. Giunta 2005/01/29: declare global these variables,
48
+    // so that xmlrpc.inc will work even if included from within a function
49
+    // Milosch: 2005/08/07 - explicitly request these via $GLOBALS where used.
50
+    $GLOBALS['xmlrpcI4']='i4';
51
+    $GLOBALS['xmlrpcInt']='int';
52
+    $GLOBALS['xmlrpcBoolean']='boolean';
53
+    $GLOBALS['xmlrpcDouble']='double';
54
+    $GLOBALS['xmlrpcString']='string';
55
+    $GLOBALS['xmlrpcDateTime']='dateTime.iso8601';
56
+    $GLOBALS['xmlrpcBase64']='base64';
57
+    $GLOBALS['xmlrpcArray']='array';
58
+    $GLOBALS['xmlrpcStruct']='struct';
59
+    $GLOBALS['xmlrpcValue']='undefined';
60
+
61
+    $GLOBALS['xmlrpcTypes']=array(
62
+        $GLOBALS['xmlrpcI4']       => 1,
63
+        $GLOBALS['xmlrpcInt']      => 1,
64
+        $GLOBALS['xmlrpcBoolean']  => 1,
65
+        $GLOBALS['xmlrpcString']   => 1,
66
+        $GLOBALS['xmlrpcDouble']   => 1,
67
+        $GLOBALS['xmlrpcDateTime'] => 1,
68
+        $GLOBALS['xmlrpcBase64']   => 1,
69
+        $GLOBALS['xmlrpcArray']    => 2,
70
+        $GLOBALS['xmlrpcStruct']   => 3
71
+    );
72
+
73
+    $GLOBALS['xmlrpc_valid_parents'] = array(
74
+        'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT'),
75
+        'BOOLEAN' => array('VALUE'),
76
+        'I4' => array('VALUE'),
77
+        'INT' => array('VALUE'),
78
+        'STRING' => array('VALUE'),
79
+        'DOUBLE' => array('VALUE'),
80
+        'DATETIME.ISO8601' => array('VALUE'),
81
+        'BASE64' => array('VALUE'),
82
+        'MEMBER' => array('STRUCT'),
83
+        'NAME' => array('MEMBER'),
84
+        'DATA' => array('ARRAY'),
85
+        'ARRAY' => array('VALUE'),
86
+        'STRUCT' => array('VALUE'),
87
+        'PARAM' => array('PARAMS'),
88
+        'METHODNAME' => array('METHODCALL'),
89
+        'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
90
+        'FAULT' => array('METHODRESPONSE'),
91
+        'NIL' => array('VALUE'), // only used when extension activated
92
+        'EX:NIL' => array('VALUE') // only used when extension activated
93
+    );
94
+
95
+    // define extra types for supporting NULL (useful for json or <NIL/>)
96
+    $GLOBALS['xmlrpcNull']='null';
97
+    $GLOBALS['xmlrpcTypes']['null']=1;
98
+
99
+    // Not in use anymore since 2.0. Shall we remove it?
100
+    /// @deprecated
101
+    $GLOBALS['xmlEntities']=array(
102
+        'amp'  => '&',
103
+        'quot' => '"',
104
+        'lt'   => '<',
105
+        'gt'   => '>',
106
+        'apos' => "'"
107
+    );
108
+
109
+    // tables used for transcoding different charsets into us-ascii xml
110
+
111
+    $GLOBALS['xml_iso88591_Entities']=array();
112
+    $GLOBALS['xml_iso88591_Entities']['in'] = array();
113
+    $GLOBALS['xml_iso88591_Entities']['out'] = array();
114
+    for ($i = 0; $i < 32; $i++)
115
+    {
116
+        $GLOBALS['xml_iso88591_Entities']['in'][] = chr($i);
117
+        $GLOBALS['xml_iso88591_Entities']['out'][] = '&#'.$i.';';
118
+    }
119
+    for ($i = 160; $i < 256; $i++)
120
+    {
121
+        $GLOBALS['xml_iso88591_Entities']['in'][] = chr($i);
122
+        $GLOBALS['xml_iso88591_Entities']['out'][] = '&#'.$i.';';
123
+    }
124
+
125
+    /// @todo add to iso table the characters from cp_1252 range, i.e. 128 to 159?
126
+    /// These will NOT be present in true ISO-8859-1, but will save the unwary
127
+    /// windows user from sending junk (though no luck when reciving them...)
128
+    /*
129 129
 	$GLOBALS['xml_cp1252_Entities']=array();
130 130
 	for ($i = 128; $i < 160; $i++)
131 131
 	{
@@ -143,222 +143,222 @@  discard block
 block discarded – undo
143 143
 	);
144 144
   */
145 145
 
146
-	$GLOBALS['xmlrpcerr'] = array(
147
-	'unknown_method'=>1,
148
-	'invalid_return'=>2,
149
-	'incorrect_params'=>3,
150
-	'introspect_unknown'=>4,
151
-	'http_error'=>5,
152
-	'no_data'=>6,
153
-	'no_ssl'=>7,
154
-	'curl_fail'=>8,
155
-	'invalid_request'=>15,
156
-	'no_curl'=>16,
157
-	'server_error'=>17,
158
-	'multicall_error'=>18,
159
-	'multicall_notstruct'=>9,
160
-	'multicall_nomethod'=>10,
161
-	'multicall_notstring'=>11,
162
-	'multicall_recursion'=>12,
163
-	'multicall_noparams'=>13,
164
-	'multicall_notarray'=>14,
165
-
166
-	'cannot_decompress'=>103,
167
-	'decompress_fail'=>104,
168
-	'dechunk_fail'=>105,
169
-	'server_cannot_decompress'=>106,
170
-	'server_decompress_fail'=>107
171
-	);
172
-
173
-	$GLOBALS['xmlrpcstr'] = array(
174
-	'unknown_method'=>'Unknown method',
175
-	'invalid_return'=>'Invalid return payload: enable debugging to examine incoming payload',
176
-	'incorrect_params'=>'Incorrect parameters passed to method',
177
-	'introspect_unknown'=>"Can't introspect: method unknown",
178
-	'http_error'=>"Didn't receive 200 OK from remote server.",
179
-	'no_data'=>'No data received from server.',
180
-	'no_ssl'=>'No SSL support compiled in.',
181
-	'curl_fail'=>'CURL error',
182
-	'invalid_request'=>'Invalid request payload',
183
-	'no_curl'=>'No CURL support compiled in.',
184
-	'server_error'=>'Internal server error',
185
-	'multicall_error'=>'Received from server invalid multicall response',
186
-	'multicall_notstruct'=>'system.multicall expected struct',
187
-	'multicall_nomethod'=>'missing methodName',
188
-	'multicall_notstring'=>'methodName is not a string',
189
-	'multicall_recursion'=>'recursive system.multicall forbidden',
190
-	'multicall_noparams'=>'missing params',
191
-	'multicall_notarray'=>'params is not an array',
192
-
193
-	'cannot_decompress'=>'Received from server compressed HTTP and cannot decompress',
194
-	'decompress_fail'=>'Received from server invalid compressed HTTP',
195
-	'dechunk_fail'=>'Received from server invalid chunked HTTP',
196
-	'server_cannot_decompress'=>'Received from client compressed HTTP request and cannot decompress',
197
-	'server_decompress_fail'=>'Received from client invalid compressed HTTP request'
198
-	);
199
-
200
-	// The charset encoding used by the server for received messages and
201
-	// by the client for received responses when received charset cannot be determined
202
-	// or is not supported
203
-	$GLOBALS['xmlrpc_defencoding']='UTF-8';
204
-
205
-	// The encoding used internally by PHP.
206
-	// String values received as xml will be converted to this, and php strings will be converted to xml
207
-	// as if having been coded with this
208
-	$GLOBALS['xmlrpc_internalencoding']='ISO-8859-1';
209
-
210
-	$GLOBALS['xmlrpcName']='XML-RPC for PHP';
211
-	$GLOBALS['xmlrpcVersion']='3.0.1';
212
-
213
-	// let user errors start at 800
214
-	$GLOBALS['xmlrpcerruser']=800;
215
-	// let XML parse errors start at 100
216
-	$GLOBALS['xmlrpcerrxml']=100;
217
-
218
-	// formulate backslashes for escaping regexp
219
-	// Not in use anymore since 2.0. Shall we remove it?
220
-	/// @deprecated
221
-	$GLOBALS['xmlrpc_backslash']=chr(92).chr(92);
222
-
223
-	// set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values
224
-	$GLOBALS['xmlrpc_null_extension']=false;
225
-
226
-	// set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
227
-	$GLOBALS['xmlrpc_null_apache_encoding']=false;
228
-	$GLOBALS['xmlrpc_null_apache_encoding_ns']='http://ws.apache.org/xmlrpc/namespaces/extensions';
229
-
230
-	// used to store state during parsing
231
-	// quick explanation of components:
232
-	//   ac - used to accumulate values
233
-	//   isf - used to indicate a parsing fault (2) or xmlrpcresp fault (1)
234
-	//   isf_reason - used for storing xmlrpcresp fault string
235
-	//   lv - used to indicate "looking for a value": implements
236
-	//        the logic to allow values with no types to be strings
237
-	//   params - used to store parameters in method calls
238
-	//   method - used to store method name
239
-	//   stack - array with genealogy of xml elements names:
240
-	//           used to validate nesting of xmlrpc elements
241
-	$GLOBALS['_xh']=null;
242
-
243
-	/**
244
-	* Convert a string to the correct XML representation in a target charset
245
-	* To help correct communication of non-ascii chars inside strings, regardless
246
-	* of the charset used when sending requests, parsing them, sending responses
247
-	* and parsing responses, an option is to convert all non-ascii chars present in the message
248
-	* into their equivalent 'charset entity'. Charset entities enumerated this way
249
-	* are independent of the charset encoding used to transmit them, and all XML
250
-	* parsers are bound to understand them.
251
-	* Note that in the std case we are not sending a charset encoding mime type
252
-	* along with http headers, so we are bound by RFC 3023 to emit strict us-ascii.
253
-	*
254
-	* @todo do a bit of basic benchmarking (strtr vs. str_replace)
255
-	* @todo	make usage of iconv() or recode_string() or mb_string() where available
256
-	*/
257
-	function xmlrpc_encode_entitites($data, $src_encoding='', $dest_encoding='')
258
-	{
259
-		if ($src_encoding == '')
260
-		{
261
-			// lame, but we know no better...
262
-			$src_encoding = $GLOBALS['xmlrpc_internalencoding'];
263
-		}
264
-
265
-		switch(strtoupper($src_encoding.'_'.$dest_encoding))
266
-		{
267
-			case 'ISO-8859-1_':
268
-			case 'ISO-8859-1_US-ASCII':
269
-				$escaped_data = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $data);
270
-				$escaped_data = str_replace($GLOBALS['xml_iso88591_Entities']['in'], $GLOBALS['xml_iso88591_Entities']['out'], $escaped_data);
271
-				break;
272
-			case 'ISO-8859-1_UTF-8':
273
-				$escaped_data = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $data);
274
-				$escaped_data = utf8_encode($escaped_data);
275
-				break;
276
-			case 'ISO-8859-1_ISO-8859-1':
277
-			case 'US-ASCII_US-ASCII':
278
-			case 'US-ASCII_UTF-8':
279
-			case 'US-ASCII_':
280
-			case 'US-ASCII_ISO-8859-1':
281
-			case 'UTF-8_UTF-8':
282
-			//case 'CP1252_CP1252':
283
-				$escaped_data = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $data);
284
-				break;
285
-			case 'UTF-8_':
286
-			case 'UTF-8_US-ASCII':
287
-			case 'UTF-8_ISO-8859-1':
288
-	// NB: this will choke on invalid UTF-8, going most likely beyond EOF
289
-	$escaped_data = '';
290
-	// be kind to users creating string xmlrpcvals out of different php types
291
-	$data = (string) $data;
292
-	$ns = strlen ($data);
293
-	for ($nn = 0; $nn < $ns; $nn++)
294
-	{
295
-		$ch = $data[$nn];
296
-		$ii = ord($ch);
297
-		//1 7 0bbbbbbb (127)
298
-		if ($ii < 128)
299
-		{
300
-			/// @todo shall we replace this with a (supposedly) faster str_replace?
301
-			switch($ii){
302
-				case 34:
303
-					$escaped_data .= '&quot;';
304
-					break;
305
-				case 38:
306
-					$escaped_data .= '&amp;';
307
-					break;
308
-				case 39:
309
-					$escaped_data .= '&apos;';
310
-					break;
311
-				case 60:
312
-					$escaped_data .= '&lt;';
313
-					break;
314
-				case 62:
315
-					$escaped_data .= '&gt;';
316
-					break;
317
-				default:
318
-					$escaped_data .= $ch;
319
-			} // switch
320
-		}
321
-		//2 11 110bbbbb 10bbbbbb (2047)
322
-		else if ($ii>>5 == 6)
323
-		{
324
-			$b1 = ($ii & 31);
325
-			$ii = ord($data[$nn+1]);
326
-			$b2 = ($ii & 63);
327
-			$ii = ($b1 * 64) + $b2;
328
-			$ent = sprintf ('&#%d;', $ii);
329
-			$escaped_data .= $ent;
330
-			$nn += 1;
331
-		}
332
-		//3 16 1110bbbb 10bbbbbb 10bbbbbb
333
-		else if ($ii>>4 == 14)
334
-		{
335
-			$b1 = ($ii & 15);
336
-			$ii = ord($data[$nn+1]);
337
-			$b2 = ($ii & 63);
338
-			$ii = ord($data[$nn+2]);
339
-			$b3 = ($ii & 63);
340
-			$ii = ((($b1 * 64) + $b2) * 64) + $b3;
341
-			$ent = sprintf ('&#%d;', $ii);
342
-			$escaped_data .= $ent;
343
-			$nn += 2;
344
-		}
345
-		//4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
346
-		else if ($ii>>3 == 30)
347
-		{
348
-			$b1 = ($ii & 7);
349
-			$ii = ord($data[$nn+1]);
350
-			$b2 = ($ii & 63);
351
-			$ii = ord($data[$nn+2]);
352
-			$b3 = ($ii & 63);
353
-			$ii = ord($data[$nn+3]);
354
-			$b4 = ($ii & 63);
355
-			$ii = ((((($b1 * 64) + $b2) * 64) + $b3) * 64) + $b4;
356
-			$ent = sprintf ('&#%d;', $ii);
357
-			$escaped_data .= $ent;
358
-			$nn += 3;
359
-		}
360
-	}
361
-				break;
146
+    $GLOBALS['xmlrpcerr'] = array(
147
+    'unknown_method'=>1,
148
+    'invalid_return'=>2,
149
+    'incorrect_params'=>3,
150
+    'introspect_unknown'=>4,
151
+    'http_error'=>5,
152
+    'no_data'=>6,
153
+    'no_ssl'=>7,
154
+    'curl_fail'=>8,
155
+    'invalid_request'=>15,
156
+    'no_curl'=>16,
157
+    'server_error'=>17,
158
+    'multicall_error'=>18,
159
+    'multicall_notstruct'=>9,
160
+    'multicall_nomethod'=>10,
161
+    'multicall_notstring'=>11,
162
+    'multicall_recursion'=>12,
163
+    'multicall_noparams'=>13,
164
+    'multicall_notarray'=>14,
165
+
166
+    'cannot_decompress'=>103,
167
+    'decompress_fail'=>104,
168
+    'dechunk_fail'=>105,
169
+    'server_cannot_decompress'=>106,
170
+    'server_decompress_fail'=>107
171
+    );
172
+
173
+    $GLOBALS['xmlrpcstr'] = array(
174
+    'unknown_method'=>'Unknown method',
175
+    'invalid_return'=>'Invalid return payload: enable debugging to examine incoming payload',
176
+    'incorrect_params'=>'Incorrect parameters passed to method',
177
+    'introspect_unknown'=>"Can't introspect: method unknown",
178
+    'http_error'=>"Didn't receive 200 OK from remote server.",
179
+    'no_data'=>'No data received from server.',
180
+    'no_ssl'=>'No SSL support compiled in.',
181
+    'curl_fail'=>'CURL error',
182
+    'invalid_request'=>'Invalid request payload',
183
+    'no_curl'=>'No CURL support compiled in.',
184
+    'server_error'=>'Internal server error',
185
+    'multicall_error'=>'Received from server invalid multicall response',
186
+    'multicall_notstruct'=>'system.multicall expected struct',
187
+    'multicall_nomethod'=>'missing methodName',
188
+    'multicall_notstring'=>'methodName is not a string',
189
+    'multicall_recursion'=>'recursive system.multicall forbidden',
190
+    'multicall_noparams'=>'missing params',
191
+    'multicall_notarray'=>'params is not an array',
192
+
193
+    'cannot_decompress'=>'Received from server compressed HTTP and cannot decompress',
194
+    'decompress_fail'=>'Received from server invalid compressed HTTP',
195
+    'dechunk_fail'=>'Received from server invalid chunked HTTP',
196
+    'server_cannot_decompress'=>'Received from client compressed HTTP request and cannot decompress',
197
+    'server_decompress_fail'=>'Received from client invalid compressed HTTP request'
198
+    );
199
+
200
+    // The charset encoding used by the server for received messages and
201
+    // by the client for received responses when received charset cannot be determined
202
+    // or is not supported
203
+    $GLOBALS['xmlrpc_defencoding']='UTF-8';
204
+
205
+    // The encoding used internally by PHP.
206
+    // String values received as xml will be converted to this, and php strings will be converted to xml
207
+    // as if having been coded with this
208
+    $GLOBALS['xmlrpc_internalencoding']='ISO-8859-1';
209
+
210
+    $GLOBALS['xmlrpcName']='XML-RPC for PHP';
211
+    $GLOBALS['xmlrpcVersion']='3.0.1';
212
+
213
+    // let user errors start at 800
214
+    $GLOBALS['xmlrpcerruser']=800;
215
+    // let XML parse errors start at 100
216
+    $GLOBALS['xmlrpcerrxml']=100;
217
+
218
+    // formulate backslashes for escaping regexp
219
+    // Not in use anymore since 2.0. Shall we remove it?
220
+    /// @deprecated
221
+    $GLOBALS['xmlrpc_backslash']=chr(92).chr(92);
222
+
223
+    // set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values
224
+    $GLOBALS['xmlrpc_null_extension']=false;
225
+
226
+    // set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
227
+    $GLOBALS['xmlrpc_null_apache_encoding']=false;
228
+    $GLOBALS['xmlrpc_null_apache_encoding_ns']='http://ws.apache.org/xmlrpc/namespaces/extensions';
229
+
230
+    // used to store state during parsing
231
+    // quick explanation of components:
232
+    //   ac - used to accumulate values
233
+    //   isf - used to indicate a parsing fault (2) or xmlrpcresp fault (1)
234
+    //   isf_reason - used for storing xmlrpcresp fault string
235
+    //   lv - used to indicate "looking for a value": implements
236
+    //        the logic to allow values with no types to be strings
237
+    //   params - used to store parameters in method calls
238
+    //   method - used to store method name
239
+    //   stack - array with genealogy of xml elements names:
240
+    //           used to validate nesting of xmlrpc elements
241
+    $GLOBALS['_xh']=null;
242
+
243
+    /**
244
+     * Convert a string to the correct XML representation in a target charset
245
+     * To help correct communication of non-ascii chars inside strings, regardless
246
+     * of the charset used when sending requests, parsing them, sending responses
247
+     * and parsing responses, an option is to convert all non-ascii chars present in the message
248
+     * into their equivalent 'charset entity'. Charset entities enumerated this way
249
+     * are independent of the charset encoding used to transmit them, and all XML
250
+     * parsers are bound to understand them.
251
+     * Note that in the std case we are not sending a charset encoding mime type
252
+     * along with http headers, so we are bound by RFC 3023 to emit strict us-ascii.
253
+     *
254
+     * @todo do a bit of basic benchmarking (strtr vs. str_replace)
255
+     * @todo	make usage of iconv() or recode_string() or mb_string() where available
256
+     */
257
+    function xmlrpc_encode_entitites($data, $src_encoding='', $dest_encoding='')
258
+    {
259
+        if ($src_encoding == '')
260
+        {
261
+            // lame, but we know no better...
262
+            $src_encoding = $GLOBALS['xmlrpc_internalencoding'];
263
+        }
264
+
265
+        switch(strtoupper($src_encoding.'_'.$dest_encoding))
266
+        {
267
+            case 'ISO-8859-1_':
268
+            case 'ISO-8859-1_US-ASCII':
269
+                $escaped_data = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $data);
270
+                $escaped_data = str_replace($GLOBALS['xml_iso88591_Entities']['in'], $GLOBALS['xml_iso88591_Entities']['out'], $escaped_data);
271
+                break;
272
+            case 'ISO-8859-1_UTF-8':
273
+                $escaped_data = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $data);
274
+                $escaped_data = utf8_encode($escaped_data);
275
+                break;
276
+            case 'ISO-8859-1_ISO-8859-1':
277
+            case 'US-ASCII_US-ASCII':
278
+            case 'US-ASCII_UTF-8':
279
+            case 'US-ASCII_':
280
+            case 'US-ASCII_ISO-8859-1':
281
+            case 'UTF-8_UTF-8':
282
+            //case 'CP1252_CP1252':
283
+                $escaped_data = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $data);
284
+                break;
285
+            case 'UTF-8_':
286
+            case 'UTF-8_US-ASCII':
287
+            case 'UTF-8_ISO-8859-1':
288
+    // NB: this will choke on invalid UTF-8, going most likely beyond EOF
289
+    $escaped_data = '';
290
+    // be kind to users creating string xmlrpcvals out of different php types
291
+    $data = (string) $data;
292
+    $ns = strlen ($data);
293
+    for ($nn = 0; $nn < $ns; $nn++)
294
+    {
295
+        $ch = $data[$nn];
296
+        $ii = ord($ch);
297
+        //1 7 0bbbbbbb (127)
298
+        if ($ii < 128)
299
+        {
300
+            /// @todo shall we replace this with a (supposedly) faster str_replace?
301
+            switch($ii){
302
+                case 34:
303
+                    $escaped_data .= '&quot;';
304
+                    break;
305
+                case 38:
306
+                    $escaped_data .= '&amp;';
307
+                    break;
308
+                case 39:
309
+                    $escaped_data .= '&apos;';
310
+                    break;
311
+                case 60:
312
+                    $escaped_data .= '&lt;';
313
+                    break;
314
+                case 62:
315
+                    $escaped_data .= '&gt;';
316
+                    break;
317
+                default:
318
+                    $escaped_data .= $ch;
319
+            } // switch
320
+        }
321
+        //2 11 110bbbbb 10bbbbbb (2047)
322
+        else if ($ii>>5 == 6)
323
+        {
324
+            $b1 = ($ii & 31);
325
+            $ii = ord($data[$nn+1]);
326
+            $b2 = ($ii & 63);
327
+            $ii = ($b1 * 64) + $b2;
328
+            $ent = sprintf ('&#%d;', $ii);
329
+            $escaped_data .= $ent;
330
+            $nn += 1;
331
+        }
332
+        //3 16 1110bbbb 10bbbbbb 10bbbbbb
333
+        else if ($ii>>4 == 14)
334
+        {
335
+            $b1 = ($ii & 15);
336
+            $ii = ord($data[$nn+1]);
337
+            $b2 = ($ii & 63);
338
+            $ii = ord($data[$nn+2]);
339
+            $b3 = ($ii & 63);
340
+            $ii = ((($b1 * 64) + $b2) * 64) + $b3;
341
+            $ent = sprintf ('&#%d;', $ii);
342
+            $escaped_data .= $ent;
343
+            $nn += 2;
344
+        }
345
+        //4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
346
+        else if ($ii>>3 == 30)
347
+        {
348
+            $b1 = ($ii & 7);
349
+            $ii = ord($data[$nn+1]);
350
+            $b2 = ($ii & 63);
351
+            $ii = ord($data[$nn+2]);
352
+            $b3 = ($ii & 63);
353
+            $ii = ord($data[$nn+3]);
354
+            $b4 = ($ii & 63);
355
+            $ii = ((((($b1 * 64) + $b2) * 64) + $b3) * 64) + $b4;
356
+            $ent = sprintf ('&#%d;', $ii);
357
+            $escaped_data .= $ent;
358
+            $nn += 3;
359
+        }
360
+    }
361
+                break;
362 362
 /*
363 363
 			case 'CP1252_':
364 364
 			case 'CP1252_US-ASCII':
@@ -378,2443 +378,2443 @@  discard block
 block discarded – undo
378 378
 				$escaped_data = str_replace($GLOBALS['xml_cp1252_Entities']['in'], $GLOBALS['xml_cp1252_Entities']['out'], $escaped_data);
379 379
 				break;
380 380
 */
381
-			default:
382
-				$escaped_data = '';
383
-				error_log("Converting from $src_encoding to $dest_encoding: not supported...");
384
-		}
385
-		return $escaped_data;
386
-	}
387
-
388
-	/// xml parser handler function for opening element tags
389
-	function xmlrpc_se($parser, $name, $attrs, $accept_single_vals=false)
390
-	{
391
-		// if invalid xmlrpc already detected, skip all processing
392
-		if ($GLOBALS['_xh']['isf'] < 2)
393
-		{
394
-			// check for correct element nesting
395
-			// top level element can only be of 2 types
396
-			/// @todo optimization creep: save this check into a bool variable, instead of using count() every time:
397
-			///       there is only a single top level element in xml anyway
398
-			if (count($GLOBALS['_xh']['stack']) == 0)
399
-			{
400
-				if ($name != 'METHODRESPONSE' && $name != 'METHODCALL' && (
401
-					$name != 'VALUE' && !$accept_single_vals))
402
-				{
403
-					$GLOBALS['_xh']['isf'] = 2;
404
-					$GLOBALS['_xh']['isf_reason'] = 'missing top level xmlrpc element';
405
-					return;
406
-				}
407
-				else
408
-				{
409
-					$GLOBALS['_xh']['rt'] = strtolower($name);
410
-					$GLOBALS['_xh']['rt'] = strtolower($name);
411
-				}
412
-			}
413
-			else
414
-			{
415
-				// not top level element: see if parent is OK
416
-				$parent = end($GLOBALS['_xh']['stack']);
417
-				if (!array_key_exists($name, $GLOBALS['xmlrpc_valid_parents']) || !in_array($parent, $GLOBALS['xmlrpc_valid_parents'][$name]))
418
-				{
419
-					$GLOBALS['_xh']['isf'] = 2;
420
-					$GLOBALS['_xh']['isf_reason'] = "xmlrpc element $name cannot be child of $parent";
421
-					return;
422
-				}
423
-			}
424
-
425
-			switch($name)
426
-			{
427
-				// optimize for speed switch cases: most common cases first
428
-				case 'VALUE':
429
-					/// @todo we could check for 2 VALUE elements inside a MEMBER or PARAM element
430
-					$GLOBALS['_xh']['vt']='value'; // indicator: no value found yet
431
-					$GLOBALS['_xh']['ac']='';
432
-					$GLOBALS['_xh']['lv']=1;
433
-					$GLOBALS['_xh']['php_class']=null;
434
-					break;
435
-				case 'I4':
436
-				case 'INT':
437
-				case 'STRING':
438
-				case 'BOOLEAN':
439
-				case 'DOUBLE':
440
-				case 'DATETIME.ISO8601':
441
-				case 'BASE64':
442
-					if ($GLOBALS['_xh']['vt']!='value')
443
-					{
444
-						//two data elements inside a value: an error occurred!
445
-						$GLOBALS['_xh']['isf'] = 2;
446
-						$GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
447
-						return;
448
-					}
449
-					$GLOBALS['_xh']['ac']=''; // reset the accumulator
450
-					break;
451
-				case 'STRUCT':
452
-				case 'ARRAY':
453
-					if ($GLOBALS['_xh']['vt']!='value')
454
-					{
455
-						//two data elements inside a value: an error occurred!
456
-						$GLOBALS['_xh']['isf'] = 2;
457
-						$GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
458
-						return;
459
-					}
460
-					// create an empty array to hold child values, and push it onto appropriate stack
461
-					$cur_val = array();
462
-					$cur_val['values'] = array();
463
-					$cur_val['type'] = $name;
464
-					// check for out-of-band information to rebuild php objs
465
-					// and in case it is found, save it
466
-					if (@isset($attrs['PHP_CLASS']))
467
-					{
468
-						$cur_val['php_class'] = $attrs['PHP_CLASS'];
469
-					}
470
-					$GLOBALS['_xh']['valuestack'][] = $cur_val;
471
-					$GLOBALS['_xh']['vt']='data'; // be prepared for a data element next
472
-					break;
473
-				case 'DATA':
474
-					if ($GLOBALS['_xh']['vt']!='data')
475
-					{
476
-						//two data elements inside a value: an error occurred!
477
-						$GLOBALS['_xh']['isf'] = 2;
478
-						$GLOBALS['_xh']['isf_reason'] = "found two data elements inside an array element";
479
-						return;
480
-					}
481
-				case 'METHODCALL':
482
-				case 'METHODRESPONSE':
483
-				case 'PARAMS':
484
-					// valid elements that add little to processing
485
-					break;
486
-				case 'METHODNAME':
487
-				case 'NAME':
488
-					/// @todo we could check for 2 NAME elements inside a MEMBER element
489
-					$GLOBALS['_xh']['ac']='';
490
-					break;
491
-				case 'FAULT':
492
-					$GLOBALS['_xh']['isf']=1;
493
-					break;
494
-				case 'MEMBER':
495
-					$GLOBALS['_xh']['valuestack'][count($GLOBALS['_xh']['valuestack'])-1]['name']=''; // set member name to null, in case we do not find in the xml later on
496
-					//$GLOBALS['_xh']['ac']='';
497
-					// Drop trough intentionally
498
-				case 'PARAM':
499
-					// clear value type, so we can check later if no value has been passed for this param/member
500
-					$GLOBALS['_xh']['vt']=null;
501
-					break;
502
-				case 'NIL':
503
-				case 'EX:NIL':
504
-					if ($GLOBALS['xmlrpc_null_extension'])
505
-					{
506
-						if ($GLOBALS['_xh']['vt']!='value')
507
-						{
508
-							//two data elements inside a value: an error occurred!
509
-							$GLOBALS['_xh']['isf'] = 2;
510
-							$GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
511
-							return;
512
-						}
513
-						$GLOBALS['_xh']['ac']=''; // reset the accumulator
514
-						break;
515
-					}
516
-					// we do not support the <NIL/> extension, so
517
-					// drop through intentionally
518
-				default:
519
-					/// INVALID ELEMENT: RAISE ISF so that it is later recognized!!!
520
-					$GLOBALS['_xh']['isf'] = 2;
521
-					$GLOBALS['_xh']['isf_reason'] = "found not-xmlrpc xml element $name";
522
-					break;
523
-			}
524
-
525
-			// Save current element name to stack, to validate nesting
526
-			$GLOBALS['_xh']['stack'][] = $name;
527
-
528
-			/// @todo optimization creep: move this inside the big switch() above
529
-			if($name!='VALUE')
530
-			{
531
-				$GLOBALS['_xh']['lv']=0;
532
-			}
533
-		}
534
-	}
535
-
536
-	/// Used in decoding xml chunks that might represent single xmlrpc values
537
-	function xmlrpc_se_any($parser, $name, $attrs)
538
-	{
539
-		xmlrpc_se($parser, $name, $attrs, true);
540
-	}
541
-
542
-	/// xml parser handler function for close element tags
543
-	function xmlrpc_ee($parser, $name, $rebuild_xmlrpcvals = true)
544
-	{
545
-		if ($GLOBALS['_xh']['isf'] < 2)
546
-		{
547
-			// push this element name from stack
548
-			// NB: if XML validates, correct opening/closing is guaranteed and
549
-			// we do not have to check for $name == $curr_elem.
550
-			// we also checked for proper nesting at start of elements...
551
-			$curr_elem = array_pop($GLOBALS['_xh']['stack']);
552
-
553
-			switch($name)
554
-			{
555
-				case 'VALUE':
556
-					// This if() detects if no scalar was inside <VALUE></VALUE>
557
-					if ($GLOBALS['_xh']['vt']=='value')
558
-					{
559
-						$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
560
-						$GLOBALS['_xh']['vt']=$GLOBALS['xmlrpcString'];
561
-					}
562
-
563
-					if ($rebuild_xmlrpcvals)
564
-					{
565
-						// build the xmlrpc val out of the data received, and substitute it
566
-						$temp = new xmlrpcval($GLOBALS['_xh']['value'], $GLOBALS['_xh']['vt']);
567
-						// in case we got info about underlying php class, save it
568
-						// in the object we're rebuilding
569
-						if (isset($GLOBALS['_xh']['php_class']))
570
-							$temp->_php_class = $GLOBALS['_xh']['php_class'];
571
-						// check if we are inside an array or struct:
572
-						// if value just built is inside an array, let's move it into array on the stack
573
-						$vscount = count($GLOBALS['_xh']['valuestack']);
574
-						if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type']=='ARRAY')
575
-						{
576
-							$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][] = $temp;
577
-						}
578
-						else
579
-						{
580
-							$GLOBALS['_xh']['value'] = $temp;
581
-						}
582
-					}
583
-					else
584
-					{
585
-						/// @todo this needs to treat correctly php-serialized objects,
586
-						/// since std deserializing is done by php_xmlrpc_decode,
587
-						/// which we will not be calling...
588
-						if (isset($GLOBALS['_xh']['php_class']))
589
-						{
590
-						}
591
-
592
-						// check if we are inside an array or struct:
593
-						// if value just built is inside an array, let's move it into array on the stack
594
-						$vscount = count($GLOBALS['_xh']['valuestack']);
595
-						if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type']=='ARRAY')
596
-						{
597
-							$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][] = $GLOBALS['_xh']['value'];
598
-						}
599
-					}
600
-					break;
601
-				case 'BOOLEAN':
602
-				case 'I4':
603
-				case 'INT':
604
-				case 'STRING':
605
-				case 'DOUBLE':
606
-				case 'DATETIME.ISO8601':
607
-				case 'BASE64':
608
-					$GLOBALS['_xh']['vt']=strtolower($name);
609
-					/// @todo: optimization creep - remove the if/elseif cycle below
610
-					/// since the case() in which we are already did that
611
-					if ($name=='STRING')
612
-					{
613
-						$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
614
-					}
615
-					elseif ($name=='DATETIME.ISO8601')
616
-					{
617
-						if (!preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $GLOBALS['_xh']['ac']))
618
-						{
619
-							error_log('XML-RPC: invalid value received in DATETIME: '.$GLOBALS['_xh']['ac']);
620
-						}
621
-						$GLOBALS['_xh']['vt']=$GLOBALS['xmlrpcDateTime'];
622
-						$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
623
-					}
624
-					elseif ($name=='BASE64')
625
-					{
626
-						/// @todo check for failure of base64 decoding / catch warnings
627
-						$GLOBALS['_xh']['value']=base64_decode($GLOBALS['_xh']['ac']);
628
-					}
629
-					elseif ($name=='BOOLEAN')
630
-					{
631
-						// special case here: we translate boolean 1 or 0 into PHP
632
-						// constants true or false.
633
-						// Strings 'true' and 'false' are accepted, even though the
634
-						// spec never mentions them (see eg. Blogger api docs)
635
-						// NB: this simple checks helps a lot sanitizing input, ie no
636
-						// security problems around here
637
-						if ($GLOBALS['_xh']['ac']=='1' || strcasecmp($GLOBALS['_xh']['ac'], 'true') == 0)
638
-						{
639
-							$GLOBALS['_xh']['value']=true;
640
-						}
641
-						else
642
-						{
643
-							// log if receiveing something strange, even though we set the value to false anyway
644
-							if ($GLOBALS['_xh']['ac']!='0' && strcasecmp($GLOBALS['_xh']['ac'], 'false') != 0)
645
-								error_log('XML-RPC: invalid value received in BOOLEAN: '.$GLOBALS['_xh']['ac']);
646
-							$GLOBALS['_xh']['value']=false;
647
-						}
648
-					}
649
-					elseif ($name=='DOUBLE')
650
-					{
651
-						// we have a DOUBLE
652
-						// we must check that only 0123456789-.<space> are characters here
653
-						// NOTE: regexp could be much stricter than this...
654
-						if (!preg_match('/^[+-eE0123456789 \t.]+$/', $GLOBALS['_xh']['ac']))
655
-						{
656
-							/// @todo: find a better way of throwing an error than this!
657
-							error_log('XML-RPC: non numeric value received in DOUBLE: '.$GLOBALS['_xh']['ac']);
658
-							$GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
659
-						}
660
-						else
661
-						{
662
-							// it's ok, add it on
663
-							$GLOBALS['_xh']['value']=(double)$GLOBALS['_xh']['ac'];
664
-						}
665
-					}
666
-					else
667
-					{
668
-						// we have an I4/INT
669
-						// we must check that only 0123456789-<space> are characters here
670
-						if (!preg_match('/^[+-]?[0123456789 \t]+$/', $GLOBALS['_xh']['ac']))
671
-						{
672
-							/// @todo find a better way of throwing an error than this!
673
-							error_log('XML-RPC: non numeric value received in INT: '.$GLOBALS['_xh']['ac']);
674
-							$GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
675
-						}
676
-						else
677
-						{
678
-							// it's ok, add it on
679
-							$GLOBALS['_xh']['value']=(int)$GLOBALS['_xh']['ac'];
680
-						}
681
-					}
682
-					//$GLOBALS['_xh']['ac']=''; // is this necessary?
683
-					$GLOBALS['_xh']['lv']=3; // indicate we've found a value
684
-					break;
685
-				case 'NAME':
686
-					$GLOBALS['_xh']['valuestack'][count($GLOBALS['_xh']['valuestack'])-1]['name'] = $GLOBALS['_xh']['ac'];
687
-					break;
688
-				case 'MEMBER':
689
-					//$GLOBALS['_xh']['ac']=''; // is this necessary?
690
-					// add to array in the stack the last element built,
691
-					// unless no VALUE was found
692
-					if ($GLOBALS['_xh']['vt'])
693
-					{
694
-						$vscount = count($GLOBALS['_xh']['valuestack']);
695
-						$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][$GLOBALS['_xh']['valuestack'][$vscount-1]['name']] = $GLOBALS['_xh']['value'];
696
-					} else
697
-						error_log('XML-RPC: missing VALUE inside STRUCT in received xml');
698
-					break;
699
-				case 'DATA':
700
-					//$GLOBALS['_xh']['ac']=''; // is this necessary?
701
-					$GLOBALS['_xh']['vt']=null; // reset this to check for 2 data elements in a row - even if they're empty
702
-					break;
703
-				case 'STRUCT':
704
-				case 'ARRAY':
705
-					// fetch out of stack array of values, and promote it to current value
706
-					$curr_val = array_pop($GLOBALS['_xh']['valuestack']);
707
-					$GLOBALS['_xh']['value'] = $curr_val['values'];
708
-					$GLOBALS['_xh']['vt']=strtolower($name);
709
-					if (isset($curr_val['php_class']))
710
-					{
711
-						$GLOBALS['_xh']['php_class'] = $curr_val['php_class'];
712
-					}
713
-					break;
714
-				case 'PARAM':
715
-					// add to array of params the current value,
716
-					// unless no VALUE was found
717
-					if ($GLOBALS['_xh']['vt'])
718
-					{
719
-						$GLOBALS['_xh']['params'][]=$GLOBALS['_xh']['value'];
720
-						$GLOBALS['_xh']['pt'][]=$GLOBALS['_xh']['vt'];
721
-					}
722
-					else
723
-						error_log('XML-RPC: missing VALUE inside PARAM in received xml');
724
-					break;
725
-				case 'METHODNAME':
726
-					$GLOBALS['_xh']['method']=preg_replace('/^[\n\r\t ]+/', '', $GLOBALS['_xh']['ac']);
727
-					break;
728
-				case 'NIL':
729
-				case 'EX:NIL':
730
-					if ($GLOBALS['xmlrpc_null_extension'])
731
-					{
732
-						$GLOBALS['_xh']['vt']='null';
733
-						$GLOBALS['_xh']['value']=null;
734
-						$GLOBALS['_xh']['lv']=3;
735
-						break;
736
-					}
737
-					// drop through intentionally if nil extension not enabled
738
-				case 'PARAMS':
739
-				case 'FAULT':
740
-				case 'METHODCALL':
741
-				case 'METHORESPONSE':
742
-					break;
743
-				default:
744
-					// End of INVALID ELEMENT!
745
-					// shall we add an assert here for unreachable code???
746
-					break;
747
-			}
748
-		}
749
-	}
750
-
751
-	/// Used in decoding xmlrpc requests/responses without rebuilding xmlrpc values
752
-	function xmlrpc_ee_fast($parser, $name)
753
-	{
754
-		xmlrpc_ee($parser, $name, false);
755
-	}
756
-
757
-	/// xml parser handler function for character data
758
-	function xmlrpc_cd($parser, $data)
759
-	{
760
-		// skip processing if xml fault already detected
761
-		if ($GLOBALS['_xh']['isf'] < 2)
762
-		{
763
-			// "lookforvalue==3" means that we've found an entire value
764
-			// and should discard any further character data
765
-			if($GLOBALS['_xh']['lv']!=3)
766
-			{
767
-				// G. Giunta 2006-08-23: useless change of 'lv' from 1 to 2
768
-				//if($GLOBALS['_xh']['lv']==1)
769
-				//{
770
-					// if we've found text and we're just in a <value> then
771
-					// say we've found a value
772
-					//$GLOBALS['_xh']['lv']=2;
773
-				//}
774
-				// we always initialize the accumulator before starting parsing, anyway...
775
-				//if(!@isset($GLOBALS['_xh']['ac']))
776
-				//{
777
-				//	$GLOBALS['_xh']['ac'] = '';
778
-				//}
779
-				$GLOBALS['_xh']['ac'].=$data;
780
-			}
781
-		}
782
-	}
783
-
784
-	/// xml parser handler function for 'other stuff', ie. not char data or
785
-	/// element start/end tag. In fact it only gets called on unknown entities...
786
-	function xmlrpc_dh($parser, $data)
787
-	{
788
-		// skip processing if xml fault already detected
789
-		if ($GLOBALS['_xh']['isf'] < 2)
790
-		{
791
-			if(substr($data, 0, 1) == '&' && substr($data, -1, 1) == ';')
792
-			{
793
-				// G. Giunta 2006-08-25: useless change of 'lv' from 1 to 2
794
-				//if($GLOBALS['_xh']['lv']==1)
795
-				//{
796
-				//	$GLOBALS['_xh']['lv']=2;
797
-				//}
798
-				$GLOBALS['_xh']['ac'].=$data;
799
-			}
800
-		}
801
-		return true;
802
-	}
803
-
804
-	class xmlrpc_client
805
-	{
806
-		var $path;
807
-		var $server;
808
-		var $port=0;
809
-		var $method='http';
810
-		var $errno;
811
-		var $errstr;
812
-		var $debug=0;
813
-		var $username='';
814
-		var $password='';
815
-		var $authtype=1;
816
-		var $cert='';
817
-		var $certpass='';
818
-		var $cacert='';
819
-		var $cacertdir='';
820
-		var $key='';
821
-		var $keypass='';
822
-		var $verifypeer=true;
823
-		var $verifyhost=1;
824
-		var $no_multicall=false;
825
-		var $proxy='';
826
-		var $proxyport=0;
827
-		var $proxy_user='';
828
-		var $proxy_pass='';
829
-		var $proxy_authtype=1;
830
-		var $cookies=array();
831
-		var $extracurlopts=array();
832
-
833
-		/**
834
-		* List of http compression methods accepted by the client for responses.
835
-		* NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib
836
-		*
837
-		* NNB: you can set it to any non-empty array for HTTP11 and HTTPS, since
838
-		* in those cases it will be up to CURL to decide the compression methods
839
-		* it supports. You might check for the presence of 'zlib' in the output of
840
-		* curl_version() to determine wheter compression is supported or not
841
-		*/
842
-		var $accepted_compression = array();
843
-		/**
844
-		* Name of compression scheme to be used for sending requests.
845
-		* Either null, gzip or deflate
846
-		*/
847
-		var $request_compression = '';
848
-		/**
849
-		* CURL handle: used for keep-alive connections (PHP 4.3.8 up, see:
850
-		* http://curl.haxx.se/docs/faq.html#7.3)
851
-		*/
852
-		var $xmlrpc_curl_handle = null;
853
-		/// Whether to use persistent connections for http 1.1 and https
854
-		var $keepalive = false;
855
-		/// Charset encodings that can be decoded without problems by the client
856
-		var $accepted_charset_encodings = array();
857
-		/// Charset encoding to be used in serializing request. NULL = use ASCII
858
-		var $request_charset_encoding = '';
859
-		/**
860
-		* Decides the content of xmlrpcresp objects returned by calls to send()
861
-		* valid strings are 'xmlrpcvals', 'phpvals' or 'xml'
862
-		*/
863
-		var $return_type = 'xmlrpcvals';
864
-		/**
865
-		* Sent to servers in http headers
866
-		*/
867
-		var $user_agent;
868
-
869
-		/**
870
-		* @param string $path either the complete server URL or the PATH part of the xmlrc server URL, e.g. /xmlrpc/server.php
871
-		* @param string $server the server name / ip address
872
-		* @param integer $port the port the server is listening on, defaults to 80 or 443 depending on protocol used
873
-		* @param string $method the http protocol variant: defaults to 'http', 'https' and 'http11' can be used if CURL is installed
874
-		*/
875
-		function __construct($path, $server='', $port='', $method='')
876
-		{
877
-			// allow user to specify all params in $path
878
-			if($server == '' and $port == '' and $method == '')
879
-			{
880
-				$parts = parse_url($path);
881
-				$server = $parts['host'];
882
-				$path = isset($parts['path']) ? $parts['path'] : '';
883
-				if(isset($parts['query']))
884
-				{
885
-					$path .= '?'.$parts['query'];
886
-				}
887
-				if(isset($parts['fragment']))
888
-				{
889
-					$path .= '#'.$parts['fragment'];
890
-				}
891
-				if(isset($parts['port']))
892
-				{
893
-					$port = $parts['port'];
894
-				}
895
-				if(isset($parts['scheme']))
896
-				{
897
-					$method = $parts['scheme'];
898
-				}
899
-				if(isset($parts['user']))
900
-				{
901
-					$this->username = $parts['user'];
902
-				}
903
-				if(isset($parts['pass']))
904
-				{
905
-					$this->password = $parts['pass'];
906
-				}
907
-			}
908
-			if($path == '' || $path[0] != '/')
909
-			{
910
-				$this->path='/'.$path;
911
-			}
912
-			else
913
-			{
914
-				$this->path=$path;
915
-			}
916
-			$this->server=$server;
917
-			if($port != '')
918
-			{
919
-				$this->port=$port;
920
-			}
921
-			if($method != '')
922
-			{
923
-				$this->method=$method;
924
-			}
925
-
926
-			// if ZLIB is enabled, let the client by default accept compressed responses
927
-			if(function_exists('gzinflate') || (
928
-				function_exists('curl_init') && (($info = curl_version()) &&
929
-				((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version'])))
930
-			))
931
-			{
932
-				$this->accepted_compression = array('gzip', 'deflate');
933
-			}
934
-
935
-			// keepalives: enabled by default
936
-			$this->keepalive = true;
937
-
938
-			// by default the xml parser can support these 3 charset encodings
939
-			$this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
940
-
941
-			// initialize user_agent string
942
-			$this->user_agent = $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion'];
943
-		}
944
-
945
-		/**
946
-		* @deprecated
947
-		*/
948
-		function xmlrpc_client($path, $server='', $port='', $method='')
949
-		{
950
-			self::__construct($path, $server, $port, $method);
951
-		}
952
-
953
-		/**
954
-		* Enables/disables the echoing to screen of the xmlrpc responses received
955
-		* @param integer $in values 0, 1 and 2 are supported (2 = echo sent msg too, before received response)
956
-		* @access public
957
-		*/
958
-		function setDebug($in)
959
-		{
960
-			$this->debug=$in;
961
-		}
962
-
963
-		/**
964
-		* Add some http BASIC AUTH credentials, used by the client to authenticate
965
-		* @param string $u username
966
-		* @param string $p password
967
-		* @param integer $t auth type. See curl_setopt man page for supported auth types. Defaults to CURLAUTH_BASIC (basic auth)
968
-		* @access public
969
-		*/
970
-		function setCredentials($u, $p, $t=1)
971
-		{
972
-			$this->username=$u;
973
-			$this->password=$p;
974
-			$this->authtype=$t;
975
-		}
976
-
977
-		/**
978
-		* Add a client-side https certificate
979
-		* @param string $cert
980
-		* @param string $certpass
981
-		* @access public
982
-		*/
983
-		function setCertificate($cert, $certpass)
984
-		{
985
-			$this->cert = $cert;
986
-			$this->certpass = $certpass;
987
-		}
988
-
989
-		/**
990
-		* Add a CA certificate to verify server with (see man page about
991
-		* CURLOPT_CAINFO for more details)
992
-		* @param string $cacert certificate file name (or dir holding certificates)
993
-		* @param bool $is_dir set to true to indicate cacert is a dir. defaults to false
994
-		* @access public
995
-		*/
996
-		function setCaCertificate($cacert, $is_dir=false)
997
-		{
998
-			if ($is_dir)
999
-			{
1000
-				$this->cacertdir = $cacert;
1001
-			}
1002
-			else
1003
-			{
1004
-				$this->cacert = $cacert;
1005
-			}
1006
-		}
1007
-
1008
-		/**
1009
-		* Set attributes for SSL communication: private SSL key
1010
-		* NB: does not work in older php/curl installs
1011
-		* Thanks to Daniel Convissor
1012
-		* @param string $key The name of a file containing a private SSL key
1013
-		* @param string $keypass The secret password needed to use the private SSL key
1014
-		* @access public
1015
-		*/
1016
-		function setKey($key, $keypass)
1017
-		{
1018
-			$this->key = $key;
1019
-			$this->keypass = $keypass;
1020
-		}
1021
-
1022
-		/**
1023
-		* Set attributes for SSL communication: verify server certificate
1024
-		* @param bool $i enable/disable verification of peer certificate
1025
-		* @access public
1026
-		*/
1027
-		function setSSLVerifyPeer($i)
1028
-		{
1029
-			$this->verifypeer = $i;
1030
-		}
1031
-
1032
-		/**
1033
-		* Set attributes for SSL communication: verify match of server cert w. hostname
1034
-		* @param int $i
1035
-		* @access public
1036
-		*/
1037
-		function setSSLVerifyHost($i)
1038
-		{
1039
-			$this->verifyhost = $i;
1040
-		}
1041
-
1042
-		/**
1043
-		* Set proxy info
1044
-		* @param string $proxyhost
1045
-		* @param string $proxyport Defaults to 8080 for HTTP and 443 for HTTPS
1046
-		* @param string $proxyusername Leave blank if proxy has public access
1047
-		* @param string $proxypassword Leave blank if proxy has public access
1048
-		* @param int $proxyauthtype set to constant CURLAUTH_NTLM to use NTLM auth with proxy
1049
-		* @access public
1050
-		*/
1051
-		function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1)
1052
-		{
1053
-			$this->proxy = $proxyhost;
1054
-			$this->proxyport = $proxyport;
1055
-			$this->proxy_user = $proxyusername;
1056
-			$this->proxy_pass = $proxypassword;
1057
-			$this->proxy_authtype = $proxyauthtype;
1058
-		}
1059
-
1060
-		/**
1061
-		* Enables/disables reception of compressed xmlrpc responses.
1062
-		* Note that enabling reception of compressed responses merely adds some standard
1063
-		* http headers to xmlrpc requests. It is up to the xmlrpc server to return
1064
-		* compressed responses when receiving such requests.
1065
-		* @param string $compmethod either 'gzip', 'deflate', 'any' or ''
1066
-		* @access public
1067
-		*/
1068
-		function setAcceptedCompression($compmethod)
1069
-		{
1070
-			if ($compmethod == 'any')
1071
-				$this->accepted_compression = array('gzip', 'deflate');
1072
-			else
1073
-				if ($compmethod == false )
1074
-					$this->accepted_compression = array();
1075
-				else
1076
-					$this->accepted_compression = array($compmethod);
1077
-		}
1078
-
1079
-		/**
1080
-		* Enables/disables http compression of xmlrpc request.
1081
-		* Take care when sending compressed requests: servers might not support them
1082
-		* (and automatic fallback to uncompressed requests is not yet implemented)
1083
-		* @param string $compmethod either 'gzip', 'deflate' or ''
1084
-		* @access public
1085
-		*/
1086
-		function setRequestCompression($compmethod)
1087
-		{
1088
-			$this->request_compression = $compmethod;
1089
-		}
1090
-
1091
-		/**
1092
-		* Adds a cookie to list of cookies that will be sent to server.
1093
-		* NB: setting any param but name and value will turn the cookie into a 'version 1' cookie:
1094
-		* do not do it unless you know what you are doing
1095
-		* @param string $name
1096
-		* @param string $value
1097
-		* @param string $path
1098
-		* @param string $domain
1099
-		* @param int $port
1100
-		* @access public
1101
-		*
1102
-		* @todo check correctness of urlencoding cookie value (copied from php way of doing it...)
1103
-		*/
1104
-		function setCookie($name, $value='', $path='', $domain='', $port=null)
1105
-		{
1106
-			$this->cookies[$name]['value'] = urlencode($value);
1107
-			if ($path || $domain || $port)
1108
-			{
1109
-				$this->cookies[$name]['path'] = $path;
1110
-				$this->cookies[$name]['domain'] = $domain;
1111
-				$this->cookies[$name]['port'] = $port;
1112
-				$this->cookies[$name]['version'] = 1;
1113
-			}
1114
-			else
1115
-			{
1116
-				$this->cookies[$name]['version'] = 0;
1117
-			}
1118
-		}
1119
-
1120
-		/**
1121
-		* Directly set cURL options, for extra flexibility
1122
-		* It allows eg. to bind client to a specific IP interface / address
1123
-		* @param array $options
1124
-		*/
1125
-		function SetCurlOptions( $options )
1126
-		{
1127
-			$this->extracurlopts = $options;
1128
-		}
1129
-
1130
-		/**
1131
-		* Set user-agent string that will be used by this client instance
1132
-		* in http headers sent to the server
1133
-		*/
1134
-		function SetUserAgent( $agentstring )
1135
-		{
1136
-			$this->user_agent = $agentstring;
1137
-		}
1138
-
1139
-		/**
1140
-		* Send an xmlrpc request
1141
-		* @param mixed $msg The message object, or an array of messages for using multicall, or the complete xml representation of a request
1142
-		* @param integer $timeout Connection timeout, in seconds, If unspecified, a platform specific timeout will apply
1143
-		* @param string $method if left unspecified, the http protocol chosen during creation of the object will be used
1144
-		* @return xmlrpcresp
1145
-		* @access public
1146
-		*/
1147
-		function& send($msg, $timeout=0, $method='')
1148
-		{
1149
-			// if user deos not specify http protocol, use native method of this client
1150
-			// (i.e. method set during call to constructor)
1151
-			if($method == '')
1152
-			{
1153
-				$method = $this->method;
1154
-			}
1155
-
1156
-			if(is_array($msg))
1157
-			{
1158
-				// $msg is an array of xmlrpcmsg's
1159
-				$r = $this->multicall($msg, $timeout, $method);
1160
-				return $r;
1161
-			}
1162
-			elseif(is_string($msg))
1163
-			{
1164
-				$n = new xmlrpcmsg('');
1165
-				$n->payload = $msg;
1166
-				$msg = $n;
1167
-			}
1168
-
1169
-			// where msg is an xmlrpcmsg
1170
-			$msg->debug=$this->debug;
1171
-
1172
-			if($method == 'https')
1173
-			{
1174
-				$r =& $this->sendPayloadHTTPS(
1175
-					$msg,
1176
-					$this->server,
1177
-					$this->port,
1178
-					$timeout,
1179
-					$this->username,
1180
-					$this->password,
1181
-					$this->authtype,
1182
-					$this->cert,
1183
-					$this->certpass,
1184
-					$this->cacert,
1185
-					$this->cacertdir,
1186
-					$this->proxy,
1187
-					$this->proxyport,
1188
-					$this->proxy_user,
1189
-					$this->proxy_pass,
1190
-					$this->proxy_authtype,
1191
-					$this->keepalive,
1192
-					$this->key,
1193
-					$this->keypass
1194
-				);
1195
-			}
1196
-			elseif($method == 'http11')
1197
-			{
1198
-				$r =& $this->sendPayloadCURL(
1199
-					$msg,
1200
-					$this->server,
1201
-					$this->port,
1202
-					$timeout,
1203
-					$this->username,
1204
-					$this->password,
1205
-					$this->authtype,
1206
-					null,
1207
-					null,
1208
-					null,
1209
-					null,
1210
-					$this->proxy,
1211
-					$this->proxyport,
1212
-					$this->proxy_user,
1213
-					$this->proxy_pass,
1214
-					$this->proxy_authtype,
1215
-					'http',
1216
-					$this->keepalive
1217
-				);
1218
-			}
1219
-			else
1220
-			{
1221
-				$r =& $this->sendPayloadHTTP10(
1222
-					$msg,
1223
-					$this->server,
1224
-					$this->port,
1225
-					$timeout,
1226
-					$this->username,
1227
-					$this->password,
1228
-					$this->authtype,
1229
-					$this->proxy,
1230
-					$this->proxyport,
1231
-					$this->proxy_user,
1232
-					$this->proxy_pass,
1233
-					$this->proxy_authtype
1234
-				);
1235
-			}
1236
-
1237
-			return $r;
1238
-		}
1239
-
1240
-		/**
1241
-		* @access private
1242
-		*/
1243
-		function &sendPayloadHTTP10($msg, $server, $port, $timeout=0,
1244
-			$username='', $password='', $authtype=1, $proxyhost='',
1245
-			$proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1)
1246
-		{
1247
-			if($port==0)
1248
-			{
1249
-				$port=80;
1250
-			}
1251
-
1252
-			// Only create the payload if it was not created previously
1253
-			if(empty($msg->payload))
1254
-			{
1255
-				$msg->createPayload($this->request_charset_encoding);
1256
-			}
1257
-
1258
-			$payload = $msg->payload;
1259
-			// Deflate request body and set appropriate request headers
1260
-			if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
1261
-			{
1262
-				if($this->request_compression == 'gzip')
1263
-				{
1264
-					$a = @gzencode($payload);
1265
-					if($a)
1266
-					{
1267
-						$payload = $a;
1268
-						$encoding_hdr = "Content-Encoding: gzip\r\n";
1269
-					}
1270
-				}
1271
-				else
1272
-				{
1273
-					$a = @gzcompress($payload);
1274
-					if($a)
1275
-					{
1276
-						$payload = $a;
1277
-						$encoding_hdr = "Content-Encoding: deflate\r\n";
1278
-					}
1279
-				}
1280
-			}
1281
-			else
1282
-			{
1283
-				$encoding_hdr = '';
1284
-			}
1285
-
1286
-			// thanks to Grant Rauscher <[email protected]> for this
1287
-			$credentials='';
1288
-			if($username!='')
1289
-			{
1290
-				$credentials='Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
1291
-				if ($authtype != 1)
1292
-				{
1293
-					error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported with HTTP 1.0');
1294
-				}
1295
-			}
1296
-
1297
-			$accepted_encoding = '';
1298
-			if(is_array($this->accepted_compression) && count($this->accepted_compression))
1299
-			{
1300
-				$accepted_encoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n";
1301
-			}
1302
-
1303
-			$proxy_credentials = '';
1304
-			if($proxyhost)
1305
-			{
1306
-				if($proxyport == 0)
1307
-				{
1308
-					$proxyport = 8080;
1309
-				}
1310
-				$connectserver = $proxyhost;
1311
-				$connectport = $proxyport;
1312
-				$uri = 'http://'.$server.':'.$port.$this->path;
1313
-				if($proxyusername != '')
1314
-				{
1315
-					if ($proxyauthtype != 1)
1316
-					{
1317
-						error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported with HTTP 1.0');
1318
-					}
1319
-					$proxy_credentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyusername.':'.$proxypassword) . "\r\n";
1320
-				}
1321
-			}
1322
-			else
1323
-			{
1324
-				$connectserver = $server;
1325
-				$connectport = $port;
1326
-				$uri = $this->path;
1327
-			}
1328
-
1329
-			// Cookie generation, as per rfc2965 (version 1 cookies) or
1330
-			// netscape's rules (version 0 cookies)
1331
-			$cookieheader='';
1332
-			if (count($this->cookies))
1333
-			{
1334
-				$version = '';
1335
-				foreach ($this->cookies as $name => $cookie)
1336
-				{
1337
-					if ($cookie['version'])
1338
-					{
1339
-						$version = ' $Version="' . $cookie['version'] . '";';
1340
-						$cookieheader .= ' ' . $name . '="' . $cookie['value'] . '";';
1341
-						if ($cookie['path'])
1342
-							$cookieheader .= ' $Path="' . $cookie['path'] . '";';
1343
-						if ($cookie['domain'])
1344
-							$cookieheader .= ' $Domain="' . $cookie['domain'] . '";';
1345
-						if ($cookie['port'])
1346
-							$cookieheader .= ' $Port="' . $cookie['port'] . '";';
1347
-					}
1348
-					else
1349
-					{
1350
-						$cookieheader .= ' ' . $name . '=' . $cookie['value'] . ";";
1351
-					}
1352
-				}
1353
-				$cookieheader = 'Cookie:' . $version . substr($cookieheader, 0, -1) . "\r\n";
1354
-			}
1355
-
1356
-			// omit port if 80
1357
-			$port = ($port == 80) ? '' : (':' . $port);
1358
-
1359
-			$op= 'POST ' . $uri. " HTTP/1.0\r\n" .
1360
-				'User-Agent: ' . $this->user_agent . "\r\n" .
1361
-				'Host: '. $server . $port . "\r\n" .
1362
-				$credentials .
1363
-				$proxy_credentials .
1364
-				$accepted_encoding .
1365
-				$encoding_hdr .
1366
-				'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings) . "\r\n" .
1367
-				$cookieheader .
1368
-				'Content-Type: ' . $msg->content_type . "\r\nContent-Length: " .
1369
-				strlen($payload) . "\r\n\r\n" .
1370
-				$payload;
1371
-
1372
-			if($this->debug > 1)
1373
-			{
1374
-				print "<PRE>\n---SENDING---\n" . htmlentities($op) . "\n---END---\n</PRE>";
1375
-				// let the client see this now in case http times out...
1376
-				flush();
1377
-			}
1378
-
1379
-			if($timeout>0)
1380
-			{
1381
-				$fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout);
1382
-			}
1383
-			else
1384
-			{
1385
-				$fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr);
1386
-			}
1387
-			if($fp)
1388
-			{
1389
-				if($timeout>0 && function_exists('stream_set_timeout'))
1390
-				{
1391
-					stream_set_timeout($fp, $timeout);
1392
-				}
1393
-			}
1394
-			else
1395
-			{
1396
-				$this->errstr='Connect error: '.$this->errstr;
1397
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr . ' (' . $this->errno . ')');
1398
-				return $r;
1399
-			}
1400
-
1401
-			if(!fputs($fp, $op, strlen($op)))
1402
-			{
1403
-				fclose($fp);
1404
-				$this->errstr='Write error';
1405
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr);
1406
-				return $r;
1407
-			}
1408
-			else
1409
-			{
1410
-				// reset errno and errstr on successful socket connection
1411
-				$this->errstr = '';
1412
-			}
1413
-			// G. Giunta 2005/10/24: close socket before parsing.
1414
-			// should yield slightly better execution times, and make easier recursive calls (e.g. to follow http redirects)
1415
-			$ipd='';
1416
-			do
1417
-			{
1418
-				// shall we check for $data === FALSE?
1419
-				// as per the manual, it signals an error
1420
-				$ipd.=fread($fp, 32768);
1421
-			} while(!feof($fp));
1422
-			fclose($fp);
1423
-			$r =& $msg->parseResponse($ipd, false, $this->return_type);
1424
-			return $r;
1425
-
1426
-		}
1427
-
1428
-		/**
1429
-		* @access private
1430
-		*/
1431
-		function &sendPayloadHTTPS($msg, $server, $port, $timeout=0, $username='',
1432
-			$password='', $authtype=1, $cert='',$certpass='', $cacert='', $cacertdir='',
1433
-			$proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1,
1434
-			$keepalive=false, $key='', $keypass='')
1435
-		{
1436
-			$r =& $this->sendPayloadCURL($msg, $server, $port, $timeout, $username,
1437
-				$password, $authtype, $cert, $certpass, $cacert, $cacertdir, $proxyhost, $proxyport,
1438
-				$proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass);
1439
-			return $r;
1440
-		}
1441
-
1442
-		/**
1443
-		* Contributed by Justin Miller <[email protected]>
1444
-		* Requires curl to be built into PHP
1445
-		* NB: CURL versions before 7.11.10 cannot use proxy to talk to https servers!
1446
-		* @access private
1447
-		*/
1448
-		function &sendPayloadCURL($msg, $server, $port, $timeout=0, $username='',
1449
-			$password='', $authtype=1, $cert='', $certpass='', $cacert='', $cacertdir='',
1450
-			$proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1, $method='https',
1451
-			$keepalive=false, $key='', $keypass='')
1452
-		{
1453
-			if(!function_exists('curl_init'))
1454
-			{
1455
-				$this->errstr='CURL unavailable on this install';
1456
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_curl'], $GLOBALS['xmlrpcstr']['no_curl']);
1457
-				return $r;
1458
-			}
1459
-			if($method == 'https')
1460
-			{
1461
-				if(($info = curl_version()) &&
1462
-					((is_string($info) && strpos($info, 'OpenSSL') === null) || (is_array($info) && !isset($info['ssl_version']))))
1463
-				{
1464
-					$this->errstr='SSL unavailable on this install';
1465
-					$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_ssl'], $GLOBALS['xmlrpcstr']['no_ssl']);
1466
-					return $r;
1467
-				}
1468
-			}
1469
-
1470
-			if($port == 0)
1471
-			{
1472
-				if($method == 'http')
1473
-				{
1474
-					$port = 80;
1475
-				}
1476
-				else
1477
-				{
1478
-					$port = 443;
1479
-				}
1480
-			}
1481
-
1482
-			// Only create the payload if it was not created previously
1483
-			if(empty($msg->payload))
1484
-			{
1485
-				$msg->createPayload($this->request_charset_encoding);
1486
-			}
1487
-
1488
-			// Deflate request body and set appropriate request headers
1489
-			$payload = $msg->payload;
1490
-			if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
1491
-			{
1492
-				if($this->request_compression == 'gzip')
1493
-				{
1494
-					$a = @gzencode($payload);
1495
-					if($a)
1496
-					{
1497
-						$payload = $a;
1498
-						$encoding_hdr = 'Content-Encoding: gzip';
1499
-					}
1500
-				}
1501
-				else
1502
-				{
1503
-					$a = @gzcompress($payload);
1504
-					if($a)
1505
-					{
1506
-						$payload = $a;
1507
-						$encoding_hdr = 'Content-Encoding: deflate';
1508
-					}
1509
-				}
1510
-			}
1511
-			else
1512
-			{
1513
-				$encoding_hdr = '';
1514
-			}
1515
-
1516
-			if($this->debug > 1)
1517
-			{
1518
-				print "<PRE>\n---SENDING---\n" . htmlentities($payload) . "\n---END---\n</PRE>";
1519
-				// let the client see this now in case http times out...
1520
-				flush();
1521
-			}
1522
-
1523
-			if(!$keepalive || !$this->xmlrpc_curl_handle)
1524
-			{
1525
-				$curl = curl_init($method . '://' . $server . ':' . $port . $this->path);
1526
-				if($keepalive)
1527
-				{
1528
-					$this->xmlrpc_curl_handle = $curl;
1529
-				}
1530
-			}
1531
-			else
1532
-			{
1533
-				$curl = $this->xmlrpc_curl_handle;
1534
-			}
1535
-
1536
-			// results into variable
1537
-			curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1538
-
1539
-			if($this->debug)
1540
-			{
1541
-				curl_setopt($curl, CURLOPT_VERBOSE, 1);
1542
-			}
1543
-			curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
1544
-			// required for XMLRPC: post the data
1545
-			curl_setopt($curl, CURLOPT_POST, 1);
1546
-			// the data
1547
-			curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
1548
-
1549
-			// return the header too
1550
-			curl_setopt($curl, CURLOPT_HEADER, 1);
1551
-
1552
-			// NB: if we set an empty string, CURL will add http header indicating
1553
-			// ALL methods it is supporting. This is possibly a better option than
1554
-			// letting the user tell what curl can / cannot do...
1555
-			if(is_array($this->accepted_compression) && count($this->accepted_compression))
1556
-			{
1557
-				//curl_setopt($curl, CURLOPT_ENCODING, implode(',', $this->accepted_compression));
1558
-				// empty string means 'any supported by CURL' (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
1559
-				if (count($this->accepted_compression) == 1)
1560
-				{
1561
-					curl_setopt($curl, CURLOPT_ENCODING, $this->accepted_compression[0]);
1562
-				}
1563
-				else
1564
-					curl_setopt($curl, CURLOPT_ENCODING, '');
1565
-			}
1566
-			// extra headers
1567
-			$headers = array('Content-Type: ' . $msg->content_type , 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings));
1568
-			// if no keepalive is wanted, let the server know it in advance
1569
-			if(!$keepalive)
1570
-			{
1571
-				$headers[] = 'Connection: close';
1572
-			}
1573
-			// request compression header
1574
-			if($encoding_hdr)
1575
-			{
1576
-				$headers[] = $encoding_hdr;
1577
-			}
1578
-
1579
-			curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
1580
-			// timeout is borked
1581
-			if($timeout)
1582
-			{
1583
-				curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);
1584
-			}
1585
-
1586
-			if($username && $password)
1587
-			{
1588
-				curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password);
1589
-				if (defined('CURLOPT_HTTPAUTH'))
1590
-				{
1591
-					curl_setopt($curl, CURLOPT_HTTPAUTH, $authtype);
1592
-				}
1593
-				else if ($authtype != 1)
1594
-				{
1595
-					error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported by the current PHP/curl install');
1596
-				}
1597
-			}
1598
-
1599
-			if($method == 'https')
1600
-			{
1601
-				// set cert file
1602
-				if($cert)
1603
-				{
1604
-					curl_setopt($curl, CURLOPT_SSLCERT, $cert);
1605
-				}
1606
-				// set cert password
1607
-				if($certpass)
1608
-				{
1609
-					curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $certpass);
1610
-				}
1611
-				// whether to verify remote host's cert
1612
-				curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
1613
-				// set ca certificates file/dir
1614
-				if($cacert)
1615
-				{
1616
-					curl_setopt($curl, CURLOPT_CAINFO, $cacert);
1617
-				}
1618
-				if($cacertdir)
1619
-				{
1620
-					curl_setopt($curl, CURLOPT_CAPATH, $cacertdir);
1621
-				}
1622
-				// set key file (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
1623
-				if($key)
1624
-				{
1625
-					curl_setopt($curl, CURLOPT_SSLKEY, $key);
1626
-				}
1627
-				// set key password (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
1628
-				if($keypass)
1629
-				{
1630
-					curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $keypass);
1631
-				}
1632
-
1633
-				// Upgrade transparently to more stringent check for versions of php which do not support otherwise.
1634
-				// Doing it in constructor would be cleaner; doing it here saves us a couple of function calls
1635
-				if($this->verifyhost == 1 && $info = curl_version() && version_compare($info['version'], '7.28.1') >= 0)
1636
-				{
1637
-					$this->verifyhost = 2;
1638
-				}
1639
-				// whether to verify cert's common name (CN); 0 for no, 1 to verify that it exists, and 2 to verify that it matches the hostname used
1640
-				curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
1641
-			}
1642
-
1643
-			// proxy info
1644
-			if($proxyhost)
1645
-			{
1646
-				if($proxyport == 0)
1647
-				{
1648
-					$proxyport = 8080; // NB: even for HTTPS, local connection is on port 8080
1649
-				}
1650
-				curl_setopt($curl, CURLOPT_PROXY, $proxyhost.':'.$proxyport);
1651
-				//curl_setopt($curl, CURLOPT_PROXYPORT,$proxyport);
1652
-				if($proxyusername)
1653
-				{
1654
-					curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyusername.':'.$proxypassword);
1655
-					if (defined('CURLOPT_PROXYAUTH'))
1656
-					{
1657
-						curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyauthtype);
1658
-					}
1659
-					else if ($proxyauthtype != 1)
1660
-					{
1661
-						error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
1662
-					}
1663
-				}
1664
-			}
1665
-
1666
-			// NB: should we build cookie http headers by hand rather than let CURL do it?
1667
-			// the following code does not honour 'expires', 'path' and 'domain' cookie attributes
1668
-			// set to client obj the the user...
1669
-			if (count($this->cookies))
1670
-			{
1671
-				$cookieheader = '';
1672
-				foreach ($this->cookies as $name => $cookie)
1673
-				{
1674
-					$cookieheader .= $name . '=' . $cookie['value'] . '; ';
1675
-				}
1676
-				curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2));
1677
-			}
1678
-
1679
-			foreach ($this->extracurlopts as $opt => $val)
1680
-			{
1681
-				curl_setopt($curl, $opt, $val);
1682
-			}
1683
-
1684
-			$result = curl_exec($curl);
1685
-
1686
-			if ($this->debug > 1)
1687
-			{
1688
-				print "<PRE>\n---CURL INFO---\n";
1689
-				foreach(curl_getinfo($curl) as $name => $val)
1690
-				{
1691
-					if (is_array($val))
1692
-					{
1693
-						$val = implode("\n", $val);
1694
-					}
1695
-					print $name . ': ' . htmlentities($val) . "\n";
1696
-				}
1697
-
1698
-				print "---END---\n</PRE>";
1699
-			}
1700
-
1701
-			if(!$result) /// @todo we should use a better check here - what if we get back '' or '0'?
1702
-			{
1703
-				$this->errstr='no response';
1704
-				$resp=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['curl_fail'], $GLOBALS['xmlrpcstr']['curl_fail']. ': '. curl_error($curl));
1705
-				curl_close($curl);
1706
-				if($keepalive)
1707
-				{
1708
-					$this->xmlrpc_curl_handle = null;
1709
-				}
1710
-			}
1711
-			else
1712
-			{
1713
-				if(!$keepalive)
1714
-				{
1715
-					curl_close($curl);
1716
-				}
1717
-				$resp =& $msg->parseResponse($result, true, $this->return_type);
1718
-				// if we got back a 302, we can not reuse the curl handle for later calls
1719
-				if($resp->faultCode() == $GLOBALS['xmlrpcerr']['http_error'] && $keepalive)
1720
-				{
1721
-					curl_close($curl);
1722
-					$this->xmlrpc_curl_handle = null;
1723
-				}
1724
-			}
1725
-			return $resp;
1726
-		}
1727
-
1728
-		/**
1729
-		* Send an array of request messages and return an array of responses.
1730
-		* Unless $this->no_multicall has been set to true, it will try first
1731
-		* to use one single xmlrpc call to server method system.multicall, and
1732
-		* revert to sending many successive calls in case of failure.
1733
-		* This failure is also stored in $this->no_multicall for subsequent calls.
1734
-		* Unfortunately, there is no server error code universally used to denote
1735
-		* the fact that multicall is unsupported, so there is no way to reliably
1736
-		* distinguish between that and a temporary failure.
1737
-		* If you are sure that server supports multicall and do not want to
1738
-		* fallback to using many single calls, set the fourth parameter to FALSE.
1739
-		*
1740
-		* NB: trying to shoehorn extra functionality into existing syntax has resulted
1741
-		* in pretty much convoluted code...
1742
-		*
1743
-		* @param array $msgs an array of xmlrpcmsg objects
1744
-		* @param integer $timeout connection timeout (in seconds)
1745
-		* @param string $method the http protocol variant to be used
1746
-		* @param boolean fallback When true, upon receiving an error during multicall, multiple single calls will be attempted
1747
-		* @return array
1748
-		* @access public
1749
-		*/
1750
-		function multicall($msgs, $timeout=0, $method='', $fallback=true)
1751
-		{
1752
-			if ($method == '')
1753
-			{
1754
-				$method = $this->method;
1755
-			}
1756
-			if(!$this->no_multicall)
1757
-			{
1758
-				$results = $this->_try_multicall($msgs, $timeout, $method);
1759
-				if(is_array($results))
1760
-				{
1761
-					// System.multicall succeeded
1762
-					return $results;
1763
-				}
1764
-				else
1765
-				{
1766
-					// either system.multicall is unsupported by server,
1767
-					// or call failed for some other reason.
1768
-					if ($fallback)
1769
-					{
1770
-						// Don't try it next time...
1771
-						$this->no_multicall = true;
1772
-					}
1773
-					else
1774
-					{
1775
-						if (is_a($results, 'xmlrpcresp'))
1776
-						{
1777
-							$result = $results;
1778
-						}
1779
-						else
1780
-						{
1781
-							$result = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['multicall_error'], $GLOBALS['xmlrpcstr']['multicall_error']);
1782
-						}
1783
-					}
1784
-				}
1785
-			}
1786
-			else
1787
-			{
1788
-				// override fallback, in case careless user tries to do two
1789
-				// opposite things at the same time
1790
-				$fallback = true;
1791
-			}
1792
-
1793
-			$results = array();
1794
-			if ($fallback)
1795
-			{
1796
-				// system.multicall is (probably) unsupported by server:
1797
-				// emulate multicall via multiple requests
1798
-				foreach($msgs as $msg)
1799
-				{
1800
-					$results[] =& $this->send($msg, $timeout, $method);
1801
-				}
1802
-			}
1803
-			else
1804
-			{
1805
-				// user does NOT want to fallback on many single calls:
1806
-				// since we should always return an array of responses,
1807
-				// return an array with the same error repeated n times
1808
-				foreach($msgs as $msg)
1809
-				{
1810
-					$results[] = $result;
1811
-				}
1812
-			}
1813
-			return $results;
1814
-		}
1815
-
1816
-		/**
1817
-		* Attempt to boxcar $msgs via system.multicall.
1818
-		* Returns either an array of xmlrpcreponses, an xmlrpc error response
1819
-		* or false (when received response does not respect valid multicall syntax)
1820
-		* @access private
1821
-		*/
1822
-		function _try_multicall($msgs, $timeout, $method)
1823
-		{
1824
-			// Construct multicall message
1825
-			$calls = array();
1826
-			foreach($msgs as $msg)
1827
-			{
1828
-				$call['methodName'] = new xmlrpcval($msg->method(),'string');
1829
-				$numParams = $msg->getNumParams();
1830
-				$params = array();
1831
-				for($i = 0; $i < $numParams; $i++)
1832
-				{
1833
-					$params[$i] = $msg->getParam($i);
1834
-				}
1835
-				$call['params'] = new xmlrpcval($params, 'array');
1836
-				$calls[] = new xmlrpcval($call, 'struct');
1837
-			}
1838
-			$multicall = new xmlrpcmsg('system.multicall');
1839
-			$multicall->addParam(new xmlrpcval($calls, 'array'));
1840
-
1841
-			// Attempt RPC call
1842
-			$result =& $this->send($multicall, $timeout, $method);
1843
-
1844
-			if($result->faultCode() != 0)
1845
-			{
1846
-				// call to system.multicall failed
1847
-				return $result;
1848
-			}
1849
-
1850
-			// Unpack responses.
1851
-			$rets = $result->value();
1852
-
1853
-			if ($this->return_type == 'xml')
1854
-			{
1855
-					return $rets;
1856
-			}
1857
-			else if ($this->return_type == 'phpvals')
1858
-			{
1859
-				///@todo test this code branch...
1860
-				$rets = $result->value();
1861
-				if(!is_array($rets))
1862
-				{
1863
-					return false;		// bad return type from system.multicall
1864
-				}
1865
-				$numRets = count($rets);
1866
-				if($numRets != count($msgs))
1867
-				{
1868
-					return false;		// wrong number of return values.
1869
-				}
1870
-
1871
-				$response = array();
1872
-				for($i = 0; $i < $numRets; $i++)
1873
-				{
1874
-					$val = $rets[$i];
1875
-					if (!is_array($val)) {
1876
-						return false;
1877
-					}
1878
-					switch(count($val))
1879
-					{
1880
-						case 1:
1881
-							if(!isset($val[0]))
1882
-							{
1883
-								return false;		// Bad value
1884
-							}
1885
-							// Normal return value
1886
-							$response[$i] = new xmlrpcresp($val[0], 0, '', 'phpvals');
1887
-							break;
1888
-						case 2:
1889
-							///	@todo remove usage of @: it is apparently quite slow
1890
-							$code = @$val['faultCode'];
1891
-							if(!is_int($code))
1892
-							{
1893
-								return false;
1894
-							}
1895
-							$str = @$val['faultString'];
1896
-							if(!is_string($str))
1897
-							{
1898
-								return false;
1899
-							}
1900
-							$response[$i] = new xmlrpcresp(0, $code, $str);
1901
-							break;
1902
-						default:
1903
-							return false;
1904
-					}
1905
-				}
1906
-				return $response;
1907
-			}
1908
-			else // return type == 'xmlrpcvals'
1909
-			{
1910
-				$rets = $result->value();
1911
-				if($rets->kindOf() != 'array')
1912
-				{
1913
-					return false;		// bad return type from system.multicall
1914
-				}
1915
-				$numRets = $rets->arraysize();
1916
-				if($numRets != count($msgs))
1917
-				{
1918
-					return false;		// wrong number of return values.
1919
-				}
1920
-
1921
-				$response = array();
1922
-				for($i = 0; $i < $numRets; $i++)
1923
-				{
1924
-					$val = $rets->arraymem($i);
1925
-					switch($val->kindOf())
1926
-					{
1927
-						case 'array':
1928
-							if($val->arraysize() != 1)
1929
-							{
1930
-								return false;		// Bad value
1931
-							}
1932
-							// Normal return value
1933
-							$response[$i] = new xmlrpcresp($val->arraymem(0));
1934
-							break;
1935
-						case 'struct':
1936
-							$code = $val->structmem('faultCode');
1937
-							if($code->kindOf() != 'scalar' || $code->scalartyp() != 'int')
1938
-							{
1939
-								return false;
1940
-							}
1941
-							$str = $val->structmem('faultString');
1942
-							if($str->kindOf() != 'scalar' || $str->scalartyp() != 'string')
1943
-							{
1944
-								return false;
1945
-							}
1946
-							$response[$i] = new xmlrpcresp(0, $code->scalarval(), $str->scalarval());
1947
-							break;
1948
-						default:
1949
-							return false;
1950
-					}
1951
-				}
1952
-				return $response;
1953
-			}
1954
-		}
1955
-	} // end class xmlrpc_client
1956
-
1957
-	class xmlrpcresp
1958
-	{
1959
-		var $val = 0;
1960
-		var $valtyp;
1961
-		var $errno = 0;
1962
-		var $errstr = '';
1963
-		var $payload;
1964
-		var $hdrs = array();
1965
-		var $_cookies = array();
1966
-		var $content_type = 'text/xml';
1967
-		var $raw_data = '';
1968
-
1969
-		/**
1970
-		* @param mixed $val either an xmlrpcval obj, a php value or the xml serialization of an xmlrpcval (a string)
1971
-		* @param integer $fcode set it to anything but 0 to create an error response
1972
-		* @param string $fstr the error string, in case of an error response
1973
-		* @param string $valtyp either 'xmlrpcvals', 'phpvals' or 'xml'
1974
-		*
1975
-		* @todo add check that $val / $fcode / $fstr is of correct type???
1976
-		* NB: as of now we do not do it, since it might be either an xmlrpcval or a plain
1977
-		* php val, or a complete xml chunk, depending on usage of xmlrpc_client::send() inside which creator is called...
1978
-		*/
1979
-		function __construct($val, $fcode = 0, $fstr = '', $valtyp='')
1980
-		{
1981
-			if($fcode != 0)
1982
-			{
1983
-				// error response
1984
-				$this->errno = $fcode;
1985
-				$this->errstr = $fstr;
1986
-				//$this->errstr = htmlspecialchars($fstr); // XXX: encoding probably shouldn't be done here; fix later.
1987
-			}
1988
-			else
1989
-			{
1990
-				// successful response
1991
-				$this->val = $val;
1992
-				if ($valtyp == '')
1993
-				{
1994
-					// user did not declare type of response value: try to guess it
1995
-					if (is_object($this->val) && is_a($this->val, 'xmlrpcval'))
1996
-					{
1997
-						$this->valtyp = 'xmlrpcvals';
1998
-					}
1999
-					else if (is_string($this->val))
2000
-					{
2001
-						$this->valtyp = 'xml';
2002
-
2003
-					}
2004
-					else
2005
-					{
2006
-						$this->valtyp = 'phpvals';
2007
-					}
2008
-				}
2009
-				else
2010
-				{
2011
-					// user declares type of resp value: believe him
2012
-					$this->valtyp = $valtyp;
2013
-				}
2014
-			}
2015
-		}
2016
-
2017
-		/**
2018
-		* @deprecated
2019
-		*/
2020
-		function xmlrpcresp($val, $fcode = 0, $fstr = '', $valtyp='')
2021
-		{
2022
-			self::__construct($val, $fcode, $fstr, $valtyp);
2023
-		}
2024
-
2025
-		/**
2026
-		* Returns the error code of the response.
2027
-		* @return integer the error code of this response (0 for not-error responses)
2028
-		* @access public
2029
-		*/
2030
-		function faultCode()
2031
-		{
2032
-			return $this->errno;
2033
-		}
2034
-
2035
-		/**
2036
-		* Returns the error code of the response.
2037
-		* @return string the error string of this response ('' for not-error responses)
2038
-		* @access public
2039
-		*/
2040
-		function faultString()
2041
-		{
2042
-			return $this->errstr;
2043
-		}
2044
-
2045
-		/**
2046
-		* Returns the value received by the server.
2047
-		* @return mixed the xmlrpcval object returned by the server. Might be an xml string or php value if the response has been created by specially configured xmlrpc_client objects
2048
-		* @access public
2049
-		*/
2050
-		function value()
2051
-		{
2052
-			return $this->val;
2053
-		}
2054
-
2055
-		/**
2056
-		* Returns an array with the cookies received from the server.
2057
-		* Array has the form: $cookiename => array ('value' => $val, $attr1 => $val1, $attr2 = $val2, ...)
2058
-		* with attributes being e.g. 'expires', 'path', domain'.
2059
-		* NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past)
2060
-		* are still present in the array. It is up to the user-defined code to decide
2061
-		* how to use the received cookies, and whether they have to be sent back with the next
2062
-		* request to the server (using xmlrpc_client::setCookie) or not
2063
-		* @return array array of cookies received from the server
2064
-		* @access public
2065
-		*/
2066
-		function cookies()
2067
-		{
2068
-			return $this->_cookies;
2069
-		}
2070
-
2071
-		/**
2072
-		* Returns xml representation of the response. XML prologue not included
2073
-		* @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed
2074
-		* @return string the xml representation of the response
2075
-		* @access public
2076
-		*/
2077
-		function serialize($charset_encoding='')
2078
-		{
2079
-			if ($charset_encoding != '')
2080
-				$this->content_type = 'text/xml; charset=' . $charset_encoding;
2081
-			else
2082
-				$this->content_type = 'text/xml';
2083
-			if ($GLOBALS['xmlrpc_null_apache_encoding'])
2084
-			{
2085
-				$result = "<methodResponse xmlns:ex=\"".$GLOBALS['xmlrpc_null_apache_encoding_ns']."\">\n";
2086
-			}
2087
-			else
2088
-			{
2089
-			$result = "<methodResponse>\n";
2090
-			}
2091
-			if($this->errno)
2092
-			{
2093
-				// G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
2094
-				// by xml-encoding non ascii chars
2095
-				$result .= "<fault>\n" .
381
+            default:
382
+                $escaped_data = '';
383
+                error_log("Converting from $src_encoding to $dest_encoding: not supported...");
384
+        }
385
+        return $escaped_data;
386
+    }
387
+
388
+    /// xml parser handler function for opening element tags
389
+    function xmlrpc_se($parser, $name, $attrs, $accept_single_vals=false)
390
+    {
391
+        // if invalid xmlrpc already detected, skip all processing
392
+        if ($GLOBALS['_xh']['isf'] < 2)
393
+        {
394
+            // check for correct element nesting
395
+            // top level element can only be of 2 types
396
+            /// @todo optimization creep: save this check into a bool variable, instead of using count() every time:
397
+            ///       there is only a single top level element in xml anyway
398
+            if (count($GLOBALS['_xh']['stack']) == 0)
399
+            {
400
+                if ($name != 'METHODRESPONSE' && $name != 'METHODCALL' && (
401
+                    $name != 'VALUE' && !$accept_single_vals))
402
+                {
403
+                    $GLOBALS['_xh']['isf'] = 2;
404
+                    $GLOBALS['_xh']['isf_reason'] = 'missing top level xmlrpc element';
405
+                    return;
406
+                }
407
+                else
408
+                {
409
+                    $GLOBALS['_xh']['rt'] = strtolower($name);
410
+                    $GLOBALS['_xh']['rt'] = strtolower($name);
411
+                }
412
+            }
413
+            else
414
+            {
415
+                // not top level element: see if parent is OK
416
+                $parent = end($GLOBALS['_xh']['stack']);
417
+                if (!array_key_exists($name, $GLOBALS['xmlrpc_valid_parents']) || !in_array($parent, $GLOBALS['xmlrpc_valid_parents'][$name]))
418
+                {
419
+                    $GLOBALS['_xh']['isf'] = 2;
420
+                    $GLOBALS['_xh']['isf_reason'] = "xmlrpc element $name cannot be child of $parent";
421
+                    return;
422
+                }
423
+            }
424
+
425
+            switch($name)
426
+            {
427
+                // optimize for speed switch cases: most common cases first
428
+                case 'VALUE':
429
+                    /// @todo we could check for 2 VALUE elements inside a MEMBER or PARAM element
430
+                    $GLOBALS['_xh']['vt']='value'; // indicator: no value found yet
431
+                    $GLOBALS['_xh']['ac']='';
432
+                    $GLOBALS['_xh']['lv']=1;
433
+                    $GLOBALS['_xh']['php_class']=null;
434
+                    break;
435
+                case 'I4':
436
+                case 'INT':
437
+                case 'STRING':
438
+                case 'BOOLEAN':
439
+                case 'DOUBLE':
440
+                case 'DATETIME.ISO8601':
441
+                case 'BASE64':
442
+                    if ($GLOBALS['_xh']['vt']!='value')
443
+                    {
444
+                        //two data elements inside a value: an error occurred!
445
+                        $GLOBALS['_xh']['isf'] = 2;
446
+                        $GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
447
+                        return;
448
+                    }
449
+                    $GLOBALS['_xh']['ac']=''; // reset the accumulator
450
+                    break;
451
+                case 'STRUCT':
452
+                case 'ARRAY':
453
+                    if ($GLOBALS['_xh']['vt']!='value')
454
+                    {
455
+                        //two data elements inside a value: an error occurred!
456
+                        $GLOBALS['_xh']['isf'] = 2;
457
+                        $GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
458
+                        return;
459
+                    }
460
+                    // create an empty array to hold child values, and push it onto appropriate stack
461
+                    $cur_val = array();
462
+                    $cur_val['values'] = array();
463
+                    $cur_val['type'] = $name;
464
+                    // check for out-of-band information to rebuild php objs
465
+                    // and in case it is found, save it
466
+                    if (@isset($attrs['PHP_CLASS']))
467
+                    {
468
+                        $cur_val['php_class'] = $attrs['PHP_CLASS'];
469
+                    }
470
+                    $GLOBALS['_xh']['valuestack'][] = $cur_val;
471
+                    $GLOBALS['_xh']['vt']='data'; // be prepared for a data element next
472
+                    break;
473
+                case 'DATA':
474
+                    if ($GLOBALS['_xh']['vt']!='data')
475
+                    {
476
+                        //two data elements inside a value: an error occurred!
477
+                        $GLOBALS['_xh']['isf'] = 2;
478
+                        $GLOBALS['_xh']['isf_reason'] = "found two data elements inside an array element";
479
+                        return;
480
+                    }
481
+                case 'METHODCALL':
482
+                case 'METHODRESPONSE':
483
+                case 'PARAMS':
484
+                    // valid elements that add little to processing
485
+                    break;
486
+                case 'METHODNAME':
487
+                case 'NAME':
488
+                    /// @todo we could check for 2 NAME elements inside a MEMBER element
489
+                    $GLOBALS['_xh']['ac']='';
490
+                    break;
491
+                case 'FAULT':
492
+                    $GLOBALS['_xh']['isf']=1;
493
+                    break;
494
+                case 'MEMBER':
495
+                    $GLOBALS['_xh']['valuestack'][count($GLOBALS['_xh']['valuestack'])-1]['name']=''; // set member name to null, in case we do not find in the xml later on
496
+                    //$GLOBALS['_xh']['ac']='';
497
+                    // Drop trough intentionally
498
+                case 'PARAM':
499
+                    // clear value type, so we can check later if no value has been passed for this param/member
500
+                    $GLOBALS['_xh']['vt']=null;
501
+                    break;
502
+                case 'NIL':
503
+                case 'EX:NIL':
504
+                    if ($GLOBALS['xmlrpc_null_extension'])
505
+                    {
506
+                        if ($GLOBALS['_xh']['vt']!='value')
507
+                        {
508
+                            //two data elements inside a value: an error occurred!
509
+                            $GLOBALS['_xh']['isf'] = 2;
510
+                            $GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
511
+                            return;
512
+                        }
513
+                        $GLOBALS['_xh']['ac']=''; // reset the accumulator
514
+                        break;
515
+                    }
516
+                    // we do not support the <NIL/> extension, so
517
+                    // drop through intentionally
518
+                default:
519
+                    /// INVALID ELEMENT: RAISE ISF so that it is later recognized!!!
520
+                    $GLOBALS['_xh']['isf'] = 2;
521
+                    $GLOBALS['_xh']['isf_reason'] = "found not-xmlrpc xml element $name";
522
+                    break;
523
+            }
524
+
525
+            // Save current element name to stack, to validate nesting
526
+            $GLOBALS['_xh']['stack'][] = $name;
527
+
528
+            /// @todo optimization creep: move this inside the big switch() above
529
+            if($name!='VALUE')
530
+            {
531
+                $GLOBALS['_xh']['lv']=0;
532
+            }
533
+        }
534
+    }
535
+
536
+    /// Used in decoding xml chunks that might represent single xmlrpc values
537
+    function xmlrpc_se_any($parser, $name, $attrs)
538
+    {
539
+        xmlrpc_se($parser, $name, $attrs, true);
540
+    }
541
+
542
+    /// xml parser handler function for close element tags
543
+    function xmlrpc_ee($parser, $name, $rebuild_xmlrpcvals = true)
544
+    {
545
+        if ($GLOBALS['_xh']['isf'] < 2)
546
+        {
547
+            // push this element name from stack
548
+            // NB: if XML validates, correct opening/closing is guaranteed and
549
+            // we do not have to check for $name == $curr_elem.
550
+            // we also checked for proper nesting at start of elements...
551
+            $curr_elem = array_pop($GLOBALS['_xh']['stack']);
552
+
553
+            switch($name)
554
+            {
555
+                case 'VALUE':
556
+                    // This if() detects if no scalar was inside <VALUE></VALUE>
557
+                    if ($GLOBALS['_xh']['vt']=='value')
558
+                    {
559
+                        $GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
560
+                        $GLOBALS['_xh']['vt']=$GLOBALS['xmlrpcString'];
561
+                    }
562
+
563
+                    if ($rebuild_xmlrpcvals)
564
+                    {
565
+                        // build the xmlrpc val out of the data received, and substitute it
566
+                        $temp = new xmlrpcval($GLOBALS['_xh']['value'], $GLOBALS['_xh']['vt']);
567
+                        // in case we got info about underlying php class, save it
568
+                        // in the object we're rebuilding
569
+                        if (isset($GLOBALS['_xh']['php_class']))
570
+                            $temp->_php_class = $GLOBALS['_xh']['php_class'];
571
+                        // check if we are inside an array or struct:
572
+                        // if value just built is inside an array, let's move it into array on the stack
573
+                        $vscount = count($GLOBALS['_xh']['valuestack']);
574
+                        if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type']=='ARRAY')
575
+                        {
576
+                            $GLOBALS['_xh']['valuestack'][$vscount-1]['values'][] = $temp;
577
+                        }
578
+                        else
579
+                        {
580
+                            $GLOBALS['_xh']['value'] = $temp;
581
+                        }
582
+                    }
583
+                    else
584
+                    {
585
+                        /// @todo this needs to treat correctly php-serialized objects,
586
+                        /// since std deserializing is done by php_xmlrpc_decode,
587
+                        /// which we will not be calling...
588
+                        if (isset($GLOBALS['_xh']['php_class']))
589
+                        {
590
+                        }
591
+
592
+                        // check if we are inside an array or struct:
593
+                        // if value just built is inside an array, let's move it into array on the stack
594
+                        $vscount = count($GLOBALS['_xh']['valuestack']);
595
+                        if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type']=='ARRAY')
596
+                        {
597
+                            $GLOBALS['_xh']['valuestack'][$vscount-1]['values'][] = $GLOBALS['_xh']['value'];
598
+                        }
599
+                    }
600
+                    break;
601
+                case 'BOOLEAN':
602
+                case 'I4':
603
+                case 'INT':
604
+                case 'STRING':
605
+                case 'DOUBLE':
606
+                case 'DATETIME.ISO8601':
607
+                case 'BASE64':
608
+                    $GLOBALS['_xh']['vt']=strtolower($name);
609
+                    /// @todo: optimization creep - remove the if/elseif cycle below
610
+                    /// since the case() in which we are already did that
611
+                    if ($name=='STRING')
612
+                    {
613
+                        $GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
614
+                    }
615
+                    elseif ($name=='DATETIME.ISO8601')
616
+                    {
617
+                        if (!preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $GLOBALS['_xh']['ac']))
618
+                        {
619
+                            error_log('XML-RPC: invalid value received in DATETIME: '.$GLOBALS['_xh']['ac']);
620
+                        }
621
+                        $GLOBALS['_xh']['vt']=$GLOBALS['xmlrpcDateTime'];
622
+                        $GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
623
+                    }
624
+                    elseif ($name=='BASE64')
625
+                    {
626
+                        /// @todo check for failure of base64 decoding / catch warnings
627
+                        $GLOBALS['_xh']['value']=base64_decode($GLOBALS['_xh']['ac']);
628
+                    }
629
+                    elseif ($name=='BOOLEAN')
630
+                    {
631
+                        // special case here: we translate boolean 1 or 0 into PHP
632
+                        // constants true or false.
633
+                        // Strings 'true' and 'false' are accepted, even though the
634
+                        // spec never mentions them (see eg. Blogger api docs)
635
+                        // NB: this simple checks helps a lot sanitizing input, ie no
636
+                        // security problems around here
637
+                        if ($GLOBALS['_xh']['ac']=='1' || strcasecmp($GLOBALS['_xh']['ac'], 'true') == 0)
638
+                        {
639
+                            $GLOBALS['_xh']['value']=true;
640
+                        }
641
+                        else
642
+                        {
643
+                            // log if receiveing something strange, even though we set the value to false anyway
644
+                            if ($GLOBALS['_xh']['ac']!='0' && strcasecmp($GLOBALS['_xh']['ac'], 'false') != 0)
645
+                                error_log('XML-RPC: invalid value received in BOOLEAN: '.$GLOBALS['_xh']['ac']);
646
+                            $GLOBALS['_xh']['value']=false;
647
+                        }
648
+                    }
649
+                    elseif ($name=='DOUBLE')
650
+                    {
651
+                        // we have a DOUBLE
652
+                        // we must check that only 0123456789-.<space> are characters here
653
+                        // NOTE: regexp could be much stricter than this...
654
+                        if (!preg_match('/^[+-eE0123456789 \t.]+$/', $GLOBALS['_xh']['ac']))
655
+                        {
656
+                            /// @todo: find a better way of throwing an error than this!
657
+                            error_log('XML-RPC: non numeric value received in DOUBLE: '.$GLOBALS['_xh']['ac']);
658
+                            $GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
659
+                        }
660
+                        else
661
+                        {
662
+                            // it's ok, add it on
663
+                            $GLOBALS['_xh']['value']=(double)$GLOBALS['_xh']['ac'];
664
+                        }
665
+                    }
666
+                    else
667
+                    {
668
+                        // we have an I4/INT
669
+                        // we must check that only 0123456789-<space> are characters here
670
+                        if (!preg_match('/^[+-]?[0123456789 \t]+$/', $GLOBALS['_xh']['ac']))
671
+                        {
672
+                            /// @todo find a better way of throwing an error than this!
673
+                            error_log('XML-RPC: non numeric value received in INT: '.$GLOBALS['_xh']['ac']);
674
+                            $GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
675
+                        }
676
+                        else
677
+                        {
678
+                            // it's ok, add it on
679
+                            $GLOBALS['_xh']['value']=(int)$GLOBALS['_xh']['ac'];
680
+                        }
681
+                    }
682
+                    //$GLOBALS['_xh']['ac']=''; // is this necessary?
683
+                    $GLOBALS['_xh']['lv']=3; // indicate we've found a value
684
+                    break;
685
+                case 'NAME':
686
+                    $GLOBALS['_xh']['valuestack'][count($GLOBALS['_xh']['valuestack'])-1]['name'] = $GLOBALS['_xh']['ac'];
687
+                    break;
688
+                case 'MEMBER':
689
+                    //$GLOBALS['_xh']['ac']=''; // is this necessary?
690
+                    // add to array in the stack the last element built,
691
+                    // unless no VALUE was found
692
+                    if ($GLOBALS['_xh']['vt'])
693
+                    {
694
+                        $vscount = count($GLOBALS['_xh']['valuestack']);
695
+                        $GLOBALS['_xh']['valuestack'][$vscount-1]['values'][$GLOBALS['_xh']['valuestack'][$vscount-1]['name']] = $GLOBALS['_xh']['value'];
696
+                    } else
697
+                        error_log('XML-RPC: missing VALUE inside STRUCT in received xml');
698
+                    break;
699
+                case 'DATA':
700
+                    //$GLOBALS['_xh']['ac']=''; // is this necessary?
701
+                    $GLOBALS['_xh']['vt']=null; // reset this to check for 2 data elements in a row - even if they're empty
702
+                    break;
703
+                case 'STRUCT':
704
+                case 'ARRAY':
705
+                    // fetch out of stack array of values, and promote it to current value
706
+                    $curr_val = array_pop($GLOBALS['_xh']['valuestack']);
707
+                    $GLOBALS['_xh']['value'] = $curr_val['values'];
708
+                    $GLOBALS['_xh']['vt']=strtolower($name);
709
+                    if (isset($curr_val['php_class']))
710
+                    {
711
+                        $GLOBALS['_xh']['php_class'] = $curr_val['php_class'];
712
+                    }
713
+                    break;
714
+                case 'PARAM':
715
+                    // add to array of params the current value,
716
+                    // unless no VALUE was found
717
+                    if ($GLOBALS['_xh']['vt'])
718
+                    {
719
+                        $GLOBALS['_xh']['params'][]=$GLOBALS['_xh']['value'];
720
+                        $GLOBALS['_xh']['pt'][]=$GLOBALS['_xh']['vt'];
721
+                    }
722
+                    else
723
+                        error_log('XML-RPC: missing VALUE inside PARAM in received xml');
724
+                    break;
725
+                case 'METHODNAME':
726
+                    $GLOBALS['_xh']['method']=preg_replace('/^[\n\r\t ]+/', '', $GLOBALS['_xh']['ac']);
727
+                    break;
728
+                case 'NIL':
729
+                case 'EX:NIL':
730
+                    if ($GLOBALS['xmlrpc_null_extension'])
731
+                    {
732
+                        $GLOBALS['_xh']['vt']='null';
733
+                        $GLOBALS['_xh']['value']=null;
734
+                        $GLOBALS['_xh']['lv']=3;
735
+                        break;
736
+                    }
737
+                    // drop through intentionally if nil extension not enabled
738
+                case 'PARAMS':
739
+                case 'FAULT':
740
+                case 'METHODCALL':
741
+                case 'METHORESPONSE':
742
+                    break;
743
+                default:
744
+                    // End of INVALID ELEMENT!
745
+                    // shall we add an assert here for unreachable code???
746
+                    break;
747
+            }
748
+        }
749
+    }
750
+
751
+    /// Used in decoding xmlrpc requests/responses without rebuilding xmlrpc values
752
+    function xmlrpc_ee_fast($parser, $name)
753
+    {
754
+        xmlrpc_ee($parser, $name, false);
755
+    }
756
+
757
+    /// xml parser handler function for character data
758
+    function xmlrpc_cd($parser, $data)
759
+    {
760
+        // skip processing if xml fault already detected
761
+        if ($GLOBALS['_xh']['isf'] < 2)
762
+        {
763
+            // "lookforvalue==3" means that we've found an entire value
764
+            // and should discard any further character data
765
+            if($GLOBALS['_xh']['lv']!=3)
766
+            {
767
+                // G. Giunta 2006-08-23: useless change of 'lv' from 1 to 2
768
+                //if($GLOBALS['_xh']['lv']==1)
769
+                //{
770
+                    // if we've found text and we're just in a <value> then
771
+                    // say we've found a value
772
+                    //$GLOBALS['_xh']['lv']=2;
773
+                //}
774
+                // we always initialize the accumulator before starting parsing, anyway...
775
+                //if(!@isset($GLOBALS['_xh']['ac']))
776
+                //{
777
+                //	$GLOBALS['_xh']['ac'] = '';
778
+                //}
779
+                $GLOBALS['_xh']['ac'].=$data;
780
+            }
781
+        }
782
+    }
783
+
784
+    /// xml parser handler function for 'other stuff', ie. not char data or
785
+    /// element start/end tag. In fact it only gets called on unknown entities...
786
+    function xmlrpc_dh($parser, $data)
787
+    {
788
+        // skip processing if xml fault already detected
789
+        if ($GLOBALS['_xh']['isf'] < 2)
790
+        {
791
+            if(substr($data, 0, 1) == '&' && substr($data, -1, 1) == ';')
792
+            {
793
+                // G. Giunta 2006-08-25: useless change of 'lv' from 1 to 2
794
+                //if($GLOBALS['_xh']['lv']==1)
795
+                //{
796
+                //	$GLOBALS['_xh']['lv']=2;
797
+                //}
798
+                $GLOBALS['_xh']['ac'].=$data;
799
+            }
800
+        }
801
+        return true;
802
+    }
803
+
804
+    class xmlrpc_client
805
+    {
806
+        var $path;
807
+        var $server;
808
+        var $port=0;
809
+        var $method='http';
810
+        var $errno;
811
+        var $errstr;
812
+        var $debug=0;
813
+        var $username='';
814
+        var $password='';
815
+        var $authtype=1;
816
+        var $cert='';
817
+        var $certpass='';
818
+        var $cacert='';
819
+        var $cacertdir='';
820
+        var $key='';
821
+        var $keypass='';
822
+        var $verifypeer=true;
823
+        var $verifyhost=1;
824
+        var $no_multicall=false;
825
+        var $proxy='';
826
+        var $proxyport=0;
827
+        var $proxy_user='';
828
+        var $proxy_pass='';
829
+        var $proxy_authtype=1;
830
+        var $cookies=array();
831
+        var $extracurlopts=array();
832
+
833
+        /**
834
+         * List of http compression methods accepted by the client for responses.
835
+         * NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib
836
+         *
837
+         * NNB: you can set it to any non-empty array for HTTP11 and HTTPS, since
838
+         * in those cases it will be up to CURL to decide the compression methods
839
+         * it supports. You might check for the presence of 'zlib' in the output of
840
+         * curl_version() to determine wheter compression is supported or not
841
+         */
842
+        var $accepted_compression = array();
843
+        /**
844
+         * Name of compression scheme to be used for sending requests.
845
+         * Either null, gzip or deflate
846
+         */
847
+        var $request_compression = '';
848
+        /**
849
+         * CURL handle: used for keep-alive connections (PHP 4.3.8 up, see:
850
+         * http://curl.haxx.se/docs/faq.html#7.3)
851
+         */
852
+        var $xmlrpc_curl_handle = null;
853
+        /// Whether to use persistent connections for http 1.1 and https
854
+        var $keepalive = false;
855
+        /// Charset encodings that can be decoded without problems by the client
856
+        var $accepted_charset_encodings = array();
857
+        /// Charset encoding to be used in serializing request. NULL = use ASCII
858
+        var $request_charset_encoding = '';
859
+        /**
860
+         * Decides the content of xmlrpcresp objects returned by calls to send()
861
+         * valid strings are 'xmlrpcvals', 'phpvals' or 'xml'
862
+         */
863
+        var $return_type = 'xmlrpcvals';
864
+        /**
865
+         * Sent to servers in http headers
866
+         */
867
+        var $user_agent;
868
+
869
+        /**
870
+         * @param string $path either the complete server URL or the PATH part of the xmlrc server URL, e.g. /xmlrpc/server.php
871
+         * @param string $server the server name / ip address
872
+         * @param integer $port the port the server is listening on, defaults to 80 or 443 depending on protocol used
873
+         * @param string $method the http protocol variant: defaults to 'http', 'https' and 'http11' can be used if CURL is installed
874
+         */
875
+        function __construct($path, $server='', $port='', $method='')
876
+        {
877
+            // allow user to specify all params in $path
878
+            if($server == '' and $port == '' and $method == '')
879
+            {
880
+                $parts = parse_url($path);
881
+                $server = $parts['host'];
882
+                $path = isset($parts['path']) ? $parts['path'] : '';
883
+                if(isset($parts['query']))
884
+                {
885
+                    $path .= '?'.$parts['query'];
886
+                }
887
+                if(isset($parts['fragment']))
888
+                {
889
+                    $path .= '#'.$parts['fragment'];
890
+                }
891
+                if(isset($parts['port']))
892
+                {
893
+                    $port = $parts['port'];
894
+                }
895
+                if(isset($parts['scheme']))
896
+                {
897
+                    $method = $parts['scheme'];
898
+                }
899
+                if(isset($parts['user']))
900
+                {
901
+                    $this->username = $parts['user'];
902
+                }
903
+                if(isset($parts['pass']))
904
+                {
905
+                    $this->password = $parts['pass'];
906
+                }
907
+            }
908
+            if($path == '' || $path[0] != '/')
909
+            {
910
+                $this->path='/'.$path;
911
+            }
912
+            else
913
+            {
914
+                $this->path=$path;
915
+            }
916
+            $this->server=$server;
917
+            if($port != '')
918
+            {
919
+                $this->port=$port;
920
+            }
921
+            if($method != '')
922
+            {
923
+                $this->method=$method;
924
+            }
925
+
926
+            // if ZLIB is enabled, let the client by default accept compressed responses
927
+            if(function_exists('gzinflate') || (
928
+                function_exists('curl_init') && (($info = curl_version()) &&
929
+                ((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version'])))
930
+            ))
931
+            {
932
+                $this->accepted_compression = array('gzip', 'deflate');
933
+            }
934
+
935
+            // keepalives: enabled by default
936
+            $this->keepalive = true;
937
+
938
+            // by default the xml parser can support these 3 charset encodings
939
+            $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
940
+
941
+            // initialize user_agent string
942
+            $this->user_agent = $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion'];
943
+        }
944
+
945
+        /**
946
+         * @deprecated
947
+         */
948
+        function xmlrpc_client($path, $server='', $port='', $method='')
949
+        {
950
+            self::__construct($path, $server, $port, $method);
951
+        }
952
+
953
+        /**
954
+         * Enables/disables the echoing to screen of the xmlrpc responses received
955
+         * @param integer $in values 0, 1 and 2 are supported (2 = echo sent msg too, before received response)
956
+         * @access public
957
+         */
958
+        function setDebug($in)
959
+        {
960
+            $this->debug=$in;
961
+        }
962
+
963
+        /**
964
+         * Add some http BASIC AUTH credentials, used by the client to authenticate
965
+         * @param string $u username
966
+         * @param string $p password
967
+         * @param integer $t auth type. See curl_setopt man page for supported auth types. Defaults to CURLAUTH_BASIC (basic auth)
968
+         * @access public
969
+         */
970
+        function setCredentials($u, $p, $t=1)
971
+        {
972
+            $this->username=$u;
973
+            $this->password=$p;
974
+            $this->authtype=$t;
975
+        }
976
+
977
+        /**
978
+         * Add a client-side https certificate
979
+         * @param string $cert
980
+         * @param string $certpass
981
+         * @access public
982
+         */
983
+        function setCertificate($cert, $certpass)
984
+        {
985
+            $this->cert = $cert;
986
+            $this->certpass = $certpass;
987
+        }
988
+
989
+        /**
990
+         * Add a CA certificate to verify server with (see man page about
991
+         * CURLOPT_CAINFO for more details)
992
+         * @param string $cacert certificate file name (or dir holding certificates)
993
+         * @param bool $is_dir set to true to indicate cacert is a dir. defaults to false
994
+         * @access public
995
+         */
996
+        function setCaCertificate($cacert, $is_dir=false)
997
+        {
998
+            if ($is_dir)
999
+            {
1000
+                $this->cacertdir = $cacert;
1001
+            }
1002
+            else
1003
+            {
1004
+                $this->cacert = $cacert;
1005
+            }
1006
+        }
1007
+
1008
+        /**
1009
+         * Set attributes for SSL communication: private SSL key
1010
+         * NB: does not work in older php/curl installs
1011
+         * Thanks to Daniel Convissor
1012
+         * @param string $key The name of a file containing a private SSL key
1013
+         * @param string $keypass The secret password needed to use the private SSL key
1014
+         * @access public
1015
+         */
1016
+        function setKey($key, $keypass)
1017
+        {
1018
+            $this->key = $key;
1019
+            $this->keypass = $keypass;
1020
+        }
1021
+
1022
+        /**
1023
+         * Set attributes for SSL communication: verify server certificate
1024
+         * @param bool $i enable/disable verification of peer certificate
1025
+         * @access public
1026
+         */
1027
+        function setSSLVerifyPeer($i)
1028
+        {
1029
+            $this->verifypeer = $i;
1030
+        }
1031
+
1032
+        /**
1033
+         * Set attributes for SSL communication: verify match of server cert w. hostname
1034
+         * @param int $i
1035
+         * @access public
1036
+         */
1037
+        function setSSLVerifyHost($i)
1038
+        {
1039
+            $this->verifyhost = $i;
1040
+        }
1041
+
1042
+        /**
1043
+         * Set proxy info
1044
+         * @param string $proxyhost
1045
+         * @param string $proxyport Defaults to 8080 for HTTP and 443 for HTTPS
1046
+         * @param string $proxyusername Leave blank if proxy has public access
1047
+         * @param string $proxypassword Leave blank if proxy has public access
1048
+         * @param int $proxyauthtype set to constant CURLAUTH_NTLM to use NTLM auth with proxy
1049
+         * @access public
1050
+         */
1051
+        function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1)
1052
+        {
1053
+            $this->proxy = $proxyhost;
1054
+            $this->proxyport = $proxyport;
1055
+            $this->proxy_user = $proxyusername;
1056
+            $this->proxy_pass = $proxypassword;
1057
+            $this->proxy_authtype = $proxyauthtype;
1058
+        }
1059
+
1060
+        /**
1061
+         * Enables/disables reception of compressed xmlrpc responses.
1062
+         * Note that enabling reception of compressed responses merely adds some standard
1063
+         * http headers to xmlrpc requests. It is up to the xmlrpc server to return
1064
+         * compressed responses when receiving such requests.
1065
+         * @param string $compmethod either 'gzip', 'deflate', 'any' or ''
1066
+         * @access public
1067
+         */
1068
+        function setAcceptedCompression($compmethod)
1069
+        {
1070
+            if ($compmethod == 'any')
1071
+                $this->accepted_compression = array('gzip', 'deflate');
1072
+            else
1073
+                if ($compmethod == false )
1074
+                    $this->accepted_compression = array();
1075
+                else
1076
+                    $this->accepted_compression = array($compmethod);
1077
+        }
1078
+
1079
+        /**
1080
+         * Enables/disables http compression of xmlrpc request.
1081
+         * Take care when sending compressed requests: servers might not support them
1082
+         * (and automatic fallback to uncompressed requests is not yet implemented)
1083
+         * @param string $compmethod either 'gzip', 'deflate' or ''
1084
+         * @access public
1085
+         */
1086
+        function setRequestCompression($compmethod)
1087
+        {
1088
+            $this->request_compression = $compmethod;
1089
+        }
1090
+
1091
+        /**
1092
+         * Adds a cookie to list of cookies that will be sent to server.
1093
+         * NB: setting any param but name and value will turn the cookie into a 'version 1' cookie:
1094
+         * do not do it unless you know what you are doing
1095
+         * @param string $name
1096
+         * @param string $value
1097
+         * @param string $path
1098
+         * @param string $domain
1099
+         * @param int $port
1100
+         * @access public
1101
+         *
1102
+         * @todo check correctness of urlencoding cookie value (copied from php way of doing it...)
1103
+         */
1104
+        function setCookie($name, $value='', $path='', $domain='', $port=null)
1105
+        {
1106
+            $this->cookies[$name]['value'] = urlencode($value);
1107
+            if ($path || $domain || $port)
1108
+            {
1109
+                $this->cookies[$name]['path'] = $path;
1110
+                $this->cookies[$name]['domain'] = $domain;
1111
+                $this->cookies[$name]['port'] = $port;
1112
+                $this->cookies[$name]['version'] = 1;
1113
+            }
1114
+            else
1115
+            {
1116
+                $this->cookies[$name]['version'] = 0;
1117
+            }
1118
+        }
1119
+
1120
+        /**
1121
+         * Directly set cURL options, for extra flexibility
1122
+         * It allows eg. to bind client to a specific IP interface / address
1123
+         * @param array $options
1124
+         */
1125
+        function SetCurlOptions( $options )
1126
+        {
1127
+            $this->extracurlopts = $options;
1128
+        }
1129
+
1130
+        /**
1131
+         * Set user-agent string that will be used by this client instance
1132
+         * in http headers sent to the server
1133
+         */
1134
+        function SetUserAgent( $agentstring )
1135
+        {
1136
+            $this->user_agent = $agentstring;
1137
+        }
1138
+
1139
+        /**
1140
+         * Send an xmlrpc request
1141
+         * @param mixed $msg The message object, or an array of messages for using multicall, or the complete xml representation of a request
1142
+         * @param integer $timeout Connection timeout, in seconds, If unspecified, a platform specific timeout will apply
1143
+         * @param string $method if left unspecified, the http protocol chosen during creation of the object will be used
1144
+         * @return xmlrpcresp
1145
+         * @access public
1146
+         */
1147
+        function& send($msg, $timeout=0, $method='')
1148
+        {
1149
+            // if user deos not specify http protocol, use native method of this client
1150
+            // (i.e. method set during call to constructor)
1151
+            if($method == '')
1152
+            {
1153
+                $method = $this->method;
1154
+            }
1155
+
1156
+            if(is_array($msg))
1157
+            {
1158
+                // $msg is an array of xmlrpcmsg's
1159
+                $r = $this->multicall($msg, $timeout, $method);
1160
+                return $r;
1161
+            }
1162
+            elseif(is_string($msg))
1163
+            {
1164
+                $n = new xmlrpcmsg('');
1165
+                $n->payload = $msg;
1166
+                $msg = $n;
1167
+            }
1168
+
1169
+            // where msg is an xmlrpcmsg
1170
+            $msg->debug=$this->debug;
1171
+
1172
+            if($method == 'https')
1173
+            {
1174
+                $r =& $this->sendPayloadHTTPS(
1175
+                    $msg,
1176
+                    $this->server,
1177
+                    $this->port,
1178
+                    $timeout,
1179
+                    $this->username,
1180
+                    $this->password,
1181
+                    $this->authtype,
1182
+                    $this->cert,
1183
+                    $this->certpass,
1184
+                    $this->cacert,
1185
+                    $this->cacertdir,
1186
+                    $this->proxy,
1187
+                    $this->proxyport,
1188
+                    $this->proxy_user,
1189
+                    $this->proxy_pass,
1190
+                    $this->proxy_authtype,
1191
+                    $this->keepalive,
1192
+                    $this->key,
1193
+                    $this->keypass
1194
+                );
1195
+            }
1196
+            elseif($method == 'http11')
1197
+            {
1198
+                $r =& $this->sendPayloadCURL(
1199
+                    $msg,
1200
+                    $this->server,
1201
+                    $this->port,
1202
+                    $timeout,
1203
+                    $this->username,
1204
+                    $this->password,
1205
+                    $this->authtype,
1206
+                    null,
1207
+                    null,
1208
+                    null,
1209
+                    null,
1210
+                    $this->proxy,
1211
+                    $this->proxyport,
1212
+                    $this->proxy_user,
1213
+                    $this->proxy_pass,
1214
+                    $this->proxy_authtype,
1215
+                    'http',
1216
+                    $this->keepalive
1217
+                );
1218
+            }
1219
+            else
1220
+            {
1221
+                $r =& $this->sendPayloadHTTP10(
1222
+                    $msg,
1223
+                    $this->server,
1224
+                    $this->port,
1225
+                    $timeout,
1226
+                    $this->username,
1227
+                    $this->password,
1228
+                    $this->authtype,
1229
+                    $this->proxy,
1230
+                    $this->proxyport,
1231
+                    $this->proxy_user,
1232
+                    $this->proxy_pass,
1233
+                    $this->proxy_authtype
1234
+                );
1235
+            }
1236
+
1237
+            return $r;
1238
+        }
1239
+
1240
+        /**
1241
+         * @access private
1242
+         */
1243
+        function &sendPayloadHTTP10($msg, $server, $port, $timeout=0,
1244
+            $username='', $password='', $authtype=1, $proxyhost='',
1245
+            $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1)
1246
+        {
1247
+            if($port==0)
1248
+            {
1249
+                $port=80;
1250
+            }
1251
+
1252
+            // Only create the payload if it was not created previously
1253
+            if(empty($msg->payload))
1254
+            {
1255
+                $msg->createPayload($this->request_charset_encoding);
1256
+            }
1257
+
1258
+            $payload = $msg->payload;
1259
+            // Deflate request body and set appropriate request headers
1260
+            if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
1261
+            {
1262
+                if($this->request_compression == 'gzip')
1263
+                {
1264
+                    $a = @gzencode($payload);
1265
+                    if($a)
1266
+                    {
1267
+                        $payload = $a;
1268
+                        $encoding_hdr = "Content-Encoding: gzip\r\n";
1269
+                    }
1270
+                }
1271
+                else
1272
+                {
1273
+                    $a = @gzcompress($payload);
1274
+                    if($a)
1275
+                    {
1276
+                        $payload = $a;
1277
+                        $encoding_hdr = "Content-Encoding: deflate\r\n";
1278
+                    }
1279
+                }
1280
+            }
1281
+            else
1282
+            {
1283
+                $encoding_hdr = '';
1284
+            }
1285
+
1286
+            // thanks to Grant Rauscher <[email protected]> for this
1287
+            $credentials='';
1288
+            if($username!='')
1289
+            {
1290
+                $credentials='Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
1291
+                if ($authtype != 1)
1292
+                {
1293
+                    error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported with HTTP 1.0');
1294
+                }
1295
+            }
1296
+
1297
+            $accepted_encoding = '';
1298
+            if(is_array($this->accepted_compression) && count($this->accepted_compression))
1299
+            {
1300
+                $accepted_encoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n";
1301
+            }
1302
+
1303
+            $proxy_credentials = '';
1304
+            if($proxyhost)
1305
+            {
1306
+                if($proxyport == 0)
1307
+                {
1308
+                    $proxyport = 8080;
1309
+                }
1310
+                $connectserver = $proxyhost;
1311
+                $connectport = $proxyport;
1312
+                $uri = 'http://'.$server.':'.$port.$this->path;
1313
+                if($proxyusername != '')
1314
+                {
1315
+                    if ($proxyauthtype != 1)
1316
+                    {
1317
+                        error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported with HTTP 1.0');
1318
+                    }
1319
+                    $proxy_credentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyusername.':'.$proxypassword) . "\r\n";
1320
+                }
1321
+            }
1322
+            else
1323
+            {
1324
+                $connectserver = $server;
1325
+                $connectport = $port;
1326
+                $uri = $this->path;
1327
+            }
1328
+
1329
+            // Cookie generation, as per rfc2965 (version 1 cookies) or
1330
+            // netscape's rules (version 0 cookies)
1331
+            $cookieheader='';
1332
+            if (count($this->cookies))
1333
+            {
1334
+                $version = '';
1335
+                foreach ($this->cookies as $name => $cookie)
1336
+                {
1337
+                    if ($cookie['version'])
1338
+                    {
1339
+                        $version = ' $Version="' . $cookie['version'] . '";';
1340
+                        $cookieheader .= ' ' . $name . '="' . $cookie['value'] . '";';
1341
+                        if ($cookie['path'])
1342
+                            $cookieheader .= ' $Path="' . $cookie['path'] . '";';
1343
+                        if ($cookie['domain'])
1344
+                            $cookieheader .= ' $Domain="' . $cookie['domain'] . '";';
1345
+                        if ($cookie['port'])
1346
+                            $cookieheader .= ' $Port="' . $cookie['port'] . '";';
1347
+                    }
1348
+                    else
1349
+                    {
1350
+                        $cookieheader .= ' ' . $name . '=' . $cookie['value'] . ";";
1351
+                    }
1352
+                }
1353
+                $cookieheader = 'Cookie:' . $version . substr($cookieheader, 0, -1) . "\r\n";
1354
+            }
1355
+
1356
+            // omit port if 80
1357
+            $port = ($port == 80) ? '' : (':' . $port);
1358
+
1359
+            $op= 'POST ' . $uri. " HTTP/1.0\r\n" .
1360
+                'User-Agent: ' . $this->user_agent . "\r\n" .
1361
+                'Host: '. $server . $port . "\r\n" .
1362
+                $credentials .
1363
+                $proxy_credentials .
1364
+                $accepted_encoding .
1365
+                $encoding_hdr .
1366
+                'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings) . "\r\n" .
1367
+                $cookieheader .
1368
+                'Content-Type: ' . $msg->content_type . "\r\nContent-Length: " .
1369
+                strlen($payload) . "\r\n\r\n" .
1370
+                $payload;
1371
+
1372
+            if($this->debug > 1)
1373
+            {
1374
+                print "<PRE>\n---SENDING---\n" . htmlentities($op) . "\n---END---\n</PRE>";
1375
+                // let the client see this now in case http times out...
1376
+                flush();
1377
+            }
1378
+
1379
+            if($timeout>0)
1380
+            {
1381
+                $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout);
1382
+            }
1383
+            else
1384
+            {
1385
+                $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr);
1386
+            }
1387
+            if($fp)
1388
+            {
1389
+                if($timeout>0 && function_exists('stream_set_timeout'))
1390
+                {
1391
+                    stream_set_timeout($fp, $timeout);
1392
+                }
1393
+            }
1394
+            else
1395
+            {
1396
+                $this->errstr='Connect error: '.$this->errstr;
1397
+                $r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr . ' (' . $this->errno . ')');
1398
+                return $r;
1399
+            }
1400
+
1401
+            if(!fputs($fp, $op, strlen($op)))
1402
+            {
1403
+                fclose($fp);
1404
+                $this->errstr='Write error';
1405
+                $r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr);
1406
+                return $r;
1407
+            }
1408
+            else
1409
+            {
1410
+                // reset errno and errstr on successful socket connection
1411
+                $this->errstr = '';
1412
+            }
1413
+            // G. Giunta 2005/10/24: close socket before parsing.
1414
+            // should yield slightly better execution times, and make easier recursive calls (e.g. to follow http redirects)
1415
+            $ipd='';
1416
+            do
1417
+            {
1418
+                // shall we check for $data === FALSE?
1419
+                // as per the manual, it signals an error
1420
+                $ipd.=fread($fp, 32768);
1421
+            } while(!feof($fp));
1422
+            fclose($fp);
1423
+            $r =& $msg->parseResponse($ipd, false, $this->return_type);
1424
+            return $r;
1425
+
1426
+        }
1427
+
1428
+        /**
1429
+         * @access private
1430
+         */
1431
+        function &sendPayloadHTTPS($msg, $server, $port, $timeout=0, $username='',
1432
+            $password='', $authtype=1, $cert='',$certpass='', $cacert='', $cacertdir='',
1433
+            $proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1,
1434
+            $keepalive=false, $key='', $keypass='')
1435
+        {
1436
+            $r =& $this->sendPayloadCURL($msg, $server, $port, $timeout, $username,
1437
+                $password, $authtype, $cert, $certpass, $cacert, $cacertdir, $proxyhost, $proxyport,
1438
+                $proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass);
1439
+            return $r;
1440
+        }
1441
+
1442
+        /**
1443
+         * Contributed by Justin Miller <[email protected]>
1444
+         * Requires curl to be built into PHP
1445
+         * NB: CURL versions before 7.11.10 cannot use proxy to talk to https servers!
1446
+         * @access private
1447
+         */
1448
+        function &sendPayloadCURL($msg, $server, $port, $timeout=0, $username='',
1449
+            $password='', $authtype=1, $cert='', $certpass='', $cacert='', $cacertdir='',
1450
+            $proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1, $method='https',
1451
+            $keepalive=false, $key='', $keypass='')
1452
+        {
1453
+            if(!function_exists('curl_init'))
1454
+            {
1455
+                $this->errstr='CURL unavailable on this install';
1456
+                $r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_curl'], $GLOBALS['xmlrpcstr']['no_curl']);
1457
+                return $r;
1458
+            }
1459
+            if($method == 'https')
1460
+            {
1461
+                if(($info = curl_version()) &&
1462
+                    ((is_string($info) && strpos($info, 'OpenSSL') === null) || (is_array($info) && !isset($info['ssl_version']))))
1463
+                {
1464
+                    $this->errstr='SSL unavailable on this install';
1465
+                    $r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_ssl'], $GLOBALS['xmlrpcstr']['no_ssl']);
1466
+                    return $r;
1467
+                }
1468
+            }
1469
+
1470
+            if($port == 0)
1471
+            {
1472
+                if($method == 'http')
1473
+                {
1474
+                    $port = 80;
1475
+                }
1476
+                else
1477
+                {
1478
+                    $port = 443;
1479
+                }
1480
+            }
1481
+
1482
+            // Only create the payload if it was not created previously
1483
+            if(empty($msg->payload))
1484
+            {
1485
+                $msg->createPayload($this->request_charset_encoding);
1486
+            }
1487
+
1488
+            // Deflate request body and set appropriate request headers
1489
+            $payload = $msg->payload;
1490
+            if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
1491
+            {
1492
+                if($this->request_compression == 'gzip')
1493
+                {
1494
+                    $a = @gzencode($payload);
1495
+                    if($a)
1496
+                    {
1497
+                        $payload = $a;
1498
+                        $encoding_hdr = 'Content-Encoding: gzip';
1499
+                    }
1500
+                }
1501
+                else
1502
+                {
1503
+                    $a = @gzcompress($payload);
1504
+                    if($a)
1505
+                    {
1506
+                        $payload = $a;
1507
+                        $encoding_hdr = 'Content-Encoding: deflate';
1508
+                    }
1509
+                }
1510
+            }
1511
+            else
1512
+            {
1513
+                $encoding_hdr = '';
1514
+            }
1515
+
1516
+            if($this->debug > 1)
1517
+            {
1518
+                print "<PRE>\n---SENDING---\n" . htmlentities($payload) . "\n---END---\n</PRE>";
1519
+                // let the client see this now in case http times out...
1520
+                flush();
1521
+            }
1522
+
1523
+            if(!$keepalive || !$this->xmlrpc_curl_handle)
1524
+            {
1525
+                $curl = curl_init($method . '://' . $server . ':' . $port . $this->path);
1526
+                if($keepalive)
1527
+                {
1528
+                    $this->xmlrpc_curl_handle = $curl;
1529
+                }
1530
+            }
1531
+            else
1532
+            {
1533
+                $curl = $this->xmlrpc_curl_handle;
1534
+            }
1535
+
1536
+            // results into variable
1537
+            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1538
+
1539
+            if($this->debug)
1540
+            {
1541
+                curl_setopt($curl, CURLOPT_VERBOSE, 1);
1542
+            }
1543
+            curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
1544
+            // required for XMLRPC: post the data
1545
+            curl_setopt($curl, CURLOPT_POST, 1);
1546
+            // the data
1547
+            curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
1548
+
1549
+            // return the header too
1550
+            curl_setopt($curl, CURLOPT_HEADER, 1);
1551
+
1552
+            // NB: if we set an empty string, CURL will add http header indicating
1553
+            // ALL methods it is supporting. This is possibly a better option than
1554
+            // letting the user tell what curl can / cannot do...
1555
+            if(is_array($this->accepted_compression) && count($this->accepted_compression))
1556
+            {
1557
+                //curl_setopt($curl, CURLOPT_ENCODING, implode(',', $this->accepted_compression));
1558
+                // empty string means 'any supported by CURL' (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
1559
+                if (count($this->accepted_compression) == 1)
1560
+                {
1561
+                    curl_setopt($curl, CURLOPT_ENCODING, $this->accepted_compression[0]);
1562
+                }
1563
+                else
1564
+                    curl_setopt($curl, CURLOPT_ENCODING, '');
1565
+            }
1566
+            // extra headers
1567
+            $headers = array('Content-Type: ' . $msg->content_type , 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings));
1568
+            // if no keepalive is wanted, let the server know it in advance
1569
+            if(!$keepalive)
1570
+            {
1571
+                $headers[] = 'Connection: close';
1572
+            }
1573
+            // request compression header
1574
+            if($encoding_hdr)
1575
+            {
1576
+                $headers[] = $encoding_hdr;
1577
+            }
1578
+
1579
+            curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
1580
+            // timeout is borked
1581
+            if($timeout)
1582
+            {
1583
+                curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);
1584
+            }
1585
+
1586
+            if($username && $password)
1587
+            {
1588
+                curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password);
1589
+                if (defined('CURLOPT_HTTPAUTH'))
1590
+                {
1591
+                    curl_setopt($curl, CURLOPT_HTTPAUTH, $authtype);
1592
+                }
1593
+                else if ($authtype != 1)
1594
+                {
1595
+                    error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported by the current PHP/curl install');
1596
+                }
1597
+            }
1598
+
1599
+            if($method == 'https')
1600
+            {
1601
+                // set cert file
1602
+                if($cert)
1603
+                {
1604
+                    curl_setopt($curl, CURLOPT_SSLCERT, $cert);
1605
+                }
1606
+                // set cert password
1607
+                if($certpass)
1608
+                {
1609
+                    curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $certpass);
1610
+                }
1611
+                // whether to verify remote host's cert
1612
+                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
1613
+                // set ca certificates file/dir
1614
+                if($cacert)
1615
+                {
1616
+                    curl_setopt($curl, CURLOPT_CAINFO, $cacert);
1617
+                }
1618
+                if($cacertdir)
1619
+                {
1620
+                    curl_setopt($curl, CURLOPT_CAPATH, $cacertdir);
1621
+                }
1622
+                // set key file (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
1623
+                if($key)
1624
+                {
1625
+                    curl_setopt($curl, CURLOPT_SSLKEY, $key);
1626
+                }
1627
+                // set key password (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
1628
+                if($keypass)
1629
+                {
1630
+                    curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $keypass);
1631
+                }
1632
+
1633
+                // Upgrade transparently to more stringent check for versions of php which do not support otherwise.
1634
+                // Doing it in constructor would be cleaner; doing it here saves us a couple of function calls
1635
+                if($this->verifyhost == 1 && $info = curl_version() && version_compare($info['version'], '7.28.1') >= 0)
1636
+                {
1637
+                    $this->verifyhost = 2;
1638
+                }
1639
+                // whether to verify cert's common name (CN); 0 for no, 1 to verify that it exists, and 2 to verify that it matches the hostname used
1640
+                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
1641
+            }
1642
+
1643
+            // proxy info
1644
+            if($proxyhost)
1645
+            {
1646
+                if($proxyport == 0)
1647
+                {
1648
+                    $proxyport = 8080; // NB: even for HTTPS, local connection is on port 8080
1649
+                }
1650
+                curl_setopt($curl, CURLOPT_PROXY, $proxyhost.':'.$proxyport);
1651
+                //curl_setopt($curl, CURLOPT_PROXYPORT,$proxyport);
1652
+                if($proxyusername)
1653
+                {
1654
+                    curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyusername.':'.$proxypassword);
1655
+                    if (defined('CURLOPT_PROXYAUTH'))
1656
+                    {
1657
+                        curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyauthtype);
1658
+                    }
1659
+                    else if ($proxyauthtype != 1)
1660
+                    {
1661
+                        error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
1662
+                    }
1663
+                }
1664
+            }
1665
+
1666
+            // NB: should we build cookie http headers by hand rather than let CURL do it?
1667
+            // the following code does not honour 'expires', 'path' and 'domain' cookie attributes
1668
+            // set to client obj the the user...
1669
+            if (count($this->cookies))
1670
+            {
1671
+                $cookieheader = '';
1672
+                foreach ($this->cookies as $name => $cookie)
1673
+                {
1674
+                    $cookieheader .= $name . '=' . $cookie['value'] . '; ';
1675
+                }
1676
+                curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2));
1677
+            }
1678
+
1679
+            foreach ($this->extracurlopts as $opt => $val)
1680
+            {
1681
+                curl_setopt($curl, $opt, $val);
1682
+            }
1683
+
1684
+            $result = curl_exec($curl);
1685
+
1686
+            if ($this->debug > 1)
1687
+            {
1688
+                print "<PRE>\n---CURL INFO---\n";
1689
+                foreach(curl_getinfo($curl) as $name => $val)
1690
+                {
1691
+                    if (is_array($val))
1692
+                    {
1693
+                        $val = implode("\n", $val);
1694
+                    }
1695
+                    print $name . ': ' . htmlentities($val) . "\n";
1696
+                }
1697
+
1698
+                print "---END---\n</PRE>";
1699
+            }
1700
+
1701
+            if(!$result) /// @todo we should use a better check here - what if we get back '' or '0'?
1702
+            {
1703
+                $this->errstr='no response';
1704
+                $resp=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['curl_fail'], $GLOBALS['xmlrpcstr']['curl_fail']. ': '. curl_error($curl));
1705
+                curl_close($curl);
1706
+                if($keepalive)
1707
+                {
1708
+                    $this->xmlrpc_curl_handle = null;
1709
+                }
1710
+            }
1711
+            else
1712
+            {
1713
+                if(!$keepalive)
1714
+                {
1715
+                    curl_close($curl);
1716
+                }
1717
+                $resp =& $msg->parseResponse($result, true, $this->return_type);
1718
+                // if we got back a 302, we can not reuse the curl handle for later calls
1719
+                if($resp->faultCode() == $GLOBALS['xmlrpcerr']['http_error'] && $keepalive)
1720
+                {
1721
+                    curl_close($curl);
1722
+                    $this->xmlrpc_curl_handle = null;
1723
+                }
1724
+            }
1725
+            return $resp;
1726
+        }
1727
+
1728
+        /**
1729
+         * Send an array of request messages and return an array of responses.
1730
+         * Unless $this->no_multicall has been set to true, it will try first
1731
+         * to use one single xmlrpc call to server method system.multicall, and
1732
+         * revert to sending many successive calls in case of failure.
1733
+         * This failure is also stored in $this->no_multicall for subsequent calls.
1734
+         * Unfortunately, there is no server error code universally used to denote
1735
+         * the fact that multicall is unsupported, so there is no way to reliably
1736
+         * distinguish between that and a temporary failure.
1737
+         * If you are sure that server supports multicall and do not want to
1738
+         * fallback to using many single calls, set the fourth parameter to FALSE.
1739
+         *
1740
+         * NB: trying to shoehorn extra functionality into existing syntax has resulted
1741
+         * in pretty much convoluted code...
1742
+         *
1743
+         * @param array $msgs an array of xmlrpcmsg objects
1744
+         * @param integer $timeout connection timeout (in seconds)
1745
+         * @param string $method the http protocol variant to be used
1746
+         * @param boolean fallback When true, upon receiving an error during multicall, multiple single calls will be attempted
1747
+         * @return array
1748
+         * @access public
1749
+         */
1750
+        function multicall($msgs, $timeout=0, $method='', $fallback=true)
1751
+        {
1752
+            if ($method == '')
1753
+            {
1754
+                $method = $this->method;
1755
+            }
1756
+            if(!$this->no_multicall)
1757
+            {
1758
+                $results = $this->_try_multicall($msgs, $timeout, $method);
1759
+                if(is_array($results))
1760
+                {
1761
+                    // System.multicall succeeded
1762
+                    return $results;
1763
+                }
1764
+                else
1765
+                {
1766
+                    // either system.multicall is unsupported by server,
1767
+                    // or call failed for some other reason.
1768
+                    if ($fallback)
1769
+                    {
1770
+                        // Don't try it next time...
1771
+                        $this->no_multicall = true;
1772
+                    }
1773
+                    else
1774
+                    {
1775
+                        if (is_a($results, 'xmlrpcresp'))
1776
+                        {
1777
+                            $result = $results;
1778
+                        }
1779
+                        else
1780
+                        {
1781
+                            $result = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['multicall_error'], $GLOBALS['xmlrpcstr']['multicall_error']);
1782
+                        }
1783
+                    }
1784
+                }
1785
+            }
1786
+            else
1787
+            {
1788
+                // override fallback, in case careless user tries to do two
1789
+                // opposite things at the same time
1790
+                $fallback = true;
1791
+            }
1792
+
1793
+            $results = array();
1794
+            if ($fallback)
1795
+            {
1796
+                // system.multicall is (probably) unsupported by server:
1797
+                // emulate multicall via multiple requests
1798
+                foreach($msgs as $msg)
1799
+                {
1800
+                    $results[] =& $this->send($msg, $timeout, $method);
1801
+                }
1802
+            }
1803
+            else
1804
+            {
1805
+                // user does NOT want to fallback on many single calls:
1806
+                // since we should always return an array of responses,
1807
+                // return an array with the same error repeated n times
1808
+                foreach($msgs as $msg)
1809
+                {
1810
+                    $results[] = $result;
1811
+                }
1812
+            }
1813
+            return $results;
1814
+        }
1815
+
1816
+        /**
1817
+         * Attempt to boxcar $msgs via system.multicall.
1818
+         * Returns either an array of xmlrpcreponses, an xmlrpc error response
1819
+         * or false (when received response does not respect valid multicall syntax)
1820
+         * @access private
1821
+         */
1822
+        function _try_multicall($msgs, $timeout, $method)
1823
+        {
1824
+            // Construct multicall message
1825
+            $calls = array();
1826
+            foreach($msgs as $msg)
1827
+            {
1828
+                $call['methodName'] = new xmlrpcval($msg->method(),'string');
1829
+                $numParams = $msg->getNumParams();
1830
+                $params = array();
1831
+                for($i = 0; $i < $numParams; $i++)
1832
+                {
1833
+                    $params[$i] = $msg->getParam($i);
1834
+                }
1835
+                $call['params'] = new xmlrpcval($params, 'array');
1836
+                $calls[] = new xmlrpcval($call, 'struct');
1837
+            }
1838
+            $multicall = new xmlrpcmsg('system.multicall');
1839
+            $multicall->addParam(new xmlrpcval($calls, 'array'));
1840
+
1841
+            // Attempt RPC call
1842
+            $result =& $this->send($multicall, $timeout, $method);
1843
+
1844
+            if($result->faultCode() != 0)
1845
+            {
1846
+                // call to system.multicall failed
1847
+                return $result;
1848
+            }
1849
+
1850
+            // Unpack responses.
1851
+            $rets = $result->value();
1852
+
1853
+            if ($this->return_type == 'xml')
1854
+            {
1855
+                    return $rets;
1856
+            }
1857
+            else if ($this->return_type == 'phpvals')
1858
+            {
1859
+                ///@todo test this code branch...
1860
+                $rets = $result->value();
1861
+                if(!is_array($rets))
1862
+                {
1863
+                    return false;		// bad return type from system.multicall
1864
+                }
1865
+                $numRets = count($rets);
1866
+                if($numRets != count($msgs))
1867
+                {
1868
+                    return false;		// wrong number of return values.
1869
+                }
1870
+
1871
+                $response = array();
1872
+                for($i = 0; $i < $numRets; $i++)
1873
+                {
1874
+                    $val = $rets[$i];
1875
+                    if (!is_array($val)) {
1876
+                        return false;
1877
+                    }
1878
+                    switch(count($val))
1879
+                    {
1880
+                        case 1:
1881
+                            if(!isset($val[0]))
1882
+                            {
1883
+                                return false;		// Bad value
1884
+                            }
1885
+                            // Normal return value
1886
+                            $response[$i] = new xmlrpcresp($val[0], 0, '', 'phpvals');
1887
+                            break;
1888
+                        case 2:
1889
+                            ///	@todo remove usage of @: it is apparently quite slow
1890
+                            $code = @$val['faultCode'];
1891
+                            if(!is_int($code))
1892
+                            {
1893
+                                return false;
1894
+                            }
1895
+                            $str = @$val['faultString'];
1896
+                            if(!is_string($str))
1897
+                            {
1898
+                                return false;
1899
+                            }
1900
+                            $response[$i] = new xmlrpcresp(0, $code, $str);
1901
+                            break;
1902
+                        default:
1903
+                            return false;
1904
+                    }
1905
+                }
1906
+                return $response;
1907
+            }
1908
+            else // return type == 'xmlrpcvals'
1909
+            {
1910
+                $rets = $result->value();
1911
+                if($rets->kindOf() != 'array')
1912
+                {
1913
+                    return false;		// bad return type from system.multicall
1914
+                }
1915
+                $numRets = $rets->arraysize();
1916
+                if($numRets != count($msgs))
1917
+                {
1918
+                    return false;		// wrong number of return values.
1919
+                }
1920
+
1921
+                $response = array();
1922
+                for($i = 0; $i < $numRets; $i++)
1923
+                {
1924
+                    $val = $rets->arraymem($i);
1925
+                    switch($val->kindOf())
1926
+                    {
1927
+                        case 'array':
1928
+                            if($val->arraysize() != 1)
1929
+                            {
1930
+                                return false;		// Bad value
1931
+                            }
1932
+                            // Normal return value
1933
+                            $response[$i] = new xmlrpcresp($val->arraymem(0));
1934
+                            break;
1935
+                        case 'struct':
1936
+                            $code = $val->structmem('faultCode');
1937
+                            if($code->kindOf() != 'scalar' || $code->scalartyp() != 'int')
1938
+                            {
1939
+                                return false;
1940
+                            }
1941
+                            $str = $val->structmem('faultString');
1942
+                            if($str->kindOf() != 'scalar' || $str->scalartyp() != 'string')
1943
+                            {
1944
+                                return false;
1945
+                            }
1946
+                            $response[$i] = new xmlrpcresp(0, $code->scalarval(), $str->scalarval());
1947
+                            break;
1948
+                        default:
1949
+                            return false;
1950
+                    }
1951
+                }
1952
+                return $response;
1953
+            }
1954
+        }
1955
+    } // end class xmlrpc_client
1956
+
1957
+    class xmlrpcresp
1958
+    {
1959
+        var $val = 0;
1960
+        var $valtyp;
1961
+        var $errno = 0;
1962
+        var $errstr = '';
1963
+        var $payload;
1964
+        var $hdrs = array();
1965
+        var $_cookies = array();
1966
+        var $content_type = 'text/xml';
1967
+        var $raw_data = '';
1968
+
1969
+        /**
1970
+         * @param mixed $val either an xmlrpcval obj, a php value or the xml serialization of an xmlrpcval (a string)
1971
+         * @param integer $fcode set it to anything but 0 to create an error response
1972
+         * @param string $fstr the error string, in case of an error response
1973
+         * @param string $valtyp either 'xmlrpcvals', 'phpvals' or 'xml'
1974
+         *
1975
+         * @todo add check that $val / $fcode / $fstr is of correct type???
1976
+         * NB: as of now we do not do it, since it might be either an xmlrpcval or a plain
1977
+         * php val, or a complete xml chunk, depending on usage of xmlrpc_client::send() inside which creator is called...
1978
+         */
1979
+        function __construct($val, $fcode = 0, $fstr = '', $valtyp='')
1980
+        {
1981
+            if($fcode != 0)
1982
+            {
1983
+                // error response
1984
+                $this->errno = $fcode;
1985
+                $this->errstr = $fstr;
1986
+                //$this->errstr = htmlspecialchars($fstr); // XXX: encoding probably shouldn't be done here; fix later.
1987
+            }
1988
+            else
1989
+            {
1990
+                // successful response
1991
+                $this->val = $val;
1992
+                if ($valtyp == '')
1993
+                {
1994
+                    // user did not declare type of response value: try to guess it
1995
+                    if (is_object($this->val) && is_a($this->val, 'xmlrpcval'))
1996
+                    {
1997
+                        $this->valtyp = 'xmlrpcvals';
1998
+                    }
1999
+                    else if (is_string($this->val))
2000
+                    {
2001
+                        $this->valtyp = 'xml';
2002
+
2003
+                    }
2004
+                    else
2005
+                    {
2006
+                        $this->valtyp = 'phpvals';
2007
+                    }
2008
+                }
2009
+                else
2010
+                {
2011
+                    // user declares type of resp value: believe him
2012
+                    $this->valtyp = $valtyp;
2013
+                }
2014
+            }
2015
+        }
2016
+
2017
+        /**
2018
+         * @deprecated
2019
+         */
2020
+        function xmlrpcresp($val, $fcode = 0, $fstr = '', $valtyp='')
2021
+        {
2022
+            self::__construct($val, $fcode, $fstr, $valtyp);
2023
+        }
2024
+
2025
+        /**
2026
+         * Returns the error code of the response.
2027
+         * @return integer the error code of this response (0 for not-error responses)
2028
+         * @access public
2029
+         */
2030
+        function faultCode()
2031
+        {
2032
+            return $this->errno;
2033
+        }
2034
+
2035
+        /**
2036
+         * Returns the error code of the response.
2037
+         * @return string the error string of this response ('' for not-error responses)
2038
+         * @access public
2039
+         */
2040
+        function faultString()
2041
+        {
2042
+            return $this->errstr;
2043
+        }
2044
+
2045
+        /**
2046
+         * Returns the value received by the server.
2047
+         * @return mixed the xmlrpcval object returned by the server. Might be an xml string or php value if the response has been created by specially configured xmlrpc_client objects
2048
+         * @access public
2049
+         */
2050
+        function value()
2051
+        {
2052
+            return $this->val;
2053
+        }
2054
+
2055
+        /**
2056
+         * Returns an array with the cookies received from the server.
2057
+         * Array has the form: $cookiename => array ('value' => $val, $attr1 => $val1, $attr2 = $val2, ...)
2058
+         * with attributes being e.g. 'expires', 'path', domain'.
2059
+         * NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past)
2060
+         * are still present in the array. It is up to the user-defined code to decide
2061
+         * how to use the received cookies, and whether they have to be sent back with the next
2062
+         * request to the server (using xmlrpc_client::setCookie) or not
2063
+         * @return array array of cookies received from the server
2064
+         * @access public
2065
+         */
2066
+        function cookies()
2067
+        {
2068
+            return $this->_cookies;
2069
+        }
2070
+
2071
+        /**
2072
+         * Returns xml representation of the response. XML prologue not included
2073
+         * @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed
2074
+         * @return string the xml representation of the response
2075
+         * @access public
2076
+         */
2077
+        function serialize($charset_encoding='')
2078
+        {
2079
+            if ($charset_encoding != '')
2080
+                $this->content_type = 'text/xml; charset=' . $charset_encoding;
2081
+            else
2082
+                $this->content_type = 'text/xml';
2083
+            if ($GLOBALS['xmlrpc_null_apache_encoding'])
2084
+            {
2085
+                $result = "<methodResponse xmlns:ex=\"".$GLOBALS['xmlrpc_null_apache_encoding_ns']."\">\n";
2086
+            }
2087
+            else
2088
+            {
2089
+            $result = "<methodResponse>\n";
2090
+            }
2091
+            if($this->errno)
2092
+            {
2093
+                // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
2094
+                // by xml-encoding non ascii chars
2095
+                $result .= "<fault>\n" .
2096 2096
 "<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
2097 2097
 "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
2098 2098
 xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</string></value>\n</member>\n" .
2099 2099
 "</struct>\n</value>\n</fault>";
2100
-			}
2101
-			else
2102
-			{
2103
-				if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
2104
-				{
2105
-					if (is_string($this->val) && $this->valtyp == 'xml')
2106
-					{
2107
-						$result .= "<params>\n<param>\n" .
2108
-							$this->val .
2109
-							"</param>\n</params>";
2110
-					}
2111
-					else
2112
-					{
2113
-						/// @todo try to build something serializable?
2114
-						die('cannot serialize xmlrpcresp objects whose content is native php values');
2115
-					}
2116
-				}
2117
-				else
2118
-				{
2119
-					$result .= "<params>\n<param>\n" .
2120
-						$this->val->serialize($charset_encoding) .
2121
-						"</param>\n</params>";
2122
-				}
2123
-			}
2124
-			$result .= "\n</methodResponse>";
2125
-			$this->payload = $result;
2126
-			return $result;
2127
-		}
2128
-	}
2129
-
2130
-	class xmlrpcmsg
2131
-	{
2132
-		var $payload;
2133
-		var $methodname;
2134
-		var $params=array();
2135
-		var $debug=0;
2136
-		var $content_type = 'text/xml';
2137
-
2138
-		/**
2139
-		* @param string $meth the name of the method to invoke
2140
-		* @param array $pars array of parameters to be passed to the method (xmlrpcval objects)
2141
-		*/
2142
-		function __construct($meth, $pars=0)
2143
-		{
2144
-			$this->methodname=$meth;
2145
-			if(is_array($pars) && count($pars)>0)
2146
-			{
2147
-				for($i=0; $i<count($pars); $i++)
2148
-				{
2149
-					$this->addParam($pars[$i]);
2150
-				}
2151
-			}
2152
-		}
2153
-
2154
-				/**
2155
-		* @deprecated
2156
-		*/
2157
-		function xmlrpcmsg($meth, $pars=0)
2158
-		{
2159
-			self::__construct($meth, $pars);
2160
-		}
2161
-
2162
-		/**
2163
-		* @access private
2164
-		*/
2165
-		function xml_header($charset_encoding='')
2166
-		{
2167
-			if ($charset_encoding != '')
2168
-			{
2169
-				return "<?xml version=\"1.0\" encoding=\"$charset_encoding\" ?" . ">\n<methodCall>\n";
2170
-			}
2171
-			else
2172
-			{
2173
-				return "<?xml version=\"1.0\"?" . ">\n<methodCall>\n";
2174
-			}
2175
-		}
2176
-
2177
-		/**
2178
-		* @access private
2179
-		*/
2180
-		function xml_footer()
2181
-		{
2182
-			return '</methodCall>';
2183
-		}
2184
-
2185
-		/**
2186
-		* @access private
2187
-		*/
2188
-		function kindOf()
2189
-		{
2190
-			return 'msg';
2191
-		}
2192
-
2193
-		/**
2194
-		* @access private
2195
-		*/
2196
-		function createPayload($charset_encoding='')
2197
-		{
2198
-			if ($charset_encoding != '')
2199
-				$this->content_type = 'text/xml; charset=' . $charset_encoding;
2200
-			else
2201
-				$this->content_type = 'text/xml';
2202
-			$this->payload=$this->xml_header($charset_encoding);
2203
-			$this->payload.='<methodName>' . xmlrpc_encode_entitites($this->methodname, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</methodName>\n";
2204
-			$this->payload.="<params>\n";
2205
-			for($i=0; $i<count($this->params); $i++)
2206
-			{
2207
-				$p=$this->params[$i];
2208
-				$this->payload.="<param>\n" . $p->serialize($charset_encoding) .
2209
-				"</param>\n";
2210
-			}
2211
-			$this->payload.="</params>\n";
2212
-			$this->payload.=$this->xml_footer();
2213
-		}
2214
-
2215
-		/**
2216
-		* Gets/sets the xmlrpc method to be invoked
2217
-		* @param string $meth the method to be set (leave empty not to set it)
2218
-		* @return string the method that will be invoked
2219
-		* @access public
2220
-		*/
2221
-		function method($meth='')
2222
-		{
2223
-			if($meth!='')
2224
-			{
2225
-				$this->methodname=$meth;
2226
-			}
2227
-			return $this->methodname;
2228
-		}
2229
-
2230
-		/**
2231
-		* Returns xml representation of the message. XML prologue included
2232
-		* @param string $charset_encoding
2233
-		* @return string the xml representation of the message, xml prologue included
2234
-		* @access public
2235
-		*/
2236
-		function serialize($charset_encoding='')
2237
-		{
2238
-			$this->createPayload($charset_encoding);
2239
-			return $this->payload;
2240
-		}
2241
-
2242
-		/**
2243
-		* Add a parameter to the list of parameters to be used upon method invocation
2244
-		* @param xmlrpcval $par
2245
-		* @return boolean false on failure
2246
-		* @access public
2247
-		*/
2248
-		function addParam($par)
2249
-		{
2250
-			// add check: do not add to self params which are not xmlrpcvals
2251
-			if(is_object($par) && is_a($par, 'xmlrpcval'))
2252
-			{
2253
-				$this->params[]=$par;
2254
-				return true;
2255
-			}
2256
-			else
2257
-			{
2258
-				return false;
2259
-			}
2260
-		}
2261
-
2262
-		/**
2263
-		* Returns the nth parameter in the message. The index zero-based.
2264
-		* @param integer $i the index of the parameter to fetch (zero based)
2265
-		* @return xmlrpcval the i-th parameter
2266
-		* @access public
2267
-		*/
2268
-		function getParam($i) { return $this->params[$i]; }
2269
-
2270
-		/**
2271
-		* Returns the number of parameters in the messge.
2272
-		* @return integer the number of parameters currently set
2273
-		* @access public
2274
-		*/
2275
-		function getNumParams() { return count($this->params); }
2276
-
2277
-		/**
2278
-		* Given an open file handle, read all data available and parse it as axmlrpc response.
2279
-		* NB: the file handle is not closed by this function.
2280
-		* NNB: might have trouble in rare cases to work on network streams, as we
2281
-		*      check for a read of 0 bytes instead of feof($fp).
2282
-		*      But since checking for feof(null) returns false, we would risk an
2283
-		*      infinite loop in that case, because we cannot trust the caller
2284
-		*      to give us a valid pointer to an open file...
2285
-		* @access public
2286
-		* @param resource $fp stream pointer
2287
-		* @return xmlrpcresp
2288
-		* @todo add 2nd & 3rd param to be passed to ParseResponse() ???
2289
-		*/
2290
-		function &parseResponseFile($fp)
2291
-		{
2292
-			$ipd='';
2293
-			while($data=fread($fp, 32768))
2294
-			{
2295
-				$ipd.=$data;
2296
-			}
2297
-			//fclose($fp);
2298
-			$r =& $this->parseResponse($ipd);
2299
-			return $r;
2300
-		}
2301
-
2302
-		/**
2303
-		* Parses HTTP headers and separates them from data.
2304
-		* @access private
2305
-		*/
2306
-		function &parseResponseHeaders(&$data, $headers_processed=false)
2307
-		{
2308
-				// Support "web-proxy-tunelling" connections for https through proxies
2309
-				if(preg_match('/^HTTP\/1\.[0-1] 200 Connection established/', $data))
2310
-				{
2311
-					// Look for CR/LF or simple LF as line separator,
2312
-					// (even though it is not valid http)
2313
-					$pos = strpos($data,"\r\n\r\n");
2314
-					if($pos || is_int($pos))
2315
-					{
2316
-						$bd = $pos+4;
2317
-					}
2318
-					else
2319
-					{
2320
-						$pos = strpos($data,"\n\n");
2321
-						if($pos || is_int($pos))
2322
-						{
2323
-							$bd = $pos+2;
2324
-						}
2325
-						else
2326
-						{
2327
-							// No separation between response headers and body: fault?
2328
-							$bd = 0;
2329
-						}
2330
-					}
2331
-					if ($bd)
2332
-					{
2333
-						// this filters out all http headers from proxy.
2334
-						// maybe we could take them into account, too?
2335
-						$data = substr($data, $bd);
2336
-					}
2337
-					else
2338
-					{
2339
-						error_log('XML-RPC: '.__METHOD__.': HTTPS via proxy error, tunnel connection possibly failed');
2340
-						$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $GLOBALS['xmlrpcstr']['http_error']. ' (HTTPS via proxy error, tunnel connection possibly failed)');
2341
-						return $r;
2342
-					}
2343
-				}
2344
-
2345
-				// Strip HTTP 1.1 100 Continue header if present
2346
-				while(preg_match('/^HTTP\/1\.1 1[0-9]{2} /', $data))
2347
-				{
2348
-					$pos = strpos($data, 'HTTP', 12);
2349
-					// server sent a Continue header without any (valid) content following...
2350
-					// give the client a chance to know it
2351
-					if(!$pos && !is_int($pos)) // works fine in php 3, 4 and 5
2352
-					{
2353
-						break;
2354
-					}
2355
-					$data = substr($data, $pos);
2356
-				}
2357
-				if(!preg_match('/^HTTP\/[0-9.]+ 200 /', $data))
2358
-				{
2359
-					$errstr= substr($data, 0, strpos($data, "\n")-1);
2360
-					error_log('XML-RPC: '.__METHOD__.': HTTP error, got response: ' .$errstr);
2361
-					$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $GLOBALS['xmlrpcstr']['http_error']. ' (' . $errstr . ')');
2362
-					return $r;
2363
-				}
2364
-
2365
-				$GLOBALS['_xh']['headers'] = array();
2366
-				$GLOBALS['_xh']['cookies'] = array();
2367
-
2368
-				// be tolerant to usage of \n instead of \r\n to separate headers and data
2369
-				// (even though it is not valid http)
2370
-				$pos = strpos($data,"\r\n\r\n");
2371
-				if($pos || is_int($pos))
2372
-				{
2373
-					$bd = $pos+4;
2374
-				}
2375
-				else
2376
-				{
2377
-					$pos = strpos($data,"\n\n");
2378
-					if($pos || is_int($pos))
2379
-					{
2380
-						$bd = $pos+2;
2381
-					}
2382
-					else
2383
-					{
2384
-						// No separation between response headers and body: fault?
2385
-						// we could take some action here instead of going on...
2386
-						$bd = 0;
2387
-					}
2388
-				}
2389
-				// be tolerant to line endings, and extra empty lines
2390
-				$ar = preg_split("/\r?\n/", trim(substr($data, 0, $pos)));
2391
-				while(list(,$line) = @each($ar))
2392
-				{
2393
-					// take care of multi-line headers and cookies
2394
-					$arr = explode(':',$line,2);
2395
-					if(count($arr) > 1)
2396
-					{
2397
-						$header_name = strtolower(trim($arr[0]));
2398
-						/// @todo some other headers (the ones that allow a CSV list of values)
2399
-						/// do allow many values to be passed using multiple header lines.
2400
-						/// We should add content to $GLOBALS['_xh']['headers'][$header_name]
2401
-						/// instead of replacing it for those...
2402
-						if ($header_name == 'set-cookie' || $header_name == 'set-cookie2')
2403
-						{
2404
-							if ($header_name == 'set-cookie2')
2405
-							{
2406
-								// version 2 cookies:
2407
-								// there could be many cookies on one line, comma separated
2408
-								$cookies = explode(',', $arr[1]);
2409
-							}
2410
-							else
2411
-							{
2412
-								$cookies = array($arr[1]);
2413
-							}
2414
-							foreach ($cookies as $cookie)
2415
-							{
2416
-								// glue together all received cookies, using a comma to separate them
2417
-								// (same as php does with getallheaders())
2418
-								if (isset($GLOBALS['_xh']['headers'][$header_name]))
2419
-									$GLOBALS['_xh']['headers'][$header_name] .= ', ' . trim($cookie);
2420
-								else
2421
-									$GLOBALS['_xh']['headers'][$header_name] = trim($cookie);
2422
-								// parse cookie attributes, in case user wants to correctly honour them
2423
-								// feature creep: only allow rfc-compliant cookie attributes?
2424
-								// @todo support for server sending multiple time cookie with same name, but using different PATHs
2425
-								$cookie = explode(';', $cookie);
2426
-								foreach ($cookie as $pos => $val)
2427
-								{
2428
-									$val = explode('=', $val, 2);
2429
-									$tag = trim($val[0]);
2430
-									$val = trim(@$val[1]);
2431
-									/// @todo with version 1 cookies, we should strip leading and trailing " chars
2432
-									if ($pos == 0)
2433
-									{
2434
-										$cookiename = $tag;
2435
-										$GLOBALS['_xh']['cookies'][$tag] = array();
2436
-										$GLOBALS['_xh']['cookies'][$cookiename]['value'] = urldecode($val);
2437
-									}
2438
-									else
2439
-									{
2440
-										if ($tag != 'value')
2441
-										{
2442
-											$GLOBALS['_xh']['cookies'][$cookiename][$tag] = $val;
2443
-										}
2444
-									}
2445
-								}
2446
-							}
2447
-						}
2448
-						else
2449
-						{
2450
-							$GLOBALS['_xh']['headers'][$header_name] = trim($arr[1]);
2451
-						}
2452
-					}
2453
-					elseif(isset($header_name))
2454
-					{
2455
-						///	@todo version1 cookies might span multiple lines, thus breaking the parsing above
2456
-						$GLOBALS['_xh']['headers'][$header_name] .= ' ' . trim($line);
2457
-					}
2458
-				}
2459
-
2460
-				$data = substr($data, $bd);
2461
-
2462
-				if($this->debug && count($GLOBALS['_xh']['headers']))
2463
-				{
2464
-					print '<PRE>';
2465
-					foreach($GLOBALS['_xh']['headers'] as $header => $value)
2466
-					{
2467
-						print htmlentities("HEADER: $header: $value\n");
2468
-					}
2469
-					foreach($GLOBALS['_xh']['cookies'] as $header => $value)
2470
-					{
2471
-						print htmlentities("COOKIE: $header={$value['value']}\n");
2472
-					}
2473
-					print "</PRE>\n";
2474
-				}
2475
-
2476
-				// if CURL was used for the call, http headers have been processed,
2477
-				// and dechunking + reinflating have been carried out
2478
-				if(!$headers_processed)
2479
-				{
2480
-					// Decode chunked encoding sent by http 1.1 servers
2481
-					if(isset($GLOBALS['_xh']['headers']['transfer-encoding']) && $GLOBALS['_xh']['headers']['transfer-encoding'] == 'chunked')
2482
-					{
2483
-						if(!$data = decode_chunked($data))
2484
-						{
2485
-							error_log('XML-RPC: '.__METHOD__.': errors occurred when trying to rebuild the chunked data received from server');
2486
-							$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['dechunk_fail'], $GLOBALS['xmlrpcstr']['dechunk_fail']);
2487
-							return $r;
2488
-						}
2489
-					}
2490
-
2491
-					// Decode gzip-compressed stuff
2492
-					// code shamelessly inspired from nusoap library by Dietrich Ayala
2493
-					if(isset($GLOBALS['_xh']['headers']['content-encoding']))
2494
-					{
2495
-						$GLOBALS['_xh']['headers']['content-encoding'] = str_replace('x-', '', $GLOBALS['_xh']['headers']['content-encoding']);
2496
-						if($GLOBALS['_xh']['headers']['content-encoding'] == 'deflate' || $GLOBALS['_xh']['headers']['content-encoding'] == 'gzip')
2497
-						{
2498
-							// if decoding works, use it. else assume data wasn't gzencoded
2499
-							if(function_exists('gzinflate'))
2500
-							{
2501
-								if($GLOBALS['_xh']['headers']['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data))
2502
-								{
2503
-									$data = $degzdata;
2504
-									if($this->debug)
2505
-									print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2506
-								}
2507
-								elseif($GLOBALS['_xh']['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
2508
-								{
2509
-									$data = $degzdata;
2510
-									if($this->debug)
2511
-									print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2512
-								}
2513
-								else
2514
-								{
2515
-									error_log('XML-RPC: '.__METHOD__.': errors occurred when trying to decode the deflated data received from server');
2516
-									$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['decompress_fail'], $GLOBALS['xmlrpcstr']['decompress_fail']);
2517
-									return $r;
2518
-								}
2519
-							}
2520
-							else
2521
-							{
2522
-								error_log('XML-RPC: '.__METHOD__.': the server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
2523
-								$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['cannot_decompress'], $GLOBALS['xmlrpcstr']['cannot_decompress']);
2524
-								return $r;
2525
-							}
2526
-						}
2527
-					}
2528
-				} // end of 'if needed, de-chunk, re-inflate response'
2529
-
2530
-				// real stupid hack to avoid PHP complaining about returning NULL by ref
2531
-				$r = null;
2532
-				$r =& $r;
2533
-				return $r;
2534
-		}
2535
-
2536
-		/**
2537
-		* Parse the xmlrpc response contained in the string $data and return an xmlrpcresp object.
2538
-		* @param string $data the xmlrpc response, eventually including http headers
2539
-		* @param bool $headers_processed when true prevents parsing HTTP headers for interpretation of content-encoding and consequent decoding
2540
-		* @param string $return_type decides return type, i.e. content of response->value(). Either 'xmlrpcvals', 'xml' or 'phpvals'
2541
-		* @return xmlrpcresp
2542
-		* @access public
2543
-		*/
2544
-		function &parseResponse($data='', $headers_processed=false, $return_type='xmlrpcvals')
2545
-		{
2546
-			if($this->debug)
2547
-			{
2548
-				//by maHo, replaced htmlspecialchars with htmlentities
2549
-				print "<PRE>---GOT---\n" . htmlentities($data) . "\n---END---\n</PRE>";
2550
-			}
2551
-
2552
-			if($data == '')
2553
-			{
2554
-				error_log('XML-RPC: '.__METHOD__.': no response received from server.');
2555
-				$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_data'], $GLOBALS['xmlrpcstr']['no_data']);
2556
-				return $r;
2557
-			}
2558
-
2559
-			$GLOBALS['_xh']=array();
2560
-
2561
-			$raw_data = $data;
2562
-			// parse the HTTP headers of the response, if present, and separate them from data
2563
-			if(substr($data, 0, 4) == 'HTTP')
2564
-			{
2565
-				$r =& $this->parseResponseHeaders($data, $headers_processed);
2566
-				if ($r)
2567
-				{
2568
-					// failed processing of HTTP response headers
2569
-					// save into response obj the full payload received, for debugging
2570
-					$r->raw_data = $data;
2571
-					return $r;
2572
-				}
2573
-			}
2574
-			else
2575
-			{
2576
-				$GLOBALS['_xh']['headers'] = array();
2577
-				$GLOBALS['_xh']['cookies'] = array();
2578
-			}
2579
-
2580
-			if($this->debug)
2581
-			{
2582
-				$start = strpos($data, '<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
2583
-				if ($start)
2584
-				{
2585
-					$start += strlen('<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
2586
-					$end = strpos($data, '-->', $start);
2587
-					$comments = substr($data, $start, $end-$start);
2588
-					print "<PRE>---SERVER DEBUG INFO (DECODED) ---\n\t".htmlentities(str_replace("\n", "\n\t", base64_decode($comments)))."\n---END---\n</PRE>";
2589
-				}
2590
-			}
2591
-
2592
-			// be tolerant of extra whitespace in response body
2593
-			$data = trim($data);
2594
-
2595
-			/// @todo return an error msg if $data=='' ?
2596
-
2597
-			// be tolerant of junk after methodResponse (e.g. javascript ads automatically inserted by free hosts)
2598
-			// idea from Luca Mariano <[email protected]> originally in PEARified version of the lib
2599
-			$pos = strrpos($data, '</methodResponse>');
2600
-			if($pos !== false)
2601
-			{
2602
-				$data = substr($data, 0, $pos+17);
2603
-			}
2604
-
2605
-			// if user wants back raw xml, give it to him
2606
-			if ($return_type == 'xml')
2607
-			{
2608
-				$r = new xmlrpcresp($data, 0, '', 'xml');
2609
-				$r->hdrs = $GLOBALS['_xh']['headers'];
2610
-				$r->_cookies = $GLOBALS['_xh']['cookies'];
2611
-				$r->raw_data = $raw_data;
2612
-				return $r;
2613
-			}
2614
-
2615
-			// try to 'guestimate' the character encoding of the received response
2616
-			$resp_encoding = guess_encoding(@$GLOBALS['_xh']['headers']['content-type'], $data);
2617
-
2618
-			$GLOBALS['_xh']['ac']='';
2619
-			//$GLOBALS['_xh']['qt']=''; //unused...
2620
-			$GLOBALS['_xh']['stack'] = array();
2621
-			$GLOBALS['_xh']['valuestack'] = array();
2622
-			$GLOBALS['_xh']['isf']=0; // 0 = OK, 1 for xmlrpc fault responses, 2 = invalid xmlrpc
2623
-			$GLOBALS['_xh']['isf_reason']='';
2624
-			$GLOBALS['_xh']['rt']=''; // 'methodcall or 'methodresponse'
2625
-
2626
-			// Since parsing will fail if charset is not specified in the xml prologue,
2627
-			// the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
2628
-			// The following code might be better for mb_string enabled installs, but
2629
-			// makes the lib about 200% slower...
2630
-			//if (!is_valid_charset($resp_encoding, array('UTF-8')))
2631
-			if (!in_array($resp_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($data)) {
2632
-				if ($resp_encoding == 'ISO-8859-1') {
2633
-					$data = utf8_encode($data);
2634
-				} else {
2635
-					if (extension_loaded('mbstring')) {
2636
-						$data = mb_convert_encoding($data, 'UTF-8', $resp_encoding);
2637
-					} else {
2638
-						error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $resp_encoding);
2639
-					}
2640
-				}
2641
-			}
2642
-
2643
-			$parser = xml_parser_create();
2644
-			xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
2645
-			// G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell
2646
-			// the xml parser to give us back data in the expected charset.
2647
-			// What if internal encoding is not in one of the 3 allowed?
2648
-			// we use the broadest one, ie. utf8
2649
-			// This allows to send data which is native in various charset,
2650
-			// by extending xmlrpc_encode_entitites() and setting xmlrpc_internalencoding
2651
-			if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
2652
-			{
2653
-				xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
2654
-			}
2655
-			else
2656
-			{
2657
-				xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
2658
-			}
2659
-
2660
-			if ($return_type == 'phpvals')
2661
-			{
2662
-				xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast');
2663
-			}
2664
-			else
2665
-			{
2666
-				xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
2667
-			}
2668
-
2669
-			xml_set_character_data_handler($parser, 'xmlrpc_cd');
2670
-			xml_set_default_handler($parser, 'xmlrpc_dh');
2671
-
2672
-			// first error check: xml not well formed
2673
-			if(!xml_parse($parser, $data, count($data)))
2674
-			{
2675
-				// thanks to Peter Kocks <[email protected]>
2676
-				if((xml_get_current_line_number($parser)) == 1)
2677
-				{
2678
-					$errstr = 'XML error at line 1, check URL';
2679
-				}
2680
-				else
2681
-				{
2682
-					$errstr = sprintf('XML error: %s at line %d, column %d',
2683
-						xml_error_string(xml_get_error_code($parser)),
2684
-						xml_get_current_line_number($parser), xml_get_current_column_number($parser));
2685
-				}
2686
-				error_log($errstr);
2687
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcstr']['invalid_return'].' ('.$errstr.')');
2688
-				xml_parser_free($parser);
2689
-				if($this->debug)
2690
-				{
2691
-					print $errstr;
2692
-				}
2693
-				$r->hdrs = $GLOBALS['_xh']['headers'];
2694
-				$r->_cookies = $GLOBALS['_xh']['cookies'];
2695
-				$r->raw_data = $raw_data;
2696
-				return $r;
2697
-			}
2698
-			xml_parser_free($parser);
2699
-			// second error check: xml well formed but not xml-rpc compliant
2700
-			if ($GLOBALS['_xh']['isf'] > 1)
2701
-			{
2702
-				if ($this->debug)
2703
-				{
2704
-					/// @todo echo something for user?
2705
-				}
2706
-
2707
-				$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'],
2708
-				$GLOBALS['xmlrpcstr']['invalid_return'] . ' ' . $GLOBALS['_xh']['isf_reason']);
2709
-			}
2710
-			// third error check: parsing of the response has somehow gone boink.
2711
-			// NB: shall we omit this check, since we trust the parsing code?
2712
-			elseif ($return_type == 'xmlrpcvals' && !is_object($GLOBALS['_xh']['value']))
2713
-			{
2714
-				// something odd has happened
2715
-				// and it's time to generate a client side error
2716
-				// indicating something odd went on
2717
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'],
2718
-					$GLOBALS['xmlrpcstr']['invalid_return']);
2719
-			}
2720
-			else
2721
-			{
2722
-				if ($this->debug)
2723
-				{
2724
-					print "<PRE>---PARSED---\n";
2725
-					// somehow htmlentities chokes on var_export, and some full html string...
2726
-					//print htmlentitites(var_export($GLOBALS['_xh']['value'], true));
2727
-					print htmlspecialchars(var_export($GLOBALS['_xh']['value'], true));
2728
-					print "\n---END---</PRE>";
2729
-				}
2730
-
2731
-				// note that using =& will raise an error if $GLOBALS['_xh']['st'] does not generate an object.
2732
-				$v =& $GLOBALS['_xh']['value'];
2733
-
2734
-				if($GLOBALS['_xh']['isf'])
2735
-				{
2736
-					/// @todo we should test here if server sent an int and a string,
2737
-					/// and/or coerce them into such...
2738
-					if ($return_type == 'xmlrpcvals')
2739
-					{
2740
-						$errno_v = $v->structmem('faultCode');
2741
-						$errstr_v = $v->structmem('faultString');
2742
-						$errno = $errno_v->scalarval();
2743
-						$errstr = $errstr_v->scalarval();
2744
-					}
2745
-					else
2746
-					{
2747
-						$errno = $v['faultCode'];
2748
-						$errstr = $v['faultString'];
2749
-					}
2750
-
2751
-					if($errno == 0)
2752
-					{
2753
-						// FAULT returned, errno needs to reflect that
2754
-						$errno = -1;
2755
-					}
2756
-
2757
-					$r = new xmlrpcresp(0, $errno, $errstr);
2758
-				}
2759
-				else
2760
-				{
2761
-					$r=new xmlrpcresp($v, 0, '', $return_type);
2762
-				}
2763
-			}
2764
-
2765
-			$r->hdrs = $GLOBALS['_xh']['headers'];
2766
-			$r->_cookies = $GLOBALS['_xh']['cookies'];
2767
-			$r->raw_data = $raw_data;
2768
-			return $r;
2769
-		}
2770
-	}
2771
-
2772
-	class xmlrpcval
2773
-	{
2774
-		var $me=array();
2775
-		var $mytype=0;
2776
-		var $_php_class=null;
2777
-
2778
-		/**
2779
-		* @param mixed $val
2780
-		* @param string $type any valid xmlrpc type name (lowercase). If null, 'string' is assumed
2781
-		*/
2782
-		function __construct($val=-1, $type='')
2783
-		{
2784
-			/// @todo: optimization creep - do not call addXX, do it all inline.
2785
-			/// downside: booleans will not be coerced anymore
2786
-			if($val!==-1 || $type!='')
2787
-			{
2788
-				// optimization creep: inlined all work done by constructor
2789
-				switch($type)
2790
-				{
2791
-					case '':
2792
-						$this->mytype=1;
2793
-						$this->me['string']=$val;
2794
-						break;
2795
-					case 'i4':
2796
-					case 'int':
2797
-					case 'double':
2798
-					case 'string':
2799
-					case 'boolean':
2800
-					case 'dateTime.iso8601':
2801
-					case 'base64':
2802
-					case 'null':
2803
-						$this->mytype=1;
2804
-						$this->me[$type]=$val;
2805
-						break;
2806
-					case 'array':
2807
-						$this->mytype=2;
2808
-						$this->me['array']=$val;
2809
-						break;
2810
-					case 'struct':
2811
-						$this->mytype=3;
2812
-						$this->me['struct']=$val;
2813
-						break;
2814
-					default:
2815
-						error_log("XML-RPC: ".__METHOD__.": not a known type ($type)");
2816
-				}
2817
-				/*if($type=='')
2100
+            }
2101
+            else
2102
+            {
2103
+                if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
2104
+                {
2105
+                    if (is_string($this->val) && $this->valtyp == 'xml')
2106
+                    {
2107
+                        $result .= "<params>\n<param>\n" .
2108
+                            $this->val .
2109
+                            "</param>\n</params>";
2110
+                    }
2111
+                    else
2112
+                    {
2113
+                        /// @todo try to build something serializable?
2114
+                        die('cannot serialize xmlrpcresp objects whose content is native php values');
2115
+                    }
2116
+                }
2117
+                else
2118
+                {
2119
+                    $result .= "<params>\n<param>\n" .
2120
+                        $this->val->serialize($charset_encoding) .
2121
+                        "</param>\n</params>";
2122
+                }
2123
+            }
2124
+            $result .= "\n</methodResponse>";
2125
+            $this->payload = $result;
2126
+            return $result;
2127
+        }
2128
+    }
2129
+
2130
+    class xmlrpcmsg
2131
+    {
2132
+        var $payload;
2133
+        var $methodname;
2134
+        var $params=array();
2135
+        var $debug=0;
2136
+        var $content_type = 'text/xml';
2137
+
2138
+        /**
2139
+         * @param string $meth the name of the method to invoke
2140
+         * @param array $pars array of parameters to be passed to the method (xmlrpcval objects)
2141
+         */
2142
+        function __construct($meth, $pars=0)
2143
+        {
2144
+            $this->methodname=$meth;
2145
+            if(is_array($pars) && count($pars)>0)
2146
+            {
2147
+                for($i=0; $i<count($pars); $i++)
2148
+                {
2149
+                    $this->addParam($pars[$i]);
2150
+                }
2151
+            }
2152
+        }
2153
+
2154
+                /**
2155
+                 * @deprecated
2156
+                 */
2157
+        function xmlrpcmsg($meth, $pars=0)
2158
+        {
2159
+            self::__construct($meth, $pars);
2160
+        }
2161
+
2162
+        /**
2163
+         * @access private
2164
+         */
2165
+        function xml_header($charset_encoding='')
2166
+        {
2167
+            if ($charset_encoding != '')
2168
+            {
2169
+                return "<?xml version=\"1.0\" encoding=\"$charset_encoding\" ?" . ">\n<methodCall>\n";
2170
+            }
2171
+            else
2172
+            {
2173
+                return "<?xml version=\"1.0\"?" . ">\n<methodCall>\n";
2174
+            }
2175
+        }
2176
+
2177
+        /**
2178
+         * @access private
2179
+         */
2180
+        function xml_footer()
2181
+        {
2182
+            return '</methodCall>';
2183
+        }
2184
+
2185
+        /**
2186
+         * @access private
2187
+         */
2188
+        function kindOf()
2189
+        {
2190
+            return 'msg';
2191
+        }
2192
+
2193
+        /**
2194
+         * @access private
2195
+         */
2196
+        function createPayload($charset_encoding='')
2197
+        {
2198
+            if ($charset_encoding != '')
2199
+                $this->content_type = 'text/xml; charset=' . $charset_encoding;
2200
+            else
2201
+                $this->content_type = 'text/xml';
2202
+            $this->payload=$this->xml_header($charset_encoding);
2203
+            $this->payload.='<methodName>' . xmlrpc_encode_entitites($this->methodname, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</methodName>\n";
2204
+            $this->payload.="<params>\n";
2205
+            for($i=0; $i<count($this->params); $i++)
2206
+            {
2207
+                $p=$this->params[$i];
2208
+                $this->payload.="<param>\n" . $p->serialize($charset_encoding) .
2209
+                "</param>\n";
2210
+            }
2211
+            $this->payload.="</params>\n";
2212
+            $this->payload.=$this->xml_footer();
2213
+        }
2214
+
2215
+        /**
2216
+         * Gets/sets the xmlrpc method to be invoked
2217
+         * @param string $meth the method to be set (leave empty not to set it)
2218
+         * @return string the method that will be invoked
2219
+         * @access public
2220
+         */
2221
+        function method($meth='')
2222
+        {
2223
+            if($meth!='')
2224
+            {
2225
+                $this->methodname=$meth;
2226
+            }
2227
+            return $this->methodname;
2228
+        }
2229
+
2230
+        /**
2231
+         * Returns xml representation of the message. XML prologue included
2232
+         * @param string $charset_encoding
2233
+         * @return string the xml representation of the message, xml prologue included
2234
+         * @access public
2235
+         */
2236
+        function serialize($charset_encoding='')
2237
+        {
2238
+            $this->createPayload($charset_encoding);
2239
+            return $this->payload;
2240
+        }
2241
+
2242
+        /**
2243
+         * Add a parameter to the list of parameters to be used upon method invocation
2244
+         * @param xmlrpcval $par
2245
+         * @return boolean false on failure
2246
+         * @access public
2247
+         */
2248
+        function addParam($par)
2249
+        {
2250
+            // add check: do not add to self params which are not xmlrpcvals
2251
+            if(is_object($par) && is_a($par, 'xmlrpcval'))
2252
+            {
2253
+                $this->params[]=$par;
2254
+                return true;
2255
+            }
2256
+            else
2257
+            {
2258
+                return false;
2259
+            }
2260
+        }
2261
+
2262
+        /**
2263
+         * Returns the nth parameter in the message. The index zero-based.
2264
+         * @param integer $i the index of the parameter to fetch (zero based)
2265
+         * @return xmlrpcval the i-th parameter
2266
+         * @access public
2267
+         */
2268
+        function getParam($i) { return $this->params[$i]; }
2269
+
2270
+        /**
2271
+         * Returns the number of parameters in the messge.
2272
+         * @return integer the number of parameters currently set
2273
+         * @access public
2274
+         */
2275
+        function getNumParams() { return count($this->params); }
2276
+
2277
+        /**
2278
+         * Given an open file handle, read all data available and parse it as axmlrpc response.
2279
+         * NB: the file handle is not closed by this function.
2280
+         * NNB: might have trouble in rare cases to work on network streams, as we
2281
+         *      check for a read of 0 bytes instead of feof($fp).
2282
+         *      But since checking for feof(null) returns false, we would risk an
2283
+         *      infinite loop in that case, because we cannot trust the caller
2284
+         *      to give us a valid pointer to an open file...
2285
+         * @access public
2286
+         * @param resource $fp stream pointer
2287
+         * @return xmlrpcresp
2288
+         * @todo add 2nd & 3rd param to be passed to ParseResponse() ???
2289
+         */
2290
+        function &parseResponseFile($fp)
2291
+        {
2292
+            $ipd='';
2293
+            while($data=fread($fp, 32768))
2294
+            {
2295
+                $ipd.=$data;
2296
+            }
2297
+            //fclose($fp);
2298
+            $r =& $this->parseResponse($ipd);
2299
+            return $r;
2300
+        }
2301
+
2302
+        /**
2303
+         * Parses HTTP headers and separates them from data.
2304
+         * @access private
2305
+         */
2306
+        function &parseResponseHeaders(&$data, $headers_processed=false)
2307
+        {
2308
+                // Support "web-proxy-tunelling" connections for https through proxies
2309
+                if(preg_match('/^HTTP\/1\.[0-1] 200 Connection established/', $data))
2310
+                {
2311
+                    // Look for CR/LF or simple LF as line separator,
2312
+                    // (even though it is not valid http)
2313
+                    $pos = strpos($data,"\r\n\r\n");
2314
+                    if($pos || is_int($pos))
2315
+                    {
2316
+                        $bd = $pos+4;
2317
+                    }
2318
+                    else
2319
+                    {
2320
+                        $pos = strpos($data,"\n\n");
2321
+                        if($pos || is_int($pos))
2322
+                        {
2323
+                            $bd = $pos+2;
2324
+                        }
2325
+                        else
2326
+                        {
2327
+                            // No separation between response headers and body: fault?
2328
+                            $bd = 0;
2329
+                        }
2330
+                    }
2331
+                    if ($bd)
2332
+                    {
2333
+                        // this filters out all http headers from proxy.
2334
+                        // maybe we could take them into account, too?
2335
+                        $data = substr($data, $bd);
2336
+                    }
2337
+                    else
2338
+                    {
2339
+                        error_log('XML-RPC: '.__METHOD__.': HTTPS via proxy error, tunnel connection possibly failed');
2340
+                        $r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $GLOBALS['xmlrpcstr']['http_error']. ' (HTTPS via proxy error, tunnel connection possibly failed)');
2341
+                        return $r;
2342
+                    }
2343
+                }
2344
+
2345
+                // Strip HTTP 1.1 100 Continue header if present
2346
+                while(preg_match('/^HTTP\/1\.1 1[0-9]{2} /', $data))
2347
+                {
2348
+                    $pos = strpos($data, 'HTTP', 12);
2349
+                    // server sent a Continue header without any (valid) content following...
2350
+                    // give the client a chance to know it
2351
+                    if(!$pos && !is_int($pos)) // works fine in php 3, 4 and 5
2352
+                    {
2353
+                        break;
2354
+                    }
2355
+                    $data = substr($data, $pos);
2356
+                }
2357
+                if(!preg_match('/^HTTP\/[0-9.]+ 200 /', $data))
2358
+                {
2359
+                    $errstr= substr($data, 0, strpos($data, "\n")-1);
2360
+                    error_log('XML-RPC: '.__METHOD__.': HTTP error, got response: ' .$errstr);
2361
+                    $r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $GLOBALS['xmlrpcstr']['http_error']. ' (' . $errstr . ')');
2362
+                    return $r;
2363
+                }
2364
+
2365
+                $GLOBALS['_xh']['headers'] = array();
2366
+                $GLOBALS['_xh']['cookies'] = array();
2367
+
2368
+                // be tolerant to usage of \n instead of \r\n to separate headers and data
2369
+                // (even though it is not valid http)
2370
+                $pos = strpos($data,"\r\n\r\n");
2371
+                if($pos || is_int($pos))
2372
+                {
2373
+                    $bd = $pos+4;
2374
+                }
2375
+                else
2376
+                {
2377
+                    $pos = strpos($data,"\n\n");
2378
+                    if($pos || is_int($pos))
2379
+                    {
2380
+                        $bd = $pos+2;
2381
+                    }
2382
+                    else
2383
+                    {
2384
+                        // No separation between response headers and body: fault?
2385
+                        // we could take some action here instead of going on...
2386
+                        $bd = 0;
2387
+                    }
2388
+                }
2389
+                // be tolerant to line endings, and extra empty lines
2390
+                $ar = preg_split("/\r?\n/", trim(substr($data, 0, $pos)));
2391
+                while(list(,$line) = @each($ar))
2392
+                {
2393
+                    // take care of multi-line headers and cookies
2394
+                    $arr = explode(':',$line,2);
2395
+                    if(count($arr) > 1)
2396
+                    {
2397
+                        $header_name = strtolower(trim($arr[0]));
2398
+                        /// @todo some other headers (the ones that allow a CSV list of values)
2399
+                        /// do allow many values to be passed using multiple header lines.
2400
+                        /// We should add content to $GLOBALS['_xh']['headers'][$header_name]
2401
+                        /// instead of replacing it for those...
2402
+                        if ($header_name == 'set-cookie' || $header_name == 'set-cookie2')
2403
+                        {
2404
+                            if ($header_name == 'set-cookie2')
2405
+                            {
2406
+                                // version 2 cookies:
2407
+                                // there could be many cookies on one line, comma separated
2408
+                                $cookies = explode(',', $arr[1]);
2409
+                            }
2410
+                            else
2411
+                            {
2412
+                                $cookies = array($arr[1]);
2413
+                            }
2414
+                            foreach ($cookies as $cookie)
2415
+                            {
2416
+                                // glue together all received cookies, using a comma to separate them
2417
+                                // (same as php does with getallheaders())
2418
+                                if (isset($GLOBALS['_xh']['headers'][$header_name]))
2419
+                                    $GLOBALS['_xh']['headers'][$header_name] .= ', ' . trim($cookie);
2420
+                                else
2421
+                                    $GLOBALS['_xh']['headers'][$header_name] = trim($cookie);
2422
+                                // parse cookie attributes, in case user wants to correctly honour them
2423
+                                // feature creep: only allow rfc-compliant cookie attributes?
2424
+                                // @todo support for server sending multiple time cookie with same name, but using different PATHs
2425
+                                $cookie = explode(';', $cookie);
2426
+                                foreach ($cookie as $pos => $val)
2427
+                                {
2428
+                                    $val = explode('=', $val, 2);
2429
+                                    $tag = trim($val[0]);
2430
+                                    $val = trim(@$val[1]);
2431
+                                    /// @todo with version 1 cookies, we should strip leading and trailing " chars
2432
+                                    if ($pos == 0)
2433
+                                    {
2434
+                                        $cookiename = $tag;
2435
+                                        $GLOBALS['_xh']['cookies'][$tag] = array();
2436
+                                        $GLOBALS['_xh']['cookies'][$cookiename]['value'] = urldecode($val);
2437
+                                    }
2438
+                                    else
2439
+                                    {
2440
+                                        if ($tag != 'value')
2441
+                                        {
2442
+                                            $GLOBALS['_xh']['cookies'][$cookiename][$tag] = $val;
2443
+                                        }
2444
+                                    }
2445
+                                }
2446
+                            }
2447
+                        }
2448
+                        else
2449
+                        {
2450
+                            $GLOBALS['_xh']['headers'][$header_name] = trim($arr[1]);
2451
+                        }
2452
+                    }
2453
+                    elseif(isset($header_name))
2454
+                    {
2455
+                        ///	@todo version1 cookies might span multiple lines, thus breaking the parsing above
2456
+                        $GLOBALS['_xh']['headers'][$header_name] .= ' ' . trim($line);
2457
+                    }
2458
+                }
2459
+
2460
+                $data = substr($data, $bd);
2461
+
2462
+                if($this->debug && count($GLOBALS['_xh']['headers']))
2463
+                {
2464
+                    print '<PRE>';
2465
+                    foreach($GLOBALS['_xh']['headers'] as $header => $value)
2466
+                    {
2467
+                        print htmlentities("HEADER: $header: $value\n");
2468
+                    }
2469
+                    foreach($GLOBALS['_xh']['cookies'] as $header => $value)
2470
+                    {
2471
+                        print htmlentities("COOKIE: $header={$value['value']}\n");
2472
+                    }
2473
+                    print "</PRE>\n";
2474
+                }
2475
+
2476
+                // if CURL was used for the call, http headers have been processed,
2477
+                // and dechunking + reinflating have been carried out
2478
+                if(!$headers_processed)
2479
+                {
2480
+                    // Decode chunked encoding sent by http 1.1 servers
2481
+                    if(isset($GLOBALS['_xh']['headers']['transfer-encoding']) && $GLOBALS['_xh']['headers']['transfer-encoding'] == 'chunked')
2482
+                    {
2483
+                        if(!$data = decode_chunked($data))
2484
+                        {
2485
+                            error_log('XML-RPC: '.__METHOD__.': errors occurred when trying to rebuild the chunked data received from server');
2486
+                            $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['dechunk_fail'], $GLOBALS['xmlrpcstr']['dechunk_fail']);
2487
+                            return $r;
2488
+                        }
2489
+                    }
2490
+
2491
+                    // Decode gzip-compressed stuff
2492
+                    // code shamelessly inspired from nusoap library by Dietrich Ayala
2493
+                    if(isset($GLOBALS['_xh']['headers']['content-encoding']))
2494
+                    {
2495
+                        $GLOBALS['_xh']['headers']['content-encoding'] = str_replace('x-', '', $GLOBALS['_xh']['headers']['content-encoding']);
2496
+                        if($GLOBALS['_xh']['headers']['content-encoding'] == 'deflate' || $GLOBALS['_xh']['headers']['content-encoding'] == 'gzip')
2497
+                        {
2498
+                            // if decoding works, use it. else assume data wasn't gzencoded
2499
+                            if(function_exists('gzinflate'))
2500
+                            {
2501
+                                if($GLOBALS['_xh']['headers']['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data))
2502
+                                {
2503
+                                    $data = $degzdata;
2504
+                                    if($this->debug)
2505
+                                    print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2506
+                                }
2507
+                                elseif($GLOBALS['_xh']['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
2508
+                                {
2509
+                                    $data = $degzdata;
2510
+                                    if($this->debug)
2511
+                                    print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2512
+                                }
2513
+                                else
2514
+                                {
2515
+                                    error_log('XML-RPC: '.__METHOD__.': errors occurred when trying to decode the deflated data received from server');
2516
+                                    $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['decompress_fail'], $GLOBALS['xmlrpcstr']['decompress_fail']);
2517
+                                    return $r;
2518
+                                }
2519
+                            }
2520
+                            else
2521
+                            {
2522
+                                error_log('XML-RPC: '.__METHOD__.': the server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
2523
+                                $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['cannot_decompress'], $GLOBALS['xmlrpcstr']['cannot_decompress']);
2524
+                                return $r;
2525
+                            }
2526
+                        }
2527
+                    }
2528
+                } // end of 'if needed, de-chunk, re-inflate response'
2529
+
2530
+                // real stupid hack to avoid PHP complaining about returning NULL by ref
2531
+                $r = null;
2532
+                $r =& $r;
2533
+                return $r;
2534
+        }
2535
+
2536
+        /**
2537
+         * Parse the xmlrpc response contained in the string $data and return an xmlrpcresp object.
2538
+         * @param string $data the xmlrpc response, eventually including http headers
2539
+         * @param bool $headers_processed when true prevents parsing HTTP headers for interpretation of content-encoding and consequent decoding
2540
+         * @param string $return_type decides return type, i.e. content of response->value(). Either 'xmlrpcvals', 'xml' or 'phpvals'
2541
+         * @return xmlrpcresp
2542
+         * @access public
2543
+         */
2544
+        function &parseResponse($data='', $headers_processed=false, $return_type='xmlrpcvals')
2545
+        {
2546
+            if($this->debug)
2547
+            {
2548
+                //by maHo, replaced htmlspecialchars with htmlentities
2549
+                print "<PRE>---GOT---\n" . htmlentities($data) . "\n---END---\n</PRE>";
2550
+            }
2551
+
2552
+            if($data == '')
2553
+            {
2554
+                error_log('XML-RPC: '.__METHOD__.': no response received from server.');
2555
+                $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_data'], $GLOBALS['xmlrpcstr']['no_data']);
2556
+                return $r;
2557
+            }
2558
+
2559
+            $GLOBALS['_xh']=array();
2560
+
2561
+            $raw_data = $data;
2562
+            // parse the HTTP headers of the response, if present, and separate them from data
2563
+            if(substr($data, 0, 4) == 'HTTP')
2564
+            {
2565
+                $r =& $this->parseResponseHeaders($data, $headers_processed);
2566
+                if ($r)
2567
+                {
2568
+                    // failed processing of HTTP response headers
2569
+                    // save into response obj the full payload received, for debugging
2570
+                    $r->raw_data = $data;
2571
+                    return $r;
2572
+                }
2573
+            }
2574
+            else
2575
+            {
2576
+                $GLOBALS['_xh']['headers'] = array();
2577
+                $GLOBALS['_xh']['cookies'] = array();
2578
+            }
2579
+
2580
+            if($this->debug)
2581
+            {
2582
+                $start = strpos($data, '<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
2583
+                if ($start)
2584
+                {
2585
+                    $start += strlen('<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
2586
+                    $end = strpos($data, '-->', $start);
2587
+                    $comments = substr($data, $start, $end-$start);
2588
+                    print "<PRE>---SERVER DEBUG INFO (DECODED) ---\n\t".htmlentities(str_replace("\n", "\n\t", base64_decode($comments)))."\n---END---\n</PRE>";
2589
+                }
2590
+            }
2591
+
2592
+            // be tolerant of extra whitespace in response body
2593
+            $data = trim($data);
2594
+
2595
+            /// @todo return an error msg if $data=='' ?
2596
+
2597
+            // be tolerant of junk after methodResponse (e.g. javascript ads automatically inserted by free hosts)
2598
+            // idea from Luca Mariano <[email protected]> originally in PEARified version of the lib
2599
+            $pos = strrpos($data, '</methodResponse>');
2600
+            if($pos !== false)
2601
+            {
2602
+                $data = substr($data, 0, $pos+17);
2603
+            }
2604
+
2605
+            // if user wants back raw xml, give it to him
2606
+            if ($return_type == 'xml')
2607
+            {
2608
+                $r = new xmlrpcresp($data, 0, '', 'xml');
2609
+                $r->hdrs = $GLOBALS['_xh']['headers'];
2610
+                $r->_cookies = $GLOBALS['_xh']['cookies'];
2611
+                $r->raw_data = $raw_data;
2612
+                return $r;
2613
+            }
2614
+
2615
+            // try to 'guestimate' the character encoding of the received response
2616
+            $resp_encoding = guess_encoding(@$GLOBALS['_xh']['headers']['content-type'], $data);
2617
+
2618
+            $GLOBALS['_xh']['ac']='';
2619
+            //$GLOBALS['_xh']['qt']=''; //unused...
2620
+            $GLOBALS['_xh']['stack'] = array();
2621
+            $GLOBALS['_xh']['valuestack'] = array();
2622
+            $GLOBALS['_xh']['isf']=0; // 0 = OK, 1 for xmlrpc fault responses, 2 = invalid xmlrpc
2623
+            $GLOBALS['_xh']['isf_reason']='';
2624
+            $GLOBALS['_xh']['rt']=''; // 'methodcall or 'methodresponse'
2625
+
2626
+            // Since parsing will fail if charset is not specified in the xml prologue,
2627
+            // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
2628
+            // The following code might be better for mb_string enabled installs, but
2629
+            // makes the lib about 200% slower...
2630
+            //if (!is_valid_charset($resp_encoding, array('UTF-8')))
2631
+            if (!in_array($resp_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($data)) {
2632
+                if ($resp_encoding == 'ISO-8859-1') {
2633
+                    $data = utf8_encode($data);
2634
+                } else {
2635
+                    if (extension_loaded('mbstring')) {
2636
+                        $data = mb_convert_encoding($data, 'UTF-8', $resp_encoding);
2637
+                    } else {
2638
+                        error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $resp_encoding);
2639
+                    }
2640
+                }
2641
+            }
2642
+
2643
+            $parser = xml_parser_create();
2644
+            xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
2645
+            // G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell
2646
+            // the xml parser to give us back data in the expected charset.
2647
+            // What if internal encoding is not in one of the 3 allowed?
2648
+            // we use the broadest one, ie. utf8
2649
+            // This allows to send data which is native in various charset,
2650
+            // by extending xmlrpc_encode_entitites() and setting xmlrpc_internalencoding
2651
+            if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
2652
+            {
2653
+                xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
2654
+            }
2655
+            else
2656
+            {
2657
+                xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
2658
+            }
2659
+
2660
+            if ($return_type == 'phpvals')
2661
+            {
2662
+                xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast');
2663
+            }
2664
+            else
2665
+            {
2666
+                xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
2667
+            }
2668
+
2669
+            xml_set_character_data_handler($parser, 'xmlrpc_cd');
2670
+            xml_set_default_handler($parser, 'xmlrpc_dh');
2671
+
2672
+            // first error check: xml not well formed
2673
+            if(!xml_parse($parser, $data, count($data)))
2674
+            {
2675
+                // thanks to Peter Kocks <[email protected]>
2676
+                if((xml_get_current_line_number($parser)) == 1)
2677
+                {
2678
+                    $errstr = 'XML error at line 1, check URL';
2679
+                }
2680
+                else
2681
+                {
2682
+                    $errstr = sprintf('XML error: %s at line %d, column %d',
2683
+                        xml_error_string(xml_get_error_code($parser)),
2684
+                        xml_get_current_line_number($parser), xml_get_current_column_number($parser));
2685
+                }
2686
+                error_log($errstr);
2687
+                $r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcstr']['invalid_return'].' ('.$errstr.')');
2688
+                xml_parser_free($parser);
2689
+                if($this->debug)
2690
+                {
2691
+                    print $errstr;
2692
+                }
2693
+                $r->hdrs = $GLOBALS['_xh']['headers'];
2694
+                $r->_cookies = $GLOBALS['_xh']['cookies'];
2695
+                $r->raw_data = $raw_data;
2696
+                return $r;
2697
+            }
2698
+            xml_parser_free($parser);
2699
+            // second error check: xml well formed but not xml-rpc compliant
2700
+            if ($GLOBALS['_xh']['isf'] > 1)
2701
+            {
2702
+                if ($this->debug)
2703
+                {
2704
+                    /// @todo echo something for user?
2705
+                }
2706
+
2707
+                $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'],
2708
+                $GLOBALS['xmlrpcstr']['invalid_return'] . ' ' . $GLOBALS['_xh']['isf_reason']);
2709
+            }
2710
+            // third error check: parsing of the response has somehow gone boink.
2711
+            // NB: shall we omit this check, since we trust the parsing code?
2712
+            elseif ($return_type == 'xmlrpcvals' && !is_object($GLOBALS['_xh']['value']))
2713
+            {
2714
+                // something odd has happened
2715
+                // and it's time to generate a client side error
2716
+                // indicating something odd went on
2717
+                $r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'],
2718
+                    $GLOBALS['xmlrpcstr']['invalid_return']);
2719
+            }
2720
+            else
2721
+            {
2722
+                if ($this->debug)
2723
+                {
2724
+                    print "<PRE>---PARSED---\n";
2725
+                    // somehow htmlentities chokes on var_export, and some full html string...
2726
+                    //print htmlentitites(var_export($GLOBALS['_xh']['value'], true));
2727
+                    print htmlspecialchars(var_export($GLOBALS['_xh']['value'], true));
2728
+                    print "\n---END---</PRE>";
2729
+                }
2730
+
2731
+                // note that using =& will raise an error if $GLOBALS['_xh']['st'] does not generate an object.
2732
+                $v =& $GLOBALS['_xh']['value'];
2733
+
2734
+                if($GLOBALS['_xh']['isf'])
2735
+                {
2736
+                    /// @todo we should test here if server sent an int and a string,
2737
+                    /// and/or coerce them into such...
2738
+                    if ($return_type == 'xmlrpcvals')
2739
+                    {
2740
+                        $errno_v = $v->structmem('faultCode');
2741
+                        $errstr_v = $v->structmem('faultString');
2742
+                        $errno = $errno_v->scalarval();
2743
+                        $errstr = $errstr_v->scalarval();
2744
+                    }
2745
+                    else
2746
+                    {
2747
+                        $errno = $v['faultCode'];
2748
+                        $errstr = $v['faultString'];
2749
+                    }
2750
+
2751
+                    if($errno == 0)
2752
+                    {
2753
+                        // FAULT returned, errno needs to reflect that
2754
+                        $errno = -1;
2755
+                    }
2756
+
2757
+                    $r = new xmlrpcresp(0, $errno, $errstr);
2758
+                }
2759
+                else
2760
+                {
2761
+                    $r=new xmlrpcresp($v, 0, '', $return_type);
2762
+                }
2763
+            }
2764
+
2765
+            $r->hdrs = $GLOBALS['_xh']['headers'];
2766
+            $r->_cookies = $GLOBALS['_xh']['cookies'];
2767
+            $r->raw_data = $raw_data;
2768
+            return $r;
2769
+        }
2770
+    }
2771
+
2772
+    class xmlrpcval
2773
+    {
2774
+        var $me=array();
2775
+        var $mytype=0;
2776
+        var $_php_class=null;
2777
+
2778
+        /**
2779
+         * @param mixed $val
2780
+         * @param string $type any valid xmlrpc type name (lowercase). If null, 'string' is assumed
2781
+         */
2782
+        function __construct($val=-1, $type='')
2783
+        {
2784
+            /// @todo: optimization creep - do not call addXX, do it all inline.
2785
+            /// downside: booleans will not be coerced anymore
2786
+            if($val!==-1 || $type!='')
2787
+            {
2788
+                // optimization creep: inlined all work done by constructor
2789
+                switch($type)
2790
+                {
2791
+                    case '':
2792
+                        $this->mytype=1;
2793
+                        $this->me['string']=$val;
2794
+                        break;
2795
+                    case 'i4':
2796
+                    case 'int':
2797
+                    case 'double':
2798
+                    case 'string':
2799
+                    case 'boolean':
2800
+                    case 'dateTime.iso8601':
2801
+                    case 'base64':
2802
+                    case 'null':
2803
+                        $this->mytype=1;
2804
+                        $this->me[$type]=$val;
2805
+                        break;
2806
+                    case 'array':
2807
+                        $this->mytype=2;
2808
+                        $this->me['array']=$val;
2809
+                        break;
2810
+                    case 'struct':
2811
+                        $this->mytype=3;
2812
+                        $this->me['struct']=$val;
2813
+                        break;
2814
+                    default:
2815
+                        error_log("XML-RPC: ".__METHOD__.": not a known type ($type)");
2816
+                }
2817
+                /*if($type=='')
2818 2818
 				{
2819 2819
 					$type='string';
2820 2820
 				}
@@ -2830,1079 +2830,1079 @@  discard block
 block discarded – undo
2830 2830
 				{
2831 2831
 					$this->addStruct($val);
2832 2832
 				}*/
2833
-			}
2834
-		}
2835
-
2836
-		/**
2837
-		* @deprecated
2838
-		*/
2839
-		function xmlrpcval($val=-1, $type='')
2840
-		{
2841
-			self::__construct($val, $type);
2842
-		}
2843
-
2844
-		/**
2845
-		* Add a single php value to an (unitialized) xmlrpcval
2846
-		* @param mixed $val
2847
-		* @param string $type
2848
-		* @return int 1 or 0 on failure
2849
-		*/
2850
-		function addScalar($val, $type='string')
2851
-		{
2852
-			$typeof=@$GLOBALS['xmlrpcTypes'][$type];
2853
-			if($typeof!=1)
2854
-			{
2855
-				error_log("XML-RPC: ".__METHOD__.": not a scalar type ($type)");
2856
-				return 0;
2857
-			}
2858
-
2859
-			// coerce booleans into correct values
2860
-			// NB: we should either do it for datetimes, integers and doubles, too,
2861
-			// or just plain remove this check, implemented on booleans only...
2862
-			if($type==$GLOBALS['xmlrpcBoolean'])
2863
-			{
2864
-				if(strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false')))
2865
-				{
2866
-					$val=true;
2867
-				}
2868
-				else
2869
-				{
2870
-					$val=false;
2871
-				}
2872
-			}
2873
-
2874
-			switch($this->mytype)
2875
-			{
2876
-				case 1:
2877
-					error_log('XML-RPC: '.__METHOD__.': scalar xmlrpcval can have only one value');
2878
-					return 0;
2879
-				case 3:
2880
-					error_log('XML-RPC: '.__METHOD__.': cannot add anonymous scalar to struct xmlrpcval');
2881
-					return 0;
2882
-				case 2:
2883
-					// we're adding a scalar value to an array here
2884
-					//$ar=$this->me['array'];
2885
-					//$ar[]=new xmlrpcval($val, $type);
2886
-					//$this->me['array']=$ar;
2887
-					// Faster (?) avoid all the costly array-copy-by-val done here...
2888
-					$this->me['array'][]=new xmlrpcval($val, $type);
2889
-					return 1;
2890
-				default:
2891
-					// a scalar, so set the value and remember we're scalar
2892
-					$this->me[$type]=$val;
2893
-					$this->mytype=$typeof;
2894
-					return 1;
2895
-			}
2896
-		}
2897
-
2898
-		/**
2899
-		* Add an array of xmlrpcval objects to an xmlrpcval
2900
-		* @param array $vals
2901
-		* @return int 1 or 0 on failure
2902
-		* @access public
2903
-		*
2904
-		* @todo add some checking for $vals to be an array of xmlrpcvals?
2905
-		*/
2906
-		function addArray($vals)
2907
-		{
2908
-			if($this->mytype==0)
2909
-			{
2910
-				$this->mytype=$GLOBALS['xmlrpcTypes']['array'];
2911
-				$this->me['array']=$vals;
2912
-				return 1;
2913
-			}
2914
-			elseif($this->mytype==2)
2915
-			{
2916
-				// we're adding to an array here
2917
-				$this->me['array'] = array_merge($this->me['array'], $vals);
2918
-				return 1;
2919
-			}
2920
-			else
2921
-			{
2922
-				error_log('XML-RPC: '.__METHOD__.': already initialized as a [' . $this->kindOf() . ']');
2923
-				return 0;
2924
-			}
2925
-		}
2926
-
2927
-		/**
2928
-		* Add an array of named xmlrpcval objects to an xmlrpcval
2929
-		* @param array $vals
2930
-		* @return int 1 or 0 on failure
2931
-		* @access public
2932
-		*
2933
-		* @todo add some checking for $vals to be an array?
2934
-		*/
2935
-		function addStruct($vals)
2936
-		{
2937
-			if($this->mytype==0)
2938
-			{
2939
-				$this->mytype=$GLOBALS['xmlrpcTypes']['struct'];
2940
-				$this->me['struct']=$vals;
2941
-				return 1;
2942
-			}
2943
-			elseif($this->mytype==3)
2944
-			{
2945
-				// we're adding to a struct here
2946
-				$this->me['struct'] = array_merge($this->me['struct'], $vals);
2947
-				return 1;
2948
-			}
2949
-			else
2950
-			{
2951
-				error_log('XML-RPC: '.__METHOD__.': already initialized as a [' . $this->kindOf() . ']');
2952
-				return 0;
2953
-			}
2954
-		}
2955
-
2956
-		// poor man's version of print_r ???
2957
-		// DEPRECATED!
2958
-		function dump($ar)
2959
-		{
2960
-			foreach($ar as $key => $val)
2961
-			{
2962
-				echo "$key => $val<br />";
2963
-				if($key == 'array')
2964
-				{
2965
-					while(list($key2, $val2) = each($val))
2966
-					{
2967
-						echo "-- $key2 => $val2<br />";
2968
-					}
2969
-				}
2970
-			}
2971
-		}
2972
-
2973
-		/**
2974
-		* Returns a string containing "struct", "array" or "scalar" describing the base type of the value
2975
-		* @return string
2976
-		* @access public
2977
-		*/
2978
-		function kindOf()
2979
-		{
2980
-			switch($this->mytype)
2981
-			{
2982
-				case 3:
2983
-					return 'struct';
2984
-					break;
2985
-				case 2:
2986
-					return 'array';
2987
-					break;
2988
-				case 1:
2989
-					return 'scalar';
2990
-					break;
2991
-				default:
2992
-					return 'undef';
2993
-			}
2994
-		}
2995
-
2996
-		/**
2997
-		* @access private
2998
-		*/
2999
-		function serializedata($typ, $val, $charset_encoding='')
3000
-		{
3001
-			$rs='';
3002
-			switch(@$GLOBALS['xmlrpcTypes'][$typ])
3003
-			{
3004
-				case 1:
3005
-					switch($typ)
3006
-					{
3007
-						case $GLOBALS['xmlrpcBase64']:
3008
-							$rs.="<${typ}>" . base64_encode($val) . "</${typ}>";
3009
-							break;
3010
-						case $GLOBALS['xmlrpcBoolean']:
3011
-							$rs.="<${typ}>" . ($val ? '1' : '0') . "</${typ}>";
3012
-							break;
3013
-						case $GLOBALS['xmlrpcString']:
3014
-							// G. Giunta 2005/2/13: do NOT use htmlentities, since
3015
-							// it will produce named html entities, which are invalid xml
3016
-							$rs.="<${typ}>" . xmlrpc_encode_entitites($val, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding). "</${typ}>";
3017
-							break;
3018
-						case $GLOBALS['xmlrpcInt']:
3019
-						case $GLOBALS['xmlrpcI4']:
3020
-							$rs.="<${typ}>".(int)$val."</${typ}>";
3021
-							break;
3022
-						case $GLOBALS['xmlrpcDouble']:
3023
-							// avoid using standard conversion of float to string because it is locale-dependent,
3024
-							// and also because the xmlrpc spec forbids exponential notation.
3025
-							// sprintf('%F') could be most likely ok but it fails eg. on 2e-14.
3026
-							// The code below tries its best at keeping max precision while avoiding exp notation,
3027
-							// but there is of course no limit in the number of decimal places to be used...
3028
-							$rs.="<${typ}>".preg_replace('/\\.?0+$/','',number_format((double)$val, 128, '.', ''))."</${typ}>";
3029
-							break;
3030
-						case $GLOBALS['xmlrpcDateTime']:
3031
-							if (is_string($val))
3032
-							{
3033
-								$rs.="<${typ}>${val}</${typ}>";
3034
-							}
3035
-							else if(is_a($val, 'DateTime'))
3036
-							{
3037
-								$rs.="<${typ}>".$val->format('Ymd\TH:i:s')."</${typ}>";
3038
-							}
3039
-							else if(is_int($val))
3040
-							{
3041
-								$rs.="<${typ}>".strftime("%Y%m%dT%H:%M:%S", $val)."</${typ}>";
3042
-							}
3043
-							else
3044
-							{
3045
-								// not really a good idea here: but what shall we output anyway? left for backward compat...
3046
-								$rs.="<${typ}>${val}</${typ}>";
3047
-							}
3048
-							break;
3049
-						case $GLOBALS['xmlrpcNull']:
3050
-							if ($GLOBALS['xmlrpc_null_apache_encoding'])
3051
-							{
3052
-								$rs.="<ex:nil/>";
3053
-							}
3054
-							else
3055
-							{
3056
-								$rs.="<nil/>";
3057
-							}
3058
-							break;
3059
-						default:
3060
-							// no standard type value should arrive here, but provide a possibility
3061
-							// for xmlrpcvals of unknown type...
3062
-							$rs.="<${typ}>${val}</${typ}>";
3063
-					}
3064
-					break;
3065
-				case 3:
3066
-					// struct
3067
-					if ($this->_php_class)
3068
-					{
3069
-						$rs.='<struct php_class="' . $this->_php_class . "\">\n";
3070
-					}
3071
-					else
3072
-					{
3073
-						$rs.="<struct>\n";
3074
-					}
3075
-					foreach($val as $key2 => $val2)
3076
-					{
3077
-						$rs.='<member><name>'.xmlrpc_encode_entitites($key2, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding)."</name>\n";
3078
-						//$rs.=$this->serializeval($val2);
3079
-						$rs.=$val2->serialize($charset_encoding);
3080
-						$rs.="</member>\n";
3081
-					}
3082
-					$rs.='</struct>';
3083
-					break;
3084
-				case 2:
3085
-					// array
3086
-					$rs.="<array>\n<data>\n";
3087
-					for($i=0; $i<count($val); $i++)
3088
-					{
3089
-						//$rs.=$this->serializeval($val[$i]);
3090
-						$rs.=$val[$i]->serialize($charset_encoding);
3091
-					}
3092
-					$rs.="</data>\n</array>";
3093
-					break;
3094
-				default:
3095
-					break;
3096
-			}
3097
-			return $rs;
3098
-		}
3099
-
3100
-		/**
3101
-		* Returns xml representation of the value. XML prologue not included
3102
-		* @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed
3103
-		* @return string
3104
-		* @access public
3105
-		*/
3106
-		function serialize($charset_encoding='')
3107
-		{
3108
-			// add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
3109
-			//if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
3110
-			//{
3111
-				reset($this->me);
3112
-				list($typ, $val) = each($this->me);
3113
-				return '<value>' . $this->serializedata($typ, $val, $charset_encoding) . "</value>\n";
3114
-			//}
3115
-		}
3116
-
3117
-		// DEPRECATED
3118
-		function serializeval($o)
3119
-		{
3120
-			// add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
3121
-			//if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
3122
-			//{
3123
-				$ar=$o->me;
3124
-				reset($ar);
3125
-				list($typ, $val) = each($ar);
3126
-				return '<value>' . $this->serializedata($typ, $val) . "</value>\n";
3127
-			//}
3128
-		}
3129
-
3130
-		/**
3131
-		* Checks whether a struct member with a given name is present.
3132
-		* Works only on xmlrpcvals of type struct.
3133
-		* @param string $m the name of the struct member to be looked up
3134
-		* @return boolean
3135
-		* @access public
3136
-		*/
3137
-		function structmemexists($m)
3138
-		{
3139
-			return array_key_exists($m, $this->me['struct']);
3140
-		}
3141
-
3142
-		/**
3143
-		* Returns the value of a given struct member (an xmlrpcval object in itself).
3144
-		* Will raise a php warning if struct member of given name does not exist
3145
-		* @param string $m the name of the struct member to be looked up
3146
-		* @return xmlrpcval
3147
-		* @access public
3148
-		*/
3149
-		function structmem($m)
3150
-		{
3151
-			return $this->me['struct'][$m];
3152
-		}
3153
-
3154
-		/**
3155
-		* Reset internal pointer for xmlrpcvals of type struct.
3156
-		* @access public
3157
-		*/
3158
-		function structreset()
3159
-		{
3160
-			reset($this->me['struct']);
3161
-		}
3162
-
3163
-		/**
3164
-		* Return next member element for xmlrpcvals of type struct.
3165
-		* @return xmlrpcval
3166
-		* @access public
3167
-		*/
3168
-		function structeach()
3169
-		{
3170
-			return each($this->me['struct']);
3171
-		}
3172
-
3173
-		// DEPRECATED! this code looks like it is very fragile and has not been fixed
3174
-		// for a long long time. Shall we remove it for 2.0?
3175
-		function getval()
3176
-		{
3177
-			// UNSTABLE
3178
-			reset($this->me);
3179
-			list($a,$b)=each($this->me);
3180
-			// contributed by I Sofer, 2001-03-24
3181
-			// add support for nested arrays to scalarval
3182
-			// i've created a new method here, so as to
3183
-			// preserve back compatibility
3184
-
3185
-			if(is_array($b))
3186
-			{
3187
-				@reset($b);
3188
-				while(list($id,$cont) = @each($b))
3189
-				{
3190
-					$b[$id] = $cont->scalarval();
3191
-				}
3192
-			}
3193
-
3194
-			// add support for structures directly encoding php objects
3195
-			if(is_object($b))
3196
-			{
3197
-				$t = get_object_vars($b);
3198
-				@reset($t);
3199
-				while(list($id,$cont) = @each($t))
3200
-				{
3201
-					$t[$id] = $cont->scalarval();
3202
-				}
3203
-				@reset($t);
3204
-				while(list($id,$cont) = @each($t))
3205
-				{
3206
-					@$b->$id = $cont;
3207
-				}
3208
-			}
3209
-			// end contrib
3210
-			return $b;
3211
-		}
3212
-
3213
-		/**
3214
-		* Returns the value of a scalar xmlrpcval
3215
-		* @return mixed
3216
-		* @access public
3217
-		*/
3218
-		function scalarval()
3219
-		{
3220
-			reset($this->me);
3221
-			list(,$b)=each($this->me);
3222
-			return $b;
3223
-		}
3224
-
3225
-		/**
3226
-		* Returns the type of the xmlrpcval.
3227
-		* For integers, 'int' is always returned in place of 'i4'
3228
-		* @return string
3229
-		* @access public
3230
-		*/
3231
-		function scalartyp()
3232
-		{
3233
-			reset($this->me);
3234
-			list($a,)=each($this->me);
3235
-			if($a==$GLOBALS['xmlrpcI4'])
3236
-			{
3237
-				$a=$GLOBALS['xmlrpcInt'];
3238
-			}
3239
-			return $a;
3240
-		}
3241
-
3242
-		/**
3243
-		* Returns the m-th member of an xmlrpcval of struct type
3244
-		* @param integer $m the index of the value to be retrieved (zero based)
3245
-		* @return xmlrpcval
3246
-		* @access public
3247
-		*/
3248
-		function arraymem($m)
3249
-		{
3250
-			return $this->me['array'][$m];
3251
-		}
3252
-
3253
-		/**
3254
-		* Returns the number of members in an xmlrpcval of array type
3255
-		* @return integer
3256
-		* @access public
3257
-		*/
3258
-		function arraysize()
3259
-		{
3260
-			return count($this->me['array']);
3261
-		}
3262
-
3263
-		/**
3264
-		* Returns the number of members in an xmlrpcval of struct type
3265
-		* @return integer
3266
-		* @access public
3267
-		*/
3268
-		function structsize()
3269
-		{
3270
-			return count($this->me['struct']);
3271
-		}
3272
-	}
3273
-
3274
-
3275
-	// date helpers
3276
-
3277
-	/**
3278
-	* Given a timestamp, return the corresponding ISO8601 encoded string.
3279
-	*
3280
-	* Really, timezones ought to be supported
3281
-	* but the XML-RPC spec says:
3282
-	*
3283
-	* "Don't assume a timezone. It should be specified by the server in its
3284
-	* documentation what assumptions it makes about timezones."
3285
-	*
3286
-	* These routines always assume localtime unless
3287
-	* $utc is set to 1, in which case UTC is assumed
3288
-	* and an adjustment for locale is made when encoding
3289
-	*
3290
-	* @param int $timet (timestamp)
3291
-	* @param int $utc (0 or 1)
3292
-	* @return string
3293
-	*/
3294
-	function iso8601_encode($timet, $utc=0)
3295
-	{
3296
-		if(!$utc)
3297
-		{
3298
-			$t=strftime("%Y%m%dT%H:%M:%S", $timet);
3299
-		}
3300
-		else
3301
-		{
3302
-			if(function_exists('gmstrftime'))
3303
-			{
3304
-				// gmstrftime doesn't exist in some versions
3305
-				// of PHP
3306
-				$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
3307
-			}
3308
-			else
3309
-			{
3310
-				$t=strftime("%Y%m%dT%H:%M:%S", $timet-date('Z'));
3311
-			}
3312
-		}
3313
-		return $t;
3314
-	}
3315
-
3316
-	/**
3317
-	* Given an ISO8601 date string, return a timet in the localtime, or UTC
3318
-	* @param string $idate
3319
-	* @param int $utc either 0 or 1
3320
-	* @return int (datetime)
3321
-	*/
3322
-	function iso8601_decode($idate, $utc=0)
3323
-	{
3324
-		$t=0;
3325
-		if(preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $idate, $regs))
3326
-		{
3327
-			if($utc)
3328
-			{
3329
-				$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3330
-			}
3331
-			else
3332
-			{
3333
-				$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3334
-			}
3335
-		}
3336
-		return $t;
3337
-	}
3338
-
3339
-	/**
3340
-	* Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types.
3341
-	*
3342
-	* Works with xmlrpc message objects as input, too.
3343
-	*
3344
-	* Given proper options parameter, can rebuild generic php object instances
3345
-	* (provided those have been encoded to xmlrpc format using a corresponding
3346
-	* option in php_xmlrpc_encode())
3347
-	* PLEASE NOTE that rebuilding php objects involves calling their constructor function.
3348
-	* This means that the remote communication end can decide which php code will
3349
-	* get executed on your server, leaving the door possibly open to 'php-injection'
3350
-	* style of attacks (provided you have some classes defined on your server that
3351
-	* might wreak havoc if instances are built outside an appropriate context).
3352
-	* Make sure you trust the remote server/client before eanbling this!
3353
-	*
3354
-	* @author Dan Libby ([email protected])
3355
-	*
3356
-	* @param xmlrpcval $xmlrpc_val
3357
-	* @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is
3358
-	* @return mixed
3359
-	*/
3360
-	function php_xmlrpc_decode($xmlrpc_val, $options=array())
3361
-	{
3362
-		switch($xmlrpc_val->kindOf())
3363
-		{
3364
-			case 'scalar':
3365
-				if (in_array('extension_api', $options))
3366
-				{
3367
-					reset($xmlrpc_val->me);
3368
-					list($typ,$val) = each($xmlrpc_val->me);
3369
-					switch ($typ)
3370
-					{
3371
-						case 'dateTime.iso8601':
3372
-							$xmlrpc_val->scalar = $val;
3373
-							$xmlrpc_val->xmlrpc_type = 'datetime';
3374
-							$xmlrpc_val->timestamp = iso8601_decode($val);
3375
-							return $xmlrpc_val;
3376
-						case 'base64':
3377
-							$xmlrpc_val->scalar = $val;
3378
-							$xmlrpc_val->type = $typ;
3379
-							return $xmlrpc_val;
3380
-						default:
3381
-							return $xmlrpc_val->scalarval();
3382
-					}
3383
-				}
3384
-				if (in_array('dates_as_objects', $options) && $xmlrpc_val->scalartyp() == 'dateTime.iso8601')
3385
-				{
3386
-					// we return a Datetime object instead of a string
3387
-					// since now the constructor of xmlrpcval accepts safely strings, ints and datetimes,
3388
-					// we cater to all 3 cases here
3389
-					$out = $xmlrpc_val->scalarval();
3390
-					if (is_string($out))
3391
-					{
3392
-						$out = strtotime($out);
3393
-					}
3394
-					if (is_int($out))
3395
-					{
3396
-						$result = new Datetime();
3397
-						$result->setTimestamp($out);
3398
-						return $result;
3399
-					}
3400
-					elseif (is_a($out, 'Datetime'))
3401
-					{
3402
-						return $out;
3403
-					}
3404
-				}
3405
-				return $xmlrpc_val->scalarval();
3406
-			case 'array':
3407
-				$size = $xmlrpc_val->arraysize();
3408
-				$arr = array();
3409
-				for($i = 0; $i < $size; $i++)
3410
-				{
3411
-					$arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
3412
-				}
3413
-				return $arr;
3414
-			case 'struct':
3415
-				$xmlrpc_val->structreset();
3416
-				// If user said so, try to rebuild php objects for specific struct vals.
3417
-				/// @todo should we raise a warning for class not found?
3418
-				// shall we check for proper subclass of xmlrpcval instead of
3419
-				// presence of _php_class to detect what we can do?
3420
-				if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != ''
3421
-					&& class_exists($xmlrpc_val->_php_class))
3422
-				{
3423
-					$obj = @new $xmlrpc_val->_php_class;
3424
-					while(list($key,$value)=$xmlrpc_val->structeach())
3425
-					{
3426
-						$obj->$key = php_xmlrpc_decode($value, $options);
3427
-					}
3428
-					return $obj;
3429
-				}
3430
-				else
3431
-				{
3432
-					$arr = array();
3433
-					while(list($key,$value)=$xmlrpc_val->structeach())
3434
-					{
3435
-						$arr[$key] = php_xmlrpc_decode($value, $options);
3436
-					}
3437
-					return $arr;
3438
-				}
3439
-			case 'msg':
3440
-				$paramcount = $xmlrpc_val->getNumParams();
3441
-				$arr = array();
3442
-				for($i = 0; $i < $paramcount; $i++)
3443
-				{
3444
-					$arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
3445
-				}
3446
-				return $arr;
3447
-			}
3448
-	}
3449
-
3450
-	// This constant left here only for historical reasons...
3451
-	// it was used to decide if we have to define xmlrpc_encode on our own, but
3452
-	// we do not do it anymore
3453
-	if(function_exists('xmlrpc_decode'))
3454
-	{
3455
-		define('XMLRPC_EPI_ENABLED','1');
3456
-	}
3457
-	else
3458
-	{
3459
-		define('XMLRPC_EPI_ENABLED','0');
3460
-	}
3461
-
3462
-	/**
3463
-	* Takes native php types and encodes them into xmlrpc PHP object format.
3464
-	* It will not re-encode xmlrpcval objects.
3465
-	*
3466
-	* Feature creep -- could support more types via optional type argument
3467
-	* (string => datetime support has been added, ??? => base64 not yet)
3468
-	*
3469
-	* If given a proper options parameter, php object instances will be encoded
3470
-	* into 'special' xmlrpc values, that can later be decoded into php objects
3471
-	* by calling php_xmlrpc_decode() with a corresponding option
3472
-	*
3473
-	* @author Dan Libby ([email protected])
3474
-	*
3475
-	* @param mixed $php_val the value to be converted into an xmlrpcval object
3476
-	* @param array $options	can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api'
3477
-	* @return xmlrpcval
3478
-	*/
3479
-	function php_xmlrpc_encode($php_val, $options=array())
3480
-	{
3481
-		$type = gettype($php_val);
3482
-		switch($type)
3483
-		{
3484
-			case 'string':
3485
-				if (in_array('auto_dates', $options) && preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $php_val))
3486
-					$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcDateTime']);
3487
-				else
3488
-					$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcString']);
3489
-				break;
3490
-			case 'integer':
3491
-				$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcInt']);
3492
-				break;
3493
-			case 'double':
3494
-				$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcDouble']);
3495
-				break;
3496
-				// <G_Giunta_2001-02-29>
3497
-				// Add support for encoding/decoding of booleans, since they are supported in PHP
3498
-			case 'boolean':
3499
-				$xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcBoolean']);
3500
-				break;
3501
-				// </G_Giunta_2001-02-29>
3502
-			case 'array':
3503
-				// PHP arrays can be encoded to either xmlrpc structs or arrays,
3504
-				// depending on wheter they are hashes or plain 0..n integer indexed
3505
-				// A shorter one-liner would be
3506
-				// $tmp = array_diff(array_keys($php_val), range(0, count($php_val)-1));
3507
-				// but execution time skyrockets!
3508
-				$j = 0;
3509
-				$arr = array();
3510
-				$ko = false;
3511
-				foreach($php_val as $key => $val)
3512
-				{
3513
-					$arr[$key] = php_xmlrpc_encode($val, $options);
3514
-					if(!$ko && $key !== $j)
3515
-					{
3516
-						$ko = true;
3517
-					}
3518
-					$j++;
3519
-				}
3520
-				if($ko)
3521
-				{
3522
-					$xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcStruct']);
3523
-				}
3524
-				else
3525
-				{
3526
-					$xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcArray']);
3527
-				}
3528
-				break;
3529
-			case 'object':
3530
-				if(is_a($php_val, 'xmlrpcval'))
3531
-				{
3532
-					$xmlrpc_val = $php_val;
3533
-				}
3534
-				else if(is_a($php_val, 'DateTime'))
3535
-				{
3536
-					$xmlrpc_val = new xmlrpcval($php_val->format('Ymd\TH:i:s'), $GLOBALS['xmlrpcStruct']);
3537
-				}
3538
-				else
3539
-				{
3540
-					$arr = array();
3541
-					reset($php_val);
3542
-					while(list($k,$v) = each($php_val))
3543
-					{
3544
-						$arr[$k] = php_xmlrpc_encode($v, $options);
3545
-					}
3546
-					$xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcStruct']);
3547
-					if (in_array('encode_php_objs', $options))
3548
-					{
3549
-						// let's save original class name into xmlrpcval:
3550
-						// might be useful later on...
3551
-						$xmlrpc_val->_php_class = get_class($php_val);
3552
-					}
3553
-				}
3554
-				break;
3555
-			case 'NULL':
3556
-				if (in_array('extension_api', $options))
3557
-				{
3558
-					$xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcString']);
3559
-				}
3560
-				else if (in_array('null_extension', $options))
3561
-				{
3562
-					$xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcNull']);
3563
-				}
3564
-				else
3565
-				{
3566
-					$xmlrpc_val = new xmlrpcval();
3567
-				}
3568
-				break;
3569
-			case 'resource':
3570
-				if (in_array('extension_api', $options))
3571
-				{
3572
-					$xmlrpc_val = new xmlrpcval((int)$php_val, $GLOBALS['xmlrpcInt']);
3573
-				}
3574
-				else
3575
-				{
3576
-					$xmlrpc_val = new xmlrpcval();
3577
-				}
3578
-			// catch "user function", "unknown type"
3579
-			default:
3580
-				// giancarlo pinerolo <[email protected]>
3581
-				// it has to return
3582
-				// an empty object in case, not a boolean.
3583
-				$xmlrpc_val = new xmlrpcval();
3584
-				break;
3585
-			}
3586
-			return $xmlrpc_val;
3587
-	}
3588
-
3589
-	/**
3590
-	* Convert the xml representation of a method response, method request or single
3591
-	* xmlrpc value into the appropriate object (a.k.a. deserialize)
3592
-	* @param string $xml_val
3593
-	* @param array $options
3594
-	* @return mixed false on error, or an instance of either xmlrpcval, xmlrpcmsg or xmlrpcresp
3595
-	*/
3596
-	function php_xmlrpc_decode_xml($xml_val, $options=array())
3597
-	{
3598
-		$GLOBALS['_xh'] = array();
3599
-		$GLOBALS['_xh']['ac'] = '';
3600
-		$GLOBALS['_xh']['stack'] = array();
3601
-		$GLOBALS['_xh']['valuestack'] = array();
3602
-		$GLOBALS['_xh']['params'] = array();
3603
-		$GLOBALS['_xh']['pt'] = array();
3604
-		$GLOBALS['_xh']['isf'] = 0;
3605
-		$GLOBALS['_xh']['isf_reason'] = '';
3606
-		$GLOBALS['_xh']['method'] = false;
3607
-		$GLOBALS['_xh']['rt'] = '';
3608
-
3609
-		// 'guestimate' encoding
3610
-		$val_encoding = guess_encoding('', $xml_val);
3611
-
3612
-		// Since parsing will fail if charset is not specified in the xml prologue,
3613
-		// the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
3614
-		// The following code might be better for mb_string enabled installs, but
3615
-		// makes the lib about 200% slower...
3616
-		//if (!is_valid_charset($val_encoding, array('UTF-8')))
3617
-		if (!in_array($val_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($xml_val)) {
3618
-			if ($val_encoding == 'ISO-8859-1') {
3619
-				$xml_val = utf8_encode($xml_val);
3620
-			} else {
3621
-				if (extension_loaded('mbstring')) {
3622
-					$xml_val = mb_convert_encoding($xml_val, 'UTF-8', $val_encoding);
3623
-				} else {
3624
-					error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $val_encoding);
3625
-				}
3626
-			}
3627
-		}
3628
-
3629
-		$parser = xml_parser_create();
3630
-		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
3631
-		// What if internal encoding is not in one of the 3 allowed?
3632
-		// we use the broadest one, ie. utf8!
3633
-		if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
3634
-		{
3635
-			xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
3636
-		}
3637
-		else
3638
-		{
3639
-			xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
3640
-		}
3641
-		xml_set_element_handler($parser, 'xmlrpc_se_any', 'xmlrpc_ee');
3642
-		xml_set_character_data_handler($parser, 'xmlrpc_cd');
3643
-		xml_set_default_handler($parser, 'xmlrpc_dh');
3644
-		if(!xml_parse($parser, $xml_val, 1))
3645
-		{
3646
-			$errstr = sprintf('XML error: %s at line %d, column %d',
3647
-						xml_error_string(xml_get_error_code($parser)),
3648
-						xml_get_current_line_number($parser), xml_get_current_column_number($parser));
3649
-			error_log($errstr);
3650
-			xml_parser_free($parser);
3651
-			return false;
3652
-		}
3653
-		xml_parser_free($parser);
3654
-		if ($GLOBALS['_xh']['isf'] > 1) // test that $GLOBALS['_xh']['value'] is an obj, too???
3655
-		{
3656
-			error_log($GLOBALS['_xh']['isf_reason']);
3657
-			return false;
3658
-		}
3659
-		switch ($GLOBALS['_xh']['rt'])
3660
-		{
3661
-			case 'methodresponse':
3662
-				$v =& $GLOBALS['_xh']['value'];
3663
-				if ($GLOBALS['_xh']['isf'] == 1)
3664
-				{
3665
-					$vc = $v->structmem('faultCode');
3666
-					$vs = $v->structmem('faultString');
3667
-					$r = new xmlrpcresp(0, $vc->scalarval(), $vs->scalarval());
3668
-				}
3669
-				else
3670
-				{
3671
-					$r = new xmlrpcresp($v);
3672
-				}
3673
-				return $r;
3674
-			case 'methodcall':
3675
-				$m = new xmlrpcmsg($GLOBALS['_xh']['method']);
3676
-				for($i=0; $i < count($GLOBALS['_xh']['params']); $i++)
3677
-				{
3678
-					$m->addParam($GLOBALS['_xh']['params'][$i]);
3679
-				}
3680
-				return $m;
3681
-			case 'value':
3682
-				return $GLOBALS['_xh']['value'];
3683
-			default:
3684
-				return false;
3685
-		}
3686
-	}
3687
-
3688
-	/**
3689
-	* decode a string that is encoded w/ "chunked" transfer encoding
3690
-	* as defined in rfc2068 par. 19.4.6
3691
-	* code shamelessly stolen from nusoap library by Dietrich Ayala
3692
-	*
3693
-	* @param string $buffer the string to be decoded
3694
-	* @return string
3695
-	*/
3696
-	function decode_chunked($buffer)
3697
-	{
3698
-		// length := 0
3699
-		$length = 0;
3700
-		$new = '';
3701
-
3702
-		// read chunk-size, chunk-extension (if any) and crlf
3703
-		// get the position of the linebreak
3704
-		$chunkend = strpos($buffer,"\r\n") + 2;
3705
-		$temp = substr($buffer,0,$chunkend);
3706
-		$chunk_size = hexdec( trim($temp) );
3707
-		$chunkstart = $chunkend;
3708
-		while($chunk_size > 0)
3709
-		{
3710
-			$chunkend = strpos($buffer, "\r\n", $chunkstart + $chunk_size);
3711
-
3712
-			// just in case we got a broken connection
3713
-			if($chunkend == false)
3714
-			{
3715
-				$chunk = substr($buffer,$chunkstart);
3716
-				// append chunk-data to entity-body
3717
-				$new .= $chunk;
3718
-				$length += strlen($chunk);
3719
-				break;
3720
-			}
3721
-
3722
-			// read chunk-data and crlf
3723
-			$chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
3724
-			// append chunk-data to entity-body
3725
-			$new .= $chunk;
3726
-			// length := length + chunk-size
3727
-			$length += strlen($chunk);
3728
-			// read chunk-size and crlf
3729
-			$chunkstart = $chunkend + 2;
3730
-
3731
-			$chunkend = strpos($buffer,"\r\n",$chunkstart)+2;
3732
-			if($chunkend == false)
3733
-			{
3734
-				break; //just in case we got a broken connection
3735
-			}
3736
-			$temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
3737
-			$chunk_size = hexdec( trim($temp) );
3738
-			$chunkstart = $chunkend;
3739
-		}
3740
-		return $new;
3741
-	}
3742
-
3743
-	/**
3744
-	* xml charset encoding guessing helper function.
3745
-	* Tries to determine the charset encoding of an XML chunk received over HTTP.
3746
-	* NB: according to the spec (RFC 3023), if text/xml content-type is received over HTTP without a content-type,
3747
-	* we SHOULD assume it is strictly US-ASCII. But we try to be more tolerant of unconforming (legacy?) clients/servers,
3748
-	* which will be most probably using UTF-8 anyway...
3749
-	*
3750
-	* @param string $httpheader the http Content-type header
3751
-	* @param string $xmlchunk xml content buffer
3752
-	* @param string $encoding_prefs comma separated list of character encodings to be used as default (when mb extension is enabled)
3753
-	* @return string
3754
-	*
3755
-	* @todo explore usage of mb_http_input(): does it detect http headers + post data? if so, use it instead of hand-detection!!!
3756
-	*/
3757
-	function guess_encoding($httpheader='', $xmlchunk='', $encoding_prefs=null)
3758
-	{
3759
-		// discussion: see http://www.yale.edu/pclt/encoding/
3760
-		// 1 - test if encoding is specified in HTTP HEADERS
3761
-
3762
-		//Details:
3763
-		// LWS:           (\13\10)?( |\t)+
3764
-		// token:         (any char but excluded stuff)+
3765
-		// quoted string: " (any char but double quotes and cointrol chars)* "
3766
-		// header:        Content-type = ...; charset=value(; ...)*
3767
-		//   where value is of type token, no LWS allowed between 'charset' and value
3768
-		// Note: we do not check for invalid chars in VALUE:
3769
-		//   this had better be done using pure ereg as below
3770
-		// Note 2: we might be removing whitespace/tabs that ought to be left in if
3771
-		//   the received charset is a quoted string. But nobody uses such charset names...
3772
-
3773
-		/// @todo this test will pass if ANY header has charset specification, not only Content-Type. Fix it?
3774
-		$matches = array();
3775
-		if(preg_match('/;\s*charset\s*=([^;]+)/i', $httpheader, $matches))
3776
-		{
3777
-			return strtoupper(trim($matches[1], " \t\""));
3778
-		}
3779
-
3780
-		// 2 - scan the first bytes of the data for a UTF-16 (or other) BOM pattern
3781
-		//     (source: http://www.w3.org/TR/2000/REC-xml-20001006)
3782
-		//     NOTE: actually, according to the spec, even if we find the BOM and determine
3783
-		//     an encoding, we should check if there is an encoding specified
3784
-		//     in the xml declaration, and verify if they match.
3785
-		/// @todo implement check as described above?
3786
-		/// @todo implement check for first bytes of string even without a BOM? (It sure looks harder than for cases WITH a BOM)
3787
-		if(preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlchunk))
3788
-		{
3789
-			return 'UCS-4';
3790
-		}
3791
-		elseif(preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlchunk))
3792
-		{
3793
-			return 'UTF-16';
3794
-		}
3795
-		elseif(preg_match('/^(\xEF\xBB\xBF)/', $xmlchunk))
3796
-		{
3797
-			return 'UTF-8';
3798
-		}
3799
-
3800
-		// 3 - test if encoding is specified in the xml declaration
3801
-		// Details:
3802
-		// SPACE:         (#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
3803
-		// EQ:            SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
3804
-		if (preg_match('/^<\?xml\s+version\s*=\s*'. "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))".
3805
-			'\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
3806
-			$xmlchunk, $matches))
3807
-		{
3808
-			return strtoupper(substr($matches[2], 1, -1));
3809
-		}
3810
-
3811
-		// 4 - if mbstring is available, let it do the guesswork
3812
-		// NB: we favour finding an encoding that is compatible with what we can process
3813
-		if(extension_loaded('mbstring'))
3814
-		{
3815
-			if($encoding_prefs)
3816
-			{
3817
-				$enc = mb_detect_encoding($xmlchunk, $encoding_prefs);
3818
-			}
3819
-			else
3820
-			{
3821
-				$enc = mb_detect_encoding($xmlchunk);
3822
-			}
3823
-			// NB: mb_detect likes to call it ascii, xml parser likes to call it US_ASCII...
3824
-			// IANA also likes better US-ASCII, so go with it
3825
-			if($enc == 'ASCII')
3826
-			{
3827
-				$enc = 'US-'.$enc;
3828
-			}
3829
-			return $enc;
3830
-		}
3831
-		else
3832
-		{
3833
-			// no encoding specified: as per HTTP1.1 assume it is iso-8859-1?
3834
-			// Both RFC 2616 (HTTP 1.1) and 1945 (HTTP 1.0) clearly state that for text/xxx content types
3835
-			// this should be the standard. And we should be getting text/xml as request and response.
3836
-			// BUT we have to be backward compatible with the lib, which always used UTF-8 as default...
3837
-			return $GLOBALS['xmlrpc_defencoding'];
3838
-		}
3839
-	}
3840
-
3841
-	/**
3842
-	 * Helper function: checks if an xml chunk as a charset declaration (BOM or in the xml declaration)
3843
-	 *
3844
-	 * @param string $xmlChunk
3845
-	 * @return bool
3846
-	 */
3847
-	function has_encoding($xmlChunk)
3848
-	{
3849
-		// scan the first bytes of the data for a UTF-16 (or other) BOM pattern
3850
-		//	 (source: http://www.w3.org/TR/2000/REC-xml-20001006)
3851
-		if (preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlChunk))
3852
-		{
3853
-			return true;
3854
-		}
3855
-		elseif (preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlChunk))
3856
-		{
3857
-			return true;
3858
-		}
3859
-		elseif (preg_match('/^(\xEF\xBB\xBF)/', $xmlChunk))
3860
-		{
3861
-			return true;
3862
-		}
3863
-
3864
-		// test if encoding is specified in the xml declaration
3865
-		// Details:
3866
-		// SPACE:		(#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
3867
-		// EQ:			SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
3868
-		if (preg_match('/^<\?xml\s+version\s*=\s*' . "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))" .
3869
-			'\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
3870
-			$xmlChunk, $matches))
3871
-		{
3872
-			return true;
3873
-		}
3874
-
3875
-		return false;
3876
-	}
3877
-
3878
-	/**
3879
-	* Checks if a given charset encoding is present in a list of encodings or
3880
-	* if it is a valid subset of any encoding in the list
3881
-	* @param string $encoding charset to be tested
3882
-	* @param mixed $validlist comma separated list of valid charsets (or array of charsets)
3883
-	* @return bool
3884
-	*/
3885
-	function is_valid_charset($encoding, $validlist)
3886
-	{
3887
-		$charset_supersets = array(
3888
-			'US-ASCII' => array ('ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4',
3889
-				'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8',
3890
-				'ISO-8859-9', 'ISO-8859-10', 'ISO-8859-11', 'ISO-8859-12',
3891
-				'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'UTF-8',
3892
-				'EUC-JP', 'EUC-', 'EUC-KR', 'EUC-CN')
3893
-		);
3894
-		if (is_string($validlist))
3895
-			$validlist = explode(',', $validlist);
3896
-		if (@in_array(strtoupper($encoding), $validlist))
3897
-			return true;
3898
-		else
3899
-		{
3900
-			if (array_key_exists($encoding, $charset_supersets))
3901
-				foreach ($validlist as $allowed)
3902
-					if (in_array($allowed, $charset_supersets[$encoding]))
3903
-						return true;
3904
-			return false;
3905
-		}
3906
-	}
2833
+            }
2834
+        }
2835
+
2836
+        /**
2837
+         * @deprecated
2838
+         */
2839
+        function xmlrpcval($val=-1, $type='')
2840
+        {
2841
+            self::__construct($val, $type);
2842
+        }
2843
+
2844
+        /**
2845
+         * Add a single php value to an (unitialized) xmlrpcval
2846
+         * @param mixed $val
2847
+         * @param string $type
2848
+         * @return int 1 or 0 on failure
2849
+         */
2850
+        function addScalar($val, $type='string')
2851
+        {
2852
+            $typeof=@$GLOBALS['xmlrpcTypes'][$type];
2853
+            if($typeof!=1)
2854
+            {
2855
+                error_log("XML-RPC: ".__METHOD__.": not a scalar type ($type)");
2856
+                return 0;
2857
+            }
2858
+
2859
+            // coerce booleans into correct values
2860
+            // NB: we should either do it for datetimes, integers and doubles, too,
2861
+            // or just plain remove this check, implemented on booleans only...
2862
+            if($type==$GLOBALS['xmlrpcBoolean'])
2863
+            {
2864
+                if(strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false')))
2865
+                {
2866
+                    $val=true;
2867
+                }
2868
+                else
2869
+                {
2870
+                    $val=false;
2871
+                }
2872
+            }
2873
+
2874
+            switch($this->mytype)
2875
+            {
2876
+                case 1:
2877
+                    error_log('XML-RPC: '.__METHOD__.': scalar xmlrpcval can have only one value');
2878
+                    return 0;
2879
+                case 3:
2880
+                    error_log('XML-RPC: '.__METHOD__.': cannot add anonymous scalar to struct xmlrpcval');
2881
+                    return 0;
2882
+                case 2:
2883
+                    // we're adding a scalar value to an array here
2884
+                    //$ar=$this->me['array'];
2885
+                    //$ar[]=new xmlrpcval($val, $type);
2886
+                    //$this->me['array']=$ar;
2887
+                    // Faster (?) avoid all the costly array-copy-by-val done here...
2888
+                    $this->me['array'][]=new xmlrpcval($val, $type);
2889
+                    return 1;
2890
+                default:
2891
+                    // a scalar, so set the value and remember we're scalar
2892
+                    $this->me[$type]=$val;
2893
+                    $this->mytype=$typeof;
2894
+                    return 1;
2895
+            }
2896
+        }
2897
+
2898
+        /**
2899
+         * Add an array of xmlrpcval objects to an xmlrpcval
2900
+         * @param array $vals
2901
+         * @return int 1 or 0 on failure
2902
+         * @access public
2903
+         *
2904
+         * @todo add some checking for $vals to be an array of xmlrpcvals?
2905
+         */
2906
+        function addArray($vals)
2907
+        {
2908
+            if($this->mytype==0)
2909
+            {
2910
+                $this->mytype=$GLOBALS['xmlrpcTypes']['array'];
2911
+                $this->me['array']=$vals;
2912
+                return 1;
2913
+            }
2914
+            elseif($this->mytype==2)
2915
+            {
2916
+                // we're adding to an array here
2917
+                $this->me['array'] = array_merge($this->me['array'], $vals);
2918
+                return 1;
2919
+            }
2920
+            else
2921
+            {
2922
+                error_log('XML-RPC: '.__METHOD__.': already initialized as a [' . $this->kindOf() . ']');
2923
+                return 0;
2924
+            }
2925
+        }
2926
+
2927
+        /**
2928
+         * Add an array of named xmlrpcval objects to an xmlrpcval
2929
+         * @param array $vals
2930
+         * @return int 1 or 0 on failure
2931
+         * @access public
2932
+         *
2933
+         * @todo add some checking for $vals to be an array?
2934
+         */
2935
+        function addStruct($vals)
2936
+        {
2937
+            if($this->mytype==0)
2938
+            {
2939
+                $this->mytype=$GLOBALS['xmlrpcTypes']['struct'];
2940
+                $this->me['struct']=$vals;
2941
+                return 1;
2942
+            }
2943
+            elseif($this->mytype==3)
2944
+            {
2945
+                // we're adding to a struct here
2946
+                $this->me['struct'] = array_merge($this->me['struct'], $vals);
2947
+                return 1;
2948
+            }
2949
+            else
2950
+            {
2951
+                error_log('XML-RPC: '.__METHOD__.': already initialized as a [' . $this->kindOf() . ']');
2952
+                return 0;
2953
+            }
2954
+        }
2955
+
2956
+        // poor man's version of print_r ???
2957
+        // DEPRECATED!
2958
+        function dump($ar)
2959
+        {
2960
+            foreach($ar as $key => $val)
2961
+            {
2962
+                echo "$key => $val<br />";
2963
+                if($key == 'array')
2964
+                {
2965
+                    while(list($key2, $val2) = each($val))
2966
+                    {
2967
+                        echo "-- $key2 => $val2<br />";
2968
+                    }
2969
+                }
2970
+            }
2971
+        }
2972
+
2973
+        /**
2974
+         * Returns a string containing "struct", "array" or "scalar" describing the base type of the value
2975
+         * @return string
2976
+         * @access public
2977
+         */
2978
+        function kindOf()
2979
+        {
2980
+            switch($this->mytype)
2981
+            {
2982
+                case 3:
2983
+                    return 'struct';
2984
+                    break;
2985
+                case 2:
2986
+                    return 'array';
2987
+                    break;
2988
+                case 1:
2989
+                    return 'scalar';
2990
+                    break;
2991
+                default:
2992
+                    return 'undef';
2993
+            }
2994
+        }
2995
+
2996
+        /**
2997
+         * @access private
2998
+         */
2999
+        function serializedata($typ, $val, $charset_encoding='')
3000
+        {
3001
+            $rs='';
3002
+            switch(@$GLOBALS['xmlrpcTypes'][$typ])
3003
+            {
3004
+                case 1:
3005
+                    switch($typ)
3006
+                    {
3007
+                        case $GLOBALS['xmlrpcBase64']:
3008
+                            $rs.="<${typ}>" . base64_encode($val) . "</${typ}>";
3009
+                            break;
3010
+                        case $GLOBALS['xmlrpcBoolean']:
3011
+                            $rs.="<${typ}>" . ($val ? '1' : '0') . "</${typ}>";
3012
+                            break;
3013
+                        case $GLOBALS['xmlrpcString']:
3014
+                            // G. Giunta 2005/2/13: do NOT use htmlentities, since
3015
+                            // it will produce named html entities, which are invalid xml
3016
+                            $rs.="<${typ}>" . xmlrpc_encode_entitites($val, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding). "</${typ}>";
3017
+                            break;
3018
+                        case $GLOBALS['xmlrpcInt']:
3019
+                        case $GLOBALS['xmlrpcI4']:
3020
+                            $rs.="<${typ}>".(int)$val."</${typ}>";
3021
+                            break;
3022
+                        case $GLOBALS['xmlrpcDouble']:
3023
+                            // avoid using standard conversion of float to string because it is locale-dependent,
3024
+                            // and also because the xmlrpc spec forbids exponential notation.
3025
+                            // sprintf('%F') could be most likely ok but it fails eg. on 2e-14.
3026
+                            // The code below tries its best at keeping max precision while avoiding exp notation,
3027
+                            // but there is of course no limit in the number of decimal places to be used...
3028
+                            $rs.="<${typ}>".preg_replace('/\\.?0+$/','',number_format((double)$val, 128, '.', ''))."</${typ}>";
3029
+                            break;
3030
+                        case $GLOBALS['xmlrpcDateTime']:
3031
+                            if (is_string($val))
3032
+                            {
3033
+                                $rs.="<${typ}>${val}</${typ}>";
3034
+                            }
3035
+                            else if(is_a($val, 'DateTime'))
3036
+                            {
3037
+                                $rs.="<${typ}>".$val->format('Ymd\TH:i:s')."</${typ}>";
3038
+                            }
3039
+                            else if(is_int($val))
3040
+                            {
3041
+                                $rs.="<${typ}>".strftime("%Y%m%dT%H:%M:%S", $val)."</${typ}>";
3042
+                            }
3043
+                            else
3044
+                            {
3045
+                                // not really a good idea here: but what shall we output anyway? left for backward compat...
3046
+                                $rs.="<${typ}>${val}</${typ}>";
3047
+                            }
3048
+                            break;
3049
+                        case $GLOBALS['xmlrpcNull']:
3050
+                            if ($GLOBALS['xmlrpc_null_apache_encoding'])
3051
+                            {
3052
+                                $rs.="<ex:nil/>";
3053
+                            }
3054
+                            else
3055
+                            {
3056
+                                $rs.="<nil/>";
3057
+                            }
3058
+                            break;
3059
+                        default:
3060
+                            // no standard type value should arrive here, but provide a possibility
3061
+                            // for xmlrpcvals of unknown type...
3062
+                            $rs.="<${typ}>${val}</${typ}>";
3063
+                    }
3064
+                    break;
3065
+                case 3:
3066
+                    // struct
3067
+                    if ($this->_php_class)
3068
+                    {
3069
+                        $rs.='<struct php_class="' . $this->_php_class . "\">\n";
3070
+                    }
3071
+                    else
3072
+                    {
3073
+                        $rs.="<struct>\n";
3074
+                    }
3075
+                    foreach($val as $key2 => $val2)
3076
+                    {
3077
+                        $rs.='<member><name>'.xmlrpc_encode_entitites($key2, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding)."</name>\n";
3078
+                        //$rs.=$this->serializeval($val2);
3079
+                        $rs.=$val2->serialize($charset_encoding);
3080
+                        $rs.="</member>\n";
3081
+                    }
3082
+                    $rs.='</struct>';
3083
+                    break;
3084
+                case 2:
3085
+                    // array
3086
+                    $rs.="<array>\n<data>\n";
3087
+                    for($i=0; $i<count($val); $i++)
3088
+                    {
3089
+                        //$rs.=$this->serializeval($val[$i]);
3090
+                        $rs.=$val[$i]->serialize($charset_encoding);
3091
+                    }
3092
+                    $rs.="</data>\n</array>";
3093
+                    break;
3094
+                default:
3095
+                    break;
3096
+            }
3097
+            return $rs;
3098
+        }
3099
+
3100
+        /**
3101
+         * Returns xml representation of the value. XML prologue not included
3102
+         * @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed
3103
+         * @return string
3104
+         * @access public
3105
+         */
3106
+        function serialize($charset_encoding='')
3107
+        {
3108
+            // add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
3109
+            //if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
3110
+            //{
3111
+                reset($this->me);
3112
+                list($typ, $val) = each($this->me);
3113
+                return '<value>' . $this->serializedata($typ, $val, $charset_encoding) . "</value>\n";
3114
+            //}
3115
+        }
3116
+
3117
+        // DEPRECATED
3118
+        function serializeval($o)
3119
+        {
3120
+            // add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
3121
+            //if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
3122
+            //{
3123
+                $ar=$o->me;
3124
+                reset($ar);
3125
+                list($typ, $val) = each($ar);
3126
+                return '<value>' . $this->serializedata($typ, $val) . "</value>\n";
3127
+            //}
3128
+        }
3129
+
3130
+        /**
3131
+         * Checks whether a struct member with a given name is present.
3132
+         * Works only on xmlrpcvals of type struct.
3133
+         * @param string $m the name of the struct member to be looked up
3134
+         * @return boolean
3135
+         * @access public
3136
+         */
3137
+        function structmemexists($m)
3138
+        {
3139
+            return array_key_exists($m, $this->me['struct']);
3140
+        }
3141
+
3142
+        /**
3143
+         * Returns the value of a given struct member (an xmlrpcval object in itself).
3144
+         * Will raise a php warning if struct member of given name does not exist
3145
+         * @param string $m the name of the struct member to be looked up
3146
+         * @return xmlrpcval
3147
+         * @access public
3148
+         */
3149
+        function structmem($m)
3150
+        {
3151
+            return $this->me['struct'][$m];
3152
+        }
3153
+
3154
+        /**
3155
+         * Reset internal pointer for xmlrpcvals of type struct.
3156
+         * @access public
3157
+         */
3158
+        function structreset()
3159
+        {
3160
+            reset($this->me['struct']);
3161
+        }
3162
+
3163
+        /**
3164
+         * Return next member element for xmlrpcvals of type struct.
3165
+         * @return xmlrpcval
3166
+         * @access public
3167
+         */
3168
+        function structeach()
3169
+        {
3170
+            return each($this->me['struct']);
3171
+        }
3172
+
3173
+        // DEPRECATED! this code looks like it is very fragile and has not been fixed
3174
+        // for a long long time. Shall we remove it for 2.0?
3175
+        function getval()
3176
+        {
3177
+            // UNSTABLE
3178
+            reset($this->me);
3179
+            list($a,$b)=each($this->me);
3180
+            // contributed by I Sofer, 2001-03-24
3181
+            // add support for nested arrays to scalarval
3182
+            // i've created a new method here, so as to
3183
+            // preserve back compatibility
3184
+
3185
+            if(is_array($b))
3186
+            {
3187
+                @reset($b);
3188
+                while(list($id,$cont) = @each($b))
3189
+                {
3190
+                    $b[$id] = $cont->scalarval();
3191
+                }
3192
+            }
3193
+
3194
+            // add support for structures directly encoding php objects
3195
+            if(is_object($b))
3196
+            {
3197
+                $t = get_object_vars($b);
3198
+                @reset($t);
3199
+                while(list($id,$cont) = @each($t))
3200
+                {
3201
+                    $t[$id] = $cont->scalarval();
3202
+                }
3203
+                @reset($t);
3204
+                while(list($id,$cont) = @each($t))
3205
+                {
3206
+                    @$b->$id = $cont;
3207
+                }
3208
+            }
3209
+            // end contrib
3210
+            return $b;
3211
+        }
3212
+
3213
+        /**
3214
+         * Returns the value of a scalar xmlrpcval
3215
+         * @return mixed
3216
+         * @access public
3217
+         */
3218
+        function scalarval()
3219
+        {
3220
+            reset($this->me);
3221
+            list(,$b)=each($this->me);
3222
+            return $b;
3223
+        }
3224
+
3225
+        /**
3226
+         * Returns the type of the xmlrpcval.
3227
+         * For integers, 'int' is always returned in place of 'i4'
3228
+         * @return string
3229
+         * @access public
3230
+         */
3231
+        function scalartyp()
3232
+        {
3233
+            reset($this->me);
3234
+            list($a,)=each($this->me);
3235
+            if($a==$GLOBALS['xmlrpcI4'])
3236
+            {
3237
+                $a=$GLOBALS['xmlrpcInt'];
3238
+            }
3239
+            return $a;
3240
+        }
3241
+
3242
+        /**
3243
+         * Returns the m-th member of an xmlrpcval of struct type
3244
+         * @param integer $m the index of the value to be retrieved (zero based)
3245
+         * @return xmlrpcval
3246
+         * @access public
3247
+         */
3248
+        function arraymem($m)
3249
+        {
3250
+            return $this->me['array'][$m];
3251
+        }
3252
+
3253
+        /**
3254
+         * Returns the number of members in an xmlrpcval of array type
3255
+         * @return integer
3256
+         * @access public
3257
+         */
3258
+        function arraysize()
3259
+        {
3260
+            return count($this->me['array']);
3261
+        }
3262
+
3263
+        /**
3264
+         * Returns the number of members in an xmlrpcval of struct type
3265
+         * @return integer
3266
+         * @access public
3267
+         */
3268
+        function structsize()
3269
+        {
3270
+            return count($this->me['struct']);
3271
+        }
3272
+    }
3273
+
3274
+
3275
+    // date helpers
3276
+
3277
+    /**
3278
+     * Given a timestamp, return the corresponding ISO8601 encoded string.
3279
+     *
3280
+     * Really, timezones ought to be supported
3281
+     * but the XML-RPC spec says:
3282
+     *
3283
+     * "Don't assume a timezone. It should be specified by the server in its
3284
+     * documentation what assumptions it makes about timezones."
3285
+     *
3286
+     * These routines always assume localtime unless
3287
+     * $utc is set to 1, in which case UTC is assumed
3288
+     * and an adjustment for locale is made when encoding
3289
+     *
3290
+     * @param int $timet (timestamp)
3291
+     * @param int $utc (0 or 1)
3292
+     * @return string
3293
+     */
3294
+    function iso8601_encode($timet, $utc=0)
3295
+    {
3296
+        if(!$utc)
3297
+        {
3298
+            $t=strftime("%Y%m%dT%H:%M:%S", $timet);
3299
+        }
3300
+        else
3301
+        {
3302
+            if(function_exists('gmstrftime'))
3303
+            {
3304
+                // gmstrftime doesn't exist in some versions
3305
+                // of PHP
3306
+                $t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
3307
+            }
3308
+            else
3309
+            {
3310
+                $t=strftime("%Y%m%dT%H:%M:%S", $timet-date('Z'));
3311
+            }
3312
+        }
3313
+        return $t;
3314
+    }
3315
+
3316
+    /**
3317
+     * Given an ISO8601 date string, return a timet in the localtime, or UTC
3318
+     * @param string $idate
3319
+     * @param int $utc either 0 or 1
3320
+     * @return int (datetime)
3321
+     */
3322
+    function iso8601_decode($idate, $utc=0)
3323
+    {
3324
+        $t=0;
3325
+        if(preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $idate, $regs))
3326
+        {
3327
+            if($utc)
3328
+            {
3329
+                $t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3330
+            }
3331
+            else
3332
+            {
3333
+                $t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3334
+            }
3335
+        }
3336
+        return $t;
3337
+    }
3338
+
3339
+    /**
3340
+     * Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types.
3341
+     *
3342
+     * Works with xmlrpc message objects as input, too.
3343
+     *
3344
+     * Given proper options parameter, can rebuild generic php object instances
3345
+     * (provided those have been encoded to xmlrpc format using a corresponding
3346
+     * option in php_xmlrpc_encode())
3347
+     * PLEASE NOTE that rebuilding php objects involves calling their constructor function.
3348
+     * This means that the remote communication end can decide which php code will
3349
+     * get executed on your server, leaving the door possibly open to 'php-injection'
3350
+     * style of attacks (provided you have some classes defined on your server that
3351
+     * might wreak havoc if instances are built outside an appropriate context).
3352
+     * Make sure you trust the remote server/client before eanbling this!
3353
+     *
3354
+     * @author Dan Libby ([email protected])
3355
+     *
3356
+     * @param xmlrpcval $xmlrpc_val
3357
+     * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is
3358
+     * @return mixed
3359
+     */
3360
+    function php_xmlrpc_decode($xmlrpc_val, $options=array())
3361
+    {
3362
+        switch($xmlrpc_val->kindOf())
3363
+        {
3364
+            case 'scalar':
3365
+                if (in_array('extension_api', $options))
3366
+                {
3367
+                    reset($xmlrpc_val->me);
3368
+                    list($typ,$val) = each($xmlrpc_val->me);
3369
+                    switch ($typ)
3370
+                    {
3371
+                        case 'dateTime.iso8601':
3372
+                            $xmlrpc_val->scalar = $val;
3373
+                            $xmlrpc_val->xmlrpc_type = 'datetime';
3374
+                            $xmlrpc_val->timestamp = iso8601_decode($val);
3375
+                            return $xmlrpc_val;
3376
+                        case 'base64':
3377
+                            $xmlrpc_val->scalar = $val;
3378
+                            $xmlrpc_val->type = $typ;
3379
+                            return $xmlrpc_val;
3380
+                        default:
3381
+                            return $xmlrpc_val->scalarval();
3382
+                    }
3383
+                }
3384
+                if (in_array('dates_as_objects', $options) && $xmlrpc_val->scalartyp() == 'dateTime.iso8601')
3385
+                {
3386
+                    // we return a Datetime object instead of a string
3387
+                    // since now the constructor of xmlrpcval accepts safely strings, ints and datetimes,
3388
+                    // we cater to all 3 cases here
3389
+                    $out = $xmlrpc_val->scalarval();
3390
+                    if (is_string($out))
3391
+                    {
3392
+                        $out = strtotime($out);
3393
+                    }
3394
+                    if (is_int($out))
3395
+                    {
3396
+                        $result = new Datetime();
3397
+                        $result->setTimestamp($out);
3398
+                        return $result;
3399
+                    }
3400
+                    elseif (is_a($out, 'Datetime'))
3401
+                    {
3402
+                        return $out;
3403
+                    }
3404
+                }
3405
+                return $xmlrpc_val->scalarval();
3406
+            case 'array':
3407
+                $size = $xmlrpc_val->arraysize();
3408
+                $arr = array();
3409
+                for($i = 0; $i < $size; $i++)
3410
+                {
3411
+                    $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
3412
+                }
3413
+                return $arr;
3414
+            case 'struct':
3415
+                $xmlrpc_val->structreset();
3416
+                // If user said so, try to rebuild php objects for specific struct vals.
3417
+                /// @todo should we raise a warning for class not found?
3418
+                // shall we check for proper subclass of xmlrpcval instead of
3419
+                // presence of _php_class to detect what we can do?
3420
+                if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != ''
3421
+                    && class_exists($xmlrpc_val->_php_class))
3422
+                {
3423
+                    $obj = @new $xmlrpc_val->_php_class;
3424
+                    while(list($key,$value)=$xmlrpc_val->structeach())
3425
+                    {
3426
+                        $obj->$key = php_xmlrpc_decode($value, $options);
3427
+                    }
3428
+                    return $obj;
3429
+                }
3430
+                else
3431
+                {
3432
+                    $arr = array();
3433
+                    while(list($key,$value)=$xmlrpc_val->structeach())
3434
+                    {
3435
+                        $arr[$key] = php_xmlrpc_decode($value, $options);
3436
+                    }
3437
+                    return $arr;
3438
+                }
3439
+            case 'msg':
3440
+                $paramcount = $xmlrpc_val->getNumParams();
3441
+                $arr = array();
3442
+                for($i = 0; $i < $paramcount; $i++)
3443
+                {
3444
+                    $arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
3445
+                }
3446
+                return $arr;
3447
+            }
3448
+    }
3449
+
3450
+    // This constant left here only for historical reasons...
3451
+    // it was used to decide if we have to define xmlrpc_encode on our own, but
3452
+    // we do not do it anymore
3453
+    if(function_exists('xmlrpc_decode'))
3454
+    {
3455
+        define('XMLRPC_EPI_ENABLED','1');
3456
+    }
3457
+    else
3458
+    {
3459
+        define('XMLRPC_EPI_ENABLED','0');
3460
+    }
3461
+
3462
+    /**
3463
+     * Takes native php types and encodes them into xmlrpc PHP object format.
3464
+     * It will not re-encode xmlrpcval objects.
3465
+     *
3466
+     * Feature creep -- could support more types via optional type argument
3467
+     * (string => datetime support has been added, ??? => base64 not yet)
3468
+     *
3469
+     * If given a proper options parameter, php object instances will be encoded
3470
+     * into 'special' xmlrpc values, that can later be decoded into php objects
3471
+     * by calling php_xmlrpc_decode() with a corresponding option
3472
+     *
3473
+     * @author Dan Libby ([email protected])
3474
+     *
3475
+     * @param mixed $php_val the value to be converted into an xmlrpcval object
3476
+     * @param array $options	can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api'
3477
+     * @return xmlrpcval
3478
+     */
3479
+    function php_xmlrpc_encode($php_val, $options=array())
3480
+    {
3481
+        $type = gettype($php_val);
3482
+        switch($type)
3483
+        {
3484
+            case 'string':
3485
+                if (in_array('auto_dates', $options) && preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $php_val))
3486
+                    $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcDateTime']);
3487
+                else
3488
+                    $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcString']);
3489
+                break;
3490
+            case 'integer':
3491
+                $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcInt']);
3492
+                break;
3493
+            case 'double':
3494
+                $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcDouble']);
3495
+                break;
3496
+                // <G_Giunta_2001-02-29>
3497
+                // Add support for encoding/decoding of booleans, since they are supported in PHP
3498
+            case 'boolean':
3499
+                $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcBoolean']);
3500
+                break;
3501
+                // </G_Giunta_2001-02-29>
3502
+            case 'array':
3503
+                // PHP arrays can be encoded to either xmlrpc structs or arrays,
3504
+                // depending on wheter they are hashes or plain 0..n integer indexed
3505
+                // A shorter one-liner would be
3506
+                // $tmp = array_diff(array_keys($php_val), range(0, count($php_val)-1));
3507
+                // but execution time skyrockets!
3508
+                $j = 0;
3509
+                $arr = array();
3510
+                $ko = false;
3511
+                foreach($php_val as $key => $val)
3512
+                {
3513
+                    $arr[$key] = php_xmlrpc_encode($val, $options);
3514
+                    if(!$ko && $key !== $j)
3515
+                    {
3516
+                        $ko = true;
3517
+                    }
3518
+                    $j++;
3519
+                }
3520
+                if($ko)
3521
+                {
3522
+                    $xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcStruct']);
3523
+                }
3524
+                else
3525
+                {
3526
+                    $xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcArray']);
3527
+                }
3528
+                break;
3529
+            case 'object':
3530
+                if(is_a($php_val, 'xmlrpcval'))
3531
+                {
3532
+                    $xmlrpc_val = $php_val;
3533
+                }
3534
+                else if(is_a($php_val, 'DateTime'))
3535
+                {
3536
+                    $xmlrpc_val = new xmlrpcval($php_val->format('Ymd\TH:i:s'), $GLOBALS['xmlrpcStruct']);
3537
+                }
3538
+                else
3539
+                {
3540
+                    $arr = array();
3541
+                    reset($php_val);
3542
+                    while(list($k,$v) = each($php_val))
3543
+                    {
3544
+                        $arr[$k] = php_xmlrpc_encode($v, $options);
3545
+                    }
3546
+                    $xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcStruct']);
3547
+                    if (in_array('encode_php_objs', $options))
3548
+                    {
3549
+                        // let's save original class name into xmlrpcval:
3550
+                        // might be useful later on...
3551
+                        $xmlrpc_val->_php_class = get_class($php_val);
3552
+                    }
3553
+                }
3554
+                break;
3555
+            case 'NULL':
3556
+                if (in_array('extension_api', $options))
3557
+                {
3558
+                    $xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcString']);
3559
+                }
3560
+                else if (in_array('null_extension', $options))
3561
+                {
3562
+                    $xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcNull']);
3563
+                }
3564
+                else
3565
+                {
3566
+                    $xmlrpc_val = new xmlrpcval();
3567
+                }
3568
+                break;
3569
+            case 'resource':
3570
+                if (in_array('extension_api', $options))
3571
+                {
3572
+                    $xmlrpc_val = new xmlrpcval((int)$php_val, $GLOBALS['xmlrpcInt']);
3573
+                }
3574
+                else
3575
+                {
3576
+                    $xmlrpc_val = new xmlrpcval();
3577
+                }
3578
+            // catch "user function", "unknown type"
3579
+            default:
3580
+                // giancarlo pinerolo <[email protected]>
3581
+                // it has to return
3582
+                // an empty object in case, not a boolean.
3583
+                $xmlrpc_val = new xmlrpcval();
3584
+                break;
3585
+            }
3586
+            return $xmlrpc_val;
3587
+    }
3588
+
3589
+    /**
3590
+     * Convert the xml representation of a method response, method request or single
3591
+     * xmlrpc value into the appropriate object (a.k.a. deserialize)
3592
+     * @param string $xml_val
3593
+     * @param array $options
3594
+     * @return mixed false on error, or an instance of either xmlrpcval, xmlrpcmsg or xmlrpcresp
3595
+     */
3596
+    function php_xmlrpc_decode_xml($xml_val, $options=array())
3597
+    {
3598
+        $GLOBALS['_xh'] = array();
3599
+        $GLOBALS['_xh']['ac'] = '';
3600
+        $GLOBALS['_xh']['stack'] = array();
3601
+        $GLOBALS['_xh']['valuestack'] = array();
3602
+        $GLOBALS['_xh']['params'] = array();
3603
+        $GLOBALS['_xh']['pt'] = array();
3604
+        $GLOBALS['_xh']['isf'] = 0;
3605
+        $GLOBALS['_xh']['isf_reason'] = '';
3606
+        $GLOBALS['_xh']['method'] = false;
3607
+        $GLOBALS['_xh']['rt'] = '';
3608
+
3609
+        // 'guestimate' encoding
3610
+        $val_encoding = guess_encoding('', $xml_val);
3611
+
3612
+        // Since parsing will fail if charset is not specified in the xml prologue,
3613
+        // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
3614
+        // The following code might be better for mb_string enabled installs, but
3615
+        // makes the lib about 200% slower...
3616
+        //if (!is_valid_charset($val_encoding, array('UTF-8')))
3617
+        if (!in_array($val_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($xml_val)) {
3618
+            if ($val_encoding == 'ISO-8859-1') {
3619
+                $xml_val = utf8_encode($xml_val);
3620
+            } else {
3621
+                if (extension_loaded('mbstring')) {
3622
+                    $xml_val = mb_convert_encoding($xml_val, 'UTF-8', $val_encoding);
3623
+                } else {
3624
+                    error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $val_encoding);
3625
+                }
3626
+            }
3627
+        }
3628
+
3629
+        $parser = xml_parser_create();
3630
+        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
3631
+        // What if internal encoding is not in one of the 3 allowed?
3632
+        // we use the broadest one, ie. utf8!
3633
+        if (!in_array($GLOBALS['xmlrpc_internalencoding'], array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
3634
+        {
3635
+            xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
3636
+        }
3637
+        else
3638
+        {
3639
+            xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $GLOBALS['xmlrpc_internalencoding']);
3640
+        }
3641
+        xml_set_element_handler($parser, 'xmlrpc_se_any', 'xmlrpc_ee');
3642
+        xml_set_character_data_handler($parser, 'xmlrpc_cd');
3643
+        xml_set_default_handler($parser, 'xmlrpc_dh');
3644
+        if(!xml_parse($parser, $xml_val, 1))
3645
+        {
3646
+            $errstr = sprintf('XML error: %s at line %d, column %d',
3647
+                        xml_error_string(xml_get_error_code($parser)),
3648
+                        xml_get_current_line_number($parser), xml_get_current_column_number($parser));
3649
+            error_log($errstr);
3650
+            xml_parser_free($parser);
3651
+            return false;
3652
+        }
3653
+        xml_parser_free($parser);
3654
+        if ($GLOBALS['_xh']['isf'] > 1) // test that $GLOBALS['_xh']['value'] is an obj, too???
3655
+        {
3656
+            error_log($GLOBALS['_xh']['isf_reason']);
3657
+            return false;
3658
+        }
3659
+        switch ($GLOBALS['_xh']['rt'])
3660
+        {
3661
+            case 'methodresponse':
3662
+                $v =& $GLOBALS['_xh']['value'];
3663
+                if ($GLOBALS['_xh']['isf'] == 1)
3664
+                {
3665
+                    $vc = $v->structmem('faultCode');
3666
+                    $vs = $v->structmem('faultString');
3667
+                    $r = new xmlrpcresp(0, $vc->scalarval(), $vs->scalarval());
3668
+                }
3669
+                else
3670
+                {
3671
+                    $r = new xmlrpcresp($v);
3672
+                }
3673
+                return $r;
3674
+            case 'methodcall':
3675
+                $m = new xmlrpcmsg($GLOBALS['_xh']['method']);
3676
+                for($i=0; $i < count($GLOBALS['_xh']['params']); $i++)
3677
+                {
3678
+                    $m->addParam($GLOBALS['_xh']['params'][$i]);
3679
+                }
3680
+                return $m;
3681
+            case 'value':
3682
+                return $GLOBALS['_xh']['value'];
3683
+            default:
3684
+                return false;
3685
+        }
3686
+    }
3687
+
3688
+    /**
3689
+     * decode a string that is encoded w/ "chunked" transfer encoding
3690
+     * as defined in rfc2068 par. 19.4.6
3691
+     * code shamelessly stolen from nusoap library by Dietrich Ayala
3692
+     *
3693
+     * @param string $buffer the string to be decoded
3694
+     * @return string
3695
+     */
3696
+    function decode_chunked($buffer)
3697
+    {
3698
+        // length := 0
3699
+        $length = 0;
3700
+        $new = '';
3701
+
3702
+        // read chunk-size, chunk-extension (if any) and crlf
3703
+        // get the position of the linebreak
3704
+        $chunkend = strpos($buffer,"\r\n") + 2;
3705
+        $temp = substr($buffer,0,$chunkend);
3706
+        $chunk_size = hexdec( trim($temp) );
3707
+        $chunkstart = $chunkend;
3708
+        while($chunk_size > 0)
3709
+        {
3710
+            $chunkend = strpos($buffer, "\r\n", $chunkstart + $chunk_size);
3711
+
3712
+            // just in case we got a broken connection
3713
+            if($chunkend == false)
3714
+            {
3715
+                $chunk = substr($buffer,$chunkstart);
3716
+                // append chunk-data to entity-body
3717
+                $new .= $chunk;
3718
+                $length += strlen($chunk);
3719
+                break;
3720
+            }
3721
+
3722
+            // read chunk-data and crlf
3723
+            $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
3724
+            // append chunk-data to entity-body
3725
+            $new .= $chunk;
3726
+            // length := length + chunk-size
3727
+            $length += strlen($chunk);
3728
+            // read chunk-size and crlf
3729
+            $chunkstart = $chunkend + 2;
3730
+
3731
+            $chunkend = strpos($buffer,"\r\n",$chunkstart)+2;
3732
+            if($chunkend == false)
3733
+            {
3734
+                break; //just in case we got a broken connection
3735
+            }
3736
+            $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
3737
+            $chunk_size = hexdec( trim($temp) );
3738
+            $chunkstart = $chunkend;
3739
+        }
3740
+        return $new;
3741
+    }
3742
+
3743
+    /**
3744
+     * xml charset encoding guessing helper function.
3745
+     * Tries to determine the charset encoding of an XML chunk received over HTTP.
3746
+     * NB: according to the spec (RFC 3023), if text/xml content-type is received over HTTP without a content-type,
3747
+     * we SHOULD assume it is strictly US-ASCII. But we try to be more tolerant of unconforming (legacy?) clients/servers,
3748
+     * which will be most probably using UTF-8 anyway...
3749
+     *
3750
+     * @param string $httpheader the http Content-type header
3751
+     * @param string $xmlchunk xml content buffer
3752
+     * @param string $encoding_prefs comma separated list of character encodings to be used as default (when mb extension is enabled)
3753
+     * @return string
3754
+     *
3755
+     * @todo explore usage of mb_http_input(): does it detect http headers + post data? if so, use it instead of hand-detection!!!
3756
+     */
3757
+    function guess_encoding($httpheader='', $xmlchunk='', $encoding_prefs=null)
3758
+    {
3759
+        // discussion: see http://www.yale.edu/pclt/encoding/
3760
+        // 1 - test if encoding is specified in HTTP HEADERS
3761
+
3762
+        //Details:
3763
+        // LWS:           (\13\10)?( |\t)+
3764
+        // token:         (any char but excluded stuff)+
3765
+        // quoted string: " (any char but double quotes and cointrol chars)* "
3766
+        // header:        Content-type = ...; charset=value(; ...)*
3767
+        //   where value is of type token, no LWS allowed between 'charset' and value
3768
+        // Note: we do not check for invalid chars in VALUE:
3769
+        //   this had better be done using pure ereg as below
3770
+        // Note 2: we might be removing whitespace/tabs that ought to be left in if
3771
+        //   the received charset is a quoted string. But nobody uses such charset names...
3772
+
3773
+        /// @todo this test will pass if ANY header has charset specification, not only Content-Type. Fix it?
3774
+        $matches = array();
3775
+        if(preg_match('/;\s*charset\s*=([^;]+)/i', $httpheader, $matches))
3776
+        {
3777
+            return strtoupper(trim($matches[1], " \t\""));
3778
+        }
3779
+
3780
+        // 2 - scan the first bytes of the data for a UTF-16 (or other) BOM pattern
3781
+        //     (source: http://www.w3.org/TR/2000/REC-xml-20001006)
3782
+        //     NOTE: actually, according to the spec, even if we find the BOM and determine
3783
+        //     an encoding, we should check if there is an encoding specified
3784
+        //     in the xml declaration, and verify if they match.
3785
+        /// @todo implement check as described above?
3786
+        /// @todo implement check for first bytes of string even without a BOM? (It sure looks harder than for cases WITH a BOM)
3787
+        if(preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlchunk))
3788
+        {
3789
+            return 'UCS-4';
3790
+        }
3791
+        elseif(preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlchunk))
3792
+        {
3793
+            return 'UTF-16';
3794
+        }
3795
+        elseif(preg_match('/^(\xEF\xBB\xBF)/', $xmlchunk))
3796
+        {
3797
+            return 'UTF-8';
3798
+        }
3799
+
3800
+        // 3 - test if encoding is specified in the xml declaration
3801
+        // Details:
3802
+        // SPACE:         (#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
3803
+        // EQ:            SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
3804
+        if (preg_match('/^<\?xml\s+version\s*=\s*'. "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))".
3805
+            '\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
3806
+            $xmlchunk, $matches))
3807
+        {
3808
+            return strtoupper(substr($matches[2], 1, -1));
3809
+        }
3810
+
3811
+        // 4 - if mbstring is available, let it do the guesswork
3812
+        // NB: we favour finding an encoding that is compatible with what we can process
3813
+        if(extension_loaded('mbstring'))
3814
+        {
3815
+            if($encoding_prefs)
3816
+            {
3817
+                $enc = mb_detect_encoding($xmlchunk, $encoding_prefs);
3818
+            }
3819
+            else
3820
+            {
3821
+                $enc = mb_detect_encoding($xmlchunk);
3822
+            }
3823
+            // NB: mb_detect likes to call it ascii, xml parser likes to call it US_ASCII...
3824
+            // IANA also likes better US-ASCII, so go with it
3825
+            if($enc == 'ASCII')
3826
+            {
3827
+                $enc = 'US-'.$enc;
3828
+            }
3829
+            return $enc;
3830
+        }
3831
+        else
3832
+        {
3833
+            // no encoding specified: as per HTTP1.1 assume it is iso-8859-1?
3834
+            // Both RFC 2616 (HTTP 1.1) and 1945 (HTTP 1.0) clearly state that for text/xxx content types
3835
+            // this should be the standard. And we should be getting text/xml as request and response.
3836
+            // BUT we have to be backward compatible with the lib, which always used UTF-8 as default...
3837
+            return $GLOBALS['xmlrpc_defencoding'];
3838
+        }
3839
+    }
3840
+
3841
+    /**
3842
+     * Helper function: checks if an xml chunk as a charset declaration (BOM or in the xml declaration)
3843
+     *
3844
+     * @param string $xmlChunk
3845
+     * @return bool
3846
+     */
3847
+    function has_encoding($xmlChunk)
3848
+    {
3849
+        // scan the first bytes of the data for a UTF-16 (or other) BOM pattern
3850
+        //	 (source: http://www.w3.org/TR/2000/REC-xml-20001006)
3851
+        if (preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlChunk))
3852
+        {
3853
+            return true;
3854
+        }
3855
+        elseif (preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlChunk))
3856
+        {
3857
+            return true;
3858
+        }
3859
+        elseif (preg_match('/^(\xEF\xBB\xBF)/', $xmlChunk))
3860
+        {
3861
+            return true;
3862
+        }
3863
+
3864
+        // test if encoding is specified in the xml declaration
3865
+        // Details:
3866
+        // SPACE:		(#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
3867
+        // EQ:			SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
3868
+        if (preg_match('/^<\?xml\s+version\s*=\s*' . "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))" .
3869
+            '\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
3870
+            $xmlChunk, $matches))
3871
+        {
3872
+            return true;
3873
+        }
3874
+
3875
+        return false;
3876
+    }
3877
+
3878
+    /**
3879
+     * Checks if a given charset encoding is present in a list of encodings or
3880
+     * if it is a valid subset of any encoding in the list
3881
+     * @param string $encoding charset to be tested
3882
+     * @param mixed $validlist comma separated list of valid charsets (or array of charsets)
3883
+     * @return bool
3884
+     */
3885
+    function is_valid_charset($encoding, $validlist)
3886
+    {
3887
+        $charset_supersets = array(
3888
+            'US-ASCII' => array ('ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4',
3889
+                'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8',
3890
+                'ISO-8859-9', 'ISO-8859-10', 'ISO-8859-11', 'ISO-8859-12',
3891
+                'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'UTF-8',
3892
+                'EUC-JP', 'EUC-', 'EUC-KR', 'EUC-CN')
3893
+        );
3894
+        if (is_string($validlist))
3895
+            $validlist = explode(',', $validlist);
3896
+        if (@in_array(strtoupper($encoding), $validlist))
3897
+            return true;
3898
+        else
3899
+        {
3900
+            if (array_key_exists($encoding, $charset_supersets))
3901
+                foreach ($validlist as $allowed)
3902
+                    if (in_array($allowed, $charset_supersets[$encoding]))
3903
+                        return true;
3904
+            return false;
3905
+        }
3906
+    }
3907 3907
 
3908 3908
 ?>
3909 3909
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35 35
 // OF THE POSSIBILITY OF SUCH DAMAGE.
36 36
 
37
-	if(!function_exists('xml_parser_create'))
37
+	if (!function_exists('xml_parser_create'))
38 38
 	{
39 39
 		// For PHP 4 onward, XML functionality is always compiled-in on windows:
40 40
 		// no more need to dl-open it. It might have been compiled out on *nix...
41
-		if(strtoupper(substr(PHP_OS, 0, 3) != 'WIN'))
41
+		if (strtoupper(substr(PHP_OS, 0, 3) != 'WIN'))
42 42
 		{
43 43
 			dl('xml.so');
44 44
 		}
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
 	// G. Giunta 2005/01/29: declare global these variables,
48 48
 	// so that xmlrpc.inc will work even if included from within a function
49 49
 	// Milosch: 2005/08/07 - explicitly request these via $GLOBALS where used.
50
-	$GLOBALS['xmlrpcI4']='i4';
51
-	$GLOBALS['xmlrpcInt']='int';
52
-	$GLOBALS['xmlrpcBoolean']='boolean';
53
-	$GLOBALS['xmlrpcDouble']='double';
54
-	$GLOBALS['xmlrpcString']='string';
55
-	$GLOBALS['xmlrpcDateTime']='dateTime.iso8601';
56
-	$GLOBALS['xmlrpcBase64']='base64';
57
-	$GLOBALS['xmlrpcArray']='array';
58
-	$GLOBALS['xmlrpcStruct']='struct';
59
-	$GLOBALS['xmlrpcValue']='undefined';
60
-
61
-	$GLOBALS['xmlrpcTypes']=array(
50
+	$GLOBALS['xmlrpcI4'] = 'i4';
51
+	$GLOBALS['xmlrpcInt'] = 'int';
52
+	$GLOBALS['xmlrpcBoolean'] = 'boolean';
53
+	$GLOBALS['xmlrpcDouble'] = 'double';
54
+	$GLOBALS['xmlrpcString'] = 'string';
55
+	$GLOBALS['xmlrpcDateTime'] = 'dateTime.iso8601';
56
+	$GLOBALS['xmlrpcBase64'] = 'base64';
57
+	$GLOBALS['xmlrpcArray'] = 'array';
58
+	$GLOBALS['xmlrpcStruct'] = 'struct';
59
+	$GLOBALS['xmlrpcValue'] = 'undefined';
60
+
61
+	$GLOBALS['xmlrpcTypes'] = array(
62 62
 		$GLOBALS['xmlrpcI4']       => 1,
63 63
 		$GLOBALS['xmlrpcInt']      => 1,
64 64
 		$GLOBALS['xmlrpcBoolean']  => 1,
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
 	);
94 94
 
95 95
 	// define extra types for supporting NULL (useful for json or <NIL/>)
96
-	$GLOBALS['xmlrpcNull']='null';
97
-	$GLOBALS['xmlrpcTypes']['null']=1;
96
+	$GLOBALS['xmlrpcNull'] = 'null';
97
+	$GLOBALS['xmlrpcTypes']['null'] = 1;
98 98
 
99 99
 	// Not in use anymore since 2.0. Shall we remove it?
100 100
 	/// @deprecated
101
-	$GLOBALS['xmlEntities']=array(
101
+	$GLOBALS['xmlEntities'] = array(
102 102
 		'amp'  => '&',
103 103
 		'quot' => '"',
104 104
 		'lt'   => '<',
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
 
109 109
 	// tables used for transcoding different charsets into us-ascii xml
110 110
 
111
-	$GLOBALS['xml_iso88591_Entities']=array();
111
+	$GLOBALS['xml_iso88591_Entities'] = array();
112 112
 	$GLOBALS['xml_iso88591_Entities']['in'] = array();
113 113
 	$GLOBALS['xml_iso88591_Entities']['out'] = array();
114
-	for ($i = 0; $i < 32; $i++)
114
+	for ($i = 0; $i<32; $i++)
115 115
 	{
116 116
 		$GLOBALS['xml_iso88591_Entities']['in'][] = chr($i);
117 117
 		$GLOBALS['xml_iso88591_Entities']['out'][] = '&#'.$i.';';
118 118
 	}
119
-	for ($i = 160; $i < 256; $i++)
119
+	for ($i = 160; $i<256; $i++)
120 120
 	{
121 121
 		$GLOBALS['xml_iso88591_Entities']['in'][] = chr($i);
122 122
 		$GLOBALS['xml_iso88591_Entities']['out'][] = '&#'.$i.';';
@@ -200,32 +200,32 @@  discard block
 block discarded – undo
200 200
 	// The charset encoding used by the server for received messages and
201 201
 	// by the client for received responses when received charset cannot be determined
202 202
 	// or is not supported
203
-	$GLOBALS['xmlrpc_defencoding']='UTF-8';
203
+	$GLOBALS['xmlrpc_defencoding'] = 'UTF-8';
204 204
 
205 205
 	// The encoding used internally by PHP.
206 206
 	// String values received as xml will be converted to this, and php strings will be converted to xml
207 207
 	// as if having been coded with this
208
-	$GLOBALS['xmlrpc_internalencoding']='ISO-8859-1';
208
+	$GLOBALS['xmlrpc_internalencoding'] = 'ISO-8859-1';
209 209
 
210
-	$GLOBALS['xmlrpcName']='XML-RPC for PHP';
211
-	$GLOBALS['xmlrpcVersion']='3.0.1';
210
+	$GLOBALS['xmlrpcName'] = 'XML-RPC for PHP';
211
+	$GLOBALS['xmlrpcVersion'] = '3.0.1';
212 212
 
213 213
 	// let user errors start at 800
214
-	$GLOBALS['xmlrpcerruser']=800;
214
+	$GLOBALS['xmlrpcerruser'] = 800;
215 215
 	// let XML parse errors start at 100
216
-	$GLOBALS['xmlrpcerrxml']=100;
216
+	$GLOBALS['xmlrpcerrxml'] = 100;
217 217
 
218 218
 	// formulate backslashes for escaping regexp
219 219
 	// Not in use anymore since 2.0. Shall we remove it?
220 220
 	/// @deprecated
221
-	$GLOBALS['xmlrpc_backslash']=chr(92).chr(92);
221
+	$GLOBALS['xmlrpc_backslash'] = chr(92).chr(92);
222 222
 
223 223
 	// set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values
224
-	$GLOBALS['xmlrpc_null_extension']=false;
224
+	$GLOBALS['xmlrpc_null_extension'] = false;
225 225
 
226 226
 	// set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
227
-	$GLOBALS['xmlrpc_null_apache_encoding']=false;
228
-	$GLOBALS['xmlrpc_null_apache_encoding_ns']='http://ws.apache.org/xmlrpc/namespaces/extensions';
227
+	$GLOBALS['xmlrpc_null_apache_encoding'] = false;
228
+	$GLOBALS['xmlrpc_null_apache_encoding_ns'] = 'http://ws.apache.org/xmlrpc/namespaces/extensions';
229 229
 
230 230
 	// used to store state during parsing
231 231
 	// quick explanation of components:
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 	//   method - used to store method name
239 239
 	//   stack - array with genealogy of xml elements names:
240 240
 	//           used to validate nesting of xmlrpc elements
241
-	$GLOBALS['_xh']=null;
241
+	$GLOBALS['_xh'] = null;
242 242
 
243 243
 	/**
244 244
 	* Convert a string to the correct XML representation in a target charset
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	* @todo do a bit of basic benchmarking (strtr vs. str_replace)
255 255
 	* @todo	make usage of iconv() or recode_string() or mb_string() where available
256 256
 	*/
257
-	function xmlrpc_encode_entitites($data, $src_encoding='', $dest_encoding='')
257
+	function xmlrpc_encode_entitites($data, $src_encoding = '', $dest_encoding = '')
258 258
 	{
259 259
 		if ($src_encoding == '')
260 260
 		{
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 			$src_encoding = $GLOBALS['xmlrpc_internalencoding'];
263 263
 		}
264 264
 
265
-		switch(strtoupper($src_encoding.'_'.$dest_encoding))
265
+		switch (strtoupper($src_encoding.'_'.$dest_encoding))
266 266
 		{
267 267
 			case 'ISO-8859-1_':
268 268
 			case 'ISO-8859-1_US-ASCII':
@@ -289,16 +289,16 @@  discard block
 block discarded – undo
289 289
 	$escaped_data = '';
290 290
 	// be kind to users creating string xmlrpcvals out of different php types
291 291
 	$data = (string) $data;
292
-	$ns = strlen ($data);
293
-	for ($nn = 0; $nn < $ns; $nn++)
292
+	$ns = strlen($data);
293
+	for ($nn = 0; $nn<$ns; $nn++)
294 294
 	{
295 295
 		$ch = $data[$nn];
296 296
 		$ii = ord($ch);
297 297
 		//1 7 0bbbbbbb (127)
298
-		if ($ii < 128)
298
+		if ($ii<128)
299 299
 		{
300 300
 			/// @todo shall we replace this with a (supposedly) faster str_replace?
301
-			switch($ii){
301
+			switch ($ii) {
302 302
 				case 34:
303 303
 					$escaped_data .= '&quot;';
304 304
 					break;
@@ -319,31 +319,31 @@  discard block
 block discarded – undo
319 319
 			} // switch
320 320
 		}
321 321
 		//2 11 110bbbbb 10bbbbbb (2047)
322
-		else if ($ii>>5 == 6)
322
+		else if ($ii >> 5 == 6)
323 323
 		{
324 324
 			$b1 = ($ii & 31);
325 325
 			$ii = ord($data[$nn+1]);
326 326
 			$b2 = ($ii & 63);
327
-			$ii = ($b1 * 64) + $b2;
328
-			$ent = sprintf ('&#%d;', $ii);
327
+			$ii = ($b1 * 64)+$b2;
328
+			$ent = sprintf('&#%d;', $ii);
329 329
 			$escaped_data .= $ent;
330 330
 			$nn += 1;
331 331
 		}
332 332
 		//3 16 1110bbbb 10bbbbbb 10bbbbbb
333
-		else if ($ii>>4 == 14)
333
+		else if ($ii >> 4 == 14)
334 334
 		{
335 335
 			$b1 = ($ii & 15);
336 336
 			$ii = ord($data[$nn+1]);
337 337
 			$b2 = ($ii & 63);
338 338
 			$ii = ord($data[$nn+2]);
339 339
 			$b3 = ($ii & 63);
340
-			$ii = ((($b1 * 64) + $b2) * 64) + $b3;
341
-			$ent = sprintf ('&#%d;', $ii);
340
+			$ii = ((($b1 * 64)+$b2) * 64)+$b3;
341
+			$ent = sprintf('&#%d;', $ii);
342 342
 			$escaped_data .= $ent;
343 343
 			$nn += 2;
344 344
 		}
345 345
 		//4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
346
-		else if ($ii>>3 == 30)
346
+		else if ($ii >> 3 == 30)
347 347
 		{
348 348
 			$b1 = ($ii & 7);
349 349
 			$ii = ord($data[$nn+1]);
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 			$b3 = ($ii & 63);
353 353
 			$ii = ord($data[$nn+3]);
354 354
 			$b4 = ($ii & 63);
355
-			$ii = ((((($b1 * 64) + $b2) * 64) + $b3) * 64) + $b4;
356
-			$ent = sprintf ('&#%d;', $ii);
355
+			$ii = ((((($b1 * 64)+$b2) * 64)+$b3) * 64)+$b4;
356
+			$ent = sprintf('&#%d;', $ii);
357 357
 			$escaped_data .= $ent;
358 358
 			$nn += 3;
359 359
 		}
@@ -386,10 +386,10 @@  discard block
 block discarded – undo
386 386
 	}
387 387
 
388 388
 	/// xml parser handler function for opening element tags
389
-	function xmlrpc_se($parser, $name, $attrs, $accept_single_vals=false)
389
+	function xmlrpc_se($parser, $name, $attrs, $accept_single_vals = false)
390 390
 	{
391 391
 		// if invalid xmlrpc already detected, skip all processing
392
-		if ($GLOBALS['_xh']['isf'] < 2)
392
+		if ($GLOBALS['_xh']['isf']<2)
393 393
 		{
394 394
 			// check for correct element nesting
395 395
 			// top level element can only be of 2 types
@@ -422,15 +422,15 @@  discard block
 block discarded – undo
422 422
 				}
423 423
 			}
424 424
 
425
-			switch($name)
425
+			switch ($name)
426 426
 			{
427 427
 				// optimize for speed switch cases: most common cases first
428 428
 				case 'VALUE':
429 429
 					/// @todo we could check for 2 VALUE elements inside a MEMBER or PARAM element
430
-					$GLOBALS['_xh']['vt']='value'; // indicator: no value found yet
431
-					$GLOBALS['_xh']['ac']='';
432
-					$GLOBALS['_xh']['lv']=1;
433
-					$GLOBALS['_xh']['php_class']=null;
430
+					$GLOBALS['_xh']['vt'] = 'value'; // indicator: no value found yet
431
+					$GLOBALS['_xh']['ac'] = '';
432
+					$GLOBALS['_xh']['lv'] = 1;
433
+					$GLOBALS['_xh']['php_class'] = null;
434 434
 					break;
435 435
 				case 'I4':
436 436
 				case 'INT':
@@ -439,18 +439,18 @@  discard block
 block discarded – undo
439 439
 				case 'DOUBLE':
440 440
 				case 'DATETIME.ISO8601':
441 441
 				case 'BASE64':
442
-					if ($GLOBALS['_xh']['vt']!='value')
442
+					if ($GLOBALS['_xh']['vt'] != 'value')
443 443
 					{
444 444
 						//two data elements inside a value: an error occurred!
445 445
 						$GLOBALS['_xh']['isf'] = 2;
446 446
 						$GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
447 447
 						return;
448 448
 					}
449
-					$GLOBALS['_xh']['ac']=''; // reset the accumulator
449
+					$GLOBALS['_xh']['ac'] = ''; // reset the accumulator
450 450
 					break;
451 451
 				case 'STRUCT':
452 452
 				case 'ARRAY':
453
-					if ($GLOBALS['_xh']['vt']!='value')
453
+					if ($GLOBALS['_xh']['vt'] != 'value')
454 454
 					{
455 455
 						//two data elements inside a value: an error occurred!
456 456
 						$GLOBALS['_xh']['isf'] = 2;
@@ -468,10 +468,10 @@  discard block
 block discarded – undo
468 468
 						$cur_val['php_class'] = $attrs['PHP_CLASS'];
469 469
 					}
470 470
 					$GLOBALS['_xh']['valuestack'][] = $cur_val;
471
-					$GLOBALS['_xh']['vt']='data'; // be prepared for a data element next
471
+					$GLOBALS['_xh']['vt'] = 'data'; // be prepared for a data element next
472 472
 					break;
473 473
 				case 'DATA':
474
-					if ($GLOBALS['_xh']['vt']!='data')
474
+					if ($GLOBALS['_xh']['vt'] != 'data')
475 475
 					{
476 476
 						//two data elements inside a value: an error occurred!
477 477
 						$GLOBALS['_xh']['isf'] = 2;
@@ -486,31 +486,31 @@  discard block
 block discarded – undo
486 486
 				case 'METHODNAME':
487 487
 				case 'NAME':
488 488
 					/// @todo we could check for 2 NAME elements inside a MEMBER element
489
-					$GLOBALS['_xh']['ac']='';
489
+					$GLOBALS['_xh']['ac'] = '';
490 490
 					break;
491 491
 				case 'FAULT':
492
-					$GLOBALS['_xh']['isf']=1;
492
+					$GLOBALS['_xh']['isf'] = 1;
493 493
 					break;
494 494
 				case 'MEMBER':
495
-					$GLOBALS['_xh']['valuestack'][count($GLOBALS['_xh']['valuestack'])-1]['name']=''; // set member name to null, in case we do not find in the xml later on
495
+					$GLOBALS['_xh']['valuestack'][count($GLOBALS['_xh']['valuestack'])-1]['name'] = ''; // set member name to null, in case we do not find in the xml later on
496 496
 					//$GLOBALS['_xh']['ac']='';
497 497
 					// Drop trough intentionally
498 498
 				case 'PARAM':
499 499
 					// clear value type, so we can check later if no value has been passed for this param/member
500
-					$GLOBALS['_xh']['vt']=null;
500
+					$GLOBALS['_xh']['vt'] = null;
501 501
 					break;
502 502
 				case 'NIL':
503 503
 				case 'EX:NIL':
504 504
 					if ($GLOBALS['xmlrpc_null_extension'])
505 505
 					{
506
-						if ($GLOBALS['_xh']['vt']!='value')
506
+						if ($GLOBALS['_xh']['vt'] != 'value')
507 507
 						{
508 508
 							//two data elements inside a value: an error occurred!
509 509
 							$GLOBALS['_xh']['isf'] = 2;
510 510
 							$GLOBALS['_xh']['isf_reason'] = "$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
511 511
 							return;
512 512
 						}
513
-						$GLOBALS['_xh']['ac']=''; // reset the accumulator
513
+						$GLOBALS['_xh']['ac'] = ''; // reset the accumulator
514 514
 						break;
515 515
 					}
516 516
 					// we do not support the <NIL/> extension, so
@@ -526,9 +526,9 @@  discard block
 block discarded – undo
526 526
 			$GLOBALS['_xh']['stack'][] = $name;
527 527
 
528 528
 			/// @todo optimization creep: move this inside the big switch() above
529
-			if($name!='VALUE')
529
+			if ($name != 'VALUE')
530 530
 			{
531
-				$GLOBALS['_xh']['lv']=0;
531
+				$GLOBALS['_xh']['lv'] = 0;
532 532
 			}
533 533
 		}
534 534
 	}
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 	/// xml parser handler function for close element tags
543 543
 	function xmlrpc_ee($parser, $name, $rebuild_xmlrpcvals = true)
544 544
 	{
545
-		if ($GLOBALS['_xh']['isf'] < 2)
545
+		if ($GLOBALS['_xh']['isf']<2)
546 546
 		{
547 547
 			// push this element name from stack
548 548
 			// NB: if XML validates, correct opening/closing is guaranteed and
@@ -550,14 +550,14 @@  discard block
 block discarded – undo
550 550
 			// we also checked for proper nesting at start of elements...
551 551
 			$curr_elem = array_pop($GLOBALS['_xh']['stack']);
552 552
 
553
-			switch($name)
553
+			switch ($name)
554 554
 			{
555 555
 				case 'VALUE':
556 556
 					// This if() detects if no scalar was inside <VALUE></VALUE>
557
-					if ($GLOBALS['_xh']['vt']=='value')
557
+					if ($GLOBALS['_xh']['vt'] == 'value')
558 558
 					{
559
-						$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
560
-						$GLOBALS['_xh']['vt']=$GLOBALS['xmlrpcString'];
559
+						$GLOBALS['_xh']['value'] = $GLOBALS['_xh']['ac'];
560
+						$GLOBALS['_xh']['vt'] = $GLOBALS['xmlrpcString'];
561 561
 					}
562 562
 
563 563
 					if ($rebuild_xmlrpcvals)
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 						// check if we are inside an array or struct:
572 572
 						// if value just built is inside an array, let's move it into array on the stack
573 573
 						$vscount = count($GLOBALS['_xh']['valuestack']);
574
-						if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type']=='ARRAY')
574
+						if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type'] == 'ARRAY')
575 575
 						{
576 576
 							$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][] = $temp;
577 577
 						}
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 						// check if we are inside an array or struct:
593 593
 						// if value just built is inside an array, let's move it into array on the stack
594 594
 						$vscount = count($GLOBALS['_xh']['valuestack']);
595
-						if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type']=='ARRAY')
595
+						if ($vscount && $GLOBALS['_xh']['valuestack'][$vscount-1]['type'] == 'ARRAY')
596 596
 						{
597 597
 							$GLOBALS['_xh']['valuestack'][$vscount-1]['values'][] = $GLOBALS['_xh']['value'];
598 598
 						}
@@ -605,28 +605,28 @@  discard block
 block discarded – undo
605 605
 				case 'DOUBLE':
606 606
 				case 'DATETIME.ISO8601':
607 607
 				case 'BASE64':
608
-					$GLOBALS['_xh']['vt']=strtolower($name);
608
+					$GLOBALS['_xh']['vt'] = strtolower($name);
609 609
 					/// @todo: optimization creep - remove the if/elseif cycle below
610 610
 					/// since the case() in which we are already did that
611
-					if ($name=='STRING')
611
+					if ($name == 'STRING')
612 612
 					{
613
-						$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
613
+						$GLOBALS['_xh']['value'] = $GLOBALS['_xh']['ac'];
614 614
 					}
615
-					elseif ($name=='DATETIME.ISO8601')
615
+					elseif ($name == 'DATETIME.ISO8601')
616 616
 					{
617 617
 						if (!preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $GLOBALS['_xh']['ac']))
618 618
 						{
619 619
 							error_log('XML-RPC: invalid value received in DATETIME: '.$GLOBALS['_xh']['ac']);
620 620
 						}
621
-						$GLOBALS['_xh']['vt']=$GLOBALS['xmlrpcDateTime'];
622
-						$GLOBALS['_xh']['value']=$GLOBALS['_xh']['ac'];
621
+						$GLOBALS['_xh']['vt'] = $GLOBALS['xmlrpcDateTime'];
622
+						$GLOBALS['_xh']['value'] = $GLOBALS['_xh']['ac'];
623 623
 					}
624
-					elseif ($name=='BASE64')
624
+					elseif ($name == 'BASE64')
625 625
 					{
626 626
 						/// @todo check for failure of base64 decoding / catch warnings
627
-						$GLOBALS['_xh']['value']=base64_decode($GLOBALS['_xh']['ac']);
627
+						$GLOBALS['_xh']['value'] = base64_decode($GLOBALS['_xh']['ac']);
628 628
 					}
629
-					elseif ($name=='BOOLEAN')
629
+					elseif ($name == 'BOOLEAN')
630 630
 					{
631 631
 						// special case here: we translate boolean 1 or 0 into PHP
632 632
 						// constants true or false.
@@ -634,19 +634,19 @@  discard block
 block discarded – undo
634 634
 						// spec never mentions them (see eg. Blogger api docs)
635 635
 						// NB: this simple checks helps a lot sanitizing input, ie no
636 636
 						// security problems around here
637
-						if ($GLOBALS['_xh']['ac']=='1' || strcasecmp($GLOBALS['_xh']['ac'], 'true') == 0)
637
+						if ($GLOBALS['_xh']['ac'] == '1' || strcasecmp($GLOBALS['_xh']['ac'], 'true') == 0)
638 638
 						{
639
-							$GLOBALS['_xh']['value']=true;
639
+							$GLOBALS['_xh']['value'] = true;
640 640
 						}
641 641
 						else
642 642
 						{
643 643
 							// log if receiveing something strange, even though we set the value to false anyway
644
-							if ($GLOBALS['_xh']['ac']!='0' && strcasecmp($GLOBALS['_xh']['ac'], 'false') != 0)
644
+							if ($GLOBALS['_xh']['ac'] != '0' && strcasecmp($GLOBALS['_xh']['ac'], 'false') != 0)
645 645
 								error_log('XML-RPC: invalid value received in BOOLEAN: '.$GLOBALS['_xh']['ac']);
646
-							$GLOBALS['_xh']['value']=false;
646
+							$GLOBALS['_xh']['value'] = false;
647 647
 						}
648 648
 					}
649
-					elseif ($name=='DOUBLE')
649
+					elseif ($name == 'DOUBLE')
650 650
 					{
651 651
 						// we have a DOUBLE
652 652
 						// we must check that only 0123456789-.<space> are characters here
@@ -655,12 +655,12 @@  discard block
 block discarded – undo
655 655
 						{
656 656
 							/// @todo: find a better way of throwing an error than this!
657 657
 							error_log('XML-RPC: non numeric value received in DOUBLE: '.$GLOBALS['_xh']['ac']);
658
-							$GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
658
+							$GLOBALS['_xh']['value'] = 'ERROR_NON_NUMERIC_FOUND';
659 659
 						}
660 660
 						else
661 661
 						{
662 662
 							// it's ok, add it on
663
-							$GLOBALS['_xh']['value']=(double)$GLOBALS['_xh']['ac'];
663
+							$GLOBALS['_xh']['value'] = (double) $GLOBALS['_xh']['ac'];
664 664
 						}
665 665
 					}
666 666
 					else
@@ -671,16 +671,16 @@  discard block
 block discarded – undo
671 671
 						{
672 672
 							/// @todo find a better way of throwing an error than this!
673 673
 							error_log('XML-RPC: non numeric value received in INT: '.$GLOBALS['_xh']['ac']);
674
-							$GLOBALS['_xh']['value']='ERROR_NON_NUMERIC_FOUND';
674
+							$GLOBALS['_xh']['value'] = 'ERROR_NON_NUMERIC_FOUND';
675 675
 						}
676 676
 						else
677 677
 						{
678 678
 							// it's ok, add it on
679
-							$GLOBALS['_xh']['value']=(int)$GLOBALS['_xh']['ac'];
679
+							$GLOBALS['_xh']['value'] = (int) $GLOBALS['_xh']['ac'];
680 680
 						}
681 681
 					}
682 682
 					//$GLOBALS['_xh']['ac']=''; // is this necessary?
683
-					$GLOBALS['_xh']['lv']=3; // indicate we've found a value
683
+					$GLOBALS['_xh']['lv'] = 3; // indicate we've found a value
684 684
 					break;
685 685
 				case 'NAME':
686 686
 					$GLOBALS['_xh']['valuestack'][count($GLOBALS['_xh']['valuestack'])-1]['name'] = $GLOBALS['_xh']['ac'];
@@ -698,14 +698,14 @@  discard block
 block discarded – undo
698 698
 					break;
699 699
 				case 'DATA':
700 700
 					//$GLOBALS['_xh']['ac']=''; // is this necessary?
701
-					$GLOBALS['_xh']['vt']=null; // reset this to check for 2 data elements in a row - even if they're empty
701
+					$GLOBALS['_xh']['vt'] = null; // reset this to check for 2 data elements in a row - even if they're empty
702 702
 					break;
703 703
 				case 'STRUCT':
704 704
 				case 'ARRAY':
705 705
 					// fetch out of stack array of values, and promote it to current value
706 706
 					$curr_val = array_pop($GLOBALS['_xh']['valuestack']);
707 707
 					$GLOBALS['_xh']['value'] = $curr_val['values'];
708
-					$GLOBALS['_xh']['vt']=strtolower($name);
708
+					$GLOBALS['_xh']['vt'] = strtolower($name);
709 709
 					if (isset($curr_val['php_class']))
710 710
 					{
711 711
 						$GLOBALS['_xh']['php_class'] = $curr_val['php_class'];
@@ -716,22 +716,22 @@  discard block
 block discarded – undo
716 716
 					// unless no VALUE was found
717 717
 					if ($GLOBALS['_xh']['vt'])
718 718
 					{
719
-						$GLOBALS['_xh']['params'][]=$GLOBALS['_xh']['value'];
720
-						$GLOBALS['_xh']['pt'][]=$GLOBALS['_xh']['vt'];
719
+						$GLOBALS['_xh']['params'][] = $GLOBALS['_xh']['value'];
720
+						$GLOBALS['_xh']['pt'][] = $GLOBALS['_xh']['vt'];
721 721
 					}
722 722
 					else
723 723
 						error_log('XML-RPC: missing VALUE inside PARAM in received xml');
724 724
 					break;
725 725
 				case 'METHODNAME':
726
-					$GLOBALS['_xh']['method']=preg_replace('/^[\n\r\t ]+/', '', $GLOBALS['_xh']['ac']);
726
+					$GLOBALS['_xh']['method'] = preg_replace('/^[\n\r\t ]+/', '', $GLOBALS['_xh']['ac']);
727 727
 					break;
728 728
 				case 'NIL':
729 729
 				case 'EX:NIL':
730 730
 					if ($GLOBALS['xmlrpc_null_extension'])
731 731
 					{
732
-						$GLOBALS['_xh']['vt']='null';
733
-						$GLOBALS['_xh']['value']=null;
734
-						$GLOBALS['_xh']['lv']=3;
732
+						$GLOBALS['_xh']['vt'] = 'null';
733
+						$GLOBALS['_xh']['value'] = null;
734
+						$GLOBALS['_xh']['lv'] = 3;
735 735
 						break;
736 736
 					}
737 737
 					// drop through intentionally if nil extension not enabled
@@ -758,11 +758,11 @@  discard block
 block discarded – undo
758 758
 	function xmlrpc_cd($parser, $data)
759 759
 	{
760 760
 		// skip processing if xml fault already detected
761
-		if ($GLOBALS['_xh']['isf'] < 2)
761
+		if ($GLOBALS['_xh']['isf']<2)
762 762
 		{
763 763
 			// "lookforvalue==3" means that we've found an entire value
764 764
 			// and should discard any further character data
765
-			if($GLOBALS['_xh']['lv']!=3)
765
+			if ($GLOBALS['_xh']['lv'] != 3)
766 766
 			{
767 767
 				// G. Giunta 2006-08-23: useless change of 'lv' from 1 to 2
768 768
 				//if($GLOBALS['_xh']['lv']==1)
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 				//{
777 777
 				//	$GLOBALS['_xh']['ac'] = '';
778 778
 				//}
779
-				$GLOBALS['_xh']['ac'].=$data;
779
+				$GLOBALS['_xh']['ac'] .= $data;
780 780
 			}
781 781
 		}
782 782
 	}
@@ -786,16 +786,16 @@  discard block
 block discarded – undo
786 786
 	function xmlrpc_dh($parser, $data)
787 787
 	{
788 788
 		// skip processing if xml fault already detected
789
-		if ($GLOBALS['_xh']['isf'] < 2)
789
+		if ($GLOBALS['_xh']['isf']<2)
790 790
 		{
791
-			if(substr($data, 0, 1) == '&' && substr($data, -1, 1) == ';')
791
+			if (substr($data, 0, 1) == '&' && substr($data, -1, 1) == ';')
792 792
 			{
793 793
 				// G. Giunta 2006-08-25: useless change of 'lv' from 1 to 2
794 794
 				//if($GLOBALS['_xh']['lv']==1)
795 795
 				//{
796 796
 				//	$GLOBALS['_xh']['lv']=2;
797 797
 				//}
798
-				$GLOBALS['_xh']['ac'].=$data;
798
+				$GLOBALS['_xh']['ac'] .= $data;
799 799
 			}
800 800
 		}
801 801
 		return true;
@@ -805,30 +805,30 @@  discard block
 block discarded – undo
805 805
 	{
806 806
 		var $path;
807 807
 		var $server;
808
-		var $port=0;
809
-		var $method='http';
808
+		var $port = 0;
809
+		var $method = 'http';
810 810
 		var $errno;
811 811
 		var $errstr;
812
-		var $debug=0;
813
-		var $username='';
814
-		var $password='';
815
-		var $authtype=1;
816
-		var $cert='';
817
-		var $certpass='';
818
-		var $cacert='';
819
-		var $cacertdir='';
820
-		var $key='';
821
-		var $keypass='';
822
-		var $verifypeer=true;
823
-		var $verifyhost=1;
824
-		var $no_multicall=false;
825
-		var $proxy='';
826
-		var $proxyport=0;
827
-		var $proxy_user='';
828
-		var $proxy_pass='';
829
-		var $proxy_authtype=1;
830
-		var $cookies=array();
831
-		var $extracurlopts=array();
812
+		var $debug = 0;
813
+		var $username = '';
814
+		var $password = '';
815
+		var $authtype = 1;
816
+		var $cert = '';
817
+		var $certpass = '';
818
+		var $cacert = '';
819
+		var $cacertdir = '';
820
+		var $key = '';
821
+		var $keypass = '';
822
+		var $verifypeer = true;
823
+		var $verifyhost = 1;
824
+		var $no_multicall = false;
825
+		var $proxy = '';
826
+		var $proxyport = 0;
827
+		var $proxy_user = '';
828
+		var $proxy_pass = '';
829
+		var $proxy_authtype = 1;
830
+		var $cookies = array();
831
+		var $extracurlopts = array();
832 832
 
833 833
 		/**
834 834
 		* List of http compression methods accepted by the client for responses.
@@ -872,59 +872,59 @@  discard block
 block discarded – undo
872 872
 		* @param integer $port the port the server is listening on, defaults to 80 or 443 depending on protocol used
873 873
 		* @param string $method the http protocol variant: defaults to 'http', 'https' and 'http11' can be used if CURL is installed
874 874
 		*/
875
-		function __construct($path, $server='', $port='', $method='')
875
+		function __construct($path, $server = '', $port = '', $method = '')
876 876
 		{
877 877
 			// allow user to specify all params in $path
878
-			if($server == '' and $port == '' and $method == '')
878
+			if ($server == '' and $port == '' and $method == '')
879 879
 			{
880 880
 				$parts = parse_url($path);
881 881
 				$server = $parts['host'];
882 882
 				$path = isset($parts['path']) ? $parts['path'] : '';
883
-				if(isset($parts['query']))
883
+				if (isset($parts['query']))
884 884
 				{
885 885
 					$path .= '?'.$parts['query'];
886 886
 				}
887
-				if(isset($parts['fragment']))
887
+				if (isset($parts['fragment']))
888 888
 				{
889 889
 					$path .= '#'.$parts['fragment'];
890 890
 				}
891
-				if(isset($parts['port']))
891
+				if (isset($parts['port']))
892 892
 				{
893 893
 					$port = $parts['port'];
894 894
 				}
895
-				if(isset($parts['scheme']))
895
+				if (isset($parts['scheme']))
896 896
 				{
897 897
 					$method = $parts['scheme'];
898 898
 				}
899
-				if(isset($parts['user']))
899
+				if (isset($parts['user']))
900 900
 				{
901 901
 					$this->username = $parts['user'];
902 902
 				}
903
-				if(isset($parts['pass']))
903
+				if (isset($parts['pass']))
904 904
 				{
905 905
 					$this->password = $parts['pass'];
906 906
 				}
907 907
 			}
908
-			if($path == '' || $path[0] != '/')
908
+			if ($path == '' || $path[0] != '/')
909 909
 			{
910
-				$this->path='/'.$path;
910
+				$this->path = '/'.$path;
911 911
 			}
912 912
 			else
913 913
 			{
914
-				$this->path=$path;
914
+				$this->path = $path;
915 915
 			}
916
-			$this->server=$server;
917
-			if($port != '')
916
+			$this->server = $server;
917
+			if ($port != '')
918 918
 			{
919
-				$this->port=$port;
919
+				$this->port = $port;
920 920
 			}
921
-			if($method != '')
921
+			if ($method != '')
922 922
 			{
923
-				$this->method=$method;
923
+				$this->method = $method;
924 924
 			}
925 925
 
926 926
 			// if ZLIB is enabled, let the client by default accept compressed responses
927
-			if(function_exists('gzinflate') || (
927
+			if (function_exists('gzinflate') || (
928 928
 				function_exists('curl_init') && (($info = curl_version()) &&
929 929
 				((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version'])))
930 930
 			))
@@ -939,13 +939,13 @@  discard block
 block discarded – undo
939 939
 			$this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
940 940
 
941 941
 			// initialize user_agent string
942
-			$this->user_agent = $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion'];
942
+			$this->user_agent = $GLOBALS['xmlrpcName'].' '.$GLOBALS['xmlrpcVersion'];
943 943
 		}
944 944
 
945 945
 		/**
946 946
 		* @deprecated
947 947
 		*/
948
-		function xmlrpc_client($path, $server='', $port='', $method='')
948
+		function xmlrpc_client($path, $server = '', $port = '', $method = '')
949 949
 		{
950 950
 			self::__construct($path, $server, $port, $method);
951 951
 		}
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
 		*/
958 958
 		function setDebug($in)
959 959
 		{
960
-			$this->debug=$in;
960
+			$this->debug = $in;
961 961
 		}
962 962
 
963 963
 		/**
@@ -967,11 +967,11 @@  discard block
 block discarded – undo
967 967
 		* @param integer $t auth type. See curl_setopt man page for supported auth types. Defaults to CURLAUTH_BASIC (basic auth)
968 968
 		* @access public
969 969
 		*/
970
-		function setCredentials($u, $p, $t=1)
970
+		function setCredentials($u, $p, $t = 1)
971 971
 		{
972
-			$this->username=$u;
973
-			$this->password=$p;
974
-			$this->authtype=$t;
972
+			$this->username = $u;
973
+			$this->password = $p;
974
+			$this->authtype = $t;
975 975
 		}
976 976
 
977 977
 		/**
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
 		* @param bool $is_dir set to true to indicate cacert is a dir. defaults to false
994 994
 		* @access public
995 995
 		*/
996
-		function setCaCertificate($cacert, $is_dir=false)
996
+		function setCaCertificate($cacert, $is_dir = false)
997 997
 		{
998 998
 			if ($is_dir)
999 999
 			{
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
 			if ($compmethod == 'any')
1071 1071
 				$this->accepted_compression = array('gzip', 'deflate');
1072 1072
 			else
1073
-				if ($compmethod == false )
1073
+				if ($compmethod == false)
1074 1074
 					$this->accepted_compression = array();
1075 1075
 				else
1076 1076
 					$this->accepted_compression = array($compmethod);
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
 		*
1102 1102
 		* @todo check correctness of urlencoding cookie value (copied from php way of doing it...)
1103 1103
 		*/
1104
-		function setCookie($name, $value='', $path='', $domain='', $port=null)
1104
+		function setCookie($name, $value = '', $path = '', $domain = '', $port = null)
1105 1105
 		{
1106 1106
 			$this->cookies[$name]['value'] = urlencode($value);
1107 1107
 			if ($path || $domain || $port)
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
 		* It allows eg. to bind client to a specific IP interface / address
1123 1123
 		* @param array $options
1124 1124
 		*/
1125
-		function SetCurlOptions( $options )
1125
+		function SetCurlOptions($options)
1126 1126
 		{
1127 1127
 			$this->extracurlopts = $options;
1128 1128
 		}
@@ -1131,7 +1131,7 @@  discard block
 block discarded – undo
1131 1131
 		* Set user-agent string that will be used by this client instance
1132 1132
 		* in http headers sent to the server
1133 1133
 		*/
1134
-		function SetUserAgent( $agentstring )
1134
+		function SetUserAgent($agentstring)
1135 1135
 		{
1136 1136
 			$this->user_agent = $agentstring;
1137 1137
 		}
@@ -1144,22 +1144,22 @@  discard block
 block discarded – undo
1144 1144
 		* @return xmlrpcresp
1145 1145
 		* @access public
1146 1146
 		*/
1147
-		function& send($msg, $timeout=0, $method='')
1147
+		function& send($msg, $timeout = 0, $method = '')
1148 1148
 		{
1149 1149
 			// if user deos not specify http protocol, use native method of this client
1150 1150
 			// (i.e. method set during call to constructor)
1151
-			if($method == '')
1151
+			if ($method == '')
1152 1152
 			{
1153 1153
 				$method = $this->method;
1154 1154
 			}
1155 1155
 
1156
-			if(is_array($msg))
1156
+			if (is_array($msg))
1157 1157
 			{
1158 1158
 				// $msg is an array of xmlrpcmsg's
1159 1159
 				$r = $this->multicall($msg, $timeout, $method);
1160 1160
 				return $r;
1161 1161
 			}
1162
-			elseif(is_string($msg))
1162
+			elseif (is_string($msg))
1163 1163
 			{
1164 1164
 				$n = new xmlrpcmsg('');
1165 1165
 				$n->payload = $msg;
@@ -1167,11 +1167,11 @@  discard block
 block discarded – undo
1167 1167
 			}
1168 1168
 
1169 1169
 			// where msg is an xmlrpcmsg
1170
-			$msg->debug=$this->debug;
1170
+			$msg->debug = $this->debug;
1171 1171
 
1172
-			if($method == 'https')
1172
+			if ($method == 'https')
1173 1173
 			{
1174
-				$r =& $this->sendPayloadHTTPS(
1174
+				$r = & $this->sendPayloadHTTPS(
1175 1175
 					$msg,
1176 1176
 					$this->server,
1177 1177
 					$this->port,
@@ -1193,9 +1193,9 @@  discard block
 block discarded – undo
1193 1193
 					$this->keypass
1194 1194
 				);
1195 1195
 			}
1196
-			elseif($method == 'http11')
1196
+			elseif ($method == 'http11')
1197 1197
 			{
1198
-				$r =& $this->sendPayloadCURL(
1198
+				$r = & $this->sendPayloadCURL(
1199 1199
 					$msg,
1200 1200
 					$this->server,
1201 1201
 					$this->port,
@@ -1218,7 +1218,7 @@  discard block
 block discarded – undo
1218 1218
 			}
1219 1219
 			else
1220 1220
 			{
1221
-				$r =& $this->sendPayloadHTTP10(
1221
+				$r = & $this->sendPayloadHTTP10(
1222 1222
 					$msg,
1223 1223
 					$this->server,
1224 1224
 					$this->port,
@@ -1240,29 +1240,29 @@  discard block
 block discarded – undo
1240 1240
 		/**
1241 1241
 		* @access private
1242 1242
 		*/
1243
-		function &sendPayloadHTTP10($msg, $server, $port, $timeout=0,
1244
-			$username='', $password='', $authtype=1, $proxyhost='',
1245
-			$proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1)
1243
+		function &sendPayloadHTTP10($msg, $server, $port, $timeout = 0,
1244
+			$username = '', $password = '', $authtype = 1, $proxyhost = '',
1245
+			$proxyport = 0, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1)
1246 1246
 		{
1247
-			if($port==0)
1247
+			if ($port == 0)
1248 1248
 			{
1249
-				$port=80;
1249
+				$port = 80;
1250 1250
 			}
1251 1251
 
1252 1252
 			// Only create the payload if it was not created previously
1253
-			if(empty($msg->payload))
1253
+			if (empty($msg->payload))
1254 1254
 			{
1255 1255
 				$msg->createPayload($this->request_charset_encoding);
1256 1256
 			}
1257 1257
 
1258 1258
 			$payload = $msg->payload;
1259 1259
 			// Deflate request body and set appropriate request headers
1260
-			if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
1260
+			if (function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
1261 1261
 			{
1262
-				if($this->request_compression == 'gzip')
1262
+				if ($this->request_compression == 'gzip')
1263 1263
 				{
1264 1264
 					$a = @gzencode($payload);
1265
-					if($a)
1265
+					if ($a)
1266 1266
 					{
1267 1267
 						$payload = $a;
1268 1268
 						$encoding_hdr = "Content-Encoding: gzip\r\n";
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
 				else
1272 1272
 				{
1273 1273
 					$a = @gzcompress($payload);
1274
-					if($a)
1274
+					if ($a)
1275 1275
 					{
1276 1276
 						$payload = $a;
1277 1277
 						$encoding_hdr = "Content-Encoding: deflate\r\n";
@@ -1284,10 +1284,10 @@  discard block
 block discarded – undo
1284 1284
 			}
1285 1285
 
1286 1286
 			// thanks to Grant Rauscher <[email protected]> for this
1287
-			$credentials='';
1288
-			if($username!='')
1287
+			$credentials = '';
1288
+			if ($username != '')
1289 1289
 			{
1290
-				$credentials='Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
1290
+				$credentials = 'Authorization: Basic '.base64_encode($username.':'.$password)."\r\n";
1291 1291
 				if ($authtype != 1)
1292 1292
 				{
1293 1293
 					error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported with HTTP 1.0');
@@ -1295,28 +1295,28 @@  discard block
 block discarded – undo
1295 1295
 			}
1296 1296
 
1297 1297
 			$accepted_encoding = '';
1298
-			if(is_array($this->accepted_compression) && count($this->accepted_compression))
1298
+			if (is_array($this->accepted_compression) && count($this->accepted_compression))
1299 1299
 			{
1300
-				$accepted_encoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n";
1300
+				$accepted_encoding = 'Accept-Encoding: '.implode(', ', $this->accepted_compression)."\r\n";
1301 1301
 			}
1302 1302
 
1303 1303
 			$proxy_credentials = '';
1304
-			if($proxyhost)
1304
+			if ($proxyhost)
1305 1305
 			{
1306
-				if($proxyport == 0)
1306
+				if ($proxyport == 0)
1307 1307
 				{
1308 1308
 					$proxyport = 8080;
1309 1309
 				}
1310 1310
 				$connectserver = $proxyhost;
1311 1311
 				$connectport = $proxyport;
1312 1312
 				$uri = 'http://'.$server.':'.$port.$this->path;
1313
-				if($proxyusername != '')
1313
+				if ($proxyusername != '')
1314 1314
 				{
1315 1315
 					if ($proxyauthtype != 1)
1316 1316
 					{
1317 1317
 						error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported with HTTP 1.0');
1318 1318
 					}
1319
-					$proxy_credentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyusername.':'.$proxypassword) . "\r\n";
1319
+					$proxy_credentials = 'Proxy-Authorization: Basic '.base64_encode($proxyusername.':'.$proxypassword)."\r\n";
1320 1320
 				}
1321 1321
 			}
1322 1322
 			else
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
 
1329 1329
 			// Cookie generation, as per rfc2965 (version 1 cookies) or
1330 1330
 			// netscape's rules (version 0 cookies)
1331
-			$cookieheader='';
1331
+			$cookieheader = '';
1332 1332
 			if (count($this->cookies))
1333 1333
 			{
1334 1334
 				$version = '';
@@ -1336,73 +1336,73 @@  discard block
 block discarded – undo
1336 1336
 				{
1337 1337
 					if ($cookie['version'])
1338 1338
 					{
1339
-						$version = ' $Version="' . $cookie['version'] . '";';
1340
-						$cookieheader .= ' ' . $name . '="' . $cookie['value'] . '";';
1339
+						$version = ' $Version="'.$cookie['version'].'";';
1340
+						$cookieheader .= ' '.$name.'="'.$cookie['value'].'";';
1341 1341
 						if ($cookie['path'])
1342
-							$cookieheader .= ' $Path="' . $cookie['path'] . '";';
1342
+							$cookieheader .= ' $Path="'.$cookie['path'].'";';
1343 1343
 						if ($cookie['domain'])
1344
-							$cookieheader .= ' $Domain="' . $cookie['domain'] . '";';
1344
+							$cookieheader .= ' $Domain="'.$cookie['domain'].'";';
1345 1345
 						if ($cookie['port'])
1346
-							$cookieheader .= ' $Port="' . $cookie['port'] . '";';
1346
+							$cookieheader .= ' $Port="'.$cookie['port'].'";';
1347 1347
 					}
1348 1348
 					else
1349 1349
 					{
1350
-						$cookieheader .= ' ' . $name . '=' . $cookie['value'] . ";";
1350
+						$cookieheader .= ' '.$name.'='.$cookie['value'].";";
1351 1351
 					}
1352 1352
 				}
1353
-				$cookieheader = 'Cookie:' . $version . substr($cookieheader, 0, -1) . "\r\n";
1353
+				$cookieheader = 'Cookie:'.$version.substr($cookieheader, 0, -1)."\r\n";
1354 1354
 			}
1355 1355
 
1356 1356
 			// omit port if 80
1357
-			$port = ($port == 80) ? '' : (':' . $port);
1358
-
1359
-			$op= 'POST ' . $uri. " HTTP/1.0\r\n" .
1360
-				'User-Agent: ' . $this->user_agent . "\r\n" .
1361
-				'Host: '. $server . $port . "\r\n" .
1362
-				$credentials .
1363
-				$proxy_credentials .
1364
-				$accepted_encoding .
1365
-				$encoding_hdr .
1366
-				'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings) . "\r\n" .
1367
-				$cookieheader .
1368
-				'Content-Type: ' . $msg->content_type . "\r\nContent-Length: " .
1369
-				strlen($payload) . "\r\n\r\n" .
1357
+			$port = ($port == 80) ? '' : (':'.$port);
1358
+
1359
+			$op = 'POST '.$uri." HTTP/1.0\r\n".
1360
+				'User-Agent: '.$this->user_agent."\r\n".
1361
+				'Host: '.$server.$port."\r\n".
1362
+				$credentials.
1363
+				$proxy_credentials.
1364
+				$accepted_encoding.
1365
+				$encoding_hdr.
1366
+				'Accept-Charset: '.implode(',', $this->accepted_charset_encodings)."\r\n".
1367
+				$cookieheader.
1368
+				'Content-Type: '.$msg->content_type."\r\nContent-Length: ".
1369
+				strlen($payload)."\r\n\r\n".
1370 1370
 				$payload;
1371 1371
 
1372
-			if($this->debug > 1)
1372
+			if ($this->debug>1)
1373 1373
 			{
1374
-				print "<PRE>\n---SENDING---\n" . htmlentities($op) . "\n---END---\n</PRE>";
1374
+				print "<PRE>\n---SENDING---\n".htmlentities($op)."\n---END---\n</PRE>";
1375 1375
 				// let the client see this now in case http times out...
1376 1376
 				flush();
1377 1377
 			}
1378 1378
 
1379
-			if($timeout>0)
1379
+			if ($timeout>0)
1380 1380
 			{
1381
-				$fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout);
1381
+				$fp = @fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout);
1382 1382
 			}
1383 1383
 			else
1384 1384
 			{
1385
-				$fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr);
1385
+				$fp = @fsockopen($connectserver, $connectport, $this->errno, $this->errstr);
1386 1386
 			}
1387
-			if($fp)
1387
+			if ($fp)
1388 1388
 			{
1389
-				if($timeout>0 && function_exists('stream_set_timeout'))
1389
+				if ($timeout>0 && function_exists('stream_set_timeout'))
1390 1390
 				{
1391 1391
 					stream_set_timeout($fp, $timeout);
1392 1392
 				}
1393 1393
 			}
1394 1394
 			else
1395 1395
 			{
1396
-				$this->errstr='Connect error: '.$this->errstr;
1397
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr . ' (' . $this->errno . ')');
1396
+				$this->errstr = 'Connect error: '.$this->errstr;
1397
+				$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr.' ('.$this->errno.')');
1398 1398
 				return $r;
1399 1399
 			}
1400 1400
 
1401
-			if(!fputs($fp, $op, strlen($op)))
1401
+			if (!fputs($fp, $op, strlen($op)))
1402 1402
 			{
1403 1403
 				fclose($fp);
1404
-				$this->errstr='Write error';
1405
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr);
1404
+				$this->errstr = 'Write error';
1405
+				$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $this->errstr);
1406 1406
 				return $r;
1407 1407
 			}
1408 1408
 			else
@@ -1412,15 +1412,15 @@  discard block
 block discarded – undo
1412 1412
 			}
1413 1413
 			// G. Giunta 2005/10/24: close socket before parsing.
1414 1414
 			// should yield slightly better execution times, and make easier recursive calls (e.g. to follow http redirects)
1415
-			$ipd='';
1415
+			$ipd = '';
1416 1416
 			do
1417 1417
 			{
1418 1418
 				// shall we check for $data === FALSE?
1419 1419
 				// as per the manual, it signals an error
1420
-				$ipd.=fread($fp, 32768);
1421
-			} while(!feof($fp));
1420
+				$ipd .= fread($fp, 32768);
1421
+			} while (!feof($fp));
1422 1422
 			fclose($fp);
1423
-			$r =& $msg->parseResponse($ipd, false, $this->return_type);
1423
+			$r = & $msg->parseResponse($ipd, false, $this->return_type);
1424 1424
 			return $r;
1425 1425
 
1426 1426
 		}
@@ -1428,12 +1428,12 @@  discard block
 block discarded – undo
1428 1428
 		/**
1429 1429
 		* @access private
1430 1430
 		*/
1431
-		function &sendPayloadHTTPS($msg, $server, $port, $timeout=0, $username='',
1432
-			$password='', $authtype=1, $cert='',$certpass='', $cacert='', $cacertdir='',
1433
-			$proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1,
1434
-			$keepalive=false, $key='', $keypass='')
1431
+		function &sendPayloadHTTPS($msg, $server, $port, $timeout = 0, $username = '',
1432
+			$password = '', $authtype = 1, $cert = '', $certpass = '', $cacert = '', $cacertdir = '',
1433
+			$proxyhost = '', $proxyport = 0, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1,
1434
+			$keepalive = false, $key = '', $keypass = '')
1435 1435
 		{
1436
-			$r =& $this->sendPayloadCURL($msg, $server, $port, $timeout, $username,
1436
+			$r = & $this->sendPayloadCURL($msg, $server, $port, $timeout, $username,
1437 1437
 				$password, $authtype, $cert, $certpass, $cacert, $cacertdir, $proxyhost, $proxyport,
1438 1438
 				$proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass);
1439 1439
 			return $r;
@@ -1445,31 +1445,31 @@  discard block
 block discarded – undo
1445 1445
 		* NB: CURL versions before 7.11.10 cannot use proxy to talk to https servers!
1446 1446
 		* @access private
1447 1447
 		*/
1448
-		function &sendPayloadCURL($msg, $server, $port, $timeout=0, $username='',
1449
-			$password='', $authtype=1, $cert='', $certpass='', $cacert='', $cacertdir='',
1450
-			$proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1, $method='https',
1451
-			$keepalive=false, $key='', $keypass='')
1448
+		function &sendPayloadCURL($msg, $server, $port, $timeout = 0, $username = '',
1449
+			$password = '', $authtype = 1, $cert = '', $certpass = '', $cacert = '', $cacertdir = '',
1450
+			$proxyhost = '', $proxyport = 0, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1, $method = 'https',
1451
+			$keepalive = false, $key = '', $keypass = '')
1452 1452
 		{
1453
-			if(!function_exists('curl_init'))
1453
+			if (!function_exists('curl_init'))
1454 1454
 			{
1455
-				$this->errstr='CURL unavailable on this install';
1456
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_curl'], $GLOBALS['xmlrpcstr']['no_curl']);
1455
+				$this->errstr = 'CURL unavailable on this install';
1456
+				$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_curl'], $GLOBALS['xmlrpcstr']['no_curl']);
1457 1457
 				return $r;
1458 1458
 			}
1459
-			if($method == 'https')
1459
+			if ($method == 'https')
1460 1460
 			{
1461
-				if(($info = curl_version()) &&
1461
+				if (($info = curl_version()) &&
1462 1462
 					((is_string($info) && strpos($info, 'OpenSSL') === null) || (is_array($info) && !isset($info['ssl_version']))))
1463 1463
 				{
1464
-					$this->errstr='SSL unavailable on this install';
1465
-					$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_ssl'], $GLOBALS['xmlrpcstr']['no_ssl']);
1464
+					$this->errstr = 'SSL unavailable on this install';
1465
+					$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_ssl'], $GLOBALS['xmlrpcstr']['no_ssl']);
1466 1466
 					return $r;
1467 1467
 				}
1468 1468
 			}
1469 1469
 
1470
-			if($port == 0)
1470
+			if ($port == 0)
1471 1471
 			{
1472
-				if($method == 'http')
1472
+				if ($method == 'http')
1473 1473
 				{
1474 1474
 					$port = 80;
1475 1475
 				}
@@ -1480,19 +1480,19 @@  discard block
 block discarded – undo
1480 1480
 			}
1481 1481
 
1482 1482
 			// Only create the payload if it was not created previously
1483
-			if(empty($msg->payload))
1483
+			if (empty($msg->payload))
1484 1484
 			{
1485 1485
 				$msg->createPayload($this->request_charset_encoding);
1486 1486
 			}
1487 1487
 
1488 1488
 			// Deflate request body and set appropriate request headers
1489 1489
 			$payload = $msg->payload;
1490
-			if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
1490
+			if (function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
1491 1491
 			{
1492
-				if($this->request_compression == 'gzip')
1492
+				if ($this->request_compression == 'gzip')
1493 1493
 				{
1494 1494
 					$a = @gzencode($payload);
1495
-					if($a)
1495
+					if ($a)
1496 1496
 					{
1497 1497
 						$payload = $a;
1498 1498
 						$encoding_hdr = 'Content-Encoding: gzip';
@@ -1501,7 +1501,7 @@  discard block
 block discarded – undo
1501 1501
 				else
1502 1502
 				{
1503 1503
 					$a = @gzcompress($payload);
1504
-					if($a)
1504
+					if ($a)
1505 1505
 					{
1506 1506
 						$payload = $a;
1507 1507
 						$encoding_hdr = 'Content-Encoding: deflate';
@@ -1513,17 +1513,17 @@  discard block
 block discarded – undo
1513 1513
 				$encoding_hdr = '';
1514 1514
 			}
1515 1515
 
1516
-			if($this->debug > 1)
1516
+			if ($this->debug>1)
1517 1517
 			{
1518
-				print "<PRE>\n---SENDING---\n" . htmlentities($payload) . "\n---END---\n</PRE>";
1518
+				print "<PRE>\n---SENDING---\n".htmlentities($payload)."\n---END---\n</PRE>";
1519 1519
 				// let the client see this now in case http times out...
1520 1520
 				flush();
1521 1521
 			}
1522 1522
 
1523
-			if(!$keepalive || !$this->xmlrpc_curl_handle)
1523
+			if (!$keepalive || !$this->xmlrpc_curl_handle)
1524 1524
 			{
1525
-				$curl = curl_init($method . '://' . $server . ':' . $port . $this->path);
1526
-				if($keepalive)
1525
+				$curl = curl_init($method.'://'.$server.':'.$port.$this->path);
1526
+				if ($keepalive)
1527 1527
 				{
1528 1528
 					$this->xmlrpc_curl_handle = $curl;
1529 1529
 				}
@@ -1536,7 +1536,7 @@  discard block
 block discarded – undo
1536 1536
 			// results into variable
1537 1537
 			curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1538 1538
 
1539
-			if($this->debug)
1539
+			if ($this->debug)
1540 1540
 			{
1541 1541
 				curl_setopt($curl, CURLOPT_VERBOSE, 1);
1542 1542
 			}
@@ -1552,7 +1552,7 @@  discard block
 block discarded – undo
1552 1552
 			// NB: if we set an empty string, CURL will add http header indicating
1553 1553
 			// ALL methods it is supporting. This is possibly a better option than
1554 1554
 			// letting the user tell what curl can / cannot do...
1555
-			if(is_array($this->accepted_compression) && count($this->accepted_compression))
1555
+			if (is_array($this->accepted_compression) && count($this->accepted_compression))
1556 1556
 			{
1557 1557
 				//curl_setopt($curl, CURLOPT_ENCODING, implode(',', $this->accepted_compression));
1558 1558
 				// empty string means 'any supported by CURL' (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
@@ -1564,26 +1564,26 @@  discard block
 block discarded – undo
1564 1564
 					curl_setopt($curl, CURLOPT_ENCODING, '');
1565 1565
 			}
1566 1566
 			// extra headers
1567
-			$headers = array('Content-Type: ' . $msg->content_type , 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings));
1567
+			$headers = array('Content-Type: '.$msg->content_type, 'Accept-Charset: '.implode(',', $this->accepted_charset_encodings));
1568 1568
 			// if no keepalive is wanted, let the server know it in advance
1569
-			if(!$keepalive)
1569
+			if (!$keepalive)
1570 1570
 			{
1571 1571
 				$headers[] = 'Connection: close';
1572 1572
 			}
1573 1573
 			// request compression header
1574
-			if($encoding_hdr)
1574
+			if ($encoding_hdr)
1575 1575
 			{
1576 1576
 				$headers[] = $encoding_hdr;
1577 1577
 			}
1578 1578
 
1579 1579
 			curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
1580 1580
 			// timeout is borked
1581
-			if($timeout)
1581
+			if ($timeout)
1582 1582
 			{
1583
-				curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);
1583
+				curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout-1);
1584 1584
 			}
1585 1585
 
1586
-			if($username && $password)
1586
+			if ($username && $password)
1587 1587
 			{
1588 1588
 				curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password);
1589 1589
 				if (defined('CURLOPT_HTTPAUTH'))
@@ -1596,43 +1596,43 @@  discard block
 block discarded – undo
1596 1596
 				}
1597 1597
 			}
1598 1598
 
1599
-			if($method == 'https')
1599
+			if ($method == 'https')
1600 1600
 			{
1601 1601
 				// set cert file
1602
-				if($cert)
1602
+				if ($cert)
1603 1603
 				{
1604 1604
 					curl_setopt($curl, CURLOPT_SSLCERT, $cert);
1605 1605
 				}
1606 1606
 				// set cert password
1607
-				if($certpass)
1607
+				if ($certpass)
1608 1608
 				{
1609 1609
 					curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $certpass);
1610 1610
 				}
1611 1611
 				// whether to verify remote host's cert
1612 1612
 				curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
1613 1613
 				// set ca certificates file/dir
1614
-				if($cacert)
1614
+				if ($cacert)
1615 1615
 				{
1616 1616
 					curl_setopt($curl, CURLOPT_CAINFO, $cacert);
1617 1617
 				}
1618
-				if($cacertdir)
1618
+				if ($cacertdir)
1619 1619
 				{
1620 1620
 					curl_setopt($curl, CURLOPT_CAPATH, $cacertdir);
1621 1621
 				}
1622 1622
 				// set key file (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
1623
-				if($key)
1623
+				if ($key)
1624 1624
 				{
1625 1625
 					curl_setopt($curl, CURLOPT_SSLKEY, $key);
1626 1626
 				}
1627 1627
 				// set key password (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
1628
-				if($keypass)
1628
+				if ($keypass)
1629 1629
 				{
1630 1630
 					curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $keypass);
1631 1631
 				}
1632 1632
 
1633 1633
 				// Upgrade transparently to more stringent check for versions of php which do not support otherwise.
1634 1634
 				// Doing it in constructor would be cleaner; doing it here saves us a couple of function calls
1635
-				if($this->verifyhost == 1 && $info = curl_version() && version_compare($info['version'], '7.28.1') >= 0)
1635
+				if ($this->verifyhost == 1 && $info = curl_version() && version_compare($info['version'], '7.28.1')>=0)
1636 1636
 				{
1637 1637
 					$this->verifyhost = 2;
1638 1638
 				}
@@ -1641,15 +1641,15 @@  discard block
 block discarded – undo
1641 1641
 			}
1642 1642
 
1643 1643
 			// proxy info
1644
-			if($proxyhost)
1644
+			if ($proxyhost)
1645 1645
 			{
1646
-				if($proxyport == 0)
1646
+				if ($proxyport == 0)
1647 1647
 				{
1648 1648
 					$proxyport = 8080; // NB: even for HTTPS, local connection is on port 8080
1649 1649
 				}
1650 1650
 				curl_setopt($curl, CURLOPT_PROXY, $proxyhost.':'.$proxyport);
1651 1651
 				//curl_setopt($curl, CURLOPT_PROXYPORT,$proxyport);
1652
-				if($proxyusername)
1652
+				if ($proxyusername)
1653 1653
 				{
1654 1654
 					curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyusername.':'.$proxypassword);
1655 1655
 					if (defined('CURLOPT_PROXYAUTH'))
@@ -1671,7 +1671,7 @@  discard block
 block discarded – undo
1671 1671
 				$cookieheader = '';
1672 1672
 				foreach ($this->cookies as $name => $cookie)
1673 1673
 				{
1674
-					$cookieheader .= $name . '=' . $cookie['value'] . '; ';
1674
+					$cookieheader .= $name.'='.$cookie['value'].'; ';
1675 1675
 				}
1676 1676
 				curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2));
1677 1677
 			}
@@ -1683,40 +1683,40 @@  discard block
 block discarded – undo
1683 1683
 
1684 1684
 			$result = curl_exec($curl);
1685 1685
 
1686
-			if ($this->debug > 1)
1686
+			if ($this->debug>1)
1687 1687
 			{
1688 1688
 				print "<PRE>\n---CURL INFO---\n";
1689
-				foreach(curl_getinfo($curl) as $name => $val)
1689
+				foreach (curl_getinfo($curl) as $name => $val)
1690 1690
 				{
1691 1691
 					if (is_array($val))
1692 1692
 					{
1693 1693
 						$val = implode("\n", $val);
1694 1694
 					}
1695
-					print $name . ': ' . htmlentities($val) . "\n";
1695
+					print $name.': '.htmlentities($val)."\n";
1696 1696
 				}
1697 1697
 
1698 1698
 				print "---END---\n</PRE>";
1699 1699
 			}
1700 1700
 
1701
-			if(!$result) /// @todo we should use a better check here - what if we get back '' or '0'?
1701
+			if (!$result) /// @todo we should use a better check here - what if we get back '' or '0'?
1702 1702
 			{
1703
-				$this->errstr='no response';
1704
-				$resp=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['curl_fail'], $GLOBALS['xmlrpcstr']['curl_fail']. ': '. curl_error($curl));
1703
+				$this->errstr = 'no response';
1704
+				$resp = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['curl_fail'], $GLOBALS['xmlrpcstr']['curl_fail'].': '.curl_error($curl));
1705 1705
 				curl_close($curl);
1706
-				if($keepalive)
1706
+				if ($keepalive)
1707 1707
 				{
1708 1708
 					$this->xmlrpc_curl_handle = null;
1709 1709
 				}
1710 1710
 			}
1711 1711
 			else
1712 1712
 			{
1713
-				if(!$keepalive)
1713
+				if (!$keepalive)
1714 1714
 				{
1715 1715
 					curl_close($curl);
1716 1716
 				}
1717
-				$resp =& $msg->parseResponse($result, true, $this->return_type);
1717
+				$resp = & $msg->parseResponse($result, true, $this->return_type);
1718 1718
 				// if we got back a 302, we can not reuse the curl handle for later calls
1719
-				if($resp->faultCode() == $GLOBALS['xmlrpcerr']['http_error'] && $keepalive)
1719
+				if ($resp->faultCode() == $GLOBALS['xmlrpcerr']['http_error'] && $keepalive)
1720 1720
 				{
1721 1721
 					curl_close($curl);
1722 1722
 					$this->xmlrpc_curl_handle = null;
@@ -1747,16 +1747,16 @@  discard block
 block discarded – undo
1747 1747
 		* @return array
1748 1748
 		* @access public
1749 1749
 		*/
1750
-		function multicall($msgs, $timeout=0, $method='', $fallback=true)
1750
+		function multicall($msgs, $timeout = 0, $method = '', $fallback = true)
1751 1751
 		{
1752 1752
 			if ($method == '')
1753 1753
 			{
1754 1754
 				$method = $this->method;
1755 1755
 			}
1756
-			if(!$this->no_multicall)
1756
+			if (!$this->no_multicall)
1757 1757
 			{
1758 1758
 				$results = $this->_try_multicall($msgs, $timeout, $method);
1759
-				if(is_array($results))
1759
+				if (is_array($results))
1760 1760
 				{
1761 1761
 					// System.multicall succeeded
1762 1762
 					return $results;
@@ -1795,9 +1795,9 @@  discard block
 block discarded – undo
1795 1795
 			{
1796 1796
 				// system.multicall is (probably) unsupported by server:
1797 1797
 				// emulate multicall via multiple requests
1798
-				foreach($msgs as $msg)
1798
+				foreach ($msgs as $msg)
1799 1799
 				{
1800
-					$results[] =& $this->send($msg, $timeout, $method);
1800
+					$results[] = & $this->send($msg, $timeout, $method);
1801 1801
 				}
1802 1802
 			}
1803 1803
 			else
@@ -1805,7 +1805,7 @@  discard block
 block discarded – undo
1805 1805
 				// user does NOT want to fallback on many single calls:
1806 1806
 				// since we should always return an array of responses,
1807 1807
 				// return an array with the same error repeated n times
1808
-				foreach($msgs as $msg)
1808
+				foreach ($msgs as $msg)
1809 1809
 				{
1810 1810
 					$results[] = $result;
1811 1811
 				}
@@ -1823,12 +1823,12 @@  discard block
 block discarded – undo
1823 1823
 		{
1824 1824
 			// Construct multicall message
1825 1825
 			$calls = array();
1826
-			foreach($msgs as $msg)
1826
+			foreach ($msgs as $msg)
1827 1827
 			{
1828
-				$call['methodName'] = new xmlrpcval($msg->method(),'string');
1828
+				$call['methodName'] = new xmlrpcval($msg->method(), 'string');
1829 1829
 				$numParams = $msg->getNumParams();
1830 1830
 				$params = array();
1831
-				for($i = 0; $i < $numParams; $i++)
1831
+				for ($i = 0; $i<$numParams; $i++)
1832 1832
 				{
1833 1833
 					$params[$i] = $msg->getParam($i);
1834 1834
 				}
@@ -1839,9 +1839,9 @@  discard block
 block discarded – undo
1839 1839
 			$multicall->addParam(new xmlrpcval($calls, 'array'));
1840 1840
 
1841 1841
 			// Attempt RPC call
1842
-			$result =& $this->send($multicall, $timeout, $method);
1842
+			$result = & $this->send($multicall, $timeout, $method);
1843 1843
 
1844
-			if($result->faultCode() != 0)
1844
+			if ($result->faultCode() != 0)
1845 1845
 			{
1846 1846
 				// call to system.multicall failed
1847 1847
 				return $result;
@@ -1858,29 +1858,29 @@  discard block
 block discarded – undo
1858 1858
 			{
1859 1859
 				///@todo test this code branch...
1860 1860
 				$rets = $result->value();
1861
-				if(!is_array($rets))
1861
+				if (!is_array($rets))
1862 1862
 				{
1863
-					return false;		// bad return type from system.multicall
1863
+					return false; // bad return type from system.multicall
1864 1864
 				}
1865 1865
 				$numRets = count($rets);
1866
-				if($numRets != count($msgs))
1866
+				if ($numRets != count($msgs))
1867 1867
 				{
1868
-					return false;		// wrong number of return values.
1868
+					return false; // wrong number of return values.
1869 1869
 				}
1870 1870
 
1871 1871
 				$response = array();
1872
-				for($i = 0; $i < $numRets; $i++)
1872
+				for ($i = 0; $i<$numRets; $i++)
1873 1873
 				{
1874 1874
 					$val = $rets[$i];
1875 1875
 					if (!is_array($val)) {
1876 1876
 						return false;
1877 1877
 					}
1878
-					switch(count($val))
1878
+					switch (count($val))
1879 1879
 					{
1880 1880
 						case 1:
1881
-							if(!isset($val[0]))
1881
+							if (!isset($val[0]))
1882 1882
 							{
1883
-								return false;		// Bad value
1883
+								return false; // Bad value
1884 1884
 							}
1885 1885
 							// Normal return value
1886 1886
 							$response[$i] = new xmlrpcresp($val[0], 0, '', 'phpvals');
@@ -1888,12 +1888,12 @@  discard block
 block discarded – undo
1888 1888
 						case 2:
1889 1889
 							///	@todo remove usage of @: it is apparently quite slow
1890 1890
 							$code = @$val['faultCode'];
1891
-							if(!is_int($code))
1891
+							if (!is_int($code))
1892 1892
 							{
1893 1893
 								return false;
1894 1894
 							}
1895 1895
 							$str = @$val['faultString'];
1896
-							if(!is_string($str))
1896
+							if (!is_string($str))
1897 1897
 							{
1898 1898
 								return false;
1899 1899
 							}
@@ -1908,38 +1908,38 @@  discard block
 block discarded – undo
1908 1908
 			else // return type == 'xmlrpcvals'
1909 1909
 			{
1910 1910
 				$rets = $result->value();
1911
-				if($rets->kindOf() != 'array')
1911
+				if ($rets->kindOf() != 'array')
1912 1912
 				{
1913
-					return false;		// bad return type from system.multicall
1913
+					return false; // bad return type from system.multicall
1914 1914
 				}
1915 1915
 				$numRets = $rets->arraysize();
1916
-				if($numRets != count($msgs))
1916
+				if ($numRets != count($msgs))
1917 1917
 				{
1918
-					return false;		// wrong number of return values.
1918
+					return false; // wrong number of return values.
1919 1919
 				}
1920 1920
 
1921 1921
 				$response = array();
1922
-				for($i = 0; $i < $numRets; $i++)
1922
+				for ($i = 0; $i<$numRets; $i++)
1923 1923
 				{
1924 1924
 					$val = $rets->arraymem($i);
1925
-					switch($val->kindOf())
1925
+					switch ($val->kindOf())
1926 1926
 					{
1927 1927
 						case 'array':
1928
-							if($val->arraysize() != 1)
1928
+							if ($val->arraysize() != 1)
1929 1929
 							{
1930
-								return false;		// Bad value
1930
+								return false; // Bad value
1931 1931
 							}
1932 1932
 							// Normal return value
1933 1933
 							$response[$i] = new xmlrpcresp($val->arraymem(0));
1934 1934
 							break;
1935 1935
 						case 'struct':
1936 1936
 							$code = $val->structmem('faultCode');
1937
-							if($code->kindOf() != 'scalar' || $code->scalartyp() != 'int')
1937
+							if ($code->kindOf() != 'scalar' || $code->scalartyp() != 'int')
1938 1938
 							{
1939 1939
 								return false;
1940 1940
 							}
1941 1941
 							$str = $val->structmem('faultString');
1942
-							if($str->kindOf() != 'scalar' || $str->scalartyp() != 'string')
1942
+							if ($str->kindOf() != 'scalar' || $str->scalartyp() != 'string')
1943 1943
 							{
1944 1944
 								return false;
1945 1945
 							}
@@ -1976,9 +1976,9 @@  discard block
 block discarded – undo
1976 1976
 		* NB: as of now we do not do it, since it might be either an xmlrpcval or a plain
1977 1977
 		* php val, or a complete xml chunk, depending on usage of xmlrpc_client::send() inside which creator is called...
1978 1978
 		*/
1979
-		function __construct($val, $fcode = 0, $fstr = '', $valtyp='')
1979
+		function __construct($val, $fcode = 0, $fstr = '', $valtyp = '')
1980 1980
 		{
1981
-			if($fcode != 0)
1981
+			if ($fcode != 0)
1982 1982
 			{
1983 1983
 				// error response
1984 1984
 				$this->errno = $fcode;
@@ -2017,7 +2017,7 @@  discard block
 block discarded – undo
2017 2017
 		/**
2018 2018
 		* @deprecated
2019 2019
 		*/
2020
-		function xmlrpcresp($val, $fcode = 0, $fstr = '', $valtyp='')
2020
+		function xmlrpcresp($val, $fcode = 0, $fstr = '', $valtyp = '')
2021 2021
 		{
2022 2022
 			self::__construct($val, $fcode, $fstr, $valtyp);
2023 2023
 		}
@@ -2074,10 +2074,10 @@  discard block
 block discarded – undo
2074 2074
 		* @return string the xml representation of the response
2075 2075
 		* @access public
2076 2076
 		*/
2077
-		function serialize($charset_encoding='')
2077
+		function serialize($charset_encoding = '')
2078 2078
 		{
2079 2079
 			if ($charset_encoding != '')
2080
-				$this->content_type = 'text/xml; charset=' . $charset_encoding;
2080
+				$this->content_type = 'text/xml; charset='.$charset_encoding;
2081 2081
 			else
2082 2082
 				$this->content_type = 'text/xml';
2083 2083
 			if ($GLOBALS['xmlrpc_null_apache_encoding'])
@@ -2088,24 +2088,24 @@  discard block
 block discarded – undo
2088 2088
 			{
2089 2089
 			$result = "<methodResponse>\n";
2090 2090
 			}
2091
-			if($this->errno)
2091
+			if ($this->errno)
2092 2092
 			{
2093 2093
 				// G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
2094 2094
 				// by xml-encoding non ascii chars
2095
-				$result .= "<fault>\n" .
2096
-"<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
2097
-"</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
2098
-xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</string></value>\n</member>\n" .
2095
+				$result .= "<fault>\n".
2096
+"<value>\n<struct><member><name>faultCode</name>\n<value><int>".$this->errno.
2097
+"</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>".
2098
+xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding)."</string></value>\n</member>\n".
2099 2099
 "</struct>\n</value>\n</fault>";
2100 2100
 			}
2101 2101
 			else
2102 2102
 			{
2103
-				if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
2103
+				if (!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
2104 2104
 				{
2105 2105
 					if (is_string($this->val) && $this->valtyp == 'xml')
2106 2106
 					{
2107
-						$result .= "<params>\n<param>\n" .
2108
-							$this->val .
2107
+						$result .= "<params>\n<param>\n".
2108
+							$this->val.
2109 2109
 							"</param>\n</params>";
2110 2110
 					}
2111 2111
 					else
@@ -2116,8 +2116,8 @@  discard block
 block discarded – undo
2116 2116
 				}
2117 2117
 				else
2118 2118
 				{
2119
-					$result .= "<params>\n<param>\n" .
2120
-						$this->val->serialize($charset_encoding) .
2119
+					$result .= "<params>\n<param>\n".
2120
+						$this->val->serialize($charset_encoding).
2121 2121
 						"</param>\n</params>";
2122 2122
 				}
2123 2123
 			}
@@ -2131,20 +2131,20 @@  discard block
 block discarded – undo
2131 2131
 	{
2132 2132
 		var $payload;
2133 2133
 		var $methodname;
2134
-		var $params=array();
2135
-		var $debug=0;
2134
+		var $params = array();
2135
+		var $debug = 0;
2136 2136
 		var $content_type = 'text/xml';
2137 2137
 
2138 2138
 		/**
2139 2139
 		* @param string $meth the name of the method to invoke
2140 2140
 		* @param array $pars array of parameters to be passed to the method (xmlrpcval objects)
2141 2141
 		*/
2142
-		function __construct($meth, $pars=0)
2142
+		function __construct($meth, $pars = 0)
2143 2143
 		{
2144
-			$this->methodname=$meth;
2145
-			if(is_array($pars) && count($pars)>0)
2144
+			$this->methodname = $meth;
2145
+			if (is_array($pars) && count($pars)>0)
2146 2146
 			{
2147
-				for($i=0; $i<count($pars); $i++)
2147
+				for ($i = 0; $i<count($pars); $i++)
2148 2148
 				{
2149 2149
 					$this->addParam($pars[$i]);
2150 2150
 				}
@@ -2154,7 +2154,7 @@  discard block
 block discarded – undo
2154 2154
 				/**
2155 2155
 		* @deprecated
2156 2156
 		*/
2157
-		function xmlrpcmsg($meth, $pars=0)
2157
+		function xmlrpcmsg($meth, $pars = 0)
2158 2158
 		{
2159 2159
 			self::__construct($meth, $pars);
2160 2160
 		}
@@ -2162,15 +2162,15 @@  discard block
 block discarded – undo
2162 2162
 		/**
2163 2163
 		* @access private
2164 2164
 		*/
2165
-		function xml_header($charset_encoding='')
2165
+		function xml_header($charset_encoding = '')
2166 2166
 		{
2167 2167
 			if ($charset_encoding != '')
2168 2168
 			{
2169
-				return "<?xml version=\"1.0\" encoding=\"$charset_encoding\" ?" . ">\n<methodCall>\n";
2169
+				return "<?xml version=\"1.0\" encoding=\"$charset_encoding\" ?".">\n<methodCall>\n";
2170 2170
 			}
2171 2171
 			else
2172 2172
 			{
2173
-				return "<?xml version=\"1.0\"?" . ">\n<methodCall>\n";
2173
+				return "<?xml version=\"1.0\"?".">\n<methodCall>\n";
2174 2174
 			}
2175 2175
 		}
2176 2176
 
@@ -2193,23 +2193,23 @@  discard block
 block discarded – undo
2193 2193
 		/**
2194 2194
 		* @access private
2195 2195
 		*/
2196
-		function createPayload($charset_encoding='')
2196
+		function createPayload($charset_encoding = '')
2197 2197
 		{
2198 2198
 			if ($charset_encoding != '')
2199
-				$this->content_type = 'text/xml; charset=' . $charset_encoding;
2199
+				$this->content_type = 'text/xml; charset='.$charset_encoding;
2200 2200
 			else
2201 2201
 				$this->content_type = 'text/xml';
2202
-			$this->payload=$this->xml_header($charset_encoding);
2203
-			$this->payload.='<methodName>' . xmlrpc_encode_entitites($this->methodname, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</methodName>\n";
2204
-			$this->payload.="<params>\n";
2205
-			for($i=0; $i<count($this->params); $i++)
2202
+			$this->payload = $this->xml_header($charset_encoding);
2203
+			$this->payload .= '<methodName>'.xmlrpc_encode_entitites($this->methodname, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding)."</methodName>\n";
2204
+			$this->payload .= "<params>\n";
2205
+			for ($i = 0; $i<count($this->params); $i++)
2206 2206
 			{
2207
-				$p=$this->params[$i];
2208
-				$this->payload.="<param>\n" . $p->serialize($charset_encoding) .
2207
+				$p = $this->params[$i];
2208
+				$this->payload .= "<param>\n".$p->serialize($charset_encoding).
2209 2209
 				"</param>\n";
2210 2210
 			}
2211
-			$this->payload.="</params>\n";
2212
-			$this->payload.=$this->xml_footer();
2211
+			$this->payload .= "</params>\n";
2212
+			$this->payload .= $this->xml_footer();
2213 2213
 		}
2214 2214
 
2215 2215
 		/**
@@ -2218,11 +2218,11 @@  discard block
 block discarded – undo
2218 2218
 		* @return string the method that will be invoked
2219 2219
 		* @access public
2220 2220
 		*/
2221
-		function method($meth='')
2221
+		function method($meth = '')
2222 2222
 		{
2223
-			if($meth!='')
2223
+			if ($meth != '')
2224 2224
 			{
2225
-				$this->methodname=$meth;
2225
+				$this->methodname = $meth;
2226 2226
 			}
2227 2227
 			return $this->methodname;
2228 2228
 		}
@@ -2233,7 +2233,7 @@  discard block
 block discarded – undo
2233 2233
 		* @return string the xml representation of the message, xml prologue included
2234 2234
 		* @access public
2235 2235
 		*/
2236
-		function serialize($charset_encoding='')
2236
+		function serialize($charset_encoding = '')
2237 2237
 		{
2238 2238
 			$this->createPayload($charset_encoding);
2239 2239
 			return $this->payload;
@@ -2248,9 +2248,9 @@  discard block
 block discarded – undo
2248 2248
 		function addParam($par)
2249 2249
 		{
2250 2250
 			// add check: do not add to self params which are not xmlrpcvals
2251
-			if(is_object($par) && is_a($par, 'xmlrpcval'))
2251
+			if (is_object($par) && is_a($par, 'xmlrpcval'))
2252 2252
 			{
2253
-				$this->params[]=$par;
2253
+				$this->params[] = $par;
2254 2254
 				return true;
2255 2255
 			}
2256 2256
 			else
@@ -2289,13 +2289,13 @@  discard block
 block discarded – undo
2289 2289
 		*/
2290 2290
 		function &parseResponseFile($fp)
2291 2291
 		{
2292
-			$ipd='';
2293
-			while($data=fread($fp, 32768))
2292
+			$ipd = '';
2293
+			while ($data = fread($fp, 32768))
2294 2294
 			{
2295
-				$ipd.=$data;
2295
+				$ipd .= $data;
2296 2296
 			}
2297 2297
 			//fclose($fp);
2298
-			$r =& $this->parseResponse($ipd);
2298
+			$r = & $this->parseResponse($ipd);
2299 2299
 			return $r;
2300 2300
 		}
2301 2301
 
@@ -2303,22 +2303,22 @@  discard block
 block discarded – undo
2303 2303
 		* Parses HTTP headers and separates them from data.
2304 2304
 		* @access private
2305 2305
 		*/
2306
-		function &parseResponseHeaders(&$data, $headers_processed=false)
2306
+		function &parseResponseHeaders(&$data, $headers_processed = false)
2307 2307
 		{
2308 2308
 				// Support "web-proxy-tunelling" connections for https through proxies
2309
-				if(preg_match('/^HTTP\/1\.[0-1] 200 Connection established/', $data))
2309
+				if (preg_match('/^HTTP\/1\.[0-1] 200 Connection established/', $data))
2310 2310
 				{
2311 2311
 					// Look for CR/LF or simple LF as line separator,
2312 2312
 					// (even though it is not valid http)
2313
-					$pos = strpos($data,"\r\n\r\n");
2314
-					if($pos || is_int($pos))
2313
+					$pos = strpos($data, "\r\n\r\n");
2314
+					if ($pos || is_int($pos))
2315 2315
 					{
2316 2316
 						$bd = $pos+4;
2317 2317
 					}
2318 2318
 					else
2319 2319
 					{
2320
-						$pos = strpos($data,"\n\n");
2321
-						if($pos || is_int($pos))
2320
+						$pos = strpos($data, "\n\n");
2321
+						if ($pos || is_int($pos))
2322 2322
 						{
2323 2323
 							$bd = $pos+2;
2324 2324
 						}
@@ -2337,28 +2337,28 @@  discard block
 block discarded – undo
2337 2337
 					else
2338 2338
 					{
2339 2339
 						error_log('XML-RPC: '.__METHOD__.': HTTPS via proxy error, tunnel connection possibly failed');
2340
-						$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $GLOBALS['xmlrpcstr']['http_error']. ' (HTTPS via proxy error, tunnel connection possibly failed)');
2340
+						$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $GLOBALS['xmlrpcstr']['http_error'].' (HTTPS via proxy error, tunnel connection possibly failed)');
2341 2341
 						return $r;
2342 2342
 					}
2343 2343
 				}
2344 2344
 
2345 2345
 				// Strip HTTP 1.1 100 Continue header if present
2346
-				while(preg_match('/^HTTP\/1\.1 1[0-9]{2} /', $data))
2346
+				while (preg_match('/^HTTP\/1\.1 1[0-9]{2} /', $data))
2347 2347
 				{
2348 2348
 					$pos = strpos($data, 'HTTP', 12);
2349 2349
 					// server sent a Continue header without any (valid) content following...
2350 2350
 					// give the client a chance to know it
2351
-					if(!$pos && !is_int($pos)) // works fine in php 3, 4 and 5
2351
+					if (!$pos && !is_int($pos)) // works fine in php 3, 4 and 5
2352 2352
 					{
2353 2353
 						break;
2354 2354
 					}
2355 2355
 					$data = substr($data, $pos);
2356 2356
 				}
2357
-				if(!preg_match('/^HTTP\/[0-9.]+ 200 /', $data))
2357
+				if (!preg_match('/^HTTP\/[0-9.]+ 200 /', $data))
2358 2358
 				{
2359
-					$errstr= substr($data, 0, strpos($data, "\n")-1);
2360
-					error_log('XML-RPC: '.__METHOD__.': HTTP error, got response: ' .$errstr);
2361
-					$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $GLOBALS['xmlrpcstr']['http_error']. ' (' . $errstr . ')');
2359
+					$errstr = substr($data, 0, strpos($data, "\n")-1);
2360
+					error_log('XML-RPC: '.__METHOD__.': HTTP error, got response: '.$errstr);
2361
+					$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['http_error'], $GLOBALS['xmlrpcstr']['http_error'].' ('.$errstr.')');
2362 2362
 					return $r;
2363 2363
 				}
2364 2364
 
@@ -2367,15 +2367,15 @@  discard block
 block discarded – undo
2367 2367
 
2368 2368
 				// be tolerant to usage of \n instead of \r\n to separate headers and data
2369 2369
 				// (even though it is not valid http)
2370
-				$pos = strpos($data,"\r\n\r\n");
2371
-				if($pos || is_int($pos))
2370
+				$pos = strpos($data, "\r\n\r\n");
2371
+				if ($pos || is_int($pos))
2372 2372
 				{
2373 2373
 					$bd = $pos+4;
2374 2374
 				}
2375 2375
 				else
2376 2376
 				{
2377
-					$pos = strpos($data,"\n\n");
2378
-					if($pos || is_int($pos))
2377
+					$pos = strpos($data, "\n\n");
2378
+					if ($pos || is_int($pos))
2379 2379
 					{
2380 2380
 						$bd = $pos+2;
2381 2381
 					}
@@ -2388,11 +2388,11 @@  discard block
 block discarded – undo
2388 2388
 				}
2389 2389
 				// be tolerant to line endings, and extra empty lines
2390 2390
 				$ar = preg_split("/\r?\n/", trim(substr($data, 0, $pos)));
2391
-				while(list(,$line) = @each($ar))
2391
+				while (list(,$line) = @each($ar))
2392 2392
 				{
2393 2393
 					// take care of multi-line headers and cookies
2394
-					$arr = explode(':',$line,2);
2395
-					if(count($arr) > 1)
2394
+					$arr = explode(':', $line, 2);
2395
+					if (count($arr)>1)
2396 2396
 					{
2397 2397
 						$header_name = strtolower(trim($arr[0]));
2398 2398
 						/// @todo some other headers (the ones that allow a CSV list of values)
@@ -2416,7 +2416,7 @@  discard block
 block discarded – undo
2416 2416
 								// glue together all received cookies, using a comma to separate them
2417 2417
 								// (same as php does with getallheaders())
2418 2418
 								if (isset($GLOBALS['_xh']['headers'][$header_name]))
2419
-									$GLOBALS['_xh']['headers'][$header_name] .= ', ' . trim($cookie);
2419
+									$GLOBALS['_xh']['headers'][$header_name] .= ', '.trim($cookie);
2420 2420
 								else
2421 2421
 									$GLOBALS['_xh']['headers'][$header_name] = trim($cookie);
2422 2422
 								// parse cookie attributes, in case user wants to correctly honour them
@@ -2450,23 +2450,23 @@  discard block
 block discarded – undo
2450 2450
 							$GLOBALS['_xh']['headers'][$header_name] = trim($arr[1]);
2451 2451
 						}
2452 2452
 					}
2453
-					elseif(isset($header_name))
2453
+					elseif (isset($header_name))
2454 2454
 					{
2455 2455
 						///	@todo version1 cookies might span multiple lines, thus breaking the parsing above
2456
-						$GLOBALS['_xh']['headers'][$header_name] .= ' ' . trim($line);
2456
+						$GLOBALS['_xh']['headers'][$header_name] .= ' '.trim($line);
2457 2457
 					}
2458 2458
 				}
2459 2459
 
2460 2460
 				$data = substr($data, $bd);
2461 2461
 
2462
-				if($this->debug && count($GLOBALS['_xh']['headers']))
2462
+				if ($this->debug && count($GLOBALS['_xh']['headers']))
2463 2463
 				{
2464 2464
 					print '<PRE>';
2465
-					foreach($GLOBALS['_xh']['headers'] as $header => $value)
2465
+					foreach ($GLOBALS['_xh']['headers'] as $header => $value)
2466 2466
 					{
2467 2467
 						print htmlentities("HEADER: $header: $value\n");
2468 2468
 					}
2469
-					foreach($GLOBALS['_xh']['cookies'] as $header => $value)
2469
+					foreach ($GLOBALS['_xh']['cookies'] as $header => $value)
2470 2470
 					{
2471 2471
 						print htmlentities("COOKIE: $header={$value['value']}\n");
2472 2472
 					}
@@ -2475,12 +2475,12 @@  discard block
 block discarded – undo
2475 2475
 
2476 2476
 				// if CURL was used for the call, http headers have been processed,
2477 2477
 				// and dechunking + reinflating have been carried out
2478
-				if(!$headers_processed)
2478
+				if (!$headers_processed)
2479 2479
 				{
2480 2480
 					// Decode chunked encoding sent by http 1.1 servers
2481
-					if(isset($GLOBALS['_xh']['headers']['transfer-encoding']) && $GLOBALS['_xh']['headers']['transfer-encoding'] == 'chunked')
2481
+					if (isset($GLOBALS['_xh']['headers']['transfer-encoding']) && $GLOBALS['_xh']['headers']['transfer-encoding'] == 'chunked')
2482 2482
 					{
2483
-						if(!$data = decode_chunked($data))
2483
+						if (!$data = decode_chunked($data))
2484 2484
 						{
2485 2485
 							error_log('XML-RPC: '.__METHOD__.': errors occurred when trying to rebuild the chunked data received from server');
2486 2486
 							$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['dechunk_fail'], $GLOBALS['xmlrpcstr']['dechunk_fail']);
@@ -2490,25 +2490,25 @@  discard block
 block discarded – undo
2490 2490
 
2491 2491
 					// Decode gzip-compressed stuff
2492 2492
 					// code shamelessly inspired from nusoap library by Dietrich Ayala
2493
-					if(isset($GLOBALS['_xh']['headers']['content-encoding']))
2493
+					if (isset($GLOBALS['_xh']['headers']['content-encoding']))
2494 2494
 					{
2495 2495
 						$GLOBALS['_xh']['headers']['content-encoding'] = str_replace('x-', '', $GLOBALS['_xh']['headers']['content-encoding']);
2496
-						if($GLOBALS['_xh']['headers']['content-encoding'] == 'deflate' || $GLOBALS['_xh']['headers']['content-encoding'] == 'gzip')
2496
+						if ($GLOBALS['_xh']['headers']['content-encoding'] == 'deflate' || $GLOBALS['_xh']['headers']['content-encoding'] == 'gzip')
2497 2497
 						{
2498 2498
 							// if decoding works, use it. else assume data wasn't gzencoded
2499
-							if(function_exists('gzinflate'))
2499
+							if (function_exists('gzinflate'))
2500 2500
 							{
2501
-								if($GLOBALS['_xh']['headers']['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data))
2501
+								if ($GLOBALS['_xh']['headers']['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data))
2502 2502
 								{
2503 2503
 									$data = $degzdata;
2504
-									if($this->debug)
2505
-									print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2504
+									if ($this->debug)
2505
+									print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n".htmlentities($data)."\n---END---</PRE>";
2506 2506
 								}
2507
-								elseif($GLOBALS['_xh']['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
2507
+								elseif ($GLOBALS['_xh']['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10)))
2508 2508
 								{
2509 2509
 									$data = $degzdata;
2510
-									if($this->debug)
2511
-									print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n" . htmlentities($data) . "\n---END---</PRE>";
2510
+									if ($this->debug)
2511
+									print "<PRE>---INFLATED RESPONSE---[".strlen($data)." chars]---\n".htmlentities($data)."\n---END---</PRE>";
2512 2512
 								}
2513 2513
 								else
2514 2514
 								{
@@ -2529,7 +2529,7 @@  discard block
 block discarded – undo
2529 2529
 
2530 2530
 				// real stupid hack to avoid PHP complaining about returning NULL by ref
2531 2531
 				$r = null;
2532
-				$r =& $r;
2532
+				$r = & $r;
2533 2533
 				return $r;
2534 2534
 		}
2535 2535
 
@@ -2541,28 +2541,28 @@  discard block
 block discarded – undo
2541 2541
 		* @return xmlrpcresp
2542 2542
 		* @access public
2543 2543
 		*/
2544
-		function &parseResponse($data='', $headers_processed=false, $return_type='xmlrpcvals')
2544
+		function &parseResponse($data = '', $headers_processed = false, $return_type = 'xmlrpcvals')
2545 2545
 		{
2546
-			if($this->debug)
2546
+			if ($this->debug)
2547 2547
 			{
2548 2548
 				//by maHo, replaced htmlspecialchars with htmlentities
2549
-				print "<PRE>---GOT---\n" . htmlentities($data) . "\n---END---\n</PRE>";
2549
+				print "<PRE>---GOT---\n".htmlentities($data)."\n---END---\n</PRE>";
2550 2550
 			}
2551 2551
 
2552
-			if($data == '')
2552
+			if ($data == '')
2553 2553
 			{
2554 2554
 				error_log('XML-RPC: '.__METHOD__.': no response received from server.');
2555 2555
 				$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['no_data'], $GLOBALS['xmlrpcstr']['no_data']);
2556 2556
 				return $r;
2557 2557
 			}
2558 2558
 
2559
-			$GLOBALS['_xh']=array();
2559
+			$GLOBALS['_xh'] = array();
2560 2560
 
2561 2561
 			$raw_data = $data;
2562 2562
 			// parse the HTTP headers of the response, if present, and separate them from data
2563
-			if(substr($data, 0, 4) == 'HTTP')
2563
+			if (substr($data, 0, 4) == 'HTTP')
2564 2564
 			{
2565
-				$r =& $this->parseResponseHeaders($data, $headers_processed);
2565
+				$r = & $this->parseResponseHeaders($data, $headers_processed);
2566 2566
 				if ($r)
2567 2567
 				{
2568 2568
 					// failed processing of HTTP response headers
@@ -2577,7 +2577,7 @@  discard block
 block discarded – undo
2577 2577
 				$GLOBALS['_xh']['cookies'] = array();
2578 2578
 			}
2579 2579
 
2580
-			if($this->debug)
2580
+			if ($this->debug)
2581 2581
 			{
2582 2582
 				$start = strpos($data, '<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
2583 2583
 				if ($start)
@@ -2597,7 +2597,7 @@  discard block
 block discarded – undo
2597 2597
 			// be tolerant of junk after methodResponse (e.g. javascript ads automatically inserted by free hosts)
2598 2598
 			// idea from Luca Mariano <[email protected]> originally in PEARified version of the lib
2599 2599
 			$pos = strrpos($data, '</methodResponse>');
2600
-			if($pos !== false)
2600
+			if ($pos !== false)
2601 2601
 			{
2602 2602
 				$data = substr($data, 0, $pos+17);
2603 2603
 			}
@@ -2615,13 +2615,13 @@  discard block
 block discarded – undo
2615 2615
 			// try to 'guestimate' the character encoding of the received response
2616 2616
 			$resp_encoding = guess_encoding(@$GLOBALS['_xh']['headers']['content-type'], $data);
2617 2617
 
2618
-			$GLOBALS['_xh']['ac']='';
2618
+			$GLOBALS['_xh']['ac'] = '';
2619 2619
 			//$GLOBALS['_xh']['qt']=''; //unused...
2620 2620
 			$GLOBALS['_xh']['stack'] = array();
2621 2621
 			$GLOBALS['_xh']['valuestack'] = array();
2622
-			$GLOBALS['_xh']['isf']=0; // 0 = OK, 1 for xmlrpc fault responses, 2 = invalid xmlrpc
2623
-			$GLOBALS['_xh']['isf_reason']='';
2624
-			$GLOBALS['_xh']['rt']=''; // 'methodcall or 'methodresponse'
2622
+			$GLOBALS['_xh']['isf'] = 0; // 0 = OK, 1 for xmlrpc fault responses, 2 = invalid xmlrpc
2623
+			$GLOBALS['_xh']['isf_reason'] = '';
2624
+			$GLOBALS['_xh']['rt'] = ''; // 'methodcall or 'methodresponse'
2625 2625
 
2626 2626
 			// Since parsing will fail if charset is not specified in the xml prologue,
2627 2627
 			// the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
@@ -2635,7 +2635,7 @@  discard block
 block discarded – undo
2635 2635
 					if (extension_loaded('mbstring')) {
2636 2636
 						$data = mb_convert_encoding($data, 'UTF-8', $resp_encoding);
2637 2637
 					} else {
2638
-						error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $resp_encoding);
2638
+						error_log('XML-RPC: '.__METHOD__.': invalid charset encoding of received request: '.$resp_encoding);
2639 2639
 					}
2640 2640
 				}
2641 2641
 			}
@@ -2670,10 +2670,10 @@  discard block
 block discarded – undo
2670 2670
 			xml_set_default_handler($parser, 'xmlrpc_dh');
2671 2671
 
2672 2672
 			// first error check: xml not well formed
2673
-			if(!xml_parse($parser, $data, count($data)))
2673
+			if (!xml_parse($parser, $data, count($data)))
2674 2674
 			{
2675 2675
 				// thanks to Peter Kocks <[email protected]>
2676
-				if((xml_get_current_line_number($parser)) == 1)
2676
+				if ((xml_get_current_line_number($parser)) == 1)
2677 2677
 				{
2678 2678
 					$errstr = 'XML error at line 1, check URL';
2679 2679
 				}
@@ -2684,9 +2684,9 @@  discard block
 block discarded – undo
2684 2684
 						xml_get_current_line_number($parser), xml_get_current_column_number($parser));
2685 2685
 				}
2686 2686
 				error_log($errstr);
2687
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcstr']['invalid_return'].' ('.$errstr.')');
2687
+				$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcstr']['invalid_return'].' ('.$errstr.')');
2688 2688
 				xml_parser_free($parser);
2689
-				if($this->debug)
2689
+				if ($this->debug)
2690 2690
 				{
2691 2691
 					print $errstr;
2692 2692
 				}
@@ -2697,7 +2697,7 @@  discard block
 block discarded – undo
2697 2697
 			}
2698 2698
 			xml_parser_free($parser);
2699 2699
 			// second error check: xml well formed but not xml-rpc compliant
2700
-			if ($GLOBALS['_xh']['isf'] > 1)
2700
+			if ($GLOBALS['_xh']['isf']>1)
2701 2701
 			{
2702 2702
 				if ($this->debug)
2703 2703
 				{
@@ -2705,7 +2705,7 @@  discard block
 block discarded – undo
2705 2705
 				}
2706 2706
 
2707 2707
 				$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'],
2708
-				$GLOBALS['xmlrpcstr']['invalid_return'] . ' ' . $GLOBALS['_xh']['isf_reason']);
2708
+				$GLOBALS['xmlrpcstr']['invalid_return'].' '.$GLOBALS['_xh']['isf_reason']);
2709 2709
 			}
2710 2710
 			// third error check: parsing of the response has somehow gone boink.
2711 2711
 			// NB: shall we omit this check, since we trust the parsing code?
@@ -2714,7 +2714,7 @@  discard block
 block discarded – undo
2714 2714
 				// something odd has happened
2715 2715
 				// and it's time to generate a client side error
2716 2716
 				// indicating something odd went on
2717
-				$r=new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'],
2717
+				$r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['invalid_return'],
2718 2718
 					$GLOBALS['xmlrpcstr']['invalid_return']);
2719 2719
 			}
2720 2720
 			else
@@ -2729,9 +2729,9 @@  discard block
 block discarded – undo
2729 2729
 				}
2730 2730
 
2731 2731
 				// note that using =& will raise an error if $GLOBALS['_xh']['st'] does not generate an object.
2732
-				$v =& $GLOBALS['_xh']['value'];
2732
+				$v = & $GLOBALS['_xh']['value'];
2733 2733
 
2734
-				if($GLOBALS['_xh']['isf'])
2734
+				if ($GLOBALS['_xh']['isf'])
2735 2735
 				{
2736 2736
 					/// @todo we should test here if server sent an int and a string,
2737 2737
 					/// and/or coerce them into such...
@@ -2748,7 +2748,7 @@  discard block
 block discarded – undo
2748 2748
 						$errstr = $v['faultString'];
2749 2749
 					}
2750 2750
 
2751
-					if($errno == 0)
2751
+					if ($errno == 0)
2752 2752
 					{
2753 2753
 						// FAULT returned, errno needs to reflect that
2754 2754
 						$errno = -1;
@@ -2758,7 +2758,7 @@  discard block
 block discarded – undo
2758 2758
 				}
2759 2759
 				else
2760 2760
 				{
2761
-					$r=new xmlrpcresp($v, 0, '', $return_type);
2761
+					$r = new xmlrpcresp($v, 0, '', $return_type);
2762 2762
 				}
2763 2763
 			}
2764 2764
 
@@ -2771,26 +2771,26 @@  discard block
 block discarded – undo
2771 2771
 
2772 2772
 	class xmlrpcval
2773 2773
 	{
2774
-		var $me=array();
2775
-		var $mytype=0;
2776
-		var $_php_class=null;
2774
+		var $me = array();
2775
+		var $mytype = 0;
2776
+		var $_php_class = null;
2777 2777
 
2778 2778
 		/**
2779 2779
 		* @param mixed $val
2780 2780
 		* @param string $type any valid xmlrpc type name (lowercase). If null, 'string' is assumed
2781 2781
 		*/
2782
-		function __construct($val=-1, $type='')
2782
+		function __construct($val = -1, $type = '')
2783 2783
 		{
2784 2784
 			/// @todo: optimization creep - do not call addXX, do it all inline.
2785 2785
 			/// downside: booleans will not be coerced anymore
2786
-			if($val!==-1 || $type!='')
2786
+			if ($val !== -1 || $type != '')
2787 2787
 			{
2788 2788
 				// optimization creep: inlined all work done by constructor
2789
-				switch($type)
2789
+				switch ($type)
2790 2790
 				{
2791 2791
 					case '':
2792
-						$this->mytype=1;
2793
-						$this->me['string']=$val;
2792
+						$this->mytype = 1;
2793
+						$this->me['string'] = $val;
2794 2794
 						break;
2795 2795
 					case 'i4':
2796 2796
 					case 'int':
@@ -2800,16 +2800,16 @@  discard block
 block discarded – undo
2800 2800
 					case 'dateTime.iso8601':
2801 2801
 					case 'base64':
2802 2802
 					case 'null':
2803
-						$this->mytype=1;
2804
-						$this->me[$type]=$val;
2803
+						$this->mytype = 1;
2804
+						$this->me[$type] = $val;
2805 2805
 						break;
2806 2806
 					case 'array':
2807
-						$this->mytype=2;
2808
-						$this->me['array']=$val;
2807
+						$this->mytype = 2;
2808
+						$this->me['array'] = $val;
2809 2809
 						break;
2810 2810
 					case 'struct':
2811
-						$this->mytype=3;
2812
-						$this->me['struct']=$val;
2811
+						$this->mytype = 3;
2812
+						$this->me['struct'] = $val;
2813 2813
 						break;
2814 2814
 					default:
2815 2815
 						error_log("XML-RPC: ".__METHOD__.": not a known type ($type)");
@@ -2836,7 +2836,7 @@  discard block
 block discarded – undo
2836 2836
 		/**
2837 2837
 		* @deprecated
2838 2838
 		*/
2839
-		function xmlrpcval($val=-1, $type='')
2839
+		function xmlrpcval($val = -1, $type = '')
2840 2840
 		{
2841 2841
 			self::__construct($val, $type);
2842 2842
 		}
@@ -2847,10 +2847,10 @@  discard block
 block discarded – undo
2847 2847
 		* @param string $type
2848 2848
 		* @return int 1 or 0 on failure
2849 2849
 		*/
2850
-		function addScalar($val, $type='string')
2850
+		function addScalar($val, $type = 'string')
2851 2851
 		{
2852
-			$typeof=@$GLOBALS['xmlrpcTypes'][$type];
2853
-			if($typeof!=1)
2852
+			$typeof = @$GLOBALS['xmlrpcTypes'][$type];
2853
+			if ($typeof != 1)
2854 2854
 			{
2855 2855
 				error_log("XML-RPC: ".__METHOD__.": not a scalar type ($type)");
2856 2856
 				return 0;
@@ -2859,19 +2859,19 @@  discard block
 block discarded – undo
2859 2859
 			// coerce booleans into correct values
2860 2860
 			// NB: we should either do it for datetimes, integers and doubles, too,
2861 2861
 			// or just plain remove this check, implemented on booleans only...
2862
-			if($type==$GLOBALS['xmlrpcBoolean'])
2862
+			if ($type == $GLOBALS['xmlrpcBoolean'])
2863 2863
 			{
2864
-				if(strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false')))
2864
+				if (strcasecmp($val, 'true') == 0 || $val == 1 || ($val == true && strcasecmp($val, 'false')))
2865 2865
 				{
2866
-					$val=true;
2866
+					$val = true;
2867 2867
 				}
2868 2868
 				else
2869 2869
 				{
2870
-					$val=false;
2870
+					$val = false;
2871 2871
 				}
2872 2872
 			}
2873 2873
 
2874
-			switch($this->mytype)
2874
+			switch ($this->mytype)
2875 2875
 			{
2876 2876
 				case 1:
2877 2877
 					error_log('XML-RPC: '.__METHOD__.': scalar xmlrpcval can have only one value');
@@ -2885,12 +2885,12 @@  discard block
 block discarded – undo
2885 2885
 					//$ar[]=new xmlrpcval($val, $type);
2886 2886
 					//$this->me['array']=$ar;
2887 2887
 					// Faster (?) avoid all the costly array-copy-by-val done here...
2888
-					$this->me['array'][]=new xmlrpcval($val, $type);
2888
+					$this->me['array'][] = new xmlrpcval($val, $type);
2889 2889
 					return 1;
2890 2890
 				default:
2891 2891
 					// a scalar, so set the value and remember we're scalar
2892
-					$this->me[$type]=$val;
2893
-					$this->mytype=$typeof;
2892
+					$this->me[$type] = $val;
2893
+					$this->mytype = $typeof;
2894 2894
 					return 1;
2895 2895
 			}
2896 2896
 		}
@@ -2905,13 +2905,13 @@  discard block
 block discarded – undo
2905 2905
 		*/
2906 2906
 		function addArray($vals)
2907 2907
 		{
2908
-			if($this->mytype==0)
2908
+			if ($this->mytype == 0)
2909 2909
 			{
2910
-				$this->mytype=$GLOBALS['xmlrpcTypes']['array'];
2911
-				$this->me['array']=$vals;
2910
+				$this->mytype = $GLOBALS['xmlrpcTypes']['array'];
2911
+				$this->me['array'] = $vals;
2912 2912
 				return 1;
2913 2913
 			}
2914
-			elseif($this->mytype==2)
2914
+			elseif ($this->mytype == 2)
2915 2915
 			{
2916 2916
 				// we're adding to an array here
2917 2917
 				$this->me['array'] = array_merge($this->me['array'], $vals);
@@ -2919,7 +2919,7 @@  discard block
 block discarded – undo
2919 2919
 			}
2920 2920
 			else
2921 2921
 			{
2922
-				error_log('XML-RPC: '.__METHOD__.': already initialized as a [' . $this->kindOf() . ']');
2922
+				error_log('XML-RPC: '.__METHOD__.': already initialized as a ['.$this->kindOf().']');
2923 2923
 				return 0;
2924 2924
 			}
2925 2925
 		}
@@ -2934,13 +2934,13 @@  discard block
 block discarded – undo
2934 2934
 		*/
2935 2935
 		function addStruct($vals)
2936 2936
 		{
2937
-			if($this->mytype==0)
2937
+			if ($this->mytype == 0)
2938 2938
 			{
2939
-				$this->mytype=$GLOBALS['xmlrpcTypes']['struct'];
2940
-				$this->me['struct']=$vals;
2939
+				$this->mytype = $GLOBALS['xmlrpcTypes']['struct'];
2940
+				$this->me['struct'] = $vals;
2941 2941
 				return 1;
2942 2942
 			}
2943
-			elseif($this->mytype==3)
2943
+			elseif ($this->mytype == 3)
2944 2944
 			{
2945 2945
 				// we're adding to a struct here
2946 2946
 				$this->me['struct'] = array_merge($this->me['struct'], $vals);
@@ -2948,7 +2948,7 @@  discard block
 block discarded – undo
2948 2948
 			}
2949 2949
 			else
2950 2950
 			{
2951
-				error_log('XML-RPC: '.__METHOD__.': already initialized as a [' . $this->kindOf() . ']');
2951
+				error_log('XML-RPC: '.__METHOD__.': already initialized as a ['.$this->kindOf().']');
2952 2952
 				return 0;
2953 2953
 			}
2954 2954
 		}
@@ -2957,12 +2957,12 @@  discard block
 block discarded – undo
2957 2957
 		// DEPRECATED!
2958 2958
 		function dump($ar)
2959 2959
 		{
2960
-			foreach($ar as $key => $val)
2960
+			foreach ($ar as $key => $val)
2961 2961
 			{
2962 2962
 				echo "$key => $val<br />";
2963
-				if($key == 'array')
2963
+				if ($key == 'array')
2964 2964
 				{
2965
-					while(list($key2, $val2) = each($val))
2965
+					while (list($key2, $val2) = each($val))
2966 2966
 					{
2967 2967
 						echo "-- $key2 => $val2<br />";
2968 2968
 					}
@@ -2977,7 +2977,7 @@  discard block
 block discarded – undo
2977 2977
 		*/
2978 2978
 		function kindOf()
2979 2979
 		{
2980
-			switch($this->mytype)
2980
+			switch ($this->mytype)
2981 2981
 			{
2982 2982
 				case 3:
2983 2983
 					return 'struct';
@@ -2996,28 +2996,28 @@  discard block
 block discarded – undo
2996 2996
 		/**
2997 2997
 		* @access private
2998 2998
 		*/
2999
-		function serializedata($typ, $val, $charset_encoding='')
2999
+		function serializedata($typ, $val, $charset_encoding = '')
3000 3000
 		{
3001
-			$rs='';
3002
-			switch(@$GLOBALS['xmlrpcTypes'][$typ])
3001
+			$rs = '';
3002
+			switch (@$GLOBALS['xmlrpcTypes'][$typ])
3003 3003
 			{
3004 3004
 				case 1:
3005
-					switch($typ)
3005
+					switch ($typ)
3006 3006
 					{
3007 3007
 						case $GLOBALS['xmlrpcBase64']:
3008
-							$rs.="<${typ}>" . base64_encode($val) . "</${typ}>";
3008
+							$rs .= "<${typ}>".base64_encode($val)."</${typ}>";
3009 3009
 							break;
3010 3010
 						case $GLOBALS['xmlrpcBoolean']:
3011
-							$rs.="<${typ}>" . ($val ? '1' : '0') . "</${typ}>";
3011
+							$rs .= "<${typ}>".($val ? '1' : '0')."</${typ}>";
3012 3012
 							break;
3013 3013
 						case $GLOBALS['xmlrpcString']:
3014 3014
 							// G. Giunta 2005/2/13: do NOT use htmlentities, since
3015 3015
 							// it will produce named html entities, which are invalid xml
3016
-							$rs.="<${typ}>" . xmlrpc_encode_entitites($val, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding). "</${typ}>";
3016
+							$rs .= "<${typ}>".xmlrpc_encode_entitites($val, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding)."</${typ}>";
3017 3017
 							break;
3018 3018
 						case $GLOBALS['xmlrpcInt']:
3019 3019
 						case $GLOBALS['xmlrpcI4']:
3020
-							$rs.="<${typ}>".(int)$val."</${typ}>";
3020
+							$rs .= "<${typ}>".(int) $val."</${typ}>";
3021 3021
 							break;
3022 3022
 						case $GLOBALS['xmlrpcDouble']:
3023 3023
 							// avoid using standard conversion of float to string because it is locale-dependent,
@@ -3025,71 +3025,71 @@  discard block
 block discarded – undo
3025 3025
 							// sprintf('%F') could be most likely ok but it fails eg. on 2e-14.
3026 3026
 							// The code below tries its best at keeping max precision while avoiding exp notation,
3027 3027
 							// but there is of course no limit in the number of decimal places to be used...
3028
-							$rs.="<${typ}>".preg_replace('/\\.?0+$/','',number_format((double)$val, 128, '.', ''))."</${typ}>";
3028
+							$rs .= "<${typ}>".preg_replace('/\\.?0+$/', '', number_format((double) $val, 128, '.', ''))."</${typ}>";
3029 3029
 							break;
3030 3030
 						case $GLOBALS['xmlrpcDateTime']:
3031 3031
 							if (is_string($val))
3032 3032
 							{
3033
-								$rs.="<${typ}>${val}</${typ}>";
3033
+								$rs .= "<${typ}>${val}</${typ}>";
3034 3034
 							}
3035
-							else if(is_a($val, 'DateTime'))
3035
+							else if (is_a($val, 'DateTime'))
3036 3036
 							{
3037
-								$rs.="<${typ}>".$val->format('Ymd\TH:i:s')."</${typ}>";
3037
+								$rs .= "<${typ}>".$val->format('Ymd\TH:i:s')."</${typ}>";
3038 3038
 							}
3039
-							else if(is_int($val))
3039
+							else if (is_int($val))
3040 3040
 							{
3041
-								$rs.="<${typ}>".strftime("%Y%m%dT%H:%M:%S", $val)."</${typ}>";
3041
+								$rs .= "<${typ}>".strftime("%Y%m%dT%H:%M:%S", $val)."</${typ}>";
3042 3042
 							}
3043 3043
 							else
3044 3044
 							{
3045 3045
 								// not really a good idea here: but what shall we output anyway? left for backward compat...
3046
-								$rs.="<${typ}>${val}</${typ}>";
3046
+								$rs .= "<${typ}>${val}</${typ}>";
3047 3047
 							}
3048 3048
 							break;
3049 3049
 						case $GLOBALS['xmlrpcNull']:
3050 3050
 							if ($GLOBALS['xmlrpc_null_apache_encoding'])
3051 3051
 							{
3052
-								$rs.="<ex:nil/>";
3052
+								$rs .= "<ex:nil/>";
3053 3053
 							}
3054 3054
 							else
3055 3055
 							{
3056
-								$rs.="<nil/>";
3056
+								$rs .= "<nil/>";
3057 3057
 							}
3058 3058
 							break;
3059 3059
 						default:
3060 3060
 							// no standard type value should arrive here, but provide a possibility
3061 3061
 							// for xmlrpcvals of unknown type...
3062
-							$rs.="<${typ}>${val}</${typ}>";
3062
+							$rs .= "<${typ}>${val}</${typ}>";
3063 3063
 					}
3064 3064
 					break;
3065 3065
 				case 3:
3066 3066
 					// struct
3067 3067
 					if ($this->_php_class)
3068 3068
 					{
3069
-						$rs.='<struct php_class="' . $this->_php_class . "\">\n";
3069
+						$rs .= '<struct php_class="'.$this->_php_class."\">\n";
3070 3070
 					}
3071 3071
 					else
3072 3072
 					{
3073
-						$rs.="<struct>\n";
3073
+						$rs .= "<struct>\n";
3074 3074
 					}
3075
-					foreach($val as $key2 => $val2)
3075
+					foreach ($val as $key2 => $val2)
3076 3076
 					{
3077
-						$rs.='<member><name>'.xmlrpc_encode_entitites($key2, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding)."</name>\n";
3077
+						$rs .= '<member><name>'.xmlrpc_encode_entitites($key2, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding)."</name>\n";
3078 3078
 						//$rs.=$this->serializeval($val2);
3079
-						$rs.=$val2->serialize($charset_encoding);
3080
-						$rs.="</member>\n";
3079
+						$rs .= $val2->serialize($charset_encoding);
3080
+						$rs .= "</member>\n";
3081 3081
 					}
3082
-					$rs.='</struct>';
3082
+					$rs .= '</struct>';
3083 3083
 					break;
3084 3084
 				case 2:
3085 3085
 					// array
3086
-					$rs.="<array>\n<data>\n";
3087
-					for($i=0; $i<count($val); $i++)
3086
+					$rs .= "<array>\n<data>\n";
3087
+					for ($i = 0; $i<count($val); $i++)
3088 3088
 					{
3089 3089
 						//$rs.=$this->serializeval($val[$i]);
3090
-						$rs.=$val[$i]->serialize($charset_encoding);
3090
+						$rs .= $val[$i]->serialize($charset_encoding);
3091 3091
 					}
3092
-					$rs.="</data>\n</array>";
3092
+					$rs .= "</data>\n</array>";
3093 3093
 					break;
3094 3094
 				default:
3095 3095
 					break;
@@ -3103,14 +3103,14 @@  discard block
 block discarded – undo
3103 3103
 		* @return string
3104 3104
 		* @access public
3105 3105
 		*/
3106
-		function serialize($charset_encoding='')
3106
+		function serialize($charset_encoding = '')
3107 3107
 		{
3108 3108
 			// add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
3109 3109
 			//if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
3110 3110
 			//{
3111 3111
 				reset($this->me);
3112 3112
 				list($typ, $val) = each($this->me);
3113
-				return '<value>' . $this->serializedata($typ, $val, $charset_encoding) . "</value>\n";
3113
+				return '<value>'.$this->serializedata($typ, $val, $charset_encoding)."</value>\n";
3114 3114
 			//}
3115 3115
 		}
3116 3116
 
@@ -3120,10 +3120,10 @@  discard block
 block discarded – undo
3120 3120
 			// add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
3121 3121
 			//if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
3122 3122
 			//{
3123
-				$ar=$o->me;
3123
+				$ar = $o->me;
3124 3124
 				reset($ar);
3125 3125
 				list($typ, $val) = each($ar);
3126
-				return '<value>' . $this->serializedata($typ, $val) . "</value>\n";
3126
+				return '<value>'.$this->serializedata($typ, $val)."</value>\n";
3127 3127
 			//}
3128 3128
 		}
3129 3129
 
@@ -3176,32 +3176,32 @@  discard block
 block discarded – undo
3176 3176
 		{
3177 3177
 			// UNSTABLE
3178 3178
 			reset($this->me);
3179
-			list($a,$b)=each($this->me);
3179
+			list($a, $b) = each($this->me);
3180 3180
 			// contributed by I Sofer, 2001-03-24
3181 3181
 			// add support for nested arrays to scalarval
3182 3182
 			// i've created a new method here, so as to
3183 3183
 			// preserve back compatibility
3184 3184
 
3185
-			if(is_array($b))
3185
+			if (is_array($b))
3186 3186
 			{
3187 3187
 				@reset($b);
3188
-				while(list($id,$cont) = @each($b))
3188
+				while (list($id, $cont) = @each($b))
3189 3189
 				{
3190 3190
 					$b[$id] = $cont->scalarval();
3191 3191
 				}
3192 3192
 			}
3193 3193
 
3194 3194
 			// add support for structures directly encoding php objects
3195
-			if(is_object($b))
3195
+			if (is_object($b))
3196 3196
 			{
3197 3197
 				$t = get_object_vars($b);
3198 3198
 				@reset($t);
3199
-				while(list($id,$cont) = @each($t))
3199
+				while (list($id, $cont) = @each($t))
3200 3200
 				{
3201 3201
 					$t[$id] = $cont->scalarval();
3202 3202
 				}
3203 3203
 				@reset($t);
3204
-				while(list($id,$cont) = @each($t))
3204
+				while (list($id, $cont) = @each($t))
3205 3205
 				{
3206 3206
 					@$b->$id = $cont;
3207 3207
 				}
@@ -3218,7 +3218,7 @@  discard block
 block discarded – undo
3218 3218
 		function scalarval()
3219 3219
 		{
3220 3220
 			reset($this->me);
3221
-			list(,$b)=each($this->me);
3221
+			list(,$b) = each($this->me);
3222 3222
 			return $b;
3223 3223
 		}
3224 3224
 
@@ -3231,10 +3231,10 @@  discard block
 block discarded – undo
3231 3231
 		function scalartyp()
3232 3232
 		{
3233 3233
 			reset($this->me);
3234
-			list($a,)=each($this->me);
3235
-			if($a==$GLOBALS['xmlrpcI4'])
3234
+			list($a,) = each($this->me);
3235
+			if ($a == $GLOBALS['xmlrpcI4'])
3236 3236
 			{
3237
-				$a=$GLOBALS['xmlrpcInt'];
3237
+				$a = $GLOBALS['xmlrpcInt'];
3238 3238
 			}
3239 3239
 			return $a;
3240 3240
 		}
@@ -3291,23 +3291,23 @@  discard block
 block discarded – undo
3291 3291
 	* @param int $utc (0 or 1)
3292 3292
 	* @return string
3293 3293
 	*/
3294
-	function iso8601_encode($timet, $utc=0)
3294
+	function iso8601_encode($timet, $utc = 0)
3295 3295
 	{
3296
-		if(!$utc)
3296
+		if (!$utc)
3297 3297
 		{
3298
-			$t=strftime("%Y%m%dT%H:%M:%S", $timet);
3298
+			$t = strftime("%Y%m%dT%H:%M:%S", $timet);
3299 3299
 		}
3300 3300
 		else
3301 3301
 		{
3302
-			if(function_exists('gmstrftime'))
3302
+			if (function_exists('gmstrftime'))
3303 3303
 			{
3304 3304
 				// gmstrftime doesn't exist in some versions
3305 3305
 				// of PHP
3306
-				$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
3306
+				$t = gmstrftime("%Y%m%dT%H:%M:%S", $timet);
3307 3307
 			}
3308 3308
 			else
3309 3309
 			{
3310
-				$t=strftime("%Y%m%dT%H:%M:%S", $timet-date('Z'));
3310
+				$t = strftime("%Y%m%dT%H:%M:%S", $timet-date('Z'));
3311 3311
 			}
3312 3312
 		}
3313 3313
 		return $t;
@@ -3319,18 +3319,18 @@  discard block
 block discarded – undo
3319 3319
 	* @param int $utc either 0 or 1
3320 3320
 	* @return int (datetime)
3321 3321
 	*/
3322
-	function iso8601_decode($idate, $utc=0)
3322
+	function iso8601_decode($idate, $utc = 0)
3323 3323
 	{
3324
-		$t=0;
3325
-		if(preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $idate, $regs))
3324
+		$t = 0;
3325
+		if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $idate, $regs))
3326 3326
 		{
3327
-			if($utc)
3327
+			if ($utc)
3328 3328
 			{
3329
-				$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3329
+				$t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3330 3330
 			}
3331 3331
 			else
3332 3332
 			{
3333
-				$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3333
+				$t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3334 3334
 			}
3335 3335
 		}
3336 3336
 		return $t;
@@ -3357,15 +3357,15 @@  discard block
 block discarded – undo
3357 3357
 	* @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is
3358 3358
 	* @return mixed
3359 3359
 	*/
3360
-	function php_xmlrpc_decode($xmlrpc_val, $options=array())
3360
+	function php_xmlrpc_decode($xmlrpc_val, $options = array())
3361 3361
 	{
3362
-		switch($xmlrpc_val->kindOf())
3362
+		switch ($xmlrpc_val->kindOf())
3363 3363
 		{
3364 3364
 			case 'scalar':
3365 3365
 				if (in_array('extension_api', $options))
3366 3366
 				{
3367 3367
 					reset($xmlrpc_val->me);
3368
-					list($typ,$val) = each($xmlrpc_val->me);
3368
+					list($typ, $val) = each($xmlrpc_val->me);
3369 3369
 					switch ($typ)
3370 3370
 					{
3371 3371
 						case 'dateTime.iso8601':
@@ -3406,7 +3406,7 @@  discard block
 block discarded – undo
3406 3406
 			case 'array':
3407 3407
 				$size = $xmlrpc_val->arraysize();
3408 3408
 				$arr = array();
3409
-				for($i = 0; $i < $size; $i++)
3409
+				for ($i = 0; $i<$size; $i++)
3410 3410
 				{
3411 3411
 					$arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
3412 3412
 				}
@@ -3421,7 +3421,7 @@  discard block
 block discarded – undo
3421 3421
 					&& class_exists($xmlrpc_val->_php_class))
3422 3422
 				{
3423 3423
 					$obj = @new $xmlrpc_val->_php_class;
3424
-					while(list($key,$value)=$xmlrpc_val->structeach())
3424
+					while (list($key, $value) = $xmlrpc_val->structeach())
3425 3425
 					{
3426 3426
 						$obj->$key = php_xmlrpc_decode($value, $options);
3427 3427
 					}
@@ -3430,7 +3430,7 @@  discard block
 block discarded – undo
3430 3430
 				else
3431 3431
 				{
3432 3432
 					$arr = array();
3433
-					while(list($key,$value)=$xmlrpc_val->structeach())
3433
+					while (list($key, $value) = $xmlrpc_val->structeach())
3434 3434
 					{
3435 3435
 						$arr[$key] = php_xmlrpc_decode($value, $options);
3436 3436
 					}
@@ -3439,7 +3439,7 @@  discard block
 block discarded – undo
3439 3439
 			case 'msg':
3440 3440
 				$paramcount = $xmlrpc_val->getNumParams();
3441 3441
 				$arr = array();
3442
-				for($i = 0; $i < $paramcount; $i++)
3442
+				for ($i = 0; $i<$paramcount; $i++)
3443 3443
 				{
3444 3444
 					$arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
3445 3445
 				}
@@ -3450,13 +3450,13 @@  discard block
 block discarded – undo
3450 3450
 	// This constant left here only for historical reasons...
3451 3451
 	// it was used to decide if we have to define xmlrpc_encode on our own, but
3452 3452
 	// we do not do it anymore
3453
-	if(function_exists('xmlrpc_decode'))
3453
+	if (function_exists('xmlrpc_decode'))
3454 3454
 	{
3455
-		define('XMLRPC_EPI_ENABLED','1');
3455
+		define('XMLRPC_EPI_ENABLED', '1');
3456 3456
 	}
3457 3457
 	else
3458 3458
 	{
3459
-		define('XMLRPC_EPI_ENABLED','0');
3459
+		define('XMLRPC_EPI_ENABLED', '0');
3460 3460
 	}
3461 3461
 
3462 3462
 	/**
@@ -3476,10 +3476,10 @@  discard block
 block discarded – undo
3476 3476
 	* @param array $options	can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api'
3477 3477
 	* @return xmlrpcval
3478 3478
 	*/
3479
-	function php_xmlrpc_encode($php_val, $options=array())
3479
+	function php_xmlrpc_encode($php_val, $options = array())
3480 3480
 	{
3481 3481
 		$type = gettype($php_val);
3482
-		switch($type)
3482
+		switch ($type)
3483 3483
 		{
3484 3484
 			case 'string':
3485 3485
 				if (in_array('auto_dates', $options) && preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $php_val))
@@ -3508,16 +3508,16 @@  discard block
 block discarded – undo
3508 3508
 				$j = 0;
3509 3509
 				$arr = array();
3510 3510
 				$ko = false;
3511
-				foreach($php_val as $key => $val)
3511
+				foreach ($php_val as $key => $val)
3512 3512
 				{
3513 3513
 					$arr[$key] = php_xmlrpc_encode($val, $options);
3514
-					if(!$ko && $key !== $j)
3514
+					if (!$ko && $key !== $j)
3515 3515
 					{
3516 3516
 						$ko = true;
3517 3517
 					}
3518 3518
 					$j++;
3519 3519
 				}
3520
-				if($ko)
3520
+				if ($ko)
3521 3521
 				{
3522 3522
 					$xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcStruct']);
3523 3523
 				}
@@ -3527,11 +3527,11 @@  discard block
 block discarded – undo
3527 3527
 				}
3528 3528
 				break;
3529 3529
 			case 'object':
3530
-				if(is_a($php_val, 'xmlrpcval'))
3530
+				if (is_a($php_val, 'xmlrpcval'))
3531 3531
 				{
3532 3532
 					$xmlrpc_val = $php_val;
3533 3533
 				}
3534
-				else if(is_a($php_val, 'DateTime'))
3534
+				else if (is_a($php_val, 'DateTime'))
3535 3535
 				{
3536 3536
 					$xmlrpc_val = new xmlrpcval($php_val->format('Ymd\TH:i:s'), $GLOBALS['xmlrpcStruct']);
3537 3537
 				}
@@ -3539,7 +3539,7 @@  discard block
 block discarded – undo
3539 3539
 				{
3540 3540
 					$arr = array();
3541 3541
 					reset($php_val);
3542
-					while(list($k,$v) = each($php_val))
3542
+					while (list($k, $v) = each($php_val))
3543 3543
 					{
3544 3544
 						$arr[$k] = php_xmlrpc_encode($v, $options);
3545 3545
 					}
@@ -3569,7 +3569,7 @@  discard block
 block discarded – undo
3569 3569
 			case 'resource':
3570 3570
 				if (in_array('extension_api', $options))
3571 3571
 				{
3572
-					$xmlrpc_val = new xmlrpcval((int)$php_val, $GLOBALS['xmlrpcInt']);
3572
+					$xmlrpc_val = new xmlrpcval((int) $php_val, $GLOBALS['xmlrpcInt']);
3573 3573
 				}
3574 3574
 				else
3575 3575
 				{
@@ -3593,7 +3593,7 @@  discard block
 block discarded – undo
3593 3593
 	* @param array $options
3594 3594
 	* @return mixed false on error, or an instance of either xmlrpcval, xmlrpcmsg or xmlrpcresp
3595 3595
 	*/
3596
-	function php_xmlrpc_decode_xml($xml_val, $options=array())
3596
+	function php_xmlrpc_decode_xml($xml_val, $options = array())
3597 3597
 	{
3598 3598
 		$GLOBALS['_xh'] = array();
3599 3599
 		$GLOBALS['_xh']['ac'] = '';
@@ -3621,7 +3621,7 @@  discard block
 block discarded – undo
3621 3621
 				if (extension_loaded('mbstring')) {
3622 3622
 					$xml_val = mb_convert_encoding($xml_val, 'UTF-8', $val_encoding);
3623 3623
 				} else {
3624
-					error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $val_encoding);
3624
+					error_log('XML-RPC: '.__METHOD__.': invalid charset encoding of received request: '.$val_encoding);
3625 3625
 				}
3626 3626
 			}
3627 3627
 		}
@@ -3641,7 +3641,7 @@  discard block
 block discarded – undo
3641 3641
 		xml_set_element_handler($parser, 'xmlrpc_se_any', 'xmlrpc_ee');
3642 3642
 		xml_set_character_data_handler($parser, 'xmlrpc_cd');
3643 3643
 		xml_set_default_handler($parser, 'xmlrpc_dh');
3644
-		if(!xml_parse($parser, $xml_val, 1))
3644
+		if (!xml_parse($parser, $xml_val, 1))
3645 3645
 		{
3646 3646
 			$errstr = sprintf('XML error: %s at line %d, column %d',
3647 3647
 						xml_error_string(xml_get_error_code($parser)),
@@ -3651,7 +3651,7 @@  discard block
 block discarded – undo
3651 3651
 			return false;
3652 3652
 		}
3653 3653
 		xml_parser_free($parser);
3654
-		if ($GLOBALS['_xh']['isf'] > 1) // test that $GLOBALS['_xh']['value'] is an obj, too???
3654
+		if ($GLOBALS['_xh']['isf']>1) // test that $GLOBALS['_xh']['value'] is an obj, too???
3655 3655
 		{
3656 3656
 			error_log($GLOBALS['_xh']['isf_reason']);
3657 3657
 			return false;
@@ -3659,7 +3659,7 @@  discard block
 block discarded – undo
3659 3659
 		switch ($GLOBALS['_xh']['rt'])
3660 3660
 		{
3661 3661
 			case 'methodresponse':
3662
-				$v =& $GLOBALS['_xh']['value'];
3662
+				$v = & $GLOBALS['_xh']['value'];
3663 3663
 				if ($GLOBALS['_xh']['isf'] == 1)
3664 3664
 				{
3665 3665
 					$vc = $v->structmem('faultCode');
@@ -3673,7 +3673,7 @@  discard block
 block discarded – undo
3673 3673
 				return $r;
3674 3674
 			case 'methodcall':
3675 3675
 				$m = new xmlrpcmsg($GLOBALS['_xh']['method']);
3676
-				for($i=0; $i < count($GLOBALS['_xh']['params']); $i++)
3676
+				for ($i = 0; $i<count($GLOBALS['_xh']['params']); $i++)
3677 3677
 				{
3678 3678
 					$m->addParam($GLOBALS['_xh']['params'][$i]);
3679 3679
 				}
@@ -3701,18 +3701,18 @@  discard block
 block discarded – undo
3701 3701
 
3702 3702
 		// read chunk-size, chunk-extension (if any) and crlf
3703 3703
 		// get the position of the linebreak
3704
-		$chunkend = strpos($buffer,"\r\n") + 2;
3705
-		$temp = substr($buffer,0,$chunkend);
3706
-		$chunk_size = hexdec( trim($temp) );
3704
+		$chunkend = strpos($buffer, "\r\n")+2;
3705
+		$temp = substr($buffer, 0, $chunkend);
3706
+		$chunk_size = hexdec(trim($temp));
3707 3707
 		$chunkstart = $chunkend;
3708
-		while($chunk_size > 0)
3708
+		while ($chunk_size>0)
3709 3709
 		{
3710
-			$chunkend = strpos($buffer, "\r\n", $chunkstart + $chunk_size);
3710
+			$chunkend = strpos($buffer, "\r\n", $chunkstart+$chunk_size);
3711 3711
 
3712 3712
 			// just in case we got a broken connection
3713
-			if($chunkend == false)
3713
+			if ($chunkend == false)
3714 3714
 			{
3715
-				$chunk = substr($buffer,$chunkstart);
3715
+				$chunk = substr($buffer, $chunkstart);
3716 3716
 				// append chunk-data to entity-body
3717 3717
 				$new .= $chunk;
3718 3718
 				$length += strlen($chunk);
@@ -3720,21 +3720,21 @@  discard block
 block discarded – undo
3720 3720
 			}
3721 3721
 
3722 3722
 			// read chunk-data and crlf
3723
-			$chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
3723
+			$chunk = substr($buffer, $chunkstart, $chunkend-$chunkstart);
3724 3724
 			// append chunk-data to entity-body
3725 3725
 			$new .= $chunk;
3726 3726
 			// length := length + chunk-size
3727 3727
 			$length += strlen($chunk);
3728 3728
 			// read chunk-size and crlf
3729
-			$chunkstart = $chunkend + 2;
3729
+			$chunkstart = $chunkend+2;
3730 3730
 
3731
-			$chunkend = strpos($buffer,"\r\n",$chunkstart)+2;
3732
-			if($chunkend == false)
3731
+			$chunkend = strpos($buffer, "\r\n", $chunkstart)+2;
3732
+			if ($chunkend == false)
3733 3733
 			{
3734 3734
 				break; //just in case we got a broken connection
3735 3735
 			}
3736
-			$temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
3737
-			$chunk_size = hexdec( trim($temp) );
3736
+			$temp = substr($buffer, $chunkstart, $chunkend-$chunkstart);
3737
+			$chunk_size = hexdec(trim($temp));
3738 3738
 			$chunkstart = $chunkend;
3739 3739
 		}
3740 3740
 		return $new;
@@ -3754,7 +3754,7 @@  discard block
 block discarded – undo
3754 3754
 	*
3755 3755
 	* @todo explore usage of mb_http_input(): does it detect http headers + post data? if so, use it instead of hand-detection!!!
3756 3756
 	*/
3757
-	function guess_encoding($httpheader='', $xmlchunk='', $encoding_prefs=null)
3757
+	function guess_encoding($httpheader = '', $xmlchunk = '', $encoding_prefs = null)
3758 3758
 	{
3759 3759
 		// discussion: see http://www.yale.edu/pclt/encoding/
3760 3760
 		// 1 - test if encoding is specified in HTTP HEADERS
@@ -3772,7 +3772,7 @@  discard block
 block discarded – undo
3772 3772
 
3773 3773
 		/// @todo this test will pass if ANY header has charset specification, not only Content-Type. Fix it?
3774 3774
 		$matches = array();
3775
-		if(preg_match('/;\s*charset\s*=([^;]+)/i', $httpheader, $matches))
3775
+		if (preg_match('/;\s*charset\s*=([^;]+)/i', $httpheader, $matches))
3776 3776
 		{
3777 3777
 			return strtoupper(trim($matches[1], " \t\""));
3778 3778
 		}
@@ -3784,15 +3784,15 @@  discard block
 block discarded – undo
3784 3784
 		//     in the xml declaration, and verify if they match.
3785 3785
 		/// @todo implement check as described above?
3786 3786
 		/// @todo implement check for first bytes of string even without a BOM? (It sure looks harder than for cases WITH a BOM)
3787
-		if(preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlchunk))
3787
+		if (preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlchunk))
3788 3788
 		{
3789 3789
 			return 'UCS-4';
3790 3790
 		}
3791
-		elseif(preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlchunk))
3791
+		elseif (preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlchunk))
3792 3792
 		{
3793 3793
 			return 'UTF-16';
3794 3794
 		}
3795
-		elseif(preg_match('/^(\xEF\xBB\xBF)/', $xmlchunk))
3795
+		elseif (preg_match('/^(\xEF\xBB\xBF)/', $xmlchunk))
3796 3796
 		{
3797 3797
 			return 'UTF-8';
3798 3798
 		}
@@ -3801,8 +3801,8 @@  discard block
 block discarded – undo
3801 3801
 		// Details:
3802 3802
 		// SPACE:         (#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
3803 3803
 		// EQ:            SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
3804
-		if (preg_match('/^<\?xml\s+version\s*=\s*'. "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))".
3805
-			'\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
3804
+		if (preg_match('/^<\?xml\s+version\s*=\s*'."((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))".
3805
+			'\s+encoding\s*=\s*'."((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
3806 3806
 			$xmlchunk, $matches))
3807 3807
 		{
3808 3808
 			return strtoupper(substr($matches[2], 1, -1));
@@ -3810,9 +3810,9 @@  discard block
 block discarded – undo
3810 3810
 
3811 3811
 		// 4 - if mbstring is available, let it do the guesswork
3812 3812
 		// NB: we favour finding an encoding that is compatible with what we can process
3813
-		if(extension_loaded('mbstring'))
3813
+		if (extension_loaded('mbstring'))
3814 3814
 		{
3815
-			if($encoding_prefs)
3815
+			if ($encoding_prefs)
3816 3816
 			{
3817 3817
 				$enc = mb_detect_encoding($xmlchunk, $encoding_prefs);
3818 3818
 			}
@@ -3822,7 +3822,7 @@  discard block
 block discarded – undo
3822 3822
 			}
3823 3823
 			// NB: mb_detect likes to call it ascii, xml parser likes to call it US_ASCII...
3824 3824
 			// IANA also likes better US-ASCII, so go with it
3825
-			if($enc == 'ASCII')
3825
+			if ($enc == 'ASCII')
3826 3826
 			{
3827 3827
 				$enc = 'US-'.$enc;
3828 3828
 			}
@@ -3865,8 +3865,8 @@  discard block
 block discarded – undo
3865 3865
 		// Details:
3866 3866
 		// SPACE:		(#x20 | #x9 | #xD | #xA)+ === [ \x9\xD\xA]+
3867 3867
 		// EQ:			SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]*
3868
-		if (preg_match('/^<\?xml\s+version\s*=\s*' . "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))" .
3869
-			'\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
3868
+		if (preg_match('/^<\?xml\s+version\s*=\s*'."((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))".
3869
+			'\s+encoding\s*=\s*'."((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
3870 3870
 			$xmlChunk, $matches))
3871 3871
 		{
3872 3872
 			return true;
@@ -3885,7 +3885,7 @@  discard block
 block discarded – undo
3885 3885
 	function is_valid_charset($encoding, $validlist)
3886 3886
 	{
3887 3887
 		$charset_supersets = array(
3888
-			'US-ASCII' => array ('ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4',
3888
+			'US-ASCII' => array('ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4',
3889 3889
 				'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8',
3890 3890
 				'ISO-8859-9', 'ISO-8859-10', 'ISO-8859-11', 'ISO-8859-12',
3891 3891
 				'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'UTF-8',
Please login to merge, or discard this patch.