phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] api/interface class.interface_soap.php, 1.1.2.1, 1.1.


From: Dan Kuykendall <address@hidden>
Subject: [Phpgroupware-cvs] api/interface class.interface_soap.php, 1.1.2.1, 1.1.2.2 class.interface_xmlrpc.php, 1.1.2.9, 1.1.2.10
Date: Sat, 08 Nov 2003 01:38:44 +0000

Update of /cvsroot/phpgroupware/api/interface
In directory subversions:/tmp/cvs-serv12187/interface

Modified Files:
      Tag: proposal-branch
        class.interface_soap.php class.interface_xmlrpc.php 
Log Message:
wrote my own soap server

Index: class.interface_xmlrpc.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/interface/Attic/class.interface_xmlrpc.php,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -C2 -d -r1.1.2.9 -r1.1.2.10
*** class.interface_xmlrpc.php  3 Nov 2003 17:31:22 -0000       1.1.2.9
--- class.interface_xmlrpc.php  8 Nov 2003 01:38:42 -0000       1.1.2.10
***************
*** 70,73 ****
--- 70,74 ----
                        $newsid = $GLOBALS['phpgw']->session->sid();
                        $result = "<?xml 
version=\"1.0\"?>\n<methodResponse>\n<params>\n<param>\n<value>\n<base64>".base64_encode($newsid)."</base64>\n</value>\n</param>\n</params>\n</methodResponse>";
+                       $GLOBALS['phpgw']->session->save_data();
                        $this->output($result);
                        exit;

Index: class.interface_soap.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/interface/Attic/class.interface_soap.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** class.interface_soap.php    7 Nov 2003 09:05:43 -0000       1.1.2.1
--- class.interface_soap.php    8 Nov 2003 01:38:42 -0000       1.1.2.2
***************
*** 28,31 ****
--- 28,32 ----
        {
                var $methodName;
+               var $mainnodename;
                var $op;
                var $inputs;
***************
*** 68,75 ****
                function good_login()
                {
                        $newsid = $GLOBALS['phpgw']->session->sid();
!           $result = $this->soapserver->serialize_val($newsid, 'sid');
!           //$result = 
$this->soapserver->serialize_val(base64_encode($newsid), 'sid');
!                       /*$result = "<?xml 
version=\"1.0\"?>\n<methodResponse>\n<params>\n<param>\n<value>\n<base64>".base64_encode($newsid)."</base64>\n</value>\n</param>\n</params>\n</methodResponse>";*/
                        $this->output($result);
                        exit;
--- 69,89 ----
                function good_login()
                {
+                       //$newsid = 
base64_encode($GLOBALS['phpgw']->session->sid());
                        $newsid = $GLOBALS['phpgw']->session->sid();
!                       $result = "<?xml version=\"1.0\"?>\n<SOAP-ENV:Body\n";
!                       foreach($this->xml_vals[0]['attributes'] as $key=>$val)
!                       {
!                               $result .= "$key=\"$val\"\n";                   
        
!                       }
!                       $result .= ">\n";
!                       $result .= "<".$this->mainnodename."Response>\n";
! 
!                       $result .= "<sid 
xsi:type=\"xsd:string\">$newsid</sid>\n";
!                       
!                       $result .= "</".$this->mainnodename."Response>\n";
!                       $result .= "</SOAP-ENV:Body>";
! //html_print_r($GLOBALS['phpgw']);
! //exit;
!                       $GLOBALS['phpgw']->session->save_data();
                        $this->output($result);
                        exit;
***************
*** 88,92 ****
                                $msg = 'Username and/or password missing.';
                        }
!                       $this->soap_fault($msg);
                }
  
--- 102,106 ----
                                $msg = 'Username and/or password missing.';
                        }
!                       $this->soap_fault($code, $msg);
                }
  
***************
*** 95,110 ****
                }
  
