Ejemplo n.º 1
0
function executionAction(&$body)
{
    $classConstruct =& $body->getClassConstruct();
    $methodName = $body->methodName;
    $args = $body->getValue();
    $output = Executive::doMethodCall($body, &$classConstruct, $methodName, $args);
    if ($output !== "__amfphp_error") {
        $body->setResults($output);
    }
}
Ejemplo n.º 2
0
function executionAction(&$body)
{
    $classConstruct = $body->getClassConstruct();
    $methodName = $body->methodName;
    $className = $body->className;
    $xmlrpc_server = xmlrpc_server_create();
    $lambdaFunc = 'return adapterMap(call_user_func_array (array(&$userData[0], $userData[1]), $args));';
    $func = create_function('$a,$args,$userData', $lambdaFunc);
    xmlrpc_server_register_method($xmlrpc_server, $body->packageClassMethodName, $func);
    $request_xml = $body->getValue();
    $args = array($xmlrpc_server, $request_xml, array(&$classConstruct, $methodName));
    $nullObj = NULL;
    $response = Executive::doMethodCall($body, $nullObj, 'xmlrpc_server_call_method', $args);
    //$response = xmlrpc_server_call_method();
    if ($response !== "__amfphp_error") {
        $body->setResults($response);
    } else {
        return false;
    }
}
Ejemplo n.º 3
0
/**
 * Class loader action loads the class from which we will get the remote method
 */
