Author: Edd Dumbill (edd@usefulinc.com)
Author: Stig Bakken (stig@php.net)
Author: Martin Jansen (mj@php.net)
Author: Daniel Convissor (danielc@php.net)
Inheritance: extends XML_RPC_Base
Example #1
0
/**
 * This is the core XML-RPC client it takes the parameters passed in and bundles them up
 * and sends them as an XML-RPC request to the origin server, which processes them against
 * the central database and passes the results back to this client
 *
 * @param string $function  The name of the remote origin function to be called
 * @param array  $params    An array of the parameters to be passed to the origin function
 * @return mixed            The decoded response from the origin server
 */
function getFromOrigin($function, $params)
{
    /**
     * @package    MaxDal
     * @subpackage Delivery
     * @author     Chris Nutting <*****@*****.**>
     *
     */
    $conf = $GLOBALS['_MAX']['CONF'];
    // Create an XML-RPC client to talk to the XML-RPC server
    $client = new XML_RPC_Client($conf['origin']['script'], $conf['origin']['host'], $conf['origin']['port']);
    $message = new XML_RPC_Message($function, array());
    // Add the parameters to the message
    $message->addParam(new XML_RPC_Value($params, $GLOBALS['XML_RPC_String']));
    // Send the XML-RPC message to the server
    $response = $client->send($message, $conf['origin']['timeout'], $conf['origin']['protocol']);
    if (!$response || $response->faultCode() != 0) {
        if (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) {
            return OA_DELIVERY_CACHE_FUNCTION_ERROR;
        } else {
            return null;
        }
    } else {
        // Decode the serialized response
        $value = $response->value();
        $value = $value->scalarval();
        $value = unserialize($value);
    }
    return $value;
}
 function authenticate($username, $password)
 {
     /* check it's livejournal.com */
     $email = '';
     $struct = new XML_RPC_Value(array('username' => new XML_RPC_Value($username, 'string'), 'hpassword' => new XML_RPC_Value(md5($password), 'string')), 'struct');
     $message = new XML_RPC_Message('LJ.XMLRPC.login');
     $message->addparam($struct);
     $client = new XML_RPC_Client('/interface/xmlrpc', 'www.livejournal.com', 80);
     $result = $client->send($message, 5);
     if ($result && !$result->faultCode()) {
         /* Carefuly noting that no LJ API returns the email address, */
         /* because they suck.                                        */
         return true;
     } else {
         return false;
     }
 }
Example #3
0
 /**
  * Server Function: Multi-call
  *
  * @param	mixed
  * @return	object
  */
 public function multicall($m)
 {
     // Disabled
     return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
     $parameters = $m->output_parameters();
     $calls = $parameters[0];
     $result = array();
     foreach ($calls as $value) {
         $m = new XML_RPC_Message($value[0]);
         $plist = '';
         for ($i = 0, $c = count($value[1]); $i < $c; $i++) {
             $m->addParam(new XML_RPC_Values($value[1][$i], 'string'));
         }
         $attempt = $this->_execute($m);
         if ($attempt->faultCode() !== 0) {
             return $attempt;
         }
         $result[] = new XML_RPC_Values(array($attempt->value()), 'array');
     }
     return new XML_RPC_Response(new XML_RPC_Values($result, 'array'));
 }
