From 8671df505b7dc941ee4aa811858c1cff11f109dd Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 26 Mar 2008 14:47:12 +0000 Subject: [PATCH] Updated socket & Daemon class -Updated error message. Added timeout message git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9999 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_gosaSupportDaemon.inc | 111 +++++++++++++++++- gosa-core/include/class_socketClient.inc | 33 +++++- 2 files changed, 136 insertions(+), 8 deletions(-) diff --git a/gosa-core/include/class_gosaSupportDaemon.inc b/gosa-core/include/class_gosaSupportDaemon.inc index 219fdbb36..8270f9ffc 100644 --- a/gosa-core/include/class_gosaSupportDaemon.inc +++ b/gosa-core/include/class_gosaSupportDaemon.inc @@ -134,28 +134,47 @@ class gosaSupportDaemon } - public function FAI_get_packages($release,$package = "") + public function FAI_get_packages($release,$attrs, $package="") { $this->reset_error(); + $ret = array(); + if(!is_array($attrs) || !count($attrs)){ + trigger_error("Second parameter must be an array. With at least one attribute name."); + return($ret); + } + + $attr = ""; + foreach($attrs as $at){ +# $attr.= ""; + } + if(empty($package)){ $xml_msg = "
gosa_query_packages_list
GOSAGOSA". - "".$release."
"; + $attr. + "".$release."10"; }else{ $xml_msg = "
gosa_query_packages_list
GOSAGOSA". + $attr. "". "AND". "".$release."". "".$package."". "". - "
"; + "10"; } - $ret = array(); if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML']) && is_array($entries['XML'])){ @@ -194,6 +213,13 @@ class gosaSupportDaemon if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML']) && is_array($entries['XML'])){ @@ -230,6 +256,13 @@ class gosaSupportDaemon if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML']) && is_array($entries['XML'])){ @@ -297,6 +330,13 @@ $xml_msg.= " if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML']) && is_array($entries['XML'])){ @@ -353,6 +393,13 @@ $xml_msg.= " if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML']) && is_array($entries['XML'])){ foreach($entries['XML'] as $entry){ @@ -400,6 +447,13 @@ $xml_msg.= " if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML'])){ foreach($entries['XML'] as $name => $entry){ @@ -447,6 +501,13 @@ $xml_msg.= " if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML'])){ foreach($entries['XML'] as $name => $entry){ @@ -490,6 +551,13 @@ $xml_msg.= " if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return(FALSE); + } + $entries = $this->xml_to_array($str); if( isset($entries['XML']['HEADER']) && $entries['XML']['HEADER']=="answer" && @@ -530,6 +598,13 @@ $xml_msg.= " if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if( isset($entries['XML']['HEADER']) && $entries['XML']['HEADER']=="answer" && @@ -576,6 +651,13 @@ $xml_msg.= " if($this->connect()){ $this->o_sock->write($xml_msg); $str = $this->o_sock->read(); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML']) || isset($entries['COUNT'])){ new log("debug","DaemonEvent (IDS) ", "gosaSupportDaemon::remove_entries()", $ids,"SUCCESS"); @@ -701,6 +783,13 @@ $xml_msg.= " $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return(FALSE); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML'])){ if(isset($entries['XML']['ERROR_STRING'])) { @@ -726,6 +815,13 @@ $xml_msg.= " if($this->connect()){ $this->o_sock->write($xml_msg); $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return(0); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML'])){ return($entries['XML']['COUNT']); @@ -832,6 +928,13 @@ $xml_msg.= " $this->o_sock->write($data); if ($answer_expected){ $str = trim($this->o_sock->read()); + + /* Check if something went wrong while reading */ + if($this->o_sock->is_error()){ + $this->set_error($this->o_sock->get_error()); + return($ret); + } + $entries = $this->xml_to_array($str); if(isset($entries['XML']) && is_array($entries['XML'])){ $ret = $entries; diff --git a/gosa-core/include/class_socketClient.inc b/gosa-core/include/class_socketClient.inc index 93e49de40..1cef298c7 100644 --- a/gosa-core/include/class_socketClient.inc +++ b/gosa-core/include/class_socketClient.inc @@ -31,7 +31,8 @@ class Socket_Client private $handle = NULL; private $bytes_read = 0; private $error = ""; - private $b_encrypt = FALSE; + private $is_error = FALSE; + private $b_encrypt = FALSE; /* Crypto information */ private $td= NULL; @@ -44,6 +45,7 @@ class Socket_Client $this->host= $host; $this->port= $port; $this->timeout= $timeout; + $this->reset_error(); /* Connect if needed */ if($connect){ @@ -55,7 +57,7 @@ class Socket_Client public function setEncryptionKey($key) { if(!function_exists("mcrypt_get_iv_size")){ - $this->error = _("The mcrypt module was not found. Please install php5-mcrypt."); + $this->set_error(_("The mcrypt module was not found. Please install php5-mcrypt.")); $this->ckey = ""; $this->b_encrypt = FALSE; } @@ -99,10 +101,11 @@ class Socket_Client public function open() { + $this->reset_error(); $this->handle = @fsockopen($this->host, $this->port, $this->errno, $this->errstr, $this->timeout); if(!$this->handle){ $this->handle = NULL; - $this->error = $this->errstr; + $this->set_error( $this->errstr); }else{ $this->b_data_send = TRUE; @@ -116,6 +119,26 @@ class Socket_Client } + public function set_error($str) + { + $this->is_error =TRUE; + $this->error=$str; + } + + + public function reset_error() + { + $this->is_error =FALSE; + $this->error = ""; + } + + + public function is_error() + { + return($this->is_error); + } + + public function get_error() { return $this->error; @@ -138,6 +161,7 @@ class Socket_Client public function read() { // Output the request results + $this->reset_error(); $str = ""; $data = "test"; socket_set_timeout($this->handle,$this->timeout); @@ -163,7 +187,8 @@ class Socket_Client } } } - if((microtime(TRUE) - $start) > $this->timeout ){ + if((microtime(TRUE) - $start) > $this->timeout ){ + $this->set_error(sprintf(_("Socket timeout of %s seconds reached."),$this->timeout)); break; } } -- 2.30.2