phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] api/interface class.interface_browser.php, NONE, 1.1.


From: Dan Kuykendall <address@hidden>
Subject: [Phpgroupware-cvs] api/interface class.interface_browser.php, NONE, 1.1.2.1 class.interface_xmlrpc.php, NONE, 1.1.2.1
Date: Fri, 31 Oct 2003 04:33:49 +0000

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

Added Files:
      Tag: proposal-branch
        class.interface_browser.php class.interface_xmlrpc.php 
Log Message:
switched from rpc to interface

--- NEW FILE: class.interface_browser.php ---
<?php
        
/**************************************************************************\
        * phpGroupWare                                                          
   *
        * http://www.phpgroupware.org                                           
   *
        * This file written by Dan Kuykendall <address@hidden>                 *
        * Copyright (C) 2003 Dan Kuykendall                                     
   *
        * 
-------------------------------------------------------------------------*
        * This library is part of the phpGroupWare API                          
   *
        * http://www.phpgroupware.org/api                                       
   * 
        * 
------------------------------------------------------------------------ *
        * This library is free software; you can redistribute it and/or modify 
it  *
        * under the terms of the GNU Lesser General Public License as published 
by *
        * the Free Software Foundation; either version 2.1 of the License,      
   *
        * or any later version.                                                 
   *
        * This library is distributed in the hope that it will be useful, but   
   *
        * WITHOUT ANY WARRANTY; without even the implied warranty of            
   *
        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  
   *
        * See the GNU Lesser General Public License for more details.           
   *
        * You should have received a copy of the GNU Lesser General Public 
License *
        * along with this library; if not, write to the Free Software 
Foundation,  *
        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA         
   *
        
\**************************************************************************/

        /* $Id: class.interface_browser.php,v 1.1.2.1 2003/10/31 04:33:47 
seek3r Exp $ */

        class api_interface
        {
                var $xslt_render;
                var $xslt_render_force_server = False;

                function api_interface()
                {
                        reg_var('op', 'any', 'any','##NOVAL##');
                }

                function get_op()
                {
                        $this->op;
                }

                function login()
                {
                        $GLOBALS['phpgw']->add_xsl('api.login');
                        $GLOBALS['phpgw']->finish(False);
                }

                function good_login()
                {
                        /* Not needed in this RPC, but stub required */
                }
                
                function failed_login($reason = 'missing')
                {
                        if($reason == 'invalid')
                        {
                                $GLOBALS['msgbox']->add('Login 
failed!',__LINE__,__FILE__, 'notice');
                        }
                        $this->login();
                }

                function logout()
                {
                        $GLOBALS['phpgw']->session->destroy();
                        $GLOBALS['phpgw_data']['api']['op'] = 'api.base.login';
                }

                function access_denied($methodname, $inputs = '')
                {
                        $msg = 'You do not have access to';
                        if(function_exists('lang'))
                        {
                                $msg = lang($msg);
                        }

                        $GLOBALS['msgbox']->add(lang($msg.' 
').$methodname,__LINE__,__FILE__, 'access');
                        foreach($inputs as $key=>$val)                          
                        {
                                $input_list[] = array('name'=>$key, 
'val'=>$val);
                        }
                        
$GLOBALS['phpgw_xml_apinode']->add_node($input_list,'input_list');
                }
                
                function get_inputs()
                {
                        $inputs = 
array_merge($GLOBALS['HTTP_SESSION_VARS']['phpgw_session'], 
$GLOBALS['HTTP_COOKIE_VARS'], $GLOBALS['HTTP_GET_VARS'], 
$GLOBALS['HTTP_POST_VARS']);
                        unset($inputs['phpgw_lid'], 
$inputs['PHPSESSID'],$inputs['session_lid'],$inputs['sid']);
                        unset($inputs['op'], $inputs['nextop'], 
$inputs['prevop']);
                        unset($inputs['phpgw_user'], $inputs['phpgw_pass']);
                        unset($inputs['fxsl'], $inputs['lang_cache']);
                        return $inputs;
                }

                /*!
                @function handle_result
                @abstract Takes the results of the operation, packs it up and 
then has phpgw->finish handle the rest.
                @param $app_data
                */
                function handle_result($result)
                {
                        $GLOBALS['phpgw_xmldoc']->add_node($result, 'APP');
                        $GLOBALS['phpgw']->finish();
                }

                function sendtoclient()
                {
                        /* Start the XSLT class for it to be able to decide how 
to build the strings */
                        $this->xslt_render = createobject('api_xslt');
                        
                        if($this->xslt_render_force_server)
                        {
                                $this->xslt_render->client_render = False;
                        }
                        
                        $stylesheet_string = 
$this->xslt_render->setup_stylesheet($GLOBALS['phpgw']->xsl_files);
                        
$GLOBALS['phpgw']->base_xml->set_stylesheet($stylesheet_string);

                        /* Constructing the XML doc */
                        $xml_result =  
$GLOBALS['phpgw']->base_xml->export_xml();
                        
                        /* Use the XSLT class to handle browser detection */
                        /* and if needed, the rendering of the XML */
                        $this->xslt_render->set_xml($xml_result);

                        /* Before we send output, save the session data */
                        $GLOBALS['phpgw']->session->save_data();

                        /* Have XSLT class output as it determins as best */
                        //echo '<pre>'; print_r($GLOBALS); echo '</pre>';
                        $GLOBALS['performance_timer']->start('xslt_out');
                        echo $this->xslt_render->getOutput();
                        $GLOBALS['performance_timer']->stop('xslt_out');
                }
        }

--- NEW FILE: class.interface_xmlrpc.php ---
<?php
        
/**************************************************************************\
        * phpGroupWare                                                          
   *
        * http://www.phpgroupware.org                                           
   *
        * This file written by Dan Kuykendall <address@hidden>                 *
        * Copyright (C) 2003 Dan Kuykendall                                     
   *
        * 
-------------------------------------------------------------------------*
        * This library is part of the phpGroupWare API                          
   *
        * http://www.phpgroupware.org/api                                       
   * 
        * 
------------------------------------------------------------------------ *
        * This library is free software; you can redistribute it and/or modify 
it  *
        * under the terms of the GNU Lesser General Public License as published 
by *
        * the Free Software Foundation; either version 2.1 of the License,      
   *
        * or any later version.                                                 
   *
        * This library is distributed in the hope that it will be useful, but   
   *
        * WITHOUT ANY WARRANTY; without even the implied warranty of            
   *
        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  
   *
        * See the GNU Lesser General Public License for more details.           
   *
        * You should have received a copy of the GNU Lesser General Public 
License *
        * along with this library; if not, write to the Free Software 
Foundation,  *
        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA         
   *
        
\**************************************************************************/

        /* $Id: class.interface_xmlrpc.php,v 1.1.2.1 2003/10/31 04:33:47 seek3r 
Exp $ */

        class api_interface
        {
                var $op;
                var $inputs;
                var $method_result;
                var $indent = '';
                var $first_input = True;
                
                function api_interface()
                {
                        $this->parse();
                        $GLOBALS['phpgw_data']['api']['op'] = $this->op;
                        $GLOBALS['phpgw_data']['server']['session_method'] = 
'url';
                }

                function output($result, $debug = False)
                {
                        /* Before we send output, save the session data */
                        $GLOBALS['phpgw']->session->save_data();
                        if(!$debug)
                        {
                                header('Content-type: text/xml');
                                header('Content-Length: '.strlen($result));
                                echo $result;
                        }
                        else
                        {
                                echo htmlentities($result);
                        }
                }

                function get_op()
                {
                        $this->op;
                }

                function login()
                {
                        $GLOBALS['phpgw']->finish(False);
                        $error_result = "<?xml version=\"1.0\"?>\n";
                        $error_result .= "<methodResponse>\n";
                        $error_result .= "      <fault>\n";
                        $error_result .= "              <value>\n";
                        $error_result .= "                      <struct>\n";
                        $error_result .= "                              
<member>\n";
                        $error_result .= "                                      
<name>faultCode</name>\n";
                        $error_result .= "                                      
<value><int>1</int></value>\n";
                        $error_result .= "                              
</member>\n";
                        $error_result .= "                              
<member>\n";
                        $error_result .= "                                      
<name>faultString</name>\n";
                        $error_result .= "                                      
<value><string>Please login.</string></value>\n";
                        $error_result .= "                              
</member>\n";
                        $error_result .= "                      </struct>\n";
                        $error_result .= "              </value>\n";
                        $error_result .= "      </fault>\n";
                        $error_result .= "</methodResponse>\n";
                        
                        $this->output($error_result);
                        exit;
                }

                function good_login()
                {
                        $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>";
                        $this->output($result);
                        exit;
                }
                
                function failed_login($reason = 'missing')
                {
                        if($reason == 'invalid')
                        {
                                $code = 4;
                                $msg = 'Authentication Failed!';
                        }
                        elseif($reason == 'missing')
                        {
                                $code = 3;
                                $msg = 'Username and/or password missing.';
                        }
                        $error_result = "<?xml version=\"1.0\"?>\n";
                        $error_result .= "<methodResponse>\n";
                        $error_result .= "      <fault>\n";
                        $error_result .= "              <value>\n";
                        $error_result .= "                      <struct>\n";
                        $error_result .= "                              
<member>\n";
                        $error_result .= "                                      
<name>faultCode</name>\n";
                        $error_result .= "                                      
<value><int>$code</int></value>\n";
                        $error_result .= "                              
</member>\n";
                        $error_result .= "                              
<member>\n";
                        $error_result .= "                                      
<name>faultString</name>\n";
                        $error_result .= "                                      
<value><string>$msg</string></value>\n";
                        $error_result .= "                              
</member>\n";
                        $error_result .= "                      </struct>\n";
                        $error_result .= "              </value>\n";
                        $error_result .= "      </fault>\n";
                        $error_result .= "</methodResponse>\n";
                        
                        $this->output($error_result);
                        exit;
                }

                function logout()
                {
                }

                function access_denied($methodname, $inputs = '')
                {
                        $error_result = "<?xml version=\"1.0\"?>\n";
                        $error_result .= "<methodResponse>\n";
                        $error_result .= "      <fault>\n";
                        $error_result .= "              <value>\n";
                        $error_result .= "                      <struct>\n";
                        $error_result .= "                              
<member>\n";
                        $error_result .= "                                      
<name>faultCode</name>\n";
                        $error_result .= "                                      
<value><int>99</int></value>\n";
                        $error_result .= "                              
</member>\n";
                        $error_result .= "                              
<member>\n";
                        $error_result .= "                                      
<name>faultString</name>\n";
                        $error_result .= "                                      
<value><string>Access denied to $methodname</string></value>\n";
                        $error_result .= "                              
</member>\n";
                        $error_result .= "                      </struct>\n";
                        $error_result .= "              </value>\n";
                        $error_result .= "      </fault>\n";
                        $error_result .= "</methodResponse>\n";
                        
                        $this->output($error_result);
                        exit;
                }
                
                function get_inputs()
                {
                        return $this->inputs;
                }

                function handle_result($result)
                {
                        $this->method_result = $result;
                        $GLOBALS['phpgw']->finish();
                }

                function sendtoclient()
                {
                        $xml_result =  
$GLOBALS['phpgw']->base_xml->export_xml();
                        $api_data = xml2var($xml_result);
                        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";
                        $response_packet .= "<methodResponse>\n";

                        if(!empty($this->method_result))
                        {
                                $response_packet .= "<params>\n";

                                if(!is_array($this->method_result))
                                {
                                        $response_packet .= "<param>\n";
                                        $response_packet .=  
$this->add_vars($this->method_result);
                                        $response_packet .= "</param>\n";
                                }
                                else
                                {
                                        
if(array_key_exists(0,$this->method_result))
                                        {
                                                $num = 
count($this->method_result);
                                                for ($i=0; $i < $num; $i++)
                                                {
                                                        $response_packet .= 
"<param>\n";
                                                        $response_packet .=  
$this->add_vars($this->method_result[$i]);
                                                        $response_packet .= 
"</param>\n";
                                                }
                                        }
                                        else
                                        {
                                                $response_packet .= "<param>\n";
                                                $response_packet .= "<value>\n";
                                                $response_packet .= 
$this->add_vars($this->method_result);
                                                $response_packet .= 
"</value>\n";
                                                $response_packet .= 
"</param>\n";
                                        }
                                }
                                $response_packet .= "</params>\n";
                        }
                        
                        $response_packet .= "</methodResponse>";
                        
                        $this->output($response_packet);
                }
                
                function parse()
                {
                        if(!isset($GLOBALS['HTTP_RAW_POST_DATA']))
                        {
                                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($hit_start)
                                {
                                        $xmlrpc_input .= $tmp[$i]."\n";
                                }
                                elseif(stristr($tmp[$i], '<?xml'))
                                {
                                        $hit_start = True;
                                        $xmlrpc_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, $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']))
                        {
                                $GLOBALS['phpgw']->finish(False);
                                $error_result = "<?xml version=\"1.0\"?>\n";
                                $error_result .= "<methodResponse>\n";
                                $error_result .= "      <fault>\n";
                                $error_result .= "              <value>\n";
                                $error_result .= "                      
<struct>\n";
                                $error_result .= "                              
<member>\n";
                                $error_result .= "                              
        <name>faultCode</name>\n";
                                $error_result .= "                              
        <value><int>1</int></value>\n";
                                $error_result .= "                              
</member>\n";
                                $error_result .= "                              
<member>\n";
                                $error_result .= "                              
        <name>faultString</name>\n";
                                $error_result .= "                              
        <value><string>Invalid xmlrpc packet. methodName 
missing.</string></value>\n";
                                $error_result .= "                              
</member>\n";
                                $error_result .= "                      
</struct>\n";
                                $error_result .= "              </value>\n";
                                $error_result .= "      </fault>\n";
                                $error_result .= "</methodResponse>\n";
                                exit;
                        }

                        $this->op = 
$this->xml_vals[$this->xml_index['methodName'][0]]['value'];

                        $GLOBALS['methodCall'] = xml2var($xmlrpc_input);

                        if(count($this->xml_index['params']) == 2)
                        {
                                $this->i = $this->xml_index['params'][0];
                                $this->xml_vals_count = count($this->xml_vals);
                                $this->inputs = $this->parse_params();
                        }
                }

                function parse_params()
                {
                        switch($this->xml_vals[$this->i]['type'])
                        {
                                case 'complete':
                                        $this->input_num++;
                                        switch($this->xml_vals[$this->i]['tag'])
                                        {
                                                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;
                                        }
                                        $this->i++;
                                        
                                        if($this->op == 'api.base.login')
                                        {
                                                if($this->input_num == 1)
                                                {
                                                        
$GLOBALS['HTTP_GET_VARS']['phpgw_user'] = $value;
                                                }
                                                elseif($this->input_num == 2)
                                                {
                                                        
$GLOBALS['HTTP_GET_VARS']['phpgw_pass'] = $value;
                                                }
                                                return;
                                        }
                                        elseif($this->input_num == 1)
                                        {
                                                
$GLOBALS['HTTP_GET_VARS']['sid'] = $value;
                                                return;
                                        }
                                        else
                                        {
                                                return $value;
                                                if(isset($name))
                                                {
                                                        return 
array($name=>$value);
                                                }
                                                else
                                                {
                                                        return $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;
                        }
                }

                function add_vars($params)
                {
                        if(!is_array($params))
                        {
                                $result =  
"<value>".$this->add_params_type_handler($params)."</value>\n";
                        }
                        else
                        {
                                if(array_key_exists(0,$params))
                                {
                                        $num = count($params);
                                        $result = "<array>\n<data>\n";
                                        for ($i=0; $i < $num; $i++)
                                        {
                                                if(is_array($params[$i]))
                                                {
                                                        $result .= 
$this->add_vars($params[$i]);
                                                }
                                                else
                                                {
                                                        $result .= 
"<value>".$this->add_params_type_handler($params[$i])."</value>\n";
                                                }
                                        }
                                        
                                        $result .= "</data>\n</array>\n";
                                }
                                else
                                {
                                        $result = "<struct>\n";
                                        foreach($params as $key=>$val)          
                
                                        {
                                                if(is_array($val))
                                                {
                                                        $result .= 
$this->add_vars($val);
                                                }
                                                else
                                                {
                                                        $result .= "<member>\n";
                                                        $result .= 
"<name>".$key."</name>\n";
                                                        $result .= 
"<value>".$this->add_params_type_handler($val)."</value>\n";
                                                        $result .= 
"</member>\n";
                                                }
                                        }
                                        $result .= "</struct>\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 
("<struct>\n<struct>\n", "<struct>\n", $result); 
                                        $result = str_replace 
("</struct>\n</struct>\n", "</struct>\n", $result); 
                                }
                        }
                        return $result;
                }

                function add_params_type_handler($param)
                {
                        switch(gettype($param))
                        {
                                case 'boolean':
                                        return '<boolean>'.$param.'</boolean>';
                                        break;
                                case 'double':
                                        return '<double>'.$param.'</double>';
                                        break;
                                case 'integer':
                                        return '<i4>'.$param.'</i4>';
                                        break;
                                case 'array':
                                        //need to handle this
                                        break;
                                default:
                                        return '<string>'.$param.'</string>';
                        }
                }
        }





reply via email to

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