Example #4
0
 /**
  * @return object  a new XML_RPC_Response object
  *
  * @uses XML_RPC_Message::getEncoding(), XML_RPC_Server::$encoding
  */
 function parseRequest($data = '')
 {
     global $XML_RPC_xh, $HTTP_RAW_POST_DATA, $XML_RPC_err, $XML_RPC_str, $XML_RPC_errxml, $XML_RPC_defencoding, $XML_RPC_Server_dmap;
     if ($data == '') {
         $data = $HTTP_RAW_POST_DATA;
     }
     $this->encoding = XML_RPC_Message::getEncoding($data);
     $parser_resource = xml_parser_create($this->encoding);
     $parser = (int) $parser_resource;
     $XML_RPC_xh[$parser] = array();
     $XML_RPC_xh[$parser]['cm'] = 0;
     $XML_RPC_xh[$parser]['isf'] = 0;
     $XML_RPC_xh[$parser]['params'] = array();
     $XML_RPC_xh[$parser]['method'] = '';
     $XML_RPC_xh[$parser]['stack'] = array();
     $XML_RPC_xh[$parser]['valuestack'] = array();
     $XML_RPC_xh[$parser]['max_data_len'] = strlen($data) * 2;
     $plist = '';
     // decompose incoming XML into request structure
     xml_parser_set_option($parser_resource, XML_OPTION_CASE_FOLDING, true);
     xml_set_element_handler($parser_resource, 'XML_RPC_se', 'XML_RPC_ee');
     xml_set_character_data_handler($parser_resource, 'XML_RPC_cd');
     if (!xml_parse($parser_resource, $data, 1)) {
         // return XML error as a faultCode
         $r = new XML_RPC_Response(0, $XML_RPC_errxml + xml_get_error_code($parser_resource), sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($parser_resource)), xml_get_current_line_number($parser_resource)));
         xml_parser_free($parser_resource);
     } elseif ($XML_RPC_xh[$parser]['isf'] > 1) {
         $r = new XML_RPC_Response(0, $XML_RPC_err['invalid_request'], $XML_RPC_str['invalid_request'] . ': ' . $XML_RPC_xh[$parser]['isf_reason']);
         xml_parser_free($parser_resource);
     } else {
         xml_parser_free($parser_resource);
         $m = new XML_RPC_Message($XML_RPC_xh[$parser]['method']);
         // now add parameters in
         for ($i = 0; $i < sizeof($XML_RPC_xh[$parser]['params']); $i++) {
             // print '<!-- ' . $XML_RPC_xh[$parser]['params'][$i]. "-->\n";
             $plist .= "{$i} - " . var_export($XML_RPC_xh[$parser]['params'][$i], true) . " \n";
             $m->addParam($XML_RPC_xh[$parser]['params'][$i]);
         }
         if ($this->debug) {
             XML_RPC_Server_debugmsg($plist);
         }
         // now to deal with the method
         $methName = $XML_RPC_xh[$parser]['method'];
         if (strpos($methName, 'system.') === 0) {
             $dmap = $XML_RPC_Server_dmap;
             $sysCall = 1;
         } else {
             $dmap = $this->dmap;
             $sysCall = 0;
         }
         if (isset($dmap[$methName]['function']) && is_string($dmap[$methName]['function']) && strpos($dmap[$methName]['function'], '::') !== false) {
             $dmap[$methName]['function'] = explode('::', $dmap[$methName]['function']);
         }
         if (isset($dmap[$methName]['function']) && is_callable($dmap[$methName]['function'])) {
             // dispatch if exists
             if (isset($dmap[$methName]['signature'])) {
                 $sr = $this->verifySignature($m, $dmap[$methName]['signature']);
             }
             if (!isset($dmap[$methName]['signature']) || $sr[0]) {
                 // if no signature or correct signature
                 if ($sysCall) {
                     $r = call_user_func($dmap[$methName]['function'], $this, $m);
                 } else {
                     $r = call_user_func($dmap[$methName]['function'], $m);
                 }
                 if (!is_a($r, 'XML_RPC_Response')) {
                     $r = new XML_RPC_Response(0, $XML_RPC_err['not_response_object'], $XML_RPC_str['not_response_object']);
                 }
             } else {
                 $r = new XML_RPC_Response(0, $XML_RPC_err['incorrect_params'], $XML_RPC_str['incorrect_params'] . ': ' . $sr[1]);
             }
         } else {
             // else prepare error response
             $r = new XML_RPC_Response(0, $XML_RPC_err['unknown_method'], $XML_RPC_str['unknown_method']);
         }
     }
     return $r;
 }
    function event_hook($event, &$bag, &$eventData)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'backend_display':
                    ?>
                    <fieldset style="margin: 5px">
                        <legend><?php 
                    echo PLUGIN_EVENT_WEBLOGPING_PING;
                    ?>
