Rollback soap server class to workable state, make login/logout work

This commit is contained in:
Miles Lott 2001-12-10 02:09:17 +00:00
parent 2b1bf39cd3
commit 9f568f8b33
6 changed files with 220 additions and 191 deletions

View File

@ -1,29 +1,11 @@
<?php
// SOAP server class
// SOAP server class
// for example usage, see the test_server.php file.
/* changelog:
2001-07-05
- detection of character encoding in Content-Type header. server
will now call the soap_parser object with the specified encoding
- server will now return the Content-Type header with the sender's encoding type specified
must still learn more bout encoding, and figure out what i have to do to be able to
make sure that my response is *actually* encoded correctly
2001-07-21
- force proper error reporting for windows compatibility
2001-07-27
- get_all_headers() check for windows compatibility
*/
/* $Id$ */
// make errors handle properly in windows
error_reporting(2039);
// for example usage, see the test_server.php file.
class soap_server
{
function soap_server()
function soap_server($data='',$serviceNow=False)
{
// create empty dispatch map
$this->dispatch_map = array();
@ -31,20 +13,23 @@
$this->debug_str = '';
$this->headers = '';
$this->request = '';
$this->xml_encoding = 'UTF-8';
$this->result = 'successful';
$this->fault = false;
$this->fault_code = '';
$this->fault_str = '';
$this->fault_actor = '';
// for logging interop results to db
$this->result = 'successful';
if($serviceNow == 1)
{
$this->service($data);
}
}
// parses request and posts response
function service($data)
{
// $response is a soap_msg object
$response = $this->parse_request($data);
$response = $this->parseRequest($data);
$this->debug("parsed request and got an object of this class '".get_class($response)."'");
$this->debug("server sending...");
// pass along the debug string
@ -65,51 +50,54 @@
}
$header[] = "Server: SOAPx4 Server v0.344359s\r\n";
$header[] = "Connection: Close\r\n";
$header[] = "Content-Type: text/xml; charset=$this->xml_encoding\r\n";
$header[] = "Content-Type: text/xml; charset=UTF-8\r\n";
$header[] = "Content-Length: ".strlen($payload)."\r\n\r\n";
@reset($header);
while(list($null,$hdr) = @each($header))
/* foreach($header as $hdr) */
reset($header);
foreach($header as $hdr)
{
header($hdr);
}
print $payload;
}
function parse_request($data='')
function parseRequest($data="")
{
global $HTTP_SERVER_VARS;
$this->debug('entering parse_request() on '.date('H:i Y-m-d'));
$request_uri = $HTTP_SERVER_VARS['REQUEST_URI'];
$this->debug("entering parseRequest() on ".date("H:i Y-m-d"));
$request_uri = $HTTP_SERVER_VARS["REQUEST_URI"];
$this->debug("request uri: $request_uri");
// get headers
if(function_exists('getallheaders'))
$headers_array = getallheaders();
foreach($headers_array as $k=>$v)
{
$this->headers = getallheaders();
while(list($k,$v) = @each($this->headers))
/* foreach($this->headers as $k=>$v) */
{
$dump .= "$k: $v\r\n";
}
// get SOAPAction header
if($this->headers['SOAPAction'])
{
$this->SOAPAction = str_replace('"','',$this->headers['SOAPAction']);
$this->service = $this->SOAPAction;
}
// get character encoding
if(ereg("=",$this->headers['Content-Type']))
{
$this->xml_encoding = str_replace("\"","",substr(strstr($this->headers["Content-Type"],"="),1));
}
elseif(ereg("^text/xml",$this->headers['Content-Type']))
{
$this->xml_encoding = 'us-ascii';
}
$this->debug("got encoding: $this->xml_encoding");
$dump .= "$k: $v\r\n";
}
$this->request = $dump."\r\n\r\n".$data;
$dump .= "\r\n\r\n".$data;
$this->headers = $headers_array;
$this->request = $dump;
// get SOAPAction header -> methodname
if($headers_array["SOAPAction"])
{
$action = str_replace('"','',$headers_array["SOAPAction"]);
if(ereg("^urn:",$action))
{
$this->service = substr($action,4);
}
elseif(ereg(".php",$action))
{
$this->service = ereg_replace('"|/','',substr(strrchr($action,".php"),4,strlen(strrchr($action,"/"))));
}
$this->debug("got service: $this->service");
}
else
{
// throw a fault if no soapaction
$this->debug("ERROR: no SOAPAction header found");
}
// NOTE:::: throw a fault for no/bad soapaction here?
// parse response, get soap parser obj
$parser = CreateObject('phpgwapi.soap_parser',$data);
// get/set methodname
@ -117,15 +105,29 @@
$this->debug("method name: $this->methodname");
// does method exist?
if(function_exists($this->methodname))
$test = ereg_replace("\.",'_',$this->methodname);
if(function_exists($test))
{
$method = $this->methodname = $test;
$this->debug("method '$this->methodname' exists");
}
else
{
/* phpgroupware customization - createobject based on methodname */
list($app,$class,$method) = explode('.',$this->methodname);
$obj = CreateObject(sprintf('%s.%s',$app,$class));
if(ereg("^service",$app))
{
$args = $class;
$class = 'service';
$app = 'phpgwapi';
$obj = CreateObject(sprintf('%s.%s',$app,$class),$args);
unset($args);
}
else
{
$obj = CreateObject(sprintf('%s.%s',$app,$class));
}
$this->debug('app: ' . $app . ', class: ' . $class . ', method: ' . $method);
/*
// "method not found" fault here
$this->debug("method '$obj->method' not found!");
@ -140,16 +142,16 @@
{
// parser debug
$this->debug($parser->debug_str);
$this->result = 'fault: error in msg parsing or eval';
$this->result = "fault: error in msg parsing or eval";
$this->make_fault("Server","error in msg parsing or eval:\n".$parser->get_response());
// return soapresp
return $this->fault();
// else successfully parsed request into soapval object
// else successfully parsed request into soapval object
}
else
{
// get eval_str
$this->debug('calling parser->get_response()');
$this->debug("calling parser->get_response()");
// evaluate it, getting back a soapval object
if(!$request_val = $parser->get_response())
{
@ -157,7 +159,7 @@
}
// parser debug
$this->debug($parser->debug_str);
if(get_class($request_val) == 'soapval')
if(get_class($request_val) == "soapval")
{
if (is_object($obj))
{
@ -191,40 +193,47 @@
{
if (is_object($obj))
{
$code = "\$method_response = call_user_method(\$method,\$obj,";
$this->debug("about to call method '$class -> $method'");
$code = "\$method_response = call_user_method($method,$obj,";
$this->debug("about to call object method '$class\-\>$method' with args");
}
else
{
$code = "\$method_response = call_user_func(\$this->methodname,";
$this->debug("about to call method '$this->methodname'");
$code = '$method_response = ' . $this->methodname . "('";
$args = implode("','",$request_data['return']);
$this->debug("about to call method '$this->methodname' with args: $args");
}
/* call method with parameters */
$this->debug("about to call method '$class -> $method'");
$code .= implode("','",$request_data['return']);
/*
while(list($x,$y) = each($request_data))
{
$code .= "\$request_data[$x]" . ',';
}
$code = substr($code,0,-1) .');';
$code = substr($code,0,-1) .");";
*/
$code .= "');";
$this->debug('CODE: ' . $code);
if(eval($code))
{
if (is_object($obj))
{
$this->make_fault("Server","Method call failed for '$obj->method' with params: ".join(",",$request_data));
$this->make_fault("Server","Object method call failed for '$class\-\>$method' with params: ".join(',',$request_data));
}
else
{
$this->make_fault("Server","Method call failed for '$this->methodname' with params: ".join(",",$request_data));
$this->make_fault("Server","Method call failed for '$this->methodname' with params: ".join(',',$request_data));
}
return $this->fault();
}
$this->debug('Response: ' . $method_response);
// _debug_array($method_response);
}
else
{
/* call method w/ no parameters */
if (is_object($obj))
{
$this->debug("about to call method '$obj->method'");
$this->debug("about to call object method '$obj\-\>$method'");
if(!$method_response = call_user_method($method,$obj))
{
$this->make_fault("Server","Method call failed for '$obj->method' with no params");
@ -241,7 +250,7 @@
}
}
}
/* no return values */
/* no return values */
}
else
{
@ -253,48 +262,43 @@
{
$code .= "\$request_data[$x]" . ',';
}
$code = substr($code,0,-1) .');';
$this->debug("about to call method '$obj->method'");
$code = substr($code,0,-1) .");";
$this->debug("about to call object method '$obj\-\>$method'");
eval($code);
}
else
{
/* call method w/ no parameters */
$this->debug("about to call method '$obj->method'");
call_user_method($method,$obj);
if(is_object($obj))
{
$this->debug("about to call object method '$obj\-\>$method'");
call_user_method($method,$obj);
}
else
{
$this->debug("about to call method '$method'");
call_user_func($method);
}
}
}
/* return fault */
if(get_class($method_response) == 'soapmsg')
/* create soap_val object w/ return values from method, use method signature to determine type */
if(get_class($method_response) != 'soapval')
{
if(eregi('fault',$method_response->value->name))
{
$this->fault = True;
}
$return_msg = $method_response;
$return_val = CreateObject('phpgwapi.soapval',$method,$this->return_type,$method_response);
}
else
{
/* return soapval object */
if(get_class($method_response) == 'soapval')
{
$return_val = $method_response;
/* create soap_val object w/ return values from method, use method signature to determine type */
}
else
{
$return_val = CreateObject('phpgwapi.soapval',$method,$this->return_type,$method_response);
}
$this->debug($return_val->debug_str);
/* response object is a soap_msg object */
$return_msg = CreateObject('phpgwapi.soapmsg',$method.'Response',array($return_val),$this->service);
$return_val = $method_response;
}
$this->debug($return_val->debug_str);
/* response object is a soap_msg object */
$return_msg = CreateObject('phpgwapi.soapmsg',$method.'Response',array($return_val),$this->service);
if($this->debug_flag)
{
$return_msg->debug_flag = true;
}
$this->result = 'successful';
$this->result = "successful";
return $return_msg;
}
else
@ -312,7 +316,7 @@
$this->debug("ERROR: parser did not return soapval object: $request_val ".get_class($request_val));
$this->result = "fault: parser did not return soapval object: $request_val";
// return fault
$this->make_fault('Server',"parser did not return soapval object: $request_val");
$this->make_fault("Server","parser did not return soapval object: $request_val");
return $this->fault();
}
}
@ -321,7 +325,7 @@
function verify_method($request)
{
//return true;
$this->debug('entered verify_method() w/ request name: '.$request->name);
$this->debug("entered verify_method() w/ request name: ".$request->name);
$params = $request->value;
// if there are input parameters required...
if($sig = $this->dispatch_map[$this->methodname]["in"])
@ -329,10 +333,8 @@
$this->input_value = count($sig);
if(is_array($params))
{
$this->debug('entered verify_method() with '.count($params).' parameters');
@reset($params);
while(list($null,$v) = @each($params))
/* foreach($params as $v) */
$this->debug("entered verify_method() with ".count($params)." parameters");
foreach($params as $v)
{
$this->debug("param '$v->name' of type '$v->type'");
}
@ -341,9 +343,7 @@
{
$this->debug("got correct number of parameters: ".count($sig));
// make array of param types
@reset($params);
while(list($null,$param) = @each($params))
/* foreach($params as $param) */
foreach($params as $param)
{
$p[] = strtolower($param->type);
}
@ -354,26 +354,26 @@
if(strtolower($sig[$i]) != strtolower($p[$i]))
{
$this->debug("mismatched parameter types: $sig[$i] != $p[$i]");
$this->make_fault('Client',"soap request contained mismatching parameters of name $v->name had type $p[$i], which did not match signature's type: $sig[$i]");
$this->make_fault("Client","soap request contained mismatching parameters of name $v->name had type $p[$i], which did not match signature's type: $sig[$i]");
return false;
}
$this->debug("parameter type match: $sig[$i] = $p[$i]");
}
return true;
// oops, wrong number of paramss
// oops, wrong number of paramss
}
else
{
$this->debug('oops, wrong number of parameter!');
$this->make_fault('Client',"soap request contained incorrect number of parameters. method '$this->methodname' required ".count($sig)." and request provided ".count($params));
$this->debug("oops, wrong number of parameter!");
$this->make_fault("Client","soap request contained incorrect number of parameters. method '$this->methodname' required ".count($sig)." and request provided ".count($params));
return false;
}
// oops, no params...
// oops, no params...
}
else
{
$this->debug("oops, no parameters sent! Method '$this->methodname' requires ".count($sig)." input parameters!");
$this->make_fault('Client',"soap request contained incorrect number of parameters. method '$this->methodname' requires ".count($sig)." parameters, and request provided none");
$this->make_fault("Client","soap request contained incorrect number of parameters. method '$this->methodname' requires ".count($sig)." parameters, and request provided none");
return false;
}
// no params
@ -394,9 +394,9 @@
// get string return type from dispatch map
function get_return_type()
{
if(count($this->dispatch_map[$this->methodname]['out']) >= 1)
if(count($this->dispatch_map[$this->methodname]["out"]) >= 1)
{
$type = array_shift($this->dispatch_map[$this->methodname]['out']);
$type = array_shift($this->dispatch_map[$this->methodname]["out"]);
$this->debug("got return type from dispatch map: '$type'");
return $type;
}
@ -415,30 +415,30 @@
// add a method to the dispatch map
function add_to_map($methodname,$in,$out)
{
$this->dispatch_map[$methodname]['in'] = $in;
$this->dispatch_map[$methodname]['out'] = $out;
$this->dispatch_map[$methodname]["in"] = $in;
$this->dispatch_map[$methodname]["out"] = $out;
}
// set up a fault
function fault()
{
return CreateObject('phpgwapi.soapmsg',
'Fault',
array(
'faultcode' => $this->fault_code,
'faultstring' => $this->fault_str,
'faultactor' => $this->fault_actor,
'faultdetail' => $this->fault_detail.$this->debug_str
),
'http://schemas.xmlsoap.org/soap/envelope/'
);
}
function make_fault($fault_code,$fault_string)
{
$this->fault_code = $fault_code;
$this->fault_str = $fault_string;
$this->fault = true;
}
"Fault",
array(
"faultcode" => $this->fault_code,
"faultstring" => $this->fault_str,
"faultactor" => $this->fault_actor,
"faultdetail" => $this->fault_detail.$this->debug_str
),
"http://schemas.xmlphpgwapi.org/soap/envelope/"
);
}
function make_fault($fault_code,$fault_string)
{
$this->fault_code = $fault_code;
$this->fault_str = $fault_string;
$this->fault = true;
}
}
?>

