Add one other weird exclusion in createobject() (this should fix passing 0

to xmlrpcval class for an int type; formatting;
This commit is contained in:
Miles Lott 2002-02-09 21:19:22 +00:00
parent c77dea5328
commit e00280c5b0
5 changed files with 93 additions and 108 deletions

View File

@ -195,27 +195,11 @@
$_type = (is_integer($_res)?'int':gettype($_res));
if ($recursed)
{
// Passing an integer of 0 to the xmlrpcval constructor results in the value being lost. (jengo)
if ($_type == 'int' && $_res == 0)
{
return CreateObject('phpgwapi.xmlrpcval','0',$_type);
}
else
{
return CreateObject('phpgwapi.xmlrpcval',$_res,$_type);
}
return CreateObject('phpgwapi.xmlrpcval',$_res,$_type);
}
else
{
// Passing an integer of 0 to the xmlrpcval constructor results in the value being lost. (jengo)
if ($_type == 'int' && $_res == 0)
{
$this->resp_struct[] = CreateObject('phpgwapi.xmlrpcval','0',$_type);
}
else
{
$this->resp_struct[] = CreateObject('phpgwapi.xmlrpcval',$_res,$_type);
}
$this->resp_struct[] = CreateObject('phpgwapi.xmlrpcval',$_res,$_type);
}
}
}
@ -381,7 +365,7 @@
/* _debug_array($res);exit; */
$this->resp_struct = array();
$this->build_resp($res);
/*_debug_array($this->resp_struct); */
/* _debug_array($this->resp_struct); */
@reset($this->resp_struct);
$r = CreateObject('phpgwapi.xmlrpcresp',CreateObject('phpgwapi.xmlrpcval',$this->resp_struct,'struct'));
/* _debug_array($r); */

View File