</legend>
<?php 
                    $noneclick = '';
                    foreach ($this->services as $index => $service) {
                        // Detect if the current checkbox needs to be saved. We use the field chk_timestamp to see,
                        // if the form has already been submitted and individual changes shall be preserved
                        $selected = $serendipity['POST']['chk_timestamp'] && $serendipity['POST']['announce_entries_' . $service['name']] || !isset($serendipity['POST']['chk_timestamp']) && $this->get_config($service['name']) == 'true' ? 'checked="checked"' : '';
                        $noneclick .= 'document.getElementById(\'serendipity[announce_entries_' . $service['name'] . ']\').checked = false; ';
                        $onclick = '';
                        if (!empty($service['supersedes'])) {
                            $onclick = 'onclick="';
                            $supersedes = explode(', ', $service['supersedes']);
                            foreach ($supersedes as $sid => $servicename) {
                                $onclick .= 'document.getElementById(\'serendipity[announce_entries_' . $servicename . ']\').checked = false; ';
                            }
                            $onclick .= '"';
                        }
                        $title = sprintf(PLUGIN_EVENT_WEBLOGPING_SENDINGPING, $service['name']) . (!empty($service['supersedes']) ? ' ' . sprintf(PLUGIN_EVENT_WEBLOGPING_SUPERSEDES, $service['supersedes']) : '');
                        ?>
                            <input <?php 
                        echo $onclick;
                        ?>
 class="input_checkbox" style="margin: 0px; padding: 0px; vertical-align: bottom;" type="checkbox" name="serendipity[announce_entries_<?php 
                        echo $service['name'];
                        ?>
]" id="serendipity[announce_entries_<?php 
                        echo $service['name'];
                        ?>
]" value="true" <?php 
                        echo $selected;
                        ?>
 />
                                <label title="<?php 
                        echo $title;
                        ?>
" style="vertical-align: bottom; margin: 0px; padding: 0px;" for="serendipity[announce_entries_<?php 
                        echo $service['name'];
                        ?>
]">&nbsp;<?php 
                        echo $service['name'];
                        ?>
&nbsp;&nbsp;</label><br />
<?php 
                    }
                    ?>
                            <input onclick="<?php 
                    echo $noneclick;
                    ?>
" class="input_checkbox" style="margin: 0px; padding: 0px; vertical-align: bottom;" type="checkbox" value="none" id="serendipity[announce_entries_none]" />
                                <label title="<?php 
                    echo NONE;
                    ?>
" style="vertical-align: bottom; margin: 0px; padding: 0px;" for="serendipity[announce_entries_none]">&nbsp;<?php 
                    echo NONE;
                    ?>
&nbsp;&nbsp;</label><br />
                    </fieldset>
<?php 
                    return true;
                    break;
                case 'backend_publish':
                    if (!class_exists('XML_RPC_Base')) {
                        include_once S9Y_PEAR_PATH . "XML/RPC.php";
                    }
                    // First cycle through list of services to remove superseding services which may have been checked
                    foreach ($this->services as $index => $service) {
                        if (!empty($service['supersedes']) && isset($serendipity['POST']['announce_entries_' . $service['name']])) {
                            $supersedes = explode(', ', $service['supersedes']);
                            foreach ($supersedes as $sid => $servicename) {
                                // A service has been checked that is superseded by another checked meta-service. Remove that service from the list of services to be ping'd
                                unset($serendipity['POST']['announce_entries_' . $servicename]);
                            }
                        }
                    }
                    foreach ($this->services as $index => $service) {
                        if (isset($serendipity['POST']['announce_entries_' . $service['name']]) || defined('SERENDIPITY_IS_XMLRPC') && serendipity_db_bool($this->get_config($service['name']))) {
                            if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) {
                                printf(PLUGIN_EVENT_WEBLOGPING_SENDINGPING . '...', $service['host']);
                            }
                            flush();
                            # XXX append $serendipity['indexFile'] to baseURL?
                            $args = array(new XML_RPC_Value($serendipity['blogTitle'], 'string'), new XML_RPC_Value($serendipity['baseURL'], 'string'));
                            if ($service['extended']) {
                                # the checkUrl: for when the main page is not really the main page
                                $args[] = new XML_RPC_Value('', 'string');
                                # the rssUrl
                                $args[] = new XML_RPC_Value($serendipity['baseURL'] . 'rss.php?version=2.0', 'string');
                            }
                            $message = new XML_RPC_Message($service['extended'] ? 'weblogUpdates.extendedPing' : 'weblogUpdates.ping', $args);
                            $client = new XML_RPC_Client(trim($service['path']), trim($service['host']));
                            # 15 second timeout may not be long enough for weblogs.com
                            $message->createPayload();
                            $options = array();
                            serendipity_plugin_api::hook_event('backend_http_request', $options, 'weblogping');
                            serendipity_request_start();
                            $req = new HTTP_Request("http://" . $service['host'] . $service['path'], $options);
                            $req->setMethod(HTTP_REQUEST_METHOD_POST);
                            $req->addHeader("Content-Type", "text/xml");
                            if (strtoupper(LANG_CHARSET) != 'UTF-8') {
                                $payload = utf8_encode($message->payload);
                            } else {
                                $payload = $message->payload;
                            }
                            $req->addRawPostData($payload);
                            $http_result = $req->sendRequest();
                            $http_response = $req->getResponseBody();
                            $xmlrpc_result = $message->parseResponse($http_response);
                            if ($xmlrpc_result->faultCode()) {
                                $out = sprintf(PLUGIN_EVENT_WEBLOGPING_SEND_FAILURE . "<br />", htmlspecialchars($xmlrpc_result->faultString()));
                            } else {
                                $out = PLUGIN_EVENT_WEBLOGPING_SEND_SUCCESS . "<br />";
                            }
                            serendipity_request_end();
                            if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) {
                                echo $out;
                            }
                        }
                    }
                    return true;
                    break;
                case 'external_plugin':
                    if ($eventData == 'xmlrpc_ping') {
                        echo "XMLRPC START\n";
                        @define('SERENDIPITY_IS_XMLRPC', true);
                        @define('SERENDIPITY_XMLRPC_VERBOSE', true);
                        $this->event_hook('backend_publish', $bag, $eventData);
                        echo "XMLRPC DONE\n";
                    }
                    return true;
                case 'frontend_display':
                case 'backend_insert':
                case 'backend_update':
                case 'backend_draft':
                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
