phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] api/interface/class.interface_xmlrpc.php, 1.1.2.21


From: nomail
Subject: [Phpgroupware-cvs] api/interface/class.interface_xmlrpc.php, 1.1.2.21
Date: Mon, 28 Jun 2004 16:12:57 +0200

Update of /api/interface
Modified Files:
        Branch: proposal-branch
          class.interface_xmlrpc.php

date: 2004/06/28 14:12:57;  author: dcech;  state: Exp;  lines: +64 -48

Log Message:
added 'numeric' type to validate
added phpgw_error support for apps to return an error code
updated xmlrpc interface for better error handling
=====================================================================
Index: api/interface/class.interface_xmlrpc.php
diff -u api/interface/class.interface_xmlrpc.php:1.1.2.20 
api/interface/class.interface_xmlrpc.php:1.1.2.21
--- api/interface/class.interface_xmlrpc.php:1.1.2.20   Tue Jun 22 15:42:43 2004
+++ api/interface/class.interface_xmlrpc.php    Mon Jun 28 14:12:57 2004
@@ -42,17 +42,15 @@
 
                function output($result, $debug = false)
                {
-                       define('PHPGW_FINISHED', true);
-                       if(!$debug)
-                       {
-                               header('Content-type: text/xml');
-                               header('Content-Length: '.strlen($result));
-                               return $result;
-                       }
-                       else
+                       if($debug)
                        {
                                return htmlentities($result);
                        }
+                       
+                       define('PHPGW_FINISHED', true);
+                       header('Content-type: text/xml');
+                       header('Content-Length: '.strlen($result));
+                       return $result;
                }
 
                function get_op()
@@ -62,8 +60,8 @@
 
                function login()
                {
-                       $GLOBALS['phpgw']->finish(false);
-                       $this->xmlrpc_fault('1', 'Please login.');
+                       echo $this->output($this->xmlrpc_fault('1', 'Please 
login.'));
+                       exit;
                }
 
                function good_login()
@@ -86,7 +84,8 @@
                                $code = 3;
                                $msg = 'Username and/or password missing.';
                        }
-                       $this->xmlrpc_fault($code, $msg);
+                       echo $this->output($this->xmlrpc_fault($code, $msg));
+                       exit;
                }
 
                function logout()
@@ -95,7 +94,8 @@
 
                function access_denied($methodname, $inputs = '')
                {
-                       $this->xmlrpc_fault('99', 'Access denied to 
'.$methodname);
+                       echo $this->output($this->xmlrpc_fault('99', 'Access 
denied to '.$methodname));
+                       exit;
                }
                
                function get_inputs()
@@ -118,17 +118,17 @@
                {
                        if (defined('MISBEHAVEDAPP'))
                        {
-                               $this->xmlrpc_fault(1, 'method returned faulty 
data. may not be xml-rpc compliant.');
+                               return $this->output($this->xmlrpc_fault(1, 
'method returned faulty data. may not be xml-rpc compliant.'));
                        }
                        
                        switch ($this->methodName)
                        {
                                case 'system.listMethods':
-                                       return $this->system_listMethods();
+                                       return 
$this->output($this->system_listMethods());
                                case 'system.methodSignature':
-                                       return $this->system_methodSignature();
+                                       return 
$this->output($this->system_methodSignature());
                                case 'system.methodHelp':
-                                       return $this->system_methodHelp();
+                                       return 
$this->output($this->system_methodHelp());
                        }
 
                        if(!isset($this->method_result))
@@ -152,13 +152,13 @@
                                exit;
                        }
                        
-                       if 
(!preg_match('/(<\?xml.+?>\s)?(<methodCall>.*<\/methodCall>)/is',$GLOBALS['HTTP_RAW_POST_DATA'],$matches))
+                       if 
(!preg_match('/(<\?xml.+?\?>\s)?(<methodCall>.*<\/methodCall>)/is',$GLOBALS['HTTP_RAW_POST_DATA'],$matches))
                        {
-                               $GLOBALS['phpgw']->finish(false);
-                               $this->xmlrpc_fault('1', 'Invalid xmlrpc 
packet.');
+                               echo $this->output($this->xmlrpc_fault('1', 
'Invalid xmlrpc packet.'));
+                               exit;
                        }
                        
-                       $xmlrpc_input  = empty($matches[1]) ? '<?xml 
version="1.0">'."\n" : $matches[1];
+                       $xmlrpc_input  = empty($matches[1]) ? '<?xml 
version="1.0"?>'."\n" : $matches[1];
                        $xmlrpc_input .= $matches[2];
                        
                        $request = xml2var($xmlrpc_input);
@@ -253,14 +253,19 @@
                {
                        if(empty($result) || $result == NOTSET)
                        {
-                               $GLOBALS['phpgw']->finish(false);
-                               $this->xmlrpc_fault('1', 'No Response.');
+                               return $this->xmlrpc_fault('1', 'No Response.');
+                       }
+                       
+                       if(is_error($result))
+                       {
+                               return 
$this->xmlrpc_fault($result->errno,$result->message);
                        }
                        
                        $response  = "<?xml version=\"1.0\"?>\n";
                        $response .= "<methodResponse>\n";
                        $response .= $this->indent."<params>\n";
                        
+                       /*
                        if(is_array($result) && reset(array_keys($result)) === 
0)
                        {
                                foreach ($result as $val)
@@ -272,10 +277,12 @@
                        }
                        else
                        {
+                       */
                                $response .= 
str_repeat($this->indent,2)."<param>\n";
                                $response .= $this->add_vars($result,3);
                                $response .= 
str_repeat($this->indent,2)."</param>\n";
-                       }
+                       //}
+                       
                        
                        $response .= $this->indent."</params>\n";
                        $response .= '</methodResponse>';
@@ -289,7 +296,7 @@
                        switch(gettype($params))
                        {
                                case 'boolean': // booleans
-                                       $result .= 
str_repeat($this->indent,$level+1).'<boolean>'.$params."</boolean>\n";
+                                       $result .= 
str_repeat($this->indent,$level+1).'<boolean>'.intval($params)."</boolean>\n";
                                        break;
                                case 'double': // floats
                                        $result .= 
str_repeat($this->indent,$level+1).'<double>'.$params."</double>\n";
@@ -335,7 +342,9 @@
 
                function system_listMethods()
                {
+                       $allow_methods = array();
                        $GLOBALS['phpgw']->load_docs();
+                       
                        foreach($GLOBALS['docs'] as $appname=>$app_data)
                        {
                                foreach($app_data['classes'] as 
$class=>$class_data)
@@ -345,24 +354,27 @@
                                        
                                        if(is_array($class_data['functions']))
                                        {
-                                               
foreach($class_data['functions'] as $function=>$function_data)
+                                               
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'
+                                                       if 
(($GLOBALS['phpgw']->acl->check($method, 1)
+                                                               || $method == 
'api.base.login'
+                                                               || $method == 
'api.base.logout'
+                                                               || $method == 
'api.base.about')
+                                                               && 
$function_data['type'] == 'public'
                                                        )
                                                        {
                                                                
$allow_methods[$method] = $function_data;
                                                        }
                                                }
-                                       }               
+                                       }
                                }
                        }
+                       return $this->response($allow_methods);
+                       /*
                        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 */
+                               // 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)
                                {
@@ -373,7 +385,8 @@
                                }
                                $result .= 
"</data>\n</array>\n</value>\n</param>\n</params>\n</methodResponse>";
                        }
-                       return $this->output($result);
+                       return $result;
+                       */
                }
 
                function system_methodSignature()
@@ -388,7 +401,7 @@
                        }
                        else
                        {
-                               $this->xmlrpc_fault('1', 'Invalid request. 
methodName missing.');
+                               return $this->xmlrpc_fault('1', 'Invalid 
request. methodName missing.');
                        }
 
                        $GLOBALS['phpgw']->load_docs();
@@ -407,15 +420,17 @@
                                        $result .= 
"</data>\n</array></value>\n</data>\n</array></value>\n</param>\n</params>\n";
                                }
                                $result .= "</methodResponse>\n";
-                               return $this->output($result);
+                               return $result;
                        }
-                       
elseif(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func])
 && !$GLOBALS['phpgw']->acl->check($methodname, 1))
