/**
  * Processes an incoming request, executes it and builds a response.
  *
  * @since 5.1
  * @param ModuleServerRequest $request Incoming request.
  * @param ModuleServerResponse $response Outcoming response.
  * @return void
  */
 public function process(ModuleServerRequest $request, ModuleServerResponse $response)
 {
     $command = explode(' ', $request->getCommand());
     $module_location = $command[1];
     if (!strlen($module_location)) {
         $response->sendWarning(ModuleServerResponse::SC_NOT_FOUND, 'Module location not defined.', ModuleServerRsponse::ERROR_CLASSNAME_MISSING);
         return;
     }
     try {
         $locator = new ModuleLocator('module://' . $request->getHeader('User') . ':' . $request->getHeader('Password') . '@/' . $module_location);
         $sessionId = $request->getHeader('Session');
         if ($sessionId) {
             $this->module = ModuleFactory::getSessionModule($locator, $sessionId);
         } else {
             $this->module = ModuleFactory::getModule($locator);
         }
     } catch (ModuleException $e) {
         $response->sendWarning(ModuleServerResponse::SC_INTERNAL_SERVER_ERROR, $e->__toString());
         return;
     } catch (\Exception $e) {
         $response->sendWarning(ModuleServerResponse::SC_INTERNAL_SERVER_ERROR, $e->__toString());
         return;
     }
     if (!($xmlrpc_server = xmlrpc_server_create())) {
         $response->sendWarning(ModuleServerResponse::SC_INTERNAL_SERVER_ERROR, 'Internal error: Could not create an XML-RPC server.', ModuleServerResponse::ERROR_XMLRPC_ERROR);
         return;
     }
     $theClass = new \ReflectionObject($this->module);
     $methods = $theClass->getMethods();
     foreach ($methods as $method) {
         // Ignore private methods
         $theMethod = new \ReflectionMethod($theClass->getName(), $method->getName());
         if (!$theMethod->isPublic()) {
             continue;
         }
         // Expose only methods beginning with "module" prefix
         if (!(substr($method->getName(), 0, 6) == 'module')) {
             continue;
         }
         xmlrpc_server_register_method($xmlrpc_server, strtolower($method->getName()), array($this, 'xmlrpcGateway'));
     }
     xmlrpc_server_register_introspection_callback($xmlrpc_server, array($this, 'introspectionGateway'));
     try {
         $buffer = xmlrpc_server_call_method($xmlrpc_server, $request->getPayload(), '', array('output_type' => 'xml'));
         $response->addHeader('Module/1.0 ' . ModuleServerResponse::SC_OK);
         $response->setBuffer($buffer);
     } catch (\Exception $e) {
         $response->addHeader('Module/1.0 ' . ModuleServerResponse::SC_INTERNAL_ERROR);
         $response->setBuffer($buffer);
     }
     xmlrpc_server_destroy($xmlrpc_server);
     $context = new ModuleContext($module_location);
     $session = new \Innomatic\Module\Session\ModuleSession($context, $sessionId);
     $session->save($this->module);
     $response->addHeader('Session: ' . $session->getId());
 }
Beispiel #2
0
 /**
  * Creates a new instance of the Ripcord server.
  *
  * @param mixed $services   . Optional. An object or array of objects.
  *                          The public methods in these objects will be exposed through the RPC server.
  *                          If the services array has non-numeric keys, the key for each object will define its namespace.
  * @param array $options    . Optional. Allows you to override the default server settings. Accepted key names are:
  *                          - 'documentor': allows you to specify an alternative HTML documentor class, no HTML documentor.
  *                          - 'name'      : The name of the server, used by the default HTML documentor.
  *                          - 'css'       : An url of a css file to link to in the HTML documentation.
  *                          - 'wsdl'      : The wsdl 1.0 description of this service ('soap 1.1' version, or the 'auto' version
  *                          - 'wsdl2'     : The wsdl 2.0 description of this service
  *                          In addition you can set any of the outputOptions for the xmlrpc server.
  * @param null  $documentor
  *
  * @throws ConfigurationException when the xmlrpc extension in not available.
  *
  * @see Ripcord_Server::setOutputOption()
  */
 public function __construct($services = null, $options = null, $documentor = null)
 {
     if (!function_exists('xmlrpc_server_create')) {
         throw new ConfigurationException('PHP XMLRPC library is not installed', Ripcord::XMLRPC_NOT_INSTALLED);
     }
     $this->xmlrpc = xmlrpc_server_create();
     if (isset($services)) {
         if (is_array($services)) {
             foreach ($services as $serviceName => $service) {
                 $this->addService($service, $serviceName);
             }
         } else {
             $this->addService($services);
         }
     }
     if (isset($documentor) && is_object($documentor)) {
         $this->documentor = $documentor;
         xmlrpc_server_register_introspection_callback($this->xmlrpc, [$this->documentor, 'getIntrospectionXML']);
     }
     if (isset($options)) {
         $this->outputOptions = array_merge($this->outputOptions, $options);
     }
 }
