[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] api/interface/class.interface_xmlrpc.php, 1.1.2.19
From: |
nomail |
Subject: |
[Phpgroupware-cvs] api/interface/class.interface_xmlrpc.php, 1.1.2.19 |
Date: |
Tue, 22 Jun 2004 16:15:46 +0200 |
Update of /api/interface
Modified Files:
Branch: proposal-branch
class.interface_xmlrpc.php
date: 2004/06/22 14:15:46; author: dcech; state: Exp; lines: +55 -194
Log Message:
new input parser for xmlrpc interface
moved some environment initialisation stuff from core_functions.inc.php into
starter.inc.php
moved interface check code into class.interface.php
=====================================================================
Index: api/interface/class.interface_xmlrpc.php
diff -u api/interface/class.interface_xmlrpc.php:1.1.2.18
api/interface/class.interface_xmlrpc.php:1.1.2.19
--- api/interface/class.interface_xmlrpc.php:1.1.2.18 Tue Jun 22 12:51:50 2004
+++ api/interface/class.interface_xmlrpc.php Tue Jun 22 14:15:46 2004
@@ -151,43 +151,25 @@
header('Location: index.php');
exit;
}
-
- if(!strstr($GLOBALS['HTTP_RAW_POST_DATA'], '<?xml'))
- {
- $GLOBALS['HTTP_RAW_POST_DATA'] = "<?xml
version=\"1.0\"?>\n".$GLOBALS['HTTP_RAW_POST_DATA'];
- }
- $tmp = explode ("\n", $GLOBALS['HTTP_RAW_POST_DATA']);
- $num = count($tmp);
- $hit_start = false;
- $xmlrpc_input = '';
- for ($i=0; $i < $num; $i++)
+
+ if
(!preg_match('/(<\?xml.+?>\s)?(<methodCall>.*<\/methodCall>)/is',$GLOBALS['HTTP_RAW_POST_DATA'],$matches))
{
- if($hit_start)
- {
- $xmlrpc_input .= $tmp[$i]."\n";
- }
- elseif(stristr($tmp[$i], '<?xml'))
- {
- $hit_start = true;
- $xmlrpc_input .= $tmp[$i]."\n";
- }
+ $GLOBALS['phpgw']->finish(false);
+ $this->xmlrpc_fault('1', 'Invalid xmlrpc
packet.');
}
-
- $parser = xml_parser_create();
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING,
0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE,
1);
- xml_parse_into_struct($parser, $xmlrpc_input,
$xml_vals, $xml_index);
- xml_parser_free($parser);
- $this->xml_index = $xml_index;
- $this->xml_vals = $xml_vals;
- unset($xml_index, $xml_vals);
-
if(!isset($this->xml_vals[$this->xml_index['methodName'][0]]['value']))
+
+ $xmlrpc_input = empty($matches[1]) ? '<?xml
version="1.0">'."\n" : $matches[1];
+ $xmlrpc_input .= $matches[2];
+
+ $request = xml2var($xmlrpc_input);
+
+ if (!isset($request['methodName']))
{
$GLOBALS['phpgw']->finish(false);
$this->xmlrpc_fault('1', 'Invalid xmlrpc
packet. methodName missing.');
}
-
- $this->methodName =
$this->xml_vals[$this->xml_index['methodName'][0]]['value'];
+
+ $this->methodName = $request['methodName'];
switch ($this->methodName)
{
case 'system.listMethods':
@@ -205,187 +187,66 @@
default:
$this->op = $this->methodName;
}
-
- if(count($this->xml_index['params']) == 2)
+
+ if (is_array($request['params']['param']))
{
- $this->i = $this->xml_index['params'][0];
- $this->xml_vals_count = count($this->xml_vals);
- $this->inputs = $this->parse_params();
+ $this->inputs =
$this->parse_param(reset($request['params']['param']));
+ }
+ else
+ {
+ $this->inputs =
$this->parse_param($request['params']['param']);
}
}
-
- function parse_params()
+
+ function parse_param($param)
{
- switch($this->xml_vals[$this->i]['type'])
+ $value = reset($param);
+
+ switch (key($param))
{
- case 'complete':
- $this->input_num++;
- switch($this->xml_vals[$this->i]['tag'])
+ case 'value':
+ return $this->parse_param($value);
+ case 'array':
+ $ret = array();
+ if (count($value['data']) == 1)
{
- case 'value':
- $back = 1;
- $value =
$this->xml_vals[$this->i]['value'];
- break;
- case 'base64':
- $back = 2;
- $value =
base64_decode($this->xml_vals[$this->i]['value']);
- break;
- case 'boolean':
- $back = 2;
- $value =
$this->xml_vals[$this->i]['value'];
-
settype($value,'boolean');
- break;
- case 'int':
- case 'i4':
- case 'double':
- case 'dateTime.iso8601':
- case 'string':
- $back = 2;
- $value =
$this->xml_vals[$this->i]['value'];
- break;
+ $ret[] =
$this->parse_param($value['data']);
}
- $this->i++;
-
- if($this->op == 'api.base.login')
+ else
{
- if($this->input_num == 1)
+ foreach ($value['data'] as
$item)
{
- $_GET['phpgw_user'] =
$value;
+ $ret[] =
$this->parse_param($item);
}
- elseif($this->input_num == 2)
- {
- $_GET['phpgw_pass'] =
$value;
- }
- return;
}
- elseif($this->input_num == 1)
+ return $ret;
+ case 'struct':
+ $ret = array();
+ if (isset($value['member']['name']))
{
- $_GET['sid'] = $value;
- return;
+ $ret[$value['member']['name']]
= $this->parse_param($value['member']['value']);
}
else
{
- return $value;
- if(isset($name))
- {
- return
array($name=>$value);
- }
- else
+ foreach ($value['member'] as
$item)
{
- return $value;
+ $ret[$item['name']] =
$this->parse_param($item['value']);
}
}
- break;
- case 'open':
- switch
($this->xml_vals[$this->i]['tag'])
- {
- case 'params':
- case 'param':
- $this->i++;
-
while($this->xml_vals[$this->i]['type'] != 'close')
- {
- $tmp =
$this->parse_params();
- if(isset($tmp))
- {
-
$result[] = $tmp;
- }
- $this->i++;
- }
- if(count($result) == 1)
- {
- return
$result[0];
- }
- else
- {
- return $result;
- }
- break;
- case 'array':
- $this->i++;
- $this->i++;
-
while($this->xml_vals[$this->i]['type'] != 'close')
- {
- $tmp =
$this->parse_params();
- if(isset($tmp))
- {
-
$result[] = $tmp;
- }
- $this->i++;
- }
- $this->i++;
- $this->i++;
- if(count($result) == 1)
- {
- return
$result[0];
- }
- else
- {
- return $result;
- }
- break;
-
- case 'struct':
- $this->i++;
- $this->i++;
-
while($this->xml_vals[$this->i]['type'] != 'close')
- {
-
if($this->xml_vals[$this->i]['tag'] == 'name')
- {
-
if(isset($this->xml_vals[$this->i]['value']))
- {
-
$name = $this->xml_vals[$this->i]['value'];
- }
-
$this->i++;
- }
- $tmp =
$this->parse_params();
-
-
if($this->xml_vals[$this->i+1]['tag'] == 'name')
- {
-
if(isset($this->xml_vals[$this->i+1]['value']))
- {
-
$name = $this->xml_vals[$this->i+1]['value'];
- }
-
//$this->i++;
- }
-
- if(isset($tmp))
- {
-
if(isset($name))
- {
-
$result[$name] = $tmp;
- }
- else
- {
-
$result[] = $tmp;
- }
-
- }
- $this->i++;
- $this->i++;
- }
- $this->i++;
- $this->i++;
- reset ($result);
- if(count($result) == 1
&& key($result) === 0)
- {
- return
$result[0];
- }
- else
- {
- return $result;
- }
- break;
-
- case 'value':
- $this->i++;
- return
$this->parse_params();
- break;
- }
- break;
- case 'close':
- return;
- break;
+ return $ret;
+ case 'base64':
+ return base64_decode($value);
+ case 'boolean':
+ return (bool)$value;
+ case 'int':
+ case 'i4':
+ case 'double':
+ case 'dateTime.iso8601':
+ case 'string':
+ return $value;
}
+
+ return;
}
function response($result = NOTSET)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] api/interface/class.interface_xmlrpc.php, 1.1.2.19,
nomail <=