-               function soap_fault($msg)
-               {
-                       $this->soapserver->result = 'fault: '.$msg.' 
'.$this->methodName;
-                       $this->soapserver->fault('Server',"$msg 
'".$this->methodName."'");
-                       return $this->soapserver->fault->serialize();
-               }
- 
                function access_denied($methodname, $inputs = '')
                {
!                       $this->soapserver->result = 'fault: Access denied to 
'.$this->methodName;
!                       $this->soapserver->fault('Server',"Access denied to 
method '".$this->methodName."'");
!                       return $this->soapserver->fault->serialize();
                }
                
--- 109,115 ----
                }
  
                function access_denied($methodname, $inputs = '')
                {
!                       $this->soap_fault('99', 'Access denied to 
'.$methodname);
                }
                
***************
*** 125,137 ****
                        $api_data = xml2var($xml_result);
  
                        if(empty($this->method_result) && 
isset($api_data['APP']))
                        {
                                $this->method_result = $api_data['APP'];
                        }
!           $response_packet = 
$this->soapserver->handle_result($this->method_result);
!           //$response_packet = 
$this->soapserver->serialize_val($this->method_result);
! //echo '<hr><hr>';
! //html_print_r($this->method_result);
! //exit;
                        $this->output($response_packet);
                }
--- 130,168 ----
                        $api_data = xml2var($xml_result);
  
+                       switch ($this->methodName)
+                       {
+                               case 'system.listMethods':
+                                       $this->system_listMethods();
+                                       return;
+                               case 'system.methodSignature':
+                                       $this->system_methodSignature();
+                                       return;
+                               case 'system.methodHelp':
+                                       $this->system_methodHelp();
+                                       return;                                 
+                       }
+                       
                        if(empty($this->method_result) && 
isset($api_data['APP']))
                        {
                                $this->method_result = $api_data['APP'];
                        }
!                       
!                       /* Constructing the XML doc */
!                       $response_packet = "<?xml 
version=\"1.0\"?>\n<SOAP-ENV:Body\n";
!                       foreach($this->xml_vals[0]['attributes'] as $key=>$val)
!                       {
!                               $response_packet .= "$key=\"$val\"\n";          
                
!                       }
!                       $response_packet .= ">\n";
!                       $response_packet .= 
"<".$this->mainnodename."Response>\n";
! 
!                       if(!empty($this->method_result))
!                       {
!                               $response_packet .=  
$this->add_vars($this->method_result);
!                       }
!                       
!                       $response_packet .= 
"</".$this->mainnodename."Response>\n";
!                       $response_packet .= "</SOAP-ENV:Body>";
!                       
                        $this->output($response_packet);
                }
***************
*** 144,158 ****
                                exit;
                        }
!                       
                        if(!strstr($GLOBALS['HTTP_RAW_POST_DATA'], '<?xml'))
                        {
                                $GLOBALS['HTTP_RAW_POST_DATA'] = "<?xml 
version=\"1.0\"?>\n".$GLOBALS['HTTP_RAW_POST_DATA'];
                        }
  
!                       $this->soapserver = createobject('api_soap_server');
!                       
$this->soapserver->service($GLOBALS['HTTP_RAW_POST_DATA']);
  
!                       $this->methodName = $this->soapserver->methodname;
!                       $this->soapserver->methodname = str_replace('.', '_', 
$this->soapserver->methodname);
                        switch ($this->methodName)
                        {
--- 175,221 ----
                                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;
+                       $soap_input = '';
+                       for ($i=0; $i < $num; $i++)
+                       {
+                               if($hit_start)
+                               {
+                                       $soap_input .= $tmp[$i]."\n";
+                               }
+                               elseif(stristr($tmp[$i], '<?xml'))
+                               {
+                                       $hit_start = True;
+                                       $soap_input .= $tmp[$i]."\n";
+                               }
+                       }
  
!                       $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, $soap_input, $xml_vals, 
$xml_index);
!                       xml_parser_free($parser);
!                       $this->xml_index = $xml_index;
!                       $this->xml_vals = $xml_vals;
!                       unset($xml_index, $xml_vals);
  
! //html_print_r($this->xml_index);
! //html_print_r($this->xml_vals);
! //exit;
!                       
if(!isset($this->xml_vals[$this->xml_index['SOAP-ENV:Body'][0]+1]['tag']))
!                       {
!                               $GLOBALS['phpgw']->finish(False);
!                               $this->soap_fault('1', 'Invalid soap packet. 
Main body tag missing.');
!                       }
!                       $this->mainnodename = 
$this->xml_vals[$this->xml_index['SOAP-ENV:Body'][0]+1]['tag'];
!                       $this->mainnodelevel = 
$this->xml_vals[$this->xml_index['SOAP-ENV:Body'][0]+1]['level'];
!                       $tmpmeth = explode(':', $this->mainnodename);
!                       $this->methodName = $tmpmeth[1];
                        switch ($this->methodName)
                        {
***************
*** 173,192 ****
                        }
  
!                       $this->inputs = $this->soapserver->inputs;
!                       if(isset($this->inputs['sid']))
                        {
!                               $GLOBALS['HTTP_GET_VARS']['sid'] = 
$this->inputs['sid'];
!                               unset($this->inputs['sid']);
!                       }                       
!                       if(isset($this->inputs['phpgw_user']))
                        {
!                               $GLOBALS['HTTP_GET_VARS']['phpgw_user'] = 
$this->inputs['phpgw_user'];
!                               unset($this->inputs['phpgw_user']);
!                       }                       
!                       if(isset($this->inputs['phpgw_pass']))
                        {
!                               $GLOBALS['HTTP_GET_VARS']['phpgw_pass'] = 
$this->inputs['phpgw_pass'];
!                               unset($this->inputs['phpgw_pass']);
!                       }                       
                }
        }
