[20853] update xmlrpc

Sigurd Nes <[email protected]>
Newsgroups gmane.comp.web.phpgroupware.cvs
Message-ID <[email protected]>
Revision: 20853
          http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20853
Author:   sigurdne
Date:     2009-11-20 10:29:32 +0000 (Fri, 20 Nov 2009)
Log Message:
-----------
update xmlrpc

Modified Paths:
--------------
    people/sigurdne/modules/xmlrpc/trunk/bettydemo.php
    people/sigurdne/modules/xmlrpc/trunk/client.php
    people/sigurdne/modules/xmlrpc/trunk/interserv.php
    people/sigurdne/modules/xmlrpc/trunk/mail.php
    people/sigurdne/modules/xmlrpc/trunk/phpgw_test.php
    people/sigurdne/modules/xmlrpc/trunk/testsuite.php

Added Paths:
-----------
    people/sigurdne/modules/xmlrpc/trunk/inc/
    people/sigurdne/modules/xmlrpc/trunk/inc/class.examples.inc.php

Modified: people/sigurdne/modules/xmlrpc/trunk/bettydemo.php
===================================================================
--- people/sigurdne/modules/xmlrpc/trunk/bettydemo.php	2009-11-20 10:29:28 UTC (rev 20852)
+++ people/sigurdne/modules/xmlrpc/trunk/bettydemo.php	2009-11-20 10:29:32 UTC (rev 20853)
@@ -4,14 +4,14 @@
 <?php
 include("xmlrpc.inc");
 
