Author: Jan Schneider (jan@horde.org)
Inheritance: extends Horde_Translation
示例#1
0
文件: Soap.php 项目: raz0rsdge/horde
 /**
  * Will be registered as the handler for all methods called in the
  * SOAP server and will call the appropriate function through the registry.
  *
  * @todo  PEAR SOAP operates on a copy of this object at some unknown
  *        point and therefore doesn't have access to instance
  *        variables if they're set here. Instead, globals are used
  *        to track the method name and args for the logging code.
  *        Once this is PHP 5-only, the globals can go in favor of
  *        instance variables.
  *
  * @access private
  *
  * @param string $method    The name of the method called by the RPC request.
  * @param array $params     The passed parameters.
  * @param mixed $data       Unknown.
  *
  * @return mixed            The result of the called registry method.
  */
 public function __call($method, $params)
 {
     $method = str_replace('.', '/', $method);
     if (!empty($this->_params['allowedMethods']) && !in_array($method, $this->_params['allowedMethods'])) {
         return sprintf(Horde_Rpc_Translation::t("Method \"%s\" is not defined"), $method);
     }
     $GLOBALS['__horde_rpc_PhpSoap']['lastMethodCalled'] = $method;
     $GLOBALS['__horde_rpc_PhpSoap']['lastMethodParams'] = !empty($params) ? $params : array();
     if (!$GLOBALS['registry']->hasMethod($method)) {
         return sprintf(Horde_Rpc_Translation::t("Method \"%s\" is not defined"), $method);
     }
     return $GLOBALS['registry']->call($method, $params);
 }
示例#2
0
 /**
  * Sends an RPC request to the server and returns the result.
  *
  * @param string $request  PHP input stream (ignored).
  */
 public function getResponse($request)
 {
     ob_start(null, 1048576);
     $serverVars = $this->_request->getServerVars();
     switch ($serverVars['REQUEST_METHOD']) {
         case 'OPTIONS':
         case 'GET':
             if ($serverVars['REQUEST_METHOD'] == 'GET' && $this->_get['Cmd'] != 'OPTIONS' && stripos($serverVars['REQUEST_URI'], 'autodiscover/autodiscover.xml') === false) {
                 $this->_logger->debug('Accessing ActiveSync endpoing from browser or missing required data.');
                 throw new Horde_Rpc_Exception(Horde_Rpc_Translation::t('Trying to access the ActiveSync endpoint from a browser. Not Supported.'));
             }
             if (stripos($serverVars['REQUEST_URI'], 'autodiscover/autodiscover.xml') !== false) {
                 try {
                     if (!$this->_server->handleRequest('Autodiscover', null)) {
                         $this->_logger->err('Unknown error during Autodiscover.');
                         throw new Horde_Exception('Unknown Error');
                     }
                 } catch (Horde_Exception_AuthenticationFailure $e) {
                     $this->_sendAuthenticationFailedHeaders();
                     exit;
                 } catch (Horde_Exception $e) {
                     $this->_handleError($e);
                 }
                 break;
             }
             $this->_logger->debug('Horde_Rpc_ActiveSync::getResponse() starting for OPTIONS');
             try {
                 if (!$this->_server->handleRequest('Options', null)) {
                     throw new Horde_Exception('Unknown Error');
                 }
             } catch (Horde_Exception_AuthenticationFailure $e) {
                 $this->_sendAuthenticationFailedHeaders();
                 exit;
             } catch (Horde_Exception $e) {
                 $this->_handleError($e);
             }
             break;
         case 'POST':
             // Autodiscover Request
             if (stripos($serverVars['REQUEST_URI'], 'autodiscover/autodiscover.xml') !== false) {
                 $this->_get['Cmd'] = 'Autodiscover';
                 $this->_get['DeviceId'] = null;
             }
             $this->_logger->debug('Horde_Rpc_ActiveSync::getResponse() starting for ' . $this->_get['Cmd']);
             try {
                 $ret = $this->_server->handleRequest($this->_get['Cmd'], $this->_get['DeviceId']);
                 if ($ret === false) {
                     throw new Horde_Rpc_Exception(sprintf('Received FALSE while handling %s command.', $this->_get['Cmd']));
                 } elseif ($ret !== true) {
                     $this->_contentType = $ret;
                 }
             } catch (Horde_ActiveSync_Exception_InvalidRequest $e) {
                 $this->_logger->err(sprintf('Returning HTTP 400 while handling %s command', $this->_get['Cmd']));
                 $this->_handleError($e);
                 header('HTTP/1.1 400 Invalid Request ' . $e->getMessage());
                 exit;
             } catch (Horde_Exception_AuthenticationFailure $e) {
                 $this->_sendAuthenticationFailedHeaders();
                 exit;
             } catch (Horde_Exception $e) {
                 $this->_logger->err(sprintf('Returning HTTP 500 while handling %s command.', $this->_get['Cmd']));
                 $this->_handleError($e);
                 header('HTTP/1.1 500 ' . $e->getMessage());
                 exit;
             }
             break;
     }
 }
示例#3
0
 /**
  * Builds an XMLRPC request and sends it to the XMLRPC server.
  *
  * This statically called method is actually the XMLRPC client.
  *
  * @param string|Horde_Url $url     The path to the XMLRPC server on the
  *                                  called host.
  * @param string $method             The method to call.
  * @param Horde_Http_Client $client  The transport client
  * @param array $params              A hash containing any necessary
  *                                   parameters for the method call.
  *
  * @return mixed  The returned result from the method.
  * @throws Horde_Rpc_Exception
  */
 public static function request($url, $method, $client, $params = null)
 {
     $options['method'] = 'POST';
     $headers = array('User-Agent' => 'Horde RPC client', 'Content-Type', 'text/xml');
     try {
         $result = $client->post($url, xmlrpc_encode_request($method, $params), $headers);
     } catch (Horde_Http_Exception $e) {
         throw new Horde_Rpc_Exception($result);
     }
     if ($result->code != 200) {
         throw new Horde_Rpc_Exception(Horde_Rpc_Translation::t("Request couldn't be answered. Returned errorcode: ") . $result->code);
     } elseif (strpos($result->getBody(), '<?xml') === false) {
         throw new Horde_Rpc_Exception(Horde_Rpc_Translation::t("No valid XML data returned:") . "\n" . $result->getBody());
     } else {
         $response = @xmlrpc_decode(substr($result->getBody(), strpos($result->getBody(), '<?xml')));
         if (is_array($response) && isset($response['faultString'])) {
             throw new Horde_Rpc_Exception($response['faultString']);
         } elseif (is_array($response) && isset($response[0]) && is_array($response[0]) && isset($response[0]['faultString'])) {
             throw new Horde_Rpc_Exception($response[0]['faultString']);
         }
         return $response;
     }
 }
示例#4
0
 /**
  * Returns the plural translation of a message.
  *
  * @param string $singular  The singular version to translate.
  * @param string $plural    The plural version to translate.
  * @param integer $number   The number that determines singular vs. plural.
  *
  * @return string  The string translation, or the original string if no
  *                 translation exists.
  */
 public static function ngettext($singular, $plural, $number)
 {
     self::$_domain = 'Horde_Rpc';
     self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Rpc/locale';
     return parent::ngettext($singular, $plural, $number);
 }