--- 236,553 ----
                        }
  
!                       
if($this->xml_vals[$this->xml_index['SOAP-ENV:Body'][0]+2]['tag'] != 
$this->mainnodename && 
$this->xml_vals[$this->xml_index['SOAP-ENV:Body'][0]+2]['tag'] != 
'SOAP-ENV:Body')
                        {
!                               $this->i = 
$this->xml_index['SOAP-ENV:Body'][0]+2;
!                               while($this->xml_vals[$this->i]['tag'] != 
$this->mainnodename)
!                               {
!                                       $additional_inputs = 
$this->parse_params();
!                                       $this->inputs = 
array_merge($this->inputs, $additional_inputs);
!                               }
!                       }
! //echo 'inputs<br>';
! //html_print_r($this->inputs);
! //exit;
!               }
! 
!               function parse_params()
!               {
!                       switch($this->xml_vals[$this->i]['type'])
                        {
!                               case 'complete':
!                                       
switch($this->xml_vals[$this->i]['attributes']['xsi:type'])
!                                       {
!                                               case 'SOAP-ENC:base64':
!                                                       $value = 
base64_decode($this->xml_vals[$this->i]['value']);
!                                                       break;
!                                               case 'xsd:boolean':
!                                                       $value = 
$this->xml_vals[$this->i]['value'];
!                                                       
settype($value,'boolean');
!                                                       break;
!                                               case 'xsd:int':
!                                               case 'xsd:i4':
!                                               case 'xsd:double':
!                                               case 'dateTime.iso8601':
!                                               case 'xsd:string':
!                                               default:
!                                                       $name = 
$this->xml_vals[$this->i]['tag'];
!                                                       $value = 
$this->xml_vals[$this->i]['value'];
!                                                       break;
!                                       }
!                                       $this->i++;
! //echo '$name: '.$name.'<br>';
! //echo '$value: '.$value.'<br>';
!                                       if($this->op == 'api.base.login')
!                                       {
!                                               if($name == 'phpgw_user')
!                                               {
!                                                       
$GLOBALS['HTTP_GET_VARS']['phpgw_user'] = $value;
!                                               }
!                                               elseif($name == 'phpgw_pass')
!                                               {
!                                                       
$GLOBALS['HTTP_GET_VARS']['phpgw_pass'] = $value;
!                                               }
!                                               return;
!                                       }
!                                       elseif($name == 'sid')
!                                       {
!                                               
$GLOBALS['HTTP_GET_VARS']['sid'] = $value;
!                                               return;
!                                       }
!                                       else
!                                       {
!                                               if(isset($name))
!                                               {
!                                                       return 
array($name=>$value);
!                                               }
!                                               else
!                                               {
!                                                       return $value;
!                                               }
!                                       }
!                                       break;
!                               case 'open':
!                                       switch 
($this->xml_vals[$this->i]['attributes']['xsi:type'])
!                                       {
!                                               case 'SOAP-ENC:Array':
!                                                       $name = 
$this->xml_vals[$this->i]['tag'];
!                                                       $this->i++;
!                                                       
while($this->xml_vals[$this->i]['type'] != 'close')
!                                                       {
!                                                               $tmp = 
$this->parse_params();
!                                                               if(isset($tmp))
!                                                               {
!                                                                       
if(is_array($tmp))
!                                                                       {
!                                                                               
$result[] = $tmp[key($tmp)];
!                                                                       }
!                                                                       else
!                                                                       {
!                                                                               
$result[] = $tmp;
!                                                                       }
!                                                               }
!                                                       }
!                                                       $this->i++;
!                                                       return 
array($name=>$result);
!                                                       break;
!                                               default:
!                                                       $name = 
$this->xml_vals[$this->i]['tag'];
!                                                       $this->i++;
!                                                       
while($this->xml_vals[$this->i]['type'] != 'close')
!                                                       {
!                                                               $tmp = 
$this->parse_params();
!                                                               if(isset($tmp) 
&& is_array($tmp))
!                                                               {
!                                                                       
if(key($tmp) !==0 && key($tmp) != 'soapVal')
!                                                                       {
!                                                                               
$result[key($tmp)] = $tmp[key($tmp)];
!                                                                       }
!                                                                       else
!                                                                       {
!                                                                               
$result[] = $tmp[key($tmp)];
!                                                                       }
!                                                               }
!                                                       }
!                                                       $this->i++;
!                                                       return 
array($name=>$result);
!                                       }
!                                       break;
!                               case 'close':
!                                       return;
!                                       break;
!                       }
!               }
! 
!               function add_vars($params, $name='soapVal')
!               {
!                       if(!is_array($params))
                        {
!                               $result =  
$this->add_params_type_handler($params, $name)."\n";
!                       }
!                       else
!                       {
!                               $result = "<$name>\n";
!                               foreach($params as $key=>$val)                  
        
!                               {
!                                       if(is_array($val))
!                                       {
!                                               $result .= 
$this->add_vars($val);
!                                       }
!                                       else
!                                       {
!                                               $result .= 
$this->add_params_type_handler($val,$key)."\n";
!                                       }
!                               }
!                               $result .= "</$name>\n";
!                       }
!                       /* Im not clear why its double struct'ing, but it is 
and this is how I fixed it for now /*
!                       /* If you dont like this hack, fix it.  Dan*/
!                       //$result = str_replace ("<soapVal>\n<soapVal>\n", 
"<soapVal>\n", $result); 
!                       //$result = str_replace ("</soapVal>\n</soapVal>\n", 
"</soapVal>\n", $result); 
!                       return $result;
                }
