1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpXmlRpc; |
4
|
|
|
|
5
|
|
|
use PhpXmlRpc\Helper\Charset; |
6
|
|
|
use PhpXmlRpc\Helper\Http; |
7
|
|
|
use PhpXmlRpc\Helper\XMLParser; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Manages global configuration for operation of the library. |
11
|
|
|
*/ |
12
|
|
|
class PhpXmlRpc |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var int[] |
16
|
|
|
*/ |
17
|
|
|
static public $xmlrpcerr = array( |
18
|
|
|
'unknown_method' => 1, |
19
|
|
|
/// @deprecated. left in for BC |
20
|
|
|
'invalid_return' => 2, |
21
|
|
|
'incorrect_params' => 3, |
22
|
|
|
'introspect_unknown' => 4, |
23
|
|
|
'http_error' => 5, |
24
|
|
|
'no_data' => 6, |
25
|
|
|
'no_ssl' => 7, |
26
|
|
|
'curl_fail' => 8, |
27
|
|
|
'invalid_request' => 15, |
28
|
|
|
'no_curl' => 16, |
29
|
|
|
'server_error' => 17, |
30
|
|
|
'multicall_error' => 18, |
31
|
|
|
'multicall_notstruct' => 9, |
32
|
|
|
'multicall_nomethod' => 10, |
33
|
|
|
'multicall_notstring' => 11, |
34
|
|
|
'multicall_recursion' => 12, |
35
|
|
|
'multicall_noparams' => 13, |
36
|
|
|
'multicall_notarray' => 14, |
37
|
|
|
'no_http2' => 19, |
38
|
|
|
// the following 3 are meant to give greater insight than 'invalid_return'. They use the same code for BC, |
39
|
|
|
// but you can override their value in your own code |
40
|
|
|
'invalid_xml' => 2, |
41
|
|
|
'xml_not_compliant' => 2, |
42
|
|
|
'xml_parsing_error' => 2, |
43
|
|
|
|
44
|
|
|
/// @todo verify: can these conflict with $xmlrpcerrxml? |
45
|
|
|
'cannot_decompress' => 103, |
46
|
|
|
'decompress_fail' => 104, |
47
|
|
|
'dechunk_fail' => 105, |
48
|
|
|
'server_cannot_decompress' => 106, |
49
|
|
|
'server_decompress_fail' => 107, |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string[] |
54
|
|
|
*/ |
55
|
|
|
static public $xmlrpcstr = array( |
56
|
|
|
'unknown_method' => 'Unknown method', |
57
|
|
|
/// @deprecated. left in for BC |
58
|
|
|
'invalid_return' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)', |
59
|
|
|
'incorrect_params' => 'Incorrect parameters passed to method', |
60
|
|
|
'introspect_unknown' => "Can't introspect: method unknown", |
61
|
|
|
'http_error' => "Didn't receive 200 OK from remote server", |
62
|
|
|
'no_data' => 'No data received from server', |
63
|
|
|
'no_ssl' => 'No SSL support compiled in', |
64
|
|
|
'curl_fail' => 'CURL error', |
65
|
|
|
'invalid_request' => 'Invalid request payload', |
66
|
|
|
'no_curl' => 'No CURL support compiled in', |
67
|
|
|
'server_error' => 'Internal server error', |
68
|
|
|
'multicall_error' => 'Received from server invalid multicall response', |
69
|
|
|
'multicall_notstruct' => 'system.multicall expected struct', |
70
|
|
|
'multicall_nomethod' => 'Missing methodName', |
71
|
|
|
'multicall_notstring' => 'methodName is not a string', |
72
|
|
|
'multicall_recursion' => 'Recursive system.multicall forbidden', |
73
|
|
|
'multicall_noparams' => 'Missing params', |
74
|
|
|
'multicall_notarray' => 'params is not an array', |
75
|
|
|
'no_http2' => 'No HTTP/2 support compiled in', |
76
|
|
|
// the following 3 are meant to give greater insight than 'invalid_return'. They use the same string for BC, |
77
|
|
|
// but you can override their value in your own code |
78
|
|
|
'invalid_xml' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)', |
79
|
|
|
'xml_not_compliant' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)', |
80
|
|
|
'xml_parsing_error' => 'Invalid response payload (you can use the setDebug method to allow analysis of the response)', |
81
|
|
|
|
82
|
|
|
'cannot_decompress' => 'Received from server compressed HTTP and cannot decompress', |
83
|
|
|
'decompress_fail' => 'Received from server invalid compressed HTTP', |
84
|
|
|
'dechunk_fail' => 'Received from server invalid chunked HTTP', |
85
|
|
|
'server_cannot_decompress' => 'Received from client compressed HTTP request and cannot decompress', |
86
|
|
|
'server_decompress_fail' => 'Received from client invalid compressed HTTP request', |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var string |
91
|
|
|
* The charset encoding used by the server for received requests and by the client for received responses when |
92
|
|
|
* received charset cannot be determined and mbstring extension is not enabled. |
93
|
|
|
*/ |
94
|
|
|
public static $xmlrpc_defencoding = "UTF-8"; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var string[] |
98
|
|
|
* The list of preferred encodings used by the server for requests and by the client for responses to detect the |
99
|
|
|
* charset of the received payload when |
100
|
|
|
* - the charset cannot be determined by looking at http headers, xml declaration or BOM |
101
|
|
|
* - mbstring extension is enabled |
102
|
|
|
*/ |
103
|
|
|
public static $xmlrpc_detectencodings = array(); |
104
|
|
|
|
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.9.5"; |
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
|
|
|
*/ |
132
|
|
|
public static $xmlrpcerrxml = 100; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @var bool |
136
|
|
|
* Set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values |
137
|
|
|
*/ |
138
|
|
|
public static $xmlrpc_null_extension = false; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @var bool |
142
|
|
|
* Set to TRUE to make the library use DateTime objects instead of strings for all values parsed from incoming XML. |
143
|
2 |
|
* NB: if the received strings are not parseable as dates, NULL will be returned. To prevent that, enable as |
144
|
|
|
* well `xmlrpc_reject_invalid_values`, so that invalid dates will be rejected by the library |
145
|
2 |
|
*/ |
146
|
2 |
|
public static $xmlrpc_return_datetimes = false; |
147
|
2 |
|
|
148
|
2 |
|
/** |
149
|
2 |
|
* @var bool |
150
|
|
|
* Set to TRUE to make the library reject incoming xml which uses invalid data for xml-rpc elements, such |
151
|
|
|
* as base64 strings which can not be decoded, dateTime strings which do not represent a valid date, invalid bools, |
152
|
2 |
|
* floats and integers, method names with forbidden characters, or struct members missing the value or name |
153
|
|
|
*/ |
154
|
|
|
public static $xmlrpc_reject_invalid_values = false; |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @var bool |
158
|
|
|
* Set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/> |
159
|
|
|
*/ |
160
|
|
|
public static $xmlrpc_null_apache_encoding = false; |
161
|
|
|
|
162
|
|
|
public static $xmlrpc_null_apache_encoding_ns = "http://ws.apache.org/xmlrpc/namespaces/extensions"; |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @var int |
166
|
|
|
* Number of decimal digits used to serialize Double values. |
167
|
|
|
* @todo rename :'-( |
168
|
|
|
*/ |
169
|
|
|
public static $xmlpc_double_precision = 128; |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @var string |
173
|
|
|
* Used to validate received date values. Alter this if the server/client you are communicating with uses date |
174
|
|
|
* formats non-conformant with the spec |
175
|
|
|
* NB: atm, the Date helper uses this regexp and expects to find matches in a specific order |
176
|
|
|
*/ |
177
|
|
|
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)$/'; |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @var string |
181
|
|
|
* Used to validate received integer values. Alter this if the server/client you are communicating with uses |
182
|
|
|
* formats non-conformant with the spec. |
183
|
|
|
* We keep in spaces for BC, even though they are forbidden by the spec. |
184
|
|
|
* NB: the string should not match any data which php can not successfully cast to an integer |
185
|
|
|
*/ |
186
|
|
|
public static $xmlrpc_int_format = '/^[ \t]*[+-]?[0-9]+[ \t]*$/'; |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @var string |
190
|
|
|
* Used to validate received double values. Alter this if the server/client you are communicating with uses |
191
|
|
|
* formats non-conformant with the spec, e.g. with leading/trailing spaces/tabs/newlines. |
192
|
|
|
* We keep in spaces for BC, even though they are forbidden by the spec. |
193
|
|
|
* NB: the string should not match any data which php can not successfully cast to a float |
194
|
|
|
*/ |
195
|
|
|
public static $xmlrpc_double_format = '/^[ \t]*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?[ \t]*$/'; |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @var string |
199
|
|
|
* Used to validate received methodname values. |
200
|
|
|
* According to the spec: "The string may only contain identifier characters, upper and lower-case A-Z, the numeric |
201
|
|
|
* characters, 0-9, underscore, dot, colon and slash". |
202
|
|
|
* We keep in spaces for BC, even though they are forbidden by the spec. |
203
|
|
|
*/ |
204
|
|
|
public static $xmlrpc_methodname_format = '|^[ \t]*[a-zA-Z0-9_.:/]+[ \t]*$|'; |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* A function to be used for compatibility with legacy code: it creates all global variables which used to be declared, |
208
|
|
|
* such as library version etc... |
209
|
|
|
* @return void |
210
|
|
|
*/ |
211
|
|
|
public static function exportGlobals() |
212
|
|
|
{ |
213
|
|
|
$reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc'); |
214
|
|
|
foreach ($reflection->getStaticProperties() as $name => $value) { |
215
|
|
|
$GLOBALS[$name] = $value; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
// NB: all the variables exported into the global namespace below here do NOT guarantee 100% compatibility, |
219
|
|
|
// as they are NOT reimported back during calls to importGlobals() |
220
|
|
|
|
221
|
|
|
$reflection = new \ReflectionClass('PhpXmlRpc\Value'); |
222
|
|
|
foreach ($reflection->getStaticProperties() as $name => $value) { |
223
|
|
|
if (!in_array($name, array('logger', 'charsetEncoder'))) { |
224
|
|
|
$GLOBALS[$name] = $value; |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
$parser = new Helper\XMLParser(); |
229
|
|
|
$reflection = new \ReflectionClass('PhpXmlRpc\Helper\XMLParser'); |
230
|
|
|
foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $name => $value) { |
231
|
|
|
if (in_array($value->getName(), array('xmlrpc_valid_parents'))) |
232
|
|
|
{ |
233
|
|
|
$GLOBALS[$value->getName()] = $value->getValue($parser); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
$charset = Charset::instance(); |
238
|
|
|
$GLOBALS['xml_iso88591_Entities'] = $charset->getEntities('iso88591'); |
|
|
|
|
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* A function to be used for compatibility with legacy code: it gets the values of all global variables which used |
243
|
|
|
* to be declared, such as library version etc... and sets them to php classes. |
244
|
|
|
* It should be used by code which changed the values of those global variables to alter the working of the library. |
245
|
|
|
* Example code: |
246
|
|
|
* 1. include xmlrpc.inc |
247
|
|
|
* 2. set the values, e.g. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; |
248
|
|
|
* 3. import them: PhpXmlRpc\PhpXmlRpc::importGlobals(); |
249
|
|
|
* 4. run your own code. |
250
|
|
|
* |
251
|
|
|
* @return void |
252
|
|
|
*/ |
253
|
|
|
public static function importGlobals() |
254
|
|
|
{ |
255
|
|
|
$reflection = new \ReflectionClass('PhpXmlRpc\PhpXmlRpc'); |
256
|
|
|
$staticProperties = $reflection->getStaticProperties(); |
257
|
|
|
foreach ($staticProperties as $name => $value) { |
258
|
|
|
if (isset($GLOBALS[$name])) { |
259
|
|
|
self::$$name = $GLOBALS[$name]; |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Inject a logger into all classes of the PhpXmlRpc library which use one |
266
|
|
|
* |
267
|
|
|
* @param $logger |
268
|
|
|
* @return void |
269
|
|
|
*/ |
270
|
|
|
public static function setLogger($logger) |
271
|
|
|
{ |
272
|
|
|
Charset::setLogger($logger); |
273
|
|
|
Client::setLogger($logger); |
274
|
|
|
Encoder::setLogger($logger); |
275
|
|
|
Http::setLogger($logger); |
276
|
|
|
Request::setLogger($logger); |
277
|
|
|
Server::setLogger($logger); |
278
|
|
|
Value::setLogger($logger); |
279
|
|
|
Wrapper::setLogger($logger); |
280
|
|
|
XMLParser::setLogger($logger); |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
|