Example #1
0
 /**
  * @access private
  */
 function createPayload($charset_encoding = '')
 {
     if ($charset_encoding != '') {
         $this->content_type = 'application/json; charset=' . $charset_encoding;
     } else {
         $this->content_type = 'application/json';
     }
     // @ todo: verify if all chars are allowed for method names or can
     // we just skip the js encoding on it?
     $this->payload = "{\n\"method\": \"" . json_encode_entities($this->methodname, '', $charset_encoding) . "\",\n\"params\": [ ";
     for ($i = 0; $i < sizeof($this->params); $i++) {
         $p = $this->params[$i];
         // MB: we try to force serialization as json even though the object
         // param might be a plain xmlrpcval object.
         // This way we do not need to override addParam, aren't we lazy?
         $this->payload .= "\n  " . serialize_jsonrpcval($p, $charset_encoding) . ",";
     }
     $this->payload = substr($this->payload, 0, -1) . "\n],\n\"id\": ";
     switch (true) {
         case $this->id === null:
             $this->payload .= 'null';
             break;
         case is_string($this->id):
             $this->payload .= '"' . json_encode_entities($this->id, '', $charset_encoding) . '"';
             break;
         case is_bool($this->id):
             $this->payload .= $this->id ? 'true' : 'false';
             break;
         default:
             $this->payload .= $this->id;
     }
     $this->payload .= "\n}\n";
 }
Example #2
0
/**
 * Serialize an ezjscoreval (or xmlrpcval) as application/x-www-form-urlencoded.
 * Recursive stuff is handles as json (@todo: to be verified...)
 * Moved outside of the corresponding class to ease multi-serialization of
 * xmlrpcval/jsonrpcval objects
 * @param xmlrpcval or jsonrpcval $value
 * @string $charset_encoding
 * @access private
 */
function serialize_ezjscoreval($value, $charset_encoding = '')
{
    reset($value->me);
    list($typ, $val) = each($value->me);
    $rs = '';
    switch (@$GLOBALS['xmlrpcTypes'][$typ]) {
        case 1:
            switch ($typ) {
                case $GLOBALS['xmlrpcString']:
                    $rs .= urlencode($val);
                    break;
                case $GLOBALS['xmlrpcI4']:
                case $GLOBALS['xmlrpcInt']:
                    $rs .= (int) $val;
                    break;
                case $GLOBALS['xmlrpcDateTime']:
                    // send date as string.
                    $rs .= urlencode($val);
                    break;
                case $GLOBALS['xmlrpcDouble']:
                    // add a .0 in case value is integer.
                    // This helps us carrying around floats in js, and keep them separated from ints
                    $sval = strval((double) $val);
                    // convert to string
                    // fix usage of comma, in case of eg. german locale
                    $sval = str_replace(',', '.', $sval);
                    if (strpos($sval, '.') !== false || strpos($sval, 'e') !== false) {
                        $rs .= $sval;
                    } else {
                        $rs .= $val . '.0';
                    }
                    break;
                case $GLOBALS['xmlrpcBoolean']:
                    $rs .= $val ? 'true' : 'false';
                    break;
                case $GLOBALS['xmlrpcBase64']:
                    // treat base 64 values as strings ???
                    $rs .= base64_encode($val);
                    break;
                default:
                    $rs .= "null";
            }
            break;
        case 2:
            // array or struct: sent as json
            $rs .= "[";
            $len = sizeof($val);
            if ($len) {
                for ($i = 0; $i < $len; $i++) {
                    $rs .= serialize_ezjscoreval($val[$i], $charset_encoding);
                    $rs .= ",";
                }
                $rs = substr($rs, 0, -1) . "]";
            } else {
                $rs .= "]";
            }
            break;
        case 3:
            // struct
            foreach ($val as $key2 => $val2) {
                $rs .= ',"' . json_encode_entities($key2, null, $charset_encoding) . '":';
                $rs .= serialize_ezjscoreval($val2, $charset_encoding);
            }
            $rs = '{' . substr($rs, 1) . '}';
            break;
        case 0:
            // let uninitialized jsonrpcval objects serialize to an empty string, as they do in xmlrpc land
            $rs = '""';
            break;
        default:
            break;
    }
    return $rs;
}
 /**
  * @access private
  */
 function createPayload($charset_encoding = '')
 {
     // @ todo: verify if all chars are allowed for method names or can
     // we just skip the js encoding on it?
     $this->payload = "{\n\"method\": \"" . json_encode_entities($this->methodname, '', $charset_encoding) . "\",\n\"params\": [ ";
     for ($i = 0; $i < sizeof($this->params); $i++) {
         $p = $this->params[$i];
         // MB: we try to force serialization as json even though the object
         // param might be a plain xmlrpcval object.
         // This way we do not need to override addParam, aren't we lazy?
         $this->payload .= "\n  " . serialize_jsonrpcval($p, $charset_encoding) . ",";
     }
     $this->payload = substr($this->payload, 0, -1) . "\n],\n\"id\": " . ($this->id == null ? 'null' : $this->id) . "\n}\n";
 }