function cakeClassLoaderAction(&$amfbody)
{
    if (!$amfbody->noExec) {
        // change to the gateway.php script directory
        // now change to the directory of the classpath.  Possible relative to gateway.php
        $dirname = dirname($amfbody->classPath);
        if (is_dir($dirname)) {
            //chdir($dirname);
        } else {
            $ex = new MessageException(E_USER_ERROR, "The classpath folder {" . $amfbody->classPath . "} does not exist. You probably misplaced your service.", __FILE__, __LINE__, "AMFPHP_CLASSPATH_NOT_FOUND");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        //$fileExists = @file_exists(basename($amfbody->classPath)); // see if the file exists
        $fileExists = @file_exists($amfbody->classPath);
        // see if the file exists
        if (!$fileExists) {
            $ex = new MessageException(E_USER_ERROR, "The class {" . $amfbody->className . "} could not be found under the class path {" . $amfbody->classPath . "}", __FILE__, __LINE__, "AMFPHP_FILE_NOT_FOUND");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        global $amfphp;
        $time = microtime_float();
        //$fileIncluded = Executive::includeClass($amfbody, "./" . basename($amfbody->classPath));
        $fileIncluded = Executive::includeClass($amfbody, $amfbody->classPath);
        $amfphp['includeTime'] += microtime_float() - $time;
        if (!$fileIncluded) {
            $ex = new MessageException(E_USER_ERROR, "The class file {" . $amfbody->className . "} exists but could not be included. The file may have syntax errors, or includes at the top of the file cannot be resolved.", __FILE__, __LINE__, "AMFPHP_FILE_NOT_INCLUDED");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        if (!class_exists($amfbody->className)) {
            // Just make sure the class name is the same as the file name
            $ex = new MessageException(E_USER_ERROR, "The file {" . $amfbody->className . ".php} exists and was included correctly but a class by that name could not be found in that file. Perhaps the class is misnamed.", __FILE__, __LINE__, "AMFPHP_CLASS_NOT_FOUND");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        //Let executive handle building the class
        //The executive can handle making exceptions and all that, that's why
        $classConstruct = Executive::buildClass($amfbody, $amfbody->className);
        $classConstruct->params['controller'] = Inflector::underscore(str_replace('Controller', '', $amfbody->className));
        $classConstruct->params['action'] = strtolower($amfbody->methodName);
        //We need exception handling when initializing CakePHP controllers,
        // (AmfAuth component, beforeFilters can throw exceptions). This way exceptions
        // are handled correctly, and returned through amf message
        $object = null;
        $init = Executive::doMethodCall($amfbody, $object, 'initCakeController', array($classConstruct));
        if ($init === '__amfphp_error') {
            return false;
        }
        if ($classConstruct !== '__amfphp_error') {
            $amfbody->setClassConstruct($classConstruct);
        } else {
            return false;
        }
    }
    return true;
}
Ejemplo n.º 4
0
/**
 * MetaDataAction loads the required info from the methodTable
 */
function securityAction(&$amfbody)
{
    if (!$amfbody->noExec) {
        $classConstruct =& $amfbody->getClassConstruct();
        $methodName = $amfbody->methodName;
        $className = $amfbody->className;
        //Check if method exists
        if (!method_exists($classConstruct, $methodName)) {
            // check to see if the method exists
            $ex = new MessageException(E_USER_ERROR, "The method  {" . $methodName . "} does not exist in class {" . $className . "}.", __FILE__, __LINE__, "AMFPHP_INEXISTANT_METHOD");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        //Check if method is private (PHP4)
        if (strpos($methodName, '_') === 0) {
            // check to see if the method exists
            $ex = new MessageException(E_USER_ERROR, "The method  {" . $methodName . "} starts with an underscore and is therefore considered private, so it cannot be remotely called.", __FILE__, __LINE__, "AMFPHP_PRIVATE_METHOD");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        //Check to see if method is private or protected (PHP5)
        if (class_exists('ReflectionMethod')) {
            $method = new ReflectionMethod($className, $methodName);
            if (!$method->isPublic()) {
                $ex = new MessageException(E_USER_ERROR, "The method  {" . $methodName . "} in {" . $className . "} is not public and therefore cannot be called.", __FILE__, __LINE__, "AMFPHP_PRIVATE_METHOD");
                MessageException::throwException($amfbody, $ex);
                return false;
            }
        }
        $classConstruct =& $amfbody->getClassConstruct();
        $methodName = $amfbody->methodName;
        $className = $amfbody->className;
        if (method_exists($classConstruct, "beforeFilter")) {
            //Pass throught the executive
            $allow = Executive::doMethodCall($amfbody, $classConstruct, 'beforeFilter', array($methodName));
            if ($allow === '__amfphp_error' || $allow === false) {
                $ex = new MessageException(E_USER_ERROR, "Method access blocked by beforeFilter in " . $className . " class", __FILE__, __LINE__, "AMFPHP_AUTHENTICATE_ERROR");
                MessageException::throwException($amfbody, $ex);
                return false;
            }
        }
    }
    return true;
}
Ejemplo n.º 5
0
/**
 * ExecutionAction executes the required methods
 */
function executionAction(&$amfbody)
{
    $specialHandling = $amfbody->getSpecialHandling();
    if (!$amfbody->isSpecialHandling() || $amfbody->isSpecialHandling(array('describeService', 'pageFetch', 'RemotingMessage'))) {
        $construct =& $amfbody->getClassConstruct();
        $method = $amfbody->methodName;
        $args = $amfbody->getValue();
        if ($specialHandling == 'describeService') {
            include_once AMFPHP_BASE . "util/DescribeService.php";
            $ds = new DescribeService();
            $results = $ds->describe($construct, $amfbody->className);
        } else {
            if ($specialHandling == 'pageFetch') {
                $args[count($args) - 2] = $args[count($args) - 2] - 1;
                $dataset = Executive::doMethodCall($amfbody, $construct, $method, $args);
                $results = array("cursor" => $args[count($args) - 2] + 1, "data" => $dataset);
                $amfbody->setMetadata('type', '__DYNAMIC_PAGE__');
            } else {
                /*
                			if(isset($construct->methodTable[$method]['pagesize']))
                			{
                //Check if counting method was overriden
                if(isset($construct->methodTable[$method]['countMethod']))
                {
                	$counter = $construct->methodTable[$method]['countMethod'];
                }
                else
                {
                	$counter = $method . '_count';
                }
                
                $dataset = Executive::doMethodCall($amfbody, $construct, $method, $args); // do the magic
                $count = Executive::doMethodCall($amfbody, $construct, $counter, $args);
                
                //Include the wrapper
                $results = array('class' => $amfbody->uriClassPath, 
                				 'method' => $amfbody->methodName, 
                				 'count' => $count, 
                				 "args" => $args, 
                				 "data" => $dataset);
                $amfbody->setMetadata('type', '__DYNAMIC_PAGEABLE_RESULTSET__');
                $amfbody->setMetadata('pagesize', $construct->methodTable[$method]['pagesize']);
                */
                //}
                //else
                //{
                //The usual
                $time = microtime_float();
                $results = Executive::doMethodCall($amfbody, $construct, $method, $args);
                // do the magic
                global $amfphp;
                $amfphp['callTime'] += microtime_float() - $time;
                //}
            }
        }
        if ($results !== '__amfphp_error') {
            if ($specialHandling == 'RemotingMessage') {
                $wrapper = new AcknowledgeMessage($amfbody->getMetadata("messageId"), $amfbody->getMetadata("clientId"));
                $wrapper->body = $results;
                $amfbody->setResults($wrapper);
            } else {
                $amfbody->setResults($results);
            }
            $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
        }
        return false;
    } elseif ($specialHandling == 'Ping') {
        $wrapper = new AcknowledgeMessage($amfbody->getMetadata("messageId"), $amfbody->getMetadata("clientId"));
        $amfbody->setResults($wrapper);
        $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
    } else {
        if ($specialHandling == 'pageRelease') {
            //Ignore PageAbleResult.release
            $amfbody->setResults(true);
            $amfbody->setMetaData('type', 'boolean');
            $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
            return false;
        }
    }
    return true;
}
Ejemplo n.º 6
0
/**
 * ExecutionAction executes the required methods
 */
function executionAction(&$amfbody)
{
    $specialHandling = $amfbody->getSpecialHandling();
    if (!$amfbody->isSpecialHandling() || $amfbody->isSpecialHandling(array('describeService', 'pageFetch'))) {
        $construct =& $amfbody->getClassConstruct();
        $method = $amfbody->methodName;
        $args = $amfbody->getValue();
        if (isset($construct->methodTable[$method]['fastArray']) && $construct->methodTable[$method]['fastArray'] == true) {
            $amfbody->setMetaData('fastArray', true);
        }
        if ($specialHandling == 'describeService') {
            include_once AMFPHP_BASE . "util/DescribeService.php";
            $ds = new DescribeService();
            $results = $ds->describe($construct, $amfbody->className);
        } else {
            if ($specialHandling == 'pageFetch') {
                $args[count($args) - 2] = $args[count($args) - 2] - 1;
                $dataset = Executive::doMethodCall($amfbody, $construct, $method, $args);
                $results = array("cursor" => $args[count($args) - 2] + 1, "data" => $dataset);
                $amfbody->setMetadata('type', '__DYNAMIC_PAGE__');
            } else {
                if (isset($construct->methodTable[$method]['pagesize'])) {
                    //Check if counting method was overriden
                    if (isset($construct->methodTable[$method]['countMethod'])) {
                        $counter = $construct->methodTable[$method]['countMethod'];
                    } else {
                        $counter = $method . '_count';
                    }
                    $dataset = Executive::doMethodCall($amfbody, $construct, $method, $args);
                    // do the magic
                    $count = Executive::doMethodCall($amfbody, $construct, $counter, $args);
                    //Include the wrapper
                    $results = array('class' => $amfbody->uriClassPath, 'method' => $amfbody->methodName, 'count' => $count, "args" => $args, "data" => $dataset);
                    $amfbody->setMetadata('type', '__DYNAMIC_PAGEABLE_RESULTSET__');
                    $amfbody->setMetadata('pagesize', $construct->methodTable[$method]['pagesize']);
                } else {
                    //The usual
                    $results = Executive::doMethodCall($amfbody, $construct, $method, $args);
                    // do the magic
                }
            }
        }
        if ($results !== '__amfphp_error') {
            $amfbody->setResults($results);
            if (isset($construct->methodTable[$method]['returns']) && !isset($construct->methodTable[$method]['pagesize'])) {
                $amfbody->setMetadata('type', $construct->methodTable[$method]['returns']);
            }
            $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
        }
        return false;
    } else {
        if ($specialHandling == 'pageRelease') {
            //Ignore PageAbleResult.release
            $amfbody->setResults(true);
            $amfbody->setMetaData('type', 'boolean');
            $amfbody->responseURI = $amfbody->responseIndex . "/onResult";
            return false;
        }
    }
    return true;
}