Example #6
0
/**
 * A function to handle XML-RPC advertisement view requests. 2.0 version
 *
 * @deprecated
 *
 * @param XML_RPC_Message $params
 * @return XML_RPC_Response
 */
function OA_Delivery_XmlRpc_View_PAN($params)
{
    // Extract the remote_info parameter
    $remoteInfoXmlRpcValue = $params->getParam(0);
    $remote_info = XML_RPC_Decode($params->getParam(0));
    // Add empty cookies array
    $remote_info['cookies'] = array();
    // Create environment array
    $remoteInfoXmlRpcValue = XML_RPC_encode($remote_info);
    // Extract the context param
    if ($params->getNumParams() > 6) {
        $contextXmlRpcValue = $params->getParam(6);
    } else {
        $contextXmlRpcValue = new XML_RPC_Value(array(), $XML_RPC_Array);
    }
    // Recreate XML-RPC message
    $msg = new XML_RPC_Message('phpAds.view', array($remoteInfoXmlRpcValue, $params->getParam(1), $params->getParam(2), $params->getParam(3), $params->getParam(4), $params->getParam(5), $contextXmlRpcValue));
    // Relay call to openads.view
    $xmlResponse = OA_Delivery_XmlRpc_View($msg);
    // Check for errors as-is
    return $xmlResponse;
}
 function parseRequest($data = '')
 {
     global $HTTP_RAW_POST_DATA;
     //-------------------------------------
     //  Get Data
     //-------------------------------------
     if ($data == '') {
         $data = $HTTP_RAW_POST_DATA;
     }
     //-------------------------------------
     //  Set up XML Parser
     //-------------------------------------
     $parser = xml_parser_create($this->xmlrpc_defencoding);
     $parser_object = new XML_RPC_Message("filler");
     $parser_object->xh[$parser] = array();
     $parser_object->xh[$parser]['isf'] = 0;
     $parser_object->xh[$parser]['isf_reason'] = '';
     $parser_object->xh[$parser]['params'] = array();
     $parser_object->xh[$parser]['stack'] = array();
     $parser_object->xh[$parser]['valuestack'] = array();
     $parser_object->xh[$parser]['method'] = '';
     xml_set_object($parser, $parser_object);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
     xml_set_element_handler($parser, 'open_tag', 'closing_tag');
     xml_set_character_data_handler($parser, 'character_data');
     //xml_set_default_handler($parser, 'default_handler');
     //-------------------------------------
     //  PARSE + PROCESS XML DATA
     //-------------------------------------
     if (!xml_parse($parser, $data, 1)) {
         // return XML error as a faultCode
         $r = new XML_RPC_Response(0, $this->xmlrpcerrxml + xml_get_error_code($parser), sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)));
         xml_parser_free($parser);
     } elseif ($parser_object->xh[$parser]['isf']) {
         return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_retrun']);
     } else {
         xml_parser_free($parser);
         $m = new XML_RPC_Message($parser_object->xh[$parser]['method']);
         $plist = '';
         for ($i = 0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) {
             $plist .= "{$i} - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE) . ";\n";
             $m->addParam($parser_object->xh[$parser]['params'][$i]);
         }
         if ($this->debug === TRUE) {
             echo "<pre>";
             echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
             echo "</pre>";
         }
         $r = $this->execute($m);
     }
     //-------------------------------------
     //  SET DEBUGGING MESSAGE
     //-------------------------------------
     if ($this->debug === TRUE) {
         $this->debug_msg = "<!-- DEBUG INFO:\n\n" . $plist . "\n END DEBUG-->\n";
     }
     return $r;
 }
