phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] api/rpc class.rpc_browser.php, 1.1.2.2, 1.1.2.3 class


From: Dan Kuykendall <address@hidden>
Subject: [Phpgroupware-cvs] api/rpc class.rpc_browser.php, 1.1.2.2, 1.1.2.3 class.rpc_xmlrpc.php, 1.1.2.2, 1.1.2.3
Date: Tue, 28 Oct 2003 08:52:10 +0000

Update of /cvsroot/phpgroupware/api/rpc
In directory subversions:/tmp/cvs-serv23829/api/rpc

Modified Files:
      Tag: proposal-branch
        class.rpc_browser.php class.rpc_xmlrpc.php 
Log Message:
finished up xmlrpc support. At least for the moment it appears to be working 
well. It needs more error handling routines, but its pretty decent

Index: class.rpc_browser.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/rpc/Attic/class.rpc_browser.php,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** class.rpc_browser.php       28 Oct 2003 05:14:14 -0000      1.1.2.2
--- class.rpc_browser.php       28 Oct 2003 08:52:08 -0000      1.1.2.3
***************
*** 39,42 ****
--- 39,84 ----
                }
  
+               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()
                {

Index: class.rpc_xmlrpc.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/rpc/Attic/class.rpc_xmlrpc.php,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** class.rpc_xmlrpc.php        28 Oct 2003 05:14:14 -0000      1.1.2.2
--- class.rpc_xmlrpc.php        28 Oct 2003 08:52:08 -0000      1.1.2.3
***************
*** 35,43 ****
                        $this->parse();
                        $GLOBALS['phpgw_data']['api']['op'] = $this->op;
                }
  
                function parse()
                {
! $GLOBALS['HTTP_RAW_POST_DATA'] = 'POST /RPC2 HTTP/1.0
  User-Agent: Frontier/5.1.2 (WinNT)
  Host: betty.userland.com
--- 35,222 ----
                        $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);
