X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_socketClient.inc;h=4442e1c5017729efdbccdfd6513655a279c079e7;hb=78a6813efd2f0b4eb471a688685a2abf1429ebf8;hp=2812e26880eab4dd50b5455bc3d2eb204d4b7348;hpb=924f80ac5a0642c90c3e4574bef8ce85545048fc;p=gosa.git diff --git a/gosa-core/include/class_socketClient.inc b/gosa-core/include/class_socketClient.inc index 2812e2688..4442e1c50 100644 --- a/gosa-core/include/class_socketClient.inc +++ b/gosa-core/include/class_socketClient.inc @@ -1,4 +1,24 @@ host= $host; $this->port= $port; $this->timeout= $timeout; + $this->reset_error(); /* Connect if needed */ if($connect){ @@ -35,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; } @@ -62,7 +84,7 @@ class Socket_Client private function decrypt($data) { /* decrypt data */ - if($this->b_encrypt){ + if($this->b_encrypt && strlen($data)){ $data = base64_decode($data); mcrypt_generic_init($this->td, $this->ckey, $this->iv); $data = mdecrypt_generic($this->td, $data); @@ -79,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(sprintf(_("Socket connection to host '%s:%s' failed: %s"),$this->host,$this->port,$this->errstr)); }else{ $this->b_data_send = TRUE; @@ -96,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; @@ -118,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); @@ -136,11 +180,15 @@ class Socket_Client $str .= $data; } else { if(strlen($str) != 0){ - break; + + /* We got but is still missing, keep on reading */ + if(preg_match("/<\/xml>/",$this->decrypt($str))){ + break; + } } } - if((microtime(TRUE) - $start) > $this->timeout ){ - trigger_error(sprintf("Exceeded timeout %f while reading from socket",$this->timeout)); + if((microtime(TRUE) - $start) > $this->timeout ){ + $this->set_error(sprintf(_("Socket timeout of %s seconds reached."),$this->timeout)); break; } }