+                       
+                       
if(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func])
 && !$GLOBALS['phpgw']->acl->check($methodname, 1))
                        {
-                               $this->xmlrpc_fault('1', 'Access Denied. Your 
account does not have rights to this function.');
+                               return $this->xmlrpc_fault('1', 'Access Denied. 
Your account does not have rights to this function.');
                        }
-                       
elseif(!isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]))
+                       
+                       
if(!isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]))
                        {
-                               $this->xmlrpc_fault('1', 'No such method 
exists.');
+                               return $this->xmlrpc_fault('1', 'No such method 
exists.');
                        }
                }
 
@@ -431,7 +446,7 @@
                        }
                        else
                        {
-                               $this->xmlrpc_fault('1', 'Invalid request. 
methodName missing.');
+                               return $this->xmlrpc_fault('1', 'Invalid 
request. methodName missing.');
                        }
 
                        $GLOBALS['phpgw']->load_docs();
@@ -441,17 +456,19 @@
                        {
                                
if(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]['abstract']))
                                {
-                                       return 
$this->output($this->response($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]['abstract']));
+                                       return 
$this->response($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]['abstract']);
                                }
-                               return $this->output($this->response());
+                               return $this->response();
                        }
-                       
elseif(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func])
 && !$GLOBALS['phpgw']->acl->check($methodname, 1))
+                       
+                       
if(isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func])
 && !$GLOBALS['phpgw']->acl->check($methodname, 1))
                        {
-                               $this->xmlrpc_fault(1, 'Access Denied. Your 
account does not have rights to this function.');
+                               return $this->xmlrpc_fault(1, 'Access Denied. 
Your account does not have rights to this function.');
                        }
-                       
elseif(!isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]))
+                       
+                       
if(!isset($GLOBALS['docs'][$app]['classes'][$app.'_'.$class]['functions'][$func]))
                        {
-                               $this->xmlrpc_fault(1, 'No such method 
exists.');
+                               return $this->xmlrpc_fault(1, 'No such method 
exists.');
                        }
                }
                
@@ -468,7 +485,6 @@
                        $error_result .= $this->add_vars($fault,2);
                        $error_result .= $this->indent."</fault>\n";
                        $error_result .= "</methodResponse>\n";
-                       echo $this->output($error_result);
-                       exit;
+                       return $error_result;
                }
        }




reply via email to

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