+                       }
+                       exit;
+               }
+ 
+ 
+               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);
+               }
+ 
+               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<param>\n<value>\n<string>$newsid</string>\n</value>\n</param>\n</params>\n</methodResponse>";
+                       $this->output($result);
+               }
+               
+               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);
+               }
+ 
+               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);
+               }
+               
+               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()
                {
! 
! $xmlrpc_test = 'POST /RPC2 HTTP/1.0
  User-Agent: Frontier/5.1.2 (WinNT)
  Host: betty.userland.com
***************
*** 47,51 ****
  <?xml version="1.0"?>
  <methodCall>
!       <methodName>api.base.start</methodName>
        <params>
                <param>
--- 226,230 ----
  <?xml version="1.0"?>
  <methodCall>
!       <methodName>wcm.base.start</methodName>
        <params>
                <param>
***************
*** 61,64 ****
--- 240,265 ----
  </methodCall>';
  
+ $xmlrpc_login = 'POST /RPC2 HTTP/1.0
+ User-Agent: Frontier/5.1.2 (WinNT)
+ Host: betty.userland.com
+ Content-Type: text/xml
+ Content-length: 181
+ 
+ <?xml version="1.0"?>
+ <methodCall>
+       <methodName>api.base.login</methodName>
+       <params>
+               <param>
+                       <value>admin</value>
+               </param>
+               <param>
+                       <value>temppass</value>
+               </param>
+       </params>
+ </methodCall>';
+ 
+ //$GLOBALS['HTTP_RAW_POST_DATA'] = $xmlrpc_login;
+ $GLOBALS['HTTP_RAW_POST_DATA'] = $xmlrpc_test;
+ 
                        $tmp = explode ("\n", $GLOBALS['HTTP_RAW_POST_DATA']);
                        $num = count($tmp);
***************
*** 83,87 ****
                        {
                                $this->op = 
$GLOBALS['methodCall']['methodName'];
!                               if(is_array($GLOBALS['methodCall']['params']))
                                {
                                        
$this->parse_params($GLOBALS['methodCall']['params']);
--- 284,340 ----
                        {
                                $this->op = 
$GLOBALS['methodCall']['methodName'];
! 
!                               if($this->op == 'api.base.login')
!                               {
!                                       /* pick up the username */
!                                       
if(isset($GLOBALS['methodCall']['params']['param'][0]['value']))
!                                       {
!                                               
if(isset($GLOBALS['methodCall']['params']['param'][0]['value']['string']))
!                                               {
!                                                       
$GLOBALS['HTTP_GET_VARS']['phpgw_user'] = 
$GLOBALS['methodCall']['params']['param'][0]['value']['string'];                
                              
!                                               }
!                                               else
!                                               {
!                                                       
$GLOBALS['HTTP_GET_VARS']['phpgw_user'] = 
$GLOBALS['methodCall']['params']['param'][0]['value'];
!                                               }
!                                               
$GLOBALS['HTTP_GET_VARS']['phpgw_user'] = 
$GLOBALS['methodCall']['params']['param'][0]['value'];
!                                       }
! 
!                                       /* pick up the password */
!                                       
if(isset($GLOBALS['methodCall']['params']['param'][1]['value']))
!                                       {
!                                               
if(isset($GLOBALS['methodCall']['params']['param'][1]['value']['string']))
!                                               {
!                                                       
$GLOBALS['HTTP_GET_VARS']['phpgw_pass'] = 
$GLOBALS['methodCall']['params']['param'][1]['value']['string'];                
                              
!                                               }
!                                               else
!                                               {
!                                                       
$GLOBALS['HTTP_GET_VARS']['phpgw_pass'] = 
$GLOBALS['methodCall']['params']['param'][1]['value'];
!                                               }
!                                               
$GLOBALS['HTTP_GET_VARS']['phpgw_pass'] = 
$GLOBALS['methodCall']['params']['param'][1]['value'];
!                                       }
!                                       
!                                       unset($GLOBALS['methodCall']['params']);
!                               }
!                               
!                               if($this->op != 'api.base.login' && 
is_array($GLOBALS['methodCall']['params']))
!                               {
!                                       
if(isset($GLOBALS['methodCall']['params']['param']['value']['base64']))
!                                       {
!                                               
$GLOBALS['HTTP_GET_VARS']['sid'] = 
base64_decode($GLOBALS['methodCall']['params']['param']['value']['base64']);
!                                               
unset($GLOBALS['methodCall']['params']);
!                                       }
!                                       
elseif(isset($GLOBALS['methodCall']['params']['param'][0]['value']['base64']))
!                                       {
!                                               
$GLOBALS['HTTP_GET_VARS']['sid'] = 
base64_decode($GLOBALS['methodCall']['params']['param'][0]['value']['base64']);
!                                               
unset($GLOBALS['methodCall']['params']['param'][0]);
!                                       }
!                                       else
!                                       {
!                                               /* not a valid session */
!                                               /* means that things will run 
as anonymous */
!                                       }
!                               }
!                               if(is_array($GLOBALS['methodCall']['params']) 
&& count($GLOBALS['methodCall']['params']) > 0)
                                {
                                        
$this->parse_params($GLOBALS['methodCall']['params']);
***************
*** 133,200 ****
                }
  
-               function get_op()
-               {
-                       $this->op;
-               }
- 
-               function get_inputs()
-               {
-                       $this->inputs;
-               }
- 
-               function handle_result($result)
-               {
-                       $this->method_result = $result;
-                       $GLOBALS['phpgw']->finish();
-               }
- 
-               function sendtoclient()
-               {
-                       /* 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>";
-                       
-                       header('Content-type: text/xml');
-                       header('Content-Length: '.strlen($response_packet));
-                       echo $response_packet;
-                       exit;
-               }
  
                function add_vars($params)
--- 386,389 ----





reply via email to

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