From 220e0a5c6223538cb218877d58dd814eed6c1c04 Mon Sep 17 00:00:00 2001 From: skeeter Date: Fri, 15 Feb 2002 19:05:40 +0000 Subject: [PATCH] Adding parts of new app registry system. Initial calls allow get_appby[id/name] and find_new_app. More to follow. --- phpgwapi/inc/class.app_registry.inc.php | 335 ++++++++++++++++++++++++ phpgwapi/inc/class.service.inc.php | 8 +- phpgwapi/inc/class.xmlrpcmsg.inc.php | 4 +- phpgwapi/inc/xml_functions.inc.php | 39 +++ 4 files changed, 384 insertions(+), 2 deletions(-) create mode 100755 phpgwapi/inc/class.app_registry.inc.php diff --git a/phpgwapi/inc/class.app_registry.inc.php b/phpgwapi/inc/class.app_registry.inc.php new file mode 100755 index 0000000000..f1afa7f6c3 --- /dev/null +++ b/phpgwapi/inc/class.app_registry.inc.php @@ -0,0 +1,335 @@ + * + * Copyright (C) 2001 Mark Peters * + * -------------------------------------------------------------------------* + * This library is part of the phpGroupWare API * + * http://www.phpgroupware.org/api * + * ------------------------------------------------------------------------ * + * This library is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as published by * + * the Free Software Foundation; either version 2.1 of the License, * + * or any later version. * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU Lesser General Public License for more details. * + * You should have received a copy of the GNU Lesser General Public License * + * along with this library; if not, write to the Free Software Foundation, * + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + \**************************************************************************/ + + /* $Id$ */ + /*! + @class app_registry + @abstract functions for managing and installing apps via XML-RPC/SOAP + @discussion Author: skeeter + */ + class app_registry + { + var $public_functions = array( + 'list_methods' => True, + 'request_appbyid' => True, + 'request_appbyname' => True, + 'request_newer_applist' => True, + 'get_appbyid' => True, + 'get_appbyname' => True, + 'find_new_app' => True + ); + + var $soap_functions = array(); + + var $db; + var $is; + var $client; + var $server; + +// var $target_page = '/cvsdemo/xmlrpc.php'; +// var $target_site = 'www.phpgroupware.org'; + var $target_page = '/phpgroupware/xmlrpc.php'; + var $target_site = 'devel'; + var $target_port = 80; + + function app_registry($param='') + { + $this->db = $GLOBALS['phpgw']->db; + + if(is_array($param)) + { + // This is the interserver communicator + $this->is = CreateObject('phpgwapi.interserver',$param['server']); + $this->is->sessionid = $param['sessionid']; + $this->is->kp3 = $param['kp3']; + } + else + { + // create the app_registry services client + $this->client = CreateObject('phpgwapi.xmlrpc_client',$this->target_page,$this->target_site,$this->target_port); + $this->client->debug = False; + } + } + + + function list_methods($_type='xmlrpc') + { + /* + This handles introspection or discovery by the logged in client, + in which case the input might be an array. The server always calls + this function to fill the server dispatch map using a string. + */ + if (is_array($_type)) + { + $_type = $_type['type']; + } + switch($_type) + { + case 'xmlrpc': + $xml_functions = Array( + 'list_methods' => Array( + 'function' => 'list_methods', + 'signature' => Array( + Array( + xmlrpcStruct, + xmlrpcString + ) + ), + 'docstring' => lang('Read this list of methods.') + ), + 'get_appbyid' => Array( + 'function' => 'get_appbyid', + 'signature' => Array( + Array( + xmlrpcStruct, + xmlrpcString + ) + ), + 'docstring' => lang('Read a single app by id.') + ), + 'get_appbyname' => Array( + 'function' => 'get_appbyname', + 'signature' => Array( + Array( + xmlrpcStruct, + xmlrpcString + ) + ), + 'docstring' => lang('Read a single app by name.') + ), + 'find_new_app' => Array( + 'function' => 'find_new_app', + 'signature' => Array( + Array( + xmlrpcStruct, + xmlrpcStruct + ) + ), + 'docstring' => lang('compare an array of apps/versions against the repository and return new/updated list of apps.') + ) + ); + return $xml_functions; + break; + case 'soap': + return $this->soap_functions; + break; + default: + return array(); + break; + } + } + + function request($method, $args) + { + $msg = CreateObject('phpgwapi.xmlrpcmsg',$method,$args); + $resp = $this->client->send($msg); + if (!$resp) + { + echo '

IO error: '.$this->client->errstr.'

'; + $GLOBALS['phpgw']->common->phpgw_exit(); + } + if ($resp->faultCode()) + { + echo '

There was an error: '.$resp->faultCode().' '.$resp->faultString().'

