Exemplo n.º 1
0
 public function createPayload($charsetEncoding = '')
 {
     if ($charsetEncoding != '') {
         $this->content_type = 'text/xml; charset=' . $charsetEncoding;
     } else {
         $this->content_type = 'text/xml';
     }
     $this->payload = $this->xml_header($charsetEncoding);
     $this->payload .= '<methodName>' . Charset::instance()->encodeEntities($this->methodname, PhpXmlRpc::$xmlrpc_internalencoding, $charsetEncoding) . "</methodName>\n";
     $this->payload .= "<params>\n";
     foreach ($this->params as $p) {
         $this->payload .= "<param>\n" . $p->serialize($charsetEncoding) . "</param>\n";
     }
     $this->payload .= "</params>\n";
     $this->payload .= $this->xml_footer();
 }
Exemplo n.º 2
0
 /**
  * Return a string with the serialized representation of all debug info.
  *
  * @param string $charsetEncoding the target charset encoding for the serialization
  *
  * @return string an XML comment (or two)
  */
 public function serializeDebug($charsetEncoding = '')
 {
     // 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 (static::$_xmlrpc_debuginfo != '') {
         $out .= "<!-- DEBUG INFO:\n" . Charset::instance()->encodeEntities(str_replace('--', '_-', static::$_xmlrpc_debuginfo), PhpXmlRpc::$xmlrpc_internalencoding, $charsetEncoding) . "\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(']]>', ']_]_>', static::$_xmlrpc_debuginfo) . "\n]]>\n";
     }
     return $out;
 }
Exemplo n.º 3
0
 /**
  * Returns xml representation of the response. XML prologue not included.
  *
  * @param string $charsetEncoding the charset to be used for serialization. If null, US-ASCII is assumed
  *
  * @return string the xml representation of the response
  *
  * @throws \Exception
  */
 public function serialize($charsetEncoding = '')
 {
     if ($charsetEncoding != '') {
         $this->content_type = 'text/xml; charset=' . $charsetEncoding;
     } else {
         $this->content_type = 'text/xml';
     }
     if (PhpXmlRpc::$xmlrpc_null_apache_encoding) {
         $result = "<methodResponse xmlns:ex=\"" . PhpXmlRpc::$xmlrpc_null_apache_encoding_ns . "\">\n";
     } else {
         $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>" . Charset::instance()->encodeEntities($this->errstr, PhpXmlRpc::$xmlrpc_internalencoding, $charsetEncoding) . "</string></value>\n</member>\n" . "</struct>\n</value>\n</fault>";
     } else {
         if (!is_object($this->val) || !is_a($this->val, 'PhpXmlRpc\\Value')) {
             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?
                 throw new \Exception('cannot serialize xmlrpc response objects whose content is native php values');
             }
         } else {
             $result .= "<params>\n<param>\n" . $this->val->serialize($charsetEncoding) . "</param>\n</params>";
         }
     }
     $result .= "\n</methodResponse>";
     $this->payload = $result;
     return $result;
 }
Exemplo n.º 4
0
 protected function serializedata($typ, $val, $charsetEncoding = '')
 {
     $rs = '';
     if (!isset(static::$xmlrpcTypes[$typ])) {
         return $rs;
     }
     switch (static::$xmlrpcTypes[$typ]) {
         case 1:
             switch ($typ) {
                 case static::$xmlrpcBase64:
                     $rs .= "<{$typ}>" . base64_encode($val) . "</{$typ}>";
                     break;
                 case static::$xmlrpcBoolean:
                     $rs .= "<{$typ}>" . ($val ? '1' : '0') . "</{$typ}>";
                     break;
                 case static::$xmlrpcString:
                     // G. Giunta 2005/2/13: do NOT use htmlentities, since
                     // it will produce named html entities, which are invalid xml
                     $rs .= "<{$typ}>" . Charset::instance()->encodeEntities($val, PhpXmlRpc::$xmlrpc_internalencoding, $charsetEncoding) . "</{$typ}>";
                     break;
                 case static::$xmlrpcInt:
                 case static::$xmlrpcI4:
                     $rs .= "<{$typ}>" . (int) $val . "</{$typ}>";
                     break;
                 case static::$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 static::$xmlrpcDateTime:
                     if (is_string($val)) {
                         $rs .= "<{$typ}>{$val}</{$typ}>";
                     } elseif (is_a($val, 'DateTime')) {
                         $rs .= "<{$typ}>" . $val->format('Ymd\\TH:i:s') . "</{$typ}>";
                     } elseif (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 static::$xmlrpcNull:
                     if (PhpXmlRpc::$xmlrpc_null_apache_encoding) {
                         $rs .= "<ex:nil/>";
                     } else {
                         $rs .= "<nil/>";
                     }
                     break;
                 default:
                     // no standard type value should arrive here, but provide a possibility
                     // for xmlrpc values 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";
             }
             $charsetEncoder = Charset::instance();
             foreach ($val as $key2 => $val2) {
                 $rs .= '<member><name>' . $charsetEncoder->encodeEntities($key2, PhpXmlRpc::$xmlrpc_internalencoding, $charsetEncoding) . "</name>\n";
                 //$rs.=$this->serializeval($val2);
                 $rs .= $val2->serialize($charsetEncoding);
                 $rs .= "</member>\n";
             }
             $rs .= '</struct>';
             break;
         case 2:
             // array
             $rs .= "<array>\n<data>\n";
             foreach ($val as $element) {
                 //$rs.=$this->serializeval($val[$i]);
                 $rs .= $element->serialize($charsetEncoding);
             }
             $rs .= "</data>\n</array>";
             break;
         default:
             break;
     }
     return $rs;
 }