Welcome Guest, Not a member yet? Register   Sign In
[CI2.0] XML-RPC Server & Drivers
#1

[eluser]Schotte[/eluser]
Hi all,

I have started to work with CI 2.0 and been trying to port an XML-RPC server of mine across to the new version.

My thoughts are that it would be easiest to create a driver called Api for example. Then for each additional module that one creates one can simply dump one file into the Api/drivers folder that handles the API requests for that module.

Now for the XMLRPCS class. Some adaptations are necessary for it to work:

1) When defining the callback functions in the controller do it in this way (assuming driver is $api->module->function() ):
Code:
$config['functions']['mymodule.myfunction'] = array('function' => 'api.module.function');

2) In the _execute() method of xmlrpcs:

lines 285 - 292 replaced by this (in MY_Xmlrpcs)
Code:
if (($num_parts = count($method_parts)) <= 2 || $num_parts > 3)
{
    if ($objectCall && ! is_callable(array($method_parts['0'],$method_parts['1'])))
    {
        return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
    }
    elseif ( ! $objectCall && ! is_callable($this->methods[$methName]['function']))
    {
        return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
    }
}

lines 346 - 349 replaced by this
Code:
if (count($method_parts) <= 2)
                    {
                        return $this->object->$method_parts['1']($m);
                        //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m);
                    }
                    else
                    {
                        return $this->object->$method_parts['0']->$method_parts['1']->$method_parts['2']($m);
                        //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m);
                    }

Now to my problem. I basically circumvent the security check whether the requested method is callable or not (HUGE flaw). As I believe that I need to change this I have looked on the internet whether it would somehow be possible to get PHP's is_callable() working with 3 parts (driver, object, method) as opposed to 2 (object & method), but haven't turned up anything just yet.

Anyone of you bright guys got an idea on how this could be tackled?

Furthermore I am open to change my approach from drivers to a better architecture if you have one. I want the system to be easily scalable without having to manually edit the code when a new module is installed.

Regards,

Schotte
#2

[eluser]Jamie Rumbelow[/eluser]
Since the XML-RPC library is built into CodeIgniter's Standard Library, couldn't you just create a driver specific to your API, then use that to interface with the XML-RPC library directly? That would make more sense than trying to morph the actual library into a driver. Also, there are some architectural differences with different types of APIs you'll want to take into account.

Jamie
#3

[eluser]Schotte[/eluser]
[quote author="Jamie Rumbelow" date="1275887408"]Since the XML-RPC library is built into CodeIgniter's Standard Library, couldn't you just create a driver specific to your API, then use that to interface with the XML-RPC library directly?[/quote]

That's exactly what I am trying to do. The problem with using a driver is that it has the format $this->driver_name->driver_class->function(). To check whether this is a callable method does not work with is_callable(). Therefore I am looking for a solution how to check whether a driver is callable.

[quote author="Jamie Rumbelow" date="1275887408"]That would make more sense than trying to morph the actual library into a driver.[/quote]

I am not trying to morph the xml-rpc class into a driver. Just trying to change the function calls away from models. Drivers have the unique possibility of adding more functionality to them by altering the array "valid_drivers" (i.e. adding entries via mysql).

[quote author="Jamie Rumbelow" date="1275887408"]Also, there are some architectural differences with different types of APIs you'll want to take into account.[/quote]

Can you give brief examples?

Cheers for the quick response already,

Schotte
#4

[eluser]Schotte[/eluser]
*bump* Wink




Theme © iAndrew 2016 - Forum software by © MyBB