Beispiel #3
0
 /**
  * Creates a new instance of the Ripcord server.
  * @param mixed $services. Optional. An object or array of objects. The public methods in these objects will be exposed
  * through the RPC server. If the services array has non-numeric keys, the key for each object will define its namespace.
  * @param array $options. Optional. Allows you to override the default server settings. Accepted key names are:
  * - 'documentor': allows you to specify an alternative HTML documentor class, or if set to false, no HTML documentor.
  * - 'name'      : The name of the server, used by the default HTML documentor.
  * - 'css'       : An url of a css file to link to in the HTML documentation.
  * - 'wsdl'      : The wsdl 1.0 description of this service (only usefull if you run the 'soap 1.1' version, or the 'auto' version
  * - 'wsdl2'     : The wsdl 2.0 description of this service
  * In addition you can set any of the outputOptions for the xmlrpc server.
  * @see Ripcord_Server::setOutputOption()
  * @throws Ripcord_InvalidArgumentException (ripcord::unknownServiceType) when passed an incorrect service
  * @throws Ripcord_ConfigurationException (ripcord::xmlrpcNotInstalled) when the xmlrpc extension in not available.
  */
 function __construct($services = null, $options = null, $documentor = null)
 {
     if (!function_exists('xmlrpc_server_create')) {
         throw new Ripcord_ConfigurationException('PHP XMLRPC library is not installed', ripcord::xmlrpcNotInstalled);
     }
     libxml_disable_entity_loader();
     // prevents XXE attacks
     $this->xmlrpc = xmlrpc_server_create();
     if (isset($services)) {
         if (is_array($services)) {
             foreach ($services as $serviceName => $service) {
                 $this->addService($service, $serviceName);
             }
         } else {
             $this->addService($services);
         }
     }
     if (isset($documentor) && is_object($documentor)) {
         $this->documentor = $documentor;
         xmlrpc_server_register_introspection_callback($this->xmlrpc, array($this->documentor, 'getIntrospectionXML'));
     }
     if (isset($options)) {
         $this->outputOptions = array_merge($this->outputOptions, $options);
     }
 }
        xmlrpc_server_register_method($xmlrpc_server, "echoBoolean", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoString", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoInteger", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoFloat", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoBase64", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoDate", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoValue", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoStruct", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoStringArray", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoIntegerArray", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoFloatArray", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoStructArray", "method_echo");
        xmlrpc_server_register_method($xmlrpc_server, "echoVoid", "method_echo_void");
        xmlrpc_server_register_method($xmlrpc_server, "whichToolkit", "method_toolkit");
        xmlrpc_server_register_method($xmlrpc_server, "noInParams", "method_no_in_params");
        xmlrpc_server_register_introspection_callback($xmlrpc_server, "introspection_cb");
        //$val =  xmlrpc_decode($request_xml, &$method);
        //echo "xml: $request_xml\n";
        //echo "method: $method\nvar: ";
        //print_r($val);
        // parse xml and call method
        echo xmlrpc_server_call_method($xmlrpc_server, $request_xml, $response, array(output_type => "xml", version => "auto"));
        // free server resources
        $success = xmlrpc_server_destroy($xmlrpc_server);
    }
}
/********************
* API Documentation *
********************/
function introspection_cb($method)
{
<?php

$server = xmlrpc_server_create();
$method = 'abc';
xmlrpc_server_register_introspection_callback($server, $method);
xmlrpc_server_register_method($server, 'abc', $method);
echo 'Done';
<?php

$options = array();
$request = xmlrpc_encode_request("system.describeMethods", $options);
$server = xmlrpc_server_create();
function foo()
{
    return 11111;
}
class bar
{
    public static function test()
    {
        return 'foo';
    }
}
xmlrpc_server_register_introspection_callback($server, 'foobar');
xmlrpc_server_register_introspection_callback($server, array('bar', 'test'));
xmlrpc_server_register_introspection_callback($server, array('foo', 'bar'));
$options = array('output_type' => 'xml', 'version' => 'xmlrpc');
xmlrpc_server_call_method($server, $request, NULL, $options);