'; + $GLOBALS['phpgw']->common->phpgw_exit(); + } + return xmlrpc_decode($resp->value()); + } + + function request_appbyid($appid) + { + if(is_object($this->is)) + { + return $this->is->send('system.get_appbyid',$appid,$this->is->server['server_url']); + } + else + { + return $this->request('phpgwapi.app_registry.get_appbyid',$appid); + } + } + + + function request_appbyname($app_name) + { + if(is_object($this->is)) + { + return $this->is->send('system.get_appbyname',$app_name,$this->is->server['server_url']); + } + else + { + return $this->request('phpgwapi.app_registry.get_appbyname',$app_name); + } + } + + function request_newer_applist($dummy='') + { + $this->db->query('SELECT * FROM phpgw_applications',__LINE__,__FILE__); + while($this->db->next_record()) + { + $app_list[$this->db->f('app_id')] = Array( + 'id' => $this->db->f('app_id'), + 'version' => $this->db->f('app_version') + ); + } + + if(is_object($this->is)) + { + return $this->is->send('system.find_new_app',$app_list,$this->is->server['server_url']); + } + else + { + return $this->request('phpgwapi.app_registry.find_new_app',$app_list); + } + } + + function get_result() + { + switch($this->db->num_rows()) + { + case 0: + $app[] = CreateObject('phpgwapi.xmlrpcval',CreateObject('phpgwapi.xmlrpcval',False,'boolean'),'boolean'); + break; + case 1: + $this->db->next_record(); + $app[] = CreateObject('phpgwapi.xmlrpcval', + Array( + 'id' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_id'),'int'), + 'name' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_name'),'string'), + 'title' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_title'),'string'), + 'version' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_version'),'string'), + 'tables' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_tables'),'string') + ), + 'struct' + ); + break; + default: + while($this->db->next_record()) + { + $app[] = CreateObject('phpgwapi.xmlrpcval', + Array( + 'id' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_id'),'int'), + 'name' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_name'),'string'), + 'title' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_title'),'string'), + 'version' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_version'),'string'), + 'tables' => CreateObject('phpgwapi.xmlrpcval',$this->db->f('app_tables'),'string') + ), + 'struct' + ); + } + break; + } + return CreateObject('phpgwapi.xmlrpcresp',CreateObject('phpgwapi.xmlrpcval',$app, 'struct')); + } + +// function get_result() +// { +// switch($this->db->num_rows()) +// { +// case 0: +// $app = False; +// break; +// case 1: +// $this->db->next_record(); +// $app = Array( +// 'id' => $this->db->f('app_id'), +// 'name' => $this->db->f('app_name'), +// 'title' => $this->db->f('app_title'), +// 'version' => $this->db->f('app_version'), +// 'tables' => $this->db->f('app_tables') +// ); +// break; +// default: +// while($this->db->next_record()) +// { +// $app[] = Array( +// 'id' => $this->db->f('app_id'), +// 'name' => $this->db->f('app_name'), +// 'title' => $this->db->f('app_title'), +// 'version' => $this->db->f('app_version'), +// 'tables' => $this->db->f('app_tables') +// ); +// } +// break; +// } +// return $app; +// } + + function get_appbyid($app_id) + { + $this->db->query('SELECT * FROM phpgw_applications WHERE app_id='.$app_id,__LINE__,__FILE__); + return $this->get_result(); + } + + function get_appbyname($app_name) + { + $this->db->query("SELECT * FROM phpgw_applications WHERE app_name='".$app_name."'",__LINE__,__FILE__); + return $this->get_result(); + } + + function get_allapps() + { + $this->db->query('SELECT * FROM phpgw_applications',__LINE__,__FILE__); + return $this->get_result(); + } + + function find_new_app($apps) + { + $this->db->query('SELECT * FROM phpgw_applications',__LINE__,__FILE__); + while($this->db->next_record()) + { + $app[$this->db->f('app_id')] = Array( + 'id' => $this->db->f('app_id'), + 'name' => $this->db->f('app_name'), + 'title' => $this->db->f('app_title'), + 'version' => $this->db->f('app_version'), + 'tables' => $this->db->f('app_tables') + ); + } + @reset($apps); + while($apps && list($id,$application) = each($apps)) + { + if($app[$id]) + { + if($app[$id]->version == $application->version) + { + unset($app[$id]); + } + } + } + @reset($app); + while($app && list($id,$application) = each($app)) + { + $updated_app[$id] = CreateObject('phpgwapi.xmlrpcval', + Array( + 'id' => CreateObject('phpgwapi.xmlrpcval',$id,'int'), + 'name' => CreateObject('phpgwapi.xmlrpcval',$application->name,'string'), + 'title' => CreateObject('phpgwapi.xmlrpcval',$application->title,'string'), + 'version' => CreateObject('phpgwapi.xmlrpcval',$application->version,'string'), + 'tables' => CreateObject('phpgwapi.xmlrpcval',$application->tables,'string') + ), + 'struct' + ); + } + return CreateObject('phpgwapi.xmlrpcresp',CreateObject('phpgwapi.xmlrpcval',$updated_app, 'struct')); + } + } +?> diff --git a/phpgwapi/inc/class.service.inc.php b/phpgwapi/inc/class.service.inc.php index bebf2f5720..2630fa81a9 100644 --- a/phpgwapi/inc/class.service.inc.php +++ b/phpgwapi/inc/class.service.inc.php @@ -35,7 +35,10 @@ { $data = $service[2]; $function = $service[1]; - $service = $service[0]; + $temp_service = $service[0]; + settype($service,'string'); + $service = $temp_service; + unset($temp_service); } switch ($service) { @@ -45,6 +48,9 @@ case 'todo': $this = CreateObject('phpgwapi.service_' . $service); break; + case 'app_registry': + $this = CreateObject('phpgwapi.'.$service); + break; default: $this = CreateObject($service); break; diff --git a/phpgwapi/inc/class.xmlrpcmsg.inc.php b/phpgwapi/inc/class.xmlrpcmsg.inc.php index a6dcace472..dc49b33e53 100644 --- a/phpgwapi/inc/class.xmlrpcmsg.inc.php +++ b/phpgwapi/inc/class.xmlrpcmsg.inc.php @@ -25,7 +25,8 @@ var $payload; var $methodname; var $params = array(); - var $debug = 0; +// var $debug = True; + var $debug = False; function xmlrpcmsg($meth, $pars=0) { @@ -198,6 +199,7 @@ xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); } +// echo $errstr; error_log($errstr); $r = CreateObject('phpgwapi.xmlrpcresp', '', $GLOBALS['xmlrpcerr']['invalid_return'],$GLOBALS['xmlrpcstr']['invalid_return']); xml_parser_free($parser); diff --git a/phpgwapi/inc/xml_functions.inc.php b/phpgwapi/inc/xml_functions.inc.php index 433fa8152e..04a6edeaf6 100644 --- a/phpgwapi/inc/xml_functions.inc.php +++ b/phpgwapi/inc/xml_functions.inc.php @@ -685,6 +685,30 @@ } */ + $GLOBALS['_xmlrpcs_get_appbyname_sig'] = array(array(xmlrpcStruct,xmlrpcString)); + $GLOBALS['_xmlrpcs_get_appbyname_doc'] = 'Returns an array of information for the requested application name'; + function _xmlrpcs_get_appbyname($server,$m) + { + $app = $m->getParam(0); + return ExecMethod('phpgwapi.app_registry.get_appbyname',$app->scalarval()); + } + + $GLOBALS['_xmlrpcs_get_appbyid_sig'] = array(array(xmlrpcStruct,xmlrpcString)); + $GLOBALS['_xmlrpcs_get_appbyid_doc'] = 'Returns an array of information for the requested application ID'; + function _xmlrpcs_get_appbyid($server,$m) + { + $app = $m->getParam(0); + return ExecMethod('phpgwapi.app_registry.get_appbyid',$app->scalarval()); + } + + $GLOBALS['_xmlrpcs_find_new_app_sig'] = array(array(xmlrpcStruct,xmlrpcStruct)); + $GLOBALS['_xmlrpcs_find_new_app_doc'] = 'Returns an array of information for the requested application ID'; + function _xmlrpcs_find_new_app($server,$m) + { + $app = $m->getParam(0); + return ExecMethod('phpgwapi.app_registry.find_new_app',$app->scalarval()); + } + $GLOBALS['_xmlrpcs_login_sig'] = array(array(xmlrpcStruct,xmlrpcStruct)); $GLOBALS['_xmlrpcs_login_doc'] = 'phpGroupWare client or server login via XML-RPC'; function _xmlrpcs_login($server,$m) @@ -782,6 +806,21 @@ 'docstring' => $GLOBALS['_xmlrpcs_listApps_doc'] ), */ + 'system.get_appbyname' => array( + 'function' => '_xmlrpcs_get_appbyname', + 'signature' => $GLOBALS['_xmlrpcs_get_appbyname_sig'], + 'docstring' => $GLOBALS['_xmlrpcs_get_appbyname_doc'] + ), + 'system.get_appbyid' => array( + 'function' => '_xmlrpcs_get_appbyid', + 'signature' => $GLOBALS['_xmlrpcs_get_appbyid_sig'], + 'docstring' => $GLOBALS['_xmlrpcs_get_appbyid_doc'] + ), + 'system.find_new_app' => array( + 'function' => '_xmlrpcs_find_new_app', + 'signature' => $GLOBALS['_xmlrpcs_find_new_app_sig'], + 'docstring' => $GLOBALS['_xmlrpcs_find_new_app_doc'] + ), 'system.login' => array( 'function' => '_xmlrpcs_login', 'signature' => $GLOBALS['_xmlrpcs_login_sig'],