Example #8
0
 /**
  *  XMLRPC methods wrapper
  *  Encode XMLRPC request message, send it, receive and decode response.
  *
  *  @param method string, method name
  *  @param gettedPars array, returned by func_get_args() in called method
  *
  *  @return array, PHP hash with response
  */
 public function callMethod($method, $gettedPars)
 {
     $parr = array();
     $XML_RPC_val = new XML_RPC_Value();
     foreach ($this->mdefs[$method]['p'] as $i => $p) {
         $parr[$p] = new XML_RPC_Value();
         if ($this->mdefs[$method]['t'][$i] == 'array') {
             $parr[$p] = XML_RPC_encode($gettedPars[$i]);
         } else {
             $parr[$p]->addScalar($gettedPars[$i], $this->mdefs[$method]['t'][$i]);
         }
     }
     $XML_RPC_val->addStruct($parr);
     $fullmethod = $this->mdefs[$method]['m'];
     $msg = new XML_RPC_Message($fullmethod, array($XML_RPC_val));
     if ($this->verbose) {
         echo "parr:\n";
         var_dump($parr);
         echo "message:\n";
         echo $msg->serialize() . "\n";
     }
     $this->client->setDebug($this->debug);
     $res = $this->client->send($msg);
     if (!$res) {
         return $this->client->errstr;
     }
     if ($res->faultCode() > 0) {
         return PEAR::raiseError("XR_CcClient::{$method}:" . $res->faultString() . " " . $res->faultCode() . "\n", $res->faultCode(), PEAR_ERROR_RETURN);
     }
     if ($this->verbose) {
         echo "result:\n";
         echo $res->serialize();
     }
     $val = $res->value();
     $resp = XML_RPC_decode($res->value());
     return $resp;
 }
Example #9
0
 function parseRequest($data = "")
 {
     global $XML_RPC_xh, $HTTP_RAW_POST_DATA;
     global $XML_RPC_err, $XML_RPC_str, $XML_RPC_errxml, $XML_RPC_defencoding, $XML_RPC_Server_dmap;
     if ($data == "") {
         $data = $HTTP_RAW_POST_DATA;
     }
     $parser = xml_parser_create($XML_RPC_defencoding);
     $XML_RPC_xh[$parser] = array();
     $XML_RPC_xh[$parser]['isf'] = 0;
     $XML_RPC_xh[$parser]['isf_reason'] = '';
     $XML_RPC_xh[$parser]['params'] = array();
     $XML_RPC_xh[$parser]['method'] = "";
     $XML_RPC_xh[$parser]['stack'] = array();
     $XML_RPC_xh[$parser]['valuestack'] = array();
     $plist = '';
     // decompose incoming XML into request structure
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
     xml_set_element_handler($parser, "XML_RPC_se", "XML_RPC_ee");
     xml_set_character_data_handler($parser, "XML_RPC_cd");
     xml_set_default_handler($parser, "XML_RPC_dh");
     if (!xml_parse($parser, $data, 1)) {
         // return XML error as a faultCode
         $r = new XML_RPC_Response(0, $XML_RPC_errxml + xml_get_error_code($parser), sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)));
         xml_parser_free($parser);
     } else {
         if ($XML_RPC_xh[$parser]['isf'] > 1) {
             $r = new XML_RPC_Response(0, $XML_RPC_err['invalid_request'], $XML_RPC_str['invalid_request'] . ': ' . $XML_RPC_xh[$parser]['isf_reason']);
             xml_parser_free($parser);
         } else {
             xml_parser_free($parser);
             $m = new XML_RPC_Message($XML_RPC_xh[$parser]['method']);
             // now add parameters in
             for ($i = 0; $i < sizeof($XML_RPC_xh[$parser]['params']); $i++) {
                 // print "<!-- " . $XML_RPC_xh[$parser]['params'][$i]. "-->\n";
                 $plist .= "{$i} - " . var_export($XML_RPC_xh[$parser]['params'][$i], true) . " \n";
                 @$m->addParam($XML_RPC_xh[$parser]['params'][$i]);
             }
             XML_RPC_Server_debugmsg($plist);
             // now to deal with the method
             $methName = $XML_RPC_xh[$parser]['method'];
             if (ereg("^system\\.", $methName)) {
                 $dmap = $XML_RPC_Server_dmap;
                 $sysCall = 1;
             } else {
                 $dmap = $this->dmap;
                 $sysCall = 0;
             }
             if (isset($dmap[$methName]['function'])) {
                 // dispatch if exists
                 if (isset($dmap[$methName]['signature'])) {
                     $sr = $this->verifySignature($m, $dmap[$methName]['signature']);
                 }
                 if (!isset($dmap[$methName]['signature']) || $sr[0]) {
                     // if no signature or correct signature
                     if ($sysCall) {
                         eval('$r=' . $dmap[$methName]['function'] . '($this, $m);');
                     } else {
                         eval('$r=' . $dmap[$methName]['function'] . '($m);');
                     }
                 } else {
                     $r = new XML_RPC_Response(0, $XML_RPC_err["incorrect_params"], $XML_RPC_str["incorrect_params"] . ": " . $sr[1]);
                 }
             } else {
                 // else prepare error response
                 $r = new XML_RPC_Response(0, $XML_RPC_err["unknown_method"], $XML_RPC_str["unknown_method"]);
             }
         }
     }
     return $r;
 }