@ -28,21 +28,21 @@
$this->me = array();
$this->mytype = 0;
if ($val != -1 || $type != '')
if($val != -1 || $type != '')
{
if ($type=='')
if($type == '')
{
$type='string';
$type = 'string';
}
if ($GLOBALS['xmlrpcTypes'][$type]==1)
if($GLOBALS['xmlrpcTypes'][$type] == 1)
{
$this->addScalar($val,$type);
}
elseif ($GLOBALS['xmlrpcTypes'][$type]==2)
elseif($GLOBALS['xmlrpcTypes'][$type] == 2)
{
$this->addArray($val);
}
elseif ($GLOBALS['xmlrpcTypes'][$type]==3)
elseif($GLOBALS['xmlrpcTypes'][$type] == 3)
{
$this->addStruct($val);
}
@ -51,23 +51,23 @@
function addScalar($val, $type='string')
{
if ($this->mytype==1)
if ($this->mytype == 1)
{
echo '<B>xmlrpcval</B>: scalar can have only one value<BR>';
return 0;
}
$typeof=$GLOBALS['xmlrpcTypes'][$type];
if ($typeof!=1)
$typeof = $GLOBALS['xmlrpcTypes'][$type];
if ($typeof != 1)
{
echo '<B>xmlrpcval</B>: not a scalar type ('.$typeof.')<BR>';
return 0;
}
if ($type==xmlrpcBoolean)
if ($type == xmlrpcBoolean)
{
if (strcasecmp($val,'true')==0 ||
$val==1 || ($val==true &&
strcasecmp($val,'false')))
if (strcasecmp($val,'true') == 0 ||
$val == 1 ||
($val == True && strcasecmp($val,'false')))
{
$val=1;
}
@ -77,58 +77,58 @@
}
}
if ($this->mytype==2)
if ($this->mytype == 2)
{
// we're adding to an array here
$ar=$this->me['array'];
$ar = $this->me['array'];
$ar[] = CreateObject('phpgwapi.xmlrpcval',$val, $type);
$this->me['array']=$ar;
$this->me['array'] = $ar;
}
else
{
// a scalar, so set the value and remember we're scalar
$this->me[$type]=$val;
$this->mytype=$typeof;
$this->me[$type] = $val;
$this->mytype = $typeof;
}
return 1;
}
function addArray($vals)
{
if ($this->mytype!=0)
if($this->mytype != 0)
{
echo '<B>xmlrpcval</B>: already initialized as a [' . $this->kindOf() . ']<BR>';
return 0;
}
$this->mytype=$GLOBALS['xmlrpcTypes']['array'];
$this->me['array']=$vals;
$this->mytype = $GLOBALS['xmlrpcTypes']['array'];
$this->me['array'] = $vals;
return 1;
}
function addStruct($vals)
{
if ($this->mytype!=0)
if($this->mytype != 0)
{
echo '<B>xmlrpcval</B>: already initialized as a [' . $this->kindOf() . ']<BR>';
return 0;
}
$this->mytype=$GLOBALS['xmlrpcTypes']['struct'];
$this->me['struct']=$vals;
$this->mytype = $GLOBALS['xmlrpcTypes']['struct'];
$this->me['struct'] = $vals;
return 1;
}
function dump($ar)
{
reset($ar);
while (list($key,$val) = each($ar))
while(list($key,$val) = each($ar))
{
echo $key.' => '.$val.'<br>';
if ($key == 'array')
if($key == 'array')
{
while (list($key2,$val2) = each($val))
while(list($key2,$val2) = each($val))
{
echo '-- '.$key2.' => '.$val2.'<br>';
echo '-- ' . $key2.' => ' . $val2 . '<br>';
}
}
}
@ -154,7 +154,7 @@
function serializedata($typ, $val)
{
$rs='';
$rs = '';
if($typ)
{
switch($GLOBALS['xmlrpcTypes'][$typ])
@ -165,36 +165,36 @@
reset($val);
while(list($key2, $val2)=each($val))
{
$rs .= '<member><name>'.$key2.'</name>'."\n".$this->serializeval($val2).'</member>'."\n";
$rs .= '<member><name>' . $key2 . '</name>' . "\n" . $this->serializeval($val2) . '</member>' . "\n";
}
$rs .= '</struct>';
break;
case 2:
// array
$rs .= '<array>'."\n".'<data>'."\n";
$rs .= '<array>' . "\n" . '<data>' . "\n";
for($i=0; $i<sizeof($val); $i++)
{
$rs .= $this->serializeval($val[$i]);
}
$rs .= '</data>'."\n".'</array>';
$rs .= '</data>' . "\n" . '</array>';
break;
case 1:
$rs .= '<'.$typ.'>';
switch ($typ)
$rs .= '<' . $typ . '>';
switch($typ)
{
case xmlrpcBase64:
$rs.= base64_encode($val);
$rs .= base64_encode($val);
break;
case xmlrpcBoolean:
$rs.= ($val ? '1' : '0');
$rs .= ($val ? '1' : '0');
break;
case xmlrpcString:
$rs.= htmlspecialchars($val);
$rs .= htmlspecialchars($val);
break;
default:
$rs.= $val;
$rs .= $val;
}
$rs .= '</'.$typ.'>';
$rs .= '</' . $typ . '>';
break;
default:
break;
@ -210,19 +210,19 @@
function serializeval($o)
{
$rs='';
$ar=$o->me;
$rs = '';
$ar = $o->me;
reset($ar);
list($typ, $val) = each($ar);
$rs.='<value>';
$rs.= @$this->serializedata($typ, $val);
$rs.='</value>'."\n";
$rs .= '<value>';
$rs .= @$this->serializedata($typ, $val);
$rs .= '</value>' . "\n";
return $rs;
}
function structmem($m)
{
$nv=$this->me['struct'][$m];
$nv = $this->me['struct'][$m];
return $nv;
}
@ -240,13 +240,13 @@
{
// UNSTABLE
reset($this->me);
list($a,$b)=each($this->me);
list($a,$b) = each($this->me);
// contributed by I Sofer, 2001-03-24
// add support for nested arrays to scalarval
// i've created a new method here, so as to
// preserve back compatibility
if (is_array($b))
if(is_array($b))
{
@reset($b);
while(list($id,$cont) = @each($b))
@ -256,7 +256,7 @@
}
// add support for structures directly encoding php objects
if (is_object($b))
if(is_object($b))
{
$t = get_object_vars($b);
@reset($t);
@ -277,31 +277,31 @@
function scalarval()
{
reset($this->me);
list($a,$b)=each($this->me);
list($a,$b) = each($this->me);
return $b;
}
function scalartyp()
{
reset($this->me);
list($a,$b)=each($this->me);
if ($a==xmlrpcI4)
list($a,$b) = each($this->me);
if ($a == xmlrpcI4)
{
$a=xmlrpcInt;
$a = xmlrpcInt;
}
return $a;
}
function arraymem($m)
{
$nv=@$this->me['array'][$m];
$nv = @$this->me['array'][$m];
return $nv;
}
function arraysize()
{
reset($this->me);
list($a,$b)=each($this->me);
list($a,$b) = each($this->me);
return sizeof($b);
}
}

View File

@ -227,7 +227,7 @@
{
global $phpgw_info, $phpgw;
if (is_object(@$GLOBALS['phpgw']->log) && $class != 'phpgwapi.error' && $class != 'phpgwapi.errorlog')
if(is_object(@$GLOBALS['phpgw']->log) && $class != 'phpgwapi.error' && $class != 'phpgwapi.errorlog')
{
//$GLOBALS['phpgw']->log->write(array('text'=>'D-Debug, dbg: %1','p1'=>'This class was run: '.$class,'file'=>__FILE__,'line'=>__LINE__));
}
@ -235,10 +235,10 @@
/* error_reporting(0); */
list($appname,$classname) = explode(".", $class);
if (!isset($GLOBALS['phpgw_info']['flags']['included_classes'][$classname]) ||
if(!isset($GLOBALS['phpgw_info']['flags']['included_classes'][$classname]) ||
!$GLOBALS['phpgw_info']['flags']['included_classes'][$classname])
{
if(@file_exists(PHPGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php'))
if(@file_exists(PHPGW_INCLUDE_ROOT . '/' . $appname . '/inc/class.' . $classname . '.inc.php'))
{
include(PHPGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php');
$GLOBALS['phpgw_info']['flags']['included_classes'][$classname] = True;
@ -250,7 +250,7 @@
}
if($GLOBALS['phpgw_info']['flags']['included_classes'][$classname])
{
if ($p1 == '_UNDEF_' && $p1 != 1)
if($p1 == '_UNDEF_' && $p1 != 1 && $p1 != '0')
{
eval('$obj = new ' . $classname . ';');
}
@ -259,9 +259,9 @@
$input = array($p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9,$p10,$p11,$p12,$p13,$p14,$p15,$p16);
$i = 1;
$code = '$obj = new ' . $classname . '(';
while (list($x,$test) = each($input))
while(list($x,$test) = each($input))
{
if (($test == '_UNDEF_' && $test != 1 ) || $i == 17)
if(($test == '_UNDEF_' && $test != 1 && $test != '0') || $i == 17)
{
break;
}
@ -420,7 +420,7 @@
*/
function get_account_id($account_id = '',$default_id = '')
{
if (gettype($account_id) == 'integer')
if (is_int($account_id))
{
return $account_id;
}

View File

@ -3,7 +3,7 @@
// <edd@usefulinc.com>
// xmlrpc.inc,v 1.18 2001/07/06 18:23:57 edmundd
// License is granted to use or modify this software ("XML-RPC for PHP")
// 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
// is preserved in any distributed or derivative work.
@ -22,7 +22,7 @@
if (!function_exists('xml_parser_create'))
{
// Win 32 fix. From: "Leo West" <lwest@imaginet.fr>
// Win 32 fix. From: 'Leo West' <lwest@imaginet.fr>
if($WINDIR)
{
dl('php3_xml.dll');
@ -125,7 +125,7 @@
// qt - used to decide if quotes are needed for evaluation
// cm - used to denote struct or array (comma needed)
// isf - used to indicate a fault
// lv - used to indicate "looking for a value": implements
// lv - used to indicate 'looking for a value': implements
// the logic to allow values with no types to be strings
// params - used to store parameters in method calls
// method - used to store method name
@ -314,8 +314,9 @@
$GLOBALS['_xh'][$parser]['st'].=$GLOBALS['_xh'][$parser]['ac'];
}
}
$GLOBALS['_xh'][$parser]['ac']=""; $GLOBALS['_xh'][$parser]['qt']=0;
$GLOBALS['_xh'][$parser]['lv']=3; // indicate we've found a value
$GLOBALS['_xh'][$parser]['ac'] = '';
$GLOBALS['_xh'][$parser]['qt'] = 0;
$GLOBALS['_xh'][$parser]['lv'] = 3; // indicate we've found a value
break;
case 'VALUE':
// deal with a string value
@ -325,7 +326,7 @@
$GLOBALS['_xh'][$parser]['st'].='"'. $GLOBALS['_xh'][$parser]['ac'] . '"';
}
// This if() detects if no scalar was inside <VALUE></VALUE>
// and pads an empty "".
// and pads an empty ''.
if($GLOBALS['_xh'][$parser]['st'][strlen($GLOBALS['_xh'][$parser]['st'])-1] == '(')
{
$GLOBALS['_xh'][$parser]['st'].= '""';
@ -333,22 +334,22 @@
$GLOBALS['_xh'][$parser]['st'].=", '" . $GLOBALS['_xh'][$parser]['vt'] . "')";
if ($GLOBALS['_xh'][$parser]['cm'])
{
$GLOBALS['_xh'][$parser]['st'].=",";
$GLOBALS['_xh'][$parser]['st'].=',';
}
break;
case 'MEMBER':
$GLOBALS['_xh'][$parser]['ac']="";
$GLOBALS['_xh'][$parser]['ac']='';
$GLOBALS['_xh'][$parser]['qt']=0;
break;
case 'DATA':
$GLOBALS['_xh'][$parser]['ac']="";
$GLOBALS['_xh'][$parser]['ac']='';
$GLOBALS['_xh'][$parser]['qt']=0;
break;
case 'PARAM':
$GLOBALS['_xh'][$parser]['params'][]=$GLOBALS['_xh'][$parser]['st'];
break;
case 'METHODNAME':
$GLOBALS['_xh'][$parser]['method']=ereg_replace("^[\n\r\t ]+", "", $GLOBALS['_xh'][$parser]['ac']);
$GLOBALS['_xh'][$parser]['method']=ereg_replace("^[\n\r\t ]+", '', $GLOBALS['_xh'][$parser]['ac']);
break;
case 'BOOLEAN':
// special case here: we translate boolean 1 or 0 into PHP
@ -380,7 +381,7 @@
if ($GLOBALS['_xh'][$parser]['lv']!=3)
{
// "lookforvalue==3" means that we've found an entire value
// 'lookforvalue==3' means that we've found an entire value
// and should discard any further character data
if ($GLOBALS['_xh'][$parser]['lv']==1)
{
@ -426,19 +427,19 @@
// and an adjustment for locale is made when encoding
if (!$utc)
{
$t=strftime("%Y%m%dT%H:%M:%S", $timet);
$t=strftime('%Y%m%dT%H:%M:%S', $timet);
}
else
{
if (function_exists("gmstrftime"))
if (function_exists('gmstrftime'))
{
// gmstrftime doesn't exist in some versions
// of PHP
$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
$t=gmstrftime('%Y%m%dT%H:%M:%S', $timet);
}
else
{
$t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z"));
$t=strftime('%Y%m%dT%H:%M:%S', $timet-date('Z'));
}
}
return $t;
@ -472,11 +473,11 @@
{
$kind = @$xmlrpc_val->kindOf();
if($kind == "scalar")
if($kind == 'scalar')
{
return $xmlrpc_val->scalarval();
}
elseif($kind == "array")
elseif($kind == 'array')
{
$size = $xmlrpc_val->arraysize();
$arr = array();
@ -487,7 +488,7 @@
}
return $arr;
}
elseif($kind == "struct")
elseif($kind == 'struct')
{
$xmlrpc_val->structreset();
$arr = array();
@ -519,8 +520,8 @@
switch($type)
{
case "array":
case "object":
case 'array':
case 'object':
$arr = array();
while (list($k,$v) = each($php_val))
{
@ -528,22 +529,22 @@
}
$xmlrpc_val->addStruct($arr);
break;
case "integer":
case 'integer':
$xmlrpc_val->addScalar($php_val, xmlrpcInt);
break;
case "double":
case 'double':
$xmlrpc_val->addScalar($php_val, xmlrpcDouble);
break;
case "string":
case 'string':
$xmlrpc_val->addScalar($php_val, xmlrpcString);
break;
// <G_Giunta_2001-02-29>
// Add support for encoding/decoding of booleans, since they are supported in PHP
case "boolean":
case 'boolean':
$xmlrpc_val->addScalar($php_val, xmlrpcBoolean);
break;
// </G_Giunta_2001-02-29>
case "unknown type":
case 'unknown type':
default:
$xmlrpc_val = false;
break;
@ -704,7 +705,7 @@
if($server_name)
{
list($sessionid,$kp3) = $GLOBALS['phpgw']->session->create_server($username.'@'.$server_name,$password,"text");
list($sessionid,$kp3) = $GLOBALS['phpgw']->session->create_server($username.'@'.$server_name,$password,'text');
}
else
{
@ -716,7 +717,7 @@
{
$user = $username;
}
$sessionid = $GLOBALS['phpgw']->session->create($user,$password,"text");
$sessionid = $GLOBALS['phpgw']->session->create($user,$password,'text');
$kp3 = $GLOBALS['phpgw']->session->kp3;
$domain = $GLOBALS['phpgw']->session->account_domain;
}

View File

@ -489,7 +489,7 @@ text is a string, it contains the body of the message.
'ctApostrophes' => CreateObject('phpgwapi.xmlrpcval',$ap, 'int'),
'ctQuotes' => CreateObject('phpgwapi.xmlrpcval',$qu, 'int')
),
'struct'
'struct'
));
}