/** * @access private */ function serializedata($typ, $val, $charset_encoding = '') { $rs = ''; switch (@$GLOBALS['xmlrpcTypes'][$typ]) { case 1: switch ($typ) { case $GLOBALS['xmlrpcBase64']: $rs .= "<{$typ}>" . base64_encode($val) . "</{$typ}>"; break; case $GLOBALS['xmlrpcBoolean']: $rs .= "<{$typ}>" . ($val ? '1' : '0') . "</{$typ}>"; break; case $GLOBALS['xmlrpcString']: // G. Giunta 2005/2/13: do NOT use htmlentities, since // it will produce named html entities, which are invalid xml $rs .= "<{$typ}>" . xmlrpc_encode_entitites($val, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</{$typ}>"; break; case $GLOBALS['xmlrpcInt']: case $GLOBALS['xmlrpcI4']: $rs .= "<{$typ}>" . (int) $val . "</{$typ}>"; break; case $GLOBALS['xmlrpcDouble']: // avoid using standard conversion of float to string because it is locale-dependent, // and also because the xmlrpc spec forbids exponential notation. // sprintf('%F') could be most likely ok but it fails eg. on 2e-14. // The code below tries its best at keeping max precision while avoiding exp notation, // but there is of course no limit in the number of decimal places to be used... $rs .= "<{$typ}>" . preg_replace('/\\.?0+$/', '', number_format((double) $val, 128, '.', '')) . "</{$typ}>"; break; case $GLOBALS['xmlrpcDateTime']: if (is_string($val)) { $rs .= "<{$typ}>{$val}</{$typ}>"; } else { if (is_a($val, 'DateTime')) { $rs .= "<{$typ}>" . $val->format('Ymd\\TH:i:s') . "</{$typ}>"; } else { if (is_int($val)) { $rs .= "<{$typ}>" . strftime("%Y%m%dT%H:%M:%S", $val) . "</{$typ}>"; } else { // not really a good idea here: but what shall we output anyway? left for backward compat... $rs .= "<{$typ}>{$val}</{$typ}>"; } } } break; case $GLOBALS['xmlrpcNull']: if ($GLOBALS['xmlrpc_null_apache_encoding']) { $rs .= "<ex:nil/>"; } else { $rs .= "<nil/>"; } break; default: // no standard type value should arrive here, but provide a possibility // for xmlrpcvals of unknown type... $rs .= "<{$typ}>{$val}</{$typ}>"; } break; case 3: // struct if ($this->_php_class) { $rs .= '<struct php_class="' . $this->_php_class . "\">\n"; } else { $rs .= "<struct>\n"; } foreach ($val as $key2 => $val2) { $rs .= '<member><name>' . xmlrpc_encode_entitites($key2, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</name>\n"; //$rs.=$this->serializeval($val2); $rs .= $val2->serialize($charset_encoding); $rs .= "</member>\n"; } $rs .= '</struct>'; break; case 2: // array $rs .= "<array>\n<data>\n"; for ($i = 0; $i < count($val); $i++) { //$rs.=$this->serializeval($val[$i]); $rs .= $val[$i]->serialize($charset_encoding); } $rs .= "</data>\n</array>"; break; default: break; } return $rs; }
/** * Return a string with the serialized representation of all debug info * @param string $charset_encoding the target charset encoding for the serialization * @return string an XML comment (or two) */ function serializeDebug($charset_encoding = '') { // Tough encoding problem: which internal charset should we assume for debug info? // It might contain a copy of raw data received from client, ie with unknown encoding, // intermixed with php generated data and user generated data... // so we split it: system debug is base 64 encoded, // user debug info should be encoded by the end user using the INTERNAL_ENCODING $out = ''; if ($this->debug_info != '') { $out .= "<!-- SERVER DEBUG INFO (BASE64 ENCODED):\n" . base64_encode($this->debug_info) . "\n-->\n"; } if ($GLOBALS['_xmlrpc_debuginfo'] != '') { $out .= "<!-- DEBUG INFO:\n" . xmlrpc_encode_entitites(str_replace('--', '_-', $GLOBALS['_xmlrpc_debuginfo']), $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "\n-->\n"; // NB: a better solution MIGHT be to use CDATA, but we need to insert it // into return payload AFTER the beginning tag //$out .= "<![CDATA[ DEBUG INFO:\n\n" . str_replace(']]>', ']_]_>', $GLOBALS['_xmlrpc_debuginfo']) . "\n]]>\n"; } return $out; }
function serializedata($typ, $val) { $rs = ''; switch (@$GLOBALS['xmlrpcTypes'][$typ]) { case 3: // struct if ($this->_php_class) { $rs .= '<struct php_class="' . $this->_php_class . "\">\n"; } else { $rs .= "<struct>\n"; } foreach ($val as $key2 => $val2) { $rs .= "<member><name>{$key2}</name>\n"; //$rs.=$this->serializeval($val2); $rs .= $val2->serialize(); $rs .= "</member>\n"; } $rs .= '</struct>'; break; case 2: // array $rs .= "<array>\n<data>\n"; for ($i = 0; $i < sizeof($val); $i++) { //$rs.=$this->serializeval($val[$i]); $rs .= $val[$i]->serialize(); } $rs .= "</data>\n</array>"; break; case 1: switch ($typ) { case $GLOBALS['xmlrpcBase64']: $rs .= "<{$typ}>" . base64_encode($val) . "</{$typ}>"; break; case $GLOBALS['xmlrpcBoolean']: $rs .= "<{$typ}>" . ($val ? '1' : '0') . "</{$typ}>"; break; case $GLOBALS['xmlrpcString']: // G. Giunta 2005/2/13: do NOT use htmlentities, since // it will produce named html entities, which are invalid xml $rs .= "<{$typ}>" . xmlrpc_encode_entitites($val, $GLOBALS['xmlrpc_internalencoding']) . "</{$typ}>"; // $rs.="<${typ}>" . htmlentities($val). "</${typ}>"; break; default: $rs .= "<{$typ}>{$val}</{$typ}>"; } break; default: break; } return $rs; }
/** * @access private */ function serializedata($typ, $val, $charset_encoding = '') { $rs = ''; switch (@$GLOBALS['xmlrpcTypes'][$typ]) { case 1: switch ($typ) { case $GLOBALS['xmlrpcBase64']: $rs .= "<{$typ}>" . base64_encode($val) . "</{$typ}>"; break; case $GLOBALS['xmlrpcBoolean']: $rs .= "<{$typ}>" . ($val ? '1' : '0') . "</{$typ}>"; break; case $GLOBALS['xmlrpcString']: // G. Giunta 2005/2/13: do NOT use htmlentities, since // it will produce named html entities, which are invalid xml $rs .= "<{$typ}>" . xmlrpc_encode_entitites($val, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</{$typ}>"; break; case $GLOBALS['xmlrpcInt']: case $GLOBALS['xmlrpcI4']: $rs .= "<{$typ}>" . (int) $val . "</{$typ}>"; break; case $GLOBALS['xmlrpcDouble']: $rs .= "<{$typ}>" . (double) $val . "</{$typ}>"; break; case $GLOBALS['xmlrpcNull']: $rs .= "<nil/>"; break; default: // no standard type value should arrive here, but provide a possibility // for xmlrpcvals of unknown type... $rs .= "<{$typ}>{$val}</{$typ}>"; } break; case 3: // struct if ($this->_php_class) { $rs .= '<struct php_class="' . $this->_php_class . "\">\n"; } else { $rs .= "<struct>\n"; } foreach ($val as $key2 => $val2) { $rs .= '<member><name>' . xmlrpc_encode_entitites($key2, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</name>\n"; //$rs.=$this->serializeval($val2); $rs .= $val2->serialize($charset_encoding); $rs .= "</member>\n"; } $rs .= '</struct>'; break; case 2: // array $rs .= "<array>\n<data>\n"; for ($i = 0; $i < count($val); $i++) { //$rs.=$this->serializeval($val[$i]); $rs .= $val[$i]->serialize($charset_encoding); } $rs .= "</data>\n</array>"; break; default: break; } return $rs; }
function serializeDebug() { global $_xmlrpc_debuginfo; if ($_xmlrpc_debuginfo != '') { return "<!-- DEBUG INFO:\n\n" . xmlrpc_encode_entitites($_xmlrpc_debuginfo) . "\n-->\n"; } else { return ''; } }
function serializedata($typ, $val) { $rs = ''; global $xmlrpcTypes, $xmlrpcBase64, $xmlrpcString, $xmlrpcBoolean; switch (@$xmlrpcTypes[$typ]) { case 3: // struct $rs .= "<struct>\n"; reset($val); while (list($key2, $val2) = each($val)) { $rs .= "<member><name>{$key2}</name>\n"; $rs .= $this->serializeval($val2); $rs .= "</member>\n"; } $rs .= '</struct>'; break; case 2: // array $rs .= "<array>\n<data>\n"; for ($i = 0; $i < sizeof($val); $i++) { $rs .= $this->serializeval($val[$i]); } $rs .= "</data>\n</array>"; break; case 1: switch ($typ) { case $xmlrpcBase64: $rs .= "<{$typ}>" . base64_encode($val) . "</{$typ}>"; break; case $xmlrpcBoolean: $rs .= "<{$typ}>" . ($val ? '1' : '0') . "</{$typ}>"; break; case $xmlrpcString: // G. Giunta 2005/2/13: do NOT use htmlentities, since // it will produce named html entities, which are invalid xml $rs .= "<{$typ}>" . xmlrpc_encode_entitites($val) . "</{$typ}>"; // $rs.="<${typ}>" . htmlentities($val). "</${typ}>"; break; default: $rs .= "<{$typ}>{$val}</{$typ}>"; } break; default: break; } return $rs; }
/** * Returns xml representation of the response. XML prologue not included * @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed * @return string the xml representation of the response */ function serialize($charset_encoding = '') { if ($charset_encoding != '') { $this->content_type = 'text/xml; charset=' . $charset_encoding; } else { $this->content_type = 'text/xml'; } $result = "<methodResponse>\n"; if ($this->errno) { // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients // by xml-encoding non ascii chars $result .= "<fault>\n" . "<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno . "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" . xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</string></value>\n</member>\n" . "</struct>\n</value>\n</fault>"; } else { if (!is_object($this->val) || !is_a($this->val, '\\Innomatic\\Webservices\\Xmlrpc\\XmlRpcVal')) { if (is_string($this->val) && $this->valtyp == 'xml') { $result .= "<params>\n<param>\n" . $this->val . "</param>\n</params>"; } else { /// @todo try to build something serializable? die('cannot serialize xmlrpcresp objects whose content is native php values'); } } else { $result .= "<params>\n<param>\n" . $this->val->serialize($charset_encoding) . "</param>\n</params>"; } } $result .= "\n</methodResponse>"; $this->payload = $result; return $result; }