Example #10
0
     */
    require_once 'XML/RPC.php';
} else {
    if (substr(dirname(__FILE__), -9, -6) != 'XML') {
        echo "The parent directory must be named 'XML'.\n";
        exit;
    }
    ini_set('include_path', '../../' . PATH_SEPARATOR . '.' . PATH_SEPARATOR . ini_get('include_path'));
    /**
     * Get the needed class from the parent directory
     */
    require_once '../RPC.php';
}
$input = "First lfs\n\nSecond crlfs\r\n\r\nThird crs\r\rFourth line";
$expect_removed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<methodCall>\n\n<methodName>nada</methodName>\n\n<params>\n\n<param>\n\n<value><string>First lfs\n\nSecond crlfs\n\nThird crs\n\nFourth line</string></value>\n\n</param>\n\n</params>\n\n</methodCall>\n\n";
$expect_not_removed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<methodCall>\n\n<methodName>nada</methodName>\n\n<params>\n\n<param>\n\n<value><string>First lfs\n\n\n\nSecond crlfs\n\n\n\nThird crs\n\n\n\nFourth line</string></value>\n\n</param>\n\n</params>\n\n</methodCall>\n\n";
$msg = new XML_RPC_Message('nada', array(XML_RPC_encode($input)));
$msg->createPayload();
if ($msg->payload == $expect_removed) {
    echo "passed\n";
} else {
    echo "PROBLEM\n";
}
$msg = new XML_RPC_Message('nada', array(XML_RPC_encode($input)));
$msg->remove_extra_lines = false;
$msg->createPayload();
if ($msg->payload == $expect_not_removed) {
    echo "passed\n";
} else {
    echo "PROBLEM\n";
}
Example #11
0
 /**
  * Transmit the RPC request via HTTP 1.0 protocol
  * Requests should be sent using XML_RPC_Client send() rather than
  * calling this method directly.
  *
  * @param XML_RPC_Message $msg      the XML_RPC_Message object
  * @param string          $server   the server to send the request to
  * @param int             $port     the server port send the request to
  * @param int             $timeout  how many seconds to wait for the request
  *                                  before giving up
  * @param string          $userName a user name for accessing the RPC server
  * @param string          $password a password for accessing the RPC server
  * @return XML_RPC_Response|int 0 is returned if any problems happen.
  * @see XML_RPC_Client::send()
  */
 protected function sendPayloadHTTP10(XML_RPC_Message $msg, $server, $port, $timeout = 0, $userName = '', $password = '')
 {
     // Preemptive BC hacks for fools calling sendPayloadHTTP10() directly
     if ($userName != $this->userName) {
         $this->setCredentials($userName, $password);
     }
     // Only create the payload if it was not created previously
     if (empty($msg->payload)) {
         $msg->createPayload();
     }
     $this->createHeaders($msg);
     $op = $this->headers . "\r\n\r\n";
     $op .= $msg->payload;
     if ($this->debug) {
         echo "\n<pre>---SENT---\n";
         echo $op;
         echo "\n---END---</pre>\n";
     }
     /*
      * If we're using a proxy open a socket to the proxy server
      * instead to the xml-rpc server
      */
     if ($this->proxy) {
         if ($this->proxyProtocol === 'http://') {
             $protocol = '';
         } else {
             $protocol = $this->proxyProtocol;
         }
         if ($timeout > 0) {
             $fp = @fsockopen($protocol . $this->proxy, $this->proxyPort, $this->errNo, $this->errString, $timeout);
         } else {
             $fp = @fsockopen($protocol . $this->proxy, $this->proxyPort, $this->errNo, $this->errString);
         }
     } else {
         if ($this->protocol === 'http://') {
             $protocol = '';
         } else {
             $protocol = $this->protocol;
         }
         if ($timeout > 0) {
             $fp = @fsockopen($protocol . $server, $port, $this->errNo, $this->errString, $timeout);
         } else {
             $fp = @fsockopen($protocol . $server, $port, $this->errNo, $this->errString);
         }
     }
     /*
      * Just raising the error without returning it is strange,
      * but keep it here for backwards compatibility.
      */
     if (!$fp && $this->proxy) {
         $this->raiseError('Connection to proxy server ' . $this->proxy . ':' . $this->proxyPort . ' failed. ' . $this->errString, XML_RPC_ERROR_CONNECTION_FAILED);
         return 0;
     } elseif (!$fp) {
         $this->raiseError('Connection to RPC server ' . $server . ':' . $port . ' failed. ' . $this->errString, XML_RPC_ERROR_CONNECTION_FAILED);
         return 0;
     }
     if ($timeout) {
         /*
          * Using socket_set_timeout() because stream_set_timeout()
          * was introduced in 4.3.0, but we need to support 4.2.0.
          */
         socket_set_timeout($fp, $timeout);
     }
     if (!fputs($fp, $op, strlen($op))) {
         $this->errString = 'Write error';
         return 0;
     }
     $resp = $msg->parseResponseFile($fp);
     $meta = socket_get_status($fp);
     if ($meta['timed_out']) {
         fclose($fp);
         $this->errString = 'RPC server did not send response before timeout.';
         $this->raiseError($this->errString, XML_RPC_ERROR_CONNECTION_FAILED);
         return 0;
     }
     fclose($fp);
     return $resp;
 }
