| 12 |
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 13 |
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 14 |
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 15 |
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 16 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 17 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 18 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 72 |
$GLOBALS['XML_RPC_defencoding']="UTF-8"; |
$GLOBALS['XML_RPC_defencoding']="UTF-8"; |
| 73 |
|
|
| 74 |
// let user errors start at 800 |
// let user errors start at 800 |
| 75 |
$GLOBALS['XML_RPC_erruser']=800; |
$GLOBALS['XML_RPC_erruser']=800; |
| 76 |
// let XML parse errors start at 100 |
// let XML parse errors start at 100 |
| 77 |
$GLOBALS['XML_RPC_errxml']=100; |
$GLOBALS['XML_RPC_errxml']=100; |
| 78 |
|
|
| 99 |
{ |
{ |
| 100 |
$top=split("&", $string); |
$top=split("&", $string); |
| 101 |
$op=""; |
$op=""; |
| 102 |
$i=0; |
$i=0; |
| 103 |
while($i<sizeof($top)) { |
while($i<sizeof($top)) { |
| 104 |
if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs)) { |
if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs)) { |
| 105 |
$op.=ereg_replace("^[#a-zA-Z0-9]+;", |
$op.=ereg_replace("^[#a-zA-Z0-9]+;", |
| 106 |
XML_RPC_lookup_entity($regs[1]), |
XML_RPC_lookup_entity($regs[1]), |
| 107 |
$top[$i]); |
$top[$i]); |
| 108 |
} else { |
} else { |
| 109 |
if ($i==0) |
if ($i==0) |
| 110 |
$op=$top[$i]; |
$op=$top[$i]; |
| 111 |
else |
else |
| 112 |
$op.="&" . $top[$i]; |
$op.="&" . $top[$i]; |
| 113 |
} |
} |
| 114 |
|
|
| 115 |
$i++; |
$i++; |
| 116 |
} |
} |
| 117 |
return $op; |
return $op; |
| 121 |
function XML_RPC_lookup_entity($ent) |
function XML_RPC_lookup_entity($ent) |
| 122 |
{ |
{ |
| 123 |
global $XML_RPC_entities; |
global $XML_RPC_entities; |
| 124 |
|
|
| 125 |
if ($XML_RPC_entities[strtolower($ent)]) |
if ($XML_RPC_entities[strtolower($ent)]) |
| 126 |
return $XML_RPC_entities[strtolower($ent)]; |
return $XML_RPC_entities[strtolower($ent)]; |
| 127 |
|
|
| 128 |
if (ereg("^#([0-9]+)$", $ent, $regs)) |
if (ereg("^#([0-9]+)$", $ent, $regs)) |
| 129 |
return chr($regs[1]); |
return chr($regs[1]); |
| 130 |
|
|
| 131 |
return "?"; |
return "?"; |
| 132 |
} |
} |
| 133 |
|
|
| 135 |
function XML_RPC_se($parser, $name, $attrs) |
function XML_RPC_se($parser, $name, $attrs) |
| 136 |
{ |
{ |
| 137 |
global $XML_RPC_xh, $XML_RPC_DateTime, $XML_RPC_String; |
global $XML_RPC_xh, $XML_RPC_DateTime, $XML_RPC_String; |
| 138 |
|
|
| 139 |
switch($name) { |
switch($name) { |
| 140 |
case "STRUCT": |
case "STRUCT": |
| 141 |
case "ARRAY": |
case "ARRAY": |
| 142 |
$XML_RPC_xh[$parser]['st'].="array("; |
$XML_RPC_xh[$parser]['st'].="array("; |
| 143 |
$XML_RPC_xh[$parser]['cm']++; |
$XML_RPC_xh[$parser]['cm']++; |
| 144 |
// this last line turns quoting off |
// this last line turns quoting off |
| 145 |
// this means if we get an empty array we'll |
// this means if we get an empty array we'll |
| 146 |
// simply get a bit of whitespace in the eval |
// simply get a bit of whitespace in the eval |
| 147 |
$XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['qt']=0; |
| 148 |
break; |
break; |
| 156 |
$XML_RPC_xh[$parser]['st']=""; |
$XML_RPC_xh[$parser]['st']=""; |
| 157 |
break; |
break; |
| 158 |
case "VALUE": |
case "VALUE": |
| 159 |
$XML_RPC_xh[$parser]['st'].="new XML_RPC_Value("; |
$XML_RPC_xh[$parser]['st'].="new XML_RPC_Value("; |
| 160 |
$XML_RPC_xh[$parser]['lv']=1; |
$XML_RPC_xh[$parser]['lv']=1; |
| 161 |
$XML_RPC_xh[$parser]['vt']=$XML_RPC_String; |
$XML_RPC_xh[$parser]['vt']=$XML_RPC_String; |
| 162 |
$XML_RPC_xh[$parser]['ac']=""; |
$XML_RPC_xh[$parser]['ac']=""; |
| 165 |
// time we reach the first data segment then the type is string |
// time we reach the first data segment then the type is string |
| 166 |
// by implication and we need to add in a quote |
// by implication and we need to add in a quote |
| 167 |
break; |
break; |
| 168 |
|
|
| 169 |
case "I4": |
case "I4": |
| 170 |
case "INT": |
case "INT": |
| 171 |
case "STRING": |
case "STRING": |
| 174 |
case "DATETIME.ISO8601": |
case "DATETIME.ISO8601": |
| 175 |
case "BASE64": |
case "BASE64": |
| 176 |
$XML_RPC_xh[$parser]['ac']=""; // reset the accumulator |
$XML_RPC_xh[$parser]['ac']=""; // reset the accumulator |
| 177 |
|
|
| 178 |
if ($name=="DATETIME.ISO8601" || $name=="STRING") { |
if ($name=="DATETIME.ISO8601" || $name=="STRING") { |
| 179 |
$XML_RPC_xh[$parser]['qt']=1; |
$XML_RPC_xh[$parser]['qt']=1; |
| 180 |
|
|
| 181 |
if ($name=="DATETIME.ISO8601") |
if ($name=="DATETIME.ISO8601") |
| 182 |
$XML_RPC_xh[$parser]['vt']=$XML_RPC_DateTime; |
$XML_RPC_xh[$parser]['vt']=$XML_RPC_DateTime; |
| 183 |
|
|
| 184 |
} else if ($name=="BASE64") { |
} else if ($name=="BASE64") { |
| 185 |
$XML_RPC_xh[$parser]['qt']=2; |
$XML_RPC_xh[$parser]['qt']=2; |
| 186 |
} else { |
} else { |
| 190 |
$XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['qt']=0; |
| 191 |
} |
} |
| 192 |
break; |
break; |
| 193 |
|
|
| 194 |
case "MEMBER": |
case "MEMBER": |
| 195 |
$XML_RPC_xh[$parser]['ac']=""; |
$XML_RPC_xh[$parser]['ac']=""; |
| 196 |
break; |
break; |
| 197 |
default: |
default: |
| 198 |
break; |
break; |
| 199 |
} |
} |
| 200 |
|
|
| 201 |
if ($name!="VALUE") $XML_RPC_xh[$parser]['lv']=0; |
if ($name!="VALUE") $XML_RPC_xh[$parser]['lv']=0; |
| 202 |
} |
} |
| 203 |
|
|
| 212 |
if ($XML_RPC_xh[$parser]['cm'] && substr($XML_RPC_xh[$parser]['st'], -1) ==',') { |
if ($XML_RPC_xh[$parser]['cm'] && substr($XML_RPC_xh[$parser]['st'], -1) ==',') { |
| 213 |
$XML_RPC_xh[$parser]['st']=substr($XML_RPC_xh[$parser]['st'],0,-1); |
$XML_RPC_xh[$parser]['st']=substr($XML_RPC_xh[$parser]['st'],0,-1); |
| 214 |
} |
} |
| 215 |
|
|
| 216 |
$XML_RPC_xh[$parser]['st'].=")"; |
$XML_RPC_xh[$parser]['st'].=")"; |
| 217 |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
| 218 |
$XML_RPC_xh[$parser]['cm']--; |
$XML_RPC_xh[$parser]['cm']--; |
| 219 |
break; |
break; |
| 220 |
|
|
| 221 |
case "NAME": |
case "NAME": |
| 222 |
$XML_RPC_xh[$parser]['st'].= $XML_RPC_xh[$parser]['ac'] . "' => "; |
$XML_RPC_xh[$parser]['st'].= $XML_RPC_xh[$parser]['ac'] . "' => "; |
| 223 |
break; |
break; |
| 224 |
|
|
| 225 |
case "BOOLEAN": |
case "BOOLEAN": |
| 226 |
// special case here: we translate boolean 1 or 0 into PHP |
// special case here: we translate boolean 1 or 0 into PHP |
| 227 |
// constants true or false |
// constants true or false |
| 228 |
if ($XML_RPC_xh[$parser]['ac']=='1') |
if ($XML_RPC_xh[$parser]['ac']=='1') |
| 229 |
$XML_RPC_xh[$parser]['ac']="true"; |
$XML_RPC_xh[$parser]['ac']="true"; |
| 230 |
else |
else |
| 231 |
$XML_RPC_xh[$parser]['ac']="false"; |
$XML_RPC_xh[$parser]['ac']="false"; |
| 232 |
|
|
| 233 |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
| 234 |
// Drop through intentionally. |
// Drop through intentionally. |
| 235 |
|
|
| 236 |
case "I4": |
case "I4": |
| 237 |
case "INT": |
case "INT": |
| 238 |
case "STRING": |
case "STRING": |
| 241 |
case "BASE64": |
case "BASE64": |
| 242 |
if ($XML_RPC_xh[$parser]['qt']==1) { |
if ($XML_RPC_xh[$parser]['qt']==1) { |
| 243 |
// we use double quotes rather than single so backslashification works OK |
// we use double quotes rather than single so backslashification works OK |
| 244 |
$XML_RPC_xh[$parser]['st'].="\"". $XML_RPC_xh[$parser]['ac'] . "\""; |
$XML_RPC_xh[$parser]['st'].="\"". $XML_RPC_xh[$parser]['ac'] . "\""; |
| 245 |
} else if ($XML_RPC_xh[$parser]['qt']==2) { |
} else if ($XML_RPC_xh[$parser]['qt']==2) { |
| 246 |
$XML_RPC_xh[$parser]['st'].="base64_decode('". $XML_RPC_xh[$parser]['ac'] . "')"; |
$XML_RPC_xh[$parser]['st'].="base64_decode('". $XML_RPC_xh[$parser]['ac'] . "')"; |
| 247 |
} else if ($name=="BOOLEAN") { |
} else if ($name=="BOOLEAN") { |
| 248 |
$XML_RPC_xh[$parser]['st'].=$XML_RPC_xh[$parser]['ac']; |
$XML_RPC_xh[$parser]['st'].=$XML_RPC_xh[$parser]['ac']; |
| 249 |
} else { |
} else { |
| 253 |
// TODO: find a better way of throwing an error |
// TODO: find a better way of throwing an error |
| 254 |
// than this! |
// than this! |
| 255 |
error_log("XML-RPC: non numeric value received in INT or DOUBLE"); |
error_log("XML-RPC: non numeric value received in INT or DOUBLE"); |
| 256 |
$XML_RPC_xh[$parser]['st'].="ERROR_NON_NUMERIC_FOUND"; |
$XML_RPC_xh[$parser]['st'].="ERROR_NON_NUMERIC_FOUND"; |
| 257 |
} else { |
} else { |
| 258 |
// it's ok, add it on |
// it's ok, add it on |
| 259 |
$XML_RPC_xh[$parser]['st'].=$XML_RPC_xh[$parser]['ac']; |
$XML_RPC_xh[$parser]['st'].=$XML_RPC_xh[$parser]['ac']; |
| 260 |
} |
} |
| 261 |
} |
} |
| 262 |
|
|
| 263 |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
| 264 |
$XML_RPC_xh[$parser]['lv']=3; // indicate we've found a value |
$XML_RPC_xh[$parser]['lv']=3; // indicate we've found a value |
| 265 |
break; |
break; |
| 266 |
|
|
| 267 |
case "VALUE": |
case "VALUE": |
| 268 |
// deal with a string value |
// deal with a string value |
| 269 |
if (strlen($XML_RPC_xh[$parser]['ac'])>0 && |
if (strlen($XML_RPC_xh[$parser]['ac'])>0 && |
| 270 |
$XML_RPC_xh[$parser]['vt']==$XML_RPC_String) { |
$XML_RPC_xh[$parser]['vt']==$XML_RPC_String) { |
| 271 |
|
|
| 272 |
$XML_RPC_xh[$parser]['st'].="\"". $XML_RPC_xh[$parser]['ac'] . "\""; |
$XML_RPC_xh[$parser]['st'].="\"". $XML_RPC_xh[$parser]['ac'] . "\""; |
| 273 |
} |
} |
| 274 |
|
|
| 275 |
// This if() detects if no scalar was inside <VALUE></VALUE> |
// This if() detects if no scalar was inside <VALUE></VALUE> |
| 276 |
// and pads an empty "". |
// and pads an empty "". |
| 277 |
if($XML_RPC_xh[$parser]['st'][strlen($XML_RPC_xh[$parser]['st'])-1] == '(') { |
if($XML_RPC_xh[$parser]['st'][strlen($XML_RPC_xh[$parser]['st'])-1] == '(') { |
| 280 |
$XML_RPC_xh[$parser]['st'].=", '" . $XML_RPC_xh[$parser]['vt'] . "')"; |
$XML_RPC_xh[$parser]['st'].=", '" . $XML_RPC_xh[$parser]['vt'] . "')"; |
| 281 |
if ($XML_RPC_xh[$parser]['cm']) $XML_RPC_xh[$parser]['st'].=","; |
if ($XML_RPC_xh[$parser]['cm']) $XML_RPC_xh[$parser]['st'].=","; |
| 282 |
break; |
break; |
| 283 |
|
|
| 284 |
case "MEMBER": |
case "MEMBER": |
| 285 |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
| 286 |
break; |
break; |
| 287 |
|
|
| 288 |
case "DATA": |
case "DATA": |
| 289 |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
| 290 |
break; |
break; |
| 291 |
|
|
| 292 |
case "PARAM": |
case "PARAM": |
| 293 |
$XML_RPC_xh[$parser]['params'][]=$XML_RPC_xh[$parser]['st']; |
$XML_RPC_xh[$parser]['params'][]=$XML_RPC_xh[$parser]['st']; |
| 294 |
break; |
break; |
| 295 |
|
|
| 296 |
case "METHODNAME": |
case "METHODNAME": |
| 297 |
$XML_RPC_xh[$parser]['method']=ereg_replace("^[\n\r\t ]+", "", $XML_RPC_xh[$parser]['ac']); |
$XML_RPC_xh[$parser]['method']=ereg_replace("^[\n\r\t ]+", "", $XML_RPC_xh[$parser]['ac']); |
| 298 |
break; |
break; |
| 299 |
|
|
| 300 |
case "BOOLEAN": |
case "BOOLEAN": |
| 301 |
// special case here: we translate boolean 1 or 0 into PHP |
// special case here: we translate boolean 1 or 0 into PHP |
| 302 |
// constants true or false |
// constants true or false |
| 303 |
if ($XML_RPC_xh[$parser]['ac']=='1') |
if ($XML_RPC_xh[$parser]['ac']=='1') |
| 304 |
$XML_RPC_xh[$parser]['ac']="true"; |
$XML_RPC_xh[$parser]['ac']="true"; |
| 305 |
else |
else |
| 306 |
$XML_RPC_xh[$parser]['ac']="false"; |
$XML_RPC_xh[$parser]['ac']="false"; |
| 307 |
|
|
| 308 |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
| 309 |
break; |
break; |
| 310 |
|
|
| 311 |
default: |
default: |
| 312 |
break; |
break; |
| 313 |
} |
} |
| 319 |
|
|
| 320 |
|
|
| 321 |
function XML_RPC_cd($parser, $data) |
function XML_RPC_cd($parser, $data) |
| 322 |
{ |
{ |
| 323 |
global $XML_RPC_xh, $XML_RPC_backslash; |
global $XML_RPC_xh, $XML_RPC_backslash; |
| 324 |
|
|
| 325 |
//if (ereg("^[\n\r \t]+$", $data)) return; |
//if (ereg("^[\n\r \t]+$", $data)) return; |
| 326 |
// print "adding [${data}]\n"; |
// print "adding [${data}]\n"; |
| 327 |
|
|
| 328 |
if ($XML_RPC_xh[$parser]['lv']!=3) { |
if ($XML_RPC_xh[$parser]['lv']!=3) { |
| 329 |
// "lookforvalue==3" means that we've found an entire value |
// "lookforvalue==3" means that we've found an entire value |
| 330 |
// and should discard any further character data |
// and should discard any further character data |
| 331 |
|
|
| 332 |
if ($XML_RPC_xh[$parser]['lv']==1) { |
if ($XML_RPC_xh[$parser]['lv']==1) { |
| 333 |
// if we've found text and we're just in a <value> then |
// if we've found text and we're just in a <value> then |
| 334 |
// turn quoting on, as this will be a string |
// turn quoting on, as this will be a string |
| 335 |
$XML_RPC_xh[$parser]['qt']=1; |
$XML_RPC_xh[$parser]['qt']=1; |
| 336 |
// and say we've found a value |
// and say we've found a value |
| 337 |
$XML_RPC_xh[$parser]['lv']=2; |
$XML_RPC_xh[$parser]['lv']=2; |
| 338 |
} |
} |
| 339 |
|
|
| 340 |
// replace characters that eval would |
// replace characters that eval would |
| 341 |
// do special things with |
// do special things with |
| 342 |
@$XML_RPC_xh[$parser]['ac'].=str_replace('$', '\$', |
@$XML_RPC_xh[$parser]['ac'].=str_replace('$', '\$', |
| 350 |
{ |
{ |
| 351 |
global $XML_RPC_xh; |
global $XML_RPC_xh; |
| 352 |
if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") { |
if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") { |
| 353 |
if ($XML_RPC_xh[$parser]['lv']==1) { |
if ($XML_RPC_xh[$parser]['lv']==1) { |
| 354 |
$XML_RPC_xh[$parser]['qt']=1; |
$XML_RPC_xh[$parser]['qt']=1; |
| 355 |
$XML_RPC_xh[$parser]['lv']=2; |
$XML_RPC_xh[$parser]['lv']=2; |
| 356 |
} |
} |
| 357 |
$XML_RPC_xh[$parser]['ac'].=str_replace('$', '\$', |
$XML_RPC_xh[$parser]['ac'].=str_replace('$', '\$', |
| 358 |
str_replace('"', '\"', str_replace(chr(92), |
str_replace('"', '\"', str_replace(chr(92), |
| 371 |
var $debug=0; |
var $debug=0; |
| 372 |
var $username=""; |
var $username=""; |
| 373 |
var $password=""; |
var $password=""; |
| 374 |
|
|
| 375 |
function XML_RPC_Client($path, $server, $port=80, $proxy="", $proxy_port=8080) |
function XML_RPC_Client($path, $server, $port = 80, |
| 376 |
|
$proxy = '', $proxy_port = 8080, |
| 377 |
|
$proxy_user = '', $proxy_pass = '') |
| 378 |
{ |
{ |
| 379 |
$this->port=$port; |
$this->port=$port; |
| 380 |
$this->server=$server; |
$this->server=$server; |
| 381 |
$this->path=$path; |
$this->path=$path; |
| 382 |
$this->proxy = $proxy; |
$this->proxy = $proxy; |
| 383 |
$this->proxy_port = $proxy_port ; |
$this->proxy_port = $proxy_port; |
| 384 |
|
$this->proxy_user = $proxy_user; |
| 385 |
|
$this->proxy_pass = $proxy_pass; |
| 386 |
} |
} |
| 387 |
|
|
| 388 |
function setDebug($in) |
function setDebug($in) |
| 389 |
{ |
{ |
| 390 |
if ($in) { |
if ($in) { |
| 391 |
$this->debug=1; |
$this->debug=1; |
| 392 |
} else { |
} else { |
| 393 |
$this->debug=0; |
$this->debug=0; |
| 405 |
// where msg is an xmlrpcmsg |
// where msg is an xmlrpcmsg |
| 406 |
$msg->debug=$this->debug; |
$msg->debug=$this->debug; |
| 407 |
return $this->sendPayloadHTTP10($msg, $this->server, $this->port, |
return $this->sendPayloadHTTP10($msg, $this->server, $this->port, |
| 408 |
$timeout, $this->username, |
$timeout, $this->username, |
| 409 |
$this->password); |
$this->password); |
| 410 |
} |
} |
| 411 |
|
|
| 418 |
$fp=fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr, $timeout); |
$fp=fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr, $timeout); |
| 419 |
} |
} |
| 420 |
else { |
else { |
| 421 |
$fp=fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr); |
$fp=fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr); |
| 422 |
} |
} |
| 423 |
} |
} |
| 424 |
else { |
else { |
| 425 |
if($timeout > 0) { |
if($timeout > 0) { |
| 426 |
$fp=fsockopen($server, $port, $this->errno, $this->errstr, $timeout); |
$fp=fsockopen($server, $port, $this->errno, $this->errstr, $timeout); |
| 427 |
} |
} |
| 428 |
else { |
else { |
| 429 |
$fp=fsockopen($server, $port, $this->errno, $this->errstr); |
$fp=fsockopen($server, $port, $this->errno, $this->errstr); |
| 430 |
} |
} |
| 431 |
} |
} |
| 432 |
|
|
| 436 |
else if(!$fp) { |
else if(!$fp) { |
| 437 |
PEAR::raiseError("Connection to RPC server ".$this->server." failed"); |
PEAR::raiseError("Connection to RPC server ".$this->server." failed"); |
| 438 |
} |
} |
| 439 |
|
|
|
if (!$fp) { return; } |
|
|
|
|
| 440 |
// Only create the payload if it was not created previously |
// Only create the payload if it was not created previously |
| 441 |
if(empty($msg->payload)) $msg->createPayload(); |
if(empty($msg->payload)) $msg->createPayload(); |
| 442 |
|
|
| 443 |
// thanks to Grant Rauscher <grant7@firstworld.net> |
// thanks to Grant Rauscher <grant7@firstworld.net> |
| 444 |
// for this |
// for this |
| 445 |
$credentials=""; |
$credentials=""; |
| 447 |
$credentials="Authorization: Basic " . |
$credentials="Authorization: Basic " . |
| 448 |
base64_encode($username . ":" . $password) . "\r\n"; |
base64_encode($username . ":" . $password) . "\r\n"; |
| 449 |
} |
} |
| 450 |
|
|
| 451 |
|
|
| 452 |
if($this->proxy) { |
if($this->proxy) { |
| 453 |
$op = "POST http://" . $this->server; |
$op = "POST http://" . $this->server; |
| 454 |
|
|
| 455 |
if($this->proxy_port) { |
if($this->proxy_port) { |
| 456 |
$op .= ":" . $this->port; |
$op .= ":" . $this->port; |
| 457 |
} |
} |
| 459 |
else { |
else { |
| 460 |
$op = "POST "; |
$op = "POST "; |
| 461 |
} |
} |
| 462 |
|
|
| 463 |
$op .= $this->path. " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n" . |
$op .= $this->path. " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n" . |
| 464 |
"Host: ". $this->server . "\r\n" . |
"Host: ". $this->server . "\r\n"; |
| 465 |
$credentials . |
if ($this->proxy && $this->proxy_user != '') { |
| 466 |
|
$op .= 'Proxy-Authorization: Basic ' . |
| 467 |
|
base64_encode($this->proxy_user . ':' . $this->proxy_pass) . |
| 468 |
|
"\r\n"; |
| 469 |
|
} |
| 470 |
|
$op .= $credentials . |
| 471 |
"Content-Type: text/xml\r\nContent-Length: " . |
"Content-Type: text/xml\r\nContent-Length: " . |
| 472 |
strlen($msg->payload) . "\r\n\r\n" . |
strlen($msg->payload) . "\r\n\r\n" . |
| 473 |
$msg->payload; |
$msg->payload; |
| 474 |
|
|
| 475 |
// print($op); |
// print($op); |
| 476 |
|
|
| 477 |
if (!fputs($fp, $op, strlen($op))) { |
if (!$fp || !fputs($fp, $op, strlen($op))) { |
| 478 |
$this->errstr="Write error"; |
$this->errstr="Write error"; |
| 479 |
return 0; |
return 0; |
| 480 |
} |
} |
| 502 |
} |
} |
| 503 |
} |
} |
| 504 |
|
|
| 505 |
function faultCode() |
function faultCode() |
| 506 |
{ |
{ |
| 507 |
if (isset($this->fn)) |
if (isset($this->fn)) |
| 508 |
return $this->fn; |
return $this->fn; |
| 509 |
else |
else |
| 510 |
return 0; |
return 0; |
| 513 |
function faultString() { return $this->fs; } |
function faultString() { return $this->fs; } |
| 514 |
function value() { return $this->xv; } |
function value() { return $this->xv; } |
| 515 |
|
|
| 516 |
function serialize() { |
function serialize() { |
| 517 |
$rs="<methodResponse>\n"; |
$rs="<methodResponse>\n"; |
| 518 |
if ($this->fn) { |
if ($this->fn) { |
| 519 |
$rs.="<fault> |
$rs.="<fault> |
| 531 |
</value> |
</value> |
| 532 |
</fault>"; |
</fault>"; |
| 533 |
} else { |
} else { |
| 534 |
$rs.="<params>\n<param>\n" . $this->xv->serialize() . |
$rs.="<params>\n<param>\n" . $this->xv->serialize() . |
| 535 |
"</param>\n</params>"; |
"</param>\n</params>"; |
| 536 |
} |
} |
| 537 |
$rs.="\n</methodResponse>"; |
$rs.="\n</methodResponse>"; |
| 551 |
{ |
{ |
| 552 |
$this->methodname=$meth; |
$this->methodname=$meth; |
| 553 |
if (is_array($pars) && sizeof($pars)>0) { |
if (is_array($pars) && sizeof($pars)>0) { |
| 554 |
for($i=0; $i<sizeof($pars); $i++) |
for($i=0; $i<sizeof($pars); $i++) |
| 555 |
$this->addParam($pars[$i]); |
$this->addParam($pars[$i]); |
| 556 |
} |
} |
| 557 |
} |
} |
| 560 |
{ |
{ |
| 561 |
return "<?xml version=\"1.0\"?>\n<methodCall>\n"; |
return "<?xml version=\"1.0\"?>\n<methodCall>\n"; |
| 562 |
} |
} |
| 563 |
|
|
| 564 |
function xml_footer() |
function xml_footer() |
| 565 |
{ |
{ |
| 566 |
return "</methodCall>\n"; |
return "</methodCall>\n"; |
| 615 |
{ |
{ |
| 616 |
global $XML_RPC_xh,$XML_RPC_err,$XML_RPC_str; |
global $XML_RPC_xh,$XML_RPC_err,$XML_RPC_str; |
| 617 |
global $XML_RPC_defencoding; |
global $XML_RPC_defencoding; |
| 618 |
|
|
| 619 |
$parser = xml_parser_create($XML_RPC_defencoding); |
$parser = xml_parser_create($XML_RPC_defencoding); |
| 620 |
|
|
| 621 |
$XML_RPC_xh[$parser]=array(); |
$XML_RPC_xh[$parser]=array(); |
| 622 |
|
|
| 623 |
$XML_RPC_xh[$parser]['st']=""; |
$XML_RPC_xh[$parser]['st']=""; |
| 624 |
$XML_RPC_xh[$parser]['cm']=0; |
$XML_RPC_xh[$parser]['cm']=0; |
| 625 |
$XML_RPC_xh[$parser]['isf']=0; |
$XML_RPC_xh[$parser]['isf']=0; |
| 626 |
$XML_RPC_xh[$parser]['ac']=""; |
$XML_RPC_xh[$parser]['ac']=""; |
| 627 |
$XML_RPC_xh[$parser]['qt']=""; |
$XML_RPC_xh[$parser]['qt']=""; |
| 628 |
|
|
| 629 |
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); |
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); |
| 630 |
xml_set_element_handler($parser, "XML_RPC_se", "XML_RPC_ee"); |
xml_set_element_handler($parser, "XML_RPC_se", "XML_RPC_ee"); |
| 631 |
xml_set_character_data_handler($parser, "XML_RPC_cd"); |
xml_set_character_data_handler($parser, "XML_RPC_cd"); |
| 633 |
$xmlrpc_value = new XML_RPC_Value; |
$xmlrpc_value = new XML_RPC_Value; |
| 634 |
|
|
| 635 |
$hdrfnd=0; |
$hdrfnd=0; |
| 636 |
if ($this->debug) |
if ($this->debug) { |
| 637 |
print "<PRE>---GOT---\n" . htmlspecialchars($data) . |
print "<PRE>---GOT---\n"; |
| 638 |
"\n---END---\n</PRE>"; |
print isset($_SERVER['SERVER_PROTOCOL']) ? htmlspecialchars($data) : $data; |
| 639 |
|
print "\n---END---\n</PRE>"; |
| 640 |
|
} |
| 641 |
// see if we got an HTTP 200 OK, else bomb |
// see if we got an HTTP 200 OK, else bomb |
| 642 |
// but only do this if we're using the HTTP protocol. |
// but only do this if we're using the HTTP protocol. |
| 643 |
if (ereg("^HTTP",$data) && |
if (ereg("^HTTP",$data) && |
| 644 |
!ereg("^HTTP/[0-9\.]+ 200 ", $data)) { |
!ereg("^HTTP/[0-9\.]+ 200 ", $data)) { |
| 645 |
$errstr= substr($data, 0, strpos($data, "\n")-1); |
$errstr= substr($data, 0, strpos($data, "\n")-1); |
| 646 |
error_log("HTTP error, got response: " .$errstr); |
error_log("HTTP error, got response: " .$errstr); |
| 651 |
return $r; |
return $r; |
| 652 |
} |
} |
| 653 |
// gotta get rid of headers here |
// gotta get rid of headers here |
| 654 |
if ((!$hdrfnd) && ereg("^(.*)\r\n\r\n",$data,$XML_RPC_xh[$parser]['ha'])) { |
|
| 655 |
$data=ereg_replace("^.*\r\n\r\n", "", $data); |
|
| 656 |
|
if ((!$hdrfnd) && ($brpos = strpos($data,"\r\n\r\n"))) { |
| 657 |
|
$XML_RPC_xh[$parser]['ha'] = substr($data,0,$brpos); |
| 658 |
|
$data= substr($data,$brpos+4); |
| 659 |
$hdrfnd=1; |
$hdrfnd=1; |
| 660 |
} |
} |
| 661 |
|
|
| 662 |
if (!xml_parse($parser, $data, sizeof($data))) { |
if (!xml_parse($parser, $data, sizeof($data))) { |
| 663 |
// thanks to Peter Kocks <peter.kocks@baygate.com> |
// thanks to Peter Kocks <peter.kocks@baygate.com> |
| 664 |
if((xml_get_current_line_number($parser)) == 1) |
if((xml_get_current_line_number($parser)) == 1) |
| 665 |
$errstr = "XML error at line 1, check URL"; |
$errstr = "XML error at line 1, check URL"; |
| 666 |
else |
else |
| 667 |
$errstr = sprintf("XML error: %s at line %d", |
$errstr = sprintf("XML error: %s at line %d", |
| 675 |
} |
} |
| 676 |
xml_parser_free($parser); |
xml_parser_free($parser); |
| 677 |
if ($this->debug) { |
if ($this->debug) { |
| 678 |
print "<PRE>---EVALING---[" . |
print "<PRE>---EVALING---[" . |
| 679 |
strlen($XML_RPC_xh[$parser]['st']) . " chars]---\n" . |
strlen($XML_RPC_xh[$parser]['st']) . " chars]---\n" . |
| 680 |
htmlspecialchars($XML_RPC_xh[$parser]['st']) . ";\n---END---</PRE>"; |
htmlspecialchars($XML_RPC_xh[$parser]['st']) . ";\n---END---</PRE>"; |
| 681 |
} |
} |
| 682 |
if (strlen($XML_RPC_xh[$parser]['st'])==0) { |
if (strlen($XML_RPC_xh[$parser]['st'])==0) { |
| 690 |
if ($XML_RPC_xh[$parser]['isf']) { |
if ($XML_RPC_xh[$parser]['isf']) { |
| 691 |
$f=$v->structmem("faultCode"); |
$f=$v->structmem("faultCode"); |
| 692 |
$fs=$v->structmem("faultString"); |
$fs=$v->structmem("faultString"); |
| 693 |
$r=new XML_RPC_Response($v, $f->scalarval(), |
$r=new XML_RPC_Response($v, $f->scalarval(), |
| 694 |
$fs->scalarval()); |
$fs->scalarval()); |
| 695 |
} else { |
} else { |
| 696 |
$r=new XML_RPC_Response($v); |
$r=new XML_RPC_Response($v); |
| 728 |
function addScalar($val, $type="string") |
function addScalar($val, $type="string") |
| 729 |
{ |
{ |
| 730 |
global $XML_RPC_Types, $XML_RPC_Boolean; |
global $XML_RPC_Types, $XML_RPC_Boolean; |
| 731 |
|
|
| 732 |
if ($this->mytype==1) { |
if ($this->mytype==1) { |
| 733 |
echo "<B>XML_RPC_Value</B>: scalar can have only one value<BR>"; |
echo "<B>XML_RPC_Value</B>: scalar can have only one value<BR>"; |
| 734 |
return 0; |
return 0; |
| 738 |
echo "<B>XML_RPC_Value</B>: not a scalar type (${typeof})<BR>"; |
echo "<B>XML_RPC_Value</B>: not a scalar type (${typeof})<BR>"; |
| 739 |
return 0; |
return 0; |
| 740 |
} |
} |
| 741 |
|
|
| 742 |
if ($type==$XML_RPC_Boolean) { |
if ($type==$XML_RPC_Boolean) { |
| 743 |
if (strcasecmp($val,"true")==0 || |
if (strcasecmp($val,"true")==0 || |
| 744 |
$val==1 || |
$val==1 || |
| 745 |
($val==true && |
($val==true && |
| 746 |
strcasecmp($val,"false"))) { |
strcasecmp($val,"false"))) { |
| 747 |
|
|
| 748 |
$val=1; |
$val=1; |
| 749 |
} else { |
} else { |
| 750 |
$val=0; |
$val=0; |
| 751 |
} |
} |
| 752 |
} |
} |
| 753 |
|
|
| 754 |
if ($this->mytype==2) { |
if ($this->mytype==2) { |
| 755 |
// we're adding to an array here |
// we're adding to an array here |
| 756 |
$ar=$this->me["array"]; |
$ar=$this->me["array"]; |
| 768 |
{ |
{ |
| 769 |
global $XML_RPC_Types; |
global $XML_RPC_Types; |
| 770 |
if ($this->mytype!=0) { |
if ($this->mytype!=0) { |
| 771 |
echo "<B>XML_RPC_Value</B>: already initialized as a [" . |
echo "<B>XML_RPC_Value</B>: already initialized as a [" . |
| 772 |
$this->kindOf() . "]<BR>"; |
$this->kindOf() . "]<BR>"; |
| 773 |
return 0; |
return 0; |
| 774 |
} |
} |
| 781 |
{ |
{ |
| 782 |
global $XML_RPC_Types; |
global $XML_RPC_Types; |
| 783 |
if ($this->mytype!=0) { |
if ($this->mytype!=0) { |
| 784 |
echo "<B>XML_RPC_Value</B>: already initialized as a [" . |
echo "<B>XML_RPC_Value</B>: already initialized as a [" . |
| 785 |
$this->kindOf() . "]<BR>"; |
$this->kindOf() . "]<BR>"; |
| 786 |
return 0; |
return 0; |
| 787 |
} |
} |
| 892 |
{ |
{ |
| 893 |
reset($this->me["struct"]); |
reset($this->me["struct"]); |
| 894 |
} |
} |
| 895 |
|
|
| 896 |
function structeach() |
function structeach() |
| 897 |
{ |
{ |
| 898 |
return each($this->me["struct"]); |
return each($this->me["struct"]); |
| 899 |
} |
} |
| 900 |
|
|
| 901 |
function getval() { |
function getval() { |
| 902 |
// UNSTABLE |
// UNSTABLE |
| 903 |
global $XML_RPC_BOOLEAN, $XML_RPC_Base64; |
global $XML_RPC_BOOLEAN, $XML_RPC_Base64; |
| 904 |
|
|
| 905 |
reset($this->me); |
reset($this->me); |
| 906 |
list($a,$b)=each($this->me); |
list($a,$b)=each($this->me); |
| 907 |
|
|
| 908 |
// contributed by I Sofer, 2001-03-24 |
// contributed by I Sofer, 2001-03-24 |
| 909 |
// add support for nested arrays to scalarval |
// add support for nested arrays to scalarval |
| 910 |
// i've created a new method here, so as to |
// i've created a new method here, so as to |
| 926 |
eval('$b->'.$id.' = $cont;'); |
eval('$b->'.$id.' = $cont;'); |
| 927 |
} |
} |
| 928 |
} |
} |
| 929 |
|
|
| 930 |
// end contrib |
// end contrib |
| 931 |
return $b; |
return $b; |
| 932 |
} |
} |
| 933 |
|
|
| 934 |
function scalarval() |
function scalarval() |
| 935 |
{ |
{ |
| 936 |
global $XML_RPC_Boolean, $XML_RPC_Base64; |
global $XML_RPC_Boolean, $XML_RPC_Base64; |
| 944 |
global $XML_RPC_I4, $XML_RPC_Int; |
global $XML_RPC_I4, $XML_RPC_Int; |
| 945 |
reset($this->me); |
reset($this->me); |
| 946 |
list($a,$b)=each($this->me); |
list($a,$b)=each($this->me); |
| 947 |
if ($a==$XML_RPC_I4) |
if ($a==$XML_RPC_I4) |
| 948 |
$a=$XML_RPC_Int; |
$a=$XML_RPC_Int; |
| 949 |
return $a; |
return $a; |
| 950 |
} |
} |
| 974 |
// |
// |
| 975 |
// "Don't assume a timezone. It should be specified by the server in its |
// "Don't assume a timezone. It should be specified by the server in its |
| 976 |
// documentation what assumptions it makes about timezones." |
// documentation what assumptions it makes about timezones." |
| 977 |
// |
// |
| 978 |
// these routines always assume localtime unless |
// these routines always assume localtime unless |
| 979 |
// $utc is set to 1, in which case UTC is assumed |
// $utc is set to 1, in which case UTC is assumed |
| 980 |
// and an adjustment for locale is made when encoding |
// and an adjustment for locale is made when encoding |
| 981 |
if (!$utc) { |
if (!$utc) { |
| 982 |
$t=strftime("%Y%m%dT%H:%M:%S", $timet); |
$t=strftime("%Y%m%dT%H:%M:%S", $timet); |
| 983 |
} else { |
} else { |
| 984 |
if (function_exists("gmstrftime")) |
if (function_exists("gmstrftime")) |
| 985 |
// gmstrftime doesn't exist in some versions |
// gmstrftime doesn't exist in some versions |
| 986 |
// of PHP |
// of PHP |
| 987 |
$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet); |
$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet); |
| 989 |
$t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z")); |
$t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z")); |
| 990 |
} |
} |
| 991 |
} |
} |
| 992 |
|
|
| 993 |
return $t; |
return $t; |
| 994 |
} |
} |
| 995 |
|
|
| 997 |
// return a timet in the localtime, or UTC |
// return a timet in the localtime, or UTC |
| 998 |
$t=0; |
$t=0; |
| 999 |
if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})",$idate, $regs)) { |
if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})",$idate, $regs)) { |
| 1000 |
|
|
| 1001 |
if ($utc) { |
if ($utc) { |
| 1002 |
$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
| 1003 |
} else { |
} else { |
| 1004 |
$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
| 1005 |
} |
} |
| 1006 |
} |
} |
| 1007 |
|
|
| 1008 |
return $t; |
return $t; |
| 1009 |
} |
} |
| 1027 |
for($i = 0; $i < $size; $i++) { |
for($i = 0; $i < $size; $i++) { |
| 1028 |
$arr[]=XML_RPC_decode($XML_RPC_val->arraymem($i)); |
$arr[]=XML_RPC_decode($XML_RPC_val->arraymem($i)); |
| 1029 |
} |
} |
| 1030 |
return $arr; |
return $arr; |
| 1031 |
} |
} |
| 1032 |
else if($kind == "struct") { |
else if($kind == "struct") { |
| 1033 |
$XML_RPC_val->structreset(); |
$XML_RPC_val->structreset(); |