View File

@ -40,13 +40,13 @@
function soapmsg($method,$params,$method_namespace='http://testuri.org',$new_namespaces=False)
{
// globalize method namespace
global $methodNamespace;
$methodNamespace = $method_namespace;
$GLOBALS['methodNamespace'] = $method_namespace;
$namespaces = $GLOBALS['namespaces'];
// make method struct
$this->value = CreateObject('phpgwapi.soapval',$method,"struct",$params,$method_namespace);
if(is_array($new_namespaces))
{
global $namespaces;
$i = count($namespaces);
@reset($new_namespaces);
while(list($null,$v) = @each($new_namespaces))
@ -63,7 +63,7 @@
function make_envelope($payload)
{
global $namespaces;
$namespaces = $GLOBALS['namespaces'];
@reset($namespaces);
while(list($k,$v) = @each($namespaces))
/* foreach($namespaces as $k => $v) */

View File

@ -39,8 +39,6 @@
// function soapval($name='',$type=False,$value=-1,$namespace=False,$type_namespace=False)
function soapval($name='',$type=False,$value=0,$namespace=False,$type_namespace=False)
{
global $soapTypes, $typemap, $namespaces, $methodNamespace;
// detect type if not passed
if(!$type)
{
@ -74,7 +72,7 @@
$type = 'int';
}
$this->soapTypes = $soapTypes;
$this->soapTypes = $GLOBALS['soapTypes'];
$this->name = $name;
$this->value = '';
$this->type = $type;
@ -88,11 +86,11 @@
if($namespace)
{
$this->namespace = $namespace;
if(!isset($namespaces[$namespace]))
if(!isset($GLOBALS['namespaces'][$namespace]))
{
$namespaces[$namespace] = "ns".(count($namespaces)+1);
$GLOBALS['namespaces'][$namespace] = "ns".(count($GLOBALS['namespaces'])+1);
}
$this->prefix = $namespaces[$namespace];
$this->prefix = $GLOBALS['namespaces'][$namespace];
}
// get type prefix
@ -103,11 +101,11 @@
}
elseif($type_namespace)
{
if(!isset($namespaces[$type_namespace]))
if(!isset($GLOBALS['namespaces'][$type_namespace]))
{
$namespaces[$type_namespace] = 'ns'.(count($namespaces)+1);
$GLOBALS['namespaces'][$type_namespace] = 'ns'.(count($GLOBALS['namespaces'])+1);
}
$this->type_prefix = $namespaces[$type_namespace];
$this->type_prefix = $GLOBALS['namespaces'][$type_namespace];
}
// if type namespace was not explicitly passed, and we're not in a method struct:
@ -117,7 +115,7 @@
if(!$this->type_prefix = $this->verify_type($type))
{
// else default to method namespace
$this->type_prefix = $namespaces[$methodNamespace];
$this->type_prefix = $GLOBALS['namespaces'][$GLOBALS['methodNamespace']];
}
}
@ -141,7 +139,7 @@
}
else
{
//if($namespace == $methodNamespace){
//if($namespace == $GLOBALS['methodNamespace']){
$this->type_code = 3;
$this->addStruct($value);
//}
@ -433,16 +431,16 @@
{
if ($type)
{
// global $namespaces,$soapTypes,$typemap;
global $namespaces,$typemap;
// global $GLOBALS['namespaces'],$GLOBALS['soapTypes'],$GLOBALS['typemap'];
// global $GLOBALS['namespaces'],$GLOBALS['typemap'];
@reset($typemap);
while(list($namespace,$types) = @each($typemap))
/* foreach($typemap as $namespace => $types) */
@reset($GLOBALS['typemap']);
while(list($namespace,$types) = @each($GLOBALS['typemap']))
/* foreach($GLOBALS['typemap'] as $namespace => $types) */
{
if(in_array($type,$types))
{
return $namespaces[$namespace];
return $GLOBALS['namespaces'][$namespace];
}
}
}

View File

@ -103,8 +103,7 @@
{
$rtrn = array(CreateObject('phpgwapi.soapval','GOAWAY','string',$username));
}
$r = CreateObject('phpgwapi.soapmsg','system_loginResponse',$rtrn);
return $r;
return $rtrn;
}
function system_logout($m1,$m2)
@ -112,13 +111,12 @@
$sessionid = $m1;
$kp3 = $m2;
$username = $GLOBALS['phpgw']->session->account_lid;
$later = $GLOBALS['phpgw']->session->destroy();
$later = $GLOBALS['phpgw']->session->destroy($sessionid,$kp3);
if($later)
{
$rtrn = array(
CreateObject('phpgwapi.soapval','GOODBYE','string',$username)
CreateObject('phpgwapi.soapval','GOODBYE','string','XOXO')
);
}
else
@ -127,7 +125,31 @@
CreateObject('phpgwapi.soapval','OOPS','string','WHAT?')
);
}
$r = CreateObject('phpgwapi.soapmsg','system_logoutResponse',$rtrn);
return $r;
return $rtrn;
}
/*
function system_listApps()
{
$GLOBALS['phpgw']->db->query("SELECT * FROM phpgw_applications WHERE app_enabled<3",__LINE__,__FILE__);
$apps = array();
if($GLOBALS['phpgw']->db->num_rows())
{
while ($GLOBALS['phpgw']->db->next_record())
{
$name = $GLOBALS['phpgw']->db->f('app_name');
$title = $GLOBALS['phpgw']->db->f('app_title');
$status = $GLOBALS['phpgw']->db->f('app_enabled');
$version= $GLOBALS['phpgw']->db->f('app_version');
$apps[$name] = array(
CreateObject('phpgwapi.soapval','title','string',$title),
CreateObject('phpgwapi.soapval','name','string',$name),
CreateObject('phpgwapi.soapval','status','string',$status),
CreateObject('phpgwapi.soapval','version','string',$version)
);
}
}
return $apps;
}
*/
?>

