Welcome Guest, Not a member yet? Register   Sign In
Extending sendPayload method of XML_RPC_Client class for SSL
#1

[eluser]skunkbad[/eluser]
I've been working to extend the sendPayload method of the XML_RPC_Client class so that it uses cURL and operates on HTTPS. Its only half working, and I'm wondering if anyone can help:

Code:
function sendPayload($msg)
{
    if(empty($msg->payload))
    {
        // $msg = XML_RPC_Messages
        $msg->createPayload();
    }

    $ch = curl_init();

    if( ! is_resource( $ch ) )
    {
        error_log($this->xmlrpcstr['http_error']);
        $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']);
        return $r;
    }

    $header = array(
        'POST ' . $this->path,
        'Host: ' . $this->server,
        'Content-Type: text/xml',
        'User-Agent: ' . $this->xmlrpcName,
        'Content-Length: ' . strlen($msg->payload),
        $msg->payload
    );

    if( $this->port == '443' )
    {
        $pre = 'https://';
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
    }
    else
    {
        $pre = 'http://';
    }

    curl_setopt( $ch, CURLOPT_URL, $pre . $this->server . $this->path );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $msg->payload );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );

    if( $resp = curl_exec( $ch ) )
    {
        var_dump( $resp );
        return $resp;
    }
    else
    {
        error_log($this->xmlrpcstr['http_error']);
        $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']);
        return $r;
    }

    curl_close($ch);
}

This is the output:

Code:
string(328) "<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>you_said</name>
<value>
<string>How is it going?</string>
</value>
</member>
<member>
<name>i_respond</name>

<value>
<string>Not bad at all.</string>
</value>
</member>
</struct></value>
</param>
</params>
</methodResponse>"
<hr />PHP E_NOTICE #8 - Date/Time: 6/24/2011 17:23:25
<br />File: <b>C:\xampp\htdocs\beta-cps\system\libraries\Xmlrpc.php</b>
<br />Line: <b>284</b>
<br /><b>Trying to get property of non-object</b><hr /><hr />PHP E_NOTICE #8 - Date/Time: 6/24/2011 17:23:25

<br />File: <b>C:\xampp\htdocs\beta-cps\system\libraries\Xmlrpc.php</b>
<br />Line: <b>286</b>
<br /><b>Trying to get property of non-object</b><hr />
#2

[eluser]skunkbad[/eluser]
I figured out that I just needed to do two things:

1) Have cURL include the header in the result.
2) Bypass fread() in parseResponse() and instead of passing the resource to it, pass the result.

So it looks like everything is working will SSL. What I'd like to know is the best way to extend or use the modifications I made to the XML_RPC_Client and XML_RPC_Message classes without touching system files. I was working directly on Xmlrpc.php.
#3

[eluser]skunkbad[/eluser]
I figured it out. Wanted to post my MY_Xmlrpc file contents here, but it's too big. I posted it in the Wiki if anyone is interested:

http://codeigniter.com/wiki/MY_Xmlrpc/
#4

[eluser]skunkbad[/eluser]
I thought I had it working, but hadn't tested enough. I'm probably overlooking something simple, but the requests array gets wiped out before it gets sent to the server. If anyone has time and can help, my MY_Xmlrpc and MY_Xmlrpcs code is at:

https://bitbucket.org/skunkbad/my_xmlrpc




Theme © iAndrew 2016 - Forum software by © MyBB