[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] api/rpc class.rpc_browser.php, NONE, 1.1.2.1 class.rp
From: |
Dan Kuykendall <address@hidden> |
Subject: |
[Phpgroupware-cvs] api/rpc class.rpc_browser.php, NONE, 1.1.2.1 class.rpc_xmlrpc.php, NONE, 1.1.2.1 |
Date: |
Tue, 28 Oct 2003 04:30:03 +0000 |
Update of /cvsroot/phpgroupware/api/rpc
In directory subversions:/tmp/cvs-serv14506/api/rpc
Added Files:
Tag: proposal-branch
class.rpc_browser.php class.rpc_xmlrpc.php
Log Message:
modified loading structure to handle xmlrpc and other rpc services such as
soap. Added xmlrpc support
--- NEW FILE: class.rpc_browser.php ---
<?php
/**************************************************************************\
* phpGroupWare
*
* http://www.phpgroupware.org
*
* This file written by Dan Kuykendall <address@hidden> *
* Copyright (C) 2003 Dan Kuykendall
*
*
-------------------------------------------------------------------------*
* 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.rpc_browser.php,v 1.1.2.1 2003/10/28 04:30:01 seek3r Exp
$ */
class api_rpc
{
var $xslt_render;
var $xslt_render_force_server = False;
function api_rpc()
{
reg_var('op', 'any', 'any','##NOVAL##');
}
function get_op()
{
$this->op;
}
function get_inputs()
{
$inputs =
array_merge($HTTP_SESSION_VARS['phpgw_session'], $HTTP_COOKIE_VARS,
$HTTP_GET_VARS, $HTTP_POST_VARS);
unset($inputs['phpgw_lid'],
$inputs['PHPSESSID'],$inputs['session_lid'],$inputs['sid']);
unset($inputs['op'], $inputs['nextop'],
$inputs['prevop']);
unset($inputs['phpgw_user'], $inputs['phpgw_pass']);
unset($inputs['fxsl'], $inputs['lang_cache']);
return $inputs;
}
/*!
@function handle_result
@abstract Takes the results of the operation, packs it up and
then has phpgw->finish handle the rest.
@param $app_data
*/
function handle_result($result)
{
$GLOBALS['phpgw_xmldoc']->add_node($result, 'APP');
$GLOBALS['phpgw']->finish();
}
function sendtoclient()
{
/* Start the XSLT class for it to be able to decide how
to build the strings */
$this->xslt_render = createobject('api_xslt');
if($this->xslt_render_force_server)
{
$this->xslt_render->client_render = False;
}
$stylesheet_string =
$this->xslt_render->setup_stylesheet($GLOBALS['phpgw']->xsl_files);
$GLOBALS['phpgw']->base_xml->set_stylesheet($stylesheet_string);
/* Constructing the XML doc */
$xml_result =
$GLOBALS['phpgw']->base_xml->export_xml();
/* Use the XSLT class to handle browser detection */
/* and if needed, the rendering of the XML */
$this->xslt_render->set_xml($xml_result);
/* Before we send output, save the session data */
$GLOBALS['phpgw']->session->save_data();
/* Have XSLT class output as it determins as best */
//echo '<pre>'; print_r($GLOBALS); echo '</pre>';
echo $this->xslt_render->getOutput();
exit;
}
}
--- NEW FILE: class.rpc_xmlrpc.php ---
<?php
/**************************************************************************\
* phpGroupWare
*
* http://www.phpgroupware.org
*
* This file written by Dan Kuykendall <address@hidden> *
* Copyright (C) 2003 Dan Kuykendall
*
*
-------------------------------------------------------------------------*
* 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.rpc_xmlrpc.php,v 1.1.2.1 2003/10/28 04:30:01 seek3r Exp $
*/
class api_rpc
{
var $op;
var $inputs;
var $method_result;
var $indent = '';
function api_rpc()
{
$this->parse();
$GLOBALS['phpgw_data']['api']['op'] = $this->op;
}
function parse()
{
/*
$GLOBALS['HTTP_RAW_POST_DATA'] = 'POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
Host: betty.userland.com
Content-Type: text/xml
Content-length: 181
<?xml version="1.0"?>
<methodCall>
<methodName>api.base.start</methodName>
<params>
<param>
<value><i4>41</i4></value>
</param>
<param>
<value><string>blah</string></value>
</param>
<param>
<value>dan</value>
</param>
</params>
</methodCall>';
*/
$tmp = explode ("\n", $GLOBALS['HTTP_RAW_POST_DATA']);
$num = count($tmp);
$hit_start = False;
$xmlrpc_input = '';
for ($i=1; $i < $num; $i++)
{
if($hit_start)
{
$xmlrpc_input .= $tmp[$i]."\n";
}
elseif(stristr($tmp[$i], '<?xml'))
{
$hit_start = True;
$xmlrpc_input .= $tmp[$i]."\n";
}
}
$GLOBALS['methodCall'] = xml2var($xmlrpc_input);
if(isset($GLOBALS['methodCall']['methodName']))
{
$this->op =
$GLOBALS['methodCall']['methodName'];
if(is_array($GLOBALS['methodCall']['params']))
{
$this->parse_params($GLOBALS['methodCall']['params']);
}
}
}
function parse_params($params)
{
foreach($params as $key=>$val)
{
if(isset($val['value']))
{
$this->parse_param_sub($val);
}
else
{
foreach($val as $subkey=>$subval)
{
$this->parse_param_sub($subval);
}
}
}
}
function parse_param_sub($param)
{
if(!is_array($param['value']))
{
$this->inputs[] = $param['value'];
}
else
{
$type = key($param['value']);
switch ($type)
{
case 'base64':
$val['value'][$type] =
base64_decode($param['value'][$type]);
case 'boolean':
settype($param['value'][$type],'boolean');
case 'i4':
case 'double':
case 'dateTime.iso8601':
case 'string':
default:
$this->inputs[] =
$param['value'][$type];
}
}
}
function get_op()
{
$this->op;
}
function get_inputs()
{
$this->inputs;
}
function handle_result($result)
{
$this->method_result = $result;
$GLOBALS['phpgw']->finish();
}
function sendtoclient()
{
/* Constructing the XML doc */
$response_packet = "<?xml version=\"1.0\"?>\n";
$response_packet .= "<methodResponse>\n";
if(!empty($this->method_result))
{
$response_packet .= "<params>\n";
if(!is_array($this->method_result))
{
$response_packet .= "<param>\n";
$response_packet .=
$this->add_vars($this->method_result);
$response_packet .= "</param>\n";
}
else
{
if(array_key_exists(0,$this->method_result))
{
$num =
count($this->method_result);
for ($i=0; $i < $num; $i++)
{
$response_packet .=
"<param>\n";
$response_packet .=
$this->add_vars($this->method_result[$i]);
$response_packet .=
"</param>\n";
}
}
else
{
$response_packet .= "<param>\n";
$response_packet .= "<value>\n";
$response_packet .=
$this->add_vars($this->method_result);
$response_packet .=
"</value>\n";
$response_packet .=
"</param>\n";
}
}
$response_packet .= "</params>\n";
}
$response_packet .= "</methodResponse>";
header('Content-type: text/xml');
header('Content-Length: '.strlen($response_packet));
echo $response_packet;
exit;
}
function add_vars($params)
{
if(!is_array($params))
{
$result =
"<value>".$this->add_params_type_handler($params)."</value>\n";
}
else
{
if(array_key_exists(0,$params))
{
$num = count($params);
$result = "<array>\n<data>\n";
for ($i=0; $i < $num; $i++)
{
if(is_array($params[$i]))
{
$result .=
$this->add_vars($params[$i]);
}
else
{
$result .=
"<value>".$this->add_params_type_handler($params[$i])."</value>\n";
}
}
$result .= "</data>\n</array>\n";
}
else
{
$result = "<struct>\n";
foreach($params as $key=>$val)
{
if(is_array($val))
{
$result .=
$this->add_vars($val);
}
else
{
$result .= "<member>\n";
$result .=
"<name>".$key."</name>\n";
$result .=
"<value>".$this->add_params_type_handler($val)."</value>\n";
$result .=
"</member>\n";
}
}
$result .= "</struct>\n";
}
}
return $result;
}
function add_params_type_handler($param)
{
switch(gettype($param))
{
case 'boolean':
return '<boolean>'.$param.'</boolean>';
break;
case 'double':
return '<double>'.$param.'</double>';
break;
case 'integer':
return '<i4>'.$param.'</i4>';
break;
case 'array':
//need to handle this
break;
default:
return '<string>'.$param.'</string>';
}
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] api/rpc class.rpc_browser.php, NONE, 1.1.2.1 class.rpc_xmlrpc.php, NONE, 1.1.2.1,
Dan Kuykendall <address@hidden> <=