cvs: pearweb /include pear-database.php signatures.php xmlrpc-methods.php /public_html test.php xmlrpc.php
| From: | Stig Bakken | Date: | Fri, 05 Oct 2001 09:15:41 +0000 |
| Subject: | cvs: pearweb /include pear-database.php signatures.php xmlrpc-methods.php /public_html test.php xmlrpc.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-930@lists.php.net to get a copy of this message | ||
ssb Fri Oct 5 05:15:41 2001 EDT
Added files:
/pearweb/include signatures.php
Modified files:
/pearweb/include pear-database.php xmlrpc-methods.php
/pearweb/public_html test.php xmlrpc.php
Log:
* working on xmlrpc interface/introspection
Index: pearweb/include/pear-database.php diff -u pearweb/include/pear-database.php:1.20 pearweb/include/pear-database.php:1.21 --- pearweb/include/pear-database.php:1.20 Wed Oct 3 09:47:12 2001 +++ pearweb/include/pear-database.php Fri Oct 5 05:15:34 2001 @@ -160,7 +160,7 @@ } $dbh->query($query); } - return DB_OK; + return true; } // }}} @@ -171,7 +171,7 @@ class category { - // {{{ category::add() + // {{{ API int category::add(struct) /* $data = array( @@ -213,7 +213,7 @@ class package { - // {{{ package::add() + // {{{ API int package::add(struct) // add a package, return new package id or PEAR error function add($data) @@ -255,7 +255,7 @@ } // }}} - // {{{ package::info() + // {{{ API struct package::info(string|int) function info($pkg) { @@ -286,11 +286,28 @@ } // }}} + // {{{ API struct package::listAll() + + function listAll($name, $params, $appdata) + { + global $dbh; + return $dbh->getAssoc("SELECT p.id AS packageid, p.name AS name, ". + "c.id AS categoryid, c.name AS category, ". + "p.stablerelease AS stable, ". + "p.license AS license, ". + "p.summary AS summary, ". + "p.description AS description". + " FROM packages p, categories c ". + "WHERE c.id = p.category ". + "ORDER BY p.name"); + } + + // }}} } class maintainer { - // {{{ maintainer::add() + // {{{ API int maintainer::add(int, string, string) function add($package, $user, $role) { @@ -304,7 +321,7 @@ if (DB::isError($err)) { return $err; } - return DB_OK; + return true; } // }}} @@ -312,7 +329,7 @@ class release { - // {{{ release::getRecent() + // {{{ API array release::getRecent([int]) function getRecent($n = 5) { @@ -335,28 +352,25 @@ } // }}} - // {{{ release::upload() + // {{{ API bool release::upload(string, string, string, binary, string) function upload($package, $version, $relnotes, &$tarball, $md5sum) { - global $_return_value; // used by XML-RPC backend global $dbh, $auth_user; // (2) verify that package exists $test = $dbh->getOne("SELECT name FROM packages WHERE name = ?", array($package)); - if (isset($_return_value)) return $_return_value; if (empty($test)) { - return "no such package: $package"; + return PEAR::raiseError("no such package: $package"); } // (3) verify that version does not exist $test = $dbh->getOne("SELECT version FROM releases ". "WHERE package = ? AND version = ?", array($package, $version)); - if (isset($_return_value)) return $_return_value; if ($test) { - return "already exists: $package $version"; + return PEAR::raiseError("already exists: $package $version"); } // (4) store tar ball to temp file @@ -365,13 +379,13 @@ $file = sprintf("%s/%s-%s.tgz", PEAR_TARBALL_DIR, $package, $version); $fp = @fopen($tempfile, "w"); if (!$fp) { - return "fopen failed: $php_errormsg"; + return PEAR::raiseError("fopen failed: $php_errormsg"); } fwrite($fp, $distfile); fclose($fp); // later: do lots of integrity checks on the tarball if (!@rename($tempfile, $file)) { - return "rename failed: $php_errormsg"; + return PEAR::raiseError("rename failed: $php_errormsg"); } // (5) verify MD5 checksum @@ -380,7 +394,7 @@ $data = ob_get_contents(); ob_end_clean(); if (md5($data) != $md5sum) { - return "bad md5 checksum"; + return PEAR::raiseError("bad md5 checksum"); } // Update releases table @@ -388,7 +402,7 @@ $sth = $dbh->prepare($query); $dbh->execute($sth, array($package, $version, $auth_user->handle, gmdate('Y-m-d H:i'), $relnotes, $md5sum, $file)); - if (isset($_return_value)) return $_return_value; + return true; } // }}} @@ -396,7 +410,7 @@ class note { - // {{{ note::add() + // {{{ API bool note::add(string, int, string) function add($key, $value, $note) { @@ -405,27 +419,39 @@ $nid = $dbh->nextId("notes"); $stmt = $dbh->prepare("INSERT INTO notes (id,$key,nby,ntime,note) ". "VALUES(?,?,?,?,?)"); - return $dbh->execute($stmt, array($nid, $value, $nby, + $res = $dbh->execute($stmt, array($nid, $value, $nby, gmdate('Y-m-d H:i'), $note)); + if (DB::isError($res)) { + return $res; + } + return true; } // }}} - // {{{ note::delete() + // {{{ API bool note::delete(int) function delete($id) { global $dbh; $id = (int)$id; - return $dbh->query("DELETE FROM notes WHERE id = $id"); + $res = $dbh->query("DELETE FROM notes WHERE id = $id"); + if (DB::isError($res)) { + return $res; + } + return true; } // }}} - // {{{ note::deleteAll() + // {{{ API bool note::deleteAll(string, int) - function deleteall($key, $value) + function deleteAll($key, $value) { global $dbh; - return $dbh->query("DELETE FROM notes WHERE $key = ". $dbh->quote($value)); + $res = $dbh->query("DELETE FROM notes WHERE $key = ". $dbh->quote($value)); + if (DB::isError($res)) { + return $res; + } + return true; } // }}} @@ -433,7 +459,7 @@ class user { - // {{{ user::delete() + // {{{ API bool user::delete(string) function delete($uid) { @@ -444,9 +470,9 @@ } // }}} - // {{{ user::rejectRequest() + // {{{ API bool user::rejectRequest(string, string) - function rejectrequest($uid, $reason) + function rejectRequest($uid, $reason) { global $PHP_AUTH_USER, $dbh; list($email) = $dbh->getRow('SELECT email FROM users WHERE handle = ?', @@ -460,7 +486,7 @@ } // }}} - // {{{ user::activate() + // {{{ API bool user::activate(string) function activate($uid) { @@ -490,6 +516,15 @@ // }}} } + +// {{{ API string echotest(string) + +function echotest($str) +{ + return "Echo: $str"; +} + +// }}} // {{{ mail_pear_admins() Index: pearweb/include/xmlrpc-methods.php diff -u pearweb/include/xmlrpc-methods.php:1.3 pearweb/include/xmlrpc-methods.php:1.4 --- pearweb/include/xmlrpc-methods.php:1.3 Wed Oct 3 08:56:11 2001 +++ pearweb/include/xmlrpc-methods.php Fri Oct 5 05:15:36 2001 @@ -1,50 +1,49 @@ <?php // -*- C++ -*- -$pear_xmlrpc_methods = array(); +require_once "signatures.php"; -// {{{ xmlrpc method: package.new +$xmlrpc_method_index = parse_signatures_from_file("../include/pear-database.php", "index"); -$pear_xmlrpc_methods[] = "package.new"; - -function pear_xmlrpc_package_add($name, $params, $appdata) +function pear_register_xmlrpc_methods($xs) { - $ret = package::add($params[0]); - if (PEAR::isError($ret)) { - return false; + global $xmlrpc_method_index; + foreach ($xmlrpc_method_index as $method => $foo) { + error_log("registering $method"); + xmlrpc_server_register_method($xs, $method, "pear_xmlrpc_dispatcher"); } - return true; } -// }}} - -// {{{ xmlrpc method: package.info - -$pear_xmlrpc_methods[] = "package.info"; - -function pear_xmlrpc_package_info($name, $params, $appdata) +function pear_xmlrpc_dispatcher($method_name, $params, $appdata) { - global $dbh; - return pacakge::info($params[0]); -} - -// }}} - -// {{{ xmlrpc method: package.list - -$pear_xmlrpc_methods[] = "package.list"; - -function pear_xmlrpc_package_list($name, $params, $appdata) -{ - global $dbh; - return $dbh->getAssoc("SELECT p.id AS packageid, p.name AS name, ". - "c.id AS categoryid, c.name AS category, ". - "p.stablerelease AS stable, p.license AS license, ". - "p.summary AS summary, p.description AS description". - " FROM packages p, categories c ". - "WHERE c.id = p.category ". - "ORDER BY p.name"); + global $xmlrpc_method_index; + error_log("pear_xmlrpc_dispatcher: $method_name called"); + if (empty($xmlrpc_method_index[$method_name])) { + error_log("unknown method: $method_name"); + return false; // XXX FAULT + } + $type_key = ""; + for ($i = 0; $i < sizeof($params); $i++) { + if ($i > 0) { + $type_key .= ","; + } + $type_key .= xmlrpc_get_type($params[$i]); + } + if (!isset($xmlrpc_method_index[$method_name][$type_key])) { + error_log("no signature found for $method_name($type_key)"); + return false; // XXX FAULT + } + $function = $xmlrpc_method_index[$method_name][$type_key]; + if (strstr($function, "::")) { + list($class, $method) = explode("::", $function); + $ret = call_user_method_array($method, $class, $params); + } else { + $ret = call_user_func_array($function, $params); + } + ob_start(); + var_dump($ret); + error_log("$method_name returned ".ob_get_contents()); + ob_end_clean(); + return $ret; } - -// }}} ?> Index: pearweb/public_html/test.php diff -u pearweb/public_html/test.php:1.3 pearweb/public_html/test.php:1.4 --- pearweb/public_html/test.php:1.3 Tue Aug 7 17:18:37 2001 +++ pearweb/public_html/test.php Fri Oct 5 05:15:41 2001 @@ -1,19 +1,20 @@ <?php -ini_set("include_path", - ini_get("include_path") . ":/home/ssb/src/Smarty-1.4.3"); -include_once "Smarty.class.php"; -$s = new Smarty; -$s->compile_check = true; -$s->debugging = false; -$s->template_dir = "../templates"; -$s->compile_dir = "../templates_c"; -$s->cache_dir = "../cache"; -$s->config_dir = "../configs"; -$s->register_function("page", "smarty_page_start"); -$s->register_function("endpage", "smarty_page_end"); -$s->register_function("box", "smarty_border_box_start"); -$s->register_function("endbox", "smarty_border_box_end"); -$s->display('test.tpl'); +require_once "signatures.php"; + +$signatures = parse_signatures_from_file("../include/pear-database.php", "index"); +print "<pre>"; +//var_dump($signatures); +print "</pre>\n"; + +class foo { + function bar($str) { + return "bing: $str"; + } +} + +$params = array("gazonk"); +$func = "foo"; +var_dump(@call_user_method_array("bar", $func, $params)); ?> Index: pearweb/public_html/xmlrpc.php diff -u pearweb/public_html/xmlrpc.php:1.7 pearweb/public_html/xmlrpc.php:1.8 --- pearweb/public_html/xmlrpc.php:1.7 Mon Oct 1 22:49:37 2001 +++ pearweb/public_html/xmlrpc.php Fri Oct 5 05:15:41 2001 @@ -7,22 +7,15 @@ } else { $request_body = "<?xml version='1.0' ?> <methodCall> - <methodName>package.new</methodName> - <params> - <param> - <value><string>{$query}</string></value> - </param> - </params> + <methodName>test</methodName> + <params/> </methodCall> "; } $xs = xmlrpc_server_create(); -foreach ($pear_xmlrpc_methods as $method) { - $handler = "pear_xmlrpc_".strtr($method, '.', '_'); - xmlrpc_server_register_method($xs, $method, $handler); -} +pear_register_xmlrpc_methods($xs); xmlrpc_server_register_method($xs, "test", "pear_xmlrpc_test"); Index: pearweb/include/signatures.php +++ pearweb/include/signatures.php <?php function parse_signatures_from_file($file, $out_format = "signatures") { $fp = fopen($file, "r"); if (!is_resource($fp)) { return false; } $contents = ""; while (!feof($fp)) { $contents .= fread($fp, 10240); } // format: array( array(returntype, methodname, paramlist), ... ) $signatures = array(); if (preg_match_all('/API\s+([a-z|]+)\s+([a-zA-Z0-9_:]+)\s*\(([^\)]*)\)/', $contents, $matches)) { for ($i = 0; $i < sizeof($matches[0]); $i++) { $return_type = $matches[1][$i]; $method_name = $matches[2][$i]; $parameters = $matches[3][$i]; //print "signature: $return_type <b>$method_name</b>($parameters)<br />\n"; $return_type_permutations = explode("|", $return_type); $xmlrpc_method = str_replace("::", ".", $method_name); $param_list = preg_split('/\s*,\s*/', $parameters); $first_optional_param = -1; error_log("found method $xmlrpc_method"); for ($j = 0; $j < sizeof($param_list); $j++) { if ($first_optional_param == -1 && strstr($param_list[$j], "[")) { $first_optional_param = $j; } $param_list[$j] = preg_replace('/[\[\]]/', '', $param_list[$j]); } if ($first_optional_param == -1) { $numparams = array(sizeof($param_list)); } else { $numparams = array(); for ($j = $first_optional_param; $j <= sizeof($param_list); $j++) { $numparams[] = $j; } } $param_variations = array(); for ($j = 0; $j < sizeof($param_list); $j++) { $param_variations[$j] = explode("|", $param_list[$j]); } $paramlist_permutations = array(); foreach ($numparams as $nump) { $v = 1; $params = array(); $varyat = array(); for ($j = 0; $j < $nump; $j++) { $v *= sizeof($param_variations[$j]); if (sizeof($param_variations[$j]) > 1) { $varyat[] = $j; } $params[$j] = $param_variations[$j][0]; } //print "$nump params, $v variations<br>\n"; if (sizeof($varyat) > 0) { _signature_worker($paramlist_permutations, $params, $varyat, $param_variations); } else { $paramlist_permutations[implode(",", $params)] = 1; } } if ($out_format == "full_description") { foreach ($return_type_permutations as $ret_type) { foreach ($paramlist_permutations as $paramlist => $dummy) { foreach (explode(",", $paramlist) as $ind => $pp) { $plist[$ind] = array("type" => $pp); } $signatures[] = array( "xmlrpc_method" => $xmlrpc_method, "implemented_in" => $method_name, "return_type" => $ret_type, "parameters" => $plist); } } } elseif ($out_format == "index") { foreach ($paramlist_permutations as $paramlist => $dummy) { $signatures[$xmlrpc_method][$paramlist] = $method_name; } } else { foreach ($return_type_permutations as $ret_type) { foreach ($paramlist_permutations as $paramlist => $dummy) { $signatures[] = array($xmlrpc_method, $ret_type, $paramlist); } } } //print "<br>\n"; } } return $signatures; } function _signature_worker(&$storage, $params, &$varyat, &$param_variations, $j = 0) { $n = $varyat[$j]; $variations = $param_variations[$n]; for ($k = 0; $k < sizeof($variations); $k++) { $params[$n] = $variations[$k]; $storage[implode(",", $params)] = 1; if (($j+1) < sizeof($varyat)) { _signature_worker($storage, $params, $varyat, $param_variations, $j+1); } } } ?>
Index: pearweb/include/pear-database.php diff -u pearweb/include/pear-database.php:1.20 pearweb/include/pear-database.php:1.21 --- pearweb/include/pear-database.php:1.20 Wed Oct 3 09:47:12 2001 +++ pearweb/include/pear-database.php Fri Oct 5 05:15:34 2001 @@ -160,7 +160,7 @@ } $dbh->query($query); } - return DB_OK; + return true; } // }}} @@ -171,7 +171,7 @@ class category { - // {{{ category::add() + // {{{ API int category::add(struct) /* $data = array( @@ -213,7 +213,7 @@ class package { - // {{{ package::add() + // {{{ API int package::add(struct) // add a package, return new package id or PEAR error function add($data) @@ -255,7 +255,7 @@ } // }}} - // {{{ package::info() + // {{{ API struct package::info(string|int) function info($pkg) { @@ -286,11 +286,28 @@ } // }}} + // {{{ API struct package::listAll() + + function listAll($name, $params, $appdata) + { + global $dbh; + return $dbh->getAssoc("SELECT p.id AS packageid, p.name AS name, ". + "c.id AS categoryid, c.name AS category, ". + "p.stablerelease AS stable, ". + "p.license AS license, ". + "p.summary AS summary, ". + "p.description AS description". + " FROM packages p, categories c ". + "WHERE c.id = p.category ". + "ORDER BY p.name"); + } + + // }}} } class maintainer { - // {{{ maintainer::add() + // {{{ API int maintainer::add(int, string, string) function add($package, $user, $role) { @@ -304,7 +321,7 @@ if (DB::isError($err)) { return $err; } - return DB_OK; + return true; } // }}} @@ -312,7 +329,7 @@ class release { - // {{{ release::getRecent() + // {{{ API array release::getRecent([int]) function getRecent($n = 5) { @@ -335,28 +352,25 @@ } // }}} - // {{{ release::upload() + // {{{ API bool release::upload(string, string, string, binary, string) function upload($package, $version, $relnotes, &$tarball, $md5sum) { - global $_return_value; // used by XML-RPC backend global $dbh, $auth_user; // (2) verify that package exists $test = $dbh->getOne("SELECT name FROM packages WHERE name = ?", array($package)); - if (isset($_return_value)) return $_return_value; if (empty($test)) { - return "no such package: $package"; + return PEAR::raiseError("no such package: $package"); } // (3) verify that version does not exist $test = $dbh->getOne("SELECT version FROM releases ". "WHERE package = ? AND version = ?", array($package, $version)); - if (isset($_return_value)) return $_return_value; if ($test) { - return "already exists: $package $version"; + return PEAR::raiseError("already exists: $package $version"); } // (4) store tar ball to temp file @@ -365,13 +379,13 @@ $file = sprintf("%s/%s-%s.tgz", PEAR_TARBALL_DIR, $package, $version); $fp = @fopen($tempfile, "w"); if (!$fp) { - return "fopen failed: $php_errormsg"; + return PEAR::raiseError("fopen failed: $php_errormsg"); } fwrite($fp, $distfile); fclose($fp); // later: do lots of integrity checks on the tarball if (!@rename($tempfile, $file)) { - return "rename failed: $php_errormsg"; + return PEAR::raiseError("rename failed: $php_errormsg"); } // (5) verify MD5 checksum @@ -380,7 +394,7 @@ $data = ob_get_contents(); ob_end_clean(); if (md5($data) != $md5sum) { - return "bad md5 checksum"; + return PEAR::raiseError("bad md5 checksum"); } // Update releases table @@ -388,7 +402,7 @@ $sth = $dbh->prepare($query); $dbh->execute($sth, array($package, $version, $auth_user->handle, gmdate('Y-m-d H:i'), $relnotes, $md5sum, $file)); - if (isset($_return_value)) return $_return_value; + return true; } // }}} @@ -396,7 +410,7 @@ class note { - // {{{ note::add() + // {{{ API bool note::add(string, int, string) function add($key, $value, $note) { @@ -405,27 +419,39 @@ $nid = $dbh->nextId("notes"); $stmt = $dbh->prepare("INSERT INTO notes (id,$key,nby,ntime,note) ". "VALUES(?,?,?,?,?)"); - return $dbh->execute($stmt, array($nid, $value, $nby, + $res = $dbh->execute($stmt, array($nid, $value, $nby, gmdate('Y-m-d H:i'), $note)); + if (DB::isError($res)) { + return $res; + } + return true; } // }}} - // {{{ note::delete() + // {{{ API bool note::delete(int) function delete($id) { global $dbh; $id = (int)$id; - return $dbh->query("DELETE FROM notes WHERE id = $id"); + $res = $dbh->query("DELETE FROM notes WHERE id = $id"); + if (DB::isError($res)) { + return $res; + } + return true; } // }}} - // {{{ note::deleteAll() + // {{{ API bool note::deleteAll(string, int) - function deleteall($key, $value) + function deleteAll($key, $value) { global $dbh; - return $dbh->query("DELETE FROM notes WHERE $key = ". $dbh->quote($value)); + $res = $dbh->query("DELETE FROM notes WHERE $key = ". $dbh->quote($value)); + if (DB::isError($res)) { + return $res; + } + return true; } // }}} @@ -433,7 +459,7 @@ class user { - // {{{ user::delete() + // {{{ API bool user::delete(string) function delete($uid) { @@ -444,9 +470,9 @@ } // }}} - // {{{ user::rejectRequest() + // {{{ API bool user::rejectRequest(string, string) - function rejectrequest($uid, $reason) + function rejectRequest($uid, $reason) { global $PHP_AUTH_USER, $dbh; list($email) = $dbh->getRow('SELECT email FROM users WHERE handle = ?', @@ -460,7 +486,7 @@ } // }}} - // {{{ user::activate() + // {{{ API bool user::activate(string) function activate($uid) { @@ -490,6 +516,15 @@ // }}} } + +// {{{ API string echotest(string) + +function echotest($str) +{ + return "Echo: $str"; +} + +// }}} // {{{ mail_pear_admins() Index: pearweb/include/xmlrpc-methods.php diff -u pearweb/include/xmlrpc-methods.php:1.3 pearweb/include/xmlrpc-methods.php:1.4 --- pearweb/include/xmlrpc-methods.php:1.3 Wed Oct 3 08:56:11 2001 +++ pearweb/include/xmlrpc-methods.php Fri Oct 5 05:15:36 2001 @@ -1,50 +1,49 @@ <?php // -*- C++ -*- -$pear_xmlrpc_methods = array(); +require_once "signatures.php"; -// {{{ xmlrpc method: package.new +$xmlrpc_method_index = parse_signatures_from_file("../include/pear-database.php", "index"); -$pear_xmlrpc_methods[] = "package.new"; - -function pear_xmlrpc_package_add($name, $params, $appdata) +function pear_register_xmlrpc_methods($xs) { - $ret = package::add($params[0]); - if (PEAR::isError($ret)) { - return false; + global $xmlrpc_method_index; + foreach ($xmlrpc_method_index as $method => $foo) { + error_log("registering $method"); + xmlrpc_server_register_method($xs, $method, "pear_xmlrpc_dispatcher"); } - return true; } -// }}} - -// {{{ xmlrpc method: package.info - -$pear_xmlrpc_methods[] = "package.info"; - -function pear_xmlrpc_package_info($name, $params, $appdata) +function pear_xmlrpc_dispatcher($method_name, $params, $appdata) { - global $dbh; - return pacakge::info($params[0]); -} - -// }}} - -// {{{ xmlrpc method: package.list - -$pear_xmlrpc_methods[] = "package.list"; - -function pear_xmlrpc_package_list($name, $params, $appdata) -{ - global $dbh; - return $dbh->getAssoc("SELECT p.id AS packageid, p.name AS name, ". - "c.id AS categoryid, c.name AS category, ". - "p.stablerelease AS stable, p.license AS license, ". - "p.summary AS summary, p.description AS description". - " FROM packages p, categories c ". - "WHERE c.id = p.category ". - "ORDER BY p.name"); + global $xmlrpc_method_index; + error_log("pear_xmlrpc_dispatcher: $method_name called"); + if (empty($xmlrpc_method_index[$method_name])) { + error_log("unknown method: $method_name"); + return false; // XXX FAULT + } + $type_key = ""; + for ($i = 0; $i < sizeof($params); $i++) { + if ($i > 0) { + $type_key .= ","; + } + $type_key .= xmlrpc_get_type($params[$i]); + } + if (!isset($xmlrpc_method_index[$method_name][$type_key])) { + error_log("no signature found for $method_name($type_key)"); + return false; // XXX FAULT + } + $function = $xmlrpc_method_index[$method_name][$type_key]; + if (strstr($function, "::")) { + list($class, $method) = explode("::", $function); + $ret = call_user_method_array($method, $class, $params); + } else { + $ret = call_user_func_array($function, $params); + } + ob_start(); + var_dump($ret); + error_log("$method_name returned ".ob_get_contents()); + ob_end_clean(); + return $ret; } - -// }}} ?> Index: pearweb/public_html/test.php diff -u pearweb/public_html/test.php:1.3 pearweb/public_html/test.php:1.4 --- pearweb/public_html/test.php:1.3 Tue Aug 7 17:18:37 2001 +++ pearweb/public_html/test.php Fri Oct 5 05:15:41 2001 @@ -1,19 +1,20 @@ <?php -ini_set("include_path", - ini_get("include_path") . ":/home/ssb/src/Smarty-1.4.3"); -include_once "Smarty.class.php"; -$s = new Smarty; -$s->compile_check = true; -$s->debugging = false; -$s->template_dir = "../templates"; -$s->compile_dir = "../templates_c"; -$s->cache_dir = "../cache"; -$s->config_dir = "../configs"; -$s->register_function("page", "smarty_page_start"); -$s->register_function("endpage", "smarty_page_end"); -$s->register_function("box", "smarty_border_box_start"); -$s->register_function("endbox", "smarty_border_box_end"); -$s->display('test.tpl'); +require_once "signatures.php"; + +$signatures = parse_signatures_from_file("../include/pear-database.php", "index"); +print "<pre>"; +//var_dump($signatures); +print "</pre>\n"; + +class foo { + function bar($str) { + return "bing: $str"; + } +} + +$params = array("gazonk"); +$func = "foo"; +var_dump(@call_user_method_array("bar", $func, $params)); ?> Index: pearweb/public_html/xmlrpc.php diff -u pearweb/public_html/xmlrpc.php:1.7 pearweb/public_html/xmlrpc.php:1.8 --- pearweb/public_html/xmlrpc.php:1.7 Mon Oct 1 22:49:37 2001 +++ pearweb/public_html/xmlrpc.php Fri Oct 5 05:15:41 2001 @@ -7,22 +7,15 @@ } else { $request_body = "<?xml version='1.0' ?> <methodCall> - <methodName>package.new</methodName> - <params> - <param> - <value><string>{$query}</string></value> - </param> - </params> + <methodName>test</methodName> + <params/> </methodCall> "; } $xs = xmlrpc_server_create(); -foreach ($pear_xmlrpc_methods as $method) { - $handler = "pear_xmlrpc_".strtr($method, '.', '_'); - xmlrpc_server_register_method($xs, $method, $handler); -} +pear_register_xmlrpc_methods($xs); xmlrpc_server_register_method($xs, "test", "pear_xmlrpc_test"); Index: pearweb/include/signatures.php +++ pearweb/include/signatures.php <?php function parse_signatures_from_file($file, $out_format = "signatures") { $fp = fopen($file, "r"); if (!is_resource($fp)) { return false; } $contents = ""; while (!feof($fp)) { $contents .= fread($fp, 10240); } // format: array( array(returntype, methodname, paramlist), ... ) $signatures = array(); if (preg_match_all('/API\s+([a-z|]+)\s+([a-zA-Z0-9_:]+)\s*\(([^\)]*)\)/', $contents, $matches)) { for ($i = 0; $i < sizeof($matches[0]); $i++) { $return_type = $matches[1][$i]; $method_name = $matches[2][$i]; $parameters = $matches[3][$i]; //print "signature: $return_type <b>$method_name</b>($parameters)<br />\n"; $return_type_permutations = explode("|", $return_type); $xmlrpc_method = str_replace("::", ".", $method_name); $param_list = preg_split('/\s*,\s*/', $parameters); $first_optional_param = -1; error_log("found method $xmlrpc_method"); for ($j = 0; $j < sizeof($param_list); $j++) { if ($first_optional_param == -1 && strstr($param_list[$j], "[")) { $first_optional_param = $j; } $param_list[$j] = preg_replace('/[\[\]]/', '', $param_list[$j]); } if ($first_optional_param == -1) { $numparams = array(sizeof($param_list)); } else { $numparams = array(); for ($j = $first_optional_param; $j <= sizeof($param_list); $j++) { $numparams[] = $j; } } $param_variations = array(); for ($j = 0; $j < sizeof($param_list); $j++) { $param_variations[$j] = explode("|", $param_list[$j]); } $paramlist_permutations = array(); foreach ($numparams as $nump) { $v = 1; $params = array(); $varyat = array(); for ($j = 0; $j < $nump; $j++) { $v *= sizeof($param_variations[$j]); if (sizeof($param_variations[$j]) > 1) { $varyat[] = $j; } $params[$j] = $param_variations[$j][0]; } //print "$nump params, $v variations<br>\n"; if (sizeof($varyat) > 0) { _signature_worker($paramlist_permutations, $params, $varyat, $param_variations); } else { $paramlist_permutations[implode(",", $params)] = 1; } } if ($out_format == "full_description") { foreach ($return_type_permutations as $ret_type) { foreach ($paramlist_permutations as $paramlist => $dummy) { foreach (explode(",", $paramlist) as $ind => $pp) { $plist[$ind] = array("type" => $pp); } $signatures[] = array( "xmlrpc_method" => $xmlrpc_method, "implemented_in" => $method_name, "return_type" => $ret_type, "parameters" => $plist); } } } elseif ($out_format == "index") { foreach ($paramlist_permutations as $paramlist => $dummy) { $signatures[$xmlrpc_method][$paramlist] = $method_name; } } else { foreach ($return_type_permutations as $ret_type) { foreach ($paramlist_permutations as $paramlist => $dummy) { $signatures[] = array($xmlrpc_method, $ret_type, $paramlist); } } } //print "<br>\n"; } } return $signatures; } function _signature_worker(&$storage, $params, &$varyat, &$param_variations, $j = 0) { $n = $varyat[$j]; $variations = $param_variations[$n]; for ($k = 0; $k < sizeof($variations); $k++) { $params[$n] = $variations[$k]; $storage[implode(",", $params)] = 1; if (($j+1) < sizeof($varyat)) { _signature_worker($storage, $params, $varyat, $param_variations, $j+1); } } } ?>