1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpXmlRpc; |
4
|
|
|
|
5
|
|
|
use PhpXmlRpc\Helper\Charset; |
6
|
|
|
use PhpXmlRpc\Helper\Http; |
7
|
|
|
use PhpXmlRpc\Helper\Interop; |
8
|
|
|
use PhpXmlRpc\Helper\XMLParser; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Manages global configuration for operation of the library. |
12
|
|
|
*/ |
13
|
|
|
class PhpXmlRpc |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var int[] |
17
|
|
|
*/ |
18
|
|
|
public static $xmlrpcerr = array( |
19
|
|
|
'unknown_method' => 1, // server |
20
|
|
|
/// @deprecated. left in for BC |
21
|
|
|
'invalid_return' => 2, // client |
22
|
|
|
'incorrect_params' => 3, // server |
23
|
|
|
'introspect_unknown' => 4, // server |
24
|
|
|
'http_error' => 5, // client |
25
|
|
|
'no_data' => 6, // client |
26
|
|
|
'no_ssl' => 7, // client |
27
|
|
|
'curl_fail' => 8, // client |
28
|
|
|
'invalid_request' => 15, // server |
29
|
|
|
'no_curl' => 16, // client |
30
|
|
|
'server_error' => 17, // server |
31
|
|
|
'multicall_error' => 18, // client |
32
|
|
|
'multicall_notstruct' => 9, // client |
33
|
|
|
'multicall_nomethod' => 10, // client |
34
|
|
|
'multicall_notstring' => 11, // client |
35
|
|
|
'multicall_recursion' => 12, // client |
36
|
|
|
'multicall_noparams' => 13, // client |
37
|
|
|
'multicall_notarray' => 14, // client |
38
|
|
|
'no_http2' => 19, // client |
39
|
|
|
'unsupported_option' => 20, // client |
40
|
|
|
// the following 3 are meant to give greater insight than 'invalid_return'. They use the same code for BC, |
41
|
|
|
// but you can override their value in your own code |
42
|
|
|
'invalid_xml' => 2, // client (and server, when interop mode is enabled) |
43
|
|
|
'xml_not_compliant' => 2, // client |
44
|
|
|
'xml_parsing_error' => 2, // client |
45
|
|
|
|
46
|
|
|
'cannot_decompress' => 153, |
47
|
|
|
'decompress_fail' => 154, |
48
|
|
|
'dechunk_fail' => 155, |
49
|
|
|
'server_cannot_decompress' => 156, |
50
|
|
|
'server_decompress_fail' => 157, |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string[] |
55
|
|
|
*/ |
56
|
|
|
public static $xmlrpcstr = array( |
57
|
|
|
'unknown_method' => 'Unknown method', |
58
|
|
|
/// @deprecated. left in for BC |
59
|
|
|
'invalid_return' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)', |
60
|
|
|
'incorrect_params' => 'Incorrect parameters passed to method', |
61
|
|
|
'introspect_unknown' => "Can't introspect: method unknown", |
62
|
|
|
'http_error' => "Didn't receive 200 OK from remote server", |
63
|
|
|
'no_data' => 'No data received from server', |
64
|
|
|
'no_ssl' => 'No SSL support compiled in', |
65
|
|
|
'curl_fail' => 'CURL error', |
66
|
|
|
'invalid_request' => 'Invalid request payload', |
67
|
|
|
'no_curl' => 'No CURL support compiled in', |
68
|
|
|
'server_error' => 'Internal server error', |
69
|
|
|
'multicall_error' => 'Received from server invalid multicall response', |
70
|
|
|
'multicall_notstruct' => 'system.multicall expected struct', |
71
|
|
|
'multicall_nomethod' => 'Missing methodName', |
72
|
|
|
'multicall_notstring' => 'methodName is not a string', |
73
|
|
|
'multicall_recursion' => 'Recursive system.multicall forbidden', |
74
|
|
|
'multicall_noparams' => 'Missing params', |
75
|
|
|
'multicall_notarray' => 'params is not an array', |
76
|
|
|
'no_http2' => 'No HTTP/2 support compiled in', |
77
|
|
|
'unsupported_option' => 'Some client option is not supported with the transport method currently in use', |
78
|
|
|
// the following 3 are meant to give greater insight than 'invalid_return'. They use the same string for BC, |
79
|
|
|
// but you can override their value in your own code |
80
|
|
|
'invalid_xml' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)', |
81
|
|
|
'xml_not_compliant' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)', |
82
|
|
|
'xml_parsing_error' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)', |
83
|
|
|
|
84
|
|
|
'cannot_decompress' => 'Received from server compressed HTTP and cannot decompress', |
85
|
|
|
'decompress_fail' => 'Received from server invalid compressed HTTP', |
86
|
|
|
'dechunk_fail' => 'Received from server invalid chunked HTTP', |
87
|
|
|
'server_cannot_decompress' => 'Received from client compressed HTTP request and cannot decompress', |
88
|
|
|
'server_decompress_fail' => 'Received from client invalid compressed HTTP request', |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var string |
93
|
|
|
* The charset encoding used by the server for received requests and by the client for received responses when |
94
|
|
|
* received charset cannot be determined and mbstring extension is not enabled. |
95
|
|
|
*/ |
96
|
|
|
public static $xmlrpc_defencoding = "UTF-8"; |
97
|
|
|
/** |
98
|
|
|
* @var string[] |
99
|
|
|
* The list of preferred encodings used by the server for requests and by the client for responses to detect the |
100
|
|
|
* charset of the received payload when |
101
|
|
|
* - the charset cannot be determined by looking at http headers, xml declaration or BOM |
102
|
|
|
* - mbstring extension is enabled |
103
|
|
|
*/ |
104
|
|
|
public static $xmlrpc_detectencodings = array(); |
105
|
|
|
/** |
106
|
|
|
* @var string |
107
|
|
|
* The encoding used internally by PHP. |
108
|
|
|
* String values received as xml will be converted to this, and php strings will be converted to xml as if |
109
|
|
|
* having been coded with this. |
110
|
|
|
* Valid also when defining names of xml-rpc methods |
111
|
|
|
*/ |
112
|
|
|
public static $xmlrpc_internalencoding = "UTF-8"; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var string |
116
|
|
|
*/ |
117
|
|
|
public static $xmlrpcName = "XML-RPC for PHP"; |
118
|
|
|
/** |
119
|
|
|
* @var string |
120
|
|
|
*/ |
121
|
|
|
public static $xmlrpcVersion = "4.11.3"; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @var int |
125
|
|
|
* Let user errors start at 800 |
126
|
|
|
*/ |
127
|
|
|
public static $xmlrpcerruser = 800; |
128
|
|
|
/** |
129
|
|
|
* @var int |
130
|
|
|
* Let XML parse errors start at 100. |
131
|
|
|
* The final code will be 100 + X, with X coming from https://www.php.net/manual/en/xml.error-codes.php. |
132
|
|
|
* Values are known to go from 1 (XML_ERROR_NO_MEMORY) to 21 (XML_ERROR_EXTERNAL_ENTITY_HANDLING). |
133
|
|
|
* Used only server-side |
134
|
|
|
*/ |
135
|
|
|
public static $xmlrpcerrxml = 100; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @var bool |
139
|
|
|
* Set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values |
140
|
|
|
*/ |
141
|
|
|
public static $xmlrpc_null_extension = false; |
142
|
|
|
|
143
|
2 |
|
/** |
144
|
|
|
* @var bool |
145
|
2 |
|
* Set to TRUE to make the library use DateTime objects instead of strings for all values parsed from incoming XML. |
146
|
2 |
|
* NB: if the received strings are not parseable as dates, NULL will be returned. To prevent that, enable as |
147
|
2 |
|
* well `xmlrpc_reject_invalid_values`, so that invalid dates will be rejected by the library |
148
|
2 |
|
*/ |
149
|
2 |
|
public static $xmlrpc_return_datetimes = false; |
150
|
|
|
|
151
|
|
|
/** |
152
|
2 |
|
* @var bool |
153
|
|
|
* Set to TRUE to make the library reject incoming xml which uses invalid data for xml-rpc elements, such |
154
|
|
|
* as base64 strings which can not be decoded, dateTime strings which do not represent a valid date, invalid bools, |
155
|
|
|
* floats and integers, method names with forbidden characters, or struct members missing the value or name |
156
|
|
|
*/ |
157
|
|
|
public static $xmlrpc_reject_invalid_values = false; |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @var bool |
161
|
|
|
* Set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/> |
162
|
|
|
*/ |
163
|
|
|
public static $xmlrpc_null_apache_encoding = false; |
164
|
|
|
|
165
|
|
|
public static $xmlrpc_null_apache_encoding_ns = "http://ws.apache.org/xmlrpc/namespaces/extensions"; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @var int |
169
|
|
|
* Number of decimal digits used to serialize Double values. |
170
|
|
|
* @todo rename :'-( |
171
|
|
|
*/ |
172
|
|
|
public static $xmlpc_double_precision = 128; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @var string |
176
|
|
|
* Used to validate received date values. Alter this if the server/client you are communicating with uses date |
177
|
|
|
* formats non-conformant with the spec |
178
|
|
|
* NB: the string should not match any data which php can not successfully use in a DateTime object constructor call |
179
|
|
|
* NB: atm, the Date helper uses this regexp and expects to find matches in a specific order |
180
|
|
|
*/ |
181
|
|
|
public static $xmlrpc_datetime_format = '/^([0-9]{4})(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-4]):([0-5][0-9]):([0-5][0-9]|60)$/'; |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @var string |
185
|
|
|
* Used to validate received integer values. Alter this if the server/client you are communicating with uses |
186
|
|
|
* formats non-conformant with the spec. |
187
|
|
|
* We keep in spaces for BC, even though they are forbidden by the spec. |
188
|
|
|
* NB: the string should not match any data which php can not successfully cast to an integer |
189
|
|
|
*/ |
190
|
|
|
public static $xmlrpc_int_format = '/^[ \t]*[+-]?[0-9]+[ \t]*$/'; |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @var string |
194
|
|
|
* Used to validate received double values. Alter this if the server/client you are communicating with uses |
195
|
|
|
* formats non-conformant with the spec, e.g. with leading/trailing spaces/tabs/newlines. |
196
|
|
|
* We keep in spaces for BC, even though they are forbidden by the spec. |
197
|
|
|
* NB: the string should not match any data which php can not successfully cast to a float |
198
|
|
|
*/ |
199
|
|
|
public static $xmlrpc_double_format = '/^[ \t]*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?[ \t]*$/'; |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @var string |
203
|
|
|
* Used to validate received methodname values. |
204
|
|
|
* According to the spec: "The string may only contain identifier characters, upper and lower-case A-Z, the numeric |
205
|
|
|
* characters, 0-9, underscore, dot, colon and slash". |
206
|
|
|
* We keep in leading and trailing spaces for BC, even though they are forbidden by the spec. |
207
|
|
|
* But what about "identifier characters"? Is that meant to be 'identifier characters: upper and lower-case A-Z, ...' |
208
|
|
|
* or something else? If the latter, there is no consensus across programming languages about what is a valid |
209
|
|
|
* identifier character. PHP has one of the most crazy definitions of what is a valid identifier character, allowing |
210
|
|
|
* _bytes_ in range x80-xff, without even specifying a character set (and then lowercasing anyway in some cases)... |
211
|
|
|
*/ |
212
|
|
|
public static $xmlrpc_methodname_format = '|^[ \t]*[a-zA-Z0-9_.:/]+[ \t]*$|'; |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @var bool |
216
|
|
|
* Set this to false to have a warning added to the log whenever user code uses a deprecated method/parameter/property |
217
|
|
|
*/ |
218
|
|
|
public static $xmlrpc_silence_deprecations = true; |
219
|
|
|
|
220
|
|
|
// *** BC layer *** |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Inject a logger into all classes of the PhpXmlRpc library which use one |
224
|
|
|
* |
225
|
|
|
* @param $logger |
226
|
|
|
* @return void |
227
|
|
|
*/ |
228
|
|
|
public static function setLogger($logger) |
229
|
|
|
{ |
230
|
|
|
Charset::setLogger($logger); |
231
|
|
|
Client::setLogger($logger); |
232
|
|
|
Encoder::setLogger($logger); |
233
|
|
|
Http::setLogger($logger); |
234
|
|
|
Request::setLogger($logger); |
235
|
|
|
Server::setLogger($logger); |
236
|
|
|
Value::setLogger($logger); |
237
|
|
|
Wrapper::setLogger($logger); |
238
|
|
|
XMLParser::setLogger($logger); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Makes the library use the error codes detailed at https://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php |
243
|
|
|
* |
244
|
|
|
* @return void |
245
|
|
|
* |
246
|
|
|
* @todo feature creep - allow switching back to the original set of codes; querying the current mode |
247
|
|
|
*/ |
248
|
|
|
public static function useInteropFaults() |
249
|
|
|
{ |
250
|
|
|
self::$xmlrpcerr = Interop::$xmlrpcerr; |
251
|
|
|
|
252
|
|
|
self::$xmlrpcerruser = -Interop::$xmlrpcerruser; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
public static function isUsingInteropFaults() |
256
|
|
|
{ |
257
|
|
|
return self::$xmlrpcerruser == -Interop::$xmlrpcerruser; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* A function to be used for compatibility with legacy code: it creates all global variables which used to be declared, |
262
|
|
|
* such as library version etc... |
263
|
|
|
* @return void |
264
|
|
|
* |
265
|
|
|
* @deprecated |
266
|
|
|
*/ |
267
|
|
|
public static function exportGlobals() |
268
|
|
|
{ |
269
|
|
|
$reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc'); |
270
|
|
|
foreach ($reflection->getStaticProperties() as $name => $value) { |
271
|
|
|
if (!in_array($name, array('xmlrpc_return_datetimes', 'xmlrpc_reject_invalid_values', 'xmlrpc_datetime_format', |
272
|
|
|
'xmlrpc_int_format', 'xmlrpc_double_format', 'xmlrpc_methodname_format', 'xmlrpc_silence_deprecations'))) { |
273
|
|
|
$GLOBALS[$name] = $value; |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
// NB: all the variables exported into the global namespace below here do NOT guarantee 100% compatibility, |
278
|
|
|
// as they are NOT reimported back during calls to importGlobals() |
279
|
|
|
|
280
|
|
|
$reflection = new \ReflectionClass('PhpXmlRpc\Value'); |
281
|
|
|
foreach ($reflection->getStaticProperties() as $name => $value) { |
282
|
|
|
if (!in_array($name, array('logger', 'charsetEncoder'))) { |
283
|
|
|
$GLOBALS[$name] = $value; |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/// @todo mke it possible to inject the XMLParser and Charset, as we do in other classes |
288
|
|
|
|
289
|
|
|
$parser = new Helper\XMLParser(); |
290
|
|
|
$GLOBALS['xmlrpc_valid_parents'] = $parser->xmlrpc_valid_parents; |
291
|
|
|
|
292
|
|
|
$charset = Charset::instance(); |
293
|
|
|
$GLOBALS['xml_iso88591_Entities'] = $charset->getEntities('iso88591'); |
|
|
|
|
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* A function to be used for compatibility with legacy code: it gets the values of all global variables which used |
298
|
|
|
* to be declared, such as library version etc... and sets them to php classes. |
299
|
|
|
* It should be used by code which changed the values of those global variables to alter the working of the library. |
300
|
|
|
* Example code: |
301
|
|
|
* 1. include xmlrpc.inc |
302
|
|
|
* 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; |
303
|
|
|
* 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals(); |
304
|
|
|
* 4. run your own code. |
305
|
|
|
* |
306
|
|
|
* @return void |
307
|
|
|
* |
308
|
|
|
* @deprecated |
309
|
|
|
* |
310
|
|
|
* @todo this function does not import back xmlrpc_valid_parents and xml_iso88591_Entities |
311
|
|
|
*/ |
312
|
|
|
public static function importGlobals() |
313
|
|
|
{ |
314
|
|
|
$reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc'); |
315
|
|
|
foreach ($reflection->getStaticProperties() as $name => $value) { |
316
|
|
|
if (!in_array($name, array('xmlrpc_return_datetimes', 'xmlrpc_reject_invalid_values', 'xmlrpc_datetime_format', |
317
|
|
|
'xmlrpc_int_format', 'xmlrpc_double_format', 'xmlrpc_methodname_format', 'xmlrpc_silence_deprecations'))) |
318
|
|
|
{ |
319
|
|
|
if (isset($GLOBALS[$name])) { |
320
|
|
|
self::$$name = $GLOBALS[$name]; |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
} |
325
|
|
|
} |
326
|
|
|
|