/**
 * 输出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;
    }
}
function reportExceptions($code, $descr, $filename, $line)
{
    // obey error_level set by system/user
    if (!($code & error_reporting())) {
        return;
    }
    // init a new error info object
    $error = new MessageException($code, $descr, $filename, $line, "AMFPHP_RUNTIME_ERROR");
    // add the error object to the body of the AMFObject
    $amfbody = new MessageBody(NULL, $GLOBALS['amfphp']['lastMethodCall']);
    MessageException::throwException($amfbody, $error);
    //$amfbody->setResults($error);
    if ($GLOBALS['amfphp']['encoding'] == 'amf0' || $GLOBALS['amfphp']['encoding'] == 'amf3') {
        // build a new AMFObject
        $amfout = new AMFObject("");
        $amfout->addBody($amfbody);
        // Add the trace headers we have so far while we're at it
        debugFilter($amfout);
        // create a new serializer
        $serializer = new AMFSerializer();
        // serialize the data
        $data = $serializer->serialize($amfout);
        // send the correct header
        header('Content-type: application/x-amf');
        // flush the amf data to the client.
        print $data;
        // kill the system after we find a single error
        exit;
    } else {
        serializationAction($amfbody);
        print $amfbody->getResults();
        exit;
    }
}
Esempio n. 3
0
 public function buildAMF($data)
 {
     $amf = new AMFObject();
     $amf->addBody($data);
     $serializer = new AMFSerializer();
     //var_dump($amf->_bodys[0]);
     $serializer->writeAmf3Object($amf->_bodys[0]);
     $data = $serializer->outBuffer;
     return $data;
 }
/**
 * Executes each of the bodys
 */
function batchProcessFilter(AMFObject &$amf)
{
    $bodycount = $amf->numBody();
    $actions = $GLOBALS['amfphp']['actions'];
    for ($i = 0; $i < $bodycount; $i++) {
        $bodyObj =& $amf->getBodyAt($i);
        foreach ($actions as $action) {
            $results = $action($bodyObj);
            if ($results === false) {
                break;
            }
        }
    }
}
Esempio n. 5
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;
}
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. 7
0
function reportExceptions($code, $descr, $filename, $line)
{
    // obey error_level set by system/user
    if (!($code & error_reporting())) {
        return;
    }
    // build a new AMFObject
    $amfout = new AMFObject("");
    // init a new error info object
    $error = array();
    // pass the code
    $error["code"] = "AMFPHP_RUNTIME_ERROR";
    // pass the description
    $error["description"] = $descr;
    // pass the details
    $error["details"] = $filename;
    // pass the level
    $error["level"] = AMFException::getFriendlyError($code);
    // pass the line number
    $error["line"] = $line;
    // add the error object to the body of the AMFObject
    $amfbody = new AMFBody(NULL, $GLOBALS['amfphp']['lastMethodCall']);
    $amfbody->setResults($error);
    $amfout->addBody($amfbody);
    // Add the trace headers we have so far while we're at it
    debugFilter($amfout);
    // create a new serializer
    $serializer = new AMFSerializer();
    // serialize the data
    $data = $serializer->serialize($amfout);
    // send the correct header
    header('Content-type: application/x-amf');
    // flush the amf data to the client.
    print $data;
    // kill the system after we find a single error
    exit;
}
Esempio n. 8
0
 /**
  * Wraps a string into an error AMF message
  * @param $data the original AMF data (needed to get the response index
  * @param $error The error to send back
  * @returns String containing the AMF data
  */
 function sendError($data, $error)
 {
     //Get the last response index, otherwise the error will not register
     //In the NetConnection debugger
     $amf = new AMFObject($data);
     // create the amf object
     $deserializer = new AMFDeserializer($data);
     $deserializer->deserialize($amf);
     $lastBody =& $amf->getBodyAt($amf->numBody() - 1);
     $lastIndex = $lastBody->responseIndex;
     // add the error object to the body of the AMFObject
     $amfout = new AMFObject(NULL);
     $amfbody = new AMFBody($lastIndex . "/onStatus", $lastIndex);
     //Get line number
     preg_match("/in ([A-Za-z0-9\\/\\.\\:]+) on line ([0-9]+)/", str_replace('\\', '/', $error), $matches);
     $file = $matches[1];
     $line = $matches[2];
     $level = substr($error, 0, strpos($error, ': '));
     $amfbody->setResults(array('description' => $error, 'line' => $line, 'file' => $file, 'level' => $level, 'code' => 'AMFPHP_DEBUG_ERROR'));
     $amfout->addBody($amfbody);
     // create a new serializer
     $serializer = new AMFSerializer();
     // serialize the data
     $result = $serializer->serialize($amfout);
     return $result;
 }