Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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]['st'] = "";
     $XML_RPC_xh[$parser]['cm'] = 0;
     $XML_RPC_xh[$parser]['isf'] = 0;
     $XML_RPC_xh[$parser]['params'] = array();
     $XML_RPC_xh[$parser]['method'] = "";
     $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 {
         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} - " . $XML_RPC_xh[$parser]['params'][$i] . " \n";
             eval('$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;
 }