unbloat code
[platal.git] / include / platal / xmlrpc-client.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 require_once 'platal/xmlrpc-server.inc.php';
23
24 /* taken from : http://fr2.php.net/xml-rpc
25 * Author mboeren@php.net
26 *
27 * Usage:
28 * $client = new xmlrpc_client("http://localhost:7080");
29 * print $client->echo('x')."\n";
30 * print $client->add(1, 3)."\n";
31 */
32
33 class xmlrpc_client
34 {
35 var $url;
36 var $urlparts;
37
38 function xmlrpc_client($url)
39 {
40 $this->url = $url;
41 $this->urlparts = parse_url($this->url);
42 foreach (array('scheme', 'host', 'user', 'pass', 'path', 'query', 'fragment') as $part) {
43 if (!isset($this->urlparts[$part])) {
44 $this->urlparts[$part] = null;
45 }
46 }
47 }
48
49 function __call($function, $arguments, &$return)
50 {
51 $requestprms['host'] = $this->urlparts['host'];
52 $requestprms['port'] = $this->urlparts['port'];
53 $requestprms['uri'] = $this->urlparts['path'];
54 $requestprms['user'] = $this->urlparts['user'];
55 $requestprms['pass'] = $this->urlparts['pass'];
56 $requestprms['method'] = $function;
57 $requestprms['args'] = $arguments;
58 $requestprms['timeout'] = 0;
59 $requestprms['secure'] = 0;
60
61 $result = xu_rpc_http_concise($requestprms);
62 if (is_array($result) && isset($result['faultCode'])) {
63 print('Error in xmlrpc call \''.$function.'\''."\n");
64 print(' code : '.$result['faultCode']."\n");
65 print(' message: '.$result['faultString']."\n");
66 return false;
67 }
68 $return = $result;
69 return true;
70 }
71
72 }
73
74 overload('xmlrpc_client');
75
76 // vim:set et sw=4 sts=4 sws=4:
77 ?>