Re[2]: [PEAR-DEV] Anybody seen Stig Bakken recently?

From: Date: Fri, 03 Dec 2004 01:22:02 +0000
Subject: Re[2]: [PEAR-DEV] Anybody seen Stig Bakken recently?
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-34743@lists.php.net to get a copy of this message
Hello Daniel, DC> As mentioned, we have found someone to take care of the package. DC> Please relax, Ok. Here is the patches. I can't wait for another week. For a list of fixes see bugreports. There are some things still need to be done. Esp. with docs, because some things were wrong from start and nobody noticed this even after release. For example remote procedure recieves XML_RPC_Message object instead of Array of XML_RPC_Value objects as params. Global constants are listed in docs incorrectly. Parser should be optimized a bit. As it seems for me now that the main bottleneck of this package is evals and XML_RPC_Value(). and stale developers. =) Some other ideas include wrapper to make it easy to call ordinary functions, which return values other than XML_RPC_Response(). t --

--- C:\CVS_XRPC\RPC.php Thu Dec 02 23:59:16 2004 +++ C:\RPC2\XML\RPC.php Fri Dec 03 02:47:24 2004 @@ -2,7 +2,6 @@ // /* vim: set expandtab tabstop=4 shiftwidth=4: */ // by Edd Dumbill (C) 1999-2001 // <edd@usefulinc.com> -// $Id: RPC.php,v 1.27 2004/11/28 10:55:50 hholzgra Exp $ // License is granted to use or modify this software ("XML-RPC for PHP") // for commercial or non-commercial use provided the copyright of the author @@ -21,7 +20,9 @@ // Adapted to PEAR standards by Stig S¯õ_her Bakken <stig@php.net> and // Martin Jansen <mj@php.net> -// /* $id$ */ +// /* $Id$ */ + +define('XML_RPC_VERSION', '1.1.0'); if (!function_exists('xml_parser_create')) { // Win 32 fix. From: "Leo West" <lwest@imaginet.fr> @@ -212,6 +213,9 @@ break; default: + // Reset accumulator when new element starts -- logically + // there should be only whitespace characters in ac + $XML_RPC_xh[$parser]['ac'] = ""; break; } @@ -317,7 +321,7 @@ break; case "METHODNAME": - $XML_RPC_xh[$parser]['method'] = ereg_replace("^[\n\r\t ]+", "", $XML_RPC_xh[$parser]['ac']); + $XML_RPC_xh[$parser]['method'] = trim($XML_RPC_xh[$parser]['ac']); break; case "BOOLEAN": @@ -380,6 +384,11 @@ $XML_RPC_xh[$parser]['qt'] = 1; $XML_RPC_xh[$parser]['lv'] = 2; } + + // TESTME get a notice when there is entity right at the start + if (!isset($XML_RPC_xh[$parser]['ac'])) { + $XML_RPC_xh[$parser]['ac'] = ''; + } $XML_RPC_xh[$parser]['ac'] .= str_replace('$', '\$', str_replace('"', '\"', str_replace(chr(92), $XML_RPC_backslash, $data))); @@ -449,19 +458,23 @@ function sendPayloadHTTP10($msg, $server, $port, $timeout=0, $username = "", $password = "") { - // If we're using a proxy open a socket to the proxy server instead to the xml-rpc server - if ($this->proxy){ - if ($timeout > 0) { - $fp = fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr, $timeout); - } else { - $fp = fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr); + $target_addr = ($this->proxy) ? $this->proxy : $server; + $target_port = ($this->proxy_port) ? $this->proxy_port : $server; + + if (!(strspn($target_addr, '.0123456789') == strlen($target_addr))) { + $addr = gethostbyname($target_addr); + if (strcmp($target_addr, $addr) == 0) { + return $this->raiseError("Unable to lookup hostname '$target_addr'"); } + $target_addr = $addr; + } + // LOOKAT persistent connections (perhaps this need a Net_Socket dependency) + // Unsure about proxy servers in Net_Socket + // If we're using a proxy open a socket to the proxy server instead to the xml-rpc server + if ($timeout > 0) { + $fp = @fsockopen($target_addr, $target_port, $this->errno, $this->errstr, $timeout); } else { - if ($timeout > 0) { - $fp = fsockopen($server, $port, $this->errno, $this->errstr, $timeout); - } else { - $fp = fsockopen($server, $port, $this->errno, $this->errstr); - } + $fp = @fsockopen($target_addr, $target_port, $this->errno, $this->errstr); } if (!$fp && $this->proxy) { @@ -470,7 +483,7 @@ XML_RPC_ERROR_CONNECTION_FAILED); } elseif (!$fp) { $this->raiseError( - "Connection to RPC server " . $this->server . " failed", + "Connection to RPC server " . $server . " failed", XML_RPC_ERROR_CONNECTION_FAILED); } @@ -498,7 +511,7 @@ } $op .= $this->path. " HTTP/1.0\r\n" . - "User-Agent: PEAR XML_RPC\r\n" . + "User-Agent: PEAR XML_RPC ".XML_RPC_VERSION."\r\n" . "Host: " . $this->server . "\r\n"; if ($this->proxy && $this->proxy_user != '') { $op .= 'Proxy-Authorization: Basic ' . @@ -510,7 +523,7 @@ "Content-Length: " . strlen($msg->payload) . "\r\n\r\n" . $msg->payload; - if (!fputs($fp, $op, strlen($op))) { + if (!fwrite($fp, $op, strlen($op))) { $this->errstr = "Write error"; return 0; } @@ -623,7 +636,7 @@ } $this->payload .= "</params>\n"; $this->payload .= $this->xml_footer(); - $this->payload = str_replace("\n", "\r\n", $this->payload); +// $this->payload = str_replace("\n", "\r\n", $this->payload); } function method($meth = "") @@ -768,12 +781,12 @@ var $me = array(); var $mytype = 0; - function XML_RPC_Value($val = -1, $type = "") + function XML_RPC_Value($val = NULL, $type = "") { global $XML_RPC_Types; $this->me = array(); $this->mytype = 0; - if ($val != -1 || $type != "") { + if (!is_null($val)) { if ($type == "") { $type="string"; } @@ -802,10 +815,10 @@ } if ($type == $XML_RPC_Boolean) { - if (strcasecmp($val,"true") == 0 || + if (strcasecmp($val, "true") == 0 || $val == 1 || ($val == true && - strcasecmp($val,"false"))) { + strcasecmp($val, "false"))) { $val = 1; } else { @@ -963,7 +976,7 @@ } function getval() { - // UNSTABLE + // UNSTABLE!!! global $XML_RPC_BOOLEAN, $XML_RPC_Base64; reset($this->me); @@ -1120,33 +1133,21 @@ global $XML_RPC_Struct; $type = gettype($php_val); - $XML_RPC_val = new XML_RPC_Value; + $XML_RPC_val = new XML_RPC_Value(); switch ($type) { case "array": + // convert continuous non-associative array to <array> else to <struct> $keys = array_keys($php_val); - $count = count($php_val); - $firstkey = $keys[0]; - $lastkey = $keys[$count - 1]; - if ($firstkey === 0 && is_int($lastkey) && ($lastkey + 1) == $count) { - $is_continuous = true; - $expected = 0; - foreach ($keys as $actual) { - if ($actual != $expected) { - $is_continuous = false; - break; - } - $expected++; - } - - if ($is_continuous) { - $arr = array(); - foreach ($php_val as $k => $v) { - $arr[$k] = XML_RPC_encode($v); - } - $XML_RPC_val->addArray($arr); - break; + $expected = 0; + while ((($k = array_shift($keys)) !== NULL) && ($k != $expected++)); + if ($k === NULL) { + $arr = array(); + foreach ($php_val as $k => $v) { + $arr[$k] = XML_RPC_encode($v); } + $XML_RPC_val->addArray($arr); + break; } // fall though if not numerical and continuous case "object": --- C:\CVS_XRPC\Server.php Thu Dec 02 23:59:36 2004 +++ C:\XML\RPC\Server.php Fri Dec 03 02:03:14 2004 @@ -183,43 +183,68 @@ $r->serialize(); header('Content-Length: ' . strlen($payload)); header('Content-Type: text/xml'); + header('Server: PEAR XML_RPC '.XML_RPC_VERSION); print $payload; } function verifySignature($in, $sig) { - for ($i = 0; $i < sizeof($sig); $i++) { - // check each possible signature in turn - $cursig = $sig[$i]; - if (sizeof($cursig) == $in->getNumParams() + 1) { - $itsOK = 1; - for ($n = 0; $n < $in->getNumParams(); $n++) { - $p = $in->getParam($n); - // print "<!-- $p -->\n"; - if ($p->kindOf() == "scalar") { - $pt = $p->scalartyp(); - } else { - $pt = $p->kindOf(); - } - // $n+1 as first type of sig is return type - if ($pt != $cursig[$n+1]) { - $itsOK = 0; - $pno = $n+1; - $wanted = $cursig[$n+1]; - $got = $pt; - break; - } + if (!is_array($sig) || empty($sig)) { + return array(FALSE, 'Invalid signature definition'); + } + + $fault_reasons = ""; + // check each possible signature in turn + foreach ($sig as $cursig) { + if (!is_array($cursig) || empty($cursig)) { + return array(FALSE, 'Invalid signature'); + } + + $inparamnum = $in->getNumParams(); + // first element of cursig is return type + if ((count($cursig) - 1) != $inparamnum) { + $fault_reasons .= "Wanted " + . (count($cursig) - 1) + . " params, got " + . $inparamnum . ".\n"; + break; + } + + $itsOK = 1; + for ($n = 0; $n < $inparamnum; $n++) { + $p = $in->getParam($n); + // print "<!-- $p -->\n"; + // replace next instructions with checkType probably + if ($p->kindOf() == "scalar") { + $pt = $p->scalartyp(); + // this always returns $XML_RPC_Int for $XML_RPC_I4 + } else { + $pt = $p->kindOf(); } - if ($itsOK) - return array(1); + // $n+1 as first type of cursig is return type + if (strcmp($pt, $cursig[$n+1]) != 0 + && (($cursig[$n+1] != $XML_RPC_I4) + || ($pt != $XML_RPC_Int))) { + // this ^^^ check can be avoided if i4 -> int conversion + // take place while parsing parameters + $itsOK = 0; + $pno = $n+1; + $wanted = $cursig[$n+1]; + $got = $pt; + $fault_reasons .= "Wanted $wanted, got $got at param $pno.\n"; + break; + } + } + if ($itsOK) { + return array(TRUE); } } - return array(0, "Wanted ${wanted}, got ${got} at param ${pno})"); + return array(FALSE, $fault_reasons); } function parseRequest($data = "") { - global $XML_RPC_xh,$HTTP_RAW_POST_DATA; + global $XML_RPC_xh, $HTTP_RAW_POST_DATA; global $XML_RPC_err, $XML_RPC_str, $XML_RPC_errxml, $XML_RPC_defencoding, $XML_RPC_Server_dmap;
« previous php.pear.dev (#34743) next »