7e038340bb282a0663d28c7571357d3bc9d7e2e4
[plcapi.git] / lib / xmlrpc.inc
1 <?php
2 // by Edd Dumbill (C) 1999-2002
3 // <edd@usefulinc.com>
4
5 // Copyright (c) 1999,2000,2002 Edd Dumbill.
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 //    * Redistributions of source code must retain the above copyright
13 //      notice, this list of conditions and the following disclaimer.
14 //
15 //    * Redistributions in binary form must reproduce the above
16 //      copyright notice, this list of conditions and the following
17 //      disclaimer in the documentation and/or other materials provided
18 //      with the distribution.
19 //
20 //    * Neither the name of the "XML-RPC for PHP" nor the names of its
21 //      contributors may be used to endorse or promote products derived
22 //      from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 // REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35 // OF THE POSSIBILITY OF SUCH DAMAGE.
36
37 /******************************************************************************
38  *
39  * *** DEPRECATED ***
40  *
41  * This file is only used to insure backwards compatibility
42  * with the API of the library <= rev. 3
43  *
44  * If it is included, the library will work without any further autoloading
45  *****************************************************************************/
46
47 include_once(__DIR__.'/../src/Client.php');
48 include_once(__DIR__.'/../src/Encoder.php');
49 include_once(__DIR__.'/../src/PhpXmlRpc.php');
50 include_once(__DIR__.'/../src/Request.php');
51 include_once(__DIR__.'/../src/Response.php');
52 include_once(__DIR__.'/../src/Value.php');
53 include_once(__DIR__.'/../src/Helper/Charset.php');
54 include_once(__DIR__.'/../src/Helper/Date.php');
55 include_once(__DIR__.'/../src/Helper/Http.php');
56 include_once(__DIR__.'/../src/Helper/Logger.php');
57 include_once(__DIR__.'/../src/Helper/XMLParser.php');
58
59 use PhpXmlRpc\Client;
60 use PhpXmlRpc\Encoder;
61 use PhpXmlRpc\Request;
62 use PhpXmlRpc\Response;
63 use PhpXmlRpc\Value;
64 use PhpXmlRpc\Helper\Charset;
65 use PhpXmlRpc\Helper\Date;
66 use PhpXmlRpc\Helper\Http;
67 use PhpXmlRpc\Helper\XMLParser;
68
69 /* Expose the global variables which used to be defined */
70 PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1'; // old default
71 PhpXmlRpc\PhpXmlRpc::exportGlobals();
72
73 /* some stuff deprecated enough that we do not want to put it in the new lib version */
74
75 /// @deprecated
76 $GLOBALS['xmlEntities'] = array(
77     'amp'  => '&',
78     'quot' => '"',
79     'lt'   => '<',
80     'gt'   => '>',
81     'apos' => "'"
82 );
83
84 // formulate backslashes for escaping regexp
85 // Not in use anymore since 2.0. Shall we remove it?
86 /// @deprecated
87 $GLOBALS['xmlrpc_backslash'] = chr(92).chr(92);
88
89 /* Expose with the old names the classes which have been namespaced */
90
91 /**
92  * @todo reinstate access to method serializedata ?
93  */
94 class xmlrpcval extends Value
95 {
96     /**
97      * @deprecated
98      * @param xmlrpcval $o
99      * @return string
100      */
101     public function serializeval($o)
102     {
103         // add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
104         //if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
105         //{
106         $ar = $o->me;
107         $val = reset($ar);
108         $typ = key($ar);
109
110         return '<value>' . $this->serializedata($typ, $val) . "</value>\n";
111         //}
112     }
113
114     /**
115      * @deprecated this code looks like it is very fragile and has not been fixed
116      * for a long long time. Shall we remove it for 2.0?
117      */
118     public function getval()
119     {
120         // UNSTABLE
121         $b = reset($this->me);
122         $a = key($this->me);
123         // contributed by I Sofer, 2001-03-24
124         // add support for nested arrays to scalarval
125         // i've created a new method here, so as to
126         // preserve back compatibility
127
128         if (is_array($b)) {
129             foreach($b as $id => $cont) {
130                 $b[$id] = $cont->scalarval();
131             }
132         }
133
134         // add support for structures directly encoding php objects
135         if (is_object($b)) {
136             $t = get_object_vars($b);
137             foreach($t as $id => $cont) {
138                 $t[$id] = $cont->scalarval();
139             }
140             foreach($t as $id => $cont) {
141                 @$b->$id = $cont;
142             }
143         }
144         // end contrib
145         return $b;
146     }
147
148     /// reset functionality added by parent class: same as it would happen if no interface was declared
149     public function count()
150     {
151         return 1;
152     }
153
154     /// reset functionality added by parent class: same as it would happen if no interface was declared
155     public function getIterator()
156     {
157         return new ArrayIterator($this);
158     }
159 }
160
161 /**
162  * @todo reinstate access to method parseResponseHeaders ?
163  */
164 class xmlrpcmsg extends Request
165 {
166 }
167
168 class xmlrpcresp extends Response
169 {
170 }
171
172 /**
173  * @todo reinstate access to methods sendPayloadHTTP10, sendPayloadHTTPS, sendPayloadCURL, _try_multicall ?
174  */
175 class xmlrpc_client extends Client
176 {
177 }
178
179 /* Expose as global functions the ones which are now class methods */
180
181 /// Wrong speling, but we are adamant on backwards compatibility!
182 function xmlrpc_encode_entitites($data, $srcEncoding='', $destEncoding='')
183 {
184     return Charset::instance()->encodeEntities($data, $srcEncoding, $destEncoding);
185 }
186
187 function iso8601_encode($timeT, $utc=0)
188 {
189     return Date::iso8601Encode($timeT, $utc);
190 }
191
192 function iso8601_decode($iDate, $utc=0)
193 {
194     return Date::iso8601Decode($iDate, $utc);
195 }
196
197 function decode_chunked($buffer)
198 {
199     return Http::decodeChunked($buffer);
200 }
201
202 function php_xmlrpc_decode($xmlrpcVal, $options=array())
203 {
204     $encoder = new Encoder();
205     return $encoder->decode($xmlrpcVal, $options);
206 }
207
208 function php_xmlrpc_encode($phpVal, $options=array())
209 {
210     $encoder = new Encoder();
211     return $encoder->encode($phpVal, $options);
212 }
213
214 function php_xmlrpc_decode_xml($xmlVal, $options=array())
215 {
216     $encoder = new Encoder();
217     return $encoder->decodeXml($xmlVal, $options);
218 }
219
220 function guess_encoding($httpHeader='', $xmlChunk='', $encodingPrefs=null)
221 {
222     return XMLParser::guessEncoding($httpHeader, $xmlChunk, $encodingPrefs);
223 }
224
225 function has_encoding($xmlChunk)
226 {
227     return XMLParser::hasEncoding($xmlChunk);
228 }
229
230 function is_valid_charset($encoding, $validList)
231 {
232     return Charset::instance()->isValidCharset($encoding, $validList);
233 }