summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cd14033)
raw | patch | inline | side by side (parent: cd14033)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 24 Jan 2008 07:39:40 +0000 (07:39 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 24 Jan 2008 07:39:40 +0000 (07:39 +0000) |
-Simplified timeout breakup.
-Added new query method into deamon.
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8574 594d385d-05f5-0310-b6e9-bd551577e9d8
-Added new query method into deamon.
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8574 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/class_gosaSupportDaemon.inc | patch | blob | history | |
gosa-core/include/class_socketClient.inc | patch | blob | history |
diff --git a/gosa-core/include/class_gosaSupportDaemon.inc b/gosa-core/include/class_gosaSupportDaemon.inc
index 2eba2f8eb82f6937b7ccc5bd7c56be35140b8c3b..487fa5cf407c03716b2e9179b7b18bda5384b13c 100644 (file)
$this->b_error = FALSE;
$this->s_error = "";
- $xml_msg = "<xml><header>gosa_query_jobdb</header><where><status>*</status></where></xml>";
+
+ $xml_msg = "<xml>
+ <header>gosa_query_jobdb</header>
+ <where>
+ <clause>
+ <phrase>
+ <operator>gt</operator>
+ <id>-1</id>
+ </phrase>
+ </clause>
+ </where>
+ </xml>";
+
$this->connect();
if($this->is_connected){
$this->o_sock->write($xml_msg);
index 6b2dafddfe0757f2fcd79715fff2c0321d3f63b6..fd71b01f09fb8bd2efc3c6b8cd52b32972074fb7 100644 (file)
class Socket_Client
{
- private $host = "";
- private $port = "";
- private $timeout= "";
- private $errno = "";
- private $errstr = "";
- private $b_data_send = FALSE;
- private $handle = NULL;
- private $bytes_read = 0;
- private $error = "";
-
- /* Crypto information */
- private $td= NULL;
- private $ckey= "";
- private $ks;
- private $iv;
-
-
- public function __construct($host, $port, $connect = TRUE, $timeout = 3){
- $this->host= $host;
- $this->port= $port;
- $this->timeout= $timeout;
-
- /* Connect if needed */
- if($connect){
- $this->open();
- }
- }
-
-
- public function setEncryptionKey($key)
- {
- if(!function_exists("mcrypt_get_iv_size")){
- $this->error = _("The mcrypt module was not found. Please install php5-mcrypt.");
- $this->ckey = "";
- return FALSE ;
- }
-
- if ($this->connected()){
- $this->ckey = substr(md5($key), 0, $this->ks);
- return TRUE;
- }
-
- return FALSE;
- }
-
-
- private function encrypt($data)
- {
- mcrypt_generic_init($this->td, $this->ckey, $this->iv);
- return base64_encode(mcrypt_generic($this->td, $data));
- }
-
-
- private function decrypt($data)
- {
- /* decrypt data */
- $data = base64_decode($data);
- mcrypt_generic_init($this->td, $this->ckey, $this->iv);
- return mdecrypt_generic($this->td, $data);
- }
-
-
- public function connected()
- {
- return ($this->handle == TRUE);
- }
-
-
- public function open()
- {
- $this->handle = @fsockopen($this->host, $this->port, $this->errno, $this->errstr, $this->timeout);
- if(!$this->handle){
- $this->handle = NULL;
- $this->error = $this->errstr;
- }else{
- $this->b_data_send = TRUE;
-
- /* Open the cipher */
- $this->td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
-
- /* Create the IV and determine the keysize length */
- $this->iv = substr(md5('GONICUS GmbH'),0, mcrypt_enc_get_iv_size($this->td));
- $this->ks = mcrypt_enc_get_key_size($this->td);
- }
- }
-
-
- public function get_error()
- {
- return $this->error;
- }
-
-
- public function write($data){
- if($this->handle){
- $data = $this->encrypt($data);
- fputs($this->handle, $data."\n");
- $this->b_data_send = TRUE;
- }else{
- $this->b_data_send = FALSE;
- }
-
- return $this->b_data_send;
- }
-
-
- private function _is_timeout($start,$stop = 0)
- {
- if($stop == 0){
- $stop = microtime();
- }
- $a = split("\ ",$start);
- $b = split("\ ",$stop);
- $secs = $b[1] - $a[1];
- $msecs= $b[0] - $a[0];
- $ret = (float) ($secs+ $msecs);
- return($ret >= $this->timeout);
- }
-
-
- public function read()
- {
- // Output the request results
- $str = "";
- $data = "test";
- socket_set_timeout($this->handle,$this->timeout);
- stream_set_blocking($this->handle,0);
- $start = microtime();
-
- /* Read while
- * nothing was read yet
- * the timelimit reached
- * there is not data left on the socket.
- */
- while(TRUE){
- usleep(10000);
- $data = fread($this->handle, 1024000);
- if($data && strlen($data)>0) {
- $str .= $data;
- } else {
- if(strlen($str) != 0){
- break;
- }
- }
- if($this->_is_timeout($start)){
- break;
- }
- }
- if($this->_is_timeout($start)){
- trigger_error(sprintf("Exceeded timeout %f while reading from socket",$this->timeout));
- }
- $this->bytes_read = strlen($str);
- $this->b_data_send = FALSE;
- $str = $this->decrypt($str);
- return($str);
- }
-
-
- public function bytes_read()
- {
- return $this->bytes_read;
- }
-
-
- public function close()
- {
- if($this->handle){
- fclose($this->handle);
- }
-
- /* Terminate decryption handle and close module */
- @mcrypt_generic_deinit($this->td);
- }
+ private $host = "";
+ private $port = "";
+ private $timeout= "";
+ private $errno = "";
+ private $errstr = "";
+ private $b_data_send = FALSE;
+ private $handle = NULL;
+ private $bytes_read = 0;
+ private $error = "";
+
+ /* Crypto information */
+ private $td= NULL;
+ private $ckey= "";
+ private $ks;
+ private $iv;
+
+
+ public function __construct($host, $port, $connect = TRUE, $timeout = 3){
+ $this->host= $host;
+ $this->port= $port;
+ $this->timeout= $timeout;
+
+ /* Connect if needed */
+ if($connect){
+ $this->open();
+ }
+ }
+
+
+ public function setEncryptionKey($key)
+ {
+ if(!function_exists("mcrypt_get_iv_size")){
+ $this->error = _("The mcrypt module was not found. Please install php5-mcrypt.");
+ $this->ckey = "";
+ return FALSE ;
+ }
+
+ if ($this->connected()){
+ $this->ckey = substr(md5($key), 0, $this->ks);
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
+
+ private function encrypt($data)
+ {
+ mcrypt_generic_init($this->td, $this->ckey, $this->iv);
+ return base64_encode(mcrypt_generic($this->td, $data));
+ }
+
+
+ private function decrypt($data)
+ {
+ /* decrypt data */
+ $data = base64_decode($data);
+ mcrypt_generic_init($this->td, $this->ckey, $this->iv);
+ return mdecrypt_generic($this->td, $data);
+ }
+
+
+ public function connected()
+ {
+ return ($this->handle == TRUE);
+ }
+
+
+ public function open()
+ {
+ $this->handle = @fsockopen($this->host, $this->port, $this->errno, $this->errstr, $this->timeout);
+ if(!$this->handle){
+ $this->handle = NULL;
+ $this->error = $this->errstr;
+ }else{
+ $this->b_data_send = TRUE;
+
+ /* Open the cipher */
+ $this->td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
+
+ /* Create the IV and determine the keysize length */
+ $this->iv = substr(md5('GONICUS GmbH'),0, mcrypt_enc_get_iv_size($this->td));
+ $this->ks = mcrypt_enc_get_key_size($this->td);
+ }
+ }
+
+
+ public function get_error()
+ {
+ return $this->error;
+ }
+
+
+ public function write($data){
+ if($this->handle){
+ $data = $this->encrypt($data);
+ fputs($this->handle, $data."\n");
+ $this->b_data_send = TRUE;
+ }else{
+ $this->b_data_send = FALSE;
+ }
+
+ return $this->b_data_send;
+ }
+
+
+ public function read()
+ {
+ // Output the request results
+ $str = "";
+ $data = "test";
+ socket_set_timeout($this->handle,$this->timeout);
+ stream_set_blocking($this->handle,0);
+ $start = microtime(TRUE);
+
+ /* Read while
+ * nothing was read yet
+ * the timelimit reached
+ * there is not data left on the socket.
+ */
+ while(TRUE){
+ usleep(10000);
+ $data = fread($this->handle, 1024000);
+ if($data && strlen($data)>0) {
+ $str .= $data;
+ } else {
+ if(strlen($str) != 0){
+ break;
+ }
+ }
+ if((microtime(TRUE) - $start) > $this->timeout ){
+ trigger_error(sprintf("Exceeded timeout %f while reading from socket",$this->timeout));
+ break;
+ }
+ }
+ $this->bytes_read = strlen($str);
+ $this->b_data_send = FALSE;
+ $str = $this->decrypt($str);
+ return($str);
+ }
+
+
+ public function bytes_read()
+ {
+ return $this->bytes_read;
+ }
+
+
+ public function close()
+ {
+ if($this->handle){
+ fclose($this->handle);
+ }
+
+ /* Terminate decryption handle and close module */
+ @mcrypt_generic_deinit($this->td);
+ }
}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>