-if ($HTTP_POST_VARS["stateno"]!="") {
+if ($_POST["stateno"]!="") {
   $f=new xmlrpcmsg('examples.getStateName',
-				   array(new xmlrpcval($HTTP_POST_VARS["stateno"], "int")));
+				   array(new xmlrpcval($_POST["stateno"], "int")));
   $c=new xmlrpc_client("/RPC2", "betty.userland.com", 80);
   $r=$c->send($f);
   $v=$r->value();
   if (!$r->faultCode()) {
-	print "State number ". $HTTP_POST_VARS["stateno"] . " is " .
+	print "State number ". $_POST["stateno"] . " is " .
 	  $v->scalarval() . "<BR>";
 	print "<HR>I got this value back<BR><PRE>" .
 	  htmlentities($r->serialize()). "</PRE><HR>\n";

Modified: people/sigurdne/modules/xmlrpc/trunk/client.php
===================================================================
--- people/sigurdne/modules/xmlrpc/trunk/client.php	2009-11-20 10:29:28 UTC (rev 20852)
+++ people/sigurdne/modules/xmlrpc/trunk/client.php	2009-11-20 10:29:32 UTC (rev 20853)
@@ -21,30 +21,43 @@
 
 	include('../header.inc.php');
 
-	if ($HTTP_POST_VARS['stateno'] != '')
+	phpgw::import_class('phpgwapi.xmlrpc_client');
+	if ($_POST['stateno'] != '')
 	{
-		$f = CreateObject('phpgwapi.xmlrpcmsg','examples.getStateName',array(CreateObject('phpgwapi.xmlrpcval',$HTTP_POST_VARS['stateno'], 'int')));
-		print "<pre>" . htmlentities($f->serialize()) . "</pre>\n";
-		$c = CreateObject('phpgwapi.xmlrpc_client',"/phpgroupware/xmlrpc.php", $HTTP_SERVER_VARS['HTTP_HOST'], 80);
-		$c->setDebug(1);
-		$r = $c->send($f);
-		if (!$r)
+		$username = 'anonymous';
+		$password = 'anonymous1';
+		$phpgw_domain = 'default';
+
+		$stateno = phpgw::get_var('stateno', 'int', 'POST', 0);
+		$c = new xmlrpc_client("{$GLOBALS['phpgw_info']['server']['webserver_url']}/xmlrpc.php?domain={$phpgw_domain}", $_SERVER['HTTP_HOST'], 80);
+		$c->setCredentials($username, $password);	 
+		$f=new xmlrpcmsg('xmlrpc.examples.findstate',array(php_xmlrpc_encode($stateno))	);
+
+//		print "<pre>" . htmlentities($f->serialize('UTF-8')) . "</pre>\n";
+//		$c->setDebug(1);
+		$r=&$c->send($f);
+
+//		$cookies = $r->cookies();
+
+		if(!$r->faultCode())
 		{
-			die('send failed');
-		}
-		$v = $r->value();
-		if (!$r->faultCode())
-		{
-			print 'State number ' . $HTTP_POST_VARS['stateno'] . ' is ' . $v->scalarval() . '<br>';
+			$v=$r->value();
+			print "</pre><br/>State number " . $stateno . " is "
+				. htmlspecialchars($v->scalarval()) . "<br/>";
 			// print "<HR>I got this value back<BR><PRE>" .
 			//  htmlentities($r->serialize()). "</PRE><HR>\n";
 		}
 		else
 		{
-			print 'Fault: ';
-			print 'Code: ' . $r->faultCode() . " Reason '" .$r->faultString()."'<br>";
+			print "An error occurred: ";
+			print "Code: " . htmlspecialchars($r->faultCode())
+				. " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
 		}
 	}
+	else
+	{
+		$stateno = "";
+	}
 
 	echo '
 <form action="' . $GLOBALS['phpgw']->link('/xmlrpc/client.php') . '" method="post">

Added: people/sigurdne/modules/xmlrpc/trunk/inc/class.examples.inc.php
===================================================================
--- people/sigurdne/modules/xmlrpc/trunk/inc/class.examples.inc.php	                        (rev 0)
+++ people/sigurdne/modules/xmlrpc/trunk/inc/class.examples.inc.php	2009-11-20 10:29:32 UTC (rev 20853)
@@ -0,0 +1,130 @@
+<?php
+	/**
+	* Notes
+	* @copyright Copyright (C) 2009 Free Software Foundation, Inc. http://www.fsf.org/
+	* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
+	* @package notes
+	* @version $Id$
+	*/
+
+	/*
+		This program is free software; you can redistribute it and/or modify
+		it under the terms of the GNU General Public License as published by
+		the Free Software Foundation; either version 3 of the License, or
+		(at your option) any later version.
+
+		This program 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 General Public License for more details.
+
+		You should have received a copy of the GNU General Public License
+		along with this program.  If not, see <http://www.gnu.org/licenses/>.
+	*/
+
+	/**
+	* examples business object class
+	*
+	* @package XMLRPC
+	*/
+	class xmlrpc_examples
+	{
+		var $public_functions = array
+		(
+			'findstate'			=> true
+		);
+
+		var $soap_functions = array(
+			'findstate' => array(
+				'in'  => array('int','int','struct','string','int'),
+				'out' => array('array')
+			)
+		);
+
+		public $xmlrpc_methods = array
+		(
+			array
+			(
+				'name'       => 'findstate',
+				'decription' => 'When passed an integer between 1 and 51 returns the name of a US state, where the integer is the index of that state name in an alphabetic order.'
+			)
+		);
+
+		function __construct()
+		{
+		}
+
+		function list_methods($_type='xmlrpc')
+		{
+			/*
+			  This handles introspection or discovery by the logged in client,
+			  in which case the input might be an array.  The server always calls
+			  this function to fill the server dispatch map using a string.
+			*/
+			if (is_array($_type))
+			{
+				$_type = $_type['type'] ? $_type['type'] : $_type[0];
+			}
+			switch($_type)
+			{
+				case 'xmlrpc':
+					$xml_functions = array(
+						'read' => array(
+							'function'  => 'findstate',
+							'signature' => array(array(xmlrpcInt,xmlrpcString)),
+							'docstring' => 'When passed an integer between 1 and 51 returns the name of a US state, where the integer is the index of that state name in an alphabetic order.'
+						),
+				);
+					return $xml_functions;
+					break;
+				case 'soap':
+					return $this->soap_functions;
+					break;
+				default:
+					return array();
+					break;
+			}
+		}
+
+
+		function findstate($snv)
+		{
+			$stateNames = array(
+			"Alabama", "Alaska", "Arizona", "Arkansas", "California",
+			"Colorado", "Columbia", "Connecticut", "Delaware", "Florida",
+			"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas",
+			"Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
+			"Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
+			"New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina",
+			"North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
+			"South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
+			"Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"
+			);
+
+			$err="";
+	
+			// look it up in our array (zero-based)
+
+			if (isset($stateNames[$snv-1]))
+			{
+				$sname=$stateNames[$snv-1];
+			}
+			else
+			{
+				// not, there so complain
+				$err="I don't have a state for the index '" . $snv . "'";
+			}
+
+			// if we generated an error, create an error return response
+			if ($err)
+			{
+				return $err;
+			}
+			else
+			{
+				// otherwise, we create the right response
+				// with the state name
+				return $sname;
+			}
+		}
+	}


Property changes on: people/sigurdne/modules/xmlrpc/trunk/inc/class.examples.inc.php
___________________________________________________________________
Added: svn:keywords
   + Id Revision
Added: svn:eol-style
   + native

Modified: people/sigurdne/modules/xmlrpc/trunk/interserv.php
===================================================================
--- people/sigurdne/modules/xmlrpc/trunk/interserv.php	2009-11-20 10:29:28 UTC (rev 20852)
+++ people/sigurdne/modules/xmlrpc/trunk/interserv.php	2009-11-20 10:29:32 UTC (rev 20853)
@@ -19,9 +19,9 @@
 
 	include('../header.inc.php');
 
-	$server_id  = $HTTP_POST_VARS['server_id'];
-	$xsessionid = $HTTP_POST_VARS['xsessionid'];
-	$xkp3       = $HTTP_POST_VARS['xkp3'];
+	$server_id  = $_POST['server_id'];
+	$xsessionid = $_POST['xsessionid'];
+	$xkp3       = $_POST['xkp3'];
 
 	$is = CreateObject('phpgwapi.interserver',intval($server_id));
 
@@ -58,19 +58,19 @@
 	}
 	else
 	{
-		$xserver_name = $HTTP_POST_VARS['xserver_name'];
+		$xserver_name = $_POST['xserver_name'];
 	}
 
 	/* _debug_array($is->server); */
-	if($HTTP_POST_VARS['login'])
+	if($_POST['login'])
 	{
-		if($HTTP_POST_VARS['xserver'])
+		if($_POST['xserver'])
 		{
 			$is->send(
 				'system.login', array(
-					'server_name' => $HTTP_POST_VARS['xserver_name'],
-					'username'    => $HTTP_POST_VARS['xusername'],
-					'password'    => $HTTP_POST_VARS['xpassword']
+					'server_name' => $_POST['xserver_name'],
+					'username'    => $_POST['xusername'],
+					'password'    => $_POST['xpassword']
 				),
 				$is->server['server_url']
 			);
@@ -79,9 +79,9 @@
 		{
 			$is->send(
 				'system.login', array(
-					'domain'      => $HTTP_POST_VARS['xserver_name'],
-					'username'    => $HTTP_POST_VARS['xusername'],
-					'password'    => $HTTP_POST_VARS['xpassword']
+					'domain'      => $_POST['xserver_name'],
+					'username'    => $_POST['xusername'],
+					'password'    => $_POST['xpassword']
 				),
 				$is->server['server_url']
 			);
@@ -91,7 +91,7 @@
 		$xsessionid = $is->result['sessionid'];
 		$xkp3       = $is->result['kp3'];
 	}
-	elseif($HTTP_POST_VARS['logout'])
+	elseif($_POST['logout'])
 	{
 		$is->send(
 			'system.logout', array(
@@ -103,7 +103,7 @@
 		$xsessionid = '';
 		$xkp3       = '';
 	}
-	elseif($HTTP_POST_VARS['methods'])
+	elseif($_POST['methods'])
 	{
 		if(!$server_id)
 		{
@@ -113,9 +113,9 @@
 		$is->sessionid = $xsessionid;
 		$is->kp3 = $xkp3;
 
-		if($xsessionid & $HTTP_POST_VARS['xappname'])
+		if($xsessionid & $_POST['xappname'])
 		{
-			$method_str = $HTTP_POST_VARS['xappname'] . '.bo' . $HTTP_POST_VARS['xappname'] . '.list_methods';
+			$method_str = $_POST['xappname'] . '.bo' . $_POST['xappname'] . '.list_methods';
 			$server_id ? $is->send($method_str,'xmlrpc',$is->server['server_url']) : '';
 		}
 		else
@@ -123,28 +123,29 @@
 			$server_id ? $is->send('system.listMethods','',$is->server['server_url']) : '';
 		}
 	}
-	elseif($HTTP_POST_VARS['apps'])
+	elseif($_POST['apps'])
 	{
 		$is->sessionid = $xsessionid;
 		$is->kp3 = $xkp3;
 
-		$is->send('system.list_apps','',$is->server['server_url']);
+		$apps = $is->send('system.list_apps','',$is->server['server_url']);
+		_debug_array($apps);
 	}
-	elseif($HTTP_POST_VARS['users'])
+	elseif($_POST['users'])
 	{
 		$is->sessionid = $xsessionid;
 		$is->kp3 = $xkp3;
 
 		$is->send('system.listUsers','',$is->server['server_url']);
 	}
-	elseif($HTTP_POST_VARS['bogus'])
+	elseif($_POST['bogus'])
 	{
 		$is->sessionid = $xsessionid;
 		$is->kp3 = $xkp3;
 
 		$is->send('system.bogus','',$is->server['server_url']);
 	}
-	elseif($HTTP_POST_VARS['addressbook'])
+	elseif($_POST['addressbook'])
 	{
 		$is->sessionid = $xsessionid;
 		$is->kp3 = $xkp3;
@@ -165,7 +166,7 @@
 			$is->server['server_url']
 		);
 	}
-	elseif($HTTP_POST_VARS['calendar'])
+	elseif($_POST['calendar'])
 	{
 		$is->sessionid = $xsessionid;
 		$is->kp3 = $xkp3;
@@ -182,7 +183,7 @@
 			$is->server['server_url']
 		);
 	}
-	elseif($HTTP_POST_VARS['appbyid'])
+	elseif($_POST['appbyid'])
 	{
 		$param = Array(
 			'server'    => $server_id,
@@ -200,6 +201,7 @@
 //		$is->send('phpgwapi.app_registry.get_appbyid',1,$is->server['server_url']);
 	}
 
+	$GLOBALS['phpgw']->template->set_root(PHPGW_APP_TPL);
 	$GLOBALS['phpgw']->template->set_file('interserv','interserv.tpl');
 
 	$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/xmlrpc/interserv.php'));
@@ -225,7 +227,7 @@
 	$GLOBALS['phpgw']->template->set_var('login_type',lang('Server<->Server'));
 	$GLOBALS['phpgw']->template->set_var('note',lang('NOTE: listapps and listusers are disabled by default in xml_functions.php') . '.');
 
-	$GLOBALS['phpgw']->template->set_var('xserver',$HTTP_POST_VARS['xserver'] ? ' checked' : '');
+	$GLOBALS['phpgw']->template->set_var('xserver',$_POST['xserver'] ? ' checked' : '');
 	$GLOBALS['phpgw']->template->set_var('xsessionid',$xsessionid ? $xsessionid : lang('none'));
 	$GLOBALS['phpgw']->template->set_var('xkp3',$xkp3 ? $xkp3 : lang('none'));
 	$GLOBALS['phpgw']->template->set_var('xusername',$xusername);

Modified: people/sigurdne/modules/xmlrpc/trunk/mail.php
===================================================================
--- people/sigurdne/modules/xmlrpc/trunk/mail.php	2009-11-20 10:29:28 UTC (rev 20852)
+++ people/sigurdne/modules/xmlrpc/trunk/mail.php	2009-11-20 10:29:32 UTC (rev 20853)
@@ -4,7 +4,7 @@
 <?php
 include("xmlrpc.inc");
 
-if ($HTTP_POST_VARS["server"]) {
+if ($_POST["server"]) {
 	if ($server=="Userland") {
 		$XP="/RPC2"; $XS="206.204.24.2";
 	} else {

Modified: people/sigurdne/modules/xmlrpc/trunk/phpgw_test.php
===================================================================
--- people/sigurdne/modules/xmlrpc/trunk/phpgw_test.php	2009-11-20 10:29:28 UTC (rev 20852)
+++ people/sigurdne/modules/xmlrpc/trunk/phpgw_test.php	2009-11-20 10:29:32 UTC (rev 20853)
@@ -21,13 +21,13 @@
 
 	include('../header.inc.php');
 
-	if ($HTTP_POST_VARS['method'])
+	if ($_POST['method'])
 	{
-		$f = CreateObject('phpgwapi.xmlrpcmsg',$HTTP_POST_VARS['method'],array(
-			CreateObject('phpgwapi.xmlrpcval',$HTTP_POST_VARS['param'], 'string')
+		$f = CreateObject('phpgwapi.xmlrpcmsg',$_POST['method'],array(
+			CreateObject('phpgwapi.xmlrpcval',$_POST['param'], 'string')
 		));
 		print "<pre>" . htmlentities($f->serialize()) . "</pre>\n";
-		$c = CreateObject('phpgwapi.xmlrpc_client',"/phpgroupware/xmlrpc.php", $HTTP_SERVER_VARS['HTTP_HOST'], 80);
+		$c = CreateObject('phpgwapi.xmlrpc_client',"{$GLOBALS['phpgw_info']['server']['webserver_url']}/xmlrpc.php", $_SERVER['HTTP_HOST'], 80);
 		$c->setDebug(1);
 		$r = $c->send($f);
 		if (!$r)
@@ -37,7 +37,7 @@
 		$v = $r->value();
 		if (!$r->faultCode())
 		{
-			print 'State number ' . $HTTP_POST_VARS['stateno'] . ' is ' . $v->scalarval() . '<br>';
+			print 'State number ' . $_POST['stateno'] . ' is ' . $v->scalarval() . '<br>';
 			// print "<HR>I got this value back<BR><PRE>" .
 			//  htmlentities($r->serialize()). "</PRE><HR>\n";
 		}

Modified: people/sigurdne/modules/xmlrpc/trunk/testsuite.php
===================================================================
--- people/sigurdne/modules/xmlrpc/trunk/testsuite.php	2009-11-20 10:29:28 UTC (rev 20852)
+++ people/sigurdne/modules/xmlrpc/trunk/testsuite.php	2009-11-20 10:29:32 UTC (rev 20853)
@@ -23,7 +23,7 @@
 	require './phpunit.php';
 
 	$DEBUG = 0;
-	$LOCALSERVER = $HTTP_SERVER_VARS['HTTP_HOST'];
+	$LOCALSERVER = $_SERVER['HTTP_HOST'];
 	echo 'Testing: ' . $LOCALSERVER;
 	$suite = new TestSuite;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.