/**
 * 输出amf格式的内容
 * @param $result 需要输出到浏览器的内容
 * @param $exit 是否在输出后结束脚本
 * @return void
 */
function print_amf_result($result, $exit = true)
{
    if ($GLOBALS['amfphp']['native'] === true && function_exists('amf_decode')) {
        $serializer = new AMFBaseSerializer();
        // Create a serailizer around the output stream
    } else {
        $serializer = new AMFSerializer();
        // Create a serailizer around the output stream
    }
    $body = new MessageBody('', '/1');
    $body->responseURI = $body->responseIndex . "/onResult";
    $body->setResults($result);
    $amfObj = new AMFObject();
    $amfObj->addBody($body);
    $data = $serializer->serialize($amfObj);
    header('Content-type: application/x-amf');
    $dateStr = date('D, j M Y H:i:s', time() - 86400);
    header("Expires: {$dateStr} GMT");
    header('Pragma: no-store');
    header('Cache-Control: no-store');
    header('Content-length: ' . strlen($data));
    echo $data;
    if ($exit) {
        exit;
    }
}
Esempio n. 2
0
 function createBody()
 {
     if (strlen($GLOBALS["HTTP_RAW_POST_DATA"]) == 0) {
         echo "The XML-RPC gateway is installed correctly";
         exit;
     }
     $GLOBALS['amfphp']['encoding'] = 'xmlrpc';
     $body = new MessageBody();
     $body->setValue($GLOBALS["HTTP_RAW_POST_DATA"]);
     return $body;
 }
Esempio n. 3
0
function rpc($reqs, $progress = true)
{
    global $ua, $ch, $swfurl, $cookies, $rpcseq, $rpcmax;
    global $debugout;
    $offset = 0;
    $resps = array();
    while (true) {
        $n = min(count($reqs) - $offset, $rpcmax);
        if ($n == 0) {
            break;
        }
        $req = array(gen_header(), array_slice($reqs, $offset, $n), 0);
        $offset += $n;
        ++$rpcseq;
        $body = new MessageBody();
        $body->setResponseURI("BaseService.dispatchBatch");
        $body->setResponseTarget("/{$rpcseq}");
        $body->setResults($req);
        $amf = new AMFObject();
        $amf->addBody($body);
        $serializer = new AMFSerializer();
        $postdata = $serializer->serialize($amf);
        if ($debugout) {
            file_put_contents("out/{$rpcseq}.req", $postdata);
        }
        curl_setopt_array($ch, array(CURLOPT_POST => true, CURLOPT_BINARYTRANSFER => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $ua, CURLOPT_REFERER => $swfurl, CURLOPT_COOKIE => $cookies, CURLOPT_POSTFIELDS => $postdata));
        $out = curl_exec($ch);
        if ($debugout) {
            file_put_contents("out/{$rpcseq}.resp", $out);
        }
        if ($progress) {
            print ".";
        }
        $amf = new AMFObject($out);
        $deserializer = new AMFDeserializer($amf->rawData);
        // deserialize the data
        $deserializer->deserialize($amf);
        // run the deserializer
        $v = $amf->getBodyAt(0)->getValue();
        if ($v['errorType'] != 0) {
            die($v['errorData'] . "\n");
        }
        $resps = array_merge($resps, $v['data']);
    }
    return $resps;
}
Esempio n. 4
0
 function createBody()
 {
     $GLOBALS['amfphp']['encoding'] = 'json';
     $body = new MessageBody();
     $uri = __setUri();
     $elements = explode('/gateway.json', $uri);
     if (strlen($elements[1]) == 0) {
         echo "The JSON gateway is installed correctly. Call like this: json.php/MyClazz.myMethod/arg1/arg2";
         exit;
     }
     $args = substr($elements[1], 1);
     $rawArgs = explode('/', $args);
     if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
         $rawArgs[] = $GLOBALS['HTTP_RAW_POST_DATA'];
     }
     $body->setValue($rawArgs);
     return $body;
 }
function print_amf_result($result, $exit = true)
{
    $serializer = new AMFBaseSerializer();
    $body = new MessageBody('', '/1');
    $body->responseURI = $body->responseIndex . "/onResult";
    $body->setResults($result);
    $amfObj = new AMFObject();
    $amfObj->addBody($body);
    $data = $serializer->serialize($amfObj);
    header("Content-type: application/x-amf");
    $dateStr = date("D, j M Y ") . date("H:i:s", strtotime("-2 days"));
    header("Expires: {$dateStr} GMT");
    header("Pragma: no-store");
    header("Cache-Control: no-store");
    header("Content-length: " . strlen($data));
    echo $data;
    if ($exit) {
        exit;
    }
}
Esempio n. 6
0
/**
 * Adds debugging information to outgoing packet
 */
function debugFilter(&$amf)
{
    //Add trace headers before outputting
    if (!$GLOBALS['amfphp']['isFlashComm'] && !$GLOBALS['amfphp']['disableTrace']) {
        $headerresults = array();
        // create a result array
        $headerresults[0] = array();
        // create a sub array in results (CF seems to do this, don't know why)
        if (count(NetDebug::getTraceStack()) != 0) {
            $ts = NetDebug::getTraceStack();
            $headerresults[0][] = new TraceHeader($ts);
        }
        if (Headers::getHeader("serviceBrowser") == true) {
            global $amfphp;
            $amfphp['totalTime'] = microtime_float() - $amfphp['startTime'];
            $headerresults[0][] = new ProfilingHeader();
        }
        //Get the last body in the stack
        if (count($headerresults[0]) > 0) {
            $body =& $amf->getBodyAt($amf->numBody() - 1);
            $headers = new MessageBody(NULL, $body->responseIndex, NULL);
            // create a new amf body
            $headers->responseURI = $body->responseIndex . "/onDebugEvents";
            // set the response uri of this body
            $headers->setResults($headerresults);
            // set the results.
            $amf->addBodyAt(0, $headers);
        }
    }
}
Esempio n. 7
0
 /**
  * Sets the message body.
  *
  * @param \Brick\Http\MessageBody|null $body
  *
  * @return static
  */
 public function setBody(MessageBody $body = null)
 {
     $this->body = $body;
     if ($body) {
         $size = $body->getSize();
         if ($size === null) {
             $this->setHeader('Transfer-Encoding', 'chunked');
             $this->removeHeader('Content-Length');
         } else {
             $this->setHeader('Content-Length', (string) $size);
             $this->removeHeader('Transfer-Encoding');
         }
     } else {
         $this->removeHeader('Content-Length');
         $this->removeHeader('Transfer-Encoding');
     }
     return $this;
 }