101fa7437bb32498bc5df5ebb40df6327d3f2995
2 /******************************************************************************
4 * Original file can be found on http://xmlrpc-epi.sourceforge.net/ *
5 * in the module xmlrpc-epi-php v0.51 file samples/utils/utils.php *
7 * The Polytechnique.org TEAM *
9 **************************************************************************{{{*/
12 This file is part of, or distributed with, libXMLRPC - a C library for
13 xml-encoded function calls.
15 Author: Dan Libby (dan@libby.com)
16 Epinions.com may be contacted at feedback@epinions-inc.com
20 Copyright 2001 Epinions, Inc.
22 Subject to the following 3 conditions, Epinions, Inc. permits you, free
23 of charge, to (a) use, copy, distribute, modify, perform and display this
24 software and associated documentation files (the "Software"), and (b)
25 permit others to whom the Software is furnished to do so as well.
27 1) The above copyright notice and this permission notice shall be included
28 without modification in all copies or substantial portions of the
31 2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF
32 ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY
33 IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR
34 PURPOSE OR NONINFRINGEMENT.
36 3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
37 SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
38 OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING
39 NEGLIGENCE), EVEN IF EPINIONS, INC. IS AWARE OF THE POSSIBILITY OF SUCH
44 /* xmlrpc utilities (xu)
45 * author: Dan Libby (dan@libby.com)
48 /* generic function to call an http server with post method */
49 function xu_query_http_post($request, $host, $uri, $port, $timeout, $user,
53 if ($host && $uri && $port) {
54 $content_len = strlen($request);
55 $fsockopen = $secure ?
'fsockopen_ssl' : 'fsockopen';
56 $query_fd = $fsockopen($host, $port, $errno, $errstr, 10);
62 $auth = 'Authorization: Basic ' . base64_encode($user . ':' . $pass) . "\r\n";
66 "POST $uri HTTP/1.0\r\n" .
67 "Host: $host:$port\r\n" .
69 "User-Agent: xmlrpc-epi-php/0.2 (PHP)\r\n" .
70 "Content-Type: text/xml\r\n" .
71 "Content-Length: $content_len\r\n" .
72 "Connection: Close\r\n" .
76 fputs($query_fd, $http_request, strlen($http_request));
78 $header_parsed = false
;
79 while (!feof($query_fd)) {
80 $line = fgets($query_fd, 4096);
81 if (!$header_parsed) {
82 if ($line === "\r\n" ||
$line === "\n") {
86 $response_buf .= $line;
97 function find_and_decode_xml($buf)
100 $xml_begin = substr($buf, strpos($buf, '<?xml'));
101 if (strlen($xml_begin)) {
102 $retval = xmlrpc_decode($xml_begin);
110 * @param params a struct containing 3 or more of these key/val pairs:
111 * @param host remote host (required)
112 * @param uri remote uri (required)
113 * @param port remote port (required)
114 * @param method name of method to call
115 * @param args arguments to send (parameters to remote xmlrpc server)
116 * @param timeout timeout in secs. (0 = never)
117 * @param user user name for authentication.
118 * @param pass password for authentication
119 * @param secure secure. wether to use fsockopen_ssl. (requires special php build).
121 function xu_rpc_http_concise($params) {
122 $host = $uri = $port = $method = $args = null
;
123 $timeout = $user = $pass = $secure = null
;
134 if ($host && $uri && $port) {
135 $request_xml = xmlrpc_encode_request($method, $args);
136 $response_buf = xu_query_http_post($request_xml, $host, $uri, $port,
137 $timeout, $user, $pass, $secure);
138 $retval = find_and_decode_xml($response_buf);
143 /*}}}***********************************************************************
144 * Copyright (C) 2003-2006 Polytechnique.org *
145 * http://opensource.polytechnique.org/ *
147 * This program is free software; you can redistribute it and/or modify *
148 * it under the terms of the GNU General Public License as published by *
149 * the Free Software Foundation; either version 2 of the License, or *
150 * (at your option) any later version. *
152 * This program is distributed in the hope that it will be useful, *
153 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
154 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
155 * GNU General Public License for more details. *
157 * You should have received a copy of the GNU General Public License *
158 * along with this program; if not, write to the Free Software *
159 * Foundation, Inc., *
160 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
161 ***************************************************************************/
163 /* taken from : http://fr2.php.net/xml-rpc
164 * Author mboeren@php.net
167 * $client = new xmlrpc_client("http://localhost:7080");
168 * print $client->echo('x')."\n";
169 * print $client->add(1, 3)."\n";
177 function XmlrpcClient($url)
180 $this->urlparts
= parse_url($this->url
);
181 foreach (array('scheme', 'host', 'user', 'pass', 'path', 'query', 'fragment') as $part) {
182 if (!isset($this->urlparts
[$part])) {
183 $this->urlparts
[$part] = null
;
188 function __call($function, $arguments, &$return)
190 $requestprms['host'] = $this->urlparts
['host'];
191 $requestprms['port'] = $this->urlparts
['port'];
192 $requestprms['uri'] = $this->urlparts
['path'];
193 $requestprms['user'] = $this->urlparts
['user'];
194 $requestprms['pass'] = $this->urlparts
['pass'];
195 $requestprms['method'] = $function;
196 $requestprms['args'] = $arguments;
197 $requestprms['timeout'] = 0;
198 $requestprms['secure'] = 0;
200 $result = xu_rpc_http_concise($requestprms);
201 if (is_array($result) && isset($result['faultCode'])) {
202 print('Error in xmlrpc call \''.$function.'\''."\n");
203 print(' code : '.$result['faultCode']."\n");
204 print(' message: '.$result['faultString']."\n");
213 overload('XmlrpcClient');
215 // vim:set et sw=4 sts=4 sws=4: