From a80933621e42325f0df7d414bb1efb3fd256249d Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 3 Aug 2010 11:19:08 +0000 Subject: [PATCH] Added comments :wq git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19358 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_config.inc | 14 ++++-- gosa-core/include/class_jsonRPC.inc | 74 ++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/gosa-core/include/class_config.inc b/gosa-core/include/class_config.inc index 70bba3876..7c9fe51fc 100644 --- a/gosa-core/include/class_config.inc +++ b/gosa-core/include/class_config.inc @@ -314,13 +314,19 @@ class config { } - function getRpcHandle($url="", $user="", $pwd="", $digest = FALSE ) + function getRpcHandle($connectUrl="", $username="", $userPassword="", $authModeDigest=FALSE) { + // Get conenct information, if no info was given use the default values from gosa.conf + $connectUrl = (!empty($connectUrl)) ? $connectUrl : $this->get_cfg_value('core','gosaRpcServer'); + $username = (!empty($username)) ? $username : $this->get_cfg_value('core','gosaRpcUser'); + $userPassword = (!empty($userPassword)) ? $userPassword : $this->get_cfg_value('core','gosaRpcPassword'); + $authModeDigest = $authModeDigest; + // Create jsonRPC handle on demand. - if(!isset($this->jsonRPChandle[$url][$user]) || !$this->jsonRPChandle[$url][$user]){ - $this->jsonRPChandle[$url][$user] = new jsonRPC($this, $url, $user, $pwd, $digest); + if(!isset($this->jsonRPChandle[$connectUrl][$username]) || !$this->jsonRPChandle[$connectUrl][$username]){ + $this->jsonRPChandle[$connectUrl][$username] = new jsonRPC($this, $connectUrl, $username, $userPassword, $authModeDigest); } - return($this->jsonRPChandle[$url][$user]); + return($this->jsonRPChandle[$connectUrl][$username]); } diff --git a/gosa-core/include/class_jsonRPC.inc b/gosa-core/include/class_jsonRPC.inc index d29f47f64..6d7e98efa 100644 --- a/gosa-core/include/class_jsonRPC.inc +++ b/gosa-core/include/class_jsonRPC.inc @@ -1,4 +1,6 @@ config = $config; $this->id = 0; // Get connection data - $this->connectUrl = (!empty($connectUrl)) ? $connectUrl : $this->config->get_cfg_value('core','gosaRpcServer'); - $this->username = (!empty($username)) ? $username : $this->config->get_cfg_value('core','gosaRpcUser'); - $this->userPassword = (!empty($userPassword)) ? $userPassword : $this->config->get_cfg_value('core','gosaRpcPassword'); + $this->connectUrl = $connectUrl; + $this->username = $username; + $this->userPassword = $userPassword; $this->authModeDigest = $authModeDigest; // Put some usefull info in the logs @@ -33,6 +45,11 @@ class jsonRPC { $this->__login(); } + + /*! \brief + * @param + * @return + */ private function __login() { // Init Curl handler @@ -55,13 +72,20 @@ class jsonRPC { $this->login($this->username, $this->userPassword); } } - + + /*! \brief Returns the last HTTP status code. + * @return int The last status code. + */ public function getHTTPstatusCode() { return((isset($this->lastStats['http_code']))? $this->lastStats['http_code'] : -1 ); } + + /*! \brief Returns the last error string. + * @return string The last error message. + */ public function get_error() { if($this->lastStats['http_code'] != 200){ @@ -71,23 +95,39 @@ class jsonRPC { } } + + /*! \brief Returns TRUE if the last action was successfull else FALSE. + * @return boolean TRUE on success else FALSE. + */ public function success() { return(curl_errno($this->curlHandler) == 0 && $this->lastStats['http_code'] == 200); } + + /*! \brief The class destructor, it destroys open rpc handles if needed. + */ public function __destruct() { if($this->curlHandler){ - curl_close($this->curlHandler); + curl_close($this->curlHandler); } } + + /*! \brief This is some kind of catch-all method, all unknown method names will + * will be interpreted as rpc request. + * If you call "$this->blafasel" this method will initiate an rpc request + * for method 'blafasel'. + * @param string method The rpc method to execute. + * @param params array The parameter to use. + * @return mixed The request result. + */ public function __call($method,$params) { // Check if handle is still valid! if(!$this->curlHandler && $this->lastAction != 'login'){ - $this->__login(); + $this->__login(); } // Start request @@ -95,7 +135,7 @@ class jsonRPC { $response = $this->request($method,$params); if($this->success()){ DEBUG (DEBUG_RPC, __LINE__, __FUNCTION__, __FILE__, - (is_array($response['result']))?$response['result']:bold($response['result']), "Result: "); + (is_array($response['result']))?$response['result']:bold($response['result']), "Result: "); }else{ DEBUG (DEBUG_RPC, __LINE__, __FUNCTION__, __FILE__,bold($this->get_error())."
".$response, "Result (FAILED): "); } @@ -103,7 +143,13 @@ class jsonRPC { return($response['result']); } - + + /*! \brief This method finally initiates the real RPC requests and handles + * the result from the server. + * @param string method The method to call + * @param array params The paramter to use. + * @return mixed The server response. + */ private function request($method, $params) { // Set last action @@ -111,7 +157,7 @@ class jsonRPC { // Reset stats of last request. $this->lastStats = array(); - + // Validate input values if (!is_scalar($method)) trigger_error('jsonRPC::__call requires a scalar value as first parameter!'); if (is_array($params)) { @@ -131,11 +177,15 @@ class jsonRPC { // Set current result stats. $this->lastStats = curl_getinfo($this->curlHandler); - + return($response); } - + + /*! \brief Returns the HTTP status message for a given HTTP status code. + * @param int code The status to code to return a message for. + * @return string The corresponding status message. + */ public static function getHttpStatusCodeMessage($code) { $codes = array( -- 2.30.2