+ 
+               function add_params_type_handler($value, $name='soapVal')
+               {
+                       switch(gettype($param))
+                       {
+                               case 'boolean':
+                                       return "<$name 
xsi:type=\"xsd:boolean\">$value</$name>";
+                                       break;
+                               case 'double':
+                                       return "<$name 
xsi:type=\"xsd:double\">$value</$name>";
+                                       break;
+                               case 'integer':
+                                       return "<$name 
xsi:type=\"xsd:int\">$value</$name>";
+                                       break;
+                               case 'array':
+                                       //need to handle this
+                                       break;
+                               default:
+                                       return "<$name 
xsi:type=\"xsd:string\">$value</$name>";
+                       }
+               }
+ 
+               function system_listMethods()
+               {
+                       $GLOBALS['phpgw']->load_docs();
+                       foreach($GLOBALS['docs'] as $appname=>$app_data)
+                       {
+                               foreach($app_data['classes'] as 
$class=>$class_data)
+                               {
+                                       $pos       = strpos($class,'_');
+                                       $classname = substr($class,($pos + 1));
+                                       
+                                       if(is_array($class_data['functions']))
+                                       {
+                                               
foreach($class_data['functions'] as $function=>$function_data)
+                                               {
+                                                       $method = 
$appname.'.'.$classname.'.'.$function;
+                                                       
if($GLOBALS['phpgw']->acl->check($method, 1) 
+                                                          || $method == 
'api.base.login'
+                                                          || $method == 
'api.base.logout'
+                                                        || $method == 
'api.base.about'
+                                                       )
+                                                       {
+                                                               
$allow_methods[$method] = $function_data;
+                                                       }
+                                               }
+                                       }               
+                               }
+                       }
+                       if(is_array($allow_methods))
+                       {
+                               /* I dont think this follows the standard, but 
I need to find some good examples of how it SHOULD look. Dan */
+                               $result = "<?xml version=\"1.0\" 
?>\n<methodResponse>\n<params>\n<param>\n<value>\n<array>\n<data>\n";
+                               foreach($allow_methods as 
$methodname=>$methodname_data)
+                               {
+                                       if($methodname_data['type'] == 'public')
+                                       {
+                                               $result .= 
"<value><string>$methodname</string></value>\n";
+                                       }
+                               }
+                               $result .= 
"</data>\n</array>\n</value>\n</param>\n</params>\n</methodResponse>";
+                       }
+                       $this->output($result);
+                       exit;
+               }
+ 
+               function system_methodSignature()
+               {
+                       
if(isset($this->xml_vals[$this->xml_index['string'][0]]['value']))
+                       {
+                               $methodname = 
$this->xml_vals[$this->xml_index['string'][0]]['value'];
+                       }
+                       
elseif(isset($this->xml_vals[$this->xml_index['value'][0]]['value']))
+                       {
+                               $methodname = 
$this->xml_vals[$this->xml_index['value'][0]]['value'];
+                       }
+                       else
+                       {
+                               $this->soap_fault('1', 'Invalid request. 
methodName missing.');
+                       }
+ 
+                       $GLOBALS['phpgw']->load_docs();
+                       list($app,$class,$func) = explode('.',$methodname);
+ 
+                       
if(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func])
 && $GLOBALS['phpgw']->acl->check($methodname, 1))
