/** * Dekodiere die via XMLRPC übertragenen Atributte, dann führe die * parent Methode aus und transformiere die Antwort. * * @param xmlrpcmsg $xmlrpcmsg Die XMLRPC Anfrage * @return xmlrpcresp Gibt den Statuscode 1 für Erfolg zurück */ public function register($xmlrpcmsg) { $name = $xmlrpcmsg->getParam(0)->scalarval(); //Zugriff auf den ersten Parameter $age = $xmlrpcmsg->getParam(1)->scalarval(); //Zugriff auf den zweiten Parameter $res = parent::register($name, $age); //übergebe Parameter an parent Methode $resConverted = new xmlrpcval($res, "int"); //Kodiere Rückgabewert der parent Methode return new xmlrpcresp($resConverted); //Erstelle XMLRPC Antwort aus dem Rückgabewert für Clienten }
/** * Forward an xmlrpc request to another server, and return to client the response received. * @param xmlrpcmsg $m (see method docs below for a description of the expected parameters) * @return xmlrpcresp */ function forward_request($m) { // create client $timeout = 0; $url = php_xmlrpc_decode($m->getParam(0)); $c = new xmlrpc_client($url); if ($m->getNumParams() > 3) { // we have to set some options onto the client. // Note that if we do not untaint the received values, warnings might be generated... $options = php_xmlrpc_decode($m->getParam(3)); foreach ($options as $key => $val) { switch ($key) { case 'Cookie': break; case 'Credentials': break; case 'RequestCompression': $c->setRequestCompression($val); break; case 'SSLVerifyHost': $c->setSSLVerifyHost($val); break; case 'SSLVerifyPeer': $c->setSSLVerifyPeer($val); break; case 'Timeout': $timeout = (int) $val; break; } // switch } } // build call for remote server /// @todo find a weay to forward client info (such as IP) to server, either /// - as xml comments in the payload, or /// - using std http header conventions, such as X-forwarded-for... $method = php_xmlrpc_decode($m->getParam(1)); $pars = $m->getParam(2); $m = new xmlrpcmsg($method); for ($i = 0; $i < $pars->arraySize(); $i++) { $m->addParam($pars->arraymem($i)); } // add debug info into response we give back to caller xmlrpc_debugmsg("Sending to server {$url} the payload: " . $m->serialize()); return $c->send($m, $timeout); }
/** * Helper function: Looks up a page revision (most recent by default) in the wiki database * * @param xmlrpcmsg $params : string pagename [int version] * @return WikiDB _PageRevision object, or false if no such page */ function _getPageRevision($params) { global $request; $ParamPageName = $params->getParam(0); $ParamVersion = $params->getParam(1); $pagename = short_string_decode($ParamPageName->scalarval()); $version = $ParamVersion ? $ParamVersion->scalarval() : 0; // FIXME: test for version <=0 ?? $dbh = $request->getDbh(); if ($dbh->isWikiPage($pagename)) { $page = $dbh->getPage($pagename); if (!$version) { $revision = $page->getCurrentRevision(); } else { $revision = $page->getRevision($version); } return $revision; } return false; }
/** * Handles RPC request methods * @param {xmlrpcmsg} $request XML-RPC Request Object */ public function handleRPCMethod(xmlrpcmsg $request) { $username = $request->getParam(1)->getval(); $password = $request->getParam(2)->getval(); if ($this->authenticate($username, $password)) { $method = str_replace(array('blogger.', 'metaWeblog.', 'kapost.'), '', $request->methodname); if (!in_array($request->methodname, $this->exposed_methods) || !method_exists($this, $method)) { return $this->httpError(403, _t('KapostService.METHOD_NOT_ALLOWED', '_Action "{method}" is not allowed on class Kapost Service.', array('method' => $request->methodname))); } //Pack params into call to method if they are not the authentication parameters $params = array(); for ($i = 0; $i < $request->getNumParams(); $i++) { if ($i != 1 && $i != 2) { $params[] = php_xmlrpc_decode($request->getParam($i)); } } //Convert the custom fields to an associtive array if (array_key_exists(1, $params) && is_array($params[1]) && array_key_exists('custom_fields', $params[1])) { $params[1]['custom_fields'] = $this->struct_to_assoc($params[1]['custom_fields']); } //If transactions are supported start one for newPost and editPost if (($method == 'newPost' || $method == 'editPost') && DB::getConn()->supportsTransactions()) { DB::getConn()->transactionStart(); } //Call the method $response = call_user_func_array(array($this, $method), $params); if ($response instanceof xmlrpcresp) { //If transactions are supported check the response and rollback in the case of a fault if (($method == 'newPost' || $method == 'editPost' || $method == 'newMediaObject') && DB::getConn()->supportsTransactions()) { if ($response->faultCode() != 0) { DB::getConn()->transactionRollback(); } else { DB::getConn()->transactionEnd(); } } return $response; //Response is already encoded so return } //Encode the response $response = php_xmlrpc_encode($response); if (is_object($response) && $response instanceof xmlrpcval) { $response = new xmlrpcresp($response); if (($method == 'newPost' || $method == 'editPost' || $method == 'newMediaObject') && DB::getConn()->supportsTransactions()) { if ($response->faultCode() != 0) { DB::getConn()->transactionRollback(); } else { DB::getConn()->transactionEnd(); } } return $response; } return $this->httpError(500, _t('KapostService.INVALID_RESPONSE', '_Invalid response returned from {method}, response was: {response}', array('method' => $method, 'response' => print_r($response, true)))); } return $this->httpError(401, _t('KapostService.AUTH_FAIL', '_Authentication Failed, please check the App Center credentials for the SilverStripe end point.')); }