View File

@ -19,18 +19,17 @@
/* $Id$ */
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'hello',
array('string'),
array('string')
);
function hello($serverid)
{
global $phpgw_info;
return CreateObject('soap.soapval','return','string',$phpgw_info['server']['site_title']);
return CreateObject('soap.soapval','return','string',$GLOBALS['phpgw_info']['server']['site_title']);
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoString',
array('string'),
array('string')
@ -40,7 +39,7 @@
return CreateObject('soap.soapval','return','string',$inputString);
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoStringArray',
array('array'),
array('array')
@ -50,7 +49,7 @@
return $inputStringArray;
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoInteger',
array('int'),
array('int')
@ -60,7 +59,7 @@
return $inputInteger;
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoIntegerArray',
array('array'),
array('array')
@ -70,7 +69,7 @@
return $inputIntegerArray;
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoFloat',
array('float'),
array('float')
@ -80,7 +79,7 @@
return $inputFloat;
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoFloatArray',
array('array'),
array('array')
@ -90,7 +89,7 @@
return $inputFloatArray;
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoStruct',
array('SOAPStruct'),
array('SOAPStruct')
@ -100,7 +99,7 @@
return $inputStruct;
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoStructArray',
array('array'),
array('array')
@ -110,7 +109,7 @@
return $inputStructArray;
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoVoid',
array(),
array()
@ -119,7 +118,7 @@
{
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoBase64',
array('base64'),
array('base64')
@ -129,7 +128,7 @@
return base64_encode(base64_decode($b_encoded));
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'echoDate',
array('timeInstant'),
array('timeInstant')
@ -139,13 +138,13 @@
return $timeInstant;
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'system_auth',
array('string','string','string'),
array('array')
);
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'system_auth_verify',
array('string','string','string'),
array('array')

View File

@ -21,9 +21,9 @@
include('./header.inc.php');
$server = CreateObject('phpgwapi.soap_server');
/* _debug_array($server);exit; */
//include(PHPGW_API_INC . '/soaplib.soapinterop.php');
$GLOBALS['server'] = CreateObject('phpgwapi.soap_server');
/* _debug_array($GLOBALS['server']);exit; */
/* include(PHPGW_API_INC . '/soaplib.soapinterop.php'); */
$headers = getallheaders();
@ -37,23 +37,33 @@
if($GLOBALS['phpgw']->session->verify($sessionid,$kp3))
{
$server->authed = True;
$GLOBALS['server']->authed = True;
}
elseif($GLOBALS['phpgw']->session->verify_server($sessionid,$kp3))
{
$server->authed = True;
$GLOBALS['server']->authed = True;
}
}
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'system_login',
array('string','string','string'),
array('array')
array('soapstruct'),
array('soapstruct')
);
$server->add_to_map(
$GLOBALS['server']->add_to_map(
'system_logout',
array('string','string'),
array('array')
array('soapstruct'),
array('soapstruct')
);
$server->service($HTTP_RAW_POST_DATA);
if(function_exists('system_listapps'))
{
$GLOBALS['server']->add_to_map(
'system_listApps',
array(),
array('soapstruct')
);
}
$GLOBALS['server']->service($HTTP_RAW_POST_DATA);
?>