+                       {
+                               $result = "<?xml 
version=\"1.0\"?>\n<methodResponse>\n";
+                               
if(is_array($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]['params']))
+                               {
+                                       $result .= 
"<params>\n<param>\n<value><array>\n<data>\n<value><array>\n<data>\n";
+                                       
foreach($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]['params']
 as $paramname=>$paramname_data)
+                                       {
+                                               $result .= 
"<value><string>".$paramname_data['type']."</string></value>\n";
+                                       }
+                                       $result .= 
"</data>\n</array></value>\n</data>\n</array></value>\n</param>\n</params>\n";
+                               }
+                               $result .= "</methodResponse>\n";
+                               $this->output($result);
+                               exit;
+                       }
+                       
elseif(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func])
 && !$GLOBALS['phpgw']->acl->check($methodname, 1))
+                       {
+                               $this->soap_fault('1', 'Access Denied. Your 
account does not have rights to this function.');
+                       }
+                       
elseif(!isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]))
+                       {
+                               $this->soap_fault('1', 'No such method 
exists.');
+                       }
+               }
+ 
+               function system_methodHelp()
+               {
+                       
if(isset($this->xml_vals[$this->xml_index['string'][0]]['value']))
+                       {
+                               $methodname = 
$this->xml_vals[$this->xml_index['string'][0]]['value'];
+                       }
+                       
elseif(isset($this->xml_vals[$this->xml_index['value'][0]]['value']))
+                       {
+                               $methodname = 
$this->xml_vals[$this->xml_index['value'][0]]['value'];
+                       }
+                       else
+                       {
+                               $this->soap_fault('1', 'Invalid request. 
methodName missing.');
+                       }
+ 
+                       $GLOBALS['phpgw']->load_docs();
+                       list($app,$class,$func) = explode('.',$methodname);
+ 
+                       
if(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func])
 && $GLOBALS['phpgw']->acl->check($methodname, 1))
+                       {
+                               $result = "<?xml 
version=\"1.0\"?>\n<methodResponse>\n";
+                               
if(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]['abstract']))
+                               {
+                                       $result .= "<params>\n<param>\n";
+                                       $result .= 
"<value><string>".$GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]['abstract']."</string></value>\n";
+                                       $result .= "</param>\n</params>\n";
+                               }
+                               $result .= "</methodResponse>\n";
+                               $this->output($result);
+                               exit;
+                       }
+                       
elseif(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func])
 && !$GLOBALS['phpgw']->acl->check($methodname, 1))
+                       {
+                               $this->soap_fault('1', 'Access Denied. Your 
account does not have rights to this function.');
+                       }
+                       
elseif(!isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]))
+                       {
+                               $this->soap_fault('1', 'No such method 
exists.');
+                       }
+               }
+               
+               function soap_fault($code, $text)
+               {
+                       $error_result = "<?xml version=\"1.0\"?>\n";
+                       $error_result .= "<SOAP-ENV:Envelope 
xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\";>\n";
+                       $error_result .= "      <SOAP-ENV:Body>\n";
+                       $error_result .= "              <SOAP-ENV:Fault>\n";
+                       $error_result .= "                      
<faultcode>$code</faultcode>\n";
+                       $error_result .= "                      
<faultstring>$text</faultstring>\n";
+                       $error_result .= "              </SOAP-ENV:Fault>\n";
+                       $error_result .= "      </SOAP-ENV:Body>\n";
+                       $error_result .= "</SOAP-ENV:Envelope>\n";
+                       $this->output($error_result);
+                       exit;
+               }       
        }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]