9a9a589f168c201c7564e40b4e20e29cb7602f22
[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/PhpXmlRpc.php');
48 include_once(__DIR__.'/../src/Value.php');
49 include_once(__DIR__.'/../src/Request.php');
50 include_once(__DIR__.'/../src/Response.php');
51 include_once(__DIR__.'/../src/Client.php');
52 include_once(__DIR__.'/../src/Encoder.php');
53 include_once(__DIR__.'/../src/Helper/Date.php');
54 include_once(__DIR__.'/../src/Helper/Charset.php');
55 include_once(__DIR__.'/../src/Helper/Http.php');
56 include_once(__DIR__.'/../src/Helper/XMLParser.php');
57
58 /* Expose the global variables which used to be defined */
59 PhpXmlRpc\PhpXmlRpc::exportGlobals();
60
61 /* Expose with the old names the classes which have been namespaced */
62
63 class xmlrpcval extends PhpXmlRpc\Value
64 {
65     /**
66      * @deprecated
67      * @param xmlrpcval $o
68      * @return string
69      */
70     public function serializeval($o)
71     {
72         // add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...
73         //if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
74         //{
75         $ar = $o->me;
76         reset($ar);
77         list($typ, $val) = each($ar);
78
79         return '<value>' . $this->serializedata($typ, $val) . "</value>\n";
80         //}
81     }
82
83     /**
84      * @deprecated this code looks like it is very fragile and has not been fixed
85      * for a long long time. Shall we remove it for 2.0?
86      */
87     public function getval()
88     {
89         // UNSTABLE
90         reset($this->me);
91         list($a, $b) = each($this->me);
92         // contributed by I Sofer, 2001-03-24
93         // add support for nested arrays to scalarval
94         // i've created a new method here, so as to
95         // preserve back compatibility
96
97         if (is_array($b)) {
98             @reset($b);
99             while (list($id, $cont) = @each($b)) {
100                 $b[$id] = $cont->scalarval();
101             }
102         }
103
104         // add support for structures directly encoding php objects
105         if (is_object($b)) {
106             $t = get_object_vars($b);
107             @reset($t);
108             while (list($id, $cont) = @each($t)) {
109                 $t[$id] = $cont->scalarval();
110             }
111             @reset($t);
112             while (list($id, $cont) = @each($t)) {
113                 @$b->$id = $cont;
114             }
115         }
116         // end contrib
117         return $b;
118     }
119
120 }
121
122 class xmlrpcmsg extends PhpXmlRpc\Request
123 {
124     /**
125      * Kept the old name even if Request class was renamed, for compatibility.
126      * @deprecated
127      *
128      * @return string
129      */
130     public function kindOf()
131     {
132         return 'msg';
133     }
134 }
135
136 class xmlrpcresp extends PhpXmlRpc\Response
137 {
138 }
139
140 class xmlrpc_client extends PhpXmlRpc\Client
141 {
142 }
143
144 /* Expose as global functions the ones which are now class methods */
145
146 /// Wrong speling, but we are adamant on backwards compatibility!
147 function xmlrpc_encode_entitites($data, $srcEncoding='', $destEncoding='')
148 {
149     return PhpXmlRpc\Helper\Charset::instance()->encodeEntitites($data, $srcEncoding, $destEncoding);
150 }
151
152 function iso8601_encode($timeT, $utc=0)
153 {
154     return PhpXmlRpc\Helper\Date::iso8601_encode($timeT, $utc);
155 }
156
157 function iso8601_decode($iDate, $utc=0)
158 {
159     return PhpXmlRpc\Helper\Date::iso8601_decode($iDate, $utc);
160 }
161
162 function decode_chunked($buffer)
163 {
164     return PhpXmlRpc\Helper\Http::decodeChunked($buffer);
165 }
166
167 function php_xmlrpc_decode($xmlrpcVal, $options=array())
168 {
169     $encoder = new PhpXmlRpc\Encoder();
170     return $encoder->decode($xmlrpcVal, $options);
171 }
172
173 function php_xmlrpc_encode($phpVal, $options=array())
174 {
175     $encoder = new PhpXmlRpc\Encoder();
176     return $encoder->encode($phpVal, $options);
177 }
178
179 function php_xmlrpc_decode_xml($xmlVal, $options=array())
180 {
181     $encoder = new PhpXmlRpc\Encoder();
182     return $encoder->decode_xml($xmlVal, $options);
183 }
184
185 function guess_encoding($httpHeader='', $xmlChunk='', $encodingPrefs=null)
186 {
187 }
188
189 function is_valid_charset($encoding, $validList)
190 {
191     return PhpXmlRpc\Helper\Charset::instance()->is_valid_charset($encoding, $validList);
192 }