Example #12
0
 /**
  * A method to perform a call to the OAC XML-RPC server
  *
  * @param string $methodName The RPC method name
  * @param int    $authType   Type of required authentication, see constants
  * @param array  $aParams    Array of XML_RPC_Values
  * @return mixed The returned value or PEAR_Error on error
  */
 function call($methodName, $authType, $aParams = null, $recursionLevel = 0)
 {
     $aPref = $GLOBALS['_MAX']['PREF'];
     $oMsg = new XML_RPC_Message('oac.' . $methodName);
     $oMsg->remove_extra_lines = $this->remove_extra_lines;
     $aHeader = array('protocolVersion' => OA_DAL_CENTRAL_PROTOCOL_VERSION, 'ph' => OA_Dal_ApplicationVariables::get('platform_hash'));
     if ($authType & OA_DAL_CENTRAL_AUTH_M2M) {
         if (empty($this->oCentral)) {
             MAX::raiseError('M2M authentication used with a non M2M-enabled OA_Central object');
         }
         $aHeader['accountId'] = (int) $this->oCentral->accountId;
         $aHeader['m2mPassword'] = OA_Dal_Central_M2M::getM2MPassword($this->oCentral->accountId);
         if (empty($aHeader['m2mPassword']) || isset($GLOBALS['OX_CLEAR_M2M_PASSWORD'][$this->oCentral->accountId]) && $GLOBALS['OX_CLEAR_M2M_PASSWORD'][$this->oCentral->accountId] == true) {
             // No password stored, connect!
             $result = $this->oCentral->connectM2M();
             if (PEAR::isError($result)) {
                 return $result;
             }
             $aHeader['m2mPassword'] = $result;
         }
     }
     if ($authType & OA_DAL_CENTRAL_AUTH_SSO) {
         $aHeader['ssoUsername'] = $this->ssoUsername;
         $aHeader['ssoPassword'] = $this->ssoPassword;
     }
     if ($authType & OA_DAL_CENTRAL_AUTH_CAPTCHA) {
         $aHeader['ssoCaptcha'] = isset($_REQUEST['captcha-value']) ? $_REQUEST['captcha-value'] : '';
         $aHeader['ssoCaptchaRandom'] = isset($_REQUEST['captcha-random']) ? $_REQUEST['captcha-random'] : '';
     }
     $oMsg->addParam(XML_RPC_encode($aHeader));
     if (is_array($aParams)) {
         foreach ($aParams as $oParam) {
             $oMsg->addParam($oParam);
         }
     }
     OA::disableErrorHandling();
     $oResponse = $this->oXml->send($oMsg, OAC_RPC_TIMEOUT);
     OA::enableErrorHandling();
     if (!$oResponse) {
         return new PEAR_Error('XML-RPC connection error', OA_CENTRAL_ERROR_XML_RPC_CONNECTION_ERROR);
     }
     if ($oResponse->faultCode() || $oResponse->faultString()) {
         // Deal with particular response codes at Rpc level, avoiding endless recursion
         if (!$recursionLevel) {
             switch ($oResponse->faultCode()) {
                 case OA_CENTRAL_ERROR_PLATFORM_DOES_NOT_EXIST:
                     OA::disableErrorHandling();
                     $oSync = new OA_Sync();
                     $oSync->checkForUpdates();
                     OA::enableErrorHandling();
                     return $this->call($methodName, $authType, $aParams, ++$recursionLevel);
                 case OA_CENTRAL_ERROR_ERROR_NOT_AUTHORIZED:
                     if (!($authType & OA_DAL_CENTRAL_AUTH_M2M)) {
                         break;
                     } else {
                         // Go with OA_CENTRAL_ERROR_M2M_PASSWORD_INVALID
                     }
                 case OA_CENTRAL_ERROR_M2M_PASSWORD_INVALID:
                     // OAP was asked to connect the account to get a password
                     // Set clear the password and retry (old password is in DB in case of problems with receiving new one)
                     $GLOBALS['OX_CLEAR_M2M_PASSWORD'][$this->oCentral->accountId] = true;
                     return $this->call($methodName, $authType, $aParams, ++$recursionLevel, true);
                 case OA_CENTRAL_ERROR_M2M_PASSWORD_EXPIRED:
                     $result = $this->_reconnectM2M();
                     if (PEAR::isError($result)) {
                         return $result;
                     }
                     return $this->call($methodName, $authType, $aParams, ++$recursionLevel);
             }
         }
         return new PEAR_Error($oResponse->faultString(), $oResponse->faultCode());
     }
     $ret = XML_RPC_decode($oResponse->value());
     // handling unknown server errors
     // this may happen due to difference in Java/PHP XML-RPC handling errors
     if (is_array($ret) && (isset($ret['faultCode']) || isset($ret['faultCode']))) {
         return new PEAR_Error('Unknown server error', OA_CENTRAL_ERROR_SERVER_ERROR);
     }
     return $ret;
 }
Example #13
0
		/**
		 * Send request to server
		 *
		 * @access private
		 * @param string $command Commend
		 * @param object $params PEAR Params object
		 */
		private function Request($command, $params, $ignorerewrite = false)
		{
			$msg = new XML_RPC_Message($command, $params);
			
			$cache = $this->CacheGet($msg->serialize(), $ignorerewrite);
			if (!$cache)
			{	
				$this->RPClient->setDebug(0);
				$response = $this->RPClient->send($msg);
				
				if (!$response || !$response->faultCode()) 
				{
					try
					{
				    	$val = $response->value();
				    
				    	$retval = XML_RPC_decode($val);
				    	$this->CachePut($msg->serialize(), $retval);
				    }
					catch(Exception $e)
					{
						return false;
					}
					
				    return $retval;
				} 
				else 
				{
				    /*
				     * Display problems that have been gracefully cought and
				     * reported by the xmlrpc.php script
				     */			    
				    throw new Exception(_("RPC Fail")."(".$response->faultCode().") ".$response->faultString());
				}
			}
			else 
				return $cache;
		}